﻿
$(document).ready(function() {
    var options = {
        target: '#emailSignupResponse',   // target element(s) to be updated with server response 
        beforeSubmit: showRequest,  // pre-submit callback 
        success: showResponse,  // post-submit callback 
        url: "subscribe.ashx",
        clearForm: true
    };

    // bind to the form's submit event
    $('#aspnetForm').submit(function() {
        $(this).ajaxSubmit(options);
        return false;
    });

    $("#emailSignupSubmitButton").click(function() {

        var email = $("#emailAddress");
        var isValid = validate_email(email);
        if (isValid) {

            $('#aspnetForm').submit();
        }
        else {
            $("#emailSignupResponse").html("Invalid email format.<br /><br />");
        }
    });

    $("#emailAddress").focus(function() {
        if (this.value == this.defaultValue) {
            this.value = "";
        }
    }).blur(function() {
        if (!this.value.length) {
            this.value = this.defaultValue;
        }
    });

});


// pre-submit callback

function showRequest(formData, jqForm, options) {
    return true;
}

// post-submit callback 
function showResponse(responseText, statusText) { } 