$(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">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 subjectVal = $("#subject").val();
		if(subjectVal == '') {
			$("#subject").after('<span class="error">You forgot to enter the subject.</span>');
			hasError = true;
		}
		
		var messageVal = $("#message").val();
		if(messageVal == '') {
			$("#message").after('<span class="error">You forgot to enter the message.</span>');
			hasError = true;
		}
		
		if(hasError == false) {
			$(this).hide();
			$("#sendEmail li.buttons").append('<img src="http://www.molnies.com/images/loading.gif" alt="Loading" id="loading" />');
			$.post("http://www.molnies.com/sendemail.php", { 
				email: emailVal, name: nameVal, subject: subjectVal, message: messageVal 
				},
   					function(data){
						$("#sendEmail").slideUp("normal", function() {				   
							$("#sendEmail").before('<h3 class="success">Success</h3><p>Your email was sent.</p><p>If you asked me a question, or other reasons that might need a reply, I will try to answer you within 24 hours.</p>');											
						});
   					}
			);
		}
		return false;
	});						   
});