function Acq(IDSquadra,Ruolo,GiocIn,GiocOut,Valore,Recup,Data,Datan) {
	this.IDSquadra = IDSquadra
	this.Ruolo = Ruolo
	this.GiocIn = GiocIn
	this.GiocOut = GiocOut
	this.Valore = Valore
	this.Recup = Recup
	this.Data = Data
	this.Datan = Datan
}

function Pre(IDSquadra,Ruolo,GiocIn,GiocOut,Valore,Data1,Data2,Datan,Datan2) {
	this.IDSquadra = IDSquadra
	this.Ruolo = Ruolo
	this.GiocIn = GiocIn
	this.GiocOut = GiocOut
	this.Valore = Valore
	this.Data1 = Data1
	this.Data2 = Data2
	this.Datan = Datan
	this.Datan2 = Datan2
}

function GeneraAcquistati() {
var tabB = new Tabella(2,7)
var arrAcquisti = new Array ()
var i,j,cnt,sR,fatto,cut,Desc,datan,prestm,nosvi
	tabB.nome="Acquisti"
	tabB.larghezza=105
	tabB.border=1
	tabB.cellpadding=3
	tabB.cellspacing=0
	tabB.stile="ClassEl"
	tabB.SetLarghezzaColonna(1,17)
	tabB.SetLarghezzaColonna(2,4)
	tabB.SetLarghezzaColonna(3,33)
	tabB.SetLarghezzaColonna(4,33)
	tabB.SetLarghezzaColonna(5,4)
	tabB.SetLarghezzaColonna(6,4)
	tabB.SetLarghezzaColonna(7,10)
	tabB.SetStileRiga(1,"IntRossoBlu")
	tabB.SetStile(1,2,"CellaCentro")
	tabB.SetStile(1,3,"Cella")
	tabB.SetStile(1,4,"Cella")
	tabB.SetStile(1,5,"CellaCentro")
	tabB.SetStile(1,6,"CellaCentro")
	tabB.SetStile(1,7,"CellaCentro")
	tabB.SetValore(1,1,"Fantasquadra")
	tabB.SetValore(1,2,"Ruo")
	tabB.SetValore(1,3,"Giocatore Acquistato")
	tabB.SetValore(1,4,"Giocatore Svincolato")
	tabB.SetValore(1,5,"$Acq")
	tabB.SetValore(1,6,"$Rec")
	tabB.SetValore(1,7,"Data")

	cnt=1
	cut=0
	for(i=1;i<arrBilanci.length;i++) {
		merlib=arrBilanci[i].Descrizione.search(/Mercato Libero/)
		prest=arrBilanci[i].Descrizione.search(/Tesseramento in prestito/)
		Desc=arrBilanci[i].Descrizione
					
		if ((merlib != -1) && (prest == -1)) { 		
			Ruolo=Desc.charAt(12)
	
			if (Ruolo=="P") {
				sR="G"
			} else if (Ruolo=="D") {
				sR="V"
			} else if (Ruolo=="C") {
				sR="R"
			} else if (Ruolo=="A") {
				sR="Blu"
			} 	
	

			datan=arrBilanci[i].Data.slice(6,10).valueOf()+arrBilanci[i].Data.slice(3,5).valueOf()+arrBilanci[i].Data.slice(0,2).valueOf()
			
			cut=arrBilanci[i].Descrizione.search(/al Mercato Libero/)	
			nosvi=arrBilanci[i-1].Descrizione.search(/Recupero crediti svincolo di /)
			if (nosvi == 0) { 	
				arrAcquisti[cnt] = new Acq(arrFantasquadre[arrBilanci[i].IDSquadra].Nome,Ruolo,arrBilanci[i].Descrizione.slice(15,cut),arrBilanci[i-1].Descrizione.slice(29),-arrBilanci[i].Valore,arrBilanci[i-1].Valore,arrBilanci[i].Data.slice(0,10),datan)
			} else {
				arrAcquisti[cnt] = new Acq(arrFantasquadre[arrBilanci[i].IDSquadra].Nome,Ruolo,arrBilanci[i].Descrizione.slice(15,cut),"NESSUNO",-arrBilanci[i].Valore,0,arrBilanci[i].Data.slice(0,10),datan)
			} 
			
			cnt++
		}
	}

	arrAcquisti.sort(ordsquadra)
	arrAcquisti.sort(orddata)

	j=2
	for(i=0;i<cnt-1;i++) {

			if ((j % 2) == 0) {
				tabB.SetStileRiga(j,"riga-dispari")
			} else {
				tabB.SetStileRiga(j,"riga-pari")
			}
		
			tabB.SetStile(j,1,"Cella")
			tabB.SetStile(j,2,"CellaCentro")
			tabB.SetStile(j,3,"Cella")
			tabB.SetStile(j,4,"Cella")
			tabB.SetStile(j,5,"CellaCentro")
			tabB.SetStile(j,6,"CellaCentro")
			tabB.SetStile(j,7,"CellaCentro")


			if (arrAcquisti[i].Ruolo=="P") {
				sR="G"
			} else if (arrAcquisti[i].Ruolo=="D") {
				sR="V"
			} else if (arrAcquisti[i].Ruolo=="C") {
				sR="R"
			} else if (arrAcquisti[i].Ruolo=="A") {
				sR="Blu"
			} 

			tabB.SetValore(j,1,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].IDSquadra+"</span>")
			tabB.SetValore(j,2,"<span class='t-xxs"+sR+"B'>"+arrAcquisti[i].Ruolo+"</span>")
			tabB.SetValore(j,3,"<span class='t-xxs"+sR+"B'>"+arrAcquisti[i].GiocIn+"</span>")
			tabB.SetValore(j,4,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].GiocOut+"</span>")
			tabB.SetValore(j,5,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].Valore+"</span>")
			tabB.SetValore(j,6,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].Recup+"</span>")
			tabB.SetValore(j,7,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].Data+"</span>")

			j++
	}
	if (arrAcquisti.length == 0) {
		document.write("<b>ATTENZIONE, non ci sono giocatori acquistati!!!</b>")
	} else {
		tabB.Stampa()
	}
}




function GeneraInfortunati() {
var tabB = new Tabella(2,7)
var arrAcquisti = new Array ()
var i,k,IDSquadra,cnt,sT,sR,fatto,cut,datan,datan2,recupero,gio1,gio2
	fatto=false
	tabB.nome="Lista"
	tabB.larghezza=105
	tabB.border=1
	tabB.cellpadding=3
	tabB.cellspacing=0
	tabB.stile="tab-8"
	tabB.SetLarghezzaColonna(1,16)
	tabB.SetLarghezzaColonna(2,4)
	tabB.SetLarghezzaColonna(3,31)
	tabB.SetLarghezzaColonna(4,31)
	tabB.SetLarghezzaColonna(5,3)
	tabB.SetLarghezzaColonna(6,10)
	tabB.SetLarghezzaColonna(7,10)
	tabB.SetStileRiga(1,"IntRossoBlu")
	tabB.SetStile(1,2,"CellaCentro")
	tabB.SetStile(1,3,"Cella")
	tabB.SetStile(1,4,"Cella")
	tabB.SetStile(1,5,"CellaCentro")
	tabB.SetStile(1,6,"CellaCentro")
	tabB.SetStile(1,7,"CellaCentro")
	tabB.SetValore(1,1,"Fantasquadra")
	tabB.SetValore(1,2,"Ruo")
	tabB.SetValore(1,3,"Giocatore Acquistato")
	tabB.SetValore(1,4,"Inserito in Lista Infortunati")
	tabB.SetValore(1,5,"$Aq")
	tabB.SetValore(1,6,"Inizio")
	tabB.SetValore(1,7,"Fine")

	cnt=1
	cut=0
	for(i=1;i<arrBilanci.length;i++) {
		merlib=arrBilanci[i].Descrizione.search(/Inserimento/)
		Desc=arrBilanci[i].Descrizione
		recupero=arrBilanci[i].Descrizione.search(/per reintegro lista infortunati/)			
		if (merlib != -1) { 	

			for(j=1;j<arrRose.length;j++) {
				cut=arrBilanci[i+1].Descrizione.search(/\(/)	
				if (arrBilanci[i+1].Descrizione.slice(28,cut-1)==arrRose[j].Nome) {
							
					if (arrRose[j].Ruolo=="1") {
						Ruolo="P"
					} else if (arrRose[j].Ruolo=="2") {
						Ruolo="D"
					} else if (arrRose[j].Ruolo=="3") {
						Ruolo="C"
					} else if (arrRose[j].Ruolo=="4") {
						Ruolo="A"
					}	 

				} 
	
			} 
			datan=arrBilanci[i].Data.slice(6,10).valueOf()+arrBilanci[i].Data.slice(3,5).valueOf()+arrBilanci[i].Data.slice(0,2).valueOf()
			
			cut=arrBilanci[i+1].Descrizione.search(/\(/)	
			arrAcquisti[cnt] = new Pre(arrFantasquadre[arrBilanci[i].IDSquadra].Nome,Ruolo,arrBilanci[i+1].Descrizione.slice(28,cut-1),arrBilanci[i].Descrizione.slice(36),-arrBilanci[i].Valore,arrBilanci[i].Data.slice(0,10),"Aperta!",datan,"99999999")
			
			cnt++	
		}
		if (recupero != -1) { 	
			for(k=1;k<arrAcquisti.length;k++) {
				gio1=arrBilanci[i].Descrizione.slice(46)
				gio2=arrBilanci[i-1].Descrizione.slice(29)
				if ((gio2 == arrAcquisti[k].GiocOut) && (gio1 == arrAcquisti[k].GiocIn)){ 
					datan2=arrBilanci[i].Data.slice(6,10).valueOf()+arrBilanci[i].Data.slice(3,5).valueOf()+arrBilanci[i].Data.slice(0,2).valueOf()
					arrAcquisti[k].Data2=arrBilanci[i].Data.slice(0,10)
					arrAcquisti[k].Datan2=datan2
				} 
			} 
			
		}	
	}
	arrAcquisti.sort(ordsquadra)
	arrAcquisti.sort(orddata)
	arrAcquisti.sort(orddata2)
	j=2
	for(i=0;i<cnt-1;i++) {

			if ((j % 2) == 0) {
				tabB.SetStileRiga(j,"riga-dispari")
			} else {
				tabB.SetStileRiga(j,"riga-pari")
			}
		
			tabB.SetStile(j,1,"Cella")
			tabB.SetStile(j,2,"CellaCentro")
			tabB.SetStile(j,3,"Cella")
			tabB.SetStile(j,4,"Cella")
			tabB.SetStile(j,5,"CellaCentro")
			tabB.SetStile(j,6,"CellaCentro")
			tabB.SetStile(j,7,"CellaCentro")			
				
					if (arrAcquisti[i].Ruoloo=="P") {
						sR="G"
					} else if (arrAcquisti[i].Ruolo=="D") {
						sR="V"
					} else if (arrAcquisti[i].Ruolo=="C") {
						sR="R"
					} else if (arrAcquisti[i].Ruolo=="A") {
						sR="Blu"
					}


			tabB.SetValore(j,1,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].IDSquadra+"</span>")
			tabB.SetValore(j,2,"<span class='t-xxs"+sR+"B'>"+arrAcquisti[i].Ruolo+"</span>")
			tabB.SetValore(j,3,"<span class='t-xxs"+sR+"B'>"+arrAcquisti[i].GiocIn+"</span>")
			tabB.SetValore(j,4,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].GiocOut+"</span>")
			tabB.SetValore(j,5,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].Valore+"</span>")
			tabB.SetValore(j,6,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].Data1+"</span>")			
			tabB.SetValore(j,7,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].Data2+"</span>")

			j++
	}
	if (arrAcquisti.length == 0) {
		document.write("<b>ATTENZIONE, non ci sono giocatori inseriti in lista infortunati!!!</b>")
	} else {
		tabB.Stampa()
	}
}
	
function GeneraPrestiti() {
var tabB = new Tabella(2,7)
var arrAcquisti = new Array ()
var i,j,cnt,sR,fatto,cut,Desc,datan,merlib,prest
	tabB.nome="Prestiti"
	tabB.larghezza=105
	tabB.border=1
	tabB.cellpadding=3
	tabB.cellspacing=0
	tabB.stile="tab-8"
	tabB.SetLarghezzaColonna(1,17)
	tabB.SetLarghezzaColonna(2,4)
	tabB.SetLarghezzaColonna(3,33)
	tabB.SetLarghezzaColonna(4,34)
	tabB.SetLarghezzaColonna(5,4)
	tabB.SetLarghezzaColonna(6,4)
	tabB.SetLarghezzaColonna(7,10)
	tabB.SetStileRiga(1,"IntRossoBlu")
	tabB.SetStile(1,2,"CellaCentro")
	tabB.SetStile(1,3,"Cella")
	tabB.SetStile(1,4,"Cella")
	tabB.SetStile(1,5,"CellaCentro")
	tabB.SetStile(1,6,"CellaCentro")
	tabB.SetStile(1,7,"CellaCentro")	
	tabB.SetValore(1,1,"Fantasquadra")
	tabB.SetValore(1,2,"Ruo")
	tabB.SetValore(1,3,"Giocatore Acquistato in Prestito")
	tabB.SetValore(1,4,"Giocatore Svincolato")
	tabB.SetValore(1,5,"$Acq")
	tabB.SetValore(1,6,"$Rec")	
	tabB.SetValore(1,7,"Data")

	cnt=1
	cut=0
	for(i=1;i<arrBilanci.length;i++) {
		merlib=arrBilanci[i].Descrizione.search(/per Lista Infortunat/)
		prest=arrBilanci[i].Descrizione.search(/Tesseramento in prestito/)
		Desc=arrBilanci[i].Descrizione
					
		if ((merlib == -1) && (prest != -1)) { 	
			Ruolo=Desc.charAt(28)

			if (Ruolo=="P") {
				sR="G"
			} else if (Ruolo=="D") {
				sR="V"
			} else if (Ruolo=="C") {
				sR="R"
			} else if (Ruolo=="A") {
				sR="Blu"
			} 	
	

			datan=arrBilanci[i].Data.slice(6,10).valueOf()+arrBilanci[i].Data.slice(3,5).valueOf()+arrBilanci[i].Data.slice(0,2).valueOf()

			cut=arrBilanci[i].Descrizione.search(/al Mercato Libero/)	
			nosvi=arrBilanci[i-1].Descrizione.search(/Recupero crediti svincolo di /)
			if (nosvi == 0) { 	
				arrAcquisti[cnt] = new Acq(arrFantasquadre[arrBilanci[i].IDSquadra].Nome,Ruolo,arrBilanci[i].Descrizione.slice(31,cut),arrBilanci[i-1].Descrizione.slice(29),-arrBilanci[i].Valore,arrBilanci[i-1].Valore,arrBilanci[i].Data.slice(0,10),datan)
			} else {
				arrAcquisti[cnt] = new Acq(arrFantasquadre[arrBilanci[i].IDSquadra].Nome,Ruolo,arrBilanci[i].Descrizione.slice(31,cut),"NESSUNO",-arrBilanci[i].Valore,0,arrBilanci[i].Data.slice(0,10),datan)
			} 
			cnt++
		}
	}

	arrAcquisti.sort(ordsquadra)
	arrAcquisti.sort(orddata)

	j=2
	for(i=0;i<cnt-1;i++) {

			if ((j % 2) == 0) {
				tabB.SetStileRiga(j,"riga-dispari")
			} else {
				tabB.SetStileRiga(j,"riga-pari")
			}
		
			tabB.SetStile(j,1,"Cella")
			tabB.SetStile(j,2,"CellaCentro")
			tabB.SetStile(j,3,"Cella")
			tabB.SetStile(j,4,"Cella")
			tabB.SetStile(j,5,"CellaCentro")
			tabB.SetStile(j,6,"CellaCentro")
			tabB.SetStile(j,7,"CellaCentro")			


			if (arrAcquisti[i].Ruolo=="P") {
				sR="G"
			} else if (arrAcquisti[i].Ruolo=="D") {
				sR="V"
			} else if (arrAcquisti[i].Ruolo=="C") {
				sR="R"
			} else if (arrAcquisti[i].Ruolo=="A") {
				sR="Blu"
			} 


			tabB.SetValore(j,1,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].IDSquadra+"</span>")
			tabB.SetValore(j,2,"<span class='t-xxs"+sR+"B'>"+arrAcquisti[i].Ruolo+"</span>")
			tabB.SetValore(j,3,"<span class='t-xxs"+sR+"B'>"+arrAcquisti[i].GiocIn+"</span>")
			tabB.SetValore(j,4,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].GiocOut+"</span>")
			tabB.SetValore(j,5,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].Valore+"</span>")
			tabB.SetValore(j,6,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].Recup+"</span>")			
			tabB.SetValore(j,7,"<span class='t-xxs"+sR+"'>"+arrAcquisti[i].Data+"</span>")

			j++
	}
	if (arrAcquisti.length == 0) {
		document.write("<b>ATTENZIONE, non ci sono giocatori in prestito!!!</b>")
	} else {
		tabB.Stampa()
	}
}


function orddata(a,b) {
           if (a.Datan>b.Datan) return -1;
           if (a.Datan<b.Datan) return 1;
           return 0;
}
 
function orddata2(a,b) {
           if (a.Datan2>b.Datan2) return -1;
           if (a.Datan2<b.Datan2) return 1;
           return 0;
} 

function ordsquadra(a,b) {
           if (a.IDSquadra>b.IDSquadra) return 1;
           if (a.IDSquadra<b.IDSquadra) return -1;
           return 0;
} 
