// credit to Simon Willison for this function

function addLoadEvent(func)
{
  var oldonload = window.onload;
  if(typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
  
// Original JavaScript code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.

if(typeof hilite_tag == "undefined") {
  var hilite_tag = "EM";
}

function highlight(node)
{
  if(!node || !hilite) return;
  if(node.nodeName == hilite_tag
	|| node.nodeName == "SCRIPT"
	|| node.nodeName == "FORM"
	|| node.nodeName == "SPAN") return;
  if(node.hasChildNodes()) {
    for(var i=0; i < node.childNodes.length ; i++)
      highlight(node.childNodes[i]);
  }
  if(node.nodeType == 3) { // NODE_TEXT
    nv = node.nodeValue;
    if(nv != "" && (regs = hilite.exec(nv))) {
      var match = document.createElement(hilite_tag);
      match.appendChild(document.createTextNode(regs[0]));
      var after = node.splitText(regs.index);
      after.nodeValue = after.nodeValue.substring(regs[0].length);
      node.parentNode.insertBefore(match, after);
    }
  }
}

function searchhighlight()
{
  if(!hilite_id) return;
  if(navigator.userAgent.indexOf("Mac_PowerPC") != -1) return;
  if(!document.createElement) return;
  if(firstNode = document.getElementById(hilite_id)) highlight(firstNode);
}

addLoadEvent(searchhighlight);
