﻿$(document).ready(function() {
    $("#forgot-password #btn-recover-password").unbind("click").click(
        function() {
            RecoverPassword();
        }
    );

    InitLoginButton();
});

function InitLoginButton() {
    $("#forgot-password #btn-login").unbind("click").click(
        function() {
            window.location.href = "Login.aspx";
        }
    );
}

function RecoverPassword() {

    var username = $("#username").val();
    var data = { "username": username };

    if (username == "")
        return;

    DisplayProcessingRequest();

    var proxy = new serviceProxy("WebServices/GothamTixWS.asmx/");
    proxy.invoke("RecoverPassword", data, null,
        function(result) { // success callback                
            DisplaySuccessMessage();
        },
        function(result) { // failure callback
            DisplayFailureMessage(result.Message);
        }
    );
}

function DisplayProcessingRequest() {
    var processingHtml = $("#forgot-password .processing").html();
    $("#forgot-password .message").html(processingHtml);
    $("#forgot-password .message").show();
}

function DisplaySuccessMessage() {
    var successHtml = $("#forgot-password .request-success").html();
    $("#forgot-password .message").html(successHtml);
    $("#forgot-password .message").show();
    InitLoginButton();
}

function DisplayFailureMessage(message) {
    var html = "<span class=\"error\">" + message + "</span>";
    $("#forgot-password .message").html(html);
}
