// Form Validation
// Obtained from www.webcheatsheet.com
// Modified by Curt Siters to give it more flexibility

		function validateFormOnSubmit() {

			var reason = "";
			var returnval = false;
		  	reason += validateEmpty(document.getElementById('fname'), "your first name");
		  	reason += validateEmpty(document.getElementById('lname'), "your last name");
		  	reason += validateEmail(document.getElementById('email'));
		  	reason += validateEmpty(document.getElementById('comments'), "your comments");

			if (reason=="") {
				returnval = true;
				return returnval;
			} else {
				var element = document.getElementById('warnings');
        		warnings.innerHTML = warnings.innerHTML + reason;
        		warnings.style.display = 'block';
				warnings.style.fontsize = "7px";
				returnval = false;
				return returnval;
			}
			return returnval;
		}



		function validateEmpty(fld, word) {
			var error = "";
				if ((fld.value.length == 0) || (fld.value == "") || (fld.value == null) || (fld.length == 0)) {
						fld.style.backgroundColor = '#f5f179'; 
						fld.style.border='red';
						var field_name = "";
						var char_match = /_/g;
						var char_replace = " ";
						field_name = fld.name.replace(char_match, char_replace);
						error = "\t" + "You didn't enter  " + word +".<br />"
//						error = "You didn't enter your " + fld.name +".\n"
						} else {
						fld.style.background = 'White';
				}
				return error;   
			}



		function trim(s)
		{
		  return s.replace(/^\s+|\s+$/, '');
		} 
		
		function validateEmail(fld) {
			var error="";
			var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
			var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
			var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

			if (fld.value == "") {
					fld.style.background = '#f5f179'; 
					fld.style.border='red';
				error ="\t" + "You didn't enter your email address.<br />";
			} else if (!fld.value.match(emailFilter)) {              //test email for illegal characters
					fld.style.background = '#f5f179'; 
					fld.style.border='red';
				error ="\t" +  "Please enter a valid email address.<br />";
			} else if (fld.value.match(illegalChars)) {
					fld.style.background = '#f5f179'; 
					fld.style.border='red';
				error = "\t" + "Your email address contains illegal characters.<br />";
			} else {
				fld.style.background = 'White';
			}
			return error;
		}
