function validateCities() {
	var f = getAirEntryForm();
	var checkstr = "";
	var oneWay =  (f.td_TripType.value=="1");
	//Verificar ciudades
	if (f.td_D_City.value=="") {
		checkstr += "Selecciona una ciudad de salida.\n";
	} else {
		f.td_D_City.value = city(f.td_D_City.value);
	}
	if (f.td_A_City.value=="") {
		checkstr += "Selecciona 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 += "Debes de seleccionar las personas que van a viajar.\n";
	} else if (numTotal > 9) {
		checkstr += "Solo se puede reservar un máximo de 9 billetes.\n";
	}
	if (numAdults+numOlds < numInfants) {
		checkstr += "Los beb&eacute;s deben 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 se puede hacer busquedas en dias posteriores 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,codigo) {
	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) //Buscador de  Viajar
	{
		f.action = "http://clk.tradedoubler.com/click?p=23989&a="+ codigo +"&url=http://www.viajar.com/vuelos/buscavuelos";
		//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) // Buscador de Terminala
	{
		window.document.TA_frmBuscar.TA_CodigoAfiliado.value = codigo;
		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 ) // Buscador de eDreams
	{
		f.action = "http://clk.tradedoubler.com/click?p=51478&a=" + codigo + "&mktportal=tradedoubler&url=http://www.edreams.pt/edreams/portuguese/tradedoubler/launchSearch2.jhtml?mktportal=tradedoubler-PT";
		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 ) // Buscador de 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();
	}
	else if ( tipo == 2 ) // Buscador de Atrapalo
	{
		if (f.td_chkOneWay[0].checked)
		{
			window.document.busqueda.td_ida.value = "2";
		}
		else
		{
			window.document.busqueda.td_ida.value = "0";
		}
        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+'/'+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 ) // Buscador de Marsans
	{
		if (f.td_chkOneWay[0].checked)
			window.document.searchForm.url.value = window.document.searchForm.url.value + "?roundTrip=true";
		else
			window.document.searchForm.url.value = window.document.searchForm.url.value + "?roundTrip=false";
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&departure=" + f.td_D_City.value;
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&departureValue=" + f.td_D_City.value;
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&destination=" + f.td_A_City.value;
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&destinationValue=" + f.td_A_City.value;
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&departureDate_day=" + f.td_D_Day.value;
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&departureDate_month=" + (parseInt(f.td_D_Month.value.substring(4,6)) - 1);
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&departureDate_year=" + f.td_D_Month.value.substring(0,4);
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&destinationDate_day=" + f.td_R_Day.value;
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&destinationDate_month=" + (parseInt(f.td_R_Month.value.substring(4,6)) - 1);
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&destinationDate_year=" + f.td_R_Month.value.substring(0,4);
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&adults=" + f.td_select_adt.value;
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&children=" + f.td_select_chd.value;
		window.document.searchForm.url.value = window.document.searchForm.url.value + "&infants=" + f.td_select_inf.value;
		window.document.searchForm.submit();
	}
	else if ( tipo == 7 ) // Buscador de 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();
	}

	else if ( tipo == 8 ) //Rumbo
	{		
				
		if (f.td_chkOneWay[0].checked)
			window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "?queryType=R";
		else
			window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "?queryType=O";

		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&carrier1=&carrier2=&carrier3=";
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&depDate=" + f.td_D_Day.value+"%2F"+f.td_D_Month.value.substring(4,6)+"%2F"+f.td_D_Month.value.substring(0,4);
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&retDate=" + f.td_R_Day.value+"%2F"+f.td_R_Month.value.substring(4,6)+"%2F"+f.td_R_Month.value.substring(0,4);
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&depTime=&retTime=";
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&paxAdt=" + f.td_select_adt.value;
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&paxChd=" + f.td_select_chd.value;
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&paxInf=" + f.td_select_inf.value;
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&promCode=0&resultType=P";
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&cabin=&directOnly=N&depIata=&arrIata=";
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&firstet=20070628%201849&firstpt=20070702%201600";
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&depCity=" + f.td_D_City.value;
		window.document.RUMBO_AIR.url.value = window.document.RUMBO_AIR.url.value + "&arrCity=" + f.td_A_City.value;
//		alert(window.document.RUMBO_AIR.url.value);
//	    aleat = Math.random() * 100;
//    	aleat = Math.round(aleat);
//    	alert('rumbo'+ aleat);
//		window.open('http://clk.tradedoubler.com/click?p=63012&a=1504838&url=' + window.document.RUMBO_AIR.url.value,'rumbo'+ aleat);
		window.document.RUMBO_AIR.submit();
	}
	
	
	
	
	
	
	
	
	else if ( tipo == 9 ) // Buscador de 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();
	}
}

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 = ["Janeiro","Fevereiro","Mar&ccedil;o","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"];
	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;
	var initRDay = initDDay + 1;
	if (initRDay > f.td_R_Day.options.length) {
		initRDay = initRDay - f.td_R_Day.options.length;
		initRMonth = initRMonth + 1;
	}
	//Por el problema de lo de 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;
		}
	}

	//Refresca lo de los dias cuando se cambian
	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) {
		f.action = "http://clk.tradedoubler.com/click?p=23989" + epi + "&a=1504838&url=http://www.viajar.com/vuelos/buscavuelos";
		f.td_select_inf.style.visibility = "visible";
	} else if(tipo == 1) {
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?p=51478" + epi + "&a=1504838&mktportal=tradedoubler&url=http://www.edreams.pt/edreams/portuguese/tradedoubler/launchSearch2.jhtml?mktportal=tradedoubler-PT";
	} else if(tipo == 3) {
		f.action = "http://clk.tradedoubler.com/click?p=51448" + epi + "&amp;a=1504838&amp;url=http://www.terminala.pt/Afiliados.aspx";
		f.td_select_inf.value = 0;
	} else if(tipo == 4) {
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?p=21645" + epi + "&a=1504838&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) {
		f.td_select_inf.style.visibility = "visible";
		f.action = "http://clk.tradedoubler.com/click?p=31881" + epi + "&a=1504838&url=http://www.atrapalo.com/vuelos/index.php";
	}
}
