<!-- Form validation & submission - modify if required -->
jQuery(document).ready(function($){
	$("#email").val( $("#email").attr("title") );
	$("#email").focus(function(){
		title = $(this).attr("title");
		val = $(this).val();
		if(title==val) $(this).val("")
	});

	$("#submit").click(function(){
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		var email = $("#email").val();
		var name = $("#name").val();
		if(email == '') {
			$("#message").html('<span class="error" style="color:#ed6d00">Please enter a valid email address<\/span>');
			hasError = true;
		} else if(!emailReg.test(email)) {
			$("#message").html('<span class="error" style="color:#ed6d00">Please enter a valid email address<\/span>');
			hasError = true;
		}
		
		if(hasError == false) {
			$("#message").html('<img src="images/indicator.gif" alt="Loading" id="loading">');
			
			// If needed, you can replace sendmail.php with your own script which you want to submit the form details to
			$.post("libraries/submit_newsletter.php",
   				{ emailFrom: email,  name: name },
   					function(data){
											
						$("#loading").fadeOut("normal", function() {				   
							$("#newslettersubmit").replaceWith("<div id='newslettersubmit2'>Thank you for your subscription.</div>");																													
						});
   					}
				 );
		}


		return false;
	});
});
