function getAllSheets() {
  //if you want ICEbrowser's limited support, do it this way
  if( !window.ScriptEngine && navigator.__ice_version ) {
  	//IE errors if it sees navigator.__ice_version when a window is closing
  	//window.ScriptEngine hides it from that
    return document.styleSheets; }
  if( document.getElementsByTagName ) {
    //DOM browsers - get link and style tags
    var Lt = document.getElementsByTagName('link');
    var St = document.getElementsByTagName('style');
  } else if( document.styleSheets && document.all ) {
    //not all browsers that supply document.all supply document.all.tags
    //but those that do and can switch stylesheets will also provide
    //document.styleSheets (checking for document.all.tags produces errors [WHY?!])
    var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
  } else { return []; } //lesser browser - return a blank array
  //for all link tags ...
  for( var x = 0, os = []; Lt[x]; x++ ) {
    //check for the rel attribute to see if it contains 'style'
    if( Lt[x].rel ) { var rel = Lt[x].rel;
    } else if( Lt[x].getAttribute ) { var rel = Lt[x].getAttribute('rel');
    } else { var rel = ''; }
    if( typeof( rel ) == 'string' &&
        rel.toLowerCase().indexOf('style') + 1 ) {
      //fill os with linked stylesheets
      os[os.length] = Lt[x];
    }
  }
  //include all style tags too and return the array
  for( var x = 0; St[x]; x++ ) { os[os.length] = St[x]; } return os;
}

function changeStyle(title) {
  for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
    //for each stylesheet ...
    if( ss[x].title ) {
      //disable the stylesheet if it is switchable
      ss[x].disabled = true;
    }
    if( ss[x].title == title ) {
        //and re-enable the stylesheet if it has a chosen title
        ss[x].disabled = false;
	putCookie(title);
    }
  }
  //if( !ss.length ) { alert( 'Your browser cannot change stylesheets' ); }
}



function activateStyleSheet(title) {
	var c, i, t;

	if(!(c = document.styleSheets)) {return true;}

	i = c.length;
	while(i--) {
		if((t = c[i].title)) {
		c[i].disabled = (title != t);
		}
	}
	putCookie(title);
	return false;
	}

cookie_name = "styleCookie";
var YouEntered;
var YouWrote;
var selectionString;

function getName() {
	if(document.cookie)
	{
	index = document.cookie.indexOf(cookie_name);
	if (index != -1)
	{
		namestart = (document.cookie.indexOf("=", index) + 1);
		nameend = document.cookie.indexOf(";", index);
		if (nameend == -1) {nameend = document.cookie.length;}
		YouWrote = document.cookie.substring(namestart, nameend);
		return YouWrote;
	}
	}
}

YouWrote=getName();
selectionString="<select NAME=\"myStyleSheet\" onchange=\"changeStyle(this.value);\">";
for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) 
{
  if( ss[x].title ) {
    if( ss[x].title == YouWrote ) {
      isDefaultStr = " selected";
      changeStyle(YouWrote); 
    } else {
      isDefaultStr = "";
    }
    selectionString = selectionString + "<option VALUE=\"" + ss[x].title + "\"" + isDefaultStr +
      ">" + ss[x].title + "</option>";
  }
}
selectionString = selectionString + "</select>";



/*
  if (YouWrote == 'Blue Style') {
    selectionString='<LI><select NAME="myStyleSheet" onchange="changeStyle(this.value);"><option VALUE="Default Style">Default Style<option VALUE="Blue Style" selected>Blue Style</select></LI>';
  changeStyle(YouWrote); 
  } else {
  selectionString='<LI><select NAME="myStyleSheet" onchange="changeStyle(this.value);"><option VALUE="Default Style">Default Style<option VALUE="Blue Style">Blue Style</select></LI>';
  changeStyle("Default Style"); 
  }
} else {
  selectionString='<LI><select NAME="myStyleSheet" onchange="changeStyle(this.value);"><option VALUE="Default Style">Default Style<option VALUE="Blue Style">Blue Style</select></LI>';
  changeStyle("Default Style"); 
};
*/

function putCookie(value) {

	if(document.cookie != document.cookie) 
	{index = document.cookie.indexOf(cookie_name);}
	else 
	{ index = -1;}

	if (index == -1)
	{
	howlong = new Date(); howlong.setTime(howlong.getTime() + 1000*86400*365*5); 
	document.cookie=cookie_name + "=" + value + "; expires=" + howlong.toGMTString() + "; path=/";
	}
}

function clientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}


