/*
VERSION:
9/2/2008	1.0.2	Fixed variable error in method `truncate`.
					Added static method `convert` to the String object.
7/1/2008	1.0.1	Added method `stripTags`.
			1.0.0	Begin versioning.
*/
/* STRING PROTOTYPE METHODS ----------------------------------------------- */
String.prototype.repeat = function(n) {
	if(isNaN(n) || n == null || n == '' || n <= 0) { return this; }
	n = Math.floor(n);
	var s = "";
	for(var i = n; i > 0; i--) { s += this; }
	return s;
};
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,'');
};
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,'');
};
String.prototype.stripTags = function(){
	return this.replace(/<(.|\n)+?>/g, '');
}
String.prototype.trim = function() {
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
};
String.prototype.truncate = function(v) {
	v = (isNaN(v) || v == null || v == '' ? 0 : v - 0);
	if(v > 0) {
		if(this.length > v) {
			return this.substr(0, v);
		}
	}
	return this;
};


/* STRING STATIC METHODS ----------------------------------------------- */
String.convert = function(v) {
	//if v is anything other than a string or number, return empty string
	return typeof v != 'string' || typeof v != 'number' ? '' : v + '';
};

/* UTILITY FUNCTIONS FOR STRINGS --------------------------------------------- */

function escapeHTML (str) {
	//from prototype.js
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
};

