
$(document).ready(function(){
        $("#contact").validate
         ({
            rules:
            {
                email:
                {
                    required: true,
                    email: true
                }
            }
        });
});

$(function()
{

    $('.error').hide();
    var hasError = false;
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    
    $(".button").click(function()
    
    {
        // validate and process form here
    
        var email = $("input#email").val();
        
    
       if ((email == "") || (!emailReg.test(email)) )
        {
            $("label#email_error").show();
            $("input#email").focus();
            return false;
        }
      
        var dataString = '&email=' + email;
        //alert (dataString);return false;
        $.ajax
        ({
            type: "POST",
            url: "db_email_submit.php",
            data: dataString,
            beforeSend: function()
            {
                $('#contact_form').html("<div class='loader-gif'><img id='loading' alt='loading' src='images/spinner_gray.gif' /></div>");
                
            },
            
            success: function()
            {
                $('#contact_form').html("<div id='message'></div>");
                $('#message').html("<p>You've been added to the list!</p>")
                
                .hide()
                .fadeIn(400, function()
                    {
                        //$('#message').append("<img id='checkmark' src='images/check.png' width='20' />");
                    });
                
            }
        });
        
        return false;
    
    });
});


