// JavaScript Document

var fontSizeMin = 10;
var fontSizeMax = 18;
var fontSizeDefault = 11;

function adjustFontSize(upDown) {
	var currentSize = parseInt(getFontSizeCookie());
	if(currentSize == 'undefined' || currentSize == null || isNaN(currentSize) || currentSize < fontSizeMin || currentSize > fontSizeMax) {
		currentSize = fontSizeDefault;
	}
	if(upDown == 'up') {
		currentSize++;
		if(currentSize > fontSizeMax) {
			currentSize = fontSizeMax;
		}
	}
	if(upDown == 'dn') {
		currentSize--;
		if(currentSize < fontSizeMin) {
			currentSize = fontSizeMin;
		}
	}
	document.body.style.fontSize = currentSize+'px';
	setFontSizeCookie(currentSize,3);
	return false;
}

function getFontSizeCookie() {
	var cName = 'siteFontSize';
	if(document.cookie.length > 0) {
		var cStart = document.cookie.indexOf(cName+'=');
		if(cStart >= 0) {
			cStart += cName.length + 1;
			cEnd = document.cookie.indexOf(';',cStart);
			if(cEnd == -1) {
				cEnd = document.cookie.length;
			}
			return unescape(document.cookie.substring(cStart,cEnd));
		}
	}
	return;
}

function setFontSizeCookie(cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if(nDays == null || nDays == 0) {
		nDays = 1;
	}
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = "siteFontSize="+escape(cookieValue) + ";expires="+expire.toGMTString() + ";path=/";
}

function refreshSize() {
	document.body.style.fontSize = getFontSizeCookie() +'px';	
}
