var wmContextPath;
var wmSecureMode = false;
var wmNonSecureURL;
var wmWebContextParams;

// Poor-man's attempt at synchronous ajax response processing
var wmEvalLock = false;
var wmEvalQueue = new Array();

function wmEval(jsToEval) {
    wmEvalQueue.push(jsToEval);
    wmEvalFromQueue();
}

function wmEvalFromQueue() {
    var jsToEval;
    if (wmEvalLock) {
        setTimeout('wmEvalFromQueue()',100);
        return;
    }
    wmEvalLock = true;
    while ((jsToEval = wmEvalQueue.shift())) {
        eval(jsToEval);
    }
    wmEvalLock = false;
}

function wmDownloadAndEval(url) {
    var request = false;
    try {
        request = new XMLHttpRequest();
    }
    catch (trymicrosoft) {
        try {
            request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (othermicrosoft) {
            try {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (failed) {
                request = false;
            }
        }
    }
    if (!request) {
        alert('Error initializing XMLHttpRequest!');
    }
    request.open('GET',url,true);
    request.onreadystatechange = function(){ wmAjaxCallback(request); };
    request.send(null);
}
    
function wmAjaxCallback(request) {
    if (request.readyState != 4) { return; }
    if (request.status != 200) { return; }
    if (request.responseText) {
        wmEval(request.responseText);
    }
}

var secureModePopupBlurbStart = '<table border=0 cellpadding=2 cellspacing=0 width=480><tr><td align="left"><p class="secureModeHeading">What is Secure Mode?</p><p class="secureMode">"Secure Mode" uses SSL digital server certificate technology to ensure the privacy of your interations with Weathermeister and to provide two-way data integrity. Whether you\'re entering personal and confidential data into a form on our web site, or simply getting a weather briefing, in Secure Mode you can feel confident that it is performed securely using an encrypted connection.  In addition, our digital server certificate demonstrates site authenticity, reducing the risk to you of dealing with an intentionally corrupt source of data.</p><p class="secureMode">Any time you access Weathermeister using a URL starting with "https://" (instead of just "http://"), you are in Secure Mode.</p><p class="secureMode">NOTE: Whenever you are entering profile info, payment info, or any sensitive data, Weathermeister will automatically enter Secure Mode, which will remain enabled unless you explicitly exit Secure Mode.</p><p>';
var secureModePopupBlurbEnd = '<font class="finePrint"><a href="" onclick="nd();nd();return false;">close</a></font></p></td></tr></table>';

function secureModePopup(backgroundColor, textColor, linkColor) {
    if (wmSecureMode) {
        overlib(secureModePopupBlurbStart +
                '<a href="' + wmNonSecureURL + '" onclick="nd();nd();return true;">Exit Secure Mode</a>&nbsp;&nbsp;&nbsp;' +
                secureModePopupBlurbEnd,
                STICKY,
                OFFSETX,-20,
                OFFSETY,20,
                BGCOLOR,linkColor,
                FGCOLOR,backgroundColor,
                TEXTCOLOR,textColor);
    }
    else {
        overlib(secureModePopupBlurbStart + secureModePopupBlurbEnd,
                OFFSETX,-20,
                OFFSETY,20,
                BGCOLOR,linkColor,
                FGCOLOR,backgroundColor,
                TEXTCOLOR,textColor);
    }
    return false;
}
