$(document).ready(function() {
    $("#email").val("").bind("blur", function(e) { //Set the email to "" so that a hacker cannot bypass the email-password check (checkPass will not be set if the user does not click on the email input field). JAP 30-Sep-2010
        checkEmail();
    });
});

function checkEmail() {
    var email = $("#email").val();
    if (email.length > 0) {
        $.ajax({
            type: "POST",
            url: "sub_form_backend.ashx",
            data: { cmd: 1, email: email },
            dataType: "text",
            success: function(o) {
                if (o == "True") {
                    $("#password").bind("blur", function(e) {
                        checkPass();
                    });
                } else {
                    $("#password").unbind();
                }
            }
        });
    } else {
        $("#password").unbind();
    }
}

function checkPass() {
    var email = $("#email").val();
    var pass = $("#password").val();
    if ((email.length > 0) && (pass.length > 0)) {
        $.ajax({
            type: "POST",
            url: "sub_form_backend.ashx",
            data: { cmd: 2, email: email, pass: pass },
            dataType: "text",
            success: function(o) {
                if (o == "True") {
                    $("#pass_txt").html("");
					$("#pass_txt").hide();
                    //$("#btnSubmit").attr("disabled", "false");
					$("#btnSubmit").removeAttr("disabled");
                    //$("#submitbtn").click(function() {
                    //    submitFormStep1();
                    //});
					//Using a hidden field to control the 'submit button' (really it's a styled anchor element in ds_sub_form_step1.asp) JAP 30-Sep-2010
					$("#hBit").val("1"); //$("#submitbtn").removeAttr("disabled");
                } else {
                    $("#pass_txt").html("The password you have entered is not correct.");
					$("#pass_txt").show();
                    //$("#btnSubmit").attr("disabled", "true");
					$("#btnSubmit").attr("disabled", "disabled");
                    //$("#submitbtn").attr("onclick", "");
					//Using a hidden field to control the 'submit button' (really it's a styled anchor element in ds_sub_form_step1.asp) JAP 30-Sep-2010
					$("#hBit").val("0"); //$("#submitbtn").removeAttr("disabled");
                    $("#password").bind("keyup", function(e) {
                        if ($("#password").val().length == 0) {
                            $("#pass_txt").html("");
							$("#pass_txt").hide();
							$("#btnSubmit").removeAttr("disabled");
							//Using a hidden field to control the 'submit button' (really it's a styled anchor element in ds_sub_form_step1.asp) JAP 30-Sep-2010
							$("#hBit").val("1");
                        }
                    });
                }
            }
        });
    } else {
        $("#pass_txt").html("");
		$("#pass_txt").hide();
        //$("#btnSubmit").attr("disabled", "false");
        $("#btnSubmit").removeAttr("disabled");
        //$("#submitbtn").click(function() {
        //    submitFormStep1();
        //});
		//Using a hidden field to control the 'submit button' (really it's a styled anchor element in ds_sub_form_step1.asp) JAP 30-Sep-2010
		$("#hBit").val("1"); //$("#submitbtn").removeAttr("disabled");
    }
}


