<!--
//===========================================================
//call the function with the onSubmit event handler
//and indicate the fields to validate as well
//as the text to appear in the alert box if
//it is left blank.
//
//The validate property should be set to true to validate
//an item. The msg property should be set to a string value
//enclosed in single quotes.
//
//Radio buttons should be referenced by their 0 index.
//
//Example:
//onSubmit="
//this.first_name.validate = true;
//this.first_name.msg = 'First Name';
//this.radiobutton[0].validate = true;
//this.radiobutton[0].msg = 'Radio Choice';
//return validate(this)";
//===========================================================

function isBlank(s) {
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function validate(f,msg) {
	var errors = 0;
	var message = "Please correct the following and re-submit:\n\n"
	var bolVal;
	var type;

	for (i = 0; i < f.elements.length; i++) {

		if(f.elements[i].validate) {
			type = f.elements[i].type;

			if (type == "text" || type == "password" || type == "file") {
				if(isBlank(f.elements[i].value)) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			else if (type == "textarea") {
				if(isBlank(f.elements[i].value)) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			else if (type == "select-one") {
				if(f.elements[i].selectedIndex == 0) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			else if (type == "select-multiple") {
				var radioName = f.elements[i].name;
				chk = 0;
				for (j = 0; j < eval("f." + radioName).length; j++) {
					if(eval("f." + radioName)[j].selected) {
						chk++;
					}
				}
				if(chk == 0) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			else if (type == "radio") {
				var radioName = f.elements[i].name;
				chk = 0;
				for (j = 0; j < eval("f." + radioName).length; j++) {
					if(eval("f." + radioName)[j].checked) {
						chk++;
					}
				}
				if(chk == 0) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			else if (type == "checkbox") {
				var checkName = f.elements[i].name;
				chk = 0;
				for (j = 0; j < eval("f." + checkName).length; j++) {
					if(eval("f." + checkName)[j].checked) {
						chk++;
					}
				}
				if(chk == 0) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			//else if (type == "checkbox") {
			//	if(!f.elements[i].checked) {
			//		message += "Please supply a value for " + f.elements[i].msg + "\n";
			//		errors++;
			//	}
			//}
		}
	}

	msg = msg + "";
	if (msg != "undefined") {
		message += msg;
		errors++;
	}

	if (errors > 0) {
		alert(message);
		return false;
	}

	return true;
}

//-->
