﻿var xmlhttpobject;

function GetXMLHTTPObject()
{
    var xmlHTTPobj;
    xmlHTTPobj = null;
    //if (xmlhttpobject && xmlhttpobject  == 'undefined')
    //{return;/*object already recreated.*/}

	if(window.XMLHttpRequest)
	{
		try{xmlHTTPobj=new XMLHttpRequest;}
		catch(d){}
	}
	else if(window.ActiveXObject)
	{
		for(var i=0,xmlp;xmlp=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"][i++];)
		{
			try{xmlHTTPobj=new ActiveXObject(xmlp);break}
			catch(d){}
		}
	}
	return xmlHTTPobj;
}

function getAJAXResponse(action, param) {
    var strResponse, param;
    strResponse = '';

    xmlhttpobject = GetXMLHTTPObject();

    xmlhttpobject.open("POST", './AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('Action=' + action);
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200) {
        strResponse = xmlhttpobject.responseText;
    }

    return strResponse;
}
function getSTWMainResponse(action, param) {
    var strResponse, param;
    strResponse = '';

    xmlhttpobject = GetXMLHTTPObject();

    xmlhttpobject.open("POST", './STWMain.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('Action=' + action);
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200) {
        strResponse = xmlhttpobject.responseText;
    }

    return strResponse;
}

/*
    Returns the available cabin numbers when selecting a cabin category for RCL
    Params:
        theme       = The BrandID to pass in
        sailingdate = The date that the cruise starts
        shipcode    = The SupplierID of the ship being used
        catcode     = The Cabin Category (J, KS, etc) that was selected
        farecode    = The Fare/Itin Code of the category that was selected
*/

function returnCabins(theme, sailingdate, shipcode, catcode, farecode, mask, cruisetype, sailingid)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
    //Set the Theme
    param += '?Theme=' + theme;
    //Send the SailingDate
    param += '&SailingDate=' + sailingdate;
    //ShipCode
    param += '&ShipCode=' + shipcode;
    //Category
    param += '&CatCode=' + catcode;
    //FareCode
    param += '&FareCode=' + farecode;
    //Mask
    param += '&Mask=' + mask;
    //Sailing ID
    param += '&SailingID=' + sailingid;
         
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'./AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    if (cruisetype == 'HOAC') {
        //For HOA
        xmlhttpobject.send('Action=HOACABINNUMBERS');
    }
    else {
        xmlhttpobject.send('Action=RCLCABINNUMBERS');
    }

    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        strResponse = xmlhttpobject.responseText;
    }
     
    return strResponse; 
}

/*
    Returns the image when selecting a deck plan for RCL
    Params:
        theme       = The BrandID to pass in
        shipcode    = The ship code to find the image for
        deckplan    = The plan to find the image for
*/
function returnDeckPlanImage(theme, shipcode, deckplan, cruisetype)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
    //Set the Theme
    param += '?Theme=' + theme;
    //Send the ship code
    param += '&ShipCode=' + shipcode;
    //Send the Deck Plan
    param += '&DeckPlan=' + deckplan;
         
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'./AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    if (cruisetype == 'HOAC') {
        //Use HOA Action
        xmlhttpobject.send('Action=HOADECKPLANIMAGE');
    }
    else {
        //RCL
        xmlhttpobject.send('Action=RCLDECKPLANIMAGE');
    }
    
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        //alert('data is ready');
        strResponse = xmlhttpobject.responseText;
    }
     
    //alert('returning data');
    return strResponse; 
}

/*
    Returns the dining options for the Cabin selected
    Params:
        theme       = The BrandID to pass in
        shipcode    = The ship code to find the image for
        sailingdate = The sailing date that was selected
        cabinnumber = The cabin number to find the dining options for
        searchmask  = The mask to find the dining options for
*/
function returnDiningOptions(theme, shipcode, sailingdate, cabinnumber, searchmask, cruisetype, sailingID, fare, cat)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
    //Set the Theme
    param += '?Theme=' + theme;
    //Send the ship code
    param += '&ShipCode=' + shipcode;
    //Send the Sailing Date
    param += '&SailingDate=' + sailingdate;
    //CabinNumber
    param += '&CabinNumber=' + cabinnumber;
    //Mask
    param += '&Mask=' + searchmask;
    //Sailing ID
    param += '&SailingID=' + sailingID;
    //Fare
    param += '&FareCode=' + fare;
    //Category
    param += '&CategoryCode=' + cat;
         
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'./AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    if (cruisetype == 'HOAC') {
        xmlhttpobject.send('Action=HOADININGOPTIONS');
    }
    else {
        xmlhttpobject.send('Action=RCLDININGOPTIONS');
    }
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        //alert('data is ready');
        strResponse = xmlhttpobject.responseText;
    }
     
    //alert('returning data');
    return strResponse; 
}

/*
    Holds the given cabin number for a cruise reservation
    Params:
        shipCode    = This ship to hold the cabin for
        sailingDate = The sailing date to hold the cabin for
        cabinNumber = The cabin number to hold
        searchMask  = The mask to hold the cabin for
        fare        = The fare code of RCCL to hold the cabin for
        cat         = The category to hold the cabin for
*/
function returnRCLHold(shipCode, sailingDate, cabinNumber, searchMask, fare, cat, cruisetype, sailingID)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
    //Set the Ship
    param += '?ShipCode=' + shipCode;
    //Send the Sailing Date
    param += '&SailingDate=' + sailingDate;
    //CabinNumber
    param += '&CabinNumber=' + cabinNumber;
    //Mask
    param += '&Mask=' + searchMask;
    //Fare
    param += '&FareCode=' + fare;
    //Category
    param += '&PricedCategory=' + cat;
    //Sailing ID
    param += '&SailingID=' + sailingID;
         
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'./AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    if (cruisetype == 'HOAC') {
        xmlhttpobject.send('Action=HOAHOLD');
    }
    else {
        xmlhttpobject.send('Action=RCLHOLD');
    }
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        //alert('data is ready');
        strResponse = xmlhttpobject.responseText;
    }
     
    //alert('returning data');
    return strResponse; 
}

/*
    Returns the flight options for a cruise reservation
    Params:
        theme       = The BrandID to pass in
        productcode = The ProductCode to find the flight options for
        itemnumber  = The Seq/Plan to find the flight options for
        currency    = The currency to find the flight options for
*/
function returnFlightOptions(theme, productcode, itemnumber, currency)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
    //Set the Theme
    param += '?Theme=' + theme;
    //Send the Productcode
    param += '&productcode=' + productcode;
    //Send the Seq/ItemNumber
    param += '&ItemNumber=' + itemnumber;
    //Currency/QC
    param += '&QC=' + currency;
         
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'./AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('Action=RCLFLIGHTOPTIONS');
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        //alert('data is ready');
        strResponse = xmlhttpobject.responseText;
    }
     
    //alert('returning data');
    return strResponse; 
}

/*
    Returns the deposit/final payment rules for a cruise reservation
    Params:
        theme       = The BrandID to pass in
        sailingdate = The Date of sailing
        shipcode    = The Ship/Supplier of the selected ship
        cabincode   = The Cabin category
        farecode    = The fare code of the selected cabin category
        cabinnumber = The cabin number of the ship
        dining      = The selected dining option
        mask        = The search mask for this reservation
*/
function returnPaymentRules(theme, sailingdate, shipcode, cabincode, farecode, cabinnumber, dining, mask, cruisetype, sailingID)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
    //Set the Theme
    param += '?Theme=' + theme;
    //Send the Productcode
    param += '&sailingdate=' + sailingdate;
    //Send the Seq/ItemNumber
    param += '&shipcode=' + shipcode;
    //Currency/QC
    param += '&cabincode=' + cabincode;
    //Currency/QC
    param += '&farecode=' + farecode;
    //Currency/QC
    param += '&cabinnumber=' + cabinnumber;
    //Currency/QC
    param += '&dining=' + dining;
    //Currency/QC
    param += '&mask=' + mask;
    //Sailing ID
    param += '&SailingID=' + sailingID;
         
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'./AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    if (cruisetype == 'HOAC') {
        xmlhttpobject.send('Action=HOAPAYMENTRULES');
    }
    else {
        xmlhttpobject.send('Action=RCLPAYMENTRULES');
    }
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        //alert('data is ready');
        strResponse = xmlhttpobject.responseText;
    }
     
    //alert('returning data');
    return strResponse; 
}

/***
Function returns a list of Travel Companions based on the lead pax and which user type is logged in
***/
function returnTravelCompanions(sess, strTCReq)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
    //Set the Session
    param += '?SessID=' + sess;
    //Send the Travel Companion Request (contains Contact XML)
    param += '&TCReq=' + strTCReq;
            
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'./AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('Action=GETTRAVELCOMPANIONS');
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        strResponse = xmlhttpobject.responseText;
    }
     
    return strResponse; 
}

/***
Function returns a list of Contacts from the database that may be the contact being searched for.
Search starts to search soon as FirstName and LastName are entered on the pax screen.
***/
function returnPossibleContacts(sess, strSearchReq)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
    //Set the Session
    param += '?SessID=' + sess;
    //Send the Search Request (contains Contact XML)
    param += '&SearchReq=' + strSearchReq;
            
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'./AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('Action=GETPOSSIBLECONTACTS');
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        strResponse = xmlhttpobject.responseText;
    }
     
    return strResponse; 
}

/***
Function returns a list of Contacts from the database that may be the contact being searched for.
Search starts to search soon as FirstName and LastName are entered on the pax screen.
***/
function returnContactRewards(sess, strSearchReq)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
      
    //Set the Session
    param += '?SessID=' + sess;
    //Send the Search Request (contains Contact XML)
    param += '&Request=' + strSearchReq;
            
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'./AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('Action=GETCONTACTREWARDS');
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        strResponse = xmlhttpobject.responseText;
    }
     
    return strResponse; 
}

/*
//Updates the TOC page based on the filters selected
function UpdateTOCFilter(theme, groupid)
{    
    var minprice, maxprice, mindate, maxdate, prodtype, withcruise, param, nexttab;
    var strResponse;
    
    //Build the params
    minprice = document.getElementById('selFromTOCPrice').value;
    maxprice = document.getElementById('selToTOCPrice').value;
    mindate = document.getElementById('selFromTOCDate').value;
    maxdate = document.getElementById('selToTOCDate').value;
    
    //Product Type/Category is based on the checkboxes
    prodtype = '';
    if (document.getElementById('chkTOCTour').checked)
        prodtype += 'Escorted-GUIDED';
    if (document.getElementById('chkTOCInd').checked)
    {
        if (prodtype != '')
            prodtype += '-';
        prodtype += 'Independent';
    }
    //with a cruise or not?
    if (document.getElementById('chkTOCCruise').checked)
        withcruise = 'Y';
    else
        withcruise = 'N';

    //Find the next tab if there is one
    if (document.getElementById('nexttablink'))
        nexttab = document.getElementById('nexttablink').value;
    else
        nexttab = '';
    
    //Call the function
    strResponse = returnTOC(theme, groupid, minprice, maxprice, mindate, maxdate, prodtype, withcruise);
    
    //Now replace the TOC area
    if (document.getElementById('subgroupreplacement'))
        document.getElementById('subgroupreplacement').innerHTML = strResponse;
    if (document.getElementById('nofilterresults'))
    {
        if (strResponse == '') {
            //If we have a next tab link, use that
            if (nexttab != '') {
                //Send the MinPrice
                param = '?MinPrice=' + minprice;
                //MaxPrice
                param += '&MaxPrice=' + maxprice;
                //MinDate
                param += '&MinDate=' + mindate;
                //MaxDate
                param += '&MaxDate=' + maxdate;
                //ProdType
                param += '&TourType=' + prodtype;
                //WithCruise
                param += '&WithCruise=' + withcruise;
                param += '&ShowNoProductSubgroups=N';
                //Make sure we pass that there were no results so that we don't add these filters to the other tabs again
                param += '&noresults=Y';
                document.location.href = nexttab + param;
            }
            else {
                //No next tab, show the "no results found"
                document.getElementById('nofilterresults').style.display = '';
            }
        }
        else
            document.getElementById('nofilterresults').style.display = 'none';
    }
}

function returnTOC(theme, groupid, minprice, maxprice, mindate, maxdate, prodtype, withcruise)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
    //Set the Theme
    param += '?Theme=' + theme;
    //Send the GroupID
    param += '&GroupID=' + groupid;
    //Send the MinPrice
    param += '&MinPrice=' + minprice;
    //MaxPrice
    param += '&MaxPrice=' + maxprice;
    //MinDate
    param += '&MinDate=' + mindate;
    //MaxDate
    param += '&MaxDate=' + maxdate;
    //ProdType
    param += '&TourType=' + prodtype;
    //WithCruise
    param += '&WithCruise=' + withcruise;
    param += '&ShowNoProductSubgroups=N';
         
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'./AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('Action=TOC');
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        //alert('data is ready');
        strResponse = xmlhttpobject.responseText;
    }
     
    //alert('returning data');
    return strResponse; 
}
*/

function returnContactReview(theme, productcode, groupid, subgroupid, autoshowreviews)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    
    param += '?productcode=' + productcode;
    param += '&theme=' + theme;
    param += '&groupid=' + groupid;
    param += '&subgroupid=' + subgroupid;
   
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'/stw/AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('Action=GETCONTACTREVIEW');
    
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        strResponse = xmlhttpobject.responseText;
   
        document.getElementById('contact-review-info').innerHTML = strResponse
        if(document.getElementById('No-Reviews-Found') == null)
        {
            if(document.getElementById('showreview'))
                document.getElementById('showreview').value = 'Y';

            ShowReviewPage('CustomerReviewPage', 1);
            document.getElementById('reviews-td').style.display = '';

            if (autoshowreviews == 'Y') {
                //Show the review stuff
                ReviewsDisplay('show');
            }
        }
    }

    return strResponse; 
}
/*
used to subscribe to THEDEAL List from Home Page 
*/
function subscribeContact(subscribeaction, listid, origin, email, pos)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    //subscribeaction=S
    param += '?subscribeaction=' + subscribeaction;
    param += '&listid=' + listid;
    param += '&origin=' + origin;
    param += '&txtemail=' + email;
    if (pos == 1)
        param += '&subprocess=Email Signup(Top Nav)';
    else
        param += '&subprocess=Email Signup';
   
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'/stw/AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('Action=SUBSCRIBE');
    
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        strResponse = xmlhttpobject.responseText;
        if (strResponse.indexOf('OK') > -1)
            alert('You have been successfully added to our mailing list.\n Thank you for choosing Gate1!');
    }

    //return strResponse; 
}
/*
used to unsubscribe to THEDEAL List from Home Page 
*/
function unsubscribeContact(subscribeaction, listid, origin, email)
{
    var strResponse, param;
    strResponse = '';
    param = '';
    //subscribeaction=U
    param += '?subscribeaction=' + subscribeaction;
    param += '&listid=' + listid;
    param += '&origin=' + origin;
    param += '&txtemail=' + email;
   
    xmlhttpobject = GetXMLHTTPObject();
    
    xmlhttpobject.open("POST",'/stw/AJAX.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('Action=UNSUBSCRIBE');
    
    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200)
    {
        strResponse = xmlhttpobject.responseText;
        if (strResponse.indexOf('OK') > -1)
            alert('You have been successfully unsubscribed from our mailing list.');
    }

    //return strResponse; 
}





var arrAJAXResponse = new Array();
var citycodehelpercallby; //which ID last call the attachcitycodehelper()
var existingEvt;
var lastXML; //the last xml data that was accessed.  This is to help with find the citycode for a cityname.
var okcolor, failcolor;
okcolor = 'white'; //textbox background color.
failcolor = 'red';

//if (keyCode == 9){}

//write the select to the page.
if (document.getElementById('citycodehelper'))
{ } else { document.write('<select name="citycodehelper" class="citycodehelper" id="citycodehelper" style="display:none;overflow:hidden;z-index:1000; width:300px;" onclick="ClearCarLocations();setcitycode();setcitycode();HideHelperSelect();" onmouseout="HideHelperSelect();HideHelperSelect();" onkeydown="setselectedhelpercity(event);" onblur="HideHelperSelect();"></select>'); }

if (document.getElementById('viewalldiv'))
{ } else { document.write('<div id="viewalldiv" class="dialog" style="margin: 0;z-index:1000; padding: 0; display: none; height: 500px; width: 800px; overflow: auto;"></div>'); }



//existingEvt = document.onclick;

    function hidecitycodehelper() {
        if (document.getElementById('citycodehelper')) {
            //            if (document.getElementById('citycodehelper').style.display == 'none')
            //            {//it has been hidden...don't to anything else
            //                return;
            //            }
            document.getElementById('citycodehelper').style.display = 'none';
        }
        setcityname();
        setcitycode();
        //if (existingEvt) { existingEvt(); }
    }

//document.addEventListener('click', hidecitycodehelper, false);

function setcityname() {
    if (citycodehelpercallby) {
        if (document.getElementById('citycodehelper').selectedIndex >= 0) {
            //citycodehelpercallby.value = document.getElementById('citycodehelper').value;   
            citycodehelpercallby.value = document.getElementById('citycodehelper').options[document.getElementById('citycodehelper').selectedIndex].text;
            //de select items now
            document.getElementById('citycodehelper').selectedIndex = -1;
        }
        if (citycodehelpercallby.style) {
            citycodehelpercallby.style.borderBottomWidth = '1px';
        }
    }
}
function setcitycode() {
    setcityname();
    var desthelperid, selcityname, citycode, i, j;
    var nameid, codeid, destnum, checkprodtrans;
    try {
        checkprodtrans = '';
        destnum = 0;
        //get the IDs of the textbox holding the name and the code  (airport name vs airport code)
        if (citycodehelpercallby) {
            nameid = document.getElementById(citycodehelpercallby.getAttribute('nameid'));
            codeid = document.getElementById(citycodehelpercallby.getAttribute('codeid'));
            destnum = parseInt('0' + citycodehelpercallby.getAttribute('currentdestnum'));
            checkprodtrans = citycodehelpercallby.getAttribute('checkinterdesttransportation'); //Y/N
            if (!checkprodtrans || checkprodtrans == null || checkprodtrans == 'undefined') { checkprodtrans = ''; }
            if (nameid && codeid) {
                desthelperid = document.getElementById('citycodehelper');

                if (nameid.value == '' || !desthelperid) { return; }
                //clear was one there before.
                codeid.value = '';
                //all good....get the citycode.
                i = lastXML.toUpperCase().indexOf('|' + nameid.value.toUpperCase() + '|')
                if (i < 0)
                    i = lastXML.toUpperCase().indexOf('**' + nameid.value.toUpperCase() + '|')
                if (i < 0) {
                    //invalid city name.
                    citycodehelpercallby.style.backgroundColor = failcolor;
                    return;
                }
                j = lastXML.lastIndexOf('**', i);
                citycode = lastXML.substring(j + 2, i + 5).split('|')[0];
                //alert('citycode_'+citycode);         
                codeid.value = citycode;
                if (citycodehelpercallby.style) {//alert('testing');
                    citycodehelpercallby.style.backgroundColor = okcolor;
                }

                //are we checking inter destination transportation options?
                if (destnum <= 1) { //alert('one');
                    //alert('destnum_' + destnum);
                    if (document.getElementById('interdest' + destnum)) { //alert('two');
                        document.getElementById('interdest' + destnum).style.display = 'none';
                    }
                }
                else if (checkprodtrans.toUpperCase() == 'Y' && destnum > 1) {
                    //hard code how to get the previous citycode......damn it!!!!
                    var prevcitycode;
                    prevcitycode = ''
                    if (document.getElementById('destination' + (destnum - 1)))
                    { prevcitycode = document.getElementById('destination' + (destnum - 1)).value; }
                    //alert('checkprodtrans: ' + checkprodtrans + ' destnum: ' + destnum + ' prevcitycode: ' + prevcitycode + ' citycode: ' + citycode);
                    if (prevcitycode.length >= 3 && citycode.length >= 3) {
                        //call the function to set the interdestination transportation.
                        SetInterDestTransportation(destnum, citycode.substring(0, 3), prevcitycode.substring(0, 3));
                    }
                }
            }
        }
        //alert('returning true');
        return true;
    }
    catch (ex) {
        //alert('setcitycode() failed. ' + ex.message);
    }
}
function SetInterDestTransportation(destnum, citycode, precitycode) {
    //interdest not working correctly
    if (destnum > 1)//making sure dest is valid
    {
        destnum = parseInt(destnum) - 1; //subtracting one to the dest- so interdest appears under the right dest
    }

    //show the interdestination section for this dest.
    //why did I do this in 3 IFs? for clarity and I like it like that!  Can't I have anything my way damn it!!!
    if (citycode && citycode != null & citycode != 'undefined' & citycode.length > 0) {
        if (precitycode && precitycode != null & precitycode != 'undefined' & precitycode.length > 0) {
            if (destnum && destnum != null & destnum != 'undefined' & parseInt(destnum) > 0) {
                //show the inter destination section.
                document.getElementById('interdest' + destnum).style.display = '';
                //set the Product Transportation data for these two destination.
                var strData, bcar, btra, bair, btrf, bnone;
                strData = '';
                strData = xmlhttpResponse('GETPRODUCTTRANSPORTATION', '', '', '', '&FromCity=' + precitycode + '&ToCity=' + citycode, precitycode + citycode)
                //alert('GETPRODUCTTRANSPORTATION Data: ' + strData);
                //Date structure.
                //**|AIR:Y|TRA:Y||**    only Y (yes/allow) transportation type are return.  format: **CAR:Y|AIR:Y|TRA:Y|TRF:Y**
                strData = strData.toUpperCase();
                bcar = (strData.indexOf('CAR:Y') > -1);
                btra = (strData.indexOf('TRA:Y') > -1);
                bair = (strData.indexOf('AIR:Y') > -1 && document.getElementById('trip_type').value.toUpperCase().indexOf('AIRF') > -1);
                btrf = (strData.indexOf('TRF:Y') > -1);
                bnone = (strData.indexOf(':') < 0);

                if (bair == false) {//check for bnone again....it maybe that only 'AIR:Y is available but trip type is not air inclusive.
                    bnone = (strData.replace('AIR:Y', '').indexOf(':') < 0);
                }

                //for debugging purposes...drop a ID=test textarea somewhere to see
                //document.getElementById('test').value = 'GETPRODUCTTRANSPORTATION Data: ' + strData + '\nbcar: ' + bcar + '\nbtra: ' + btra + '\nbair: ' + bair + '\ntrf: ' + btrf + '\nbnone: ' + bnone + '\ndestnum: ' + destnum;

                //hide/show the td.                    
                if (document.getElementById('tdairf' + destnum)) { document.getElementById('tdairf' + destnum).style.display = ((bair == true) ? '' : 'none'); }
                if (document.getElementById('tdrail' + destnum)) { document.getElementById('tdrail' + destnum).style.display = ((btra == true) ? '' : 'none'); }
                if (document.getElementById('tdtrf' + destnum)) { document.getElementById('tdtrf' + destnum).style.display = ((btrf == true) ? '' : 'none'); }
                if (document.getElementById('tdcar' + destnum)) { document.getElementById('tdcar' + destnum).style.display = ((bcar == true) ? '' : 'none'); }
                if (document.getElementById('tdnone' + destnum)) { document.getElementById('tdnone' + destnum).style.display = ((bnone == true) ? 'none' : ''); }

                //show/hide the no services available between destination
                if (document.getElementById('noservicemsg' + destnum)) { document.getElementById('noservicemsg' + destnum).style.display = ((bnone == true) ? '' : 'none'); }

                //these two IDs are hardcoded in Input_FitMultiIndiv.htm template.
                if (document.getElementById('noserviceheader' + destnum)) {
                    document.getElementById('noserviceheader' + destnum).innerHTML = 'I\'d like to go from ' + document.getElementById('destcity' + (destnum - 1)).value + ' to ' + document.getElementById('destcity' + destnum).value + ' by';
                }
                if (document.getElementById('noservicemsg' + destnum)) {
                    document.getElementById('noservicemsg' + destnum).innerHTML = 'We do not have any services between these destinations.  You must go from ' + document.getElementById('destcity' + (destnum - 1)).value + ' to ' + document.getElementById('destcity' + destnum).value + ' by your own means.';
                }
            }
        }
    }
}
function ChangeAJAXLastCallID(newid) {
    if (document.getElementById(newid)) {
        citycodehelpercallby = document.getElementById(newid);
    }
}
function checkArrowDown(e) {
    var keyCode;
    //alert('keycode_' + e.keyCode);
    if (e) {
        keyCode = e.keyCode;
    }
    else {
        keyCode = e.which;
    }
    if (keyCode == 40) {
        document.getElementById('citycodehelper').focus();
    }
}
function HideHelperSelect() {
    //alert('hiding');    
    if (document.getElementById('citycodehelper')) { document.getElementById('citycodehelper').style.display = 'none'; }
}
function setselectedhelpercity(e) {
    var keyCode;
    if (e) { keyCode = e.keyCode; }
    else { keyCode = e.which; }
    //alert('keycode_' + keyCode);
    if (keyCode == 9) {
        //select the current item.
        document.getElementById('citycodehelper').selectedIndex = document.getElementById('citycodehelper').options.selectedIndex;
        //turn the key into a enter key
        /****THE LINE BELOW WAS COMMENTED-OUT BECAUSE SINCE THE ONTAB KEYCODE WAS BEING CONVERTED TO A ONTER KEYCODE THE TAB KEY WAS NOT WORKING PROPERLY.---DRITAN NOV-29-2010****/
        //keyCode = 13;  
        document.getElementById('citycodehelper').style.display = 'none';
    }
    if (keyCode == 13) {
        setcityname();
        setcitycode();
        document.getElementById('citycodehelper').style.display = 'none';
        //if has car...show locations            
        if (document.getElementById('trip_type')) {
            if (document.getElementById('trip_type').value.toUpperCase().indexOf('CAR') > -1)
            { SetCarLocations(); }
        }
    }
    else if (keyCode == 40 || keyCode == 38) {
        //do nothing...user just go up(40) and down(38)
    }
    else {
        //give control back to the current textbox
        citycodehelpercallby.focus();
    }
}
function GetLastCityCode(currdestnum) {
    if (currdestnum && currdestnum != null && currdestnum != 'undefined') {
        if (document.getElementById('destination' + (parseInt(currdestnum) - 1)))
        { return document.getElementById('destination' + (parseInt(currdestnum) - 1)).value; }
    }
    return '';
}
/*
tid: the id of the element that the list of avail cities should popup under.
datatype: type of data that you're looking for  , FROMCITY, TOCITY, PRODUCTCODE, OR CARLOCATION....see xmlhttpResponse() below for more detail
brandid: the current brandid
predest: the previous destination...for multicities FIT shops.
*/
function attachcitycodehelper(tid, datatype, brandid, predest, triptype, param) {
    var txtid, helpid, x, y, z, h, w, dom, strXML;
    citycodehelpercallby = tid
    x = getX(tid);
    y = getY(tid);
    h = tid.offsetHeight;
    w = tid.offsetWidth;
    helpid = document.getElementById('citycodehelper');
    dom = null;
    var now, end, total, debug;

    //don't trust the typetype passed in.  get it from the page to get the most current one.
    if (document.getElementById('trip_type')) { triptype = document.getElementById('trip_type').value; }

    //if the previous citycode is not passed in, attempt to find it.
    if (predest == null || predest == 'undefined' || predest == '') {
        predest = GetLastCityCode(tid.getAttribute('currentdestnum'));
    }

    //get the xml
    now = new Date();
    end = new Date();
    debug = '';
    strXML = xmlhttpResponse(datatype, brandid, predest, triptype, param);
    //remember this xml data as the last one that was accessed.
    lastXML = strXML;

    end = new Date();
    debug = 'GetData: ' + (end - now) / 1000 + ' s';
    now = new Date();
    var i, j, seektext, seeklen, city, code, country, total, maxcitylen, strtemp, pos, lpos, rpos, allcitiesarr;
    seektext = tid.value.toUpperCase();
    seeklen = seektext.length;
    total = 0;
    maxcitylen = 0;
    helpid.options.length = 0;
    helpid = document.getElementById('citycodehelper');
    begdate = new Date();
    pos = 0;
    lpos = 0;
    rpos = 0;

    //format of data.
    //**CityCode|ProductDescription|CityDescription,Country.Description|ProductProductCode
    //WARNING: do not search by cityCode (exclude cityCode when matching) because we have multiple product that point to the same citycode.  This is because we have products in cities which do not have airport and must land at other city's airport)
    //so do not search by cityCode when matching on product.

    ///SEARCHING WITH STRING
    if (datatype.toUpperCase() == 'PRODUCTCODE') {
        pos = strXML.toUpperCase().indexOf('|' + seektext, pos);
        //if (pos == -1) { pos = strXML.toUpperCase().indexOf(seektext,pos+5);} //+5 to not include the **CITYCODE in matching.
    } else {
        pos = strXML.toUpperCase().indexOf('|' + seektext, pos);
        if (pos == -1) { pos = strXML.toUpperCase().indexOf('**' + seektext, pos); }
        //if (pos == -1) { pos = strXML.toUpperCase().indexOf(seektext,pos);}
    }

    while (pos > -1) {
        lpos = strXML.lastIndexOf('**', pos);
        rpos = strXML.indexOf('**', pos);

        if (lpos > -1 && rpos > lpos) {
            lpos = lpos + 2;
            strtemp = strXML.substr(lpos, (rpos - lpos));
            if (strtemp.split('|').length >= 3) {
                if (datatype.toUpperCase() == 'FROMCITYCODE') {
                    code = strtemp.split('|')[0];
                    city = strtemp.split('|')[1].replace(/&amp;/g, '&');
                    country = strtemp.split('|')[2].replace(/&amp;/g, '&');
                }
                else {
                    code = strtemp.split('|')[0];
                    city = strtemp.split('|')[2].replace(/&amp;/g, '&');
                    country = strtemp.split('|')[3].replace(/&amp;/g, '&');
                }
                //match add to options.
                try
                    { helpid.add(new Option(city, code)) }
                catch (e)
                    { helpid.add(new Option(city, code), null) }
                total += 1;
                //if (city.length > maxcitylen){ maxcitylen = city.length }
            }
        }
        if (rpos > 0 && rpos != (strXML.length - 2) && rpos != lpos) {
            if (datatype.toUpperCase() == 'PRODUCTCODE') {
                pos = strXML.toUpperCase().indexOf('|' + seektext, rpos);
                //if (pos == -1) { pos = strXML.toUpperCase().indexOf(seektext,rpos+5);} //+5 to not include the **CITYCODE in matching.
            } else {
                pos = strXML.toUpperCase().indexOf('|' + seektext, rpos);
                if (pos == -1) { pos = strXML.toUpperCase().indexOf('**' + seektext, rpos); }
                //if (pos == -1) { pos = strXML.toUpperCase().indexOf(seektext,rpos);}
            }
            //                pos = strXML.toUpperCase().indexOf('|' + seektext,rpos);
            //                if (pos = -1) { pos = strXML.toUpperCase().indexOf('**' + seektext,rpos);}
            //                if (pos = -1) { pos = strXML.toUpperCase().indexOf(seektext,rpos);}
        } else {
            //exit while
            pos = -1
        }
    }

    if (total > 0) {
        helpid.style.display = '';
        helpid.selectedIndex = -1;
        helpid.setAttribute('size', 10);
        tid.style.borderBottomWidth = '0px';
        helpid.style.borderTopWidth = '0px';
        helpid.style.left = x + 'px';
        helpid.style.top = (y + h) + 'px';
        helpid.style.position = 'absolute';
    }
    end = new Date();
    debug = debug + 'Build: ' + (end - now) / 1000 + ' s';
    //enable for ajax stats
    //alert(debug);
}

function viewalldest(tid, datatype, brandid, predest, triptype, destnum, nameid, codeid, param) {

    var strXML, strOut, viewallid, divcontainer, divcontainerid, tdcount, record, pos1, pos2, strlastcountry;
    var country, cityname, citycode, nameid, codeid;
    var cityliststarted, linkdivstarted;

    //don't trust the typetype passed in.  get it from the page to get the most current one.
    if (document.getElementById('trip_type')) { triptype = document.getElementById('trip_type').value; }

    //build the table and then show it.    
    //if the previous citycode is not passed in, attempt to find it.
    if (predest == null || predest == 'undefined' || predest == '') {
        predest = GetLastCityCode(destnum);
    }
    strXML = xmlhttpResponse(datatype, brandid, predest, triptype, param);
    //save the last XML data that was used.
    lastXML = strXML;

    divcontainerid = document.getElementById('viewalldiv');

    citycodehelpercallby = tid;

    strOut = '';
    strOut += '         <table width="100%" bgcolor="white" border="0" cellpadding="5" align="center" style="border: 1px solid #000000;">'
    strOut += '             <tr bgcolor="white">'
    strOut += '                 <td nowrap colspan="3">'
    if (datatype.toUpperCase() == 'FROMCITYCODE') {
        strOut += '                     <span class="Header">Departure Cities</span>'
    }
    else {
        strOut += '                     <span class="Header">Destinations</span>'
    }
    strOut += '                 </td>'
    strOut += '                 <td width="100%" align="right">'
    strOut += '                     <a href="#" onclick="HideOverlay(\'viewalldiv\');"> <img src="./' + brandid + '/Pics/close.gif" width="15" height="15" alt="" border="0" align="absmiddle" title="Closed"/></a>&nbsp;'
    strOut += '                 </td>'
    strOut += '             </tr>'

    cityliststarted = false;
    country = '';
    strlastcountry = '';
    tdcount = 0;
    pos1 = strXML.indexOf('**')
    var closedtd = false;
    while (pos1 > -1) {
        pos2 = strXML.indexOf('**', pos1 + 1);
        if (pos2 > pos1) {
            record = strXML.substring(pos1 + 2, pos2);
            pos1 = pos2;
        }
        else {
            //end ...set condition to exit.
            pos1 = -1;
        }

        if (record != '') {
            if (datatype.toUpperCase() == 'FROMCITYCODE') {
                citycode = record.split("|")[0];
                cityname = record.split("|")[1];
                country = record.split("|")[2];
            } else {
                citycode = record.split("|")[0];
                cityname = record.split("|")[2];
                country = record.split("|")[3];
            }
            if (!country || country == null || country == 'undefine') { country = ''; }
            if (strlastcountry == '') {
                //the very very first time through the loop.
                strOut += '<tr> <!-- FIRST -->'
            }

            if (strlastcountry != country && tdcount == 4) {
                //close the tr                                
                strOut += '</tr>'
                cityliststarted = false;
                tdcount = 0;
            }

            if (tdcount == 0 && strlastcountry != '' && country != strlastcountry) {
                //after all TDs are created.
                strOut += '<tr> <!-- NEW COUNTRY -->'
            }

            if (country.toUpperCase() != strlastcountry.toUpperCase()) {
                if (cityliststarted)
                { strOut += '</td>'; }
                //increase td and build it.
                tdcount += 1;
                strOut += '<td nowrap valign="top" width="20%">'
                strOut += ' <strong>' + country + '</strong><br/>'
                cityliststarted = true;
            }

            if (datatype.toUpperCase() == 'FROMCITYCODE') {
                strOut += '<a href="#" class="regularlink" onclick="document.getElementById(\'' + nameid + '\').style.backgroundColor=\'' + okcolor + '\';document.getElementById(\'' + nameid + '\').value=\'' + cityname + '\';document.getElementById(\'' + codeid + '\').value=\'' + citycode + '\';HideOverlay(\'viewalldiv\');">' + cityname + '</a><br/>\n'
            }
            else if (triptype.toUpperCase() == 'CAR') {
                //pull the car location list after setting destination name and code.
                strOut += '<a href="#" class="regularlink" onclick="document.getElementById(\'' + nameid + '\').style.backgroundColor=\'' + okcolor + '\';document.getElementById(\'' + nameid + '\').value=\'' + cityname + '\';document.getElementById(\'' + codeid + '\').value=\'' + citycode + '\';SetCarLocations();HideOverlay(\'viewalldiv\');">' + cityname + '</a><br/>\n'
            }
            else if (triptype.toUpperCase() == 'TRA') {
                strOut += '<a href="#" class="regularlink" onclick="document.getElementById(\'' + nameid + '\').style.backgroundColor=\'' + okcolor + '\';document.getElementById(\'' + nameid + '\').value=\'' + cityname + '\';document.getElementById(\'' + codeid + '\').value=\'' + citycode + '\';HideOverlay(\'viewalldiv\');">' + cityname + '</a><br/>\n'
            }
            else {
                strOut += '<a href="#" class="regularlink" onclick="document.getElementById(\'' + nameid + '\').value=\'' + cityname + '\';document.getElementById(\'' + codeid + '\').value=\'' + citycode + '\';ChangeAJAXLastCallID(\'destcity\'+' + destnum + '); setcitycode();SetCarLocations();HideOverlay(\'viewalldiv\');">' + cityname + '</a><br/>\n'
            }
            //strOut += '<!-- Build Info: tdcount: ' + tdcount + ' - CityListStarted: ' + cityliststarted + ' - Country: ' + country + ' - LastCountry: ' + strlastcountry + '-->\n';
            strlastcountry = country;
        }
    }

    //if no data found...say so
    if (strXML.indexOf('**') < 0) {
        if (predest.length > 0 && document.getElementById(nameid).value != 'undefined' && document.getElementById(nameid).value.length > 0) {
            strOut += '<tr><td colspan="4">We\'re sorry.  There are no available city coming from ' + document.getElementById(nameid).value + ' for this destination.'
            //also remove the cities currently in this destination box (if any)
            document.getElementById(nameid).value = '';
            document.getElementById(codeid).value = '';
        }
        else {
            strOut += '<tr><td colspan="4">We\'re sorry.  There are no available city for this destination.'
        }
    }

    //Close the last TD and TR
    strOut += '</td></tr>';
    //Close the table
    strOut += '</table>';

    divcontainerid.innerHTML = strOut;
    ShowOverlay('viewalldiv');
}

//Function that will set the dropdown correctly based on the previous destination, etc.
function SetDestDropdown(DestNum, datatype, brandid, predest, triptype, param) {
    var pos, lpos, rpos;
    var strtemp, strprevcountry;
    var optGroup, optOption;

    strprevcountry = '';
    //don't trust the typetype passed in.  get it from the page to get the most current one.
    if (document.getElementById('trip_type')) { triptype = document.getElementById('trip_type').value; }

    strXML = xmlhttpResponse(datatype, brandid, predest, triptype, param);

    //Clear out the destination dropdown
    document.getElementById('destination' + DestNum).options.length = 0;
    var sel = document.getElementById('destination' + DestNum);
    while (sel.firstChild) {
        sel.removeChild(sel.firstChild);
    }
    document.getElementById('destination' + DestNum).options[0] = new Option('Select a Destination', '');

    pos = strXML.indexOf('**')
    while (pos > -1) {
        lpos = strXML.indexOf('**', pos + 1);
        if (lpos > pos) {
            strtemp = strXML.substring(pos + 2, lpos);
            pos = lpos;
        }
        else {
            //end ...set condition to exit.
            pos = -1;
            strtemp = '';
        }

        if (strtemp != '') {
            if (strtemp.split('|').length >= 3) {
                code = strtemp.split('|')[0];
                city = strtemp.split('|')[2].replace(/&amp;/g, '&');
                country = strtemp.split('|')[3].replace(/&amp;/g, '&');

                //Is this a new country?
                if (strprevcountry != country) {
                    //If not the first country, add the group
                    if (strprevcountry != '')
                        document.getElementById('destination' + DestNum).appendChild(optGroup);
                    //Create the new Group
                    optGroup = document.createElement('optgroup');
                    optGroup.label = country;
                }

                //match add to options.
                //If there's a - in the code, add an extra tab to the city
                if (code.indexOf('-') > 0)
                    city = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + city;
                //document.getElementById('destination' + DestNum).options[optCount]= new Option(city, code)
                //Create the new option and add it to the Group
                optOption = document.createElement('option');
                optOption.innerHTML = city;
                optOption.value = code;
                optGroup.appendChild(optOption);

                strprevcountry = country;
            }
        }
    }
    //Add the last group
    if (optGroup != null)
        document.getElementById('destination' + DestNum).appendChild(optGroup);
}

function ClearCarLocations() {
    var strXML, strtemp, strCode, strName;
    var lpos, rpos, optCount;

    strXML = '';
    strtemp = '';
    strCode = '';
    strName = '';
    lpos = 0;
    rpos = 0;
    optCount = 1;

    try {
        //Empty out the dropdowns first
        document.getElementById('selpickup').options.length = 0;
        document.getElementById('seldropoff').options.length = 0;

        document.getElementById('selpickup').options[0] = new Option('>>Select a City<<', 0)
        document.getElementById('seldropoff').options[0] = new Option('>>Select a City<<', 0)
    }
    catch (ex) {
        //alert('SetCarLocations() Error: ' + ex.message);
    }
}

//Sets the pickup and dropoff location dropdowns based on the city selected
function SetCarLocations() {
    var strXML, strtemp, strCode, strName, strcarparam, citycode;
    var lpos, rpos, optCount;

    strXML = '';
    strtemp = '';
    strCode = '';
    strName = '';
    lpos = 0;
    rpos = 0;
    optCount = 1;

    try {
        //Empty out the dropdowns first
        document.getElementById('selpickup').options.length = 0;
        document.getElementById('seldropoff').options.length = 0;

        if (document.getElementById('destination1').value != '') {
            document.getElementById('selpickup').options[0] = new Option('>>Select a Location<<', 0)
            document.getElementById('seldropoff').options[0] = new Option('>>Select a Location<<', 0)


            //function xmlhttpResponse(strRequestType, brandid, predest, triptype, param, cacheid)
            //xmlhttpobject.send('Action=GETCARLOCATIONS&CityCode=' + document.getElementById('destination1').value.substring(0, 3));

            citycode = document.getElementById('destination1').value.substring(0, 3);
            //Now get the locations
            strXML = xmlhttpResponse('CARLOCATIONS', null, null, null, '&Citycode=' + citycode, citycode);

            lpos = strXML.indexOf('**') + 2;
            //Loop through the response to load the dropdowns
            while (lpos > -1) {
                rpos = strXML.indexOf('**', lpos);

                if (rpos > lpos) {
                    strtemp = strXML.substr(lpos, (rpos - lpos));
                    if (strtemp.split('|').length >= 2) {
                        strCode = strtemp.split('|')[0];
                        strName = strtemp.split('|')[1].replace(/&amp;/g, '&');

                        //Add to the dropdown list
                        //document.getElementById('selpickup').add(new Option(strName, strCode))
                        //document.getElementById('seldropoff').add(new Option(strName, strCode))
                        //FIC:2009-12-09 - The above statement ONLY works in IE.
                        document.getElementById('selpickup').options[optCount] = new Option(strName, strCode)
                        document.getElementById('seldropoff').options[optCount] = new Option(strName, strCode)
                        optCount++;
                    }
                }
                if (rpos > 0) {
                    lpos = strXML.indexOf('**', rpos);
                    if (lpos > -1)
                        lpos += 2;
                }
                else {
                    //exit while
                    lpos = -1
                }
            }
            //NOW if car is to be drop off at a different city....pull a different drop off locations for that cities.
            //Now get the locations            
            if (document.getElementById('docarcitycode1')) {
                citycode = document.getElementById('docarcitycode1').value.substring(0, 3).replace(/ /g, '');
            }
            if (citycode.length == 3) {
                strXML = xmlhttpResponse('CARLOCATIONS', null, null, null, '&CityCode=' + citycode, citycode);
                document.getElementById('seldropoff').options.length = 0;
                document.getElementById('seldropoff').options[0] = new Option('>>Select a Location<<', 0)
                optCount = 1;

                lpos = strXML.indexOf('**') + 2;
                //Loop through the response to load the dropdowns
                while (lpos > -1) {
                    rpos = strXML.indexOf('**', lpos);

                    if (rpos > lpos) {
                        strtemp = strXML.substr(lpos, (rpos - lpos));
                        if (strtemp.split('|').length >= 2) {
                            strCode = strtemp.split('|')[0];
                            strName = strtemp.split('|')[1].replace(/&amp;/g, '&');

                            //Add to the dropdown list
                            //document.getElementById('selpickup').add(new Option(strName, strCode))
                            //document.getElementById('seldropoff').add(new Option(strName, strCode))
                            //FIC:2009-12-09 - The above statement ONLY works in IE.
                            document.getElementById('seldropoff').options[optCount] = new Option(strName, strCode)
                            optCount++;
                        }
                    }
                    if (rpos > 0) {
                        lpos = strXML.indexOf('**', rpos);
                        if (lpos > -1)
                            lpos += 2;
                    }
                    else {
                        //exit while
                        lpos = -1
                    }
                }
            }
            ///set setting dropoff locations


        }
        else {
            document.getElementById('selpickup').options[0] = new Option('>>Select a City<<', 0)
            document.getElementById('seldropoff').options[0] = new Option('>>Select a City<<', 0)
        }
    }
    catch (ex) {
        //alert('SetCarLocations() Error: ' + ex.message);
    }
}

function getX(tid) {
    var x, op;
    x = 0;
    //x = tid.offsetRight;
    x = tid.offsetLeft;
    while (tid.offsetParent) {
        //alert('tid: ' + tid.id + ' - OffsetParent: ' + tid.offsetParent.offsetLeft);
        op = tid.offsetParent; // Get container parent
        x = x + op.offsetLeft; // Add this element's offset x in pixels
        tid = tid.offsetParent; // Update current container
    }
    return x;
}
function getY(tid) {
    var y, op;
    y = 0;
    y = tid.offsetTop;
    while (tid.offsetParent) {
        op = tid.offsetParent; // Get container parent
        y = y + op.offsetTop; 	// Add this element's offset y in pixels
        tid = tid.offsetParent; // Update current container
    }
    return y;
}



function xmlhttpResponse(strRequestType, brandid, predest, triptype, param, cacheid) {
    var strResponse, strbrandid, strpredest, strtriptype;
    strResponse = '';
    strbrandid = '';
    strpredest = '';
    strtriptype = '';

    //don't trust the typetype passed in.  get it from the page to get the most current one.
    if (document.getElementById('trip_type')) { triptype = document.getElementById('trip_type').value; }

    if (!param || param == null || param.toUpperCase() == 'UNDERFINED') {//param is not passed in.  set it to empty.
        param = '';
    }
    if (!cacheid || cacheid == null || cacheid.toUpperCase() == 'UNDERFINED') {//param is not passed in.  set it to empty.
        cacheid = '';
    }

    if (brandid && brandid != null && brandid != '' && brandid.toUpperCase() != 'UNDERFINED') {
        param += '&Theme=' + brandid;
        strbrandid = brandid;
    }
    //previous destination.
    if (predest && predest != null && predest != '' && predest.toUpperCase() != 'UNDERFINED') {
        param += '&previousdest=' + predest;
        strpredest = predest;
    }
    //what type of product are we looking for?  opt, sst, htl, rail    
    if (triptype && triptype != null && triptype != '' && triptype.toUpperCase() != 'UNDERFINED') {
        param += '&triptype=' + triptype;
        strtriptype = triptype;
    }
    //replace the first & char with ? 
    if (param != '')
    { param = param.replace('&', '?'); }

    //check if we already the the response for this RequestType.
    strResponse = arrAJAXResponse[strRequestType + strbrandid + strpredest + strtriptype + cacheid];
    if (strResponse && strResponse != '' && strResponse != 'undefined') // && strRequestType.toUpperCase() != 'CARLOCATIONS'
    {
        //we already have it.
        return strResponse;
    }

    xmlhttpobject = GetXMLHTTPObject();
    //if (!xmlhttpobject || xmlhttpobject == 'undefined')
    //{ alert('failed to get xmlhttpobject');return '';  }
    switch (strRequestType.toUpperCase()) {
        case 'FROMCITYCODE':
            //alert('open and sending request');
            xmlhttpobject.open("POST", './AJAX.aspx' + param, false);
            xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xmlhttpobject.send('Action=GETFROMCITYCODES');
            //xmlhttpobject.onreadystatechange = new function statechangehandler()
            //{
            if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200) {
                //alert('data is ready');
                strResponse = xmlhttpobject.responseText;
                //call function to build dropdown.
                //attachcitycodehelper(citycodehelpercallby);

                //save the result for this call
                arrAJAXResponse[strRequestType + strbrandid + strpredest + strtriptype + cacheid] = xmlhttpobject.responseText;
            }
            //}
            break;
        case 'TOCITYCODE':
            //alert('open and sending request');
            xmlhttpobject.open("POST", './AJAX.aspx' + param, false);
            xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xmlhttpobject.send('Action=GETTOCITYCODES');
            //xmlhttpobject.onreadystatechange = new function statechangehandler()
            //{
            if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200) {
                //alert('data is ready');
                strResponse = xmlhttpobject.responseText;
                //call function to build dropdown.
                //attachcitycodehelper(citycodehelpercallby);

                //save the result for this call
                arrAJAXResponse[strRequestType + strbrandid + strpredest + strtriptype + cacheid] = xmlhttpobject.responseText;
            }
            //}
            break;
        case 'PRODUCTCODE':
            //alert('open and sending request');
            xmlhttpobject.open("POST", './AJAX.aspx' + param, false);
            xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xmlhttpobject.send('Action=GETPRODUCTCODES');
            //xmlhttpobject.onreadystatechange = new function statechangehandler()
            //{
            if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200) {
                //alert('data is ready');
                strResponse = xmlhttpobject.responseText;
                //call function to build dropdown.
                //attachcitycodehelper(citycodehelpercallby);
                //save the result for this call
                arrAJAXResponse[strRequestType + strbrandid + strpredest + strtriptype + cacheid] = xmlhttpobject.responseText;
            }
            //}
            break;
        case 'GETPRODUCTTRANSPORTATION':
            //alert('open and sending request');
            xmlhttpobject.open("POST", './AJAX.aspx' + param, false);
            xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xmlhttpobject.send('Action=GETPRODUCTTRANSPORTATION');
            if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200) {
                //alert('data is ready');
                strResponse = xmlhttpobject.responseText;
                //call function to build dropdown.
                //attachcitycodehelper(citycodehelpercallby);
                //save the result for this call
                arrAJAXResponse[strRequestType + strbrandid + strpredest + strtriptype + cacheid] = xmlhttpobject.responseText;
            }
            break;
        case 'CARLOCATIONS':
            xmlhttpobject.open("POST", './AJAX.aspx' + param, false);
            xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xmlhttpobject.send('Action=GETCARLOCATIONS');
            //xmlhttpobject.send('Action=GETCARLOCATIONS&CityCode=' + document.getElementById('destination1').value.substring(0, 3));

            if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200) {
                strResponse = xmlhttpobject.responseText;
                //save the result for this call
                //for car save result per from destination
                arrAJAXResponse[strRequestType + strbrandid + strpredest + strtriptype + cacheid] = xmlhttpobject.responseText;
            }
            break;
        default:
            //do nothing
            break;
    }
    //alert('returning data');
    return strResponse;
}


function DynamicVacBuilder(action, trip_type) {
    var strResponse, param;
    strResponse = '';
    param = '';
    //subscribeaction=U
    //param += '?action=' + action;
    param = '?trip_type=' + trip_type;

    xmlhttpobject = GetXMLHTTPObject();

    xmlhttpobject.open("POST", './STWMain.aspx' + param, false);
    xmlhttpobject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttpobject.send('action=SPECSERVICEFITPKGBUILDERGATE1');

    if (xmlhttpobject.readyState == 4 && xmlhttpobject.status == 200) {
        strResponse = xmlhttpobject.responseText;
    }

    //alert(strResponse);
    if (strResponse == '') {
        alert('Error occurred. \n Please refresh the page.');
        return;
    }

    //making sure no error were returned
    if (strResponse.match('Error') != -1 || strResponse.match('Failed') != -1) {
        //SetDate(strResponse); 
        //strResponse = strResponse.split("/--/")[0];
        //InsertRows(strResponse);
    }
    else {
        alert('Error occured while retriving data.\n Please refresh the page.'); //(strResponse);
        return;
    }

    //if we got here everything is good--adding the response to the page body
    if (document.getElementById('mainAction')) {
        document.getElementById('mainAction').innerHTML = '';
        document.getElementById('mainAction').innerHTML = '<p style="width: 980px;" align="center">\n' + strResponse + '\n</p>';


        updateNumRooms();
        DoingTesting();
    }
}

