var idioma = fdic.lang(null);
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; 
	}
}

function validateagree() {
	error = false;
	if (document.forma.iagree.status == false) { error = true; }
	if (error == true) { 
		alert(fdic.trad(disAlertAgree,idioma)); 	return false; 
	}else {
		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(fdic.trad(disAlertTrasfer,idioma)); traslado.focus(); return false;	
		}
		//Que haya indicado el hotel	
		if (hotel.value == "") {
			alert(fdic.trad(disAlertHotel,idioma)); hotel.focus(); return false;
		}		
		//Válida Adultos
		if (validatePax(num_adultos,1,999,fdic.trad(disAlertAdults,idioma),"I") == false ) {	
			num_adultos.focus(); return false;		
		}
		//Válida nińos
		if (validatePax(num_ninos,0,5,fdic.trad(disAlertKids,idioma),"I") == false ) {	
			num_ninos.focus();	return false;		
		}
		//Válida Tipo de Traslado Diferente de Select opcion
		if (tipo_traslado.value == "X" ) {	
			alert(fdic.trad(disAlertTipoTraslado,idioma)); 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(fdic.trad(disAlertFechaHoy1,idioma)); return false;
			}
		}else if (tipo_traslado.value.toUpperCase() == "S") {
			if (validaFechaHoy(anio_hasta.value,mes_hasta.value,dia_hasta.value,'sin') == false) {
				alert(fdic.trad(disAlertFechaHoy2,idioma)); return false;
			}
		}		
		//Valido Fecha Hasta  no sea posterior a la Fecha Desde (Solo Round Trip)
		if (tipo_traslado.value == "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 == "R" || tipo_traslado.value == "L") {
			//Valida la fecha de llegada 48 horas de anticipacion.
			if (ValidaFechaTraslado(anio_desde,mes_desde,dia_desde) == false) {				
				alert(fdic.trad(disAlertFechaMinima,idioma));	anio_desde.focus(); return false;			
			}
			if (AirlineGo.value == "") {
				alert(fdic.trad(disAlertAirline1,idioma)); AirlineGo.focus(); return false;			
			}
			if (FlightNumberGo.value == "") {
				alert(fdic.trad(disAlertFlight1,idioma)); FlightNumberGo.focus(); return false;
			}
		}		
		// Si es Sálida o Round
		if (tipo_traslado.value == "R" || tipo_traslado.value == "S") {
			//Valida la fecha de salida 48 horas de anticipacion.
			if (ValidaFechaTraslado(anio_hasta,mes_hasta,dia_hasta) == false) {				
				alert(fdic.trad(disAlertFechaMinima,idioma));	anio_hasta.focus(); return false;			
			}
			if (AirlineReturn.value == "") {
				alert(fdic.trad(disAlertAirline2,idioma)); AirlineReturn.focus(); return false;
			}
			if (FlightNumberReturn.value == "") {
				alert(fdic.trad(disAlertFlight2,idioma)); FlightNumberReturn.focus(); return false;
			}
		}		
	}
	return true;
}
//Funcion que valida que haya 48 horas para el traslado
function ValidaFechaTraslado(elAnio,elMes,elDia) {
   //Guarda en un arreglo los meses para formar la fecha de hoy en formato gringo.
   var ArregloMeses= fdic.meses(idioma);

   //Hace un parse a la fecha de hoy.
   var laFechaDeHoy=new Date();
   var elAnioDeHoy=laFechaDeHoy.getFullYear();   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;
	}
}


