/*betting*/
function selectOdds(gameId,tipoScomm){				
	nome="sbmt_"+gameId+"_"+tipoScomm;
	document.getElementById(nome).click();
}

/*SERVE PER CAMBIARE IL CSS*/
function defCss()
{
	if(document.getElementById("nomeCss")!=null && document.getElementById("nomeCss")!=undefined){
		css=document.getElementById("nomeCss").value;
		
		if(navigator.appName=="Microsoft Internet Explorer")
	    	css=css+".css";
	    else
	    	 css=css+"_frx.css";
		document.getElementById("linkcss").href=css;
	}
}    	 
function riconosciBrowser()
{
	if(navigator.appName!="Microsoft Internet Explorer"){
		var w = 520;
		   var h = 200;
		   var l = Math.floor((screen.width-w)/2);
		   var t = Math.floor((screen.height-h)/2);
		   window.open("/AtlantisBet/pop-up/avviso.jsp","avviso","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
	 	}
} 

/*contratto*/
function openContratto(idGioco,token,idRivenditore,idConto)
{
	var width  = dimensioni[idGioco]["buy"][0]; // larghezza e altezza vengono impostate
	var height = dimensioni[idGioco]["buy"][1]; // nel contenitore 'dimensioni'
	var title  = dimensioni[idGioco]["title"];  // titolo del gioco
	
	// calcolo per l'apertura della popup al centro dello schermo
	var pLeft  = (screen.width - width) / 2;
  	var pRight = (screen.height - height) / 2;

	window.open('/AtlantisBet/private/actions/ViewAccettazioneContrattoAction.action?idGioco='+idGioco+'&token='+token+'&idRivenditore='+idRivenditore+'&idConto='+idConto, 'info', 'left=' + pLeft + ',top=' + pRight + ',width=' + width + ',height=' + height + ',scrollbars=yes,resizable=no,status=yes');
}

function accettaContratto()
{
	var idConto = document.getElementById('idConto').value;
	var idGioco = document.getElementById('idGioco').value;
	var idRivenditore = document.getElementById('idRivenditore').value;
	var token = document.getElementById('token').value;
	var radioLength = document.form1.contratto.length;
	
	var width  = dimensioni[idGioco]["buy"][0]; // larghezza e altezza vengono impostate
	var height = dimensioni[idGioco]["buy"][1]; // nel contenitore 'dimensioni'
	var title  = dimensioni[idGioco]["title"];  // titolo del gioco
	
	// calcolo per l'apertura della popup al centro dello schermo
	var pLeft  = (screen.width - width) / 2;
  	var pRight = (screen.height - height) / 2;
	
	for(var i=0; i<radioLength; i++)
	{
		if(document.form1.contratto[i].checked && document.form1.contratto[i].value=='SI')
		{	window.open('/AtlantisBet/private/actions/ConfirmAccettazioneContrattoAction.action?idGioco='+idGioco+'&token='+token+'&idRivenditore='+idRivenditore+'&idConto='+idConto, 'info', 'left=' + pLeft + ',top=' + pRight + ',width=' + width + ',height=' + height + ',scrollbars=no,resizable=no,status=yes');
			break;
		}
		else if(document.form1.contratto[i].checked && document.form1.contratto[i].value=='NO')
		{	window.close();
			break;
		}
			
	}
}

function gioca()
{
	var idConto = document.getElementById('idConto').value;
	var idGioco = document.getElementById('idGioco').value;
	var idRivenditore = document.getElementById('idRivenditore').value;
	var token = document.getElementById('token').value;
	
	var width  = dimensioni[idGioco]["buy"][0]; // larghezza e altezza vengono impostate
	var height = dimensioni[idGioco]["buy"][1]; // nel contenitore 'dimensioni'
	var title  = dimensioni[idGioco]["title"];  // titolo del gioco
	
	// calcolo per l'apertura della popup al centro dello schermo
	var pLeft  = (screen.width - width) / 2;
  	var pRight = (screen.height - height) / 2;
	window.close();
	buyLauncher(idGioco, token, idConto, idRivenditore);
}

/*coupon*/
function ricalcolaImporto(importo,saldoUtente,maxGiocabile)
{	
	var expr = /^[0-9]*$/;
	var exprLettere=/^[a-zA-Z]*$/;
	importo=document.getElementById("fieldImport").value;
	if(exprLettere.test(importo)){
		alert("Attenzione importo non valido! Si possono inserire solo numeri.")
		importo=3;
		document.getElementById("sbmSched").disabled=true;
	}
	else if(isNaN( parseInt(importo))||!expr.test(importo)){
		alert("Attenzione importo non valido! Si possono giocare solo importi interi superiori a 2 Euro.")
		importo=parseInt(importo);
		if(importo>=2)
			document.getElementById("nuovoImporto").value=importo;
		document.getElementById("sbmSched").disabled=true;
	}
	/*
	if(importo<3)
	{
		alert("Attenzione l'importo deve essere almeno 3 Euro!\nValore attuale: "+importo );
		importoNew=3;
		alert("Alert 3 Euro! importoNew="+importoNew);
		document.getElementById("nuovoImporto").value=importoNew;
		document.getElementById("sbmSched").disabled=true;
	}
	else  */
	if(importo>saldoUtente)
	{
		alert("Attenzione l'importo supera il saldo disponibile!")
		document.getElementById("sbmSched").disabled=true;
	}
	else if(importo>maxGiocabile)
	{
		alert("Attenzione stai cercando di giocare una cifra superiore al massimo consentito.")
		document.getElementById("sbmSched").disabled=true;
	}
	else
	{							
		document.getElementById("sbmSched").disabled=false;
		document.getElementById("nuovoImporto").value=importo;
		document.getElementById("submitFrmImporto").click();
	}
}


function eliminaScommessa(gameId,nrEvento)
{
	document.getElementById("scomEliminata").value=gameId;
	document.getElementById("nrEventoEliminata").value=nrEvento;
	document.getElementById("submitFrmElimina").click();
}   

function selezionaDeselezionaScommessa(gameId,nrEvento)
{
	document.getElementById("gameIdSelDeselBet").value=gameId;
	document.getElementById("nrEventoSelDeselBet").value=nrEvento;
	document.getElementById("submitSelDeselBet").click();
}

function dettaglioScommessa(matchId)
{
	document.getElementById("frmMatchMatchId").value=matchId;
	document.getElementById("submitFrmScomMatch").click();
}   

/*menu*/
function aggiornaMenu(sportId,altriSportIdMenu){
	document.getElementById("sportIdMenu").value=sportId;	
	document.getElementById("altriSportIdMenu").value=altriSportIdMenu;
	document.getElementById("competitionId").value=0;
	document.getElementById("sbmtMenuAjaxForm").click();
	
}
function aggiornaMenuComp(sportId,altriSportIdMenu){
	document.getElementById("sportIdMenu").value=sportId;	
	document.getElementById("altriSportIdMenu").value=altriSportIdMenu;
	document.getElementById("competitionId").value=999999;
	document.getElementById("sbmtMenuAjaxForm").click();
	
}
// Script for GoalsLive PopUp
function goalslivepopup(){
	var tmp;
	if (aPopupWin){tmp=aPopupWin;aPopupWin=null;}
	aPopupWin=window.open('http://www.GoalsLive.com/new/live/index4.aspx?myid=3620','GoalsLive','height=400,location=0,menubar=0,personalbar=0,scrollbars=1,status=0,toolbar=0,width=580,resizable=1,screenx=0,screeny=0,left=0,top=0');
} var aPopupWin;

/*submit*/
function swaper(){
	if(document.formName.Accedi.style.color=="orange")
		document.formName.Accedi.style.color="white";
	else
		document.formName.Accedi.style.color="orange";
}
function swaper2(){
	if(document.formName.Logout.style.color=="orange")
		document.formName.Logout.style.color="white";
	else
		document.formName.Logout.style.color="orange";
}	

/*vetrina*/ 
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
function HideAll(){
	var tab0 =  document.getElementById("tab0")
	var tab1 =  document.getElementById("tab1")
	var tab2 =  document.getElementById("tab2")
	//var tab3 =  document.getElementById("tab3")
	//var tab4 =  document.getElementById("tab4")
	
	tab0.style.display="none";
	tab1.style.display="none";
	tab2.style.display="none";
	//tab3.style.display="none";
	//tab4.style.display="none";
}

function View(obj){
	HideAll();
	var objtab =  document.getElementById(obj);
	objtab.style.display="block";
}	

/*registrazione*/

function setAbility(){
         if (document.form1.accetto.checked){
            document.form1.Conferma.disabled = false;
         }
         else{
         document.form1.Conferma.disabled=true;
         }
}
function annulla(){
			if(confirm('Sei sicuro di voler annullare la registrazione?')){
				window.location.replace("/AtlantisBet"); 
			}	
		}
		
function dettaglioScommesseBR(matchId) {
	var href='http://www.stats.betradar.com/statistics/atlantisbet/main.php?page=guth_statistics_headtohead&language=it&matchid='+matchId;
	var load = window.open(href,'','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}

function tornaTop()
{	return document.getElementById('info-Cavallo').style.top;
}

function inline(y,idPalinsesto,idEvento,idEsito)
{	
	
	
	if(navigator.appName=="Microsoft Internet Explorer"){
		
		document.getElementById('info-Cavallo').style.top=(y)+'px';
		document.getElementById('info-Cavallo').style.display="inline";
	}

	document.getElementById('idPalinsestoInfoCavallo').value=idPalinsesto;
	document.getElementById('idEventoInfoCavallo').value=idEvento;
	document.getElementById('idEsitoInfoCavallo').value=idEsito;
	document.getElementById('idPalinsestoInfoCavalloInterno').value=idPalinsesto;
	document.getElementById('idEventoInfoCavalloInterno').value=idEvento;
	document.getElementById('idEsitoInfoCavalloInterno').value=idEsito;
	
	document.getElementById('posizioneInfoCavallo').value=y;
	
	document.getElementById('sbmtInfoCavallo').click();
	
	document.getElementById('sbmtInfoCavalloInterno').click();
	
} 
function piazza(numeroVolte,colonneGiocate,importoScommesso)
{	
	
	document.getElementById('numeroVolte').value=numeroVolte;
	document.getElementById('colonneGiocate').value=colonneGiocate;
	document.getElementById('importoScommesso').value=importoScommesso;

	document.getElementById('sbmtPiazza').click();

	
} 
function infoCavallo(idPalinsesto,idEvento,idEsito)
{
	document.getElementById('idPalinsestoInfoCavallo').value=idPalinsesto;
	document.getElementById('idEventoInfoCavallo').value=idEvento;
	document.getElementById('idEsitoInfoCavallo').value=idEsito;
	document.getElementById('sbmtInfoCavallo').click();
	document.getElementById('cont-infoCavallo').style.display="inline";
}
function dispNone()
{
	if(document.getElementById('info-Cavallo')!=null)
	document.getElementById('info-Cavallo').style.display="none";
}
/**  SCRIPT IPPICA  **/
function scegliCorsaSingolaAbilitazioniScommesse(idConcorso,idPalinsesto,idEvento)
{
	scegliCorsaSingola(idConcorso);
	abilitazioniScommesse(idPalinsesto,idEvento);
	visualizzaTabellaCavalli(idPalinsesto,idEvento,idConcorso);

	azzera();
	calcolaImporto('3');
}
function scegliCorsaSingola(idConcorso)
{	
	document.getElementById('idConcorsoScelta').value=idConcorso;
	document.getElementById('idConcorsoConfirm').value=idConcorso;
	document.getElementById('sbmtCorsaSingola').click();
}
function abilitazioniScommesse(idPalinsesto,idEvento)
{
	document.getElementById('idPalinsestoScommetti').value=idPalinsesto;
	document.getElementById('idEventoScommetti').value=idEvento;
	document.getElementById('sbmtScommetti').click();
}
function visualizzaTabellaCavalli(idPalinsesto,idEvento,idConcorso)
{
	document.getElementById('idPalinsestoCavalli').value=idPalinsesto;
	document.getElementById('idEventoCavalli').value=idEvento;	
	document.getElementById('idConcorsoCavalli').value=idConcorso;	
	document.getElementById('sbmtCavalli').click();
}
function scegliTipo(id)
{	
	for(var i=1; i<=5; i++)
	{	
		if(document.getElementById('tipo'+i)!=undefined)
		{	document.getElementById('tipo'+i).className="iQuadratinoNoSelezione";
			document.getElementById('iCinquetipo'+i).style.display='none';
			document.getElementById('iCinqueNotipo'+i).style.display='inline';			
		}
	}
	document.getElementById('volte').value='volte1';
	document.getElementById(id).className="iQuadratinoSelezione";
	document.getElementById('tipo').value=id;
	document.getElementById('iCinque'+id).style.display='inline';
	document.getElementById('iCinqueNo'+id).style.display='none';
	document.getElementById('erroreGiocataMinima').style.display='none';
	document.getElementById('erroreImportoMinimo').style.display='none';
	
	checkAbilitazione();
	moltiplicaColonne();
	visualizzaConferma();
	
}
function scegliGioco(id)
{
	for(var i=1; i<=2; i++)
		document.getElementById('gioco'+i).className="iQuadratinoNoSelezione";
	document.getElementById(id).className="iQuadratinoSelezione";
	document.getElementById('gioco').value=id;
	document.getElementById('erroreGiocataMinima').style.display='none';
	document.getElementById('erroreImportoMinimo').style.display='none';
	
	checkAbilitazione();
	moltiplicaColonne();
	visualizzaConferma();
}

function selezionaTuttiCavalli(riga)
{
	if(document.getElementById('selCavalloTutti'+riga).className=="iQuadratinoNoSelezione")
	{
		document.getElementById('selCavalloTutti'+riga).className="iQuadratinoSelezione";
		document.getElementById('selCavalloFont'+riga).className="iFontWhite-piccolo";
		for(i=1; i<=20; i++)
		{
			if(document.getElementById('selCavallo'+riga+i)!=undefined && document.getElementById('selCavallo'+riga+i).className=="iQuadratinoNoSelezione")
			{	document.getElementById('selCavallo'+riga+i).className="iQuadratinoSelezione";
				document.getElementById('selCavalloFont'+riga+i).className="iFontWhite-piccolo";
				document.getElementById('numCavallo_'+riga+'_'+i).value="true";
				document.getElementById('num').value=Number(document.getElementById('num').value)+1;
			}
		}
	}
	else
	{
		document.getElementById('selCavalloTutti'+riga).className="iQuadratinoNoSelezione";
		document.getElementById('selCavalloFont'+riga).className="iFontRed-piccolo";
		for(i=1; i<=20; i++)
		{
			if(document.getElementById('selCavallo'+riga+i)!=undefined && document.getElementById('selCavallo'+riga+i).className=="iQuadratinoSelezione")
			{	document.getElementById('selCavallo'+riga+i).className="iQuadratinoNoSelezione";
				document.getElementById('selCavalloFont'+riga+i).className="iFontRed-piccolo";
				document.getElementById('numCavallo_'+riga+'_'+i).value="false";
				document.getElementById('num').value=Number(document.getElementById('num').value)-1;
			}
		}
	}
	document.getElementById('erroreGiocataMinima').style.display='none';
	document.getElementById('erroreImportoMinimo').style.display='none';
	
	calcolaColonneImporto();
	moltiplicaColonne();
	visualizzaConferma();       
}
function selezionaCavallo(riga,idCavallo)
{	
	
	if(document.getElementById('selCavallo'+riga+idCavallo).className=="iQuadratinoNoSelezione")
	{
		document.getElementById('selCavallo'+riga+idCavallo).className="iQuadratinoSelezione";
		document.getElementById('selCavalloFont'+riga+idCavallo).className="iFontWhite-piccolo";
		document.getElementById('numCavallo_'+riga+'_'+idCavallo).value="true";
		document.getElementById('num').value=Number(document.getElementById('num').value)+1;
	}
	else
	{	document.getElementById('selCavallo'+riga+idCavallo).className="iQuadratinoNoSelezione";
		document.getElementById('selCavalloFont'+riga+idCavallo).className="iFontRed-piccolo";
		document.getElementById('numCavallo_'+riga+'_'+idCavallo).value="false";
		document.getElementById('num').value=Number(document.getElementById('num').value)-1;
	}
	document.getElementById('erroreGiocataMinima').style.display='none';
	document.getElementById('erroreImportoMinimo').style.display='none';
	
	calcolaColonneImporto();
	moltiplicaColonne();
	visualizzaConferma();
}
function calcolaColonneImporto()
{
	var num = Number(document.getElementById('num').value);
	var gruppi = Number(document.getElementById('gruppi').value);
	var minimo = Number(document.getElementById('minimoSelezionabileAGirare').value);
	var gioco = document.getElementById('gioco').value;
	if(num!=0)
	{	if(gioco=='gioco2' && num>=minimo) // gioco 'A girare'
			document.getElementById('colonne').value=binomiale(num,gruppi);
		else if(gioco=='gioco1') // gioco 'Ordine esatto'
			document.getElementById('colonne').value=calcolaColonneOrdineEsatto();
		else
			document.getElementById('colonne').value='0';
	}
	else
		document.getElementById('colonne').value='0';
	
	calcolaImporto(gruppi);
}
function moltiplicaColonne(tipo)
{
	var volte = document.getElementById('volte').value;
	var colonne = document.getElementById('colonne').value;
	
	if(volte=='volte1')
		document.getElementById('colonne').value=Number(document.getElementById('colonne').value)*1;
	else if(volte=='volte2')
		document.getElementById('colonne').value=Number(document.getElementById('colonne').value)*2;
	else if(volte=='volte3')
		document.getElementById('colonne').value=Number(document.getElementById('colonne').value)*4;
	else if(volte=='volte4')
		document.getElementById('colonne').value=Number(document.getElementById('colonne').value)*5;
	else if(volte=='volte5')
		document.getElementById('colonne').value=Number(document.getElementById('colonne').value)*10;
	else if(volte=='volte6')
		document.getElementById('colonne').value=Number(document.getElementById('colonne').value)*20;
	calcolaImporto();
}
var varGruppi=0;
function calcolaImporto(gruppi)
{
	if(gruppi!=undefined){
		varGruppi=gruppi;
		var i=0;
		for(i=1;i<=5;i++){
			document.getElementById('iTextTab'+i).innerHTML="";
		}
	}
	if(document.getElementById('colonne').value!='0')
		document.getElementById('importo').value=Number(document.getElementById('colonne').value)*calcolaPuntata();
	else
		document.getElementById('importo').value='0';
	
	
	var imValue=Number(document.getElementById('importo').value);
	var j=imValue.toFixed(2);
	var colValue=document.getElementById('colonne').value;
	var imCol="Colonne "+colValue+"<br/>&euro; "+j+"";
	if(imValue!=undefined){
	document.getElementById('iTextTab'+varGruppi).innerHTML=imCol;
	document.getElementById('iTextTabTotale').innerHTML=imCol;}
	
}
function checkAbilitazione()
{
	var tipo = document.getElementById('tipo').value;
	var volte = document.getElementById('volte').value;
	var gioco = document.getElementById('gioco').value;
	if(tipo!="" && gioco!="" && volte!="") // Ho selezionato tutte e tre le tipologie
	{
		disabilitaTutti();
		if(gioco=="gioco1") // gioco 'Ordine esatto'
		{
			if(tipo=="tipo1") // tipo 'Vincente'
				abilitaTabella(1);
			else if(tipo=="tipo2") // tipo 'Accoppiata'
			{
				abilitaTabella(1);
				abilitaTabella(2);
			}
			else if(tipo=="tipo3") // tipo 'Tris'
			{
				abilitaTabella(1);
				abilitaTabella(2);
				abilitaTabella(3);
			}
			else if(tipo=="tipo4") // tipo 'Quartè'
			{
				abilitaTabella(1);
				abilitaTabella(2);
				abilitaTabella(3);
				abilitaTabella(4);
			}
			else if(tipo=="tipo5") // tipo 'Quintè'
			{
				abilitaTabella(1);
				abilitaTabella(2);
				abilitaTabella(3);
				abilitaTabella(4);
				abilitaTabella(5);
			}
		}
		else if(gioco=="gioco2") // gioco 'A girare'
		{
			abilitaTabella(1);
			disabilitaOrdineEsatto();
			if(tipo=="tipo1") // tipo 'Vincente'
			{	document.getElementById('minimoSelezionabileAGirare').value=1;
				document.getElementById('gruppi').value=1;
			}
			else if(tipo=="tipo2") // tipo 'Accoppiata'
			{	document.getElementById('minimoSelezionabileAGirare').value=2;
				document.getElementById('gruppi').value=2;
			}
			else if(tipo=="tipo3") // tipo 'Tris'		
			{	document.getElementById('minimoSelezionabileAGirare').value=3;
				document.getElementById('gruppi').value=3;
			}
			else if(tipo=="tipo4") // tipo 'Quartè'	
			{	document.getElementById('minimoSelezionabileAGirare').value=4;
				document.getElementById('gruppi').value=4;
			}
			else if(tipo=="tipo5") // tipo 'Quintè'
			{	document.getElementById('minimoSelezionabileAGirare').value=5;
				document.getElementById('gruppi').value=5;
			}	
		}	
	}
	calcolaColonneImporto();
}

function abilitaTabella(i)
{
	for(j=1; j<=20; j++){
		if(document.getElementById('selCavalloFont'+i+j)!=undefined && document.getElementById('selCavalloFont'+i+j).className=="iFontWhite-piccolo")
			document.getElementById('selCavalloFont'+i+j).className="iFontWhite-piccolo";
	}
	document.getElementById('tabellaCavalliDisabilitata'+i).style.display='none';
	document.getElementById('tabellaCavalliAbilitata'+i).style.display='inline';
}


function calcolaPuntata()
{
	var tipo = document.getElementById('tipo').value;
	if(tipo=='tipo1')
		return 1;
	else if(tipo=='tipo2')
		return 1;
	else if(tipo=='tipo3')
		return 0.50;
	else if(tipo=='tipo4')
		return 0.25;
	else if(tipo=='tipo5')
		return 0.25;
}
function binomiale(num1,num2)
{
    var val;
    var i;
    var ret_val;
    var continua;
    val = 1;
    i = 0;
    continua = true;
    while (continua)
    {	if (i == num2)
     		continua = false;
       	else
       	{	val = val * num1;
         	num1--;
       	}
       	i++;
    }
    ret_val = (val / fattoriale(num2));
    return(ret_val);
}

function fattoriale(val_1,val_2)
{
	var i,k;
	var p,p1;
	var retu;
	
	retu=0;
	if((val_1<1) || (val_2<1) || (val_1<val_2) ) return 0;
	p=1;
	k=val_1-val_2+1;
	
	for(i=val_1;i>=k;i--) p=p*i;
	p1=1;
	for(i=val_2;i>=1;i--) p1=p1*i;
	
	retu =( p / p1);
	return retu;
}

function calcolaColonneOrdineEsatto()
{	
	var colonne = 0;
	var tipo = getColonneAbilitate();
	var cavallo1 = new Array();
	var cavallo2 = new Array();
	var cavallo3 = new Array();
	var cavallo4 = new Array();
	var cavallo5 = new Array();
	
	switch(tipo)
	{
		case 1:
			cavallo1 = riempiCavalliSelezionati(1,cavallo1);
			for(var i=0; i<cavallo1.length; i++)
				colonne++;
		break;
		case 2:
			cavallo1 = riempiCavalliSelezionati(1,cavallo1);
			cavallo2 = riempiCavalliSelezionati(2,cavallo2);
			for(var i=0; i<cavallo1.length; i++)
				for(var j=0; j<cavallo2.length; j++)
					if(cavallo1[i]!=cavallo2[j])
						colonne++;	
		break;
		case 3:
			cavallo1 = riempiCavalliSelezionati(1,cavallo1);
			cavallo2 = riempiCavalliSelezionati(2,cavallo2);
			cavallo3 = riempiCavalliSelezionati(3,cavallo3);
			for(var i=0; i<cavallo1.length; i++)
				for(var j=0; j<cavallo2.length; j++)
					if(cavallo1[i]!=cavallo2[j])
						for(var k=0; k<cavallo3.length; k++)
							if(cavallo2[j]!=cavallo3[k] && cavallo1[i]!=cavallo3[k])
								colonne++;
		break;
		case 4:
			cavallo1 = riempiCavalliSelezionati(1,cavallo1);
			cavallo2 = riempiCavalliSelezionati(2,cavallo2);
			cavallo3 = riempiCavalliSelezionati(3,cavallo3);
			cavallo4 = riempiCavalliSelezionati(4,cavallo4);
			for(var i=0; i<cavallo1.length; i++)
				for(var j=0; j<cavallo2.length; j++)
					if(cavallo1[i]!=cavallo2[j])
						for(var k=0; k<cavallo3.length; k++)
							if(cavallo2[j]!=cavallo3[k] && cavallo1[i]!=cavallo3[k])
								for(l=0; l<cavallo4.length; l++)
									if(cavallo4[l]!=cavallo1[i] && cavallo4[l]!=cavallo2[j] && cavallo4[l]!=cavallo3[k])
										colonne++;
		break;								
		case 5:
			cavallo1 = riempiCavalliSelezionati(1,cavallo1);
			cavallo2 = riempiCavalliSelezionati(2,cavallo2);
			cavallo3 = riempiCavalliSelezionati(3,cavallo3);
			cavallo4 = riempiCavalliSelezionati(4,cavallo4);
			cavallo5 = riempiCavalliSelezionati(5,cavallo5);
			for(var i=0; i<cavallo1.length; i++)
				for(var j=0; j<cavallo2.length; j++)
					if(cavallo1[i]!=cavallo2[j])
						for(var k=0; k<cavallo3.length; k++)
							if(cavallo2[j]!=cavallo3[k] && cavallo1[i]!=cavallo3[k])
								for(l=0; l<cavallo4.length; l++)
									if(cavallo4[l]!=cavallo1[i] && cavallo4[l]!=cavallo2[j] && cavallo4[l]!=cavallo3[k])
										for(p=0; p<cavallo5.length; p++)
											if(cavallo5[p]!=cavallo1[i] && cavallo5[p]!=cavallo2[j] && cavallo5[p]!=cavallo3[k] && cavallo5[p]!=cavallo4[l])
												colonne++;
		break;											
	}
	return colonne;
}
function getColonneAbilitate()
{	
	var tipo = document.getElementById('tipo').value;
	if(tipo=='tipo1')
		return 1;
	else if(tipo=='tipo2')
		return 2;
	else if(tipo=='tipo3')
		return 3;
	else if(tipo=='tipo4')
		return 4;
	else if(tipo=='tipo5')
		return 5;
}
function riempiCavalliSelezionati(i,cavallo)
{
	var k = 0;
	for(var j=1; j<=20; j++)
	{	if(document.getElementById('selCavallo'+i+j)!=undefined && document.getElementById('selCavallo'+i+j).className=="iQuadratinoSelezione")
		{	cavallo[k]=j;
			k++;
		} 
	}
	return cavallo;
}



function disabilitaTabella(i)
{
	document.getElementById('tabellaCavalliDisabilitata'+i).style.display='inline';
	document.getElementById('tabellaCavalliAbilitata'+i).style.display='none';
}

function disabilitaTutti()
{
	for(var i=1; i<=5; i++)
		disabilitaTabella(i);
}

function disabilitaOrdineEsatto()
{
	for(var i=2; i<=5; i++)
	{	
		for(var j=1; j<=20; j++)
		{	if(document.getElementById('selCavallo'+i+j)!=undefined && document.getElementById('selCavallo'+i+j).className=="iQuadratinoSelezione")
			{	document.getElementById('selCavallo'+i+j).className="iQuadratinoNoSelezione";
				document.getElementById('num').value=Number(document.getElementById('num').value)-1;
				document.getElementById('selCavalloTutti'+i).className="iQuadratinoNoSelezione";
			}
		}
	}
}
function scegliVolte(id,scoM,tipo)
{
	for(var i=1; i<=6; i++)
	{	
		document.getElementById('volte'+i+tipo).className="iQuadratinoNoSelezioneVolte";
		document.getElementById('volteFont'+i+tipo).className="iFontRed-piccolo";
	}
	document.getElementById(id+tipo).className="iQuadratinoSelezioneVolte";
	document.getElementById(scoM+tipo).className="iFontWhite-piccolo";
	document.getElementById('volte').value=id;
	checkAbilitazione();
	moltiplicaColonne(tipo);
	visualizzaConferma();
}

function visualizzaConferma()
{
	if(document.getElementById('colonne').value!='0')
	{	document.getElementById('contieniBottoneGrigio').style.display='none';
		document.getElementById('contieniBottoneArancio').style.display='inline';
	}
	else	
	{	document.getElementById('contieniBottoneArancio').style.display='none';
		document.getElementById('contieniBottoneGrigio').style.display='inline';
	}
}

function controlliConferma(saldo,loggato)
{
	if(controllaLoggato(loggato) && controllaGiocataMinima() &&  controllaImportoMinimo(saldo))
		document.getElementById('formConfermaGiocataIppica').submit();
}

function controllaLoggato(loggato)
{
	if(loggato==0)
	{	document.getElementById('erroreLoggato').style.display='inline';
		return false;
	}
	else
	{	document.getElementById('erroreLoggato').style.display='none';
		return true;
	}
}
function controllaGiocataMinima()
{
	var colonne = Number(document.getElementById('colonne').value);
	if(colonne>=2)
	{	document.getElementById('erroreGiocataMinima').style.display='none';
	return true;
	}
	else
	{	document.getElementById('erroreGiocataMinima').style.display='inline';
	return false;
	}
}

function controllaImportoMinimo(saldo)
{
	var importo = Number(document.getElementById('importo').value);
	if(Number(saldo)>=importo)
	{	document.getElementById('erroreImportoMinimo').style.display='none';
		return true;
	}
	else
	{	document.getElementById('erroreImportoMinimo').style.display='inline';
		return false;
	}
}
function conferma()
{	
	document.getElementById('sbmtConferma').click();
}
function azzera(){
	document.getElementById('importo').value='0';
	document.getElementById('colonne').value='0';
	document.getElementById('num').value='0';
	document.getElementById('gruppi').value='3';
	document.getElementById('gioco').value='gioco2';
}

function scegliUltimaCorsa(idConcorso)
{
	document.getElementById('idConcorsoConfirm').value=idConcorso;
	document.getElementById('sbmtUltimaCorsa').click();
}
function infoScommessaIppica(idTicket)
{
	document.getElementById('idTicket').value=idTicket;
	document.getElementById('sbmtInfoScommessaIppica').click();
}

function inviaSms(numeroCellulare){

	if ((isNaN(numeroCellulare)) || (numeroCellulare == "") || (numeroCellulare == "undefined")) 
		document.getElementById('message').innerHTML="&bull; Il campo numero di cellulare non può essere vuoto";
	else if((/3[0-9]{9}/.test(numeroCellulare)) || (/3[0-9]{8}/.test(numeroCellulare)))	
		document.getElementById('numeroCellulare').value=numeroCellulare;
	else
		document.getElementById('message').innerHTML="&bull; Il campo numero di cellulare non é scritto correttamente";
	
}
