/**
Appends all options defined by the array "a" (defined in the form value=>text) to the select-elemet
identified by the id "id"
*/
function appendOptions(id,a)
{
 // First remove all the items from the select list (if any)
 removeOptions(id);
 // Append the new items to the select list
 for(var i in a)
 {
  appendOptionLast(id,a[i],i);
 }
}

/**
Adds an option-item to the select-element with the id "id"
text and value of the option-element are identifed by 2nd and 3rd parameters
*/
function appendOptionLast(id,text,value)
{
  var elSel = document.getElementById(id); 
 
  var elOpt = document.createElement('option');
  elOpt.text = text;
  elOpt.value = value;

  try {
   elSel.add(elOpt, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
   elSel.add(elOpt); // IE only
  }
}

/**
Remove all option-elements from the select-element identified by the id
*/
function removeOptions(id)
{
  var elSel = document.getElementById(id);
  while(elSel.length > 0)
  {
   elSel.remove(elSel.length - 1);
  }
}

/**
Prevent default action (including event bubbling)
*/
function stopDefault(e)
{
 if(e && e.preventDefault)
 {
   e.preventDefault();
 } else {
  window.event.returnValue=false;
 }
}
