var Hoy=new Date();
arrDia = new Array();
arrDia[0] = new Array(7);
arrDia[0][0] = "Domingo";
arrDia[0][1] = "Lunes";
arrDia[0][2] = "Martes";
arrDia[0][3] = "Miércoles";
arrDia[0][4] = "Jueves";
arrDia[0][5] = "Viernes"; 
arrDia[0][6] = "Sábado";

function selectAirports(selMAD,selBCN,TripType) {
	document.write("<option value=\"ALC\">Alicante</option><option value=\"LEI\">Almería</option><option value=\"AMS\">Amsterdam</option><option value=\"BJZ\">Badajoz</option><option value=\"BCN\" "+selBCN+">Barcelona</option><option value=\"BIO\">Bilbao</option><option value=\"BRU\">Bruselas</option><option value=\"BUE\">Buenos Aires</option><option value=\"CPH\">Copenhagen</option><option value=\"DUB\">Dublín</option><option value=\"DUS\">Dusseldorf</option><option value=\"STO\">Estocolmo</option><option value=\"FRA\">Frankfurt</option><option value=\"FUE\">Fuerteventura</option><option value=\"GVA\">Ginebra</option><option value=\"GRX\">Granada</option><option value=\"IBZ\">Ibiza </option><option value=\"XRY\">Jerez</option><option value=\"LCG\">La Coruña</option><option value=\"SPC\">La Palma</option><option value=\"ACE\">Lanzarote</option><option value=\"LPA\">Las Palmas G. Canaria</option><option value=\"LEN\">León</option><option value=\"LIS\">Lisboa</option><option value=\"RJL\">Logroño</option><option value=\"LON\">Londres</option><option value=\"MAD\" "+selMAD+">Madrid</option><option value=\"AGP\">Málaga</option><option value=\"MAH\">Menorca</option><option value=\"MIL\">Milán</option><option value=\"MJV\">Murcia</option><option value=\"NYC\">Nueva York</option><option value=\"OPO\">Oporto</option><option value=\"OVD\">Oviedo</option><option value=\"PMI\">Palma de Mallorca</option><option value=\"PNA\">Pamplona</option><option value=\"PAR\">París</option><option value=\"ROM\">Roma</option><option value=\"EAS\">San Sebastián</option><option value=\"SDR\">Santander</option><option value=\"SCQ\">Santiago Compostela</option><option value=\"SVQ\">Sevilla</option><option value=\"TCI\">Tenerife</option><option value=\"VLC\">Valencia</option><option value=\"VLL\">Valladolid</option><option value=\"VGO\">Vigo</option><option value=\"ZIC\">Vitoria</option><option value=\"ZAZ\">Zaragoza</option><option value=\"ZRH\">Zurich</option><option value=\"OTH\">"+TripType+"</OPTION>");
}

function selectAirports_D(selMAD,selBCN,TripType) {
	document.write("<option value=\"ALC\">Alicante</option><option value=\"LEI\">Almería</option><option value=\"AMS\">Amsterdam</option><option value=\"BCN\" "+selBCN+">Barcelona</option><option value=\"BER\">Berlín</option><option value=\"BIO\">Bilbao</option><option value=\"BRU\">Bruselas</option><option value=\"BUE\">Buenos Aires</option><option value=\"CPH\">Copenhagen</option><option value=\"DUB\">Dublín</option><option value=\"DUS\">Dusseldorf</option><option value=\"STO\">Estocolmo</option><option value=\"FRA\">Frankfurt</option><option value=\"FUE\">Fuerteventura</option><option value=\"GVA\">Ginebra</option><option value=\"GRX\">Granada</option><option value=\"IBZ\">Ibiza </option><option value=\"XRY\">Jerez</option><option value=\"LCG\">La Coruña</option><option value=\"ACE\">Lanzarote</option><option value=\"LPA\">Las Palmas G. Canaria</option><option value=\"LIS\">Lisboa</option><option value=\"LON\">Londres</option><option value=\"MAD\" "+selMAD+">Madrid</option><option value=\"AGP\">Málaga</option><option value=\"MAH\">Menorca</option><option value=\"MEX\">México</option><option value=\"MIA\">Miami</option><option value=\"MIL\">Milán</option><option value=\"MUC\">Munich</option><option value=\"NYC\">Nueva York</option><option value=\"OPO\">Oporto</option><option value=\"OVD\">Oviedo</option><option value=\"PMI\">Palma de Mallorca</option><option value=\"PNA\">Pamplona</option><option value=\"PAR\">París</option><option value=\"PRG\">Praga</option><option value=\"ROM\">Roma</option><option value=\"EAS\">San Sebastián</option><option value=\"SDR\">Santander</option><option value=\"SCQ\">Santiago Compostela</option><option value=\"SVQ\">Sevilla</option><option value=\"STR\">Stuttgart</option><option value=\"TCI\">Tenerife</option><option value=\"VLC\">Valencia</option><option value=\"VCE\">Venecia</option><option value=\"VIE\">Viena</option><option value=\"VGO\">Vigo</option><option value=\"ZRH\">Zurich</option><option value=\"OTH\">"+TripType+"</OPTION>");
}

function horas_options(ini,fin,sel,nameSelect,classSelect) {
	var i=parseInt(ini);
	var textoFirstOption = "<bean:message key='buscador.comboHoras'/>";
	document.write('<select name=' + nameSelect + ' class=' + classSelect + '>');
 	document.write('<option value="">'+textoFirstOption+'</option>');
	while (i<=parseInt(fin)){
		if (sel!='' && parseInt(i,10)==sel)
			document.write('<option value='+decode(i-1)+'00>'+decode(i-1)+':00</option>');
		else
			document.write('<option value='+decode(i-1)+'00>'+decode(i-1)+':00</option>');
		i++;
	}
	document.write('<\/select>');
}

function dia_options(ini,fin,sel,nameSelect,classSelect) {
	var i = parseInt(ini);
	var textoFirstOption = "<bean:message key='buscador.comboDias'/>";	
	var mes = '';
	var week = '';
	if(nameSelect=='fe_dia'){
		mes = 'fe_mesanyo';
		week = 'fe_dayOfWeek';
	}else{
		mes = 'fs_mesanyo';
		week = 'fs_dayOfWeek';		
	}
	document.write('<select name=' + nameSelect + ' class=' + classSelect + ' onChange="DayOfWeek(\'es\', document.flightForm.' + mes + ', document.flightForm.' + nameSelect + ', document.flightForm.' + week + ')">');
	document.write('<option value="">'+textoFirstOption+'</option>');
	while (i<=parseInt(fin)){
		if (sel!='' && i==parseInt(sel,10))
			document.write('<option value='+decode(i-1)+'>'+decode(i-1)+'</option>');
		else
			document.write('<option value='+decode(i-1)+'>'+decode(i-1)+'</option>');
		i++;
	}
	document.write('<\/select>');
}


function DayOfWeek(pais, mesyear, dia, dayofweek){
	lang = 0;
	year=mesyear.value.substring(0,4);
	mes=mesyear.value.substring(4);
	var c = new Date( year,(mes-1),dia.value );
	var dayOfWeek = c.getDay();
	if (-1!=(mes-1) && (mes-1)<=12 &&-1!=dia.value && dia.value<=31 ) {
		diaSemana = arrDia[lang][dayOfWeek];
		dayofweek.value = diaSemana;
	}
}

function decode(i) {
	if ((i+1).toString().length==1) return '0'+(i+1);
	else return (i+1);
}

function decodeYear(x,y) {
	if (x==y) return "";
	else return x;
}

function format(valor, asignacion) {
	if (asignacion=='I'){
		document.RgAvailability.fe_dia.value = valor.substring(0,valor.indexOf("/"));
		document.RgAvailability.fe_mesanyo.value = "20"+valor.substring(valor.indexOf("/",valor.indexOf("/")+1 )+1)+valor.substring(valor.indexOf("/")+1, valor.indexOf("/",valor.indexOf("/")+1));
	} else {
		document.RgAvailability.fs_dia.value = valor.substring(0,valor.indexOf("/"));
		document.RgAvailability.fs_mesanyo.value = "20"+valor.substring(valor.indexOf("/"), valor.indexOf("/",valor.indexOf("/")+1))+valor.substring(0,valor.indexOf("/"));
	}
}

function validaForm(form){
	if (form.B_LOCATION_IN.value=="" || form.E_LOCATION_IN.value==""){
		alert(alert_location);
		return -1
	}
	if (form.B_LOCATION_IN.value==form.E_LOCATION_IN.value){
		alert(alert_samelocation);
		return -1
	}
	today =today_Date();
	diah=parseInt(today.substring(0,today.indexOf('/')),10);
	mesh=parseInt(today.substring(today.indexOf('/')+1,today.indexOf('/',3)),10);
	anyh=parseInt(today.substring(today.indexOf('/',3)+1,today.length),10);
	diae=parseInt(form.fe_dia.value,10);
	mese=parseInt(form.fe_mesanyo.value.substring(4,6),10);
	anye=parseInt(form.fe_mesanyo.value.substring(0,4),10);
	dateHoy	= new Date(anyh,(mesh-1),diah);
	dateComboe = new Date(anye,(mese-1),diae);
	if (((anye>anyh) || (anye==anyh && mese>mesh)) || ((anye==anyh && mese==mesh) && diae>=diah)){
		dias=parseInt(form.fs_dia.value,10);
		mess=parseInt(form.fs_mesanyo.value.substring(4,6),10);
		anys=parseInt(form.fs_mesanyo.value.substring(0,4),10);
		dateComboss	= new Date(anys, (mess-1), dias);
		if (((dateComboe - dateHoy)/86400000)<3){
			alert(alert_date72);
		}
	} else {
		alert(alert_dateorder);
		return -1;
	}
	if (form.fs_dia.value!="" || form.fs_mesanyo.value!="") {
	   	if (((anys>anye) || (anys==anye && mess>mese)) || ((anys==anye && mess==mese) && dias>=diae)){
			if (dias==diae && mess==mese && anys==anye){
				document.RgAvailability.D_DATE.value = document.RgAvailability.fe_mesanyo.value+ document.RgAvailability.fe_dia.value+"0900";
				document.RgAvailability.R_DATE.value = document.RgAvailability.fs_mesanyo.value+ document.RgAvailability.fs_dia.value+"2100";
			}
		}else{
			alert(alert_dateorder);
			return -1;
		}
	form.TRIP_TYPE.value="R";
	}else{form.TRIP_TYPE.value="O";}
}

function search(type){
	document.RgAvailability.D_DATE.value = document.RgAvailability.fe_mesanyo.value+ document.RgAvailability.fe_dia.value+"0000";
	document.RgAvailability.R_DATE.value = document.RgAvailability.fs_mesanyo.value+ document.RgAvailability.fs_dia.value+"0000";
	res = validaForm(document.RgAvailability);
	if (res==-1) return;
	if (type=='1') {
		document.RgAvailability.flag.value="airavailability";
		document.RgAvailability.B_DATE_1.value=document.RgAvailability.D_DATE.value;
		if (document.RgAvailability.TRIP_TYPE.value=="R") document.RgAvailability.B_DATE_2.value=document.RgAvailability.R_DATE.value;
		else document.RgAvailability.B_DATE_2.value="";
		document.RgAvailability.E_LOCATION_1.value=document.RgAvailability.E_LOCATION_IN.value;
		document.RgAvailability.B_LOCATION_1.value=document.RgAvailability.B_LOCATION_IN.value;
		document.RgAvailability.E_LOCATION_2.value=document.RgAvailability.B_LOCATION_IN.value;
		document.RgAvailability.B_LOCATION_2.value=document.RgAvailability.E_LOCATION_IN.value;
	}
	else document.RgAvailability.flag.value="mpavailability";
	price = '0';
	time = '0';
	if(document.RgAvailability.B_LOCATION_IN.type=="text"){
		document.RgAvailability.DEPARTURE_DESC_LOC.value= document.RgAvailability.B_LOCATION_IN.value;
	}else{
		document.RgAvailability.DEPARTURE_DESC_LOC.value= document.RgAvailability.B_LOCATION_IN.options[document.RgAvailability.B_LOCATION_IN.selectedIndex].text;
	}
	if(document.RgAvailability.E_LOCATION_IN.type=="text"){
		document.RgAvailability.ARRIVAL_DESC_LOC.value= document.RgAvailability.E_LOCATION_IN.value;
	}else{
		document.RgAvailability.ARRIVAL_DESC_LOC.value=  document.RgAvailability.E_LOCATION_IN.options[document.RgAvailability.E_LOCATION_IN.selectedIndex].text;
	}
	document.RgAvailability.submit();
}

var periodo = 100;
var n= 0;
var auxn = 1;
function cambiaNum() {
	document.buscando.buscando.value = n;
	var td1=document.getElementById("td1");
	var td2=document.getElementById("td2");
	var td3=document.getElementById("td3");

	if (auxn==1 ) {
		td1.setAttribute('className','flight'); //IE
		td1.setAttribute('class','flight'); //MO
		td2.setAttribute('className','rumbo4'); //IE
		td2.setAttribute('class','rumbo4'); //MO
		td3.setAttribute('className','rumbo4'); //IE
		td3.setAttribute('class','rumbo4'); //MO
		auxn++;

	} else if (auxn==2) {
		td1.setAttribute('className','flight'); //IE
		td1.setAttribute('class','flight'); //MO
		td2.setAttribute('className','flight'); //IE
		td2.setAttribute('class','flight'); //MO
		td3.setAttribute('className','rumbo4'); //IE
		td3.setAttribute('class','rumbo4'); //MO
		auxn++;
	} else if (auxn==3) {
		td1.setAttribute('className','flight'); //IE
		td1.setAttribute('class','flight'); //MO
		td2.setAttribute('className','flight'); //IE
		td2.setAttribute('class','flight'); //MO
		td3.setAttribute('className','flight'); //IE
		td3.setAttribute('class','flight'); //MO
		auxn++;
	}
	else if (auxn==4) {
		td1.setAttribute('className','rumbo4'); //IE
		td1.setAttribute('class','rumbo4'); //MO
		td2.setAttribute('className','rumbo4'); //IE
		td2.setAttribute('class','rumbo4'); //MO
		td3.setAttribute('className','rumbo4'); //IE
		td3.setAttribute('class','rumbo4'); //MO
		auxn=1;
	}
	Window.setTimeout("cambiaNum()",periodo);				
	n++;
	if (n==500) n=1;
}

function comprueba_fecha(){								
	var fecha_ini=document.ReservationStep1.fe_anyo.options[document.ReservationStep1.fe_anyo.selectedIndex].value + document.ReservationStep1.fe_mes.options[document.ReservationStep1.fe_mes.selectedIndex].value + document.ReservationStep1.fe_dia.options[document.ReservationStep1.fe_dia.selectedIndex].value;				
	var fecha_fin=document.ReservationStep1.fs_anyo.options[document.ReservationStep1.fs_anyo.selectedIndex].value + document.ReservationStep1.fs_mes.options[document.ReservationStep1.fs_mes.selectedIndex].value + document.ReservationStep1.fs_dia.options[document.ReservationStep1.fs_dia.selectedIndex].value;			
	var fechahoy=GeneraFecha();				
	if(parseInt(fecha_ini)< (parseInt(fechahoy)+1)){
		alert("La fecha de recogida debe ser posterior al día de hoy.");
		return false;
	}											
	else if(parseInt(fecha_ini)>parseInt(fecha_fin)){
		alert("La fecha de recogida debe ser anterior a la devolución.");
		return false;
	}
	else return true;
}
/* Devuelve la fecha actual en formato aaaammdd */
function GeneraFecha() {
var fechaString = "";
var ahora = new Date();
var year=ahora.getFullYear().toString();
var mes=(ahora.getMonth()+1).toString();
var dia=ahora.getDate().toString();
if(mes.length==1) mes="0"+mes;
if(dia.length==1) dia="0"+dia;
	fechaString = year+mes+dia;
    return fechaString;
}
/* Si la regi?n seleccionada en ambos combos es la misma, selecciona como oficina de devoluci?n la misma que la de recogida */
var countryIniCode = "ES0";
var countryFinCode = "ES0";
var country="ES";
var city1="0";
function setOficinaFin(){
    if(countryIniCode==countryFinCode)
	document.ReservationStep1.oficinaFin.selectedIndex=document.ReservationStep1.oficinaIni.selectedIndex;
}
/* Comprueba que el usuario haya seleccionado una oficina de recogida y una de devoluci?n */
function comprueba_seleccion(){
	if(document.ReservationStep1.oficinaIni.selectedIndex==0) {
		alert("Debe seleccionar una oficina de recogida");
		return false;
	}
	if(document.ReservationStep1.oficinaFin.selectedIndex==0) {
		alert("Debe seleccionar una oficina de devolución");
		return false;
	}
	else return true;
}
/* Valida el formulario y adjudica valor a los campos ocultos */
function valida_form (){
var dateI =document.ReservationStep1.fs_mesanyo.value+document.ReservationStep1.fs_dia.value;
var dateV =document.ReservationStep1.fe_mesanyo.value+document.ReservationStep1.fe_dia.value;
	if(dateV*1 < dateI*1){
		alert("La fecha de devolución debe ser posterior a la fecha de recogida.");
		return;
	}
	if(!comprueba_seleccion()) return;
	document.ReservationStep1.oficinaIniCity.value=document.ReservationStep1.oficinaIni.options[document.ReservationStep1.oficinaIni.selectedIndex].text;
	document.ReservationStep1.oficinaFinCity.value=document.ReservationStep1.oficinaFin.options[document.ReservationStep1.oficinaFin.selectedIndex].text;
	document.ReservationStep1.carexample.value=document.ReservationStep1.cargroup.options[document.ReservationStep1.cargroup.selectedIndex].text;
	document.ReservationStep1.submit();
}
/* Selecciona en el combo de grupos de coche el que le pasan como par?metro */
function setGroup(grupo){
	for(var i=0; i<	document.ReservationStep1.cargroup.options.length; i++){
		if(document.ReservationStep1.cargroup.options[i].value==grupo){
			document.ReservationStep1.cargroup.selectedIndex=i;
			break;
		}
	}
}

function selectPax(ObjMaster,ObjCustom,pass_total){ /* to limit num passenger max in combos adults and childs */
	var minCustom = parseInt(ObjCustom.options[0].value);
	var ObjCustomMaxLength = pass_total*1 - parseInt(ObjMaster.value);
	var ObjCustomLength = ObjCustom.options.length;
	var ObjCustomSelect = ObjCustom.value;
	for (j = ObjCustomLength-1; j >0; j--)
		ObjCustom.options[j] = null;
	for (j=0;j<=ObjCustomMaxLength-minCustom;j++)
		ObjCustom.options[j] = new Option(j+minCustom,j+minCustom);
	if (parseInt(ObjCustomSelect) <= ObjCustomMaxLength)
		ObjCustom.value = ObjCustomSelect;
}

//ARRAYS DE DESTINOS PARA LA CAJA DE LA HOME DE VUELO M?S HOTEL
var array_ALC = "ES|182|6286|1|Alicante";
var array_LEI = "ES|183|6322|1|Almeria";
var array_AMS = "HO|1511|5192|1|Amsterdam";
var array_BCN = "ES|10|6297|1|Barcelona";
var array_BER = "AL|1487|5149|1|Berlín";
var array_BIO = "ES|226|6811|5|Bilbao";
var array_BRU = "BE|1492|4989|1|Bruselas";
var array_CPH = "DI|1503|5570|1|Copenhague";
var array_DUB = "IR|1514|5033|1|Dublin";
var array_DUS = "AL|1487|5122|1|Dusseldorf";
var array_STO = "SC||5055|1|Estocolmo";
var array_FRA = "AL|1487|13014|1|Frankfurt";
var array_FUE = "ES|226|11579|1|Fuerteventura";
var array_GVA = "SU|1540|5066|1|Ginebra";
var array_GRX = "ES|111|6568|1|Granada";
var array_IBZ = "ES||6385|1|Ibiza";
var array_XRY = "ES||6439|1|Jerez";
var array_LCG = "ES||6629|1|A Coruña";
var array_ACE = "ES||11578|1|Lanzarote";
var array_LPA = "ES|1571|6462|1|Las Palmas";
var array_LIS = "PO||4958|1|Lisboa";
var array_LON = "GB||7257|1|Londres";
var array_MAD = "ES|36|6396|1|Madrid";
var array_AGP = "ES||6681|1|Malaga";
var array_MAH = "ES||17049|1|Menorca";
var array_MEX = "ME||5617|1|México";
var array_MIA = "US||5158|1|Miami";
var array_MIL = "IT||5049|1|Milán";
var array_MUC = "AL|1487|5597|1|Munich";
var array_NYC = "US||5014|1|Nueva York";
var array_OPO = "PO||4970||Oporto";
var array_OVD = "ES||6331|1|Oviedo";
var array_PMI = "ES||6378|1|Palma de Mallorca";
var array_PNA = "ES|214|6718|1|Pamplona";
var array_PAR = "FR||4984|1|París";
var array_PRG = "RC|1534|5114|1|Praga";
var array_ROM = "IT||5102|1|Roma";
var array_EAS = "ES||6583|1|San Sebastian";
var array_SDR = "ES||6511|1|Santander";
var array_SCQ = "ES|205|6627|1|Santiago De Compostela";
var array_SVQ = "ES||6768|1|Sevilla";
var array_STR = "AL|1487|5433|1|Stuttgart";
var array_TCI = "ES|1572|6471|1|Santa Cruz De Tenerife";
var array_VLC = "ES||6819|1|Valencia";
var array_VCE = "IT||5074|1|Venecia";
var array_VIE = "AT||5027|1|Viena";
var array_VGO = "ES||6739|1|Vigo";
var array_ZRH = "SU|1540|5610|1|Zurich";

function seleccionaProvincia(destino){
	eval('var datos = array_'+destino);
	var array_datos = datos.split('|');
	var datos_poblacion = array_datos[2];
	if(datos_poblacion =="") datos_poblacion=array_datos[4];
	var datos_pais = array_datos[0];
	var datos_busc = array_datos[3];
	var datos_busc_letra;
  	if(datos_busc == 0) datos_busc_letra = "AMADEUS";
  	if(datos_busc == 1) datos_busc_letra = "TRANSHOTEL";
  	if(datos_busc == 2) datos_busc_letra = "HOTELBEDS";
  	if(datos_busc == 3) datos_busc_letra = "RUMBO";
  	if(datos_busc == 4) datos_busc_letra = "BOSCOLO";
  	if(datos_busc == 5) datos_busc_letra = "HOTUSA";
  	if(datos_busc == 6) datos_busc_letra = "TROPIKAL";

	document.hotel_flight_search.search_engine.value = datos_busc ;
	document.hotel_flight_search.Buscador.value = datos_busc_letra ;
	document.hotel_flight_search.Poblacion.value=datos_poblacion;
	document.hotel_flight_search.GEOZONE.value=datos_poblacion;
	document.hotel_flight_search.nombre_pob.value=datos_poblacion;
	document.hotel_flight_search.Provincia.value=datos_pais;
	document.hotel_flight_search.PAIS.value=datos_pais;
	document.hotel_flight_search.Country.value=datos_pais;
	document.hotel_flight_search.DEPARTURE_DESC_LOC.value="Madrid";
	document.hotel_flight_search.D_DATE.value=document.hotel_flight_search.fe_mesanyo.value + document.hotel_flight_search.fe_dia.value+"0900";
	document.hotel_flight_search.R_DATE.value=document.hotel_flight_search.fs_mesanyo.value + document.hotel_flight_search.fs_dia.value+"0900";
	document.hotel_flight_search.R_HOUR.value="";
	document.hotel_flight_search.D_HOUR.value="";
}

function pintaHab(){
	buscador=document.hotel_flight_search.search_engine.value.toUpperCase();
  	if(buscador == 0) buscador = "AMADEUS";
  	if(buscador == 1) buscador = "TRANSHOTEL";//SOLO FUNCIONA TRANSHOTEL EN V+H
  	if(buscador == 2) buscador = "HOTELBEDS";
  	if(buscador == 3) buscador = "RUMBO";
  	if(buscador == 4) buscador = "BOSCOLO";
  	if(buscador == 5) buscador = "HOTUSA";
  	if(buscador == 6) buscador = "TROPIKAL";
	//if (prev_buscador != buscador){
	document.hotel_flight_search.tipHab1.options.length = 0;
	document.hotel_flight_search.cantHab1.options.length = 0;
	var ArrayHabitaciones= new Array();
	ArrayHabitaciones = eval('HABITACION_'+buscador);
	for (n=0;n<ArrayHabitaciones.length;n++){
		cadenaPar=ArrayHabitaciones[n]; 
		codigo=cadenaPar.substring(cadenaPar.indexOf('###')+'###'.length,cadenaPar.length);
		descripcion=cadenaPar.substring(0,cadenaPar.indexOf('###'));
		document.hotel_flight_search.tipHab1.options[n] = new Option(descripcion,codigo);	
	}
	var ArraynumHabitaciones= new Array();
	ArraynumHabitaciones= eval('numHABITACIONES_'+buscador);
	for (n=0;n<ArraynumHabitaciones.length;n++){
		cadenaPar=ArraynumHabitaciones[n];	
		codigo=cadenaPar.substring(cadenaPar.indexOf('###')+'###'.length,cadenaPar.length);
		descripcion=cadenaPar.substring(0,cadenaPar.indexOf('###'));
		document.hotel_flight_search.cantHab1.options[n] = new Option(descripcion,codigo);
	}
	document.hotel_flight_search.Buscador.value=buscador;
	prev_buscador = buscador;
    //}
}

function enviavh(){
//comprobamos si el usuario ha distribuido a los pasajeros en habitaciones correctamente.
var numAdultRoom =document.hotel_flight_search.cantHab1.value*document.hotel_flight_search.tipHab1.value.substring(0,1);
var numChildRoom =document.hotel_flight_search.cantHab1.value *document.hotel_flight_search.tipHab1.value.substring(1,2);
//Si no tenemos en cuenta a los bebes en el computo de habitaciones
	if( parseInt(document.hotel_flight_search.N_CHILD.value,10) != numChildRoom ||
		parseInt(document.hotel_flight_search.N_ADULT.value,10) != numAdultRoom){
		alert("La selección de habitaciones no coincide con el número de pasajeros.");
	}
	else if(!validateVueloHotel()){}
	else{
		document.hotel_flight_search.D_DATE.value=document.hotel_flight_search.fe_mesanyo.value + document.hotel_flight_search.fe_dia.value+"0900";
		document.hotel_flight_search.R_DATE.value=document.hotel_flight_search.fs_mesanyo.value + document.hotel_flight_search.fs_dia.value+"0900";
		document.hotel_flight_search.submit();
	}
}

function validateVueloHotel(){
var today = today_Date();
form = document.hotel_flight_search;
var ok= 0;
var ok2= 0;
var diaE= form.fe_dia.options[form.fe_dia.selectedIndex].text;
var mesE= form.fe_mesanyo.options[form.fe_mesanyo.selectedIndex].value.substring(4,6);
var anyE= form.fe_mesanyo.options[form.fe_mesanyo.selectedIndex].value.substring(0,4);
var diaS= form.fs_dia.options[form.fs_dia.selectedIndex].text;
var mesS= form.fs_mesanyo.options[form.fs_mesanyo.selectedIndex].value.substring(4,6);
var anyS= form.fs_mesanyo.options[form.fs_mesanyo.selectedIndex].value.substring(0,4);
	if (isNaN(parseInt(diaE,10))|| (isNaN(parseInt(mesE,10))|| isNaN(parseInt(anyE,10))))
		ok= -11; //error fechas e/s
	else {
		diaE=parseInt(diaE,10);
		mesE=parseInt(mesE,10);
		anyE=parseInt(anyE,10);
	}
	if (isNaN(parseInt(diaS,10))|| (isNaN(parseInt(mesS,10))|| isNaN(parseInt(anyS,10)))){
		ok= -12; //error fechas e/s
	}
    else {
		diaS=parseInt(diaS,10);
		mesS=parseInt(mesS,10);
		anyS=parseInt(anyS,10);
	}
	ok2=compruebaFechaMinima(diaE,mesE,anyE);
	if (ok==0 && ok2!=0)
	ok= -21; //fecha debe ser posterior
	ok2=compruebaFechaMinima(diaS, mesS, anyS);
	if (ok==0 && ok2!=0)
	ok= -22; //fecha debe ser posterior
	if (form.cantHab1.options[form.cantHab1.selectedIndex].value=='0')
	ok = -2;
	if ( ( (anyS>anyE) ||  (anyS==anyE && mesS>mesE) ) || ((anyS==anyE && mesS==mesE) && diaS>diaE) ){ }
	else if (ok==0) ok= -23;//fS posterior a fE
		switch (ok){
			case -1:{ alert("Error fechas entrada y/o salida en hotel");
				form.fe_dia.focus();} //Error fechas entrada y/o salida en hotel
                return false;
			case -11:{ alert("Error fechas entrada y/o salida en hotel");
				form.fe_dia.focus();} //Error fechas entrada y/o salida en hotel
                return false;
			case -12:{ alert("Error fechas entrada y/o salida en hotel");
				form.fs_dia.focus();} //Error fechas entrada y/o salida en hotel
                return false;
			case -21:{alert("La fecha debe ser posterior al dia de hoy");
				form.fe_dia.focus();} //La fecha debe ser igual o posterior al dia de hoy
              	return false;
			case -22:{alert("La fecha debe ser igual o posterior al dia de hoy");
				form.fs_dia.focus();} //La fecha debe ser igual o posterior al dia de hoy
              	return false;
			case -23:{alert("La fecha de salida debe ser anterior a la de regreso");
				form.fe_dia.focus();} //La fecha de entrada debe ser anterior a la de salida
               	return false;
			default: {}
		}
	return true;
}