function checkEmail(email)
	{	
		var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emailVal = $("#" + email).val();
		return pattern.test(emailVal);
	}
	
$(document).ready(function(){
	$("#ebullSignup #sign-up").click(function() {	

			
			// First, disable the form from submitting
			$('#ebullSignup').submit(function() { return false; });
			
			// Grab form action
			formAction = $(this).parents('form').attr("action");
			
			// Hack together id for email field
			emailId = formAction.replace("http://ebull.dusteddesign.com/t/r/s/", "");
			emailId = emailId.replace("/", "");
			emailId = emailId + "-" + emailId;

			emailChk = true;
			
			// Validate email address with regex
			if (!checkEmail(emailId)) 
			{
				
				$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
				$("#confirmation").addClass("panel");
				$("#confirmation").html("Please enter a valid email address");
				return false;
			}
			
			// Serialize form values to be submitted with POST
			var str = $(this).parents('form').serialize();
	
			// Add form action to end of serialized data
			final = str + "&action=" + formAction;
			
			// Submit the form via ajax
			$.ajax({
				url: "http://www.harrisoncatering.co.uk/proxy.php",
				type: "POST",
				data: final,
				success: function(html){
					$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
					$("#confirmation").addClass("panel");
					$("#confirmation").html("Thanks for subscribing");
				}
			});
			return false;
	});
});
printLink = function() {
	if (document.getElementById("printBut")) {
		var printBut = document.getElementById("printBut");
		printBut.onclick=function() {
			if (window.print) {
				window.print();
			} else {
				alert("Unfortunately your browser doesn't support printing via Javascript.\nTo print this page please select \"File > Print...\" in your browser's menu.");
			}
			return false;
		}
	}
}
addBookmark = function() {
	if (document.getElementById("bookmarkBut")) {
		var bookBut = document.getElementById("bookmarkBut");
		bookBut.onclick=function() {
			if (document.all) {
				bookmarkurl=document.location;
				bookmarktitle="Harrison Catering";
				window.external.AddFavorite(bookmarkurl,bookmarktitle);
			} else {
				alert("Unfortunately your browser doesn't support adding bookmarks via this link.\n\nTo bookmark this page please use your browser's menu.");
			}
			return false;
		}
	}
}

window.onload = function() {
	printLink();addBookmark();
}