    var phonePattern = /\(\d\d\d\) \d\d\d-\d\d\d\d/;
    var phoneAlt     = '(555) 555-5555';
    var phoneLength  = 14;

    var datePattern  = /\d\d\/\d\d\/\d\d\d\d/;
    var dateAlt      = 'mm/dd/yyyy';
    var dateLength   = 10;

    var a = new Array;

    function setPhoneFormat(p, d, l) {
        if(p) { phonePattern = p; }
        if(d) { phoneAlt = d; }
        if(l) { phoneLength = l; }
    }


    function setDateFormat(p, d, l) {
        if(p) { datePattern = p; }
        if(d) { dateAlt = d; }
        if(l) { dateLength = l; }
    }


    function isBlank(s) {
        if(s == null || s == "") {
            return true;
        }

        for(var i = 0; i < s.length; i++) {
            var c = s.charAt(i);
            if((c != ' ') && (c != '\n') && (c != '\t')) {
                return false;
            }
        }
        return true;
    }


    function clearFlags() {
        for(var x = 0; x < a.length; x++) {
            a[x].wasChecked = 0;
        }
    }


    function verifySubmit(f) {
        var msg = '';
        var empty_fields = '';
        var errors = '';

        for(var i = 0; i < f.length; i++) {
            var e = f.elements[i];
            var field = e.alt || e.name;

     	    if(e != null && typeof(e) != 'undefined') {

                if(((e.type == "text") || (e.type == "textarea") || (e.type == "password")) && !e.optional && e.disabled == false) {
                    if(isBlank(e.value)) {
                        empty_fields += "\n    - " + field;
                        continue;
                    }
                    if(e.numeric || (e.min != null) || (e.max != null)) {
                        var v = parseFloat(e.value);
                        if(isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max))) {
                            errors += "- The field " + field + " must be a number";
                            if(e.min != null) {
                                errors += " that is greater than " + e.min;
                            }
                            if(e.max != null && e.min != null) {
                                errors += " and less than than " + e.max;
                            }
                            else if(e.max != null) {
                                errors += " that is less than " + e.max;
                            }
                            errors += ".\n";
                        }
                    }
                }
                else if(e.type == "select-one" && !e.optional && e.disabled == false) {
                    if(isBlank(e.options[e.selectedIndex].value)) {
                        empty_fields += "\n    - " + field;
                    }
                }


                else if(e.type == "select-multiple" && !e.optional && e.disabled == false) {
                    if(readSelectSet(f, e.name) == 0) {
                        empty_fields += "\n    - " + field;
                    }
                }

                else if(e.type == "checkbox" && !e.optional && e.disabled == false) {
                    if(!(e.checked)) {
                        errors += "- " + field + " must be checked\n";
                    }
                }

                else if(e.type == "radio" && !e.optional && e.disabled == false) {
                    if(readRadioSet(f, e.name) == 0) {
                        empty_fields += "\n    - " + field;
                    }
                }

                if(e.isPhone && !isBlank(e.value) && e.disabled == false) {
                    if(e.value.length != phoneLength) { // Account for extra crap or fields that are too short
                        errors += "- The field " + field + " must be in the format " + phoneAlt + "\n";
                        continue;
                    }
                    if((e.value.match(phonePattern) == null)) {
                        errors += "- The field " + field + " must be in the format " + phoneAlt + "\n";
                    }
                }
                if(e.isDate && !isBlank(e.value) && e.disabled == false) {
                    if(e.value.length != dateLength) { // Account for extra crap or fields that are too short
                        errors += "- The field " + field + " must be in the format " + dateAlt + "\n";
                        continue;
                    }

                    if((e.value.match(datePattern) == null)) {
                        errors += "- The field " + field + " must be in the format " + dateAlt + "\n";
                    }
                }
                if(e.isEmail && !isBlank(e.value) && e.disabled == false) {
                    if((e.value.match(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) == null)) {
                        errors += "- Invalid email address\n";
                    }
                }
                if(e.isNumber && !isBlank(e.value) && e.disabled == false) {
                    if(isNaN(e.value)) {
                        errors += "- The field " + field + " must be a number.\n";
                    }
                }
                if(e.isCreditCard && !isBlank(e.value) && e.disabled == false) {
                    if(checkCreditCard(e.value) == false) {
                        errors += "- Credit Card number entered is an invalid format\n";
                    }
                }
            }
        }

        if(!empty_fields && !errors) {
            return true;
        }

        msg += "The form was not submitted because of the following error(s)\n";
        msg += "Please correct these errors and re-submit.\n";
        msg += "________________________________________________\n\n\n";

        if(empty_fields) {
            msg += "The following required field(s) are empty:" + empty_fields + "\n";
            if(errors) {
                msg += "\n";
            }
        }
 
        msg += errors;

        clearFlags();

        alert(msg);

        return false;
    }


    function readRadioSet(f, s) {
        var e = eval('document.forms.' + f.name + '.' + s);

        if(e.wasChecked) {
            return;
        }
        
        var checked = 0;

        for(var x = 0; x < e.length; x++) {
            if(e[x].checked) {
                checked = 1;
                continue;
            }
        }

        e.wasChecked = 1;
        a.push(e);

        if(checked) {
            return true;
        }

        return false;
    }

    
    function readSelectSet(f, s) {
        var e = eval('document.forms.' + f.name + '.' + s);

        if(e.wasChecked) {
            return;
        }
        
        var checked = 0;

        for(var x = 0; x < e.length; x++) {
            if(e[x].selected) {
                checked = 1;
                continue;
            }
        }

        e.wasChecked = 1;
        a.push(e);

        if(checked) {
            return true;
        }

        return false;
    }


    function checkCreditCard(n) {
        var cc = n.replace(/[^0-9]/g, '');

        if(isNaN(cc) || isBlank(cc)) {
            return false;
        }

        var num_digit = cc.length;
        var oddOReven = num_digit & 1;
        var sum = 0;

        for(var count = 0; count < num_digit; count++) {
            var digit = parseInt(cc.charAt(count));
            if(!((count & 1) ^ oddOReven)) {
                digit *= 2;
                if(digit > 9)
                    digit -= 9;
                }
                sum += digit;
            }

            if(sum % 10 == 0) {
                return true;
            }
            else {
                return false;
            }

        return false;
    }