﻿
//This requires that the property NamingContainerId is set on the
//validation object in the code behind by using the: ClientScriptManager..::.RegisterExpandoAttribute Method
var familyDetailsValidationHelper = {

    DoValidate: function(sender, args) {
        args.IsValid = this._isValid("#" + sender.NamingContainerId);
    },

    //ensures that the details information is complete or just empty
    _isValid: function(selector) {
        var isValid = false;
        var numValid = 0;
        //ensure text is filled or not filled
        $(selector + " input").each(function() {
            if ($(this).attr("type") != "radio") {
                numValid += ($(this).val().length > 0 ? 1 : 0); //increment numValid if there is data in the field
            }
        });
        isValid = (numValid == 0 || numValid == 2);
        //ensure radio buttons have been selected if it's valid
        if (numValid == 2) {
            //first check if there are radio buttons
            if ($(selector + " .radioButtons input").length > 0) {
                isValid = ($(selector + " .radioButtons input:checked").val() != undefined);
            }
        }
        return isValid;
    }
}


