// -- ---------------------------------------------------------------------------
// -- %MODULE:
// -- clsValidation.js
// -- ---------------------------------------------------------------------------
// --
// -- %DESCRIPTION:
// -- RinkerNet Form Submit Validation Script Include
// --
// -- %AUTHOR:
// -- EDS
// --
// -- %COPYRIGHT:
// -- Copyright (c) 2006 Electronic Data Systems. All Rights Reserved.
// --
// -- ---------------------------------------------------------------------------
// --

// -- -------------------------------------------------------------
// -- C O N T R O L   C O N S T A N T S
// -- -------------------------------------------------------------
var doDebug							= true;

// -- -------------------------------------------------------------
// -- validation constants
// -- -------------------------------------------------------------
var vbCrLf							= "\r\n";

var vbOKOnly           				= 0;
var vbOKCancel         				= 1;
var vbAbortRetryIgnore 				= 2;
var vbYesNoCancel      				= 3;
var vbYesNo            				= 4;
var vbRetryCancel      				= 5;

var vbOK      						= 1;
var vbCancel  						= 2;
var vbAbort   						= 3;
var vbRetry   						= 4;
var vbIgnore  						= 5;
var vbYes     						= 6;
var vbNo      						= 7;

var	vbCritical     					= 16;
var	vbQuestion     					= 32;
var	vbExclamation  					= 48;
var	vbInformation  					= 64;

var cvaldtnERR_SRC 					= "CVLDTN";

var cvaldtnVALD_LETTER_DIGIT 		= "^[A-Za-z0-9]+$";
var cvaldtnVALD_LETTER_DIGIT_SPACE 	= "^[A-Za-z0-9 ]+$";
var cvaldtnVALD_NUMERIC 			= "^[0-9 ]+$";

var cvaldtnVALD_NAME 				= "^[A-Za-z0-9]+[A-Za-z0-9 \-'\.]+$";
var cvaldtnVALD_NAME_MSG_SUFX 		= " is required and may contain only letters, numbers, spaces, single quotes('), periods(.), and dashes(-).";

var cvaldtnVALD_PHONE 				= "^[0-9\-\+\(\) ]+$";
// -- var cvaldtnVALD_EMAIL 				= "^[A-Za-z0-9_\-]+@[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+[A-Za-z0-9_\.\-]*$";
var cvaldtnVALD_EMAIL 				= "^[\:A-Z\.a-z0-9_\-]+@[\:A-Z\.a-z0-9_\-]+\.[A-Za-z0-9_\-]+[A-Za-z0-9_\.\-]*$";
//-- var cvaldtnEMAIL1 					= "[A-Za-z0-9_\-]+@[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+[A-Za-z0-9_\-\.]*";
var cvaldtnEMAIL1 					= "[A-Za-z0-9_\-]+@[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+[A-Za-z0-9_\-\.]*";
var cvaldtnVALD_EMAIL_PREFIX 		= "^[A-Za-z0-9_\-]+$";
var cvaldtnVALD_DD_SELECTION 		= "^[^#].*$";

var cvaldtnVALD_12HR_TIME 			= "^((1[012])|([1-9])):[0-5][0-9]$";

// -- -------------------------------------------------------------
// -- this give -40 < temp < 130
// -- -------------------------------------------------------------
var cvaldtnVALD_DEGREES_F 			= "^((1[012][0-9])|([1-9]{0,1}[0-9])|(\-[123][0-9]|(-[1-9])))$";


// -- -------------------------------------------------------------
// -- refer to the first public methods for more field validations
// --
// --	VALD_ATLEASTx_NONBLANK_CHARS (x)
// --	VALD_ATLEASTx_ATMOSTy_NONBLANK_CHARS (x,y)
// --   VALD_ATLEASTx_ATMOSTy_NUMBERS
// -- -------------------------------------------------------------
var cvaldtnDFLT_FORM_ID         = "theForm";
var cvaldtnDFLT_VALUE_SEPARATOR = "<COMMA/>";
var cvaldtnDFLT_ERR_TITLE       = "INPUT ERROR!";
var cvaldtnDFLT_ERR_PROMPT_TOP  = "Error in input.  Please correct the errors indicated below and resubmit the form.";
var cvaldtnDFLT_ERR_PROMPT_BOT  = "";
var cvaldtnDFLT_DO_ALERT        = true;
var cvaldtnDFLT_DO_SHOWBTN      = false;
var cvaldtnDFLT_DLG_URL         = "/sinclude/asp/dlgAlert2.asp";

var cvaldtnDFLT_DLG_BTN         = 0;
var cvaldtnDFLT_DLG_IMG_TOP     = 48;
var cvaldtnDFLT_DLG_IMG_BOT     = 0;

var cvaldtnDFLT_DLG_WIDTH       = "400px";
var cvaldtnDFLT_DLG_HEIGHT      = "250px";

var cvaldtnDFLT_DLG_ORNAMENTS 	= " help:no; status:yes; resizable:yes";
var cvaldtnDFLT_ERRS_DIVNAME	= "divValdtnErrs";


// -- -------------------------------------------------------------
// -- ALERT DIALOG WINDOW
// -- -------------------------------------------------------------
var cvaldtnNumDlgArgs = 8;

// -- -------------------------------------------------------------
// -- indexes into input/output arg arrays
// -- -------------------------------------------------------------
// -- input and output (for dialog)
// -- -------------------------------------------------------------
var cvaldtnIdxWinLocn       = 0;
var cvaldtnIdxBtn           = 1; // -- which button(s) to display

// -- -------------------------------------------------------------
// -- which button pressed: uses the same return values
// --  as the msgbox function:
// -- -------------------------------------------------------------
// -- ----------------
// -- IN INPUT ARRAY
// -- ----------------
// -- vbOKOnly           0 Display OK button only.
// -- vbOKCancel         1 Display OK and Cancel buttons.
// -- vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons.
// -- vbYesNoCancel      3 Display Yes, No, and Cancel buttons.
// -- vbYesNo            4 Display Yes and No buttons.
// -- vbRetryCancel      5 Display Retry and Cancel buttons.

// -- ----------------
// -- IN OUTPUT ARRAY
// -- ----------------
// --         0 No button clicked
// --vbOK     1 OK button was clicked.
// --vbCancel 2 Cancel button was clicked.
// --vbAbort  3 Abort button was clicked.
// --vbRetry  4 Retry button was clicked.
// --vbIgnore 5 Ignore button was clicked.
// --vbYes    6 Yes button was clicked.
// --vbNo     7 No button was clicked


// -- -------------------------------------------------------------
// -- indexing
// -- -------------------------------------------------------------
var cvaldtnIdxImgTop         = 2; 	// -- which image to display: values same as msgbox:
										  // --             0 no icon
									// --vbCritical    16 Display Critical Message icon.
									// --vbQuestion    32 Display Warning Query icon.
									// --vbExclamation 48 Display Warning Message icon.
									// --vbInformation 64 Display Information Message icon.

var cvaldtnIdxImgBot         = 3; 	// -- which image to display: values same as msgbox:
var cvaldtnIdxMsgs           = 4; 	// -- array of messages to display

// -- -------------------------------------------------------------
// -- input to dialog
// -- -------------------------------------------------------------
var cvaldtnIdxDlgTitle       = 5;
var cvaldtnIdxDlgPromptTop   = 6;
var cvaldtnIdxDlgPromptBot   = 7;

var cvaldtnSendArray = new Array("", 0, 0, 0, "", "", "", "");
var cvaldtnRetnArray = new Array("", 0, 0, 0, "", "", "", "");

// -- provide scroll-to ability
function scrollToNextLocn (sEleId) {
  // alert ('ScrollTo:  ' + sEleId);
  var oEle = document.getElementById(sEleId);

  var iX = 0;
  var iY = 0;

  while (oEle != null) {
	 iX += oEle.offsetLeft;
	 iY += oEle.offsetTop;
	 oEle = oEle.offsetParent;
  }

  window.scrollTo(iX,iY);

  return false;
}

// -- -------------------------------------------------------------
// -- clsValidation
// -- clsValidation
// -- clsValidation
// -- -------------------------------------------------------------
function clsValidation()
{
// -- local variables
var arERRORS				 = new Array(0);					// -- array of true errors encountered

  // -- -----------------------------------------------------------
  // -- class initialization begins
  // -- -----------------------------------------------------------
  if (!( clsValidation.prototype.AddFldForValdtn ))
  {
	// -- ------------------------------
	// -- prepare for form field editing
	// -- ------------------------------
	var arFldNms 			= new Array(0);					// -- array of fields to validate
	var arFldPatterns 		= new Array(0);     			// -- patterns to use in validation of fields in arFldNms
	var arFldErrMsgs 		= new Array(0);     			// -- error messages to use for each of the fields in arFldNms
				     										// -- if the field fails validation
	var arActualErrMsgs 	= new Array(0);   				// -- messages for each of the errors that actually occur

	var oForm				= null;						// -- the form object for the form into which the fields
				   											// -- to hold the fields,patterns,error msgs are to be injected

	var gbAddedFld 			= false;						// -- set to true once any field is added via the AddFldForValdtn
															// -- method.  Many properties cannot be changed once this
															// -- method is used and this being true will also indicate
															// -- the oForm object has been set

	// -- more private vars

	var lpvNumFldsForValdtn = 0;  							// -- # of fields we have for validation
															// -- incremented by the AddFldForValdtn method
	var lpvNumErrs 			= 0;           					// -- # of errors encountered in last call to
															// -- to ValdtFlds
	var lpvTheFormID    	= cvaldtnDFLT_FORM_ID;      	// -- ID of the form to inject the fields into
	var lpvValueSeparator	= cvaldtnDFLT_VALUE_SEPARATOR;  // -- separator to use when placing separated values
						 									// -- into the injected form fields
	var lpvFldsFldNm		= "hSSE_Fields"; 				// -- Name of the field to hold the list of fields
						 									// -- to be validated
	var lpvPatternsFldNm	= "hSSE_Patterns";  			// -- Name of the field to hold the list of patterns
						 									// -- to use in validation
	var lpvErrMsgsFldNm     = "hSSE_ErrMsgs";    			// -- Name of the field to hold the list of error
						 									// -- messages for field validation

	var lpvAlertTitle       = "Form Data Validation";     						// -- dlg window title for error messages
	var lpvAlertPromptTop   = cvaldtnDFLT_ERR_PROMPT_TOP; 	// -- string to display before error messages in dlg
															// -- window when errors found
	var lpvAlertPromptBot   = cvaldtnDFLT_ERR_PROMPT_BOT;	// -- string to display after error messages in dlg
							     							// -- window when errors found

	var lpvDoShowBtn		= cvaldtnDFLT_DO_SHOWBTN;
	var lpvDoAutoAlert      = cvaldtnDFLT_DO_ALERT;         // -- T/F indicates whether encountering errors results in
															// --  an alert-type pop-up; may not want to do this
															// --  automatically, for instance, if you could have
															// --  other error messages to add

	var lpvAlertURL         = cvaldtnDFLT_DLG_URL;          // -- URL for alert dlg window
	var lpvAlertImgTop      = cvaldtnDFLT_DLG_IMG_TOP;      // -- image to display in the alert window with promptTop
															// -- vbCritical    16 Display Critical Message icon.
															// -- vbQuestion    32 Display Warning Query icon.
															// -- vbExclamation 48 Display Warning Message icon.
															// -- vbInformation 64 Display Information Message icon.
	var lpvAlertImgBot      = cvaldtnDFLT_DLG_IMG_BOT;      // -- image to display in the alert window with promptBot

	var lpvAlertBtns        = cvaldtnDFLT_DLG_BTN;         	// -- button(s) to display in alert w
														    // -- vbOKOnly           0 Display OK button only.
															// -- vbOKCancel         1 Display OK and Cancel buttons.
															// -- vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons.
															// -- vbYesNoCancel      3 Display Yes, No, and Cancel buttons.
															// -- vbYesNo            4 Display Yes and No buttons.
															// -- vbRetryCancel      5 Display Retry and Cancel buttons.

	var lpvAlertWidth       = cvaldtnDFLT_DLG_WIDTH;        // -- width of alert window
	var lpvAlertHeight      = cvaldtnDFLT_DLG_HEIGHT;		// -- height of alert window

	var lpvAlertOrnaments	= cvaldtnDFLT_DLG_ORNAMENTS;	// -- ornaments (extended window settings)
	var lpvErrsDivName		= cvaldtnDFLT_ERRS_DIVNAME;		// -- default validation results div

	// -- ------------------------------------------------
	// -- attach our methods and properties to this object
	// -- ------------------------------------------------
	clsValidation.prototype.theFormID 				= _theFormID;					// -- a property
	clsValidation.prototype.AddFldForValdtn 		= _AddFldForValdtn;				// -- method
	clsValidation.prototype.VALD_LETTER_DIGIT 		= _VALD_LETTER_DIGIT; 			// -- read-only property (method)
	clsValidation.prototype.VALD_LETTER_DIGIT_SPACE = _VALD_LETTER_DIGIT_SPACE ;	// -- read-only property (method)
	clsValidation.prototype.VALD_NAME 				= _VALD_NAME; 					// -- read-only property (method)
	clsValidation.prototype.VALD_NAME_MSG_SUFX 		= _VALD_NAME_MSG_SUFX; 			// -- read-only property (method)
	clsValidation.prototype.VALD_PHONE 				= _VALD_PHONE();					// -- read-only property (method)
	clsValidation.prototype.VALD_EMAIL 				= _VALD_EMAIL(); 					// -- read-only property (method)
	clsValidation.prototype.VALD_EMAIL_PREFIX 		= _VALD_EMAIL_PREFIX; 			// -- read-only property (method)
	clsValidation.prototype.VALD_MULTPL_EMAILS 		= _VALD_MULTPL_EMAILS; 			// -- read-only property (method)
	clsValidation.prototype.VALD_DD_SELECTION		= _VALD_DD_SELECTION;			// -- read-only property (method)
	clsValidation.prototype.VALD_12HR_TIME 			= _VALD_12HR_TIME; 				// -- read-only property (method)
	clsValidation.prototype.VALD_DEGREES_F 			= _VALD_DEGREES_F; 				// -- read-only property (method)
	clsValidation.prototype.numFldsForValdtn 		= _numFldsForValdtn; 			// -- read-only property (method)
	clsValidation.prototype.numErrs 				= _numErrs; 					// -- read-only property (method)
	clsValidation.prototype.valueSeparator			= _valueSeparator;				// -- String separating values in the injected fields
	clsValidation.prototype.alertTitle				= _alertTitle;					// -- Title for dialog window containing error message(s)
	clsValidation.prototype.alertPromptTop			= _alertPromptTop;				// -- String to display before the individual error message(s) in the error dialog window
	clsValidation.prototype.alertPromptBot			= _alertPromptBot;				// -- String to display after the individual error message(s) in the error dialog window
	clsValidation.prototype.alertImgTop				= _alertImgTop;					// -- Img to display with alertImgTop
	clsValidation.prototype.alertImgBot				= _alertImgBot;					// -- Img to display with alertImgBot
	clsValidation.prototype.alertURL				= _alertURL;					// -- URL for dialog error window
	clsValidation.prototype.alertBtns				= _alertBtns;					// -- button(s) to display
	clsValidation.prototype.alertWinWidth			= _alertWinWidth;				// -- width of error window
	clsValidation.prototype.alertWinHeight			= _alertWinHeight;				// -- heigth of error window
	clsValidation.prototype.doShowBtn				= _doShowBtn;					// -- doShowBtn - show the buttons be visible?
	clsValidation.prototype.doAutoAlert				= _doAutoAlert;					// -- doAutoAlert - automatically alert for encountered field validation errors?
	clsValidation.prototype.appendErrMsg         =  _appendErrMsg;

	clsValidation.prototype.errDescriptions			= _errDescriptions;				// -- error messages from errors encountered during field validation

	clsValidation.prototype.fldsFldNm				= _fldsFldNm;					// -- returns name of field holding validation fieldname array
	clsValidation.prototype.patternsFldNm			= _patternsFldNm;				// -- returns name of field holding validation patterns array
	clsValidation.prototype.errMsgsFldNm			= _errMsgsFldNm;				// -- returns name of field holding validation errmsgs array

	clsValidation.prototype.VALD_ATLEASTx_NONBLANK_CHARS	= _VALD_ATLEASTx_NONBLANK_CHARS;	// -- returns validation regExp
	clsValidation.prototype.VALD_ATLEASTx_ATMOSTy_CHARS		= _VALD_ATLEASTx_ATMOSTy_CHARS;		// -- returns validation regExp
	clsValidation.prototype.VALD_ATLEASTx_ATMOSTy_NUMBERS	= _VALD_ATLEASTx_ATMOSTy_NUMBERS;	// -- returns validation regExp

	clsValidation.prototype.ValdtFlds				= _ValdtFlds;					// -- perform validations
	clsValidation.prototype.doAlert					= _doAlert;						// -- show alert dialog

	clsValidation.prototype.ErrsDivName				= lpvErrsDivName;				// -- property

  }	// -- if !( clsValidation.prototype.AddFldForValdtn )

  // -- -----------------------------------------------------------
  // -- class initialization ends
  // -- -----------------------------------------------------------

	// -- -------------------------------------------------------------
	// -- P U B L I C   M E T H O D S
	// -- -------------------------------------------------------------

	function _VALD_LETTER_DIGIT()		// -- read-only property (method)
	{
		return cvaldtnVALD_LETTER_DIGIT;
	}

	function _VALD_LETTER_DIGIT_SPACE()	// -- read-only property (method)
	{
		return cvaldtnVALD_LETTER_DIGIT_SPACE;
	}

	function _VALD_NAME()				// -- read-only property (method)
	{
		return cvaldtnVALD_NAME;
	}

	function _VALD_NAME_MSG_SUFX()		// -- read-only property (method)
	{
		return cvaldtnVALD_NAME_MSG_SUFX;
	}

	function _VALD_PHONE()				// -- read-only property (method)
	{
		return cvaldtnVALD_PHONE;
	}

	function _VALD_EMAIL()				// -- read-only property (method)
	{
		return cvaldtnVALD_EMAIL;
	}

	function _VALD_EMAIL_PREFIX()		// -- read-only property (method)
	{
		return cvaldtnVALD_EMAIL_PREFIX;
	}

	function _VALD_MULTPL_EMAILS()		// -- read-only property (method)
	{
		return "^" + cvaldtnEMAIL1 + "(;" + cvaldtnEMAIL1 + ")*$";
	}

	function _VALD_DD_SELECTION()		// -- read-only property (method)
	{
		return cvaldtnVALD_DD_SELECTION;
	}

	function _VALD_12HR_TIME()			// -- read-only property (method)
	{
		return cvaldtnVALD_12HR_TIME;
	}

	function _VALD_DEGREES_F()			// -- read-only property (method)
	{
		return cvaldtnVALD_DEGREES_F;
	}

	function _numFldsForValdtn()		// -- read-only property (method)
	{
		return lpvNumFldsForValdtn;
	}

	function _numErrs()					// -- read-only property (method)
	{
		return lpvNumErrs;
	}

	function _valueSeparator(varDat)	// -- String separating values in the injected fields
	{
		if (varDat == null)
		{
	    	return lpvValueSeparator;
		}

		if (!( gbAddedFld ))
		{
			lpvValueSeparator = varDat;
			return true;
		}
		else
		{
			arERRORS.push("520" + cvaldtnERR_SRC + " " + "AUTHOR CREATED AN INVALID PAGE; VALDTN ILLEGAL PROPERTY VALUE valueSeparator; Cannot be set once fields are added.");
			//throw arERRORS.pop();
			return false;
		}
    }

	function _alertTitle(varDat)		// -- Title for dialog window containing error message(s)
	{
		if (!( varDat == null ))
		{
			lpvAlertTitle = varDat;
		}

		return lpvAlertTitle;
	}

	function _alertPromptTop(varDat)	// -- String to display before the individual error message(s) in the error dialog window
	{
		if (!( varDat == null ))
		{
			lpvAlertPromptTop = varDat;
		}

		return lpvAlertPromptTop;
	}

	function _alertPromptBot(varDat)	// -- String to display after the individual error message(s) in the error dialog window
	{
		if (!( varDat == null ))
		{
			lpvAlertPromptBot = varDat;
		}

		return lpvAlertPromptBot;
	}

	function _alertImgTop(varDat)		// -- Img to display with alertImgTop
	{
		if (!( varDat == null ))
		{
			lpvAlertImgTop = varDat;
		}

		return lpvAlertImgTop;
	}

	function _alertImgBot(varDat)		// -- Img to display with alertImgBot
	{
		if (!( varDat == null ))
		{
			lpvAlertImgBot = varDat;
		}

		return lpvAlertImgBot;
	}

	function _alertURL(varDat)			// -- URL for dialog error window
	{
		if (!( varDat == null ))
		{
			lpvAlertURL = varDat;
		}

		return lpvAlertURL;
	}

	function _alertBtns(varDat)			// -- button(s) to display
	{
		if (!( varDat == null ))
		{
			lpvAlertBtns = varDat;
		}

		return lpvAlertBtns;
	}

	function _alertWinWidth(varDat)		// -- width of error window
	{
		if (!( varDat == null ))
		{
			lpvAlertWidth = varDat;
		}

		return lpvAlertWidth;
	}

	function _alertWinHeight(varDat)	// -- heigth of error window
	{
		if (!( varDat == null ))
		{
			lpvAlertHeight = varDat;
		}

		return lpvAlertHeight;
	}

	function _doShowBtn(varDat)		// -- doAutoAlert - should the buttons be visible?
	{
		if (!( varDat == null ))
		{
			lpvDoShowBtn = varDat;
		}

		return lpvDoShowBtn;
	}

	function _doAutoAlert(varDat)		// -- doAutoAlert - automatically alert for encountered field validation errors?
	{
		if (!( varDat == null ))
		{
			lpvDoAutoAlert = varDat;
		}

		return lpvDoAutoAlert;
	}

	function _errDescriptions(arDat)	// -- error messages from errors encountered during field validation
	{
		var s;

		s = 'riches\n' + arActualErrMsgs;
		return s;
	}

	// -- fldsFldNm, patternsFldNm, errMsgsFldNm
    // -- -------------------------------------
    // -- each holds a separated list of values - separator
    // -- is given by the property valueSeparator
    // -- which defaults to VALUE_SEPARATOR
    // --
    // -- the fldsFldNm form field injected into the form
    // -- will contain a separated list of form fields to
    // -- validate; patternsFldNm and errMsgsFldNm will
    // -- contain the same number of separated values.
    // --
    // -- the patternsFldNm form field injected into the form
    // -- will contain  a separated list of patterns to use
    // -- in the validation.  The field fails validation if
    // -- its value does NOT match the given pattern.  The
    // -- first pattern will be used on the first field
    // -- contained in fldsFldNm; the second pattern will
    // -- be used on the second field in fldsFldNm, etc.
    // --
   	// -- the errMsgsFldNm form field injected into the form
    // -- will contain  a separated list of error messages to use
    // -- in the validation.  if the field fails validation,
    // -- the error message to display is obtained from this list.
    // -- The first error msg will be used on the first field
    // -- contained in fldsFldNm; the second error msg will
    // -- be used on the second field in fldsFldNm, etc.
    // --
    // -- These form fields will be injected into the form
    // -- with ID=theFormID when the first field is added
    // -- (first time AddFldForValdtn called); therefore,
    // -- the form must exist at that time.
    // -- The method AddFldForValdtn will also
    // -- add the values into these injected fields.
    // --

    // -- --------------------
    // -- fldsFldNm
    // -- --------------------
    // --
    // -- name of the form field to inject into the form
    // -- (the form with ID=theFormID) to contain the separated
    // -- list of field names to validate
   	// --
    // -- empty string if you do not wish to have the
    // -- form field injected (inject the form field
    // -- if you want to do similar form field validation
    // -- on the server side - providing the form field
    // -- will pass the field names on to the server)
    // -- --------------------
	function _fldsFldNm(varDat)			// -- returns name of field holding validation fieldname array
    {
		if (!( varDat == null ))
		{
			if (!( gbAddedFld ))
			{
				lpvFldsFldNm = varDat;
			}
			else
			{
				arERRORS.push("530" + cvaldtnERR_SRC + " " + "AUTHOR CREATED AN INVALID PAGE; VALDTN ILLEGAL PROPERTY VALUE fldsFldNm; Cannot be set once fields are added.");
				//throw arERRORS.pop();
			}
		}

		return lpvFldsFldNm;
	}

	// -- --------------------
	// -- patternsFldNm
	// -- --------------------
	// --
	// -- name of the form field to inject into the form
	// -- (the form with ID=theFormID) to contain the separated
	// -- list of patterns to use in validating the fields
    // -- --------------------
    function _patternsFldNm(varDat)		// -- returns name of field holding validation patterns array
    {
		if (!( varDat == null))
		{
			if (!( gbAddedFld ))
			{
				lpvPatternsFldNm = varDat;
			}
			else
			{
				arERRORS.push("540" + cvaldtnERR_SRC + " " + "AUTHOR CREATED AN INVALID PAGE; VALDTN ILLEGAL PROPERTY VALUE patternsFldNm; Cannot be set once fields are added.");
				//throw arERRORS.pop();
			}
		}

		return lpvPatternsFldNm;
	}

	// -- --------------------
	// -- errMsgsFldNm
	// -- --------------------
	// --
	// -- name of the form field to inject into the form
	// -- (the form with ID=theFormID) to contain the separated
    // -- list of error messages to use in validating the fields
    // -- --------------------
    function _errMsgsFldNm(varDat)		// -- returns name of field holding validation errmsgs array
	{
		if (!( varDat == null ))
		{
			if (!( gbAddedFld ))
			{
				lpvErrMsgsFldNm = varDat;
			}
			else
			{
				arERRORS.push("550" + cvaldtnERR_SRC + " " + "AUTHOR CREATED AN INVALID PAGE; VALDTN ILLEGAL PROPERTY VALUE errMsgsFldNm; Cannot be set once fields are added.");
				//throw arERRORS.pop();
			}
		}

		return lpvErrMsgsFldNm;
	}

	function _VALD_ATLEASTx_NONBLANK_CHARS (x)		// -- returns validation regExp
	{
		return "([^ ] *){" + x + ",}";
	}

	function _VALD_ATLEASTx_ATMOSTy_CHARS (x,y)		// -- returns validation regExp
	{
		return "^.{" + x + "," + y + "}$";
	}

	function _VALD_ATLEASTx_ATMOSTy_NUMBERS (x,y)	// -- returns validation regExp
	{
		return "^[0-9]{" + x + "," + y + "}$";
	}

	// -- -------------------------------------------------------------
	// -- function theFormID
	// -- -------------------------------------------------------------
	function _theFormID(varDat)
	{
		if (!( varDat == null ))
		{
			if (!( gbAddedFld ))
			{
				if (( varDat.length > 0 ))
				{
					lpvTheFormID = varDat;
					//throw "crap";
				}
				else
				{
					arERRORS.push("512" + cvaldtnERR_SRC + " " + "AUTHOR CREATED AN INVALID PAGE; VALDTN ILLEGAL PROPERTY VALUE theFormID; Empty String Not Allowed.");
					//throw arERRORS.pop();
				}
			}
			else
			{
				arERRORS.push("510" + cvaldtnERR_SRC + " " + "AUTHOR CREATED AN INVALID PAGE; VALDTN ILLEGAL PROPERTY VALUE theFormID; Cannot be set once fields are added.");
				//throw arERRORS.pop();
			}
		}

		return lpvTheFormID;
	}	// -- function _theFormID

	// -- -------------------------------------------------------------
	// -- function AddFldForValdtn
	// -- -------------------------------------------------------------
	function _AddFldForValdtn(sFldNm, sFldPattern, sFldErrMsg)
	{
      var bFldPrevAdded;

      bFldPrevAdded 		= gbAddedFld;
      gbAddedFld 			= true;

      lpvNumFldsForValdtn 	= lpvNumFldsForValdtn + 1;

      arFldNms.push(sFldNm);
      arFldPatterns.push(sFldPattern);
      arFldErrMsgs.push(sFldErrMsg);

      if ( this.fldsFldNm().length > 0 )
      {
         if ( bFldPrevAdded )
         {
            // -- fields already injected; just update the values
            oForm[this.fldsFldNm()].value 		= oForm[this.fldsFldNm()].value 	+ lpvValueSeparator + sFldNm;		// -- msgbox oForm(fldsFldNm()).value
            oForm[this.patternsFldNm()].value 	= oForm[this.patternsFldNm()].value + lpvValueSeparator + sFldPattern;	// -- msgbox oForm(patternsFldNm()).value
            oForm[this.errMsgsFldNm()].value 	= oForm[this.errMsgsFldNm()].value 	+ lpvValueSeparator + sFldErrMsg;	// -- msgbox oForm(errMsgsFldNm()).value
		 }
         else
         {
			// -- inject fields
            InjectFld( this.fldsFldNm(), sFldNm);
            InjectFld( this.patternsFldNm(), sFldPattern );
            InjectFld( this.errMsgsFldNm(),  sFldErrMsg );
         }

      }	// -- if ( fldsFldNm.length > 0 )

	}	// -- function _AddFldForValdtn

    // -- -------------------------------------
    // -- function ValdtFlds
    // -- returns  number of validation failures found
	// -- -------------------------------------
    function _ValdtFlds()
    {
    	var rc 				= 0;
    	lpvNumErrs 			= 0;
		arActualErrMsgs 	= new Array(0);   				// -- clear array of errors actually found

    	valdtFldsUsingPatterns();

    	if (!( lpvNumErrs == 0 ))
    	{
    		if ( lpvDoAutoAlert )
	    	{
		    	// -- show the errors that were encountered
		    	rc = this.doAlert(arActualErrMsgs);
  	     	}
	  	}
		lpvNumErrs = arActualErrMsgs.length;
		rc = lpvNumErrs;

      	return rc;
	}	// -- function ValdtFlds

	// -- -------------------------------------------------------------
	// -- function doAlert
	// -- -------------------------------------------------------------
    function _doAlert(arMsgs)
	{
		var sOut;

		// for some reason any other syntax tried here fails
		// var select = document.getElementById(this.ErrsDivName);
		// select.innerHTML = "<hr>";
		var select = document.getElementById(this.ErrsDivName);
		select.innerHTML = "<hr>";

	    sOut  = getErrMsgTbl();

	    if ( lpvDoShowBtn )
	    {
		    sOut += getButtons();
		}

		select.innerHTML += sOut;
		select.innerHTML += "<hr>";

	}	// -- function doAlert

	function _appendErrMsg (sMsg) {
      lpvNumErrs 	= lpvNumErrs + 1;
	   arActualErrMsgs.push(sMsg);
	}



	// -- -------------------------------------------------------------
	// -- P R I V A T E   M E T H O D S
	// -- -------------------------------------------------------------

	// -- -------------------------------------------------------------
	// -- function getErrMsgTbl
	// -- -------------------------------------------------------------
	function getErrMsgTbl()
	{
	   var sOut;

	   sOut = "<table border='0' width='95%' cellspacing='0' cellpadding='0'>";
	   sOut += getPromptRow(lpvAlertPromptTop, lpvAlertImgTop);
	   sOut += "<td colspan='3'><hr style='width:95%;'></td></tr><tr><td colspan='3'><ol name='cvaldtErrList' id='cvaldtErrList' style='margin-bottom:0px;'>";

	   for (i = 0; i < arActualErrMsgs.length; i++)
	   {
		  sOut += "<li>" + arActualErrMsgs[i] + "</li>";

	   }

	   sOut += "</ol></td></tr><tr><td colspan='3'><hr style='width:95%;'></td></tr>";
	   sOut += getPromptRow(lpvAlertPromptBot, lpvAlertImgBot);
	   sOut += "</table>";

	   // -- blank row:  <tr><td colspan='3'></td></tr>

	   return sOut;
	}

	// -- -------------------------------------------------------------
	// -- function getPromptRow
	// -- -------------------------------------------------------------
	function getPromptRow(strPrompt, iIcon)
	{
	   var sImgSrc, sImgTitle;
	   var sOut = "";

	   if ( !(strPrompt == null) || (iIcon > 0) )
	   {
		  switch(iIcon)
		  {
			 case( vbCritical ):
				sImgSrc = "vbCritical.gif";
				sImgTitle = "Critical";
				break;

			 case(  vbQuestion ):
				sImgSrc = "vbQuestion.gif";
				sImgTitle = "Critical";
				break;

			 case(  vbExclamation ):
				sImgSrc = "vbExclamation.gif";
				sImgTitle = "Critical";
				break;

			 case(  vbInformation ):
				sImgSrc = "vbInformation.gif";
				sImgTitle = "Critical";
				break;

			 default:
				iIcon = 0;
				break;

		  }

		  if (iIcon > 0)
		  {
			 sOut += "<tr><td width='32'><img border='0' alt='Input Error' title='" + sImgTitle + "' src='/rgImages/" + sImgSrc + "' width='32' height='32'></td><td width='15'></td><td class='prompt' valign='middle'>" + strPrompt + "</td></tr>";
		  }
		  else if ( !(strPrompt == '') )
		  {
			 sOut += "<tr><td colspan='3' class='prompt' valign='middle'>" + strPrompt + "</td></tr>";
		  }

		  return sOut;

	   }

	}

	// -- -------------------------------------------------------------
	// -- function getButtons
	// -- -------------------------------------------------------------
	function getButtons()
	{
		var sOut = "";

		sOut += "<div align='right' style='width:95%'>" ;

		switch( lpvAlertBtns )
		{
		  case( vbOKOnly ):
			 sOut += getButton("btnOK",     "k", vbOK,     "O<u>k</u>");
			 break;

		  case( vbOKCancel ):
			 sOut += getButton("btnOK",     "k", vbOK,     "O<u>k</u>");
			 sOut += getButton("btnCancel", "a", vbCancel, "C<u>a</u>ncel");
			 break;

		  case( vbAbortRetryIgnore ):
			 sOut += getButton("btnAbort",  "b", vbAbort,  "A<u>b</u>ort");
			 sOut += getButton("btnRetry",  "e", vbRetry,  "R<u>e</u>try");
			 sOut += getButton("btnIgnore", "g", vbIgnore, "I<u>g</u>nore");
			 break;

		  case( vbYesNoCancel ):
			 sOut += getButton("btnYes",    "e", vbYes,    "Y<u>e</u>s");
			 sOut += getButton("btnNo",     "o", vbNo,     "N<u>o</u>");
			 sOut += getButton("btnCancel", "a", vbCancel, "C<u>a</u>ncel");
			 break;

		  case( vbYesNo ):
			 sOut += getButton("btnYes",    "e", vbYes,    "Y<u>e</u>s");
			 sOut += getButton("btnNo",     "o", vbNo,     "N<u>o</u>");
			 break;

		  case( vbRetryCancel ):
			 sOut += getButton("btnRetry",  "e", vbRetry,  "R<u>e</u>try");
			 sOut += getButton("btnCancel", "a", vbCancel, "C<u>a</u>ncel");
			 break;

		  default:
			 // -- vbOKOnly is the default
			 sOut += getButton("btnOK",     "k", vbOK,     "O<u>k</u>");
			 break;

		}

		sOut += "</div>";

		return sOut;
	}

	// -- -------------------------------------------------------------
	// -- function getButton
	// -- -------------------------------------------------------------
	function getButton(sID, sAccessKey, sVal, sDisplay)
	{
	   return "<BUTTON id=" + sID + " name='" + sID + "' class='sbtn' doSub='0'" + " accesskey='" + sAccessKey + "' value='" + sVal + "' onclick='vbscript::btnOnClick(" + sVal + ")'>&nbsp;&nbsp;" + sDisplay + "&nbsp;&nbsp;</BUTTON>&nbsp;";
	}

	// -- -------------------------------------------------------------
	// -- function InjectFld
	// -- assign provided value to indicated field
	// -- OR append to form a new hidden field with the indicated name and value
	// -- -------------------------------------------------------------
	function InjectFld(sFldNm, sFldVal)
	{		//DebugOut('InjectFld(sFldNm, sFldVal)', sFldNm + ', ' + sFldVal + ' 1');
        var theElement;

        if ( oForm == null )
        {

//DebugOut(lpvTheFormID);		//works because we are calling a global var
//DebugOut(this.theFormID());	//does not work because the method InjectFld is not part of the object, only private
//DebugOut(theFormID());		//does not work because the method InjectFld is not part of the object

		   oForm = document.forms[lpvTheFormID];
           //oForm = document.forms(this.theFormID());
		}

        theElement = oForm[sFldNm];

		if (!( theElement == null ))
		{	//DebugOut('field reused');
			// -- overwrite the current value
		    theElement.value = sFldVal;
		}
		else
		{	//DebugOut('creating field');
			// -- create the field
			theElement       = document.createElement("INPUT");
			theElement.type  = "hidden";
			theElement.Name  = sFldNm;
			theElement.id 	 = sFldNm;
			theElement.value = sFldVal;

			oForm.appendChild(theElement);
	  	}

        theElement = null;		// JSW may want to remove this line
	//	return true;
	}	// -- function InjectFld

	// -- -------------------------------------------------------------
	//-- function valdtFldsUsingPatterns
	// -- -------------------------------------------------------------
	function valdtFldsUsingPatterns()
	{
		var DFLT_PATTERN 		= "[^ ]";   // -- any single character not equal to space

		var ubFlds, ubPatterns, ubMsgs, i;
		var strFldNm, strFldVal, strPattern;

		var regEx;
		var bTrimFldValFirst, lLenPattern;

        lpvNumErrs 				= 0;

		regEx            		= new RegExp();
		//regEx.IgnoreCase 		= False;

		ubFlds     				= arFldNms.length;
		ubPatterns 				= arFldPatterns.length;
		ubMsgs     				= arFldErrMsgs.length;

		for (i = 0; i < ubFlds; i++)
		{
   			bTrimFldValFirst 	= false;

			if ( i > ubPatterns )
			{
				strPattern = DFLT_PATTERN;
			}
			else
			{
			    strPattern  = trimFld(arFldPatterns[i], true);
				lLenPattern = strPattern.length;

				if (lLenPattern > 0)
				{
					if (lLenPattern > 7)
					{
						if (Left(strPattern,7) == "<TRIM/>")
						{
							// -- special case pattern - indicates trim the field val before testing pattern
							strPattern       = Right(strPattern, lLenPattern - 7);
							bTrimFldValFirst = true;
						}
					}
				}
				else
				{
					strPattern = DFLT_PATTERN;
				}

			}

			try
			{
				regEx = new RegExp(strPattern);
			}
			catch(err)
			{
				regEx = null;

				arERRORS.push("406" + cvaldtnERR_SRC + " " + "AUTHOR CREATED AN INVALID PAGE; ILLEGAL TEST PATTERN; " + vbCrLf +   strFldNm + ":" + strFldVal + "(" + strPattern + ")" + vbCrLf + "     (" + err.Number + ")  " + err.Description);
				//throw arERRORS.pop();

				break;	// -- exit function
			}

			strFldNm 	= trimFld(arFldNms[i], true);
			strFldVal 	= getVal(strFldNm, bTrimFldValFirst);

			try
			{
				// -- Change CRLF to space in the field value for pattern matching purposes.
				// -- and attempt the match
				if ( !(!(Replace(strFldVal,vbCrLf," ").search(regEx))) )
				{
					// -- --------------------------------------------------
					// -- pattern not found; U S E R   I N P U T   E R R O R
					// -- --------------------------------------------------
					lpvNumErrs 	= lpvNumErrs + 1;

					if ( i > ubMsgs )
					{
						arActualErrMsgs.push("Error in field " + strFldNm + ": value=(" + strFldVal + "); did not pass validation.");
					}
					else
					{
						// -- error message provided - use it
						arActualErrMsgs.push(trimFld(arFldErrMsgs[i], true));
					}

				}
			}
			catch(err)
			{
				regEx = null;

				arERRORS.push("404" + cvaldtnERR_SRC + " " + "AUTHOR CREATED AN INVALID PAGE; ILLEGAL VALDN FIELD VALUE; " + vbCrLf + strFldNm + ":" + strFldVal + "(" + strPattern + ")" + vbCrLf + "     (" + err.Number + ")  " + err.Description);
				//throw arERRORS.pop();
				break;	// -- exit function
			}

		} // -- For (i = 0; i < ubFlds; i++)

		// -- instead of validations, use any actual errors encountered
		if ( !( arERRORS.length == 0 ) )
		{
			// -- clear validation errors
			arActualErrMsgs 	= new Array(0);   				// -- clear array of errors actually found
			lpvNumErrs = arERRORS.length;

			for (j = 0; j < lpvNumErrs; j++)
			{
				arActualErrMsgs.push(arERRORS[j]);
			}
		}

		// release object
		regEx = null;

      return lpvNumErrs;

	}	// -- function valdtFldsUsingPatterns()
	
	// -- -------------------------------------------------------------------------
	// -- FUNCTION:  getVal
	// -- INPUTS:    strFldNm - string form field name
	// -- -------------------------------------------------------------------------
	function getVal(strFldNm, bTrimIt)
	{
		var bFound;
		var strRetn;
		var objForm, objFld;
		var strWork;

		bFound 	= false;
		strRetn = "";

		//For Each objForm in document.forms
		for (i=0; i < document.forms.length; i++)				// get each form via forms(i)
		{
			try
			{
				//For Each objFld in objForm
				for (j=0; j < document.forms[i].length; j++)	// get each element via forms(i).elements(j)
				{
					if ( document.forms[i].elements[j].name.toUpperCase() == strFldNm.toUpperCase() )
					{
						try
						{
							strWork = ( document.forms[i].elements[j].type.toUpperCase() );

							if ( (strWork == "RADIO") || (strWork == "CHECKBOX") )
							{
								if ( document.forms[i].elements[j].checked )
								{
									strWork = document.forms[i].elements[j].value;

									if ( bTrimIt )
									{
										strWork = Trim(strWork);
									}

									if (Len(strWork) > 0)
									{
										// -- nada
									}
									else
									{
										strWork = "CHECKED";
									}

									strRetn = strWork;
									bFound 	= true;

									break;	// -- exit for (j=0; j < document.forms(i).length; j++)
								}
							}	// -- if ( (strWork == "RADIO") OR (strWork == "CHECKBOX") )
							else
							{
								strRetn = document.forms[i].elements[j].value;

								if ( bTrimIt )
								{
									strRetn = Trim(strRetn);
								}

								bFound = true;

								break;	// -- exit for (j=0; j < document.forms(i).length; j++)
							}	// -- if ( (strWork == "RADIO") OR (strWork == "CHECKBOX") )

						}	// -- try
						catch(err)
						{
							arERRORS.push("614" + cvaldtnERR_SRC + " " + "UNABLE TO DERIVE FIELD VALUE DURING VALIDATION ROUTINE; PLEASE CONTACT FORM ADMINISTRATOR;");
							//throw arERRORS.pop();
						}

					}	// -- if ( forms(i).elements(j).Name.toUppercase() == strFldNm.toUppercase() )
				}	// -- for (j=0; j < document.forms(i).length; j++)
			}	// -- try
			catch(err)
			{
				arERRORS.push("613" + cvaldtnERR_SRC + " " + "UNABLE TO DERIVE FIELD VALUE DURING VALIDATION ROUTINE; PLEASE CONTACT FORM ADMINISTRATOR;");
				//throw arERRORS.pop();
			}

			if ( bFound )
			{
				break;	// -- exit for (i=0; i < document.forms.length; i++)
			}

		}	// -- for (i=0; i < document.forms.length; i++)

		return strRetn;

	}	// -- function getVal(strFldNm, bTrimIt)

	// -- -------------------------------------------------------------------------
	// -- FUNCTION trimFld
	// -- INPUTS:  strIn:  input string to test
	// --          trimSp: boolean value indicating whether or not leading & trailing
	// --              spaces should be removed from the strIn string.
	// -- PURPOSE: remove leading and trailing CR & LF characters and, optionally,
	// --          remove leading and trailing spaces from the passed strIn string.
	// -- RETURNS: strIn with leading/trailing CR & LF chars, and optionally
	// --          leading/trailing spaces removed.
	// -- -------------------------------------------------------------------------
	function trimFld (strIn, trimSp)
	{
		var s = new String(strIn);

		s = Replace(s, '\r', '');
		s = Replace(s, '\n', '');

		if ( trimSp )
		{
			s = Trim(s);
		}

		return s;
	}	// -- function trimFld

	// -- -------------------------------------------------------------
	// -- function trim
	// -- -------------------------------------------------------------
	function Trim(strIn)
	{
		var s = new String(strIn);
		while (s.substring(0,1) == ' ') {
			s = s.substring(1,s.length);
		}
		while (s.substring(s.length-1,s.length) == ' ') {
			s = s.substring(0,s.length-1);
		}
		return s;
	}	// -- function Trim

	// -- -------------------------------------------------------------
	// -- function Right
	// -- -------------------------------------------------------------
	function Right(strIn, iHowMany)
	{
		var s = new String(strIn);
		return s.slice((s.length-iHowMany),s.length);
	}	// -- function Right

	// -- -------------------------------------------------------------
	// -- function Left
	// -- -------------------------------------------------------------
	function Left(strIn, iHowMany)
	{
		var s = new String(strIn);
		return s.slice(0,iHowMany);
	}	// -- function Left

	// -- -------------------------------------------------------------
	// -- function Replace
	// -- -------------------------------------------------------------
	function Replace(strIn, strFind, strReplace)
	{
		var s = new String(strIn);

		var regEx = new RegExp (strFind, 'gi') ;
        s = s.replace(regEx, strReplace);

        return s;
	}	// -- function Replace

	// -- ---------------------------------
	// -- C L A S S   T E R M I N A T E --
	// -- ---------------------------------
	// -- oForm = null

} 		// -- function clsValidation (class clsValidation)

	// -- -------------------------------------------------------------
	// -- function DebugOut
	// -- -------------------------------------------------------------
	function DebugOut(strIn, strLine)
	{
		if ( doDebug )
		{
			if (!(strLine == null))
			{
				alert(strIn + ' : ' + strLine);
			}
			else
			{
				alert(strIn);
			}
		}
	}	// -- function DebugOut
