function setActiveStyleSheet(title) {
  var i, a, main;
  var kfn = document.getElementsByTagName('*');
  for(i=0; i<kfn.length; i++) {
    a = kfn[i];
    if(a.getAttribute("type") == 'text/css' && a.getAttribute("title")) {
      a.disabled = true;
      if(title != '' && a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  var kfn = document.getElementsByTagName('*');
  for(i=0; i<kfn.length; i++) {
    a = kfn[i];
    if(a.getAttribute("type") == 'text/css' && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  var kfn = document.getElementsByTagName('*');
  for(i=0; i<kfn.length; i++) {
    a = kfn[i];
    if(a.getAttribute("type") == 'text/css' && 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 styleSwicther() {	
	if (document.getElementsByTagName) { 
		document.writeln('<span id="compliance"> <a href="#" onclick="setActiveStyleSheet(\'Default\');return false;" onkeypress="setActiveStyleSheet(\'Default\');return false;" title="Default style" accesskey="d">Default<\/a>')
		document.writeln(' | ')
		document.writeln('<a href="#" onclick="setActiveStyleSheet(\'Text Only\');return false;" onkeypress="setActiveStyleSheet(\'Text Only\');return false;" title="Text only" accesskey="t">Text Only<\/a>')
		document.writeln(' | ')
		document.writeln('<a href="#" onclick="setActiveStyleSheet(\'High Visibility\');return false;" onkeypress="setActiveStyleSheet(\'High Visibility\');return false;" title="High Visibility" accesskey="h">High Visibility<\/a></span>')
	}
}

window.onload = function(e) {
  var cookie = readCookie("TheRolandPartnership-style");
  var title = cookie ? cookie : getPreferredStyleSheet();
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("TheRolandPartnership-style", title, 365);
}

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

