var sCookie = "UserStyleSheet" //Name of user style sheet Cookie
var sCssId = "CustomStyle"

var oLastCSS = readCookie (sCookie); // Get the last stylesheet from the cookie

if (undefined != oLastCSS){loadCssFile (oLastCSS);} // Load the last stylesheet saved in the Cookie
  
 function loadCssFile(filename){
 //Load a stylesheet and saves in a Cookie
  createCookie (sCookie, filename, 365);
 
 var oStyleSheet = document.getElementById(sCssId)
 if (undefined != oStyleSheet) { // If the style link was already added, change the Href
    oStyleSheet.setAttribute("href", filename)}
 else{ // Add a Css link
  var fileref=document.createElement("link");
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", filename);
    fileref.setAttribute("id", sCssId);
    document.getElementsByTagName("head")[0].appendChild(fileref);
    }
}

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;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}