$(document).ready(function(){
	$('#contact-form').ajaxForm({ 
	    url: 'contact.php', 
	    beforeSubmit: function() {
	    	if(!validate_form()) {
	    		return false;
	    	}
	    },
	    success: function(){ 
			$('#contact-form').hide();
			$('#thank-you').show();
	    } 
	})
});

function validate_form() {
	var errors = new Array();

	if($('#name').val().length == 0) errors.push('name');
	if(!$('#email').val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) errors.push('email');
	if($('#comment').val().length == 0) errors.push('comment');
	
	$('#contact-form label').removeClass('error');
	if(errors.length > 0)
	{
		$.each(errors,function(key){
			$('label[@for='+ errors[key] +']').addClass('error');
		});
		alert('Some fields have not been completed.\n\nThese fields have been marked in red for your attention.');
	} else {
		return true;
	}
	return false;
}