﻿var selectedLink;
var oldClassName;
function setSelectedSubmenu() {
    smDiv = document.getElementById('submenutext');
    if (smDiv) {
        p = location.pathname;
        if (p[0] != '/') { p = '/' + p; }
        links = smDiv.getElementsByTagName('a');
        for (i = 0; i < links.length; i++) {
            link = links[i];
            if (link.getAttribute('href').indexOf(p) >= 0) {
                oldClassName = link.className;
                link.className = link.className + ' selected';
                selectedLink = link;
            }
            link.setAttribute('onmouseover', 'submenuOnMouseOver()');
            link.setAttribute('onmouseout', 'submenuOnMouseOut()');
        }
    }
    icDiv = document.getElementById('submenu');
    if (icDiv) {
        p = location.pathname;
        if (p[0] != '/') { p = '/' + p; }
        links = icDiv.getElementsByTagName('a');
        for (i = 0; i < links.length; i++) {
            link = links[i];
            link.setAttribute('onmouseover', 'submenuIconOnMouseOver(this)');
            link.setAttribute('onmouseout', 'submenuIconOnMouseOut(this)');
        }
    }
}

function submenuIconOnMouseOver(anchor) {
    links = document.getElementById('submenutext').getElementsByTagName('a');
    for (i = 0; i < links.length; i++) {
        link = links[i];
        if (link.getAttribute('href') == anchor.getAttribute('href')) {
            link.className = link.className + ' selected';
        } else {
            link.className = link.className.replace('selected', '');
        }
    }
}

function submenuIconOnMouseOut() {
    links = document.getElementById('submenutext').getElementsByTagName('a');
    for (i = 0; i < links.length; i++) {
        link = links[i];
        link.className = link.className.replace('selected', '');
    }
    if (selectedLink) {
        selectedLink.className = oldClassName + ' selected';
    }
}

function submenuOnMouseOver() {
    if (selectedLink) { 
        selectedLink.className = oldClassName;
    }
}
function submenuOnMouseOut() {
    if (selectedLink) {
        selectedLink.className = oldClassName + ' selected';
    }
}

function blockNonNumbers(obj, e) {

    var key;
    var keychar;

    if (window.event) {
        key = window.event.keyCode;
    }
    else if (e) {
        key = e.which;
    }
    else {
        return true;
    }
    keychar = String.fromCharCode(key);

    // control keys
    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27)) {
        return true;
    }

    // numbers
    else if ((("0123456789").indexOf(keychar) > -1)) {
        return true;
    }
    return false;
}

function trimString(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
} 

