function hasClass(node, className){
  var clName = " "+node.className+" ";
  return (clName.indexOf(" "+className+" ") != -1);
}
function showHideContent(node){
  var childID;
  for (childID=0;childID<node.childNodes.length;childID++){        
    var child = node.childNodes[childID];
    if (child.nodeName=="TR" && hasClass(child, "show-hide-content")){
      if (child.style.display == 'table-row'){
        child.style.display ='none';
      } else {
        child.style.display = 'table-row';
      }
    } else showHideContent(child);
  }
}
function showHideTable(tableID){
  var table = document.getElementById('show-hide-table_'+tableID);
  showHideContent(table);
  return false;
}
function searchShowHideLink(node, tableID){
  var childID;
  for (childID=0;childID<node.childNodes.length;childID++){        
    var child = node.childNodes[childID];
    if (child.nodeName=="A"){
      child.href = "#";
      child.onclick = function() { return showHideTable(tableID); }
    } else searchShowHideLink(child, tableID);
  }
}
function searchShowHideButton(node, tableID){
  var childID;
  for (childID=0;childID<node.childNodes.length;childID++){        
    var child = node.childNodes[childID];    
    if (child.nodeName=="TR"){
      if (hasClass(child, "show-hide-button")) {
        searchShowHideLink(child, tableID);
      }
    } else searchShowHideButton(child, tableID);
  }
}

function init_show_hide_table(){
  var tableID;
  var allTables = document.getElementsByTagName("table");
  
  for (tableID=0;tableID<allTables.length;tableID++) {
    var table = allTables[tableID];
    
    if (hasClass(table, "show-hide-table")) {
      table.id = 'show-hide-table_'+tableID;
      searchShowHideButton(table, tableID);
    }
  }
}

function addLoadEvent(func) {
    var oldQueue = window.onload? window.onload: function() {};
    window.onload = function() {
        oldQueue();
        func();
    }
}

if ( document.getElementById && document.getElementsByTagName ) {
  addLoadEvent(init_show_hide_table);
}

