$(document).ready(function(){
	
	$('#contactForm').submit(function(){
	
		var formData = $(this).serialize();
	
		$.ajax({
			 type: "post",
			 url: "inc/form.php",
			 dataType: "json",
			 data: formData,
			 success: function(msg){
				if(msg == 'OK'){
					$("#messageSent").html('Your message has been sent successfully!').show("slow");
					$( "#contactForm" )[ 0 ].reset();
					setTimeout('$("#messageSent").hide()', 2000);
				}else{
					if($('.error_name').length==0){
						$('#contactForm').prepend(msg.error_name);
						
					}
					if($('.error_telephone').length==0){
						$('#contactForm').prepend(msg.error_telephone);
					}
					if($('.error_email').length==0){
						$('#contactForm').prepend(msg.error_email);
					}
					if($('.error_message').length==0){
						$('#contactForm').prepend(msg.error_message);
					}
					$("#messageSent").html('Error occured. Please try again.').show("slow");
					$('.error').css({"font-size":"12px"});
				}
			 },//end function processResponse...
			 beforeSend: function(){
				 $("#contactForm input[type=submit]").hide();
				 $("#loading").show();
			 },
			 complete: function(){
				 $("#contactForm input[type=submit]").show();
				 $("#loading").hide();
			 }
		});//end of $.ajax
	
		return false;
	
	});//end $('#commentForm').submit...

	$('#contactForm input[name=name]').focus(function() {
		$('.error_name').remove();
	});
	$('#contactForm input[name=telephone]').focus(function() {
		$('.error_telephone').remove();
	});
	$('#contactForm input[name=email]').focus(function() {
		$('.error_email').remove();
	});
	$('#contactForm textarea').focus(function() {
		$('.error_message').remove();
	});
	
});//end of ready
