function setActiveStyleSheet(href) {
  
//if(window.location.host == "www.blankenberge.be"){
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    
      
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("href") && (a.getAttribute("media")=="screen")) {
      a.disabled = true;
      if(a.getAttribute("href") == href) a.disabled = false;
    	
    }
   }
  }
  
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
      
        
      if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("href")=='/01/Stylesheets/9blankenberge.css' && (a.getAttribute("media")=="all")) {
        a.disabled = true;
      
      	
      }
     }
  
  
//}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("href") && !a.disabled && (a.getAttribute("media")=="screen")) return a.getAttribute("href");
  //  alert('get media=');
  //  alert(a.getAttribute("media"));
  //  alert( a.getAttribute("href"));
  //  alert ( a.disabled));
  
  }
  
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  //for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  //  if(a.getAttribute("rel").indexOf("style") != -1
  //     && a.getAttribute("rel").indexOf("alt") == -1
  //     && a.getAttribute("href")
  //     && a.getAttribute("media")== "screen"
  //     ) return a.getAttribute("href");
  //}
  //return null;
  if(window.location.host == "www.blankenberge.be"){return "/01/Stylesheets/9blankenberge.css";}
  if(window.location.host == "academie.blankenberge.be"){return "/01/Stylesheets/9bl_aca.css";}
  if(window.location.host == "bibliotheek.blankenberge.be"){return "/01/Stylesheets/9bl_bib.css";}
  if(window.location.host == "jeugd.blankenberge.be"){return "/01/Stylesheets/9bl_jeugd.css";}
  if(window.location.host == "sport.blankenberge.be"){return "/01/Stylesheets/9bl_sport.css";}
  if(window.location.host == "cultuur.blankenberge.be"){return "/01/Stylesheets/9bl_cult.css";}
}

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;
}

window.onload = function(e) {
  var cookie = readCookie("stylesy");
  var href = cookie ? cookie : getPreferredStyleSheet();
  if(window.location.host == "www.blankenberge.be"){setActiveStyleSheet(href);}
}

window.onunload = function(e) {
  var href = getActiveStyleSheet();
  createCookie("stylesy", href, 365);
}

var cookie = readCookie("stylesy");
var href = cookie ? cookie : getPreferredStyleSheet();
if(window.location.host == "www.blankenberge.be"){setActiveStyleSheet(href);}
