$(document).ready(function(){
	$("#contactform").submit(function(){		
		// Place ID's of all required fields here. If using ID's other than #email, #cardnum, or #card_brand, replace them here
		required = ["email", "name", "comments"];
		var email = $("#email");
		
		//Validate required fields
		for (i=0;i<required.length;i++) {
			var input = $('#'+required[i]);
			if ((input.val() == "") || (input.val() == "Please fill out this field.")) {
				input.addClass("needsfilled");
				input.val("Please fill out this field.");
			} else {input.removeClass("needsfilled");}
		}
		// Validate the e-mail.
		if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
			email.addClass("needsfilled");
			email.val("Please enter a valid e-mail.");
		}
		//if any inputs on the page have the class 'needsfilled' the form will not submit
		if ($(":input").hasClass("needsfilled")) {
			return false;
		} else {return true;}
	});
	
	// Clears any fields in the form when the user clicks on them
	$(":input").add($(":textarea")).focus(function(){		
	   if ($(this).hasClass("needsfilled") ) {
			$(this).val("");
			$(this).removeClass("needsfilled");
	   }
	});
});	

