var prefsLoaded = false;
var defaultFontSize = 75;
var currentFontSize = defaultFontSize;
var p=0;
var f=1;

function AccessSwitch() {
var pageType = (document.getElementById) ? document.getElementById('Accessibility') : document.all('Accessibility');
 if (pageType.value==1) {changeFontSize(3);return false;
     } else if (pageType.value==2) {revertStyles(); return false;
     } else if (pageType.value==3) {togglestylesheet(); return false;
     } else if (pageType.value==4) {togglestylesheet();changeFontSize(3); return false;
     } else if (pageType.value==5) {hideFlash(); return false;
     } else if (pageType.value==6) {showFlash(); return false;
     }
}
function revertStyles(){
	currentFontSize = defaultFontSize;
	changeFontSize(0);
}
function changeFontSize(sizeDifference){
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);
	if(currentFontSize > 120){
		currentFontSize = 120;
	}else if(currentFontSize < 75){
		currentFontSize = 75;
	}
	setFontSize(currentFontSize);
	createCookie("fontSize", currentFontSize, 365);
};
function setFontSize(fontSize){
	var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
	document.body.style.fontSize = fontSize + '%';
};
function setUserOptions(){
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
	if(!prefsLoaded){
		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : defaultFontSize;
		setFontSize(currentFontSize);
		prefsLoaded = true;
	}
}
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title")!= "flash" && a.getAttribute("title")!= "noflash") {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  createCookie("style", title, 365);
}
function togglestylesheet() {
	if (p==0) {
		setActiveStyleSheet('invert');
		p=1;
	} else {setActiveStyleSheet('colour'); p=0;}
}
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 && a.getAttribute("title")!= "flash"  && a.getAttribute("title")!= "noflash" ) return a.getAttribute("title");
  }
  return null;
}
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")!= "flash" 
       && a.getAttribute("title")!= "noflash" 
       && 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 = 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;
}
function hideFlash(){
    toggleFlash(0);
}
function showFlash(){
    toggleFlash(1);
}
function toggleFlash(title)
{
    var i, a;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) 
    {
        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) 
        {
          if(a.getAttribute("title") == "flash"){ 
            if(title == 1){
                a.disabled = false;
            }
            else{
                a.disabled = true;
            }
          }
          if(a.getAttribute("title") == "noflash")
          {
            if(title == 0){
            a.disabled = false;
            }
            else{
            a.disabled = true;
            }
          }
        }
    }
    createCookie("flash", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
cookie = readCookie("flash");
f = cookie ? cookie : 1;
if(f==1){
    showFlash();
}
else{
    hideFlash();
}