﻿function lostPasswordPopUp() {

    var container = document.createElement("div");
    container.style.position = "absolute";
    container.id = "lostPasswordPopUp";
    container.style.zIndex = "5000";
    main = createTable(260);
    container.appendChild(main);
    main.createRows(1, 2);
    main.className = "ReferenceDialog";


    main.rowArray[0].cellArray[0].className = "TACContentDivHeader";
    main.rowArray[0].cellArray[0].style.padding = "10px";
    main.rowArray[0].cellArray[0].innerHTML = "Forgot Password";

    var close = createAnchor("Close");

    close.onclick = function() {
        destroyObject(container);
    }

    main.rowArray[0].cellArray[1].style.padding = "10px";
    main.rowArray[0].cellArray[1].style.textAlign = "right";
    main.rowArray[0].cellArray[1].appendChild(close);

//    var uneRow = main.createRow(1);
//    uneRow.cellArray[0].colSpan = "2";
//    uneRow.cellArray[0].style.paddingBottom = "10px";
//    uneRow.cellArray[0].style.textAlign = "center";
//    uneRow.cellArray[0].innerHTML = "Please enter your User name";

//    var tbRow = main.createRow(1);
//    tbRow.cellArray[0].colSpan = "2";
//    tbRow.cellArray[0].style.textAlign = "center";

//    var txt = document.createElement("input");
//    txt.id = "lostPasswordPopUp_UserName"
//    txt.className = "TextFields150px";
//    tbRow.cellArray[0].appendChild(txt);

    var uneRow = main.createRow(1);
    uneRow.cellArray[0].colSpan = "2";
    uneRow.cellArray[0].style.paddingBottom = "5px";
    uneRow.cellArray[0].style.textAlign = "center";
    //uneRow.cellArray[0].innerHTML = "Nickname or Email Address";

    var tbRow = main.createRow(1);
    tbRow.cellArray[0].colSpan = "2";
    tbRow.cellArray[0].style.width = "260px";
    tbRow.style.height = "30px";
    tbRow.style.align = "left";

    //tbRow.cellArray[0].style.textAlign = "center";
    tbRow.cellArray[0].style.paddingLeft = "28px";
    tbRow.cellArray[0].style.cellPadding = "0px";
    tbRow.cellArray[0].style.cellSpacing = "0px";

    var txtTable = document.createElement("table");
    txtTable.style.width = "200px";
    txtTable.cellPadding = 0;
    txtTable.cellSpacing = 0;
    txtTable.border = 0;
    txtTable.style.align = "center";

    var txtTableRow = document.createElement("tr");
    txtTableRow.style.width = "200px";
    txtTableRow.style.height = "30px";
    txtTableRow.style.padding = "0px";

    var txtBkgdLeft = document.createElement("td");
    var txtBkgdCenter = document.createElement("td");
    var txt = document.createElement("input");
    var txtBkgdRight = document.createElement("td");

    txt.id = "lostPasswordPopUp_UserName";
    txt.type = "text";
    txt.style.width = "186px";
    txt.style.paddingTop = "8px";
    //txt.className = "TextFields150px";
    txt.className = "LoginTextBox";
    txt.value = "Nickname or Email Address";
    txt.defaultValue = "Nickname or Email Address";

    txt.onfocus = function () {
        if (txt.value == "Nickname or Email Address") {
            txt.value = "";
        }
        else if (txt.value != "") {
            //Do Nothing
        }
    }

    txt.onblur = function () {
        if (txt.value != "") {
            //Do Nothing
        }
        else {
            txt.value = "Nickname or Email Address";
        }
    }

    SI.src("login_field_cornerLeft.png", txtBkgdLeft, SiteImagesType.BaseSiteColorShade);
    SI.src("login_field_middleBck.png", txtBkgdCenter, SiteImagesType.BaseSiteColorShade);
    SI.src("login_field_cornerRight.png", txtBkgdRight, SiteImagesType.BaseSiteColorShade);

    txtBkgdLeft.style.width = "7px";
    txtBkgdCenter.style.width = "186px";
    txtBkgdRight.style.width = "7px";

    txtBkgdCenter.appendChild(txt);

    txtTable.appendChild(txtTableRow);

    txtTableRow.appendChild(txtBkgdLeft);
    txtTableRow.appendChild(txtBkgdCenter);
    txtTableRow.appendChild(txtBkgdRight);

    tbRow.cellArray[0].appendChild(txtTable);
    //tbRow.cellArray[0].appendChild(txtBkgdLeft);
    //tbRow.cellArray[0].appendChild(txtBkgdCenter);
    ////tbRow.cellArray[0].appendChild(txt);
    //tbRow.cellArray[0].appendChild(txtBkgdRight);

    //main.appendChild(tbRow);

    txt.onkeypress = function() {
        return action_onkeypress(e, "recoverPassword()");
    }

    var statusRow = main.createRow(1);
    statusRow.cellArray[0].style.height = "20px";
    statusRow.cellArray[0].className = "OrangeText";
    statusRow.cellArray[0].style.textAlign = "center";
    statusRow.cellArray[0].id = "lostPasswordPopUp_status"
    statusRow.cellArray[0].colSpan = "2";

    var sRow = main.createRow(1);
    sRow.cellArray[0].colSpan = "2";
    sRow.cellArray[0].style.paddingBottom = "10px";
    sRow.cellArray[0].style.textAlign = "center";

    var submit = document.createElement("img");

    submit.onclick = function() {
        if (txt.value == "Nickname or Email Address") {
            statusRow.cellArray[0].innerHTML = "Enter a Valid Nickname or Email Address";
        }
        else {
            recoverPassword();
        } 
    }

    submit.onmouseover = function() {
        image_onmouseover(this);
    }

    SI.src("btForms_Submit.png", submit, SiteImagesType.BaseColorShadeLanguage)
    sRow.cellArray[0].appendChild(submit);


    document.body.appendChild(container);

    var ah = document.getElementById("AllHeaderDiv")

//    if (DetermineBrowser() == Browsers.IE)
        DockToObject(container, ah, "center", "top", "center", 0, 10);
//    else {
//        CenterFloatingObject(container);
//        container.style.top = "10px";
//    }

    if (parseInt(container.style.top) < 10)
        container.style.top = "10px";


}



function recoverPassword() {

    var txt = document.getElementById("lostPasswordPopUp_UserName");
    var status = document.getElementById("lostPasswordPopUp_status");

    if (!txt) return;
    if (!status) return;

    var sendData = "username=" + txt.value;
    sendData += "&language=" + top.MainLanguage;

    if (top.MainTheme.toLowerCase() == "hollywood") {
        sendData += "&theme=21";
    }
    else {
        sendData += "&theme=5";
    }

    status.innerHTML = "Attempt to locate account";

    this.readyFunction = function(responseText) {

        var code = parseInt(responseText)
        switch (code) {
            case 1:
                status.innerHTML = "Password recovery email sent.";
                break;
            case -1:
                status.innerHTML = "You must provide a nickname or email address.";
                break;
            case -2:
                status.innerHTML = "No member by that nickname found.";
                break;
            case -3:
                status.innerHTML = "Unable to send recovery email, no addresses found."
                break;
        }
    }

    AJAXPost(top.document.getElementById("websiteURL").value + "/data/PasswordReset.aspx", "AddParams[1].readyFunction", sendData, this);
}
