function AddFormError (sFormErrors, sNewError)
{
  if (!sFormErrors.length) return "Errors in Form:\n\n" + sNewError ;
  else return sFormErrors + "\n" + sNewError ;
}

function Enter2Tab (eEvent, oNextField, bSelect)
{
  if ((eEvent.keyCode ? eEvent.keyCode : eEvent.which ? eEvent.which : eEvent.charCode) == 13)
  {
    oNextField.focus () ;
    if (bSelect) oNextField.select () ;
    return false ;
  }

  return true ;
}

function SubmitContactForm (oForm)
{
  var sFormErrors = "" ;

  var sRegEx_Generic_SingleLine = /^.{1,128}$/  ;
  var sRegEx_Generic_MultiLine  = /^[\s\S]{1,4096}$/ ;

  var sRegEx_Email =
   /^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/ ;

  if (!oForm.Contact_Name.value.length) sFormErrors =
   AddFormError (sFormErrors, "- Please enter your Name.") ;
  else
  {
    if (!sRegEx_Generic_SingleLine.test (oForm.Contact_Name.value)) sFormErrors =
     AddFormError (sFormErrors, "- Field 'Your Name' cannot contain more than 128 characters.") ;
  }

  if (!oForm.Contact_Email.value.length) sFormErrors =
   AddFormError (sFormErrors, "- Please enter your E-mail.") ;
  else
  {
    if (!sRegEx_Email.test (oForm.Contact_Email.value)) sFormErrors =
     AddFormError (sFormErrors, "- Invalid E-mail format.") ;
    else
    {
      if (oForm.Contact_Email2.value != oForm.Contact_Email.value) sFormErrors = AddFormError
       (sFormErrors, "- E-mails do not match. Please review 'Your E-mail' and '(Confirm) E-mail'.") ;
    }
  }

  if (!oForm.Contact_Subject.value.length) sFormErrors =
   AddFormError (sFormErrors, "- Please enter a Subject for your request.") ;
  else
  {
    if (!sRegEx_Generic_SingleLine.test (oForm.Contact_Subject.value)) sFormErrors =
     AddFormError (sFormErrors, "- Field 'Subject' cannot contain more than 128 characters.") ;
  }

  if (!oForm.Contact_Text.value.length) sFormErrors =
   AddFormError (sFormErrors, "- Please write your request into the field 'Text'.") ;
  else
  {
    if (!sRegEx_Generic_MultiLine.test (oForm.Contact_Text.value)) sFormErrors =
     AddFormError (sFormErrors, "- Field 'Text' cannot contain more than 4,096 characters.") ;
  }

  if (!sFormErrors.length) return true ;

  alert (sFormErrors) ;
  return false ;
}
