﻿
function bookingMouseOver(obj){
	obj.src = "/images/booking/BookNow_Bttn_rollover.gif";
}

function bookingMouseOut(obj){
	obj.src = "/images/booking/BookNow_Bttn.gif";
}

function bookingClicked(mytype, departlocid, departdateid, returnlocid, returndateid, numpassengersid) {
    var err = false;
    if (document.getElementById(departlocid).value == "--Select--") {
        err = true;
        alert('Whoops!\nWhich airport will you be flying out of.');
    } else if (document.getElementById(returnlocid).value == "--Select--") {
        err = true;
        alert('Whoops!\nWhich airport will you be flying in to.');
    } else {
        var departdate = new Date(document.getElementById(departdateid).value);
        var returndate = new Date(document.getElementById(returndateid).value);
        var now = new Date();
        now.setHours(0, 0, 0, 0);
        if (departdate == "Invalid Date") {
            err = true;            
            alert('Whoops!\nInvalid departure date. Please use calendar popup for date selection.');
        } else if (returndate == "Invalid Date") {
            err = true;            
            alert('Whoops!\nInvalid return date. Please use calendar popup for date selection.');
        } else if (departdate < now) {
            err = true;
            alert('Whoops!\nYou can not depart before today.');
        } else if (returndate < now) {
            err = true;
            alert('Whoops!\nYou can not return before today.');
        } else if (returndate < departdate) {
            err = true;            
            alert('Whoops!\nInvalid dates. You can not return before you depart.');
        } else {
            var origin = document.getElementById(departlocid).value;
            var destination = document.getElementById(returnlocid).value;            
            var selectDepart = origin.substring(0, origin.indexOf(' ', 0)); 
            var selectReturn = destination.substring(0, destination.indexOf(' ', 0)); 

            if (mytype == 'fare') {
                var myopen = "http://clk.atdmt.com/00A/go/110412218/direct/01/?href=http://www.aa.com/FlightSearch%3FsearchType=matrix%26ADID=AADV-MDL-ALL-09-01";
                myopen += "%26origin=" + selectDepart;
                myopen += "%26destination=" + selectReturn;
                myopen += "%26numAdultPassengers=" + document.getElementById(numpassengersid).value;
                myopen += "%26departureMonth=" + (departdate.getMonth() + 1);
                myopen += "%26departureDay=" + departdate.getDate();
                myopen += "%26departureYear=" + departdate.getFullYear();
                myopen += "%26returnMonth=" + (returndate.getMonth() + 1);
                myopen += "%26returnDay=" + returndate.getDate();
                myopen += "%26returnYear=" + returndate.getFullYear();
            } else {
            var myopen = "http://clk.atdmt.com/00A/go/157494840/direct/01/?href=http://www.aavacations.com/deeplink.asp%3FsearchType=matrix%26ADID=AADV-MDL-ALL-09-01";
                myopen += "%26from_city_code=" + selectDepart;
                myopen += "%26to_city_code=" + selectReturn;
                myopen += "%26adults=" + document.getElementById(numpassengersid).value;
                myopen += "%26from_date=" + (departdate.getMonth() + 1) + "/" + departdate.getDate() + "/" + departdate.getFullYear();
                myopen += "%26to_date=" + (returndate.getMonth() + 1) + "/" + returndate.getDate() + "/" + returndate.getFullYear();
               }
			   myopen += "%26tripType=";

			   if (rblRoundTripRoundTrip.checked)
			   {
			   	myopen += rblRoundTripRoundTrip.value;
			   }
			   else
			   {
			   	myopen += rblRoundTripOneWay.value;
			   };

			   myopen += "%26discountCode=" + txtPromotionCode.value;
            window.open(myopen);return false;
        }
    }
    if (err == true) {
        return false;
    }
}

function bookingDateChange(ctrl, dropDownMonth, dropDownDate) {
	var d1 = new Date(ctrl.value);

	if (dropDownMonth.value != d1.getMonth() + 1 || dropDownDate.value != d1.getDate()) {
		dropDownMonth.value = d1.getMonth() + 1;
		dropDownDate.value = d1.getDate();
	}
}

