var intFontSize = 2; // below min for check, but if javascirpt fails we won't destroy the browser. 
var bolLoaded = false;
var intDefaultSize = 12;

window.onload = Initialize;

function Initialize()
{
	if(!bolLoaded)
	{
		cookie = ReadCookie("fontSize");
		intFontSize = cookie ? cookie : intDefaultSize;
		bolLoaded = true;
	}
//  if (typeof CustomOnLoad()!='undefined') // Apparantly, nobody supports the *new* standard. :p
if (window.CustomOnLoad)
  	CustomOnLoad();	
}

function ReadCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		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;
};

window.onunload = WriteCookies;

function WriteCookies()
{
	if (intFontSize == 2)
		{
		cookie = ReadCookie("fontSize");
		intFontSize = cookie ? cookie : intDefaultSize;	
		}
	WriteCookie("fontSize", intFontSize, 365);
}

function WriteCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
		{var expires = "";}
	document.cookie = name+"="+value+expires+"; path=/";
};

function increaseFontSize()
	{
		
	if (intFontSize == 2)
		{
		cookie = ReadCookie("fontSize");
		intFontSize = cookie ? cookie : intDefaultSize;	
		}		
		
	setFontSize(++intFontSize);
	}
function decreaseFontSize()
	{
	if (intFontSize == 2)
		{
		cookie = ReadCookie("fontSize");
		intFontSize = cookie ? cookie : intDefaultSize;	
		}		
		
	if (intFontSize > 4)
		setFontSize(--intFontSize);
	}	
function resetFontSize()
	{
	intFontSize = intDefaultSize;
	setFontSize(intFontSize);
	}

function setFontSize(fontSize)
	{
	var bodyObj = document.body;
	bodyObj.style.fontSize = fontSize + 'px';
	intFontSize = fontSize;
	};