function update_drop_down(parent, child_id, hash, selected) {

  new_node = dropDown(getElement(child_id).name, hash[parent.value], selected);
  new_node.id = child_id;  // assign the same id to the new node
  new_node.className = getElement(child_id).className;  // assign the same id to the new node

  replaceNode(child_id, new_node);
}


function dropDown(name, array, selected) {

  select = document.createElement('select');
  select.name = name;

  for (key in array) {
    option = document.createElement('option');
    option.value = key;
    if (key == selected) {
      option.selected = true;
    }
    option.appendChild(document.createTextNode(array[key]));
    select.appendChild(option);
  }

  return select;
}

function getElement(id){
	if(document.getElementById){
		getElement = function(id){ return document.getElementById(id); }
	}else if(document.all){
		getElement = function(id){ return document.all[id]; };
	}else if(document.layers){
		getElement = function(id){ return document.layers[id]; };
	}else{
		getElement = function() { return null; }
	}

	// When we get here, the getElement function has been replaced.
	// So we return the result of the new function.
	return getElement(id);
}

function replaceNode(node_id, new_node) {
  target_node = getElement(node_id);
  target_node.parentNode.replaceChild(new_node, target_node);
}
