/**
 * Compatibility functions
 */

if (String.prototype.trim === undefined) {
	
	String.prototype.trim = function () {
		try {
			var start = 0;
			while (start < this.length && this.charCodeAt(start) == 32 || this.charCodeAt(start) == 9) {
				start++;
			}
			var end  = this.length;
			while (end > start && this.charCodeAt(end-1) == 32 || this.charCodeAt(end-1) == 9) {
				end--;
			}
			
			return this.substring (start, end);				
		} catch (e) {
			return this;
		}
	};
}
	
if (typeof (console) == "undefined") {
	console = {};
	console._write = function (level, str) {
		try {				
			var c = document.getElementById ('Console');
			c.className = level;
			var div = document.createElement ('div');
			div.innerHTML = str;
			c.appendChild (div);
		} catch (e) {
			// Do nothing. Too bad.
		}
	}
	
	console.log = function (str) {
		this._write ('log', str);
	}
	
	console.warn = function (str) {
		this._write ('warn', str);
	}
	
	console.error = function (str) {
		this._write ('error', str);
	}
	
	console.debug = function (str) {
		this._write ('debug', str);
	}
}
