// variables
telephone_length = 6;
lng_hotelname = ["Hotel Name","Nombre del Hotel"];
lng_hotel = ["Please Write Hotel Name","Escriba el Nombre del Hotel"];
lng_room = ["Select Room Type","Seleccione el Tipo de Habitación"];
lng_noroom = ["Select the Number of Rooms","Seleccione la Cantidad de Habitaciones"];
lng_name = ["Write Your Name","Escriba tu Nombre"];
lng_email = ["Write Your Email Address","Escriba tu Email"];
lng_emailck = ["Check Your Email Address","Email EQUIVOCADO. Revíselo"];
lng_confemail = ["Confirm Your Email Address","Confirme tu Email"];
lng_confemailck = ["Check Your Confirm Email Address","Email de Confirmación EQUIVOCADO. Revíselo"];
lng_emailnomatch = ["E-mails do not match","E-mails NO Coinciden"];
lng_phone = ["Write Your Telephone","Escribe tu Teléfono"];
lng_phoneerr1 = ["Your Phone must be at least ","El Número de Teléfono debe tener al menos "];
lng_phoneerr2 = [" characters digits. Try again."," dígitos. Intente de Nuevo"];
// hasta aqui lo del hotel
// esto es de contactenos
lng_subject = ["Write Your Subject","Escriba el Asunto"];
lng_message = ["Write Your Message","Escriba el Mensaje"];
// esto es de planificador
lng_budget = ["Please Choose the Budget","Seleccione el Presupuesto"];

language = 0; // english 


function ck_integer(campo, comparador, alerta) {
	if (campo.value == comparador)
      {
		alert(alerta);
		campo.focus();
		return (false);
      }
	return (true);
}

function ck_correo(campo, alerta) {
	var checkStr = campo.value;
	var ix = (checkStr.length - 4)
	var RC = true;
	var xerror = false;
	var x = AtSignValid = DoublePeriod = PeriodValid = SpaceValid = ExtValid = 0;
	for (i = 0;  i < checkStr.length;  i++)
	{
		if (checkStr.charAt(i) == '@') AtSignValid++;
		if (checkStr.charAt(i) == '.') PeriodValid++;
		if (checkStr.charAt(i) == ' ') SpaceValid ++;
	}
	xerror = false;
	if (AtSignValid != 1) xerror = true ;
	if (PeriodValid == 0) xerror = true ;
	if (SpaceValid > 0) xerror = true ;
	if (SpaceValid > 1) xerror = true ;
	if (checkStr.length > 120) xerror = true ;
	if (xerror)
	{
		alert(alerta) ;
		campo.focus();
		return(false);
	}
	return(true);
}

function dateSubmit() {
   firstDate  = date1.getObjSelectedDate();
   secondDate = date2.getObjSelectedDate();
	 if (firstDate>secondDate) {
		 date1.setObjDate(secondDate);           
		 date2.setObjDate(firstDate);
	 }
  return(false);
}
	
function  validarHotel(theForm) {
	// variables
	if (theForm.idioma.value == "spanish") language = 1; // spanish 
	if (theForm.hotel.value == lng_hotelname[language] || theForm.hotel.value == "") {
		alert(lng_hotel[language]);
		theForm.hotel.focus();
		return (false);
	}
	if (!(ck_integer(theForm.roomType,"-1",lng_room[language]))) return(false);
	if (!(ck_integer(theForm.noOfRooms,"-1",lng_noroom[language]))) return(false);
	if (!(ck_integer(theForm.realname,"",lng_name[language]))) return(false);
	if (!(ck_integer(theForm.email,"",lng_email[language]))) return(false);
	if (!ck_correo(theForm.email,lng_emailck[language])) return(false);
	if (!(ck_integer(theForm.confemail,"",lng_confemail[language]))) return(false);
	if (!ck_correo(theForm.confemail,lng_confemailck[language])) return(false);	
	if (!(theForm.email.value == theForm.confemail.value)){
		alert(lng_emailnomatch[language]);
		theForm.confemail.focus();
		return(false);
	}
	if (!(ck_integer(theForm.yourTelephone,"",lng_phone[language]))) return(false);
	if (theForm.yourTelephone.value.length < telephone_length) {
		alert(lng_phoneerr1[language] + telephone_length + lng_phoneerr2[language]);
		theForm.yourTelephone.focus();
		return false;
	}
	dateSubmit();
}
	
function validarPlan(theForm) {
	if (theForm.idioma.value == "spanish") language = 1; // spanish 
	if (!(ck_integer(theForm.budget,"-1",lng_budget[language]))) return(false);
	if (!(ck_integer(theForm.noOfRooms,"-1",lng_noroom[language]))) return(false);
	if (!(ck_integer(theForm.realname,"",lng_name[language]))) return(false);
	if (!(ck_integer(theForm.email,"",lng_email[language]))) return(false);
	if (!ck_correo(theForm.email,lng_emailck[language])) return(false);
	if (!(ck_integer(theForm.confemail,"",lng_confemail[language]))) return(false);
	if (!ck_correo(theForm.confemail,lng_confemailck[language])) return(false);	
	if (!(theForm.email.value == theForm.confemail.value)){
		alert(lng_emailnomatch[language]);
		theForm.confemail.focus();
		return(false);
	}
	if (!(ck_integer(theForm.yourTelephone,"",lng_phone[language]))) return(false);
	if (theForm.yourTelephone.value.length < telephone_length) {
		alert(lng_phoneerr1[language] + telephone_length + lng_phoneerr2[language]);
		theForm.yourTelephone.focus();
		return false;
	}
	dateSubmit();
}

function  validarTour(theForm)
{
	if (!ck_integer(theForm.tourType,"-1","Choose Name Tour")) return(false);
	if (!ck_integer(theForm.realname,"","Write Your Name")) return(false);
	if (!(ck_integer(theForm.email,"","Write Your Email Address"))) return(false);
	if (!ck_correo(theForm.email,"Check Your Email Address")) return(false);
	if (!(ck_integer(theForm.confemail,"","Confirm Your Email Address"))) return(false);
	if (!ck_correo(theForm.confemail,"Check Your Confirm Email Address")) return(false);	
	if (!(theForm.email.value == theForm.confemail.value)){
		alert("E-mails do not match");
		theForm.confemail.focus();
		return(false);
	}
	if (!(ck_integer(theForm.yourTelephone,"","Write Your Telephone"))) return(false);
	if (theForm.yourTelephone.value.length < telephone_length) {
		alert('Your Phone must be at least ' + telephone_length + ' characters digits. Try again.');
		theForm.yourTelephone.focus();
		return false;
	}
 }

function  validarPackage(theForm)
{
	if (!ck_integer(theForm.packageName,"-1","Choose Name Package")) return(false);
	if (!ck_integer(theForm.budget,"-1","Choose Choose Budget")) return(false);
	if (!ck_integer(theForm.realname,"","Write Your Name")) return(false);
	if (!(ck_integer(theForm.email,"","Write Your Email Address"))) return(false);
	if (!ck_correo(theForm.email,"Check Your Email Address")) return(false);
	if (!(ck_integer(theForm.confemail,"","Confirm Your Email Address"))) return(false);
	if (!ck_correo(theForm.confemail,"Check Your Confirm Email Address")) return(false);	
	if (!(theForm.email.value == theForm.confemail.value)){
		alert("E-mails do not match");
		theForm.confemail.focus();
		return(false);
	}
	if (!(ck_integer(theForm.yourTelephone,"","Write Your Telephone"))) return(false);
	if (theForm.yourTelephone.value.length < telephone_length) {
		alert('Your Phone must be at least ' + telephone_length + ' characters digits. Try again.');
		theForm.yourTelephone.focus();
		return false;
	}
}

function Validar(theForm)
{
	if (!ck_integer(theForm.realname,"","Write Your Name")) return(false);
	if (!(ck_integer(theForm.email,"","Write Your Email Address"))) return(false);
	if (!ck_correo(theForm.email,"Check Your Email Address")) return(false);
	if (!(ck_integer(theForm.yourTelephone,"","Write Your Telephone"))) return(false);
	if (theForm.yourTelephone.value.length < telephone_length) {
		alert('Your Phone must be at least ' + telephone_length + ' characters digits. Try again.');
		theForm.yourTelephone.focus();
		return false;
	}
}

function ValidarContacto(theForm)
{
	if (theForm.idioma.value == "spanish") language = 1; // spanish 
	if (!(ck_integer(theForm.realname,"",lng_name[language]))) return(false);
	if (!(ck_integer(theForm.email,"",lng_email[language]))) return(false);
	if (!ck_correo(theForm.email,lng_emailck[language])) return(false);
	if (!ck_integer(theForm.asunto,"",lng_subject[language])) return(false);
	if (!ck_integer(theForm.message,"",lng_message[language])) return(false);
}

function AntiSpam(codelist, description, atagattr) {
	var thiscode, thischar;
	var CodeString = new String(codelist);
	var CodedArray = CodeString.split('|');
	var L = CodedArray.length;
	var AddrDecoded = "";
	for (var x=0; x < L; x++) {
		thiscode = CodedArray[x];
		thischar = String.fromCharCode( thiscode - L );
		AddrDecoded += thischar;
	}
	atagattr = atagattr ? ' ' + atagattr : '';
	if (!description) description = AddrDecoded; // if no description supplied, display email address
	var strOutput = '<a href="mailto:'+AddrDecoded+'"' + atagattr+'>' + description + '</a>';
	document.write(strOutput);
}