$(function()
{
	$("#newsletter form :submit").click(function() {	
			
		// First, disable the form from submitting
		$('#newsletter form').submit(function() { return false; });
			
		// Grab form action
		formAction = $("#newsletter form").attr("action");
						
		// Validate email address with regex
		if (!checkEmail()) 
		{
			alert("Please enter a valid email address");
			return;
		}
			
		// Serialize form values to be submitted with POST
		var str = $("#newsletter form").serialize();
			
		// Add form action to end of serialized data
		final = str + "&action=" + formAction;
			
		// Submit the form via ajax
		$.ajax({
			url: "/wp-content/themes/seriouspr/proxy.php",
			type: "POST",
			data: final,
			success: function(html){
				// If successfully submitted hides the form
				$("#newsletter").hide();
				// Shows "Thanks for subscribing" div
				$("#confirmation").slideDown();
					
				// Fire off Google Analytics fake pageview
				var pageTracker = _gat._getTracker("UA-2776635-21");
				pageTracker._trackPageview("/newsletter_signup");
			}
		});
	});
});
function checkEmail()
{	
	var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var emailVal = $("#wpnewsletter_email").val();
	return pattern.test(emailVal);
}