﻿/*
Check Your Flight quick tools
*/
function showAirlinePage()
{
    var link = airlinesDropDownList.options[airlinesDropDownList.selectedIndex].value;
    window.open(link);
}

/*
Book your next stay quick tools
*/

function countriesDropDownList_OnChange()
{
    var strSelectedCountryID = countriesDropDownList.value;
    
    if(strSelectedCountryID != null && strSelectedCountryID != "")
    {
        if(strSelectedCountryID == "0001")
        {
            //usa
            var stateContainer = document.getElementById("statesContainer");
            stateContainer.style.display = "";
            stateCaptionLabel.innerHTML = "State:";
        } 
        else if(strSelectedCountryID == "0260")
        {
            //canada
            var stateContainer = document.getElementById("statesContainer");
            stateContainer.style.display = "";
            stateCaptionLabel.innerHTML = "Province:";
        }
        else
        {
            //hide state and dropdownlist
            var stateContainer = document.getElementById("statesContainer");
            stateContainer.style.display = "none";
        }
    }
}

function findHotelButton_Click()
{
    var strSelectedCountryID = countriesDropDownList.value;
    var strCityTown = escape(trim(cityTownTextBox.value));
    var strSelectedStateID = statesDropDownList.value;

    var url = "http://www.ichotelsgroup.com/redirect?path=hotelsearchresults&brandCode=ex&regionCode=1&";
    
    var strCulture = getCulture();
    
    if(strCulture != null && strCulture != "")
    {
        var strTemp = "";
        
        if(strCulture == "en-US")
        {
            strTemp = "en";
        }
        else
        {
            strTemp = "fr";
        }
        url += "localeCode=" + strTemp + "&";
    }
   
    url += "city=" + strCityTown + "&";
    
    //add state only if USA or Canada
    if(strSelectedStateID != null && strSelectedStateID != "")
    {
        if(isUSAOrCanada(strSelectedCountryID))
        {
            url += "stateId=" + strSelectedStateID + "&";
        }
    }
               
    url += "countryId=" + strSelectedCountryID + "&";
    url += "searchGroupCodes=all&rateTypeCodes=6CBARC";
      
    window.open(url);
}

function trim(str)
{
    return str.replace(/^\s+|\s+$/g, '') ;
}

function getCulture()
{
    var x = document.getElementById("currentCulture");
    return x.value;
}

function isUSAOrCanada(str)
{
    return str == "0001" || str == "0260";
}

