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 doBigflightSearch() {
	var providers_list = Array(8,1,4,7,15,13,3,2,5,19,21,22);
	var f = getAirEntryForm();

	for (var i=0; i <= (providers_list.length-1); i++) {
		name = "providers_id_" + (i+1);
		eval("j=f." + name + ".checked");
		if (j) {
			if(!doFlightSearch(providers_list[i])){
				return false;
			}

		}
	}
}

function trim(string) {
	return string.replace(/^\s*|\s*$/g, "");
}

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();

	departure_city = '';
	arrival_city = '';

	var resultat = f.td_D_City.value.search(/,/);
	if(resultat != -1){
		departure_city = document.AIR_ENTRY_FORM.iata_depart.value;
	}else{
		departure_city = f.td_D_City.value;
	}

	var resultat = f.td_A_City.value.search(/,/);
	if(resultat != -1){
		arrival_city = document.AIR_ENTRY_FORM.iata_arrivee.value;
	}else{
		arrival_city = f.td_A_City.value;
	}

	if(document.AIR_ENTRY_FORM.iata_arrivee.value != ''){
		arrival_city = document.AIR_ENTRY_FORM.iata_arrivee.value;
	}
	if(document.AIR_ENTRY_FORM.iata_depart.value != ''){
		departure_city = document.AIR_ENTRY_FORM.iata_depart.value;
	}

	arrival_city = trim(arrival_city);
	departure_city = trim(departure_city);

	if(checkstr!=""){
		alert(checkstr);
		return false;
	}

	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.idmarchand.value="19";
		f.action = "/marchand.php";
		f.submit();
	}
	else if (tipo == 3) //Terminal A
	{
		window.document.TA_frmBuscar.TA_CodigoAfiliado.value = "1139857";
		//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 = departure_city;
		window.document.TA_frmBuscar.TD_TA_CiudadHasta.value = arrival_city;
		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 = departure_city;
		f.td_arrivalCity.value = arrival_city;
		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.idmarchand.value="9";
		f.action = "/marchand.php";
		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 = departure_city;
		window.document.lfe_availability.td_lfe_destination.value = arrival_city;
		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 = departure_city;
		window.document.busqueda.td_destino.value = arrival_city;
		window.document.busqueda.td_salida_trigger.value = f.td_D_Day.value+'/'+f.td_D_Month.value.substring(4,6)+'/'+f.td_D_Month.value.substring(0,4);
		window.document.busqueda.td_regreso_trigger.value = f.td_R_Day.value+'/'+f.td_R_Month.value.substring(4,6)+'/'+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)+'/'+f.td_D_Month.value.substring(4,6)+'/'+f.td_D_Day.value;
		window.document.busqueda.td_fecha_regreso.value = f.td_R_Month.value.substring(0,4)+'/'+f.td_R_Month.value.substring(4,6)+'/'+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=" + departure_city;
		base = base + "&departureValue=" + departure_city;
		base = base + "&destination=" + arrival_city;
		base = base + "&destinationValue=" + arrival_city;
		base = base + "&departureDate_day=" + f.td_D_Day.value;
		base = base + "&departureDate_month=" + (parseInt(f.td_D_Month.value.substring(4,6))-1);
		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))-1);
		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 ){ //logitravel
		window.document.form_logitravel.action = '/marchand.php?';
		window.document.form_logitravel.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=" + departure_city;
		base = base  + "&LARR=" + arrival_city;
		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 = departure_city;
		window.document.RUMBO_AIR.td_B_LOCATION_IN.value = departure_city;
		window.document.RUMBO_AIR.td_ARRIVAL_DESC_LOC.value = arrival_city;
		window.document.RUMBO_AIR.td_E_LOCATION_IN.value = arrival_city;
		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 ) //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=" + departure_city;
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&D=" + arrival_city;
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&FECS=" + f.td_D_Day.value +"/"+ f.td_D_Month.value.substring(4,6) +"/"+ f.td_D_Month.value.substring(0,4);
		window.document.vuelosMV.action = window.document.vuelosMV.action + "&FECV=" + f.td_R_Day.value +"/"+ f.td_R_Month.value.substring(4,6) +"/"+ 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();
	}
	else if ( tipo == 10 ) //Barcelo Viajes
	{
		base = "http://www.barceloviajes.com/sites/all/procesa_peticion_3os.jsp";

		if (f.td_chkOneWay[0].checked)
		base = base  + "?tipo=idavuelta";
		else
		base = base  + "?tipo=ida";
		base = base  + "&origentxt=" + departure_city;
		base = base  + "&destinotxt=" + arrival_city;
		base = base  + "&fida=" + f.td_D_Day.value +"/"+ f.td_D_Month.value.substring(4,6) +"/"+ f.td_D_Month.value.substring(0,4);
		base = base  + "&fvuelta=" + f.td_R_Day.value +"/"+ f.td_R_Month.value.substring(4,6) +"/"+ f.td_R_Month.value.substring(0,4);
		base = base  + "&adultos=" + f.td_select_adt.value;
		base = base  + "&nens=" + f.td_select_chd.value;
		base = base  + "&bebes=" + f.td_select_inf.value;
		base = base  + "&tprod=VUE";
		base = base  + "&form=AIR_ENTRY_FORM";

		window.document.form_barcelo.url.value = base;
		window.document.form_barcelo.submit();
	}
	else if ( tipo == 11 ) //Supersaver
	{

		var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dec");
		customers = f.td_select_adt.value + f.td_select_chd.value + f.td_select_inf.value;
		ninos = f.td_select_chd.value + f.td_select_inf.value;


		base = "http://www.supersaver.es/etravelstore/searchfare?campaign=xmlsearch&txtClass=1&SITENAME=supersaver_es&redirect_server=";

		if (f.td_chkOneWay[0].checked)
		base = base  + "&selOW=false";
		else
		base = base  + "&selOW=true";
		base = base  + "&txtFromCity=" + departure_city;
		base = base  + "&txtToCity=" + arrival_city;
		base = base  + "&txtDepDay=" + f.td_D_Day.value;
		base = base  + "&txtDepMonth=" + months[parseInt(f.td_D_Month.value.substring(4,6))-1] + f.td_D_Month.value.substring(2,4);
		base = base  + "&txtRetDay=" + f.td_R_Day.value;
		base = base  + "&txtRetMonth=" + months[parseInt(f.td_R_Month.value.substring(4,6))-1] + f.td_R_Month.value.substring(2,4);
		base = base  + "&selAdl=" + f.td_select_adt.value;
		base = base  + "&selChd=" + ninos;
		base = base  + "&CUSTOMER=" + customers;

		window.document.form_supersaver.url.value = base;
		window.document.form_supersaver.submit();
	}
	else if ( tipo == 12 ) //ViajesIberia
	{

		base = "http://www.viajesiberia.com/viajesiberia/home/default.aspx?pagdestino=/amadeus/disponibilidad.aspx";
		base = base  + "?utm_medium=CPA&utm_content=Vuelos";
		if (f.td_chkOneWay[0].checked)
		base = base  + "&SoloIdaSV=oVn";
		else
		base = base  + "&SoloIdaSV=on";
		base = base  + "&origenSV=" + departure_city;
		base = base  + "&strOrigen=" + departure_city;
		base = base  + "&destinoSV=" + arrival_city;
		base = base  + "&strDestino=" + arrival_city;
		base = base  + "&fechaIdaSV=" + f.td_D_Day.value +"/"+ f.td_D_Month.value.substring(4,6) +"/"+ f.td_D_Month.value.substring(0,4);
		base = base  + "&fechaVueltaSV=" + f.td_R_Day.value +"/"+ f.td_R_Month.value.substring(4,6) +"/"+ f.td_R_Month.value.substring(0,4);
		base = base  + "&adultos=" + f.td_select_adt.value;
		base = base  + "&ninos=" + f.td_select_chd.value;
		base = base  + "&bebes=" + f.td_select_inf.value;
		window.document.form_viajes.url.value = base;
		window.document.form_viajes.submit();
	}else if ( tipo == 13 ) //Spanair
	{
		if (f.td_chkOneWay[0].checked){
			window.document.form_spanair.action = window.document.form_spanair.action + "spa_triptype=RT";
		}
		else{
			window.document.form_spanair.action = window.document.form_spanair.action + "spa_triptype=OW";
		}
		window.document.form_spanair.action = window.document.form_spanair.action + "&spa_res=N";
		window.document.form_spanair.action = window.document.form_spanair.action + "&spa_origen=" + departure_city;
		window.document.form_spanair.action = window.document.form_spanair.action + "&spa_destino=" + arrival_city;
		window.document.form_spanair.action = window.document.form_spanair.action + "&spa_dida=" + f.td_D_Day.value;
		window.document.form_spanair.action = window.document.form_spanair.action + "&spa_mida=" + f.td_D_Month.value.substring(4,6) +"/"+ f.td_D_Month.value.substring(0,4);
		window.document.form_spanair.action = window.document.form_spanair.action + "&spa_dreg=" + f.td_R_Day.value;
		window.document.form_spanair.action = window.document.form_spanair.action + "&spa_mreg=" + f.td_R_Month.value.substring(4,6) +"/"+ f.td_R_Month.value.substring(0,4);
		window.document.form_spanair.action = window.document.form_spanair.action + "&spa_adt=" + f.td_select_adt.value;
		window.document.form_spanair.action = window.document.form_spanair.action + "&spa_chd=" + f.td_select_chd.value;
		window.document.form_spanair.action = window.document.form_spanair.action + "&spa_bab=" + f.td_select_inf.value;
		//alert(window.document.form_spanair.action);
		//pop(window.document.form_spanair.action+'&q=http://ad.zanox.com/ppc/?9922912C1769566962T&ULP=//www.spanair.com/web/es-es/Buscadores-Partners/Partners-Intermedia/?&idmarchand=72&spa_partner=ZANOX',"Spanair",1024,768);
		window.document.form_spanair.submit();

	}
	else if ( tipo == 14 ) //KLM
	{
		window.document.form_klm.action = window.document.form_klm.action + "origin=" + departure_city;
		window.document.form_klm.action = window.document.form_klm.action + "&destination=" + arrival_city;
		window.document.form_klm.submit();

	}else if( tipo == 15 ) //Vueling
	{

		window.document.form_vueling.action = '/marchand.php?';
		window.document.form_vueling.action = window.document.form_vueling.action+'&m1='+ f.td_D_Month.value.substring(0,4) + f.td_D_Month.value.substring(4,6) +'01' + departure_city + arrival_city;
		if (f.td_chkOneWay[0].checked){
			window.document.form_vueling.action = window.document.form_vueling.action + "&m2=" + f.td_R_Month.value.substring(0,4) + f.td_R_Month.value.substring(4,6)  + '01' + arrival_city + departure_city;
		}
		window.document.form_vueling.action = window.document.form_vueling.action + "&ADULT=" + f.td_select_adt.value;
		window.document.form_vueling.action = window.document.form_vueling.action + "&CHILD=" + f.td_select_chd.value;
		window.document.form_vueling.action = window.document.form_vueling.action + "&INFANT=" + f.td_select_inf.value;
		window.document.form_vueling.submit();
	}else if( tipo == 16 ) //BravoFLy
	{
		window.document.form_bravofly.action = '/marchand.php?';
		if (f.td_chkOneWay[0].checked){
			window.document.form_bravofly.action = window.document.form_bravofly.action + 'roundtrip=true';
			window.document.form_bravofly.action = window.document.form_bravofly.action+'&returnMonthYear='+  f.td_R_Month.value.substring(4,6) + f.td_R_Month.value.substring(0,4);
			window.document.form_bravofly.action = window.document.form_bravofly.action+'&returnDay='+  f.td_R_Day.value;
		}else{
			window.document.form_bravofly.action = window.document.form_bravofly.action + 'roundtrip=false';
		}

		window.document.form_bravofly.action = window.document.form_bravofly.action+'&outboundMonthYear='+  f.td_D_Month.value.substring(4,6) + f.td_D_Month.value.substring(0,4);
		window.document.form_bravofly.action = window.document.form_bravofly.action+'&outboundDay='+  f.td_D_Day.value;
		window.document.form_bravofly.action = window.document.form_bravofly.action + '&departureAirport=' + departure_city;
		window.document.form_bravofly.action = window.document.form_bravofly.action + '&arrivalAirport=' + arrival_city;
		window.document.form_bravofly.action = window.document.form_bravofly.action + "&adults=" + f.td_select_adt.value;
		window.document.form_bravofly.action = window.document.form_bravofly.action + "&childs=" + f.td_select_chd.value;
		window.document.form_bravofly.action = window.document.form_bravofly.action + "&infants=" + f.td_select_inf.value;
		window.document.form_bravofly.submit();
	}else if( tipo == 17 ){ //tuyfly
		window.document.form_tuyfly.action = '/marchand.php?';
		if(f.td_chkOneWay[0].checked){
			window.document.form_tuyfly.action = window.document.form_tuyfly.action + 'RadioButtonMarketStructure=RoundTrip';
			window.document.form_tuyfly.action = window.document.form_tuyfly.action + '&Day2=' + f.td_R_Day.value + '&MonthYear2=' + f.td_R_Month.value.substring(4,6) +'-'+ f.td_R_Month.value.substring(0,4);
		}else{
			window.document.form_tuyfly.action = window.document.form_tuyfly.action + 'RadioButtonMarketStructure=OneWay';
		}
		window.document.form_tuyfly.action = window.document.form_tuyfly.action + '&Origin1='+departure_city+'&Destination1='+arrival_city;
		window.document.form_tuyfly.action = window.document.form_tuyfly.action + '&Day1='+f.td_D_Day.value+'&MonthYear1=' + f.td_D_Month.value.substring(4,6) +'-' + f.td_D_Month.value.substring(0,4);
		window.document.form_tuyfly.submit();
		
	}else if( tipo == 18 ){ //airfrance
		window.document.form_airfrance.action = '/marchand.php?';
		if (f.td_chkOneWay[0].checked){
		window.document.form_airfrance.action = window.document.form_airfrance.action + 'td_typeTrajet=2';
		} else {
		window.document.form_airfrance.action = window.document.form_airfrance.action + 'td_typeTrajet=1';
		}
		window.document.form_airfrance.action = window.document.form_airfrance.action + '&td_nbAdults=' + f.td_select_adt.value;
		window.document.form_airfrance.action = window.document.form_airfrance.action + '&td_nbEnfants=' + f.td_select_chd.value;
		window.document.form_airfrance.action = window.document.form_airfrance.action + '&td_aeroportDepart=' + departure_city;
		window.document.form_airfrance.action = window.document.form_airfrance.action + '&td_aeroportArrivee=' + arrival_city;
		window.document.form_airfrance.action = window.document.form_airfrance.action + '&td_jourAller=' + f.td_D_Day.value;
		window.document.form_airfrance.action = window.document.form_airfrance.action + '&td_moisAller=' + f.td_D_Month.value.substring(0,4) + f.td_D_Month.value.substring(4,6);
		window.document.form_airfrance.action = window.document.form_airfrance.action + '&td_jourRetour=' + f.td_R_Day.value;
		window.document.form_airfrance.action = window.document.form_airfrance.action + '&td_moisRetour=' + f.td_R_Month.value.substring(0,4) + f.td_R_Month.value.substring(4,6);
		window.document.form_airfrance.submit();
	}else if( tipo == 19 ){ //expedia
		window.document.form_expedia.action = '/marchand.php?';
		window.document.form_expedia.submit();
	}else if( tipo == 20 ){ //destinia
		window.document.form_destinia.action = '/marchand.php?';
		window.document.form_destinia.submit();
	}else if( tipo == 21 ){ //transavia
		window.document.form_transavia.action = '/marchand.php?';
		window.document.form_transavia.submit();
	}else if( tipo == 22 ){ //govolo
		window.document.form_govolo.action = '/marchand.php?';
		window.document.form_govolo.submit();
	}

	return true;
}

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.list_D_Day.options.length) {
		initDDay = initDDay - f.list_D_Day.options.length;
		initDMonth = initDMonth + 1;
		initRMonth = initRMonth + 1;
	}

	//	var daysToNextSunday;
	//	var dayWeek = myDate.getDay()+initDays;
	//	if (dayWeek > 7) dayWeek = dayWeek - 7;
	//	daysToNextSunday = 7 - dayWeek;
	//	if (daysToNextSunday == 0) daysToNextSunday = 7;

	//	var initRDay = initDDay + daysToNextSunday;
	var initRDay = initDDay + 1;
	if (initRDay > f.list_R_Day.options.length) {
		initRDay = initRDay - f.list_R_Day.options.length;
		initRMonth = initRMonth + 1;
	}
	//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.list_R_Day.style.visibility = oneway?"hidden":"visible";
	f.R_mes_list.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 + '/' + f.td_" + dateType + "_Month.value.substring(4) + '/' + 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";
	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";
	} 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=1423898&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=1139857&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 + 'buscador_vuelos.php?origen=' + 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.D_ano_list.value.substring(2,4);

		if(f.list_D_Day.value>28 && f.list_D_Day.value > getDaysInMonth(f.D_mes_list.value,temp))
		{
			jour = 1;
		}
		else
		{
			jour = f.list_D_Day.value;
		}

		if(jour<10){jour = "0" + jour;}

		mois = f.D_mes_list.value;
		if(mois<10){mois = "0" + mois;}

		f.dateeedep.value = jour + "/" + mois + "/" + temp;

	}
	else
	{
		if(typedate=='R')
		{
			temp=f.R_ano_list.value.substring(2,4);

			if(f.list_R_Day.value>28 && f.list_R_Day.value > getDaysInMonth(f.R_mes_list.value,temp))
			{
				jour = 1;
			}
			else
			{
				jour = f.list_R_Day.value;
			}

			if(jour<10){jour = "0" + jour;}

			mois = f.R_mes_list.value;
			if(mois<10){mois = "0" + mois;}

			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();

	if(typedate=='D')
	{
		f.list_D_Day.options[f.dateeedep.value.substring(0,2)-1].selected = true;
		f.D_mes_list.options[f.dateeedep.value.substring(3,5)-1].selected = true;
		f.D_ano_list.options[f.dateeedep.value.substring(7,8) - 7].selected = true;  // Voir a changer le -7 pour les années.

		// On rafraichi le nombre de jours de la liste jour en fonction du nouveau mois saisi
		_adjustDaysInMonth('salida',f.D_mes_list.value, '20' + document.AIR_ENTRY_FORM.dateeeret.value.substring(6,8));

	}

	if(typedate=='R')
	{
		f.list_R_Day.options[f.dateeeret.value.substring(0,2)-1].selected = true;
		f.R_mes_list.options[f.dateeeret.value.substring(3,5)-1].selected = true;
		f.R_ano_list.options[f.dateeeret.value.substring(7,8)- 7].selected = true;

		_adjustDaysInMonth('llegada',f.R_mes_list.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.list_D_Day.length;

	if(typedate == "salida" || typedate == "all")
	{
		if (prevDaysInSelection > daysForThisSelection)
		{
			for (i=0; i<(prevDaysInSelection - daysForThisSelection); i++)
			{
				f.list_D_Day.options[f.list_D_Day.options.length - 1] = null
			}
		}
		if (daysForThisSelection > prevDaysInSelection)
		{
			var prevLastDay = f.list_D_Day.options.length;
			for( i = prevLastDay+1; i <= daysForThisSelection; i++ )
			{
				var newOption = new Option( i, i );
				var optionsColl = f.list_D_Day.options;
				optionsColl[optionsColl.length] = newOption;
			}
		}
		if (f.list_D_Day.selectedIndex < 0)
		f.list_D_Day.selectedIndex == 0;
	}

	if(typedate == "llegada" || typedate == "all")
	{
		var prevDaysInSelection = f.list_R_Day.length;

		if (prevDaysInSelection > daysForThisSelection)
		{
			for (i=0; i<(prevDaysInSelection - daysForThisSelection); i++)
			{
				f.list_R_Day.options[f.list_R_Day.options.length - 1] = null
			}
		}
		if (daysForThisSelection > prevDaysInSelection)
		{
			var prevLastDay = f.list_R_Day.options.length;
			for( i = prevLastDay+1; i <= daysForThisSelection; i++ )
			{
				var newOption = new Option( i, i );
				var optionsColl = f.list_R_Day.options;
				optionsColl[optionsColl.length] = newOption;
			}
		}
		if (f.list_R_Day.selectedIndex < 0)
		f.list_R_Day.selectedIndex == 0;
	}

}

function MyInit()
{
	var present_jour = new Date();
	//present_jour = getDate();
	var present_month = new Date();
	present_month = getMonth()+1;
	f.list_D_Day.selectedIndex = present_jour+1; // Pour séléctionner le bon jour dans la liste.
	f.list_D_Month.selectedIndex = present_month;

	f.list_R_Day.selectedIndex = present_jour+1; // Pour séléctionner le bon jour dans la liste.
	f.list_R_Month.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 + "/" + year + " // " + nbday_month;

	if(typedate=="salida" || typedate=="all")
	{
		// vide la liste avant de la remplir.
		/*
		for(val in f.list_D_Day.options){val=null;}
		*/
		//	for(i=1; i<=f.list_D_Day.options.length; i++)
		/*
		do
		{
		f.list_D_Day.options[i] = null;
		i++;
		}
		while(f.list_D_Day.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.list_D_Day.options[f.list_D_Day.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.list_R_Day.options[f.list_R_Day.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('/');
	var regresso = f.dateeeret.value.split('/');
	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("/");
	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 + "/";}else{ var dadate = jour + "/";}
	if(mois<10){ dadate = dadate + "0" + mois + "/";}else{ dadate = dadate + mois + "/";}
	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("/");
	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 + "/";} else{var dadate = jour + "/";}
	if(mois<10){ dadate = dadate + "0" + mois + "/";} else{ dadate = dadate + mois + "/";}
	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('http://www.compararvuelos.com/jour_semaine.php?date='+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);
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) return(xhr_object.responseText);
	else return(false);
}
