var strTestExists = 'test string';

try {
	strTestExists.trim();
} catch (e) {
	String.prototype.trim = function () {
	  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
	}
}

try {
	strTestExists.toUCaseFirst();
} catch (e) {
	String.prototype.toUCaseFirst = function() {
		a = this.substr(0,1).toUpperCase();
		a = a + this.substr(1).toLowerCase();
		return  a;
	};
}

try {
	strTestExists.formatNumber();
} catch (e) {
	String.prototype.formatNumber = function(decimal_places, comma) {
		var tmpNum = parseFloat(this);
		if (isNaN(tmpNum)) tmpNum = 0;
		
		if (!decimal_places) decimal_places = 0;
		tmpNum = tmpNum.toFixed(decimal_places);
		
		fNum = tmpNum + '';
		if (comma) {
			x = fNum.split('.');
			x1 = x[0];
			x2 = x.length > 1 ? '.' + x[1] : '';
			var rgx = /(\d+)(\d{3})/;
			while (rgx.test(x1)) {
				x1 = x1.replace(rgx, '$1' + ',' + '$2');
			}
			fNum = x1 + x2;
		}
		
		return fNum;
	}
}

try {
	strTestExists.toMoney();
} catch (e) {
	String.prototype.toMoney = function(cSign) {
		if (!cSign) cSign = '$';
		return cSign+this.formatNumber(2,true);
	}
}

try {
	var elmTestExists = new Element('div');
	elmTestExists.replaceClass('oldclass', 'newclass');
} catch (e) {
	try {
		Element.prototype.replaceClass = function (oldClass, newClass) {
			var regex_replace = new RegExp('\\b'+oldClass+'\\b');
			var className = new String(this.className);
			var tmp = new String(className.match(regex_replace));
			
			tmp = tmp.replace(oldClass, newClass);
			this.className = className.replace(regex_replace, tmp);
			
			return this.className;
		}
	} catch (e) { /* Element.prototype appears to be unsupported */ }
}

try {
	document.getElementsByClassName('someclassthatdoesnotexist');
} catch (e) {
	try {
	HTMLDocument.prototype.getElementsByClassName = function(class_name) {
		var elms = [];
		var regex_test = new RegExp('\\b'+class_name+'\\b');
		var elem = this.getElementsByTagName('*');
		for (var i = 0; i < elem.length; i++) {
			if (regex_test.test(elem[i].className)) elms.push(elem[i]);
		}
		return elms;
	};
	}catch (e) { /* HTMLDocument.prototype appears to be unsupported */ }
}

