/* global functions */
/* todo: delete this file and replace usages with references to 
   typo methods with similar use */

function debug(obj)
{
    var props = "";
    for (var property in obj)
    {
      props += property + ": " + obj[property] + "\n";
    }
    props = "Properties of object: \n\t" + props;
    //alert(props);
    var opts = "width=250,height=450,resizable,scrollbars=auto";
    var win = window.open("", "x", opts, true);
    win.document.writeln("<pre>"+props+"</pre>");
}

function getElementsByClassName(objRef, className)
{
    var matches = new Array();
    var alltags = objRef.getElementsByTagName( "*" );
    for (var i=0; i<alltags.length; i++)
    {
      if (alltags[i].className.toLowerCase() == className.toLowerCase())
      {
        matches[matches.length] = alltags[i];
      }
    }
    return matches;
}

function getEvtTarget(evt)
{
  if (document.all) return window.event.srcElement; // for M$IE
  if (evt.target.nodeType == Node.TEXT_NODE) return evt.target.parentNode; // for Safari
  return evt.target;
}

function deriveName(from, prefix)
{
  var num = from.substring(from.lastIndexOf("-")+1);
  return prefix + "-" + num;
}

function deselectExisting(parentNode, correspondingPrefix)
{
  var existingList = getElementsByClassName(parentNode, "selected");
  if (!existingList || existingList.length == 0) return;  // done
  var existing = existingList[0];
  existing.className = "";
  var existingCorrespondingId = deriveName(existing.id, correspondingPrefix);
  document.getElementById(existingCorrespondingId).className = "";
}

function selectNew(newNode, correspondingPrefix)
{
  newNode.className = "selected";
  var correspondingIdName = deriveName(newNode.id, correspondingPrefix);
  document.getElementById(correspondingIdName).className = "selected";
}

function hasClassName(node, className)
{
  var ra = node.className.split(" ");
  for (var i=0; i<ra.length; i++)
  {
    if (ra[i] == className)
    {
      return true;
    }
  }
  return false;
}

function toggleVisibility(tagid)
{
  var node = document.getElementById(tagid);
  var vis = node.style.visibility;
  if (vis == "" || vis == "visible")
  {
    node.style.visibility = "hidden";
  }
  else
  {
    node.style.visibility = "visible";
  }
}


