
var _CComboBox_Array = new Array();
 
function _CComboBox_onLoad() {
	var i, cbo;
	for (i=0;i<_CComboBox_Array.length;i++) { 
		cbo = _CComboBox_Array[i];
		//cbo.elementName =  _CComboBox_Names[i];
		eval('_' + cbo + '.initialize()');
	};
};
_window_onLoad[_window_onLoad.length] = _CComboBox_onLoad;

//Crea un oggetto ComboBox sostituendo l'oggetto SELECT con una TextBox, un pulsante per
//il DropDown ed una lista DropDown
function CComboBox(elementName) {
	this.elementName = elementName;
	if (_riseWindowInited == true) this.initialize();
	else _CComboBox_Array[_CComboBox_Array.length] = elementName;
};

CComboBox.prototype.initialize = function() {
	this.dropDownWidth = 200;
	this.dropDownHeight = 250;
	 
	
	//Recupera l'elenco
	this.dropDownList = document.getElementById(this.elementName);
	
	
	this.width = getElementWidth(this.dropDownList);
	
	//Recupera il contenitore dell'elenco
	this.parentNode = this.dropDownList.parentNode;
	
	//Contenitore per TextBox ed immagine
	this.container = document.createElement('div');
	this.container.style.width = this.width + 'px';
	this.container.style.height = getElementHeight(this.dropDownList) + 'px';
	this.container.style.overflow = 'hidden';
	this.container.style.position = 'relative';
	
	//Prepara la TextBox
	this.textBox = document.createElement('input');
	this.textBox.type = 'text';
	this.textBox.setAttribute(attributeClass, "textfield");
	this.textBox.style.width = this.width + 'px';
	this.textBox.style.height = getElementHeight(this.dropDownList) + 'px';
	this.textBox.style.top = '0';
	this.textBox.style.left = '0';
	this.textBox.style.height = '20px';
	this.textBox.style.position = 'absolute';
	this.textBox.style.borderRight.width = '0';
	
	this.dropDownList.name = 'list_' + this.elementName;
	this.dropDownList.id = 'list_' + this.elementName;
	
	this.textBox.name = this.elementName;
	this.textBox.id = this.elementName;
	
	this.container.appendChild(this.textBox);
	
	//Prepara il pulsante	 
	this.btnDropDown = document.createElement('img');
	this.btnDropDown.src = '/widgets/ComboBox/img/btnDropDown.gif'; //_ComboBox_btnDropDown.src;
	this.btnDropDown.border = '0';
	this.btnDropDown.style.position = 'absolute';
	this.btnDropDown.style.width = '18px';
	this.btnDropDown.style.height = '20px';
	this.btnDropDown.style.top = '0';
	this.btnDropDown.style.left = (this.width - 18) + 'px';
	this.btnDropDown.align='top';
	this.btnDropDown.style.backgroundColor = 'red';	
	this.btnDropDown.name = 'btn_' + this.textBox.name;
	this.btnDropDown.id = this.btnDropDown.name;
	this.btnDropDown.onclick = function() {
		var elemName = this.name.substring(4);
		var elem = document.getElementById(elemName);
		var x = getElementAbsX(elem);
		var y = getElementAbsY(elem);
		var h = getElementHeight(elem);
		var list = document.getElementById('win_' + elemName);
		list.style.top = (y + h+1)+'px';
		list.style.left = x + 'px';
		list.style.display = '';
		list.style.zorder = 10000;
		list.firstChild.focus();
	};
	this.btnDropDown.onmouseover = function() { this.src = '/widgets/ComboBox/img/btnDropDownH.gif'; };
	this.btnDropDown.onmouseout = function() { this.src = '/widgets/ComboBox/img/btnDropDown.gif'; };
	this.btnDropDown.onmousedown = function() { this.src = '/widgets/ComboBox/img/btnDropDownD.gif'; };
	this.btnDropDown.onmouseup = function() { this.src = '/widgets/ComboBox/img/btnDropDown.gif'; };
	
	this.container.appendChild(this.btnDropDown);
		
	this.parentNode.replaceChild(this.container, this.dropDownList);
	
	this.dropDownWindow = document.createElement('div');
	this.dropDownWindow.name = 'win_' + this.elementName;
 	this.dropDownWindow.id = 'win_' + this.elementName;
 	this.dropDownWindow.style.display = 'none';
	this.dropDownWindow.style.position='absolute';
	this.dropDownWindow.style.border = 'solid 0px #c0c0c0';
 	this.dropDownWindow.style.padding = '0';
 	this.dropDownWindow.style.margin = '0';
 	this.dropDownWindow.style.backgroundColor = '#ffffff';
 	this.dropDownWindow.style.fontFamily = 'tahoma,arial,verdana';
 	this.dropDownWindow.style.fontSize = '10pt';
 	
 	
 	this.dropDownWindow.appendChild(this.dropDownList);
 	this.dropDownList.size = 10;
 	this.dropDownList.style.width = this.dropDownWidth;
	this.dropDownList.style.height = this.dropDownHeight;
	this.dropDownList.onblur = function() { this.parentNode.style.display = 'none'; };
	this.dropDownList.onchange = function() {
		var elemName = this.name.substring(5);
		var elem = document.getElementById(elemName);
		elem.value = this.options[this.selectedIndex].text;
		this.blur();
	};
 	
 	/*
	var i;
	this.uList = document.createElement('ul');
	this.uList.style.padding = '0';
	this.uList.style.margin = '0';
	this.uList.style.marginLeft = '5px';
	
	this.dropDownWindow.appendChild(this.uList);
	
	for(i=0;i<this.dropDownList.options.length;i++) {
		var item = document.createElement('li');
		item.innerHTML = this.dropDownList.options[i].text;
		this.uList.appendChild(item);	
	};
	*/
	
	document.body.appendChild(this.dropDownWindow);
	var val =this.dropDownList.getAttribute("value");
	if (val!=null) this.textBox.value = val;
};


