// Javascript validation functions
// http://www.designplace.org/

//function to check empty fields

function checkempty(theform) {
	var returnval = true; // by default, allow form submission
	for (i = 0; i < theform.elements.length; i++) {
		if (theform.elements[i].type == "text"
				|| theform.elements[i].type == "textarea") {
			if (theform.elements[i].value == "") { // if empty field
				alert("Please make sure all fields are entered") // alert
																	// error
																	// message
				returnval = false; // disallow form submission
				break; // end loop. No need to continue.
			}
		}
	}
	return returnval;
}

// function to check valid email address
function isValidEmail(email) {
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	strEmail = email.value;

	// search email text for regular exp matches
	if (strEmail.search(validRegExp) == -1) {
		alert('A valid e-mail address is required.');
		return false;
	}
	return true;
}

// function that performs all functions, defined in the onsubmit event handler

function check(form) {
	if (isEmpty(form.field1)) {
		if (isEmpty(form.field2)) {
			if (isEmpty(form.field3)) {
				if (isValidEmail(form.email)) {
					return true;
				}
			}
		}
	}
	return false;
}
