// JavaScript Document
//------------------------------------------------
// ANNO 2007
//------------------------------------------------
function f_bill_summ_2008()	{
//OGNI mese bisogna aggiungere "xxx07" ----------------------
/*mesi_vet=["gen06", "feb06", "mar06", "apr06", "mag06", "giu06", "lug06", "ago06", "set06", "ott06", "nov06", "dic06", "eof"];
nomi_vet=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "eof"];
nomi_bill_summ=["GENNAIO_06", "FEBBRAIO_06", "MARZO_06", "APRILE_06", "MAGGIO_06", "GIUGNO_06", "LUGLIO_06", "AGOSTO_06", "SETTEMBRE_06", "OTTOBRE_06", "NOVEMBRE_06", "DICEMBRE_06", "eof"];*/
mesi_vet=["gen08", "feb08", "mar08", "apr08", "mag08", "giu08", "lug08", "ago08", "set08", "ott08", "nov08", "dic08"];
nomi_vet=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
nomi_bill_summ=["GENNAIO_08", "FEBBRAIO_08", "MARZO_08", "APRILE_08", "MAGGIO_08", "GIUGNO_08", "LUGLIO_08", "AGOSTO_08", "SETTEMBRE_08", "OTTOBRE_08", "NOVEMBRE_08", "DICEMBRE_08"];
//------------------------------------------------------------
var Mostra = "";
//Gestisce quando si ha un solo mese, in pratica a Gennaio.
if (mesi_vet.length == 1)	
			{
			solo_gennaio="../../xml/bilancio/betting_tennis_mesecorrente.xml";
			calcola_utile(solo_gennaio);
			utile_solo_gennaio=utile_totale;//ritorna da calcola_utile
			stakes_solo_gennaio=stakes_totale;//ritorna da calcola_utile
			//Variabili visualizzate
			tot_utile=Math.round((utile_solo_gennaio)*100)/100;
			tot_stakes=Math.round((stakes_solo_gennaio)*100)/100;
			tot_roi=Math.round((tot_utile/tot_stakes)*10000)/100;
			}
			else {

//Imposta il file relativo al bilancio dei mesi precedenti a quello corrente
betting_prec_xml="../../xml/bilancio/bill_summ/bill_summ_2008.xml";
//Richiama la funzione che fà i calcoli relativi per estrarre utile e stakes
calcola_utile(betting_prec_xml);
//appoggia i valori in altre variabili per richiamare poi la stessa funzione
utile_mesi_prec=utile_totale;
stakes_mesi_prec=stakes_totale;
j=0;
f_bill_summ_mensile_y07(betting_prec_xml);			
//Imposta k per caricare il file del mese corrente...l'ultimo del vettore mesi_vet
//Ora però il file del mese corrente si chiama diversamente
//k=(mesi_vet.length-1);
//Ripete gli stessi passi di prima
//betting_corr_xml="../xml/bilancio/betting_" + mesi_vet[k] + ".xml"
betting_corr_xml="../../xml/bilancio/betting_tennis_mesecorrente.xml"
calcola_utile(betting_corr_xml);
utile_mese_corr=utile_totale;
stakes_mese_corr=stakes_totale;
//-------------------------------------
//Variabili visualizzate
tot_utile=Math.round((utile_mesi_prec+utile_mese_corr)*100)/100;
tot_stakes=Math.round((stakes_mesi_prec+stakes_mese_corr)*100)/100;
tot_roi=Math.round((tot_utile/tot_stakes)*10000)/100;
}//fine dell'else

Mostra += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
Mostra += "<tr>"
if (tot_utile <= 0)	
			{
			Mostra += "<td id='bt_anni_utile'><font color='red'>" + tot_utile + "</font></td>"
			}
			else {
			Mostra += "<td id='bt_anni_utile'><font color='green'>" + tot_utile + "</font></td>"
			}
Mostra += "<td id='bt_anni_stakes'>" + tot_stakes + "</td>"
if (tot_roi <= 0)	
			{
			Mostra += "<td id='bt_anni_perc'><font color='red'>" + tot_roi + "%" + "</font></td>"
			}
			else {
			Mostra += "<td id='bt_anni_perc'><font color='green'>" + tot_roi + "%" + "</font></td>"
			}
Mostra += "</tr>"
Mostra += "</table>"

// scrive nel td con id=bill_summ_2005
bill_summ_2008.innerHTML = Mostra;
}
//---------------------------------------------
function f_bill_summ_mensile_y07(file)	{

var Mostra = "";

objXml = new ActiveXObject("Microsoft.XMLDOM");
objXml.async = false;
objXml.load(file);	
//j=0;
contatore=(mesi_vet.length-1);
while (j<contatore)
	{ 
			nick_locale = mesi_vet[j];
			mese_locale = nomi_vet[j];
			tag_mese = nomi_bill_summ[j];
			utile_locale = parseFloat(objXml.documentElement.childNodes(j).childNodes(0).text);
			stakes_locale = parseFloat(objXml.documentElement.childNodes(j).childNodes(1).text);
if (utile_locale == 0)
			{
				roi_locale = 0;
			}
			else {
			roi_locale = Math.round((utile_locale/stakes_locale)*10000)/100;
			}

Mostra += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
Mostra += "<tr>"
Mostra += "<td id='bt_mesi'><a href='bilancio_" + nick_locale + "_eng.htm'>" + mese_locale + "</a></td>"//mese
Mostra += "<td><table width='100%' border='0' cellpadding='0' cellspacing='1'><tr>"

if (utile_locale < 0)	
			{
			Mostra += "<td id='bt_mesi_utile'><font color='red'>" + utile_locale + "</font></td>"
			}
			else {
			Mostra += "<td id='bt_mesi_utile'><font color='green'>" + utile_locale + "</font></td>"
			}
Mostra += "<td id='bt_mesi_stakes'>" + stakes_locale + "</td>"
if (roi_locale < 0)	
			{
			Mostra += "<td id='bt_mesi_perc'><font color='red'>" + roi_locale + "%" + "</font></td>"
			}
			else {
			Mostra += "<td id='bt_mesi_perc'><font color='green'>" + roi_locale + "%" + "</font></td>"
			}
			
Mostra += "</tr></table></td>"		
			
Mostra += "</tr>"
Mostra += "</table>"

	year_2008.innerHTML = Mostra;
	j++;
	
	}//fine del ciclo for/while
}
// FINE ANNO 2007 ---------------------------------------------*********************************

//-----------------
// PER OGNI ANNO
//-----------------
//---------------------------------------------
function calcola_utile(file)	{
// Richiamata da f_bill_summ_2005(),f_bill_summ_2007().
	var utile_txt = " ";var stakes_txt = " ";
	var utile_num;var stakes_num;
	somma_utile_anno=0; somma_stakes_anno=0; roi=0;
	var somma_utile_mese=0;var somma_stakes_mese=0;
	utile_totale=0; stakes_totale=0;
	
	objXml = new ActiveXObject("Microsoft.XMLDOM");
	objXml.async = false;
	objXml.load(file);
	// Leggo tutti i nodi del file col metodo getElementsByTagName()
	var utile = objXml.getElementsByTagName("U_UTILE");//questo è un array.
	var stakes = objXml.getElementsByTagName("U_GIOCATE");//questo è un array.
	for (i=0; i<utile.length; i++)
			{
			utile_txt = utile[i].text;
			utile_num = parseFloat(utile_txt);//trasforma la stringa in valore numerico
			utile_totale = utile_totale + utile_num;
			//----------------
			stakes_txt = stakes[i].text;
			stakes_num = parseFloat(stakes_txt);//trasforma la stringa in valore numerico
			stakes_totale = stakes_totale + stakes_num;
			}
}
//-------------------------------------------------------
function f_calcola_totale_mese_corrente()	{
var Mostra = ""; var StringaXml = DSO_totale_mese_corrente.XMLDocument;
var i;
somma_utile=0;
somma_stakes=0;
somma_quota=0;
count_OK=0;
count_tot=StringaXml.documentElement.childNodes.length;
for (i=0; i<StringaXml.documentElement.childNodes.length; i++) {
	
		stakes = StringaXml.documentElement.childNodes(i).childNodes(11).text;//campo unità totali giocate
		utile = StringaXml.documentElement.childNodes(i).childNodes(12).text;//campo utile
		quota = StringaXml.documentElement.childNodes(i).childNodes(5).text;//campo quota
		stakes_num = parseFloat(stakes);//trasforma la stringa in valore numerico
		utile_num = parseFloat(utile);//trasforma la stringa in valore numerico
		quota_num = parseFloat(quota);//trasforma la stringa in valore numerico
		somma_utile = somma_utile + utile_num;
		somma_stakes = somma_stakes + stakes_num;
		somma_quota = somma_quota + quota_num;
		somma_utile_2d=Math.round((somma_utile)*100)/100;//arrotonda a due cifre decimali
		somma_stakes_2d=Math.round((somma_stakes)*100)/100;//arrotonda a due cifre decimali
		somma_quota_2d=Math.round((somma_quota)*100)/100;//arrotonda a due cifre decimali
		//Calcola i colpi OK
		if (utile_num>0)	{
							count_OK = count_OK + 1;
							}
}
//Calcoli supplementari
roi=Math.round((somma_utile_2d/somma_stakes_2d)*10000)/100;//così si ottiene la percentuale con 2 cifre decimali...34.23%
hit_perc=Math.round(((count_OK/count_tot)*100)*100)/100;
average_odds=Math.round(((somma_quota_2d/count_tot))*100)/100;
//--------------------------------------------
Mostra += "<table id='totale_mensile' width='100%' border='0' cellpadding='0' cellspacing='0'>"
Mostra += "<tr>"
Mostra += "<td id='top_left'></td><td id='bordo_lavagna_top'></td><td id='bordo_lavagna_top' ></td><td id='bordo_lavagna_top' ></td><td id='bordo_lavagna_top' ></td><td id='bordo_lavagna_top' ></td><td id='bordo_lavagna_top' ></td><td id='top_right' ></td>"
Mostra += "</tr>"
Mostra += "<tr>"
Mostra += "<td id='bordo_lavagna_left'></td>"
//Mostra += "<td id='totale_mensile_blank'>&nbsp;</td>"
Mostra += "<td id='totale_mensile_label' title='utile=vincita-(unità giocate)'>PROFIT:</td>"
Mostra += "<td id='totale_mensile_label' title='totale unità giocate'>STAKES:</td>"
Mostra += "<td id='totale_mensile_label' title='percentuale utile/(unità totali)'>ROI:</td>"
Mostra += "<td id='totale_mensile_label' title='scommesse OK / totale scomm.'>WIN/STAKES:</td>"
Mostra += "<td id='totale_mensile_label' title='% di realizzazione'>(WIN/STAKES)%:</td>"
Mostra += "<td id='totale_mensile_label' title='quota media'>AVERAGE ODDS:</td>"
//Mostra += "<td id='totale_mensile_blank'>&nbsp;</td>"
Mostra += "<td id='bordo_lavagna_right'></td>"
Mostra += "</tr>"
Mostra += "<tr>"
Mostra += "<td id='bordo_lavagna_left'></td>"
//Mostra += "<td id='totale_mensile_blank'>&nbsp;</td>"
if	(somma_utile<=0) {
						Mostra += "<td id='totale_mensile_utile_red'>" + somma_utile_2d + "</td>"
					 }
					else {
							Mostra += "<td id='totale_mensile_utile'>" + somma_utile_2d + "</td>"
						 }
Mostra += "<td id='totale_mensile_stakes'>" + somma_stakes_2d + "</td>"
if (roi<=0)	{	
			Mostra += "<td id='totale_mensile_roi_red'>" + roi + "%" + "</td>"
			}
			else {
				Mostra += "<td id='totale_mensile_roi'>" + roi + "%" + "</td>"
				}
Mostra += "<td id='totale_mensile_hit'>" + count_OK + "/" + count_tot + "</td>"
Mostra += "<td id='totale_mensile_hit_perc'>" + hit_perc + "%" + "</td>"
Mostra += "<td id='qmedia'>" + average_odds + "</td>"
//Mostra += "<td id='totale_mensile_blank'>&nbsp;</td>"
Mostra += "<td id='bordo_lavagna_right'></td>"
Mostra += "</tr>"
Mostra += "<tr>"
Mostra += "<td id='bottom_left' ></td><td id='bordo_lavagna_bottom'></td><td id='bordo_lavagna_bottom'></td><td id='bordo_lavagna_bottom'></td><td id='bordo_lavagna_bottom'></td><td id='bordo_lavagna_bottom'></td><td id='bordo_lavagna_bottom'></td><td id='bottom_right' ></td>"
Mostra += "</tr>"
Mostra += "</table>"

totale_mese_in_corso.innerHTML = Mostra;
}

//--------------------------------------------------------------------------------------------
function f_betting_mese_corrente()	{
var Mostra = ""; var StringaXml = DSO_mese_corrente.XMLDocument;
var i;
somma =0;
var ghost;var value;
for (i=0; i<StringaXml.documentElement.childNodes.length; i++) {
	valore = StringaXml.documentElement.childNodes(i).childNodes(12).text;
	valore_num = parseFloat(valore);	
	gioco = StringaXml.documentElement.childNodes(i).childNodes(4).text;
				if (valore_num < 0) // utile negativo
								{
										var stato = "_red";
								}
								else	{
										var stato = "_green";
										}
									Mostra += "<table class='ruler' id='bil_mensile_perizie' width='100%' border='0' cellpadding='0' cellspacing='0'>"
									Mostra += "<tbody>"
									Mostra += "<tr>"
									Mostra += "<td id='data_month" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(0).text + "</td>"
									//Gestione della giocata multipla
									if	(gioco=="singola") {
											Mostra += "<td id='player1_month" + stato + "'><b>" + StringaXml.documentElement.childNodes(i).childNodes(2).text + "</b></td>"
											Mostra += "<td id='meno_month" + stato + "'>-</td>"
											Mostra += "<td id='player2_month" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(3).text + "</td>"
					 					}
									else if (gioco=="multipla") {
											Mostra += "<td id='multipla_month" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(6).text + "</td>"
									 }
									//end Gestione della giocata multipla
									Mostra += "<td id='gioco_month" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(4).text + "</td>"
									Mostra += "<td id='quota_month" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(5).text + "</td>"
									Mostra += "<td id='u_giocate" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(11).text + "</td>"
									Mostra += "<td id='book_month" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(7).text + "</td>"
									Mostra += "<td id='tournament_month" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(8).text + "</td>"
									Mostra += "<td id='u_utile" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(12).text + "</td>"
									Mostra += "<td id='arch_perizie" + stato + "'><FORM METHOD='POST'><INPUT type='button' name='bottone' value='"+i+"' onClick='leggi_i(this)'></FORM></td>"
									Mostra += "</tr>"
									Mostra += "</tbody>"
									Mostra += "</table>"
				/*}// fine primo if*/
}

mese_in_corso.innerHTML = Mostra;
}
// FINE PER OGNI ANNO ------------------------------------------------********************
//---------------------
// FUNZIONI GENERICHE
//---------------------
//-------------------------
function tableruler()
{
 if (document.getElementById && document.createTextNode)
  {
   var tables=document.getElementsByTagName('table');
   for (var i=0;i<tables.length;i++)
   {
    if(tables[i].className=='ruler')
    {
     var trs=tables[i].getElementsByTagName('tr');
     for(var j=0;j<trs.length;j++)
     {
      if(trs[j].parentNode.nodeName=='TBODY' && trs[j].parentNode.nodeName!='TFOOT')
       {
       trs[j].onmouseover=function(){this.className='ruled';return false}
       trs[j].onmouseout=function(){this.className='';return false}
     }
    }
   }
  }
 }
}
//------------------------
function startList() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
//------------------------------ END FUNZIONI GENERICHE --------------------------------**************
//------------------------------------------------
// FUNZIONI PER L'ARCHIVIAZIONE DEI VARI ANNI
//------------------------------------------------
//xml sorgente: bill_summ_archivio.xml
function f_bill_summ_arch()	{

var Mostra = ""; var StringaXml = DSO_archivio_bilanci.XMLDocument;
var i;
var anno, u_utile, u_giocate;

for (i=0; i<StringaXml.documentElement.childNodes.length; i++) {
	anno = StringaXml.documentElement.childNodes(i).childNodes(0).text;
	u_utile = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(1).text);
	u_giocate = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(2).text);
	roi=Math.round((u_utile/u_giocate)*10000)/100;

//Tabella Archivio Bilanci
Mostra += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
Mostra += "<tr>"
Mostra += "<td id='bt_anni'><a href='../html/bilancio_" + anno + "_eng.htm' target='_parent'>" + anno +"</a></td>"
if (u_utile <= 0)	
			{
			Mostra += "<td id='bt_anni_utile'><font color='red'>" + u_utile + "</font></td>"
			}
			else {
			Mostra += "<td id='bt_anni_utile'><font color='green'>" + u_utile + "</font></td>"
			}
Mostra += "<td id='bt_anni_stakes'>" + u_giocate + "</td>"
if (roi <= 0)	
			{
			Mostra += "<td id='bt_anni_perc'><font color='red'>" + roi + "%" + "</font></td>"
			}
			else {
			Mostra += "<td id='bt_anni_perc'><font color='green'>" + roi + "%" + "</font></td>"
			}
Mostra += "</tr>"
Mostra += "</table>"
}
archive_bilanci.innerHTML = Mostra;
}
//------------------------------ END FUNZIONI DI ARCHIVIAZIONE -------------------------------**************
// ************* MAIN **********************************************

f_bill_summ_2008();
// Buone x ogni mese
f_bill_summ_arch();
f_calcola_totale_mese_corrente();
f_betting_mese_corrente();
//--------------------------
// Funzioni generiche
tableruler();
startList();
//**************************************************** END ************************************************************************************************
