﻿var intHideMenuTimeout = 0;
var strPrevIdList = "";

function HideElement(strElementID)
{
        objTableElement = document.getElementById("table_" + strElementID);
        objLinkElement = document.getElementById("link_" + strElementID);
        
        if (objTableElement)
            objTableElement.style.display = 'none';
            
        if (objLinkElement)
            objLinkElement.className = '';//highlight
}

function smenu(strIdList)
{
    if (intHideMenuTimeout > 0)
    {
        window.clearTimeout(intHideMenuTimeout);
        intHideMenuTimeout = 0
    }

    var arrayIDList = strIdList.split(',');
    var objElement;
    var strID;

    if (strPrevIdList != '')
    {
        var arrayPrevIDList = strPrevIdList.split(',');
        var strIDCheckString = ''
        
        for (var i=0; i<arrayIDList.length; i++)
        {
            strIDCheckString += '#' + arrayIDList[i] + '#';
        }
        //The following loop must work in this order, or it messes up IE7
        //It need to close sub-elements before their parents, or it leaves
        //artifacts behind
        for (var i=arrayPrevIDList.length-1; i>=0; i--)
        {
            if (strIDCheckString.indexOf('#' + arrayPrevIDList[i] + '#') == -1)
            {
                HideElement(arrayPrevIDList[i]);
            }
        }
    }
    
    strPrevIdList = strIdList;
    
    for (var i=0; i<arrayIDList.length; i++)
    {
        strID = arrayIDList[i];
        objTableElement = document.getElementById("table_" + strID);
        objLinkElement = document.getElementById("link_" + strID);
        
        if (objTableElement)
            objTableElement.style.display = 'block';
        if (objLinkElement)
            objLinkElement.className = 'highlight';
    }
}

function hmenu(strIdList)
{
    if (intHideMenuTimeout > 0)
    {
        window.clearTimeout(intHideMenuTimeout);
        intHideMenuTimeout = 0
    }
    intHideMenuTimeout = window.setTimeout("smenu('');",600);
}

