function showRegisterForm(pStrPopUpTitle)
{
    var strUrl = "./jsp/showRegisterForm.jsp";
    var strUrlParams = "lang=" + strLang;

    closeLoginPopUp();

    // 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 objDivRegisterPopUp = createDivPopUp(pStrPopUpTitle, oTempXmlHttp.responseText, "divRegisterPopUp", "popUpDefaultModal popUpRegister", true, true);

    oTempXmlHttp = null;

    // Position the div.
    centerObjectWithin(objDivRegisterPopUp, (document.body || window));

    if (document.getElementById("txtNewUserID"))
        document.getElementById("txtNewUserID").focus();
}

function doRegister(pStrUserID, pStrPassword, pStrFullName, pStrEmail, pStrErrorNoUserID, pStrErrorNoPassword, pStrErrorNoEmail, pObjErrorMsg)
{
    // Validate the fields before processing to ensure that all the appropriate fields are entered.
    if (pStrUserID.trim().length == 0)
    {
            pObjErrorMsg.innerHTML = pStrErrorNoUserID;
            pObjErrorMsg.style.display = "";
    }
    else if (pStrPassword.trim().length == 0)
    {
            pObjErrorMsg.innerHTML = pStrErrorNoPassword;
            pObjErrorMsg.style.display = "";
    }
    else if (pStrEmail.trim().length == 0)
    {
                pObjErrorMsg.innerHTML = pStrErrorNoEmail;
                pObjErrorMsg.style.display = "";
    }
    else
        pObjErrorMsg.style.display = "none";

    // If no error message visible, register the new user.
    if (pObjErrorMsg.style.display.toUpperCase() == "NONE")
    {
        var strUrl = "./jsp/processRegister.jsp";
        var strUrlParams = "userID=" + pStrUserID.trim() + "&password=" + pStrPassword.trim() + "&fullName=" + pStrFullName.trim() + "&email=" + pStrEmail.trim() + "&lang=" + strLang;

        // Create a new XML HTTP object for AJAX operation.
        var oTempXmlHttp = getNewXmlHTTPObject();

        // Process the AJAX request.
        if (!isXmlHTTPNull(oTempXmlHttp))
        {
            logMsg("Processing new registration. url: " + encodeURIComponent(strUrl + "?" + strUrlParams), "info", "register.js (doRegister)");
            doXMLRequest(oTempXmlHttp, strUrl, strUrlParams, "post", false, "application/x-www-form-urlencoded");
            logMsg("*** result: " + encodeURI(oTempXmlHttp.responseText), "info", "register.js (doRegister)");
        }

        // Get the response from the request.
        var strResult = oTempXmlHttp.responseText.split("|")[0].replace(/\n/g, "").replace(/\r/g, "");
        var strWelcomeMsg = oTempXmlHttp.responseText.split("|")[1].replace(/\n/g, "").replace(/\r/g, "");

        oTempXmlHttp = null;

        // Check to see if the registration was successful.
        if (strResult == 1)
        {
            initializeLogin(strWelcomeMsg);

            closeRegisterPopUp();
        }
        else
        {
            pObjErrorMsg.innerHTML = strResult;
            pObjErrorMsg.style.display = "";
        }
    }
}

function closeRegisterPopUp()
{
    // Remove the div.
    removePopUp("divRegisterPopUp");
}

function validatePasswords(pStrPassword, pStrPasswordConfirm, pStrErrorMsg, pObjErrorMsg, pObjButton)
{
    pObjButton.disabled = (pStrPassword != pStrPasswordConfirm);

    // Validate the passwords.
    if (pStrPassword != pStrPasswordConfirm)
    {
        pObjErrorMsg.innerHTML = pStrErrorMsg;
        pObjErrorMsg.style.display = "";
    }
    else
        pObjErrorMsg.style.display = "none";
}
