$(document).ready(function(){
	$("#submit").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var fullNameVal = $("#fullName").val();
		if(fullNameVal == '') {
			$("#fullName").after('<span class="error">Please enter your full name above.</span>');
			hasError = true;
		}
		
		var emailAddVal = $("#emailAdd").val();
		if(emailAddVal == '') {
			$("#emailAdd").after('<span class="error">Please enter your email address above.</span>');
			hasError = true;
		} else if(!emailReg.test(emailAddVal)) {
			$("#emailAdd").after('<span class="error">Please enter a valid email address to send to.</span>');
			hasError = true;
		}
		
		var mobilePhVal = $("#mobilePh").val();
		if(mobilePhVal == '*') {
			$("#mobilePh").after('<span class="error">You forgot to enter your mobile phone number</span>');
			hasError = true;
		}
		
		var workPhVal = $("#workPh").val();
		if(workPhVal == '*') {
			$("#workPh").after('<span class="error">You forgot to enter your work phone number</span>');
			hasError = true;
		}
		
		var homePhVal = $("#homePh").val();
		if(homePhVal == '*') {
			$("#homePh").after('<span class="error">You forgot to enter your home phone number</span>');
			hasError = true;
		}
		
		var address1Val = $("#address1").val();
		if(address1Val == '*') {
			$("#address1").after('<span class="error">You forgot to enter your home phone number</span>');
			hasError = true;
		}
		
			var address2Val = $("#address2").val();
		if(address2Val == '*') {
			$("#address2").after('<span class="error">You forgot to enter your home phone number</span>');
			hasError = true;
		}
		
			var cityVal = $("#city").val();
		if(cityVal == '*') {
			$("#city").after('<span class="error">You forgot to enter your home phone number</span>');
			hasError = true;
		}
		
		/*var checkbox1 = document.forms["contactForm"]["checkbox1"];
		var checkedState1 = checkbox1.checked;
		if(checkedState1 == true)*/
		
		var questionVal = $("#question").val();
		if(questionVal == '') {
			$("#question").after('<span class="error">Please enter your question above.</span>');
			hasError = true;
		}
		
		
		if(hasError == false) {
			$("#contactForm").hide();
			$("#contactForm").append('<img src="/images/colorbox/loading.gif" alt="Loading" id="loading" />');
			
			$.post("http://www.classiccarpets.co.nz/sendemail.php",
   				{ fullName: fullNameVal, emailAdd: emailAddVal, mobilePh: mobilePhVal, workPh: workPhVal, homePh: homePhVal, address1: address1Val, address2: address2Val, city: cityVal, question: questionVal },
   					function(data){
						$("#contactForm").slideUp("normal", function() {				   
							
							$("#contactForm").before('<h1>Success</h1><p>Thanks for sending us a message. We will be in touch soon.</p><p><a href="javascript:location.reload()">Send another message</a></p>');											
						});
   					}
				 );
		}
		
		return false;
	});						   
});