var prefsLoaded = false;
var currentFontSize = 12;
var currentFontType = 1;
var currentStyle = "White";
var currentWidth = 990;
function revertStyles(){
	currentFontType = 1;
	setFontFace(1);
	
	currentFontSize = 12;
	changeFontSize(0);
	
	currentStyle = "White";
	setColor("White");
	
	currentWidth = 990;
	setWidth(990);
}
function toggleColors(){
	if(currentStyle == "White"){
		setColor("Black");
	}else{
		setColor("White");
	}
}
function setColor(color){
	d=new Date();
	flash=Math.round(Math.random()*d.getTime());
	if(color != "White"){
		document.body.className = 'Retro';
		currentStyle = "Black";
	}else{
		document.body.className = '';
		currentStyle = "White";
	}
}
function toggleWidth(){
	currentWidth = parseInt(currentWidth);
	var newWidth = 990;
	if(currentWidth == 990){
		newWidth = 1200;
	}
	setWidth(newWidth);
	currentWidth = newWidth;
}
function setWidth(width){
	if(width != 990){
		newWidth = 1200;
		document.body.style.width = '90%';
	}else{
		document.body.style.width = '990px';
	}
}
function changeFontSize(sizeDifference){
	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){
	var stObj = (document.getElementById) ? document.getElementById('ContentArea') : 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('ContentArea') : document.all('ContentArea');
	if(fontType == 2){
		stObj.style.fontFamily = 'georgia,times,times new roman,serif';
		changeFontSize(1);
	}else{
		stObj.style.fontFamily = 'verdana,geneva,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;
};

window.onload = setUserOptions;

function setUserOptions(){
	if(!prefsLoaded){
		cookie = readCookie("fontFace");
		currentFontType = cookie ? cookie : 1;
		setFontFace(currentFontType);

		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : 12;
		setFontSize(currentFontSize);
		
		cookie = readCookie("pageWidth");
		currentWidth = cookie ? cookie : 990;
		setWidth(currentWidth);
		
		cookie = readCookie("pageColor");
		currentStyle = cookie ? cookie : "White";
		setColor(currentStyle);

		prefsLoaded = true;
	}

}

window.onunload = saveSettings;

function saveSettings()
{
  createCookie("fontSize", currentFontSize, 365);
  createCookie("fontFace", currentFontType, 365);
  createCookie("pageWidth", currentWidth, 365);
  createCookie("pageColor", currentStyle, 365);
}

function popupImage(url, x, y, scroll)
{
  ua   = window.navigator.userAgent;
  ns   = (document.layers) ? 1 : 0;
  mz   = (ua.indexOf("zilla") >= 0) ? 1 : 0;
  pcie = (ua.indexOf( "MSIE " ) >= 0 && ua.indexOf("Win") >= 0) ? 1 : 0;

  // Grrr...
  if(ns || pcie || mz) { x += 15; y += 15; }
  if(mz) { x += 10; y += 10; } 

  noise = Math.round((Math.random() * 10000) + 1);

  pictureWindow = open(url, "pictureWindow" + noise, "width=" + x + ",height=" + y + ",scrollbars=" + ((scroll) ? "yes" : "no") + ",status=no,toolbar=no,resizable=yes");

  return false;
}