

var SelectExtend = {
  addOption: function(element, value, display, selected)
  {
    if (!display) 
      display = value;
      
    var option = document.createElement('option');
    option.value = value;
    if (selected)
      option.selected = true;
    option.innerHTML = display;
    element.appendChild(option);
    return element;
  },
  
  clearOptions: function(element, keepFirstOption)
  {
    var i = keepFirstOption ? 1 : 0;
    var children = element.childElements();
    while(children.length > i)
    {
      element.removeChild(children[i]);
      children = element.childElements();
    }
    return element; 
  },
  
  hasOption: function(element, value)
  {
    for(var i=0; i<element.options.length; ++i)
		{
      if (element.options[i].value == value)
       return true;
    }
    return false;
  },
  
  selectOption: function(element, value)
  {
    for(var i=0; i<element.options.length; ++i)
    {
      var option = element.options[i];
      option.selected = (option.value == value);
    }
    
  }
}

try
{
  Element.addMethods(SelectExtend);
}
catch (e)
{
  console.error('SelectExtend', e);
}