// constants to define the title of the alert and button text.

function validate_contact_form(thisform){ 
	with (thisform){ 
		if (validate_email_required(email,"Email cannot be left blank!")==false){
			email.focus();
			return false;
		}
		else if (validate_email(email,"Not a valid email address!")==false){
			email.focus();
			return false;
		}
		else if (validate_required(message,"Message cannot be left blank!")==false){
			message.focus();
			return false;
		}
		else if (validate_security_question(question,"What color is this text?")==false){
			question.focus();
			return false;
		}
		else {
			$.post("send.php", $("#contact").serialize(),
				function(data) {
					switch (data){
						case "complete":
							var message = "<span id='emailSuccess'>Thank You, Your message was sent.</span><br />Please allow up to 48 hours for a response.";
						break;
						case "error":
							var message = "<span id='emailError'>An error occurred, please try again later.</span><br />If the problem persists, please use the email address given to contact me.";
						break;
					}
					$("#contactResult").append("<div align='center'>" + message + "</div>");
					$("#theContactFormArea").fadeTo(500, 0);
					$("#contactResult").fadeTo(500, 1);
					$("#theContactFormArea").animate({"height": "0px"}, 500);
					$("#contactResult").animate({"height": "450px"}, 500);
				}
			);
			return false;						
		}
	}
}
function validate_email_required(field,alerttxt) {
	with (field){
		if (value==null || value=="" || value=="Your Email"){
			$("#userEmail").css({'color' : 'white' , 'background-color' : 'red', 'font-style' : 'normal' , 'font-weight' : 'bold'});
			$("#userEmail").val(alerttxt);
			return false;
		}
		else {
			return true;
		}
	}
}
function validate_required(field,alerttxt) {
	with (field){
		if (value==null || value=="" || value=="Your Message" || value=="Your Message" || value=="Message cannot be left blank!"){
			$("#formTA").css({'color' : 'white' , 'background-color' : 'red', 'font-size' : '48px' , 'font-style' : 'normal' , 'font-weight' : 'bold'});
			$("#formTA").val(alerttxt);
			return false;
		}
		else {
			return true;
		}
	}
}
function validate_security_question(field,alerttxt){
	with (field){
		if (value.toLowerCase()!="blue"){
			$("#SQanswer").css({'color' : 'white' , 'background-color' : 'red', 'font-style' : 'normal' , 'font-weight' : 'bold'});
			$("#SQanswer").val(alerttxt);
			return false;
		}
		else {
			return true;
		}
	}
}
function validate_email(field,alerttxt){
	with (field){
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2){
			$("#userEmail").css({'color' : 'white' , 'background-color' : 'red', 'font-style' : 'normal' , 'font-weight' : 'bold'});
			$("#userEmail").val(alerttxt);
			return false;
		}
		else {
			return true;
		}
	}
}
// JavaScript Document
