﻿(function ($) {
    $.fn.selctl = function (s) {
        s = $.extend({
            all: null,
            reverse: null,
            cancel: null
        }, s || {});
        return this.each(function () {
            var that = this;
            if (s.all)
                s.all.click(function () {
                    $(that).find(":checkbox").attr("checked", "checked");
                });
            if (s.reverse)
                s.reverse.click(function () {
                    var checkeds = $(that).find(":checked");
                    var nocheckeds = $(that).find(":checkbox:not(:checked)");
                    checkeds.removeAttr("checked");
                    nocheckeds.attr("checked", "checked");
                });
            if (s.cancel)
                s.cancel.click(function () {
                    $(that).find(":checked").removeAttr("checked");
                });
        });
    }
    return this;
})(jQuery);
