function checkForm() {
    var error = 0;
    jQuery("#formcontainer input").each(function (i, e) {

        if (typeof jQuery(e).data('no-autovalidate') === "undefined" && !jQuery(e).val() && error < 1) {
            error = 1;           
        }
        else if (jQuery(e).data('no-autovalidate') == 'yes') {

            if (jQuery(e).attr('id').indexOf("tbOrgNewAcct") > -1) {

                var radioTable = jQuery("table[id*='rbMediaNewAcct']");
                var list = document.getElementById(radioTable.attr('id'));
                var inputs = list.getElementsByTagName("input");
                var selected;
                for (var i = 0; i < inputs.length; i++) {
                    if (inputs[i].checked) {
                        selected = inputs[i];
                        break;
                    }
                }
                if (selected && selected.value == 1 && !jQuery(e).val() && error < 1) {
                    error = 1;                  
                }
            }
            else if (jQuery(e).attr('id').indexOf("tbOrgUpdate") > -1) {

                var radioTable = jQuery("table[id*='rbMediaUpdate']");
                var list = document.getElementById(radioTable.attr('id'));
                var inputs = list.getElementsByTagName("input");
                var selected;
                for (var i = 0; i < inputs.length; i++) {
                    if (inputs[i].checked) {
                        selected = inputs[i];
                        break;
                    }
                }
                if (selected && selected.value == 1 && !jQuery(e).val() && error < 1) {
                    error = 1;                   
                }
            }
        }

        if (jQuery(e).attr('id').indexOf("rbMediaNewAcct_0") > -1) {

            var radioTable = jQuery("table[id*='rbMediaNewAcct']");
            var list = document.getElementById(radioTable.attr('id'));
            var inputs = list.getElementsByTagName("input");
            var selected;

            for (var i = 0; i < inputs.length; i++) {
                if (inputs[i].checked) {
                    selected = inputs[i];
                    break;
                }
            }
            if (selected == null) {
                error = 1;              
            }
        }
        else if (jQuery(e).attr('id').indexOf("rbMediaUpdate_0") > -1) {

            var radioTable = jQuery("table[id*='rbMediaUpdate']");
            var list = document.getElementById(radioTable.attr('id'));
            var inputs = list.getElementsByTagName("input");
            var selected;
            for (var i = 0; i < inputs.length; i++) {
                if (inputs[i].checked) {
                    selected = inputs[i];
                    break;
                }
            }
            if (selected == null) {
                error = 1;             
            }
        }
    });


    jQuery("#formcontainer input[id*='tbEmail']").each(function () {
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        var email = jQuery(this).val();

        if (re.test(email) != true) {
            error = 1;           
        }
    });

    return error;
}

jQuery(document).ready(function () {

    jQuery("#formcontainer input[type*=submit]").click(function () {
        if (jQuery(this).attr('value') == 'Cancel') {
            window.location = location.protocol + '//' + location.host + location.pathname;
        }
        else if (jQuery(this).attr('value').indexOf('Forgot Answer?') > -1) {
            //do nothing
        }
        else {
            var error = checkForm();

            if (error == 1) {
                alert("It appears that your submission has errors. Please ensure that all input boxes have been completed and that you have entered a valid e-mail address.");
                return false;
            }
        }
    });

    jQuery("table[id*='rbMediaNewAcct'] input").change(function () {

        if (jQuery(this).val() == 0) {

            jQuery("tr[id*='trOrgNewAcct']").hide();
        }
        else {
            jQuery("tr[id*='trOrgNewAcct']").show();
        }
    });

    jQuery("table[id*='rbMediaUpdate'] input").change(function () {

        if (jQuery(this).val() == 0) {

            jQuery("tr[id*='trOrgUpdate']").hide();
        }
        else {
            jQuery("tr[id*='trOrgUpdate']").show();
        }
    });


 

});