/*==========================================//
    Enable active stylesheet, disable others
//==========================================*/
function setActiveStyleSheet(title) {
    var i, linkedStyle;    
    
    for(i=0; (linkedStyle = document.getElementsByTagName("link")[i]); i++) {
             
         if(linkedStyle.getAttribute("rel").indexOf("style") != -1 
                && linkedStyle.getAttribute("title")
                &&(linkedStyle.getAttribute("title") == title)) {
                
                //Is a stylesheet, has a title, title matches supplied title
                //Enable this stylesheet
                    linkedStyle.disabled = false;      
         
         }else if(linkedStyle.getAttribute("rel").indexOf("style") != -1 
                    && linkedStyle.getAttribute("title")
                    &&linkedStyle.getAttribute("title").indexOf("Text") != -1){
                    
                    //Is a stylesheet, has a title, title contains the string 'Text'
                    //Disable this stylesheet
                        linkedStyle.disabled = true;                        
            
         }
    }
    
    if(self.accordionIni){
        accordionIni();
    }
}

/*================================================//
    Return active stylesheet to add to the cookie
//================================================*/
function getActiveStyleSheet() {
  var i, linkedStyle;
  for(i=0; (linkedStyle = document.getElementsByTagName("link")[i]); i++) {
    
    if(linkedStyle.getAttribute("rel").indexOf("style") != -1 && linkedStyle.getAttribute("title") && !linkedStyle.disabled){ 
        return linkedStyle.getAttribute("title");
    }
  }
  return null;
}

/*==========================================//
    Create and read cookies
//==========================================*/
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 + "=";
  
  if(document.cookie){
      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 & Unload
//==========================================*/
//window.onload = function(e) {
  var cookie = readCookie("ILtextStyle");  
  var title = cookie;
  setActiveStyleSheet(title);
//}

window.onunload = function(e) {
    var title = getActiveStyleSheet();
    createCookie("ILtextStyle", title, 365);
}
