var currentStyleSheet="Default CSS";

function changeFontSize(multiplier)
{ if(document.body)
 { if (document.body.style.fontSize == null || document.body.style.fontSize=="") document.body.style.fontSize = "1.0em";
   document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
   if(parseFloat(document.body.style.fontSize)<.4) document.body.style.fontSize = "0.4em";
   createCookie("usersFontSizePref", document.body.style.fontSize, 365);
 }
}
 
function loadUserDisplayPrefs()
{ var usersFontSize = readCookie("usersFontSizePref");
  if (usersFontSize != null && document.body) document.body.style.fontSize = usersFontSize;
  var usersStyleSheetPref = readCookie("usersStyleSheetPref");
  if (usersStyleSheetPref != null) 
  { changeStyle(usersStyleSheetPref);
  }
}

function setColorSelectorIndexToCurrent()
{ switch(currentStyleSheet)
  { case "White On Black": 
      setColorSelectorIndex(1);
      break;    
    case "Black On Yellow": 
      setColorSelectorIndex(2);
      break;
    case "Yellow On Black":  
      setColorSelectorIndex(3);
      break;
    case "Default CSS":
    default:
      currentStyleSheet="Default CSS";
      setColorSelectorIndex(0);
  }
  changeStyle(currentStyleSheet);
}

function setColorSelectorIndex(iv)
{ var colorSelector=document.getElementById('selectColor');
  if (colorSelector != null) colorSelector.selectedIndex = iv;
}

/***********************************************************************************************
 Following two functions are based on the functions found here:
                             Script to swap between stylesheets
  Written by Mark Wilton-Jones, 05/12/2002. v2.2.1 updated 14/03/2006 for dynamic stylesheets
************************************************************************************************

Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use */

function getAllSheets() 
{ if( !window.ScriptEngine && navigator.__ice_version ) 
  { return document.styleSheets; 
  }
  if( document.getElementsByTagName ) 
  { var Lt = document.getElementsByTagName('link'), St = document.getElementsByTagName('style');
  } 
  else if( document.styleSheets && document.all ) 
  { var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
  } 
  else 
  { return []; 
  } 
  for( var x = 0, os = []; Lt[x]; x++ ) 
  { var rel = Lt[x].rel ? Lt[x].rel : Lt[x].getAttribute ? Lt[x].getAttribute('rel') : '';
	if( typeof( rel ) == 'string' && rel.toLowerCase().indexOf('style') + 1 ) 
	{ os[os.length] = Lt[x]; 
	}
  } 
  for( var x = 0; St[x]; x++ ) 
  { os[os.length] = St[x]; 
  } 
  return os;
}

function changeStyle(upss) 
{ for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) 
  { if(ss[x].title != "Main CSS") ss[x].disabled = true;
    if( ss[x].title == upss) 
    { ss[x].disabled = false; 
    }
  } 
  currentStyleSheet = upss;
  createCookie("usersStyleSheetPref", upss, 365);
}

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 var 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;
}
