/**
 * @author pfigueiredo
 */
KSelect.prototype = new KInput;
KSelect.prototype.constructor = KSelect;
function KSelect(parent, id) {
	KInput.call(this, parent, id, 'select');
	this.isMultiple = false;
	this.panel.className += ' KSelectPanel';
}

KSelect.prototype.onData = function() {
	for (i = 0; i != this.data.option.length; i++) {
		this.addValue(this.data.option[i].value, this.data.option[i].label, false);
	}
}

KSelect.prototype.setMultiple = function(isMultiple) {
	if (isMultiple) {
		this.input.setAttribute('multiple', 'multiple');
	}
	else {
		if (this.input.getAttribute('multiple') == 'multiple') {
			this.input.removeAttribute('multiple');
		}
	}
	this.isMultiple = isMultiple;
}

KSelect.prototype.getValue = function() {
	if (this.isMultiple) {
		var toReturn = new Array();
		for (var i  = 0; i != this.input.options.length; i++) {
			if (this.input.options[i].selected) {
				toReturn.push(this.input.options[i].value);
			}
		}
		return toReturn;
	}
	return this.input.options[this.input.selectedIndex].value;
}

KSelect.prototype.addValue = function(value, text, selected) {
	var newOption = document.createElement('option');
	newOption.value = value;
	newOption.selected = selected;
	newOption.text = text;
	this.input.appendChild(newOption);
}
