// Esta funcion es valida que solo se introduzcan letras y no numeros


function validar(e,modo) { // 1
		tecla = (document.all) ? e.keyCode : e.which; // 2
		if (tecla==8) return true; // 3
		patron = (modo=='letra') ? /[A-Za-zs]/ : /d/ // 4
		te = String.fromCharCode(tecla); // 5
		return patron.test(te); // 6
}

// Esta funcion es valida solo para el grupo de ficheros para Contacto


function Validar(){
    var txt = "Error en los siguientes campos: \n\n";
	msg_f = txt.length;

if (document.contacto.nombre.value == "")
	{
	 alert("Por favor, introduzca un Nombre de Contacto en el campo correspondiente, gracias");
			document.contacto.nombre.focus();
			document.contacto.nombre.style.backgroundColor = "#C3C3C3";
			return false;
	}


		if (document.contacto.telefono.value=="")
		{
      alert("Por favor, introduzca un Teléfono en el campo correspondiente, gracias");
			document.contacto.telefono.focus();
			document.contacto.telefono.style.backgroundColor = "#C3C3C3";

			return false;
		}





var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^[(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=document.contacto.correo.value.match(emailPat);
	if (matchArray==null) {
		alert("La direccion de correo parece ser invalida (verifique las @ y .)")
		document.contacto.correo.focus();
			document.contacto.correo.style.backgroundColor = "#C3C3C3";
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
		alert("El nombre de usuario parece ser invalido.")
		document.contacto.correo.focus();
			document.contacto.correo.style.backgroundColor = "#C3C3C3";
		return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			alert("La direccion IP de destino es invalida!")
			document.contacto.correo.focus();
			document.contacto.correo.style.backgroundColor = "#C3C3C3";
			return false
			}
	}
	return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("El dominio no parece ser valido.")
		document.contacto.correo.focus();
			document.contacto.correo.style.backgroundColor = "#C3C3C3";
		return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
		alert("Las direcciones deben terminar con dominios de tres letras, o el codigo de pais de dos letras.")
		document.contacto.correo.focus();
			document.contacto.correo.style.backgroundColor = "#C3C3C3";
		return false
	}

	if (len<2) {
		var errStr="Dominio Invalido!";
		alert(errStr)
		document.contacto.correo.focus();
			document.contacto.correo.style.backgroundColor = "#C3C3C3";
		return false
	}

if(document.contacto.aceptar_condiciones.checked == false )
	{
	document.contacto.aceptar_condiciones.style.backgroundColor = "#C3C3C3"
	txt+="\tAceptar Condiciones \n";
	}


if (msg_f != txt.length){
	alert(txt);
	return false;
	}else{
		return true;
	}
}




function TestMail(texto)
{
	var correcto=true;
	var contador = 0;
	var tlds = new Array(259);
	tlds[0]="AC";
	tlds[1]="AD";
	tlds[2]="AE";
	tlds[3]="AERO";
	tlds[4]="AF";
	tlds[5]="AG";
	tlds[6]="AI";
	tlds[7]="AL";
	tlds[8]="AM";
	tlds[9]="AN";
	tlds[10]="AO";
	tlds[11]="AQ";
	tlds[12]="AR";
	tlds[13]="ARPA";
	tlds[14]="AS";
	tlds[15]="AT";
	tlds[16]="AU";
	tlds[17]="AW";
	tlds[18]="AZ";
	tlds[19]="BA";
	tlds[20]="BB";
	tlds[21]="BD";
	tlds[22]="BE";
	tlds[23]="BF";
	tlds[24]="BG";
	tlds[25]="BH";
	tlds[26]="BI";
	tlds[27]="BIZ";
	tlds[28]="BJ";
	tlds[29]="BM";
	tlds[30]="BN";
	tlds[31]="BO";
	tlds[32]="BR";
	tlds[33]="BS";
	tlds[34]="BT";
	tlds[35]="BV";
	tlds[36]="BW";
	tlds[37]="BY";
	tlds[38]="BZ";
	tlds[39]="CA";
	tlds[40]="CC";
	tlds[41]="CD";
	tlds[42]="CF";
	tlds[43]="CG";
	tlds[44]="CH";
	tlds[45]="CI";
	tlds[46]="CK";
	tlds[47]="CL";
	tlds[48]="CM";
	tlds[49]="CN";
	tlds[50]="CO";
	tlds[51]="COM";
	tlds[52]="COOP";
	tlds[53]="CR";
	tlds[54]="CU";
	tlds[55]="CV";
	tlds[56]="CX";
	tlds[57]="CY";
	tlds[58]="CZ";
	tlds[59]="DE";
	tlds[60]="DJ";
	tlds[61]="DK";
	tlds[62]="DM";
	tlds[63]="DO";
	tlds[64]="DZ";
	tlds[65]="EC";
	tlds[66]="EDU";
	tlds[67]="EE";
	tlds[68]="EG";
	tlds[69]="ER";
	tlds[70]="ES";
	tlds[71]="ET";
	tlds[72]="FI";
	tlds[73]="FJ";
	tlds[74]="FK";
	tlds[75]="FM";
	tlds[76]="FO";
	tlds[77]="FR";
	tlds[78]="GA";
	tlds[79]="GB";
	tlds[80]="GD";
	tlds[81]="GE";
	tlds[82]="GF";
	tlds[83]="GG";
	tlds[84]="GH";
	tlds[85]="GI";
	tlds[86]="GL";
	tlds[87]="GM";
	tlds[88]="GN";
	tlds[89]="GOV";
	tlds[90]="GP";
	tlds[91]="GQ";
	tlds[92]="GR";
	tlds[93]="GS";
	tlds[94]="GT";
	tlds[95]="GU";
	tlds[96]="GW";
	tlds[97]="GY";
	tlds[98]="HK";
	tlds[99]="HM";
	tlds[100]="HN";
	tlds[101]="HR";
	tlds[102]="HT";
	tlds[103]="HU";
	tlds[104]="ID";
	tlds[105]="IE";
	tlds[106]="IL";
	tlds[107]="IM";
	tlds[108]="IN";
	tlds[109]="INFO";
	tlds[110]="INT";
	tlds[111]="IO";
	tlds[112]="IQ";
	tlds[113]="IR";
	tlds[114]="IS";
	tlds[115]="IT";
	tlds[116]="JE";
	tlds[117]="JM";
	tlds[118]="JO";
	tlds[119]="JP";
	tlds[120]="KE";
	tlds[121]="KG";
	tlds[122]="KH";
	tlds[123]="KI";
	tlds[124]="KM";
	tlds[125]="KN";
	tlds[126]="KR";
	tlds[127]="KW";
	tlds[128]="KY";
	tlds[129]="KZ";
	tlds[130]="LA";
	tlds[131]="LB";
	tlds[132]="LC";
	tlds[133]="LI";
	tlds[134]="LK";
	tlds[135]="LR";
	tlds[136]="LS";
	tlds[137]="LT";
	tlds[138]="LU";
	tlds[139]="LV";
	tlds[140]="LY";
	tlds[141]="MA";
	tlds[142]="MC";
	tlds[143]="MD";
	tlds[144]="MG";
	tlds[145]="MH";
	tlds[146]="MIL";
	tlds[147]="MK";
	tlds[148]="ML";
	tlds[149]="MM";
	tlds[150]="MN";
	tlds[151]="MO";
	tlds[152]="MP";
	tlds[153]="MQ";
	tlds[154]="MR";
	tlds[155]="MS";
	tlds[156]="MT";
	tlds[157]="MU";
	tlds[158]="MUSEUM";
	tlds[159]="MV";
	tlds[160]="MW";
	tlds[161]="MX";
	tlds[162]="MY";
	tlds[163]="MZ";
	tlds[164]="NA";
	tlds[165]="NAME";
	tlds[166]="NC";
	tlds[167]="NE";
	tlds[168]="NET";
	tlds[169]="NF";
	tlds[170]="NG";
	tlds[171]="NI";
	tlds[172]="NL";
	tlds[173]="NO";
	tlds[174]="NP";
	tlds[175]="NR";
	tlds[176]="NU";
	tlds[177]="NZ";
	tlds[178]="OM";
	tlds[179]="ORG";
	tlds[180]="PA";
	tlds[181]="PE";
	tlds[182]="PF";
	tlds[183]="PG";
	tlds[184]="PH";
	tlds[185]="PK";
	tlds[186]="PL";
	tlds[187]="PM";
	tlds[188]="PN";
	tlds[189]="PR";
	tlds[190]="PRO";
	tlds[191]="PS";
	tlds[192]="PT";
	tlds[193]="PW";
	tlds[194]="PY";
	tlds[195]="QA";
	tlds[196]="RE";
	tlds[197]="RO";
	tlds[198]="RU";
	tlds[199]="RW";
	tlds[200]="SA";
	tlds[201]="SB";
	tlds[202]="SC";
	tlds[203]="SD";
	tlds[204]="SE";
	tlds[205]="SG";
	tlds[206]="SH";
	tlds[207]="SI";
	tlds[208]="SJ";
	tlds[209]="SK";
	tlds[210]="SL";
	tlds[211]="SM";
	tlds[212]="SN";
	tlds[213]="SO";
	tlds[214]="SR";
	tlds[215]="ST";
	tlds[216]="SU";
	tlds[217]="SV";
	tlds[218]="SY";
	tlds[219]="SZ";
	tlds[220]="TC";
	tlds[221]="TD";
	tlds[222]="TF";
	tlds[223]="TG";
	tlds[224]="TH";
	tlds[225]="TJ";
	tlds[226]="TK";
	tlds[227]="TL";
	tlds[228]="TM";
	tlds[229]="TN";
	tlds[230]="TO";
	tlds[231]="TP";
	tlds[232]="TR";
	tlds[233]="TT";
	tlds[234]="TV";
	tlds[235]="TW";
	tlds[236]="TZ";
	tlds[237]="UA";
	tlds[238]="UG";
	tlds[239]="UK";
	tlds[240]="UM";
	tlds[241]="US";
	tlds[242]="UY";
	tlds[243]="UZ";
	tlds[244]="VA";
	tlds[245]="VC";
	tlds[246]="VE";
	tlds[247]="VG";
	tlds[248]="VI";
	tlds[249]="VN";
	tlds[250]="VU";
	tlds[251]="WF";
	tlds[252]="WS";
	tlds[253]="YE";
	tlds[254]="YT";
	tlds[255]="YU";
	tlds[256]="ZA";
	tlds[257]="ZM";
	tlds[258]="ZW";

for(i=0;i<tlds.length;i++){	
	 if( (texto.indexOf(tlds[i])<1) ) contador++
}
	 if (contador == 1)
	 {
		 correcto=true;
	 }

  if((texto.indexOf("@")<1) || (texto.indexOf("@")>25))
    { correcto=false; }

  
return correcto;
}


