function GetXmlHttpObject(handler) {
    var objXMLHttp = null;
    if (window.XMLHttpRequest) {
        objXMLHttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
}
function isValidEmail(jsEmailID) {
    jsEmailID = trim(jsEmailID);
    var reg = /^([A-Za-z0-9_\-\.\'])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    return reg.test(jsEmailID);
}
function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}
function LoadDynamicMenu(param) {
    xmlLoadWindow = GetXmlHttpObject();
    url = "/DynamicWindows/LoadWindow.aspx?window=" + param + "&sid=" + Math.random();
    xmlLoadWindow.onreadystatechange = LoadDynamicMenu2;
    xmlLoadWindow.open("GET", url, true);
    xmlLoadWindow.send(null);
}
function LoadDynamicMenu2() {
    if (xmlLoadWindow.readyState == 4 || xmlLoadWindow.readyState == "complete") {
        document.getElementById('divHomeAreaGENERIC').innerHTML = xmlLoadWindow.responseText;
        document.getElementById('divHomeAreaGENERIC').style.display = '';
    } 
}
function showHomeArea(area) {
    document.getElementById('divHomeAreaGENERIC').innerHTML = '';
    document.getElementById('divHomeAreaGENERIC').style.display = 'none';
    if (area != "") {
        LoadDynamicMenu(area);
    } 
}

function RefreshTemplateMenu(jsDivID) {
    RefreshTemplateMenu2(jsDivID, '');
}
function RefreshTemplateMenu2(jsDivID, jsParam1) {
    var strURLEnd = "param1=" + jsParam1 + "&path=" + window.location.pathname + "&sid=" + Math.random();
    if (jsDivID == "template-login") {
        xmlHttpM1 = GetXmlHttpObject();
        url = "/inc/template-loginmenu-request.aspx?" + strURLEnd;
        xmlHttpM1.onreadystatechange = RefreshTemplate1;
        xmlHttpM1.open("GET", url, true);
        xmlHttpM1.send(null);
    }
    if (jsDivID == "admin-menu") {
        xmlHttpM2 = GetXmlHttpObject();
        url = "/inc/template-adminmenu-request.aspx?" + strURLEnd;
        xmlHttpM2.onreadystatechange = RefreshTemplate2;
        xmlHttpM2.open("GET", url, true);
        xmlHttpM2.send(null);
    }
    if (jsDivID == "editorial-menu") {
        xmlHttpM3 = GetXmlHttpObject();
        url = "/inc/template-editorialmenu-request.aspx?edID=" + jsParam1 + "&sid=" + Math.random();
        xmlHttpM3.onreadystatechange = RefreshTemplate3;
        xmlHttpM3.open("GET", url, true);
        xmlHttpM3.send(null);
    }
    if (jsDivID == "company-menu") {
        xmlHttpM4 = GetXmlHttpObject();
        url = "/inc/template-companymenu-request.aspx?cid=" + jsParam1 + "&sid=" + Math.random();
        xmlHttpM4.onreadystatechange = RefreshTemplate4;
        xmlHttpM4.open("GET", url, true);
        xmlHttpM4.send(null);
    }
    if (jsDivID == "template-personalmenu") {
        xmlHttpM5 = GetXmlHttpObject();
        url = "/inc/template-PersonalMenu-request.aspx?" + strURLEnd;
        xmlHttpM5.onreadystatechange = RefreshTemplate5;
        xmlHttpM5.open("GET", url, true);
        xmlHttpM5.send(null);
    }
    if (jsDivID == "template-shoppingcart") {
        xmlHttpM6 = GetXmlHttpObject();
        url = "/inc/template-shopping-cart-get.aspx?" + strURLEnd;
        xmlHttpM6.onreadystatechange = RefreshTemplate6;
        xmlHttpM6.open("GET", url, true);
        xmlHttpM6.send(null);
    }
    if (jsDivID == "template-store") {
        xmlHttpM7 = GetXmlHttpObject();
        url = "/inc/template-store-get.aspx?" + strURLEnd;
        xmlHttpM7.onreadystatechange = RefreshTemplate7;
        xmlHttpM7.open("GET", url, true);
        xmlHttpM7.send(null);
    }
}
function RefreshTemplate1() {
    if (xmlHttpM1.readyState == 4 || xmlHttpM1.readyState == "complete") {
        if (document.getElementById("template-login") != null) {
            document.getElementById("template-login").innerHTML = xmlHttpM1.responseText;
        }
        jsFocusAfterMenuRefresh();
    } 
}
function RefreshTemplate2() {
    if (xmlHttpM2.readyState == 4 || xmlHttpM2.readyState == "complete") {
        if (document.getElementById("admin-menu") != null) {
            document.getElementById("admin-menu").style.display = "";
            document.getElementById("admin-menu").innerHTML = xmlHttpM2.responseText;
        }
        jsFocusAfterMenuRefresh();
    }
}
function RefreshTemplate3() {
    if (xmlHttpM3.readyState == 4 || xmlHttpM3.readyState == "complete") {
        document.getElementById("editorial-menu").style.display = "";
        document.getElementById("editorial-menu").innerHTML = xmlHttpM3.responseText;
    } 
}
function RefreshTemplate4() {
    if (xmlHttpM4.readyState == 4 || xmlHttpM4.readyState == "complete") {
        document.getElementById("company-menu").style.display = "";
        document.getElementById("company-menu").innerHTML = xmlHttpM4.responseText;
    } 
}
function RefreshTemplate5() {
    if (xmlHttpM5.readyState == 4 || xmlHttpM5.readyState == "complete") {
        document.getElementById("template-personalmenu").innerHTML = xmlHttpM5.responseText;
    }
}
function RefreshTemplate6() {
    if (xmlHttpM6.readyState == 4 || xmlHttpM6.readyState == "complete") {
        if (document.getElementById("shopping-cart") != null) {
            document.getElementById("shopping-cart").style.display = "";
            document.getElementById("shopping-cart").innerHTML = xmlHttpM6.responseText;
        }
    }
}
function RefreshTemplate7() {
    if (xmlHttpM7.readyState == 4 || xmlHttpM7.readyState == "complete") {
        document.getElementById("template-store").innerHTML = xmlHttpM7.responseText;
    }
}

jsSetFocusElementID = "";
function jsFocusAfterMenuRefresh() {
    if (jsSetFocusElementID != "") {
        if (document.getElementById(jsSetFocusElementID) != null) {
            jsSetFocus(jsSetFocusElementID);
            jsSetFocusElementID = "";
        }
    }
}

function RefreshTemplateLogin() {
    xmlHttpLogin = GetXmlHttpObject();
    url = "/inc/template-loginmenu-request.aspx?sid=" + Math.random();
    xmlHttpLogin.onreadystatechange = RefreshTemplateLogin2;
    xmlHttpLogin.open("GET", url, true);
    xmlHttpLogin.send(null);
}
function RefreshTemplateLogin2() {
    if (xmlHttpLogin.readyState == 4 || xmlHttpLogin.readyState == "complete") {
        varRequestChunk = xmlHttpLogin.responseText;
        document.getElementById('template-login').innerHTML = varRequestChunk;
    } 
}

function enableObject() {
    theObjects = document.getElementsByTagName("object");
    for (var i = 0; i < theObjects.length; i++) {
        theObjects[i].outerHTML = theObjects[i].outerHTML;
    } 
}

var jsCurrentMenuItem;
function jsLoadSubMenu(jsIndex, jsMenuSelect) {
    jsCurrentMenuItem = jsIndex;
    xmlHttp3x = GetXmlHttpObject();
    url = "/inc/LoadSubMenu.aspx?index=" + jsIndex + "&menuselect=" + jsMenuSelect + "&sid=" + Math.random();
    xmlHttp3x.onreadystatechange = jsLoadSubMenu2;
    xmlHttp3x.open("GET", url, true);
    xmlHttp3x.send(null);
}
function jsLoadSubMenu2() {
    if (xmlHttp3x.readyState == 4 || xmlHttp3x.readyState == "complete") {
        document.getElementById("menu-index" + jsCurrentMenuItem).innerHTML = xmlHttp3x.responseText;
    } 
}

function jsSetOnlineStatus(jsOnlineStatus) {
    xmlHttpLogin = GetXmlHttpObject();
    url = "/setOnlineStatus.aspx?set=" + jsOnlineStatus + "&sid=" + Math.random();
    xmlHttpLogin.onreadystatechange = jsSetOnlineStatus2;
    xmlHttpLogin.open("GET", url, true);
    xmlHttpLogin.send(null);
}
function jsSetOnlineStatus2() {
    if (xmlHttpLogin.readyState == 4 || xmlHttpLogin.readyState == "complete") {
        varRequestChunk = xmlHttpLogin.responseText;
        //RefreshTemplateLogin();
        //RefreshTemplateMenu2('admin-menu', '');

        RefreshTemplateMenu2('template-login', '');


        if (document.getElementById("spanMyProfile") != null) {
            if (varRequestChunk == "0") {
                document.getElementById(document.getElementById("spanMyProfile").value).innerHTML = "<a href=\"javascript: void(0);\" onclick=\"jsSetOnlineStatus('2');\"><img src=\"/images/OfflineImage.jpg\" border=\"0\" /></a>";
            }
            if (varRequestChunk == "2") {
                document.getElementById(document.getElementById("spanMyProfile").value).innerHTML = "<a href=\"javascript: void(0);\" onclick=\"jsSetOnlineStatus('0');\"><img src=\"/images/OnlineImage.jpg\" border=\"0\" /></a>";
            }
        }
        if (document.getElementById("chkPriv4") != null) {
            if (varRequestChunk == "0") {
                document.getElementById("chkPriv4").checked = false;
            }
            if (varRequestChunk == "2") {
                document.getElementById("chkPriv4").checked = true;
            }
        }
    } 
}
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') { window.onload = func; }
    else { window.onload = function () { oldonload(); func(); } } 
}
