$(document).ready(function(){
	$("#submit").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailToVal = "dawn@dawnclement.com";
/*		if(emailToVal == '') {
			$("#emailTo").after('<span class="error">You forgot to enter the email address to send to.</span>');
			hasError = true;
		} else if(!emailReg.test(emailToVal)) {	
			$("#emailTo").after('<span class="error">Enter a valid email address to send to.</span>');
			hasError = true;
		}
*/		
		var emailFromVal = $("#emailFrom").val();
		if(emailFromVal == '') {
			$("#emailFrom").after('<span class="error">You forgot to enter your email address.</span>');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {	
			$("#emailFrom").after('<span class="error">Enter a valid email address.</span>');
			hasError = true;
		}
		
		var emailNameVal = $("#emailName").val();
		if(emailNameVal == '') {
			$("#emailName").after('<span class="error">You forgot to enter your name.</span>');
			hasError = true;
		}

		var subjectVal = "New email from website: ";
/*		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 your message.</span>');
			hasError = true;
		}

		var questionVal = $("#question").val();
		if(questionVal != '14') {
			$("#question").after('<span class="error">You answered the question incorrectly.</span>');
			hasError = true;
		}
		
		var subjectAndName = subjectVal + " " + emailNameVal;
		
		if(hasError == false) {
			$(this).hide();
			$("#sendEmail li.buttons").append('Sending email...');
			
			$.post("email/sendemail.php",
   				{ emailTo: emailToVal, emailFrom: emailFromVal, subject: subjectAndName, message: messageVal },
   					function(data){
						$("#sendEmail").hide();				   
						$("#sendEmail").before('<h1>Thanks for emailing me!</h1><p>I always like to get emails from people interested in my music and I will respond to you as soon as possible</p>');											
   					}
				 );
		}
		
		return false;
	});						   
});