// JavaScript Document
$(document).ready ( function() {
	$("#newsletter-widget").load(
		"widget-subscribe.html",
		{},
		function() {
			$("#subscribeform").submit(function(){  
				
				var regex = new RegExp("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");
				if ($("#email").val().match(regex))
				{	
					$.post(  
						"sendmail.php",  
						$("#subscribeform").serialize(),  
						function(data){  
							if (data.success)
								alert("Your email has been submitted.");
							else
								alert("There was an error in submission.");
						} ,
						"json" 
					);
					$("#email").val("")
				} else
				{
					$("#email").focus();
					alert("Please enter a valid email address.");
				}
				
			});
		}
	);
	
	
});