﻿/// <reference path="jquery-1.3.2-vsdoc2.js"/>
/// <reference path="jquery_ui/ui.core.js" />
/// <reference path="jquery_ui/ui.draggable.js" />

/********************************************************

//		ESTENSIONI VARIE

********************************************************/


// Setup per ajax
var SEP_OR = String.fromCharCode(208);
var SEP_VT = String.fromCharCode(198);

$.ajaxSetup({type: 'POST', url: 'as_send.aspx', async: false});

// Ajax sincrono che ritorna il response
jQuery.ajaxEx= function(datax) {
// Ritorna il rsponse text dalla funzione ajax
		//datax=encodeURIComponent(datax)
		try{
			q=datax;
			if($.ajaxSettings.url=="as_send_sql.aspx"||$.ajaxSettings.url=="as_send.aspx"){
					if(datax>""){
						if(datax.indexOf("+")>-1){datax=datax.replace(/[+]/g,"§20");}
						if(datax.substr(0,6).toLowerCase()=="query="){
							var q=datax;
						}else{
							q="query="+datax;
						}
					}else{q=""}
			}
			var x=$.ajax({
				data: q
			}).responseText
		}catch(e){}
		try{
			if(x.substr(0,6)=="<html>"){
				document.write(x)
			}else{return(x)}
		}catch(e){return (x)}
};


// Ajax sincrono che ritorna il response ma ritorna la matrice
jQuery.ajaxEx2= function(datax) {
// Ritorna il rsponse text dalla funzione ajax
		//datax=encodeURIComponent(datax)
		try{
			q=datax;
			if($.ajaxSettings.url=="as_send_sql.aspx"||$.ajaxSettings.url=="as_send.aspx"){
					if(datax>""){
						if(datax.indexOf("+")>-1){datax=datax.replace(/[+]/g,"§20");}
						if(datax.substr(0,6).toLowerCase()=="query="){
							var q=datax;
						}else{
							q="query="+datax;
						}
					}else{q=""}
			}
			var x=$.ajax({
				data: q
			}).responseText
			x=$.DATA_getFieldsFromResponseRequestObj(x)
		}catch(e){}
		try{
			if(x.substr(0,6)=="<html>"){
				document.write(x)
			}else{return(x)}
		}catch(e){return (x)}
};

// Tabella che viene creata e riempita automaticamente
jQuery.ajaxExFillTable = function(query_only_select,ID_COLUMN_NUM_BASEZERO,id,container,left_top_width_heigth,columns,css_or_class_header,css_or_class_grid){
	if(query_only_select.substr(0,6).toLowerCase()=="query="){
		var q=query_only_select;
	}else{
		q="query="+query_only_select;
	}
	var	divmain=document.getElementById(id);
	if(!divmain){
		if(container){
			if(typeof(container)=="string"){
				container=document.getElementById(container);
			}else{
				container.appendChild(tb);
			}
		}
		if(left_top_width_heigth){
			var left=left_top_width_heigth.split(",")[0];
			var top=left_top_width_heigth.split(",")[1];
			var width=left_top_width_heigth.split(",")[2];
			var height=left_top_width_heigth.split(",")[3];
			var pos="left:"+left+";top:"+top+";width:"+width+";height:"+height+";"
		}else{
			pos="";
		}
		divmain=$.CM_createObj("div",container, id,"","","overflow:auto;"+pos);
		var tb=$.CM_createObj("table",id, "grid-"+id,"","","width:100%;");
		divmain.appendChild(tb)
		divmain.id=id
		tb.id="grid-"+id
	}else{
		tb=document.getElementById("grid-"+id)
	}
	try{
		if(tb.rows.length>0){
			if(columns){
				$.TABLE_RemoveAllCell(tb,0)}else{$.TABLE_RemoveAllCell(tb,1);}
	}}catch(e){}
	// Colonne
	if(columns){
		var or=tb.insertRow(-1);or.style.fontWeight="bold"
		columns=columns.split(",");
		for(var c=0;c<columns.length;c++){var oc=or.insertCell(-1);oc.innerHTML=columns[c]}
	}else{
		or=tb.rows[0];
	}
	if(css_or_class_header){$(or).cssEX(css_or_class_header);};
	
	var risp=$.ajaxEx(q);
	var v=$.DATA_getFieldsFromResponseRequestObj(risp);
	if(!ID_COLUMN_NUM_BASEZERO) ID_COLUMN_NUM_BASEZERO=-1;
	if($.trim(v.toString())>" "){
		for(var r=0;r<v.length;r++){
			or=tb.insertRow(-1);
			or.id="r-"+r;
			for(c=0;c<v[r].length;c++){
				if(c!=ID_COLUMN_NUM_BASEZERO){
					oc=or.insertCell(-1);
					oc.innerHTML=v[r][c];
					oc.id="c-"+r+c;
				}else{
					or.id=or.id+"-"+v[r][c];
				}
			}
	}}
	if(css_or_class_grid){
		$(divmain).cssEX(css_or_class_grid);
	}
};

// css ex
jQuery.fn.cssEX = function(cssstring) {
	return this.each(function() {
		var v = cssstring.split(";")
		for (var d = 0; d < v.length; d++) {
			var w = v[d].split(":");
			var ex = "this.style." + w[0] + "='" + w[1]+"'";
			try { eval(ex); }
			catch (e) {  }
		}
	})
};

// for next ????
jQuery.CM_fornext = function(ninit, nfin, fn) {
	for (var a = ninit; a < nfin; a++) {
		fn(a);
	}
};

//  Ritorna la data odierna nel formato dd/mm/yyyy hh:mm
jQuery.CM_getTodayDateTime=function () {
	var d=new Date();var s="";
	if(SERVERLANGUAGE.toString().toLowerCase()=="en"){
		s += (d.getMonth() + 1) + "/";
		s += d.getDate() + "/";
		s += d.getFullYear();
		s+=" "+d.getHours()+":"+d.getMinutes();
	}else{
		s += d.getDate() + "/";
		s += (d.getMonth() + 1) + "/";
		s += d.getFullYear();
		s+=" "+d.getHours()+":"+d.getMinutes();
	}
	return(s);
};

jQuery.CM_alertDebug=function(msg){
	if(window.location.href.indexOf("localhost")>-1){
		alert(msg)
	}
};

// Split al contrario da un array ritorna una stringa




/********************************************************

//		ESTENSIONI X COMMON

********************************************************/


// linguaggio del server e client
var SERVERLANGUAGE="en";
var CLIENTLANGUAGE="en";
jQuery.CM_getServerLanguage=function(){
	var memo=$.ajaxSettings.url.toString();
	$.ajaxSetup({type: 'POST', url: 'language.aspx', async: false});
	SERVERLANGUAGE=$.ajaxEx();
	$.ajaxSetup({type: 'POST', url: memo, async: false});
	CLIENTLANGUAGE=(navigator["language"])?navigator["language"]:navigator["userLanguage"];
};
jQuery.CM_getServerLanguage();

// estensioni jquery create object
jQuery.CM_createObj = function(s_type, container, id, html, sclass, styles, attributes,arrEvents,rows,columns,mousepointer) {
				var err="Error create obj"
				if (!s_type) return (err + " no type.");
				if (!container) return (err + " no container.");
				if(container.constructor==String){container=$("#"+container)[0]}
				var t = document.createElement(s_type);
				if (id) t.id = id
				if (sclass > "") {
					t.className = sclass;
				}
				if (attributes) {
					var v = attributes.split(",");
					for (var x = 0; x < v.length; x++) {
						var v1 = v[x].split(":");
						var ex = "t." + v1[0] + "='" + v1[1] + "';"
						try { eval(ex); }
						catch (e) { }
					}
				}
				if (styles) {
					if (styles.indexOf(":") > -1) {
						var v = styles.split(";");
						for (var x = 0; x < v.length; x++) {
							var v1 = v[x].split(":");
							var ex = "t.style." + v1[0] + "='" + $.trim(v1[1]) + "';"
							try{eval(ex);}
							catch (e){}
						}
					} else {
						var v = styles.split(";");
						for (var x = 0; x < v.length; x += 2) {
							var ex = "t.style." + v[x] + "='" + $.trim(v[x + 1]) + "';"
							eval(ex);
						}
					}
				}
				if (rows&&columns) {
					try {
						for (var x = 0; x < rows; x++) {
							var oc = t.insertRow(-1);
							for (var y = 0; y < columns; y++) {
								oc.insertCell(-1);
							}
						}
						$(t).TABLE_extensions();
					} catch (e) {alert(e)}
				}
				if (html) {
					if (t.tagName.toLowerCase() != "table") {
						try { t.innerHTML = html; } catch (e) { }
					}
				}
				container.appendChild(t);
				if (mousepointer) {
					$.CM_setcursorwithhand(t)
				}
				if (arrEvents) {
					for (var x = 0; x < arrEvents.length; x++) {
						CM_Event(t, arrEvents[0], arrEvents[1]);
					}
				}
				return (t)
};


// estensioni jquery getID
jQuery.CM_getEl= function(el) {
		return document.getElementById(el);
};

// Cursore con hand
jQuery.CM_setcursorwithhand= function(Object) {
		if (Object) {
			if ($.browser.msie)
				Object.style.cursor = "hand";
			else
				Object.style.cursor = "pointer";
		}
};
	
//  attacca evento
jQuery.fn.CM_Event=function(event, handler) {
	return this.each(function() {
				if (this.addEventListener)
					this.addEventListener(event, handler, false);

				else if (this.attachEvent)
					this.attachEvent("on" + event, handler);
})};

//  Altra gestione wait
jQuery.CM_WaitShow = function(solosfondo) {
	// Creo lo sfondo
	var sfondo = $.CM_getEl("sfondo2244");
	var cursor=""
	if(!solosfondo) cursor=";cursor:wait"
	if (!sfondo) {
		var sfondo2244=$.CM_createObj("div", document.body, "sfondo2244", "", "", "left:1px; top:1px; width:100%; height:100%; -ms-filter: 'progid:DXImageTransform.Microsoft.Alpha(opacity=40)';  filter: progid:DXImageTransform.Microsoft.Alpha(opacity=40); opacity:0.5; moxOpacity:0.5; position:absolute; backgroundColor:gray "+cursor) //cursor:hand; cursor:pointer
		sfondo2244.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=40)"
		$.CM_createObj("div", document.body, "winwait2244", "<br><b>&nbsp;&nbsp;Attendere...</b>", "", "left:40px; top:40px; width:200px; height:60px; border:solid 2px red; backgroundColor:white; position:absolute; color:#aaaaaa")
	} else {
		sfondo.style.display = "block";
		sfondo.style.cursor = "wait";
		var wwait = $.CM_getEl("winwait2244");
		wwait.style.display = "block";
	}
	if (solosfondo) {
		$.CM_getEl("winwait2244").style.display = "none";
	}
};
jQuery.CM_WaitHide = function(onlyMessage) {
	var x=setTimeout(function(){
		var sfondo = $.CM_getEl("sfondo2244");
		var wwait = $.CM_getEl("winwait2244");
		if (sfondo) {
			wwait.style.display = "none";
			if(!onlyMessage){
				sfondo.style.display = "none";
				sfondo.style.cursor = "auto";
			}
		}
	},700)
};

jQuery.CM_remove_path= function(path_file) {
				var sfile="";var pt=-1
				var cs=String.fromCharCode(92)
				var s=path_file
				for (var i=s.length-1; i>-1; i--) {
							if (s.substr(i,1)==cs) {
									pt=i
									break;	
							}
				}
				if (pt>-1) {
						s=s.substr(pt+1)
				}
				return(s)
}






/********************************************************

//		ESTENSIONI X TABELLE

********************************************************/

// Aggiunge una colonna alla tabella
// se indexcol=0 l'aggiunge alla prima
// se no alla fine
jQuery.TABLE_addColumn=function(objtable,indexcol){
	if(indexcol==0){
	
	}else{
		for(var r=0;r<objtable.rows.length;r++){
			objtable.rows[r].insertCell(-1)
		}
	}
};


// Ritorna la cella della tabella
jQuery.TABLE_Cell=function(objTable,row, col,Htmlvalue) {
	if (objTable.tagName.toLowerCase() != "table"){return("No table")}
	if(Htmlvalue)
		{objTable.rows[row].cells[col].innerHTML=Htmlvalue;}
	else
		{return (objTable.rows[row].cells[col]);}
};

// Ritorna la riga della tabella
jQuery.TABLE_Row= function(objTable, row,Htmlvalue) {
	if (objTable.tagName.toLowerCase() != "table"){return ("No table")}
	if(Htmlvalue){
		objTable.rows[row].innerHTML=Htmlvalue
	}else{
		return (objTable.rows[row]);
	}
};

// Mette le righe in una tabella + gli eventi e gli id
jQuery.TABLE_AddRows = function(table, nrows, ncols, rows_id, cols_id, rowsEvents, colsEvents, arrayData, columnsWidth, editable, editablestyle, cellsstyle, editEvents,rowsStyle,colsStyle) {
	///	<summary>
	///		1: Aggiunge righe e colonne alla tabella compresi gli eventi e i dati
	///	</summary>
	///	<param name="table" type="Object">
	///		table - Oggetto tabella alla quale aggiungere i parametri
	///	</param>
	///	<param name="event" type="String">
	///		event - Evento da assegnare es: "click".
	///	</param>
	///	<param name="handler" type="function">
	///		handler - Puntatore della funzione esterna.
	///	</param>
	if (typeof (table) == "string") {
		table=document.getElementById(table);
	}
	
	if (!table){return ("Tabella inesistente")}

	if (typeof (arrayData) == "string") {
		var tarr = arrayData.split(",");
		arrayData = new Array(tarr);
	}
	// imposto columnswidth
	if (columnsWidth) { columnsWidth = columnsWidth.split(","); } //else { columnsWidth = new Array("100px", "100px") }
	if (table.style.font) { var ofont = table.style.font } else { ofont = "" }
	var edev = "";
	if (editEvents) {
		for (ev = 0; ev < editEvents.length; ev += 2) {
			var edf=editEvents[ev + 1].toString().substr(9,editEvents[ev + 1].toString().indexOf("(")-9)
			edev += "on" + editEvents[ev] + "='" + edf + "(this)' ";
		} 
	}
	if(!columnsWidth){
			/*
			var cw=new Array()
			var or=table.parentNode.getBoundingClientRect()
			var wc=parseInt((or.right-or.left)/ncols)//+"px"
			//alert(wc+","+or+" width: "+table.style.width+", orwidth:"+or.right)
			for(var xc=0; xc<ncols; xc++){
				cw.push(wc)
			}
			columnsWidth=cw//.join(",")
			*/
	}
	for (var r = 0; r < nrows; r++) {
		var or = table.insertRow(-1);
		if (rows_id){or.id = rows_id + (r).toString()};
		if(rowsStyle){}
		
		
		if (rowsEvents) {
			for (var ev=0;ev<rowsEvents.length;ev+=2){
				$(or).CM_Event(rowsEvents[ev], rowsEvents[ev+1]);
			}
		}
		for (var c = 0; c < ncols; c++) {
			var oc = or.insertCell(-1);
			if (cols_id) {oc.id = cols_id + (c).toString()}else{oc.id=table.id+"-"+r+"-"+c}
			if(colsStyle){
				$(oc).cssEX(colsStyle);
			}
			if(columnsWidth){
				oc.style.width=columnsWidth[c];
				//alert(columnsWidth[c]);
			}
			if (colsEvents) {
				for (ev=0;ev<colsEvents.length;ev+=2){
					$(or).CM_Event(colsEvents[ev], colsEvents[ev+1]);
				}
			}
			
			var dtx="";
			var fillwith_spaces=(table.border==1)?true:false
			
			//if(r==0) alert(arrayData[r][c]);
			try	{
			if(arrayData.constructor==Array){
				if(arrayData[r][c]){dtx=arrayData[r][c]};
			}}catch(e){}
			if(editable&&table.rows[0].cells[c].innerHTML.toLowerCase()!="id"){
				if(editEvents){
					if(editablestyle){
						$(oc).append("<textarea "+edev+" id=ta-"+oc.id+" style='"+editablestyle+"'>"+dtx+"</textarea>");
					}else{
						//if(r==0) alert(dtx)
						//oc.innerHTML="<input type=text value="+dtx+" />"
						$(oc).append("<textarea "+edev+" id=ta-"+oc.id+" style='border:solid 0px white; width:100%; "+ofont+"'>"+dtx+"</textarea>");
					}
				}
			}else{
				// Ho inserito il div perchè nn fa word wrap con FF e Chrome
				
				//$("<div style='position:relative; overflow:hidden; text-overflow:ellipsis; '>"+dtx+"</div>").appendTo(oc)  //border:solid 1px red  //width:60px; 
				
				with(oc.style){
				position="relative"
				oveflow="hidden"
				textOverflow="ellipsis"
				wordWrap="break-word"
				}
				if(columnsWidth){
					//alert("Col "+c+": "+columnsWidth[c])
					oc.style.width=columnsWidth[c]+"px"
				}
				if(dtx==""){
					if(fillwith_spaces){
						oc.innerHTML=" " //"&nbsp;";
					}
				}else{
					oc.innerHTML =dtx;
					oc.title=dtx;
				}
				/*
				if(columnsWidth>""){
					//oc.innerHTML ="<div id="+oc.id+" style='position:relative; overflow:hidden; text-overflow:ellipsis; width:"+columnsWidth[c]+"px;'>"+dtx+"</div>"; 
					//oc.innerHTML ="<div id="+oc.id+" style='position:relative; overflow:hidden; text-overflow:ellipsis; width:"+columnsWidth[c]+"px;'>"+dtx+"</div>"; 
					oc.id=""
				}else{
					oc.innerHTML =dtx;
				}
				*/
			}
			
		}
	}
};


// estensioni jquery selector aggiunge righe  e colonne as una tabella
jQuery.TABLE_addRowsCells = function(rows,cols,arrayHTMLcols, options){
		defaultopt={
			columnsEditable: "none",
			setHtmlCol: function(col){},
			header: "",
			headerColor: "",
			headerBackgroundColor: ""
		
		}
		var settings = jQuery.extend({}, defaultopt, options);
		for(var r=0;r<rows;r++){
			var or=this[0].insertRow(-1);
			for (var c=0;c<cols;c++){
				var oc=or.insertCell(-1)
				oc.id=this[0].id+"-"+r+"-"+c;
				if(settings.header&&r==0){
					oc.innerHTML=settings.header.split(",")[c];
					if(settings.headerColor){
						oc.style.color=settings.headerColor;
					}
					if(settings.headerBackgroundColor){
						oc.style.backgroundColor=settings.headerBackgroundColor;
					}
				}else{
					//oc.innerHTML="aa";	
					if(arrayHTMLcols){
						if(arrayHTMLcols[c]){
							oc.innerHTML=arrayHTMLcols[c];
						}
					}
				}
		}}
		//return(this)
};


jQuery.TABLE_fill= function(data,firstrow){
		var rowdata=data.split(SEP_VT);
		var initrow=0;
		if(firstrow) initrow=firstrow;
		for(var r=initrow;r<rowdata.length;r++){
			var coldata=rowdata[r].split(SEP_OR);
			for(var c=0; c<coldata.length; c++){
				this[0].rows[r].cells(c).innerHTML=coldata[c];
			}
		}

};

// Rimuove le celle della tabella
jQuery.TABLE_RemoveAllCell= function(objTable, intZeroBasedFirstRow) {
	//try{
	if(intZeroBasedFirstRow)
			{np=intZeroBasedFirstRow}
		else	
			{np=0}
	var TR=objTable.rows.length;
	//try{
		while(TR>np){
			objTable.deleteRow(-1);
			if(!objTable.rows){break}
			TR=objTable.rows.length;
		}
	//}catch(e){}
	return
	
	for(var r=np;r<objTable.rows.length;r++){
		objTable.deleteRow(-1);
	}
	//}catch(e){}
	return

	$.each(objTable.rows, function(i, item) {
		var fr=0;
		if(firstRowToRemove){fr=firstRowToRemove}
		//alert(i+", "+fr);
		if(i>fr-1){
			try{
			objTable.deleteRow(-1);}
			catch(e){}
		}})
};


jQuery.TABLE_setOverColor=function(strtable,overcolor,firstrow){
	if(firstrow){
		$("#"+strtable+" tr:gt("+(firstrow-1)+")").mouseenter(function(){
			this.olbgcolor=this.style.backgroundColor
			this.style.backgroundColor=overcolor;
		})
		$("#"+strtable+" tr:gt("+(firstrow-1)+")").mouseleave(function(){
			this.style.backgroundColor=this.olbgcolor;//"";
		})
	}else{
		$("#"+strtable+" tr").mouseenter(function(){
			this.olbgcolor=this.style.backgroundColor
			this.style.backgroundColor=overcolor;
		})
		$("#"+strtable+" tr").mouseleave(function(){
			this.style.backgroundColor=this.olbgcolor;//"";
		})
	}
};

// estensioni prototype (tipo) x tabelle
jQuery.fn.TABLE_extensions=function(table){
	return this.each(function(){
						var vthis=this
						this.cell=function(row,col){
							return vthis.rows[row].cells[col]
						}
						this.cellEx=function(row,col,innerHTML,css){
							if(innerHTML) vthis.rows[row].cells[col].innerHTML=innerHTML;
							if(css) {
								$(vthis.rows[row].cells[col]).cssEX(css);
							}
							return vthis.rows[row].cells[col]
						}

	})
};


jQuery.TABLEGRID = function(id,container,squery,Left_Top_width_height,styleHeader,styleGrid,isvirtual,iseditable,colsWidth){
			
			if(typeof(container)=="string"){container=document.getElementById(container)}
			if(!container){alert("no container");return "no container"}
			
			// proprietà generali
			this._left="1px";this._top="1px";this._width="300px";this._height="200px"
			this.virtual=isvirtual;
			this.rows=0;
			this.cols=0;
			this.visibleRows=0;
			this.visibleCols=0;
			this.defaultColWidth=120;
			this._columnsWidth="80,80";
			this.widthGrid=300;
			this.heightGrid=200;
			this.grid="";
			this.header="";
			this.campi="";
			this._overRowColor="";
			this._alternateColor="";
			this.iseditable=iseditable;
			this.editCell=jQuery.CM_createObj("textarea",document.body,id+"_txa","","","display:none")
			this._colsWidth="";
			var _this=this
			
			// container generale
			var st="border:solid 1px gray; display:none; left:1px; top:1px; width:300px; height:200px; overflow:hidden; backgroundColor:white; position:absolute"
			var tg_divmain=jQuery.CM_createObj("div",container,id+"_divmain","","",st);this.divMain=tg_divmain
			
			
			// Header
			st="position:relative; left:0px; top:0px; width:300px; height:20px; backgroundColor:maroon; color:white; font:bold 12px Arial,Helvetica"
			var tg_header=jQuery.CM_createObj("table",tg_divmain,id+"_header","","",st,"","",1,3,true);this.header=tg_header
			jQuery.TABLE_Cell(tg_header,0,0,"Colonna 1");jQuery.TABLE_Cell(tg_header,0,1,"Colonna 2");jQuery.TABLE_Cell(tg_header,0,2,"-")
			jQuery.TABLE_Cell(tg_header,0,0).style.width="120px";
			jQuery.TABLE_Cell(tg_header,0,1).style.width="120px";
			jQuery.TABLE_Cell(tg_header,0,2).style.width="60px";
			jQuery("#"+id+"_header td").mousemove(function(e){
					//$("#debug").text("qui"+e.clientX)		
			})
			jQuery("#"+id+"_header td").each(function(i,o){
				$("<div id=cell-"+o.id+" ></div>").appendTo(o)
			})
			
			
			
			// Grid container e grid
			st="position:relative; overflow:hidden; left:1px; top:1px; width:297px; height:172px"
			var tg_gridContainer=jQuery.CM_createObj("div",tg_divmain,id+"_gridContainer","","",st);this.gridContainer=tg_gridContainer
			var nscroll=0;
			jQuery(tg_gridContainer).scroll(function(e){
			
				/*			DEBUG
				$("#debug").text("qui"+$(tg_gridContainer)[0].scrollLeft)
				// Timer per dare la nuova videata ogni secondo
				//var tms=setTimeout(
				if($("#debug")[0]){
					nscroll+=1
					//$("#debug").text("qui "+nscroll)
				}
				FINE DEBUG					*/
				
				
				if(parseInt(_this.header.style.left)!=parseInt(_this.gridContainer.scrollLeft)){
					_this.header.style.left=(0-parseInt(_this.gridContainer.scrollLeft))+"px"
				}
			})
			
			st="position:relative; font:normal 12px Arial,Helvetica"
			if(styleGrid){st+=";"+styleGrid}
			var tg_grid=jQuery.CM_createObj("table",tg_gridContainer,id+"_grid","","",st,"cellSpacing:1,cellPadding:1","","","",true)//,"","",10,2,true)
			this.grid=tg_grid;
			var data=new Array()
			if(squery){var nrows=2}else{nrows=200}
			for(var r=0;r<nrows;r++) {data[r]=new Array(); for(var c=0;c<2;c++){ data[r][c]=r.toString()+c.toString() }}
			jQuery.TABLE_AddRows(tg_grid,nrows,2,"","","","",data)
			jQuery.TABLE_Cell(tg_grid,0,0).style.width="120px";
			jQuery.TABLE_Cell(tg_grid,0,1).style.width="120px";



			// dimensioni / Resize
			if(Left_Top_width_height){
				this._left=Left_Top_width_height.split(",")[0]
				this._top=Left_Top_width_height.split(",")[1]
				this._width=Left_Top_width_height.split(",")[2]
				this._height=Left_Top_width_height.split(",")[3]
				jQuery(tg_divmain).cssEX("left:"+this._left+"; top:"+this._top+"; width:"+this._width+"; height:"+this._height)
			}else{
				jQuery(tg_divmain).css({
					left:"1px",
					top:"1px",
					width:"300px",
					height:"200px"
				});
			}
			this._width=parseInt(tg_divmain.style.width)
			this._height=parseInt(tg_divmain.style.height)
			jQuery(tg_divmain).resize(this.resize)
			//resizeGrid()
			this.resize()
			
			
			// stili
			if(styleHeader){jQuery(tg_header).cssEx(styleHeader)}
			
			
			// draw
			tg_divmain.style.display="block";
			this.defaultRowHeight=tg_grid.rows[0].getBoundingClientRect().bottom-tg_grid.rows[0].getBoundingClientRect().top;
			
			
			
			// Query
			if(squery>""){
				
				query(squery)
				/*
				//tg_divmain.style.display="none";
					var dt=$.ajaxEx2(squery)
					this.grid.style.display="none"
					jQuery.TABLE_RemoveAllCell(this.grid)
					var editEvents=new Array("change",_event_Edit_Change);
					var cellevents=new Array("click",_event_click_cell,"change",_event_Edit_Change);
					var rowsEvents=new Array("mouseover",_event_overMouse_Row)
					jQuery.TABLE_AddRows(this.grid,dt.length,dt[0].length,"","",rowsEvents,cellevents,dt) //,"",false,"","",editEvents)
					this.grid.style.display="block"
					this.campi=jQuery.QUERY_retPart(squery,"campi").split(",")
					_this.heightGrid=this.defaultRowHeight*dt.length;
					var rt
					for(var r=0;r<tg_grid.rows.length;r++){
						tg_grid.rows[r].insertCell(-1);
						//rt=tg_grid.rows[r].getBoundingClientRect();
						//_this.heightGrid+=(rt.bottom-rt.top);
					}
					this.visibleRows=(this._height<this.heightGrid)?parseInt((this._height-parseInt(this.header.style.height))/this.defaultRowHeight):this.grid.rows.length
					this.resizeHeader(this.campi);
					this.resize()
				//tg_divmain.style.display="block";
				*/
				
			}
			
			function _event_overMouse_Row(e){
					if(_this._overRowColor>""){
						//alert(_this._alternateColor)
						for(var r=0;r<_this.visibleRows;r++){
							if(_this.grid.rows[r].alternate){
								_this.grid.rows[r].style.backgroundColor=_this._alternateColor
							}else{
								_this.grid.rows[r].style.backgroundColor=""
							}
						}
						var o=$.browser.msie?e.srcElement:e.target
						o.parentNode.style.backgroundColor=_this._overRowColor
					}
			}
			
			function _event_Edit_Change(e){
			//this._event_Edit_Change = function(e){
						//alert("change")
						var o=$.browser.msie?e.srcElement:e.target
						var row=o.parentNode.parentNode
						//alert(row)
						//row.cells[0].style.border="1px solid red"
						
						//row.style.border="1px solid red"
						//o.parentNode.style.border="1px solid red"
			}
			function _event_click_cell(e){
						
						if(!_this.iseditable){return}
						
						var o=$.browser.msie?e.srcElement:e.target
						
						
						//alert(o.tagName+","+o.innerHTML)
						if(o.tagName.toLowerCase()!="textarea"&&o.innerHTML.toLowerCase().indexOf("</textarea>")==-1){
							
							if(o.tagName.toLowerCase()=="td"){
									//alert(_this.editCell.parentNode.tagName)
									var savetext=false;var pn
									var parentTa=$.browser.msie?_this.editCell.parentElement:_this.editCell.parentNode;
									//alert(parentTa.tagName)
									if(parentTa){
												if(parentTa.tagName.toLowerCase()!="body"){
													savetext=_this.editCell.value
													//alert("save "+savetext)
													pn=parentTa  //_this.editCell.parentNode
												}
											
												_this.editCell.value=o.innerHTML;
												var rt=o.getBoundingClientRect()
												_this.editCell.style.width=rt.right-rt.left//-4
												_this.editCell.style.height=rt.bottom-rt.top-3
												//alert(_this.editCell.style.width+","+_this.editCell.style.height)
												_this.editCell.style.margin="0px";
												_this.editCell.style.padding="0px";
												_this.editCell.style.font="normal 12px Arial,Helvetica"
												_this.editCell.style.overflow="hidden"
												_this.editCell.style.border="none" //"solid 1px blue"// 
												_this.editCell.style.zIndex="10"
												o.innerHTML="";
												o.appendChild(_this.editCell)
												_this.editCell.style.display="block"
												
												if(typeof(savetext)=="string"&&pn){
													pn.innerHTML=savetext
												}
												try{var rr=setTimeout(_this.editCell.focus(),200)}catch(e){}
												//alert(o.innerHTML)
									}
								}
						}
			}
			function _event_dbclick_cell(e){
				//alert(e)
				try{_this.onDblClick(e)}catch(er){}
				
			}
			
			function query(q){
					var dt=$.ajaxEx2(q)
					_this.grid.style.display="none"
					jQuery.TABLE_RemoveAllCell(_this.grid)
					var editEvents=new Array("change",_event_Edit_Change);
					var cellevents=new Array("click",_event_click_cell,"change",_event_Edit_Change,"dblclick",_event_dbclick_cell);
					var rowsEvents=new Array("mouseover",_event_overMouse_Row)
					_this._colsWidth=""
					jQuery.TABLE_AddRows(_this.grid,dt.length,dt[0].length,"","",rowsEvents,cellevents,dt) //,"",false,"","",editEvents)
					_this.grid.style.display="block"
					_this.campi=jQuery.QUERY_retPart(q,"campi").split(",")
					_this.heightGrid=_this.defaultRowHeight*dt.length;
					_this.cols=dt[0].length
					var rt
					for(var r=0;r<_this.grid.rows.length;r++){
						_this.grid.rows[r].insertCell(-1);
						//rt=tg_grid.rows[r].getBoundingClientRect();
						//_this.heightGrid+=(rt.bottom-rt.top);
					}
					//alert(_this.cols+"  ,  "+_this._colsWidth)
					if(_this._colsWidth==""){
						var a=new Array()
						var or=_this.grid.parentNode.getBoundingClientRect()
						var w=parseInt((or.right-or.left)/_this.cols)
						for( var c=0;c<_this.cols; c++){
							a.push(w)
						}
						_this._colsWidth=a
						//alert(_this._colsWidth)
					}
					_this.visibleRows=(_this._height<_this.heightGrid)?parseInt((_this._height-parseInt(_this.header.style.height))/_this.defaultRowHeight):_this.grid.rows.length
					_this.resizeHeader(_this.campi,_this._colsWidth);
					_this.resize()
			}
			this.query=query
			
			
			return(this)

};

jQuery.TABLEGRID.prototype={
			hide:function(){
				$(this.divMain).hide()
			},
			show:function(){
				$(this.divMain).show()
			},

			height:function(newheight){
				this._height=newheight;
				this.resize()
			},
			width:function(newwidth){
				this._width=newwidth;
				this.resize()
			},
			resize:function resizeGrid(){
				if(this.divMain){
					this.divMain.style.width=this._width+"px"
					this.divMain.style.height=this._height+"px"
					this.gridContainer.style.top="1px"
					var stepie=$.browser.msie?3:0
					if(this._width<this.widthGrid){
						//this.header.rows[this.header.rows.length-1].style.width=
						this.gridContainer.style.width=(parseInt(this._width)-stepie)+"px"
						this.gridContainer.style.height=(this._height-parseInt(this.header.style.height)-stepie)+"px"
					}else{
						this.gridContainer.style.width=(parseInt(this._width)-stepie)+"px"
						this.header.style.width=this._width+"px"
						this.gridContainer.style.height=(this._height-parseInt(this.header.style.height)-stepie)+"px"
					}
					//this.resizeHeader(this.campi)
					//tg_grid.width=
					//alert("new w "+this.gridContainer.style.width)
					this.gridContainer.style.overflowX=(this._width<this.widthGrid)?"auto":"hidden";
					this.gridContainer.style.overflowY="auto" //(this._height<this.heightGrid)?"auto":"hidden";
					//alert(this.gridContainer.style.overflowY)
					
				}
			},
			resizeHeader:function headerColumns(columns,width){
					if(width){
						if(typeof(width)=="string"){var v_width=width.split(",")}else{v_width=width}
					}
					this._columnsWidth="",virg="";
					this.widthGrid=0;
					jQuery.TABLE_RemoveAllCell(this.header)
					var orw=this.header.insertRow(-1); var WidthTotCol
					//this.gridContainer.style.width=this._width+"px"
					//this.header.style.width=this._width+"px"
					for(c=0;c<columns.length+1;c++){
						if(c==columns.length){
							if(this.widthGrid>this._width){
								// empty
								var oc=this.header.rows[0].insertCell(-1)
								oc.style.width=20
								this.header.style.width=(this.widthGrid+20)+"px"
								//_this.header.rows[0].cells[
								this.grid.style.width=this.widthGrid+"px"
							}else{
								this.header.style.width=this.divMain.style.width
								this.gridContainer.style.width=this.header.style.width
								this.grid.style.width=this.header.style.width
								var ocol=orw.insertCell(-1);
								ocol.style.width=(this._width-this.widthGrid)+"px";
								ocol.innerHTML="--";
								if(this.grid.rows.length>0){
									//var nr=this.grid.rows[0].insertCell(-1)
									this.grid.rows[0].cells[c].style.width=ocol.style.width
									//nr.style.width=ocol.style.width
									//nr.innerHTML="ppppp"
								}
							}
						}else{
							ocol=orw.insertCell(-1);
							$("<div style='position:relative; overflow:hidden; text-overflow:ellipsis; width:60px; border:solid 1px white'>"+$.QUERY_removebrackets(columns[c])+"</div>").appendTo(ocol)
							/*
							ocol.style.position="relative"
							ocol.style.oveflow="hidden"
							ocol.style.textOverflow="ellipsis"
							*/
							//alert(v_width)
							if(v_width){
								ocol.style.width=v_width[c]+"px";
								this._columnsWidth+=v_width[c]+virg;virg=",";
								ocol.innerHTML=$.QUERY_removebrackets(columns[c])
								this.widthGrid+=v_width[c];
								if(this.grid.rows.length>0){
									this.grid.rows[0].cells[c].style.width=ocol.style.width
								}
							}else{
								ocol.style.width=this.defaultColWidth.toString()+"px";
								this._columnsWidth+=this.defaultColWidth.toString()+virg;virg=",";
								//ocol.innerHTML=$.QUERY_removebrackets(columns[c])
								this.widthGrid+=this.defaultColWidth;
								if(this.grid.rows.length>0){
									this.grid.rows[0].cells[c].style.width=ocol.style.width
								}
							}
						}
					}
					//alert(this.grid.style.width+","+this.header.style.width+","+this.gridContainer.style.width)
					
			},
			alternateRowColor:function(color){
							var colr=""
							if(color.toLowerCase()=="none"){colr=""}else{colr=color}
							this._alternateColor=colr;
							for(var r=0;r<this.grid.rows.length;r++){
								if(r%2==0){
									this.grid.rows[r].style.backgroundColor=colr
									this.grid.rows[r].alternate=true;
								}else{
									this.grid.rows[r].alternate=false;
								}
							}
						},
			overRowColor:function(color){
							this._overRowColor=color;
						},
			columnsWidth:function(colsWidth){
							var v=colsWidth.split(",")
							var _this=this
							$.each(v,function(i, item){
								if(_this.grid.rows.length>0){
									_this.grid.rows[0].cells[i].style.width=parseInt(item)+"px"
									//alert("width col "+i+","+_this.grid.rows[0].cells[i].style.width)
								}
								_this.header.rows[0].cells[i].style.width=parseInt(item)+"px"
							})
							
							
							
							//this.resizeHeader(this.campi,colsWidth)
			},
			colWidth:function(columnindex, widthPixel){
							
							
							
							
			
			}
			
			
};



jQuery.EDITFIELDS = function(id,container,query,Left_Top_width_height,styleLabels,styleEditFields){
			//  Gruppo di fields editabili da database
			
			// container generale
			if(typeof(container)=="string"){container=document.getElementById(container)}
			if(!container){alert("no container");return "no container"}
			this.divmain=jQuery.CM_createObj("div",container,id+"_divmain","","",st);
			
			// Tabella per contenere i campi
			this.tbfields=jQuery.CM_createObj("table",this.divmain,id+"_tbfields","","","","border:1","",3,2)
			
			
			// Campi
			this.fields=new Array()
			
					// test
					for (var c=0;c<10;c++){
						
						var fl=jQuery.CM_createObj("input",this.tbfields.rows[c].cells[1],id+"_fl"+c,"","","","type:text,value:prova")
						
						
						this.fields.push(fl)
					
					}
			


};


/********************************************************

//		ESTENSIONI X DATABASE

********************************************************/

jQuery.DATA_getFieldsFromResponseRequestObj = function(sResponse) {
	// Ritorna un array doppio dai dati del response
	try {
		var art=[];
		var arv = sResponse.split(SEP_VT);
		for(var r=0;r<arv.length;r++){
			art[r]=arv[r].split(SEP_OR);
		}
		return art	
	} catch (e) {jQuery.CM_alertDebug("Error DATA_getFieldsFromResponseRequestObj="+e.description)}
	
};







/********************************************************

//		ESTENSIONI X WINDOWS

********************************************************/

jQuery.WIN_add = function(id, position, size,title,bcenter,round_border) {
	if (size) {
		var width = size.split(",")[0];
		var height = size.split(",")[1];
	}else{
		width = "200px";
		height = "100px";
	}
	if (position) {
		var leftpos = position.split(",")[0];
		var toppos = position.split(",")[1];
	}else{
		if(bcenter){
			leftpos = (parseInt(document.body.clientWidth)/2-parseInt(width)/2)+"px";
			toppos = (parseInt(document.body.clientHeight)/2-parseInt(height)/2)+"px";
		}else{
			leftpos = "10px";
			toppos = "10px";
		}
	}
	var sstyle = "border:solid 1px blue; left:" + leftpos + "; top:" + toppos + "; width:" + width + "; height:" + height + "; backgroundColor:white; position:absolute "; //position:absolute
	var divmain = $.CM_createObj("div", document.body, id, "", "", sstyle);
	sstyle = "backgroundColor:black; border:solid 1px black; color: white; height:22px; cursor:move; paddingLeft:4px; paddingTop:3px; fontWeight:bold";
	if(!title) title="Window "+id
	var divcaption = $.CM_createObj("div", divmain, id + "-caption", title, "", sstyle);
	if(width.indexOf("%")>-1){var wd="width: "+(parseInt(document.body.clientWidth)/100*parseInt(width))+"px";}else{wd="width:"+(parseInt(width)-4)+"px;"}
	if(height.indexOf("%")>-1){var hd="height: "+((parseInt(document.body.clientHeight)-2)/100*parseInt(height)-70)+"px";}else{hd="height:"+(parseInt(height)-60)+"px"}
	var divclient = $.CM_createObj("div", divmain, id + "-client","","", "overflow:auto; left:1px; top:1px;"+hd+"; "+wd );
	//alert($(divmain)[0]); 
	if(round_border){
		$("#"+id).bg(8);
		$(divcaption).bg(['8px','8px','0px','0px']);
	}
	$("#"+id).draggable({
		drag: function(e){}, handle: divcaption // '#'+id+'-caption' //alert("move"+e.srcElement.style.left)
	}) 
	return(divclient)	
};

jQuery.WIN_close=function(id){
	if($("#"+id)[0]){
		document.body.removeChild($("#"+id)[0])
	}
};


jQuery.WIN_hide=function(id_or_object){
	if($(id_or_object)[0]){
		$(id_or_object)[0].style.dysplay="none"
	}else{
		id_or_object.style.display="none"
	}
};






/********************************************************

//		ALTRE VARIE

********************************************************/

$.fn.ellipsis = function(enableUpdating){
		var s = document.documentElement.style;		
		if (!('textOverflow' in s || 'OTextOverflow' in s)) {
			return this.each(function(){
				var el = $(this);
				if(el.css("overflow") == "hidden"){
					var originalText = el.html();
					var w = el.width();
					
					var t = $(this.cloneNode(true)).hide().css({
                        'position': 'absolute',
                        'width': 'auto',
                        'overflow': 'visible',
                        'max-width': 'inherit'
                    });
					el.after(t);
					
					var text = originalText;
					while(text.length > 0 && t.width() > el.width()){
						text = text.substr(0, text.length - 1);
						t.html(text + "...");
					}
					el.html(t.html());
					
					t.remove();
					
					if(enableUpdating == true){
						var oldW = el.width();
						setInterval(function(){
							if(el.width() != oldW){
								oldW = el.width();
								el.html(originalText);
								el.ellipsis();
							}
						}, 200);
					}
				}
			});
		} else return this;
	};
//})(jQuery);



/********************************************************

//		STRING

********************************************************/
$.STRING_TrimNoChar = function(tx){
	var re=/\w/
	tx=re.exec(tx);
	return(tx)
};



/********************************************************

//		EFFETTI // GRAFICA

********************************************************/
jQuery.carousel = function(name, container, width, height, fixedimgaewidth, images, incspeed_10to100, type_of_animation, logo, titoli) {
	if (!name) return

	var DIVCOVER, DIVZOOM, DIVMAIN, DIVSTATUS, DIVCAROUSEL
	this.name = name;
	DIVMAIN = document.getElementById(name)
	if (!DIVMAIN) {
		DIVCAROUSEL = document.createElement("div");
		DIVMAIN = document.createElement("div");
		var otb = document.createElement("table");
	}

	DIVMAIN.style.width = width;
	DIVMAIN.style.height = height;
	DIVMAIN.style.border = "solid 1px gray";
	DIVMAIN.style.overflow = "hidden";
	DIVMAIN.id = name

	DIVCAROUSEL.style.width = DIVMAIN.style.width;
	DIVCAROUSEL.style.height = (parseInt(height) - 10) + "px";
	//DIVCAROUSEL.style.border="solid 1px red";
	DIVCAROUSEL.style.overflow = "hidden";

	DIVMAIN.appendChild(DIVCAROUSEL)

	DIVSTATUS = document.createElement("div")
	$(DIVSTATUS).css({
		//border: "solid 1px blue",
		textAlign: "center",
		font: "bold 8px Arial"
	})
	DIVMAIN.appendChild(DIVSTATUS)
	this.divmain=DIVMAIN
	 
	this.srtStatus = ""

	this.imglogo = ""

	otb.id = name + "_tbimages";
	otb.style.position = "relative";
	otb.cellPadding = 0;
	otb.border = 0;
	otb.style.left = "0px"
	otb.style.height = (parseInt(DIVCAROUSEL.style.height) - 2) + "px";
	var or = otb.insertRow(-1)
	//var ximages="<tr>"
	var nimm = 10
	if (images.indexOf(",") > -1) {
		this.array_simg = images.split(",")
		nimm = this.array_simg.length
		this.nImages = nimm
		this.useimage_directoryauto = false
	} else {
		this.nImages = 0

	}
	if (type_of_animation == "swift") {
		//nimm+=2
		//this.array_simg.unshift(this.array_simg[this.array_simg.length-1])
		//this.array_simg.push(this.array_simg[0])
	}
	
	
	this.padding_right_images="4px"
	
	for (var i = 0; i < nimm; i++) {

		var oim = new Image()
		oim.style.visibility="hidden"
		if (images.indexOf(",") > -1) {
			oim.src = this.array_simg[i]
		} else {
			oim.src = images + (i + 1).toString() + ".jpg"
		}
		oim.id = name + "_" + i
		ocell = or.insertCell(-1)
		ocell.style.paddingRight = this.padding_right_images
		ocell.valign = "center";
		ocell.appendChild(oim)

	}
	DIVCAROUSEL.appendChild(otb)
	
	
	//  DRAG DELLE IMMAGGINI
	this.disablezoom = false
	var _this = this
	$(otb).draggable({
		axis: "x",
		start: function(e, ui) {
			_this.disablezoom = true
			$(_this.div_title).hide()
			$(_this.div_title_text).hide()
			$.each(_this.array_oimgx, function(i, item) {
				$(item).fadeTo(0, 1)
			})
			if(_this.imglogo){
				_this.imglogo.style.display="none"
			}

		},
		stop: function() {
			var i = setTimeout(function() {
				_this.disablezoom = false
				stepdone=49
				$(_this.div_title).show()
				$(_this.div_title_text).show()
			}, 200)
		}
	})







	this.otable = otb
	this.div_carousel = DIVCAROUSEL
	this.div_main = DIVMAIN



	if (typeof (container) == "string") {
		$(container).add(DIVMAIN)
	} else {
		container.appendChild(DIVMAIN)
	}



	// metto il logo che appare nei punti vuoti a sinistra e poi a destra
	this.rect_divmain=null
	if (logo && type_of_animation == "swift") {
		if (!this.imglogo) {
			this.imglogo = new Image()
		}
		this.imglogo.src = logo
		var f=setTimeout(function(){
			_this.imglogo.align = "left"
			_this.imglogo.style.display = "block"
			_this.rect_divmain = DIVMAIN.getBoundingClientRect();
			$(_this.imglogo).css({
				position: "absolute",
				left: (_this.rect_divmain.left+20)+"px",
				top: (((_this.rect_divmain.bottom-_this.rect_divmain.top)/2)+_this.rect_divmain.top-(parseInt(_this.imglogo.height)/2))+"px"
				//float: "left"
			})
			//DIVCAROUSEL.appendChild(this.imglogo)
			_this.imglogo.style.zIndex=100
			document.body.appendChild(_this.imglogo)
			$(_this.imglogo).fadeTo(0,0.9)
		},1000)
	}


	// Titoli e descrizioni sulle foto
	this.titoli=[]
	if(titoli){
		this.titoli=titoli.split(",")
		this.div_title=document.createElement("div")
		this.div_title.style.position="absolute"
		this.div_title.innerHTML="&nbsp;"
		this.div_title.style.zIndex=100
		this.div_title.style.color="white"
		this.div_title.style.font="normal 9pt Arial"
		this.div_title.align="center"
		//this.div_title.style.border="solid 1px white"
		this.div_title.style.backgroundColor="gray"
		$(this.div_title).fadeTo(0,0.6)
		this.div_title.style.visibility="hidden"
		document.body.appendChild(this.div_title)
		
		this.div_title_text=document.createElement("div")
		this.div_title_text.style.font="normal 9pt Arial"
		this.div_title_text.style.color="white"
		this.div_title_text.style.position="absolute"
		this.div_title_text.innerHTML="&nbsp;"
		this.div_title_text.style.visibility="hidden"
		//this.div_title_text.style.border="solid 2px red"
		this.div_title_text.align="center"
		this.div_title_text.style.zIndex=101
		document.body.appendChild(this.div_title_text)
		
	}
	
	

	// Carico le immagini e le punto sull'array
	this.current_title=""
	var widthtotimages = 0
	this.isShowZoom = false
	this.disablescroll = false;
	this.array_oimgx = new Array()
	var tt = setTimeout(function() {
		for (var i = 0; i < nimm; i++) {
			var imgx = document.getElementById(name + "_" + i)
			_this.array_oimgx.push(imgx)
			var std_height_img = parseInt(DIVCAROUSEL.style.height) - 6
			if (parseInt(imgx.height) > std_height_img) {
				var rapp = parseInt(imgx.height) / parseInt(imgx.width)
				imgx.height = std_height_img
				imgx.width = std_height_img / rapp
			}
			widthtotimages += imgx.width;
			imgx.title = "Fai click sull'immagine per ingrandire"
			imgx.titolo=_this.titoli[i]
			$(imgx).click(function() {
				// Zoom dell'immagine
				if (_this.disablezoom != true) {
					_this.disablescroll = true
					_this.isShowZoom = true
					// rimuovo 'compressed' dalla dir
					var newfoto=this.src.replace(/compressed/i,"")
					zoom(newfoto,this.titolo,function() {
						_this.disablescroll = false
						_this.isShowZoom = false
					})
				}

			})
			/*
			if (imgx.width < 38) {
				_this.nImages = i//-1
				for (var c = i; c < 10; c++) {
					try{
					imgx = document.getElementById(name + "_" + c)
					imgx.parentNode.removeChild(imgx)}catch(e){}
				}
				break
			}
			*/
		}
		
		//_this.otable=document.getElementById(name+"_tbimages")
		_this.otable.style.width = widthtotimages + "px"
		var color = "white"
		for (i = 0; i < _this.nImages; i++) {
			_this.srtStatus += "<span style='color:" + color + ";'>&#9679;</span>"
			color = "gray"
			$("#" + name + "_" + i).mouseover(function() {
				_this.disablescroll = true;
			}).css("cursor", "pointer").css("cursor", "hand").mouseleave(function() {
				try {
					if (_this.isShowZoom != true) {
						_this.disablescroll = false;
					} 
				} catch (er) { _this.disablescroll = false; }

			})
		}
		DIVSTATUS.innerHTML = _this.srtStatus
	}, 800)

	
	
	


	var inc = 1, currentimage = 0
	var stepdone = 0, nimgdone_step = 0
	if (incspeed_10to100) { var speed = incspeed_10to100 } else { speed = 30 }
	var widthdiv = parseInt(width);
	var left_zero = 0

	
	var t2=setTimeout(function(){
			//alert("aa "+DIVMAIN.style.width+","+widthtotimages)
			if (widthtotimages < parseInt(DIVMAIN.style.width)) {
				//DIVMAIN.style.width=(widthtotimages)+"px"
				//alert("qq "+DIVMAIN.style.width)
				_this.disablescroll=true
				$.each(_this.array_oimgx, function(i, itm) {
					$(itm).show()
					itm.style.visibility="visible"
					//alert(itm)
				})
			}
	},1000)
	
	

	var d = setTimeout(function() {		// time out per load immagini ora di 1100 ms

		if (widthtotimages > parseInt(DIVCAROUSEL.style.width)) {

			if (type_of_animation == "swift") {
			
				// centro la prima immagine per lo swift
				//$(_this.otable).hide()
				//_this.otable.style.visiblity="hidden"
				_this.otable.style.left = (parseInt(_this.div_carousel.style.width) / 2) - (parseInt(_this.array_oimgx[0].width) / 2)
				var retro = false
				$.each(_this.array_oimgx, function(i, itm) {
					//if (i > 0) {
						$(itm).fadeTo(20, 0.2)
					//}
					itm.style.visibility="visible"
				})
				
				// titolo alla prima immagine
				_this.div_title.style.visibility="hidden"
				var p=setTimeout(function(){
					var rect_div_title=_this.div_title.getBoundingClientRect()
					var save_div_title_height=rect_div_title.bottom-rect_div_title.top
					_this.div_title.style.visibility="hidden"
					_this.div_title_text.innerHTML=_this.titoli[0]
					var rect_image=_this.div_carousel.getBoundingClientRect() // _this.array_oimgx[nimgdone_step].getBoundingClientRect()
					var rect_image2=_this.array_oimgx[0].getBoundingClientRect()
					//_this.array_oimgx[0].titolo_imm=_this.titoli[0]
					if(_this.div_title){
						
						_this.div_title.style.width=_this.array_oimgx[0].width+"px"
						var rect_div_titolo=_this.div_title.getBoundingClientRect() 
						_this.div_title.style.left=rect_image2.left+"px" //((rect_image.right-rect_image.left)/2+rect_image.left-((rect_div_titolo.right-rect_div_titolo.left)/2))+"px"			
						_this.div_title.style.top=(rect_image.bottom-(save_div_title_height)-6)+"px"
						
						with(_this.div_title_text.style){
							left=_this.div_title.style.left
							top=_this.div_title.style.top
							width=_this.div_title.style.width
							visibility="visible"
						}
						
						_this.div_title.style.visibility="visible"
						//_this.div_title.style.display="none"
						$(_this.array_oimgx[0]).fadeTo("normal",1)
						$(_this.div_title).fadeIn("fast")
					}
					//_this.otable.style.visiblity="visible"
					//$(_this.otable).show(200)
				},100)
				
			}else{
				
				$.each(_this.array_oimgx, function(i, itm) {
					itm.style.visibility="visible"
				})
				$(_this.array_oimgx[0]).fadeTo("normal",1)

			}

			// timer per lo scroll
			_this.timer = window.setInterval(function() {
			
				if(_this.divmain.style.display=="none"){
					_this.imglogo.style.display="none"
					return
				}
			
				if (widthtotimages > 0 && _this.disablescroll == false) {

					stepdone += 1
					if (type_of_animation == "swift") {

						//  ANIMAZIONE A SCATTI

						if (stepdone > 100000) { stepdone = 0 }
						if (stepdone % 50 == 0) {

							if (nimgdone_step == 0) {
								retro = false
							}
							if (nimgdone_step + 1 == _this.array_oimgx.length) {
								retro = true
							}

							if (retro) {
								nimgdone_step -= 1
								if (nimgdone_step == 0) {
									left_zero = 0//(parseInt(_this.divmain.style.width)/2)-(parseInt(_this.array_oimgx[0].width)/2)
								} else {
									left_zero += parseInt(_this.array_oimgx[nimgdone_step].width) + (nimgdone_step) * parseInt(_this.padding_right_images)
								}
								currentimage -= 1
							} else {
								nimgdone_step += 1
								currentimage += 1
								left_zero -= parseInt(_this.array_oimgx[nimgdone_step - 1].width) + (nimgdone_step) * parseInt(_this.padding_right_images)
							}

							var w_img = parseInt(_this.array_oimgx[nimgdone_step].width)
							var w_dim = parseInt(_this.div_carousel.style.width)
							var ptleft = ((w_dim / 2) - (w_img / 2)) + left_zero  //Math.abs((w_img/2)-(w_dim/2))
							
							var rect_div_title=_this.div_title.getBoundingClientRect()
							var save_div_title_height=rect_div_title.bottom-rect_div_title.top
							_this.div_title.style.display="none"
							_this.div_title_text.innerHTML=_this.titoli[nimgdone_step]
							this.current_title=_this.titoli[nimgdone_step]
							$(_this.otable).animate({
								left: ptleft //'-='+parseInt(_this.array_oimgx[nimgdone_step].width)
							}, 300,"",function(){
							
										// titolo dell'immagine (dopo l'animazione ovviamente)
										
										var rect_image=_this.div_carousel.getBoundingClientRect() // 
										var rect_image2=_this.array_oimgx[nimgdone_step].getBoundingClientRect()
										if(_this.div_title){
											
											_this.div_title.style.width=(parseInt(_this.array_oimgx[nimgdone_step].width)+0)+"px"
											var rect_div_titolo=_this.div_title.getBoundingClientRect() 
											_this.div_title.style.left=(rect_image2.left)+"px" //((rect_image.right-rect_image.left)/2+rect_image.left-((rect_div_titolo.right-rect_div_titolo.left)/2))+"px"
											_this.div_title.style.top=(rect_image.bottom-(save_div_title_height)-6)+"px"

											with(_this.div_title_text.style){
												left=_this.div_title.style.left
												top=_this.div_title.style.top
												width=_this.div_title.style.width
											}
										}
										$(_this.div_title).fadeIn("normal")
							
							})

							$.each(_this.array_oimgx, function(i, itm) {
								if (i != nimgdone_step) {
									$(itm).fadeTo(20, 0.4).css("border","");
								}
								if (i == nimgdone_step) {
									$(itm).css("border","solid 1px white");
								}
							})
							$(_this.array_oimgx[nimgdone_step]).fadeTo(20, 1)
							
							
							

							change_status(currentimage)
						
							// Se è la prima o ultima immagine visualizzo il logo
							if (_this.imglogo) {
								if (currentimage == 0) {
									_this.imglogo.style.left=(_this.rect_divmain.left+20)+"px";
									_this.imglogo.style.top=(((_this.rect_divmain.bottom-_this.rect_divmain.top)/2)+_this.rect_divmain.top-(parseInt(_this.imglogo.height)/2))+"px";
									_this.imglogo.style.display = "block"
								} else {
									//alert(_this.nImages+","+currentimage)
									if (currentimage == _this.nImages-1) {
										_this.imglogo.style.left=(_this.rect_divmain.right-20-_this.imglogo.width)+"px";
										_this.imglogo.style.top=(((_this.rect_divmain.bottom-_this.rect_divmain.top)/2)+_this.rect_divmain.top-(parseInt(_this.imglogo.height)/2))+"px";
										_this.imglogo.style.display = "block"
									}else{
										_this.imglogo.style.display = "none"
									}
								}
							}



						}

					} else {


						//  ANIMAZIONE CONTINUA
						
						
						var lf = parseInt(_this.otable.style.left)
						_this.otable.style.left = (lf - inc) + "px"
						//alert(_this.otable)
						if (parseInt(_this.otable.style.left) < -1000) {
							_this.otable.style.left = "0px"
						}
						//alert(widthtotimages)
						if (widthtotimages < (widthdiv + Math.abs(parseInt(_this.otable.style.left)))) {
							inc = 0 - inc
						}
						if (parseInt(_this.otable.style.left) > 0) {
							inc = Math.abs(inc)
						}

						var nextleft = 0
						if (stepdone % 10 == 0) {
							apc = Math.abs(parseInt(_this.otable.style.width)) - parseInt(DIVCAROUSEL.style.width)
							currentimage = Math.abs(parseInt(Math.abs(_this.nImages / apc) * lf))
							change_status(currentimage)
							//DIVSTATUS.childNodes[0].innerHTML=currentimage

						}


					}
				}





			}, speed)
		}
	}, 1100);



	function change_status(nimage) {
		$.each(DIVSTATUS.childNodes, function(i, itm) {
			if (i == nimage) {
				itm.style.color = "white";
			} else {
				itm.style.color = "gray";
			}

		})
	}


	return this;
}
	
jQuery.carousel.prototype={
	hide:function(){
		this.divmain.style.display="none"
		if(this.imglogo){
			this.imglogo.style.display="none"
		}
		this.div_title.style.display="none"
		this.div_title_text.style.display="none"
	},
	show:function(){
		this.divmain.style.display="block"
		if(this.imglogo){
			this.imglogo.style.display="block"
		}
		this.div_title.style.display="block"
		this.div_title_text.style.display="block"
	},
	destroy:function(){
		//alert("rem")
		
		
		
		window.clearInterval(this.timer)
		this.timer=""
		divc=document.getElementById(this.name)
		if(divc){
			document.removeChild(divc)
		}
		if(this.imglogo){
			document.body.removeNode(this.imglogo)
		}
	}
};





var DIVCOVER,DIVZOOM
function zoom(image,title,cb){

		
					// zoom
					if(!DIVCOVER){
						
						DIVCOVER=document.createElement("divcover")
						DIVCOVER.id="divcover"
						DIVCOVER.style.display="none"
						document.body.appendChild(DIVCOVER)
						$(DIVCOVER).fadeTo(0,0.9).cssEX("position:absolute; zIndex:1000; backgroundColor:#333; left:1px; top:0px; width:"+(parseInt(document.body.clientWidth)-10)+"px; height:"+(parseInt(document.body.clientHeight)-10)+"px;")		
						
						DIVZOOM=document.createElement("divzoom")
						DIVZOOM.id="divzoom"
						DIVZOOM.style.display="none"
						document.body.appendChild(DIVZOOM)
						$(DIVZOOM).cssEX("position:absolute; zIndex:1001; border:solid 4px white; left:1px; top:0px; backgroundImage:'url("+image+")'")
						
						
					}
					$(DIVCOVER).show()
					DIVCOVER.style.display="block"
					
						if(!document.getElementById("zoom-image")){
							var imz=new Image()
							imz.id="zoom-image"
							document.body.appendChild(imz)
							imz.style.visibility="hidden"
						}else{
							imz=document.getElementById("zoom-image")
							//imz.style.display="block"
							//alert(imz.style.visibility+","+imz.style.display)
						}
						//imz.style.visibility="hidden"
						imz.src=image
						imz.style.border="solid 3px white"
						var imx_w=0,imx_h=0
						
						var t=setTimeout(function(){
						
						
								DIVZOOM.style.width="10px" //imz.width+"px"
								DIVZOOM.style.height="10px" //imz.height+"px"
								
								if(parseInt(imz.width)>parseInt(document.body.clientWidth)||parseInt(imz.height)>parseInt(document.body.clientHeight)){
									var rapp=parseInt(imz.height)/parseInt(imz.width)
									if(parseInt(imz.height)>parseInt(document.body.clientHeight)){
										imx_h=(parseInt(document.body.clientHeight)-100)
										imx_w=(parseInt(document.body.clientWidth)-100)*rapp
									}else{
										imx_w=(parseInt(document.body.clientWidth)-100)
										imx_h=(parseInt(document.body.clientHeight)-100)/rapp
									}
								}else{
									imx_h=parseInt(imz.height)
									imx_w=parseInt(imz.width)
								}
								DIVZOOM.style.left=((document.body.clientWidth/2)-(imx_w/2))+"px"
								DIVZOOM.style.top=((document.body.clientHeight/2)-(imx_h/2))+"px"
								DIVZOOM.style.display="block"
								DIVZOOM.style.backgroundImage="url("+image+")"
								DIVZOOM.style.backgroundRepeat="no-repeat"
								if(title){var tt=title}else{
									tt=image.substr(image.toString().lastIndexOf("/")+1)
								}
								$("#zoom-title").html(tt)
								
								$(DIVZOOM).animate({
									width: (imx_w)+"px"
								},"normal","",function(){
										$(DIVZOOM).animate({
											height: (parseInt(imx_h))+"px"
										},"fast","",function(){
										
												// Visualizzo il button close e il titolo
												//$(imz).hide()
												/*
												$(imz).fadeTo("fast",0,function(){
													imz.style.visibility="visible"
													$(imz).fadeTo("fast",1)
												})
												*/
												//imz.style.visibility="hidden"
												if(!document.getElementById("zoom-spanzoom")){
													var htm="<span id=zoom-spanzoom style='font:bold 11pt Arial; float:right; color:red; cursor:pointer; backgroundColor:gray; margin-right:4px'><u>Close</u></span>"
													DIVZOOM.innerHTML=DIVZOOM.innerHTML+htm
												}
												
												// titolo
												var ot=document.getElementById("zoom-title")
												if(!ot){
													ot=document.createElement("div")
													ot.id="zoom-title"
													document.body.appendChild(ot)
													ot.align="center"
													ot.style.position="absolute"
													ot.style.backgroundColor="gray"
													ot.style.color="white"
													$(ot).fadeTo(0,0.6)
												}
												
												
												with(ot.style){
												
												left=(parseInt(DIVZOOM.style.left)+8)+"px"
												top=(parseInt(DIVZOOM.style.top)+parseInt(DIVZOOM.style.height)-20)+"px"
												width=(parseInt(DIVZOOM.style.width)-10)+"px"
												font="normal 9pt Arial"
												//left=DIVZOOM.style.left
												display="block"
												zIndex=1002
												}
												ot.innerHTML=tt
												
												//alert(DIVZOOM.innerHTML)
												$("#zoom-spanzoom").click(function(){
													$("#divzoom,#divcover,#zoom-title").hide()
													if(cb){
														cb()
													}
												})
												DIVZOOM.style.border="solid 4px white"
												//imz.style.border="solid 3px white"
												//imz.border="4"
												//imz.borderColor="white"
												//$(imz).show("slow")
												//imz.hspace="4"
												
										})
								})
								
						},800)
					
};






/********************************************************

//		COMBO / SELECT

********************************************************/


jQuery.CM_Select_IndexValue= function(objsel,index){
		var value=objsel.options[index].innerHTML
		return(value)
}

jQuery.CM_Select_CurrentValue= function(objsel){
		var value=objsel.options[objsel.selectedIndex].innerHTML
		return(value)
};



/********************************************************

//		QUERY

********************************************************/


//--------------------------------------------------------
//		Ritorna parte della query (nuovo)
//		part="campi","tabelle","where","orderby"
//--------------------------------------------------------
jQuery.QUERY_retPart = function(query,part){
	part=part.toLowerCase();
   query=query.toLowerCase();
   
   var init_select=query.indexOf(" select ",0);
   var init_insertinto=query.indexOf(" insert into   ",0);
   var init_update=query.indexOf(" select ",0);
   
   var init_distinct=query.indexOf(" distinct ",0);
   var init_percent=query.indexOf(" percent ",0);
   var init_set=query.indexOf(" set ",0);
   var init_all=query.indexOf(" all ",0);

   var init_from=query.indexOf(" from ",0);

   var init_where=query.indexOf(" where ",0);
   var init_having=query.indexOf(" having ",0);
   var init_groupby=query.indexOf(" group by ",0);
   var init_union=query.indexOf(" union ",0);

   var init_orderby=query.indexOf(" order by ",0);
   
   part=part.toLowerCase();
	if(part=="campi"){
		var retfields=$.trim(query.substring("select ".length,init_from));
		//alert("retf="+retfields+" is="+init_select)
		retfields=jQuery.QUERY_validateFields(retfields);
		return(retfields);
	};
	
	if(part=="tabelle"){
      if (init_where>0) 
         {var retTables=$.trim(query.substring(init_from+" from ".length,init_where))}
      else {
         if (init_orderby>0) { 
					retTables=$.trim(query.substring(init_from+" from ".length,init_orderby))
            } else {
					retTables=$.trim(query.substring(init_from+" from ".length,query.length))
			}
		}
		return(retTables);
	};
	
	if(part=="where"){
      if (init_where>0)  {
         if (init_orderby>0) {
             retWhere=$.trim(query.substring(init_where+"where ".length,init_orderby))} else
            {retWhere=$.trim(query.substring(init_where+"where ".length,query.length))}
         return(retWhere);
      }
	};
	
	if(part=="orderby"){
      if (init_orderby>0) {
         retSort=$.trim(query.substring(init_orderby+"order by ".length,query.length));
      } else {retSort=""}
		return(retSort);
	}

};

//------------------------------------------------------------
// Fa ilcontrollo dei campi che siano regolari (anche 
// nei casi di es: select nome, 'cognome,nome=' & cognome
// ritornano i fields o false se c'e' errore
//------------------------------------------------------------
jQuery.QUERY_validateFields = function(fileds,retarray){
	
	if(fileds=="*"){return("*")};
	var fls=new Array();
	var incfls=0;
	var openvirg=false;
	var campodescr="";
	var closecampodesc=false;
	var fl="";
	var firstlett=false;
	var lastlett=false;
	var finevirg=false;
	
	var af=new Array();
	af=fileds.split(",");
	af2=new Array();var inc=0;
	var pos44=0;var pos44b=0;
	for(var i=0;i<af.length;i++){
		pos44=af[i].indexOf(String.fromCharCode(44));
		if(pos44>-1){
			// stringa con virgolette la unisco a quella dopo solo se ha
			// la virgola all'nterno (se nn e' chiusa)
			pos44b=af[i].indexOf(String.fromCharCode(39),pos44+1);
			if(pos44b==-1){
				af2[inc]=af[i]+af[i+1] ;
				i=+1;
			}else{
				af2[inc]=af[i];
			}
		}else{
			af2[inc]=af[i];
		}
		inc+=1;
	}
	// Ripasso l'array new per mettere le virgolette
	for(i=0;i<af2.length;i++){
		af2[i]=$.QUERY_fieldsbracketsEx(af2[i]);
		//alert(af2[i])
	}
	var campi="";var virg=""
	for(i=0;i<af2.length;i++){
		campi=campi+virg+af2[i];
		virg=",";
	}
	//alert("campi="+af2[0])
	if(retarray){return(af2)}
	return(campi);
};


//--------------------------------------------------------
//	Metto parentesi nel campo dato (EX=fisse)
// Il campo può anche avere le virgolette
//--------------------------------------------------------
jQuery.QUERY_fieldsbracketsEx = function(field) {
	if(field.indexOf(String.fromCharCode(39))>-1||field.indexOf(String.fromCharCode(34))>-1){
		var openvirg=false;
		var closevirg=false;
		var mid="";
		var nf="";
		var initcampo=0;
		var posas=field.indexOf(" as ");
		for(var i=0;i<field.length;i++){
			mid=field.toString().substr(i,1);
			if(mid==String.fromCharCode(39)||mid==String.fromCharCode(34)){
				if(openvirg) closevirg=true;
				openvirg=!openvirg;
			}
			if(mid=="&") initcampo=i;
			if(initcampo>0&&i==initcampo+2&&mid!="["){nf=nf+"["}
			nf=nf+mid;
			if(i==posas-1&&nf.substr(nf.length-1,1)!="]"){nf=nf+"]"}
		}
		return(nf);
	}else{
		if(field.substr(0,1)!="["){
			field="["+field;
		}
		if(field.substr(field.length-1,1)!="]"){
			field=field+"]";
		}
		return(field);
	}
};


//  Rimuove le parentesi nei fields per le query
jQuery.QUERY_removebrackets = function(field) {
					
					var pos=field.indexOf("[");
					if (pos==0) {
							return(field.toString().substr(1,field.length-2));
					} else {
							return(field);
					}
}


//**************************************************
//    Raddoppio le virgolette nelle stringhe
//		per la ricerca nel db
//**************************************************
jQuery.QUERY_double_virg_db = function(text) {
					if(!text) return("");
					var pt=0;var doit=true;
					while (doit) {
		
							pt=text.indexOf("'",pt);
							if (pt==-1) {
                                doit=false;
                                break;
                            }
							text=text.substr(0,pt+1)+"'"+text.substr(pt+1);
							pt+=2;
		
					}
					return(text);
}



COMMON_createRequestObject()
var FORM_DATA = COMMON_createRequestObject();
function COMMON_createRequestObject() {
  FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.
  separator = ',';
    // The token used to separate data from multi-select inputs
  query = '' + this.location;
  qu = query
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.
  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
  if (query.length < 1) { return false; }  // Perhaps we got some bad data?
  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.
  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }
  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.<
  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }
    keyValue = unescape(keyValue);
      // URLDecode non-alphanumerics
    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }
  return FORM_DATA;
}




