 $(document).ready(function() {
    $('#email').val("");
    $('#email').focus();
    $(".button").button();
    
    $("#dialog").dialog({ 
        autoOpen: false,
        closeOnEscape: true,
        resizable: false,
        title: "system message",
        modal: true
    });
    
    $("#subscribe").click(function() {
        $('#email').val($('#email').val().replace(/\s/gi,''));
        $("#dialog").html("<img src='images/ajax-loader.gif' />");
        if(!validateEmail($('#email').val())) {
            $("#dialog").html('Email address you entered is not a valid email address. Please correct and try again.');
        } else {
            $("#dialog").load("ajax/subscribe.php", {email: $('#email').val()});
        }
        $("#dialog").dialog("open");
    });
    
    
});

function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 
    return email.match(re) 
}

