function checkEmail (emailStr) {
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 false;
}
var user=matchArray[1];
var domain=matchArray[2];

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    
    return false;
}

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 false;
	    }
    }
    return true;
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
    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>3) {
   // the address must end in a two letter or three letter word.
   return false;
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   return false;
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->



function validatePullDown(theForm, fieldName, errName)
{
  // If the field selected is (still) the first (blank) one ...
	// if (eval("theForm."+fieldName+".selectedIndex == 0"))
	if (document.getElementById(fieldName).selectedIndex == 0)
  {
    alert("Please select "+errName+".");
    eval("theForm."+fieldName+".focus()");
    return false;
  }
  return true;
}

// Generic function to validate a radio button set. 
// Needs the error name because field names aren't always meaningful to user. 
function validateRadio(theForm, numOptions, fieldName, errName)
{
  for (i=0;i<numOptions;i++)
  {
    if (eval("theForm."+fieldName+"["+i+"].checked") == true) 
    {
      return true;
    }
  }
  alert("Please select "+errName+".");
  return false;
}

// Generic function to validate a check box. 
// Needs the error name because field names aren't always meaningful to user. 
function validateCheck(theForm, fieldName, errName)
{
  if (eval("theForm."+fieldName+".checked") == false) 
  {
    alert("Please enter "+errName+".");
    eval("theForm."+fieldName+".focus()");
    return false;
  }
  return true;
}

// Generic function to validate a text field. 
// Needs the error name because field names aren't always meaningful to user. 
function validateText(theForm, fieldName, theValue, errName)
{
  if (eval("theForm."+fieldName+".value == \'"+theValue+"\'")) 
  {
    //alert("theForm."+fieldName+".value == \'"+theValue+"\'");
    alert("Please enter "+errName+".");
    eval("theForm."+fieldName+".focus()");
    return false;
  }
  return true;
}

function validateEmail(theForm, fieldName, theValue, errName)
{
  if (!checkEmail(eval("theForm."+fieldName+".value"))) 
  {
    alert("Please enter a valid "+errName+".");
    eval("theForm."+fieldName+".focus()");
    return false;
  }
  return true;
}
