function swapOn(project) {
   document.getElementById(project).style.backgroundColor = "#bfced5";
}

function swapOff(project) {
   document.getElementById(project).style.backgroundColor = "#ffffff";
}

function popUp(page, width, height) {
   OpenWin = this.open(page, "popupWin", "width="+width+",height="+height+",toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,status=no");
}

// Stylesheet Switcher section -------------------------------------------------

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

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 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 a.getAttribute("title");
  }
  return null;
}

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;
}

// --------------------------------------------- End Stylesheet Switcher section

// O'Reilly cookies.js code setting cookies ------------------------------------

function getExpDate(days, hours, minutes) {
  var expDate = new Date();
  if (typeof days == "number" && typeof hours == "number" && typeof minutes == "number") {
    expDate.setDate(expDate.getDate() + parseInt(days));
    expDate.setHours(expDate.getHours() + parseInt(hours));
    expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
    return expDate.toGMTString();
  }
}

function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";",offset);
  if (endstr == -1) {
    endstr == document.cookie.length;
  }
  return unescape(document.cookie.substring(offset,endstr));
}

function getCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i,j) == arg) {
      return getCookieVal(j);
    }
    i = document.cookie.indexOf(" ",i) + 1;
    if (i == 0) break;
  }
  return "";
}

function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
                    ((expires) ? "; expires=" + expires : "") +
                    ((path) ? "; path=" + path : "") +
                    ((domain) ? "; domain=" + domain : "") +
                    ((secure) ? "; secure" : "");
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    docment.cookie = name + "=" +
                     ((path) ? "; path=" + path : "") + 
                     ((domain) ? "; domain=" + domain : "") +
                     "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// -------------------------------- End O'Reilly cookies.js code setting cookies
window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);