﻿
var userInformation = null;    
var userInfoDataObject = null;
document.observe("dom:loaded", initPage);

function initPage() {
    userInformation = new UserInformation();
}

function SendPasswordReminder() {
    $('EnterEmail').hide();
    $('divNotifications').hide();
    if ($('txtEmail').value == '' || $('txtEmail').value.indexOf('@') == -1 || $('txtEmail').value.indexOf('.') == -1) {
        $('EnterEmail').toggle();
        return;
    }
    userInformation.SendPassword($('txtEmail').value);
    $('divNotifications').toggle();
    return;
}

function ChangePassword() {
    $('divMsgWarning').hide();
    var formComplete;
    formComplete = true;
    if ($('txtCurPassword').value == '') {
        if (formComplete == true)
            $('divMsgWarning').update("Current password is incorrect");
        $('divMsgWarning').show();
        $('txtCurPassword').addClassName("inputText redBorder");
        formComplete = false;
    } else {
        $('txtCurPassword').removeClassName("inputText redBord");
        $('txtCurPassword').addClassName("inputText");
    }
    if ($('txtPassword').value == '' || $('txtPassword').value.length<6) {
        if (formComplete == true)
            $('divMsgWarning').update("Please enter a valid 6 digit password");
        $('divMsgWarning').show();
        $('txtPassword').addClassName("inputText redBorder");
        formComplete = false;
    } else {
        $('txtPassword').removeClassName("inputText redBord");
        $('txtPassword').addClassName("inputText");
    }
    if ($('txtPassword').value != $('txtConfirmPassword').value) {
        if (formComplete == true)
            $('divMsgWarning').update("Passwords do not match");
        $('divMsgWarning').show();
        $('txtConfirmPassword').addClassName("inputText redBorder");
        formComplete = false;
    } else {
        $('txtConfirmPassword').removeClassName("inputText redBord");
        $('txtConfirmPassword').addClassName("inputText");
    }
    if (formComplete == false)
        return;
    userInfoDataObject = userInformation.GetByID();
    userInfoDataObject = userInformation.CheckLogin(userInfoDataObject.Email, $('txtCurPassword').value);
    if (userInfoDataObject.Valid == false)
    {
        if (formComplete == true)
            $('divMsgWarning').update("Current password is incorrect");
        $('divMsgWarning').show();
        $('txtCurPassword').addClassName("inputText redBorder");
        return;
    } else {
        $('txtCurPassword').removeClassName("inputText redBord");
        $('txtCurPassword').addClassName("inputText");
    }
    userInfoDataObject = userInformation.UpdatePassword($('txtPassword').value);
    window.location.href = "../Dashboard.htm?status=changePasswordOk";
    return;
}
