var bodynode = document.getElementById("pagebody");
var pnode = document.createElement('p');
var anode = document.createElement('a');
var imgnode = document.createElement('img');
var spannode = document.createElement('span'); 
var textnodeone = document.createTextNode("    ");
var textnodetwo = document.createTextNode("Hide menu.");
pnode.setAttribute("class", "menu");
pnode.setAttribute("style", "margin-bottom: 0.1em");
anode.setAttribute("title","Toggle tree menu state, visual display effect.");
anode.onclick = new Function("hidetreemenu();return false;");
anode.onkeypress = new Function("hidetreemenu();return false;");
imgnode.setAttribute("id","menutoggle");
imgnode.setAttribute("style","width: 16px; height: 16px; border-width: 0px");
imgnode.setAttribute("alt","Hide menu button");
imgnode.setAttribute("width","16px");
imgnode.setAttribute("height","16px");
imgnode.setAttribute("src","/images/hidemenu.gif");
spannode.setAttribute("id","menutext");
pnode.appendChild(anode);
pnode.appendChild(textnodeone);
pnode.appendChild(spannode);
anode.appendChild(imgnode);
spannode.appendChild(textnodetwo);
bodynode.insertBefore(pnode, bodynode.firstChild);
//self.document.write('<p class="menu" style="margin-bottom: 0.1em"><a onclick="hidetreemenu();" onkeypress="hidetreemenu();" title="Toggle tree menu state, visual display effect."><img id="menutoggle" src="/images/hidemenu.gif" width="16px" height="16px" style="width: 16px; height: 16px; border-width: 0px" alt="Hide menu button"/></a>&nbsp;&nbsp;&nbsp;&nbsp;<span id="menutext">Hide menu.<span></p>');

function hidetreemenu()
{
  var tmcell = document.getElementById("treemenucell");
  var mtimage = document.getElementById("menutoggle");
  var mtspan = document.getElementById("menutext");
  var j;
  for(var i = 0;i<mtspan.childNodes.length;i++)
  {
    if (mtspan.childNodes[i].nodeType == 3) 
    {
      j = i;
    }
  }
  var currenttext = mtspan.childNodes[j].nodeValue;
  var currentstate = mtimage.getAttribute("alt");
  var currentimage = mtimage.getAttribute("src");
  var pattern = /Show/i;
  var showit = pattern.test(currentstate);
  if (showit)
  {
    tmcell.style.display = "";
    pattern = /Show/i;
    currentstate = currentstate.replace(pattern, "Hide");
    currentimage = currentimage.replace(pattern, "hide");
    currenttext  = currenttext.replace(pattern, "Hide"); 
  }
  else
  {
    tmcell.style.display = "none";
    pattern = /Hide/i;
    currentstate = currentstate.replace(pattern, "Show");
    currentimage = currentimage.replace(pattern, "show"); 
    currenttext  = currenttext.replace(pattern, "Show"); 
  }
  mtimage.setAttribute("alt", currentstate );
  mtimage.setAttribute("src", currentimage );
  mtspan.childNodes[j].nodeValue = currenttext;
}