// JavaScript Document endDate=cambiar_caja_de_texto_de_lugar;
/* COMIENZA PROCESO DE CALENDARIO PARA EL BUSCADOR ******************************************/
var startDate; // end hiding contents from old browsers  -->
var endDate;
var ONEDAY=3600*24;
fecha_a_colocar_en_la_caja_de_texto="";
function filterDates1(cal){
	startDate=cal.date;
	if(endDate==null){
		Zapatec.Calendar.setup({
			button			:	"btn_fecha_hasta_hoteles_buscador",  // What will trigger the popup of the calendar
			controlMonth	:	1,
			date			:	startDate,
			disableFunc		:	dateInRange2, //the function to call
			electric		:	false,
			ifFormat		:	"%d/%m/%Y",
			inputField		:	"caja_de_texto_fecha_hasta_hoteles_buscador",
			numberMonths	:	2,
			onUpdate		:	filterDates2,
//			saveDate		:	1,
			showsTime		:	false,          //no time
			timeFormat		:	"24"
		});
	}
}
function filterDates1aereo(cal){
	startDate=cal.date;
	if(endDate==null){
		Zapatec.Calendar.setup({
			button			:	"btn_fecha_hasta_aereos_buscador",  // What will trigger the popup of the calendar
			controlMonth	:	1,
			date			:	startDate,
			disableFunc		:	dateInRange2, //the function to call
			electric		:	false,
			ifFormat		:	"%d/%m/%Y",
			inputField		:	"caja_de_texto_fecha_hasta_aereos_buscador",
			numberMonths	:	2,
			onUpdate		:	filterDates2,
//			saveDate		:	1,
			showsTime		:	false,          //no time
			timeFormat		:	"24"
		});
	}
}
function filterDates2(cal){endDate=cal.date;}
function dateInRange1(date){
	if(endDate!=null){
		var compareEnd=compareDatesOnly(date,endDate);//Disable dates after end date
		if(compareEnd<0){return (true);}
		if(compareEnd==0){{return "edges";}}// Hilight end date with "edges" style
		if(startDate!=null){//Hilight inner dates with "between" style
			var compareStart=compareDatesOnly(date,startDate);
			if(compareStart<0){return "between";} 
		}
	}
	var today=new Date();//disable days prior to today
	if(buscador_actual == 'hoteles'){//Suma tres dias a la fecha actual
		if(document.getElementById('id_pais_fuente').value=='CH'){fecha_para_hoteles=today.getTime()+dias_reserva_ch*24*60*60*1000;
		}else{fecha_para_hoteles=today.getTime()+dias_reserva_th*24*60*60*1000;}
		today.setTime(fecha_para_hoteles);
	}
	if(buscador_actual=='paquetes')today.setTime(today.getTime()+dias_reserva_ch*24*60*60*1000);
	if(buscador_actual=='aereos')today.setTime(today.getTime()+dias_reserva_ch*24*60*60*1000);
	if(buscador_actual=='nohaybuscador')today.setTime(today.getTime());
	var compareToday=compareDatesOnly(date,today);
	if(compareToday>0){return(true);}
	return false;//all other days are enabled
	return(ret);//alert(ret + " " + today + ":" + date + ":" + compareToday + ":" + days1 + ":" + days2);
}
/** Can't choose days before the start date if it is choosen, hilights start and end dates with one style and dates between them with another */
function dateInRange2(date){
	if(startDate!=null){//Disable dates before start date
		var compareDays=compareDatesOnly(startDate,date);
		if(compareDays<0){return (true);}
		if(compareDays==0){{return "edges";}}//Hilight end date with "edges" style
		if((endDate != null)&&(date>startDate)&&(date<endDate)){return "between";}//Hilight inner dates with "between" style
	}
	var now=new Date();
	if(buscador_actual=='hoteles'){//Suma tres dias a la fecha actual
		if(document.getElementById('id_pais_fuente').value=='CH'){fecha_para_hoteles=now.getTime()+dias_reserva_ch*24*60*60*1000;
		}else{fecha_para_hoteles = now.getTime()+dias_reserva_th*24*60*60*1000;}
		now.setTime(fecha_para_hoteles);
	}
	if(buscador_actual=='paquetes')now.setTime(now.getTime()+dias_reserva_ch*24*60*60*1000);
	if(buscador_actual=='aereos')now.setTime(now.getTime()+dias_reserva_ch*24*60*60*1000);
	
	if(buscador_actual=='nohaybuscador')now.setTime(now.getTime());
	if(compareDatesOnly(now,date)<0){return (true);}
	return false;//all other days are enabled
}
function compareDatesOnly(date1,date2){
	var year1=date1.getYear();
	var year2=date2.getYear();
	var month1=date1.getMonth();
	var month2=date2.getMonth();
	var day1=date1.getDate();
	var day2=date2.getDate();
	if(year1>year2){return -1;}
	if(year2>year1){return 1;}
	//years are equal
	if(month1>month2){return -1;}
	if(month2>month1){return 1;}
	//years and months are equal
	if(day1>day2){return -1;}
	if(day2>day1){return 1;}
	//days are equal
	return 0;
	/* Can't do this because of timezone issues
	var days1 = Math.floor(date1.getTime()/Date.DAY);
	var days2 = Math.floor(date2.getTime()/Date.DAY);
	return (days1 - days2);
	*/
}
/* TERMINA PROCESO DE CALENDARIO PARA EL BUSCADOR ******************************************/
