// JavaScript Document

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 + "</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 calcola_utile(file)	{
	
	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_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;
	tipo = StringaXml.documentElement.childNodes(i).childNodes(15).text;
	pronostico=StringaXml.documentElement.childNodes(i).childNodes(16).text;
	pl1 = StringaXml.documentElement.childNodes(i).childNodes(2).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(14).text + "</td>"
									//Gestione della giocata multipla
									if	(gioco=="singola") {
											Mostra += "<td id='player1_month" + stato + "'>" + pl1 + "</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>"
										if	(tipo=="HA") {
											//manipola il HA separando i vari handicap
												var ha_vect = pronostico.split(",");
												num_set=(ha_vect.length);
											//--------------------
											if	(num_set==1) {
												Mostra += "<td id='tipo_month" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(15).text + "</td>"
												/*Mostra += "<td id='risultato_month" + stato + "'>" + pl1 + " " + ha_vect[0] + "</td>"*/
												Mostra += "<td id='risultato_month" + stato + "'>" + ha_vect[0] + "</td>"/*new....*/
											}
											else if (num_set==2) {
												Mostra += "<td id='tipo_month" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(15).text + "</td>"
												/*Mostra += "<td id='risultato_month" + stato + "'>" + pl1 + " " + ha_vect[0]+ " & " + ha_vect[1] + "</td>"*/
												Mostra += "<td id='risultato_month" + stato + "'>" + ha_vect[0]+ " & " + ha_vect[1] + "</td>"/*NEW*/
											}
										}//fine if tipo==HA
										else {
										Mostra += "<td id='tipo_month" + stato + "'>" + StringaXml.documentElement.childNodes(i).childNodes(15).text + "</td>"
										Mostra += "<td id='risultato_month" + stato + "'>" + pronostico + "</td>"
										}// fine del "ciclo" if per regolare l'HA
									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*/
}//fine del for

mese_in_corso.innerHTML = Mostra;
}

//-----------------------------------------------------------------------------------------------------
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", "");
   }
   }
  }
 }
}
//------------------------------
// ************* MAIN **********************************************
f_calcola_totale_mese_corrente();
f_betting_mese_corrente();

tableruler();
startList();
