
/*
 *
 */
String.prototype.trim = function() {
	/* inizio modifica funzione originale */
	var A=/^[\s\xA0]+|[\s\xA0]+$/g;
	return this.replace(A,"")
	/* fine modifica funzione originale 
	 * la funzione originale invece prevedeva:
	 *
	 * var A=/^\s+|\s+$/g;
	 * return function() {
	 * 	return this.replace(A,"")
	 * }
	 *
	 * per cui eliminava da inizio e fine stringa solo gli spazi veri e non i caratteri del tipo &nbsp; 
	 */
};


Ext.override(Ext.form.ComboBox,
	{doQuery: function(C,B) {
		if (C===undefined || C===null) {
			C = "";
		}
		var A = {
			query: C,
			forceAll: B,
			combo: this,
			cancel: false
		};
		if (this.fireEvent("beforequery",A)===false || A.cancel) {
			return false;
		}
		C = A.query;
		B = A.forceAll;
		if (B===true || (C.length>=this.minChars)) {
			if (this.lastQuery!==C) {
				this.lastQuery = C;
				if (this.mode=="local") {
					this.selectedIndex = -1;
					if (B) {
						this.store.clearFilter();
					} else {
						/* inizio modifica funzione originale */
						this.anyMatch = (this.anyMatch===undefined) ? false : this.anyMatch;
						this.caseSensitive = (this.caseSensitive===undefined) ? false : this.caseSensitive;
						this.store.filter(this.displayField,C,this.anyMatch,this.caseSensitive);
						/* fine modifica funzione originale 
						 * la funzione originale invece prevedeva:
						 *
						 * this.store.filter(this.displayField,C)
						 *
						 * per cui non c'era modo di rendere la selezione case sensitive e di 
						 * permettere di selezionare in base ad un 'contains' anzichč uno 'startwith'
						 */
					}
					this.onLoad();
				} else {
					this.store.baseParams[this.queryParam] = C;
					this.store.load({params:this.getParams(C)});
					this.expand();
				}
			} else {
				this.selectedIndex = -1;
				this.onLoad();
			}
		}
	}
});


Ext.override(Ext.Layer,
	{hideAction: function() {
		this.visible = false;
		if (this.useDisplay===true) {
			this.setDisplayed(false);
		} else {
			/* inizio modifica funzione originale */
			this.setLeftTop(-200000,-200000);
			/* fine modifica funzione originale 
			 * la funzione originale invece prevedeva:
			 *
			 * this.setLeftTop(-10000,-10000)
			 *
			 * cosė facendo se la combobox originaria prevede centinaia di record 
			 * al primo click sulla combobox nuova la pagina del browser si allunga a dismisura
			 */
		}
	}
});

Ext.override(Ext.form.ComboBox,
	{initComponent: function() {
		Ext.form.ComboBox.superclass.initComponent.call(this);
		this.addEvents("expand","collapse","beforeselect","select","beforequery");
		if (this.transform) {
			this.allowDomMove = false;
			var C = Ext.getDom(this.transform);
			if (!this.hiddenName) {
				this.hiddenName = C.name;
			}
			if (!this.store) {
				this.mode = "local";
				var G=[], D = C.options;
				for (var B=0,A=D.length;B<A;B++) {
					var F = D[B];
					var E = (Ext.isIE ? F.getAttributeNode("value").specified : F.hasAttribute("value")) ? F.value : F.text;
					if (F.selected) {
						this.value = E;
					}
					G.push([E,F.text]);
				}
				this.store = new Ext.data.SimpleStore({"id":0,fields:["value","text"],data:G});
				this.valueField = "value";
				this.displayField = "text";
			}
			C.name = Ext.id();
			if (!this.lazyRender) {
				this.target = true;
				this.el = Ext.DomHelper.insertBefore(C,this.autoCreate||this.defaultAutoCreate);
				Ext.removeNode(C);
				this.render(this.el.parentNode);
			} else {
				Ext.removeNode(C);
			}
		} else {
			if (Ext.isArray(this.store)) {
				if (Ext.isArray(this.store[0])) {
					this.store = new Ext.data.SimpleStore({fields:["value","text"],data:this.store});
					this.valueField = "value";
				} else {
					this.store = new Ext.data.SimpleStore({fields:["text"],data:this.store,expandData:true});
					this.valueField = "text";
				}
				this.displayField = "text";
				this.mode = "local";
			}
		}
		this.selectedIndex = -1;
		if (this.mode=="local") {
			if (this.initialConfig.queryDelay===undefined) {
				this.queryDelay = 10;
			}
			if (this.initialConfig.minChars===undefined) {
				this.minChars = 0;
			}
		}
		/* inizio modifica funzione originale */
		this.noSpaceText = (this.noSpaceText===undefined) ? true : this.noSpaceText;
		if (this.editable===true && this.noSpaceText===true) {
			this.spaceTextValue = (this.spaceTextValue===undefined) ? "" : this.spaceTextValue;
			this.on("focus",
				function(combo) {
					if (combo.getRawValue().trim()=="") {
						combo.setRawValue("");
					}
					this.on("select",
						function(combo,record,index) {
							if (combo.getRawValue().trim()=="") {
								combo.setValue(this.spaceTextValue);
								combo.setRawValue("");
							}
						} 
					);
					this.on("blur",
						function(combo) {
							if (combo.getRawValue().trim()=="") {
								combo.setValue(this.spaceTextValue);
								combo.setRawValue("");
							}
						}
					);
				}
			);
		}
		/* fine modifica funzione originale 
		 * la funzione originale non prevedeva queste istruzioni.
		 * Cosė facendo se la combobox originaria ha una option con testo contente solo spazi e nbsp,
		 * nella combobox nuova, qualora sia editabile, appariono gli spazi che rendono errata la selezione dei campi. 
		 * In questo modo invece le option con testo contenente solo spazi e nbsp appaiono con il testo contenuto nel
		 * parametro di configurazione spaceTextValue (default=""). 
		 */
	}
});




