function validateCities() {
	var f = getAirEntryForm();
	var checkstr = "";
	var oneWay =  (f.td_TripType.value=="1");
	//Verificar ciudades
	if (f.td_D_City.value=="") {
		checkstr += "Introduce una ciudad de salida.\n";
	} else {
		f.td_D_City.value = city(f.td_D_City.value);
	}
	if (f.td_A_City.value=="") {
		checkstr += "Introduce una ciudad de llegada\n";
	} else {
		f.td_A_City.value = city(f.td_A_City.value);
	}
	return checkstr;
}

function validatePassengers() {
	var f = getAirEntryForm();
	var checkstr = "";
	var numAdults = f.td_select_adt?f.td_select_adt.selectedIndex:0;
	var numChilds = f.td_select_chd?f.td_select_chd.selectedIndex:0;
	var numInfants = f.td_select_inf?f.td_select_inf.selectedIndex:0;
	var numOlds = 0;
    	var numTotal = 0 + numAdults + numChilds + numInfants + numOlds;
	if (numTotal == 0) {
		checkstr += "Tienes que seleccionar las personas que van a viajar.\n";
	} else if (numTotal > 9) {
		checkstr += "Solo puede reservar un máximo de 9 billetes.\n";
	}
	if (numAdults+numOlds < numInfants) {
		checkstr += "Cada bebé debe ir acompañado por un adulto.\n";
	}
	return checkstr;
}

function validateActualDate() {
	var f = getAirEntryForm();
	var myDate = new Date();
	var checkstr = "";
	if (Number(f.td_D_Month.value.substring(4)) == myDate.getMonth()+1 && Number(f.td_D_Day.value) < myDate.getDate()) {
		checkstr = "No puede hacer busquedas en dias anteriores a hoy";
	}
	return checkstr;
}

function city(v) {
	i=v.indexOf("(");
	j=v.lastIndexOf(")");
	if (j-i==4) return v.substring(i+1,j);
	return v;
}

function doFlightSearch(tipo) {
	var f = getAirEntryForm();

	var checkstr = "";
	checkstr += validateCities();

	var oneWay =  (f.td_TripType.value=="1");
	if (oneWay) {
		f.td_R_Date.value = "";
	}

	checkstr += validatePassengers();
	checkstr += validateActualDate();

	if(checkstr!=""){
		alert(checkstr);
		return;
	}

	if (tipo == 5) //viajar.com
	{
		//f.td_select_inf.value = 0;
		if (f.td_chkOneWay[1].checked)
		{
			f.td_TripType.value = "1";
		}
		else
		{
			f.td_TripType.value = "2";
		}
		f.submit();
	}
	else if (tipo == 3) //Terminal A
	{
		window.document.TA_frmBuscar.TA_CodigoAfiliado.value = "1233488";
		window.document.TA_frmBuscar.TA_CodigoIntermediario.value = "TRAD";
		if (f.td_chkOneWay[0].checked)
		{
			window.document.TA_frmBuscar.TD_TA_SoloIda.value = "N";
		}
		else
		{
			window.document.TA_frmBuscar.TD_TA_SoloIda.value = "S";
		}
		window.document.TA_frmBuscar.TD_TA_DiaRegreso.value = f.td_R_Day.value;
		window.document.TA_frmBuscar.TD_TA_MesAnioRegreso.value = f.td_R_Month.value.substring(0,4) + f.td_R_Month.value.substring(4,6);
		window.document.TA_frmBuscar.TD_TA_DiaPartida.value = f.td_D_Day.value;
		window.document.TA_frmBuscar.TD_TA_MesAnioPartida.value = f.td_D_Month.value.substring(0,4) + f.td_D_Month.value.substring(4,6);
		window.document.TA_frmBuscar.TD_TA_CiudadDesde.value = f.td_D_City.value;
		window.document.TA_frmBuscar.TD_TA_CiudadHasta.value = f.td_A_City.value;
		window.document.TA_frmBuscar.TD_TA_Adultos.value = f.td_select_adt.value;
		window.document.TA_frmBuscar.TD_TA_Chicos.value = f.td_select_chd.value;
		window.document.TA_frmBuscar.submit();
	}
	else if ( tipo == 1 ) //eDreams
	{
		f.td_departureDate.value = f.td_D_Day.value + f.td_D_Month.value.substring(4,6) + f.td_D_Month.value.substring(0,4);
		if (f.td_chkOneWay[0].checked)
		{
			f.td_TripType.value = "1";
			f.td_returnDate.value = f.td_R_Day.value + f.td_R_Month.value.substring(4,6) + f.td_R_Month.value.substring(0,4);
		}
		else
		{
			f.td_TripType.value = "0";
			f.td_returnDate.value = f.td_D_Day.value + f.td_D_Month.value.substring(4,6) + f.td_D_Month.value.substring(0,4);
		}

		f.td_departureCity.value = f.td_D_City.value;
		f.td_arrivalCity.value = f.td_A_City.value;
		f.td_adults.value = f.td_select_adt.value;
		f.td_childs.value = f.td_select_chd.value;
		f.td_infants.value = f.td_select_inf.value;
		f.submit();
	}
	else if ( tipo == 4 ) // LASTMINUTE
	{
		
		if (!f.td_chkOneWay[0].checked)
		{
			window.document.lfe_availability.td_lfe_ticket_type.value = "false";
		}
		else
		{	
			/* window.document.lfe_availability.td_lfe_ticket_type = "false"; */
		}
		window.document.lfe_availability.td_lfe_ret_day.value = f.td_R_Day.value;
		window.document.lfe_availability.td_lfe_ret_month.value = f.td_R_Month.value.substring(4,6);
		window.document.lfe_availability.td_lfe_dep_day.value = f.td_D_Day.value;
		window.document.lfe_availability.td_lfe_dep_month.value = f.td_D_Month.value.substring(4,6);
		window.document.lfe_availability.td_lfe_origin.value = f.td_D_City.value;
		window.document.lfe_availability.td_lfe_destination.value = f.td_A_City.value;
		window.document.lfe_availability.td_lfe_num_adult.value = f.td_select_adt.value;
		window.document.lfe_availability.td_lfe_num_child.value = f.td_select_chd.value;
		window.document.lfe_availability.td_lfe_num_infant.value = f.td_select_inf.value;
		window.document.lfe_availability.submit();
	}
	else if ( tipo == 2 ) //Atrapalo
	{
		if (f.td_chkOneWay[0].checked)
		{
			window.document.busqueda.td_ida.value = "2";
		}
		else
		{
			window.document.busqueda.td_ida.value = "1";
		}
        window.document.busqueda.td_origen.value = f.td_D_City.value;
        window.document.busqueda.td_destino.value = f.td_A_City.value;
        window.document.busqueda.td_salida_trigger.value = f.td_D_Day.value+'../default1.htm'+f.td_D_Month.value.substring(4,6)+'../default1.htm'+f.td_D_Month.value.substring(0,4);
        window.document.busqueda.td_regreso_trigger.value = f.td_R_Day.value+'../default1.htm'+f.td_R_Month.value.substring(4,6)+'../default1.htm'+f.td_R_Month.value.substring(0,4);
        window.document.busqueda.td_adultos.value = f.td_select_adt.value;
        window.document.busqueda.td_ninos.value = f.td_select_chd.value;
        window.document.busqueda.td_bebes.value = f.td_select_inf.value;
        window.document.busqueda.td_fecha_salida.value = f.td_D_Month.value.substring(0,4)+'../default1.htm'+f.td_D_Month.value.substring(4,6)+'../default1.htm'+f.td_D_Day.value;
        window.document.busqueda.td_fecha_regreso.value = f.td_R_Month.value.substring(0,4)+'../default1.htm'+f.td_R_Month.value.substring(4,6)+'../default1.htm'+f.td_R_Day.value;
        window.document.busqueda.td_s_dia.value = f.td_D_Day.value;
        window.document.busqueda.td_r_dia.value = f.td_R_Day.value;
        window.document.busqueda.td_s_anymes.value = f.td_D_Month.value.substring(0,4)+f.td_D_Month.value.substring(4,6);
        window.document.busqueda.td_r_anymes.value = f.td_R_Month.value.substring(0,4)+f.td_R_Month.value.substring(4,6);
		window.document.busqueda.submit();
	}
	else if ( tipo == 6 ) //Marsans
	{
		base = "http://www.marsans.es/viajes/flight/availabilityCity.do";
if (f.td_chkOneWay[0].checked)
			base = base + "?roundTrip=true";
		else
			base = base + "?roundTrip=false";
		base = base + "&departure=" + f.td_D_City.value;
		base = base + "&departureValue=" + f.td_D_City.value;
		base = base + "&destination=" + f.td_A_City.value;
		base = base + "&destinationValue=" + f.td_A_City.value;
		base = base + "&departureDate_day=" + f.td_D_Day.value;
		base = base + "&departureDate_month=" + (parseInt(f.td_D_Month.value.substring(4,6)));
		base = base + "&departureDate_year=" + f.td_D_Month.value.substring(0,4);
		base = base + "&destinationDate_day=" + f.td_R_Day.value;
		base = base + "&destinationDate_month=" + (parseInt(f.td_D_Month.value.substring(4,6)));
		base = base + "&destinationDate_year=" + f.td_R_Month.value.substring(0,4);
		base = base + "&adults=" + f.td_select_adt.value;
		base = base + "&children=" + f.td_select_chd.value;
		base = base + "&infants=" + f.td_select_inf.value;
		window.document.searchForm.url.value = base;
		window.document.searchForm.submit();
	}
	else if ( tipo == 7 ) //eBookers
	{
		base = "http://www.ebookers.es/afo/flights/buscando.html";
		
		if (f.td_chkOneWay[0].checked)
			base = base  + "?TYPE=R";
		else
			base = base  + "?TYPE=O";
		base = base  + "&SID=RTi7uwrfNGgAACZtxB0";
		base = base  + "&checkDIRECT=1";
		base = base  + "&CURRENCY=EUR";
		base = base  + "&DIRECT=1";
		base = base  + "&TIME=0";
		base = base  + "&RTIME=0";
		base = base  + "&COS=Y";
		base = base  + "&LDEP=" + f.td_D_City.value;
		base = base  + "&LARR=" + f.td_A_City.value;
		base = base  + "&DAY_DATE=" + f.td_D_Day.value;
		base = base  + "&MONTH_DATE=" + f.td_D_Month.value.substring(0,4)+f.td_D_Month.value.substring(4,6);
		base = base  + "&DAY_RDATE=" + f.td_R_Day.value;
		base = base  + "&MONTH_RDATE=" + f.td_R_Month.value.substring(0,4)+f.td_R_Month.value.substring(4,6);
		base = base  + "&PAX0=" + f.td_select_adt.value;
		base = base  + "&PAX1=" + f.td_select_chd.value;
		base = base  + "&PAX2=" + f.td_select_inf.value;
		
		window.document.fform1.url.value = base;
		window.document.fform1.submit();
	}
	else if ( tipo == 8 ) //Rumbo
	{
		if (f.td_chkOneWay[0].checked)
			window.document.RUMBO_AIR.td_TRIP_TYPE.value = "R";
		else
			window.document.RUMBO_AIR.td_TRIP_TYPE.value = "O";

        window.document.RUMBO_AIR.td_DEPARTURE_DESC_LOC.value = f.td_D_City.value;
        window.document.RUMBO_AIR.td_B_LOCATION_IN.value = f.td_D_City.value;
        window.document.RUMBO_AIR.td_ARRIVAL_DESC_LOC.value = f.td_A_City.value;
        window.document.RUMBO_AIR.td_E_LOCATION_IN.value = f.td_A_City.value;
        window.document.RUMBO_AIR.td_D_DATE.value = f.td_D_Month.value.substring(0,4)+f.td_D_Month.value.substring(4,6)+f.td_D_Day.value+'0000';
        window.document.RUMBO_AIR.td_R_DATE.value = f.td_R_Month.value.substring(0,4)+f.td_R_Month.value.substring(4,6)+f.td_R_Day.value+'0000';
        window.document.RUMBO_AIR.td_fe_dia.value = f.td_D_Day.value;
        window.document.RUMBO_AIR.td_fe_mesanyo.value = f.td_D_Month.value.substring(0,4)+f.td_D_Month.value.substring(4,6);
        window.document.RUMBO_AIR.td_fs_dia.value = f.td_R_Day.value;
        window.document.RUMBO_AIR.td_fs_mesanyo.value = f.td_R_Month.value.substring(0,4)+f.td_R_Month.value.substring(4,6);
        window.document.RUMBO_AIR.td_N_ADULT.value = f.td_select_adt.value;
        window.document.RUMBO_AIR.td_N_CHILD.value = f.td_select_chd.value;
        window.document.RUMBO_AIR.td_N_INFANT.value = f.td_select_inf.value;
		window.document.RUMBO_AIR.submit();
	}
	else if ( tipo == 9 ) //viajar
	{
		if (f.td_chkOneWay[0].checked)
			window.document.RUMBO_AIR.td_TRIP_TYPE.value = "R";
		else
			window.document.RUMBO_AIR.td_TRIP_TYPE.value = "O";

        window.document.RUMBO_AIR.td_DEPARTURE_DESC_LOC.value = f.td_D_City.value;
        window.document.RUMBO_AIR.td_B_LOCATION_IN.value = f.td_D_City.value;
        window.document.RUMBO_AIR.td_ARRIVAL_DESC_LOC.value = f.td_A_City.value;
        window.document.RUMBO_AIR.td_E_LOCATION_IN.value = f.td_A_City.value;
        window.document.RUMBO_AIR.td_D_DATE.value = f.td_D_Month.value.substring(0,4)+f.td_D_Month.value.substring(4,6)+f.td_D_Day.value+'0000';
        window.document.RUMBO_AIR.td_R_DATE.value = f.td_R_Month.value.substring(0,4)+f.td_R_Month.value.substring(4,6)+f.td_R_Day.value+'0000';
        window.document.RUMBO_AIR.td_fe_dia.value = f.td_D_Day.value;
        window.document.RUMBO_AIR.td_fe_mesanyo.value = f.td_D_Month.value.substring(0,4)+f.td_D_Month.value.substring(4,6);
        window.document.RUMBO_AIR.td_fs_dia.value = f.td_R_Day.value;
        window.document.RUMBO_AIR.td_fs_mesanyo.value = f.td_R_Month.value.substring(0,4)+f.td_R_Month.value.substring(4,6);
        window.document.RUMBO_AIR.td_N_ADULT.value = f.td_select_adt.value;
        window.document.RUMBO_AIR.td_N_CHILD.value = f.td_select_chd.value;
        window.document.RUMBO_AIR.td_N_INFANT.value = f.td_select_inf.value;
		window.document.RUMBO_AIR.submit();
	}
	else if ( tipo == 10 ) //Muchoviaje
	{
		if (f.td_chkOneWay[0].checked)
			window.document.vuelosMV.action = window.document.vuelosMV.action + "IDA=0";
		else
			window.document.vuelosMV.action = window.document.vuelosMV.action + "IDA=1";
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&HR=";
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&HS=";
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&O=" + f.td_D_City.value;
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&D=" + f.td_A_City.value;
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&FECS=" + f.td_D_Day.value +"../default1.htm"+ f.td_D_Month.value.substring(4,6) +"../default1.htm"+ f.td_D_Month.value.substring(0,4);
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&FECV=" + f.td_R_Day.value +"../default1.htm"+ f.td_R_Month.value.substring(4,6) +"../default1.htm"+ f.td_R_Month.value.substring(0,4);
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&NA=" + f.td_select_adt.value;
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&NN=" + f.td_select_chd.value;
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&NB=" + f.td_select_inf.value;
		window.document.vuelosMV.submit();
	}
}

function getDaysMonth(month, year){
	var arrDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if(isLeapYear(year) && month==1) return 29;
	else return arrDays[month];
}

function getMes(m) {
	var arrMonthNames = ["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"];
	return arrMonthNames[m];
}

function completeDays2(comboType){
	var f = getAirEntryForm();
	
	// Vide la liste si des options sont déja présentes.
	var size = eval("f.list_" + comboType + "_Day.length;");
	for (var i=size; i >= 0;i--) {
		eval("f.list_" + comboType + "_Day.options[" + i +"] = null;");
	}

	var month = eval("f.td_" + comboType + "_Month.value.substring(4) - 1;");
	var year = eval("f.td_" + comboType + "_Month.value.substring(0,4);");

	var numDays = getDaysMonth(month, year);

	//rellenar dias
	for (var i=1;i< numDays+1;i++) {
		var newDay = new Option(i,(i<10?"0"+i:i));
		eval("f.list_" + comboType + "_Day[f.list_" + comboType + "_Day.length] = newDay;");
	}
}

function completeMonths2() {
	var myDate = new Date();

	var f = getAirEntryForm();

	for (var i=0; i < 10;i++) {
		f.td_D_Month.options[0] = null;
		f.td_R_Month.options[0] = null;
	}

	for (var i=0;i<10;i++) {
		var monthIndex = myDate.getMonth()+i <= 11?myDate.getMonth()+i:myDate.getMonth()+i-12;
		var strMonth = getMes(monthIndex);
		var year = (myDate.getMonth() > monthIndex?myDate.getFullYear()+1:myDate.getFullYear());
		var newMonthD = new Option(strMonth + " " + year,year+""+((monthIndex+1)<10?"0"+(monthIndex+1):(monthIndex+1)));
		var newMonthR = new Option(strMonth + " " + year,year+""+((monthIndex+1)<10?"0"+(monthIndex+1):(monthIndex+1)));
		f.td_D_Month[f.td_D_Month.length] = newMonthD;
		f.td_R_Month[f.td_R_Month.length] = newMonthR;
	}
}

function initDate(initDays) {
	var myDate = new Date();
	var f = getAirEntryForm();
	
	//completeMonths2();
	//completeDays2("D");
	//completeDays2("R");

	var initDMonth = myDate.getMonth();
	var initRMonth = myDate.getMonth();
	var initDDay = myDate.getDate() + initDays;
	
	//Si pasamos del maximo de dias del mes actual
	if (initDDay > f.FlySearchUserControl_ddlDayFrom.options.length) {
		initDDay = initDDay - f.FlySearchUserControl_ddlDayFrom.options.length;
		initDMonth = initDMonth + 1;
		initRMonth = initRMonth + 1;
	}

	var initRDay = initDDay + 1;
	if (initRDay > f.FlySearchUserControl_ddlDayTo.options.length) {
		initRDay = initRDay - f.FlySearchUserControl_ddlDayTo.options.length;
		initRMonth = initRMonth + 1;
	}
	
	var year = myDate.getYear().toString().substring(2,4);
	f.dateeedep.value = initDDay + "/" + initDMonth + "/" + year;
	f.dateeeret.value = initRDay + "/" + initRMonth + "/" + year; 
	
//	// Le sumamos uno a los initMonths, ya que el 0 corresponde a enero
//	setDateCalendar(initDDay, initDMonth + 1, "D", false);
//	setDateCalendar(initRDay, initRMonth + 1, "R", false);
//	changeDateField2("D");
//	changeDateField2("R");
}

function Check(){
	var f=document.forms['AIR_ENTRY_FORM'];
		var dYearMonthValue = f.td_D_Month.value;
		var dDayValue = f.td_D_Day.value;
		var dTimeIndex = f.td_D_Time.selectedIndex;

		var departureDate = new Date(dYearMonthValue.substring(0,4), parseInt(dYearMonthValue.substring(4,6),10)-1, dDayValue, dTimeIndex-1, 0, 0);
	var today=new Date();
	today.setTime(today.getTime()+(1000*60*60*24*3));
	today.setHours(7);
	alert(departureDate);
	alert(today);
	if(departureDate < today)
	{
		if(!confirm("Recuerda que sólo podrás hacer reservas con, al menos, 3 días de antelación al día de viaje"))
			return false;
	}
	return true;
}
function oneWay(oneway) {
	var f = getAirEntryForm();
	
	/*
	f.td_TripType.value = oneway?'1':'2';

	f.FlySearchUserControl_ddlDayTo.style.visibility = oneway?"hidden":"visible";
	f.FlySearchUserControl_ddlMonthTo.style.visibility = oneway?"hidden":"visible";
	f.ano_list.style.visibility = oneway?"hidden":"visible";
	
	f.f_trigger_retour.visibility = oneway?"hidden":"visible";
	
	//f.fecha_llegada.visibility = oneway?"hidden":"visible";
*/

	document.getElementById('tr_regresso').style.visibility = oneway?"hidden":"visible";
	
	
	document.busqueda.ida.value = oneway?"1":"2";
	
/*	
	document.getElementById('txtFecha1').style.visibility = oneway?"hidden":"visible";
	document.getElementById('txtFecha2').style.visibility = oneway?"hidden":"visible";
*/
}

function getAirEntryForm() {

	var f;
	if (navigator.userAgent.indexOf("MSIE") >= 0) {
		for (var i=0;i < document.forms.length;i++) {
			if (document.forms[i].name == "AIR_ENTRY_FORM") {
				f=document.forms[i];
			}
		}
	} else {
		f=document.forms["AIR_ENTRY_FORM"];
	}

	return f;
}

function changeDateField2(dateType){
	var f = getAirEntryForm();
	eval("f.td_" + dateType + "_Date.value = f.td_" + dateType + "_Day.value + '../default1.htm' + f.td_" + dateType + "_Month.value.substring(4) + '../default1.htm' + f.td_" + dateType + "_Month.value.substring(0,4);");
}

function isLeapYear (year) {
    var leapYear = false;
    if ((year % 400) == 0) {
        leapYear = true;
    } else if ((year % 100) == 0) {
        leapYear = false;
    } else if ((year % 4) == 0) {
        leapYear = true;
    } else {
        leapYear =false;
    }
    return leapYear;
}


function getDaysMonth(month, year){
	var arrDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if(isLeapYear(year) && month==1) return 29;
	else return arrDays[month];
}


function completeDays2(comboType){
	var f = getAirEntryForm();

	var size = eval("f.td_" + comboType + "_Day.length;");
	for (var i=size; i >= 0;i--) {
		eval("f.td_" + comboType + "_Day.options[" + i +"] = null;");
	}

	var month = eval("f.td_" + comboType + "_Month.value.substring(4) - 1;");
	var year = eval("f.td_" + comboType + "_Month.value.substring(0,4);");

	var numDays = getDaysMonth(month, year);

	//rellenar dias
	for (var i=1;i < numDays+1;i++) {
		var newDay = new Option(i,(i<10?"0"+i:i));
		eval("f.td_" + comboType + "_Day[f.td_" + comboType + "_Day.length] = newDay;");
	}
}

function setDateCalendar(day, month, typeDate, blnChangeOtherDate){
	var f = getAirEntryForm();
	month = Number(month);
	day = Number(day);	
	cmbDay = eval("f.list_"+ typeDate + "_Day");
	cmbMonth = eval("f.list_"+typeDate+ "_Month");
	cmbDate = eval("f.td_" + typeDate + " _Date");

	var temp = eval("f.td_"+typeDate+"_Day");
	year = temp.value.substring(0,4);
//	year = Number(cmbMonth.value.substring(0,4));

	for (var i=0;i < cmbMonth.options.length;i++){
		if (Number(cmbMonth.options[i].value.substring(4)) == month) {
			cmbMonth.selectedIndex = i;
		}
	}

	//Si cambia el numero de dias que tiene el mes rellenamos de nuevo el combo
	if (getDaysMonth(month-1, year) != cmbDay.options.length) {
		completeDays2(typeDate);
	}
	if (day-1 >= cmbDay.options.length) {
		cmbDay.selectedIndex = cmbDay.options.length-1;
	} else {
		cmbDay.selectedIndex = day-1;
	}
	changeDateField2(typeDate);

	var dDate = f.td_D_Month.value.substring(0,4) + f.td_D_Month.value.substring(4) + f.td_D_Day.value;
	var rDate = f.td_R_Month.value.substring(0,4) + f.td_R_Month.value.substring(4) + f.td_R_Day.value;

	if (blnChangeOtherDate){
		if ("D" == typeDate && dDate > rDate) {
			if (f.td_D_Day.selectedIndex == f.td_D_Day.options.length - 1) {
				month = month + 1;
				day = 1;
			} else {
				day = day + 1;
			}
			setDateCalendar(day,month,"R",false);
		} else if ("R" == typeDate && rDate < dDate) {
			setDateCalendar(day,month,"D",false);
		}
	}
}

function setCmbDate(typeDate, blnChangeOtherDate){
	var f = getAirEntryForm();

	cmbDay = eval("f.td_"+typeDate+"_Day");
	cmbMonth = eval("f.td_"+typeDate+"_Month");
	cmbDate = eval("f.td_"+typeDate+"_Date");

	var day = Number(cmbDay.value);
	var month = Number(cmbMonth.value.substring(4));

	setDateCalendar(day, month, typeDate, blnChangeOtherDate);
}

function cambiarProducto(epi,tipo)
{
	var f = getAirEntryForm();
	if(tipo == 5) // viajar.com
	{	f.idmarchand.value="19";
		f.action = "../marchand.php.htm";
		f.td_select_inf.style.visibility = "visible";
	} else if(tipo == 1)  // eDreams
	{
		f.idmarchand.value="9";
		f.td_select_inf.style.visibility = "visible";
		f.action = "../marchand.php.htm";
	} else if(tipo == 3) // TerminalA
	{
		f.action = "http://clk.tradedoubler.com/click?p=20683" + epi + "&amp;a=1139857&g=875450&amp;url=http://www.terminala.com/VuelosAfiliados.aspx";
		f.td_select_inf.value = 0;
	} else if(tipo == 4)  // LASTMINUTE 
	{
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?p=21645" + epi + "&a=1233488&g=12882553&url=http://www.es.lastminute.com/lmn/lfe/flights/search/search_helper.jhtml?_DARGS=%2Flmn%2Flfe%2Fflights%2Fsearch%2Fsearch.jhtml.1";
	} else if(tipo == 2) // Atrapalo
	{
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?p=31881" + epi + "&a=943541&g=16194830&url=http://www.atrapalo.com/vuelos/index.php";
	}
}

// Functions du form 
	function checkClickable() {
    	if (document.f.origen.options[document.f.origen.selectedIndex].value != "0")
        	document.location = document.f.origen.options[document.f.origen.selectedIndex].value;
    }

	function busquedaVuelos(url,origen) {
    	if (document.f.origen.options[document.f.origen.selectedIndex].value != "0" &&
        	document.f.dest.options[document.f.dest.selectedIndex].value != "0")
        	document.location = url + '../Wc21172748831b.htm' + origen + '&destino=' + document.f.dest.options[document.f.dest.selectedIndex].value;
    }

	function popUp(URL) {
	    day = new Date();
	    id = day.getTime();
	    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=360,height=350,left = 100,top = 100');");
	}


// from le goyen

function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}

function couleur(obj) {
     obj.style.backgroundColor = "#FFFFFF";
}

// Fin des scripts from Le goyen


function fill_field()
{
	var MonTableau = new Array();
	MonTableau["01"] = "enero";
	MonTableau["02"] ="febrero";
	MonTableau["03"] ="marzo";
	MonTableau["04"] ="abril";
	MonTableau["05"] ="mayo";
	MonTableau["06"] ="junio";
	MonTableau["07"] ="julio";
	MonTableau["08"] ="agosto";
	MonTableau["09"] ="septiembre";
	MonTableau["10"] ="octubre";
	MonTableau["11"] ="noviembre";
	MonTableau["12"] ="diciembre";
	window.document.AIR_ENTRY_FORM.td_D_Day.value = window.document.AIR_ENTRY_FORM.dateeedep.value.substring(0,2);
	window.document.AIR_ENTRY_FORM.td_D_Month.value = "20"+ window.document.AIR_ENTRY_FORM.dateeedep.value.substring(6,8)+window.document.AIR_ENTRY_FORM.dateeedep.value.substring(3,5);
	window.document.AIR_ENTRY_FORM.D_Month_num.value = window.document.AIR_ENTRY_FORM.dateeedep.value.substring(3,5);
}


function fill_field_retour()
{
	var MonTableau = new Array();
	MonTableau["01"] = "enero";
	MonTableau["02"] ="febrero";
	MonTableau["03"] ="marzo";
	MonTableau["04"] ="abril";
	MonTableau["05"] ="mayo";
	MonTableau["06"] ="junio";
	MonTableau["07"] ="julio";
	MonTableau["08"] ="agosto";
	MonTableau["09"] ="septiembre";
	MonTableau["10"] ="octubre";
	MonTableau["11"] ="noviembre";
	MonTableau["12"] ="diciembre";
	
	window.document.AIR_ENTRY_FORM.td_R_Day.value = window.document.AIR_ENTRY_FORM.dateeeret.value.substring(0,2);
	window.document.AIR_ENTRY_FORM.td_R_Month.value = "20" + window.document.AIR_ENTRY_FORM.dateeeret.value.substring(6,8)+window.document.AIR_ENTRY_FORM.dateeeret.value.substring(3,5);
	window.document.AIR_ENTRY_FORM.R_Month_num.value = window.document.AIR_ENTRY_FORM.dateeeret.value.substring(3,5);
}

function Day_todateee(typedate)
{
	// Copie le numéro du jour dans la case dateeee	sur changement d'une liste jour 
	// Le paramètre typedate doit être 'D' ou 'R' pour depart et retour	
	var f = getAirEntryForm();
	var temp = new String();

	if(typedate=='D')
	{
		temp=f.FlySearchUserControl_ddlYearFrom.value.substring(2,4);
		
		if(f.FlySearchUserControl_ddlDayFrom.value>28 && f.FlySearchUserControl_ddlDayFrom.value > getDaysInMonth(f.FlySearchUserControl_ddlMonthFrom.value,temp))
		{
			jour = 1;
		}
		else
        {		    
			jour = f.FlySearchUserControl_ddlDayFrom.value;
		}
		
		if(jour<10){jour = "0" + jour;}

		mois = f.FlySearchUserControl_ddlMonthFrom.value;
		if(mois<10){mois = "0" + mois;}
		
		//f.dateeedep.value = jour + "../default1.htm" + mois + "../default1.htm" + temp;				
		f.dateeedep.value = jour + "/" + mois + "/" + temp;
	}
	else
	{
		if(typedate=='R')
		{
			temp=f.FlySearchUserControl_ddlYearTo.value.substring(2,4);
		
			if(f.FlySearchUserControl_ddlDayTo.value>28 && f.FlySearchUserControl_ddlDayTo.value > getDaysInMonth(f.FlySearchUserControl_ddlMonthTo.value,temp))
			{
				jour = 1;
			}
			else
			{
				jour = f.FlySearchUserControl_ddlDayTo.value;
			}
			
			if(jour<10){jour = "0" + jour;}
	
			mois = f.FlySearchUserControl_ddlMonthTo.value;
			if(mois<10){mois = "0" + mois;}
			
			//f.dateeeret.value = jour + "../default1.htm" + mois + "../default1.htm" + temp;
			f.dateeeret.value = jour + "/" + mois + "/" + temp;
		}
	}	
}

function update_lists(typedate)
{
	// Function sert à mettre à jour les listes formant les dates a partir de 
	// la boite cachée dateee contenant la date issue du calendrier (boite centrale du sys de date)
	// Le paramètre typedate doit être 'D' ou 'R' pour depart et retour
	
	var f = getAirEntryForm();
	var now = new Date();
    var year = 0;
    
	if(typedate=='D')
	{
	    year = parseInt('20' + document.AIR_ENTRY_FORM.dateeedep.value.substring(6, 8));
	    
		f.FlySearchUserControl_ddlDayFrom.options[f.dateeedep.value.substring(0, 2) - 1].selected = true;
		f.FlySearchUserControl_ddlMonthFrom.options[f.dateeedep.value.substring(3, 5) - 1].selected = true;
		f.FlySearchUserControl_ddlYearFrom.options[year - now.getYear()].selected = true;
		
		// On rafraichi le nombre de jours de la liste jour en fonction du nouveau mois saisi
		_adjustDaysInMonth('salida', f.FlySearchUserControl_ddlMonthFrom.value, year);
	}
	
	if(typedate=='R')
	{
	    year = parseInt('20' + document.AIR_ENTRY_FORM.dateeeret.value.substring(6, 8));
	    
		f.FlySearchUserControl_ddlDayTo.options[f.dateeeret.value.substring(0, 2) - 1].selected = true;
		f.FlySearchUserControl_ddlMonthTo.options[f.dateeeret.value.substring(3, 5) - 1].selected = true;
		f.FlySearchUserControl_ddlYearTo.options[year - now.getYear()].selected = true;

		// On rafraichi le nombre de jours de la liste jour en fonction du nouveau mois saisi		
		_adjustDaysInMonth('llegada', f.FlySearchUserControl_ddlMonthTo.value, '20' + document.AIR_ENTRY_FORM.dateeeret.value.substring(6,8));
	}
}

function MyGetMonth()
{
	var datedujour, date, mois, mois1, jour, jour1, an;
	datedujour = new Date();
	date = datedujour.getDate();
	mois = datedujour.getMonth() + 1;
	return mois;
}

function MyGetYear()
{
	var datedujour, date, mois, mois1, jour, jour1, an;
	
	datedujour = new Date();
	date = datedujour.getDate();
	an = datedujour.getFullYear()
	return an;
}

function getDaysInMonth(m, y)
{	
	var f = getAirEntryForm();

	if(m[0]=='0') // Si c'est un mois inférieur à 10, on enlève le 0 devant 
	{
		m = m.slice(1,2);
		m[0]=null;
	}
	monthdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if (m != 2) {
		return monthdays[m];
	} else {
		return ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0 ? 29 : 28);
	}
}

function _adjustDaysInMonth(typedate, month, year)
{
	var f = getAirEntryForm();
	var daysForThisSelection = getDaysInMonth(month, year);
	
	var prevDaysInSelection = f.FlySearchUserControl_ddlDayFrom.length;

	if(typedate == "salida" || typedate == "all")
	{	
		if (prevDaysInSelection > daysForThisSelection)
		{
			for (i=0; i<(prevDaysInSelection - daysForThisSelection); i++)
			{
				f.FlySearchUserControl_ddlDayFrom.options[f.FlySearchUserControl_ddlDayFrom.options.length - 1] = null
			}
		}
		if (daysForThisSelection > prevDaysInSelection)
		{
			var prevLastDay = f.FlySearchUserControl_ddlDayFrom.options.length;
			for( i = prevLastDay+1; i <= daysForThisSelection; i++ )
			{
				var newOption = new Option( i, i );
				var optionsColl = f.FlySearchUserControl_ddlDayFrom.options;
				optionsColl[optionsColl.length] = newOption;
			}
		}
		if (f.FlySearchUserControl_ddlDayFrom.selectedIndex < 0)
			f.FlySearchUserControl_ddlDayFrom.selectedIndex == 0;
	}

	if(typedate == "llegada" || typedate == "all")
	{
		var prevDaysInSelection = f.FlySearchUserControl_ddlDayTo.length;
		
		if (prevDaysInSelection > daysForThisSelection)
		{
			for (i=0; i<(prevDaysInSelection - daysForThisSelection); i++)
			{
				f.FlySearchUserControl_ddlDayTo.options[f.FlySearchUserControl_ddlDayTo.options.length - 1] = null
			}
		}
		if (daysForThisSelection > prevDaysInSelection)
		{
			var prevLastDay = f.FlySearchUserControl_ddlDayTo.options.length;
			for( i = prevLastDay+1; i <= daysForThisSelection; i++ )
			{
				var newOption = new Option( i, i );
				var optionsColl = f.FlySearchUserControl_ddlDayTo.options;
				optionsColl[optionsColl.length] = newOption;
			}
		}
		if (f.FlySearchUserControl_ddlDayTo.selectedIndex < 0)
			f.FlySearchUserControl_ddlDayTo.selectedIndex == 0;
	}

}

function MyInit()
{
	var present_jour = new Date();	
	var present_month = new Date();
	
	present_month = getMonth() + 1;
	
	f.FlySearchUserControl_ddlDayFrom.selectedIndex = present_jour + 1; // Pour séléctionner le bon jour dans la liste.
	f.FlySearchUserControl_ddlMonthFrom.selectedIndex = present_month;

	f.FlySearchUserControl_ddlDayTo.selectedIndex = present_jour + 1; // Pour séléctionner le bon jour dans la liste.
	f.FlySearchUserControl_ddlMonthTo.selectedIndex = present_month + 1;
}

function _writeDayOptions(typedate, month, year)
{
	// Le mois passé en paramètre va nous servir a trouver le nombre de jours dans ce mois.
	// Le type date servira pour déterminer si il faut remplir la liste de date départ ou retour.
	var f = getAirEntryForm();

// Si le mois n'a pas été n'est pas passé en paramètre, alors on utilise le mois en cours.
	if(month == "13" || month=="") {month = MyGetMonth();}
	
// Si l'année n'a pas été n'est pas passé en paramètre, alors on utilise l'année en cours.
	if(year == ""){year = MyGetYear();}

//Cherche le nombre de jours dans une journée.
	
	var month_int = parseInt(month,10);

	nbday_month = getDaysInMonth(month_int, year);
	
//	f.tosee.value=month_int + "../default1.htm" + year + " // " + nbday_month;

	if(typedate=="salida" || typedate=="all")
	{
// vide la liste avant de la remplir.
		/*
		for(val in f.FlySearchUserControl_ddlDayFrom.options){val=null;}
		*/
	//	for(i=1; i<=f.FlySearchUserControl_ddlDayFrom.options.length; i++)
/*
	do
	{
			f.FlySearchUserControl_ddlDayFrom.options[i] = null;
			i++;
	}
	while(f.FlySearchUserControl_ddlDayFrom.options.length != 0)
*/

// Remplissage
		for( i=1; i <= nbday_month; i++ )
		{
			if(i<10){nouvel_element = new Option('0'+i,i);}
			else{nouvel_element = new Option(i,i);}
			f.FlySearchUserControl_ddlDayFrom.options[f.FlySearchUserControl_ddlDayFrom.length] = nouvel_element;
		}
	}
	
	if(typedate=="llegada" || typedate=="all")
	{
		for( i=1; i <= nbday_month; i++ )
		{
			if(i<10){nouvel_element = new Option('0'+i,i);}
			else{nouvel_element = new Option(i,i);}
			f.FlySearchUserControl_ddlDayTo.options[f.FlySearchUserControl_ddlDayTo.length] = nouvel_element;
		}
	}
}



// Function pour mettre à jour la date retour sur changement de la date départ

function maj_retour(typedatemaj)
{
	var f = getAirEntryForm();
	// Avant d'éxécuter de mettre à jour vérifier si il y a lieu de changer la date
	
	var salida  = f.dateeedep.value.split('../default1.htm');
	var regresso = f.dateeeret.value.split('../default1.htm');
	var temoin=0;
	
	if(typedatemaj == "D")
	{
		var origine = f.dateeedep.value;
//f.tosee.value = parseInt(salida[1],10) + ">=" + parseInt(regresso[1],10);
		
		if(parseInt(salida[2],10) > parseInt(regresso[2],10)){temoin = 1; } // Test pour les années 
		else
		{
			if(parseInt(salida[1],10) > parseInt(regresso[1],10)){temoin = 1;} // Test pour les mois
				else
				{
					if(parseInt(salida[0],10) >= parseInt(regresso[0],10)){temoin = 1;}// Test pour les jours
				}
		}
		if(temoin==1)
		{
			newdateretour = add_days(origine);
			f.dateeeret.value = newdateretour; 
			fill_field_retour(); 
			update_lists('R'); 
		}
	}
	else
	{		
		if(parseInt(salida[2],10) > parseInt(regresso[2],10)){temoin = 1;}
		else
		{
			if(parseInt(salida[1],10) > parseInt(regresso[1],10)){temoin = 1;}
				else
				{
					if(parseInt(salida[0],10) > parseInt(regresso[0],10)){temoin = 1;}
				}
		}
		if(typedatemaj == "R")
		{
			if(temoin==1)
			{
				var origine = f.dateeeret.value;
				newdatealler = prev_days(origine);
				f.dateeedep.value = newdatealler;
				fill_field();
				update_lists('D');
			}
		}
	}
}

function add_days(origine) // Cette function ajoute un nombre de jours à une date.
{
	var f = getAirEntryForm();
	var temp = origine.split("../default1.htm");
	var jour = parseInt(temp[0],10);
	var mois = parseInt(temp[1],10);
	var anne = parseInt(temp[2],10);  // Suprimer la [1] pour compatibilité du code avec 2010 
//	/!\  ATTENTION : ParseInt ne fonctionne pas pour les années.
	
	
	
	var nbjourmonth = getDaysInMonth(mois, anne);
	jour = jour + 1;
	if (jour > nbjourmonth)
	{
		jour = 1;
		mois = mois + 1;
		if( mois > 12 )
		{
			anne = anne + 1;
			mois = 1;
		}
	}
	
	if(jour<10){ var dadate = "0" + jour + "../default1.htm";}else{ var dadate = jour + "../default1.htm";}
	if(mois<10){ dadate = dadate + "0" + mois + "../default1.htm";}else{ dadate = dadate + mois + "../default1.htm";}
	if(anne<10){dadate = dadate + "0" + anne ;}else{/* dadate = dadate + anne; */}
	return dadate;
}

function prev_days(origine) // Cette function ajoute un nombre de jours à une date.
{
	var f = getAirEntryForm();
	var temp = origine.split("../default1.htm");
	var jour = parseInt(temp[0],10);
	var mois = parseInt(temp[1],10);
	var anne = parseInt(temp[2],10);
	var nbjourmonth = getDaysInMonth(mois, anne);
	
	jour = jour - 1;
	
	if ( jour < 1 ) // Si on passe au mois précédent
	{
		mois = mois - 1;
		var nbjourmonth = getDaysInMonth(mois, anne);
		jour = nbjourmonth;
		
		if( mois < 1 )
		{
			anne = anne - 1;
			mois = 12;
		}
	}
	if(jour<10){var dadate = "0" + jour + "../default1.htm";} else{var dadate = jour + "../default1.htm";}
	if(mois<10){ dadate = dadate + "0" + mois + "../default1.htm";} else{ dadate = dadate + mois + "../default1.htm";}
	if(anne<10){ dadate = dadate + "0" + anne;} else { dadate = dadate + anne;}
	return dadate;
}




// Script "Ajax" pour faire apparaître le jour de la semaine.

function writediv(texte,fecha)
     {
     document.getElementById(fecha).innerHTML = texte;
     }

function jour_date(date,fecha)
{
	if(texte = file('../Wc8e4f8f3ef99.htm'+escape(date)))
	{
		   writediv('<span style="color:#cc0000"><strong>'+texte+' </strong></span>',fecha);
	}         
}

function file(fichier)
{
     if(window.XMLHttpRequest) // FIREFOX
          xhr_object = new XMLHttpRequest();
     else if(window.ActiveXObject) // IE
          xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
     else
          return(false);
     
     window.alert(fichier);
     
     xhr_object.open("GET", fichier, false);
     xhr_object.send(null);
     if(xhr_object.readyState == 4) return(xhr_object.responseText);
     else return(false);
}