/*
 * libreria di controlli video
 */

////////////////////////////////////////////////////////////////////////////////////////////////////
// classe base: contiene eventuali proprietà e metodi comuni

function Ctl()
	{
	this.objFather = null; // puntatore all'eventuale contenitore del controllo
	this.validate = function ()
		{
		return {ok:true};
		}
	this.focus = function ()
		{
		if(this.objFather != null) this.objFather.focus();
		}
	this.create = function ()
		{
		var objDOM = this.createDOM();
		objBody_.appendChild(objDOM);
		}
	this.posDOM = function (objDOM, iLeft, iTop, iWidth, iHeight, iZIndex, strPosition) // imposta il posizionamento per l'oggetto DOM
		{
		if(iWidth != undefined) objDOM.style.width = String(iWidth) + "px";
		if(iHeight != undefined) objDOM.style.height = String(iHeight) + "px";
		if(iZIndex != undefined) objDOM.style.zIndex = String(iZIndex);
		
		if(iLeft == undefined && iTop == undefined) return;
		
		objDOM.style.position = dVal(strPosition, "absolute"); // default: "absolute"
		if(iLeft != undefined) objDOM.style.left = String(iLeft) + "px";
		if(iTop != undefined) objDOM.style.top = String(iTop) + "px";
		}
	}

Ctl.objRadCnt = {}; // contatori dei radio buttons

Ctl.row = function (iRow) // coordinata top per i controlli sulla riga n-esima
	{
	return (iRow - 1) * 21;
	}

Ctl.height = function (iRows) // altezza di un controllo con n righe
	{
	return iRows * 21 - 1;
	}

////////////////////////////////////////////////////////////////////////////////////////////////////
// Window è il contenitore principale, con intestazione, loghi, menù;
// _objMain è l'area di lavoro, in cui vivono le pagine "operative"

Ctl.Window = function (objMenu, bShowFooter)
	{
	this.objMenu = dVal(objMenu, null);
	
	var _objMain = null;
	var _strUrl = "";
	var _strMsg = "";
	var _objDOM = null;
	var _objDOMMsg = null;
	var _objDOMLt = null;
	var _objDOMRt = null;
	
	bShowFooter = dVal(bShowFooter, false);
	
	this.loadPage = function (strUrl) // carica una pagina nella mainarea
		{
		_strUrl = strUrl;
		if(_objMain != null)
			_objMain.src = _strUrl;
		}
	
	this.message = function (strMsg) // scrive un messaggio
		{
		_strMsg = strMsg;
		if(_objDOMMsg != null)
			{
			dropDOMChildren(_objDOMMsg);
			_objDOMMsg.appendChild(newTx(_strMsg));
			}
		}
	
	this.createDOM = function () // crea gli oggetti DOM
		{
		var objDOMHead;
		var objDOMMenu;
		var objDOM2;
		var objDOM3;
		var objDOM4;
		
		// contenitore colonna centrale
		
		_objDOM = newEl("div", "id", "container");
		
		_objDOMLt = newEl("div", "id", "contleft");
		_objDOM.appendChild(_objDOMLt);
		
		_objDOMRt = newEl("div", "id", "contright");
		_objDOM.appendChild(_objDOMRt);
		
		// header
		
		objDOMHead = newEl("div", "id", "header");
		
			objDOM2 = newEl("div", "style.position", "absolute", "style.left", "0", "style.top", "0", "style.width", "320px", "style.height", "96px");
			objDOM3 = newEl("a", "href", "./restart.asp");
			objDOM4 = newEl("img", "src", strBaseUrl_ + "/alphaimg.asp?img=logo", "style.width", "340px", "style.height", "74px", "style.border", "none");
			objDOM3.appendChild(objDOM4);
			objDOM2.appendChild(objDOM3);
			objDOMHead.appendChild(objDOM2);
			
			_objDOMMsg = newEl("div", "id", "message");
			if(_strMsg != "") _objDOMMsg.appendChild(newTx(_strMsg));
			objDOMHead.appendChild(_objDOMMsg);
		
		_objDOM.appendChild(objDOMHead);
		
		// menu
		/*
		objDOMMenu = newEl("div", "id", "menubar");
		_objDOM.appendChild(objDOMMenu);
		if(this.objMenu != null)
			objDOMMenu.appendChild(this.objMenu.createDOM());
		*/
		// main
		
		_objMain = newEl("iframe", "id", "mainarea", "style.height", "0", "scrolling", "auto", "frameBorder", "0", "marginWidth", "0", "marginHeight", "0", "src", _strUrl);
		_autoHeight();
		_objDOM.appendChild(_objMain);
		
		// footer
		
		if(bShowFooter)
			{
			objDOM2 = newEl("div", "id", "footer");
			objDOM2.innerHTML =
				"<b>Ergon Informatica Srl</b> - via Circonvallazione Est, 32/N - 31033 Castelfranco Veneto TV - tel.: 0423 4247 - fax: 0423 424880 - P.IVA: 02229190265 - mail: <a href=\"mailto:dirmkt@ergon.it\" class=\"lnkmail\">dirmkt@ergon.it</a>";
			_objDOM.appendChild(objDOM2);
			}
		
		// eventi interni
		
		addEvent(window, "resize", _autoHeight);
		
		
		
		//objDOM2 = newEl("div", "style.width", "100%", "style.height", "100%", "style.background", "url(img/bgsha.png) repeat-y top center");
		//objDOM2.appendChild(_objDOM);
		//_objDOM = objDOM2;
		
		
		return _objDOM;
		}
	
	// sistema l'altezza della mainarea in funzione della window
	
	function _autoHeight()
		{
		var iHeight = clientHeight();
		if(iHeight == null)
			return;
		iHeight -= 96; // 96 è l'altezza dell'header
		if(bShowFooter)
			iHeight -= 18; // 18 è l'altezza del footer
		if(iHeight < 0)
			iHeight = 0;
		_objMain.style.height = String(iHeight) + "px";
		_objDOMLt.style.height = String(iHeight + 18) + "px";
		_objDOMRt.style.height = String(iHeight + 18) + "px";
		}
	}
Ctl.Window.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// contenitore di controlli posizionati

Ctl.Canvas = function ()
	{
	var _objC = []; // elenco dei controlli e loro posizioni
	var _objDOM = null;
	
	this.addControl = function (objCtl, iLeft, iTop)
		{
		objCtl.objFather = this;
		_objC.push({ctrl:objCtl, left:iLeft, top:iTop});
		}
	
	this.validate = function ()
		{
		var iIdx;
		var objVal;
		for(iIdx = 0; iIdx < _objC.length; iIdx++)
			if(!(objVal = _objC[iIdx].ctrl.validate()).ok) return objVal;
		return {ok:true};
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		var iIdx;
		var objC;
		var objDOM2;
		
		iLeft = dVal(iLeft, 0);
		iTop = dVal(iTop, 0);
		
		_objDOM = document.createDocumentFragment(); // il canvas non produce nessun elemento DOM reale
		
		for(iIdx = 0; iIdx < _objC.length; iIdx++)
			{
			objC = _objC[iIdx];
			objDOM2 = objC.ctrl.createDOM(iLeft + objC.left, iTop + objC.top);
			_objDOM.appendChild(objDOM2);
			}
		
		return _objDOM;
		}
	}
Ctl.Canvas.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// form

Ctl.Form = function (strId, strTitle, iWidth, iHeight)
	{
	this.strId = dVal(strId, "");
	this.strTitle = dVal(strTitle, "");
	this.iWidth = iWidth;
	this.iHeight = iHeight;
	
	var _objBtns = [];
	var _objCan = null;
	var _objDOMB = null;
	var _objDOM = null;
	
	_objCan = new Ctl.Canvas();
	_objCan.objFather = this;
	
	this.addControl = function (objCtl, iLeft, iTop)
		{
		_objCan.addControl(objCtl, iLeft, iTop);
		}
	
	this.addButton = function (objBtn)
		{
		objBtn.objFather = this;
		_objBtns.push(objBtn);
		}
	
	this.validate = function ()
		{
		return _objCan.validate();
		}
	
	this.setHeight = function (iHeight)
		{
		this.iHeight = iHeight;
		if(_objDOM != null)
			{
			_objDOM.style.height = String(this.iHeight) + "px";
			_objDOMB.style.top = String(this.iHeight - 3) + "px";
			}
		}
	
	this.form = function ()
		{
		return _objDOM;
		}
	
	this.moveControl = function (objCtl, iLeft, iTop) // sposta un controllo all'interno del form
		{
		objCtl.move(iLeft, iTop + 22 + 6);
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		var objDOM2;
		var iIdx;
		var objBtn;
		var iBtnLeft;
		
		iLeft = dVal(iLeft, 0);
		iTop = dVal(iTop, 0);
		
		_objDOM = newEl("form", "id", this.strId, "name", this.strId, "method", "post", "style.overflow", "hidden");
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth, this.iHeight);
		
		objDOM2 = newEl("div", "className", "formtitle", "style.position", "absolute", "style.left", "0px", "style.top", "0px", "style.height", "22px");
		objDOM2.appendChild(newTx(this.strTitle));
		_objDOM.appendChild(objDOM2);
		
		objDOM2 = newEl("div", "className", "formline", "style.top", "22px", "style.width", String(this.iWidth) + "px");
		objDOM2.appendChild(newEl("img", "src", strBaseUrl_ + "/img/s.png", "style.height", "1px")); // per ie6
		_objDOM.appendChild(objDOM2);
		
		_objDOMB = newEl("div", "className", "formline", "style.top", String(this.iHeight - 3) + "px", "style.width", String(this.iWidth) + "px");
		_objDOMB.appendChild(newEl("img", "src", strBaseUrl_ + "/img/s.png", "style.height", "1px")); // per ie6
		_objDOM.appendChild(_objDOMB);
		
		iBtnLeft = this.iWidth + 1;
		for(iIdx = _objBtns.length - 1; iIdx >= 0; iIdx--)
			{
			objBtn = _objBtns[iIdx];
			iBtnLeft -= objBtn.iWidth + 1;
			objDOM2 = objBtn.createDOM(iBtnLeft, 0);
			_objDOM.appendChild(objDOM2);
			}
		
		objDOM2 = _objCan.createDOM(0, 28); // il canvas del form è sempre a coordinate 0,28
		_objDOM.appendChild(objDOM2);
		
		return _objDOM;
		}
	}
Ctl.Form.prototype = new Ctl;

Ctl.Form.height = function (iRows) // altezza di un form con n righe
	{
	return (iRows == undefined ? 0 : iRows * 21 - 1) + 6 + 6 + 22;
	}

////////////////////////////////////////////////////////////////////////////////////////////////////
// label

Ctl.Label = function (strText, iWidth, iHeight, strTitle)
	{
	this.strText = dVal(strText, "");
	this.iWidth = dVal(iWidth, 79);
	this.iHeight = iHeight;
	this.strTitle = dVal(strTitle, "");
	
	var _objDOM = null;
	var _bBold = false;
	var _bVisible = true;
	
	this.visible = function (bVisible)
		{
		if(bVisible == undefined)
			return _bVisible;
		else
			{
			_bVisible = bVisible;
			if(_objDOM != null)
				_objDOM.style.visibility = (_bVisible ? "visible" : "hidden");
			}
		}
	
	this.bold = function (bBold)
		{
		if(bBold == undefined)
			return _bBold;
		else
			{
			_bBold = bBold;
			if(_objDOM != null)
				_objDOM.style.fontWeight = (_bBold ? "bold" : "normal");
			}
		}
	
	this.value = function (strVal)
		{
		if(strVal == undefined)
			return this.strText;
		else
			{
			this.strText = strVal;
			if(_objDOM != null)
				{
				dropDOMChildren(_objDOM);
				_objDOM.appendChild(newTx(this.strText));
				}
			}
		}
	
	this.setHeight = function (iHeight)
		{
		this.iHeight = iHeight;
		if(_objDOM != null)
			_objDOM.style.height = String(this.iHeight - 4) + "px";
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		_objDOM = newEl("label", "style.fontWeight", (_bBold ? "bold" : "normal"), "style.visibility", (_bVisible ? "visible" : "hidden"));
		if(this.strTitle != "")
			_objDOM.title = this.strTitle;
		
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth - 4, (this.iHeight == undefined ? undefined : this.iHeight - 4)); // NB: padding 2px
		
		_objDOM.appendChild(newTx(this.strText));
		
		return _objDOM;
		}
	}
Ctl.Label.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// casella di testo

Ctl.TextBox = function (strId, iMaxLength, iWidth, iTabIndex, bRequired)
	{
	this.strId = dVal(strId, "");
	this.iMaxLength = dVal(iMaxLength, 255);
	this.iWidth = dVal(iWidth, 80);
	this.bPassword = false;
	this.iTabIndex = dVal(iTabIndex, 0);
	this.bRequired = dVal(bRequired, false);
	
	this.onCtrlClick = null;
	
	var _strValue = "";
	var _bReadOnly = false;
	var _me = this;
	var _objDOM = null;
	
	this.validate = function ()
		{
		if(this.bRequired && isBlank(_objDOM.value))
			return {ok:false, err:"Campo obbligatorio non compilato.", obj:this};
		else
			return {ok:true};
		}
	
	this.focus = function ()
		{
		if(this.objFather != null) this.objFather.focus();
		_objDOM.focus();
		}
	
	this.value = function (strVal)
		{
		if(strVal == undefined)
			if(_objDOM != null)
				return _objDOM.value;
			else
				return _strValue;
		else
			{
			_strValue = strVal;
			if(_objDOM != null)
				_objDOM.value = _strValue;
			}
		}
	
	this.readOnly = function (bReadOnly)
		{
		if(bReadOnly == undefined)
			return _bReadOnly;
		else
			{
			_bReadOnly = bReadOnly;
			if(_objDOM != null) _objDOM.readOnly = _bReadOnly;
			}
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		_objDOM = newEl("input", "type", (this.bPassword ? "password" : "text"), "id", this.strId, "name", this.strId, "maxLength", this.iMaxLength, "tabIndex", this.iTabIndex, "className", "textbox", "value", _strValue, "readOnly", _bReadOnly);
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth - 4); // NB: bordo 1px + padding 1px
		addEvent(_objDOM, "click", _onClick);
		return _objDOM;
		}
	
	function _onClick(objEvt)
		{
		if(_me.onCtrlClick != null && objEvt.ctrlKey)
			_me.onCtrlClick(_me.strId);
		}
	}
Ctl.TextBox.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// casella numerica

Ctl.NumberBox = function (strId, dblMinValue, dblMaxValue, iDecimals, iWidth, iTabIndex, bRequired, bZeros)
	{
	this.strId = dVal(strId, "");
	this.dblMinValue = dVal(dblMinValue, -2147483648);
	this.dblMaxValue = dVal(dblMaxValue, 2147483647);
	this.iDecimals = dVal(iDecimals, 0);
	this.iWidth = dVal(iWidth, 80);
	this.iTabIndex = dVal(iTabIndex, 0);
	this.bRequired = dVal(bRequired, false);
	this.bZeros = dVal(bZeros, false);
	this.bNoValidate = false;
	
	this.onChange = null; // evento che scatta al cambio di valore con abbandono del campo
	this.onCtrlClick = null;
	
	var _strValue = "";
	var _bReadOnly = false;
	var _oldVal = "";
	var _me = this;
	var _objDOM = null;
	var _bVisible = true;
	
	this.visible = function (bVisible)
		{
		if(bVisible == undefined)
			return _bVisible;
		else
			{
			_bVisible = bVisible;
			if(_objDOM != null)
				_objDOM.style.visibility = (_bVisible ? "visible" : "hidden");
			}
		}
	
	this.validate = function ()
		{
		var objVal;
		
		if(this.bNoValidate)
			return {ok:true};
		
		if(isBlank(_objDOM.value)) // campo vuoto: controlla solo obbligatorietà
			if(this.bRequired) return {ok:false, err:"Campo obbligatorio non compilato.", obj:this};
			else return {ok:true};
		
		if(this.iDecimals > 0 && !(objVal = isFloat(_objDOM.value)).is) // controlla decimale
			return {ok:false, err:"Campo numerico decimale non valido.", obj:this};
		
		if(this.iDecimals <= 0 && !(objVal = isLong(_objDOM.value)).is) // controlla intero
			return {ok:false, err:"Campo numerico intero non valido.", obj:this};
		
		objVal.value = round(objVal.value, this.iDecimals); // arrotonda
		
		if(objVal.value < this.dblMinValue || objVal.value > this.dblMaxValue) // controlla min e max
			return {ok:false, err:"Campo numerico fuori dai limiti consentiti (da min " + String(this.dblMinValue) + " a max " + String(this.dblMaxValue) + ").", obj:this};
		
		_objDOM.value = formatNumber(objVal.value, this.iDecimals, false, this.bZeros); // formatta
		
		return {ok:true};
		}
	
	this.focus = function ()
		{
		if(this.objFather != null)
			this.objFather.focus();
		_objDOM.focus();
		}
	
	this.value = function (strVal)
		{
		if(strVal == undefined)
			if(_objDOM != null)
				return _objDOM.value;
			else
				return _strValue;
		else
			{
			_strValue = strVal;
			if(_objDOM != null)
				_objDOM.value = _strValue;
			}
		}
	
	this.readOnly = function (bReadOnly)
		{
		if(bReadOnly == undefined)
			return _bReadOnly;
		else
			{
			_bReadOnly = bReadOnly;
			if(_objDOM != null) _objDOM.readOnly = _bReadOnly;
			}
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		var iMaxLength;
		
		// calcola la lunghezza massima
		
		iMaxLength = Math.max(
			String(Math.floor(Math.abs(this.dblMinValue)) + (this.dblMinValue < 0 ? 1 : 0)).length, 
			String(Math.floor(Math.abs(this.dblMaxValue))).length
			);
		
		if(this.iDecimals != 0) iMaxLength += 1 + this.iDecimals;
		
		_objDOM = newEl("input", "type", "text", "id", this.strId, "name", this.strId, "maxLength", iMaxLength, "tabIndex", this.iTabIndex, "className", "textbox", "value", _strValue, "readOnly", _bReadOnly, "style.textAlign", "right", "style.visibility", (_bVisible ? "visible" : "hidden"));
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth - 4); // NB: bordo 1px + padding 1px
		
		addEvent(_objDOM, "focus", _onFocus);
		addEvent(_objDOM, "blur", _onBlur);
		addEvent(_objDOM, "click", _onClick);
		
		return _objDOM;
		}
	
	function _onFocus()
		{
		_oldVal = _objDOM.value;
		}
	
	function _onBlur()
		{
		if(_oldVal == _objDOM.value)
			return;
		if(_me.onChange == null)
			return;
		_me.onChange(_oldVal, _objDOM.value); // passa all'evento il valore vecchio e il valore nuovo
		}
	
	function _onClick(objEvt)
		{
		if(_me.onCtrlClick != null && objEvt.ctrlKey)
			_me.onCtrlClick(_me.strId);
		}
	}
Ctl.NumberBox.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// casella data

Ctl.DateBox = function (strId, iTabIndex, bRequired)
	{
	this.strId = dVal(strId, "");
	this.iWidth = 80;
	this.iTabIndex = dVal(iTabIndex, 0);
	this.bRequired = dVal(bRequired, false);
	this.bTimeBox = false;
	this.bSeconds = false;
	
	this.onCtrlClick = null;
	
	var _strValue = "";
	var _bReadOnly = false;
	var _me = this;
	var _objDOM = null;
	
	this.validate = function ()
		{
		var objVal;
		
		if(isBlank(_objDOM.value)) // campo vuoto: controlla solo obbligatorietà
			if(this.bRequired) return {ok:false, err:"Campo obbligatorio non compilato.", obj:this};
			else return {ok:true};
		
		if(this.bTimeBox) // ora
			{
			if(!(objVal = isTime(_objDOM.value)).is) // controlla ora
				return {ok:false, err:"Campo ora non valido (hh:mm:ss oppure hhmmss).", obj:this};
			_objDOM.value = left(formatTime(objVal.value), (this.bSeconds ? 8 : 5)); // formatta
			}
		else // data
			{
			if(!(objVal = isDate(_objDOM.value)).is) // controlla data
				return {ok:false, err:"Campo data non valido (gg/mm/aaaa oppure ggmmaaaa).", obj:this};
			_objDOM.value = formatDate(objVal.value); // formatta
			}
		
		return {ok:true};
		}
	
	this.focus = function ()
		{
		if(this.objFather != null) this.objFather.focus();
		_objDOM.focus();
		}
	
	this.value = function (strVal)
		{
		if(strVal == undefined)
			if(_objDOM != null)
				return _objDOM.value;
			else
				return _strValue;
		else
			{
			_strValue = strVal;
			if(_objDOM != null) _objDOM.value = _strValue;
			}
		}
	
	this.readOnly = function (bReadOnly)
		{
		if(bReadOnly == undefined)
			return _bReadOnly;
		else
			{
			_bReadOnly = bReadOnly;
			if(_objDOM != null) _objDOM.readOnly = _bReadOnly;
			}
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		_objDOM = newEl("input", "type", "text", "id", this.strId, "name", this.strId, "maxLength", (this.bTimeBox ? (this.bSeconds ? 8 : 5) : 10), "tabIndex", this.iTabIndex, "className", "textbox", "value", _strValue, "readOnly", _bReadOnly);
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth - 4); // NB: bordo 1px + padding 1px
		addEvent(_objDOM, "click", _onClick);
		return _objDOM;
		}
	
	function _onClick(objEvt)
		{
		if(_me.onCtrlClick != null && objEvt.ctrlKey)
			_me.onCtrlClick(_me.strId);
		}
	}
Ctl.DateBox.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// casella testo lungo

Ctl.LongTextBox = function (strId, iMaxLength, iCols, iRows, iWidth, iHeight, iTabIndex, bRequired)
	{
	this.strId = dVal(strId, "");
	this.iMaxLength = dVal(iMaxLength, 255);
	this.iCols = dVal(iCols, 80);
	this.iRows = dVal(iRows, 5);
	this.iWidth = dVal(iWidth, 300);
	this.iHeight = dVal(iHeight, 60);
	this.iTabIndex = dVal(iTabIndex, 0);
	this.bRequired = dVal(bRequired, false);
	
	this.onCtrlClick = null;
	
	var _strValue = "";
	var _bReadOnly = false;

	var _me = this;
	var _objDOM = null;
	
	var _bVisible = true;
	
	this.visible = function (bVisible)
		{
		if(bVisible == undefined)
			return _bVisible;
		else
			{
			_bVisible = bVisible;
			if(_objDOM != null)
				_objDOM.style.visibility = (_bVisible ? "visible" : "hidden");
			}
		}
	
	this.validate = function ()
		{
		if(this.bRequired && isBlank(_objDOM.value))
			return {ok:false, err:"Campo obbligatorio non compilato.", obj:this};
		else
			if(_objDOM.value.length > this.iMaxLength)
				return {ok:false, err:"Campo testo troppo lungo (lunghezza attuale " + String(_objDOM.value.length) + ", lunghezza massima " + String(this.iMaxLength) + ").", obj:this};
			else
				return {ok:true};
		}
	
	this.focus = function ()
		{
		if(this.objFather != null) this.objFather.focus();
		_objDOM.focus();
		}
	
	this.value = function (strVal)
		{
		if(strVal == undefined)
			if(_objDOM != null)
				return _objDOM.value;
			else
				return _strValue;
		else
			{
			_strValue = strVal;
			if(_objDOM != null) _objDOM.value = strVal;
			}
		}
	
	this.readOnly = function (bReadOnly)
		{
		if(bReadOnly == undefined)
			return _bReadOnly;
		else
			{
			_bReadOnly = bReadOnly;
			if(_objDOM != null)
				_objDOM.readOnly = _bReadOnly;
			}
		}
	
	this.setHeight = function (iHeight)
		{
		this.iHeight = iHeight;
		if(_objDOM != null)
			_objDOM.style.height = String(this.iHeight - 4) + "px";
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		_objDOM = newEl("textarea", "id", this.strId, "name", this.strId, "cols", this.iCols, "rows", this.iRows, "tabIndex", this.iTabIndex, "className", "textbox", "value", _strValue, "readOnly", _bReadOnly, "style.visibility", (_bVisible ? "visible" : "hidden"));
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth - 4, this.iHeight - 4); // NB: bordo 1px + padding 1px
		
		addEvent(_objDOM, "keyup", _checkLength);
		addEvent(_objDOM, "click", _onClick);
		
		return _objDOM;
		}
	
	function _checkLength(objEvt) // controlla la lunghezza massima
		{
		if(_objDOM.value.length > _me.iMaxLength)
			_objDOM.style.backgroundColor = "#FF8080";
		else
			_objDOM.style.backgroundColor = "#FFFFFF";
		}
	
	function _onClick(objEvt)
		{
		if(_me.onCtrlClick != null && objEvt.ctrlKey)
			_me.onCtrlClick(_me.strId);
		}
	}
Ctl.LongTextBox.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// campo nascosto

Ctl.Hidden = function (strId, strValue)
	{
	this.strId = dVal(strId, "");
	
	var _strValue = dVal(strValue, "");
	var _objDOM = null;
	
	this.value = function (strVal)
		{
		if(strVal == undefined)
			if(_objDOM != null)
				return _objDOM.value;
			else
				return _strValue;
		else
			{
			_strValue = strVal;
			if(_objDOM != null) _objDOM.value = _strValue;
			}
		}
	
	this.createDOM = function ()
		{
		_objDOM = newEl("input", "type", "hidden", "id", this.strId, "name", this.strId, "value", _strValue);
		return _objDOM;
		}
	}
Ctl.Hidden.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// pulsante

Ctl.Button = function (strText, iWidth, strTitle, bSmall)
	{
	this.strText = dVal(strText, "");
	this.iWidth = dVal(iWidth, 80);
	this.strTitle = dVal(strTitle, "");
	this.strEvtId = null;
	this.bDefault = false;
	this.bSmall = dVal(bSmall, false);
	
	this.onClick = null;
	
	var _me = this;
	var _bEnabled = true;
	var _objDOM = null;
	
	this.focus = function ()
		{
		if(this.objFather != null) this.objFather.focus();
		_objDOM.focus();
		}
	
	this.move = function (iLeft, iTop)
		{
		if(_objDOM == null)
			return;
		if(iLeft != undefined)
			_objDOM.style.left = String(iLeft) + "px";
		if(iTop != undefined)
			_objDOM.style.top = String(iTop) + "px";
		}
	
	this.enabled = function (bEnabled)
		{
		if(bEnabled == undefined)
			return _bEnabled;
		else
			{
			_bEnabled = bEnabled;
			if(_objDOM != null)
				_objDOM.className = "inpbutton" + (this.bSmall ? "s" : "") + " inpbutton" + (this.bSmall ? "s" : "") + (_bEnabled ? "-e" : "-d");
			}
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		var objDOM2;
		
		_objDOM = newEl("div", "className", "inpbutton" + (this.bSmall ? "s" : "") + " inpbutton" + (this.bSmall ? "s" : "") + (_bEnabled ? "-e" : "-d"), "title", this.strTitle);
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth);
		_objDOM.appendChild(newTx(_me.strText));
		
		addEvent(_objDOM, "click", _onClick);
		
		if(this.bDefault) // il pulsante risponde anche con l'invio
			addEvent(objBody_, "keypress", _checkEnter);
		
		objDOM2 = newEl("div", "className", "inpbutton-l");
		_objDOM.appendChild(objDOM2);
		objDOM2 = newEl("div", "className", "inpbutton-r");
		_objDOM.appendChild(objDOM2);
		
		return _objDOM;
		}
	
	function _onClick()
		{
		if(_me.onClick == null || !_bEnabled) return;
		_me.onClick(_me.strEvtId);
		}
	
	function _checkEnter(objEvt)
		{
		if(eventKey(objEvt) == 13) // è stato premuto invio
			{
			if(objEvt.preventDefault) // standard (per evitare il submit automatico quando la form ha un solo campo)
				objEvt.preventDefault();
			
			_onClick();
			
			if(!objEvt.preventDefault) // IE (per evitare il submit automatico)
				return false;
			}
		}
	}
Ctl.Button.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// combo box

Ctl.ComboBox = function (strId, iWidth, iTabIndex, bRequired)
	{
	this.strId = dVal(strId, "");
	this.iWidth = dVal(iWidth, 80);
	this.iTabIndex = dVal(iTabIndex, 0);
	this.bRequired = dVal(bRequired, false);
	
	this.onClick = null;
	this.onCtrlClick = null;
	
	var _me = this;
	var _strValue = null;
	var _objDOM = null;
	var _objOpts = [];
	
	this.addOption = function (strValue, strText)
		{
		_objOpts.push({value:strValue, text:strText});
		if(_objDOM != null)
			comboAddOption(_objDOM, strValue, strText);
		}
	
	this.removeOption = function (strValue)
		{
		var iIdx;

		for(iIdx = _objOpts.length - 1; iIdx >= 0; iIdx--)
			if(strValue == undefined || strValue == _objOpts[iIdx].value)
				{
				_objOpts.splice(iIdx, 1);
				if(_objDOM != null)
					_objDOM.remove(iIdx);
				}
		}
	
	this.validate = function ()
		{
		if(this.bRequired && isBlank(comboValue(_objDOM)))
			return {ok:false, err:"Campo obbligatorio non compilato.", obj:this};
		else
			return {ok:true};
		}
	
	this.focus = function ()
		{
		if(this.objFather != null)
			this.objFather.focus();
		_objDOM.focus();
		}
	
	this.value = function (strVal)
		{
		if(strVal == undefined)
			if(_objDOM != null)
				return comboValue(_objDOM);
			else
				return _strValue;
		else
			{
			_strValue = strVal;
			if(_objDOM != null)
				comboValue(_objDOM, _strValue);
			}
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		var iIdx;
		
		_objDOM = newEl("select", "id", this.strId, "name", this.strId, "tabIndex", this.iTabIndex, "className", "textbox");
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth);
		
		for(iIdx = 0; iIdx < _objOpts.length; iIdx++)
			comboAddOption(_objDOM, _objOpts[iIdx].value, _objOpts[iIdx].text);
		
		addEvent(_objDOM, "change", _onChange);
		addEvent(_objDOM, "click", _onClick);

		if(_strValue != null)
			comboValue(_objDOM, _strValue);

		return _objDOM;
		}
	
	function _onChange()
		{
		if(_me.onClick != null)
			_me.onClick(comboValue(_objDOM));
		}
	
	function _onClick(objEvt)
		{
		if(_me.onCtrlClick != null && objEvt.ctrlKey)
			_me.onCtrlClick(_me.strId);
		}
	}
Ctl.ComboBox.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// casella di spunta
// objData: informazione legata al checkbox che viene restituita con l'evento click

Ctl.CheckBox = function (strId, iTabIndex, objData)
	{
	this.strId = dVal(strId, "");
	this.iTabIndex = dVal(iTabIndex, 0);
	this.objData = dVal(objData, null);
	
	this.onClick = null;
	this.onCtrlClick = null;
	
	var _me = this;
	var _bValue = false;
	var _bReadOnly = false;
	var _objDOM = null;
	
	this.focus = function ()
		{
		if(this.objFather != null) this.objFather.focus();
		_objDOM.focus();
		}
	
	this.value = function (bVal)
		{
		if(bVal == undefined)
			if(_objDOM != null)
				return _objDOM.checked;
			else
				return _bValue;
		else
			{
			_bValue = bVal;
			if(_objDOM != null) _objDOM.checked = _bValue;
			}
		}
	
	this.readOnly = function (bReadOnly)
		{
		if(bReadOnly == undefined)
			return _bReadOnly;
		else
			_bReadOnly = bReadOnly;
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		// crea il DOM
		// nota: l'elemento non viene creato mediante tagName ma con codice HTML; questo
		// perchè IE non permette di impostare la proprietà checked

		_objDOM = newEl("<input type=\"checkbox\"" + (_bValue ? " checked" : "") + ">", "id", this.strId, "name", this.strId, "value", "S", "tabIndex", this.iTabIndex);
		this.posDOM(_objDOM, iLeft, iTop);
		
		addEvent(_objDOM, "click", _onClick);
		
		return _objDOM;
		}
	
	function _onClick(objEvt) // intercetta il click per gestire il readonly
		{
		if(_bReadOnly)
			{
			_objDOM.checked = !_objDOM.checked;
			return;
			}
		
		if(!objEvt.ctrlKey && _me.onClick != null)
			_me.onClick(_objDOM.checked, _me.strId, _me.objData);
		
		if(objEvt.ctrlKey && _me.onCtrlClick != null)
			{
			_objDOM.checked = !_objDOM.checked; // non modifica il check
			_me.onCtrlClick(_me.strId);
			}
		}
	}
Ctl.CheckBox.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// casella di ricerca

Ctl.SearchBox = function (strId, iMaxLength, iWidth, iIdWidth, iTabIndex, bRequired)
	{
	this.strId = dVal(strId, "");
	this.iMaxLength = dVal(iMaxLength, 10);
	this.iWidth = dVal(iWidth, 300);
	this.iIdWidth = dVal(iIdWidth, 50);
	this.iTabIndex = dVal(iTabIndex, 0);
	this.bRequired = dVal(bRequired, false);
	
	this.onSearch = null;
	this.onValidate = null;
	this.onAfter = null; // evento che scatta dopo aver impostato il valore
	this.onCtrlClick = null;
	
	var _me = this;
	var _strValue = "";
	var _objDOM = null;
	var _objDOMId = null;
	var _objDOMDes = null;
	var _objDOMSrc = null;
	var _oldVal = "";
	var _objData = null;
	var _bReadOnly = false;
	
	this.validate = function ()
		{
		if(this.bRequired && isBlank(_objDOMId.value))
			return {ok:false, err:"Campo obbligatorio non compilato.", obj:this};
		else
			return {ok:true};
		}
	
	this.focus = function ()
		{
		if(this.objFather != null) this.objFather.focus();
		_objDOMId.focus();
		}
	
	this.value = function (strVal, strDesVal, objData)
		{
		if(strVal == undefined)
			if(_objDOM != null)
				return _objDOMId.value;
			else
				return _strValue;
		else
			{
			_strValue = strVal;
			_objData = dVal(objData, null);
			
			if(_objDOM != null)
				{
				_objDOMId.value = _strValue;

				if(strDesVal != undefined)
					_objDOMDes.value = strDesVal;
				else
					{
					this.onValidate(_objDOMId.value, _xhCallBack); // prosegue la decodifica mediante validazione
					return;
					}
				
				if(this.onAfter != null)
					this.onAfter(this, _objDOMId.value, _objData);
				}
			}
		}
	
	this.readOnly = function (bReadOnly)
		{
		if(bReadOnly == undefined)
			return _bReadOnly;
		else
			{
			_bReadOnly = bReadOnly;
			if(_objDOM != null)
				_objDOMId.readOnly = _bReadOnly; // il click per la ricerca viene intercettato dopo
			}
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		var objDOM2;
		
		_objDOM = document.createDocumentFragment();
		
		_objDOMId = newEl("input", "type", "text", "id", this.strId, "name", this.strId, "maxLength", this.iMaxLength, "tabIndex", this.iTabIndex, "className", "textbox", "value", _strValue, "readOnly", _bReadOnly);
		this.posDOM(_objDOMId, iLeft, iTop, this.iIdWidth - 4); // NB: bordo 1px + padding 1px
		_objDOM.appendChild(_objDOMId);
		
		_objDOMSrc = newEl("div", "className", "srcbutton", "style.left", String(iLeft + this.iIdWidth) + "px", "style.top", String(iTop + 2) + "px");
		_objDOM.appendChild(_objDOMSrc);
		
		_objDOMDes = newEl("input", "type", "text", "id", "_d_" + this.strId, "name", "_d_" + this.strId, "maxLength", 255, "readOnly", true, "className", "textbox");
		this.posDOM(_objDOMDes, iLeft + this.iIdWidth + 17, iTop, this.iWidth - this.iIdWidth - 17 - 4); // NB: bordo 1px + padding 1px
		_objDOM.appendChild(_objDOMDes);
		
		if(_strValue != "") this.onValidate(_objDOMId.value, _xhCallBack);
		
		// eventi interni
		
		addEvent(_objDOMId, "focus", _onFocus);
		addEvent(_objDOMId, "blur", _onBlur);
		addEvent(_objDOMId, "click", _onClick);
		addEvent(_objDOMSrc, "click", _onSearch);
		
		return _objDOM;
		}
	
	function _onFocus()
		{
		_oldVal = _objDOMId.value;
		}
	
	function _onBlur()
		{
		if(_oldVal == _objDOMId.value)
			return;
		
		_objDOMDes.value = "";
		_objData = null;
		
		if(_objDOMId.value == "")
			{
			if(_me.onAfter != null)
				_me.onAfter(_me, "", null);
			return;
			}
		
		if(_me.onValidate == null)
			return;
		_me.onValidate(_objDOMId.value, _xhCallBack);
		}
	
	function _onSearch()
		{
		if(_me.onSearch == null || _bReadOnly) // intercetta anche il read-only
			return;
		_me.onSearch(_me);
		}
	
	function _onClick(objEvt)
		{
		if(_me.onCtrlClick != null && objEvt.ctrlKey)
			_me.onCtrlClick(_me.strId);
		}
	
	function _xhCallBack(strAnswer, strError)
		{
		var objRes;
		
		_objDOMId.value = "";
		
		if(String(strError) == "")
			{
			if((objRes = strAnswer.parseJSON()) instanceof Object)
				{
				if(objRes.err__ instanceof Object)
					alert("(" + objRes.err__.number + ") " + objRes.err__.description);
				else if(objRes.run__ instanceof String)
					eval(objRes.run__);
				else
					{
					if(objRes.id_ != undefined)
						{
						_objDOMId.value = objRes.id_;
						_objDOMDes.value = objRes.des_;
						_objData = objRes.data_;
						}
					
					if(_me.onAfter != null) 
						_me.onAfter(_me, _objDOMId.value, _objData);
					}
				}
			}
		else
			alert("La validazione del campo non è riuscita.");
		}
	}
Ctl.SearchBox.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// casella di opzione

Ctl.RadioButton = function (strName, strValue, iTabIndex)
	{
	this.strName = dVal(strName, "");
	this.strValue = dVal(strValue, "");
	this.iTabIndex = dVal(iTabIndex, 0);
	this.bNormalMode = false;
	
	this.onClick = null;
	
	var _me = this;
	var _bValue = false;
	var _bCurrent = false;
	var _objDOM = null;
	var _iIndex = 0; // indice univoco tra i radio che hanno lo stesso name
	
	this.focus = function ()
		{
		if(this.objFather != null) this.objFather.focus();
		_objDOM.focus();
		}
	
	this.value = function (bVal)
		{
		if(bVal == undefined)
			if(_objDOM != null)
				return _objDOM.checked;
			else
				return _bValue;
		else
			{
			_bValue = bVal;
			if(_objDOM != null)
				_objDOM.checked = _bValue;
			}
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		// aggiorna il contatore
		
		_iIndex = (Ctl.objRadCnt[this.strName] == undefined ? 0 : Ctl.objRadCnt[this.strName] + 1);
		Ctl.objRadCnt[this.strName] = _iIndex;
		
		if(this.strValue == "")
			this.strValue = String(_iIndex); // valore di submit, se omesso, è l'indice
		
		// crea il DOM
		// nota: l'elemento non viene creato mediante tagName ma con codice HTML; questo
		// perchè IE non permette di impostare la proprietà "name" per gli input di tipo "radio"
		// idem per il checked
		
		_objDOM = newEl("<input type=\"radio\" name=\"" + this.strName + "\"" + (_bValue ? " checked" : "") + ">", "id", this.strName + "_" + String(_iIndex), "value", this.strValue, "tabIndex", this.iTabIndex);
		this.posDOM(_objDOM, iLeft, iTop);
		
		addEvent(_objDOM, "click", _onClick);
		addEvent(_objDOM, "mousedown", _onMouseDown);
		
		return _objDOM;
		}
	
	function _onMouseDown()
		{
		_bCurrent = _objDOM.checked; 
		}
	
	function _onClick()
		{
		if(_bCurrent)
			{
			if(_me.bNormalMode)
				return;
			_objDOM.checked = false;
			}
		if(_me.onClick == null)
			return;
		_me.onClick(_objDOM.checked, _me.strValue);
		}
	}
Ctl.RadioButton.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// file upload

Ctl.FileBox = function (strId, iWidth, iTabIndex, bRequired)
	{
	this.strId = dVal(strId, "");
	this.iWidth = dVal(iWidth, 200);
	this.iTabIndex = dVal(iTabIndex, 0);
	this.bRequired = dVal(bRequired, false);
	
	var _objExt = null; // tipi di files ammessi
	var _objDOM = null;
	
	this.types = function ()
		{
		var iIdx;
		
		if(arguments.length == 0) // tutti ammessi
			_objExt = null;
		else
			{
			_objExt = {};
			
			for(iIdx = 0; iIdx < arguments.length; iIdx++)
				_objExt["EXT_" + String(arguments[iIdx]).toUpperCase()] = "OK";
			}
		}
	
	this.validate = function ()
		{
		var iPos;
		var strExt;
		
		if(isBlank(_objDOM.value)) // vuoto
			if(this.bRequired) // obbligatorio: errore
				return {ok:false, err:"Campo obbligatorio non compilato.", obj:this};
			else // non obbl: ok
				return {ok:true};
		else // non vuoto: check tipi file
			if(_objExt == null) // tutti ammessi: ok
				return {ok:true};
			else // controllo
				{
				strExt = String(_objDOM.value);
				iPos = strExt.lastIndexOf(".");
				if(iPos == -1)
					strExt = "";
				else
					strExt = strExt.substr(iPos + 1).toUpperCase();
				return {ok:(_objExt["EXT_" + strExt] == "OK"), err:"Tipo di file non ammesso.", obj:this};
				}
		}
	
	this.focus = function ()
		{
		if(this.objFather != null) this.objFather.focus();
		_objDOM.focus();
		}
	
	this.value = function ()
		{
		if(_objDOM == null)
			return "";
		else
			return _objDOM.value;
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		_objDOM = newEl("input", "type", "file", "id", this.strId, "name", this.strId, "tabIndex", this.iTabIndex, "className", "filebox");
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth);
		return _objDOM;
		}
	}
Ctl.FileBox.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// immagine

Ctl.Image = function (strSrc, iWidth, iHeight, bScroll)
	{
	this.iWidth = iWidth;
	this.iHeight = iHeight;
	this.bScroll = dVal(bScroll, false);
	
	var _strSrc = dVal(strSrc, "");
	var _objDOM = null;
	var _objDOMImg = null;
	
	this.value = function(strVal)
		{
		if(strVal == undefined)
			return _strSrc;
		else
			{
			_strSrc = strVal;
			if(_objDOMImg != null)
				if(_strSrc == "")
					{
					_objDOMImg.src = strBaseUrl_ + "/img/s.png";
					_objDOMImg.style.backgroundColor = null;
					}
				else
					{
					_objDOMImg.src = _strSrc;
					_objDOMImg.style.backgroundColor = "#FFFFFF";
					}
			}
		}
	
	this.setHeight = function (iHeight)
		{
		this.iHeight = iHeight;
		if(_objDOM != null)
			_objDOM.style.height = String(this.iHeight - (this.bScroll ? 2 : 0)) + "px";
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		var iW;
		var iH;
		
		_objDOMImg = newEl("img", "src", strBaseUrl_ + "/img/s.png", "className", "image");
		this.value(_strSrc);
		
		if(this.bScroll)
			{
			_objDOM = newEl("div", "className", "image", "style.overflow", "auto");
			_objDOM.appendChild(_objDOMImg);
			}
		else
			_objDOM = _objDOMImg;
		
		iW = this.iWidth;
		if(iW != undefined && this.bScroll)
			iW -= 2;  // border 1px
		
		iH = this.iHeight;
		if(iH != undefined && this.bScroll)
			iH -= 2;  // border 1px
		
		this.posDOM(_objDOM, iLeft, iTop, iW, iH);
		return _objDOM;
		}
	}
Ctl.Image.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// link

Ctl.Link = function (strHref, strText, strIconUrl, strTitle, iWidth)
	{
	this.strHref = dVal(strHref, "");
	this.strText = dVal(strText, "");
	this.strIconUrl = dVal(strIconUrl, "");
	this.iWidth = iWidth;
	this.strTitle = dVal(strTitle, "");
	
	var _me = this;
	var _objDOM = null;
	var _objDOMImg = null;
	var _objDOMSpan = null;
	var _bVisible = true;
	
	this.visible = function (bVisible)
		{
		if(bVisible == undefined)
			return _bVisible;
		else
			{
			_bVisible = bVisible;
			if(_objDOM != null)
				_objDOM.style.visibility = (_bVisible ? "visible" : "hidden");
			}
		}
	
	this.value = function (strHref, strText, strIconUrl, strTitle)
		{
		if(strHref != undefined)
			this.strHref = strHref;
		if(strText != undefined)
			this.strText = strText;
		if(strIconUrl != undefined)
			this.strIconUrl = strIconUrl;
		if(strTitle != undefined)
			this.strTitle = strTitle;
		
		if(_objDOM == null)
			return;
		
		_objDOM.title = this.strTitle;
		_createInner();
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		_objDOM = newEl("div", "className", "linkbox", "style.visibility", (_bVisible ? "visible" : "hidden"), "title", this.strTitle);
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth);
		_createInner();
		return _objDOM;
		}
	
	function _createInner() // crea il contenuto del link
		{
		var objDOM = null;
		
		dropDOMChildren(_objDOM);
		
		if(_me.strIconUrl != "")
			{
			_objDOMImg = newEl("img", "src", _me.strIconUrl);
			addEvent(_objDOMImg, "click", _click);
			_objDOM.appendChild(_objDOMImg);
			
			objDOM = newEl("div");
			}
		
		_objDOMSpan = newEl("span");
		_objDOMSpan.appendChild(newTx(_me.strText));
		addEvent(_objDOMSpan, "click", _click);
		
		if(objDOM != null)
			{
			objDOM.appendChild(_objDOMSpan);
			_objDOM.appendChild(objDOM);
			}
		else
			_objDOM.appendChild(_objDOMSpan);
		}
	
	function _click()
		{
		if(_me.strHref == "")
			return;
		document.location = _me.strHref;
		}
	}
Ctl.Link.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// text

Ctl.Text = function (strText, iWidth, iHeight, bNoWrap)
	{
	this.strText = dVal(strText, "");
	this.iWidth = iWidth;
	this.iHeight = iHeight;
	this.bNoWrap = dVal(bNoWrap, false);
	
	var _objDOM = null;
	var _bVisible = true;
	
	this.visible = function (bVisible)
		{
		if(bVisible == undefined)
			return _bVisible;
		else
			{
			_bVisible = bVisible;
			if(_objDOM != null)
				_objDOM.style.visibility = (_bVisible ? "visible" : "hidden");
			}
		}
	
	this.move = function (iLeft, iTop)
		{
		if(_objDOM == null)
			return;
		if(iLeft != undefined)
			_objDOM.style.left = String(iLeft) + "px";
		if(iTop != undefined)
			_objDOM.style.top = String(iTop) + "px";
		}
	
	this.value = function (strText)
		{
		if(strText == undefined)
			return this.strText;
		else
			{
			this.strText = strText;
			if(_objDOM != null)
				_objDOM.innerHTML = this.strText;
			}
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		_objDOM = newEl("div", "style.visibility", (_bVisible ? "visible" : "hidden"), "style.whiteSpace", (this.bNoWrap ? "nowrap" : "normal"), "className", "formtext");
		this.posDOM(_objDOM, iLeft, iTop, this.iWidth, this.iHeight);
		
		_objDOM.innerHTML = this.strText; // innerHTML così posso passare tag HTML nel testo
		
		return _objDOM;
		}
	}
Ctl.Text.prototype = new Ctl;

////////////////////////////////////////////////////////////////////////////////////////////////////
// titolo

Ctl.Title = function(strText, iWidth)
	{
	var _strText = dVal(strText, "");
	var _iWidth = iWidth;
	
	var _bVisible = true;
	var _objDOM = null;
	
	this.visible = function (bVisible)
		{
		if(bVisible == undefined)
			return _bVisible;
		else
			{
			_bVisible = bVisible;
			if(_objDOM != null)
				_objDOM.style.visibility = (_bVisible ? "visible" : "hidden");
			}
		}
	
	this.move = function (iLeft, iTop)
		{
		if(_objDOM == null)
			return;
		if(iLeft != undefined)
			_objDOM.style.left = String(iLeft) + "px";
		if(iTop != undefined) 
			_objDOM.style.top = String(iTop) + "px";
		}
	
	this.createDOM = function (iLeft, iTop)
		{
		
		iLeft = dVal(iLeft, 0);
		iTop = dVal(iTop, 0);
		
		_objDOM = newEl("div", "className", "inptitle", "style.height", (_strText == "" ? "9px" : "17px"), "style.visibility", (_bVisible ? "visible" : "hidden"));
		_objDOM.appendChild(newTx(_strText));
		this.posDOM(_objDOM, iLeft, iTop, _iWidth);
		
		return _objDOM;
		}
	}
Ctl.Title.prototype = new Ctl;
