//js de hoteles
var sysdate		= new Date();
var anio 		= sysdate.getFullYear();
var mes     	= sysdate.getMonth();
var locCodeHolder;
var numpaxesAdults = 4;
var numpaxesChilds = 2;
//var Meses=arrMes[0];

function add_days(date1,days)
{
	var d1 = new Date(date1.substring(0,4),date1.substring(4,6)*1-1,date1.substring(6,8))
	/* incremento los dias */
	d1.setDate(d1.getDate() + days);
	/* saco en string */
	var month = (d1.getMonth()+1).toString()
	var day = d1.getDate().toString()	
	/* a?ado 0 si solo tiene un dijito */
	if(month.length==1){
	month = "0"+month
	}
	if(day.length==1){
	day = "0"+day
	}
	return d1.getFullYear().toString()+month+day
}

function getDayStringDate(sdate){

	var d = sdate.substring(6,8)
	if(d.length==1){
		return "0"+d
	}
	else{
		return d
	}
}
function getYearStringDate(sdate){
	return sdate.substring(0,4)
}

function getMonthStringDate(sdate){
	return sdate.substring(4,6)
}
function initDay(){
	
	var ldate = '20060130';
	var iday = add_days(ldate,3);
	
	hotel_search.fe_dia.value	= getDayStringDate(iday);   	
   	hotel_search.fe_mesanyo.value = getYearStringDate(iday)+getMonthStringDate(iday);
   	
   	var jday = add_days(ldate,4);   	
   	
 	hotel_search.fs_dia.value	= getDayStringDate(jday);   	
   	hotel_search.fs_mesanyo.value = getYearStringDate(jday)+getMonthStringDate(jday);

   	hotel_search.paxAdt.value  = "2";
   	hotel_search.paxChd.value	= "0";
}

/*
function goSubmitHoteles(dat)
{
	 var str = "";
	 // Quito los acentos
	 hotel_search.arrCity.value = QuitarAcentos(hotel_search.arrCity.value);
	 var msg="";
	 //groupval(str, nom, islg, isln, isnm)
	 msg = doconcat(msg,groupval(hotel_search.arrCity.value,'Ciudad',1,1,0)); 
	 msg = doconcat(msg,groupval(hotel_search.fe_dia.options[hotel_search.fe_dia.selectedIndex].value,'D?a de entrada',0,1,1));
	 msg = doconcat(msg,groupval(hotel_search.fe_mesanyo.options[hotel_search.fe_mesanyo.selectedIndex].value,'Mes de entrada',0,1,1));
	 msg = doconcat(msg,groupval(hotel_search.fs_dia.options[hotel_search.fe_dia.selectedIndex].value,'D?a de salida',0,1,1));
	 msg = doconcat(msg,groupval(hotel_search.fs_mesanyo.options[hotel_search.fe_mesanyo.selectedIndex].value,'Mes de salida',0,1,1));
	 var fechadep = hotel_search.fe_mesanyo.options[hotel_search.fe_mesanyo.selectedIndex].value + "" + hotel_search.fe_dia.options[hotel_search.fe_dia.selectedIndex].value;
	 var fecharet = hotel_search.fs_mesanyo.options[hotel_search.fs_mesanyo.selectedIndex].value + "" + hotel_search.fs_dia.options[hotel_search.fs_dia.selectedIndex].value;
	 if ((msg == "") && fecharet < fechadep)
	 {
	      msg = doconcat(msg,"La fecha de salida del hotel tiene que ser mayor que la de entrada \n");
	 }
     //me fijo que la fecha de salida sea mayor a 2 dias
      // SACA LA HORA DEL SERVIDOR
     var now 	= new Date();
     now.setTime(dat);
     
     now.setDate(now.getDate()+1);
     var strnow = now.getFullYear()+""+addcero(now.getMonth()+1)+""+addcero(now.getDate());
     if ((msg == "") && (fechadep < strnow))
     {
      	{msg = doconcat(msg,"Para comprar con menos de 24hs de antelacion por favor contacte con nuestro Servicio de atenci?n al cliente.\n");}
     }
     var nAdt = 1 * hotel_search.paxAdt.options[hotel_search.paxAdt.selectedIndex].value;

     var nChd = 1 * hotel_search.paxChd.options[hotel_search.paxChd.selectedIndex].value;
     
     if (nChd > nAdt)msg = doconcat(msg,"El n?mero ni?os no puede superar al de adultos \n");

     if (nAdt > 3)msg = doconcat(msg,"El n?mero total de ad?ltos no puede ser mayor a tres por habitaci?n. \n");
     
     // validar la edad de los ni?os
     for (i = 1; i <= nChd; i++)
     {
     	var stringField = "hotel_search.child" + i;
     	var currentTextBox = eval(stringField);
     	if (currentTextBox.value == "")
     	{
     		msg = doconcat(msg,groupval(currentTextBox.value,'Ni?o n?mero ' + i ,0,1,1));
     	}
     }

     if (msg != '')
     {	
   		alert(msg);
     }
     else
     {
		 hotel_search.depDate.value = fechadep;
		 hotel_search.retDate.value = fecharet;
		 hotel_search.submit();
	     //alert("LLEGOOO");
     }
}
*/

//para la nueva home.
//cuando todos los servicios paises esten con lo nuevo desaparecera el otro js
function goSubmitHoteles2007(dat)
{
	 var str = "";
	 // Quito los acentos
	 //hotel_search.arrCity.value = QuitarAcentos(hotel_search.arrCity.value);
	 var msg="";
	 //groupval(str, nom, islg, isln, isnm)
	 msg = doconcat(msg,groupval(hotel_search.arrCity.value,'Ciudad',1,1,0)); 
	 msg = doconcat(msg,groupval(hotel_search.fe_dia.value,'D?a de entrada',0,1,1));
	 msg = doconcat(msg,groupval(hotel_search.fe_mesanyo.value,'Mes de entrada',0,1,1));
	 msg = doconcat(msg,groupval(hotel_search.fs_dia.value,'D?a de salida',0,1,1));
	 msg = doconcat(msg,groupval(hotel_search.fs_mesanyo.value,'Mes de salida',0,1,1));
	 var fechadep = hotel_search.fe_mesanyo.value + "" + hotel_search.fe_dia.value;
	 var fecharet = hotel_search.fs_mesanyo.value + "" + hotel_search.fs_dia.value;
	 if ((msg == "") && fecharet < fechadep)
	 {
	      msg = doconcat(msg,"La fecha de salida del hotel tiene que ser mayor que la de entrada \n");
	 }
     //me fijo que la fecha de salida sea mayor a 2 dias
      // SACA LA HORA DEL SERVIDOR
     var now 	= new Date();
     now.setTime(dat);
     
     now.setDate(now.getDate()+1);
     var strnow = now.getFullYear()+""+addcero(now.getMonth()+1)+""+addcero(now.getDate());
     if(hotel_search.paxHab!=null)
     {
     
     	var personas = hotel_search.paxHab.options[hotel_search.paxHab.selectedIndex].value;
     	var nAdt = 0;
     	var nChd = 0;
     
     	if (personas == '1A0N')
     	{
     		nAdt = 1;
     		nChd = 0;
     	}
     	if (personas == '2A0N')
     	{
     		nAdt = 2;
     		nChd = 0;
     	}
     	if (personas == '1A1N') // Un adulto y un ni?o se trata como dos adultos !!!!
     	{
     		nAdt = 2;
     		nChd = 0;
     	}
     	if (personas == '3A0N')
     	{
     		nAdt = 3;
     		nChd = 0;
     	}
     	if (personas == '4A0N')
     	{
     		nAdt = 4;
     		nChd = 0;
     	}
     	if (personas == '2A1N')
     	{
     		nAdt = 2;
     		nChd = 1;
     	}
     	if (personas == '2A2N')
     	{
     		nAdt = 2;
     		nChd = 2;
     	}
     	if (personas == '3A1N')
     	{
     		nAdt = 3;
     		nChd = 1;
     	}
     	if (personas == '5A0N')
     	{
     		nAdt = 5;
     		nChd = 0;
     	}
     	if (personas == '4A1N')
     	{
     		nAdt = 4;
     		nChd = 1;
     	}
     	if (personas == '3A2N')
     	{
     		nAdt = 3;
     		nChd = 2;
     	}
     	if (personas == '2A3N')
     	{
     		nAdt = 2;
     		nChd = 3;
     	}
     	if (personas == '6A0N')
     	{
     		nAdt = 6;
     		nChd = 0;
     	}
     	if (personas == '5A1N')
     	{
     		nAdt = 5;
     		nChd = 1;
     	}
     	if (personas == '4A2N')
     	{
     		nAdt = 4;
     		nChd = 2;
     	}  
     	if (personas == '3A3N')
     	{
     		nAdt = 3;
     		nChd = 3;
     	}   
		
		hotel_search.paxAdt.value = nAdt;	
	 	hotel_search.paxChd.value = nChd;	
        
     	if (nChd > nAdt)
     	{
     		msg = doconcat(msg,"El n?mero ni?os no puede superar al de adultos \n");     	
     	}
     	if (nAdt > 5)
     	{
     		msg = doconcat(msg,"El numero total de adultos no puede ser mayor a tres por habitacion. \n");     	
     	}
     
     	for (i = 1; i <= nChd; i++)
     	{
     		var stringField = "hotel_search.child" + i;
     		var currentTextBox = eval(stringField);
     		if (currentTextBox.value == "")
     		{
     			msg = doconcat(msg,groupval(currentTextBox.value,'Ni?o n?mero ' + i ,0,1,1));
     		}
     	}
     }
     if (msg != '')
     {
   		alert(msg);
     }
     else
     {  
	     // Cambio el formato de las fechas a dd/MM/yyyy
		 hotel_search.depDate.value = fechadep.substring(6)+ "/" + fechadep.substring(4,6) + "/" + fechadep.substring(0,4);
		 hotel_search.retDate.value = fecharet.substring(6)+ "/" + fecharet.substring(4,6) + "/" + fecharet.substring(0,4);
		 hotel_search.submit();
     }
}

function addcero(str)
{
	var str2 = "0"+str;
	return str2.substring(str2.length-2);
}

function triptype()
{
	if(hotel_search.rrt.checked)
	{
		hotel_search.fs_dia.disabled 		= false;
        hotel_search.fs_mesanyo.disabled 	= false;
        hotel_search.retTime.disabled 	= false;
	}
	if(hotel_search.row.checked)
	{
		hotel_search.fs_dia.disabled 		= true;
        hotel_search.fs_mesanyo.disabled 	= true;
        hotel_search.retTime.disabled 	= true;
	}
}

function showDiv(divName)
{	
	/* get space */
	var getSpace = "document.getElementById(\'" + divName + "\').style.position='relative'";
	var getDisplay = "document.getElementById(\'" + divName + "\').style.display='inline'";
	//alert(getSpace);
	eval(getSpace);
	eval(getDisplay);	
}

function hiddenDiv(divName)
{
	/* hidden code */
	document.getElementById(divName).style.display="none";
	/* remove space */
	var removeSpaceCode = "document.getElementById(\'" + divName + "\').style.position='absolute'";
	var removeDisplay = "document.getElementById(\'" + divName + "\').style.display='none'";
	//alert(removeSpaceCode);
	eval(removeSpaceCode);
	eval(removeDisplay);
}

function hiddenAllChilds()
{
	/* hidden */
	for (i = 1; i <= 10; i++)
	{
		hiddenDiv(("childAge" + i));
	}
}

function showChilds()
{
	/* hidden all childs */
	hiddenAllChilds();

	/* show current childs */
	var childs = hotel_search.paxChd.value;
	var rooms = hotel_search.numRooms.value;
	var childToShow = (childs*1) * (rooms*1);
	for (i = 1; i <= childToShow; i++)
	{
		showDiv(("childAge" + i))
	}
}

function buildSelect(x) {
	//HotelSearchForm.dias_en_sa.options.length = 0; 
	if(x>14){
		for(var i = 0; i<x; i++){
			if(i+1==x){
				hotel_search.dias_en_sa.options[i]= new Option(i+1,i,true,true)
			}
			else{
				hotel_search.dias_en_sa.options[i]= new Option(i+1,i)
			}
		}
	}
	else{
		for(var i = 0; i<14; i++){
			if(i+1==x){
				hotel_search.dias_en_sa.options[i]= new Option(i+1,i,true,true)
			}
			else{
				hotel_search.dias_en_sa.options[i]= new Option(i+1,i)
			}
		}
	
	}
	
	// Generamos los combos de d?as seg?n el mes
	
	// Se debe guardar la selecci?n del d?a que hab?a hecho el usuario para luego volverla
	// a poner pues si no se hace se pierde
	
	var diaIdaSeleccionado=hotel_search.fe_dia.value;
	var diaVueltaSeleccionado = hotel_search.fs_dia.value;
	
	generarOpcionesMesIda();
	generarOpcionesMesVuelta();	
	
	hotel_search.fe_dia.value=diaIdaSeleccionado;
	hotel_search.fs_dia.value=diaVueltaSeleccionado;	
	
	
	return;
}
	
function generarOpcionesMesIda()
{
	// La parte siguiente es para cambiar los combos de los meses seg?n tengan 30 o 31 d?as	
	mesEntrada = hotel_search.fe_mesanyo.value.substr(4,6);

	hotel_search.fe_dia.options.length = 0;
	
	if (mesEntrada == '04' || mesEntrada == '06' ||mesEntrada == '09' ||mesEntrada == '11')
	{
			
		for(var i = 0; i<30; i++)
		{
			hotel_search.fe_dia.options[i]= new Option (decode(i),decode(i));
		}
	}
	else if (mesEntrada == '02')
	{
		
		for(var i = 0; i<29; i++)
		{
			hotel_search.fe_dia.options[i]= new Option (decode(i),decode(i));
			
		}
	}
	else
	{		
		for(var i = 0; i<31; i++)
		{
			
			hotel_search.fe_dia.options[i]= new Option (decode(i),decode(i));
		}
	}	
}

function generarOpcionesMesVuelta()
{
	
	// La parte siguiente es para cambiar los combos de los meses seg?n tengan 30 o 31 d?as
	
	mesSalida = hotel_search.fs_mesanyo.value.substr(4,6);
	
	
	hotel_search.fs_dia.options.length = 0;
	
	if (mesSalida == '04' || mesSalida == '06' ||mesSalida == '09' ||mesSalida == '11')
	{	
		
		for(var i = 0; i<30; i++)
		{
			hotel_search.fs_dia.options[i]= new Option (decode(i),decode(i));
		}
	}
	else if (mesSalida == '02')
	{
			
		for(var i = 0; i<29; i++)
		{
			hotel_search.fs_dia.options[i]= new Option (decode(i),decode(i));
			
		}
	}
	else
	{	
		
		for(var i = 0; i<31; i++)
		{
			hotel_search.fs_dia.options[i]= new Option (decode(i),decode(i));
		}
	}	
}

function calculatedays(date,count){

	buildSelect(count+1)	
	var jday = add_days(date,count+1);   	
   	
 	hotel_search.fs_dia.value	= getDayStringDate(jday);   	
   	hotel_search.fs_mesanyo.value = getYearStringDate(jday)+getMonthStringDate(jday);
   	
   	mesSalida = hotel_search.fs_mesanyo.value.substr(4,6);
   	buildSelect(count+1); ////////////////////////// Creo que con esta llamada aqu? se actualiza bien la fecha 	
}

function days_between(date1, date2) {

	var d1 = StringDatetoDate(date1)
	var d2 = StringDatetoDate(date2)
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = d1.getTime()
    var date2_ms = d2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = date1_ms - date2_ms
    
    // Convert back to days and return
   return Math.round(difference_ms/ONE_DAY)

}

function StringDatetoDate(date){
	var d = new Date(date.substring(0,4),date.substring(4,6),date.substring(6,8))
	return d
}


function validarnino(x){
	if(isNumber(x.value)){
		var edad = x.value
		if(edad<0 || edad>12){
			alert("La edad de un ni?o debe estar comprendida entre 0 y 12 a?os")
			x.focus()
		}
	}
	else{
		alert("introduzca una edad valida")
		x.focus()
	}
}

function isNumber(x){
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
  	return objRegExp.test(x);
}

function DayOfWeek(){
}


function calculatedaysIE(date,count){

	//buildSelectIE(count+1)	
	var jday = add_days(date,count+1);   	
   	
 	hotel_search.fs_dia.value	= getDayStringDate(jday);   	
   	hotel_search.fs_mesanyo.value = getYearStringDate(jday)+getMonthStringDate(jday);
   	
   	   	
   	var dia= hotel_search.fs_dia.value;
	var temp = hotel_search.fs_mesanyo.value;
	var mes=temp.substring(4,6);											 
	var anho=temp.substring(0,4);
															  
	var anhomes=anho.concat(mes);
	hotel_search.fechaRetorno.value= dia.concat("/",mes,"/",anho);   	
   	
   	
}

function buildSelectIE() 
{
	var temp1 = hotel_search.fechaSalida.value;
	var dia1 = temp1.substring(0,2)
	var mes1 =  temp1.substring(3,5);
	var anho1 = temp1.substring(6,10);
	
	var temp2 = hotel_search.fechaRetorno.value;
	var dia2 = temp2.substring(0,2)
	var mes2 =  temp2.substring(3,5);
	var anho2 = temp2.substring(6,10);
	
	
	
	var fecha1 = new Date(anho1,mes1,dia1);
	var fecha2 = new Date(anho2,mes2,dia2);
	
	var diferenciaDias = fecha2 - fecha1;
	var diferenciaDias = Math.round(diferenciaDias/1000/60/60/24);	
	
	if(diferenciaDias>14)
	{
		for(var i = 0; i<diferenciaDias; i++)
		{
			if(i+1==diferenciaDias)
			{
				hotel_search.dias_en_sa.options[i]= new Option(i+1,i,true,true)
			}
			else
			{
				hotel_search.dias_en_sa.options[i]= new Option(i+1,i)
			}
		}
	}
	else
	{
		for(var i = 0; i<14; i++)
		{
			if(i+1==diferenciaDias)
			{
				hotel_search.dias_en_sa.options[i]= new Option(i+1,i,true,true)
			}
			else
			{
				hotel_search.dias_en_sa.options[i]= new Option(i+1,i)
			}
		}
	}
	return;
}


function edadNinhos()
{
	hotel_search.child1.value = '';
	hotel_search.child2.value = '';
	hotel_search.child3.value = '';
	hotel_search.child4.value = '';
	hotel_search.child5.value = '';
	hotel_search.child6.value = '';
	hotel_search.child7.value = '';
	hotel_search.child8.value = '';
	hotel_search.child9.value = '';
	hotel_search.child10.value = '';
	document.getElementById("edades").innerHTML = '';
	//segun los ni?os que haya pintamos tantos div como sea necesario
	var numHabitaciones = hotel_search.numRooms.value;
	var numNinhos = hotel_search.paxHab.value.substring(2,3);	
	if(numNinhos!=0)
	{			
		
		document.getElementById("rellenarEdades").style.visibility = 'visible';
		document.getElementById("rellenarEdades").style.display = 'block';
		// Primero mostramos u ocultamos los divs de las habitaciones
		
		if (numHabitaciones =='1')
        {
            document.getElementById('divHabitacion1').style.display = 'inline';
            document.getElementById('divHabitacion2').style.display = 'none';
            document.getElementById('divHabitacion3').style.display = 'none';
            document.getElementById('divHabitacion4').style.display = 'none';
            document.getElementById('divHabitacion5').style.display = 'none';
        }
        if (numHabitaciones =='2')
        {
            document.getElementById('divHabitacion1').style.display = 'inline';
            document.getElementById('divHabitacion2').style.display = 'inline';
            document.getElementById('divHabitacion3').style.display = 'none';
            document.getElementById('divHabitacion4').style.display = 'none';
            document.getElementById('divHabitacion5').style.display = 'none';
        }
        if (numHabitaciones =='3')
        {
            document.getElementById('divHabitacion1').style.display = 'inline';
            document.getElementById('divHabitacion2').style.display = 'inline';
            document.getElementById('divHabitacion3').style.display = 'inline';
            document.getElementById('divHabitacion4').style.display = 'none';
            document.getElementById('divHabitacion5').style.display = 'none';
        }
        if (numHabitaciones =='4')
        {
            document.getElementById('divHabitacion1').style.display = 'inline';
            document.getElementById('divHabitacion2').style.display = 'inline';
            document.getElementById('divHabitacion3').style.display = 'inline';
            document.getElementById('divHabitacion4').style.display = 'inline';
            document.getElementById('divHabitacion5').style.display = 'none';
        }
        if (numHabitaciones =='5')
        {
            document.getElementById('divHabitacion1').style.display = 'inline';
            document.getElementById('divHabitacion2').style.display = 'inline';
            document.getElementById('divHabitacion3').style.display = 'inline';
            document.getElementById('divHabitacion4').style.display = 'inline';
            document.getElementById('divHabitacion5').style.display = 'inline';
        }
        
        // Ahora, según sean 0 hijos, 1 hijo o 2 hijos mostramos u ocultamos los campos para la edad, se hace todo a la vez, aunque habrá
        // veces que haya algunos campos que se muestren pero el div correspondiente a esa habitación no se muestre.
        
        if (numNinhos == '0') // Todos los campos ocultos
        {
            document.getElementById('ninho1').style.display = 'none';
            document.getElementById('ninho2').style.display = 'none';
            document.getElementById('ninho3').style.display = 'none';
            document.getElementById('ninho4').style.display = 'none';
            document.getElementById('ninho5').style.display = 'none';
            document.getElementById('ninho6').style.display = 'none';
            document.getElementById('ninho7').style.display = 'none';
            document.getElementById('ninho8').style.display = 'none';
            document.getElementById('ninho9').style.display = 'none';
            document.getElementById('ninho10').style.display = 'none';
        }
        if (numNinhos == '1') // Mostramos solo la edad del primer hijo
        {
            document.getElementById('ninho1').style.display = 'inline';
            document.getElementById('ninho2').style.display = 'none';
            document.getElementById('ninho3').style.display = 'inline';
            document.getElementById('ninho4').style.display = 'none';
            document.getElementById('ninho5').style.display = 'inline';
            document.getElementById('ninho6').style.display = 'none';
            document.getElementById('ninho7').style.display = 'inline';
            document.getElementById('ninho8').style.display = 'none';
            document.getElementById('ninho9').style.display = 'inline';
            document.getElementById('ninho10').style.display = 'none';
        }
        if (numNinhos == '2') // Mostramos la edad de los dos hijos
        {
            document.getElementById('ninho1').style.display = 'inline';
            document.getElementById('ninho2').style.display = 'inline';
            document.getElementById('ninho3').style.display = 'inline';
            document.getElementById('ninho4').style.display = 'inline';
            document.getElementById('ninho5').style.display = 'inline';
            document.getElementById('ninho6').style.display = 'inline';
            document.getElementById('ninho7').style.display = 'inline';
            document.getElementById('ninho8').style.display = 'inline';
            document.getElementById('ninho9').style.display = 'inline';
            document.getElementById('ninho10').style.display = 'inline';
        }
	}
	else
	{
		document.getElementById("rellenarEdades").style.visibility = 'hidden';
		document.getElementById("rellenarEdades").style.display = 'none';
	}
}
function edadNinhos2()
{
	hotel_search.child1.value = '';
	hotel_search.child2.value = '';
	hotel_search.child3.value = '';
	hotel_search.child4.value = '';
	hotel_search.child5.value = '';
	hotel_search.child6.value = '';
	hotel_search.child7.value = '';
	hotel_search.child8.value = '';
	hotel_search.child9.value = '';
	hotel_search.child10.value = '';
	document.getElementById("edades").innerHTML = '';
	//segun los ni?os que haya pintamos tantos div como sea necesario
	var numHabitaciones = hotel_search.numRooms.value;
	var numNinhos = hotel_search.paxChd.value;
	if(numNinhos!=0)
	{			
		
		document.getElementById("rellenarEdades").style.visibility = 'visible';
		document.getElementById("rellenarEdades").style.display = 'block';
		// Primero mostramos u ocultamos los divs de las habitaciones
		
		if (numHabitaciones =='1')
        {
            document.getElementById('divHabitacion1').style.display = 'inline';
            document.getElementById('divHabitacion2').style.display = 'none';
            document.getElementById('divHabitacion3').style.display = 'none';
            document.getElementById('divHabitacion4').style.display = 'none';
            document.getElementById('divHabitacion5').style.display = 'none';
        }
        if (numHabitaciones =='2')
        {
            document.getElementById('divHabitacion1').style.display = 'inline';
            document.getElementById('divHabitacion2').style.display = 'inline';
            document.getElementById('divHabitacion3').style.display = 'none';
            document.getElementById('divHabitacion4').style.display = 'none';
            document.getElementById('divHabitacion5').style.display = 'none';
        }
        if (numHabitaciones =='3')
        {
            document.getElementById('divHabitacion1').style.display = 'inline';
            document.getElementById('divHabitacion2').style.display = 'inline';
            document.getElementById('divHabitacion3').style.display = 'inline';
            document.getElementById('divHabitacion4').style.display = 'none';
            document.getElementById('divHabitacion5').style.display = 'none';
        }
        if (numHabitaciones =='4')
        {
            document.getElementById('divHabitacion1').style.display = 'inline';
            document.getElementById('divHabitacion2').style.display = 'inline';
            document.getElementById('divHabitacion3').style.display = 'inline';
            document.getElementById('divHabitacion4').style.display = 'inline';
            document.getElementById('divHabitacion5').style.display = 'none';
        }
        if (numHabitaciones =='5')
        {
            document.getElementById('divHabitacion1').style.display = 'inline';
            document.getElementById('divHabitacion2').style.display = 'inline';
            document.getElementById('divHabitacion3').style.display = 'inline';
            document.getElementById('divHabitacion4').style.display = 'inline';
            document.getElementById('divHabitacion5').style.display = 'inline';
        }
        
        // Ahora, según sean 0 hijos, 1 hijo o 2 hijos mostramos u ocultamos los campos para la edad, se hace todo a la vez, aunque habrá
        // veces que haya algunos campos que se muestren pero el div correspondiente a esa habitación no se muestre.
        
        if (numNinhos == '0') // Todos los campos ocultos
        {
            document.getElementById('ninho1').style.display = 'none';
            document.getElementById('ninho2').style.display = 'none';
            document.getElementById('ninho3').style.display = 'none';
            document.getElementById('ninho4').style.display = 'none';
            document.getElementById('ninho5').style.display = 'none';
            document.getElementById('ninho6').style.display = 'none';
            document.getElementById('ninho7').style.display = 'none';
            document.getElementById('ninho8').style.display = 'none';
            document.getElementById('ninho9').style.display = 'none';
            document.getElementById('ninho10').style.display = 'none';
        }
        if (numNinhos == '1') // Mostramos solo la edad del primer hijo
        {
            document.getElementById('ninho1').style.display = 'inline';
            document.getElementById('ninho2').style.display = 'none';
            document.getElementById('ninho3').style.display = 'inline';
            document.getElementById('ninho4').style.display = 'none';
            document.getElementById('ninho5').style.display = 'inline';
            document.getElementById('ninho6').style.display = 'none';
            document.getElementById('ninho7').style.display = 'inline';
            document.getElementById('ninho8').style.display = 'none';
            document.getElementById('ninho9').style.display = 'inline';
            document.getElementById('ninho10').style.display = 'none';
        }
        if (numNinhos == '2') // Mostramos la edad de los dos hijos
        {
            document.getElementById('ninho1').style.display = 'inline';
            document.getElementById('ninho2').style.display = 'inline';
            document.getElementById('ninho3').style.display = 'inline';
            document.getElementById('ninho4').style.display = 'inline';
            document.getElementById('ninho5').style.display = 'inline';
            document.getElementById('ninho6').style.display = 'inline';
            document.getElementById('ninho7').style.display = 'inline';
            document.getElementById('ninho8').style.display = 'inline';
            document.getElementById('ninho9').style.display = 'inline';
            document.getElementById('ninho10').style.display = 'inline';
        }
	}
	else
	{
		document.getElementById("rellenarEdades").style.visibility = 'hidden';
		document.getElementById("rellenarEdades").style.display = 'none';
	}
}


function comprobarEdadesNinos()
{	
	var msg = '';
	var edades = 'Edades: '
	var nChd = hotel_search.paxHab.value.substring(2,3);
	var nRooms = hotel_search.numRooms.value;	
	//por cada habitacion validamos los ni?os
	var aux = 1;
	for(r=1;r<=nRooms;r++)
	{	
		edades+=' (';
		for (i = 1; i <= nChd; i++)
		{
			var stringField = eval("document.hotel_search.child" + aux);  
			var currentTextBox = eval(stringField);          		
 			if (esEdadValida(currentTextBox.value) == 0)
 			{
 				msg = doconcat(msg,groupval(currentTextBox.value,'Ni?o n?mero ' + i+' de habitacion '+r ,0,1,1));
 			} 
 			else
 			{
 				edades+=' '+currentTextBox.value+' -';
 			}	
			if(nChd==1){aux+=2;}
			else {aux++;}
		}	
		edades=edades.substring(0,edades.length-1)+' ) ';
	}		
     if(msg!='')
     {
     	alert(msg);
     }
     else
     {
     	document.getElementById("rellenarEdades").style.visibility = 'hidden';
		document.getElementById("rellenarEdades").style.display = 'none';
		//pintamos la capa de las edades
		var capaPintarEdades = document.getElementById("edades");
		capaPintarEdades.style.visibility = 'visible';
		capaPintarEdades.style.display = 'block';		
		capaPintarEdades.innerHTML = edades.substring(0,edades.length-1);
     }
}
function comprobarEdadesNinos2()
{	
	var msg = '';
	var edades = 'Edades: '
	var nChd = hotel_search.paxChd.value;
	var nRooms = hotel_search.numRooms.value;	
	//por cada habitacion validamos los ni?os
	var aux = 1;
	for(r=1;r<=nRooms;r++)
	{	
		edades+=' (';
		for (i = 1; i <= nChd; i++)
		{
			var stringField = eval("document.hotel_search.child" + aux);  
			var currentTextBox = eval(stringField);          		
 			if (esEdadValida(currentTextBox.value) == 0)
 			{
 				msg = doconcat(msg,groupval(currentTextBox.value,'Ni?o n?mero ' + i+' de habitacion '+r ,0,1,1));
 			} 
 			else
 			{
 				edades+=' '+currentTextBox.value+' -';
 			}	
			if(nChd==1){aux+=2;}
			else {aux++;}
		}	
		edades=edades.substring(0,edades.length-1)+' ) ';
	}		
     if(msg!='')
     {
     	alert(msg);
     }
     else
     {
     	document.getElementById("rellenarEdades").style.visibility = 'hidden';
		document.getElementById("rellenarEdades").style.display = 'none';
		//pintamos la capa de las edades
		var capaPintarEdades = document.getElementById("edades");
		capaPintarEdades.style.visibility = 'visible';
		capaPintarEdades.style.display = 'block';		
		capaPintarEdades.innerHTML = edades.substring(0,edades.length-1);
     }
}
/**
* Se comprueba que no es nula, no es vac?a y que es num?rica
* Parametros: edad: edad que se le pasa
*
*/
function esEdadValida (edad)
{
    var valorDevuelto = 1;
    if (edad == null)
    {
    	valorDevuelto = 0;
    }
    if (edad == '')
    {
        valorDevuelto = 0;
    }
    if (edad == ' ')
    {
        valorDevuelto = 0;
    }
    if (isNumeric(edad) == 0)
    {
        valorDevuelto = 0;
    }
    
    return valorDevuelto;
}

function isNumeric(val)
{
   for(var i=0;i<val.length;i++)
   {
		if(!isDigit(val.charAt(i)))
		{
		    return 0;
		}
    }
	return 1;
}
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
}

function initFechasIEHoteles(){
    // Autocompletar
    /*var key = document.getElementById('arrCityH');
    new Autocompleter.Request.JSON(key, '/alojamientos/autocompleter.do', {
        minLength: 3,
        delay: 0,
        overflow: true,
        overflowMargin: 34,
        filterSubset: true,
        zIndex: 1000
    });*/

    // Fecha inicial
	var fecInicial = new Date();
	hotel_search.fe_mesanyo.value = fecInicial.getFullYear()+addcero(fecInicial.getMonth()+1);	
	hotel_search.fe_dia.value = addcero(fecInicial.getDate());
	hotel_search.fechaEntrada.value = hotel_search.fe_dia.value+"/"+hotel_search.fe_mesanyo.value.substring(4)+"/"+hotel_search.fe_mesanyo.value.substring(0,4);
}

function initFechasOtrosHoteles(){
	var fecInicial = new Date();
	hotel_search.fe_mesanyo.value = fecInicial.getFullYear()+addcero(fecInicial.getMonth()+1);
	hotel_search.fe_dia.value = addcero(fecInicial.getDate());
}

function cerrarEdades()
{
	document.getElementById("rellenarEdades").style.visibility = 'hidden';
	document.getElementById("rellenarEdades").style.display = 'none';
	document.hotel_search.paxHab.value = '2A0N';
	hotel_search.child1.value = '';
	hotel_search.child2.value = '';
	hotel_search.child3.value = '';
	hotel_search.child4.value = '';
	hotel_search.child5.value = '';
	hotel_search.child6.value = '';
	hotel_search.child7.value = '';
	hotel_search.child8.value = '';
	hotel_search.child9.value = '';
	hotel_search.child10.value = '';
	document.getElementById("edades").innerHTML = '';
}
function cerrarEdades2()
{
	document.getElementById("rellenarEdades").style.visibility = 'hidden';
	document.getElementById("rellenarEdades").style.display = 'none';
	document.hotel_search.paxChd.value = '0';
	hotel_search.child1.value = '';
	hotel_search.child2.value = '';
	hotel_search.child3.value = '';
	hotel_search.child4.value = '';
	hotel_search.child5.value = '';
	hotel_search.child6.value = '';
	hotel_search.child7.value = '';
	hotel_search.child8.value = '';
	hotel_search.child9.value = '';
	hotel_search.child10.value = '';
	document.getElementById("edades").innerHTML = '';
}

function mostrarTextoHabitaciones()
{
		var numHabs = document.getElementById("HotelSearchForm").numRooms.value;
		if(numHabs>1)
		{
			document.getElementById("capa1Doble").style.visibility = 'hidden';			
			document.getElementById("capa1Doble").style.display = 'none';	
			document.getElementById("capaMasDobles").style.visibility = 'visible';
			document.getElementById("capaMasDobles").style.display = 'block';
		}
		else
		{
			document.getElementById("capa1Doble").style.visibility = 'visible';			
			document.getElementById("capa1Doble").style.display = 'block';	
			document.getElementById("capaMasDobles").style.visibility = 'hidden';
			document.getElementById("capaMasDobles").style.display = 'none';
		}
}