var currentFontSize = 10;
var currentFontType = 1;
var currentStyle = "White";

function revertStyles(){
    //alert("revert styles");
	currentFontType = 1;
	setFontFace(1);
	
	currentFontSize = 10;
	changeFontSize(0);
	
}

function changeFontSize(sizeDifference){
    //alert("changeFontSize");
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference);

	if(currentFontType == 1){
		if(currentFontSize > 16){
			currentFontSize = 16;
		}else if(currentFontSize < 8){
			currentFontSize = 8;
		}
	}else{
		if(currentFontSize > 19){
			currentFontSize = 19;
		}else if(currentFontSize < 8){
			currentFontSize = 8;
		}
	}
	setFontSize(currentFontSize);
};

function setFontSize(fontSize){
   // alert("setFontSize" + fontSize);
	// var stObj = (document.getElementById) ? document.getElementById('ContentArea') : document.all('Content');
	if (!document.getElementById) return
	var d = document,stObj = null,i,j,cTags;
	var trgt = "ContentArea";
	var tgs = new Array( 'div','td','tr');

	if ( !( stObj = d.getElementById( trgt ) ) ) stObj = d.getElementsByTagName( trgt )[ 0 ];

	stObj.style.fontSize = fontSize + 'px';

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = stObj.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = fontSize + 'px';
	}

};

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

function setFontFace(fontType){
    //alert("setFontFace");
	var stObj = (document.getElementById) ? document.getElementById('ContentArea') : document.all('ContentArea');
	if(fontType == 2){
		stObj.style.fontFamily = 'times,times new roman,serif';
	}else{
		stObj.style.fontFamily = 'verdana,geneva,arial,helvetica,sans-serif';
	}
}

function createCookie(name,value,days) {
  //alert("createCookies");
  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) {
  //alert("readCookie");
  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;
};

// this function loads the settings from the cookie
// and stores it in variables
function loadSettings(){
    //alert("loadSettings()");

    cookie = readCookie("fontFace");
    currentFontType = cookie ? cookie : 1;

    cookie = readCookie("fontSize");
    currentFontSize = cookie ? cookie : 10;

}

// enforces that user options are always loaded so when saveSettings is called when the
// onunload event handler runs the correct settings are saved
loadSettings();

// the onunload attribute of the body tag on base.jsp calls saveSettings
function saveSettings()
{
  //alert("saveSettings()");
  //alert(currentFontType);
  //alert(currentFontSize);
  createCookie("fontSize", currentFontSize, 365);
  createCookie("fontFace", currentFontType, 365);
}

// call this function inside the content area to set the font type and size
// loaded from the cookies
function setUserOptions() {
    //alert("setUserOptions()");
    setFontFace(currentFontType);
    setFontSize(currentFontSize);
}