var prefsLoaded = false;
var defaultFontSize = 0.8;
var currentFontSize = defaultFontSize;


function resetFontSize() {
	currentFontSize = defaultFontSize;
	setFontSize(currentFontSize)
}

function increaseFontSize() {
	fontSize = currentFontSize;
	if(fontSize == 0 || isNaN(fontSize)) fontSize = defaultFontSize;
	fontSize += 0.05;
	fontSize = roundNumber(fontSize,2)
	currentFontSize = fontSize;
	setFontSize(fontSize)
}

function decreaseFontSize() {
	fontSize = currentFontSize;
	if(fontSize == 0 || isNaN(fontSize)) fontSize = defaultFontSize;
	fontSize -= 0.05;
	fontSize = roundNumber(fontSize,2)	
	currentFontSize = fontSize;
	setFontSize(fontSize)
}



function setFontSize(fontSize){
	//var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
	if(fontSize == 0 || isNaN(fontSize)) fontSize = defaultFontSize;
	if(fontSize > 1.25) fontSize = 1.25;
	if(fontSize < 0.6) fontSize = 0.6;
	document.body.style.fontSize = fontSize + 'em';
	saveSettings(fontSize)
	//alert (document.body.style.fontSize);
};


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 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.onload = setUserOptions;

function setUserOptions(){
	if(!prefsLoaded){

		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : defaultFontSize;
		var currentFontSize = roundNumber(currentFontSize,2)
		setFontSize(currentFontSize);

		prefsLoaded = true;
	}

}

//window.onunload = saveSettings;

function saveSettings(saveFontSize)
{
  createCookie("fontSize", saveFontSize, 365);
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
