function ChangeTextSize( flag )
{
	var startingSize;
	var theSize;
	
	if (!document.getElementsByTagName)
	{
		return;
	}

	startingSize = parseInt(GetTextSize());

	if (!startingSize)
	{
		startingSize = defaultSize;
	}
	
	switch( flag )
	{
	case '-':
		theSize = startingSize - 2;
		break;
	case '+':
		theSize = startingSize + 2;
		break;
	case 'D':
		theSize = defaultSize;
		break;
	}

	if( theSize < minSize )
		theSize = minSize;
		
	SetTextSize( theSize );
}

function SetTextSize( setSize )
{
	if( setSize < minSize ) {		/* If setSize is that small, then something's	*/
		setSize = defaultSize;		/*  wrong with the command, probably bad cookie	*/
	}
	var theSize = setSize + 'px';

	document.getElementsByTagName('html')[0].style.fontSize = theSize;
	document.getElementsByTagName('body')[0].style.fontSize = theSize;
}

function GetTextSize() 
{
	var size = 0;
	
	if (!document.getElementsByTagName)
	{
		return 0;
	}
	
	var body = document.getElementsByTagName('body')[0];

	if (body.style && body.style.fontSize)
	{
		size = body.style.fontSize;
	}
	else if (typeof(getComputedStyle) != 'undefined')
	{
		size = getComputedStyle(body,'').getPropertyValue('font-size');
	}
	else if (body.currentStyle)
	{
		size = body.currentStyle.fontSize;
	}

	if (/pt$/.test(size)) {
		size = Math.round(parseInt(size) * 1.33333) + 'px';
	}

	return size;
}
function setActiveStyleSheet(title) {
  var i, a, main;
  if( typeof( document.getElementsByTagName ) != 'undefined' ) {
    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;
      }
    }
    document.documentElement.style.display = 'none';
    document.documentElement.style.display = '';
  }
}

function getActiveStyleSheet() {
  var i, a;
  if( typeof( document.getElementsByTagName ) != 'undefined' ) {
    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;
}

function getPreferredStyleSheet() {
  var i, a;
  if( typeof( document.getElementsByTagName ) != 'undefined' ) {
    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;
}

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 = site+name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = site+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;
}

setPref = function(e) {
  var cookie = readCookie("style");
  var textCookie = parseFloat(readCookie( "text" ));
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);

  if( textCookie ) {
  	SetTextSize( textCookie );
  }
}

savePref = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
  
  var textSize = GetTextSize( );
  createCookie("text", textSize, 365);
}

if (window.attachEvent) window.attachEvent("onload", setPref);
if (window.attachEvent) window.attachEvent("onunload", savePref);

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
