function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

function stripyTables () {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("stripy")) return false;
	var stripe = document.getElementById("stripy");
	var tables = stripe.getElementsByTagName("table");
	for (var i=0; i<tables.length; i++) {
	  var odd = false;
	  var rows = tables[i].getElementsByTagName("tr");
	  for (var j=0; j<rows.length; j++) {
	    if (odd == true) {
	      addClass(rows[j],"odd");
	      odd = false;
	    } else {
	      odd = true;
	    }
	  }
	}
}

function highlightRows() {
  if(!document.getElementsByTagName) return false;
  if (!document.getElementById("stripy")) return false;
  var stripe = document.getElementById("stripy"); 
  var rows = stripe.getElementsByTagName("tr");
  for (var i=0; i<rows.length; i++) {
    rows[i].oldClassName = rows[i].className
    rows[i].onmouseover = function() {
      	addClass(this,"highlight");
		}
		rows[i].onmouseout = function() {
      	this.className = this.oldClassName
		}
	}
}

function rowClick () {
	if(!document.getElementsByTagName) return false;
	if (!document.getElementById("stripy")) return false;
	var stripe = document.getElementById("stripy");
	var rows = stripe.getElementsByTagName("tr");		
	for (var i=0; i<rows.length; i++) {
		var links = rows[i].getElementsByTagName("a");
		if (links[0] != null) {
			rows[i].linkHref = links[0].getAttribute("href");
			rows[i].onclick = function() {
				window.location.href = this.linkHref;
			}
		}	    
	}
}

function showSection(id) {
  var div = document.getElementById(id);
  if (div.style.display == "block") {
    div.style.display = "none";
  } else {
    div.style.display = "block";
  }
}

function prepareInternalnav() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i<links.length; i++ ) {
    var sectionId = links[i].getAttribute("href").split("#")[1];
    if (!document.getElementById(sectionId)) continue;
    document.getElementById(sectionId).style.display = "none";
    links[i].destination = sectionId;
    links[i].onclick = function() {
      showSection(this.destination);
      return false;
    }
  }
}

function cancelBubble(e)
{

    if (window.event)
    {
        window.event.cancelBubble = true;
    }
    else if (e)
    {
        e.cancelBubble = true;
    }

}

addLoadEvent(stripyTables);
addLoadEvent(highlightRows);
addLoadEvent(rowClick);
addLoadEvent(prepareInternalnav);
