﻿    function validateForm() {
        var isFormValid = true;
        $(".validate").each(
            function(index){
                var isElementValid = true;
                if ($(this).is('.date')) {
                    re = /^\s*\d{1,2}(\/|-)\d{1,2}(\/|-)\d{4}\s*$/; 
                    if ((!$(this).val().match(re)) && ($(this).val().match(/\S/))) {
                        isElementValid = false;
                    }
                }
                if ($(this).is('.email')) {
                    re = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; 
                    if ((!$(this).val().match(re)) && ($(this).val().match(/\S/))) {
                        isElementValid = false;
                    }
                }
                if ($(this).is('.phone')) {
                    re = /^\s*\(?\d{3}\)?(-|\.|\s)*\d{3}(-|\.|\s)*\d{4}\s*$/; 
                    if ((!$(this).val().match(re)) && ($(this).val().match(/\S/))) {
                        isElementValid = false;
                    }
                }
                if ($(this).is('.number')) {
                    re = /^\s*\d+\s*$/; 
                    if ((!$(this).val().match(re)) && ($(this).val().match(/\S/))) {
                        isElementValid = false;
                    }
                }
                if ($(this).is('.money')) {
                    re = /^\s*\d+(.\d\d?)?\s*$/; 
                    if ((!$(this).val().match(re)) && ($(this).val().match(/\S/))) {
                        isElementValid = false;
                    }
                }
                if ($(this).is('.zip')) {
                    re = /^\s*\d{5}(-\d{4})?\s*$/; 
                    if ((!$(this).val().match(re)) && ($(this).val().match(/\S/))) {
                        isElementValid = false;
                    }
                }
                if ($(this).is('.required.radiobuttons')) {
                    if (!$("input[name='"+$(this).attr("id")+"']:checked").val()) {
                            $(this).css("background-color","#ff0000");
                            validForm = false;
                    }
                    else {
                            $(this).css("background-color","");
                    }
                } else if ($(this).is('.required')) {
                    if (!$(this).val().match(/\S/)) {
                        isElementValid = false;
                    }
                }
                if (isElementValid) {
                    $(this).css("border","");
                } else {
                    $(this).css("border","#ff0000 solid 3px");
                    isFormValid = false;
                }
            }
        )
        if (!isFormValid) 
            scroll(0,0);
        return isFormValid;
     }