$(function() {
	$('form[action$=FormMail.pl]').submit(function() {
		
		form = $(this);
		form.find('div.error').remove();
		
		errors = [];
		required = ['Contact Name', 'Contact Email', 'Contact Phone'];
		
		$.each( required, function ( i, name ) {
			
			alias = name.split(' ')[1]; // 'Name', 'Email', or 'Phone' without the 'Contact '.
			field = $('input[name=' + name + ']');
			
			if( field.val().match(/^\s*$/) ) {
				errors.push(name);
				field.after('<div class="error" style="display: none;"> Please enter your ' + alias + '</div>');
			}
			
		});
		
		if(errors.length > 0) {
			form.find('div.error').fadeIn('slow');
			form.find('input[type=image]').after('<div id="report" class="error" style="margin-top: .5em; width: 255px; background-color: #f6d4d4; padding: .2em;">Your message was not sent because you missed a required field! Please enter the missing infomration and try again.</div>');
			return false;
		}
		
	});
});