function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}	

function setFocusDelayed()
	{
	  global_valfield.focus();
	}

function setfocus(valfield)
{
  // save valfield in global variable so value retained when routine exits
  global_valfield = valfield;
  setTimeout( 'setFocusDelayed()', 100 );
}

function validateEmail  (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  //var stat = commonCheck (valfield, infofield, required);
  //if (stat != proceed) return stat;

  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
  if (!email.test(tfld)) {
    //msg (infofield, "error", "ERROR: not a valid e-mail address");
    alert("Error: not a valid email address.")
    setfocus(valfield);
    return false;
  }

  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/  ;
  if (!email2.test(tfld)) 
    //msg (infofield, "warn", "Unusual e-mail address - check if correct");
    alert("Unusual e-mail address - check if correct");
  else
    //msg (infofield, "warn", "");
  return true;
}

