// $Id$
// vi:ts=2 sw=2 expandtab

function find_parent(node, type)
{
    var pnode = null;
    type = type.toUpperCase();
    while (pnode = node.parentNode) {
        if (pnode.tagName.toUpperCase() == type) {
            return pnode;
        }
        node = pnode;
    }
    return null;
}
function showtab(anchor, id, named_anchor)
{
  if (window.event != null) window.event.returnValue = false;

  // highlight selected
  if (null == anchor) return;
  var tabobj = find_parent(anchor, 'ul');
  if (null == tabobj) return false;

  // distable all tabs
  var tabobjlinks = tabobj.getElementsByTagName("A");
  for (i=0; i<tabobjlinks.length; i++) {
    tabobjlinks[i].className = "";
  }
  anchor.className = "current";

  var parent_div = find_parent(tabobj, 'div');
  var tab_name = parent_div.id;
  var name_parts = tab_name.split(':');
  var tab_prefix = name_parts[1];

  var divs = parent_div.getElementsByTagName("DIV");
  var other_div = new Array();
  var found_target = false;
  for (var i in divs) {
    var the_div = divs[i];
    if (null == the_div.id) continue;
    name_parts = the_div.id.split(':');
    if (name_parts[0] == tab_prefix) {
      if (name_parts[1] == id) {
        the_div.style.display = "block";
        found_target = true;
      }
      else
        other_div.push(the_div);
    }
  }
  if (found_target) {
    for (i=0; i<other_div.length; i++) {
      other_div[i].style.display = "none";
    }
  }
  if (null != named_anchor) {
    document.location = '#' + named_anchor;
  }
  return false;
}


