<!-- ---------------------------------------------------------------- 
// $Id: ListChooser.js,v 1.6 1999/02/19 22:28:20 willa Exp $
//
// File:    ListChooser.js 
// Auther:  Willa Zhu,  PMEL/NOAA
// Date:    Jan 26, 1999 (Created) 
// 
// The listChooser object handles SELECTION OPTION LIST.
// Note: this version doesn' allow multiple selection.
//
// Argument: 
//    list:     The list object.
// Methods: 
//    reset()
// 		reset the list to be the initial default selected mode.
//    updateListValue(index,value)
//       	update the value of item at index of the list 
//    updateListText(index,text)
//       	update the text of item at index of the list 
//    getValue() 
//       	return the value of selected item from the list
//    getText()  
//       	return the text of selected item from the list
//    getIndex()
//		return index of selected item
//    setIndex(index)
//		set item at given index to be selected
//    listLength(index)
//		return the length of a list 
//    addItem(list,text,value,defaultSelected,selected)
// 		add a list element to the end of the list
//  
//-------------------------------------------------------------------
//
// resetSelected method for ListChooser object
// 		reset the list to be the initial default selected mode.
//
function reset() {
  for (var i=0; i < this.list.options.length; i++) {
    this.list.options[i].selected = this.list.options[i].defaultSelected;
  }
}

// getSelectedValue method for the ListChooser object.
//       	get value of selected item 
//
function getValue() {
  return(this.list.options[this.list.selectedIndex].value);
}

// getSelectedText method for the ListChooser object.
//       	get text of selected item 
//
function getText() {
  return(this.list.options[this.list.selectedIndex].text);
}

// getSelectedIndex method for the ListChooser object.
//       	get index of selected item 
//
function getSelectedIndex() {
  return(this.list.selectedIndex);
}

// setSelectedIndex method for the ListChooser object.
//       	set selected item by index
//
function setSelectedIndex(index) {
  this.list.options[index].selected=true;
  return;
}

// getListlength method for the ListChooser object.
//       	get length of the list
//
function getListLength() {
  return(this.list.options.length);
}

// updateListValue method for the ListChooser object.
//       	update the value of item at index of the list 
//
function updateListValue(index,value) {
  this.list.options[index].value = value;
}

// updateListText method for the ListChooser object.
//       	update the text of item at index of the list 
//
function updateListText(index,text) {
  this.list.options[index].text = text;
}

// addListItem method for the ListChooser object
// 		add a list element to the end of the list
//
function addItem(text,value,defaultSelected,selected) {
  this.list.options[this.list.length] =
       new Option(text, value, defaultSelected,selected);
}

// ListChooser Object Constructor
//
function ListChooser(list) {
  // properties
  if(list)
    this.list=list;
  else
    alert("Invalid List (Select Object) name. Please check you HTML file.");

  // this version will always set multiple=false
  this.multiple = false;

  // methods
  this.getText = getText;
  this.getValue = getValue;
  this.addItem = addItem;
  this.getIndex = getSelectedIndex;
  this.setIndex = setSelectedIndex;
  this.listLength = getListLength;
  this.reset = reset;
}

// -->
