// Gives "onclick='document.localtion=_link_'" to all 'LI' in a menu having 'A' inside.

// @author: Aleksey Gureev (spyromus @ noizeramp . com)



function processMenu(id) {

  processNode(document.getElementById(id));

}



function processNode(node) {

  if (node.nodeName == 'LI') {

    var link = getALink(node);

    if (link != null) {

      node.onclick = function() { document.location = getALink(this); }

    }

  }

  

  var children = node.childNodes;

  for (var i = 0; i < children.length; i++) {

    var child = children[i];

    if (child.nodeName == 'LI' || child.nodeName == 'UL') {

      processNode(children[i]);

    }

  }

}



function getALink(node) {

  var link = null;

  var children = node.childNodes;

  if (children) {

    for (var i = 0; link == null && i < children.length; i++) {

      var cnode = children[i];

      if (cnode.nodeName == 'A') { link = cnode.href; }

    }

  }

  return link;

}