$(document).ready(function(){
	
	$("#submit").click(function(){					   				   
		
		$(".error").hide();
		
		var hasError = false;
		
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailVal = $("#email").val();
		if(emailVal == '') {
			$("#email").after('<span class="error">You forgot to enter your email address...</span>');
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			$("#email").after('<span class="error">Please enter a valid email address...</span>');
			hasError = true;
		}
		
		var nameVal = $("#name").val();
		if(nameVal == '') {
			$("#name").after('<span class="error">You forgot to enter your name.</span>');
			hasError = true;
		}
		
		var phoneVal = $("#phone").val();
		if(phoneVal == '') {
			$("#phone").after('<span class="error">You forgot to enter your phone number.</span>');
			hasError = true;
		}
		
		var organizationVal = $("#organization").val();
		var descriptionVal = $("#description").val();
		var locationVal = $("#location").val();
		var eventdateVal = $("#eventdate").val();
		var guestsVal = $("#guests").val();
		var timeVal = $("#time").val();
		var menuVal = $("#menu").val();
		var additionalVal = $("#additional").val();


		if(hasError == false) {
			$(this).hide();
			$("#sendEmail div.buttons").append('<img src="../spinner.gif" alt="Loading" id="loading" />');
			
			$.post("../north-carolina-catering-estimate/email/sendemail.php",
   				{ email: emailVal, name: nameVal, phone: phoneVal, organization: organizationVal, description: descriptionVal, location: locationVal, eventdate: eventdateVal, guests: guestsVal, time: timeVal, menu: menuVal, additional:additionalVal},
   					function(data){
						$("#sendEmail").slideUp("slow", function() {				   
							
							$("#sendEmail").before('<div class="success"><h1>Message Sent Successfully...</h1><p>Thank you for considering Captain Bob\'s to cater your upcoming event. Your email was sent successfully, we will be contacting you shortly...<br /><br />In the mean time, feel free to browse the rest of our site...</p></div>');											
						});
   					}
				 );
		}
		
		return false;
	});						   
});
