var stsz = 0;
var szs = new Array( '1em','1.1em','1.2em','1.3em');

function setFont(inc) {
 document.body.style.fontSize = szs[inc];
 if (parent.frames.azlist ? true : false) parent.azlist.document.body.style.fontSize=szs[inc];

 // DMR Xeno Media 2007-12-13
 // Resize <td>s as well
 // Assumes <td>s start out at 1em
 tds = document.getElementsByTagName('TD');
 for(tds_index = 0; tds_index < tds.length; tds_index++)
 {
   tds[tds_index].style.fontSize = szs[inc];
 }

 createCookie("fontsize", inc, 365);
}

function setDef() {
 stsz = 0; setFont(stsz);
}

function setFs(inc) {
 var sz = stsz; sz += inc; if ( sz < 0 ) sz = 0; if ( sz > 3 ) sz = 3; stsz = sz; setFont(stsz);
}

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

// from http://www.robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

function loadFS() {
  var fs = readCookie("fontsize");
  stsz = fs ? fs : 0;
  stsz = parseInt(stsz);
  setFont(stsz);
}

// addLoadEvent is Simon Willison's function that aloows for convenient
// addition of multiple fuctions that are all supposed to be triggered
// on window.onload event.
// takes function name as the argument. e.g. addLoadEvent(doPopups);
 
function addLoadEvent(func) {
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
  window.onload = func;
 } else {
  window.onload = function() {
    oldonload();
    func();
  }
 }
}
addLoadEvent(loadFS);


