﻿function bindDropDownList(e, targetDropDownList) {
  bindDDList(this, targetDropDownList);
}

function bindDDList(srcList, targetDropDownList) {
  var key = srcList.value;
  var allOptions = targetDropDownList.allOptions;
  var option;
  var newOption;
  targetDropDownList.options.length = 1;

  if (!(key == null || key == "")) {
    for (var i = 0; i < allOptions.length; i++) {
      option = allOptions[i];
      if (option.key == key) {
        newOption = new Option(option.text, option.value);
        targetDropDownList.options.add(newOption);
      }
    }
  }
  targetDropDownList.value = "";
  if ("fireEvent" in targetDropDownList)
    targetDropDownList.fireEvent("onchange");
  else {
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent("change", false, true);
    targetDropDownList.dispatchEvent(evt);
  }
  targetDropDownList.disabled = (key == null || key == "");
}	

