/////////////Underline Text/////////////////////////////////////
function underline(menu, objID, linkID)
{
    document.getElementById(linkID).style.textDecorationUnderline = true;
    HM_f_PopUp(menu,objID);
} 

function remove_underline(menu, objID, linkID)
{
    document.getElementById(linkID).style.textDecorationUnderline=false;
    HM_f_PopDown(menu);
}
//////////////////////////XML General////////////////////////////
function getcountry()
{
    var country = document.getElementById('CountryDDL');
    if (country == null)
    {
        country = document.getElementById('ctrlHeader_CountryDDL');
    }
    
    return country;
}

function getCategory()
{
    var visas = document.getElementById('VisasDDL');
    if (visas == null)
    {
        visas = document.getElementById('ctrlHeader_VisasDDL');
    }
    return visas;
}

function getUSAVisas(divName)
{
    var usa = document.getElementById(divName);
    if (usa == null)
    {
        usa = document.getElementById('ctrlHeader_' + divName);
    }  
    return usa;
}


function loadXMLS(XMLfileLocation, ddl, selected, xmlNum)
{   
	    if ((xmlNum == 2) || (xmlNum == 3))
            {ddl.innerHTML = "";}
            
        $.get(XMLfileLocation, function(xml)
        {
            $(selected,xml).each(function()
            {ddl.options[ddl.options.length] = new Option($(this).attr('text'), $(this).attr('value'));}
            );
        });
        
        if (xmlNum == 2)
        {
            var flag_img = document.getElementById("flag");
            var country = getcountry();
            
            if (selected != "NONE")
            {    
                flag_img.style.display = 'block';
                flag_img.src = '/graphics/flags/' + selected + '.gif';
                ShowDIVContent('Category_Div',  country); 
                HideUSADivs();
            }
            else
            {
                flag_img.style.display = 'none';
                HideDIVContent('Category_Div', country);
                HideUSADivs();
            }
        }
        else if (xmlNum == 3)
        {
            var category = getCategory();
            if (selected != "NONE")
                {ShowDIVContent(category.value,  category);}
            else
                {HideDIVContent(category.value,  category);}
        }
}

function load_Category_Types()
{loadXMLS("/XML_CSS/CountryVisas.xml", getCategory(), getcountry().value, 2);}

function HideUSADivs()
{
    if (document.getElementById('C_Div').style.display != 'none')
    {document.getElementById('C_Div').style.display = 'none';}
    if (document.getElementById('TS_Div').style.display != 'none')
    {document.getElementById('TS_Div').style.display = 'none';}
    if (document.getElementById('TVGM_Div').style.display != 'none')
    {document.getElementById('TVGM_Div').style.display = 'none';}
    if (document.getElementById('TW_Div').style.display != 'none')
    {document.getElementById('TW_Div').style.display = 'none';}
    if (document.getElementById('FB_Div').style.display != 'none')
    {document.getElementById('FB_Div').style.display = 'none';}
    if (document.getElementById('EBIBO_Div').style.display != 'none')
    {document.getElementById('EBIBO_Div').style.display = 'none';}
}

function usavisa_redirect(divName)
{
    var visa_types = getUSAVisas(divName);
    if (visa_types.value != "Select a Visa")
    {
        window.location = visa_types.value;
    }
}
function category_redirect()
{
    var category = getCategory();
    var country = getcountry();
    
    if (country.value == "USA")
    {   
        HideUSADivs();
        ShowDIVContent(category.value,  category);
    }
    else if (category.value != "Select a Visa")
    {
        var temp = category.value;
        
        while (temp.indexOf(";") != -1)
        {temp = temp.replace(";", "&");}
        window.location = temp;
    }
}

///////////////Hide Show DIV's///////////////////////
var cX = 0; 
var cY = 0; 
var rX = 0; 
var rY = 0;

function UpdateCursorPosition(e)
{ 
    cX = e.pageX; 
    cY = e.pageY;
}

function UpdateCursorPositionDocAll(e)
{ 
    cX = event.clientX; 
    cY = event.clientY;
}

if(document.all) 
{ 
    document.onmousemove = UpdateCursorPositionDocAll; 
}
else 
{ 
    document.onmousemove = UpdateCursorPosition; 
}

function AssignPosition(d, dropdown) 
{   
    p = getElementPosition(dropdown);
    if (dropdown.name == 'CountryDDL')
    {
        d.style.left = p.x - 4;
    }
    else
    {
        d.style.left = p.x;
    }
    
    d.style.top = p.y + 23;
}

function getElementPosition(theElement)
{  
    var posX = 0;  
    var posY = 0;                
    while(theElement != null)
    {
        posX += theElement.offsetLeft;    
        posY += theElement.offsetTop;    
        theElement = theElement.offsetParent;  
    }                        		       
    return {x:posX,y:posY}
}


function HideDIVContent(d) 
{
    if(d.length < 1) 
    { 
        return;
    }
    document.getElementById(d).style.display = "none";
}

function ShowDIVContent(d, dropdown) 
{
    if(d.length < 1) 
    { 
        return; 
    }
    
    var dd = document.getElementById(d);
    AssignPosition(dd, dropdown);
    dd.style.display = "block";
}

function ReverseContentDisplay(d, dropdown) 
{
    if(d.length < 1) 
    { 
        return; 
    }
    var dd = document.getElementById(d);
    AssignPosition(dd, dropdown);
    if(dd.style.display == "none") 
    { 
        dd.style.display = "block"; 
    }
    else 
    { 
        dd.style.display = "none"; 
    }
}