function TabellaCursore(variabile,tag,titoli,fileCss,stileTabella,stileTitolo,stileCursore) {

	this.inizializza(variabile,tag,titoli,fileCss,stileTabella,stileTitolo);
	this.usaImmagine=false;
	this.img=null;
	this.imgVuota=null;
	this.col=0;
	this.stileCursore=stileCursore;
	this.colFiltro=1;
}

TabellaCursore.prototype.__proto__ = Tabella.prototype;
TabellaCursore.prototype = new Tabella(null,null,false,null,"","");
TabellaCursore.prototype.constructor = TabellaCursore;

TabellaCursore.prototype.immagineCursore=function (immagine,vuota,stile){
	var cella=null;
	if (this.titoli)
		cella=this.addTitolo('&nbsp;',"");
	this.usaImmagine=true;
	this.img=new Image;
	this.img.src=immagine;
	this.imgVuota=new Image;
	this.imgVuota.src=vuota;
	this.stileImmagine=stile;
	this.col=1;
	return cella;
}

TabellaCursore.prototype.setColFiltro=function (n){
	this.colFiltro=n;
}

TabellaCursore.prototype.aggiungiRiga=function (){
	var chiave=(new getfObj(this.fr,this.tag + "infoc" + this.dati.length)).obj.innerHTML;
	var altri=(new getfObj(this.fr,this.tag + "infoi" + this.dati.length)).obj.innerHTML;
	var evento=(new getfObj(this.fr,this.tag + "infoe" + this.dati.length)).obj.innerHTML;
	if (altri!="")
		altri=altri.split(",");
	else
		altri=null;
	var riga=this.dati[this.dati.length]=new RigaConChiave(chiave,altri);
	riga.aggiungiEvento(new Evento('onClick',this.variabile + '.tipo.spostaCursore(' + (this.dati.length+this.rTit-1) + ')'));
	if (evento!=""){
		var eventi=evento.split("§");
		for(var i=0; i<eventi.length; i++){
			evento=eventi[i].split("@");
			riga.aggiungiEvento(new Evento(evento[0],evento[1]));
		}
	}
	if (this.usaImmagine) {
		var cella=riga.aggiungiCella('<img src="">',"s",0,false);
		cella.aggiungiStile(new Stile("class",this.stileImmagine));
	}
	return riga;
}

TabellaCursore.prototype.crea=function (contenitore,frame){
	this.tipo=new Cursore(this);
	this.creaTabella(contenitore,frame);
	if (this.usaImmagine) {
		for( var i=this.rTit; i<this.tabe.rows.length; i++)
			this.tabe.rows[i].cells[0].children(0).src=this.imgVuota.src;
	}
	this.tipo.spostaCursore(this.rTit);
}

TabellaCursore.prototype.gestTasti=function (e){
	var code;
	if (!e)
		e=window.event;
	if (e.keyCode)
		code=e.keyCode;
	else
		code=e.which;
	if (pagAperta) return;
	if(code==40 && this.tipo.posizione()< this.dati.length-1){
		this.tipo.spostaCursore(this.tipo.posCorrente()+1);
		eval(this.dati[this.tipo.posizione()].estraiEvento("onClick"));
	}
	else if(code==38 && this.tipo.posizione()>0){
		this.tipo.spostaCursore(this.tipo.posCorrente()-1);
		eval(this.dati[this.tipo.posizione()].estraiEvento("onClick"));
	}
	else if(code==33){
		if(e.ctrlKey)
			this.spostaPagina('p');
		else
			this.spostaPagina('i');
	}
	else if(code==34){
		if(e.ctrlKey)
			this.spostaPagina('u');
		else
			this.spostaPagina('a');
	}
	else{
		var e=this.dati[this.tipo.posizione()].estraiEvento("onkeydown");
		if (e!="")
			eval(e);
	}
	window.event.returnValue=true;
}

TabellaCursore.prototype.setCella=function (valore,col,riga){
	if (arguments.length<3)
		riga=this.tipo.posizione();
	this.dati[riga].celle[col].setValore(valore);
	this.tabe.rows[riga+this.rTit].cells[col].innerHTML=(this.dati[riga].celle[col].valore=="")?"&nbsp;":this.dati[riga].celle[col].valore;
};

TabellaCursore.prototype.getCella=function (col,riga){
	if (arguments.length<2)
		riga=this.tipo.posizione();
	return this.dati[riga].celle[col].getValore();
};

TabellaCursore.prototype.Cerca=function (col){
	var pagina=String(document.location);
	var f=window.showModalDialog("contForm.asp","/Form/FormTrova.asp?col=" + this.origCol[col] + "&val=" + pagina.substring(0,pagina.indexOf(".asp"))+this.tag,"dialogWidth:600px;dialogHeight:270px");
	if (f!=null){
		var form=(new getfObj(this.fr,"filtro")).obj;
		form.ordine.value="undefined";
		if (f[1][1]==3){
			form.filtroDin.value='';
		}
		else {
			var filtro="";
			var virg='';
			var operatore="=";
			var valore=f[0][1];
			if (f[1][1]=="2")
				operatore="<>";
			if (f[0][1]=="")
				valore=this.dati[this.tipo.posizione()].celle[col].valore;
			if (this.tipoCol[col]=='s')
				virg="'";
			else if (this.tipoCol[col]=='d'){
				virg="#";
				valore=valore.substring(3,5) + "/" + valore.substring(0,2) + "/" + valore.substring(6);
			}
			//if (filtro!="")
			//	filtro+=" and ";
			if (valore!="")
				filtro+= this.origCol[col] + operatore + virg + valore + virg;
			else
				filtro+= this.origCol[col] + " is null";
			form.filtroDin.value=filtro;
		}
		try{
			form.indice.value=this.dati[this.tipo.posizione()].valoreChiave();
		}
		catch(e){
			form.indice.value="undefined";
		}
		form.area.value=pagina.substring(0,pagina.indexOf(".asp"))+this.tag;
		form.submit();
	}
}

TabellaCursore.riferimento=null;

TabellaCursore.prototype.annullaFiltro=function (){
	var pagina=String(document.location);
	var form=(new getfObj(this.fr,"filtro")).obj;
	form.ordine.value="";
	form.filtroDin.value='';
	form.filtro.value='undefined';
	try{
		form.indice.value=this.dati[this.tipo.posizione()].valoreChiave();
	}
	catch(e){}
	form.area.value=pagina.substring(0,pagina.indexOf(".asp"))+this.tag;
	form.submit();
}

TabellaCursore.prototype.filtroSelezione= function(col){
	var pagina=String(document.location);
	var form=(new getfObj(this.fr,"filtro")).obj;
	var filtro="";
	var virg='';
	var valore=this.dati[this.tipo.posizione()].celle[col].valoreConfronto;
	if (this.tipoCol[col]=='s'){
		valore=valore.replace(/&nbsp;/g," ");
		virg="'";
	}
	else if (this.tipoCol[col]=='d'){
		virg="#";
		valore=valore.substring(4,6) + "/" + valore.substring(6,8) + "/" + valore.substring(0,4);
	}
	if (valore!="" && valore!=null || valore==0)
		if (this.tipoCol[col]=='t'){
			var domani=new Date(valore);
			domani.setDate(domani.getDate()+1);
			filtro= this.origCol[col] + " between #" + formatoData(new Date(valore),"d")+ "# and #" + formatoData(domani,"d") + "#" ;
		}
		else if (this.tipoCol[col]=='b'){
			if (valore!=this.decCol[col])
				virg="not ";
			filtro=virg + this.origCol[col];
		}
		else
			filtro= this.origCol[col] + "=" + virg + valore + virg;
	else
		filtro= this.origCol[col] + " is null";
	form.filtroDin.value=filtro;
	try{
		form.indice.value=this.dati[this.tipo.posizione()].valoreChiave();
	}
	catch(e){
		form.indice.value="undefined";
	}
	form.area.value=pagina.substring(0,pagina.indexOf(".asp"))+this.tag;
	form.submit();
}

TabellaCursore.prototype.filtroEsclusione= function(col){
	var pagina=String(document.location);
	var form=(new getfObj(this.fr,"filtro")).obj;
	var filtro="";
	var virg='';
	var valore=this.dati[this.tipo.posizione()].celle[col].valoreConfronto;
	if (this.tipoCol[col]=='s'){
		valore=valore.replace(/&nbsp;/g," ");
		virg="'";
	}
	else if (this.tipoCol[col]=='d'){
		virg="#";
		valore=valore.substring(4,6) + "/" + valore.substring(6,8) + "/" + valore.substring(0,4);
	}
	if (valore!="" && valore!=null || valore==0)
		if (this.tipoCol[col]=='t'){
			var domani=new Date(valore);
			domani.setDate(domani.getDate()+1);
			filtro= this.origCol[col] + " not between #" + formatoData(new Date(valore),"d")+ "# and #" + formatoData(domani,"d") + "#" ;
		}
		else if (this.tipoCol[col]=='b'){
			if (valore==this.decCol[col])
				virg="not ";
			filtro=virg + this.origCol[col];
		}
		else
			filtro= this.origCol[col] + "<>" + virg + valore + virg;
	else
		filtro= " not " + this.origCol[col] + " is null";
	form.filtroDin.value=filtro;
	try{
		form.indice.value=this.dati[this.tipo.posizione()].valoreChiave();
	}
	catch(e){
		form.indice.value="undefined";
	}
	form.area.value=pagina.substring(0,pagina.indexOf(".asp"))+this.tag;
	form.submit();
}

TabellaCursore.eseguiFiltro= function(f){
	var tabella=TabellaCursore.riferimento;
	TabellaCursore.riferimento=null;
	var col=tabella.colFiltro;
	var pagina=String(document.location);
	if (f!=null){
		var form=(new getfObj(tabella.fr,"filtro")).obj;
		form.ordine.value="undefined";
		var filtro= tabella.origCol[col];
		var virg='';
		var valore=f[0][1];
		if (f[0][1]=="")
			valore=tabella.dati[tabella.tipo.posizione()].celle[col].valoreConfronto;
		if (valore=="" || valore==null)
			filtro+= " is null";
		else if (tabella.tipoCol[col]=='s'){
			virg="'";
			if (f[1][1]=="1")
				filtro+= ' LIKE "' + valore + '%"' ;
			else if (f[1][1]=="2")
				filtro+= ' LIKE "%' + valore + '%"' ;
			else
				filtro+= '="' + valore + '"';
		}
		else if (tabella.tipoCol[col]=='d' || tabella.tipoCol[col]=='n' || tabella.tipoCol[col]=='t'){
			if (tabella.tipoCol[col]=='d')
				virg="#";
			//valore=valore.substring(4,6) + "/" + valore.substring(6,8) + "/" + valore.substring(0,4);
			if (f[1][1]=="1")
				filtro= "cStr(" + filtro + ') LIKE "' + valore  + '%"' ;
			else if (f[1][1]=="2")
				filtro= "cStr(" + filtro + ') LIKE "%' + valore + '%"' ;
			else
				filtro+='=' + virg + valore + virg;
		}
			
//		if (valore!="" && valore!=null){
//			filtro+= tabella.origCol[col] + "=" + virg + valore + virg;
//		}
//		else
		form.filtroDin.value=filtro;
		try{
			form.indice.value=tabella.dati[tabella.tipo.posizione()].valoreChiave();
		}
		catch(e){
			form.indice.value="undefined";
		}
		form.area.value=pagina.substring(0,pagina.indexOf(".asp"))+tabella.tag;
		form.submit();
	}
}

TabellaCursore.prototype.attivaFiltro=function (col){
	this.colFiltro=col;
	TabellaCursore.riferimento= this;
	__apriDialogo("/Form/FormFiltro.asp?col=" + this.valTitoli[col][0],"filtro",600,270);
}

TabellaCursore.prototype.ordina=function (col,tipo){
	if(this.dati.length==0) return;
	var t=""
	if (tipo=='d')
		t=" DESC";
	var pagina=String(document.location);
	var form=(new getfObj(this.fr,"filtro")).obj;
	form.ordine.value=this.origCol[col]+t;
	form.filtro.value='undefined';
	form.indice.value=this.dati[this.tipo.posizione()].valoreChiave();
	form.area.value=pagina.substring(0,pagina.indexOf(".asp"))+this.tag;
	form.submit();
}

TabellaCursore.prototype.valoreChiave=function (riga){
	return this.dati[riga].valoreChiave();
}

TabellaCursore.prototype.trova=function (cosa){
	for (var i=0; i<this.dati.length; i++)
		if (cosa==this.dati[i].valoreChiave())
			return i;
	return -1;
}

