﻿//###############################################################################
//####     _ I N C L U D E  /  H T M L  P L U S _ C O M B O  B O X . J S     ####
//###############################################################################
//	%Application:	
//	%Module:		_Include
//	%Customer:		
//	%Attributes:	
//	28/05/2010	ver. 1.0.0.1	- [40] Corretto comportamento anomalo su alcune versioni di IE8: si interrompeva il download della pagina dopo
//				l'esecuzione di [_initialize]. La causa era che il drilldown veniva disegnato ed appeso a BODY, ma finchè BODY (o forse gli elementi
//				figlio) non è chiuso non è possibile aggiungere figli. Ho risolto il problema spostando la generazione del drilldown su neessità, e
//				spostando l'elemento drilldown da body a parentNode del textbox.
//	06/05/2010	ver. 1.0.0		- [40] Prima versione.



function HtmlPlus_ComboBox(ID, TextboxObject, DataSource, SearchFields, DisplayField, optHtmlTemplates, optInfoLabels, optClassName, optCssStyle) {
	/*Argomenti:
		IdObject :			valore ID dell'oggetto;
	*/
	this.id = ID;
	this.objectType = 'HtmlPlus_ComboBox';
	this.textboxObject = TextboxObject;			//riferimento al Textbox che mostrerà il valore e con cui si ricerca
	this.textboxValueObject = null;				//riferimento al Textbox che conterrà il valore selezionato (es. ID)
	this.dataSource = DataSource;
	this.searchFields = SearchFields;
	this.displayField = DisplayField;			//campo che riempirà il Textbox di visualizzazione
	this.valueField = null;						//campo che riempirà il Textbox di valore
	this.comboType = 'Proposal';				//può essere uno dei valori [HtmlPlus_ComboBox_ComboTypeEnum]
	this.searchType = 'Phrase';					//può essere uno dei valori [HtmlPlus_ComboBox_SearchTypeEnum]
	this.htmlTemplates = optHtmlTemplates;
	this.infoLabels = optInfoLabels;
	this.className = optClassName;
	this.cssStyle = optCssStyle;
	this.minItemsCount = 1;
	this.maxItemsCount = 16;
	this.positionatorObject = null;
	this._drilldown_aList = null;
	this._drilldown_aList_currItem = null;
	
	if (!window.HtmlPlus_ComboBoxColl) window.HtmlPlus_ComboBoxColl = new Array();
	window.HtmlPlus_ComboBoxColl[this.id] = this;
	
	this._initialize = function() {
		var str1;
		
		//Verifica valori di inizializzazione.
		if (ValueType(this.textboxObject) == 'string') this.textboxObject = findObj(this.textboxObject);
		if (ValueType(this.textboxValueObject) == 'string') this.textboxValueObject = findObj(this.textboxValueObject);
		if (!this.htmlTemplates) this.htmlTemplates = new Array();
		if (!this.infoLabels) this.infoLabels = new Array();
		
		//Setting variabili
		this._drilldown_aList = new Array();
		
		//Riempimento dei templates non dichiarati.
		str1 = 'body';		if (!this.htmlTemplates[str1]) this.htmlTemplates[str1] = '<div class="body">{content}</div>';
		str1 = 'info';		if (!this.htmlTemplates[str1]) this.htmlTemplates[str1] = '<div class="info">{info@text}</div>';
		str1 = 'list';		if (!this.htmlTemplates[str1]) this.htmlTemplates[str1] = '<ul class="list">{listItems}</ul>';
		str1 = 'listItem';	if (!this.htmlTemplates[str1]) this.htmlTemplates[str1] = '<li class="lstItm"><a class="item">{_item_}</a></li>';
		str1 = 'item';		if (!this.htmlTemplates[str1]) this.htmlTemplates[str1] = '{_string@text}';
		
		//Riempimento delle labels non dichiarate.
		str1 = 'noText';		if (!this.infoLabels[str1]) this.infoLabels[str1] = null;
		str1 = 'noItems';		if (!this.infoLabels[str1]) this.infoLabels[str1] = null;
		str1 = 'fewItems';		if (!this.infoLabels[str1]) this.infoLabels[str1] = null;
		str1 = 'tooMutchItems';	if (!this.infoLabels[str1]) this.infoLabels[str1] = null;
		str1 = 'foundItems';	if (!this.infoLabels[str1]) this.infoLabels[str1] = null;
		
		//Preparo l'oggetto TextBox
		this.textboxObject.autocomplete = 'off';
		this.textboxObject.ComboBoxObject = this;
		
		//Aggancio gli eventi agli oggetti HTML
		addEvent(this.textboxObject, 'keydown', this._textboxObject_onKeyDownHandler);
		addEvent(this.textboxObject, 'keyup', this._textboxObject_onKeyUpHandler);
		addEvent(this.textboxObject, 'focus', this._textboxObject_onFocusInHandler);
		//addEvent(this.textboxObject, 'focusout', this._textboxObject_onFocusOutHandler);
		addEvent(this.textboxObject, 'blur', this._textboxObject_onFocusOutHandler);
		
		this._tagDrilldownRoot = null;
		this._drawObject_initialize__appendJS = null;
		//this._drawObject_initialize();
	}
	this._drawObject_initialize = function() {
		var pars, cont1, vett1;
		if (!this._tagDrilldownRoot) {
			//Reset variabili riferimento oggetti HTML
			this._tagDrilldownRoot = null;
			this._tagDrilldown = null;
			this._tagDrilldownInfo = null;
			this._tagDrilldownList = null;
			this.positionatorObject = null;
			this._objServerEval = null;
			//Creazione oggetti HTML
			/**/ this._tagDrilldownRoot = document.createElement('div');
			this._tagDrilldownRoot.id = this.id;
			this._tagDrilldownRoot.className = 'B_ComboBox_Drilldown' + (this.className ? ' ' + this.className : '');
			this._tagDrilldownRoot.style.cssText = (this.cssStyle ? this.cssStyle : '');
			this._tagDrilldownRoot.style.display = 'none';
			this._tagDrilldownRoot.style.position = 'absolute';
			/**/ this._tagDrilldownRoot.innerHTML = this.htmlTemplates['body'];
			this._tagDrilldown = this._tagDrilldownRoot.childNodes[0];
			/**/ pars = {content : this.htmlTemplates['info'] + this.htmlTemplates['list']};
			this._tagDrilldown.innerHTML = ReplaceArgDict(this._tagDrilldown.innerHTML, pars);
			/**/ vett1 = this._tagDrilldown.getElementsByTagName('div');
			for (cont1 = 0; cont1 < vett1.length; cont1++) {
				if (ContainsClassName(vett1[cont1], 'info')) {
					this._tagDrilldownInfo = vett1[cont1];
					break;
				}
			}
			/**/ vett1 = this._tagDrilldown.getElementsByTagName('ul');
			for (cont1 = 0; cont1 < vett1.length; cont1++) {
				if (ContainsClassName(vett1[cont1], 'list')) {
					this._tagDrilldownList = vett1[cont1];
					break;
				}
			}
			this.textboxObject.parentNode.appendChild(this._tagDrilldownRoot);
			//Creo un riferimento fra gli oggetti HTML e THIS
			this._tagDrilldownRoot.ComboBoxObject = this;
			//Creo oggetti HtmlPlus addizionali
			this.positionatorObject = new HtmlPlus_Positionator(this.id + '__pos', this._tagDrilldownRoot, this.textboxObject, 'SE', {width:'100%'}, 'onetime');
			if (this._dataSourceType() == 'Eval') {
				this._objServerEval = new HtmlPlus_ServerEval(this.id + '__srv', this.dataSource['Server'], this.dataSource['Code']);
			}
			//Eseguo il codice JS aggiuntivo
			if (this._drawObject_initialize__appendJS) {
				eval(this._drawObject_initialize__appendJS);
			}
		}
	}
	this._dataSourceType = function(optDataSource) {
		//Restituisce il tipo di [DataSource] indicato, o se omesso il tipo di [this.dataSource]. I valori che può restituire sono:
		//		String:		il DataSource è un array di valori String;
		//		Dictionary:	il DataSource è un array di valori Dictionary;
		//		Eval:		il DataSource contiene la configurazione necessaria per generare un oggetto [HtmlPlus_ServerEval];
		//		-null-:		il valore DataSource non è in un formato valido.
		var cont1, str1, str2;
		var ds, fReturn;
		fReturn = null;
		ds = (optDataSource ? optDataSource : this.dataSource);
		switch (ValueType(ds)) {
			case 'Array':
				for (cont1 in ds) {
					if ((str2 = ValueType(ds[cont1])) != 'Function') {
						str1 = (cont1.toString() == '0' ? 'Array' : 'Dictionary');
						break;
					}
				}
				switch (str1) {
					case 'Array':
						switch (str2) {
							case 'string':	fReturn = 'String';	break;
							case 'Array':	fReturn = 'Dictionary';	break;
						}
						break;
					case 'Dictionary':
						fReturn = 'Eval';
						break;
				}
			case 'Object':
				if (ds['Server'] && ds['Code']) fReturn = 'Eval';
				break;
		}
		return fReturn;
	}
	
	/* Gestiori eventi degli oggetti HTML - inizio */
	
	this._textboxObject_onKeyDownHandler__cancelBubble = false;
	this._textboxObject_onKeyDownHandler = function(ev) {
		var eventObj = new STDEvent(ev);
		var objThis = eventObj.srcElement.ComboBoxObject;
		var indice, valValore;
		objThis._textboxObject_onKeyDownHandler__cancelBubble = false;
		if (!eventObj.altKey && !eventObj.ctrlKey && !eventObj.shiftKey) {
			switch (eventObj.keyCode) {
				case 38:	//freccia TOP
				case 40:	//freccia BOTTOM
					if (objThis._drilldown_aList.length > 0) {
						indice = objThis._drilldown_aList_currItem + (eventObj.keyCode==38 ? -1 : +1);
						if (indice < -1) indice = objThis._drilldown_aList.length - 1;
						if (indice >= objThis._drilldown_aList.length) indice = -1;
						objThis._drilldown_aListObject_lightCurrItem(indice);
						if (indice == -1) {
							valValore = null;
							if (objThis.textboxValueObject) valValore = objThis.textboxValueObject.value;
							objThis._drilldown_aListObject_setValue(objThis._runSearch__info.searchText, valValore, true);
						} else {
							objThis._drilldown_aListObject_getAndSetValues(indice, true);
						}
						objThis._textboxObject_onKeyDownHandler__cancelBubble = true;
					}
					break;
				case 27:	//tasto ESC
					objThis._hideDrilldown();
					objThis._textboxObject_onKeyDownHandler__cancelBubble = true;
					break;
				case 13:	//tasto ENTER
					break;
				default:
			}
		}
	}
	this._textboxObject_onKeyUpHandler__prevValue;
	this._textboxObject_onKeyUpHandler = function(ev) {
		var eventObj = new STDEvent(ev);
		var objThis = eventObj.srcElement.ComboBoxObject;
		if (!objThis._textboxObject_onKeyDownHandler__cancelBubble) {
			if (objThis._textboxObject_onKeyUpHandler__prevValue != objThis.textboxObject.value) {
				objThis._runSearch(objThis.textboxObject.value);
			}
		}
		objThis._textboxObject_onKeyUpHandler__prevValue = objThis.textboxObject.value;
	}
	this._textboxObject_onFocusInHandler = function(ev) {
		var eventObj = new STDEvent(ev);
		var objThis = eventObj.srcElement.ComboBoxObject;
		objThis._runSearch(objThis.textboxObject.value);
	}
	this._textboxObject_onFocusOutHandler = function(ev) {
		var eventObj = new STDEvent(ev);
		var objThis = eventObj.srcElement.ComboBoxObject;
		objThis._runSearch__info.state = 'end';
		objThis._hideDrilldown();
		objThis.OnBlur(objThis);
	}
	this._drilldown_aListObject_onMouseDownHandler = function(ev) {
		var eventObj = new STDEvent(ev);
		var srcElem, objThis;
		if (eventObj.srcElement.tagName == 'A' && ContainsClassName(eventObj.srcElement, 'item')) {
			srcElem = eventObj.srcElement;
			objThis = srcElem.ComboBoxInfo.object;
			objThis._drilldown_aListObject_getAndSetValues(srcElem.ComboBoxInfo.index, true);
		}
	}
	this._drilldown_aListObject_onMouseOverHandler = function(ev) {
		var eventObj = new STDEvent(ev);
		var srcElem, objThis;
		if (eventObj.srcElement.tagName == 'A' && ContainsClassName(eventObj.srcElement, 'item')) {
			srcElem = eventObj.srcElement;
			objThis = srcElem.ComboBoxInfo.object;
			objThis._drilldown_aListObject_lightCurrItem(srcElem.ComboBoxInfo.index);
		}
	}
	
	/* Gestiori eventi degli oggetti HTML - fine */
	
	this._drilldown_aListObject_lightCurrItem = function(NewCurrentItem) {
		if (this._drilldown_aList_currItem > -1) RemoveClassName(this._drilldown_aList[this._drilldown_aList_currItem], 'aMouHv');
		this._drilldown_aList_currItem = NewCurrentItem;
		if (this._drilldown_aList_currItem > -1) AddClassName(this._drilldown_aList[this._drilldown_aList_currItem], 'aMouHv');
	}
	this._drilldown_aListObject_getValue = function(AListIndex, FieldName) {
		var objA = this._drilldown_aList[AListIndex];
		var fReturn = null;
		if (objA) {
			switch (FieldName) {
				case '_index':		fReturn = objA.ComboBoxInfo.index; break;
				case '_position':	fReturn = objA.ComboBoxInfo.index + 1; break;
				case '_string':		fReturn = objA.ComboBoxInfo.item; break;
				default:			fReturn = objA.ComboBoxInfo.item[FieldName]; break;
			}
		}
		return fReturn;
	}
	this._drilldown_aListObject_setValue = function(ValDisplay, ValValue, IsDefinitive) {
		this.textboxObject.value = ValDisplay;
		if (IsDefinitive) {
			if (this.textboxValueObject) this.textboxValueObject.value = ValValue;
			this.OnChange(this, ValDisplay, ValValue);
		}
	}
	this._drilldown_aListObject_getAndSetValues = function(AListIndex, IsDefinitive) {
		var valDisplay, valValue;
		valDisplay = this._drilldown_aListObject_getValue(AListIndex, this.displayField);
		valValue = (IsNull(this.valueField) ? valDisplay : this._drilldown_aListObject_getValue(AListIndex, this.valueField));
		this._drilldown_aListObject_setValue(valDisplay, valValue, IsDefinitive);
	}
	
	this._runSearch__info = {state:'end', tmr:null, searchText:null, searchResult:null, allowShowResult:false, nextSearchText:null};
	this._runSearch = function(SearchText) {
		var WAIT_TIMEOUT = 350;
		switch (this._runSearch__info.state) {
			case 'wait':
				window.clearTimeout(this._runSearch__info.tmr);
				this._runSearch__info.searchText = SearchText;
				this._runSearch__info.tmr = window.setTimeout('window.HtmlPlus_ComboBoxColl[\'' + CStrJS(this.id) + '\']._runSearch_run();', WAIT_TIMEOUT);
				break;
			case 'run':
				this._runSearch__info.nextSearchText = SearchText;
				break;
			case 'end':
				//Costruisco gli oggetti HTML fissi
				this._drawObject_initialize();
				//Esamino la nuova ricerca
				if (this._runSearch__info.searchText == SearchText) {
					this._showResult();
				} else {
					this._runSearch__info.searchText = SearchText;
					this._runSearch__info.searchResult = null;
					this._runSearch__info.allowShowResult = false;
					this._runSearch__info.tmr = window.setTimeout('window.HtmlPlus_ComboBoxColl[\'' + CStrJS(this.id) + '\']._runSearch_run();', WAIT_TIMEOUT);
					this._runSearch__info.state = 'wait';
				}
				break;
		}
	}
	this._runSearch_run = function() {
		this._runSearch__info.state = 'run';
		if (this._runSearch__info.searchText == '') {
			this._runSearch_buildResult(null);
		} else {
			this._runSearch_findItems(this._runSearch__info.searchText);
		}
	}
	this._runSearch_findItems = function(SearchText) {
		var item, parole, reList, trovateMancanti, fncCerca;
		var cont1, cont2, obj1;
		var pars, fReturn;
		if (this._dataSourceType() == 'Eval') {
			//Lancio ServerEval per eseguire la ricerca sul server
			this._objServerEval.OnEnd = this._runSearch_findItems__eval_onEnd;
			pars = new Array();
			pars['id'] = this.id;
			pars['Text'] = SearchText;
			pars['SearchFields'] = this.searchFields;
			pars['MaxItemsCount'] = this.maxItemsCount;
			this._objServerEval.Run(pars, this.dataSource['Debug']);
		} else {
			//Eseguo la ricerca localmente
			fReturn = new Array();
			//Preparo reList con le regole per le ricerche
			switch (this.searchType) {
				case 'OneWord':
				case 'AllWords':
					parole = SearchText.split(' ');
					break;
				case 'Phrase':
					parole = [SearchText];
					break;
			}
			reList = new Array();		//Dictionary con la lista di regole. La key sarà formata così: "p<Parola.index>f<SearchField.index>"
			for (cont1 = 0; cont1 < parole.length; cont1++) {
				for (cont2 = 0; cont2 < SearchFields.length; cont2++) {
					switch (SearchFields[cont2]['Method']) {
						case 'Equal':		obj1 = new RegExp('^' + CStrRE(parole[cont1]) + '$', 'i'); break;
						case 'BeginPhrase':	obj1 = new RegExp('^' + CStrRE(parole[cont1]) + '', 'i'); break;
						case 'EndPhrase':	obj1 = new RegExp('' + CStrRE(parole[cont1]) + '$', 'i'); break;
						case 'Word':		obj1 = new RegExp('\\b' + CStrRE(parole[cont1]) + '\\b', 'i'); break;
						case 'BeginWord':	obj1 = new RegExp('\\b' + CStrRE(parole[cont1]) + '', 'i'); break;
						case 'EndWord':		obj1 = new RegExp('' + CStrRE(parole[cont1]) + '\\b', 'i'); break;
						default:			obj1 = null;
					}
					if (obj1) reList['p' + cont1.toString() + 'f' + cont2.toString()] = obj1;
				}
			}
			//Eseguo le ricerche, riempiendo [fReturn]
			fncCerca = function(ObjThis, ReList, IndexParola, Item) {
						var cont1, re, regola, fReturn;
						fReturn = false;
						for (cont1 = 0; cont1 < ObjThis.searchFields.length; cont1++) {
							re = ReList['p' + IndexParola.toString() + 'f' + cont1.toString()];
							regola = ObjThis.searchFields[cont1];
							switch (regola['FieldName']) {
								case '_string':		fReturn = re.test(Item);	break;
								default:			fReturn = re.test(Item[regola['FieldName']]);	break;
							}
							if (fReturn) break;
						}
						return fReturn;
					}
			for (cont1 = 0; cont1 < this.dataSource.length; cont1++) {
				item = this.dataSource[cont1];
				trovateMancanti = parole.length;
				for (cont2 = 0; cont2 < parole.length; cont2++) {
					if (fncCerca(this, reList, cont2, item)) {
						if (this.searchType == 'OneWord') {
							trovateMancanti = 0;
							break;
						} else {
							trovateMancanti -= 1;
						}
					}
				}
				if (trovateMancanti == 0) {
					fReturn.push(item);
					if (fReturn.length > this.maxItemsCount) break;
				}
			}
			this._runSearch_buildResult(fReturn);
		}
	}
	this._runSearch_findItems__eval_onEnd = function(ServerEval, ReturnValue, IsAbort) {
		var objThis;
		objThis = window.HtmlPlus_ComboBoxColl[ServerEval._parameters['id']];
		if (IsAbort) {
			objThis._runSearch_end();
		} else {
			if (!ReturnValue) ReturnValue = new Array();
			objThis._runSearch_buildResult(ReturnValue);
		}
	}
	this._runSearch_buildResult = function(ItemsColl) {
		var cont1, cont2, str1, str2, str3, vett1, vett2;
		var pars, item, indice, listaPars, strHtml;
		//Eseguo un backup dell'attributo 'display' di INFO e LIST
		if (!this._tagDrilldownInfo.Bck_StyleDisplay) this._tagDrilldownInfo.Bck_StyleDisplay = GetCssStyle(this._tagDrilldownInfo, 'display');
		if (!this._tagDrilldownList.Bck_StyleDisplay) this._tagDrilldownList.Bck_StyleDisplay = GetCssStyle(this._tagDrilldownList, 'display');
		//Rimuovo gli Handler degli item presenti in lista
		while (this._drilldown_aList.length > 0) {
			item = this._drilldown_aList.pop();		//il comando POP rimuove l'ultimo item dall'array e lo restituisce
			removeEvent(item, 'mousedown', this._drilldown_aListObject_onMouseDownHandler);
			removeEvent(item, 'mouseover', this._drilldown_aListObject_onMouseOverHandler);
			//removeEvent(item, 'mouseout', this._drilldown_aListObject_onMouseOutHandler);
		};
		//Verifico se è stata inserita una stringa di testo
		if (IsNull(this._runSearch__info.searchResult)) {
			if (this._runSearch__info.searchText == '') {
				this._runSearch__info.searchResult = 'noText';
			}
		}
		//Verifico se ho zero elementi
		if (IsNull(this._runSearch__info.searchResult)) {
			if (ItemsColl.length == 0) {
				this._runSearch__info.searchResult = 'noItems';
			}
		}
		//Verifico se ho pochi elementi
		if (IsNull(this._runSearch__info.searchResult)) {
			if (ItemsColl.length < this.minItemsCount) {
				this._runSearch__info.searchResult = 'fewItems';
			}
		}
		//Verifico se ho troppi elementi
		if (IsNull(this._runSearch__info.searchResult)) {
			if (ItemsColl.length > this.maxItemsCount) {
				this._runSearch__info.searchResult = 'tooMutchItems';
			}
		}
		//Non ho riscontrato errori, rappresento i dati
		if (IsNull(this._runSearch__info.searchResult)) {
			this._runSearch__info.searchResult = 'foundItems';
			//Ottengo la lista dei parametri richiesti dal template "listItem" e "item"; li metto in [listaPars].
			listaPars = new Array();
			ReplaceArgDict(this.htmlTemplates['item'], {}, listaPars);
			ReplaceArgDict(this.htmlTemplates['listItem'], {}, listaPars);
			//Costruisco la lista
			strHtml = '';
			pars = new Array();
			for (cont1 = 0; cont1 < ItemsColl.length; cont1++) {
				item = ItemsColl[cont1];
				for (cont2 = 0; cont2 < listaPars.length; cont2++) {
					str1 = listaPars[cont2];
					switch (str1.substr(str1.length - 5)) {
						case '@html': case '@text':		str2 = str1.substr(0, str1.length - 5); break;
						default:						str2 = str1; break;
					}
					switch (str2) {
						case '_index':		str3 = cont1; break;
						case '_position':	str3 = cont1 + 1; break;
						case '_string':		str3 = item; break;
						case '_itemsCount':	str3 = ItemsColl.length; break;
						default:			str3 = item[str1]; break;
					}
					if (str1.substr(str1.length - 5) != '@html') str3 = CStrHTML('' + str3);
					pars[str1] = str3;
				}
				str1 = ReplaceArgDict(this.htmlTemplates['item'], pars);
				pars['_item_'] = str1;
				str1 = ReplaceArgDict(this.htmlTemplates['listItem'], pars);
				strHtml += str1;
			}
			this._tagDrilldownList.innerHTML = strHtml;
			//Aggiungo gli Handler agli anchor degli item
			this._drilldown_aList_currItem = -1;
			vett1 = this._tagDrilldownList.getElementsByTagName('li');
			indice = -1;
			for (cont1 = 0; cont1 < vett1.length; cont1++) {
				if (ContainsClassName(vett1[cont1], 'lstItm')) {
					indice++;
					vett2 = vett1[cont1].getElementsByTagName('a');
					for (cont2 = 0; cont2 < vett2.length; cont2++) {
						if (ContainsClassName(vett2[cont2], 'item')) {
							this._drilldown_aList.push(vett2[cont2]);
							vett2[cont2].ComboBoxInfo = {object:this, index:indice, item:ItemsColl[indice]};
							addEvent(vett2[cont2], 'mousedown', this._drilldown_aListObject_onMouseDownHandler);
							addEvent(vett2[cont2], 'mouseover', this._drilldown_aListObject_onMouseOverHandler);
							//addEvent(vett2[cont2], 'mouseout', this._drilldown_aListObject_onMouseOutHandler);
						}
					}
				}
			}
		}
		//Configuro la grafica
		if (this.infoLabels[this._runSearch__info.searchResult]) {
			pars = new Array();
			//Compilazione parametri per testo INFO
			pars['itemsCount@html'] = (ItemsColl ? ItemsColl.length : 0);
			pars['itemsCount@text'] = CStrHTML('' + pars['itemsCount@html']);
			pars['itemsCount'] = pars['itemsCount@text'];
			//Compilazione parametri per template HTML
			pars['info@html'] = ReplaceArgDict(this.infoLabels[this._runSearch__info.searchResult], pars);
			pars['info@text'] = CStrHTML('' + pars['info@html']);
			pars['info'] = pars['info@text'];
			this._tagDrilldownInfo.innerHTML = ReplaceArgDict(this.htmlTemplates['info'], pars);
			this._tagDrilldownInfo.style.display = this._tagDrilldownInfo.Bck_StyleDisplay;
		} else {
			this._tagDrilldownInfo.style.display = 'none';
		}
		if (this._runSearch__info.searchResult == 'foundItems') {
			//Formatto gli elementi HTML
			this._tagDrilldownList.style.display = this._tagDrilldownList.Bck_StyleDisplay;
		} else {
			this._tagDrilldownList.style.display = 'none';
		}
		this._runSearch__info.allowShowResult = (this._tagDrilldownInfo.style.display != 'none' || this._tagDrilldownList.style.display != 'none' ? true : false);
		
		if (this._runSearch__info.state != 'end') this._showResult();	//nota: lo stato potrebbe essere END se è stato fatto FocusOut prima della determinazione della nuova ItemsColl
		this._runSearch_end();
	}
	this._runSearch_end = function() {
		var str1;
		if (this._runSearch__info.state != 'end') {
			this._runSearch__info.state = 'end';
			if (IsNull(this._runSearch__info.nextSearchText) == false) {
				str1 = this._runSearch__info.nextSearchText;
				this._runSearch__info.nextSearchText = null;
				this._runSearch(str1);
			}
		} else {
			this._runSearch__info.nextSearchText = null;
		}
	}
	
	this._showResult = function() {
		if (this._runSearch__info.allowShowResult) {
			this._showDrilldown();
		} else {
			this._hideDrilldown();
		}
	}
	
	/* Le procedure qui sotto mostrano e nascondono il DrillDown senza eseguire alcuna valutazione dei dati */
	this._showDrilldown = function() {
		if (this._tagDrilldownRoot.style.display != 'block') {
			this._tagDrilldownRoot.style.display = 'block';
			this.positionatorObject.Run();
		}
	}
	this._hideDrilldown = function() {
		if (this._tagDrilldownRoot.style.display != 'none') {
			this.positionatorObject.Stop();
			this._tagDrilldownRoot.style.display = 'none';
		}
	}
	
	this.OnChange = function(ComboBox, DisplayText, ValueText) {return void(0);}
	this.OnBlur = function(ComboBox) {return void(0);}
	
	this._initialize();
	return this;
}