
<!--
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 WAValidateZC(formElement,errorMsg,us5,us9,can6,uk,reformat,focusIt,stopIt,required)  {
  var value = formElement.value;
  var isValid = true;
  var allowed = "() -.\n\r";
  var hasLetters = false;
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value==""))  {
    var newVal = "";
    var charVal = "";
    for (var x=0; x<value.length; x++)  {
      var z = value.charAt(x);
      if ((z >= "0") && (z <= "9")) {
        newVal += z;
        charVal += "N";
      }
      else  {
        if ((uk || can6) && ((z >= "a") && (z <= "z")) || ((z >= "A") && (z <= "Z"))) {
          charVal += "A";
          hasLetters = true;
        }
        else if (allowed.indexOf(z) < 0 || x==0 || x == value.length-1)  {
          isValid = false;
        }
      }
    }
    if ((uk || can6) && hasLetters)  {
      var acceptPattern = "";
      if (uk)  {
        acceptPattern += ",ANNAA,ANNNAA,AANNAA,AANNNAA,ANANAA,AANANAA,";
      }
      if (can6)  {
        acceptPattern += ",ANANAN,";
      }
      if (String(acceptPattern).indexOf(","+charVal+",") < 0)
        isValid = false;
    }
    if (!((uk && (charVal.length >= 5 &&  charVal.length <= 8)) || (us5 && newVal.length == 5) || (us9 && newVal.length == 9) || (can6 && charVal.length == 6)))  {
      isValid = false;
    }
    if (isValid && !hasLetters && (us5 || us9)) {
      if (us5) {
        isValid = (value.search(/^\d{5}$/) == 0);
      }
      if (us9 && ((us5 && !isValid) || !us5)) {
        isValid = ((value.search(/^\d{5}[-\. ]\d{4}$/) == 0) || (value.search(/^\d{9}$/) == 0));
      }
    }
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
  else  {
    if (reformat != "")  {
      if (reformat != "t")  {
        for (var x=0; x<newVal.length; x++)  {
          reformat = reformat.substring(0,reformat.indexOf("x")) + newVal.charAt(x) + reformat.substring(reformat.indexOf("x")+1);
        }
        if (reformat.indexOf("x")>=0)  {
          reformat = reformat.substring(0,reformat.indexOf("x"));
          while (reformat.charAt(reformat.length-1) == " " || reformat.charAt(reformat.length-1) == "-")
            reformat = reformat.substring(0,reformat.length-1);
          z = reformat.charAt(reformat.length-1);
        }
        if (newVal.length==6)
          reformat = reformat.replace(/-/,"");
      }
      else  {
        newVal = formElement.value;
        while (newVal.charAt(0) == " ")
          newVal = newVal.substring(1);
        while (newVal.charAt(newVal.length-1) == " ")
          newVal = newVal.substring(0,newVal.length-1);
        reformat = newVal;
      }
      formElement.value = reformat;
    }
  }
}
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)  {
		  if (document.getElementById(document.WAFV_Focus.name+"___Config") && document.WAFV_Focus.type.toLowerCase() == "hidden")  {
	        var theEditor = FCKeditorAPI.GetInstance(document.WAFV_Focus.name);
		    theEditor.EditorWindow.focus();
			setTimeout("setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1); 
		  }
		  else  {
		    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;
  }
}
//-->
