// **********************************************************************
// style_ui.js
// Copyright (c) 2004-2005 mkeefeDESIGN
// http://www.mkeefedesign.com/
// **********************************************************************
//
// **********************************************************************
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
// **********************************************************************
//
// **********************************************************************
// UPDATES AND FIXES
// **********************************************************************
//

var loaded = false;
var curfontsize = 11;
var curwidth = 760;

function revertStyles()
	{
	curfontsize = 11;
	changeFontSize(0);
	curwidth = 760;
	setWidth(760);
	};

function toggleWidth()
	{
	curwidth = parseInt(curwidth);
	var newWidth = 760;
	if(curwidth == 760) { newWidth = 1200; } setWidth(newWidth); curwidth = newWidth; 
	};

function setWidth(width)
	{
		
	var obj = (document.getElementById) ? document.getElementById('wrapper') : document.all('Content');
		
	if(width != 760) { newWidth = 1200; obj.style.width = '90%'; } else { obj.style.width = '760px'; }
	};

function changeFontSize(sizeDifference)
	{
	curfontsize = parseInt(curfontsize) + parseInt(sizeDifference);

	if(curfontsize > 13) { curfontsize = 13; } else if(curfontsize < 8) { curfontsize = 8; }
	
	setFontSize(curfontsize);
	};

function setFontSize(fontSize)
	{
	var stObj = (document.getElementById) ? document.getElementById('ContentArea') : document.all('Content');
	stObj.style.fontSize = fontSize + 'px';
	};

function createCookie(name,value,days) 
	{
	if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else { expires = ""; }
	document.cookie = name+"="+value+expires+"; path=/";
	};

function readCookie(name) 
	{
	var nameEQ = name + "=";
	var cs = document.cookie.split(';');
	for(var i=0;i < cs.length;i++) 
		{
		var c = cs[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.onload = setUserOptions;

function setUserOptions()
	{
	if(!loaded) { 
		cookie = readCookie("font_size"); 
		curfontsize = cookie ? cookie : 11; 
		setFontSize(curfontsize); 
		cookie = readCookie("page_width"); 
		curwidth = cookie ? cookie : 760; 
		setWidth(curwidth); 
		loaded = true; 
	}
};

window.onunload = saveSettings;

function saveSettings()
{
	createCookie("font_size", curfontsize, 365);
	createCookie("page_width", curwidth, 365);
}