
var strPageNamePrefix, strToFor
var strCntryIDAway, strCntryIDHome
var strCntryIDAwayQS, strRegionIDAwayQS, strCntryIDHomeQS, strRegionIDHomeQS
var bHome
var strPageCurr
var strDirectory

    
function initialiseDropDowns(p_strCntryIDHomeQS,p_strRegionIDHomeQS,p_strCntryIDAwayQS,p_strRegionIDAwayQS, p_strCntryIDHome, p_strCntryIDAway)
{
    var xmlCombos
    var divNavFrom = document.getElementById('divNavFrom')
    var divNavTo = document.getElementById('divNavTo')
    
    strCntryIDHomeQS = formatLocationID(p_strCntryIDHomeQS)
    strRegionIDHomeQS = formatLocationID(p_strRegionIDHomeQS)
    strCntryIDAwayQS = formatLocationID(p_strCntryIDAwayQS)
    strRegionIDAwayQS = formatLocationID(p_strRegionIDAwayQS)

    strCntryIDHome = p_strCntryIDHome
    strCntryIDAway = p_strCntryIDAway
    strDirectory = '../'
    
    strPageCurr = window.location.href.toLowerCase()
    
    if(strPageCurr.indexOf('/world-time-difference-calculator/') > -1)
    {
        strPageNamePrefix = 'converter-'
        strToFor = 'to'
    }
    else if(strPageCurr.indexOf('/link-to-us/') > -1)
    {
        strPageNamePrefix = ''
        strToFor = 'to'
    }
    else if(strPageCurr.indexOf('/phone-cards-price-compare/') > -1)
    {
        strPageNamePrefix = 'calling-cards-'
        strToFor = 'for'
    }
    else if (strPageCurr.indexOf('/sim-cards-price-compare/') > -1) {
        strPageNamePrefix = 'calling-'
        strToFor = 'to'
    }  
    else
    {
        strDirectory = ''
        strPageNamePrefix = 'world-time-zone-dialing-codes-'
        strToFor = 'for'
    }

    if(divNavFrom || divNavTo)
    {
        function CallbackFunction(xmlCombos)
        {
            if(divNavFrom)
            {
                divNavFrom.innerHTML = xmlCombos.selectSingleNode('Nav/From').xml 
            }
            if(divNavTo)
            {
                divNavTo.innerHTML = xmlCombos.selectSingleNode('Nav/To').xml
            }
        }
        
        loadXMLDoc(strDirectory + 'LocationCombosXML.aspx', false, false, CallbackFunction)
        
    }
}

function cbxCntries_onchange(bHome)
{
    var imgSubRegion
    if(bHome == true)
    {
        cntryHomeChange() 
    }
    else
    {
        imgSubRegion = new Image()
        imgSubRegion.src = strDirectory + 'ServerValSet.aspx?SubRegionIDAway&Value='
        cntryAwayChange()
    }
}

function cbxRegions_onchange(bHome)
{
    if(bHome == true)
        regionHomeChange() 
    else
        regionAwayChange()
}

function cntryHomeChange()
{ 
    var cbxCntries = document.getElementById("cbxCntriesFrom")
    var strUrl = strPageNamePrefix + 'from-' + cbxCntries.options[cbxCntries.selectedIndex].value

    if(strCntryIDAwayQS != "")
        strUrl = strUrl + '-' + strToFor + '-' + strCntryIDAway
        
    if(strRegionIDAwayQS != "")
        strUrl = strUrl + '-' + strRegionIDAwayQS
  
    window.parent.location.href = strUrl + '.aspx' 
    
}

function regionHomeChange(bHome)
{ 

    var cbxRegions = document.getElementById("cbxRegionsFrom")
    var strUrl = strPageNamePrefix
    
    strUrl = strUrl + 'from-' + strCntryIDHome
    if(cbxRegions.options[cbxRegions.selectedIndex].value != 'Select')
        strUrl = strUrl + '-' + cbxRegions.options[cbxRegions.selectedIndex].value
    
    if(strCntryIDAwayQS != "") 
        strUrl = strUrl + '-' + strToFor + '-' + strCntryIDAway
    if(strRegionIDAwayQS != "") 
        strUrl = strUrl + '-' + strRegionIDAwayQS
   
    window.parent.location.href = strUrl + '.aspx'     
}

function cntryAwayChange(bHome)
{ 
    var cbxCntries = document.getElementById("cbxCntriesTo")
        
    var strUrl = strPageNamePrefix
    
    if(strPageCurr.indexOf('link-to-us') < 0)
    {
        if(strCntryIDHomeQS != "")
            strUrl = strUrl + 'from-' + strCntryIDHome + '-'
        
        if(strRegionIDHomeQS != "") 
            strUrl = strUrl + strRegionIDHomeQS + '-'
    }

    strUrl = strUrl + strToFor + '-' + cbxCntries.options[cbxCntries.selectedIndex].value
    
    window.parent.location.href = strUrl + '.aspx' 
    
}

function regionAwayChange()
{
    var cbxRegions = document.getElementById("cbxRegionsTo")
    var strUrl = strPageNamePrefix
    
    if(strPageCurr.indexOf('link-to-us') < 0)
    {
        if(strCntryIDHomeQS != "")
            strUrl = strUrl + 'from-' + strCntryIDHome + '-'
            
        if(strRegionIDHomeQS != "")
            strUrl = strUrl + strRegionIDHomeQS + '-'
    }
  
    strUrl = strUrl + strToFor + '-' + strCntryIDAway
    if(cbxRegions.options[cbxRegions.selectedIndex].value != 'Select')
        strUrl = strUrl + '-' + cbxRegions.options[cbxRegions.selectedIndex].value

    window.parent.location.href = strUrl + '.aspx' 
}

function formatLocationID(strLocationID)
{
    if(strLocationID == 'None' || strLocationID == 'N/A' || strLocationID == 'Select')
        return ""
    else
        return strLocationID
}

