/*
 EBookers Library
 
 Functions used to get fly
 
 */

function validateForm(form) {
	var orig = document.bookFlightsForm.td_origin.value;
	var dest = document.bookFlightsForm.td_dest.value;
	orig = orig.replace("ä", "ae");
	orig = orig.replace("Ä", "Ae");
	orig = orig.replace("ü", "ue");
	orig = orig.replace("Ü", "Ue");
	orig = orig.replace("ö", "oe");
	orig = orig.replace("Ö", "Oe");
	orig = orig.replace("ß", "ss");
	orig = orig.replace("é", "e");
	orig = orig.replace("è", "e");
	orig = orig.replace("ê", "e");
	orig = orig.replace("à", "a");
	orig = orig.replace("ô", "o");
	orig = orig.replace("î", "i");
	orig = orig.replace("â", "a");
	orig = orig.replace("ï", "i");
	orig = orig.replace("Â", "a");
	orig = orig.replace("Î", "i");
	orig = orig.replace("Ï", "i");
	dest = dest.replace("ä", "ae");
	dest = dest.replace("Ä", "Ae");
	dest = dest.replace("ü", "ue");
	dest = dest.replace("Ü", "Ue");
	dest = dest.replace("ö", "oe");
	dest = dest.replace("Ö", "Oe");
	dest = dest.replace("ß", "ss");
	dest = dest.replace("é", "e");
	dest = dest.replace("è", "e");
	dest = dest.replace("ê", "e");
	dest = dest.replace("à", "a");
	dest = dest.replace("ô", "o");
	dest = dest.replace("î", "i");
	dest = dest.replace("â", "a");
	dest = dest.replace("ï", "i");
	dest = dest.replace("Â", "a");
	dest = dest.replace("Î", "i");
	dest = dest.replace("Ï", "i");	
    document.bookFlightsForm.td_origin.value = orig;
    document.bookFlightsForm.td_dest.value = dest;

	if (document.bookFlightsForm.td_origin.value.length < 3) {
		alert("Veuillez sélectionner un aéroport de départ.");
		document.bookFlightsForm.td_origin.focus();
		return false;
	} else if (document.bookFlightsForm.td_dest.value.length < 3) {
		alert("Veuillez entrer une ville de destination ou un code aéroport.");
		document.bookFlightsForm.td_dest.focus();
		return false;
	} 
		
	if(checkValidDay('F')){}else{return false;}

	//setting the departdate and returndate in the hidden value
	str_departyearandmonth=document.bookFlightsForm.td_MONTH_DATE.options[document.bookFlightsForm.td_MONTH_DATE.selectedIndex].value;
	str_departyear=str_departyearandmonth.substring(0,4);
	str_departmonth=str_departyearandmonth.substring(4,6);
	document.bookFlightsForm.td_departdate.value=str_departdate=str_departyear+"-"+str_departmonth+"-"+document.bookFlightsForm.td_DAY_DATE.options[document.bookFlightsForm.td_DAY_DATE.selectedIndex].value;

	str_returnyearandmonth=document.bookFlightsForm.td_MONTH_RDATE.options[document.bookFlightsForm.td_MONTH_RDATE.selectedIndex].value;
	str_returnyear=str_returnyearandmonth.substring(0,4);
	str_returnmonth=str_returnyearandmonth.substring(4,6);
	document.bookFlightsForm.td_returndate.value=str_returndate=str_returnyear+"-"+str_returnmonth+"-"+document.bookFlightsForm.td_DAY_RDATE.options[document.bookFlightsForm.td_DAY_RDATE.selectedIndex].value;
	return true;
}

function checkValidDay(com){
	if(com == 'H'){
		var dep_day = document.bookHotelsForm.td_DAY_DATE.options[document.bookHotelsForm.td_DAY_DATE.selectedIndex].value;
		var ret_day = document.bookHotelsForm.td_DAY_RDATE.options[document.bookHotelsForm.td_DAY_RDATE.selectedIndex].value;
		var dep_monyear = document.bookHotelsForm.td_MONTH_DATE.options[document.bookHotelsForm.td_MONTH_DATE.selectedIndex].value;
		var ret_monyear = document.bookHotelsForm.td_MONTH_RDATE.options[document.bookHotelsForm.td_MONTH_RDATE.selectedIndex].value;

	}
	if(com == 'F'){
		var dep_day = document.bookFlightsForm.td_DAY_DATE.options[document.bookFlightsForm.td_DAY_DATE.selectedIndex].value;
		var ret_day = document.bookFlightsForm.td_DAY_RDATE.options[document.bookFlightsForm.td_DAY_RDATE.selectedIndex].value;
		var dep_monyear = document.bookFlightsForm.td_MONTH_DATE.options[document.bookFlightsForm.td_MONTH_DATE.selectedIndex].value;
		var ret_monyear = document.bookFlightsForm.td_MONTH_RDATE.options[document.bookFlightsForm.td_MONTH_RDATE.selectedIndex].value;
	}

	if(com == 'C'){
		var dep_day = document.bookCarsForm.td_DAY_DATE.options[document.bookCarsForm.td_DAY_DATE.selectedIndex].value;
		var ret_day = document.bookCarsForm.td_DAY_RDATE.options[document.bookCarsForm.td_DAY_RDATE.selectedIndex].value;
		var dep_monyear = document.bookCarsForm.td_MONTH_DATE.options[document.bookCarsForm.td_MONTH_DATE.selectedIndex].value;
		var ret_monyear = document.bookCarsForm.td_MONTH_RDATE.options[document.bookCarsForm.td_MONTH_RDATE.selectedIndex].value;
	}
	
	if(com == 'D'){
		var dep_day = document.bookDynaForm.td_DAY_DATE.options[document.bookDynaForm.td_DAY_DATE.selectedIndex].value;
		var ret_day = document.bookDynaForm.td_DAY_RDATE.options[document.bookDynaForm.td_DAY_RDATE.selectedIndex].value;
		var dep_monyear = document.bookDynaForm.td_MONTH_DATE.options[document.bookDynaForm.td_MONTH_DATE.selectedIndex].value;
		var ret_monyear = document.bookDynaForm.td_MONTH_RDATE.options[document.bookDynaForm.td_MONTH_RDATE.selectedIndex].value;
	}

	var dep_year = dep_monyear.substr(0,4);
	var dep_month = dep_monyear.substr(4,2);
	var ret_year = ret_monyear.substr(0,4);
	var ret_month = ret_monyear.substr(4,2);
	var depday_max = GetMonthMaxDays(dep_year,dep_month-1);
	var retday_max = GetMonthMaxDays(ret_year,ret_month-1);
	var newDt = new Date();
	var currDay= (newDt.getDate());
	var currMon= (newDt.getMonth()+1);
	var currYear = (newDt.getFullYear());
	var temp_new = currMon.toString();
                if (temp_new.length == 1){
                 currMon= '0'+currMon;
				 }
 	var a = (currMon.toString());
	var b = (currYear .toString());
	var MonYear =  (b+a);


	if(dep_day > depday_max)
	{
		alert("Date de départ non valide.");
		return false;
	} else if(ret_day > retday_max)
	{
		alert("Date de retour non valide.");
		return false;
	} else if((ret_monyear < dep_monyear))
	{
		alert("Date de départ non valide.");
		return false;
	} else if(((dep_monyear == ret_monyear)&&(ret_day < dep_day)))
	{
		alert("Date de départ non valide.");
		return false;
	}
	if((dep_day <= currDay)&&(dep_monyear <= MonYear))
	{
		alert("Date de retour non valide.");
		return false;
	}
				
	if(com == 'C')
	{
		makeURL();
	} else {
		return true;
	}
}

function validateHotel(){
   var orig = document.bookHotelsForm.td_market.value;
	orig = orig.replace("ä", "ae");
	orig = orig.replace("Ä", "Ae");
	orig = orig.replace("ü", "ue");
	orig = orig.replace("Ü", "Ue");
	orig = orig.replace("ö", "oe");
	orig = orig.replace("Ö", "Oe");
	orig = orig.replace("ß", "ss");
	orig = orig.replace("é", "e");
	orig = orig.replace("è", "e");
	orig = orig.replace("ê", "e");
	orig = orig.replace("à", "a");
	orig = orig.replace("ô", "o");
	orig = orig.replace("î", "i");
	orig = orig.replace("â", "a");
	orig = orig.replace("ï", "i");
	orig = orig.replace("Â", "a");
	orig = orig.replace("Î", "i");
	orig = orig.replace("Ï", "i");

	document.bookHotelsForm.td_market.value = orig;
	
	if (document.bookHotelsForm.td_market.value.length < 3) {
		alert("Choisissez une ville de destination");
		document.bookHotelsForm.td_market.focus();
		return false;
	}
	
	if(checkValidDay('H')){}else{return false;}

	//setting the departdate and returndate in the hidden value
	str_departyearandmonth=document.bookHotelsForm.td_MONTH_DATE.options[document.bookHotelsForm.td_MONTH_DATE.selectedIndex].value;
	str_departyear=str_departyearandmonth.substring(0,4);
	str_departmonth=str_departyearandmonth.substring(4,6);
	document.bookHotelsForm.td_checkin.value=str_departdate=str_departyear+"-"+str_departmonth+"-"+document.bookHotelsForm.td_DAY_DATE.options[document.bookHotelsForm.td_DAY_DATE.selectedIndex].value;

	str_returnyearandmonth=document.bookHotelsForm.td_MONTH_RDATE.options[document.bookHotelsForm.td_MONTH_RDATE.selectedIndex].value;
	str_returnyear=str_returnyearandmonth.substring(0,4);
	str_returnmonth=str_returnyearandmonth.substring(4,6);
	document.bookHotelsForm.td_checkout.value=str_returndate=str_returnyear+"-"+str_returnmonth+"-"+document.bookHotelsForm.td_DAY_RDATE.options[document.bookHotelsForm.td_DAY_RDATE.selectedIndex].value;

	return true;
}

function setHiddenDates(){

    var orig = document.bookHotelsForm.td_market.value;
	orig = orig.replace("ä", "ae");
	orig = orig.replace("Ä", "Ae");
	orig = orig.replace("ü", "ue");
	orig = orig.replace("Ü", "Ue");
	orig = orig.replace("ö", "oe");
	orig = orig.replace("Ö", "Oe");
	orig = orig.replace("ß", "ss");
	orig = orig.replace("é", "e");
	orig = orig.replace("è", "e");
	orig = orig.replace("ê", "e");
	orig = orig.replace("à", "a");
	orig = orig.replace("ô", "o");
	orig = orig.replace("î", "i");
	orig = orig.replace("â", "a");
	orig = orig.replace("ï", "i");
	orig = orig.replace("Â", "a");
	orig = orig.replace("Î", "i");
	orig = orig.replace("Ï", "i");

	document.bookHotelsForm.td_market.value = orig;
	
	if (document.bookHotelsForm.td_market.value.length < 3) {
		alert("Choisissez une ville de destination");
		document.bookHotelsForm.td_market.focus();
		return false;
	}
	

	if(checkValidDay('H')){}else{return false;}

	//setting the departdate and returndate in the hidden value
	str_departyearandmonth=document.bookHotelsForm.td_MONTH_DATE.options[document.bookHotelsForm.td_MONTH_DATE.selectedIndex].value;
	str_departyear=str_departyearandmonth.substring(0,4);
	str_departmonth=str_departyearandmonth.substring(4,6);
	document.bookHotelsForm.td_checkin.value=str_departdate=str_departyear+"-"+str_departmonth+"-"+document.bookHotelsForm.td_DAY_DATE.options[document.bookHotelsForm.td_DAY_DATE.selectedIndex].value;

	str_returnyearandmonth=document.bookHotelsForm.td_MONTH_RDATE.options[document.bookHotelsForm.td_MONTH_RDATE.selectedIndex].value;
	str_returnyear=str_returnyearandmonth.substring(0,4);
	str_returnmonth=str_returnyearandmonth.substring(4,6);
	document.bookHotelsForm.td_checkout.value=str_returndate=str_returnyear+"-"+str_returnmonth+"-"+document.bookHotelsForm.td_DAY_RDATE.options[document.bookHotelsForm.td_DAY_RDATE.selectedIndex].value;

	return true;
}

function validateCar(){
//Validation Starts here
	var orig1 = document.bookCarsForm.td_pickuptype.value;
	var dest3 = document.bookCarsForm.td_dropofftype.value;	
	
	orig1 = orig1.replace("ä", "ae");
	orig1 = orig1.replace("Ä", "Ae");
	orig1 = orig1.replace("ü", "ue");
	orig1 = orig1.replace("Ü", "Ue");
	orig1 = orig1.replace("ö", "oe");
	orig1 = orig1.replace("Ö", "Oe");
	orig1 = orig1.replace("ß", "ss");
	orig1 = orig1.replace("é", "e");
	orig1 = orig1.replace("è", "e");
	orig1 = orig1.replace("ê", "e");
	orig1 = orig1.replace("â", "a");
	orig1 = orig1.replace("î", "i");
	orig1 = orig1.replace("Â", "a");
	orig1 = orig1.replace("ï", "i");
	orig1 = orig1.replace("Î", "i");
	orig1 = orig1.replace("û", "u");
	dest3 = dest3.replace("ä", "ae");
	dest3 = dest3.replace("Ä", "Ae");
	dest3 = dest3.replace("ü", "ue");
	dest3 = dest3.replace("Ü", "Ue");
	dest3 = dest3.replace("ö", "oe");
	dest3 = dest3.replace("Ö", "Oe");
	dest3 = dest3.replace("ß", "ss");
	dest3 = dest3.replace("é", "e");
	dest3 = dest3.replace("è", "e");
	dest3 = dest3.replace("ê", "e");
	dest3 = dest3.replace("â", "a");
	dest3 = dest3.replace("î", "i");
	dest3 = dest3.replace("Â", "a");
	dest3 = dest3.replace("ï", "i");
	dest3 = dest3.replace("Î", "i");
	dest3 = dest3.replace("û", "u");
	
	document.bookCarsForm.td_pickuptype.value = orig1;
	document.bookCarsForm.td_dropofftype.value = dest3;

	var pickcity = document.bookCarsForm.td_pickuptype.value;
	var dropcity = document.bookCarsForm.td_dropofftype.value;
	

		/* OLD */
			/*
		if((pickcity.length < 3)||!(pickcity.match(/^[a-zA-Z]+$/)))
		{
			alert("Nom de la ville ou du code aéroport de départ.");
			return false;
		}
	
			if((dropcity.length < 3)||!(dropcity.match(/^[a-zA-Z]+$/)))
			{
				alert("Nom de la ville ou du code aéroport d'arrivée.");
				return false;
			}*/
			
			/* NEW */
		if(pickcity.length < 3)
		{
			alert("Nom de la ville ou du code aéroport de départ.");
			return false;
		}
	
		if(dropcity.length < 3)
		{
			alert("Nom de la ville ou du code aéroport d'arrivée.");
			return false;
		}
		
	if(checkValidDay('C')){}else{return false;}

//Validation  for Car Ends here
}

function showOnLoad(com){
    if (com == 'F') {
        document.getElementById('flight_com').style.display = "inline";
        document.getElementById('hotel_com').style.display = "none";
        document.getElementById('cars_com').style.display = "none";
        document.getElementById('dyna_com').style.display = "none";
        document.getElementById('tab_span1').style.display = "inline";
        document.getElementById('tab_span2').style.display = "none";
        document.getElementById('tab_span3').style.display = "none";
        document.getElementById('tab_span4').style.display = "none";
        updateDates('F');   
    }
    
    if (com == 'H') {
        document.getElementById('flight_com').style.display = "none";
        document.getElementById('hotel_com').style.display = "inline";
        document.getElementById('cars_com').style.display = "none";
        document.getElementById('dyna_com').style.display = "none";
        document.getElementById('tab_span1').style.display = "none";
        document.getElementById('tab_span2').style.display = "inline";
        document.getElementById('tab_span3').style.display = "none";
        document.getElementById('tab_span4').style.display = "none";
        updateDates('H');
    }
    
    if (com == 'C') {
        document.getElementById('flight_com').style.display = "none";
        document.getElementById('hotel_com').style.display = "none";
        document.getElementById('cars_com').style.display = "inline";
        document.getElementById('dyna_com').style.display = "none";
        document.getElementById('tab_span1').style.display = "none";
        document.getElementById('tab_span2').style.display = "none";
        document.getElementById('tab_span3').style.display = "inline";
        document.getElementById('tab_span4').style.display = "none";
        updateDates('C');
    }
    
    if (com == 'D') {
        document.getElementById('flight_com').style.display = "none";
        document.getElementById('hotel_com').style.display = "none";
        document.getElementById('cars_com').style.display = "none";
        document.getElementById('dyna_com').style.display = "inline";
        document.getElementById('tab_span1').style.display = "none";
        document.getElementById('tab_span2').style.display = "none";
        document.getElementById('tab_span3').style.display = "none";
        document.getElementById('tab_span4').style.display = "inline";
        updateDates('D');
    }
    
}

monthNames = new Array("Jan", "Fev", "Mar", "Avr", "Mai", "Juin", "Juil", "Ao&#251;", "Sep", "Oct", "Nov", "Dec");
now = new Date();
nowInMS = Date.parse(now);
weekInMS = 7 * 24 * 60 * 60 * 1000;

startDate = new Date(nowInMS + weekInMS);
endDate = new Date(nowInMS + (3 * weekInMS));
var Today = new Date();

function dateLogic(day_diff){
    var rd = new Date(Today.getFullYear(), Today.getMonth(), Today.getDate());
    rd.setDate(rd.getDate() + day_diff);
    return rd;
}

function to2digits(no){
    var from_date;
    thestrNo = "" + no;
    return ((thestrNo.length == 1) ? "0" : "") + thestrNo;
}

var normDate = dateLogic(0);
var departDate = dateLogic(7);
var returnDate = dateLogic(14);
var dayN = normDate.getDate();
var dayD = departDate.getDate();
dayN = to2digits(dayN);
dayD = to2digits(dayD);
var dayR = returnDate.getDate();
dayR = to2digits(dayR);
var monthD = departDate.getMonth();
var monthR = returnDate.getMonth();
var monthN = normDate.getMonth();
monthN = monthN + 1;
monthN = to2digits(monthN);
var year = normDate.getFullYear();

function generateMonths(DateObject){
    for (monthNo = now.getMonth(); monthNo < 12; monthNo++) {
        document.write('<OPTION value="' + (now.getFullYear()) + to2digits(monthNo + 1) + '"');
        if (((monthNo == monthD) && (DateObject == 'startDate')) || ((monthNo == monthR) && (DateObject == 'returnDate'))) 
            document.write(' SELECTED');
        document.write('>' + monthNames[monthNo] + '&nbsp;' + to2digits((year) - 2000) + '</OPTION>');
    }
    
    for (monthNo = 0; monthNo < now.getMonth(); monthNo++) {
        document.write('<OPTION value="' + (year + 1) + to2digits(monthNo + 1) + '"');
        if (((monthNo == monthD) && (DateObject == 'startDate')) || ((monthNo == monthR) && (DateObject == 'returnDate'))) 
            document.write(' SELECTED');
        document.write('>' + monthNames[monthNo] + '&nbsp;' + to2digits((year + 1) - 2000) + '</OPTION>');
    }
}

function generatedaytxt(txtname){
    for (var i = 1; i < 32; i++) {
        var j = to2digits(i);
        document.write('<OPTION value="' + j + '"');
        document.write('>' + j + '</OPTION>');
    }
    
}

function updateDates(com){
    if (com == 'F') {
        document.bookFlightsForm.td_DAY_DATE.value = dayD;
        document.bookFlightsForm.td_DAY_RDATE.value = dayR;
    }
    
    if (com == 'H') {
        document.bookHotelsForm.td_DAY_DATE.value = dayD;
        document.bookHotelsForm.td_DAY_RDATE.value = dayR;
    }
    
    if (com == 'C') {
        document.bookCarsForm.td_DAY_DATE.value = dayD;
        document.bookCarsForm.td_DAY_RDATE.value = dayR;
    }
    
    if (com == 'D') {
        document.bookDynaForm.td_DAY_DATE.value = dayD;
        document.bookDynaForm.td_DAY_RDATE.value = dayR_dp;
    }
    
}

function changeState(triptype){
    if (triptype == 'R') {
        document.bookFlightsForm.td_DAY_RDATE.disabled = false;
        document.bookFlightsForm.td_MONTH_RDATE.disabled = false;
    }
    
    if (triptype == 'O') {
        document.bookFlightsForm.td_DAY_RDATE.disabled = true;
        document.bookFlightsForm.td_MONTH_RDATE.disabled = true;
    }
    
}

function return_Date(com){
    var from_date;
    if (com == 'F') {
        from_date = document.bookFlightsForm.td_DAY_DATE.options[document.bookFlightsForm.td_DAY_DATE.selectedIndex].value;
        from_date = from_date + document.bookFlightsForm.td_MONTH_DATE.options[document.bookFlightsForm.td_MONTH_DATE.selectedIndex].value;
        update_return_date(from_date, 'F');
    }
    if (com == 'H') {
        from_date = document.bookHotelsForm.td_DAY_DATE.options[document.bookHotelsForm.td_DAY_DATE.selectedIndex].value;
        from_date = from_date + document.bookHotelsForm.td_MONTH_DATE.options[document.bookHotelsForm.td_MONTH_DATE.selectedIndex].value;
        update_return_date(from_date, 'H');
    }
    
    if (com == 'C') {
        from_date = document.bookCarsForm.td_DAY_DATE.options[document.bookCarsForm.td_DAY_DATE.selectedIndex].value;
        from_date = from_date + document.bookCarsForm.td_MONTH_DATE.options[document.bookCarsForm.td_MONTH_DATE.selectedIndex].value;
        update_return_date(from_date, 'C');
        
    }
    
    if (com == 'D') {
        from_date = document.bookDynaForm.td_DAY_DATE.options[document.bookDynaForm.td_DAY_DATE.selectedIndex].value;
        from_date = from_date + document.bookDynaForm.td_MONTH_DATE.options[document.bookDynaForm.td_MONTH_DATE.selectedIndex].value;
        update_return_date_dp(from_date, 'D');
        
    }
}

function update_return_date(from, com){
    var rd = new Date(from.substr(2, 4), from.substr(6, 2) - 1, from.substr(0, 2));
    rd.setDate(rd.getDate() + 7);
    var day = rd.getDate();
    var month = rd.getMonth() + 1;
    var year = rd.getFullYear();
    var yearMonth;
    if (month < 10) {
        yearMonth = year + '0' + month;
    }
    else {
        yearMonth = year + '' + month;
    }
    day = to2digits(day);
    
    if (com == 'F') {
        document.bookFlightsForm.td_DAY_RDATE.value = day;
        document.bookFlightsForm.td_MONTH_RDATE.value = yearMonth;
    }
    
    if (com == 'H') {
        document.bookHotelsForm.td_DAY_RDATE.value = day;
        document.bookHotelsForm.td_MONTH_RDATE.value = yearMonth;
    }
    
    if (com == 'C') {
        document.bookCarsForm.td_DAY_RDATE.value = day;
        document.bookCarsForm.td_MONTH_RDATE.value = yearMonth;
    }
    
}

function GetMonthMaxDays(y, m) // accepts 0 index month
{
    return new Date(y, m + 1, 0).getDate();
}

function BC(id){
    var obj = document.getElementById(id);
    return obj;
}

function makeURL(){

    var pickcity = document.bookCarsForm.td_pickuptype.value;
    var dropcity = document.bookCarsForm.td_dropofftype.value;
    var orig = document.bookCarsForm.td_pickuptype.value;
    var dest = document.bookCarsForm.td_dropofftype.value;
    orig = orig.replace("&#228;", "ae");
    
    orig = orig.replace("&#196;", "Ae");
    orig = orig.replace("&#252;", "ue");
    orig = orig.replace("&#220;", "Ue");
    orig = orig.replace("&#246;", "oe");
    orig = orig.replace("&#214;", "Oe");
    orig = orig.replace("&#223;", "ss");
    
    dest = dest.replace("&#228;", "ae");
    dest = dest.replace("&#196;", "Ae");
    dest = dest.replace("&#252;", "ue");
    dest = dest.replace("&#220;", "Ue");
    dest = dest.replace("&#246;", "oe");
    dest = dest.replace("&#214;", "Oe");
    dest = dest.replace("&#223;", "ss");
    
    //setting the departdate and returndate in the hidden value
    str_departyearandmonth = document.bookCarsForm.td_MONTH_DATE.options[document.bookCarsForm.td_MONTH_DATE.selectedIndex].value;
    
    str_departday = document.bookCarsForm.td_DAY_DATE.options[document.bookCarsForm.td_DAY_DATE.selectedIndex].value;
    str_departyear1 = str_departyearandmonth.substring(0, 4);
    str_departyear = str_departyear1.substring(2, 4);
    str_departmonth = str_departyearandmonth.substring(4, 6);
    //alert("str_departyear2::"+str_departyear2)
    
    str_returnyearandmonth = document.bookCarsForm.td_MONTH_RDATE.options[document.bookCarsForm.td_MONTH_RDATE.selectedIndex].value;
    str_returnday = document.bookCarsForm.td_DAY_RDATE.options[document.bookCarsForm.td_DAY_RDATE.selectedIndex].value;
    str_returnyear1 = str_returnyearandmonth.substring(0, 4);
    str_returnyear = str_returnyear1.substring(2, 4);
    str_returnmonth = str_returnyearandmonth.substring(4, 6);
    
    //YY-mm-dd format i.e 2008-09-15
    //var pickupdateVal1=str_departyear+"-"+str_departmonth+"-"+str_departday;
    //var dropoffdateVal1=str_returnyear+"-"+str_returnmonth+"-"+str_returnday;
    
    //dd.mm.yy format 17.09.08
    var pickupdateVal1 = str_departday + "/" + str_departmonth + "/" + str_departyear;
    var dropoffdateVal1 = str_returnday + "/" + str_returnmonth + "/" + str_returnyear;
    //alert(pickupdateVal1+"----"+dropoffdateVal1);
    
    var pickupdateVal = pickupdateVal1;
    var dropoffdateVal = dropoffdateVal1;
    var pickuptypeVal = BC("td_pickuptype").value;
    var dropofftypeVal = BC("td_dropofftype").value;
    
    var driversageVal = document.bookCarsForm.td_driversage.value;
    var air_index = document.bookCarsForm.td_air.length
    
    var airVal = "U";
    for (i = 0; i < air_index - 1; i++) {
        if (document.bookCarsForm.td_air[i].checked == true) {
            airVal = document.bookCarsForm.td_air[i].value;
            //alert("air_val::"+document.bookCarsForm.td_air[i].value)
        }
    }
    
    /////////////////////  NEW  /////////////////////////	
    var typeArg = "type=car";
    var pickupArg = "&pickup=" + pickcity;
    var dropoffArg = "&dropoff=" + dropcity;
    var pickupdateArg = "&pickupdate=" + pickupdateVal;
    var dropoffdateArg = "&dropoffdate=" + dropoffdateVal;
    //var pickuptimeArg = "&pickupTime=9AM";
    //var dropofftimeArg = "&dropoffTime=9AM";
    var pickuptypeArg = "&pickuptype=AIRPORT";
    var dropofftypeArg = "&dropofftype=AIRPORT";
    var airArg = "&air=" + airVal;
    var driversageArg = "&driversage=" + driversageVal;
    
    var preurl = "http://clk.tradedoubler.com/click?p=463&a=1649000&g=17785520";
    var URLRoot = preurl + "&url=http://www.ebookers.fr/partner/offsitesearch?";
    
    //var URLRoot = "http://clk.atdmt.com/EBS/go/117173831/direct/01/?";
    var URL = URLRoot + typeArg + pickupArg + dropoffArg + dropofftypeArg + pickupdateArg + dropoffdateArg + /*pickuptimeArg + dropofftimeArg + */ pickuptypeArg + airArg + driversageArg + "&locale=fr_CH";
    
    /////////////////////  FIN NEW  /////////////////////////	
    
    //alert(URL);
    window.open(URL);
    return false;
    
    
}

/*  Javascript r&#233;adapt&#233; pour DYNAPACK (Dates) */
function update_return_date_dp(from, com){
    var rd = new Date(from.substr(2, 4), from.substr(6, 2) - 1, from.substr(0, 2));
    rd.setDate(rd.getDate() + 3);
    var day = rd.getDate();
    var month = rd.getMonth() + 1;
    var year = rd.getFullYear();
    var yearMonth;
    if (month < 10) {
        yearMonth = year + '0' + month;
    }
    else {
        yearMonth = year + '' + month;
    }
    day = to2digits(day);
    
    if (com == 'D') {
        document.bookDynaForm.td_DAY_RDATE.value = day;
        document.bookDynaForm.td_MONTH_RDATE.value = yearMonth;
    }
}

var returnDate_dp = dateLogic(10);
var dayR_dp = returnDate_dp.getDate();
dayR_dp = to2digits(dayR_dp);

var normDate_dp = dateLogic(0);
var departDate_dp = dateLogic(7);
var returnDate_dp = dateLogic(10);
var dayN_dp = normDate_dp.getDate();
var dayD_dp = departDate_dp.getDate();
dayN_dp = to2digits(dayN_dp);
dayD_dp = to2digits(dayD_dp);
var dayR_dp = returnDate_dp.getDate();
dayR_dp = to2digits(dayR_dp);
var monthD_dp = departDate_dp.getMonth();
var monthR_dp = returnDate_dp.getMonth();
var monthN_dp = normDate_dp.getMonth();
monthN_dp = monthN_dp + 1;
monthN_dp = to2digits(monthN_dp);
var year_dp = normDate_dp.getFullYear();

function generateMonths_dp(DateObject){
    for (monthNo = now.getMonth(); monthNo < 12; monthNo++) {
        document.write('<OPTION value="' + (now.getFullYear()) + to2digits(monthNo + 1) + '"');
        if (((monthNo == monthD_dp) && (DateObject == 'startDate')) || ((monthNo == monthR_dp) && (DateObject == 'returnDate'))) 
            document.write(' SELECTED');
        document.write('>' + monthNames[monthNo] + '&nbsp;' + to2digits((year_dp) - 2000) + '</OPTION>');
    }
    
    for (monthNo = 0; monthNo < now.getMonth(); monthNo++) {
        document.write('<OPTION value="' + (year + 1) + to2digits(monthNo + 1) + '"');
        if (((monthNo == monthD_dp) && (DateObject == 'startDate')) || ((monthNo == monthR_dp) && (DateObject == 'returnDate'))) 
            document.write(' SELECTED');
        document.write('>' + monthNames[monthNo] + '&nbsp;' + to2digits((year_dp + 1) - 2000) + '</OPTION>');
    }
}

/* pour changement curseur */
function changeCurseur(){
    document.body.style.cursor = "pointer";
}

function curseurBack(){
    document.body.style.cursor = "default";
}
