
// http://www.webtoolkit.info/
function ltrim (str, chars)	{ return str.replace (new RegExp ("^[" + (chars || "\\s") + "]+",  "g"), ""); }
function rtrim (str, chars)	{ return str.replace (new RegExp ( "[" + (chars || "\\s") + "]+$", "g"), ""); }
function  trim (str, chars)	{ return ltrim (rtrim (str, chars), chars); }


// http://www.quirksmode.org/js/cookies.html
function createCookie (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=/";
}

function readCookie (name)
{
	//var nameEQ	= name + "=";
	var ca		= document.cookie.split (";");

	//for (var i = 0; i < ca.length; i++)
	for (var i = ca.length; i--; )
	{
		var c = trim (ca[i]).split ("=");
		if (c[0] == name) return c[1];

		//var c = ca[i];
		//while (c.charAt(0)==' ') c = c.substring(1,c.length);
		//if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}

	return null;
}

function eraseCookie (name)
{
	createCookie (name, "", -1);
}


// 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 = 0; x < DomLoaded.onload.length; x++)
			DomLoaded.onload[x] ();
	},

	load: function (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;
	}
};



// LWS
function lnk_print ()
{
	window.print ();
	return false;
}

function lnk_fsize (ids, size, unit)
{
	if (typeof (ids) == "string")
		ids = [ids];

	for (c = 0, x = ids.length; x--; )
	{
		createCookie ("fontEl_" + c++, ids[x], 90);

		if (el = document.getElementById (ids[x]))
		{
			el.style.fontSize = size + unit;
		}
	}

	createCookie ("fontSize", size, 90);
	createCookie ("fontUnit", unit, 90);
	createCookie ("fontNum",  c,    90);

	return false;
}

function load_fsize ()
{
	fontElem	= [];
	fontNum		= readCookie ("fontNum");
	fontSize	= readCookie ("fontSize");
	fontUnit	= readCookie ("fontUnit");

	if (fontNum != null && fontSize != null && fontUnit != null)
	{
		for (x = parseInt (fontNum); x--; )
		{
			if ((e = readCookie ("fontEl_" + x)) != null)
			{
				fontElem.push (e);
			}
		}

		lnk_fsize (fontElem, fontSize, fontUnit);
	}
}

DomLoaded.load (load_fsize);
