function trim(s) {
	return s.replace( /^\s+/, "" ).replace( /\s+$/, "" ) ;
}
function validateForm(f) {
   var textfields = [
	   [ "first", "First Name", true ],
	   [ "last", "Last Name", true ],
	   [ "email", "E-mail", true ],
	   [ "institution", "Institution", true ],
	   [ "reason", "Reason", true ]
	] ;
	var adtlfields = [
	   [ "title", "Title", true ],
	   [ "phone", "Phone", true ],
	   [ "deanname", "Dean's Name", true ],
	   [ "deanphone", "Dean's Phone", true ],
	   [ "deanemail", "Dean's E-mail", true ],
	   [ "deanaddress", "Dean's Address", true ]
	] ;
	var selects = [
	   [ "status", "Status/Occupation" ]
	] ;
	var i ;
	var missing = "" ;
	// check the normal access fields
	for ( i = 0 ; i < textfields.length ; ++i ) {
		// trim the fields
		f.elements[textfields[i][0]].value = trim(f.elements[textfields[i][0]].value) ;
		if ( textfields[i][2] && f.elements[textfields[i][0]].value == "" ) missing += textfields[i][1] + "\n" ;
	}
	// check the mandatory select inputs
	for ( i = 0 ; i < selects.length ; ++i ) {
		if ( f.elements[selects[i][0]].selectedIndex == 0 ) missing += selects[i][1] + "\n" ;
	}
	// if teaching notes were requested, check the additional fields
	if ( f.teachingnotes.selectedIndex == 1 ) {
		// trim the text fields
		for ( i = 0 ; i < adtlfields.length ; ++i ) {
			f.elements[adtlfields[i][0]].value = trim(f.elements[adtlfields[i][0]].value) ;
			if ( adtlfields[i][2] && f.elements[adtlfields[i][0]].value == "" ) missing += adtlfields[i][1] + "\n" ;
		}
	}
	if ( missing != "" ) {
		alert( "The form is incomplete.  The following mandatory fields were left empty:\n\n" + missing ) ;
		return false ;
	}
	return true;
}
function toggleDisplay(id,tv) {
	if (document.all) {
		if(tv==1) document.all[id].style.display = "";
		else document.all[id].style.display = "none";
	} else {
		if(tv==1) document.getElementById(id).style.display = "block";
		else document.getElementById(id).style.display = "none";
	}
}
