
function ValidateForm(form) {
    var e, title, empty_fields, char_check, invalid_faxNumber, invalid_card, month, year, invalid_date, eMail, invalid_eMail
    var strDate
    var iQuantity, quantity_check, checkSpecial, tempError, special_Error, msg, upperLine, lowerLine
    var num, invalid_phoneNumber, passwd_mismatch, invalid_ssn
    var strRadioButtonNames
    var RadioExists
    var RadioCnt
    var RadioChecked
    var ProdAttrCount
    ProdAttrCount = 1;
    strRadioButtonNames = ";"
    msg = "";
    empty_fields = "";
    char_check = "";
    special_Error = "";
    tempError = "";
    num = form.length
    var PasswordSet
    var PasswordStr
    for (var i = 0; i < form.length; i++) {
        e = form.elements[i]
        if ((e.title == null) || (e.title == "")) {
            title = e.name;
        }
        else {
            title = e.title;
        }

        if (((e.type == "text") || (e.type == "textarea") || (e.type == "password")) && !e.special && !e.disabled) {

            if (e.value.length <= 0 && e.required) {
                empty_fields += "\n            " + title;

                continue;
            }
            if (e.number) {
                num = e.value;
                num = stripChar(num, ".");
                num = stripChar(num, ",");
                if (!isNumber(num) || num.length > 10) {
                    char_check += "\n             " + title;
                }
            }
            if (e.creditcardnumber) {
                e.value = stripChar(e.value, " ");
                e.value = stripChar(e.value, "-");
                invalid_card = isCardNumValid(e.value);
            }


            if (e.email) {
                eMail = e.value;
                if (eMail.length > 0) {
                    if ((eMail.indexOf("@") != -1) && (eMail.indexOf(".") != -1)) {
                        invalid_eMail = false;
                    }
                    else {
                        invalid_eMail = true;
                    }
                }
            }
            if (e.name == "txtEmail") {
                eMail = e.value;
                if ((eMail.indexOf("@") != -1) && (eMail.indexOf(".") != -1)) {
                    invalid_eMail = false;
                }
                else {

                    invalid_eMail = true;
                }
            }


            if (e.phonenumber) {
                if (e.value != "") {
                    var isFax = e.title.indexOf("Fax");
                    if (isFax >= 0) {
                        num = e.value;
                        num = stripChar(num, " ");
                        num = stripChar(num, "-");
                        num = stripChar(num, "+");
                        if (num.length < 10) {
                            invalid_faxNumber = true;
                        }
                    }
                    else {

                        num = e.value;
                        num = stripChar(num, " ");
                        num = stripChar(num, "-");
                        num = stripChar(num, "+");
                        if (num.length < 10) {
                            invalid_phoneNumber = true;
                        }
                    }
                }
            }
            if (e.ssn) {
                if (e.value != "") {
                    num = e.value;
                    num = stripChar(num, "-");
                    if (num.length != 9 || !isNumber(num)) {
                        invalid_ssn = true;
                    }
                }
            }
            if (e.date) {
                if (e.value != "") {
                    strDate = e.value;

                    if (!isDate(strDate)) {
                        invalid_date = true;
                    }
                }
            }
        }
        if (e.quantitybox) {
            iQuantity = e.value;
            if (!isNumber(iQuantity)) {
                quantity_check = true;
            }
            if (parseInt(iQuantity) < 0) {
                quantity_check = true;
            }
            if ((iQuantity) < 1) {
                quantity_check = true;
            }

        }
        if (e.password) {
            if (PasswordSet == true) {
                if (e.value != PasswordStr) {
                    passwd_mismatch = true;
                }
            }
            else {
                PasswordSet = true;
                PasswordStr = e.value;
            }
        }
        //if (e.special) {
        //	checkSpecial = specialCase(e, form);
        //	if (tempError != checkSpecial) {
        //		special_Error = special_Error + checkSpecial
        //	}
        //	tempError = checkSpecial;
        //}


        if (e.type == "select-one") {
            if (e.required) {
                //alert(e.options.selectedIndex)
                if (e.options[e.options.selectedIndex].value == "" || e.options[e.options.selectedIndex].value == "Select" || e.options[e.options.selectedIndex].value == "--Select State--" || e.options[e.options.selectedIndex].value == "Month" || e.options[e.options.selectedIndex].value == "Year" || e.options[e.options.selectedIndex].value == "-1" || (e.options[e.options.selectedIndex].value == "NONE" && e.name.indexOf("cboShipping") > -1) || (e.options[e.options.selectedIndex].value == "0" && e.name.indexOf("cboShipChoices") > -1)) {
                    empty_fields += "\n            " + title;
                    continue;
                }
            }
        }
        if (e.type == "radio" && e.required) {
            if (strRadioButtonNames.indexOf(";" + e.name + ";") == -1) {//title=title + " " + ProdAttrCount
                //ProdAttrCount=++ProdAttrCount;
                RadioExists = true;
                RadioChecked = false;
                RadioCnt = 0
                strRadioButtonNames = strRadioButtonNames + e.name + ";"
                if (form.elements[e.name].checked == true) {
                    RadioChecked = true;
                }
                else if (form.elements[e.name].checked == false) {
                    empty_fields += "\n            " + title;
                }
                else {
                    do {
                        if (form.elements[e.name][RadioCnt] == undefined) {
                            RadioExists = false;
                        }
                        else {
                            if (form.elements[e.name][RadioCnt].checked == true)
                            { RadioChecked = true; }

                        }
                        RadioCnt = ++RadioCnt
                    } while (RadioExists == true);
                    if (RadioChecked == false) {
                        empty_fields += "\n            " + title;
                        continue;
                    }
                }
            }
        }
    }

    if (!empty_fields && !char_check && !invalid_ssn && !special_Error && !invalid_card && !invalid_date && !invalid_eMail && !quantity_check && !invalid_phoneNumber && !passwd_mismatch) { return true }

    msg = "The form was not submited due to the following error(s).\n";

    upperLine = "\n_________________________________________________________\n\n";
    lowerLine = "_________________________________________________________\n";

    if (empty_fields) {
        msg += upperLine;
        msg += "The following field(s) must be filled in:\n";
        msg += lowerLine;
        msg += empty_fields;
    }
    if (char_check) {
        msg += upperLine;
        msg += "The following field(s) need a numeric value 10 characters long or less:\n";
        msg += lowerLine;
        msg += char_check;
    }
    if (quantity_check) {
        msg += upperLine;
        msg += "Please Enter a Positive Integer.\n"
        msg += lowerLine;
    }
    if (invalid_card) {
        msg += upperLine;
        msg += "The Credit Card Number is an invalid format.\n";
        msg += lowerLine;
    }
    if (invalid_date) {
        msg += upperLine;
        msg += "Please Enter a Valid Date.\n";
        msg += lowerLine;
    }
    if (invalid_eMail) {
        msg += upperLine;
        msg += "The Email Address is in an invalid format.\n";
        msg += lowerLine;
    }
    if (invalid_phoneNumber) {
        msg += upperLine;
        msg += "Please enter a valid Phone Number with area code.\n";
        msg += lowerLine;
    }
    if (invalid_faxNumber) {
        msg += upperLine;
        msg += "Please enter a valid Fax Number with area code.\n";
        msg += lowerLine;
    }
    if (invalid_ssn) {
        msg += upperLine;
        msg += "Please enter a valid Social Security Number.\n";
        msg += lowerLine;
    }
    if (special_Error) {
        msg += upperLine;
        msg += special_Error + "\n";
        msg += lowerLine;
    }
    if (passwd_mismatch) {
        msg += upperLine;
        msg += "Your passwords did not match. Please enter them again.\n";
        msg += lowerLine;
    }
    alert(msg);
    return false;
}