$(document).ready(function(){
	$("#sendFeedback").submit(function(){					   				   
	
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailVal = $("#emailAddress").val();
		if(emailVal == '') {
			$("#sError").fadeIn("slow");
			$("#sError").html("<h4>Whoops...</h4><p>You forgot to provide us with your email address!  But please don't worry, we promise not to pass it out.</p>");
			$('#emailAddressLabel').css({'font-weight' : 'bold'});
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			$("#pError").fadeIn("slow");
			$("#pError").html("<h4>Whoa...</h4><p>Your email address seems invalid, could you double check it for us?</p>");
			hasError = true;
		}
		
		var firstName = $("#firstName").val();
		if (firstName == '') {
			$("#sError").fadeIn("slow");
			$("#sError").html("<h4>Whoops...</h4><p>Can we get your first name?  It's OK, we don't need your last name as well!</p>");
			$('#firstNameLabel').css({'font-weight' : 'bold'});
			hasError = true;
		}
		
		var comments = $("#comments").val();
		if (comments == '') {
			$("#sError").fadeIn("slow");
			$("#sError").html("<h4>Hey...</h4><p>Don't forget to provide us with your feedback!</p>");
			$('#commentsLabel').css({'font-weight' : 'bold'});
			hasError = true;
		}
		
		var phone = $("#phone").val();
		if (phone != ''){
			$("#sError").fadeIn("slow");
			$("#sError").html("<h4>Hmmm...</h4><p>Sorry, but we think you might be a spammer!</p>");
			hasError = true;
		}
		
		var mailingList = $("#mailingList").val();
		
		if(hasError == false) {
			$("#comments").val('');
			$("#emailAddress").val('');
			$("#firstName").val('');
			$("#send_feedback").fadeOut("slow");
			$.post("/Testimonials/sendMessage.php",
   				{ emailTo: emailVal, personName: firstName, message: comments, list: mailingList },
   					function(data){
						$("#thanks").fadeIn("slow");
						$("#thanks").html("<h4>Thank You</h4><p>Your feedback has been sent.  Here is your coupon code for 30% off your next order: <b>FBACK9</b></p>");
   					}
				 );
		}
		
		return false;
	});						   
});
