jQuery.fn.extend({
    heavyLoad: function (url, data, success) {
        var loadingIndicator = jQuery('<div id="loading-indicator"><span>'+LOADING_TEXT+'...</span></div>');
        jQuery(this).prepend(loadingIndicator);
        jQuery(this).load(Environment_APP_PATH + url, data, function () {
            loadingIndicator.remove();
            if (success) success();
        });
    }

});

jQuery.fn.extend({
    heavyLoadCombos: function (url, data, success) {
        //var loadingIndicator = jQuery('<option value="" selected>'+LOADING_TEXT+'...</option>');
        jQuery('select option', this).remove();
        jQuery('select', this).append('<option value="" selected>'+LOADING_TEXT+'...</option>');
        jQuery(this).load(Environment_APP_PATH + url, data, function () {
            if (success) success();
        });
    }

});

jQuery.unparam = function (value) {
    var params = {},
    pieces = value.split('&'),
    pair, i, l;

    for (i = 0, l = pieces.length; i < l; i++) {
        pair = pieces[i].split('=', 2);

        params[decodeURIComponent(pair[0])] = (pair.length == 2 ?
            decodeURIComponent(pair[1].replace(/\+/g, ' ')) : true);
    }

    return params;
};

jQuery.fn.extend({
    isEmpty: function () {
        if (jQuery(this).val().length == 0) {jQuery(this).addClass("error");return true;}
        else {jQuery(this).removeClass("error");return false;}
    }
});

jQuery.fn.extend({
    hasRequiredEmpty: function () {
        var $empty = false;
        $jq("select[require=1],select[require=true],input[require=1],input[require=true]", $jq(this))
            .each(function () { if (jQuery(this).isEmpty()) $empty = true; })
        return $empty;
    }
});

jQuery.fn.extend({
    enabledAndNumbers: function () {
        var $result = true;
        $jq(":text:enabled", jQuery(this))
            .each(function () { 
                if (!(/^[0-9]+$/i.test(jQuery(this).val()))) {
                    jQuery(this).addClass("error");
                    $result = false; 
                }});
        return $result
    }
});
