function AutoCompleteSelect(select){
	this.object = select;
	this.convertor = new AutoCompleteSelectConvertor();
	this.visible = false;
	var _this = this;
	EventFactory.create('click', function(e){_this.onchange(e)}, this.object, true);
}
AutoCompleteSelect.prototype = {
	onchange: function(){},
	display: function(display){
		this.visible = display;
		this.object.style.display = (display ? 'block' : 'none');
		if (!display){
			this.object.innerHTML = '';
		}else{
			this.object.size = Math.min(Math.max(this.object.childNodes.length, 3), 10);
			this._changeSelected(0);
		}
	},
	fill: function(items){
		clearNode(this.object);
		if (!items){
			return;
		}
		var div = document.createElement('div');
		div.innerHTML = '<select>' + this.convertor.convert(items) + '</select>';
		while(div.firstChild.lastChild){
			this.object.insertBefore(div.firstChild.lastChild, this.object.firstChild);
		}
	},
	getSelected: function(){
		return this.object.selectedIndex >= 0 ? this.object.childNodes.item(this.object.selectedIndex) : null;
	},
	getSelectedText: function(){
		return this.getSelected() ? this.getSelected().firstChild.nodeValue : '';
	},
	getSelectedValue: function(){
		return this.getSelected() ? this.getSelected().value : null;
	},
	moveUp: function(){
		if (this.object.selectedIndex <= 0){
			return false;
		}
		this._changeSelected(this.object.selectedIndex - 1);
		return true;
	},
	moveDown: function(){
		if ((this.object.childNodes.length - 1) <= this.object.selectedIndex){
			return false;
		}
		this._changeSelected(this.object.selectedIndex + 1);
		return true;
	},
	_changeSelected: function(newItem){
		try{
			this.object.childNodes.item(newItem).selected = true;
		}catch(e){}
	},
	onClick: function(e){
		this.onchange(e);
	}
}
function AutoCompleteSelectConvertor(){}
AutoCompleteSelectConvertor.prototype = {
	convert: function(string){
		string = string.replace(/ p=\"[^\"]*\"/ig, '');
		string = string.replace(
			/<o v=\"([^\"]*)\"[^<]*>([^<]*)<\/o>/ig,
			'<option value="$1">$2</option>'
		);
		return string;
	}
}
