/**
 * TRIM Compatibility
 * Javascript 1.2+ or JScript 3.0+
 * All modern (version 4+)
 */ 

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
};

String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
};

String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
};

String.prototype.equalsIgnoreCase = function(string) {
	return this.toLowerCase() == string.toLowerCase();
};

String.prototype.toArray = function(splitter) {
	return this.split(splitter);
};

String.prototype.getValue = function() {
	return this;
};

// boolean equals(Object anObject)
String.prototype.equals = function(anObject) {
	if (this == anObject) {
	    return true;
	}
	if (anObject instanceof String) {
	    var anotherString = anObject;
	    var n = count;
	    if (n == anotherString.count) {
		var v1 = value; // v1[]
		var v2 = anotherString.value;  // v2[]
		var i = offset;
		var j = anotherString.offset;
		while (n-- != 0) {
		    if (v1[i++] != v2[j++])
			return false;
		}
		return true;
	    }
	}
	return false;
};

String.prototype.right = function(len) {
	return this.substring(this.length - len - 1);
};

String.prototype.left = function(len) {
	return this.substring(0, len-1); 
};

// boolean startsWith(String prefix, int toffset)
String.prototype.startsWith = function(prefix, toffset) {
	if (toffset < 0 || toffset > this.length-1) return false;
	var toffs = (typeof toffset == 'undefined' || !toffset)?0:toffset;
	var comp = this.substring(toffs);
	return comp.indexOf(prefix) == 0;
};

// boolean endsWith(String suffix)
String.prototype.endsWith = function(suffix) {
	return this.startsWith(suffix, this.length - suffix.length);
};


