// Add Load Event function

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
		oldonload();
		func();
		}
	}
}

//

// li:hover function to make dynamic menu's work in ie5-6

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("mainnav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

addLoadEvent(startList);

//

// Resets Form items to preset text

function resetFields(whichform) {
  for (var i=0; i<whichform.elements.length; i++) {
    var element = whichform.elements[i];
    if (element.type == "submit") continue;
	if (element.type == "img") continue;
	if (element.type == "radio") continue;
	if (element.type == "hidden") continue;
    if (!element.defaultValue) continue;
    element.onfocus = function() {
    if (this.value == this.defaultValue) {
      this.value = "";
     }
    }
    element.onblur = function() {
      if (this.value == "") {
        this.value = this.defaultValue;
      }
    }
  }
}

function prepareForms() {
  for (var i=0; i<document.forms.length; i++) {
    var thisform = document.forms[i];
    resetFields(thisform);
  }
}

addLoadEvent(prepareForms);

//

// Text only function

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 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 textonly(){
  var cookie = readCookie("textonly");
  var flip = cookie != 'yes';
  try{
    stylesheets=this.document.styleSheets;
    for(i=0;i<stylesheets.length;i++)
      stylesheets[i].disabled = flip;
    createCookie('textonly',flip ? 'yes':'no',365);
  }
  catch(m){
  }
  var title = cookie ? cookie : getPreferredStyleSheet();
  var grdiv = document.getElementById('graphicsversion');
  if (grdiv) {
    if (flip) {
      grdiv.style.display = "block";
    } else {
      grdiv.style.display = "none";
    }
  }
  setActiveStyleSheet(title);
}
