function submitForm(form) {
       if (checkIt(form)) {
         form.submit();
       }
      }
      function checkIt(form) {
      form.question.value = win2unicode(form.question.value);
      var email = form.email.value;
      var question = form.question.value;
      var lib;
      var msg = '';
	 
      if (form.library.selectedIndex >= 0) {
                lib = form.library.options[form.library.selectedIndex].value;
        }
      if (lib == null) {
                lib=form.library.value;
        }      
      
      if(email.length < 1) {
      if(msg.length > 0)
      msg+=', ';
      msg += 'Email Address';
      }
      
      if(question.length < 1) {
      if(msg.length > 0)
      msg+=', ';
      msg += 'Question';
      }
      
      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)) {      
      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

		musExp = /.museum/
		isMus = domain.search(musExp)
		
		if ( ( (domArr[domArr.length-1].length < 2) || (domArr[domArr.length-1].length > 6) ) ||
			(domArr[domArr.length-1].length == 5) ||
			( (domArr[domArr.length-1].length == 6) && (isMus == -1) ) ) {
		   // the address must end in a two, three, or four letter word, or .museum.
			  if (alertflag) 		
		   		alert("Your e-mail address must end in a three or four-letter domain,\ntwo-letter 		country code, or .museum.")
		   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;
}

function win2unicode(str) {
   var charmap   = unescape(
      "%u0402%u0403%u201A%u0453%u201E%u2026%u2020%u2021%u20AC%u2030%u0409%u2039%u040A%u040C%u040B%u040F"+
      "%u0452%u2018%u2019%u201C%u201D%u2022%u2013%u2014%u0000%u2122%u0459%u203A%u045A%u045C%u045B%u045F"+
      "%u00A0%u040E%u045E%u0408%u00A4%u0490%u00A6%u00A7%u0401%u00A9%u0404%u00AB%u00AC%u00AD%u00AE%u0407"+
      "%u00B0%u00B1%u0406%u0456%u0491%u00B5%u00B6%u00B7%u0451%u2116%u0454%u00BB%u0458%u0405%u0455%u0457")
   var code2char = function(code) {
               if(code >= 0xC0 && code <= 0xFF) return String.fromCharCode(code - 0xC0 + 0x0410)
               if(code >= 0x80 && code <= 0xBF) return charmap.charAt(code - 0x80)
               return String.fromCharCode(code)
            }
   var res = ""
   for(var i = 0; i < str.length; i++) res = res + code2char(str.charCodeAt(i))
   return res
}

function submitQuestion(form) {
   form.andk.value = win2unicode(form.andk.value);
  form.submit();
}
