function trim ( inputStringTrim ) {
  fixedTrim = "";
  lastCh = " ";
  for (x=0; x < inputStringTrim.length; x++) {
    ch = inputStringTrim.charAt(x);
    if ((ch != " ") || (lastCh != " ")) {
     fixedTrim += ch;
    }
  lastCh = ch;
  }
  if (fixedTrim.charAt(fixedTrim.length - 1) == " ") {
    fixedTrim = fixedTrim.substring(0, fixedTrim.length - 1);
  }
  return fixedTrim;
}

function Validator(theForm)
{

  if (theForm.a0010_Name.value == "")
  {
    alert("Please enter a value for the \"Name\" field.");
    theForm.a0010_Name.focus();
    return (false);
  }

  if (theForm.a0010_Name.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Name\" field.");
    theForm.a0010_Name.focus();
    return (false);
  }

  if (theForm.a0010_Name.value.length > 40)
  {
    alert("Please enter at most 40 characters in the \"Name\" field.");
    theForm.a0010_Name.focus();
    return (false);
  }

  if (theForm.a0090_Email.value == "")
  {
    alert("Please enter a value for the \"E-mail\" field.");
    theForm.a0090_Email.focus();
    return (false);
  }

  if (theForm.a0090_Email.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"E-mail\" field.");
    theForm.a0090_Email.focus();
    return (false);
  }

  if (theForm.a0090_Email.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"E-mail\" field.");
    theForm.a0090_Email.focus();
    return (false);
  }

    var emailad = trim(theForm.a0090_Email.value);
		var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,3}$/;

		if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1))
		{
			alert ("Email is invalid. Please enter a       \nvalid email address.");
			theForm.a0090_Email.focus();
			return false;
		}


  return (true);
}
