﻿/* GPS - 22.06.06
If main text size is supposed to be changed, three values need to be changed in this file.

Value to change:
currentFontSize

Located:
global
revertStyles()
setUserOptions()
--------------------------*/


/* GPS 
used to change stylesheets, does not currently stay in the cookies.
*/
function setActiveStyleSheet(title) {
  var i, a, main;  
 // alert('setActiveStyleSheet - ' + title);
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

/* GPS - 28.06.06
not currently used, allowing it to stay if further modding of the code requires it

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
*/
//--------------------------------------------------------------------------------
var prefsLoaded = false;
var currentFontSize = 11;
var currentFontType = 1;
var currentStyle = "White";
var currentStyleSheet = "Layout"; //Used as "current default"

function revertStyles(){
	currentFontType = 1;
	setFontFace(1);
	
	currentFontSize = 11;
	changeFontSize(0);
	
	currentStyle = "White";
	setColor("White");
}

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 = 'Invert';
		currentStyle = "Black";
	}else{
		document.body.className = 'bodyMain';
		currentStyle = "White";
	}
}

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('NetQbsPageContainer') : 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('NetQbsPageContainer') : document.all('NetQbsPageContainer');
	if(fontType == 2){
		stObj.style.fontFamily = 'Arial, Helvetica, sans-serif';
		changeFontSize(1);
	}else{
		stObj.style.fontFamily = '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;

/*
GPS - 20.06.06
fontSize is renamed to fontSize_2 because of caching issues in an update.
----------------
*/
function setUserOptions(){
	if(!prefsLoaded){
		cookie = readCookie("fontFace");
		currentFontType = cookie ? cookie : 1;
		setFontFace(currentFontType);

		cookie = readCookie("fontSize_2");
		currentFontSize = cookie ? cookie : 12;
		setFontSize(currentFontSize);
		
		cookie = readCookie("StyleSheet");
		//alert("cookie: " + cookie);
		currentStyleSheet = cookie ? cookie : "Layout";
		
		setActiveStyleSheet(currentStyleSheet);
		
		/* GPS - disabled
		cookie = readCookie("pageColor");
		currentStyle = cookie ? cookie : "White";
		setColor(currentStyle);
		*/

		prefsLoaded = true;
	}

}

window.onunload = saveSettings;

function saveSettings()
{
  createCookie("fontSize_2", currentFontSize, 365);
  createCookie("fontFace", currentFontType, 365);
  createCookie("StyleSheet", currentStyleSheet, 365);
  /* GPS Disabled
  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;
}