function  walkTree(node, mapFunction, dataPackage) {
  if (node == null) return;
  mapFunction(node, dataPackage);
  for (var i = 0; i < node.childNodes.length; i++) {
    walkTree(node.childNodes[i], mapFunction, dataPackage);
  }
}

function searchTree(node, searchFunction, dataPackage) {
  if (node == null) return;
  var funcResult = searchFunction(node, dataPackage);
  if (funcResult) return funcResult;
  for (var i = 0; i < node.childNodes.length; i++) {
    var searchResult = searchTree(node.childNodes[i],
              searchFunction, dataPackage);
    if (searchResult) return searchResult;
  }
}

function  removeChildrenRecursively(node)
{
  if (!node) return;
  while (node.hasChildNodes()) {
    removeChildrenRecursively(node.firstChild);
    node.removeChild(node.firstChild);
  }
}

function removeElementById(nodeId) {
  document.getElementById(nodeId).parentNode.removeChild(
              document.getElementById(nodeId));
}

function getElmAttr(elm, attrName, ns) {
  // IE6 fails getAttribute when used on table element
  var elmValue = null;
  try {
    elmValue = (elm.getAttribute
          ? elm.getAttribute((ns ? (ns + NS_SYMB) : "")
          + attrName) : null);
  } catch (e) { return null; }
  if (!elmValue && is_saf) {
    elmValue = (elm.getAttributeNS
          ? elm.getAttributeNS(ns, attrName)
          : null);
  }
  return elmValue;
}

function setElmAttr(elm, attrName, value, ns) {
  if (!is_saf || !ns) {
    return (elm.setAttribute
          ? elm.setAttribute((ns ? (ns + NS_SYMB) : "")
          + attrName, value) : null);
  } else {
    return (elm.setAttributeNS
          ? elm.setAttributeNS(ns, attrName, value)
          : null);
  }
}

function remElmAttr(elm, attrName, ns) {
  if (!is_saf || !ns) {
    return (elm.removeAttribute
          ? elm.removeAttribute((ns ? (ns + NS_SYMB) : "")
          + attrName) : null);
  } else {
    return (elm.removeAttributeNS
          ? elm.removeAttributeNS(ns, attrName)
          : null);
  }
}

