﻿var menu = new Object();

menu.noOp = function() { return false; }

menu.initialize = function(id, currentView, callbackScript) {
    menu.menuId = id;
    menu.currentView = currentView;
    menu.callbackScript = callbackScript;
}

menu.replaceInsert = function(source, replace, insert) {
    var ndx = source.indexOf(replace);
    if (ndx >= 0) {
        var s1 = source.substr(0, ndx);
        var s2 = source.substr(ndx + replace.length);
        source = s1 + insert + s2;
    }
    return source;
}

menu.loadContent = function(pagePath, force) {
    if (force == null) force = false;
    if (!force && (menu.currentView == pagePath)) return;
    var script = menu.callbackScript.replace(/page_path/, pagePath);
    eval(script);
    menu.currentView = pagePath;
}

menu.logoutMember = function() {
    var isLogout = document.getElementById('_isLogout');
    isLogout.value = 'true';
    menu.loadContent('Members/Login', true);
}

menu.setBackground = function(id, bkg) {
    var container = document.getElementById(id);
    container.attributes['background'].value = bkg;
}

menu.setLinkClass = function(publicClass, bannerClass, memberClass, plainClass) {
    var mnu = document.getElementById(menu.menuId);
    try {
        for (var i = 0; i < mnu.children.length; ++i) {
            var lnk = mnu.children[i];
            if (lnk.tagName == 'A') {
                switch (lnk.atype) {
                    case 'Public':
                        lnk.className = publicClass;
                        break;
                    case 'Banner':
                        lnk.className = bannerClass;
                        break;
                    case 'Member':
                        lnk.className = memberClass;
                        break;
                }
            }
            if ((lnk.tagName == 'SPAN') && (lnk.atype == 'Parent')) {
                lnk.className = plainClass;
            }
        }
    }
    catch (err) { }
}

menu.setPageBackgroundColor = function(color) {
    document.getElementById('page_body').style.background = color;
    document.getElementById('rcs__leftPanel').style.background = color;
    document.getElementById('rcs_rightPanel').style.background = color;
}
