﻿// JScript File
function ShowEditUpload()
{
    $get('Edit').style.display = 'block';
    $get('ShowEdit').style.display = 'none';
    
}

function HideEditUpload()
{
    $get('Edit').style.display = 'none';
    $get('ShowEdit').style.display = 'block';
    
}

function ShowUpload()
{
    $get('Edit').style.display = 'none';
    $get('ShowEdit').style.display = 'block';
}

var newPassword;
var confirmPassword;

function ResetPassword()
{
    this.newPassword = $get('txtNewPassword').value;
    this.confirmPassword = $get('txtConfirmNewPassword').value;
    JobsGroup.ResetPassword.CheckExistingPassword($get('txtExistingPassword').value, PasswordHandled);
}

function PasswordHandled(result)
{
    if(result)
    {
        if(newPassword.length >= 8)
        {
            if(newPassword == confirmPassword)
            {
                //Success
                JobsGroup.ResetPassword.ResetPassword(newPassword, ChangeHandled)
            }
            else
            {
                $get('dvInfo').innerHTML = "Your passwords are not the same";
                $get('txtNewPassword').value = "";
                $get('txtConfirmNewPassword').value = "";
                $get('txtExistingPassword').value = "";
            }
        }
        else
        {
                $get('dvInfo').innerHTML = "Your password is too short";
                $get('txtNewPassword').value = "";
                $get('txtConfirmNewPassword').value = "";
                $get('txtExistingPassword').value = "";
        }
    }
    else
    {
        $get('dvInfo').innerHTML = "Your existing password is incorrect";
        $get('txtNewPassword').value = "";
        $get('txtConfirmNewPassword').value = "";
        $get('txtExistingPassword').value = "";
    }
}

function ChangeHandled(result)
{
    if(result == true)
    {
        $get('dvInfo').innerHTML = "Your password has been changed";
        $get('txtNewPassword').value = "";
        $get('txtConfirmNewPassword').value = "";
        $get('txtExistingPassword').value = "";        
    }
    else
    {
        $get('dvInfo').innerHTML = "Your password failed to change";
        $get('txtNewPassword').value = "";
        $get('txtConfirmNewPassword').value = "";
        $get('txtExistingPassword').value = "";
    }
}