//'getElementById()' support for older browsers.

if (!document.getElementById) {
  	if (document.all)
 		document.getElementById = function () {
    		if (typeof document.all[arguments[0]] != "undefined")
    			return document.all[arguments[0]];
    		else
    			return null;
  		};
  	else if (document.layers)
  		document.getElementById = function () {
   		 	if (typeof document[arguments[0]] != "undefined")
   				return document[arguments[0]];
    		else
    			return null;
  		};
}

//Implements support for 'push()' and 'shift()' for Array objects.
//Pre 5.5IE.

if (!Array.prototype.push) {
	Array.prototype.push = function () {
		for (var i = 0; i < arguments.length; i++) 
			this[this.length + i] = arguments[i];
		return this.length;
	};
}

if (!Array.prototype.pop) {
 	Array.prototype.pop = function () {
		var val = this[this.length - 1];
		this.length = Math.max(this.length - 1, 0);
		return val;
	};
}

if (!Array.prototype.shift) {
 	Array.prototype.shift = function () {
  		var val = this[0];
		this.reverse();
  		this.length = Math.max(this.length - 1, 0);
		this.reverse();
  		return val;
	};
}

if (!Array.prototype.unshift) {
 	Array.prototype.unshift = function () {
		this.reverse();
		for (var i = 0, j = arguments.length - 1; j >= 0; i++, j--)
  			this[this.length + i] = arguments[j];
		this.reverse();
	};
}

//Method to clone an object.

function clone(obj) {
	if (typeof(obj) != "object" || obj == null) 
		return obj;
	var newObj = new Object();
	for (var i in obj)
		newObj[i] = clone(obj[i]);
	return newObj;
}

//Return the mouse position in browser (not screen).

function getMousePos(e) {
	var posx = 0;
	var posy = 0;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	return [posx, posy];
}

//Removes tags from javascript strings.

function removeTags(aSourceString){
	regexp = new RegExp("<.*?>", "gi");
	return aSourceString.replace(regexp, "");
}

//Add to favourites function.

function AtoF() {
	if (window.sidebar) { 					// Mozilla Firefox Bookmark		
		window.sidebar.addPanel(document.title, window.location.href.split("?")[0], "");	
	} else if (window.external) { 			// IE Favorite		
		window.external.AddFavorite(window.location.href.split("?")[0], document.title); 
	} else {
	 	alert("Sorry, cannot add page to your favourites/bookmarks.\nPress Ctrl-D to complete the operation manually.");
	}
}

//Pause script execution for a given time in milliseconds.
function pause(ms) {
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); } 
	while(curDate-date < ms);
}

//Remove white space.
function trim(str) {
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
} 