// Ingles
disAlertAdults = "You must enter number of Adults";
disAlertKids = "You must enter number of Kids";
disAlertHotel = "You must enter the Hotel Name, please";
disAlertTrasfer = "You must specify the Transfer";
disAlertAirline1 = "You must enter the Airline Name for the Airport to Hotel transfer";
disAlertFlight1 = "You must enter the Flight Number for the Airport to Hotel transfer";
disAlertAirline2 = "You must enter the Airline Name for the Hotel to Airport transfer";
disAlertFlight2 = "You must enter the Flight Number for the Hotel to Airport transfer";
disAlertTipoTraslado = "You must enter the Type of Transfers";
disAlertFechaMinima = "All reservations should be made within 48 hours." 
disAlertFechaHoy1 = "The arrival date must be later than today.";
disAlertFechaHoy2 = "The departure date must be later than today.";

function validatePax(entered, min, max, alertbox, datatype)
{
	error = false;
	if (entered.value == "")
	{
		error = true;
	}
	checkvalue=parseFloat(entered.value);
	if (datatype)
	   {smalldatatype=datatype.toLowerCase();
	    if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(entered.value)};
		}
	if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || entered.value!=checkvalue)
       {
		error = true;
	    }
	if (error == true)
	{
		alert(alertbox);
		return false;
	}
	else
	{
		return true;
	}
	//return true;
}

function validateagree()
{
	error = false;
	if (document.forma.iagree.status == false)
	{
		error = true;
	}
	if (error == true)
	{
		alert(disAlertAgree);
		return false;
	}
	else
	{
		return true;
	}
	//return true;
}


function Validaciones(thisform)
{
	/* Tipos de Traslados: R: Round Trip S: On Way Salida L: On Way Llegada */

	with (thisform)
	{	
		// Que hay un traslado válido			
		if (clav_traslado == "") {			
			alert(disAlertTrasfer); traslado.focus(); return false;	
		}
		//Que haya indicado el hotel	
		if (hotel.value == "") {			
			alert(disAlertHotel); hotel.focus(); return false;
		}		
		//Válida Adultos
		if (validatePax(num_adultos,1,999,disAlertAdults,"I") == false ){	
			num_adultos.focus(); return false;		
		}
		//Válida nińos
		if (validatePax(num_ninos,0,5,disAlertKids,"I") == false ) {	
			num_ninos.focus();	return false;		
		}
		//Válida Tipo de Traslado Diferente de Select opcion
		if (tipo_traslado.value.toUpperCase() == "X" ){	
			alert(disAlertTipoTraslado); tipo_traslado.focus();	return false;		
		}
		
		//Nota: funcion "validaFechaHoy" esta en validationRates.js (Valida  que las fechas  no sean para el dia de hoy)
		if (tipo_traslado.value.toUpperCase() == "R" || tipo_traslado.value.toUpperCase() == "L") {
			if (validaFechaHoy(anio_desde.value,mes_desde.value,dia_desde.value,'sin') == false) {
				alert(disAlertFechaHoy1); return false;
			}
		}else if (tipo_traslado.value.toUpperCase() == "S") {
			if (validaFechaHoy(anio_hasta.value,mes_hasta.value,dia_hasta.value,'sin') == false) {
				alert(disAlertFechaHoy2); return false;
			}
		}
		
		//Valido Fecha Hasta  no sea posterior a la Fecha Desde (Solo Round Trip)
		if (tipo_traslado.value.toUpperCase() == "R") {
			//Esta funcion la Toma del Archivo de java: "Fechas_" + "Idioma del Sitio"
			if (validaFechas(anio_desde.value,mes_desde.value,dia_desde.value,anio_hasta.value,mes_hasta.value,dia_hasta.value,'') == false) {  
				return false;
			}	
		}
		
		// Si es Llegada o Round
		if (tipo_traslado.value.toUpperCase() == "R" || tipo_traslado.value.toUpperCase() == "L")
		{
			//Valida la fecha de llegada.
			if (ValidaFechaTraslado(anio_desde,mes_desde,dia_desde) == false) {				
				alert(disAlertFechaMinima);	anio_desde.focus(); return false;			
			}			
			if (AirlineGo.value == "") {				
				alert(disAlertAirline1); AirlineGo.focus(); return false;			
			}
			if (FlightNumberGo.value == "") { 
				alert(disAlertFlight1); FlightNumberGo.focus(); return false;
			}
		}		
		// Si es Sálida o Round
		if (tipo_traslado.value.toUpperCase() == "R" || tipo_traslado.value.toUpperCase() == "S") {		
		    
			//Valida la fecha de salida.
			if (ValidaFechaTraslado(anio_hasta,mes_hasta,dia_hasta) == false) {				
				alert(disAlertFechaMinima);	anio_hasta.focus(); return false;			
			}
		
			if (AirlineReturn.value == "") {				
				alert(disAlertAirline2); AirlineReturn.focus(); return false;
			}
			if (FlightNumberReturn.value == "") {
				alert(disAlertFlight2); FlightNumberReturn.focus(); return false;
			}
		}		
	}
	return true;
}

function ValidaFechaTraslado(elAnio,elMes,elDia){
   //Guarda en un arreglo los meses para formar la fecha de hoy en formato gringo.
   var ArregloMeses=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")   

   //Hace un parse a la fecha de hoy.
   var laFechaDeHoy=new Date();
   var elAnioDeHoy=laFechaDeHoy.getYear()
   var elMesDeHoy=laFechaDeHoy.getMonth()
   var elDiaDeHoy=laFechaDeHoy.getDate()

   //Formatea las fechas de hoy y la que se esta validando en formato gringo para 
   //sacarle la diferencia de dias.
   var laFecha1=ArregloMeses[elMesDeHoy]+" "+elDiaDeHoy+", "+elAnioDeHoy
   var laFecha2=ArregloMeses[elMes.value-1]+" "+elDia.value+", "+elAnio.value

   var laDiferencia=(Math.round((Date.parse(laFecha2) - Date.parse(laFecha1))/(24*60*60*1000))*1)

   if (laDiferencia<2){return false;}
   if (laDiferencia>=2){return true;}
}

function DisplayLlegadaSalida(Tipo_Traslado)
{	
	/* Tipos de Traslados:
		R: Round Trip
		S: On Way Salida
		L: On Way Llegada
	*/
	switch (Tipo_Traslado)
	{
		case "R":												
				eval("document.getElementById('DivLlegada').style.display=''"); // Oculto Formulario de Entrada
				eval("document.getElementById('DivSalida').style.display=''");  // Oculto Formulario de Salida
				eval("document.getElementById('DivBoton').style.display=''"); // Muestro la Seccion del Boton
				break;
		case "L":
				eval("document.getElementById('DivLlegada').style.display=''"); // Muestro Formulario de Entrada				
				eval("document.getElementById('DivSalida').style.display='none'");  // Oculto Formulario de Salida
				eval("document.getElementById('DivBoton').style.display=''"); // Muestro la Seccion del Boton
				break;
		case "S":
				eval("document.getElementById('DivSalida').style.display=''");  // Muestro Formulario de Salida				
				eval("document.getElementById('DivLlegada').style.display='none'"); // Oculto Formulario de Entrada
				eval("document.getElementById('DivBoton').style.display=''"); // Muestro la Seccion del Boton
				break;		
		default:					
				eval("document.getElementById('DivLlegada').style.display='none'"); // Oculto Formulario de Entrada
				eval("document.getElementById('DivSalida').style.display='none'");  // Oculto Formulario de Salida
				eval("document.getElementById('DivBoton').style.display=''");  // Muestro la Seccion del Boton
				break;
	}
}


