function validation() {
	// get information from the hidden input field named "required"
	var required = document.forms['theform'].elements['required'].value;
	// splitting info from "required" into an array
	var requiredarray = required.split(", ");
	// declaring vars "errorfields" and "firstemptyfield" as null.
	// errorfields will gather the names of all of the required fields
	// left empty. firstempty field will be the first required field
	// left empty, so that after the validation is run, the focus will
	// go back to the first required field left empty.
	var errorfields = "";
	var firstemptyfield = "";
	// for each item in "requiredarray"...
	for (var i = 0; i < requiredarray.length; i++) {
		// getting "fieldname" from the item in the array, and
		// "fieldvalue" from the value in the field from "fieldname"
		var fieldname = requiredarray[i];
		
		var fieldvalue = "";
		fieldvalue = document.forms['theform'].elements[fieldname].value;
		if (fieldvalue == "" || fieldvalue.length <=3 ) {
			// writing empty required fields to "errorfields". Make them
			// nice below with commas to separate fieldnames.
			//alert('length is ' + fieldvalue.length);
			if (errorfields=="") {
				errorfields += fieldname;
			} else {
				errorfields += ", " + fieldname;
			}
			// write to firstemptyfield only if it is NULL!!!
			if (firstemptyfield == "") {
				firstemptyfield = fieldname;
			}
		}
	}
	if (errorfields != "") {
		alert("The following field(s) must be filled in:\n\n" + errorfields);
		// focus on the first empty required field, and return false.
		document.forms['theform'].elements[firstemptyfield].focus();
		return false;
	}else {
		return true;
	}
}

function courseinfovalidation() {
	var SPAM = false;
	if (document.theform.FormSubmitter.value.indexOf('http')>=0){
		SPAM = true;
		alert('FormSubmitter field should not contain a web site address.');
	}
	if (document.theform.OtherInfo.value.indexOf('http')>=0){
		SPAM = true;
		alert('OtherInfo field should not contain a web site address.');
	}
	if (SPAM == false){
		var req = validation();
		if (req == true){
			return true;
		}else{
			return false;	
		}
	}else{
		alert("Your submission appears to be SPAM. Please eliminate unneeded web addresses and resubmit.");
		return false;
	}
}

