// JavaScript Document

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

function disableEnterKey(e) {
	var key; 
	
	if(window.event) {
		key = window.event.keyCode; //IE
	} else {
		key = e.which; //firefox
	}
	
    return (key != 13);
	
}

function buttonhover(field) {
	field.style.backgroundColor = '#BBBBBB';
}
function buttonrecall(field) {
	field.style.backgroundColor = '#888888';
}

function checkForm() {
	
	var pass = true;//I assume everyone fills out the form correctly.
	
	if (document.form.email.value == "" || document.form.email.value == "your email address") {
		pass = false;
		document.form.email.setAttribute("class", "texterror");//Changes the class name
	}else{
		document.form.email.setAttribute("class", "text");//Resets the class if the email passes if it had previously field
	}
	
	if (document.form.subject.value == "" || document.form.subject.value == "subject") {
		pass = false;
		document.form.subject.setAttribute("class", "texterror");//Changes the class name
	}else{
		document.form.subject.setAttribute("class", "text");//Resets the class if the email passes if it had previously field
	}
	
	if (document.form.message.value == "" || document.form.message.value == "message") {
		pass = false;
		document.form.message.setAttribute("class", "error");//Changes the class name
	}else{
		document.form.message.setAttribute("class", "normal");//Resets the class if the email passes if it had previously field
	}
	
	var rEmail = new RegExp();
	rEmail.compile(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i);
	if (!rEmail.test(document.form.email.value)) {
		pass = false;
		document.form.email.setAttribute("class", "texterror");//Changes the class name
	}else{
		document.form.email.setAttribute("class", "text");//Resets the class if the email passes if it had previously field
	}
	
	if(pass) {
		if (jcap() == false) {//Captcha validation only if all other validation has passed.
			pass = false;
		}	
	}
	
	return pass;
	
}

