$(document).ready(function(){
	$("#submit").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var phoneReg = /^([\(]{1}[0-9]{3}[\)]{1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?)?[0-9]{3}(\.|\-| )?[0-9]{4}$/;
	
		var nameVal = $("#name").val();
		if(nameVal == '') {
			$("#name").after('<span class="error">You forgot to enter your name.</span>');
			hasError = true;
		}
		
		var emailVal = $("#email").val();
		if(emailVal == '') {
			$("#email").after('<span class="error">You forgot to enter your email.</span>');
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			$("#email").after('<span class="error">Please enter a valid email address.</span>');
			hasError = true;
		}
		
		var phoneVal = $("#phone").val();
		if(phoneVal == '') {
			$("#phone").after('<span class="error">You forgot a phone number.</span>');
			hasError = true;
		} else if(!phoneReg.test(phoneVal)) {	
			$("#phone").after('<span class="error">Please enter a valid phone number.</span>');
			hasError = true;
		}
		
		var messageVal = $("#message").val();
		if(messageVal == '') {
			$("#message").after('<span class="error">You forgot to enter details.</span>');
			hasError = true;
		}
		
		if(hasError == false) {
			$(this).hide(); 
			$("#quoteRequest li.buttons").append('<img src="splash-images/loadingAnimation.gif" alt="Loading" id="loading" />');
			$.post($("#uri").val() + "/quoteRequest.php",
   				{ name: nameVal, email: emailVal, phone: phoneVal, message: messageVal },
   					function(data){
						$("#quoteRequest").slideUp("normal", function() {				   
							$("#quoteRequest").before('<p style="width: 200px;">Your email has been sent and a Sales Representative will be contacting you shortly.</p>');											
						});
   					}
				 );
		}
		
		return false;
	});						   
});
