/**
 * $Id: select.js,v 1.2 2004/12/17 08:48:32 scr34m Exp $
 */
function removeAllOptions(from) { 
  l = from.options.length - 1;
  for ( i=l; i>=0; i--) { 
    from.options[i] = null; 
  } 

  from.selectedIndex = -1; 
} 

function removeSelectedOptions(from) { 
  l = from.options.length - 1;

  for ( i=l; i>=0; i--) { 
		o = from.options[i]; 
		if (o.selected) { 
			from.options[i] = null; 
    } 
  } 
  from.selectedIndex = -1; 
} 

function unSelectOptions(obj, regex, tov) {
	selectUnselect(obj, regex, false, tov);
}

function selectOptions(obj, regex, tov) {
	selectUnselect(obj, regex, true, tov);
}

function selectUnselect(obj, regex, select, tov) {
	if (window.RegExp) {
		
		var re = new RegExp(regex);
		for (var i=0; i<obj.options.length; i++) {

      if ( tov == true) {
          text = obj.options[i].text;
      } else {
          text = obj.options[i].value;
      }

      if ( re.test(text) ) {
				obj.options[i].selected = select;
			}

		}
  }
}

function selectAllOptions(obj) {
  for (var i=0; i<obj.options.length; i++) {
    obj.options[i].selected = true;
  }
}

function addOption(to, text, value) {
  to.options[ to.options.length ] = new Option( text, value, false, false);
}