/**
 * @alias ComboBox.class
 * @author WilC <wilz04@gmail.com>
 * @since 2007.
 */

function ComboBox(element) {
	
	this.box = element;
	
	this.addItem = function (opt) {
		this.box.options[this.box.options.length] = opt;
	};
	
	this.getItemAt = function (index) {
		return this.box.options[index];
	};
	
	this.addItems = function (opts) {
		var index;
		for (index in opts) {
			this.box.options[this.box.options.length] = opts[index];
		}
	};
	
	this.setSelectedIndex = function (index) {
		this.box.selectedIndex = index;
	};
	
	this.setSelectedItem = function (item) {
		var length = this.getItemCount();
		for (var index=0; index<length; index++) {
			if (this.getItemAt(index).text == item) {
				this.setSelectedIndex(index);
				return true;
			}
		}
		return false;
	};
	
	this.setSelectedValue = function (val) {
		var length = this.getItemCount();
		for (var index=0; index<length; index++) {
			if (this.getItemAt(index).value == val) {
				this.setSelectedIndex(index);
				return true;
			}
		}
		return false;
	};
	
	this.getValue = function () {
		if (this.getItemCount() > 0) {
			return this.box.options[this.box.selectedIndex].value;
		}
		return null;
	};
	
	this.setFocus = function () {
		this.box.focus();
	};
	
	this.getItemCount = function () {
		return this.box.options.length;
	};
	
	this.removeAllItems = function () {
		for (var index=this.box.options.length-1; index>=0; index--) {
			this.box.options[index] = null;
		}
	};
	
	this.onChange = function (action) {
		this.box.onchange = action;
	};
	
}
