// styleswitcher created for design4all.ch by SwissDigital.com Web Engineering 2004
// a free WebTool for better accessibility - please reference to SwissDigital's coders
// switch from style to style as you want for the 3 actual DOMs

var linkObj = null;
var cookie  = null;


// set the href of the stylesheet
function setActiveStyleSheet(hrefNew)
   {
   linkObj.href = hrefNew;
   }

// returns the href of the currently enabled stylesheet
function getActiveStyleSheet()
   {
   return(linkObj.href);
   }

// returns the href of the first stylesheel: this is the default
function getPreferredStyleSheet()
  {
  return(linkObj.href);
  }

// creates a cookie that expires in some days
function createCookie(name, value, days) 
   {
   var date = new Date();

   date.setTime(date.getTime()+(days*24*60*60*1000));
   var expires = "; expires=" + date.toGMTString();
   document.cookie = name + "=" + value + expires + "; path=/";
   }

// return the value of the named cookie or null if no there is no cookie available
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);
   }

// onload, dependend of the DOM, we hold pointers to the two stylesheets
// also, we activate the stylesheet defined by the cookie or the default.
window.onload = function(e)
  {
  var lnks;

  cookie = readCookie("style");

  // which DOM greets us?
  if (document.all)
     lnks = document.all.tags("link");
  else if (document.getElementsByTagName)
     lnks = document.getElementsByTagName("link");
  else
     return;

  if (lnks.length < 1)
    return;
  linkObj = lnks[0];

  if ((cookie != null) && (cookie != 'null'))
     setActiveStyleSheet(cookie);
  else
     setActiveStyleSheet(getPreferredStyleSheet());
  }

// on unload, we set the cookie with the currently active Stylesheet
window.onunload = function(e)
   {
   createCookie("style", getActiveStyleSheet(), 365);
   }


