// styleswitcher.js
// Author:		Don Stier, Maplegate Technologies, LLC
// Date:		2/12/2002

function setActiveStyleSheet(title, set) {
  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;
    }
  }
  if (set == 1) createCookie ("CSSSize", title, 350);

	if (title == 'CSSMed')
		showHideLayers('CSSMed','hide', 'CSSLrg','show');
	else
		showHideLayers('CSSMed','show', 'CSSLrg','hide');
}

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;
}

window.onload = function(e) {
  var cookie = readCookie("CSSSize");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title , 0);
}

var cookie = readCookie("CSSSize");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title , 0);

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

// Accepts a variable number of arguments, in pairs as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'show',Layer2,'hide');
function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-1); i+=2)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+1];
      if (obj.style)
      {
        obj = obj.style;
        if (visStr == 'show') visStr = 'visible';
        else if (visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}
