// Global JavaScripts

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function extractSectionName(hrefString) {
    var arr = hrefString.split('/');
    return (arr.length < 5) ? (arr[3].substring(0, (arr[3].length - 5))).toLowerCase() : arr[3].toLowerCase();
}

function setActiveMenu(arr, crtPage) {
    for (var i = 0; i < arr.length; i++) {
    
        //alert(extractSectionName(arr[i].href) + ' ' + crtPage);
        if (extractSectionName(arr[i].href) == crtPage) {
            if (arr[i].parentNode.tagName != "DIV") {
                arr[i].className += " selected";
            }
        }
    }
}

function setNavOnStates() {
    hrefString = document.location.href ? document.location.href : document.location;

    if (document.getElementById("mainNav") != null)
        setActiveMenu(document.getElementById("mainNav").getElementsByTagName("a"), extractSectionName(hrefString));
    if (document.getElementById("auxNav") != null)
        setActiveMenu(document.getElementById("auxNav").getElementsByTagName("a"), extractSectionName(hrefString));
}

addLoadEvent(setNavOnStates);