var dia_inicio=getLyr('lst_dia_fecha_inicio');
var mes_inicio=getLyr('lst_mes_fecha_inicio');
var anyo_inicio=getLyr('lst_anyo_fecha_inicio');
var dia_fin=getLyr('lst_dia_fecha_fin');
var mes_fin=getLyr('lst_mes_fecha_fin');
var anyo_fin=getLyr('lst_anyo_fecha_fin');
var num_noches=getLyr('txt_num_noches');
var num_habitaciones=getLyr('lst_habitaciones');
var hist=getLyr('hdn_hist');
if(!hist){
	hist="";
}
function update_fecha_inicio(){
	var fecha_inicio=new Date();
	fecha_inicio.setDate(1);
	fecha_inicio.setFullYear(anyo_inicio.selectedIndex+2010);
	fecha_inicio.setMonth(mes_inicio.selectedIndex);
	fecha_inicio.setDate(dia_inicio.selectedIndex+1);

	fecha_inicio.setDate(fecha_inicio.getDate() + parseInt(num_noches.value))
	//fecha_inicio.addDays(parseInt(num_noches.value));
	dia_fin.selectedIndex=fecha_inicio.getDate()-1;
	mes_fin.selectedIndex=fecha_inicio.getMonth();
	anyo_fin.selectedIndex=fecha_inicio.getFullYear()-2010;
}

function update_fecha_fin(){
	var fecha_inicio=new Date();
	fecha_inicio.setDate(1);
	fecha_inicio.setFullYear(anyo_inicio.selectedIndex+2010);
	fecha_inicio.setMonth(mes_inicio.selectedIndex);
	fecha_inicio.setDate(dia_inicio.selectedIndex+1);
	var fecha_fin=new Date();
	fecha_fin.setDate(1);
	fecha_fin.setFullYear(anyo_fin.selectedIndex+2010);
	fecha_fin.setMonth(mes_fin.selectedIndex);
	fecha_fin.setDate(dia_fin.selectedIndex+1);
	num_noches.value=Date.restaFechas(fecha_inicio,fecha_fin);
	if(parseInt(num_noches.value)<0){
		num_noches.value=0;
	}

}

function update_num_noches(){
	update_fecha_inicio()
}

function open_calendar(t){
	var fecha=new Date();
	fecha.setDate(1);
	if(t==1 || t==3){
		fecha.setFullYear(anyo_inicio.selectedIndex+2010);
		fecha.setMonth(mes_inicio.selectedIndex);
		fecha.setDate(dia_inicio.selectedIndex+1);
	}else{
		fecha.setFullYear(anyo_fin.selectedIndex+2010);
		fecha.setMonth(mes_fin.selectedIndex);
		fecha.setDate(dia_fin.selectedIndex+1);
	}
 	window.open('/calendario.aspx?idioma=' + idm + '&tipo=' + t + '&fecha=' + fecha.toStr(),'calendario','left=200,top=150,width=250,height=200');
}
function reservar(zh){
	var fecha_inicio=new Date();
	fecha_inicio.setDate(1);
	fecha_inicio.setFullYear(anyo_inicio.selectedIndex+2010);
	fecha_inicio.setMonth(mes_inicio.selectedIndex);
	fecha_inicio.setDate(dia_inicio.selectedIndex+1);
	fecha_inicio.setHours(0,0,0,0); 
	var fecha_fin=new Date();
	fecha_fin.setDate(1);
	fecha_fin.setFullYear(anyo_fin.selectedIndex+2010);
	fecha_fin.setMonth(mes_fin.selectedIndex);
	fecha_fin.setDate(dia_fin.selectedIndex+1);
	fecha_fin.setHours(0,0,0,0);
	if(fecha_inicio<=hoy){
		alert(errores['hoy']);
		return false;
	}
	if(fecha_inicio.getDate()!=dia_inicio.selectedIndex+1){
		alert(errores['fecha_inicio']);
		return false;
	}
	if(fecha_fin.getDate()!=dia_fin.selectedIndex+1){
		alert(errores['fecha_fin']);
		return false;
	}
	if(num_noches.value<1){
		alert(errores['num_noches']);
		return false;
	}
	var ruta='https://www.servigroup.es/';
	if(zh==null){
		var zona_hotel=getLyr('lst_zonas_hoteles');
		zh=zona_hotel.options[zona_hotel.selectedIndex].value;
		ruta='';
	}
	hist.value="1";
	if(zh==""){
		if(idm=="en"){
			document.location=ruta+'ingles/reservas/reservas.aspx?fe='+fecha_inicio.toStr()+'&fs='+fecha_fin.toStr()+'&nn='+num_noches.value+'&nh='+(num_habitaciones.selectedIndex+1);
		}else{
			document.location=ruta+'esp/reservas/reservas.aspx?fe='+fecha_inicio.toStr()+'&fs='+fecha_fin.toStr()+'&nn='+num_noches.value+'&nh='+(num_habitaciones.selectedIndex+1);
		}
	}else{
		if(idm=="en"){
			document.location=ruta+'ingles/reservas/reservas.aspx?zh='+ zh +'&fe='+fecha_inicio.toStr()+'&fs='+fecha_fin.toStr()+'&nn='+num_noches.value+'&nh='+(num_habitaciones.selectedIndex+1);
		}else{
			document.location=ruta+'esp/reservas/reservas.aspx?zh='+ zh +'&fe='+fecha_inicio.toStr()+'&fs='+fecha_fin.toStr()+'&nn='+num_noches.value+'&nh='+(num_habitaciones.selectedIndex+1);
		}
	}
}


document.onreadystatechange=_Document_onload;

addEvent("DOMContentLoaded", _Document_onload, null);


function _Document_onload(){
	if(hist.value!=1){
		var manyana=new Date(hoy);
		
		manyana.addDay();
		dia_inicio.selectedIndex=manyana.getDate()-1;
		mes_inicio.selectedIndex=manyana.getMonth();
		anyo_inicio.selectedIndex=manyana.getFullYear()-2010;
		manyana.addDay();
		dia_fin.selectedIndex=manyana.getDate()-1;
		mes_fin.selectedIndex=manyana.getMonth();
		anyo_fin.selectedIndex=manyana.getFullYear()-2010;
	}
}





function addEvent(e,f){
	if(document.attachEvent){
		eval('document.attachEvent("on'+e+'",'+f+');');
	}else if(window.addEventListener){
		eval('window.addEventListener("'+e+'",'+f+',true);');
	}else{
		eval('window["on'+e+'"]='+f+';');
	}

}



