Extensions - jQuery

/*===============================================================================================*/
(function ($) {
    /*-------------------------------------------------------------------------------------------*/
    $.fn.showIf = function (show, fade) {

        if (fade == undefined) fade = false;

        if (show) {
            if (fade) this.fadeIn(); else this.show();
        }
        else {
            if (fade) this.fadeOut(); else this.hide();
        }
        return this;
    }
    /*-------------------------------------------------------------------------------------------*/
    $.fn.enableIf = function (enabled, disabledClass) {

        if (enabled) {
            this.removeAttr('disabled');
            if (disabledClass!= undefined)
                this.removeClass(disabledClass);
        }
        else {
            this.attr('disabled', 'disabled');
            if (disabledClass!= undefined)
                this.addClass(disabledClass);
        }

        return this;
    }
    /*-------------------------------------------------------------------------------------------*/
    $.fn.lockEditIf = function (readOnly) {

        if (readOnly)
            this.removeAttr('readonly');
        else
            this.attr('readonly', 'readonly');

        return this;
    }
    /*-------------------------------------------------------------------------------------------*/
    $.fn.setCheckedIf = function (checked) {

        if (checked)
            this.attr('checked', 'checked');
        else
            this.removeAttr('checked');

        return this;
    }
    /*-------------------------------------------------------------------------------------------*/
    $.fn.validateInt = function (errorClassName) {

        var input = $(this).val();
        if ((input - 0) == input && Math.ceil(input) == Math.floor(input)) {
            $(this).removeClass(errorClassName);
            return true;
        }
        else {
            $(this).addClass(errorClassName);
            return false;
        }
    }
    /*-------------------------------------------------------------------------------------------*/
})(jQuery);
/*===============================================================================================*/