//ES/////////////////////////////////////////////////////////////////////////
//     funciones de validacion. con mensajes de error segun el idioma.
///////////////////////////////////////////////////////////////////////////
function validaFormCorreo(formulario,idioma)
{	
	esBueno=true;
	if ((formulario.email.value.length>0))
	{
		esBueno=escorreo(formulario.email,idioma);
	}
	else
	{
		esBueno=estelefono(formulario.telefono,idioma);
	}


	if (esBueno)
	{
		if (formulario.nombre.value.length<3) escribeMensaje(9,idioma,"")
		else 
		{
			if (elejidoTipoMensaje(idioma,formulario.informacion))
			{
				formulario.submit();
			}
		}
	}
}

///////////////////////////////////////////////////////////////////////////
//ES/////////////////////////////////////////////////////////////////////////
//     funciones de validacion. con mensajes de error segun el idioma.
///////////////////////////////////////////////////////////////////////////
function validaFormCorreo100720(formulario,idioma)
{	
	sub_tel=formulario.telefono;
	sub_email=formulario.email;
	esBueno=true;
	  // 050318JAVIER FIN MODIFICACION
	  // 100510 ANGEL Quito la comprobación del teléfono
	  // 150710 ANGEL Vuelvo a activar la comprobación del teléfono
	 //if (formulario.telefono & "" == "")
	if ((sub_tel.value.length<1))
	{
		//if ((sub_email.value.length<1)) esBueno=false;
		esBueno=escorreo(formulario.email,idioma);
	//if (escorreo(formulario.email,idioma) == False)	esBueno=False
	}
	// if (escorreo(formulario.email,idioma))
	 // { 
	if (esBueno)
	{
		 if (estelefono(formulario.telefono,idioma))
		 { 
			if (formulario.nombre.value.length<3) escribeMensaje(9,idioma,"")
			else 
			{
				if (elejidoTipoMensaje(idioma,formulario.informacion))
				{
					formulario.submit();
				}
			}
		}
	}
	
	//}
}
///////////////////////////////////////////////////////////////////////////
function validaFormCorreoEsp(formulario,idioma)
{

	// 20-07-2010 lo dejo igual a validaFormCorreo
	esBueno=true;
	if ((formulario.email.value.length>0))
	{
		esBueno=escorreo(formulario.email,idioma);
	}
	else
	{
		esBueno=estelefono(formulario.telefono,idioma);
	}


	if (esBueno)
	{
		if (formulario.nombre.value.length<3) escribeMensaje(9,idioma,"")
		else 
		{
			if (elejidoTipoMensaje(idioma,formulario.informacion))
			{
				formulario.submit();
			}
		}
	}

	// 050318JAVIER FIN MODIFICACION
	// 100510 ANGEL Quito la comprobación del teléfono
	//	if (estelefono(formulario.telefono,idioma))
	//	{ 
			//if (formulario.nombre.value.length<3) escribeMensaje(9,idioma,"")
			//else 
			//{
			//	if (elejidoTipoMensaje(idioma,formulario.informacion))
			//	{
			//		formulario.zPagOrigen.value=location.pathname;
			//		formulario.submit();
			//	}
			//}
	//	}

}

///////////////////////////////////////////////////////////////////////////
function validaSoloTelefono(formulario,idioma)
{	
	// 050909 JOSE AL RESPONDER A UN CORREO SOLO VALIDAR TELEFONO PORQUE EL NOMBRE NO SE PIDE
		if (estelefono(formulario.telefono,idioma))
		{ 
			if (formulario.nombre.value=="") escribeMensaje(9,idioma,"")
			else 
			{
				formulario.submit();
			}
		}
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// 050318 JAVIER MODIFICACION NOMBRE Y 2 APELLIDOS
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
function conpruebaApellidos(texto, idioma)
{
	var subtexto;
	subtexto = trim(texto);
	subtexto = subtexto.replace("  "," ");
	var vector = subtexto.split(" ");
	var i;
	var palabras;
	if (vector.length<3)
	{
		if (idioma == "ESP")	{
		alert("Debe de introducir su nombre y sus 2 apellidos.");	
		}
		else 
		{	
			if (idioma == "VAL") {
				alert("Deu de  introduïr el seu nom i cognoms");
			}
		}
		return false;
	}
	else 
	{
		i = 0;
		palabras=0;
		while (i < vector.length) {
			if  (vector[i].length>2) palabras=palabras+1;
			i = i + 1;
		}
		
		if(palabras<3){
			if (idioma == "ESP")	{
				alert("Debe de introducir correctamente su nombre y sus 2 apellidos.");	
			}	
			else 
			{	
				if (idioma == "VAL") {
					alert("Ha d'introduïr correctament el seu nom i cognoms");
				}
			}
			return false;
		}
	  	return true;
	 }
}
// 050318 JAVIER FIN DE LA MODIFICACON
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function escorreo(correo,idioma)
{

	if ((correo.value.indexOf("@",0 )==-1) || (correo.value.indexOf(".",0 )==-1) || (correo.value.length<6))
	{
		 escribeMensaje(1,idioma,"'"+correo.value+"'");
		 correo.value="";
		 return false;
	}
	else return true;
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function bloquea_escritura(campo,maximo,idioma)
{
	if (campo.value.length>=maximo) 
	{
		escribeMensaje(10,idioma,maximo);
		campo.value=campo.value.substring(0,maximo-1);
		//return false;
	}

}
///////////////////////////////////////////////////////////////////////////
function tienePrefijo(telefono,xidioma)
{

	//if (xidioma=="VAL" || xidioma=="ESP") return true;
	//#060613 J.CARLOS Ahora se permiten tanto telefonos nacionales como extranjeros
	//en todos los idiomas, pero los nacionales han de comenzar por 6 o 9
	if (telefono.length==9){
		if(telefono.charAt(0)=='6' || telefono.charAt(0)=='9')
			return true;
		else{
			escribeMensaje(2,xidioma,"")
			return false;
		}
	}else
	{
		if(telefono.length<12) 
		{
			escribeMensaje(11,xidioma,"")
			return false;
		}
		else return true;
	}
}

///////////////////////////////////////////////////////////////////////////
function nosolodigitos(cad) 
{	
	ereg=/\D/;
	v=ereg.test(cad);
	return v
}

function elejidoTipoMensaje(idioma, informacion)
{
	
	if (informacion.value.length==0)
	{
		escribeMensaje(12,idioma,"");
		return false;
	}
	else return true;
}

function estelefono_100720(telefono,idioma)
{

	var i,j,numeros;
	var tel=telefono.value;
	var sub_tel;
	
	//Deja pasar todos
	return true;
		
	if(tel.charAt(0) + "" == "+")
	{
		sub_tel=tel.substring(1,tel.length);
		if(sub_tel.substring(0,2)!="00") sub_tel = "00" + sub_tel;
		telefono.value=sub_tel;
	}
	else
	{
		sub_tel=tel;
	}
	
	//if (nosolodigitos(sub_tel))
	//{
	//	escribeMensaje(2,idioma,"'"+tel+"'");
	//	return false;
	//}
	//else
	//{
		if ((sub_tel.length<4))
		{
			escribeMensaje(2,idioma,"'"+tel+"'");
			return false;
		}
		else return true		
	//}
}

function estelefono(telefono,idioma)
{

	var i,j,numeros;
	var tel=telefono.value;
	var sub_tel;
	
		
	if(tel.charAt(0) + "" == "+")
	{
		sub_tel=tel.substring(1,tel.length);
		if(sub_tel.substring(0,2)!="00") sub_tel = "00" + sub_tel;
		telefono.value=sub_tel;
	}
	else
	{
		sub_tel=tel;
	}
	
	if (nosolodigitos(sub_tel))
	{
		escribeMensaje(2,idioma,"'"+tel+"'");
		return false;
	}
	else
	{
		if ((sub_tel.length<9))
		{
			escribeMensaje(2,idioma,"'"+tel+"'");
			return false;
		}
		else return tienePrefijo(sub_tel,idioma)		
	}

}



///////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function validaFechaVisita(f,idioma){
	var ms4, xdif;
	
	if ((validaDia(f.dia,idioma)) & (validaMes(f.mes,idioma)) & (validaAnyo(f.anyo,idioma)) & (validaHora(f.hora,idioma)) & (validaMinutos(f.minuto,idioma))) 
		{
			var fx2=new Date(f.anyo.value,f.mes.value-1,f.dia.value,f.hora.value,f.minuto.value,0);
			var fx =new Date();

			ms4=(4*24*60*60)-3600;
			xdif=((fx2-fx)/1000);
			//alert(" Difer. fechas: " + xdif + "\n  Fx: " + fx.toLocaleString()+ "  Fx2: " + fx2.toLocaleString());
			if (xdif<ms4) 
			{
				 escribeMensaje(3,idioma,"");
				// alert("aqui")
			}
			else
			{
				//alert("submit");
				f.submit();
			}

		}
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function validaMinutos(x,idioma)
{
	if ((x.value>59) || (x.value=="") || (x.value<0) || (isNaN(x.value))) 
	{
		escribeMensaje(4,idioma,"");
		return false;
	}
		else return true;
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function validaHora(x,idioma)
{
	if ((x.value>23) || (x.value=="") || (x.value<0) || (isNaN(x.value))) 
	{
	 	escribeMensaje(5,idioma,"");
		return false;
	} 
	else return true;
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function validaDia(x,idioma)
{
	if ((x.value>31) || (x.value=="") || (x.value<1) || (isNaN(x.value)))
	{
		escribeMensaje(6,idioma,"");	
		return false;
	}
	else return true;
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function validaMes(x,idioma)
{
	if ((x.value>12) || (x.value=="") || (x.value<1) || (isNaN(x.value))) 
	{
	 escribeMensaje(7,idioma,"");	
		return false;
	}
	else return true;
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function validaAnyo(x,idioma)
{
	if ((x.value>2025) || (x.value=="") || (x.value<2000) || (isNaN(x.value)))
	{
	 escribeMensaje(8,idioma,"");	
		return false;
	}
	else return true;
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
function escribeMensaje(id,vidioma,param)
//muestra un mensaje de error segun el id del mensaje y el idioma especificado.
//el mensaje de texto se concatena con param.
{
	var msj=" ERROR no especificado. en funcion escribeMensaje"

	switch (id) 
	{
		case 1:
			if(vidioma=='ESP') msj="  la dirección de email no es correcta."
			if(vidioma=='ING') msj=" is not an email address."
			if(vidioma=='FRA') msj=" n´est pas une une direction d´e-mail."
			if(vidioma=='ALE') msj=" das  ist keine Postadresse."
			if(vidioma=='VAL') msj=" no és una adressa de correu."
			if(vidioma=='POL') msj=" to nie jest e-mail."
			if(vidioma=='HOL') msj=" Het is geen postadres"
			if(vidioma=='RUS') msj=" Ýòî íå ïî÷òîâûé àäðåñ"
			msj= param + msj												
			break;
		case 2:
			if(vidioma=='ESP') msj=" no es un nº de telefono valido por lo que no se podra contactar con usted. Por favor introduzca uno correcto."
			if(vidioma=='ING') msj=" is not a valid telephone number. In order to contact you, please introduce a correct number."
			if(vidioma=='FRA') msj="  n´est pas un numéro de téléphone valide. Nous ne pourrons donc pas nous mettre en contact avec vous. Nous vous prions d´introduire cette fois-ci un numéro correct."
			if(vidioma=='ALE') msj=" diese Telefonnummer ist nicht gültig. Bitte, geben Sie eine richtige Telefonnummer ein."
			if(vidioma=='VAL') msj=" no és un número de telèfon vàlid pel que no es podrà contactar amb vosté. Per favor introduïsca un correcte."
			if(vidioma=='POL') msj=" nº telefonu nieprawidlowy, prosimy o podanie prawidlowego nº telefonu"
			if(vidioma=='HOL') msj=" Het is geen  geldig telefoon nummer, we  kunnen  geen contact met U  nemen. Voert  U een correct telefoonnummer in."
			if(vidioma=='RUS') msj=" Ìû  íå ìîæåì ñâÿçàòüñÿ ñ Âàìè ïî ýòîìó òåëåôîííîìó íîìåðó. Ïîæàëóéñòà, ââîäèòå ïðàâèëüíûé òåëåôîííûé íîìåð."						
			msj= param + msj
			break;
		case 3:
			if(vidioma=='ESP') msj="La fecha de visita debe ser 4 días a partir de la fecha actual."
			if(vidioma=='ING') msj="The date of the visit must be 4 days from the actual date today."
			if(vidioma=='FRA') msj="La date de la visite pourra être choisie dans 4 jours à compter d´aujourd´hui."
			if(vidioma=='ALE') msj="Der Besuchtermin muss 4 Tage ab heute sein."
			if(vidioma=='VAL') msj="La data de visita ha de ser 4 dies a partir de la data actual."
			if(vidioma=='POL') msj="Data wizyty z 4 dniowym wyprzedzeniem od dnia dzisiejszego."
			if(vidioma=='HOL') msj="De  bezoekdatum is binnen 4 dagen vanaf de dag van vandaag."									
			if(vidioma=='RUS') msj="Äàòà âèçèòà íàçíà÷àåòñÿ 4 äíÿ ïîñëå êîíòàêòà ñ íàìè. Åñëè Âû õîòèòå íàçíà÷èòü äàòó çàðàíåå, çâîíèòå â ñîîòâåòñòâóþùóþ êîíòîðó."			
			break;
		case 4:
			if(vidioma=='ESP') msj="Los minutos deben ser un valor entre 0 y 59."
			if(vidioma=='ING') msj="Minutes must be between 0 and 59."
			if(vidioma=='FRA') msj="Les minutes doivent  être une valeur entre 0 et 59."
			if(vidioma=='ALE') msj="Die Minuten mussen von 0 bis 59 sein."
			if(vidioma=='VAL') msj="Els minuts han de ser un valor entre 0 i 59."
			if(vidioma=='POL') msj="Minuty musza miec walor od 0 do 59."
			if(vidioma=='HOL') msj="De minuten moeten een waarde zijn tussen 0 en 59."									
			if(vidioma=='RUS') msj="Ìèíóòû äîëæíû èìåòü ñòîèìîñòüþ ìåæäó 0 è 59."			
			break;
		case 5:
			if(vidioma=='ESP') msj="La hora debe ser un valor entre 0 y 23."
			if(vidioma=='ING') msj="The Hour must be between 0 and 23."
			if(vidioma=='FRA') msj="L´heure doit être une valeur entre 0 et 23."
			if(vidioma=='ALE') msj="Die Stunde muss von 0 bis 23 sein."
			if(vidioma=='VAL') msj="L'hora ha de ser un valor entre 0 i 23."
			if(vidioma=='POL') msj="Godziny musza miec walor od 0 do 23."
			if(vidioma=='HOL') msj="Het uur moet een waarde zijn tussen 0 en 23."									
			if(vidioma=='RUS') msj="×àñ äîëæåí èìåòü ñòîèìîñòüþ ìåæäó 0 è 23."			
			break;
		case 6:
			if(vidioma=='ESP') msj="El dia debe ser un valor entre 1 y 31."
			if(vidioma=='ING') msj="The date must be between 1 and 31."
			if(vidioma=='FRA') msj="Le jour doit être une valeur entre 1 et 31."
			if(vidioma=='ALE') msj="Der Tag muss von 1 bis 31 sein."			
			if(vidioma=='VAL') msj="El dia ha de ser un valor entre 1 i 31."
			if(vidioma=='POL') msj="Dzien musi miec walor od 1 do 31."
			if(vidioma=='HOL') msj="De dag moet een waarde zijn tussen 1en 31."						
			if(vidioma=='RUS') msj="Äåíü äîëæåí èìåòü ñòîèìîñòüþ ìåæäó 1 è 31."			
			break;
		case 7:
			if(vidioma=='ESP') msj="El mes debe ser un valor entre 1 y 12."
			if(vidioma=='ING') msj="The Month must be between 1 and 12."
			if(vidioma=='FRA') msj="Le mois doit être une valeur entre 1 et 12."
			if(vidioma=='ALE') msj="Der Monat muss von 1 bis 12 sein."			
			if(vidioma=='VAL') msj="El mes ha de ser un valor entre 1 i 12."
			if(vidioma=='POL') msj="Miesiac musi miec walor od 1 do 12."
			if(vidioma=='HOL') msj="De maand moet een waarde zijn tussen 1 en 12."									
			if(vidioma=='RUS') msj="Ìåñÿö äîëæåí èìåòü ñòîèìîñòüþ ìåæäó 1 è 12."			
			break;
		case 8:
			if(vidioma=='ESP') msj="El año debe ser un valor entre 2000 y 2025."
			if(vidioma=='ING') msj="The year must be between 2000 and 2025."
			if(vidioma=='FRA') msj="L´année doit être une valeur entre entre 2000 et 2025."
			if(vidioma=='ALE') msj="Das Jahr muss von 2000 bis 2025 sein."
			if(vidioma=='VAL') msj="L'any ha de ser un valor entre 2000 i 2025."
			if(vidioma=='POL') msj="Rok musi miec walor od 2000 do 2025."
			if(vidioma=='HOL') msj="Het jaar moet een waarde zijn tussen 2000 en 2025."												
			if(vidioma=='RUS') msj="Ãîä äîëæåí èìåòü ñòîèìîñòüþ ìåæäó 2000 è 2025."			
			break;
		case 9:
			if(vidioma=='ESP') msj="Escriba su nombre para poder contactar con usted más cordialmente."
			if(vidioma=='ING') msj="Please give your full name."
			if(vidioma=='FRA') msj="Ecrivez votre nom,  afin de pouvoir dialoguer avec vous de manière plus cordiale."
			if(vidioma=='ALE') msj="Schreiben Sie  Ihr Name um Kontakt mit Ihnen aufzunehmen."
			if(vidioma=='VAL') msj="Escriga el seu nom per a poder contactar amb vosté més cordialment."
			if(vidioma=='POL') msj="Prosze podac swoje dane do szybszego skontaktowania sie."
			if(vidioma=='HOL') msj="Please give your full name."												
			if(vidioma=='RUS') msj="Ïîæàëóéñòà, çàïîëíèòå  âñå ïîëÿ ôîðìóëÿðà. "			
			break;
		case 10:
			if(vidioma=='ESP') msj="El maximo número de carácteres permitidos es "
			if(vidioma=='ING') msj="The maximum number of permitted characters  is "
			if(vidioma=='FRA') msj="Le numéro maximum de caractères permis est de "
			if(vidioma=='ALE') msj="Die maximale Nummer von erlaubten Charakteren ist "
			if(vidioma=='VAL') msj="El maximo número de carácteres permitidos es "
			if(vidioma=='POL') msj="Maxymalna ilosc charakterow dozwolonych - "
			if(vidioma=='HOL') msj="The maximum number of permitted characters  is "
			if(vidioma=='RUS') msj="Ìàêñèìàëüíîå ÷èñëî ïîçâîëåííûõ ñèìâîëîâ - "			
			msj=msj + param	 + "."											
			break;
		case 11:
			if(vidioma=='ESP') msj="Debe de introducir un número de teléfono correcto. Si introduce un número de fuera de España recuerde que ha de introducir el prefijo internacional. Haga click sobre <prefijos telefonicos de paises> si desea conocer el prefijo de un pais."
			if(vidioma=='ING') msj="You must introduce the prefix/Area code of the country and the telephone number, Click on <country telephone prefixes>, if you wish to know the prefix of a country. "
			if(vidioma=='FRA') msj="Vous devez introduire le préfixe international du pays devant le numéro de télephone. Faîtes click sur <préfixes téléphoniques des pays> si vous souhaitez savoir quel est le préfixe d´un pays."
			if(vidioma=='ALE') msj="Geben Sie die Vorwahl des Landes der Telefonnummer ein.Klicken Sie auf < Vorwahlnummern der Länder> wenn Sie  dieVorwahl von einem Land kennen wollen"
			if(vidioma=='VAL') msj="Debe de introducir el prefijo del pais del numero de telefono. Haga click sobre <prefijos telefonicos de paises> si desea conocer el prefijo de un pais. "
			if(vidioma=='POL') msj="Prosze podac telefon kierunkowy swojego kraju. Przycisnij <numery kierunkowe krajow> jezeli nie znasz numeru kierunkowego twojego kraju. "
			if(vidioma=='HOL') msj="You must introduce the prefix/Area code of the country and the telephone number, Click on <country telephone prefixes>, if you wish to know the prefix of a country. "
			if(vidioma=='RUS') msj="You must introduce the prefix/Area code of the country and the telephone number, Click on <country telephone prefixes>, if you wish to know the prefix of a country. "			
			msj=msj;											
			break;	
		case 12:
			if(vidioma=='ESP') msj="Debe indicar si esta interesado en comprar o vender."
			if(vidioma=='ING') msj="Please indicate whether you are interested in buying or selling."
			if(vidioma=='FRA') msj="Veuillez indiquer si vous voulez acheter ou vendre un bien."
			if(vidioma=='ALE') msj="Bitte geben Sie an, ob Sie kaufen oder verkaufen möchten."
			if(vidioma=='VAL') msj="Triar el tipus del missatge per favor: vendre  o comprar."
			if(vidioma=='POL') msj="Prosimy o potwierdzenie, czy pañstwo chca sprzedac, czy kupic."
			if(vidioma=='HOL') msj="U dient aan te duiden of u geïnteresseerd bent in kopen of verkopen."
			if(vidioma=='RUS') msj="Íåîáõîäèìî óêàçàòü â ÷¸ì Âû çàèíòåðåñîâàíû â ïîêóïêå ëèáî ïðîäàæå."
			msj= param + msj												
			break;
	}
	alert(msj);
}
