$(document).ready(function(){
	$("#submit_newsletter").click(function(){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		email = $("#newsletter").val();
		if(reg.test(email) == false) {
	      alert('Please insert a valid email.');
	      return false;
	    }else{
	    	 $.blockUI({ 
	             message:  '<p>Please wait...</p>',
	             timeout:   15000 
	         }); 
	    	$.post("scripts/newsletter-script.php",
	    			{email:email},
	    			function(data){
	    				if(data == "ok"){
	    					 $.blockUI({ 
	    			             message:  '<p>Thank you for join our newsletter list.</p><p>You will be notified for our latest news and offers.</p>',
	    			             timeout:   5000 
	    			         }); 
	    					 $('.blockOverlay').click($.unblockUI); 
	    					 $("#newsletter").val('');
	    				}else{
	    					 $.blockUI({ 
	    			             message:  '<p>For some technical reason we have not received your email.</p><p>Please try again.</p>',
	    			             timeout:   5000 
	    			         }); 
	    					 $('.blockOverlay').click($.unblockUI);
	    					 $("#newsletter").val('');
	    				}
	    			}, "json"
	    	);
	    }
	});
});
