
if (typeof (String.prototype.ltrim)	=== "undefined")	{ String.prototype.ltrim = function (chars) { return this.replace (new RegExp ("^[" + (chars || "\\s") + "]+",  "g"), "");	}; }
if (typeof (String.prototype.rtrim)	=== "undefined")	{ String.prototype.rtrim = function (chars) { return this.replace (new RegExp ( "[" + (chars || "\\s") + "]+$", "g"), "");	}; }
if (typeof (String.prototype.trim)	=== "undefined")	{ String.prototype.trim  = function (chars) { return this.ltrim (chars).rtrim (chars);					}; }

if (typeof (Array.prototype.indexOf)	=== "undefined")
{
	Array.prototype.indexOf	= function (v, b, s)
	{
		for (var x = +b || 0, l = this.length; x < l; x++)
			if (this[x] === v || s && this[x] == v)
				return x;
		return -1;
	};
}


// Add all instances of FCKEditor to a neat little list.
// FCK automatically calls this function every time it finishes loading an instance
function FCKeditor_OnComplete (el)
{
	if (!document.FCKlist)	document.FCKlist = [];

	document.FCKlist.push (el.Name);
}


// Make cookies easier to deal with
var CookieJar =
{
	set: function (name, value, days)
	{
		var expires = "";

		if (days)
		{
			var date = new Date ();
			date.setTime (date.getTime () + (days * 86400000));
			expires = "; expires=" + date.toGMTString ();
		}

		document.cookie = name + "=" + value + expires + "; path=/";
	},

	get: function (name)
	{
		var ca		= document.cookie.split (";");

		for (var i = ca.length; i--; )
		{
			var c = ca[i].trim ().split ("=");
			if (c[0] == name) return c[1];
		}

		return null;
	},

	clr: function (name)
	{
		this.set (name, "", -1);
	}
};


// Sourced from http://www.cherny.com/webdev/27/domloaded-updated-again
var DomLoaded =
{
	onload: [],

	loaded: function ()
	{
		if (arguments.callee.done) return;
		arguments.callee.done = true;
		for (var x = DomLoaded.onload.length; x--; )		//for (var x = 0; x < DomLoaded.onload.length; x++)
			DomLoaded.onload[x] ();
	},

	load: function (fireThis)
	{
		this.onload.unshift (fireThis);				//this.onload.push (fireThis);

		if (document.addEventListener)
			document.addEventListener ("DOMContentLoaded", DomLoaded.loaded, null);

		if (/KHTML|WebKit/i.test (navigator.userAgent))
		{
			var _timer = setInterval (function ()
			{
				if (/loaded|complete/.test (document.readyState))
				{
					clearInterval (_timer);
					delete _timer;
					DomLoaded.loaded ();
				}
			}, 10);
		}

/*@cc_on @*/
/*@if (@_win32)
		var proto = "src='javascript:void (0)'";
		if (location.protocol == "https:") proto = "src=//0";
		document.write ("<scr" + "ipt id=__ie_onload defer " + proto + "><\/scr" + "ipt>");
		document.getElementById ("__ie_onload").onreadystatechange = function ()
		{
			if (this.readyState == "complete")
			{
				DomLoaded.loaded ();
			}
		};
/*@end @*/

		window.onload = DomLoaded.loaded;
	}
};
