function setss(ss)
{
 var expdate = new Date();
 //Do not expire for 50 days
 expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24 * 50);
 document.cookie = "style=" + ss +
  "; expires=" + expdate.toGMTString();
}

function setonce(ss)
{
 //Set and check a cookie that expires at the end of the session
 //First time one of the pages is loaded, we re-set the style cookie
 //to keep a rolling expiration date.
 var dc = document.cookie;
 if(dc.indexOf("ss_session") == -1)
 {
  //Session cookie does not exist
  document.cookie = "ss_session=1";
  setss(ss);
 }
}

/*
 * Function lifted from
 * www.netspade.com/articles/javascript/cookies.xml
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/* Get the stored cookie value - revert to style.css if no cookie */
var ss = getCookie("style");
if(ss == null)
{
 //Set default stylesheet here
 ss = "css/classic.css";
}

//Set the stylesheet again, so the cookie doesn't expire
setonce(ss);

document.write("<link rel=\"stylesheet\" type=\"text/css\"" +
               " href=\"/" + ss + "\" title=\"default\" />");
