var GuideFormObserver = Class.create({
    update: function () {
    }
});

var GuideCheckboxObserver = Class.create(GuideFormObserver, {
    initialize: function (checkboxs, btns, limit) {
        this.checkboxs = checkboxs;
        this.btns      = btns;
        this.limit     = limit;
    },

    update: function () {
        var count = this.checkboxs.inject(0, function (acc, checkbox) {
            return checkbox.checked ? acc+1 : acc;
        });
        if (count >= this.limit) {
            this.checkboxs.each(function (checkbox) {
                if (!checkbox.checked) { checkbox.disabled = true; }
            });
        } else {
            this.checkboxs.each(function (checkbox) {
                checkbox.disabled = false;
            });
        }
        this.btns.each(function (btn) { btn.disabled = (count == 0); });
    }
});

