﻿function ValidateGroups(buttonId, validationGroupList) {
    $("#" + buttonId).click(function(e) {
        //Bind the logic to the specified button with jQuery
        var list = validationGroupList.split(',');

        //Loop through the entire set of page validators
        $.each(Page_Validators, function() {
            if ((this.validationGroup && ExistsGroup(list, this.validationGroup)) ||
             (!this.validationGroup && ExistsGroup(list, ''))) {
                ValidatorValidate(this, this.validationGroup);
                Page_IsValid = Page_IsValid && this.isvalid;
            }
        });

        //Reflect validation in ValidationSummary's if there are any in the page
        $.each(list, function() {
            ValidationSummaryOnSubmit(this);
        });

        //If Page_IsValid is false the execution flow will be interrupted
        return Page_IsValid;
    });
}

function ExistsGroup(list, group) {
    var found = false;
    for (i = 0; i < list.length; i++) {
        if (list[i] == group) {
            found = true;
            break;
        }
    }
    return found;
}