
function url_encode(str) {
	str = escape(str);
	return str.replace(/%20/g, '+');
}

(function($) {
	$.fn.toggleText = function(a, b) {
		return this.each(function(i, e) {
			$(e).text($(e).text() == a ? b : a);
		});
	}
})(jQuery);

function formatCurrency(value) {
	value = value.toFixed('2') + '';
	var rx = new RegExp('(-?[0-9]+)([0-9]{3})');
	while(rx.test(value)) { value = value.replace(rx, '$1,$2'); }
	return '$' + value;
}

String.prototype.leftPad = function (length, pad) {
	return new Array(length - this.length + 1).join(pad || '0') + this;
}

String.prototype.capitalize = function(){
	return this.replace( /(^|\s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); } );
};

