addEvent(window, 'load', function(e) {
  var tables = document.getElementsByTagName('table');
  for (var i = 0; i < tables.length; i++) {
    if (tables[i].className.search(/\bscriptanalysis\b/) != -1) {
      var id = tables[i].getAttribute('id');
      var tb = document.createElement('button');
      tb.setAttribute('class', 'tableToggle');
      tb.setAttribute('type', 'button');
      tb.onclick = new Function("toggle('" + id + "')");
      tb.appendChild(document.createTextNode('Show/hide analysis'));
      tables[i].parentNode.insertBefore(tb, tables[i]);
      if (document.location.hash != '') {
        // if the browser is going to an element that would be hidden if we hid
        // this table, don't hide the table (by clearing the id)
        for (var ele = document.getElementById(document.location.hash.substr(1)); ele != null; ele = ele.parentNode) {
          if (ele.getAttribute && ele.getAttribute('id') == id) {
            id = null;
            break;
          }
        }
      }
      if (id) {
        toggle(id);
      }
    }
  }
}, false);
function toggle(id) {
  var ele = document.getElementById(id);
  ele.style.display = (ele.style.display == 'none') ? '' : 'none';
  return false;
}
