
var strPrefixIdd, strPrefixCntryCode, strPrefixNdd, strPrefixCntryCode2
var strCntryIDAway, strCntryIDHome, strDialExplanation,strPrefixCntryCodeTemp, strPrefixIddTemp
var strPrefixAreaCode, strDialExplanation
var bAwayDisclude
var nSubRegionID
var nQueryStringCount
    
function dialDisplay(p_nQueryStringCount,p_strPrefixIdd,p_strPrefixCntryCode,p_strPrefixNdd,p_strPrefixCntryCode2,p_bAwayDisclude,p_bIsQueryStringEmpty,p_strCntryIDHome,p_strCntryIDAway)
{
    var strDialCodeHTML, strCpp, strCbxDialVal, strPrefix
    var cbxDial
    var lngIndex
    var arrSubRegion
    var cbxAreaCodes = document.getElementById("cbxAreaCodes")

    nQueryStringCount = p_nQueryStringCount

    if(p_strCntryIDHome == 'GB')
    {
        if(cookieGet('DialAround') == "hide")
        {
            toggleDialAround()
        }
    }
    
    if (p_strPrefixIdd != null)
    {
        strPrefixIdd = p_strPrefixIdd
        strPrefixIddTemp = p_strPrefixIdd
    }
    if (p_strPrefixCntryCode != null)
    {
        strPrefixCntryCode = p_strPrefixCntryCode
        strPrefixCntryCodeTemp = p_strPrefixCntryCode
    }
    
    if(p_strPrefixNdd != null)
    {
        strPrefixNdd = p_strPrefixNdd
    }
    if (p_strPrefixCntryCode2 != null)
    {
        strPrefixCntryCode2 = p_strPrefixCntryCode2
    }
   
    if(p_bAwayDisclude != null)
    {
        bAwayDisclude = p_bAwayDisclude
    }
    if(p_strCntryIDAway != null)
    {
        strCntryIDAway = p_strCntryIDAway
    }

    if (p_strCntryIDHome != null) {
        strCntryIDHome = p_strCntryIDHome
    }
   
    if (p_bIsQueryStringEmpty == true)
    {
        strDialExplanation = '/#International-Dialing-Codes'
    }
    else if (p_bIsQueryStringEmpty != null)
    {
        strDialExplanation = 'dial-explanation.aspx'
    }
    
    strDialCodeHTML = "<img class=\"icon\" src=\"http://www.timedial.net/Images/Dialing.gif\" alt=\"Dialing Codes\" title=\"Dialing Codes\" />"

    
    
    if(strPrefixIdd.length != 0 || strPrefixCntryCode.length != 0 || strPrefixNdd.length != 0) {

        for (lngIndex=0;lngIndex<=strPrefixIdd.length-1;lngIndex++)
        {   
            strDialCodeHTML = strDialCodeHTML + '<a href="' + strDialExplanation + '"><img class="digitSml" src="' 
            + getDigitImage(strPrefixIdd,lngIndex,bAwayDisclude) + '" alt="Idd Prefix - Tells the telephone network that this is an international call. Can dial a plus symbol instead." title="Idd Prefix - Tells the telephone network to make an international call. Can dial a plus symbol instead." /></a>'
        }
        strDialCodeHTML = strDialCodeHTML + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
        for (lngIndex=0;lngIndex<=strPrefixCntryCode.length-1;lngIndex++)
        {
            strDialCodeHTML = strDialCodeHTML + '<a href="' + strDialExplanation + '"><img class="digitSml" src="' 
            + getDigitImage(strPrefixCntryCode,lngIndex,bAwayDisclude) + '" alt="Country Code - Identifies the country to call" title="Country Code - Identifies the country to call" /></a>'
        }
        strDialCodeHTML = strDialCodeHTML + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
        for (lngIndex=0;lngIndex<=strPrefixNdd.length-1;lngIndex++)
        {
            strDialCodeHTML = strDialCodeHTML + '<a href="' + strDialExplanation + '"><img class="digitSml" src="' 
            + getDigitImage(strPrefixNdd,lngIndex,!bAwayDisclude) + '" alt="Ndd Prefix - Dialed only for national calls not international" title="Ndd Prefix - Dialed only for national calls not international" /></a>'
        }
        
        if(document.getElementsByTagName('select').length == null)
        {
            cbxDial = document.getElementById('cbxDial')
        }
        else
        {
            for(lngIndex = document.getElementsByTagName('select').length - 1; lngIndex > -1; lngIndex--)
            {
                if(document.getElementsByTagName('select')[lngIndex].name == 'cbxDial')
                {
                    cbxDial = document.getElementsByTagName('select')[lngIndex]
                    break;
                }
            }
        }
        
        if(cbxDial != null)
        {
            if (cbxDial.value == null)
            { 
                strCbxDialVal = cbxDial[1].value
            }
            else
            {
               strCbxDialVal = cbxDial.value
            }
        }
        if(strCntryIDAway == 'MX')
        {  
            if (strCbxDialVal == 'Overseas to MX Mobile')
            {
                strDialCodeHTML = strDialCodeHTML + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                + '<a href="' + strDialExplanation + '"><img class="digitSml" src="' 
                + getDigitImage('1',0,bAwayDisclude) + '" alt="Overseas call to Mexican CPP Mobile" title="Overseas call to Mexican CPP Mobile" /></a>'
            }
        }
        
        if(strCntryIDAway == 'AR')
        {
            if (strCbxDialVal == 'CPP')
            {
                strCpp = '9'
                strDialCodeHTML = strDialCodeHTML + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                strDialCodeHTML = strDialCodeHTML + '<a href="' + strDialExplanation + '"><img class="digitSml" src="' 
                + getDigitImage(strCpp,0,bAwayDisclude) + '" alt="Argentina CPP" title="Argentina CPP" /></a>';
            }
        }

        if (strCntryIDAway == 'IT')
        {
            if(strCntryIDHome == strCntryIDAway)
                strPrefix = '1'
            else
                strPrefix = '0'
            

            strDialCodeHTML = strDialCodeHTML + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
            strDialCodeHTML = strDialCodeHTML + '<a href="' + strDialExplanation + '"><img class="digitSml" src="'
                + getDigitImage(strPrefix, 0, false) + '" alt="Italy Prefix" title="Italy Prefix" /></a>';

        }

      
        
        if(cbxAreaCodes)
        {
            arrSubRegion = cbxAreaCodes.value.split(',')
            if(arrSubRegion.length > 1)
            {
                nSubRegionID = Number(arrSubRegion[0])
                strPrefixAreaCode = arrSubRegion[1]
                
                strDialCodeHTML = strDialCodeHTML + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                for (lngIndex=0;lngIndex<=strPrefixAreaCode.length-1;lngIndex++)
                {
                    strDialCodeHTML = strDialCodeHTML + '<a href="' + strDialExplanation + '"><img class="digitSml" src="'
                    + getDigitImage(strPrefixAreaCode,lngIndex,false) + '" alt="Area Code" title="Area Code" id="imgAreaCode' + (lngIndex + 1) + '" /></a>'
                }
            }
        }
        else
        {
            nSubRegionID = null
            strPrefixAreaCode = null
        }
       
        if(strCntryIDAway == 'AR')
        {
            if (strCbxDialVal == 'CPP')
            {
                strDialCodeHTML = strDialCodeHTML + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                strCpp = '15'
                for (lngIndex=0;lngIndex<=strCpp.length-1;lngIndex++)
                {
                    strDialCodeHTML = strDialCodeHTML + '<a href="' + strDialExplanation + '"><img class="digitSml" src="' 
                    + getDigitImage(strCpp,lngIndex,!bAwayDisclude) + '" alt="Argentina CPP" title="Argentina CPP" /></a>'
                }
            }
        }
        document.getElementById("divDialCode").innerHTML = strDialCodeHTML 
    }
    else
    {
        document.getElementById("divDialCode").innerHTML = strDialCodeHTML + '<a href="' + strDialExplanation + '"><img src="http://www.timedial.net/Images/GreyRectangle.gif" class="digitBig" alt="International Dialing Codes" title="International Dialing Codes" /></a>'                      
    }
    
    document.getElementById("divDialCode").innerHTML = document.getElementById("divDialCode").innerHTML + '<a href="' + strDialExplanation + '" title="International Dialing Codes Explanation"><img src="http://www.timedial.net/Images/Help.gif" alt="International Dialing Codes Explanation" title="International Dialing Codes Explanation" /></a>'
 
}

function cbxDial_onChange()
{
    var arrPrefixes
    if (this.value != 'Overseas to MX Mobile')
    {
        arrPrefixes = this.value.split(',')
      
        if (arrPrefixes[0] != '')
        {
            strPrefixIdd = arrPrefixes[0]
        }
        
        if (arrPrefixes[1] != '')
        {   
            if (arrPrefixes[1] == "strPrefixCntryCodeFromThailand")    
            {    
                if (strPrefixCntryCode2 != '')
                {
                    strPrefixCntryCode = strPrefixCntryCode2  
                }
            }
            else if (arrPrefixes[1] == "strPrefixCntryCodeTemp")
            {
                strPrefixCntryCode = strPrefixCntryCodeTemp
                strPrefixIdd = strPrefixIddTemp
            }
            else
            {
                strPrefixCntryCode = arrPrefixes[1]
            }
        }
        if (arrPrefixes[3] != '')
        {
            strPrefixNdd = arrPrefixes[3]
        }
    }
    dialDisplay()
}

function cbxAreaCodes_onChange(strCntryIDHome)
{
    var imgSubRegion = new Image()
    var divDialAround = document.getElementById('divDialAround')
    
    dialDisplay()
    imgSubRegion.src = 'ServerValSet.aspx?SubRegionIDAway=' + nSubRegionID
    
    if(divDialAround)
    {
        postToServer('DialAround.aspx','',divDialAround, false, true)
    }
    
    for (var i = 300; i < 1500; i+= 300)
    {
        window.setTimeout('makeAreaCodeRed();', i)
        window.setTimeout('makeAreaCodeGrey();', (i + 150))
    }

    return true;
}

function makeAreaCodeRed()
{
    for (var i = 1; img = document.getElementById('imgAreaCode' + i); i++)
    {
        img.src = getDigitImage(strPrefixAreaCode,i-1,false,true)
    }
}

function makeAreaCodeGrey()
{
    for (var i = 1; img = document.getElementById('imgAreaCode' + i); i++)
    {
        img.src = getDigitImage(strPrefixAreaCode,i-1,false,false)
    }
}

function toggleDialAround()
{
    if(document.getElementById('divDialAround').style.display == 'none')
    {
        document.getElementById('divDialAround').style.display = 'block'
        cookieSet('DialAround','show',365)
        document.getElementById('divDialAroundToggle').innerHTML = '- Hide Me'
    }
    else
    {
        document.getElementById('divDialAround').style.display = 'none'
        cookieSet('DialAround','hide',365)
        document.getElementById('divDialAroundToggle').innerHTML = '+ Show Me <br /><br /><br /><br /><br /><br /><br />'
    }
}



