// http://blog.boaideia.inf.br/articles/2007/01/20/rjs-at%C3%A9-que-um-dia
var HtmlSelectOptions = {}

HtmlSelectOptions = {
  clear: function(dom_id) {
    with($(dom_id)) {
      while (hasChildNodes()) removeChild(lastChild);
      selectedIndex = 0;
    }
  },
  add: function(dom_id, text, value, selected) {
    var option = document.createElement('option');
    option.appendChild(document.createTextNode(text));
    option.setAttribute('value', value);
    if (selected) option.setAttribute('selected', '');
    $(dom_id).appendChild(option);
  },
  load: function(dom_id, options, selected) {
    if (options == null) return;
    options.each(function(item, index) {
      HtmlSelectOptions.add(dom_id, item[0], item[1], item[1] == selected);
    });
  }
}

