var _objMenuXML = null;
var _sLastContentID;

function MGT_ShowMenu()
{
    /* SET THE FIRST ITEM TO SELECTED AND LOAD IT IF NECESSARY */
    if (document.getElementById("_tdNav0") != null) document.getElementById("_tdNav0").onclick();

    ShowBackgroundDiv();
    CenterDiv(document.getElementById("_divMenu"));
}

function MGT_HideMenu()
{
    HideBackgroundDiv();    
    document.getElementById("_divMenu").style.display = "none";
}

function MGT_ShowHelp(LoadFirstItem)
{
    /* SET THE FIRST ITEM TO SELECTED AND LOAD IT IF NECESSARY */
    if (LoadFirstItem && document.getElementById("_tdHelp0") != null) document.getElementById("_tdHelp0").onclick();

    ShowBackgroundDiv();
    CenterDiv(document.getElementById("_divMGTHelp"));
}

function MGT_HideHelp()
{
    HideBackgroundDiv();    
    document.getElementById("_divMGTHelp").style.display = "none";
}

function MGT_SwitchMenu(SelectedCell, ID)
{
    MGT_SwitchNav(SelectedCell, "_tblMenuSections", "_divSectionContent", ID, "4", true);
}

function MGT_SwitchHelp(SelectedCell, ID)
{
    MGT_SwitchNav(SelectedCell, "_tblHelpSections", "_divMGTHelpContent", ID, "2", true);
}

function MGT_SwitchNav(SelectedCell, TableID, ContentDivID, ID, Type, DowloadContents)
{
    if (SelectedCell != null)
    {
        /* RESET ALL THE CELLS TO OFF */
        var objTDs = document.getElementById(TableID).getElementsByTagName("td");   
        
        if (objTDs != null)
        {
            for (var i = 0; i < objTDs.length; i++)
            {
                if (objTDs[i].className == "featureON")
                {
                    objTDs[i].className = "featureOFF";
                }
            }
        }

        /* MAKE SURE THE FEEDBACK DIV IS HIDDEN AND SHOW THE REGULAR HELP DIV */
        $("#_divMGTHelpContent").show();
        $("#_divFeedback").hide();
        
        SelectedCell.className = "featureON";
        if (document.getElementById("__hidLastSelectedItem") != null) document.getElementById("__hidLastSelectedItem").value = SelectedCell.id;
        
        /* MAKE SURE THE CONTENT DIV IS SCROLLED TO THE TOP */
        document.getElementById(ContentDivID).scrollTop = 0;
        
        _sLastContentID = ContentDivID;
        
        /* LOAD THE MENU CONTENTS */
        if (DowloadContents)
        {
            /* SHOW THE LOADING IMAGE */
            MGT_ShowLoadingImage(ContentDivID);        
        
            _objMenuXML = null;
            _objMenuXML = CreateXMLRequest("/Marketgate/Data/ReturnMenu.aspx?i=" + ID + "&t=" + Type, NavDownloadStateChange);        
        }
    }
}

function MGT_ShowLoadingImage(ContentDivID)
{
    /* CLEAR OUT THE CONTENTS */
    document.getElementById(ContentDivID).innerHTML = "<table style=\"width: 100%; margin: 0px auto;\"><tr><td align=\"center\"><img src=\"/Marketgate/Images/processing_small.gif\" alt=\"Loading\" /></td></tr></table>";
}

function MGT_HideLoadingImage()
{
    var divImage = document.getElementById("_divMenuLoadingImage");
    
    if (divImage != null)
    {
        divImage.style.display = "none";
    }
}

function NavDownloadStateChange()
{
    if (_objMenuXML != null)
    {               
        if (_objMenuXML.readyState == 4)    /* COMPLETE */
        {                           
            if (_objMenuXML.status == 200)  /* RETURNED OK */
            {                                    
                if (_objMenuXML.responseText.length > 0)
                {                    
                    document.getElementById(_sLastContentID).innerHTML = _objMenuXML.responseText; 
                }
            } 
             
            MGT_HideLoadingImage();
        }            
    } 
}

function MGT_ShowFeedback()
{
    if (document.getElementById("_divMGTHelp").style.display != "block")
    {
        MGT_ShowHelp(false);
    }

    MGT_SwitchNav(document.getElementById("_tdFeedback"), "_tblHelpSections", "_divMGTHelpContent", 0, "2", false);

    /* LOAD THE CONTENTS WITH OUR FEEDBACK DIV */
    $("#_divMGTHelpContent").hide();
    $("#_divFeedback").show();
}

function MGT_ShowTutorials()
{
    if (document.getElementById("_tdHelp1") != null) document.getElementById("_tdHelp1").onclick();
    MGT_ShowHelp(false);
}

function MGT_ShowWebcasts()
{
    if (document.getElementById("_tdHelp2") != null) document.getElementById("_tdHelp2").onclick();
    MGT_ShowHelp(false);
}

function MGT_SubmitSearch()
{
    window.location.href = "/Marketgate/Apps/Search/Search.aspx?q=" + escape(document.getElementById('_txtMGTSearch').value);
    return false;
}

function MGTMenu_Hover(ListItem)
{   
    ListItem.className += " sfhover";
}
function MGTMenu_UnHover(ListItem)
{
    ListItem.className = ListItem.className.replace(new RegExp(" sfhover\\b"), "");
}

