    // Validator constructor function.
    function Validator(pFormValueName, pFormValueType, pElementId, anArray) {
        // alert('In Validator constructor for ' + pFormValueName);

        this.formValueName = pFormValueName;
        this.elementId = pElementId;

        if (typeof(pFormValueType) == "function") {
            this.validateFunction = pFormValueType;
        }
        else if (pFormValueType.toLowerCase() == "radio") {
            this.validateFunction = Validator.selectedRadioButton;
        }
        else if (pFormValueType.toLowerCase() == "popup") {
            this.validateFunction = Validator.selectedPopupButton;
        }
        else if (pFormValueType.toLowerCase() == "checkbox") {
            this.validateFunction = Validator.selectedCheckboxButton;
        }
        else if (pFormValueType.toLowerCase() == "text_ne") { // not empty
            this.validateFunction = Validator.notEmptyText;
        }
        else if (pFormValueType.toLowerCase() == "text_pn") { // positive number
            this.validateFunction = Validator.positiveNumberText;
        }
        else if (pFormValueType.toLowerCase() == "text_pi") { // positive number
            this.validateFunction = Validator.positiveIntegerText;
        }
        else {
            this.validateFunction = null;
        }

	if (typeof(anArray) == "undefined" || anArray == null) {
	    Validator.validationArray[Validator.validationArray.length] = this;
        }
	else {
	    anArray[anArray.length] = this;
        }
    }

    // "Static" Validator variables.
    Validator.isCSS1 = (document.getElementById || document.all);
    Validator.validationArray = new Array();

    // "Static" Validator function to validate a Radio Button.
    Validator.selectedRadioButton = function(formValue) {
	if (typeof(formValue.checked) != "undefined") {
	    return formValue.checked;
        }
        for (var i = 0; i < formValue.length; ++i) {
            if (formValue[i].checked) return true;
        }
        return false;
    }

    // "Static" Validator function to validate a Popup Button.
    Validator.selectedPopupButton = function(formValue) {
        return (formValue.selectedIndex > 0);
    }
    
    // "Static" Validator function to validate a Checkbox Button.
    Validator.selectedCheckboxButton = function(formValue) {
        return formValue.checked;
    }

    // "Static" Validator function to validate a Text/Textarea input
    // is not empty.
    Validator.notEmptyText = function(formValue) {
        if (formValue.value == null) return false;
        var stringValue = formValue.value.replace(/^\s$/g, '');
        return (stringValue.length > 0);
    }

    // "Static" Validator function to validate a Text input
    // is a positive number.
    Validator.positiveNumberText = function(formValue) {
        if (formValue.value == null) return false;
        var stringValue = formValue.value.replace(/,/g, '');
	if ( !stringValue.match(/^[\d\.]*$/) ) return false;
        var val = parseFloat(stringValue);
        return (isNaN(val) || val <= 0) ? false : true;
    }

    Validator.positiveIntegerText = function(formValue) {
        if (formValue.value == null) return false;
        var stringValue = formValue.value.replace(/,/g, '');
	if ( !stringValue.match(/^[\d]*$/) ) return false;
        var val = parseInt(stringValue);
        return (isNaN(val) || val <= 0) ? false : true;
    }


    // "Static" Validator function to get an element.
    Validator.getAnElement = function(id) {
        if (document.getElementById) {
            return document.getElementById(id);
        }
        else if (document.all) {
            return document.all[id];
        }
        else {
            return null;
        }
    }

    // "Static" Validator function to validate data when a form is submitted.
    Validator.validateData = function(anArray, alreadyHasError) {
        // alert('In Validator.validateData ' + Validator.validationArray.length);

        var okay = true;
        var i = 0;
        var valObject = null;
        var formValue = null;
        var domElement = null;
	var validationArray;
	var firstError = null;
	
	if (typeof(anArray) == "undefined" || anArray == null)
	    validationArray = Validator.validationArray;
	else
	    validationArray = anArray;

        for (i = 0; i < validationArray.length; ++i) {
            valObject = validationArray[i];
            // alert('Looking at object ' + valObject.formValueName);

            formValue = eval(valObject.formValueName);
	    domElement = null;
	    if ( typeof(valObject.elementId) != "function" )
		domElement = Validator.getAnElement(valObject.elementId);
/*
alert('Validation failed for object ' + valObject.formValueName +
      ' ' + valObject.elementId);
styleAttr = domElement.getAttribute("style");
alert("styleAttr = " + typeof(styleAttr) + "|" + styleAttr + "|");
str = "domElement attributes = ";
for (obj in styleAttr) {
    str += obj + "\n";
}
alert(str);
*/

            if (valObject.validateFunction) {
                if (valObject.validateFunction(formValue)) {
                    if (domElement) domElement.style.color = "black";
                }
                else {
                    if (domElement) domElement.style.color = "red";
		    else if ( Validator.isCSS1 && firstError == null ) firstError = valObject.elementId;
                    okay = false;
                }
            }
            else {
                alert("Error!\n\n" +
                      "No validation function for " + valObject.formValueName + ".");
            }
        }

        // If there has already been an error, return false whether or
        // not these checks produced additional errors.
	if (typeof(alreadyHasError) != "undefined" && alreadyHasError)
	    return false;

        if (! okay) {
            // There was a requirement to have the page scroll to top, but it was removed.
            // If the requirement is added again, uncomment the following line.
            //window.location.replace("#pagetop");

	    if ( firstError == null ) {
            if (Validator.isCSS1) {
                alert("Oops!\n\n" +
                      "The information you have provided is not complete. " +
                      "Please review this page and complete the items in red.");
            }
            else {
                alert("Oops!\n\n" +
                      "The information you have provided is not complete. " +
                      "Please review this page and complete any missing items.");
            }
	    } else {
		if ( typeof(firstError) == "function" )
		    firstError();
		else 
		    alert("Oops!\n\n" +
			  "The information you have provided is not complete. " +
			  "Please select " + firstError);
	    }
        }

        return okay;
    }

    // "Static" Validator function to reset the style
    Validator.resetColor = function(anArray) {
	var validationArray;
	
	if (typeof(anArray) == "undefined" || anArray == null)
	    validationArray = Validator.validationArray;
	else
	    validationArray = anArray;

        for (i = 0; i < validationArray.length; ++i) {
            valObject = validationArray[i];
            domElement = Validator.getAnElement(valObject.elementId);
	    if (domElement) domElement.style.color = "black";
	}
    }

    function isOverMaxLength( formObject, maxLength, showAlert ) {
        if ( formObject == "undefined" || formObject == null ||
                        maxLength == "undefined" || maxLength == null || maxLength <= 0 ) {
                return false;
        }
        if ( formObject.value.length > maxLength ) {
		if ( showAlert )
		    alert( 'You have entered more than the ' + maxLength + ' characters allowed for this field.' );
                formObject.value = formObject.value.substr( 0, maxLength );
                return true;
        }
        return false;
    }


