function noText(thisElement) {
 // Validate text boxes and textarea
 if (gobbleWhiteSpace(thisElement.value)) {
  return false;
 }
 return true;
}

function nothingSelected(thisElement) {
 // Validate single and multiple drop down boxes
 if(thisElement.options.type == 'select-one') {
  if (thisElement.options[thisElement.options.selectedIndex].value &&
      thisElement.options[thisElement.options.selectedIndex].value != 0) {
   return false;
  }
 } else if(thisElement.options.type == 'select-multiple') {
  for (var x=0;x<thisElement.options.length;x+=1){
   if (thisElement.options[x].selected && thisElement.options[x].value &&
       thisElement.options[x].selected && thisElement.options[x].value != 0) {
    return false;
   }
  }
 } else {
  // Netscape 6.x doesn't recognize options.type, so just check values
  if (thisElement.options[thisElement.options.selectedIndex].value &&
      thisElement.options[thisElement.options.selectedIndex].value != 0) {
   return false;
  }
 }
 return true;
}

function nothingChecked(thisElement) {
 OnlyOneItemInList = true;
 // Validate radio buttons and checkboxes
 for (var x=0;x<thisElement.length;x+=1){
  if (thisElement[x].checked) {
   return false;
  }
  OnlyOneItemInList = false;
 }
 if (OnlyOneItemInList && thisElement.checked) {
  return false;
 }
 return true;
}

function gobbleWhiteSpace(textstring){
 // Get rid of whitespace from both ends of text string
 var lastChar, counter=0;
 var whiteSpaceChars = " \n\r\f\t";

 //gobble whitespace from beginning of string
 while ( textstring && whiteSpaceChars.indexOf( textstring.charAt(0) ) !=  -1 ){
  textstring = textstring.substring(1);
 }

 //gobble whitespace from end of string
 lastChar = textstring.length-1;
 while ( textstring && whiteSpaceChars.indexOf( textstring.charAt(lastChar) ) != -1 ){
  textstring = textstring.substring(0,lastChar--);
 }
 return textstring;
}

function emailCheck (emailStr) {
 // Validate an email address format
 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) {
  return "\tEmail address -- seems incorrect (check @ and .'s)\n";
 }

 var user = matchArray[1]
 var domain = matchArray[2]
 // See if "user" is valid
 if (user.match(userPat)==null) {
  // user is not valid
  return "\tEmail address -- username doesn't seem to be valid.\n";
 }

 var IPArray=domain.match(ipDomainPat)
 if (IPArray!=null) {
  // this is an IP address
  for (var i=1;i<=4;i++) {
   if (IPArray[i]>255) {
    return "\tEmail address -- Destination IP address is invalid!\n";
   }
  }
  return "";
 }

 // Domain is symbolic name
 var domainArray=domain.match(domainPat)
 if (domainArray==null) {
  return "\tEmail address -- domain name doesn't seem to be valid.\n";
 }

 /* domain name seems valid, but now make sure that it ends in a
    three-letter word (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding
    the domain or country. */
 /* Now we need to break up the domain to get a count of how many atoms
    it consists of. */
 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>3) {
  // the address must end in a two letter or three letter word.
  return "\tEmail address -- must end in a three-letter domain, or two letter country code.\n";
 }

 // Make sure there's a host name preceding the domain.
 if (len<2) {
  return "\tEmail address -- missing a hostname!\n";
 }
 return "";
}
