// JavaScript Document
var textSize = 75;

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 var expires = "";
	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++) {
		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);
}

function init ()
	{
	tempSize = readCookie( "textsize" );
	if( tempSize != null )
		{
		textSize = parseInt(tempSize);
		document.getElementsByTagName("body")[0].style.fontSize = textSize + "%";
		}
	else
		{
		createCookie( "textsize", textSize, 7 );	
		}
	
	// first we need to make sure that the right and left columns are the same height
	leftColumn  = document.getElementById("left_column");
	rightColumn = document.getElementById("right_column");
	if( rightColumn.offsetHeight > (leftColumn.offsetHeight ) )
		{
		document.getElementById("left_column_menu").style.height = ( (rightColumn.offsetHeight - 12) - 324 ) + "px";
		}
	//now we need to search the page for the increase & reduce text size button and attach the proper event handlers
	increaseButton = document.getElementById("increase_text_size");
	decreaseButton = document.getElementById("decrease_text_size");
	if( increaseButton && decreaseButton )
		{
		increaseButton.onclick = increaseTextSize;
		decreaseButton.onclick = decreaseTextSize;
		}
	}

function increaseTextSize ()
	{
	textSize += 20;
	document.getElementsByTagName("body")[0].style.fontSize = textSize + "%";
	eraseCookie( "textsize" );
	createCookie( "textsize", textSize, 7 );
	}
	
function decreaseTextSize ()
	{
	textSize -= 20;
	document.getElementsByTagName("body")[0].style.fontSize = textSize + "%";
	eraseCookie( "textsize" );
	createCookie( "textsize", textSize, 7 );
	}

window.onload = init;