 function WAAddError(formElement,errorMsg,focusIt,stopIt)  {
  if (document.WAFV_Error)  {
          document.WAFV_Error += "\n" + errorMsg;
  }
  else  {
    document.WAFV_Error = errorMsg;
  }
  if (!document.WAFV_InvalidArray)  {
    document.WAFV_InvalidArray = new Array();
  }
  document.WAFV_InvalidArray[document.WAFV_InvalidArray.length] = formElement;
  if (focusIt && !document.WAFV_Focus)  {
        document.WAFV_Focus = focusIt;
  }

  if (stopIt == 1)  {
        document.WAFV_Stop = true;
  }
  else if (stopIt == 2)  {
        formElement.WAFV_Continue = true;
  }
  else if (stopIt == 3)  {
        formElement.WAFV_Stop = true;
        formElement.WAFV_Continue = false;
  }
}

function WAValidateAN(formElement,value,errorMsg,allowUpper,allowLower,allowNumbers,allowSpace,extraChars,focusIt,stopIt,required)  {
  var isValid = true;
  extraChars = extraChars.replace(/&quot;/g,'"');
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) || formElement.WAFV_Continue)  {
    for (var x=0; x<value.length; x++)  {
          var charGood = false;
          var nextChar = value.charAt(x);
          var charCode = value.charCodeAt(x);
          if (allowLower)  {
            if (charCode >= 97 && charCode <= 122)  {
                  charGood = true;
                }
          }
          if (allowUpper)  {
            if (charCode >= 65 && charCode <= 90)  {
                  charGood = true;
                }
          }
          if (allowNumbers)  {
            if (charCode >= 48 && charCode <= 57)  {
                  charGood = true;
                }
          }
          if (allowSpace)  {
            if (nextChar == " ")  {
                  charGood = true;
                }
          }
          if (extraChars)  {
            if (unescape(extraChars).indexOf(nextChar) >= 0)  {
                  charGood = true;
                }
          }
          if (!charGood)  {
            isValid = false;
                x = value.length;
          }
        }
        if (required && value=="")
          isValid = false;
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}

function WAAlertErrors(errorHead,errorFoot,setFocus,submitForm)  {
  if (!document.WAFV_StopAlert)  {
          document.WAFV_StopAlert = true;
          if (document.WAFV_InvalidArray)  {
            document.WAFV_Stop = true;
        var errorMsg = document.WAFV_Error;
            if (errorHead!="")
                  errorMsg = errorHead + "\n" + errorMsg;
                if (errorFoot!="")
                  errorMsg += "\n" + errorFoot;
                document.MM_returnValue = false;
                if (document.WAFV_Error!="")
                  alert(errorMsg.replace(/&quot;/g,'"'));
                else if (submitForm)
                  submitForm.submit();
            if (setFocus && document.WAFV_Focus)  {
                  document.tempFocus = document.WAFV_Focus;
          setTimeout("document.tempFocus.focus();setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1);
        }
        else {
          document.WAFV_Stop = false;
          document.WAFV_StopAlert = false;
        }
        for (var x=0; x<document.WAFV_InvalidArray.length; x++)  {
              document.WAFV_InvalidArray[x].WAFV_Stop = false;
            }
          }
          else  {
        document.WAFV_Stop = false;
        document.WAFV_StopAlert = false;
            if (submitForm)  {
              submitForm.submit();
            }
            document.MM_returnValue = true;
          }
      document.WAFV_Focus = false;
          document.WAFV_Error = false;
          document.WAFV_InvalidArray = false;
  }
}
