﻿function Form_Validator(theForm)
{

  if (theForm.Anrede.value == "")
  {
    alert("Please enter a value for the \"Anrede\" field.");
    theForm.Anrede.focus();
    return (false);
  }

  if (theForm.Anrede.value.length > 256)
  {
    alert("Please enter at most 256 characters in the \"Anrede\" field.");
    theForm.Anrede.focus();
    return (false);
  }

  if (theForm.Vorname.value == "")
  {
    alert("Please enter a value for the \"Vorname\" field.");
    theForm.Vorname.focus();
    return (false);
  }

  if (theForm.Vorname.value.length > 256)
  {
    alert("Please enter at most 256 characters in the \"Vorname\" field.");
    theForm.Vorname.focus();
    return (false);
  }

  if (theForm.Name.value == "")
  {
    alert("Please enter a value for the \"Name\" field.");
    theForm.Name.focus();
    return (false);
  }

  if (theForm.Name.value.length > 256)
  {
    alert("Please enter at most 256 characters in the \"Name\" field.");
    theForm.Name.focus();
    return (false);
  }

  if (theForm.Firma.value == "")
  {
    alert("Please enter a value for the \"Firma\" field.");
    theForm.Firma.focus();
    return (false);
  }

  if (theForm.Firma.value.length > 256)
  {
    alert("Please enter at most 256 characters in the \"Firma\" field.");
    theForm.Firma.focus();
    return (false);
  }

  if (theForm.EMail.value == "")
  {
    alert("Please enter a value for the \"EMail\" field.");
    theForm.EMail.focus();
    return (false);
  }

  if (theForm.EMail.value.length < 8)
  {
    alert("Please enter at least 8 characters in the \"EMail\" field.");
    theForm.EMail.focus();
    return (false);
  }

  if (theForm.EMail.value.length > 256)
  {
    alert("Please enter at most 256 characters in the \"EMail\" field.");
    theForm.EMail.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.@";
  var checkStr = theForm.EMail.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, digit and \".@\" characters in the \"EMail\" field.");
    theForm.EMail.focus();
    return (false);
  }
  return (true);
}
