
var arrayHabitaciones = new Array();
var arrayEdadesNinos = new Array();
var checksProductos="";

habitacion = new habitaciones(1,2,0,'');
arrayHabitaciones[0] = habitacion;

// INICIALIZACION DE LA VARIABLE DOM
var DOM = {
	isParentOf: function( parentElm, contextElm) {
		while(contextElm && (contextElm != parentElm))
			contextElm = contextElm.parentNode;
		return (contextElm == parentElm);
	},
	getParentOrSelf: function( contextElm, nodeName ) {
		nodeName = nodeName.toLowerCase();
		while(contextElm.nodeName.toLowerCase() != nodeName && contextElm.parentNode)
			contextElm = contextElm.parentNode;
		return contextElm;
	},
	addClass: function( elm, className ) {
		elm.className += ' '+className;
	},
	removeClass: function( elm, className) {
		var classMatch = new RegExp('\\b'+className+'\\b', 'g');
		if(classMatch.test(elm.className))
			elm.className = elm.className.replace(classMatch, ' ');
	}	
};
//

function habitaciones(numHab,numAdultos,numNinos,edades){
	this.numHab=numHab
	this.numAdultos=numAdultos
	this.numNinos=numNinos
	this.edades=edades
}

function muestraHabitaciones(){
	var formu=document.formulario;
	var textCapa="";
	var cuantasActual=arrayHabitaciones.length;
	if (cuantasActual<formu.hotelNumHabs.value){
		for(h=cuantasActual;h<formu.hotelNumHabs.value;h++){
			habitacion = new habitaciones(h+1,2,0,'');
			arrayHabitaciones[h] = habitacion;
		}
	} else {
		arrayHabitaciones.splice(formu.hotelNumHabs.value,cuantasActual-formu.hotelNumHabs.value);
		//pintaCombosEdades();
	}
	if (formu.hotelNumHabs.value>1){
		javascript:guardarAccionHab('muestraHabitaciones();');
	}else{		
		javascript:guardarAccionHab(null);
	}
	for( var i=0;i<arrayHabitaciones.length;i++){
		indice = i+1; 
		if( i==0) {
			textCapa += "<div class='dato4'>" +
				"<label for='adultos' class='etiqueta-4'>" +
				//+ obtenerTextoIdioma('CAPAADULTOHOT') +
				"Adulto"+
				"<select class='seleccionable-2' id='hotelNumAdulto" + indice + "' name='hotelNumAdulto" + indice + "'>" +
				"<option value='1'>1</option>" +
				"<option value='2'>2</option>" +
				"<option value='3'>3</option>" +
				"<option value='4'>4</option>" +
				"<option value='5'>5</option>" +
				"<option value='6'>6</option>" +
				"<option value='7'>7</option>" +
				"<option value='8'>8</option>" +
				"<option value='9'>9</option>" +
				"</select>" +
				"</label>" +
				"</div>";  
	
			textCapa += "<div class='dato4'>" +
				"<label for='adultos' class='etiqueta-4'>" +
				//+ obtenerTextoIdioma('CAPANINOSHOT') +
				"Niño"+
				"<select class='seleccionable-2' id='hotelNumNino" + indice + "' name='hotelNumNino" + indice + "'>" +
				"<option value='0'>0</option>" +
				"<option value='1'>1</option>" +
				"<option value='2'>2</option>" +
				"<option value='3'>3</option>" +
				"<option value='4'>4</option>" +
				"<option value='5'>5</option>" +
				"<option value='6'>6</option>" +
				"<option value='7'>7</option>" +
				"<option value='8'>8</option>" +
				"<option value='9'>9</option>" +
				"</select>" +
				"</label>" +
				"</div>" +
				"<div style='display: none;'><input type='text' name='hotelEdadesNinos" + indice + "' id='hotelEdadesNinos" + indice + "' value='2'/></div>";  
	
			textCapa += "<div class='dato4'>" +
				"<label for='adultos' class='etiqueta-4'>" +
				//+ obtenerTextoIdioma('CAPABEBESHOT') +
				"Bebe"+
				"<select class='seleccionable-2' id='hotelNumBebe" + indice + "' name='hotelNumBebe" + indice + "'>" +
				"<option value='0'>0</option>" +
				"<option value='1'>1</option>" +
				"<option value='2'>2</option>" +
				"<option value='3'>3</option>" +
				"<option value='4'>4</option>" +
				"<option value='5'>5</option>" +
				"<option value='6'>6</option>" +
				"<option value='7'>7</option>" +
				"<option value='8'>8</option>" +
				"<option value='9'>9</option>" +
				"</select>" +
				"</label>" +
				"</div>";  
		} else {
			textCapa += "<div class='dato4'>" +
				"<label for='adultos' class='etiqueta-4'>" +
				"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
				"<select class='seleccionable-2' id='hotelNumAdulto" + indice + "' name='hotelNumAdulto" + indice + "'>" +
				"<option value='1'>1</option>" +
				"<option value='2'>2</option>" +
				"<option value='3'>3</option>" +
				"<option value='4'>4</option>" +
				"<option value='5'>5</option>" +
				"<option value='6'>6</option>" +
				"<option value='7'>7</option>" +
				"<option value='8'>8</option>" +
				"<option value='9'>9</option>" +
				"</select>" +
				"</label>" +
				"</div>";  

			textCapa += "<div class='dato4'>" +
				"<label for='adultos' class='etiqueta-4'>" +
				"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
				"<select class='seleccionable-2' id='hotelNumNino" + indice + "' name='hotelNumNino" + indice + "'>" +
				"<option value='0'>0</option>" +
				"<option value='1'>1</option>" +
				"<option value='2'>2</option>" +
				"<option value='3'>3</option>" +
				"<option value='4'>4</option>" +
				"<option value='5'>5</option>" +
				"<option value='6'>6</option>" +
				"<option value='7'>7</option>" +
				"<option value='8'>8</option>" +
				"<option value='9'>9</option>" +
				"</select>" +
				"</label>" +
				"</div>" +
				"<div style='display: none;'><input type='text' name='hotelEdadesNinos" + indice + "' id='hotelEdadesNinos" + indice + "' value='2'/></div>"; 
		
			textCapa += "<div class='dato4'>" +
				"<label for='adultos' class='etiqueta-4'>" +
				"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
				"<select class='seleccionable-2' id='hotelNumBebe" + indice + "' name='hotelNumBebe" + indice + "'>" +
				"<option value='0'>0</option>" +
				"<option value='1'>1</option>" +
				"<option value='2'>2</option>" +
				"<option value='3'>3</option>" +
				"<option value='4'>4</option>" +
				"<option value='5'>5</option>" +
				"<option value='6'>6</option>" +
				"<option value='7'>7</option>" +
				"<option value='8'>8</option>" +
				"<option value='9'>9</option>" +
				"</select>" +
				"</label>" +
				"</div>";  
		}
	}
	escribe("capaHabitaciones",textCapa);
	
	if (numeroNinosBebes()){
		document.getElementById("capaHabita").style.paddingTop="0px";
	}
}

function chN(numHab,numNinos){
	var ind = numHab-1;	
	if (numNinos>0){
		guardarAccionEdades('chN('+numHab+','+numNinos+');');
		var formu=document.formulario;
		var ind = numHab-1;
		if(arrayHabitaciones[ind].numNinos<numNinos){
			arrayEdadesNinos = new Array();
			for (j=0;j<numNinos;j++){
				if (arrayHabitaciones[ind].edades){
					edad = arrayHabitaciones[ind].edades[j];
				}else{
					edad = new edadesNinos('');
				}
				arrayEdadesNinos[j] = edad;
			}
			arrayHabitaciones[ind].edades = arrayEdadesNinos;
		} else {
			arrayHabitaciones[ind].edades.splice(numNinos,arrayHabitaciones[ind].numNinos-numNinos);
		}
		arrayHabitaciones[ind].numNinos = numNinos;
		document.getElementById("capaHabita").style.paddingTop="22px";
	}else{
		guardarAccionEdades(null);
		arrayHabitaciones[ind].numNinos=numNinos;
		
		if (numeroNinosBebes()){
			document.getElementById("capaHabita").style.paddingTop="0px";
		}
	}		
	pintaCombosEdades();
}

function numeroNinosBebes(){
	var contNinosBebes = 0;
	
	for(i=0;i<arrayHabitaciones.length;i++){	
		if (arrayHabitaciones[i].numNinos!=0){
			contNinosBebes++;
		}
	}	
	
	if (contNinosBebes == 0){
		return true;
	}else{
		return false;
	}
}

function pintaCombosEdades(){
	//Vemos si hay algun niño
	var cont=1;
	var pintar=false;	
	for(i=0;i<arrayHabitaciones.length;i++){				
		if (arrayHabitaciones[i].numNinos && arrayHabitaciones[i].numNinos>0){			
			pintar=true;
			break;			
		}		
		cont++;
	}	
	if (pintar){
		var textCapa="";
		var ponTexto=false;
		textCapa+="<div class='limpiar'></div><div class='filabuscador'><div class='txtizdabox' style='margin-top:4px;font-weight:bold;'>"+ obtenerTextoIdioma('ALERNIÑOS') + "</div></div>";
		var contador=0;
		for(i=0;i<arrayHabitaciones.length;i++){
			if (arrayHabitaciones[i].numNinos!=0){
				ponTexto=true;
				textCapa+="<div class='limpiar' style='margin-top:5px;'></div><div class='filabuscador'><div class='txtizdabox' style='margin-right:0px;margin-top:12px;'>"+ obtenerTextoIdioma('TEXTHAB')+ " "+arrayHabitaciones[i].numHab+"</div></div>";
				for(k=0;k<arrayHabitaciones[i].numNinos;k++){
					textCapa+="<div class='filabuscador'><div class='txtsobrebox' style='margin-left:3px;'>"+ obtenerTextoIdioma('CAPANINOSHOT') + " "+(k+1)+"</div>";
					textCapa+="<select class='texto_formu' style='width:40px;' name='hotelEdadesNinos"+(contador+1)+"' onChange=\"javascript:chE('"+arrayHabitaciones[i].numHab+"','"+k+"',this.value);\">"+pintaEdadesNinos(arrayHabitaciones[i].edades[k])+"</select></div>";
					contador++;
				}
			}
		}
		if (!ponTexto) textCapa="";
		escribe("capaEdadesNinos",textCapa);
	}else{
	escribe("capaEdadesNinos","");	
	}
	//ajustaCapaFlex();
}

/**
 * Funcion que processa el dia de inicio del buscador
 * @param fecha
 * @return
 */
function selDiaEntrada(fecha){
	var formu=document.formulario;
	if (formu.vueloTipoProductoComercial != null && formu.vueloTipoProductoComercial.value == "VUE"){
		formu.vueloFechaIda.value=fecha;
		if(comparaFechasString(formu.vueloFechaIda.value,formu.vueloFechaVuelta.value)){
			var fechaNueva = incrementaDiasString(formu.vueloFechaIda.value,1);
			var diaNew = fechaNueva.getDate();
			var mesNew = fechaNueva.getMonth()+1;
			var anioNew = fechaNueva.getFullYear();
			if (diaNew<10) diaNew="0"+diaNew;
			if (mesNew<10) mesNew="0"+mesNew;
			var fechaNuevaStr = diaNew+"/"+mesNew+"/"+anioNew;
			formu.vueloFechaVuelta.value=fechaNuevaStr;
		} 		
	} else if(formu.hotelTipoProductoComercial != null && formu.hotelTipoProductoComercial.value == "HOT") {
		formu.hotelFechaIni.value=fecha;
		if(comparaFechasString(formu.hotelFechaIni.value,formu.hotelFechaFin.value)){
			var fechaNueva = incrementaDiasString(formu.hotelFechaIni.value,1);
			var diaNew = fechaNueva.getDate();
			var mesNew = fechaNueva.getMonth()+1;
			var anioNew = fechaNueva.getFullYear();
			if (diaNew<10) diaNew="0"+diaNew;
			if (mesNew<10) mesNew="0"+mesNew;
			var fechaNuevaStr = diaNew+"/"+mesNew+"/"+anioNew;
			formu.hotelFechaFin.value=fechaNuevaStr;
		}
	}
	cerrarCalendario();
}

/**
* Funcion que processa la fecha de fin del buscador
* @param fecha
* @return
*/
function selDiaSalida(fecha){
	var formu=document.formulario;
	if (formu.vueloTipoProductoComercial != null && formu.vueloTipoProductoComercial.value == "VUE"){
		formu.vueloFechaVuelta.value=fecha;
		cerrarCalendario();
	} else if(formu.hotelTipoProductoComercial != null && formu.hotelTipoProductoComercial.value == "HOT") {
		formu.hotelFechaFin.value=fecha;
		cerrarCalendario();
	}
}

//
// Inicio funciones para el calendario
//

function getAbsoluteElementPosition(element) {
	if (typeof element == "string")
		element = document.getElementById(element);
	if (!element) return { top:0,left:0 };
	var y = 0;
	var x = 0;
	while (element.offsetParent) {
		x += element.offsetLeft;
		y += element.offsetTop;
		element = element.offsetParent;
	}
	return {top:y,left:x};
}

function cerrarCapas() {
	cerrarCalendario();
}

function cerrarCalendario(){
	WCH.Discard("capaCalVac_a");
	document.getElementById("capaCalVac_a").style.display="none";
	//document.getElementById("capaOcultaEnlace2").style.display="none";
	document.getElementById("capaCalVac_a").innerHTML="";
	if (document.getElementById("capaCalVac_a")){
		WCH.Discard("capaCalVac_a");
		document.getElementById("capaCalVac_a").style.display="none";
		document.getElementById("capaCalVac_a").innerHTML="";
		//document.getElementById("capaOcultaEnlace4").style.display="none";
		//document.getElementById("capaOcultaEnlace3").style.display="none";
	}
	DWREngine.setVerb("POST");	
}

function forwardGetSincrono_deLandings(nombreCapa,paginaInclude) {	
	try{
		if (paginaInclude.indexOf('viajes_mp'==-1)){
			paginaInclude='/viajes_mp'+paginaInclude;
		}		
		new Ajax.Updater(nombreCapa,paginaInclude, { method: 'post',asynchronous: false,evalScripts:true });	
	} catch (exception){
		alertTextoIdioma('ALERCADSESION');
		WCH.Discard(nombreCapa);	
	}		
}

function abrirCalendario(login,idCombo,titulo,numCalendarios,fechaInicio,fechaSel,diasAnt,accion,idProductoFisico){
	DWREngine.setVerb("GET");	
	nombreCapaCalendario="capaCalVac_a";
	var pos = getAbsoluteElementPosition(idCombo);
	var izda=pos.left;
	var alto=pos.top;	
	if (idCombo==""){
		pos = getAbsoluteElementPosition("topDesglose");
		alto=176;
		izda=pos.left-260;
	}
	
	// calculo de la fecha de inicio por defecto
	if(fechaInicio=='') {
		 fechaHoy= new Date();
		 mes = fechaHoy.getMonth() + 1;
		 fechaInicio=fechaHoy.getDate()+"/"+ mes +"/"+fechaHoy.getFullYear();
	}
	var nombreCapa="capaCalVac_a";
	var numDias="";
	//var paginaInclude='/servlet/calendario?metodo=ajaxCalendario&login='+login+'&titulo='+titulo+'&accion='+accion+'&numCalendarios='+numCalendarios+'&fechaInicio='+fechaInicio+'&fechaSel='+fechaSel+'&diasAnt='+diasAnt+'&idProductoFisico='+idProductoFisico+'&pagina=landingHotel';
	//var paginaInclude='/SEO/landings/calendario.jsp?accion='+accion+'&titulo='+titulo+'&login='+login+'&fechaInicio='+fechaInicio;
	var paginaInclude='/landings/jsp/calendario.jsp?accion='+accion+'&titulo='+titulo+'&login='+login+'&fechaInicio='+fechaInicio;

	forwardGetSincrono_deLandings("capaCalVac_a",paginaInclude);

	document.getElementById(nombreCapa).style.top=alto+"px";
	document.getElementById(nombreCapa).style.left=izda+"px";
	document.getElementById(nombreCapa).style.display="block";
	WCH.Apply("capaCalVac_a");
}

function mesSiguiente(indCalendario,numCalendarios,ultimo,nombreCapa,totalCalendarios){
	/*
	if(ultimo == false){
		if((indCalendario < totalCalendarios-1)){
			if(numCalendarios==1 && (indCalendario < totalCalendarios-2)){
				//alert("condicion 1 mesSiguiente");
				document.getElementById("calendar"+nombreCapa+(indCalendario+1)).style.display="block";
				document.getElementById("flechaizda"+nombreCapa+(indCalendario+1)).className="atras";
				document.getElementById("flechadcha"+nombreCapa+(indCalendario+1)).className="avance";
				document.getElementById("calendar"+nombreCapa+(indCalendario+1)).style.marginLeft="0px";		
				document.getElementById("calendar"+nombreCapa+(indCalendario)).style.display="none";
				if (ultimo){
					document.getElementById("flechadcha"+nombreCapa+(indCalendario+1)).className="avance-off";
				} 
			} else {
				document.getElementById("calendar"+nombreCapa+(indCalendario)).style.display="none";
				document.getElementById("calendar"+nombreCapa+(indCalendario+1)).style.marginLeft="0px";
				document.getElementById("calendar"+nombreCapa+(indCalendario+1)).style.display="block";
				document.getElementById("calendar"+nombreCapa+(indCalendario+1)).style.marginLeft="5px";
				document.getElementById("flechaizda"+nombreCapa+(indCalendario+1)).className="atras";
				document.getElementById("flechadcha"+nombreCapa+(indCalendario+1)).style.display="block";
				document.getElementById("flechaizda"+nombreCapa+(indCalendario+1)).style.display="block";
				document.getElementById("flechadcha"+nombreCapa+(indCalendario+1)).style.display="none";
			}
		} 
	}
}*/
	if(indCalendario < totalCalendarios-1){
		
		if(numCalendarios==2){
			document.getElementById("calendar"+nombreCapa+(indCalendario-1)).style.display="none";
			document.getElementById("calendar"+nombreCapa+(indCalendario)).style.marginLeft="0px";
			document.getElementById("calendar"+nombreCapa+(indCalendario+1)).style.display="block";
			document.getElementById("calendar"+nombreCapa+(indCalendario+1)).style.marginLeft="5px";
			document.getElementById("flechaizda"+nombreCapa+(indCalendario+1)).style.display="none";
			document.getElementById("flechadcha"+nombreCapa+(indCalendario+1)).style.display="block";
			document.getElementById("flechaizda"+nombreCapa+(indCalendario)).style.display="block";
			document.getElementById("flechadcha"+nombreCapa+(indCalendario)).style.display="none";
			if (ultimo){
				document.getElementById("flechadcha"+nombreCapa+(indCalendario+1)).style.display="none";
			}
		}else if(numCalendarios==1){

			document.getElementById("calendar"+nombreCapa+(indCalendario+1)).style.display="block";
			document.getElementById("flechaizda"+nombreCapa+(indCalendario+1)).className="atras";
			document.getElementById("flechadcha"+nombreCapa+(indCalendario+1)).className="avance";
			document.getElementById("calendar"+nombreCapa+(indCalendario+1)).style.marginLeft="0px";		
			document.getElementById("calendar"+nombreCapa+(indCalendario)).style.display="none";
			if (indCalendario == totalCalendarios-2){
				document.getElementById("flechadcha"+nombreCapa+(indCalendario+1)).className="avance-off";
			}
			if (ultimo){
				document.getElementById("flechadcha"+nombreCapa+(indCalendario+1)).className="avance-off";
			}
		}
	}	
}

function mesAnterior(indCalendario,numCalendarios,nombreCapa){
	if(indCalendario !=0){
		if(numCalendarios==2){
			document.getElementById("calendar"+nombreCapa+(indCalendario-1)).style.display="block";
			document.getElementById("calendar"+nombreCapa+(indCalendario-1)).style.marginLeft="0px";
			document.getElementById("calendar"+nombreCapa+(indCalendario+1)).style.display="none";
			document.getElementById("calendar"+nombreCapa+(indCalendario)).style.marginLeft="5px";
			document.getElementById("flechaizda"+nombreCapa+(indCalendario+1)).className="atras";
			document.getElementById("flechadcha"+nombreCapa+(indCalendario+1)).className="avance-off";
			document.getElementById("flechaizda"+nombreCapa+(indCalendario)).className="atras-off";
			document.getElementById("flechadcha"+nombreCapa+(indCalendario)).className="avance";
		}else if(numCalendarios==1){
			document.getElementById("calendar"+nombreCapa+(indCalendario-1)).style.display="block";
			document.getElementById("calendar"+nombreCapa+(indCalendario-1)).style.marginLeft="0px";
			document.getElementById("calendar"+nombreCapa+(indCalendario)).style.display="none";
		}
	}
}

//
// Fin de funciones de calendario
//
function buscar(tipoProducto,login){
	if (tipoProducto != "vacacional"){
		if (document.getElementById("esBuscadorVuelo").value=="si"){
			if (!validarBuscadorVuelo()){
		   		return false;
			}
		  	checksProductos+="1";
		  	document.getElementById("checkVuelo").value="si";
			document.formulario.action = 'http://vuelos.halconviajes.com/viajes_mp/servlet/vuelos';
		}else{
			checksProductos+="0";
		}
	    if (document.getElementById("esBuscadorHotel").value=="si"){
		   if (!validarBuscadorHotel()){
		   		return false;
		   }
		   checksProductos+="1";
		   document.getElementById("checkHotel").value="si";
		   document.formulario.action = 'http://www.hoteles.halconviajes.com/viajes_mp/servlet/hoteles';
		}else{
			checksProductos+="0";
		}
		checksProductos+="0";
		if (document.getElementById("esBuscadorVuelo").value=="si"){
			checksProductos = "1000";
		}
		document.getElementById("checksProductos").value=checksProductos;
		document.formulario.metodo.value="doDisponibilidad";
		document.formulario.submit();
		//mostrarCargando(1,checksProductos);
	}else{
		if (!validarVacacional(4,9)){
	   		return;
		}
		document.getElementById("checksProductos").value="0001";
		//mostrarCargando(1,document.getElementById("checksProductos").value);
		document.formulario.metodo.value="doDisponibilidad";
		document.formulario.action = 'http://www.hoteles.halconviajes.com/viajes_mp/servlet/vacaciones?codTpr='+document.formDiccionario.codTpr.value+'&codTva='+document.formDiccionario.codTva.value+'&login='+document.formulario.login.value;
		document.formulario.submit();
	}
}

function validarBuscadorHotel(){
	var formu = document.formulario;
	if(document.getElementById("hotelFechaIni").value==""){
		//alert('<i18n:message editable="N" key="ALERFECINIHOT"/>');
		//cerrarCapas();
		abrirCalendario('NEWHALCON','hotelFechaIni','Fecha de Entrada','1','',document.formulario.hotelFechaIni.value,5,'selDiaEntrada', '');
		return false;
	}else if(document.getElementById("hotelFechaFin").value==""){
		//alert('<i18n:message editable="N" key="ALERFECFINHOT"/>');
		//cerrarCapas();
		abrirCalendario('NEWHALCON','hotelFechaFin','Fecha de Salida','1',document.formulario.hotelFechaIni.value,document.formulario.hotelFechaFin.value,1,'selDiaSalida','');
		return false;
	}
	
	var numHab = arrayHabitaciones.length;
	var numNinos;
	var numAdultos;
	var contador=0;
	var numMaxPax=5
	for(i=0;i<numHab;i++){
		if ((arrayHabitaciones[i].numAdultos*1+arrayHabitaciones[i].numNinos*1) > numMaxPax) {
			alert(''+numMaxPax+'.');
			eval("formu.hotelNumAdulto"+(i+1)+".focus();");
			return;
		}
		if(arrayHabitaciones[i].numNinos!=0){
			numNinos=arrayHabitaciones[i].numNinos;
			for(j=0;j<numNinos;j++){
				if (arrayHabitaciones[i].edades[j].edadNino=='' || arrayHabitaciones[i].edades[j]=='') {
					alert(arrayHabitaciones[i].edades[j].edadNin + ' ' + arrayHabitaciones[i].edades[j]);
					eval("formu.hotelEdadesNinos"+(contador+1)+".focus();");
					return;
				}
			contador++;
			}
		}
	}
	return true;
}

/**
 * Funcion que valida el buscador de vuelos. Si todo esta ok devuelve true si no, false
 * @return
 */
function validarBuscadorVuelo(){
	var formu = document.formulario;
	var numAdultos = parseInt(document.getElementById("vueloNumAdultos").value);
	var numNinos = parseInt(document.getElementById("vueloNumNinos").value);
	var numBebes = parseInt(document.getElementById("vueloNumBebes").value);
	
	if ( document.getElementById("descripcionOrigen").value == null || document.getElementById("descripcionOrigen").value == "" || 
			document.getElementById("descripcionDestino").value == null || document.getElementById("descripcionDestino").value == ""){
		alert("El campo destino y el campo origen deben estar llenos");
		return false;
	}
	if(document.getElementById("vueloFechaIda").value==""){
		abrirCalendario('NEWHALCON','vueloFechaIda','Fecha de Entrada','1','',document.formulario.vueloFechaIda.value,5,'selDiaEntrada', '');
		return false;
	}else if(document.getElementById("vueloFechaVuelta").value==""){
		document.getElementById("vueloFechaVuelta").focus();
		return false;
	}
	
	if (numAdultos < numBebes){
		alert('El número de bebés no puede superar al de adultos.');
		document.getElementById("vueloNumBebes").focus();
		return false;
	}	
	if (numAdultos + numNinos + numBebes >9){
		alert('El número maximo de pasajeros es 9.');
		document.getElementById("vueloNumAdultos").focus();
		return false;
	}
	if (numNinos/2 > numAdultos){
		alert('El número máximo por cada adulto es de 2 niños.');
		document.getElementById("vueloNumAdultos").focus();
		return false;
	}
	
	return true;
}

function preparaFlashCargando(paso,checksProductos){
	/*if(paso==null||paso=="")paso="2";
	if(checksProductos==null)checksProductos="null";
	if(checksProductos=="null"||checksProductos=="")checksProductos="0000";
	var cadena = "cargando_derecha";
	document.getElementById(cadena).style.display='block';*/
}

function masCalendarios(login,numCalendarios,titulo,accion,fechaInicio,indCalendario,numeroPeticionCalendario,nombreCapa){
	alert(numCalendarios);
	var ultimo=false;
	DWREngine.setVerb("GET");	
	//Si existe ya una capa con ese indice es porque ya lo hemos pedido anteriormente
	nombreCapaCalendario=nombreCapa;
	if (document.getElementById("calendar"+nombreCapa+(indCalendario+1))){
		var texto= document.getElementById("calendar"+nombreCapa+(indCalendario+1)).innerHTML;
		alert("texto.indexOf_mesSiguiente: " + texto.indexOf("mesSiguiente",0));
		alert("texto.indexOf_masCalendarios: " + texto.indexOf("masCalendarios",0));
		if(texto.indexOf("mesSiguiente",0) == -1 && texto.indexOf("masCalendarios",0) == -1){
			ultimo=true;
		}
		mesSiguiente(indCalendario,numCalendarios,ultimo,nombreCapa, numCalendarios);
		alert("condicion 1");
	}else {
		mesSiguiente(indCalendario,numCalendarios,true,nombreCapa, numCalendarios);
	}
}

function vaciarPagRes(){
	if(document.getElementById("pagRes") != null){
		document.getElementById("pagRes").value="No";
	}
}

