var prefsLoaded = false;
var currentFontSize = 10;
var currentFontType = 1;

function revertStyles(){
	currentFontType = 1;
	setFontFace(1);
	
	currentFontSize = 10;
	changeFontSize(0);
}

function changeFontSize(sizeDifference){
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference);

	if(currentFontType == 1){
		if(currentFontSize > 14){
			currentFontSize = 14;
		}else if(currentFontSize < 8){
			currentFontSize = 8;
		}
	}else{
		if(currentFontSize > 18){
			currentFontSize = 18;
		}else if(currentFontSize < 8){
			currentFontSize = 8;
		}
	}
	setFontSize(currentFontSize);
};

function setFontSize(fontSize){
	var stObj = (document.getElementById) ? document.getElementById('content') : document.all('content');
	stObj.style.fontSize = fontSize + 'px';
};

function toggleSerif(){
	currentFontType = parseInt(currentFontType);
	if(currentFontType == 1){
		currentFontType = 2;
	}else{
		currentFontType = 1;
	}
	setFontFace(currentFontType);
};

function setFontFace(fontType){
	var stObj = (document.getElementById) ? document.getElementById('content') : document.all('content');
	if(fontType == 2){
		stObj.style.fontFamily = 'Georgia,Times,Times New Roman,serif';
		changeFontSize(1);
	}else{
		stObj.style.fontFamily = 'Verdana,Arial,Helvetica,sans-serif';
		changeFontSize(-1);
	}
}

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;
};

function setUserOptions(){
	if(!prefsLoaded){
		cookie = readCookie("fontFace");
		currentFontType = cookie ? cookie : 1;
		setFontFace(currentFontType);

		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : 12;
		setFontSize(currentFontSize);

		prefsLoaded = true;
	}

}

window.onunload = saveSettings;

function saveSettings()
{
  createCookie("fontSize", currentFontSize, 365);
  createCookie("fontFace", currentFontType, 365);
}