function Cursore(tabella){
	this.tabella=tabella;
	this.impostaCursore();
}

Cursore.prototype.impostaCursore=function (){
	//for(var i in this.tabella.dati){
	//	this.tabella.dati[i].aggiungiEvento(new Evento('onClick',this.tabella.variabile + '.tipo.spostaCursore(' + (parseInt(i)+this.tabella.rTit) + ')'));
	//}
	this.rigaCorrente=-1;
}

Cursore.prototype.spostaCursore=function (riga){
	if(this.tabella.dati.length==0)
		return;
	if(this.rigaCorrente!=-1 && (riga-this.tabella.rTit<0 || this.tabella.dati.length<=riga-this.tabella.rTit)){
		if (riga-this.tabella.rTit<0 && this.tabella)
			this.tabella.spostaPagina('i');
		else if(this.tabella.dati.length<=riga-this.tabella.rTit)
			this.tabella.spostaPagina('a');
		return;
	}
	var c;
	var tabe=this.tabella.tabe;
	if (this.rigaCorrente!=riga){
		if (this.rigaCorrente!=-1){
			for(c in this.tabella.dati[this.rigaCorrente-this.tabella.rTit].celle)
				tabe.rows[this.rigaCorrente].cells[parseInt(c)].className=this.tabella.dati[this.rigaCorrente-this.tabella.rTit].celle[c].stile.valore;
			if (this.tabella.img!=null){
				tabe.rows[this.rigaCorrente].cells[0].children(0).src=this.tabella.imgVuota.src;
			}
		}
		this.rigaCorrente=riga;
		if (this.tabella.usaImmagine){
			tabe.rows[this.rigaCorrente].cells[0].children(0).src=this.tabella.img.src;
		}
		for(var c in this.tabella.dati[this.rigaCorrente-this.tabella.rTit].celle){
			tabe.rows[this.rigaCorrente].cells[parseInt(c)].className=this.tabella.stileCursore;
		}
	}
}

Cursore.prototype.posizione=function (){
	return this.rigaCorrente-this.tabella.rTit;
}

Cursore.prototype.posCorrente=function (){
	return this.rigaCorrente;
}

Cursore.prototype.posizionaCursore=function (chiave){
	var riga=this.tabella.rTit;
	for(var i in this.tabella.dati)
		if (String(this.tabella.dati[i].chiave)==chiave){
			this.spostaCursore(riga + parseInt(i));
			return;
		}
}

