// Returns the string with all the beginning
// and ending whitespace removed
String.prototype.trim = function() {
	return this.replace(/^\s+/, '').replace(/\s+$/, '');
};

//Returns true if the string contains the text
String.prototype.contains = function(text) {
	return this.indexOf(text)>=0;
};

// Returns the left x characters of the string
String.prototype.left = function(count) {
	if (this.length>count) {
		return this.substring(0, count);
	}
	else {
		return this;
	}
};

// Returns the right x characters of the string
String.prototype.right = function(count) {
	if (this.length>count) {
		return this.substring(this.length-count, this.length);
	}
	else {
		return this;
	}
};

// Returns true if the string begins with value
String.prototype.startsWith = function(value) {
	if (value===null || this.length<value.length) {
		return false;
	}
	else {
		return this.substring(0, value.length)===value;
	}
};

// Returns true if the string ends with value
String.prototype.endsWith = function(value) {
	if (value===null || this.length<value.length) {
		return false;
	}
	else {
		return this.substring(this.length-value.length, this.length)===value;
	}
};

// Returns a shortened version of the string
// suffixed with "..." if characters are truncated
// from the original string
String.prototype.shorten = function(maxLength) {
	if (!this) {
		result = null;
	}
	else if (this.length>maxLength) {
		preferredSize = maxLength-'...'.length;
		if (preferredSize>0) {
			result = this.left(preferredSize) + '...';
		}
		else {
			result = this.left(maxLength);
		}
	}
	else {
		result = this;
	}
	return result;
};

String.prototype.encodeForHtml = function() {
	return this.replace(/</g, '&lt;').replace(/>/g, '&gt;');
};

