
setAnchors = function() {
   for (var i=0; i < document.links.length; i++) {
      if ((document.links[i].href == document.location) || (document.links[i].href == document.location + 'index.php')) {
			//alert(document.links[i].innerHTML+' is active');
         document.links[i].className = 'active';
         document.links[i].title = 'You are here.';
      }
	}
}
/*
setSourceForIE = function(elid,iesrc) {
   var arVersion = navigator.appVersion.split("MSIE");
   var version = parseFloat(arVersion[1]);
   if ((version >= 5.5) && (document.body.filters) && (document.getElementById(elid))) {
      document.getElementById(elid).src = iesrc;
   }
}*/
/*
sfFocus = function() {
   var sfEls = document.getElementsByTagName("A");
   for (var i=0; i<sfEls.length; i++) {
      sfEls[i].onfocus=function() {
         this.className+=" sffocus";
      }
      sfEls[i].onblur=function() {
         this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
      }
   }
}

sfHover = function() {
   var sfEls = document.getElementById("navigation").getElementsByTagName("li");
   for (var i=0; i<sfEls.length; i++) {
      sfEls[i].onmouseover=function() {
         this.className+=" sfhover";
      }
      sfEls[i].onmouseout=function() {
         this.className=this.className = ''; //.replace(new RegExp(" sfhover\b"), "");
      }
   }
}
*/
restoreDefault = function() {
   if (!this.value){
      this.value=this.defaultValue;
   }
}

clearDefault = function() {
   if (this.value==this.defaultValue){
      this.value='';
   }
}

setInputHandlers = function() {
   for(var i=0;i<document.forms.length;i++){
      f=document.forms[i];
      for(var j=0;j<f.length;j++){
         c=f[j];
         if(c.type == 'text' || c.type == 'textarea'){
            c.onfocus=clearDefault;
            c.onblur=restoreDefault;
         }
      }
   }
}

addEvent = function(obj, evType, fn, useCapture){
   if (obj.addEventListener){
      obj.addEventListener(evType, fn, useCapture);
      return true;
   } else if (obj.attachEvent){
      var r = obj.attachEvent("on"+evType, fn);
      return r;
   } else {
      // be silent
      // alert("Handler could not be attached");
   }
}

removeEvent = function(obj, evType, fn, useCapture){
   if (obj.removeEventListener) {
      obj.removeEventListener(evType, fn, useCapture);
      return true;
   } else if (obj.detachEvent){
      var r = obj.detachEvent("on"+evType, fn);
      return r;
   } else {
      // be silent
      // alert("Handler could not be removed");
   }
}



/* \\\\\\
Style Sheet Switcher from A List Apart
http://www.alistapart.com/stories/alternate/
modified to deal w/bad cookies
*/

function setActiveStyleSheet(title) {
  if( title == 'null' ) return;
  var i, a, main, set=0;
  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;
		  set=1;
	  }
    }
  }
  if( !set ) setActiveStyleSheet(getPreferredStyleSheet());
}

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

function setCSS() {
  var cookie = readCookie("style");
  var title = cookie != 'null' ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  if( getActiveStyleSheet() == 'null' ) setActiveStyleSheet(getPreferredStyleSheet());
}

function saveCSS() {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}


/* ////// */
addEvent(window, 'load', setCSS);
addEvent(window, 'unload', saveCSS);
addEvent(window, 'load', setAnchors);
addEvent(window, 'load', setInputHandlers);

