function validateForm(whichform) {
	for (var i=0; i < whichform.elements.length; i++) {
	 var element = whichform.elements[i];
	 if (element.className.indexOf("required") != -1) {
	 	if (!isFilled(element)) {
	 		alert("Please fill in the " + element.name + " field.");
	 		return false;
	 	}
	 }
	 if (element.className.indexOf("email") != -1) {
	 	if (!isEmail(element)) {
	 		alert("The " + element.name + " field must be a valid email address.");
	 		return false;
	 	}
	 }
	}
	
	if(!jcap()){return false};
	return true;
}
function isFilled(field) {
	if (field.value.length < 1 ) {
	return false;
	} else {
	return true;}
}
function isEmail(field) {
	if (field.value.indexOf("@") == -1 || field.value.indexOf(".") == -1) {
	return false;
	} else {
	return true;
	}
}
function prepareForms() {
	for (var i=0; i<document.forms.length; i++) {
		var thisform = document.forms[i];
		thisform.onsubmit = function() {
		 return validateForm(this);
		}
	}
}
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
addLoadEvent(prepareForms);

function showForm() {
	if(!document.getElementById("theform")){return false};
	document.getElementById("theform").style.display = "block";
	document.getElementById("themessage").style.display = "none";
}
addLoadEvent(showForm);

function submitCaptcha() {
	alert(jcap());
	if(jcap() && validateForm()){return true}else{return true};
}


