var nameArray
var valueArray

//function to split querystring name/value pairs into two separate arrays for referencing
function getPairs()
{
        // if there is not a query string, do nothing. otherwise...
        if(top.location.href.indexOf("?")>=0)
        {
                // get entire querystring and split on "&" into both arrays(name, value)
                var thePairs = top.location.href.substring(top.location.href.indexOf("?")+1, top.location.href.length)
                nameArray = thePairs.split("&")
                valueArray = thePairs.split("&")
                
                // Strip each item in each array to only necessary part(name and value respectively)
                var i
                for(i=0; i<=nameArray.length-1; i++)
                {
                        
                        nameArray[i] = unescape(nameArray[i].substring(0, nameArray[i].indexOf("="))).toLowerCase()
                        valueArray[i] = unescape(valueArray[i].substring(valueArray[i].indexOf("=")+1, valueArray[i].length))
                }
        }
}

// function to allow referencing of querystring values by name
function queryString(varName)
{
        // if the nameArray has been initialized, there are values so...
        if(nameArray)
        {
                // check each name for one that matches what we are looking for
                var i
                for(i=0; i<=nameArray.length-1; i++)
                {
                        // if we find it, return the corresponding value
                        if(nameArray[i] == varName.toLowerCase())
                        {
                                return valueArray[i]
                        }
                }
                // if we get to this point, there were values, but not for what we were looking for so...
                return ""
        }
        // the nameArray was never initialized. there are no values, so return ""
        else
        {
                return ""
        }
}

// function to control opening and closing of menus
function toggleMenu(whichItem)
{
        // check for existence of the menu...
        // if it exists, check visibility and set to the opposite
        var theMenu = document.getElementById(whichItem);
        if(theMenu)
        {
                if(theMenu.style.display=="inline")
                {
                        theMenu.style.display="none";
                }
                else
                {
                        theMenu.style.display="inline";
                }        
        }
        
}

function setVisibility()
{
    var thePage = queryString("menucat");

    if (thePage == "") {
        try
        {
            thePage = defaultMenuLocation;
        }
        catch(e)
        {
            thePage = "";
        }
    }

    var thePage2 = thePage;
    var topLevel = thePage;
    var tempPage = ""

    if (thePage != "") {
        while (thePage != "") {
            tempPage = makeSel(thePage);
            thePage = getParent(thePage);
            if(tempPage != "")
            {
                topLevel = tempPage;
            }
        }
    }

    makeVis(topLevel, thePage2)


}

function makeSel(whichItem)
{
        // check for existence of the menu...
        // if it exists, check visibility and set to the opposite
        var theMenu = document.getElementById(whichItem);
        if(theMenu)
        {
                try{
                    theMenu.getElementsByTagName("a")[0].className="selected";

                }
                catch(e)
                {
                }



                return whichItem;
                
        }
        else
        {
            return "";
        }
        
}

function makeVis(topLevel, thePage)
{
        // check for existence of the menu...
        // if it exists, check visibility and set to the opposite
        
    
    
        var theMenu = document.getElementById(thePage);
        if(theMenu)
        {
            theMenu.style.display = "block";
        }

        try{

            while (thePage != "") {
            
                theMenu = document.getElementById(thePage);

                if(theMenu)
                {
                    
                    
                    var list = theMenu.getElementsByTagName("span");
                    for(i=0; i<list.length; i++)
                    {
                        if(getParent(list[i].id) == thePage)
                        {
                            list[i].style.display="block";
                        }
                        else
                        {
                        }
        
                    }
                }
                thePage = getParent(thePage);
                
            }

        }
        catch(e)
        {
            //alert(e.description);
        }

    
    
    
    
        /*
        //var theMenu = document.getElementById(topLevel);
        if(theMenu)
        {
            theMenu.style.display="inline";
            try{
                var list = theMenu.getElementsByTagName("span");
                //alert(list.length)
                for(i=0; i<list.length; i++)
                {
                    //alert(list[i].id);
                    
                    if((list[i].id.indexOf(topLevel) == 0) && (list[i].id.indexOf(thePage) == -1))
                    {
                        //alert(list[i].id + " - hello")
                        list[i].style.display="inline";
                    }
                    else
                    {
                        //alert(list[i].id + " - nope")
                    }
                    
                }

            }
            catch(e)
            {
                alert(e.description);
            }
                
        }
        */
        
}


function makeBold(whichItem)
{
        // check for existence of the menu...
        // if it exists, check visibility and set to the opposite
        var theItem = document.getElementById(whichItem + "_li");
        if(theItem)
        {
                theItem.style.listStyleType="disc";
        }
        
}



function getParent(which)
{
    
    var curIndex = which.lastIndexOf("_")

    if (curIndex > -1) {
        which = which.substring(0, curIndex);
        while (which.substring(which.length-1, which.length) == "_")
        {

            which = which.substring(0, which.length-1);

        }
    }
    else
    {
        which = "";
    }

    return which;
}

    
