$(document).ready(function() {
	
	// Enforce required fields
	$("form").submit(function(event) {
		var alertMessage = "";

		//Check the value of each input with class="required"
		$(this).find("input.required").each(function()
		{
			var fieldName = $(this).attr("rel");
			if ($(this).val()=="") {
				alertMessage += fieldName+" is required\n";
			}
			if (fieldName=="email" && !$(this).val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) {
				alertMessage += fieldName+" is not a valid email address\n";
			}
		});

		//If there is an error message, alert it and stop form submission
		if (alertMessage.length > 0) {
			alert(alertMessage);
			return false;
		}
		else return true;
	});


	// Enforce only numbers in a number field
	$("input.number").blur(function() {
		$(this).val($(this).val().replace(/[^0-9\.]/gi, ""));
	});



});