function filterLinks(tInput){
  searchText = new RegExp(tInput.value,"i");
  inNode = getForm(tInput).nextSibling.childNodes;
  for (var i = 0; cNode = inNode[i]; i++){
    if (cNode.nodeName == "LI"){
      var t = cNode.innerText?cNode.innerText:getTextContent(cNode);
      if ((tInput.value.length == 0) || (t.search(searchText) != -1)){
        cNode.style.display = cListItemVisible; 
      } else {
        cNode.style.display = cListItemHidden; 
      }
    }
  }
}

function getForm(node){
  while (node.nodeName != "FORM") {
    node = node.parentNode;
    getForm(node);
  }
  return node;
}

function getTextContent(node) {
  if (node.nodeType == 3) {
    return node.nodeValue;
  } // text node
  if (node.nodeType == 1) { // element node
    var text = [];
    for (var chld = node.firstChild;chld;chld=chld.nextSibling) {
        text.push(getTextContent(chld));
    } 
    return text.join("");
  } return ""; // some other node, won't contain text nodes.
}


function createFilterForm(){
  var f = document.createElement("form");
  f.setAttribute("onsubmit", "return false;");
  var p = document.createElement("p");
  ft = document.createElement("label");
  ft.appendChild(document.createTextNode("Filter: "));
  p.appendChild(ft);
  ft = document.createElement("input");
  ft.onkeyup = testEvent;
  ft.title = "Plain text or regular expressions accepted";
  p.appendChild(ft);
  f.appendChild(p);
  return f;
}


function testEvent(e){
  filterLinks(e.currentTarget);
}


/**
 * function initFilter()
 *
 * Creates the input for the filter, and appends it to the chosen list.
 * Customize 
 **/

function initFilter() {
  // create filter form
  filterForm = createFilterForm();
  // Add filter to second list on page.
  // You will want to adapt this for your own site.
  // A good adoption would be only using this for
  // lists of certain classes or with certain ID's
  // This is about the only portion of the script you 
  // will need to modify.
  var lists = document.getElementsByTagName("UL");
  lists[1].parentNode.insertBefore(filterForm,lists[1]);

}



// Script initialization
var cListItemVisible = "list-item";
var cListItemHidden = "none";

if (window.opera){
  document.addEventListener("load",initFilter,false)
} else if (window.addEventListener){
  window.addEventListener("load",initFilter ,false);
}
