﻿$(function() {
    $('.error').hide();
    $('.message').hide();
	
    $("input#ForgotButton").click(function() {
        var error = false;
        $("input#ForgotButton").hide();
        $('.error').hide();
        $('.message').hide();
        
        //alert("1");
	    var email_address = $("input#email").val();
	    
	    if (email_address == "") {
            $("#email_error").show();
            $("input#email").focus();
            error = true;
        }
        
        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        if (!emailPattern.test(email_address)) {
            $("#email_error").show();
            $("input#email").focus();
            error = true;
        }
        
        if (error) {
            $("input#ForgotButton").show();
            return false;
        }

	    var dataString = 'email_address=' + email_address;
	    //alert("2");
        $.ajax({
            type: "POST",
            url: "ProcessForgot.aspx",
            data: dataString,
            success: function(response) {
                if (response == "Success") {
                    $("#ForgotConfirmation").show();
                    $("#ForgotControls").hide();
                    $("input#ForgotButton").show();
                    //alert("3");
                } else {
                    $("#email_error").show();
                    $("input#email").focus();
                    $("input#ForgotButton").show();
                    //alert("4");
                }
            }
        });
    });
});
  