    /*###########################################
    # Common Form Validation Class
    #
    # Usage Example:
    #       var oFormValidator;
    #       var aRequiredFields = new Array();
    #
    #       // aRequiredFields - oElement, sReturnMessage, sValidationType, sFieldType (1 = input, 2 = select)
    #       aRequiredFields[0] = [document.getElementById('txtCardNumber'), "You must enter a valid number in the Card Number field.", "card", 1];
    #       aRequiredFields[1] = [document.getElementById('txtBirthDate'), "You must enter a valid date in the Date of Birth field.", "date", 1];
    #
    #       // creat a new instance of the FormValidator object
    #       oFormValidator = new FormValidator(aRequiredFields);
    #
    #       // optional property overrides
    #       oFormValidator.ValidCardNumber = /^\d{3}$/;
    #
    #       // call Validate method
    #       return oFormValidator.Validate();
    #############################################*/

    function FormValidator (aRequiredFields)
    {
        // public properties
        this.aRequiredFields = aRequiredFields;
        
        // private validation properties
        this.ValidCardNumber    = /^\d{10}$/;
        this.ValidDate          = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
        this.ValidEmail         = /^\w[-.\w]*\@[-\w]+(\.[-\w]+)*\.\w{2,3}$/;
        this.ValidPhone         = /^(\()?\d{3}(\)\s?|-)\d{3}\-\d{4}$/;
        this.ValidZip           = /^\d{5}(\-\d{4})?$/;
        
        // public methods
       
        /*############################################################
        # Method:       Override_ValidCardNumber()
        # Description:  Used to override the ValidCardNumber property
        ##############################################################*/
        
        this.Override_ValidCardNumber = function (rePattern)
        {
            this.ValidCardNumber = rePattern;
        }
        
        /*######################################################
        # Method:       Override_ValidDate()
        # Description:  Used to override the ValidDate property
        ########################################################*/
        
        this.Override_ValidDate = function (rePattern)
        {
            this.ValidDate = rePattern;
        }
        
        /*########################################################
        # Method:       Override_ValidPhone()
        # Description:  Used to override the ValidPhone property
        ##########################################################*/
        
        this.Override_ValidPhone = function (rePattern)
        {
            this.ValidPhone = rePattern;
        }
        
        /*######################################################
        # Method:       Override_ValidZip()
        # Description:  Used to override the ValidZip property
        ########################################################*/
        
        this.Override_ValidZip = function (rePattern)
        {
            this.ValidZip = rePattern;
        }

        /*############################################################
        # Method:       text_ContainsValue()
        # Description:  Checks to see that the field contains a value
        # Returns:      Boolean
        ##############################################################*/
    
        this.text_ContainsValue = function (sValue)
        {
            if ((sValue != "") && (sValue != null))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        
        /*####################################################################
        # Method:       text_ValidLength()
        # Description:  Checks that the value of sElementId contains a string
        #               of the appropriate length.
        # Returns:      Boolean
        ######################################################################*/
                                
        this.text_ValidLength = function (sElementId, iLength)
        {
            var sValue = document.getElementById(sElementId).value.toString();
                
            if (sValue.length == iLength)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /*#####################################################
        # Method:       text_ValidFormat()
        # Description:  Checks the value for proper formatting
        # Returns:      Boolean
        #######################################################*/
            
        this.text_ValidFormat = function (sValue, rePattern)
        {
            return rePattern.test(sValue);
        }
        
        
        /*#####################################################
        # Method:       text_CheckBirthdate()
        # Description:  Checks the value for proper formatting
        # Returns:      Boolean
        #######################################################*/
        this.text_CheckBirthdate = function (oElement)
        {
            var now = new Date;
            var datejoined = new Date(oElement.value);
            var thisYear = new Date(now.getFullYear(),1,1);
            var aYear;
            var sError;
                      
            if (isNaN(datejoined))
            {
                sError = "Please enter a valid date in the field provided.";
                this.returnError(sError,oElement);
                return false;
            }
            
            if (datejoined.getFullYear() > thisYear.getFullYear()) 
            {
                sError = "The date you entered is not correct!";
                this.returnError(sError,oElement);
                return false;
            }
            
            if (datejoined.getFullYear() < 100) 
            {
                aYear = datejointed.getFullYear();
                aYear += 1900;
                datejoined.setFullYear(aYear);
                return false;
            } 
            
            return ((datejoined.getMonth() + 1) + "/" + datejoined.getDate() + "/" + datejoined.getFullYear());
        }
        
        /*######################################################
        # Method:       returnError()
        # Description:  Checks the value for proper formatting
        # Returns:      Boolean
        ######################################################*/
            
        this.returnError = function (sError, oElement)
        {
            alert(sError);
            oElement.focus();
            
            if (oElement.getAttribute('type') == 'text')
                oElement.select();
        }

        /*######################################################
        # Method:       Validate()
        # Description:  Checks the value for proper formatting
        # Returns:      Boolean
        ######################################################*/
            
        this.Validate = function ()
        {
            var iRow;
            
            // iterate through array and perform validation
            for (iRow = 0; iRow < this.aRequiredFields.length; iRow++)
            {
                // check validation type
                switch (this.aRequiredFields[iRow][3])
                {
                    // input
                    case 1:
                        switch (this.aRequiredFields[iRow][0].getAttribute('type'))
                        {
                            case "text":
                                switch (this.aRequiredFields[iRow][2])
                                {
                                    case "card":
                                        if (this.aRequiredFields[iRow][4] == true)
                                        {
                                            if (this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                if (!this.text_ValidFormat(this.aRequiredFields[iRow][0].value, this.ValidCardNumber))
                                                {
                                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                    return false;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (!this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                return false;
                                            }
                                            else
                                            {
                                                if (!this.text_ValidFormat(this.aRequiredFields[iRow][0].value, this.ValidCardNumber))
                                                {
                                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                    return false;
                                                }
                                            }
                                        }
                                        
                                        break;
                                    case "date":
                                        if (this.aRequiredFields[iRow][4] == true)
                                        {
                                            if (this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                if (!this.text_ValidFormat(this.aRequiredFields[iRow][0].value, this.ValidDate))
                                                {
                                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                    return false;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (!this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                return false;
                                            }
                                            else
                                            {
                                                if (!this.text_ValidFormat(this.aRequiredFields[iRow][0].value, this.ValidDate))
                                                {
                                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                    return false;
                                                }
                                            }
                                        }
                                        break;
                                    case "birthdate":
                                        if (this.aRequiredFields[iRow][4] == true)
                                        {
                                            if (this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                var sBirthdate = this.text_CheckBirthdate(this.aRequiredFields[iRow][0]);
                                                
                                                if (sBirthdate != "")
                                                {
                                                    this.aRequiredFields[iRow][0].value = sBirthdate;
                                                    return true;
                                                }
                                                else
                                                {
                                                    return false;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (!this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                return false;
                                            }
                                            else
                                            {
                                                var sBirthdate = this.text_CheckBirthdate(this.aRequiredFields[iRow][0]);
                                                
                                                if (sBirthdate != "")
                                                {
                                                    this.aRequiredFields[iRow][0].value = sBirthdate;
                                                    return true;
                                                }
                                                else
                                                {
                                                    return false;
                                                }
                                            }
                                        }
                                        
                                        break;
                                    case "phone":
                                        if (this.aRequiredFields[iRow][4] == true)
                                        {
                                            if (this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                if (!this.text_ValidFormat(this.aRequiredFields[iRow][0].value, this.ValidPhone))
                                                {
                                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                    return false;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (!this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                return false;
                                            }
                                            else
                                            {
                                                if (!this.text_ValidFormat(this.aRequiredFields[iRow][0].value, this.ValidPhone))
                                                {
                                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                    return false;
                                                }
                                            }
                                        }
                                                
                                        break;
                                    case "zip":
                                        if (this.aRequiredFields[iRow][4] == true)
                                        {
                                            if (this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                if (!this.text_ValidFormat(this.aRequiredFields[iRow][0].value, this.ValidZip))
                                                {
                                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                    return false;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (!this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                return false;
                                            }
                                            else
                                            {
                                                if (!this.text_ValidFormat(this.aRequiredFields[iRow][0].value, this.ValidZip))
                                                {
                                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                    return false;
                                                }
                                            }
                                        }
                                                    
                                        break;
                                    case "email":
                                        if (this.aRequiredFields[iRow][4] == true)
                                        {
                                            if (this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                if (!this.text_ValidFormat(this.aRequiredFields[iRow][0].value, this.ValidEmail))
                                                {
                                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                    return false;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (!this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                            {
                                                this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                return false;
                                            }
                                            else
                                            {
                                                if (!this.text_ValidFormat(this.aRequiredFields[iRow][0].value, this.ValidEmail))
                                                {
                                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                                    return false;
                                                }
                                            }
                                        }
                                                    
                                        break;
                                    default:
                                        if (!this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                        {
                                            this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                            return false;
                                        }

                                        break;
                                }

                                break;
                            case "password":
                                if (!this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                                {
                                    this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                                    return false;
                                }
                                
                                break;
                            default:
                                return true;
                                break;
                        }

                        break;
                    // select
                    case 2:
                        if (!this.text_ContainsValue(this.aRequiredFields[iRow][0].value))
                        {
                            this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                            return false;
                        }
                        break;
                    // checkbox
                    case 3:
                        if (!this.aRequiredFields[iRow][0].checked)
                        {
                            this.returnError(this.aRequiredFields[iRow][1], this.aRequiredFields[iRow][0]);
                            return false;
                        }
                    default:
                        break;
                }
            }
        }
    }