
jQuery.htmlspecialchars = function(value) {
	return this('<div/>').text(value).html().replace('"', '&quot;').replace("'", '&apos;');
}

jQuery.cleanSpace = function(value) {
	return this.trim(value.replace(/\s+/, ' '));
}

jQuery.zeroPad = function(number, width) {
	if (width === undefined)
		width = 2;
	number += '';
	while (number.length < width)
		number = '0' + number;
	return number;
}
       
jQuery.fn.reverse = function() {
	return this.pushStack(this.get().reverse());
};

jQuery.fn.inputDisable = function(disable) {
	if (disable === undefined)
		disable = true;
	else
		disable = !!disable;
	return this.each(function () {
		if ($(this).is(':input, option'))
			this.disabled = disable;
	});
};

//log jQuery objects without breaking function chain e.g. $('#some-div').cLog().find('span').cLog().each(...);
jQuery.fn.cLog = function() {
	if (typeof console !== 'undefined' && console.log)
		console.log(this);
	return this;
};

jQuery.fn.hasAncestor = function(selector) {
	return this.filter(function() {
		return !!$(this).closest(selector).length;
	});
};

jQuery.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}

function three_ajax(module, action, data, callback, error, noDataSubitem) {
	var post;
	if (noDataSubitem)
		post = $.extend({}, data, {module: module, action: action});
	else
		post = {module: module, action: action, data: data};
	jQuery.ajax({
		type: 'POST',
		url: location.pathname.replace(/\badmin(\/.*)?$/, '') + '?/m/ajax',
		data: post,
		success: callback,
		error: error
	});
}

//can we delete this? only post works in core
function three_get(module, action, data, callback, error) {
	var get = {module: module, action: action, data:data};
	jQuery.ajax({
		url: location.pathname.replace(/\badmin(\/.*)?$/, '') + '?/m/ajax',
		data: get,
		success: callback,
		error: error
	});
}

