/*  Teeple Construction
    Frank Teeple, General Manager
	 http://www.teepleconstruction.com
	 
	 Developed by Contract Web Development
	 http://www.contractwebdevelopment.com 
	 
	 
	 Conditions of Use: All downloads and use of this code are subject to the following terms: 
	 Software and source code Copyright (C) 2003-2005 Contract Web Development (http://www.contractwebdevelopment.com)
	 written by Alex Schenker (aquarius@contractwebdevelopment.com). This software is copyright under the 
	 following conditions: Permission to use, copy, and modify this software and its documentation is 
	 hereby granted to Frank Elston Teeple the third and Archibald William Miller the fifth,
	 without fee, provided that the above copyright notice, this permission notice, and the code
	 <p> All Content Copyright &copy; 2003-2005 <a href="http://www.teepleconstruction.com">Teeple 
	 Construction</a> and <a href="http://www.contractwebdevelopment.com" target="_blank">Contract Web Development</a>. 
	 All Rights Reserved.</p> appear in all copies of the software and related documentation. The output
	 this code generates must be visible at all times, and the year 2004 must be updated to reflect the 
	 current calendar year. Permission to distribute the software or modified or extended versions 
	 thereof on a not-for-profit basis is explicitly granted, under the above conditions. However, the 
	 right to use this software by companies or other for profit organizations, or in conjunction with 
	 for profit activities, and the right to distribute the software or modified or extended versions 
	 thereof for profit are NOT granted except by prior arrangement and written consent of the 
	 copyright holders. For these purposes, downloads of the source code constitute "use" and 
	 downloads of this source code by for profit organizations and/or distribution to for profit 
	 institutions in explicitly prohibited  without the prior consent of the copyright holders. 
	 Use of this source code constitutes an agreement not to criticize, in any way, the code-writing 
	 style of the author, including any statements regarding the extent of documentation and comments 
	 present. Modification of this source code constitutes an agreement that this software and source 
	 code must be validated by the W3 Validator located at http://validator.w3.org prior to being
	 hosted, served, or displayed on the Internet. The software is provided "AS-IS" and without 
	 warranty of any kind, express, implied or otherwise, including without limitation, any warranty 
	 of merchantability or fitness for a particular purpose. In no event shall Contract Web Development or the 
	 authors be liable for any special, incudental, indirect or consequential damages of any kind, or 
	 any damages whatsoever resulting from loss of use, data or profits, whether or not advised of the 
	 possibility of damage, and on any theory of liability, arising out of or in connection with the 
	 use or performance of this software. 

*/

/* Styleswitching script by Paul Sowden, a teenager from London, England, who believes the web would 
   be a better place if everyone used standards–compliant design techniques. Visit him at 
	 http://www.idontsmoke.co.uk/. 
	 styleswitcher.js retrieved December 2003 from http://www.alistapart.com/articles/alternate/
*/

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.ignore = 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("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);
