$(document).ready(function() {
	$('form#contactForm').submit(function() {
		$('form#contactForm .error').remove();
		var hasError = false;
		$('.requiredField').each(function() {
if(jQuery.trim($(this).val()) == '') {
	var labelText = $(this).prev('label').text();
	$(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
	$(this).addClass('inputError');
	hasError = true;
} else if($(this).hasClass('email')) {
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if(!emailReg.test(jQuery.trim($(this).val()))) {
		var labelText = $(this).prev('label').text();
		$(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
		$(this).addClass('inputError');
		hasError = true;
	}
}
		});
		if(!hasError) {
			$('form#contactForm li.buttons button').fadeOut('normal', function() {
				$(this).parent().append('<img src="http://www.stmichaelscemetery.com/wp-content/themes/stmichaels2/loading.gif" alt="Loading&hellip;" height="31" width="31" />');
			});
			var formInput = $(this).serialize();
			$.post($(this).attr('action'),formInput, function(data){
				$('form#contactForm').slideUp("fast", function() {				   
					$(this).before('<p class="thanks">Thank you!  We received your entry.</p><p><a href="http://clicktotweet.com/udwNs"><img src="http://www.stmichaelscemetery.com/wp-content/themes/stmichaels2/images/joplin/twitter.png" /></a></p>');
				});
			});
		}
		
		return false;
		
	});
});
