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[f.td_D_Month.selectedIndex].value.substring(4)) == myDate.getMonth()+1 && Number(f.td_D_Day[f.td_D_Day.selectedIndex].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 RedirigirAURL(f) {

		 nuevaurl = document.URL;
		 if (nuevaurl.indexOf('.htm')>0)
		 {
			nuevaurl = nuevaurl.substring(0,nuevaurl.indexOf('.htm')+1) + "php";
		 }
         else
		 {
			nuevaurl = nuevaurl.substring(0,nuevaurl.indexOf('.php')+1) + "php";
	     }
		nuevaurl="principal.php";
		if (f.td_chkOneWay[0].checked)
		{
		 nuevaurl += "?Ida=N";
		}
		else
		{
		 nuevaurl += "?Ida=S";
		}
		 nuevaurl += "&DiaRegreso=" + f.td_R_Day.value;
		 nuevaurl += "&MesAnioRegreso=" + f.td_R_Month.value.substring(0,4) + f.td_R_Month.value.substring(4,6);
		 nuevaurl += "&DiaPartida=" + f.td_D_Day.value;
		 nuevaurl += "&MesAnioPartida=" + f.td_D_Month.value.substring(0,4) + f.td_D_Month.value.substring(4,6);
		 nuevaurl += "&CiudadDesde=" + f.td_D_City.value;
		 nuevaurl += "&CiudadHasta=" + f.td_A_City.value;
		 nuevaurl += "&Adultos=" + f.td_select_adt.value;
		 nuevaurl += "&Chicos=" + f.td_select_chd.value;
		 nuevaurl += "&Infantes=" + f.td_select_inf.value;
		 		 
         // Operador
		 if (f.buscarEn[0].checked) {
			 nuevaurl += "&Ope=0";	 
		 }
		 else if (f.buscarEn[1].checked) {
			nuevaurl += "&Ope=1";
		 }
		 else if (f.buscarEn[2].checked) {
			nuevaurl += "&Ope=2";
		 }
		 else if (f.buscarEn[3].checked) {
			nuevaurl += "&Ope=3";
		 }
		 else if (f.buscarEn[4].checked) {
			nuevaurl += "&Ope=4";
		 }
		 else if (f.buscarEn[5].checked) {
			nuevaurl += "&Ope=5";
		 }
		 else if (f.buscarEn[6].checked) {
			nuevaurl += "&Ope=6";
		 }
		 // DE momento fuera window.location.href = nuevaurl;
}

function doFlightSearch() {
	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;
	}

	var myDate = new Date();
	if (Number(f.td_D_Month.value.substring(4)) == (myDate.getMonth() + 1) && Number(f.td_D_Day.value) <= (myDate.getDate() + 3)) {
		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;
		}
	}

	if ( f.buscarEn[0].checked ) //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.target = "new";
		f.submit();
		RedirigirAURL(f);
	}
	else if ( f.buscarEn[2].checked ) //Terminal A
	{
		
		window.document.TA_frmBuscar.TA_CodigoAfiliado.value = "1279252";
		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.TD_TA_Infantes.value = f.td_select_inf.value;
		
		window.document.TA_frmBuscar.target = "new";
		window.document.TA_frmBuscar.submit();
		RedirigirAURL(f);
	}
	else if ( f.buscarEn[1].checked ) //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.target = "new";
		f.submit();
		RedirigirAURL(f);
	}
	else if ( f.buscarEn[3].checked ) // LASTMINUTE
	{
		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();
		RedirigirAURL(f);

	}
	else if ( f.buscarEn[4].checked ) //Atrapalo
	{	
		if (f.td_chkOneWay[0].checked)
		{
			window.document.busquedavuelos.td_ida.value = "2";
		}
		else
		{
			window.document.busquedavuelos.td_ida.value = "0";
		}
		window.document.busquedavuelos.td_origen.value = f.td_D_City.value;
        window.document.busquedavuelos.td_destino.value = f.td_A_City.value;
        window.document.busquedavuelos.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.busquedavuelos.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.busquedavuelos.td_adultos.value = f.td_select_adt.value;
        window.document.busquedavuelos.td_ninos.value = f.td_select_chd.value;
        window.document.busquedavuelos.td_bebes.value = f.td_select_inf.value;
        window.document.busquedavuelos.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.busquedavuelos.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.busquedavuelos.td_s_dia.value = f.td_D_Day.value;
        window.document.busquedavuelos.td_r_dia.value = f.td_R_Day.value;
        window.document.busquedavuelos.td_s_anymes.value = f.td_D_Month.value.substring(0,4)+f.td_D_Month.value.substring(4,6);
        window.document.busquedavuelos.td_r_anymes.value = f.td_R_Month.value.substring(0,4)+f.td_R_Month.value.substring(4,6);
		
		window.document.busquedavuelos.submit();
		RedirigirAURL(f);
	
	}
	else if ( f.buscarEn[5].checked ) // Marsans
	{	
	  	window.document.searchFlightForm.td_departure.value = f.td_D_City.value;
		window.document.searchFlightForm.td_departureDate_day.value = f.td_D_Day.value;
		window.document.searchFlightForm.td_departureDate_month.value = f.td_R_Month.value.substring(4,6);
		window.document.searchFlightForm.td_departureDate_year.value = f.td_D_Month.value.substring(0,4);; 
		window.document.searchFlightForm.td_destination.value = f.td_A_City.value;
		window.document.searchFlightForm.td_destinationDate_day.value = f.td_R_Day.value;
		window.document.searchFlightForm.td_destinationDate_month.value = f.td_R_Month.value.substring(4,6);
		window.document.searchFlightForm.td_destinationDate_year.value = f.td_R_Month.value.substring(0,4);
		window.document.searchFlightForm.td_adults.value = f.td_select_adt.value;
			
		window.document.searchFlightForm.submit();
		RedirigirAURL(f);
	}
	else if ( f.buscarEn[6].checked ) // Rumbo
	{	
		window.document.mod468x60.td_depCity.value = f.td_D_City.value;
		window.document.mod468x60.td_depDate.value = f.td_D_Day.value + "/" + f.td_D_Month.value.substring(4,6) + "/" + f.td_D_Month.value.substring(0,4);;   
		window.document.mod468x60.td_arrCity.value = f.td_A_City.value;
		window.document.mod468x60.td_retDate.value = f.td_R_Day.value + "/" + f.td_R_Month.value.substring(4,6) + "/" + f.td_R_Month.value.substring(0,4);;
		
		window.document.mod468x60.td_paxAdt.value = f.td_select_adt.value;
		window.document.mod468x60.td_paxChd.value = f.td_select_chd.value;
		
		
		window.document.mod468x60.submit();
		RedirigirAURL(f);
	}
	else if ( f.buscarEn[7].checked ) //eBookers
	{	
	
	    if (f.td_chkOneWay[0].checked)
		{
			window.document.fform1.url.value = window.document.fform1.url.value + "?TYPE=R";
		}
		else
		{
			window.document.fform1.url.value = window.document.fform1.url.value + "?TYPE=O";
		}
		window.document.fform1.url.value = window.document.fform1.url.value + "&SID=RTi7uwrfNGgAACZtxB0";
		window.document.fform1.url.value = window.document.fform1.url.value + "&checkDIRECT=1";
		window.document.fform1.url.value = window.document.fform1.url.value + "&CURRENCY=EUR";
		window.document.fform1.url.value = window.document.fform1.url.value + "&DIRECT=1";
		window.document.fform1.url.value = window.document.fform1.url.value + "&TIME=0";
		window.document.fform1.url.value = window.document.fform1.url.value + "&RTIME=0";
		window.document.fform1.url.value = window.document.fform1.url.value + "&COS=Y";
		window.document.fform1.url.value = window.document.fform1.url.value + "&LDEP=" + f.td_D_City.value;
		window.document.fform1.url.value = window.document.fform1.url.value + "&LARR=" + f.td_A_City.value;
		window.document.fform1.url.value = window.document.fform1.url.value + "&DAY_DATE=" + f.td_D_Day.value;
		window.document.fform1.url.value = window.document.fform1.url.value + "&MONTH_DATE=" + f.td_D_Month.value.substring(0,4)+f.td_D_Month.value.substring(4,6);
		window.document.fform1.url.value = window.document.fform1.url.value + "&DAY_RDATE=" + f.td_R_Day.value;
		window.document.fform1.url.value = window.document.fform1.url.value + "&MONTH_RDATE=" + f.td_R_Month.value.substring(0,4)+f.td_R_Month.value.substring(4,6);
		window.document.fform1.url.value = window.document.fform1.url.value + "&PAX0=" + f.td_select_adt.value;
		window.document.fform1.url.value = window.document.fform1.url.value + "&PAX1=" + f.td_select_chd.value;
		window.document.fform1.url.value = window.document.fform1.url.value + "&PAX2=" + f.td_select_inf.value;
		window.document.fform1.submit();
		RedirigirAURL(f);
	}
	else if ( f.buscarEn[8].checked ) //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 +"/"+ 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();
		RedirigirAURL(f);
		}
}

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();

	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[f.td_" + comboType + "_Month.selectedIndex].value.substring(4) - 1;");
	var year = eval("f.td_" + comboType + "_Month[f.td_" + comboType + "_Month.selectedIndex].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 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.td_D_Day.options.length) {
		initDDay = initDDay - f.td_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;
	if (initRDay > f.td_R_Day.options.length) {
		initRDay = initRDay - f.td_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.options[f.td_D_Month.selectedIndex].value;
		var dDayValue = f.td_D_Day.options[f.td_D_Day.selectedIndex].value;
		var dTimeIndex = f.td_D_Time.selectedIndex;

		var departureDate = new Date(dYearMonthValue.substring(0,4), parseInt(dYearMonthValue.substring(4,6))-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.td_R_Day.style.visibility = oneway?"hidden":"visible";
	f.td_R_Month.style.visibility = oneway?"hidden":"visible";
	f.td_R_Time.style.visibility = oneway?"hidden":"visible";
	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[f.td_" + comboType + "_Month.selectedIndex].value.substring(4) - 1;");
	var year = eval("f.td_" + comboType + "_Month[f.td_" + comboType + "_Month.selectedIndex].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.td_"+typeDate+"_Day");
	cmbMonth = eval("f.td_"+typeDate+"_Month");
	cmbDate = eval("f.td_"+typeDate+"_Date");
	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)
{
	var f = getAirEntryForm();
	if(f.buscarEn[0].checked) {
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?" + epi + "p=23989&a=1059912&url=http://www.viajar.com/vuelos/buscavuelos";
		f.enviar.value = "!BUSCAR VUELOS EN VIAJAR!";
	} else if(f.buscarEn[1].checked) {
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?" + epi + "p=15407&a=1176908&mktportal=tradedoubler&url=http://www.edreams.es/edreams/espanol/tradedoubler/launchSearch.jhtml";
		f.enviar.value = "!BUSCAR VUELOS EN EDREAMS!";
	} else if(f.buscarEn[2].checked) {
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?" + epi + "p=20683&amp;a=1059912&amp;url=http://www.terminala.com/VuelosAfiliados.aspx";
		f.enviar.value = "!BUSCAR VUELOS EN TERMINALA!";
	} else if(f.buscarEn[3].checked) {
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?" + epi + "p=21645&a=1059912&url=http://www.es.lastminute.com/lmn/lfe/flights/search/search_helper.jhtml?_DARGS=%2Flmn%2Flfe%2Fflights%2Fsearch%2Fsearch.jhtml.1";
		f.enviar.value = "!BUSCAR VUELOS EN LASTMINUTE!";
	} else if(f.buscarEn[4].checked) {
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?" + epi + "p=31881&a=1059912&url=http://www.atrapalo.com/vuelos/index.php";
		f.enviar.value = "!BUSCAR VUELOS EN ATRAPALO!";
	} else if(f.buscarEn[5].checked) {
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?" + epi + "p=41423&a=1279252&epi=buscador&url=http://www.marsans.es/viajes/flight/availabilityCity.do";
		f.enviar.value = "!BUSCAR VUELOS EN MARSANS!";
	} else if(f.buscarEn[6].checked) {
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?" + epi + "48184&a=1279252&epi=buscador&url=http://www.rumbo.es/viajes/vuelos/city.do";
		f.enviar.value = "!BUSCAR VUELOS EN RUMBO!";
	}
	else if(f.buscarEn[7].checked) {
		f.td_select_inf.style.visibility = "visible";
		f.enviar.value = "!BUSCAR VUELOS EN EBOOKERS!";
	}
	else if(f.buscarEn[8].checked) {
		f.td_select_inf.style.visibility = "visible";
		f.enviar.value = "!BUSCAR VUELOS EN MUCHOVIAJE!";
	}
}

