/*
	Coder: Marc Palau
	Date: 15/08/2006
	Mail: marc ( a ) palaueb * com
*/
Selector = function(padre,id,ancho,callback,opt){
	this.div = document.createElement("div");
	var div = this.div;
		div.style.position = "relative";
		div.style.width = ancho + "px";
		div.style.cssFloat = "left";
		div.style.styleFloat = "left";
		div.id = "selector-div-" + id;
	this.inp = document.createElement("input");
	var inp = this.inp;
		inp.style.zIndex = 2;
		inp.style.width = (ancho-18) + "px";
		inp.style.clip = "rect(0px "+ (ancho - 18) +"px 25px 0px)";
		inp.id = "selector-input-" + id;
		inp.name = id;
		inp.parent=this;
		inp.onkeyup=function(e){
			if(!e){var e=window.event;}
			if(e.keyCode==13){
				this.parent.setValor(this.value,this.value);
				this.parent.sel.value = this.value;
				this.parent.sel.$onchange(this.parent.sel);
			}
		}
	this.sel = document.createElement("select");
	var sel = this.sel;
		sel.style.zIndex = 1;
		sel.style.width = ancho + "px";
		sel.style.clip = "rect(0px " + ancho + "px 25px 82px)";
		sel.id = "selector-select-" + id;
		sel.parent=this;
		sel.onchange=function(){
			this.parent.inp.value=this.value;
			this.$onchange(this);
		}
		inp.style.position = sel.style.position = "absolute";
		inp.style.top = sel.style.top = 0;
		inp.style.left = sel.style.left = 0;
	
	if(typeof callback == "function"){
		sel.callback =callback;
		sel.$onchange=function(e){e.callback(e.value);}
	}

	try{
		for(var i=0;i<opt.length;i++){
			this.setValor(opt[i],opt[i]);
		}
	}catch(e){}
	
	div.appendChild(inp);
	div.appendChild(sel);
	document.getElementById(padre).appendChild(div);
};
Selector.prototype.setValor=function(label,value){
	this.sel.options[this.sel.options.length] = new Option(label,value);
}

