function showLoginForm(pStrPopUpTitle)
{
    var strUrl = "./jsp/showLoginForm.jsp";
    var strUrlParams = "action=&lang=" + strLang;

    // Create a new XML HTTP object for AJAX operation.
    var oTempXmlHttp = getNewXmlHTTPObject();

    // Process the AJAX request.
    if (!isXmlHTTPNull(oTempXmlHttp))
        doXMLRequest(oTempXmlHttp, strUrl, strUrlParams, "post", false, "application/x-www-form-urlencoded");

    // Show the popup div.
    var objDivLoginPopUp = createDivPopUp(pStrPopUpTitle, oTempXmlHttp.responseText, "divLoginPopUp", "popUpDefaultModal popUpLogin", true, true);

    oTempXmlHttp = null;

    // Position the div.
    centerObjectWithin(objDivLoginPopUp, (document.body || window));

    if (document.getElementById("txtUserID"))
        document.getElementById("txtUserID").focus();
}

function doLogout()
{
    var strUrl = "./jsp/processLogin.jsp";
    var strUrlParams = "action=out&lang=" + strLang;

    // Create a new XML HTTP object for AJAX operation.
    var oTempXmlHttp = getNewXmlHTTPObject();

    // Process the AJAX request.
    if (!isXmlHTTPNull(oTempXmlHttp))
    {
        logMsg("Processing logout. url: " + encodeURIComponent(strUrl + "?" + strUrlParams), "info", "login.js (doLogout)");
        doXMLRequest(oTempXmlHttp, strUrl, strUrlParams, "post", false, "application/x-www-form-urlencoded");
        logMsg("*** result: " + encodeURI(oTempXmlHttp.responseText), "info", "login.js (doLogout)");
    }

    // Get the response from the request.
    var strResult = oTempXmlHttp.responseText;

    // Get the response from the request.
    var strResult = oTempXmlHttp.responseText.split("|")[0];

    oTempXmlHttp = null;

    if (strResult == 1)
    {
        // Set the logged in status.
        boolLoggedIn = false;

        // If the user is viewing a custom map, change the map view to the default map.
        if (document.getElementById("rowMyMapsSubject_0"))
            if (document.getElementById("rowMyMapsSubject_0").className == "selected")
                changeMap(numDefaultMapID);

        // Reset the map hierarchy list.
        getHierarchy(numDefaultMapID, document.getElementById("divMapHierarchy"));

        // Hide the "My Maps" hierarchy.
        getMyMapsHierarchy(numMapID, document.getElementById('divMyMapsHierarchy'));

        // Show the "Login" link and hide the the "Logout" link
        document.getElementById("lnkLogin").style.display = "";
        document.getElementById("lnkLogout").style.display = "none";
        document.getElementById("divWelcomeMsg").style.display = "none";

        // Show the popup message div.
        createDivPopUpFade(strLogoutMsg, "divLoginMsgPopUp", "popUpLoginLogoutMsg", 1000, false);
    }
    boolFirstLogin = true;

    if ((document.getElementById("divDownload") != null) && (document.getElementById("divDownload") != undefined))
        showDownloadableLayers(document.getElementById("divDownload"),numMapID, objMap.getScale());
    showMyMapsSlider(document.getElementById("divMyMapsHierarchy"),numMapID, objMap.getScale());
}

function doLogin(pStrUserID, pStrPassword, pObjErrorMsg)
{
    boolFirstLogin = false;
    var strUrl = "./jsp/processLogin.jsp";
    var strUrlParams = "action=in&userID=" + pStrUserID + "&password=" + pStrPassword + "&lang=" + strLang;

    // Create a new XML HTTP object for AJAX operation.
    var oTempXmlHttp = getNewXmlHTTPObject();

    // Process the AJAX request.
    if (!isXmlHTTPNull(oTempXmlHttp))
    {
        logMsg("Processing login. url: " + encodeURIComponent(strUrl + "?" + strUrlParams), "info", "login.js (doLogin)");
        doXMLRequest(oTempXmlHttp, strUrl, strUrlParams, "post", false, "application/x-www-form-urlencoded");
        logMsg("*** result: " + encodeURI(oTempXmlHttp.responseText), "info", "login.js (doLogin)");
    }

    // Get the response from the request.
    var strResult = oTempXmlHttp.responseText.split("|")[0];
    var strWelcomeMsg = oTempXmlHttp.responseText.split("|")[1];

    oTempXmlHttp = null;

    if (strResult == 1)
    {
        // Perform a "refresh" of the page to display extra features (ie. My Maps).
        initializeLogin(strWelcomeMsg)

        // Verify if the user is saving the map.
        if (boolSavingMap)
        {
            // Process the save function after login.
            doSaveMap(numMapID);
        }

        closeLoginPopUp();
    }
    else
        pObjErrorMsg.style.display = "";

    showMyMapsSlider(document.getElementById("divMyMapsHierarchy"),numMapID, objMap.getScale());
}

function closeLoginPopUp()
{
    // Remove the div.
    removePopUp("divLoginPopUp");
}

function initializeLogin(pStrWelcomeMsg)
{
    // Set the logged in status.
    boolLoggedIn = true;

    // Display the "My Maps" hierarchy.
    getMyMapsHierarchy(numMapID, document.getElementById("divMyMapsHierarchy"));

    // Display the download section, if applicable.
    if ((document.getElementById("divDownload") != null) && (document.getElementById("divDownload") != undefined))
        showDownloadableLayers(document.getElementById("divDownload"),numMapID, objMap.getScale());

    // Hide the "Login" link and show the the "Logout" link
    document.getElementById("lnkLogin").style.display = "none";
    document.getElementById("lnkLogout").style.display = "";
    document.getElementById("divWelcomeMsg").style.display = "inline";

    // Display a welcome message.
    document.getElementById("divWelcomeMsg").innerHTML = pStrWelcomeMsg + " |";

    // Show the popup message div.
    createDivPopUpFade(strLoginMsg, "divLoginMsgPopUp", "popUpLoginLogoutMsg", 1000, false);
}
