var gDefaultIndex      = 2
var gTagList           = new Array('th','td');
var gFontSizeList      = new Array('small','medium','x-large');
var gTableFontSizeList = new Array('x-small','small','medium');

window.onload = function() {
   FontChange('body',getFontSizeFromCookie());
}

function FontChange(pTargetTag,pTargetFunc){
  if(!document.getElementById) return
  var tmpElement  = null;
  var tmpFontSize = gDefaultIndex;
  var tmpElement2 = null;
  tmpFontSize = pTargetFunc;
  gDefaultIndex =tmpFontSize;
  if(!(tmpElement = document.getElementById(pTargetTag))){
    tmpElement = document.getElementsByTagName(pTargetTag)[0];
  }
  tmpElement.style.fontSize = gFontSizeList[tmpFontSize];
  for (var i = 0 ; i < gTagList.length ; i++){
    tmpElement2 = tmpElement.getElementsByTagName(gTagList[i]);
    for (var j = 0 ; j < tmpElement2.length ; j++){
      tmpElement2[j].style.fontSize = gTableFontSizeList[tmpFontSize];
    }
  }
  setFontSizeToCookie(tmpFontSize);
}

function getFontSizeFromCookie() {
  retFontSize   = 1;
  tmpKeyword    = "fontsize="         ;
  tmpCookie     =  document.cookie+";" ;
  tmpIndex      =  tmpCookie.indexOf(tmpKeyword);
  if(tmpIndex != -1) {
    tmpEnd      =  tmpCookie.indexOf(";",tmpIndex);
    retFontSize =  unescape(tmpCookie.substring(tmpIndex + tmpKeyword.length, tmpEnd));
  }
  return parseInt(retFontSize,10);
}

function setFontSizeToCookie(pFontSize) {
  tmpKeyword      = "fontsize=";
  document.cookie =  tmpKeyword + escape(pFontSize) + ";";
}
