/*
	JS Extending Library
	String functions.
	build 200806091110
*/

String.prototype.ucFirst = function() {
	return (this.substr(0, 1).toUpperCase() + this.substr(1).toLowerCase());
}

String.prototype.trim = function() {
	return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

String.prototype.addslashes = function() {
	return this.split('\\').join('\\\\').split('"').join('\\"');
}

String.prototype.reverse = function() {
	var src = this.toString();
	var res = '';
	for (var i = (src.length - 1); i > -1; --i) res += src.charAt(i);
	return res;
}

String.prototype.leadingZeroes = function(zeroes) {
	if (this < 0) {
		var sign = '-';
		var res = this.substr(1);
	} else {
		var sign = '';
		var res = this.toString();
	}
	if (! isset(zeroes)) var zeroes = 2;
	zeroes -= res.length;

	for (var i = 0; i < zeroes; ++i) res = '0'+ res;

	return (sign + res);
};

String.prototype.format = function(dec, decPoint, thousSep) {
	if (! isset(dec)) var dec = 2;
	if (! isset(decPoint)) var decPoint = '.';
	if (! isset(thousSep)) var thousSep = ' ';

	return (this * 1.0).format(dec, decPoint, thousSep);
}

String.prototype.htmlspecialchars = function() {
	return this.replace('&', '&amp;').replace('"', '&quot;').replace('\'', '&#039;').replace('<', '&lt;').replace('>', '&gt;');
}

function str_repeat(s, mult) {
	res = '';
	for (var i = 0; i < mult; i++) res += s;
	return res;
}

function htmlspecialchars(s) {
	return s.replace('&', '&amp;').replace('"', '&quot;').replace('\'', '&#039;').replace('<', '&lt;').replace('>', '&gt;');
}
