<!--
      function submitForm(form) {
       if (checkIt(form)) {
         form.submit();
       }
      }
      function checkIt(form) {
	  //variables that store contents of e-mail address and question fields for validation
	  //Create a variable like these for each text or textarea field that you want to require patron to complete
	  //Then add a check for the contents of the variable where indicated (see "Make sure the E-mail address
	  // contains some data" for an example)
      var email = form.email.value;
	  var email2 = form.field5.value;
      var question = form.question.value;
      var lib;
	  //variable that contains contents of message to display to patron if required field(s) are blank
      var msg = '';
	 
      if (form.library.selectedIndex >= 0) {
                lib = form.library.options[form.library.selectedIndex].value;
        }
      if (lib == null) {
                lib=form.library.value;
        }
     
	  // Make sure the E-mail address field contains some data
      if(email.length < 1) {
      if(msg.length > 0)
      msg+=', ';
      msg += 'E-mail address';
      }
      
	  // Make sure the Confirm e-mail address field contains some data
      if(email2.length < 1) {
      if(msg.length > 0)
      msg+=', ';
      msg += 'Confirm e-mail address';
      }
      
	  //Make sure the Question field contains some data
      if(question.length < 1) {
      if(msg.length > 0)
      msg+=', ';
      msg += 'Question';
      }
      
	  //Make sure Reason for research has been selected
	  //Use this as a prototype for validating other drop-down list fields
	  if (form.field3.selectedIndex == 0) {
		if (msg.length >0) 
  			msg+= ', ';
 	  msg += 'Reason for research';
	  }
	  
	  //Make sure "May we forward your question..." has been answered
	  //Use this as a prototype for validating other radio button fields
	  for (i=0, n=form.field4.length; i<n; i++) {
   		if (form.field4[i].checked) {
      		var checkvalue = form.field4[i].value;
      	break;
        }
	  }
	  if (!(checkvalue)) {
	  	if (msg.length >0)
			msg+= ', ';
		msg += 'May we forward your question?';
	   }
	   
	  //Display alert box for patron; he/she left at least one required field blank
      if (msg != '')
      {
      alert("One or more required fields are blank\r\n" + msg);
      return false;
      }
    
      if(lib.length < 1) {
      alert("The library supplying this form has an error in the form. Please contact them and alert them to the problem\r\n");
      return false;
      }
	  
      if (emailCheck(email, true)) { 
	  //the next four lines only apply to forms with a confirmation e-mail field. Remove or comment
	  //them out if you do not need them or the script will not run properly.
	  	if 	(email != email2) {
    		alert("Check the e-mail address and confirmation e-mail address. They do not match.")
    		return false;	  
		}
	  //end e-mail confirmation check
      return true;
      }
  
	  else {
      return false;
      }
      }

function emailCheck (emailStr, alertflag) {

var emailPat=/^(.+)@(.+)$/		

var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'

var word="(" + atom + "|" + quotedUser + ")"

var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
        if (alertflag)
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
     if (alertflag) 
    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
      if (alertflag)
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
      if (alertflag)
	alert("The domain name doesn't seem to be valid.")
    return false
}


var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>4) {
   // the address must end in a two, three, or four letter word.
      if (alertflag) 
   alert("The address must end in a three or four-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
      if (alertflag) 
   alert(errStr)
   return false
}


// If we've gotten this far, everything's valid!
return true;
}

//-->
