﻿function ChangeMenuBack(menuNum, className) {
    var subMenuID = GetCookie("SMEN");
    if (subMenuID == menuNum) {
        return;
    }

    var td = document.getElementById(menuNum);
    td.className = className;
}

function ShowMenu(menuID) {
    // Hide all layers
    try {
    if (menuID == null) { menuID = "menuTD1"; }
    var layer = document.getElementById(menuID);
    var layers = document.getElementsByTagName('tr');
    for (var i = 0; i < layers.length; i++) {
        if (layers[i].id.substring(0, 4) == 'menu')
            layers[i].style.display = 'none';
    }
    layer.style.display = 'block';
    document.cookie = "MEN=" + menuID;
    }
    catch(Err) {
    }
}

function GetDefaultMenu() {
    // Split so we can get the page name.  All menu groups are id'd by the page name
    pathArray = document.location.pathname.split('/');
    pageURL = pathArray[pathArray.length - 1].toLowerCase().replace('_sp', '');
    if (pageURL == "") {
        pageURL = "default.aspx";
    }

    // Loop through only the TRs that surround the menu group
    var layers = document.getElementsByTagName('tr');
    var rowHead = '';
    for (var i = 0; i < layers.length; i++) {
        if (layers[i].className == 'SubMenuHeader') { // yep, this is a menu group header.  Save the ID because we'll need to expand the menu.
            rowHead = layers[i].id;
        }
        // Now loop through all the cells in the row looking for the one that matches our page name.
        var childlayers = layers[i].cells;
        for (var x=0; x< childlayers.length; x++) {
            if (childlayers[x].id == pageURL) {  // Here's our cell.  Expand the group/TR for this menu group
                ShowMenu(rowHead);
            }
        }
    }
    // Now highlight the submenu item so it shows as selected
    var td = document.getElementById(pageURL);
    try {
        td.className = "SideMenuAltSelected";
    }
    catch (Err) {
    }
    SaveSubMenu(pageURL);
}

function SaveSubMenu(menuID) {
    document.cookie = "SMEN=" + menuID;
}

function GetCookie(cookieName) {
    var results = document.cookie.match('(^|;) ?' + cookieName + '=([^;]*)(;|$)');

    if (results)
        return (unescape(results[2]));
    else
        return null;
}

