// JavaScript Document

//Daily Betting nella pagina lavagne.htm - legge bilancio/betting_apr05.xml

// Questa parte serve per estrarre dall'xml solo i "record" della data odierna
// [usage]: il nodo xml deve avere come tag di apertura/chiusura <MATCH_g_m_yyyy></MATCH_g_m_yyyy>
// I record devono essere inseriti con la data del giorno in cui si vuole che vengano pubblicati sul sito.
function f_daily_betting() {
oggi = new Date()
data_yyyy = oggi.getDate() + "_" + oggi.getMonth() + "_" + oggi.getYear(); 
miadata = "MATCH_" + data_yyyy;
//-----------------------------
var Mostra = ""; var StringaXml = DSO_bet_giornaliero.XMLDocument;
var i;
//Mostra += "<table id='colpi' border='0' cellpadding='0' cellspacing='0'>"


for (i=0; i<StringaXml.documentElement.childNodes.length; i++) {
		testo = StringaXml.documentElement.childNodes(i).nodeName;
		nostra_lavagna = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(15).text);
		odd = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(5).text);
		vantaggio = Math.round(((100/nostra_lavagna) - (100/odd))*100)/100;
		//Gestione giocata multipla
		gioco = StringaXml.documentElement.childNodes(i).childNodes(4).text;
		//-----------
		//q_limite_num = parseFloat('quota');//trasforma la stringa in valore numerico
// Calcola la quota limite in ragione del 7%
		//q_limite_num = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(5).text);//trasforma la stringa in valore numerico
		//q_limite_num_perc = Math.round((((q_limite_num)*7)/100)*100)/100;//arrotonda a due cifre decimali e calcola il 7%
		//q_limite = Math.round((q_limite_num - q_limite_num_perc)*100)/100;
//------------------------------------------
// Calcola la probabilità dell'evento 100/q
		//prob_num = q_limite_num;//prende sempre la quota
		prob_num = odd;//prende sempre la quota
		//prob_num_perc = Math.round((100/prob_num)*100)/100;//arrotonda a due cifre decimali
//------------------------------------------
			if (testo == miadata) {
						 
						Mostra += "<table class='ruler' id='type_tabelle_bilancio' width='100%' border='0' cellpadding='0' cellspacing='0'>"
						Mostra += "<tr>"
						 Mostra += "<td id='data_green_bic'>" + StringaXml.documentElement.childNodes(i).childNodes(0).text + "</td>"
						 Mostra += "<td id='stop_green_bic'>" + StringaXml.documentElement.childNodes(i).childNodes(1).text + "</td>"
						 //Gestione giocata multipla
						 if	(gioco=="singola") {
											Mostra += "<td id='player1_green_bic'><b>" + StringaXml.documentElement.childNodes(i).childNodes(2).text + "</b></td>"
											Mostra += "<td id='meno_green_bic'>-</td>"
											Mostra += "<td id='player2_green_bic'>" + StringaXml.documentElement.childNodes(i).childNodes(3).text + "</td>"
					 					}
									else if (gioco=="multipla") {
											Mostra += "<td id='multipla_green_bic'>" + StringaXml.documentElement.childNodes(i).childNodes(6).text + "</td>"
									 }
						 // end gestione giocata multipla
						 Mostra += "<td id='quota_green_bic'>" + odd + "</td>"
//						 Mostra += "<td id='quota_limite'>" + StringaXml.documentElement.childNodes(i).childNodes(10).text + "</td>"
 						 Mostra += "<td id='unita_green_bic'>" + StringaXml.documentElement.childNodes(i).childNodes(11).text + "</td>"
						Mostra += "<td id='vantaggio_green_bic'>" + vantaggio + " %</td>"
//						 Mostra += "<td id='evento'>" + StringaXml.documentElement.childNodes(i).childNodes(6).text + "</td>"
						 //Mostra += "<td id='perc_evento_green'>" + prob_num_perc + "%" + "</td>"
						 //Mostra += "<td id='book_green'>" + StringaXml.documentElement.childNodes(i).childNodes(7).text + "</td>"
						//Mostra += "<td id='gioco_green'>" + StringaXml.documentElement.childNodes(i).childNodes(4).text + "</td>"
						Mostra += "<td id='tournament_green_bic'>" + StringaXml.documentElement.childNodes(i).childNodes(8).text + "</td>"						 
						Mostra += "</tr>"
						Mostra += "</table>"
						 //Mostra += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
						 //Mostra += "<tr>"
						 //Mostra += "<td id='tournament_green' valign='center'><b>" + StringaXml.documentElement.childNodes(i).childNodes(8).text + "</b></td>"
//						 Mostra += "<td id='perizia' align='left'><p>" + StringaXml.documentElement.childNodes(i).childNodes(9).text + "</p></td>"
						 //Mostra += "<td id='perizia_green' align='left'>" + StringaXml.documentElement.childNodes(i).childNodes(9).text + "</td>"
						 //Mostra += "</tr>"
						}
		}
		Mostra += "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td>&nbsp;</td></tr><tr><td id='link_leggi'><a href='#schede_match'>schede match</a></td></tr></table>"
betting_giornaliero.innerHTML = Mostra;
}
//------------------------------
function f_daily_betting_calcio() {
oggi = new Date();
data_yyyy = oggi.getDate() + "_" + oggi.getMonth() + "_" + oggi.getYear(); 
miadata = "MATCH_" + data_yyyy;
//-----------------------------
var Mostra = ""; var StringaXml = DSO_bet_giornaliero_calcio.XMLDocument;
var i;

for (i=0; i<StringaXml.documentElement.childNodes.length; i++) {
		testo = StringaXml.documentElement.childNodes(i).nodeName;
		/* ------ DEBUG
		alert("-->lunghezza "+StringaXml.documentElement.childNodes.length);
		alert("-->i "+i);
		alert(testo);*/
		//--------------- ERRORE ----------------------------
		nostra_lavagna = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(17).text);
		//--------------- ERRORE ----------------------------
		odd = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(5).text);
		vantaggio = Math.round(((100/nostra_lavagna) - (100/odd))*100)/100;
		//Gestione giocata multipla
		gioco = StringaXml.documentElement.childNodes(i).childNodes(4).text;
		tipo = StringaXml.documentElement.childNodes(i).childNodes(15).text;
		pronostico=StringaXml.documentElement.childNodes(i).childNodes(16).text;
// Calcola la quota limite in ragione del 7%
		//q_limite_num = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(5).text);//trasforma la stringa in valore numerico
		//q_limite_num_perc = Math.round((((q_limite_num)*7)/100)*100)/100;//arrotonda a due cifre decimali e calcola il 7%
		//q_limite = Math.round((q_limite_num - q_limite_num_perc)*100)/100;
//------------------------------------------
// Calcola la probabilità dell'evento 100/q
		//prob_num = q_limite_num;//prende sempre la quota
		//prob_num_perc = Math.round((100/prob_num)*100)/100;//arrotonda a due cifre decimali
//------------------------------------------
		if (testo == miadata) {
						Mostra += "<table class='ruler' id='type_tabelle_bilancio' width='100%' border='0' cellpadding='0' cellspacing='0'>"
						 Mostra += "<tr>"
						 Mostra += "<td id='data_green'>" + StringaXml.documentElement.childNodes(i).childNodes(0).text + "</td>"
						 Mostra += "<td id='stop_green'>" + StringaXml.documentElement.childNodes(i).childNodes(1).text + "</td>"
						 //Gestione giocata multipla....ORIG
						 /*if	(gioco=="singola") {
											Mostra += "<td id='player1_calcio'>" + StringaXml.documentElement.childNodes(i).childNodes(2).text + "</td>"
											Mostra += "<td id='meno'>-</td>"
											Mostra += "<td id='player2_calcio'>" + StringaXml.documentElement.childNodes(i).childNodes(3).text + "</td>"
					 					}
									else if (gioco=="multipla") {
											Mostra += "<td id='multipla_calcio'>" + StringaXml.documentElement.childNodes(i).childNodes(6).text + "</td>"
									 }*/
						 // end gestione giocata multipla

						 //Gestione della giocata multipla
									if	(gioco=="singola") {
											//Mostra += "<td id='player1_green'>" + StringaXml.documentElement.childNodes(i).childNodes(2).text + "</td>"
											//Mostra += "<td id='meno_green'>-</td>"
											//Mostra += "<td id='player2_green'>" + StringaXml.documentElement.childNodes(i).childNodes(3).text + "</td>"
					 					}
									else if (gioco=="multipla") {
											Mostra += "<td id='multipla_green'>" + StringaXml.documentElement.childNodes(i).childNodes(6).text + "</td>"
									 }
										//end Gestione della giocata multipla
									//Mostra += "<td id='gioco_green'>" + 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'>" + StringaXml.documentElement.childNodes(i).childNodes(15).text + "</td>"
												Mostra += "<td id='prono'><b>" + ha_vect[0] + "</b></td>"
											}
											else if (num_set==2) {
												//Mostra += "<td id='tipo'>" + StringaXml.documentElement.childNodes(i).childNodes(15).text + "</td>"
												Mostra += "<td id='prono'><b>" + ha_vect[0]+ "&" + ha_vect[1] + "</b></td>"
											}
										}//fine if tipo==HA
										else {
										//Mostra += "<td id='tipo'>" + StringaXml.documentElement.childNodes(i).childNodes(15).text + "</td>"
										Mostra += "<td id='prono'><b>" + pronostico + "</b></td>"
										}// fine del "ciclo" if per regolare l'HA

						 /*Mostra += "<td id='gioco_calcio'>" + StringaXml.documentElement.childNodes(i).childNodes(4).text + "</td>"*/
 						Mostra += "<td id='quota_green'>" + StringaXml.documentElement.childNodes(i).childNodes(5).text + "</td>"
						Mostra += "<td id='unita_green'>" + StringaXml.documentElement.childNodes(i).childNodes(11).text + "</td>"
						//Mostra += "<td id='quota_limite'>" + StringaXml.documentElement.childNodes(i).childNodes(10).text + "</td>"
						Mostra += "<td id='vantaggio_green'>" + vantaggio + " %</td>"
						//Mostra += "<td id='evento'>" + StringaXml.documentElement.childNodes(i).childNodes(6).text + "</td>"
						 //Mostra += "<td id='perc_evento_green'>" + prob_num_perc + "%" + "</td>"
						Mostra += "<td id='tournament_green' valign='center'>" + StringaXml.documentElement.childNodes(i).childNodes(8).text + "</td>"						 
						//Mostra += "<td id='book_green'>" + StringaXml.documentElement.childNodes(i).childNodes(7).text + "</td>"
						 Mostra += "</tr>"
						 Mostra += "</table>"
						 //Mostra += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
						 //Mostra += "<tr>"
						 //Mostra += "<td id='tournament_calcio' valign='center'><b>" + StringaXml.documentElement.childNodes(i).childNodes(8).text + "</b></td>"
						//Mostra += "<td id='perizia' align='left'><p>" + StringaXml.documentElement.childNodes(i).childNodes(9).text + "</p></td>"
						 //Mostra += "<td id='perizia_calcio' align='left'>" + StringaXml.documentElement.childNodes(i).childNodes(9).text + "</td>"
						 //Mostra += "</tr>"
						 //Mostra += "</table>"
						}//fine if testo == miadata
		}//fine del FOR più esterno
		
betting_giornaliero_calcio.innerHTML = Mostra;
}
//------------------------------
function f_schede_tennis() {
oggi = new Date();

data_yyyy = oggi.getDate() + "_" + oggi.getMonth() + "_" + oggi.getYear(); 
miadata = "MATCH_" + data_yyyy;
//-----------------------------
var Mostra = ""; var StringaXml = DSO_schede_tennis.XMLDocument;
var i;
//alert("nella funzione");
for (i=0; i<StringaXml.documentElement.childNodes.length; i++) {
		//alert("Primo ciclo for");
		testo = StringaXml.documentElement.childNodes(i).nodeName;
		
		player1 = StringaXml.documentElement.childNodes(i).childNodes(2).text;
		player2 = StringaXml.documentElement.childNodes(i).childNodes(3).text;
		//Gestione giocata multipla
		gioco = StringaXml.documentElement.childNodes(i).childNodes(4).text;
		//-----------
		odd = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(5).text);
		torneo = StringaXml.documentElement.childNodes(i).childNodes(8).text;
		perizia = StringaXml.documentElement.childNodes(i).childNodes(9).text;
		nostra_lavagna = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(15).text);
		
		vantaggio = Math.round(((100/nostra_lavagna) - (100/odd))*100)/100;
		
		//q_limite_num = parseFloat('quota');//trasforma la stringa in valore numerico
// Calcola la quota limite in ragione del 7%
		//q_limite_num = parseFloat(StringaXml.documentElement.childNodes(i).childNodes(5).text);//trasforma la stringa in valore numerico
		//q_limite_num_perc = Math.round((((q_limite_num)*7)/100)*100)/100;//arrotonda a due cifre decimali e calcola il 7%
		//q_limite = Math.round((q_limite_num - q_limite_num_perc)*100)/100;
//------------------------------------------
// Calcola la probabilità dell'evento 100/q
		//prob_num = q_limite_num;//prende sempre la quota
		prob_num = odd;//prende sempre la quota
		//prob_num_perc = Math.round((100/prob_num)*100)/100;//arrotonda a due cifre decimali
//------------------------------------------
			if (testo == miadata) {
						 
					//Mostra += "<table id='scheda' width='70%' border='2' cellpadding='0' cellspacing='0'>"
					Mostra += "<table id='scheda' width='450px' border='0' cellpadding='0' cellspacing='0'>"
						
						Mostra += "<tr><td>"
						Mostra += "<table id='scheda_match' width='100%' border='0' cellpadding='0' cellspacing='0'>"
						//Gestione giocata multipla
						 if	(gioco=="singola") {
											Mostra += "<td align='right' id='s_player_green'><b>" + player1 + "</b></td>"
											Mostra += "<td id='meno_green'>-</td>"
											Mostra += "<td align='left' id='s_player_black'>" + player2 + "</td>"
											//Mostra += "<tr><td id='s_player'>" + player1 + " su " +  player2 +"</td><tr>"
					 					}
									else if (gioco=="multipla") {
											Mostra += "<tr><td><h3>" + StringaXml.documentElement.childNodes(i).childNodes(6).text +"</h3></td><tr>"
											//Mostra += "<td id='multipla_green'>" + StringaXml.documentElement.childNodes(i).childNodes(6).text + "</td>"
									 }
						 // end gestione giocata multipla
							
						Mostra += "</table>"
						Mostra += "</tr></td>"

						Mostra += "<tr><td>"
						Mostra += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
										Mostra += "<tr>"
											Mostra += "<td id='s_label'>Data:</td>"
											Mostra += "<td id='s_data'>" + StringaXml.documentElement.childNodes(i).childNodes(0).text + "</td>"
										Mostra += "</tr>"
										Mostra += "<tr>"
											Mostra += "<td id='s_label'>Stop:</td>"
											Mostra += "<td id='s_stop'>" + StringaXml.documentElement.childNodes(i).childNodes(1).text + "</td>"
										Mostra += "</tr>"
										Mostra += "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>"
						Mostra += "</table>"
						Mostra += "</td></tr>"

						Mostra += "<tr><td>"
						Mostra += "<table  width='100%' border='0' cellpadding='0' cellspacing='0'>"
							Mostra += "<tr><td align='left'>"//I colonna
								Mostra += "<table  width='280px' border='0' cellpadding='0' cellspacing='0'>"
										Mostra += "<tr>"
											Mostra += "<td id='s_label'>Quota:</td>"
											Mostra += "<td id='s_quota'>" + odd + "</td>"
										Mostra += "</tr>"
										Mostra += "<tr>"
											Mostra += "<td id='s_label'>Unità giocate:</td>"
											Mostra += "<td id='s_unita'>" + StringaXml.documentElement.childNodes(i).childNodes(11).text + "</td>"
										Mostra += "</tr>"
										//Mostra += "<tr>"
											//Mostra += "<td id='s_label'>Vantaggio:</td>"
											//Mostra += "<td id='s_vantaggio'>" + vantaggio + " %</td>"
										//Mostra += "</tr>"
										Mostra += "<tr>"
											Mostra += "<td id='s_label'>Torneo:</td>"
											Mostra += "<td id='s_torneo'>" + torneo + "</td>"
										Mostra += "</tr>"
										Mostra += "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>"
								Mostra += "</table>"										
							Mostra += "</td>"//end I colonna
							Mostra += "<td>"//II colonna
								Mostra += "<table id='lavagna_vb' width='170px' height='175px' border='0' cellpadding='0' cellspacing='0'>"
									//Mostra += "<tr><td><img src='/images/lavagna_vb_opaca.gif'/></td></tr>"
									Mostra += "<tr><td><font color='#FFFFFF' size='+2'><strong>" + vantaggio + "%</strong></font></td></tr>"
									
								Mostra += "</table>"										
							Mostra += "</td>"//end II colonna
						Mostra += "</table>"
						Mostra += "</td></tr>"
 						Mostra += "<tr><td>"
						Mostra += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
										
										Mostra += "<tr>"
											Mostra += "<td id='s_label'>Perizia:</td>"
											Mostra += "<td id='s_perizia'>" + perizia + "</td>"
										Mostra += "</tr>"
										Mostra += "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>"
										Mostra += "<tr>"
											Mostra += "<td id='s_label'>Gioco:</td>"
											Mostra += "<td id='s_gioco'>" + gioco + "</td>"
										Mostra += "</tr>"
						Mostra += "</table>"
						Mostra += "</td></tr>"

						 
						 
						// Mostra += "<td id='quota_green'>" + odd + "</td>"
//						 Mostra += "<td id='quota_limite'>" + StringaXml.documentElement.childNodes(i).childNodes(10).text + "</td>"
 						 //Mostra += "<td id='unita_green'>" + StringaXml.documentElement.childNodes(i).childNodes(11).text + "</td>"
						//Mostra += "<td id='vantaggio_green'>" + vantaggio + " %</td>"
//						 Mostra += "<td id='evento'>" + StringaXml.documentElement.childNodes(i).childNodes(6).text + "</td>"
						 //Mostra += "<td id='perc_evento_green'>" + prob_num_perc + "%" + "</td>"
						 //Mostra += "<td id='book_green'>" + StringaXml.documentElement.childNodes(i).childNodes(7).text + "</td>"
						//Mostra += "<td id='gioco_green'>" + StringaXml.documentElement.childNodes(i).childNodes(4).text + "</td>"
						//Mostra += "<td id='tournament_green'>" + StringaXml.documentElement.childNodes(i).childNodes(8).text + "</td>"						 
						//Mostra += "</tr>"
						Mostra += "</table>"
						Mostra += "<table width='90%' border='0' cellpadding='0' cellspacing='0'><tr><td>&nbsp;</td><td>&nbsp;</td></tr></table>"
						 //Mostra += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
						 //Mostra += "<tr>"
						 //Mostra += "<td id='tournament_green' valign='center'><b>" + StringaXml.documentElement.childNodes(i).childNodes(8).text + "</b></td>"
//						 Mostra += "<td id='perizia' align='left'><p>" + StringaXml.documentElement.childNodes(i).childNodes(9).text + "</p></td>"
						 //Mostra += "<td id='perizia_green' align='left'>" + StringaXml.documentElement.childNodes(i).childNodes(9).text + "</td>"
						 //Mostra += "</tr>"
						
						}
 
		}

schede_tennis.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_daily_betting();
f_daily_betting_calcio();
f_schede_tennis();
tableruler();
//startList();
