/*
function setActiveStyleSheet(title) {
  var i, a, main;
  if (title == 'default') title = 'design';

  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	if (a.getAttribute("rel") &&
		a.getAttribute("rel").indexOf("style") != -1 &&
		a.getAttribute("title")) {
	  a.disabled = true;
	  if(a.getAttribute("title") == title) a.disabled = false;
	}
  }
  createCookie("style", title, 365);
	if (navigator.userAgent.search(/Gecko/) != -1) { 
		window.location.reload();
	}
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return 'default';
}

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("title")
       ) return a.getAttribute("title");
  }
  return 'default';
}
*/
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 'default';
}



// Javascript originally by Paul Snowden and Peter-Paul Koch.
// See http://alistapart.com/articles/alternate/.
// Modifications by mbl.is to support two sets of alternate stylesheets

function setActiveStyleSheet(title,type) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && isStyleSheetType(a.getAttribute("title"),type)) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function mozRepaintFix () { // Fixes Gecko problem with position of top ad
  if (navigator.userAgent.search(/Gecko/) != -1) { window.resizeBy(-1,-1) && window.resizeBy(1,1); }
}

function isStyleSheetType(str,type) {
  if      (str == "")                             { return true; }
  else if (type == "width" && str.match(/\d/))    { return true; }
  else if (type != "width" && str.match(/^\D*$/)) { return true; }
  return false;
}

function getActiveStyleSheet(type) {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && isStyleSheetType(a.getAttribute("title"),type) && !a.disabled) return a.getAttribute("title");
  }
  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("title")
       ) return "default";
  }
  return null;
}

// This function is redefined in ie5win-fix.js for IE 5.x on Windows.
// As defined below it has no effect except in Mac IE 5.x.
function ie5widthfix (title) {
  if (navigator.appVersion.indexOf('Mac') != -1 && document.all) {
    var ih = new getObj("innihald");
	if (ih && ih.style) {
      if (title.match(/800/)) {
        ih.style.width = "501px";
      } else if (title.match(/1280/)) {
        ih.style.width = "801px";
      } else {
        ih.style.width = "551px";
      }
    }
  }
  return true; 
}

window.onunload = function(e) {
  var title = getActiveStyleSheet("fontsize");
  createCookie("style", title, 365);
  title = getActiveStyleSheet("width");
  createCookie("wstyle", title, 365);
}

var cookie = readCookie("style");
if (cookie == "null") {
	cookie = "default";
	createCookie("style", "default", 365);
}
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title,"fontsize");
cookie = readCookie("wstyle");
if (cookie == "null") {
	cookie = "";
	createCookie("wstyle", "", 365);
}
title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title,"width");
ie5widthfix(title);



