var prefsLoaded = false;
var currentFontSize = 14;
var currentFontType = 1;
// var currentStyle = "White";
// var currentWidth = 990;
function revertStyles(){
currentFontType = 1;
setFontFace(1);

currentFontSize = 14;
changeFontSize(0);

}

/* currentStyle = "White";
setColor("White");

currentWidth = 990;
setWidth(990);
}
function toggleColors(){
if(currentStyle == "White"){
setColor("Black");
}else{
setColor("White");
}
}
function setColor(color){
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 > 24){
currentFontSize = 24;
}else if(currentFontSize < 8){
currentFontSize = 8;
}
}else{
if(currentFontSize > 25){
currentFontSize = 25;
}else if(currentFontSize < 9){
currentFontSize = 9;
}
}
setFontSize(currentFontSize);
};
function setFontSize(fontSize){
var stObj = (document.getElementById) ? document.getElementById('content') : document.all('content');
stObj.style.fontSize = fontSize + 'px';
var stObj2 = (document.getElementById) ? document.getElementById('rightmenu') : document.all('rightmenu');
stObj2.style.fontSize = fontSize + 'px';
};
function toggleSerif(){
currentFontType = parseInt(currentFontType);
if(currentFontType == 1){
currentFontType = 2;
changeFontSize(1);
}else{
currentFontType = 1;
changeFontSize(-1);
}
setFontFace(currentFontType);
};
function setFontFace(fontType){
var stObj = (document.getElementById) ? document.getElementById('content') : document.all('content');
var stObj2 = (document.getElementById) ? document.getElementById('rightmenu') : document.all('rightmenu');
var stObj3 = (document.getElementById) ? document.getElementById('title') : document.all('title');
if(fontType == 2){
stObj.style.fontFamily = 'georgia,times,times new roman,serif';
stObj2.style.fontFamily = 'georgia,times,times new roman,serif';
stObj3.style.fontFamily = 'georgia,times,times new roman,serif';
// changeFontSize(1);
}else{
stObj.style.fontFamily = 'verdana,geneva,arial,helvetica,sans-serif';
stObj2.style.fontFamily = 'verdana,geneva,arial,helvetica,sans-serif';
stObj3.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 : 14;
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 uiOptions () {
document.write("<div class=\"titlebars\">\n<h1>Options<\/h1><p><a href=\"./\" onclick=\"changeFontSize(1); return false;\">Increase Text Size<\/a><\/p><p><a href=\"./\" onclick=\"changeFontSize(-1); return false;\">Decrease Text Size<\/a><\/p><p><a href=\"./\" onclick=\"toggleSerif(); return false;\">Change Font<\/a><\/p><p><a href=\"./\" onclick=\"revertStyles(); return false;\">Default Size and Font<\/a><\/p></div>");
}

function popupImage(url, x, y, scroll)
{
  ua = window.navigator.userAgent;
  NS  = (document.layers) ? 1 : 0;
  PCIE = (ua.indexOf( "MSIE " ) && ua.indexOf("Win")) ? 1 : 0;

  if(NS || PCIE) { x += 15; y += 15; } // Grrr...

  pictureWindow = open(url, "pictureWindow", "width=" + x + ",height=" + y + ",scrollbars=" + ((scroll) ? "yes" : "no") + ",status=no,toolbar=no,resizable=yes");

  return false;
}
