﻿var b_stopBit = 0; // Setting to enable Date Increments
var b_overide = 0; //Overide for Survey Popup
s_userAgent = window.navigator.userAgent;
KON = (s_userAgent.indexOf("KHTML") > -1) ? 1 : 0;
isMac = (navigator.userAgent.indexOf("Mac") > -1) ? 1 : 0;
isIE = (navigator.userAgent.indexOf("MSIE") > -1) ? 1 : 0;
isMacIE = (isMac && isIE) ? 1 : 0;
navTimer = null;
currentNav = 0;
var b_loaded = 0;

function cbSetUpnav(){
    a_nav = document.cbNav.nav;
    if (!a_nav.length) 
        o_nav = document.cbNav.nav;
    else 
        for (i = 0; i < a_nav.length; i++) 
            if (a_nav[i].checked) 
                o_nav = a_nav[i];
    document.getElementById("cbForms").style.display = "block";
    cb_ChangeNav(o_nav, o_nav.parentNode);
    b_loaded = 1;
};

function cb_ChangeNav(o_radio, o_span){
    o_li = o_span.parentNode;
    o_ul = o_li.parentNode;
    var isHCX = 0;
    if (cb_ChangeNav.arguments[2]) {
        hcrow = document.getElementById(cb_ChangeNav.arguments[2]);
        o_list = o_ul.getElementsByTagName("li");
        oL = o_list.length - 1;
        b_list = hcrow.getElementsByTagName("li");
        a_lis = new Array();
        for (k = 0; k < o_list.length; k++) {
            a_lis[k] = o_list[k];
            a_lis[k + oL] = b_list[k];
        }
    }
    else {
        a_lis = o_ul.getElementsByTagName("li");
    }
    
    if (o_radio.type == "radio") {
        if (document.getElementById("cb_" + o_radio.value).style.display == "block") {
            return false
        };
            }
    
    for (i = 0; i < a_lis.length; i++) {
        a_lis[i].firstChild.className = "";
        nitem = a_lis[i].firstChild.firstChild;
        nVal = "cb_" + nitem.value;
        navList = document.getElementById(nVal);
        if (nVal == "cb_formHCX" && nitem.checked == true) {
            isHCX = 1;
        }
        navList.style.display = "none";
        navList.style.visibility = "hidden";
    }
    o_li.firstChild.className = "cbNavon";
    if (o_radio.type == "radio") {
        o_radio.checked = true;
    }
    s_radio = o_radio.value;
    document.getElementById("cb_" + s_radio).style.display = "block";
    document.getElementById("cb_" + s_radio).style.visibility = "visible";
    switch (s_radio) {
        case "formair":
            setUpAir();
            break;
        case "formFO":
            if (document.getElementById("h_formFOhp")) {
                document.getElementById("h_formFOhp").name = "tt2";
            }
            cb_bff(document.formFO);
            childAges(document.getElementById("FO_children"), 'cbFOchildages');
            if (document.formFO.inp_num_cnx) {
                document.formFO.inp_num_cnx.value = "";
            }
            break;
        case "formRO":
            if (document.getElementById('cb_formHCX')) {
                document.getElementById('cb_formHCX').style.display = 'none';
            }
            break;
        case "formFH":
            if (document.getElementById("FH_totalrooms")) {
                multirooms(document.getElementById("FH_totalrooms"));
            }
            break;
        case "formHO":
            cb_hoscope(document.getElementById("HO_country"), "cbHOstate");
            if (document.getElementById("HO_addair")) {
                cb_hoaddair();
                cb_hoshowhideair(document.formHO);
            }
            if (document.getElementById("HO_totalrooms")) {
                multirooms(document.getElementById("HO_totalrooms"));
            }
            break;
        case "formFRT":
            cb_SSA(document.formFRT.pref_aln[0]);
            cb_bff(document.formFRT);
            childAges(document.getElementById("FRT_children"), 'cbFRTchildages');
            break;
        case "formFOW":
            cb_SSA(document.formFOW.pref_aln[0]);
            cb_bff(document.formFOW);
            childAges(document.getElementById("FOW_children"), 'cbFOWchildages');
            break;
        case "formFMD":
            cb_SSA(document.formFMD.pref_aln[0]);
            childAges(document.getElementById("FMD_children"), 'cbFMDchildages');
            break;
        case "formCO":
            if (isHCX == 1) {
                if (document.getElementById('subHCX').checked == true) {
                    document.getElementById('cb_formHCX').style.display = 'block';
                    document.getElementById('cb_formHCX').style.visibility = 'visible';
                    document.getElementById('cb_formCO').style.display = 'none';
                    document.getElementById('cb_formCO').style.visibility = 'hidden';
                }
                else {
                    document.getElementById('cb_formHCX').style.display = 'none';
                    document.getElementById('cb_formHCX').style.visibility = 'hidden';
                    document.getElementById('cb_formCO').style.display = 'block';
                    document.getElementById('cb_formCO').style.display = 'visible';
                }
                if (document.getElementById("HCX_pickupoption")) {
                    carPUDO(document.getElementById("HCX_pickupoption"));
                }
            }
            else {
                carPUDO(document.getElementById("FCO_pickupoption"));
                if (document.getElementById('discountProvider1')) {
                    freqRenter('discountProvider1');
                }
            }
            break;
        case "formPD":
            cb_SetActField("act_citytext");
            break;
        case "formED":
            cb_SetActField("act_city");
            break;
        case "formTSH":
            if (document.getElementById('ts-hotels').checked == true) {
                document.getElementById('formHOfields').style.display = 'none';
                document.getElementById('formHOfields').style.visibility = 'hidden';
                document.getElementById('cb_formTSH').style.display = 'block';
                document.getElementById('cb_formTSH').style.visibility = 'visible';
                document.formHO.opaqueTabSelected.value = "1";
                document.getElementById('submitHO').innerHTML = "<div>Search Top Secret Hotels</div>";
                document.getElementById('submitHO').className = "double";
                document.getElementById('HO_country').options[0].selected = true;
            }
            else {
                document.getElementById('formHOfields').style.display = 'block';
                document.getElementById('formHOfields').style.visibility = 'visible';
                document.getElementById('cb_formTSH').style.display = 'none';
                document.getElementById('cb_formTSH').style.visibility = 'hidden';
                document.formHO.opaqueTabSelected.value = "0";
                document.getElementById('submitHO').innerHTML = "<div>Search Hotels</div>";
                document.getElementById('submitHO').className = "single";
            }
            break;
        case "formHCX":
            if (document.getElementById('ts-hotels')) {
                document.getElementById('ts-hotels').checked = false;
                document.getElementById('cb_formTSH').style.display = 'none';
                document.getElementById('cb_formTSH').style.visibility = 'hidden';
                document.getElementById('formHOfields').style.display = 'block';
                document.getElementById('formHOfields').style.visibility = 'visible';
            }
            break;
        case "formTSC":
            if (document.getElementById('ts-cars').checked == true) {
                document.getElementById('cb_formTSC').style.display = 'none';
                document.getElementById('doLinkTSC').style.display = 'block';
                document.getElementById('corporate-discount').style.display = 'none';
                document.getElementById('cars-cboptions').style.display = 'none';
                document.getElementById('pck-city').style.display = 'none';
                document.getElementById('fco_nearaddress').style.display = 'none';
                document.getElementById('fco_nearplace').style.display = 'none';
                document.getElementById('fco_airport').style.display = 'block';
                document.formCO.opaqueCar.value = "true";
                document.formCO.lastRdoLocPickup.value = document.formCO.rdoLocPickup.selectedIndex;
                document.formCO.rdoLocPickup.selectedIndex = 0;
                document.getElementById('submitCO').innerHTML = "<div>Search Top Secret Cars</div>";
                document.getElementById('submitCO').className = "double";
            }
            else {
                document.getElementById('cb_formTSC').style.display = 'block';
                document.getElementById('doLinkTSC').style.display = 'none';
                document.getElementById('corporate-discount').style.display = 'block';
                document.getElementById('cars-cboptions').style.display = 'block';
                document.getElementById('pck-city').style.display = 'inline';
                if (!isNaN(parseInt(document.formCO.lastRdoLocPickup.value))) 
                    document.formCO.rdoLocPickup.selectedIndex = parseInt(document.formCO.lastRdoLocPickup.value);
                document.formCO.lastRdoLocPickup.value = "";
                var pickup_select = document.getElementById("FCO_pickupoption");
                carPUDO(pickup_select);
                document.formCO.opaqueCar.value = "false";
                document.getElementById('submitCO').innerHTML = "<div>Search Cars</div>";
                document.getElementById('submitCO').className = "single";
            }
            break;
        default:
    }
    if (isMacIE) 
        fixMacIEselect("cb_" + o_radio.value, o_radio);
    return false;
};

function cb_hidePromo(o_select, s_id){
    if (document.getElementById(s_id)) 
        document.getElementById(s_id).style.display = (o_select.selectedIndex != '0' ? 'none' : 'block');
};

function getMousePos(evt){
    if (window.event) {
        s_srcElement = window.event.srcElement.nodeName;
        //Safari will set the clienty of an event from a form input to the form offset
        yPos = (s_srcElement == "INPUT" && KON) ? Math.abs(window.event.offsetY) + 10 : window.event.clientY - 5;
    }
    else 
        if (document.getElementById && !document.all) {
            xPos = evt.clientX + 165;
            yPos = evt.clientY - 5;
        }
        else {
            xPos = 50;
            yPos = 50;
        }
};

function getCBform(){
    for (i = 0; i < document.cbNav.nav.length; i++) {
        if (document.cbNav.nav[i].checked) 
            s_form = document.cbNav.nav[i].value;
    }
    return s_form;
};

function parseCalDate(o_input){
    o_dateinput = eval("document." + getCBform() + "." + o_input);
    s_dateinput = o_dateinput.value;
    if (s_dateinput.indexOf("/") > -1) 
        a_dateinput = s_dateinput.split("/");
    return a_dateinput;
};

function maintainState(o_input){
    if (!b_loaded) 
        return false;
    a_bit = o_input.id.split("_");
    s_bit = a_bit[1];
    for (i = 0; i < document.cbNav.nav.length; i++) {
        a_formbit = document.cbNav.nav[i].value.split("form");
        s_formbit = a_formbit[1];
        o_formelement = document.getElementById(s_formbit + "_" + s_bit);
        if (eval("document." + document.cbNav.nav[i].value) && o_formelement != o_input) {
            if (o_formelement && o_formelement != o_input && o_input.type != "radio") {
                if (o_formelement.type == "select-one" && o_formelement.type == o_input.type) {
                    for (var j = o_formelement.length - 1; j > -1; j--) {
                        if (o_formelement.options[j].text == o_input.options[o_input.selectedIndex].text) {
                            o_formelement.options[j].selected = true;
                            break;
                        }
                    }
                }
                else 
                    if (o_formelement.type == o_input.type) 
                        o_formelement.value = o_input.value;
            }
            else {
                a_input = eval("document." + document.cbNav.nav[i].value + "." + o_input.name);
                if (a_input) 
                    for (j = 0; j < a_input.length; j++) 
                        if (a_input[j] != o_input && a_input[j].value == o_input.value) 
                            a_input[j].checked = "checked";
            }
        }
    };
};

function populateDate(){
    var m_names = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    var o_todays_date = new Date;
    var a_currentYear = o_todays_date.getFullYear();
    var a_currentMonth = o_todays_date.getMonth();
    var s_form_options = new String();
    var s_monthRange = 6;
    for (i = 0; i < s_monthRange; i++) {
        s_form_options = s_form_options + ' < option value="' + eval(o_todays_date.getMonth() + 1) + '-' + o_todays_date.getFullYear() + '">' + m_names[eval(o_todays_date.getMonth() + 1)] + '-' + o_todays_date.getFullYear() + ' ';
        o_todays_date.setMonth(o_todays_date.getMonth() + 1);
    };
    document.write(s_form_options);
};

function childAges(o_select, s_div){
    o_div = document.getElementById(s_div);
    if (o_select.selectedIndex != 0) {
        if (s_div == "cbFOchildages") 
            document.getElementById("cbFOpromo").style.display = "none";
        if (s_div == "cbFHchildages") 
            document.getElementById("cbFHpromo").style.display = "none";
        a_children = o_div.getElementsByTagName("div");
        o_div.style.display = "block";
        for (i = 0; i < a_children.length; i++) 
            a_children[i].style.visibility = (i < o_select.selectedIndex) ? "visible" : "hidden";
    }
    else {
        if (s_div == "cbFOchildages" && document.getElementById("cbFOpromo")) 
            document.getElementById("cbFOpromo").style.display = "block";
        if (s_div == "cbFHchildages" && document.getElementById("cbFHpromo")) 
            document.getElementById("cbFHpromo").style.display = "block";
        o_div.style.display = "none";
    }
};

function cb_SSA(o_input){
    o_form = o_input.form;
    s_input = o_input.name;
    a_input = eval("o_form." + s_input);
    for (i = 0; i < a_input.length; i++) 
        if (a_input[i].checked) 
            o_input = a_input[i];
    o_ul = o_input.parentNode.parentNode;
    a_li = o_ul.getElementsByTagName("li");
    s_display = (o_input.value == "spec") ? "block" : "none";
    for (i = 0; i < a_li.length; i++) 
        if (a_li[i].className == "specificair") 
            a_li[i].style.display = s_display;
};

function cb_bff(o_form){
	s_radio="";
	a_formbits=o_form.name.split("form");
	s_formbit=a_formbits[1];
	a_radio=(o_form.name=="formFOW")?o_form.module:o_form.SearchMethod;
	for(i=0;i<a_radio.length;i++){if(a_radio[i].checked){
		s_radio=a_radio[i].value;
		o_radio=a_radio[i];}
	};
	if(s_radio=="tripsrch"){s_radio="LowFareByDate";}
	if(s_radio=="calendar"){s_radio="BestFareFinder";}
	switch(s_radio){
		case "LowFareByDate":
			if(document.getElementById("cb"+s_formbit+"bff")){
				document.getElementById("cb"+s_formbit+"bff").style.display="none";
			}else{
				document.getElementById("cb"+s_formbit+"bffstart").style.display="none";
				document.getElementById("cb"+s_formbit+"bffthru").style.display="none";}
			switch(s_formbit){
				case "FO":
				document.getElementById(s_formbit+"_fromcal").style.display="block";
				document.getElementById(s_formbit+"_tocal").style.display="block"; 
				document.getElementById("cbSubmitText").style.display="block";
				document.getElementById("FHbutton").style.display="block";			
				break;case "FRT":
				o_form.module.value="tripsrch";
				document.getElementById(s_formbit+"_tocal").style.visibility="visible";			
				document.getElementById(s_formbit+"_fromcal").style.display="inline";					
				document.getElementById("cbFRTmsg").style.visibility="visible";
				document.getElementById(s_formbit+"_addopt").style.visibility="visible";
				break;case "FOW":	
					document.getElementById(s_formbit+"_fromcal").style.display="inline";	
					document.getElementById(s_formbit+"_addopt").style.visibility="visible";
				break;default:}				
			if(document.getElementById("cb"+s_formbit+"nobff"))document.getElementById("cb"+s_formbit+"nobff").style.display="inline";
			if(document.getElementById("cb"+s_formbit+"promo"))document.getElementById("cb"+s_formbit+"promo").style.visibility="visible";					
		break;case "BestFareFinder":
			switch(s_formbit){
				case "FO":
					document.getElementById(s_formbit+"_tocal").style.display="none";			
					document.getElementById(s_formbit+"_fromcal").style.display="none";	
					document.getElementById("cbSubmitText").style.display="none";
					document.getElementById("FHbutton").style.display="none";			
				break;case "FRT":
					o_form.module.value="calendar";
					document.getElementById(s_formbit+"_tocal").style.visibility="hidden";
					document.getElementById(s_formbit+"_fromcal").style.display="none";
					document.getElementById("cbFRTmsg").style.visibility="hidden";
					document.getElementById(s_formbit+"_addopt").style.visibility="hidden";													
					if(o_form.FRT_addHot.checked)o_form.FRT_addHot.checked=false;
					addHotel(o_form.FRT_addHot);
				break;case "FOW":	
					document.getElementById(s_formbit+"_fromcal").style.display="none";
					document.getElementById(s_formbit+"_addopt").style.visibility="hidden";
				break;default:}
			if(document.getElementById("cb"+s_formbit+"bff")){
				document.getElementById("cb"+s_formbit+"bff").style.display="inline";
			}else{
				document.getElementById("cb"+s_formbit+"bffstart").style.display="block";
				document.getElementById("cb"+s_formbit+"bffthru").style.display="block";}
			if(isMacIE)fixMacIEselect("cb_"+o_form.name,o_radio);
			if(document.getElementById("cb"+s_formbit+"nobff"))document.getElementById("cb"+s_formbit+"nobff").style.display="none";
			if(document.getElementById("cb"+s_formbit+"promo"))document.getElementById("cb"+s_formbit+"promo").style.visibility="hidden";							
		break;
	}
};

function addHotelFO(o_form){
    if (checkform(o_form, 1, 2, 3, 4, 5, 6)) {
        document.getElementById("h_formFOhp").name = "htl_pkgs";
        document.formFO.inp_num_cnx.value = "1";
        document.formFO.submit();
    }
    else {
        return false
    }
};

function addHotel(o_input){
    o_form = o_input.form;
    switch (o_input.checked) {
        case true:
            o_form.htl_pkgs.disabled = false;
            o_form.action = o_form.fhaction.value;
            document.getElementById("FRT_from").name = "inp_dep_arp_cd_1";
            o_frommonth = document.getElementById("FRT_frommonth");
            o_frommonth.name = "leaveMonth";
            o_frommonth[o_frommonth.selectedIndex].value = o_frommonth.selectedIndex + 1;
            document.getElementById("FRT_frommonth").selectedIndex;
            document.getElementById("FRT_fromdate").name = "inp_dep_dt_dy_1";
            document.getElementById("FRT_fromtime").name = "inp_dep_tm_1";
            document.getElementById("FRT_to").name = "inp_arr_arp_cd_1";
            o_tomonth = document.getElementById("FRT_tomonth");
            o_tomonth.name = "returnMonth";
            o_tomonth[o_tomonth.selectedIndex].value = o_tomonth.selectedIndex + 1;
            document.getElementById("FRT_todate").name = "inp_ret_dep_dt_dy";
            document.getElementById("FRT_totime").name = "inp_ret_dep_tm";
            document.getElementById("FRT_adults").name = "inp_adult_pax_cnt";
            document.getElementById("FRT_children").name = "inp_child_pax_cnt";
            document.getElementById("FRT_seniors").name = "inp_senior_pax_cnt";
            document.getElementById("FRT_con").name = "inp_num_cnx";
            break;
        default:
            o_form.trip_option.value = "roundtrp";
            o_form.htl_pkgs.disabled = true;
            o_form.action = o_form.rtaction.value;
            document.getElementById("FRT_from").name = "dep_arp_cd(1)";
            o_frommonth = document.getElementById("FRT_frommonth");
            o_frommonth.name = "dep_dt_mn_1";
            o_frommonth[o_frommonth.selectedIndex].value = o_frommonth[o_frommonth.selectedIndex].text;
            document.getElementById("FRT_fromdate").name = "dep_dt_dy_1";
            document.getElementById("FRT_fromtime").name = "dep_tm_1";
            document.getElementById("FRT_to").name = "arr_arp_cd(1)";
            o_tomonth = document.getElementById("FRT_tomonth");
            o_tomonth.name = "dep_dt_mn_2";
            o_tomonth[o_tomonth.selectedIndex].value = o_tomonth[o_tomonth.selectedIndex].text;
            document.getElementById("FRT_todate").name = "dep_dt_dy_2";
            document.getElementById("FRT_totime").name = "dep_tm_2";
            document.getElementById("FRT_adults").name = "adult_pax_cnt";
            document.getElementById("FRT_children").name = "chld_pax_cnt";
            document.getElementById("FRT_seniors").name = "senior_pax_cnt";
            document.getElementById("FRT_con").name = "num_cnx";
    }
};

function cb_destination(o_form){
    s_radio = "";
    for (i = 0; i < o_form.searchoption.length; i++) 
        if (o_form.searchoption[i].checked) 
            s_radio = o_form.searchoption[i].value;
    switch (s_radio) {
        case "USorCA":
            document.getElementById("cbHOstate").style.visibility = "visible";
            document.getElementById("HO_to").name = "city";
            o_form.searchMode.value = "city";//o_form.mode.value="1";
            break;
        default:
            document.getElementById("cbHOstate").style.visibility = "hidden";
            document.getElementById("HO_to").name = "airport";
            o_form.searchMode.value = "airport";//o_form.mode.value="2";
    }
    return false;
};

function cb_specificAirlines(o_input){
    if (o_input.value.length > 0) {
        o_dl = o_input.parentNode.parentNode;
        a_dd = o_dl.getElementsByTagName("dd");
        for (i = 0; i < a_dd.length; i++) 
            a_dd[i].className = "display"
    }
    else {
        for (i = 1; i < a_dd.length; i++) 
            a_dd[i].className = "";
    }
};

function fixMacIEselect(s_formdivid, o_radio){
    o_formdiv = document.getElementById(s_formdivid);
    a_modOptions = o_formdiv.getElementsByTagName("select");
    if (a_modOptions) 
        for (i = 0; i < a_modOptions.length; i++) {
            a_modOptions[i].focus();
            a_modOptions[i].blur();
        }
    o_radio.focus();
};

function departureArrival(o_form){
    if (o_form.aln_name.selectedIndex == 0) {
        alert(o_form.error1.value);
        return false;
    }
    if (o_form.flt_num.value == "Flight #") {
        alert(o_form.error2.value);
        return false;
    }
    return true;
};

function addvars(url, o_form){
    s_url = new String(url);
    s_url += "&expr_path=" + o_form.expr_path.value;
    s_url += (o_form.name == "formHOgbl") ? "&airport=" + o_form.airport.value : "&city=" + o_form.city.value;
    s_url += "&searchMode=" + o_form.searchMode.value;
    o_hototalrooms = document.getElementById("HO_totalrooms");
    if (o_hototalrooms) {
        s_url += "&numRooms=" + o_hototalrooms.options[o_hototalrooms.selectedIndex].text;
        s_url += "&leavingDate=" + document.getElementById("HO_fromdate").value;
        s_url += "&returningDate=" + document.getElementById("HO_todate").value;
        if (o_hototalrooms.options[o_hototalrooms.selectedIndex].text.indexOf("+") == -1) {
            for (var i = 1; i < o_hototalrooms.selectedIndex + 2; i++) {
                o_adult = document.getElementById("HO_adult" + i);
                s_url += "&adult" + (i) + "=" + o_adult.options[o_adult.selectedIndex].text;
                o_child = document.getElementById("HO_child" + i);
                s_url += "&child" + (i) + "=" + o_child.options[o_child.selectedIndex].text;
            }
        }
    }
    else {
        s_url += "&adults=" + o_form.adults.options[o_form.adults.selectedIndex].text;
        s_url += "&children=" + o_form.children.options[o_form.children.selectedIndex].text;
        s_url += "&dateLeavingMonth=" + o_form.dateLeavingMonth.value;
        s_url += "&dateLeavingDay=" + o_form.dateLeavingDay.value;
        s_url += "&dateReturningMonth=" + o_form.dateReturningMonth.value;
        s_url += "&dateReturningDay=" + o_form.dateReturningDay.value;
        s_url += "&searchMode=" + o_form.searchMode.value;
    }
    s_url += "&state=" + o_form.state.value;
    if (o_form.cityCountryCode) 
        s_url += "&cityCountryCode=" + o_form.cityCountryCode.value;
    parent.window.location = s_url;
}

function cb_hoscope(o_select, s_state){
    switch (o_select.value.toLowerCase()) {
        case "us":
        case "ca":
            document.getElementById(s_state).style.visibility = "visible";
            break;
        default:
            document.getElementById(s_state).style.visibility = "hidden";
    }
}

function cb_hoGetYear(i_month, i_date){
    d_today = new Date();
    i_year = d_today.getFullYear();
    if (i_month <= d_today.getMonth() + 1 && i_date < d_today.getDate()) 
        i_year += 1;
    return i_year;
}

function cb_hosubmit(o_form){
    b_form = false;
    if (o_form.rooms) {
        s_radio = "";
        for (var i = 0; i < o_form.rooms.length; i++) {
            if (o_form.rooms[i].checked) {
                s_radio = o_form.rooms[i].value;
            }
        };
        if (s_radio == "groople") {
            s_fiveplusrooms = "/HotelPlanner?";
            s_fiveplusrooms += "Checkin=" + o_form.dateLeavingMonth.value + "/" + o_form.dateLeavingDay.value + "/" + cb_hoGetYear(o_form.dateLeavingMonth.value, o_form.dateLeavingDay.value);
            s_fiveplusrooms += "&Checkout=" + o_form.dateReturningMonth.value + "/" + o_form.dateReturningDay.value + "/" + cb_hoGetYear(o_form.dateReturningMonth.value, o_form.dateReturningDay.value);
            switch (o_form.cityCountryCode.value.toLowerCase()) {
                case "us":
                case "ca":
                    if (o_form.city.value !== "") {
                        s_fiveplusrooms += "&City=" + escape(o_form.city.value);
                    }
                    else {
                        s_fiveplusrooms += "&City=";
                    }
                    if (o_form.city.value !== "" && o_form.state.value !== "") {
                        s_fiveplusrooms += ",%20";
                    }
                    if (o_form.state.value != "") {
                        s_fiveplusrooms += o_form.state.value;
                    }
                    break;
                default:
                    s_fiveplusrooms += "&City=" + escape(o_form.city.value);
            }
            s_fiveplusrooms += "&Rooms=5";
            window.open(s_fiveplusrooms, null, 'width=954,height=730,resizable=yes,scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,copyhistory=yes');
        }
        else {
            b_form = (document.getElementById("HO_fromdate").nodeName.toLowerCase() == "input") ? b_form = checkform(o_form, 1, 2, 3, 8, 9) : checkform(o_form, 1, 2, 3, 6);
        }
    }
    else 
        if (o_form.numRooms) {
            if (o_form.numRooms.options[o_form.numRooms.selectedIndex].text.indexOf("+") > -1) {
                s_fiveplusrooms = "/HotelPlanner?";
                s_fiveplusrooms += "Checkin=" + o_form.leavingDate.value;
                s_fiveplusrooms += "&Checkout=" + o_form.returningDate.value;
                switch (o_form.cityCountryCode.options[o_form.cityCountryCode.selectedIndex].value.toLowerCase()) {
                    case "us":
                    case "ca":
                        if (o_form.city.value !== "") {
                            s_fiveplusrooms += "&City=" + escape(o_form.city.value);
                        }
                        else {
                            s_fiveplusrooms += "&City=";
                        }
                        if (o_form.city.value !== "" && o_form.state.options[o_form.state.selectedIndex].value !== "") {
                            s_fiveplusrooms += ",%20";
                        }
                        if (o_form.state.options[o_form.state.selectedIndex].value != "") {
                            s_fiveplusrooms += o_form.state.options[o_form.state.selectedIndex].value;
                        }
                        break;
                    default:
                        if (o_form.city.value !== "") {
                            s_fiveplusrooms += "&City=" + escape(o_form.city.value);
                        }
                        else {
                            s_fiveplusrooms += "&City=";
                        }
                        if (o_form.city.value && o_form.cityCountryCode.options[o_form.cityCountryCode.selectedIndex].value !== "") {
                            s_fiveplusrooms += ",%20";
                        }
                        if (o_form.cityCountryCode.options[o_form.cityCountryCode.selectedIndex].value !== "") {
                            s_fiveplusrooms += o_form.cityCountryCode.options[o_form.cityCountryCode.selectedIndex].value.substr(0, 2);
                        }
                }
                s_fiveplusrooms += "&Rooms=5";
                window.open(s_fiveplusrooms, null, 'width=954,height=730,resizable=yes,scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,copyhistory=yes');
            }
            else {
                var __toDate = document.getElementById("HO_todate");
                var __fromDate = document.getElementById("HO_fromdate");
                b_form = ((__toDate.value == "mm/dd/yyyy" || __toDate.value == "") && (__fromDate.value == "mm/dd/yyyy" || __fromDate.value == "")) ? checkform(o_form, 1, 2, 3, 9) : checkform(o_form, 1, 2, 3, 8, 9);
            }
        }
    return b_form;
};

function LinkSubmitHotelGroups(o_form){
    fiveplusrooms_url = "/HotelPlanner?";
    fiveplusrooms_url += "Checkin=" + o_form.leavingDate.value;
    fiveplusrooms_url += "&Checkout=" + o_form.returningDate.value;
    switch (o_form.cityCountryCode.options[o_form.cityCountryCode.selectedIndex].value.toLowerCase()) {
        case "us":
        case "ca":
            if (o_form.city.value !== "") {
                fiveplusrooms_url += "&City=" + escape(o_form.city.value);
            }
            else {
                fiveplusrooms_url += "&City=";
            }
            if (o_form.city.value !== "" && o_form.state.options[o_form.state.selectedIndex].value !== "") {
                fiveplusrooms_url += ",%20";
            }
            if (o_form.state.options[o_form.state.selectedIndex].value != "") {
                fiveplusrooms_url += o_form.state.options[o_form.state.selectedIndex].value;
            }
            break;
        default:
            if (o_form.city.value !== "") {
                fiveplusrooms_url += "&City=" + escape(o_form.city.value);
            }
            else {
                fiveplusrooms_url += "&City=";
            }
            if (o_form.city.value && o_form.cityCountryCode.options[o_form.cityCountryCode.selectedIndex].value !== "") {
                fiveplusrooms_url += ",%20";
            }
            if (o_form.cityCountryCode.options[o_form.cityCountryCode.selectedIndex].value !== "") {
                fiveplusrooms_url += o_form.cityCountryCode.options[o_form.cityCountryCode.selectedIndex].value.substr(0, 2);
            }
    }
    fiveplusrooms_url += "&Rooms=5";
    window.open(fiveplusrooms_url, null, 'width=954,height=730,resizable=yes,scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,copyhistory=yes');
};

function carPUDO(o_select){
	sPfx=o_select.id.split("_");
	sPrefix=sPfx[0].toLowerCase();
	switch(o_select.options[o_select.selectedIndex].value){
		case "pu_air":
			if(document.getElementById(sPrefix+"_airport"))document.getElementById(sPrefix+"_airport").style.display="block";
			if(document.getElementById(sPrefix+"_nearaddress"))document.getElementById(sPrefix+"_nearaddress").style.display="none";
			if(document.getElementById(sPrefix+"_nearplace"))document.getElementById(sPrefix+"_nearplace").style.display="none";
		break;case "pu_addr":
			document.getElementById(sPrefix+"_airport").style.display="none";
			document.getElementById(sPrefix+"_nearaddress").style.display="block";
			document.getElementById(sPrefix+"_nearplace").style.display="none";	
		break;case "pu_poi":
			document.getElementById(sPrefix+"_airport").style.display="none";
			document.getElementById(sPrefix+"_nearaddress").style.display="none";
			document.getElementById(sPrefix+"_nearplace").style.display="block";	
		break;default:
			window.location=o_select.options[o_select.selectedIndex].value;
	}
};

function checkCar(o_form){
o_select=document.getElementById("FCO_pickupoption");
switch(o_select.options[o_select.selectedIndex].value){
	case "pu_poi":b_checkCar = checkform(o_form,2,3,8);break;
	case "pu_addr":b_checkCar = checkform(o_form,8);break;
	default:b_checkCar = checkform(o_form,1,2,3,8);}
s_popFlag='1';
loadPopOrNot(b_checkCar,s_popFlag,o_form);	
return b_checkCar;};

function chkForMatch(){
if((document.getElementById("CO_to").value.toUpperCase()==document.getElementById("CO_do").value.toUpperCase())&&document.getElementById("FCO_dropoffoption").value=='do_air'){
	document.getElementById("CO_do").value='';
	document.getElementById("FCO_dropoffoption").options[document.getElementById("FCO_dropoffoption").selectedIndex].value='';
	return true;}
return true;};

function adjDate(o_form){
    if (b_stopBit == 0) {
        var a_selectedForm;
        var o_todays_date = new Date;
        var a_currentYear = o_todays_date.getFullYear();
        if (o_form) {
            a_selectedForm = o_form.name;
        }
        else {
            a_selectedForm = getCBform();
        }
        var a_formPrefix = a_selectedForm.substring(4);
        var a_fromVal = document.getElementById(a_formPrefix + "_fromdate").value;
        var a_fromMonth = document.getElementById(a_formPrefix + "_frommonth").selectedIndex;
        var cmonth = o_todays_date.getMonth();
        var fmonth;
        if (typeof(a_fromVal) != 'undefined') {
            var monthOnly = a_fromVal.substr(0, 2);
            fmonth = parseInt(monthOnly);
        }
        else {
            fmonth = cmonth;
        }
        if (typeof(a_fromMonth) != 'undefined') {
            fmonth = parseInt(a_fromMonth);
        }
        else {
            fmonth = cmonth;
        }
        if (fmonth < cmonth) {
            a_currentYear += 1;
        }
        var o_days = new Array(31, ((a_currentYear % 4 == 0 && a_currentYear % 100 != 0) || a_currentYear % 400 == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        var a_dateDiff = 3;
        if (a_fromVal > o_days[a_fromMonth]) {
            document.getElementById(a_formPrefix + "_fromdate").options[eval(o_days[a_fromMonth] - 1)].selected = true;
            var a_fromVal = document.getElementById(a_formPrefix + "_fromdate").value;
        }
        var o_selectedDate = new Date(a_currentYear, a_fromMonth, a_fromVal);
        var o_toDate = o_selectedDate.setDate(o_selectedDate.getDate() + a_dateDiff);
        document.getElementById(a_formPrefix + "_tomonth").options[o_selectedDate.getMonth()].selected = true;
        document.getElementById(a_formPrefix + "_todate").options[(o_selectedDate.getDate() - 1)].selected = true;
        maintainState(document.getElementById(a_formPrefix + "_tomonth"));
        maintainState(document.getElementById(a_formPrefix + "_todate"));
        maintainState(document.getElementById(a_formPrefix + "_fromdate"));
        maintainState(document.getElementById(a_formPrefix + "_frommonth"));
        var a_fromMonth;
        var a_fromVal;
        var a_currentYear;
        var selectedDate;
    }
};

function SetCookie(cookieName, cookieValue, nDays){
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) {
        nDays = 1;
    }
    expire.setTime(today.getTime() + 24 * 60 * 60 * 1000 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
};

function GetCookie(Name){
    var search = Name + "=";
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) {
                end = document.cookie.length;
            }
            returnvalue = unescape(document.cookie.substring(offset, end));
        }
    }
    return returnvalue;
};

function formCtrl(o_form){
s_formName=o_form.name;
var b_submit=false;
var s_popFlag='0';
switch (s_formName){  
	case 'formCO':o_select=document.getElementById("FCO_pickupoption");
		switch(o_select.options[o_select.selectedIndex].value){
			case "pu_poi":b_submit=checkform(o_form,2,3,8);break;
			case "pu_addr":b_submit=checkform(o_form,8);break;
			default:b_submit=checkform(o_form,1,2,3,8);}
		s_popFlag='1';break;
	case 'formair':b_submit=checkform(document.formair,1,2,3,4,5,8);
		if(!b_submit&&document.getElementById("FHbutton"))document.getElementById("FHbutton").disabled=false;
		s_popFlag='1';break;
	case 'formFO':
	case 'formFRT':
	case 'formFMD':b_submit=checkform(o_form,1,2,3,4,5,6);
		s_popFlag='0';break;
	case 'formFH':b_submit=checkform(o_form,1,2,3,4,8,9);
		s_popFlag='1';break;
	case 'formHOgbl':
	case 'formHOus':b_submit=checkform(o_form,1,2,3,6);
		s_popFlag='1';break;
	case 'formFOW':b_submit=checkform(o_form,1,2,3,4,5);
		s_popFlag='0';break;
	case 'formHCX':o_select=document.getElementById("HCX_pickupoption");
		if(o_select){switch(o_select.options[o_select.selectedIndex].value){
			case "pu_poi":b_submit=checkform(o_form,2,3,6);break;
			case "pu_addr":b_submit=checkform(o_form,6);break;
			default:b_submit=checkform(o_form,1,2,3,6);}
		}else{b_submit=checkform(o_form,1,2,3,5,8,9);}
		s_popFlag='1';break;
	case 'formHO':
		if(document.getElementById('ts-hotels') && document.getElementById('ts-hotels').checked == true) {
			populateTSHDest('TS_HO_destlist','HO_to','HO_country');
		}
		b_submit=cb_hosubmit(o_form);
		s_popFlag='1';break;
	case 'formact':b_submit=checkform(o_form,8);
		s_popFlag='0';break;}
loadPopOrNot(b_submit,s_popFlag,o_form);
if (b_submit) {
var bscrape = buttonScrape();
}
return b_submit;};

function buttonScrape(){
    var submitButtons = document.getElementById("cbForms").getElementsByTagName("button");
    for (var x = 0; x < submitButtons.length; x++) {
        submitButtons[x].innerHTML = "Search";
    }
    return true;
};

function getElementByValue(ElementCollection, Value){var i, Element;
for(i=0;i<ElementCollection.length;i++){
	if(ElementCollection[i].value == Value){return ElementCollection[i];}
}return null;}

var once_per_session='1';
var popunder="/popWindow";
var winfeatures="left=150,top=200,width=500,height=250,scrollbars=0,resizable=0,toolbar=0,location=0,menubar=0,status=1,directories=0";

function loadPopOrNot() {
	var once_per_session, a_arguments, b_submit, s_popFlag, o_form;
	once_per_session = 1;
	a_arguments = [];
	a_arguments = loadPopOrNot.arguments;
	b_submit = a_arguments[0];
	s_popFlag = a_arguments[1];
	o_form = a_arguments[2];
	if (b_submit && s_popFlag == "1") {
		if (once_per_session === 0) {
			loadpopunder(o_form);
		} else {
			if (!GetCookie("popunder")) {
				SetCookie("popunder", "yes", "1");
				loadpopunder(o_form);
			}
		}
	}
};


function loadpopunder(o_form){
    var iphone = navigator.userAgent.toLowerCase().indexOf('iphone');
    var s_theURL = location.href;
    var i_s59Svc1 = s_theURL.indexOf('S59BT');
    var i_s59Svc2 = s_theURL.indexOf('S59LG');
    var i_gomezSvc = s_theURL.indexOf('ROBOT-GOMEZ');
    var i_aarpSvc = s_theURL.toUpperCase().indexOf('AARP');
    var i_tcyca = s_theURL.toUpperCase().indexOf('TRAVELOCITY.CA');
    var i_aolsvc = s_theURL.toUpperCase().indexOf('AOLSVC');
    var i_tcymx = s_theURL.toUpperCase().indexOf('MX');
    var i_tcyar = s_theURL.toUpperCase().indexOf('COM.AR');
    var i_tcyla = s_theURL.toUpperCase().indexOf('COM/LA');
    var s_theAdtoShow;
    var s_days;
    var i_triptype;
    var s_theDomain = document.location.hostname;
    var s_selectedForm = o_form.name;
    var a_formPrefix = s_selectedForm.substring(4);
    var s_prefix = (s_selectedForm == 'formair') ? 'air' : (s_selectedForm == 'formFH') ? 'FH' : (s_selectedForm == 'formHO') ? 'HO' : (s_selectedForm == 'formHCX') ? 'HCX' : 'air';
    if (s_selectedForm == 'formFOW') {
        var a_fromDate = document.getElementById(a_formPrefix + "_fromdate").value;
        var a_fromMonth = document.getElementById(a_formPrefix + "_frommonth").selectedIndex;
        var b_bestFareFinder = getElementByValue(o_form, "calendar");
        b_bestFareFinder = (b_bestFareFinder) ? b_bestFareFinder.checked : false;
        b_bestFareFinder = (b_bestFareFinder) ? true : false;
    }
    else 
        if (s_selectedForm == 'formair' || s_selectedForm == 'formFH' || s_selectedForm == 'formHO' || s_selectedForm == 'formHCX') {
            var s_orig = (document.getElementById(s_prefix + "_from")) ? document.getElementById(s_prefix + "_from").value.toUpperCase() : '';
            var s_dest = (document.getElementById(s_prefix + "_to")) ? document.getElementById(s_prefix + "_to").value.toUpperCase() : '';
            var a_fromDate = document.getElementById(s_prefix + '_fromdate').value.split('/')[1];
            var a_fromMonth = document.getElementById(s_prefix + '_fromdate').value.split('/')[0];
            var a_fromYear = document.getElementById(s_prefix + '_fromdate').value.split('/')[2];
            var a_toDate = document.getElementById(s_prefix + '_todate').value.split('/')[1];
            var a_toMonth = document.getElementById(s_prefix + '_todate').value.split('/')[0];
            var a_toYear = document.getElementById(s_prefix + '_todate').value.split('/')[2];
            if (document.getElementById("HCX_carpu")) {
                var startTime = (String(document.getElementById("HCX_carpu").selectedIndex).length == 1) ? "&startTime=0" + document.getElementById("HCX_carpu").value : "&startTime=" + document.getElementById("HCX_carpu").value;
            }
            else {
                var startTime = "";
            }
            if (document.getElementById("HCX_cardo")) {
                var endTime = (String(document.getElementById("HCX_cardo").selectedIndex).length == 1) ? "&endTime=0" + document.getElementById("HCX_cardo").value : "&endTime=" + document.getElementById("HCX_cardo").value;
            }
            else {
                var endTime = "";
            }
            var b_bestFareFinder = getElementByValue(o_form, "flexibleDates");
            var noOfRooms = (document.getElementById(s_prefix + "_totalrooms")) ? document.getElementById(s_prefix + "_totalrooms").selectedIndex + 1 : "";
            if (s_prefix != "air") {
                switch (noOfRooms) {
                    case 1:
                        var noOfAdults = (document.getElementById(s_prefix + "_adult1")) ? document.getElementById(s_prefix + "_adult1").selectedIndex : "";
                        break;
                    case 2:
                        var noOfAdults = (document.getElementById(s_prefix + "_adult2")) ? document.getElementById(s_prefix + "_adult1").selectedIndex + document.getElementById(s_prefix + "_adult2").selectedIndex : "";
                        break;
                    case 3:
                        var noOfAdults = (document.getElementById(s_prefix + "_adult3")) ? document.getElementById(s_prefix + "_adult1").selectedIndex + document.getElementById(s_prefix + "_adult2").selectedIndex + document.getElementById(s_prefix + "_adult3").selectedIndex : "";
                        break;
                    case 4:
                        var noOfAdults = (document.getElementById(s_prefix + "_adult4")) ? document.getElementById(s_prefix + "_adult1").selectedIndex + document.getElementById(s_prefix + "_adult2").selectedIndex + document.getElementById(s_prefix + "_adult3").selectedIndex + document.getElementById(s_prefix + "_adult4").selectedIndex : "";
                        break;
                    default:
                        var noOfAdults = noOfRooms;
                        break;
                }
                switch (s_prefix) {
                    case "FH":
                        noOfAdults = noOfAdults;
                        break;
                    case "HO":
                    case "HCX":
                        noOfAdults = noOfAdults + noOfRooms;
                        break;
                    default:
                        noOfAdults = noOfRooms;
                        break;
                }
                if (noOfRooms != "") {
                    noOfRooms = "&noOfRooms=" + String(document.getElementById(s_prefix + "_totalrooms").selectedIndex + 1);
                }
            }
            else 
                if (s_prefix == "air") {
                    var noOfAdults = document.getElementById("FO_adults").selectedIndex;
                    if ((document.getElementById("cbNav")) && !(document.getElementById("cbpactab"))) {
                        cbAirnav = document.getElementById("cbNav").getElementsByTagName('input');
                        if (cbAirnav[0].checked) {
                            i_triptype = 2;
                        }
                        if (cbAirnav[1].checked) {
                            a_toDate = a_fromDate;
                            a_toMonth = a_fromMonth;
                            a_toYear = a_fromYear;
                            i_triptype = 1;
                        }
                        if (cbAirnav[2].checked) {
                            a_fromDate = document.getElementById('airmc_fromdate').value.split('/')[1];
                            a_fromMonth = document.getElementById('airmc_fromdate').value.split('/')[0];
                            a_fromYear = document.getElementById('airmc_fromdate').value.split('/')[2];
                            a_toDate = a_fromDate;
                            a_toMonth = a_fromMonth;
                            a_toYear = a_fromYear;
                            s_orig = (document.getElementById("airmc_from")) ? document.getElementById("airmc_from").value.toUpperCase() : '';
                            s_dest = (document.getElementById("airmc_to")) ? document.getElementById("airmc_to").value.toUpperCase() : '';
                            i_triptype = 3;
                        }
                    }
                    if (document.getElementById("radioFlexDates").checked) {
                        i_triptype = 4;
                        a_fromDate = "dd";
                        a_fromMonth = "mm";
                        a_fromYear = "yyyy";
                        a_toDate = "dd";
                        a_toMonth = "mm";
                        a_toYear = "yyyy";
                    }
                }
            noOfAdults = "&noOfAdults=" + String(noOfAdults);
            b_bestFareFinder = (b_bestFareFinder) ? b_bestFareFinder.checked : false;
            b_bestFareFinder = (b_bestFareFinder) ? true : false;
        }
        else {
            if ((s_selectedForm == 'formCO') && (!document.getElementById('CO_fromdate'))) {
                if (document.getElementById("FCO_pickupoption")) {
                    switch (document.getElementById("FCO_pickupoption").selectedIndex) {
                        case 0:
                            var s_dest = (document.getElementById("CO_to")) ? document.getElementById("CO_to").value : '';
                            break;
                        case 1:
                            var s_dest = (document.getElementById("CO_city")) ? document.getElementById("CO_city").value : '';
                            break;
                    }
                }
                else {
                    var s_dest = (document.getElementById("CO_to")) ? document.getElementById("CO_to").value : '';
                }
                var a_fromDate = document.getElementById('co-fromdate').value.split('/')[1];
                var a_fromMonth = document.getElementById('co-fromdate').value.split('/')[0];
                var a_fromYear = document.getElementById('co-fromdate').value.split('/')[2];
                var a_toDate = document.getElementById('co-todate').value.split('/')[1];
                var a_toMonth = document.getElementById('co-todate').value.split('/')[0];
                var a_toYear = document.getElementById('co-todate').value.split('/')[2];
                if (document.getElementById("CO_fromtime")) {
                    var startTime = (String(document.getElementById("CO_fromtime").selectedIndex).length == 1) ? "&startTime=0" + document.getElementById("CO_fromtime").value : "&startTime=" + document.getElementById("CO_fromtime").value;
                }
                else {
                    var startTime = "";
                }
                if (document.getElementById("CO_totime")) {
                    var endTime = (String(document.getElementById("CO_totime").selectedIndex).length == 1) ? "&endTime=0" + document.getElementById("CO_totime").value : "&endTime=" + document.getElementById("CO_totime").value;
                }
                else {
                    var endTime = "";
                }
            }
            var b_bestFareFinder = getElementByValue(o_form, "BestFareFinder");
            b_bestFareFinder = (b_bestFareFinder) ? b_bestFareFinder.checked : false;
            b_bestFareFinder = (b_bestFareFinder) ? true : false;
        }
    if (s_dest) {
        a_dest = s_dest.split("");
        for (var i = 0; i < a_dest.length; i++) {
            if (a_dest[i] == " ") {
                a_dest[i] = "_";
            }
        }
        if (s_dest != "") {
            s_dest = "&dest=" + a_dest.join("");
        }
    }
    else {
        s_dest = "";
    }
    if (s_orig) {
        a_orig = s_orig.split("");
        for (var i = 0; i < a_orig.length; i++) {
            if (a_orig[i] == " ") {
                a_orig[i] = "_";
            }
        }
        if (s_orig != "") {
            s_orig = "&orig=" + a_orig.join("");
        }
    }
    else {
        s_orig = "";
    }
    if (a_fromMonth.length == 1) {
        a_fromMonth = "0" + a_fromMonth;
    }
    if (a_toMonth.length == 1) {
        a_toMonth = "0" + a_toMonth;
    }
    if (a_fromDate.length == 1) {
        a_fromDate = "0" + a_fromDate;
    }
    if (a_toDate.length == 1) {
        a_toDate = "0" + a_toDate;
    }
    if ((s_selectedForm == 'formDV') || (s_selectedForm == 'formEV') || (s_selectedForm == 'formCO') || (b_bestFareFinder)) {
        if ((s_selectedForm == 'formDV') || (s_selectedForm == 'formEV') || (s_selectedForm == 'formFH')) {
            s_theAdtoShow = 'ad1';
        }
        if ((b_bestFareFinder) || (s_selectedForm == 'formair')) {
            s_theAdtoShow = 'ad3';
        }
        s_theAdtoShow = (document.getElementById('airTripType')) ? (document.getElementById('airTripType').disabled && s_selectedForm != 'formFH') ? 'ad3' : 'ad1' : s_theAdtoShow;
        if (s_selectedForm == 'formCO') {
            s_theAdtoShow = 'ad4';
        }
    }
    else {
        var a_ads = new Array;
        a_ads[0] = 'ad1';
        a_ads[1] = 'ad3';
        s_theAdtoShow = a_ads[Math.floor(Math.random() * 2)];
    }
    if ((s_selectedForm == 'formHO') || (s_selectedForm == 'formHOgbl') || (s_selectedForm == 'formHOus')) {
        s_theAdtoShow = 'ad2';
    }
    var win2 = new Object;
    if (s_theAdtoShow && !b_overide && i_s59Svc1 == '-1' && i_s59Svc2 == '-1' && i_gomezSvc == '-1' && i_aarpSvc == '-1' && i_tcyca == '-1' && i_aolsvc == '-1' && i_tcymx == '-1' && i_tcyar == '-1' && i_tcyla == '-1' && iphone === -1) {
        var s_urladditions;
        switch (s_selectedForm) {
            case 'formCO':
                s_urladditions = startTime + endTime;
                break;
            case 'formHCX':
                s_urladditions = noOfRooms + noOfAdults + startTime + endTime;
                break;
            case 'formHO':
                s_urladditions = noOfRooms + noOfAdults;
                break;
            case 'formFH':
                s_urladditions = noOfRooms + noOfAdults + s_orig;
                break;
            case 'formair':
                s_urladditions = noOfAdults + s_orig;
                break;
        }
        var s_urlString = "?s_theDomain=" + s_theDomain + "&s_selectedForm=" + s_selectedForm + "&a_formPrefix=" + a_formPrefix + "&a_fromDate=" + a_fromDate + "&a_fromMonth=" + a_fromMonth + "&startYear=" + a_fromYear + "&endDate=" + a_toDate + "&endMonth=" + a_toMonth + "&endYear=" + a_toYear + '&s_theAdtoShow=' + s_theAdtoShow + s_dest + "&triptype=" + i_triptype;
        if (document.getElementById("FCO_pickupoption")) {
            if (document.getElementById("FCO_pickupoption").selectedIndex != 2) {
                win2 = window.open(popunder + s_urlString + s_urladditions, "adWindow", winfeatures);
                win2.blur();
                win2.screenX = 150;
                win2.screenY = 200;
                window.focus();
            }
        }
        else {
            win2 = window.open(popunder + s_urlString + s_urladditions, "adWindow", winfeatures);
            win2.blur();
            win2.screenX = 150;
            win2.screenY = 200;
            window.focus();
        }
    }
};

function cb_hoaddair(){
    var o_checkbox = document.getElementById("HO_addair");
    var o_hidden = document.getElementById("HO_triptype");
    var o_div = document.getElementById("HO_aircity");
    var o_button = document.getElementById("submitHO");
    switch (o_checkbox.checked) {
        case true:
            o_hidden.value = "totalTrip";
            o_div.style.visibility = "visible";
            o_button.className = "";
            o_button.firstChild.innerHTML = "Search Flights<br/>+ Hotels";
            break;
        default:
            o_hidden.value = "hotel";
            o_div.style.visibility = "hidden";
            o_button.className = "single";
            o_button.firstChild.innerHTML = "Search Hotels";
    }
};

function cb_hoshowhideair(o_form){
    a_radio = o_form.rooms;
    for (var i = 0; i < a_radio.length; i++) 
        if (a_radio[i].checked) 
            o_radiochecked = a_radio[i];
    switch (o_radiochecked.value) {
        case ("groople"):
            document.getElementById("HO_addairrow").style.visibility = "hidden";
            break;
        default:
            document.getElementById("HO_addairrow").style.visibility = "visible";
    };
};

function cru_frm(s_domain, s_frmValue, s_service){
    var a_frmVals = s_frmValue.split('_');
    cru_links(s_domain, a_frmVals[0], a_frmVals[1], s_service);
};

function cru_links(s_domain, s_type, i_id, s_service){
    var s_params = 'org.apache.struts.taglib.html.TOKEN=9238b165969ffb92db678b5148c38e71&pageName=CRZ_Z1100&Service=' + s_service;
    var s_path = '/ecruise/CruiseSearch.do';
    var s_theURL = '';
    switch (s_type) {
        case 'vendor':
            s_path = '/ecruise/CruiseLineDetails.do';
            s_params = 'Service=' + s_service + '&vendorId=';
            break;
        case 'location':
            s_params += '&geographicRegion=';
            break;
        case 'ship':
            s_path = '/ecruise/ShipDetailsSailingCalendar.do';
            s_params += '&shipId=';
            break;
    }
    s_theURL = s_domain + s_path + '?' + s_params + i_id;
    parent.window.location = s_theURL;
};

function formbit(s_form){
    a_formbit = s_form.split("_");
    s_formbit = a_formbit[1];
    return s_formbit;
};

function multirooms(o_rooms,codOption){
if(typeof o_rooms=="string")o_rooms=document.getElementById(o_rooms);
s_type=formbit(o_rooms.form.name);
o_rooms=document.getElementById(s_type+"_totalrooms");
i_rooms=parseInt(o_rooms.options[o_rooms.selectedIndex].text);
cb_hidePromo(o_rooms,'cbFHpromo');
o_multiroomchild=document.getElementById(s_type+"_multichildroom");
switch(o_rooms.options[o_rooms.selectedIndex].text.indexOf("+")){
	case -1:
		if(document.getElementById("HO_grpmsg"))document.getElementById("HO_grpmsg").style.display="none";
		i_maxrooms=parseInt(o_rooms.options[o_rooms.options.length-1].text);
		for(var i=0;i<i_maxrooms;i++)if(document.getElementById(s_type+"_room"+(i+1)))document.getElementById(s_type+"_room"+(i+1)).style.display="none";
		for(var i=0;i<i_rooms;i++)if(document.getElementById(s_type+"_room"+(i+1)))document.getElementById(s_type+"_room"+(i+1)).style.display="block";
		i_childrows=(o_multiroomchild)?multiroomchild(i_rooms,i_maxrooms,s_type,o_multiroomchild,codOption):0;
		i_limitrows=(s_type=="FH")?2:1;
		if(i_childrows==0||(i_childrows==1&&i_rooms==i_limitrows&&!document.getElementById("aarp_header"))){
			cbresize(0,s_type);if(document.getElementById("cbFHpromo"))cb_hidePromo(o_rooms,'cbFHpromo');}
		else cbresize(1,s_type);
	break;
	default:
		cbresize(0,s_type);
		if(o_multiroomchild)o_multiroomchild.style.display="none";
		if(document.getElementById("HO_grpmsg"))document.getElementById("HO_grpmsg").style.display="block";
		for(var i=0;i < i_rooms;i++)if(document.getElementById(s_type+"_room"+(i+1)))document.getElementById(s_type+"_room"+(i+1)).style.display="none";}}

        function cbresize(b_resize, s_type){
            o_content = document.getElementById("content");
            if ((s_type != "FH" && s_type != "HO") || o_content.className != "home") 
                return true;
            o_cbForms = document.getElementById("cbForms");
            o_cbForm = document.getElementById("cb_form" + s_type);
            if (document.getElementById(s_type + "_moreoptions")) {
                o_moreoptions = document.getElementById(s_type + "_moreoptions");
                switch (b_resize) {
                    case 0:
                        o_moreoptions.style.position = "absolute";
                        o_moreoptions.style.top = "288px";
                        break;
                    case 1:
                        o_moreoptions.style.top = "auto";
                        o_moreoptions.style.position = "relative";
                        break;
                }
            }
        }
        
        function multiroomchild(i_rooms, i_maxrooms, s_type, o_childrooms, codOption){
            o_childrooms.style.display = "none";
            i_childrows = 0;
            for (var i = 0; i < i_maxrooms; i++) {
                o_children = document.getElementById(s_type + "_" + codOption + "_child" + (i + 1));
                if (!o_children) 
                    break;
                i_ages = o_children.selectedIndex;
                o_childrow = document.getElementById(s_type + "_childroom" + (i + 1));
                if (i_ages > 0 && i < i_rooms) {
                    i_childrows++;
                    o_childrooms.style.display = "block";
                    o_childrow = document.getElementById(s_type + "_childroom" + (i + 1));
                    a_select = o_childrow.getElementsByTagName("select");
                    for (var j = 0; j < o_children.options.length - 1; j++) {
                        a_select[j].parentNode.style.display = (j < i_ages) ? "block" : "none";
                    }
                    o_childrow.style.display = "block";
                }
                else 
                    o_childrow.style.display = "none";
            }
            return i_childrows;
        }
        
        function noneBlock_v2(){
            var a_args = noneBlock_v2.arguments;
            for (var i = a_args.length - 1; i > -1; i--) {
                var a_nb2 = a_args[i].split("|");
                var o_block = document.getElementById(a_nb2[0]);
                var o_img = document.getElementById(a_nb2[1]);
                switch (a_nb2[2]) {
                    case "flip":
                        switch (o_img.src.indexOf("show")) {
                            case -1:
                                o_img.src = o_img.src.replace("hide", "show");
                                o_block.style.display = "none";
                                break;
                            default:
                                o_img.src = o_img.src.replace("show", "hide");
                                o_block.style.display = a_nb2[3];
                        }
                        break;
                    default:
                        o_img.src = (a_nb2[2] != "none") ? o_img.src.replace("show", "hide") : o_img.src.replace("hide", "show");
                        o_block.style.display = a_nb2[2];
                }
            }
        }

function chkAll(s_parent,o_chkbox){
o_chk=document.getElementById(s_parent);
a_chk=o_chk.getElementsByTagName("input");
if(o_chkbox!=a_chk[0])a_chk[0].checked=false;
else for(i=1;i<a_chk.length;i++)a_chk[i].checked=false;}

function cb_SetActField(s_field){o_field=document.getElementById(s_field);
if(o_field){(s_field=='act_city')?o_field.selectedIndex=0:o_field.value="";}}

function cb_SetActCity(s_field){o_field=document.getElementById(s_field);
if(o_field){(s_field=='act_city')?o_field.selectedIndex=0:o_field.value="";}}
var i_page=0;

function pageSetup(i_show){
s_showcase="";o_showlist=document.getElementById("showcase");
a_showcase=o_showlist.getElementsByTagName("li");i_page=i_page+i_show;
if(i_page==-1){i_page=a_showcase.length-1;}
if(i_page==a_showcase.length){i_page=0;}
for (i=0;i<a_showcase.length;i++){
	if(i!=i_page){s_showcase="showcase"+i+"!0";noneBlock(s_showcase);
	}else{s_showcase="showcase"+i_page+"!1";noneBlock(s_showcase);
}}}Date.prototype.getLastDay = function(){
var _imonth=this.getMonth();
var _iyear=this.getFullYear();
for(var i=31;i>0;i--){var __date=new Date(_iyear,_imonth,i);if(_imonth==__date.getMonth())break;}
return __date.getDate();};

function validSelectDate(sMonth,sDate){
var dVSD=new Date();
var aDateVSD=[dVSD.getMonth(),dVSD.getFullYear()];
var oMonth=document.getElementById(sMonth);
var oDate=document.getElementById(sDate);
if(oMonth.selectedIndex<aDateVSD[0])aDateVSD[1]=aDateVSD[1]+1;
var dMonthVSD=new Date(aDateVSD[1],oMonth.selectedIndex,1);
iDaysInMonth=dMonthVSD.getLastDay();
if(iDaysInMonth<oDate.selectedIndex+1)oDate.selectedIndex=iDaysInMonth-1;};

function noneBlock(){a_arguments=noneBlock.arguments;for(var i=0;i<a_arguments.length;i++){a_nB=a_arguments[i].split("!");s_nBit=a_nB[0];i_nBdisplay=a_nB[1];o_showHide=document.getElementById(s_nBit);o_showHide.style.display=(i_nBdisplay==0)?"none":(i_nBdisplay==1)?"block":"inline";}};

function freqRenter(oSel){
switch(document.getElementById(oSel).value){
case "ZR":oDisc="Corporate Discount #:";oID="Dollar Express #:";break;
case "ZT":oDisc="Corporate Discount #:";oID="Blue Chip #:";break;
case "AL":oDisc="Corporate Discount #:";oID="Quicksilver ID:";break;
case "ZL":oDisc="Corporate Discount #:";oID="Emerald Club ID:";break;
case "ZA":oDisc="Corporate Discount #:";oID="Payless Perks #:";break;
case "ZI":oDisc="AWD #:";oID="Wizard #:";break;
case "ZD":oDisc="BCD #:";oID="Fast Break #:";break;
case "EP":oDisc="Contract #:";oID="Priviledge #:";break;
case "ZE":oDisc="CDP:";oID="Hertz #1 Club:";break;
case "ET":oDisc="Customer #:";oID="Enterprise Plus #:";break;
case "AD":oDisc="Corporate Discount #:";oID="Easy ID #:";break;
case "EZ":oDisc=false;oID="E-Z Money #:";break;
case "ZP":oDisc=false;oID=false;var noRates=true;break;
case "ZH":oDisc="Discount Number:";oID=false;break;
case "" :oDisc=false;oID=false;break;}
if(oDisc||oID){
	noneBlock('CO_discounts!1');
	if(oDisc){document.getElementById("discName").innerHTML = oDisc;noneBlock('freqDiscName!1');
	}else{noneBlock('freqDiscName!0');}
	if(oID){document.getElementById("discID").innerHTML = oID;noneBlock('freqDiscID!1');
	}else{noneBlock('freqDiscID!0');}
	}else{noneBlock('CO_discounts!0');}
if(noRates){noneBlock('noDiscRates!1');
}else{noneBlock('noDiscRates!0');}}

function populateTSHDest(source,destination,country) {
	var dest = document.getElementById(source).value.split("|");
	document.getElementById(destination).value = dest[0];
	var HO_country = document.getElementById(country);
	for(var i=0;i < HO_country.options.length; i++ ){
		if(HO_country.options[i].value == dest[1]){
			HO_country.selectedIndex = i;
			break;
		}
	}
}
//function $() {
//    var element, elements, i;
//    elements = [];
//    for (i = 0; i < arguments.length; i = i + 1) {
//        element = arguments[i];
//        if (typeof element === "string") {
//            element = document.getElementById(element);
//        }
//        if (arguments.length === 1) {
//            return element;
//        }
//        elements.push(element);
//    }
//    return elements;
//}


SEOWhySearchFlights = { COLLAPSED_TEXT:"Learn More",OPENED_TEXT:"Close",ARROW_COLLAPSED_TEXT:"Expand Cheap Flights",ARROW_OPENED_TEXT:"Close Cheap Flights"};
SEOWhySearchFlights.CollapsableBlock = (function(){
var seo_block;
function _SEOBlock(){
	var Block = function(){};
	Block.prototype= {
		oBlock:null,oCollapseControl:null,oArrowControl:null, oArrowImg:null,sAssetsDir:"",sState:"",
		setUp: function(){
			var oBlockScope= this;
			this.oBlock = $("fo-why-search-container");
			this.oCollapseControl= $("fo-learn-more").getElementsByTagName("a")[0];
			this.oArrowControl= $("fo-arrow").getElementsByTagName("a")[0];
			this.oArrowImg= $("seo-wysrch-arrow");
			this.sState="collapsed";
			noneBlock_v2("fo-content-learmore|seo-wysrch-arrow|flip|inline");
			this.oCollapseControl.innerHTML = SEOWhySearchFlights.COLLAPSED_TEXT;
			this.oArrowImg.alt= SEOWhySearchFlights.ARROW_COLLAPSED_TEXT;
			var collapseListener = function(){
				oBlockScope.toggle_collapse.apply(oBlockScope,[this]);
				return false;
			};
			if(this.oCollapseControl){ this.oCollapseControl.onclick = collapseListener;}
			if(this.oArrowControl) {this.oArrowControl.onclick = collapseListener;}
		},
		toggle_collapse: function(){
			if(this.sState == "collapsed"){
				this.oCollapseControl.innerHTML = SEOWhySearchFlights.OPENED_TEXT;
				this.oArrowImg.alt= SEOWhySearchFlights.ARROW_OPENED_TEXT;
				this.sState="opened";
			}else if(this.sState == "opened"){
				this.oCollapseControl.innerHTML = SEOWhySearchFlights.COLLAPSED_TEXT;
				this.oArrowImg.alt= SEOWhySearchFlights.ARROW_COLLAPSED_TEXT;
				this.sState="collapsed";
			}
			noneBlock_v2("fo-content-learmore|seo-wysrch-arrow|flip|inline");
		}
	};
	return new Block();
}
return {  
	getBlockInstance: function(){ if(!seo_block) { seo_block = _SEOBlock(); seo_block.setUp();}
	return seo_block;
	}
};
})();
