﻿/// <reference name="MicrosoftAjax.js" />
var mobjLastAdded_endRequestHandler = null;
var mstrApplicationPath = "/";

function HideDocScrollBars() {
    document.documentElement.style.overflow = 'hidden';
}

function ShowDocScrollBars() {
    document.documentElement.style.overflow = 'auto';
}

function SetApplicationPath(strPath) {
    mstrApplicationPath = strPath;
}

function GetApplicationPath() {
    return (mstrApplicationPath + "/").toString().replace("//","/");
}

function Do_AsyncPostBack(eventName, eventArgs, optional_onPostBackEndHandler) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    if (!Array.contains(prm._asyncPostBackControlIDs, eventName)) {
        prm._asyncPostBackControlIDs.push(eventName);
    }

    if (!Array.contains(prm._asyncPostBackControlClientIDs, eventName)) {
        prm._asyncPostBackControlClientIDs.push(eventName);
    }

    __doPostBack(eventName, eventArgs);

    try {
        if (mobjLastAdded_endRequestHandler != null) {
            prm.remove_endRequest(mobjLastAdded_endRequestHandler);
        }
    } catch (e) { }

    if (optional_onPostBackEndHandler != null) {
        mobjLastAdded_endRequestHandler = optional_onPostBackEndHandler;
        prm.add_endRequest(optional_onPostBackEndHandler);
    }
}


function Do_StandaloneAsyncPostBack(strMethod, strUrl, objOnPostbackHandler)
{
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if (objOnPostbackHandler && objOnPostbackHandler != null) {
                objOnPostbackHandler(xmlhttp.responseText);
            }
            //document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open(strMethod, strUrl, true);
    xmlhttp.send();
}

function Do_AsyncPostBackWithNodeHTML(strId, optional_onPostBackEndHandler) {
    Do_AsyncPostBack("SubmitWithHTML", encodeURIComponent(document.getElementById(strId).innerHTML));
}

function LoadXMLDoc(fileName) {
    var xmlDoc;
    // code for IE
    if (window.ActiveXObject) {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument) {
        xmlDoc = document.implementation.createDocument("", "", null);
    }
    else {
        alert('Your browser cannot handle this script');
    }
    xmlDoc.async = false;
    xmlDoc.load(fileName);


    return (xmlDoc);
}

function LoadFileContent(fname, bolWrite) {
    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
    }
    else {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhttp.open("GET", fname + (fname.toString().indexOf("?") > -1 ? "&" : "?") + "gid=" + GetStringDate(), false);
    xhttp.send("");
    
    var strStr = xhttp.responseText;
    var intBodyIndex = -1
    var str = "";

    
    if (String(strStr).toString().toLowerCase().search("</body>") > -1) {
        intBodyIndex = String(strStr).toLowerCase().search("</head>") + "</head>".length;
        strStr = String(strStr).substring(String(strStr).indexOf(">", intBodyIndex) + 1, String(strStr).toString().toLowerCase().search("</body>"));
    }
    
    if (bolWrite) {
        document.write(strStr);
    }
    return strStr;
}

function GetQueryString(strRequestedQueryStringKey) {
    var strLoc = document.URL.toString();
    var strReturnQueryStringValue = "";
    var strLocQueryStrings = "";
    var arySplitQueryStrings = null;
    var arySplitQueryStringKeyFromValue = null;
    
    try {
        strLocQueryStrings = strLoc.split("?")[1].toString();
    }
    catch (e) {
        strLocQueryStrings = "";
    }
    if (strLocQueryStrings != "") {
        try {
            arySplitQueryStrings = strLocQueryStrings.split("&");
            //arySplitQueryStrings = strLocQueryStrings.split("&");
        }
        catch (e) {
            arySplitQueryStrings = null;
        }
        if (arySplitQueryStrings == null) {
            strReturnQueryStringValue = strLocQueryStrings.split("=")[1];
        }
        else {
            for (var x = 0; x <= arySplitQueryStrings.length - 1; x++) {
                arySplitQueryStringKeyFromValue = arySplitQueryStrings[x].split("=");
                if (arySplitQueryStringKeyFromValue[0].toString() == strRequestedQueryStringKey) {
                    strReturnQueryStringValue = arySplitQueryStringKeyFromValue[1].toString();
                }
            }
        }
    }
    else {
        strReturnQueryStringValue = "";
    }
    return strReturnQueryStringValue;
}

function GetClientWidth() {
    var intClientWidth = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        intClientWidth = window.innerWidth;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        intClientWidth = document.documentElement.clientWidth;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        intClientWidth = document.body.clientWidth;
    }
    return intClientWidth
}

function GetClientHeight() {
    var intClientHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        intClientHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        intClientHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        intClientHeight = document.body.clientHeight;
    }
    return intClientHeight
}

function GetElementsByClassName(elementToSearch, strTag, strClassName) {
    if (elementToSearch) {
        this.Items = elementToSearch.getElementsByTagName(strTag.toUpperCase());
        this.retElms = [];
        if (this.Items.length > 0) {
            for (var x = 0; x <= this.Items.length - 1; x++) {
                try {
                    if (this.Items[x].className != strClassName) { continue; }
                } catch (e) { continue; }
                this.retElms.push(this.Items[x]);
            }
        }
        return this.retElms;
    }
}
function GetElementsByClassNamePrefix(elementToSearch, strTag, strClassNamePrefix) {
    if (elementToSearch) {
        this.Items = elementToSearch.getElementsByTagName(strTag.toUpperCase());
        this.retElms = [];
        if (this.Items.length > 0) {
            for (var x = 0; x <= this.Items.length - 1; x++) {
                try {
                    if (!String(this.Items[x].className).toString().toLowerCase().startsWith(strClassNamePrefix.toString().toLowerCase())) {
                        continue;
                    }
                } catch(e){ continue; }
                this.retElms.push(this.Items[x]);
            }
        }
        return this.retElms;
    }
}
function GetElementsByClassNameSuffix(elementToSearch, strTag, strClassNameSuffix) {
    if (elementToSearch) {
        this.Items = elementToSearch.getElementsByTagName(strTag.toUpperCase());
        this.retElms = [];
        if (this.Items.length > 0) {
            for (var x = 0; x <= this.Items.length - 1; x++) {
                try {
                    if (!String(this.Items[x].className).toString().toLowerCase().endsWith(strClassNameSuffix.toString().toLowerCase())) {
                        continue;
                    }
                } catch (e) { continue; }
                this.retElms.push(this.Items[x]);
            }
        }
        return this.retElms;
    }
}

function IsMoz() {
    return (navigator.appName.toLowerCase().indexOf('netscape') > -1 || navigator.appName.toLowerCase().indexOf('firefox') > -1 || navigator.appName.toLowerCase().indexOf('moz') > -1);
}

//Runs parsed javascript code
function RunCodeBlock(strStr) {
    if (navigator.appName.toLowerCase().indexOf('netscape') > -1 || navigator.appName.toLowerCase().indexOf('firefox') > -1 || navigator.appName.toLowerCase().indexOf('moz') > -1) {
        tempSpt = document.createElement('SPAN');
        strStr = "<SCRIPT type=\"text/javascript\">function runCode(){" + strStr + "}</SCRIPT>";
        tempSpt.innerHTML = strStr;
        AppendToBody(tempSpt);
        runCode();
        GetBody().removeChild(tempSpt);
        tempSpt = null;
    }
    else {
        var func = new Function(strStr);
        func();
    }    
}
function SetStyleForTagsOf(elementToSearch, strTag, arrStyleKeysAndValues) {
    if (elementToSearch) {
        this.Items = elementToSearch.getElementsByTagName(strTag.toUpperCase());
        if (this.Items.length > 0) {
            for (var x = 0; x <= this.Items.length - 1; x++) {
                try {
                    for (var x2 = 0; x2 <= arrStyleKeysAndValues.length - 1; x2++) {
                        this.Items[x].style[arrStyleKeysAndValues[x2][0]] = arrStyleKeysAndValues[x2][1];
                    }
                }
                catch (e) {
                }
            }
        }
    }
}

function SetStyleForTagsWithClassNameOf(elementToSearch, strTag, strClassName, arrStyleKeysAndValues) {
    if (elementToSearch) {
        this.Items = elementToSearch.getElementsByTagName(strTag.toUpperCase());
        if (this.Items.length > 0) {
            for (var x = 0; x <= this.Items.length - 1; x++) {
                try {
                    if (this.Items[x].className != strClassName) { continue; }
                } catch (e) { continue; }
                try {
                    for (var x2 = 0; x2 <= arrStyleKeysAndValues.length - 1; x2++) {
                        this.Items[x].style[arrStyleKeysAndValues[x2][0]] = arrStyleKeysAndValues[x2][1];
                    }
                }
                catch (e) {
                }
            }
        }
    }
}

function SetStyleForTagsWithClassNamePrefix(elementToSearch, strTag, strClassNamePrefix, arrStyleKeysAndValues) {
    if (elementToSearch) {        
        this.Items = elementToSearch.getElementsByTagName(strTag.toUpperCase());
        if (this.Items.length > 0) {
            for (var x = 0; x <= this.Items.length - 1; x++) {
                try {
                    if (!String(this.Items[x].className).toString().toLowerCase().startsWith(strClassNamePrefix.toString().toLowerCase())) {
                        continue;
                    }
                } catch (e) { continue; }
                try {
                    for (var x2 = 0; x2 <= arrStyleKeysAndValues.length - 1; x2++) {
                        this.Items[x].style[arrStyleKeysAndValues[x2][0]] = arrStyleKeysAndValues[x2][1];
                    }
                }
                catch (e) {
                }
            }
        }
    }
}

function SetStyleForTagsWithClassNameSuffix(elementToSearch, strTag, strClassNameSuffix, arrStyleKeysAndValues) {
    if (elementToSearch) {
        this.Items = elementToSearch.getElementsByTagName(strTag.toUpperCase());
        if (this.Items.length > 0) {
            for (var x = 0; x <= this.Items.length - 1; x++) {
                try {
                    if (!String(this.Items[x].className).toString().toLowerCase().endsWith(strClassNameSuffix.toString().toLowerCase())) {
                        continue;
                    }
                } catch (e) { continue; }
                try {
                    for (var x2 = 0; x2 <= arrStyleKeysAndValues.length - 1; x2++) {
                        this.Items[x].style[arrStyleKeysAndValues[x2][0]] = arrStyleKeysAndValues[x2][1];
                    }
                }
                catch (e) {
                }
            }
        }
    }
}

function AppendToBody(elm) {
    GetBody().appendChild(elm);
}

function GetBody(target) {
    if (IsMoz() == true) {
        return (!!target ? target.document.documentElement.getElementsByTagName("BODY").item(0) : document.documentElement.getElementsByTagName("BODY").item(0));
    }
    else {
        return (!!target ? target.document.body : document.body);
    }
}

function GetScrollLeft() {
    return (document.documentElement ? document.documentElement.scrollLeft : GetBody().scrollLeft);
}

function GetScrollTop() {
    if (document.documentElement) {
        return document.documentElement.scrollTop;
    }
    else {
        return GetBody().scrollTop;
    }
}

function GetStringDate() {
    var dat = new Date();    
    return String(dat.getMonth()) + String(dat.getDay()) + String(dat.getFullYear()) + String(dat.getHours()) + String(dat.getMinutes()) + String(dat.getSeconds()) + String(dat.getMilliseconds());
}

//Overlay and Popup Functions ----------------------------------------------------------------------------------------
var marrPopupParams = null;

function ShowDialog(strURL, width, height, bolAutoSetLocation) {
    var mainIFrame = document.getElementById('ifrmMain');
    var bolNoMaster = false;

    mainIFrame.src = strURL;

    if (width) {
        if (!isNaN(width)) {
            mainIFrame.width = String(width) + 'px';
        }
    }
    if (height) {
        if (!isNaN(height)) {
            mainIFrame.height = String(height) + 'px';
        }
    }
    try {
        if (!mbolIsMaster) {
            bolNoMaster = true;
        }
    }
    catch (e) {
        bolNoMaster = true;
    }

    ShowOverlay('divOverlay');
    var intClientHeight = GetClientHeight();
    var intClientWidth = GetClientWidth();
    if (bolAutoSetLocation && bolAutoSetLocation == true) {
        mainIFrame.style.display = 'block';
        mainIFrame.style.top = String((intClientHeight / 2) - ((height + 30) / 2)) + 'px';
        mainIFrame.style.left = String((intClientWidth / 2) - ((width + 30) / 2)) + 'px';
    }
}

function CloseDialog(bolNoResetParentSize) {
    HideOverlay('divOverlay', "ifrmMain");
    if (!bolNoResetParentSize) { try { ClearIFrame(); } catch (x) { } }
    try {document.getElementById("ifrmMain").src = "../BlankPage.htm"; } catch (e) { }
}

function SetDialogWindowState(windowState, elm) {
    var ifmMain = parent.document.getElementById('ifrmMain');
    var prnt = window;
    var testParnt = window;
    
    if (windowState == 1) {
        ifmMain.style.top = '0px';
        ifmMain.style.left = '0px';
        //ifmMain.style.width = '100%';

        if (!IsMater()) {
            try {
                while (testParnt.IsMater() == false && (testParnt != null) && (typeof (testParnt) != 'undefined')) {
                    try {
                        testParnt = testParnt.parent;
                        prnt = testParnt;
                    } catch (e) {
                        testParnt = null;
                    }
                }
            } catch (e) { 
            
            }
        }

        var intWidth = prnt.GetClientWidth();
        var intHeight = prnt.GetClientHeight();
        
        ifmMain.style.width = String(intWidth) + 'px';
        ifmMain.style.height = String(intHeight) + 'px';

        elm.previousSibling.style.display = 'block';
        elm.style.display = 'none';

        if (this['ResizeComponentItems'] != null) {
            this['ResizeComponentItems'](intHeight);
        }

    } else {

        SetPopupSizeRecursive(marrPopupParams.Width, marrPopupParams.Height, true);
        elm.nextSibling.style.display = 'block';
        elm.style.display = 'none';

        if (this['ResizeComponentItems'] != null) {
            this['ResizeComponentItems'](marrPopupParams.Height);
        }
    }
}
function ShowOverlay(overlayId, displayNode) {
    var intClientHeight = GetClientHeight();
    
    if (overlayId == "") {overlayId == 'divOverlay'; }

    var divOverlay = document.getElementById(overlayId);
    var intClientHeight = GetClientHeight();

    if (divOverlay == null) {
        return;
    }
    
    if (!IsMater()) {
        divOverlay.style.height = String(intClientHeight > GetBody().offsetHeight ? intClientHeight : GetBody().offsetHeight) + 'px';
    }
    else {
        divOverlay.style.height = String(intClientHeight > GetBody().offsetHeight ? intClientHeight : GetBody().offsetHeight) + 'px';
    }

    divOverlay.style.top = '0px';
    divOverlay.style.display = 'block';

    if (displayNode && displayNode != null) {
        if (displayNode.parentNode != divOverlay) {
            divOverlay.appendChild(displayNode);
        }
        displayNode.style.position = 'absolute';
        displayNode.style.visibility = 'hidden';
        displayNode.style.display = 'block';
        displayNode.style.top = String(GetScrollTop() + ((intClientHeight / 2) - ((displayNode.offsetHeight) / 2))) + 'px';
        var intLeft = String(GetScrollLeft() + ((GetClientWidth() / 2) - ((displayNode.offsetWidth) / 2)));
        displayNode.style.left = String(GetScrollLeft() + ((GetClientWidth() / 2) - ((displayNode.offsetWidth) / 2))) + 'px';
        displayNode.style.visibility = '';
    }
    if (!displayNode || displayNode == null) {
        try { displayNode = divOverlay.childNodes[0]; } catch (e) { displayNode = null; }
    }
    if (displayNode && displayNode != null && IsMater()) {
        try {
            window.onresize = function() { ResizeOverlayComponents(overlayId, displayNode.id); };
        }
        catch (e) { }
    }
}

function ResizeOverlayComponents(overlayId, displayNodeId) {
    var intClientHeight = GetClientHeight();
    var displayNode = document.getElementById(displayNodeId);
    
    if (overlayId == "") { overlayId == 'divOverlay'; }

    var divOverlay = document.getElementById(overlayId);
    var intClientHeight = GetClientHeight();

    if (divOverlay == null) {
        return;
    }

    if (!IsMater()) {
        divOverlay.style.height = String(intClientHeight > GetBody().offsetHeight ? intClientHeight : GetBody().offsetHeight) + 'px';
    }
    else {
        divOverlay.style.height = String(intClientHeight > GetBody().offsetHeight ? intClientHeight : GetBody().offsetHeight) + 'px';
    }

    divOverlay.style.top = '0px';

    if (displayNode && displayNode != null) {
        displayNode.style.top = String(GetScrollTop() + ((intClientHeight / 2) - ((displayNode.offsetHeight) / 2))) + 'px';
        displayNode.style.left = String(GetScrollLeft() + ((GetClientWidth() / 2) - ((displayNode.offsetWidth) / 2))) + 'px';
    }
}

function HideOverlay(overlayId, childNodeId) {
    try { document.getElementById(overlayId).style.display = 'none'; } catch (e) { }
    try { document.getElementById(childNodeId).style.display = 'none'; } catch (e) { }
    window.onresize = null;
}

function ClearIFrame() {
    try {
        SetPopupSizeRecursive(marrPopupParams.Width, marrPopupParams.Height, true);
    } catch (x) {
        //
}
    
}

function ShowWaitOverlayDiv(strTextNodeId, msg) {
    var objTextDiv = null;

    if (strTextNodeId != null && strTextNodeId != "") {
        objTextDiv = document.getElementById(strTextNodeId);
        if (msg != "") { objTextDiv.innerHTML = msg; }
    }
    else {
        var strDefaultId = "";
        try { divOverlay.removeChild(document.getElementById(strDefaultId)); } catch (e) { }
        objTextDiv.innerHTML = "<div style=\"width:400px; height:200px; border:solid 1px #ffffff; background-color:gray;\"><br /><br /><br /><h2>" + msg + " ...<br />Please Be Patient</h2></div>";
        objTextDiv = document.createElement("DIV");
        objTextDiv.setAttribute("Id", strDefaultId);
    }

    ShowOverlay('divOverlay', objTextDiv);
} 

function SetPopupSizeRecursive(intWidth, intHeight, bolReverse) {
    try {
        if (mbolIsMaster != null) {
            return false;
        }
    }
    catch (e) {
        //
    }
    var objIfrm = parent.document.getElementById("ifrmMain");
    
    RecordDefaultPopupSize(intWidth, intHeight);

    try {
        if (intHeight > parent.GetClientHeight() || intWidth > parent.GetClientWidth() || bolReverse) {
            parent.SetPopupSizeRecursive(intWidth, intHeight, bolReverse);
        }
    } catch (e) { }
    
    var intTop = parseInt((parent.GetClientHeight() / 2) - ((intHeight + 15) / 2));
    var intLeft = parseInt((parent.GetClientWidth() / 2) - ((intWidth + 15) / 2));
    if (intTop < 0) { intTop = 0; }
    if (intLeft < 0) { intLeft = 0; }
    objIfrm.style.top = String(intTop) + 'px';
    objIfrm.style.left = String(intLeft) + 'px';

    objIfrm.style.width = String(intWidth) + 'px';
    objIfrm.style.height = String(intHeight) + 'px';
}

function SetPopupSizeNonRecursive(intWidth, intHeight) {
    try {
        if (mbolIsMaster != null) {
            return false;
        }
    }
    catch (e) {
        //
    }
    var objIfrm = parent.document.getElementById("ifrmMain");

    objIfrm.width = String(intWidth + 30) + 'px';
    objIfrm.height = String(intHeight + 30) + 'px';

    objIfrm.style.top = String((parent.GetClientHeight() / 2) - ((intHeight + 15) / 2)) + 'px';
    objIfrm.style.left = String((parent.GetClientWidth() / 2) - ((intWidth + 15) / 2)) + 'px';
}

function SetDefaultPopupSize() {
    var objIfrm = parent.document.getElementById("ifrmMain");
    var intWidth = marrPopupParams.Width;
    var intHeight = marrPopupParams.Height;

    try {
        objIfrm.width = String(intWidth) + 'px';
        objIfrm.height = String(intHeight) + 'px';
        objIfrm.style.top = String((parent.GetClientHeight() / 2) - ((intHeight + 15) / 2)) + 'px';
        objIfrm.style.left = String((parent.GetClientWidth() / 2) - ((intWidth + 15) / 2)) + 'px';
    } catch (e) { }
}

function RecordDefaultPopupSize(intWidth, intHeight) {
    if (marrPopupParams == null) {
        marrPopupParams = { Width: intWidth, Height: intHeight};
    }
}


function IsMater() {
    var bolNoMaster = false;

    try {
        if (!mbolIsMaster) {
            bolNoMaster = true;
        }
    }
    catch (e) {
        bolNoMaster = true;
    }
    return !bolNoMaster;
}
//END Overlay and Popup Functions ------------------------------------------------------------------------------------

//MENU FUNCTIONS -----------------------------------------------------------------------------------------------------
function MouseEv(elm) {
    if (elm.getElementsByTagName('UL').length > 0) {
        elm.getElementsByTagName('UL').item(0).style.display = '';
        if (elm.getElementsByTagName('UL').item(0).getElementsByTagName('UL').length > 0) {
            var aryUls = elm.getElementsByTagName('UL').item(0).getElementsByTagName('UL');
            for (var x = 0; x <= aryUls.length - 1; x++) {
                aryUls[x].style.display = '';
            }
        }
    }
    return false;
}

function ShowFlyoutMenu(elm) {
    var elmParent = elm.parentNode;
    var ulElm = elmParent.getElementsByTagName('UL')[0];
    showAllChildrensChildren(ulElm);
}

function showAllChildrensChildren(elm) {
    elm.style.display = 'block';
    elm.style.width = '200px';
    if (elm.childNodes.length > 0) {
        for (var x = 0; x <= elm.childNodes.length - 1; x++) {
            switch (String(elm.childNodes[x].nodeName).toLowerCase()) {
                case '#text':
                    break;
                case '#comment':
                    break;
                default:
                    showAllChildrensChildren(elm.childNodes[x]);
                    break;
            }
        }
    }
}

function HideFlyout(li) {
    var ul = li.getElementsByTagName('UL').item(0);

    ul.style.display = 'none';
}
//END MENU FUNCTIONS -------------------------------------------------------------------------------------------------

// COOKIES
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
function checkCookie(cookieName) {
    username = getCookie(cookieName);
    if (username != null && username != "") {
        return true;
        //alert('Welcome again ' + username + '!');
    }
    else {
        //username = prompt('Please enter your name:', "");
        //        if (username != null && username != "") {
        //            setCookie('username', username, 365);
        //        }
        return false;
    }
}

function downloadJsFile(path, onreadystatechangeHandler, params) {
    var arrScripts = document.getElementsByTagName('SCRIPT');
    var objNewScript = null;
    var bolScriptExists = false;

    for (var x = 0; x <= arrScripts.length - 1; x++) {
        if (arrScripts[x].src != null) {
            if (String(arrScripts[x].src).toLowerCase().indexOf(String(path).toLowerCase()) > -1) {
                bolScriptExists = true;
                break;
            }
        }
    }
    if (bolScriptExists == false) {
        var objScriptDownloading = document.createElement('SCRIPT');
        objScriptDownloading.setAttribute("type", "text/javascript");
        objScriptDownloading.src = path;
        AppendToBody(objScriptDownloading);
        if (onreadystatechangeHandler != null) {
            objScriptDownloading.onreadystatechange = function() {
                switch (objScriptDownloading.readyState) {
                    case "loaded":
                        {
                            onreadystatechangeHandler(params);
                            break;
                        }
                    case "complete":
                        {
                            onreadystatechangeHandler(params);
                            break;
                        }
                    case 4:
                        {
                            onreadystatechangeHandler(params);
                            break;
                        }
                }
            }
        }
    }
}

function SwapSrc(objSender, strImgKey, bolRevert) {
    if (bolRevert) {
        objSender.src = mobjPreloadedImages[strImgKey].SrcImg.src;
    }
    else {
        if (mobjPreloadedImages[strImgKey].SrcImg == null) {
            mobjPreloadedImages[strImgKey].SrcImg = objSender.cloneNode(true);
        }
        objSender.src = mobjPreloadedImages[strImgKey].OverImg.src;
    }
}

function ShowHideWatermarkLabel(element, e, label) {
    var t = e.type.toString().toLowerCase();
    switch (e.type.toString().toLowerCase()) {
        case "blur":
            {
                if (element.value == "") {
                    element.value = label;
                    element.style.fontStyle = 'italic';
                    element.style.width = "200px";
                }
                break;
            }
        default:
            {
                if (element.value == label) {
                    element.value = "";
                    element.style.fontStyle = 'normal';
                    element.style.width = "200px";
                }
                break;
            }
    }
}

function GetFirstChild(node) {
    if (node.firstChild.nodeName == '#text') {
        try {
            return node.childNodes[1];
        } catch (e) { return node.firstChild; }
    } else
        return node.firstChild;
}

function GetLastChild(node) {
    if (node.lastChild.nodeName == '#text') {
        try {
            return node.childNodes[node.childNodes.length - 2];
        } catch (e) { return node.lastChild; }
    } else
        return node.lastChild;
}
