function WidgetSelectBox() {};

/*
* Returns a reference to the first object with the specified value of the ID attribute.
* If the attribute is already an object it will return the same object.
* 
* @param mixed sId Specifies the value of an ID attribute
* @return object A reference to the object
*/
WidgetSelectBox.getElement = function(sId) {
	var el = null;
	// If sId is an object we don't have to find the object, else we do 
	if (typeof sId == 'object') {
		el = sId;
	}else if (typeof sId == 'string') {
		el = document.getElementById(sId);
	}
	if (el && el.tagName.toUpperCase() == "SELECT") {
		return el;
	} else {
		return null;
	}
}

/*
* Retrieve the selected value of the selectbox
* 
* @param mixed sId Specifies the value of an ID attribute
* @return string The value of the selected option
*/
WidgetSelectBox.getValue = function(sId) {
	var el = WidgetSelectBox.getElement(sId);
	if (el) {
		return el.options[el.selectedIndex].value;
	} else {
		return false;
	}
}

/*
* Set the value of the selectbox. The option with this value will be selected
* 
* @param mixed sId Specifies the value of an ID attribute
* @param string sValue The new value of the selectbox
*/
WidgetSelectBox.setValue = function(sId, sValue) {
	var el = WidgetSelectBox.getElement(sId);
	if (el) {
		var options = el.options;
		var currentObj;
		for (var i = 0; i < options.length; i++) {
			var currentObj = options[i];
			if (currentObj.value == sValue) {
		  		currentObj.selected = true;
			}
		}
	}
}

/*
* Clear all options of the selectbox
* 
* @param mixed sId Specifies the value of an ID attribute
*/
WidgetSelectBox.clear = function(sId) {
	var el = WidgetSelectBox.getElement(sId);
	if (el) {
		var options = el.options;
		for (var i = options.length-1; i >= 0; i--) {
			options[i] = null;
		}
	}	
}

/*
* Add an option to the the selectbox. The option with this value will be selected
* 
* @param mixed sId Specifies the value of an ID attribute
* @param string sValue The value of the new option
* @param string sLabel The label of the new option
*/
WidgetSelectBox.addOption = function(sId, sValue, sLabel) {
	var el = WidgetSelectBox.getElement(sId);
	if (el) {
		el.options[el.options.length] = new Option(sLabel, sValue);
	}
}


