﻿(function($) {
    $.fn.jsonserialize = function(options) {

        options = $.extend({}, options);

        var obj = {};

        $(this).each(function() {
            $(this).find(':input').each(function() {
                var val = $('*[name=' + this.name + ']').val();
                obj[this.name] = val;
            });
        });
        return obj;
    };

    $.fn.mutuallyExclude = function(options) {

        options = $.extend({
            defaultCheckboxId: null,
            callback: function() { }
        }, options);

        var allItems = $(this);

        $(this).each(function() {
            $(this).bind('click', function() {
                if (this.checked) {
                    allItems.not($(this)).attr('checked', '');
                }
                else {
                    if (options.defaultCheckboxId != null) {
                        $('#' + options.defaultCheckboxId).attr('checked', 'checked');
                    }
                }

                options.callback();
            });
        });
    }
})(jQuery);
