/*
// for debugging 
function headache(topnode)
{
    var msg= "";
    var p = topnode.parentNode;
    msg += "tagname: " + topnode.tagName + "\n";
    msg += "parentNode: " + p.tagName + "\n";
    if (topnode.firstChild!= null) {    msg += "firstChild: " + topnode.firstChild.tagName + "\n"; }
    if (topnode.lastChild != null)  { msg += "lastChild: " + topnode.lastChild.tagName + "\n"; }
    if (topnode.nextSibling != null)  { msg += "nextSib: " + topnode.nextSibling.tagName + "\n"; } 
    if (p.nextSibling != null)  { msg += "p.nextSib: " + p.nextSibling.tagName + "\n"; } 
    if (topnode.previousSibling != null) { msg += "prevSib: " + topnode.previousSibling.tagName + "\n"; }
    if (p.previousSibling != null) { msg += "p.prevSib: " + p.previousSibling.tagName + "\n"; }
    if (p.hasChildNodes()) { msg += "p.children= " + p.childNodes.length + "\n"; }

    var n = p;
    while (n.nextSibling != null)
    {
        msg += "/" + n.tagName ;
        n = n.nextSibling;
    }
    msg += "\n";

    for(var i =0; i < p.childNodes.length; i++) 
    {
        msg += "c[" + i + "]=" + p.childNodes[i].tagName + "\n";
    }
    alert(msg);
}
*/


function borderit(which,color)
{
  if (document.all||document.getElementById)
  {
      which.style.borderColor=color;
  }
}
  

function expandOrCollapse(sourceNode)
{
    // toggle the expansion of a collapsible node

    /* This logic assumes that the DIV or UL to be expanded or collapsed
    is the next sibling of the parent of the image or element
    clicked. */

    //headache(sourceNode);

    //document.getElementById('DEBUG').innerHTML += 
    // "<span class='kindared'>[" + sourceNode.tagName + "] </span>";

    var p = sourceNode.parentNode;
    var block = p;

    // this is necessary because FF treats whitespace as nodes, while IE does not
    if (p.childNodes.length != 3)
    {
        // on IE7, the sub-UL that follows the LI in the html file,  is a child of the LI in the DOM
        // on FF, the sub-UL that follows the LI in the html file, is a sibling of the LI in the DOM
        block = block.firstChild;
    }

    while (block.nextSibling != null && block.tagName != "UL")
    {
        block = block.nextSibling;
    }


    // Do 2 things:  expand the UL block, and change the GIF, if it exists. 

    /* Be sure the block to be expanded or collapsed exists */
    if (null == block)  return ;
    if ("UL" != block.tagName)  return ;

//     if (gif == "class" || gif == "namespace" || gif == "method" || gif == "structure" 
//         || gif == "document" 
//         || gif == "collapsed" || gif == "expanded")

    // step 1: toggle the block
    if (block.style['display'] == 'none')
    {
        block.style['display'] = 'block';
    }
    else
    {
        block.style['display'] = 'none';
    }

    var imgNode = sourceNode;

    // step 2: change the GIF (if applicable)
    var gif;

    // Sometimes we don't clikc on the image but on the <A> word following the image.
    // This happens when the word represents a folder that holds raw HTML content. 
        while (imgNode.previousSibling != null && imgNode.tagName != "IMG")
        {
            imgNode = imgNode.previousSibling;
        }
        
        if (imgNode.tagName == "IMG")
            gif = imgNode.src;

    if (gif == undefined) return ; // bail

    var ix =  gif.lastIndexOf(".");
    gif = gif.substring(0,ix);
    ix = gif.lastIndexOf("/"); 
    if (ix > 0)
    {
      gif = gif.substring(ix+1);
    }


    if (gif == "collapsed")
    {
        imgNode.src = "images/expanded.gif";
    }
    else if (gif == "expanded")
    {
        imgNode.src = "images/collapsed.gif";
    }

}


