﻿function closeWindow() {
    // Hide this popup window
    parent.hideModalWindow("editPasswordModal");
}

function savePWord() {
    // get both passwords
    var newPWord1 = document.getElementById('inputNewPWord').value;
    var newPWord2 = document.getElementById('inputConfPWord').value;
    // Check that the two passwords are not empty or have the default values
    if (newPWord1 != "" && newPWord2 != "" && newPWord1 != "[New-Password]" && newPWord2 != "[New-Password]") {
        // Make sure that the 2 passwords match
        if (newPWord1 == newPWord2) {
            if (newPWord1.length > 3 && newPWord1.length < 9) {
                // Set the new password using the handler
                var strURL = parent.document.getElementById('hfHandlerURL').value + "/setNewUserPass.ashx"; //  call the handler to set the text in the database too
                $.post(strURL, {
                    userID: parent.document.getElementById('hfUserID').value,
                    type: "pass",
                    value: newPWord1
                }, function (data) {
                    if (data == "success") {
                        // Hide this popup window
                        parent.hideModalWindow("editPasswordModal");
                        // Show confirmation message
                        parent.showMessage2("small", "Your new password has now been set.");
                    }
                });
            }
            else {
                // the password is not of the correct length
                parent.showMessage2("small", "The password is not of the correct length.");
            }
        }
        else {
            // the two passwords do not match
            parent.showMessage2("small", "The 2 passwords do not match.");
        }
    }
    else {
        // at least one of the passwords have the default value or is an empty string
        parent.showMessage2("small", "Please enter your new password in both fields.");
    }
}

function setTextBox(element, type) {
    // Empty the text box on click if it has the default value, set it back to default text if fcocus is lost and the field is empty
    if (type == "clear") {
        if (element.value == "[New-Password]") {
            element.value = "";
        }
    }
    else {
        if (element.value == "") {
            element.value = type;
        }
    }
}
