/* $Id: functions.js,v 1.1 2009-06-04 18:59:42 andy Exp $ */

/* initialise a <select> */
function SetSelect(ele, val)
{
  if (typeof ele != 'object') return;
  if (null == ele.options) return;
  for (var i=0; i<ele.options.length; i++) {
    if (ele.options[i].value == val) {
      ele.selectedIndex = i;
      return;
    }
  }
}

/* Extract all content from a node */
function GetContent(node)
{
  var content = '';
  var children = node.childNodes;
  for (var i=0; i<children.length; i++) {
    var child = children[i];
    if (child.nodeType == 3) {
      content += child.nodeValue;
    }
    else {
      content += GetContent(child);
    }
  }
  return content;
}

/* Invoke a function on all children of a node */
function ProcessTree(node, func)
{
  func(node);
  var children = node.childNodes;
  for (var i=0; i<children.length; i++) {
    var child = children[i];
    func(child);
    if (child.nodeType != 3) {
      ProcessTree(child, func);
    }
  }
}

