String.prototype.endsWith = function(str){return (this.match(str+"$")==str)}

String.prototype.startsWith = function(str){ return (this.match("^"+str)==str) }

String.prototype.trim = function(){return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, "")) }

String.prototype.wordCount = function() { 
	var split = this.split(' ');
	
	if(split[split.length-1] == "")
		split.length--
		
	return split.length; };

String.prototype.getWordAt = function(wordIndex) { return this.split(' ')[wordIndex] };

//This function escapes CSS notations so the string can be used as an id or class.
String.prototype.css_esc = function() { return this.replace(/(:|\.)/g,'\\$1'); }

//Like the php version
String.prototype.htmlentities = function() {return this.
    replace(/&/gmi, '&amp;').
    replace(/"/gmi, '&quot;').
	replace(/‘/gmi, '&lsquo;').
	replace(/’/gmi, '&rsquo;').
	replace(/'/gmi, '\'').
    replace(/>/gmi, '&gt;').
    replace(/</gmi, '&lt;')
}
