$(document).ready(function(){
	$("#submit").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		
		var emailToVal = $("#emailTo").val();
		if(emailToVal == '') {
			$("#emailTo").after('<span class="error">You forgot to enter your Email Address.</span>');
			hasError = true;
		} else if(!emailReg.test(emailToVal)) {	
			$("#emailTo").after('<span class="error">Please enter a valid email address.</span>');
			hasError = true;
		}
		
		var TheAccomNameVal = $("#TheAccomName").val();
		if(TheAccomNameVal == '') {
			$("#TheAccomName").after('<span class="error">Please include your Listing`s Name</span>');
			hasError = true;
		}
		
		var TheContactNameVal = $("#TheContactName").val();
		if(TheContactNameVal == '') {
			$("#TheContactName").after('<span class="error">Please include a Contact Name</span>');
			hasError = true;
		}
		
		var TheAddressVal = $("#TheAddress").val();
		if(TheAddressVal == '') {
			$("#TheAddress").after('<span class="error">Please include your Address</span>');
			hasError = true;
		}

		var ThePostalCodeVal = $("#ThePostalCode").val();
		if(ThePostalCodeVal == '') {
			$("#ThePostalCode").after('<span class="error">Please include your Postal Code</span>');
			hasError = true;
		}
		
		var TownVal = $("#Town").val();
		if(TownVal == '') {
			$("#Town").after('<span class="error">Please include a City or Town</span>');
			hasError = true;
		}
		
		var ThePhoneVal = $("#ThePhone").val();
		if(ThePhoneVal == '') {
			$("#ThePhone").after('<span class="error">Please include your Phone Number</span>');
			hasError = true;
		}

		var MyphoneVal = $("#Myphone").val();
		if(MyphoneVal == '') {
			$("#Myphone").after('<span class="error">You forgot to enter your Phone Number</span>');
			hasError = true;
		}
		
		var MyaddressVal = $("#Myaddress").val();
		if(MyaddressVal == '') {
			$("#Myaddress").after('<span class="error">You forgot to enter Your Address.</span>');
			hasError = true;
		}
		
		var messageVal = $("#message").val();
		if(messageVal == '') {
			$("#message").after('<span class="error">You forgot to enter the message.</span>');
			hasError = true;
			
		}
		
		var PriceVal = $("#Price").val();
		if(PriceVal == '') {
			$("#Price").after('<span class="error">You forgot to enter the Price.</span>');
			hasError = true;
			
		}		
		
		
		if(hasError == false) {
			$(this).hide();
			$("#sendEmail li.buttons").append('<img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" />');
			
			$.post("/wp-content/uploads/2008/01/sendemail.php",
   				{ emailTo: emailToVal, emailFrom: emailFromVal, subject: subjectVal, message: messageVal },
   					function(data){
						$("#sendEmail").slideUp("normal", function() {				   
							
							$("#sendEmail").before('<h1>Success</h1><p>Your email was sent.</p>');											
						});
   					}
				 );
		}
		
		return false;
	});						   
});