
//
// Extension To SELECT/DROPDOWN POPULATION
//
function populateSelectExt(id, targetId, uri, paramName, postFunc, emptyFunc, errorFunc) {
  var inputField = document.getElementById(id);
  var targetField = document.getElementById(targetId);
  if (!postFunc) postFunc = function () {};
  if (!emptyFunc) emptyFunc = function () {};
  if (!errorFunc) errorFunc = function () {};
 
  var updater = liveUpdater(constructUri, handlerFunc, null, emptyFunc, errorFunc);
  var timeout = window.setTimeout(updater, 0);
 
  function constructUri() {
    var separator = "?";
    if (uri.indexOf("?") >= 0)
        separator = "&";
    return uri
      + separator
      + paramName
      + "="
      + escape(inputField.options[inputField.selectedIndex].value);
  }
 
  function handlerFunc(xmlDoc) {
    var root = xmlDoc.documentElement;

    // clear existing options
    targetField.options.length = 0;

    if (root != null) {
      targetField.disabled = false;
      var items = root.childNodes;
      for (var i=0; i<items.length; i++) {
        targetField.options[i] = new Option(items[i].firstChild.nodeValue, items[i].getAttribute("value"));
      }

      targetField.focus();
      postFunc();
    }
  }
}
