$(document).ready(function(){
	$("#submit").click(function(){
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var NameVal = $("#Name").val();
		if(NameVal == '') {
			$("#Name").after('<span class="error">Please give us your name.</span>');
			hasError = true;
		} 
		
		var emailFromVal = $("#emailFrom").val();
		if(emailFromVal == '') {
			$("#emailFrom").after('<span class="error">You forgot to enter your email address.</span>');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {	
			$("#emailFrom").after('<span class="error">Enter a valid email address we can contact you at.</span>');
			hasError = true;
		}
		
		var phoneVal = $("#phone").val();
		if(phoneVal == '') {
			$("#phone").after('<span class="error">You forgot to enter a phone number.</span>');
			hasError = true;
		}
		
	
		
		
		if(hasError == false) {
			$(this).hide();
			$("#sendEmail li.buttons").append('<img src="/js/shadowbox/classic/loading.gif" alt="Loading" id="loading" />');
			
			$.post("/contactform/sendemail.php",
   				{ Name: NameVal, emailFrom: emailFromVal, phone: phoneVal, message: messageVal },
   					function(data){
						$("#sendEmail").slideUp("normal", function() {				   
							
							$("#sendEmail").before('<h1>Inquire Success</h1><p>Your Message was sent.<br/>A representative will get back to you shortly.</p>');											
						});
   					}
				 );
		}
		
		return false;
	});						   
});