var color_bg_row_even 		= "#ffffff"; // rif. CSS td_avvenimenti
var color_bg_row_even_sel	= "#f0c751";
var color_bg_row_odd		= "#ffedba"; // rif. CSS td_avvenimenti_alt
var color_bg_row_odd_sel	= "#f0c751";

function send_req(type){
	if(type=='username'){
		var username_lost = document.getElementById("username_lost").value;
		var email_lost = document.getElementById("email_lost").value;
		if((username_lost=='')||(email_lost=='')){
			//alert("Warning! All fields must be filled in.");
			alert("Attenzione! Compilare tutti i campi.");
		} else{
			$.post("index.php?model=contenuti_recoverpass",{type: "username", username_lost: username_lost, email_lost: email_lost},
		    	function(data){
					document.getElementById("centro").innerHTML=data;
				}
			);			
		}
	}else if(type=='pass'){
		var email_lost = document.getElementById("email_lost").value;
		if(email_lost==''){
			//alert("Warning! All fields must be filled in.");
			alert("Attenzione! Inserire la propria e-mail");
		} else{
			$.post("index.php?model=contenuti_recoverpass",
			{type: "username", username_lost: username_lost, email_lost: email_lost},
		    	function(data){
					document.getElementById("centro").innerHTML=data;
				}
			);			
		}
	} else if(type=='contatti'){
		var nome = document.getElementById("nome").value;
		var email = document.getElementById("email").value;
		var telefono = document.getElementById("telefono").value;
		var note = document.getElementById("note").value;
		var mail_dest = document.getElementById("mail_dest").value;
	
		$.post("index.php?model=contenuti_contattaci",
				{nome: nome, email: email, telefono: telefono,note: note, dest:mail_dest, send:1},
		    	function(data){
					document.getElementById("centro").innerHTML=data;
				}
			);			
		
	}else {
		var email_lost2 = document.getElementById("email_lost2").value;
		var codfiscale_lost = document.getElementById("codfiscale_lost").value;
		if((codfiscale_lost=='')||(email_lost2=='')){
			//alert("Warning! All fields must be filled in.");
			alert("Attenzione! Compilare tutti i campi.");
		} else{
			$.post("index.php?model=contenuti_recoverpass",{type: "cod_fiscale", codfiscale_lost: codfiscale_lost, email_lost: email_lost2},
		    	function(data){
					document.getElementById("centro").innerHTML=data;
				}
			);			
		}		
	}
}

function check_casino(nome_campo){
	//alert(nome_campo);
	if((document.getElementById(nome_campo).value=='') || (isNaN(document.getElementById(nome_campo).value)))
		return  false;
	else
		return true;
}

function send_clickandbuy2(){
	 var data = new Date();
     var Hh, Mm, Ss, mm, dd, yy;
     Hh = data.getHours();
     Mm = data.getMinutes();
     Ss = data.getSeconds();
     mm = data.getMonth();
     dd = data.getDay();
     yy = data.getYear();
     

    var price=document.getElementById("price").value;
 
    var pos_virgola=price.indexOf(',');
   
    if(pos_virgola!=-1){
        var splitted=price.split(",");
        var new_price=splitted[0]+"."+splitted[1];
        price=new_price;
    }
   
    var price_old=price;
 
    price= Math.round(price * 100); 
     
    if((price=='') || (isNaN(price))){
        alert("Please insert a valid amount.")
    }
    else{
	    var my_uid=document.getElementById("my_uid").value;
	    var bdr_id=document.getElementById("my_uid").value+"_"+dd+"-"+mm+"-"+yy+"_"+Hh+Mm+Ss;  
	 
	    var type_sel=document.getElementById("type_sel").value;
	      // recupero l'anagrafica
	    var my_name    = document.getElementById("my_name").value;
	    var my_surname = document.getElementById("my_surname").value;
	    var my_address = document.getElementById("my_address").value;
	   	var my_city    = document.getElementById("my_city").value;
	   	var my_cap     = document.getElementById("my_cap").value;
	   	var my_nation  = document.getElementById("my_nation").value;
	   	var my_email   = document.getElementById("my_email").value;
	   	var url_premium = document.getElementById("url_premium").value;
	   	
		$.post("controller/ctr_verifyclickandbuy.php",{my_uid:my_uid, my_price:price},
	  		function(data){
	  			//alert(data);
	  			
				var popup = window.open('https://eu.clickandbuy.com/newauth/http://premium-'+url_premium+'.eu.clickandbuy.com/clickandbuy.php?price='+price+'&my_uid='+my_uid+'&externalBDRID='+bdr_id+'&cb_billing_FirstName='+my_name+'&cb_billing_LastName='+my_surname+'&cb_billing_Street='+my_address+'&cb_billing_HouseNumber=18&cb_billing_City='+my_city+'&cb_billing_ZIP='+my_cap+'&type_sel='+type_sel+'&Email='+my_email+'&my_trans_id='+data+'&cb_billing_Nation=IT&lang=it&cb_content_name=Ricarica+da+'+price_old+'+EUR&tipo_cassa='+type_sel);
				
					
				if(!(popup)){
					alert("Attenzione! Blocco popup rilevato. Per procedere con la transazione si prega di disattivarlo.");
				}
				}
		);
			
	   // alert('https://eu.clickandbuy.com/newauth/http://premium-56rcjz1xvrrzr1.eu.clickandbuy.com/clickandbuy.php?price='+price+'&my_uid='+my_uid+'&externalBDRID='+bdr_id+'&cb_billing_FirstName='+my_name+'&cb_billing_LastName='+my_surname+'&cb_billing_Street='+my_address+'&cb_billing_City='+my_city+'&cb_billing_ZIP='+my_cap+'&cb_billing_Nation+'my_nation'+&cb_content_name=Ricarica+da+'+price_old+'+EUR');
	   //window.open('https://eu.clickandbuy.com/newauth/http://premium-56rcjz1xvrrzr1.eu.clickandbuy.com/clickandbuy.php?price='+price+'&my_uid='+my_uid+'&externalBDRID='+bdr_id+'&cb_content_name=Ricarica+da+'+price_old+'+EUR');
	}
}

function send_clickandbuy3() {
	var my_uid=document.getElementById("my_uid").value;
	var price=document.getElementById("price").value;
	var type_sel=document.getElementById("type_sel").value;
	//alert(price);
	$.post("index.php?model=private_clickandbuyprelievo",{my_uid:my_uid, my_price:price, my_type:type_sel, my_step:2},
		function(data){
			$("#html").html(data);
		})
}

function chk_trans(){
	
	var importo = parseFloat($("#amt_trans").val());
	
	if((isNaN(importo)) || (importo=='') || (importo<=0)){
		alert("Attenzione! Inserire un importo valido");
	} else{
		for (var i=0; i < document.form_trans.type_trans.length; i++)
	    {
	   		if (document.form_trans.type_trans[i].checked)
	      	{
	      		var rad_val = document.form_trans.type_trans[i].value;
	      	}
		}
   		if(rad_val=='gen_pk')
   			var max = $("#max_prel_gen").val();   		
   		else
   			var max = $("#max_prel_pk").val();   		

	
		max = parseFloat(max);

   		if (importo > max) 
			alert("Attenzione! Importo massimo prelevabile superato");
		else {
			window.open('index.php?model=private_trasferimentocassa&amt_trans='+$("#amt_trans").val()+'&type_trans='+rad_val,'_self');
			// document.form_trans.submit();
		}
	}	
}

function load_bytype(sel_sport) {
	insert_loader('div_interno_sport');
	rnd_val = Math.round(Math.random()*1000000);
	load_ajax('index.php', { model: 'palinsesto_campionati', condition: '3', id_sport: sel_sport, rnd: rnd_val }, 'div_interno_sport', 'get', 0);
}

function load_menu() {
	$('#table_menu').html("<img src='images/blank.gif' height='22' width='6' alt='' style='border: 0px; vertical-align: middle;'><img src='images/ajax_bouncing.gif' alt='' height='16' width='16' style='border: 0px; vertical-align: middle;'>loading...");
	setTimeout("load_ajax('index.php', { model: 'palinsesto_menu' }, 'table_menu', 'GET', '')", 2000);	
}

function load_sport(key, show_now, id_now, codpal, codavv){
	$("#back_campionato").val('');
	insert_loader('div_interno_sport');
	load_ajax("index.php?model=palinsesto_campionati",{condition:key, show_now:show_now, id_now:id_now, codpal:codpal, codavv:codavv}, "div_interno_sport", "get", "SPORT");
}

function load_content_tag(rule, sport, category, row){
	load_ajax("view/tag/vw_contenttag.php", {rule: rule, sport:sport, category: category}, 'tag_content_'+row, 'get', 'TAG');
}

function load_antepost(key){	
	insert_loader('div_interno_sport');
	load_ajax("index.php?model=palinsesto_antepost",{condition:key}, "div_interno_sport", "get", "ANTEPOST");
	$('#page_id').val('ANTEPOST');
}

function load_live(key){
	//insert_loader('div_interno_sport');
	//load_ajax("index.php?model=palinsesto_live",{condition:key}, "div_interno_sport", "get", "LIVE");
	load_ajax("view/palinsesto/vw_live.php",{condition:key}, "div_interno_sport", "get", "LIVE");
	$('#page_id').val('LIVE');
}
		
function load_page(nome_pagina){	
	$.post(nome_pagina,'',
	  		function(data){
				document.getElementById("centro").innerHTML=data;
  			}
		);
}

function registrati(){
			
		var nome=document.getElementById("nome").value;
		var cognome=document.getElementById("cognome").value;
		var data_nascita=document.getElementById("data_nascita").value;
		var sesso=document.getElementById("sesso").value;
		var nazione_nascita=document.getElementById("nazione_nascita").value;
		var com_nascita=document.getElementById("com_nascita").value;
		var prov_nascita=document.getElementById("prov_nascita").value;
		var cod_fiscale=document.getElementById("cod_fiscale").value;
		var nazione=document.getElementById("nazione").value;
		var indirizzo=document.getElementById("indirizzo").value;
		var provincia=document.getElementById("provincia").value;
		var citta=document.getElementById("citta").value;
		var telefono=document.getElementById("telefono").value;
		var cellulare=document.getElementById("cellulare").value;
		var email=document.getElementById("email").value;
		var username = document.getElementById("username").value;
		var password = document.getElementById("password").value;	
		var cap = document.getElementById("cap").value;
		
		$.post("index.php?model=auth_regaction",{username: username, password: password, nome:nome, cognome:cognome, data_nascita: data_nascita, 
		sesso:sesso, nazione_nascita:nazione_nascita, com_nascita:com_nascita, prov_nascita: prov_nascita, cod_fiscale: cod_fiscale, nazione:nazione,
		indirizzo:indirizzo, provincia: provincia, telefono:telefono, cellulare:cellulare, email:email, cap:cap, citta:citta },
	  		function(data){
					document.getElementById("centro").innerHTML=data;
  			}
		);
}
function do_login(){	
		var username=document.form_login.username_ins.value;
		var password=document.form_login.password_ins.value;
	
		if((username!='') && (password!=''))
			document.form_login.submit();
		else
			alert("Insert valid username and password.");
}

function cambio_contenuto_centro(contenuto)
{
	/*
	$.post("view/contenuti/animazioni/color/intext2.html","",
    	function(data){
		document.getElementById("centro").innerHTML=data;
		}
	);
	*/
	
	$.post("index.php?model=contenuti_"+contenuto,"",
    	function(data){
		document.getElementById("centro").innerHTML=data;
		}
	);
	
}


function cambio_contenuto_centro_byId(contenuto, id)
{
	$.post("index.php?model=contenuti_"+contenuto,"",
    	function(data){
		document.getElementById(id).innerHTML=data;
		}
	);
	
}

function cambio_contenuto_centro_2(url)
{
	$.post(url,"",
    	function(data){
		document.getElementById("centro").innerHTML=data;
		}
	);
}

function contenuto_casino(contenuto)
{
	$.post(contenuto,"",
    	function(data){
		document.getElementById("centro").innerHTML=data;
		}
	);
}
function insert_data_nascita(){
		
		var giornonascita = document.getElementById("giorno_nascita").value;
		var mesenascita = document.getElementById("mese_nascita").value;
		var annonascita = document.getElementById("anno_nascita").value;
		
		var datanascita = giornonascita+"/"+mesenascita+"/"+annonascita;
		
		document.getElementById("data_nascita").value=datanascita;

	}
function codicefiscale_bis()
{
var nome = document.getElementById("nome").value
var cognome = document.getElementById("cognome").value
//var datanascita=document.getElementById("data_nascita").value;
var giornonascita = document.getElementById("giorno_nascita").value;
var mesenascita = document.getElementById("mese_nascita").value;
var annonascita = document.getElementById("anno_nascita").value;

var datanascita = giornonascita+"/"+mesenascita+"/"+annonascita;

document.getElementById("data_nascita").value=datanascita;

var sesso;
var i;
for(i = 0; i<document.form_registrati.sesso.length; i++ )
{
	if(document.form_registrati.sesso[i].checked==true)
		sesso = document.form_registrati.sesso[i].value;
}

var comune = document.getElementById("com_nascita").value;
var provincia = document.getElementById("prov_nascita").value;


$.get("classes/controlla_codicefiscale.php",
  {cognome: cognome, nome: nome, datadinascita: datanascita, sesso: sesso, com_nascita: comune, prov_nascita: provincia},
  function(data){
	  if((data.search('ERRORE') == -1) && (data.search('Warning') == -1)){
				document.getElementById("cod_fiscale").value = data
            }else{
				alert(data);
			}
  		}
	);
}


function codicefiscale()
{
var nome = document.getElementById("nome").value
var cognome = document.getElementById("cognome").value
var datanascita=document.getElementById("data_nascita").value;
var sesso;
var i;
for(i = 0; i<document.form_registrati.sesso.length; i++ )
{
	if(document.form_registrati.sesso[i].checked==true)
		sesso = document.form_registrati.sesso[i].value;
}

var comune = document.getElementById("com_nascita").value;
var provincia = document.getElementById("prov_nascita").value;


$.get("classes/controlla_codicefiscale.php",
  {cognome: cognome, nome: nome, datadinascita: datanascita, sesso: sesso, com_nascita: comune, prov_nascita: provincia},
  function(data){
	  if((data.search('ERRORE') == -1) && (data.search('Warning') == -1)){
				document.getElementById("cod_fiscale").value = data
            }else{
				alert(data);
			}
  		}
	);
}

function show_game(tipo){

	var login_ok = document.getElementById("login_ok").value;
	var casino_ok = document.getElementById("casino_ok").value;
	// alert(tipo);
	
	if ((login_ok == 1) && (casino_ok == 1)) {
		document.getElementById("centro").innerHTML = "<p class=\"tit_news\">Loading games...</p>";
		$.post("index.php?model=casinolive_lista&tipo=" + tipo, "", function(data){
			document.getElementById("centro").innerHTML = data;
		});
		//	window.open('index.php?model=casinolive_index','Live','toolbar=no, directories=no, scrollbars=no, status=no, resizable=yes,fullscreen'); 
	}
}

function show_contenuto(tipo){	

	$.post("index.php?model=contenuti",{tipo: tipo},
	  		function(data){
				document.getElementById("centro").innerHTML=data;
  			}
		);
}

function show_contenuto_byId(tipo, id){	

	$.post("index.php?model=contenuti",{tipo: tipo},
	  		function(data){
				if (document.getElementById(id)) {
					document.getElementById(id).innerHTML = data;
				}
  			}
		);
}

function go_to(tipo_page){	

	if (document.getElementById("login_ok")!=null)
		var login_ok = document.getElementById("login_ok").value;	
		
	if (document.getElementById("casinolive_ok")!=null)
		var casinolive_ok = document.getElementById("casinolive_ok").value;
		
	if (document.getElementById("casino_ok")!=null)
		var casino_ok = document.getElementById("casino_ok").value;

	switch(tipo_page){
		case 'LOGIN':
		  $.get("index.php?model=home_refresh","",
    		  function(data){
    		  	//alert(data);
    				//$('#table_login').html(data);
    				document.getElementById("table_login").innerHTML=data;
		  	  }
    	  );
		break;
		case 'BETTING':
			
		 	  if(login_ok==1) 
		 	  	var url="index.php?model=center_sportlog";
		 	  else
		 	  	var url="index.php?model=center	_sportnolog";
		
		break;
		
		case 'CASINO':
			
			if(login_ok==1) 
		 	  	var url="index.php?model=center_casino";
		 	  else
		 	  	var url="index.php?model=casino_casinonolog";
			
				$.post(url,"",
					function(data){
    					document.getElementById("centro").innerHTML=data;
		  			}
    			);
			
		break;
		
		case 'CASINO_LIVE':
				$.post("index.php?model=casinolive_info","",
					function(data){
    					document.getElementById("centro").innerHTML=data;
		  			}
    			);
    			
				if((login_ok==1) && (casinolive_ok==1)){
					window.open('index.php?model=casinolive_index','Live','toolbar=no, directories=no, scrollbars=no, status=no, resizable=yes,fullscreen'); 
				}
				
    			
		break;
		
		case 'POKER':
				window.open('http://poker.mygoldgames.com');
		break;
		case 'POKER_LIVE':
		
			if(login_ok==1){
				window.open('http://www.google.it/');
			}else{
				 $.post("index.php?model=center_pokerlive","",
    		  		function(data){
    					document.getElementById("centro").innerHTML=data;
		  			}
    			);
			}
		break;
		case 'EXCHANGE':
		
			if(login_ok==1){
				window.open('http://www.google.it/');
			}else{
				 $.post("index.php?model=center_exchange","",
    		  		function(data){
    					document.getElementById("centro").innerHTML=data;
		  			}
    			);
			}
		break;
		case 'LOTTERY':
		
			if(login_ok==1){
				window.open('http://www.google.it/');
			}else{
				 $.post("index.php?model=center_lottery","",
    		  		function(data){
    					document.getElementById("centro").innerHTML=data;
		  			}
    			);
			}
		break;
		case 'BINGO':
		
			if(login_ok==1){
				window.open('http://www.google.it/');
			}else{
				 $.post("index.php?model=center_bingo","",
    		  		function(data){
    					document.getElementById("centro").innerHTML=data;
		  			}
    			);
			}
		break;
		
		case 'REGISTRATI':
			$.post("index.php?model=contenuti_registrati","",
    		  		function(data){    		  			
    						document.getElementById("centro").innerHTML=data;
    						$("#form_registrati").validate({
						 	rules:{
									nome: {required: true},
									cognome: {required: true},
									data_nascita: {required: true},
									sesso: {required: true},
									nazione_nascita: {required:true},
									cod_fiscale: {required:true,minlength:16,maxlength:16},
									nazione: {required: true},
									indirizzo: {required: true},
									citta: {required: true},
									cap: {required: true},
									provincia:{required:true},
									telefono:{required: true},
									cellulare:{required:true},
									email:{required:true,email: true},
									username:{required:true},
									password:{required:true},
									re_password:{required:true, equalTo:"#password"}
								}		
							});   					
		  			}
		  
    			);
		break;
		
		default:
			var tolower=tipo_page.toLowerCase();
			$.post("index.php?model=contenuti_"+tolower,"",
    		  		function(data){
    					document.getElementById("centro").innerHTML=data;
		  			}
    			);
		break;
	}
	
}

function chg_password() {
	document.form_chgpsw.submit();
	/*	
	var pold =document.getElementById("old_passwd");
	var pnew =document.getElementById("new_passwd");
	var pcnew=document.getElementById("renew_passwd");
	
	$.get("index.php?model=private_cambiopsw",
		{ old_passwd:pold.value, new_passwd:pnew.value, c_new_passwd: pcnew.value},
		function(data){
    		document.getElementById("centro").innerHTML=data;
		}	
	)
	*/	
}

function get_calc(id, activity, state) {
	
	var url_model = "private_retecalcola"+activity;
	
	$.get("index.php",
  		{ model: url_model, id_user: id, activity: activity },
  		function(data){
			document.getElementById(activity+"_"+id).innerHTML=data;
  		}
  	);	
}

	function load_ajax(url, val, location, method, page_id) {		
		// verifica il tipo di pagina richiesta
		if (page_id==9999) {
	    	// verifica la presenza del div "div_interno_sport"
    		search_div();
		}
		// aggiunge un riferimento casuale
		var val2={rnd:Random(100000)};
		var myArray = [];
		var url_param = myArray.concat(val,val2);

		// carica la pagina
    	if(method=='post'){
    		$.post(url,url_param,
                function(data){
                	$('#'+location).html(data);    	
                }
		    );
    	} else{
    		$.get(url,val,
                function(data){ 
                	$('#'+location).html(data);    	
                }
		    );
    	}
    }

	function load_ajax_due(url, val, location, method, page_id) {
    	if(method=='post'){
    		$.post(url,val,
                function(data){                    	
                	$('#'+location).html(data);    	
                }
		    );
    	} else {
    		$.get(url,val,
                function(data){
                	$('#'+location).html(data);    	
                }
		    );  		
    	}
    	
		if(page_id!='') $('#page_id').val(page_id);	 
    }
	
function calcola_biglietti(){
	document.getElementById("data_da").value=document.getElementById('sel3').value;
	document.getElementById("data_a").value=document.getElementById('sel1').value;
	if (document.getElementById('sel_5')!=null) {
		var dropdownIndex = document.getElementById('sel_5').selectedIndex;
		document.getElementById("utente_betting").value = document.getElementById('sel_5')[dropdownIndex].value;
	}
	if(document.getElementById("rd_chiusura").checked==true) 
		document.getElementById("tipo_data").value='chiusura';
	else
		document.getElementById("tipo_data").value='emissione';	
	
	document.form_scommesse.submit();
}


function show_dettagli_biglietto(id_biglietto, id_sistema, num_riga){
	if(document.getElementById(num_riga).innerHTML==''){
		if (id_sistema!='') {
			$.post("view/private/vw_dettagli_sistema.php", { id_sistema: id_sistema, num_riga: num_riga},
	  			function(data){
					document.getElementById(num_riga).innerHTML = data;
	 		 	}
			)
		}
		else {
			$.post("view/private/vw_dettagli_biglietto.php", { id_biglietto: id_biglietto},
	  			function(data){
					document.getElementById(num_riga).innerHTML = data;
	 		 	}
			)
		}
	} else {
		document.getElementById(num_riga).innerHTML='';
	}
}
/*
function show_dettagli_biglietto(id_biglietto,num_riga){
	if(document.getElementById(num_riga).innerHTML==''){
		$.post("view/private/vw_dettagli_biglietto.php",
		  { id_biglietto: id_biglietto},
			  function(data){
				document.getElementById(num_riga).innerHTML = data
 			  }
		   )}
	else{
		document.getElementById(num_riga).innerHTML='';
	}
}
*/

function casino_step2(){
		$.post("index.php?model=center_casinonext", '',
	  		function(data){
	  			//alert(data);
				document.getElementById("centro").innerHTML = data;
	 		}
		)
}


	function chk_op_type(form_name){
		
		if(form_name=='form2'){
			
			while (e = document.form2.elements) {
				
					if ((e.name == 'mygold_op') && (e.checked) ) {
						var x = this.value;
						alert(x);
					}
			}

		}
	}
	
	function do_prelievo(type){
		//alert(type);
		switch(type){
		
			case 'postepay':
					var importo_prelievo = document.getElementById("importo").value;
					var intestatario_carta = document.getElementById("intestatario_carta").value;
					var numero_carta = document.getElementById("numero_carta").value;
					//var scadenza_carta = document.getElementById("scadenza_carta").value;
					
					if((importo_prelievo=='')||((isNaN(importo_prelievo)))||(intestatario_carta=='')||(numero_carta=='')){
						//alert("Warning! All fields must be filled in.");
						alert("Attenzione! Compilare tutti i campi.");
					}else{
						//window.location="index.php?model=private_richiestaprelievo";	
						document.form_pp.submit();					
					}
			break;
			
			case 'assegno':
					var importo_assegno = document.getElementById("importo_assegno").value;
					var intestatario_assegno = document.getElementById("intestazione_assegno").value;
					var indirizzo_spedizione = document.getElementById("indirizzo_spedizione").value;
					if((importo_assegno=='')||((isNaN(importo_assegno)))||(intestatario_assegno=='')||(indirizzo_spedizione=='')){
						//alert("Warning! All fields must be filled in.");
						alert("Attenzione! Compilare tutti i campi.");
					}else{
						//window.location="index.php?model=private_richiestaprelievo";	
						document.form_ass.submit();					
					}
			
			break;

			case 'contanti':
					var importo_contanti = document.getElementById("importo_contanti").value;
					var causale_prelievo = document.getElementById("causale_prelievo").value;
					if((importo_contanti=='')||(causale_prelievo=='')){
						alert("Attenzione! Compilare tutti i campi.");
					}else{
						document.form_ass.submit();					
					}
			
			break;
			
			case 'bonifico':
					var nome_bon= document.getElementById("nome_bon").value;
					var cognome_bon = document.getElementById("cognome_bon").value;
					var indirizzo_bon = document.getElementById("indirizzo_bon").value;
					var citta_bon= document.getElementById("citta_bon").value;
					var cap_bon = document.getElementById("cap_bon").value;
					var prov_bon = document.getElementById("prov_bon").value;
					var banca_bon= document.getElementById("banca_bon").value;
					
					var codpaese_bon = document.getElementById("codpaese_bon").value;
					var check_bon = document.getElementById("check_bon").value;
					var cin_bon= document.getElementById("cin_bon").value;
					var abi_bon = document.getElementById("abi_bon").value;
					var cab_bon = document.getElementById("cab_bon").value;
					var conto_bon= document.getElementById("conto_bon").value;
				
					var importo_bon = document.getElementById("importo_bon").value;
					
					if((importo_bon=='')||(nome_bon=='')||(cognome_bon=='')||(indirizzo_bon=='')||(citta_bon=='')||(cap_bon=='')||(prov_bon=='')||(banca_bon=='')||(codpaese_bon=='')||(check_bon=='')||(cin_bon=='')||(abi_bon=='')||(cab_bon=='')||(conto_bon=='')){
						//alert("Warning! All fields must be filled in.");
						alert("Attenzione! Compilare tutti i campi.");
					} else{
						document.form_bon.submit();		
					}
			break;
			
			
		}
	}

function cambia(link, location){
	if(link.indexOf("model")==-1)
		var url="contenuti/"+link;
	else
		var url=link;
	$.get(url,
	  function(data){
		
		if(link=='index.php?model=auth_registrati'){
			$('#'+location).html(data);
			$("#form_registrati").validate({
		 	rules:{
					nome: {required: true},
					cognome: {required: true},
					giorno_nascita: {required: true},
					mese_nascita: {required:true},
					anno_nascita: {required:true}, 
					sesso: {required:true},
					nazione_nascita: {required: true},
					prov_nascita: {required: true},
				    cod_fiscale: {required: true,minlength: 16,maxlength: 16},
					nazione: {required: true},
			        indirizzo: {required: true},
			        citta: {required: true},
					cap: {required: true},
					provincia: {required: true},
					email: {required: true,email: true},
					com_nascita: {required:true} 
				},
		messages: {
			re_password: {
				equalTo: "Non coincide"
				}
			}		
			});	
		}
		else{
		
			$('#'+location).html(data);			
		}
	  }
	);		
		$('#page_id').val('CONTENUTI');
}

function carica(link,target)
{	
	$.get(link,
	  function(data){
		$(target).html(data);
	  });	  
}

function go_back_campionato(target)
{
   	// verifica la presenza del div "div_interno_sport"
   	search_div();

	var url="view/palinsesto/vw_first.php";
	   	$.post(url, '',
		  		function(data){
					$('#'+target).html(data);
			});
		
}

function go_back_campionato_url(target)
{
   	// verifica la presenza del div "div_interno_sport"
   	search_div();

	var url='index.php?model=palinsesto_first&condition=3&tab_selected=1&show_now=&id_now=0&codpal=0&codavv=0&act_url=back';
	// $("#back_campionato").val();
   	
	$.post(url, '',
	  		function(data){
				$('#'+target).html(data);
		});
}

function jdate()
{
	today=new Date();
	x=today.getDate();
	y=today.getMonth();
	if (x < 10) {
	   kx = "0";	
	} else {
		   kx = "";
	}
	if (y < 9) {
	   ky = "0";	
	} else {
		   ky = "";
	}
	if (navigator.appName != "Netscape") {
	   z=today.getYear();
	} else {
	   z=(today.getYear()+1900);
	}
	date = kx+x+"/"+ky+(y+1)+"/"+z;
	return date
}

function insert_dati(){
	
	var nome= document.getElementById("nome").value;
	var cognome= document.getElementById("cognome").value;
	var indirizzo= document.getElementById("indirizzo").value;
	var citta= document.getElementById("citta").value;
	var provincia= document.getElementById("provincia").value;
	var cap= document.getElementById("cap").value;
	var nazione= document.getElementById("nazione").value;
	var telefono= document.getElementById("telefono").value;
	var cellulare= document.getElementById("cellulare").value;
	var email= document.getElementById("email").value;
	var username= document.getElementById("username").value;
	var password= document.getElementById("password").value;
	var repassword= document.getElementById("re-password").value;

	if((nome=='')||(cognome=='')||(indirizzo=='')||(citta=='')||(provincia=='')||(cap=='')||(nazione=='')||(telefono=='')||(cellulare=='')||(email=='')||(username=='')||(password=='')||(repassword=='')){
		alert("Attenzione! Inserire tutti i campi specificati");
	} else{
		
				$.post("controller/ctr_registrazione.php",{username:username},
	                function(data){	
	               		if(data=="false"){
	               			alert("Attenzione! Username gia' in uso");
	               		} else{
	               			if(repassword!=password){
	               				alert("Attenzione! Controllare la password inserita");
	               			} else{
		               			$.post("index.php?model=private_nuovocliente&action=1",{nome:nome, cognome:cognome, indirizzo:indirizzo, citta:citta, provincia:provincia, cap:cap, nazione:nazione, telefono:telefono, cellulare:cellulare, email:email, username:username, password:password},
					                function(data){	
					               		document.getElementById("messaggio").innerHTML="Utente inserito correttamente";         
					                }
							    );						    
	               			}
	               		}
	                }
			    );	
			}
	}

function chk_fields(str_fields, colore_evidenza){	
	var arr_fields = str_fields.split("@");
	var num_errori=0;
	for(var j=0; j<arr_fields.length; j++){
		var campo = arr_fields[j].split("|");
		var nome_campo = campo[0];
		var vincolo = campo[1];
		var type = campo[2];
		if(type=='editable')
			var valore_campo = document.getElementById(nome_campo).value;
		else{
			var edit = document.getElementById("edit").value;
			if(edit==1)
				var valore_campo = document.getElementById(nome_campo+"_edt").value;
			else
				var valore_campo = document.getElementById(nome_campo).innerHTML;
			
		}
			
		switch(vincolo){
			case 'numeric':				
				if ((valore_campo=='')||(isNaN(valore_campo))){		
					if(num_errori==0)				
						alert("Attenzione! Controllare i valori inseriti nei campi evidenziati");
						document.getElementById(nome_campo+"_row").style.backgroundColor=colore_evidenza;					
						num_errori++;
				} else{
						document.getElementById(nome_campo+"_row").style.backgroundColor="";	
				}
				break;
				
			default:
				if(valore_campo==''){
					if(num_errori==0)				
						alert("Attenzione! Controllare i valori inseriti nei campi evidenziati");
						document.getElementById(nome_campo+"_row").style.backgroundColor=colore_evidenza;
						num_errori++;	
				} else{
					document.getElementById(nome_campo+"_row").style.backgroundColor="";	
				}
		}
	}
}


function make_form(str_fields, url){
	var arr_fields = str_fields.split("@");	
	
		for(var j=0; j<arr_fields.length; j++){
			var nome_campo = arr_fields[j];
			if(document.getElementById("edit").value==0){
			
				var valore_campo = document.getElementById(nome_campo).innerHTML;	
				var html="<input type='text' name='"+nome_campo+"_edt' id='"+nome_campo+"_edt' style='height:12px;font-size:11;width:250px'  value='"+valore_campo+"'>";		
			}else{
				var valore_campo = document.getElementById(nome_campo+"_edt").value;
				var html=valore_campo;
				var url= url+"&"+nome_campo+"_edt="+valore_campo;		
			}
			
				document.getElementById(nome_campo).innerHTML=html;
			}
	
	if(document.getElementById("edit").value==0)
		document.getElementById("edit").value=1;
	else{
		window.location=url;
	}
}

function backto_campionati(){
		var link='';
		var pagina_attuale = $('#page_id').val();
		var tab=1;
		
		switch(pagina_attuale){
			
			case 'CALCIO':
				//link='index.php?model=palinsesto_campionatiback&id_sport=5&condition=3';
				key=3;
				show_now='';
				id_now=0;
				codavv=0;
				codpal=0;
				tab=1;
			break;
			
			case 'ANTEPOST':
				//link='index.php?model=palinsesto_campionatiback&condition=4';
				key=4;
				show_now='';
				id_now=0;
				codavv=0;
				codpal=0;
				tab=2;
			break;
			
			case 'ALTRO':
				//link='index.php?model=palinsesto_campionatiback&id_sport=altro&condition=5';
				key=5;
				show_now='';
				id_now=0;
				codavv=0;
				codpal=0;
				tab=3;
			break;
			
			default:
				//link='index.php?model=palinsesto_campionatiback&id_sport=5&condition=3';
				key=3;
				show_now='';
				id_now=0;
				codavv=0;
				codpal=0;
				tab=1;
		}

		
		load_ajax("index.php?model=palinsesto_first",{condition:key, tab_selected: tab, show_now:show_now, id_now:id_now, codpal:codpal, codavv:codavv}, "div_interno_sport", "get", "SPORT");	
	}

    function Random(N) {
		do { T = Math.random() } while (T>=1.0) ;
		return Math.floor(N*T);
    }

	


    
	function show_title(title){
		$("#title_avvenimento").css('visibility','visible');
		$("#title_avvenimento").html(title);
	
	}	
	function show_quote(id_avvenimento,codpal,codavv,nome_avvenimento,data_avvenimento){
		
		load_ajax("view/palinsesto/vw_avvenimenti_others.php",{id_avvenimento: id_avvenimento, codpal:codpal, codavv: codavv, nome_avvenimento: nome_avvenimento, data_avvenimento: data_avvenimento }, "tag_quote", "post", $("#page_id").val());
			
	}
	function show_tag(show_now, id_now, codpal, codavv){
		
		$('#table_coupon').css('visibility','visible');
		autocomplete_pal();
		
		if ((show_now=='0') || (show_now=='')) {
			if(document.getElementById('tag_pal')) setTimeout("document.myform.tag_pal.focus()", 500);
		}
		
		var val = {show_now: show_now, id_now: id_now, codpal:codpal, codavv:codavv};
		var location="div_interno_sport";
		var method ="post";

		load_ajax("view/tag/vw_index.php",val, location, method, 'TAG');
		//	load_sport('3','4', show_now, id_now, codpal, codavv);

	
	}	
	function fetch_winner_sel(location, id_select, id_quota, bgcolor){		
	
		var winner_sel = document.getElementById(id_select).value;
		insert_quota(location, winner_sel, id_quota, bgcolor);		
	}	
	
	function chg_bgcolor(id_td, bg_quota){
		if(document.getElementById(id_td)){			
			document.getElementById(id_td).style.backgroundColor=bg_quota;			
		}
		 if (document.getElementById("h_"+id_td)){			
			document.getElementById("h_"+id_td).style.backgroundColor=bg_quota;			
		}
	}	
	
	function rem_bgcolor(id_quota,pal_avv, segno, bgcolor_even, bgcolor_odd, bgcolor_black){
		
		var id_td="quota_"+id_quota;
		
		if (document.getElementById(id_td)){			
			
			var str_ref = document.getElementById(id_td).className;
			var idx1    = str_ref.indexOf("td_avvenimenti_alt");
			var idx2    = str_ref.indexOf("td_avv_mini_alt");
			if ((idx1>=0) || (idx2>=0))
				var old_bgcolor = bgcolor_odd;
			else
				var old_bgcolor = bgcolor_even;
			
			document.getElementById(id_td).style.backgroundColor=old_bgcolor;
			
		}
		if (document.getElementById("h_"+id_td)) {			
			if(bgcolor_black==null)		
				document.getElementById("h_"+id_td).style.backgroundColor="#ffffff";	
			else
				document.getElementById("h_"+id_td).style.backgroundColor=bgcolor_black;			
		}
	}

	function set_bgcolor(id_quota,pal_avv, segno, bgcolor_even, bgcolor_odd, bgcolor_black){
		
		var id_td="quota_"+id_quota;
		
		if(document.getElementById(id_td)){
			var str_ref = document.getElementById(id_td).className;
			var idx1    = str_ref.indexOf("td_avvenimenti_alt");
			var idx2    = str_ref.indexOf("td_avv_mini_alt");
			if ((idx1>=0) || (idx2>=0))
				var old_bgcolor = bgcolor_odd;
			else
				var old_bgcolor = bgcolor_even;
			document.getElementById(id_td).style.backgroundColor=old_bgcolor;
			
		} if ( document.getElementById("h_"+id_td)){			
			if(bgcolor_black==null)		
				document.getElementById("h_"+id_td).style.backgroundColor="#ffffff";	
			else
				document.getElementById("h_"+id_td).style.backgroundColor=bgcolor_black;			
		}
	}

	function close_others(id_riga){
			if(document.getElementById(id_riga)){
					document.getElementById(id_riga).innerHTML="";			
					document.getElementById(id_riga).style.visibility="hidden";	
			}
		
	}

	function close_others(id_riga){
			if(document.getElementById(id_riga)){
					document.getElementById(id_riga).innerHTML="";			
					document.getElementById(id_riga).style.visibility="hidden";	
			}
		
	}
	function show_others(id_avvenimento, codpal, codavv, nome_avvenimento, data_avvenimento){
	//alert("td_"+codpal+"."+codavv);
		if(document.getElementById("td_"+codpal+"."+codavv)){
			//alert("1. ok");
			if(document.getElementById("td_"+codpal+"."+codavv).style.visibility=="visible"){
				//alert("2. ok");
				document.getElementById("td_"+codpal+"."+codavv).innerHTML="";			
				document.getElementById("td_"+codpal+"."+codavv).style.visibility="hidden";	
			}
			else{	
				//alert("3. ok");
				$.post("view/palinsesto/vw_avvenimenti_others.php",
						{id_avvenimento: id_avvenimento, codpal: codpal, codavv: codavv, nome_avvenimento: nome_avvenimento, data_avvenimento: data_avvenimento},
		                function(data){
		               		document.getElementById("td_"+codpal+"."+codavv).innerHTML=data; 
		                }
				    );
				
				document.getElementById("td_"+codpal+"."+codavv).style.visibility="visible";		
			}	
		} else{
			//alert("4. ok");
				$.post("view/palinsesto/vw_avvenimenti_others.php",
						{id_avvenimento: id_avvenimento, codpal: codpal, codavv: codavv, nome_avvenimento: nome_avvenimento, data_avvenimento: data_avvenimento},		
		                function(data){
		               		document.getElementById("td_"+codpal+"."+codavv).innerHTML=data;         
		                }
				    );
				document.getElementById("td_"+codpal+"."+codavv).style.visibility="visible";		
			}			
	}

	function sel_tutti(prefisso){
		var arr_chk = document.getElementsByTagName("input");
		var lung=prefisso.length;
		for(var j=0; j<arr_chk.length; j++){
			arr_name=arr_chk[j].getAttribute("name");
   			if (arr_name!=null) {
	
	   			if ( (arr_chk[j].type=="checkbox") && (arr_name.substr(0,lung)==prefisso)){
	   				arr_chk[j].checked=true;
	   			}
   			}
		}
	}

	function show_avvenimenti_sel(condition,location,prefx){
   	   	//alert(condition);
   	   	var arr_name="";
   		var str_campionati="";
   		var arr_chk = document.getElementsByTagName("INPUT");
		var k=0;
   			
   		for(var j=0; j<arr_chk.length; j++){
			arr_name=arr_chk[j].getAttribute("name");
   			if (arr_name!=null) {
	   			if ( (arr_chk[j].type=="checkbox") &&(arr_name.substr(0,prefx.length)==prefx) && (arr_chk[j].getAttribute("id").substr(0,4)!='chk_') && (document.getElementById(arr_chk[j].getAttribute("id")).checked==true)){
	   				if(k>0)
	   					str_campionati = str_campionati+"@";
	   		
	   				var hidden_field = document.getElementById("hid_"+arr_chk[j].getAttribute("id")).value;
	   				str_campionati = str_campionati + hidden_field;
	   				k++;
	   			}
   			}
   		}

   		if(k==0){
   				alert("Selezionare almeno un campionato!");
   		}else{
   			//alert("location: "+location);
    		// document.getElementById(location).innerHTML="<div style='margin-top:100px; margin-bottom:100px' align='center'><br><br><img src='images/ajax-loader_bianco.gif' border='0'></div>";  
			$("#"+location).html("<div style='margin-top:100px; margin-bottom:100px' align='center'><br><br><img src='images/ajax-loader_bianco.gif' border='0'></div>");
			
			dim_var = window.screen.width - 340
   			var url="view/palinsesto/vw_avvenimenti.php?str_campionati="+str_campionati+"&dim="+dim_var;
			//var url="index.php?model=palinsesto_avvenimenti&str_campionati="+str_campionati+"&dim="+dim_var;
   			$.post(url,
   			{condition:condition},
                function(data){
                	//alert(data);
               		$("#"+location).html(data);         
                }
		    );
//			$('#div_campionati').enableTab(6);
			
			// tiene traccia del campionato visualizzato e dell'indice del bottone relativo
			$('#page_sport').val($('#page_sport_id').val());
		    $('#back_campionato').val(url);
		    
		 	//$('#page_id').val('AVVENIMENTI');   
   		}
   		if(document.getElementById('tag_pal')) document.getElementById('tag_pal').focus();   
    }
    
	function print_avvenimenti_sel(condition,location,prefx){
   		var str_campionati="";
   		var arr_chk = document.getElementsByTagName("input");
		var k=0;
   			
   		for(var j=0; j<arr_chk.length; j++){   			
   			if ( (arr_chk[j].type=="checkbox") && (arr_chk[j].getAttribute("name").substr(0,prefx.length)==prefx) && (arr_chk[j].getAttribute("id").substr(0,4)!='chk_') && (document.getElementById(arr_chk[j].getAttribute("id")).checked==true)){
   				
   				if(k>0)
   					str_campionati = str_campionati+"@";
   		
   				var hidden_field = document.getElementById("hid_"+arr_chk[j].getAttribute("id")).value;
   				str_campionati = str_campionati + hidden_field;
   				k++;
   			}
   		}

   		if(k==0){
   				alert("Selezionare almeno un campionato!");
   		}else{
   			
    		document.getElementById(location).innerHTML="<div style='margin-top:100px; margin-bottom:100px' align='center'><br><br><img src='images/ajax-loader_bianco.gif' border='0'></div>";  
			
			dim_var = window.screen.width - 340
			
   			var url="?model=palinsesto_print&str_campionati="+str_campionati+"&dim="+dim_var+"&condition=".condition;
   			$.post(url,
   			{condition:condition},
                function(data){
               		document.getElementById(location).innerHTML=data;         
                }
		    );
//			$('#div_campionati').enableTab(6);
			// tiene traccia del campionato visualizzato e dell'indice del bottone relativo
			$('#page_sport').val($('#page_sport_id').val());
		    $('#back_campionato').val(url);
		 	//$('#page_id').val('AVVENIMENTI');   
   		}   		
    }
    
    // richiama la pagina per la stampa degli avvenimenti secondo il filtro impostato
    function print_avvenimenti_filtered(condition, pdf) {
    	var segni_sel="";
		var url="";
		
		if (condition!=7) {
    		url='index.php?model=palinsesto_printfiltered';
		}
		else
		if (condition==7) {
			url='index.php?model=palinsesto_printantepost';
		}
    	// aggiunge i parametri per la selezione dei campionati
    	 url=url+"&str_campionati="+$("#str_campionati").val()+"&dim="+$("#dim").val();
    	 
    	// aggiunge i parametri per l'ordinamento e la visualizzazione
    	if ($("input[@name='f_raggruppa']:nth(0)").attr("checked"))
    		url=url+"&f_raggruppa="+($("input[@name='f_raggruppa']:nth(0)").val());
    	else
			if ($("input[@name='f_raggruppa']:nth(1)").attr("checked"))
				url=url+"&f_raggruppa="+($("input[@name='f_raggruppa']:nth(1)").val());
    		else
				if ($("input[@name='f_raggruppa']:nth(2)").attr("checked"))
					url=url+"&f_raggruppa="+($("input[@name='f_raggruppa']:nth(2)").val());
								
    	url=url+"&f_corpo="+$("#f_corpo").val();
    	if ($("#f_vis_data").attr("checked")) {
    		url=url+"&f_vis_data=1";
    	}
    	else {
    		url=url+"&f_vis_data=0";
    	}
    	// ricerca tutte le selezioni per inoltrarle alla pagina per la stampa
    	for (i=0; i<$("#count_checkbox").val(); i++) {
    		if ($("#ck_"+i).attr("checked")==true) {
    			if (segni_sel!="") segni_sel=segni_sel+"@";
    			segni_sel=segni_sel+$("#ck_"+i).val();
    		}
    	}
    	url=url+"&f_segni="+segni_sel;    	
    	url=url+"&condition="+$("#condition").val();
    	
    	// definisce il nome della finestra nella quale far comparire la stampa delle quote
    	var win_name="jenius_stampa_eventi";
    	
    	// verifica la richiesta di creazione del documento pdf
    	if (pdf==true) {
    		url=url+"&output=1";
    	}
    	
    	if (segni_sel=="") {
    		alert('Non e\' stato selezionato nessun segno.');
    	}
    	else {
    		// apre una finestra di popup
    		window.open(url,win_name,"width=800,height=600 ,toolbar=no, scrollbars=yes");
    	}
    }
    
    function show_avvenimenti(campionato, el, flag_win, condition){   
    	// verifica la presenza del div "div_interno_sport"
    	search_div();
    	
    		$("#"+el).html("<div style='margin-top:100px;margin-bottom:100px' align='center'><br><br><img src='images/ajax-loader_bianco.gif' border='0'></div>");  
    		var url="view/palinsesto/vw_avvenimenti.php?condition="+condition+"&str_campionati="+campionato;
    		//var url="index.php?model=palinsesto_avvenimenti&condition="+condition+"&str_campionati="+campionato;
	  		$.post(url,'',
                function(data){
               		// document.getElementById(el).innerHTML=data;
               		// alert(el+" : "+document.getElementById(el));
               		$("#"+el).html(data);
                }
		    ); 
			// tiene traccia del campionato visualizzato e dell'indice del bottone relativo
			$('#page_sport').val($('#page_sport_id').val());
		    $('#back_campionato').val(url);
			if(document.getElementById('tag_pal')) document.getElementById('tag_pal').focus();
   }   

    function check_all(id_cat3){

   		var arr_chk = document.getElementsByTagName("input");
		var father=0;
   		for(var j=0; j<arr_chk.length; j++){   			
   			if(arr_chk[j].type=="checkbox"){   				
				var id_chk = arr_chk[j].getAttribute("id");   				
   				var splitted = id_chk.split("_");   			
   				if(splitted[1]==id_cat3){   					
   					 if(id_chk=="chk_"+id_cat3){
   					 		if(document.getElementById(id_chk).checked==true){
   					 			father=1;
   					 		} else{
   					 			father=0;
   					 			
   					 		}
   					 } else{   					 	
	   					if(document.getElementById(id_chk).checked==true)
	   						 document.getElementById(id_chk).checked=false;
	   					else
	   						if(father==1) document.getElementById(id_chk).checked=true;   						
   					 }
   				}   				
   			}
		}
	}               

	function calcola_biglietto(curr_val, num_eventi, num_eventi_bonus, moltiplicatore_posta, min_value_p, max_value_p, tipo_controllo)
	{
		var win_1=0;
		var punta=0;
		var res=false;
//		alert(curr_val);
//		alert(moltiplicatore_posta);

		if (tipo_controllo==0) {
			if (curr_val>0) { 
				win_1=(curr_val * moltiplicatore_posta * 1.00);
			}
			else { 
				punta=min_value_p;
				win_1=(min_value_p * moltiplicatore_posta * 1.00);
			}			
		}
		else
		if (tipo_controllo==1) {
			if (curr_val>0) {
				curr_val =confirm_change_value(curr_val, min_value_p, max_value_p, true);
				// verifica che l'utente abbia confermato il cambio dell'importo, altrimenti esce
				if (curr_val==-1) return;
				win_1=(curr_val * moltiplicatore_posta * 1.00);
				bet_val=curr_val * 1.00;
				document.getElementById('puntata').value=bet_val.toFixed(0);
			}
			else {
				bet_val=min_value_p;
				win_1=bet_val * moltiplicatore_posta * 1.00;
			}			
		}
		var perc = document.getElementById('bonus_percentuale').value;		
		var temp_win_1 = win_1;
		
		// si assicura che i seguenti valori siano una cifra intera e non una stringa
		int_num_eventi_bonus = parseInt((num_eventi_bonus * 1.00).toFixed(0));
		int_num_eventi       = parseInt((num_eventi * 1.00).toFixed(0));

		for(i=int_num_eventi_bonus;i<=int_num_eventi;i++) {			
				temp_win_1 = temp_win_1 + (Math.round(((temp_win_1/100) * perc)*100)/100);
		}
		var bonus = temp_win_1 - win_1;
 		
		document.getElementById('valore_vincita_1').innerHTML = win_1.toFixed(2);
		document.getElementById('importo_bonus').innerHTML = bonus.toFixed(2);
		document.getElementById('valore_totale').innerHTML = temp_win_1.toFixed(2);
	}
		
	// verifica che l'importo inserito non superi l'importo minimo/massimo e
	//   nel caso mostra una richiesta di conferma variazione importo
	function confirm_change_value(curr_val, min_value_p, max_value_p, show_alert) {
		//alert(min_value_p);
		//alert(max_value_p);
		var curr_val_r=0;
		var res=true;
	
		// controlla che il valore esista
		if (curr_val == null) {
			curr_val = min_value_p;
		}
		else {
			// controlla che sia un valore numerico valido
			//if (isNaN(parseFloat(curr_val))) {
			if (isNaN(Number(curr_val))) {
				curr_val = min_value_p;
			}
		}
		// controlla il valore numeri nell'intervallo min / max
		if (curr_val<min_value_p) {
			if (show_alert==true) 
				res = confirm("L'IMPORTO INSERITO E' INFERIORE AL MINIMO IMPORTO GIOCABILE. CONFERMI LA VARIAZIONE AUTOMATICA DELL'IMPORTO ?")
			else
				res = true;
			
			if (res==true)
				curr_val_r=min_value_p;
			else
				curr_val_r=-1;
		}
		else
		if (curr_val>max_value_p) {
			if (show_alert==true)
				res = confirm("L'IMPORTO INSERITO E' SUPERIORE AL MASSIMO IMPORTO GIOCABILE. CONFERMI LA VARIAZIONE AUTOMATICA DELL'IMPORTO ?")
			else
				res = true;
			
			if (res==true)
				curr_val_r=max_value_p;
			else
				curr_val_r=-1;
		} 
		else {
			curr_val_r = curr_val;
		}
		
		return curr_val_r;
	}
	
	
	function ripeti_biglietto(biglietto_name)
	{
		var giocata_last = document.getElementById("giocata_last").value;
		// verifica la presenza di una giocata in memoria
		if (giocata_last!="") {
			// trasferisce la giocata in memoria come giocata attuale
			document.getElementById("giocata").value = giocata_last;
			document.getElementById("giocata_last").value = '';
			
			// seleziona le celle degli eventi
			var giocate_array = giocata_last.split("$");		
			
			//cambio il background della quota
			var quota_arr = "";
			var cod_pal = "";
			var cod_avv = "";
			var segno = "";
	
			var pal_avv = "";
			
			for (var index=0; index<giocate_array.length; index++)
			{				
				if (giocate_array[index]!="") {				
					//cambio il background della quota
					quota_arr = giocate_array[index].split("|");
					id_quota = quota_arr[1];
					cod_pal = quota_arr[2];
					cod_avv = quota_arr[3];
					segno = quota_arr[6];
					pal_avv = cod_pal+"."+cod_avv;
		
					set_bgcolor(id_quota,pal_avv, segno, color_bg_row_even_sel, color_bg_row_odd_sel);
				}
	    	}
			
			// richiama la definizione del biglietto
 			refresh_biglietto(biglietto_name, 0);
		}
	}
	
	function load_biglietto_post(biglietto_name, model, infos, username)
    {   	    	    	
    	var pal_sel='';
    	//alert(username);
    	
		var giocata_amp = infos;
		giocata_amp = giocata_amp.replace(/&/g,"e#");
    	
    	$("#"+biglietto_name+"_loader").html('<img src="images/blank.gif" width="343" height="45%" alt="1"><center><img src="images/ajax-loader_bianco.gif" alt=""></center>');
    	
    	if(document.getElementById('pal_hid'))
			pal_sel= document.getElementById('pal_hid').value;

		$.post("index.php?model=biglietto"+model, {giocata: giocata_amp, betting_touser: username},
                function(data){ 
                	$("#"+biglietto_name).html(data);                 	
					if(document.getElementById("table_coupon").style.visibility=='visible')
					{	
								if(document.getElementById('tag_pal'))
	                			{
	                				document.getElementById('tag_pal').value=pal_sel;          
									setTimeout("document.getElementById('tag_pal').focus();	document.myform.tag_pal.select()",500);
	                			}
					}
                }
		    );
    }
    
	function load_biglietto(biglietto_name, infos)
    {
    	var pal_sel='';
    	
    	$("#"+biglietto_name+"_loader").html('<img src="images/blank.gif" width="343" height="45%" alt="1"><center><img src="images/ajax-loader_bianco.gif" alt=""></center>');

    	if(document.getElementById('pal_hid'))
			pal_sel= document.getElementById('pal_hid').value;
		
		// 01/08 - modificato da $.get( a $.post(
		
		$.post("index.php?model=biglietto"+infos,"",
                function(data){ 
                	$("#"+biglietto_name).html(data); 
					if(document.getElementById("table_coupon").style.visibility=='visible')
					{	
						if(document.getElementById('tag_pal'))
            			{ 
            		
            				document.getElementById('tag_pal').value=pal_sel;          
							setTimeout("document.getElementById('tag_pal').focus();	document.myform.tag_pal.select()",500);
            			}
					}
                }
		    );
    }

    
    function insert_quota(biglietto_name, quota, id_td, bg_quota) {
	    var control = -1;
    	// var max_num_giocate      = 20;
	    var max_eventi_doppi     = 5;
	    var max_selezioni_evento = 2;
		var giocata_rif   = document.getElementById("giocata");
		var giocate       = giocata_rif.value;
		var giocate_array = giocate.split("$");
		
		var max_num_giocate      = parseInt($('#max_num_giocate').val());
		
		// verifica che il biglietto sia stato caricato, altrimenti lo carica nuovamente
		if (document.getElementById('puntata')==null) 
		{ 
			// carica il biglietto
			load_biglietto(biglietto_name, "");
		}
		else {
			// alert("ok puntata");
			// essendo stato caricato il biglietto, elabora la richiesta dell'utente
			var rimozione=0;
			if((document.getElementById(id_td))&&(rgbConvert(document.getElementById(id_td).style.backgroundColor)==bg_quota))
			{				
				// alert("remove: "+giocate);
				remove_quota("table_coupon", giocate, quota+"$", color_bg_row_odd, color_bg_row_even, 1);
				rimozione=1;
			}  
			
			if(rimozione==0){
				// controlla che non sia stata giï¿½ inserita la stessa giocata
		    	control = giocata_rif.value.indexOf(quota);
	
				// verifica se puï¿½ continuare la validazione della giocata
				//   e verifica che la giocata non sia U
				if (control<0) {
							
				}
	
			// verifica se puï¿½ continuare la validazione della giocata
			//   e verifica che la giocata sia presente al massimo due volte per ogni evento
			//   e che ci siano al massimo cinque eventi con questa condizione
			if ((control<0) && (giocate_array.length > 1)) {
				var count_selezioni_evento = 0;
				var count_eventi_doppi = 0;
				giocate_array.sort();
	
				// controlla la presenza di selezioni doppie per le quote inserite
				var exit=-1;
				var exit_sub=-1;
				var index = 1;
				var index_sub = 1;
				var index_curr = 0;			
				var giocata_sel= "";			
				var giocata_sub= "";
				var quota_sub = quota.split("|");
				var index_sub_old = -1;
							
				while (exit<0)
				{
					exit_sub = -1;
					index_sub = 1+index;
					count_selezioni_evento = 0;
					// ricerca l'evento all'interno dell'array ordinato
					// giocata_sel = giocate_array[index].substring(0,10);
					
					giocata_sel = giocate_array[index].split("|");
					
					// se fossero state inserite almeno due giocate
					if ((giocate_array.length > 2) && (index_sub < giocate_array.length))
					{
						// muove il secondo indice per ricercare all'interno delle giocate,
						//   una seconda giocata per lo stesso evento e contare quante giocate 
						//   di questo genere siano state inserite
	
						while (exit_sub<0) 
						{
//		alert(index+"-----"+index_sub);
							//giocata_sub = giocate_array[index_sub].substring(0,10);
							
							if (index_sub!=index_sub_old) {
								index_sub_old = index_sub;
								giocata_sub = giocate_array[index_sub].split("|");
							}
							
//		 alert(giocata_sel+"-----"+giocata_sub);						
							if ((giocata_sel[0]==giocata_sub[0]) && (giocata_sel[2]==giocata_sub[2]) && (giocata_sel[3]==giocata_sub[3]))	 {
								// incrementa il contatore delle stesse occorrenze per un singolo evento
								count_selezioni_evento = count_selezioni_evento + 1;
								// incrementa il contatore degli eventi con doppia selezione
								count_eventi_doppi = count_eventi_doppi + 1;
//		 alert("doppia: "+count_selezioni_evento );
	
								// verifica che non sia stato superato il limite max delle selezioni del singolo evento
								if (count_selezioni_evento == max_selezioni_evento) {
//		alert("1 exit max selezioni per evento");
									exit_sub=1;
									exit=1;
									control=1;	// si ï¿½ verificata una condizione non accettabile, esce dal ciclo e non inserisce il nuovo evento
								}
								// verifica che non sia stato superato il limite max delle selezioni del singolo evento
								if (count_eventi_doppi > max_eventi_doppi) {
//		alert("1 exit max selezione eventi doppi");
									exit_sub=1;
									exit=1;
									control=1;	// si ï¿½ verificata una condizione non accettabile, esce dal ciclo e non inserisce il nuovo evento
								}

							}
							
							// questa condizione viene elaborata nel caso di sole due quote selezionate
							if ((giocata_sub[4]==quota_sub[4]) && (giocata_sub[0]==quota_sub[0])) {
								// verifica la corrispondenza del codeve selezionato dal biglietto con il codeve da inserire
								if (check_codeve(quota_sub[13], giocate_array[index_sub])!=1) {
									exit_sub=1;
									exit=1;
									control=1;
									// alert("error");
								}
							}	
							
 							index_sub = index_sub + 1;
							if (index_sub == giocate_array.length) exit_sub=1;
						}
	
						// verifica che la quota che si intende inserire non sia uguale alla giocata in analisi
//		alert(giocata_sel+"++++++"+quota_sub);
						
						if ((giocata_sel[0]==quota_sub[0]) && (giocata_sel[2]==quota_sub[2]) && (giocata_sel[3]==quota_sub[3]))	 {
							// incrementa il contatore delle stesse occorrenze per un singolo evento
							count_selezioni_evento = count_selezioni_evento + 1;
							// incrementa il contatore degli eventi con doppia selezione
							count_eventi_doppi = count_eventi_doppi + 1;
//		alert("doppia: "+count_selezioni_evento );						
							// verifica che non sia stao superato il limite max delle selezioni del singolo evento
							if (count_selezioni_evento == max_selezioni_evento) {
//		alert("2 exit max selezioni per evento");
								exit_sub=1;
								exit=1;
								control=1;	// si ï¿½ verificata una condizione non accettabile, esce dal ciclo e non inserisce il nuovo evento
							}
							if (count_eventi_doppi > max_eventi_doppi) {
//		alert("2 exit max selezione eventi doppi");
								exit_sub=1;
								exit=1;
								control=1;	// si ï¿½ verificata una condizione non accettabile, esce dal ciclo e non inserisce il nuovo evento
							}
							
						}
					}
					else {
						// questa condizione viene elaborata nel caso di sole due quote selezionate
						giocata_sel_arr = giocate_array[1].split("|");			
						if ((giocata_sel_arr[4]==quota_sub[4]) && (giocata_sel_arr[0]==quota_sub[0])) {
							// verifica la corrispondenza del codeve selezionato dal biglietto con il codeve da inserire
							if (check_codeve(quota_sub[13], giocate_array[1])==1) {
								//
							}
							else {
								exit=1;
								control=1;
							}
						}
					}
					index = index + 1;
					// verifica il raggiungimento della fine dell'array
					if (index == giocate_array.length) { exit=1; }
				}
	
				// verifica che la quota che si intende inserire non sia uguale all'ultima giocata inserita nell'array
				giocata_sel = giocate_array[giocate_array.length-1].split("|");
				
				// verifica il legame
				// alert(quota_sub[9]+'_'+quota_sub[10]+'_'+quota_sub[11]+'!!'+giocata_sel[9]+'_'+giocata_sel[10]+'_'+giocata_sel[11]);
				if ((quota_sub[9]!=giocata_sel[9]) || (quota_sub[10]!=giocata_sel[10]) || (quota_sub[11]!=giocata_sel[11])) {
					exit_sub=1;
					exit=1;
					control=1;	// si ï¿½ verificata una condizione non accettabile, esce dal ciclo e non inserisce il nuovo evento				
				}
				// verifica che la quota che si intende inserire non sia uguale alla giocata in analisi
//		alert(giocata_sel+"!!!!!!!"+quota_sub);
				if ((giocata_sel[0]==quota_sub[0]) && (giocata_sel[2]==quota_sub[2]) && (giocata_sel[3]==quota_sub[3]))	 {
					// incrementa il contatore delle stesse occorrenze per un singolo evento
					count_selezioni_evento = count_selezioni_evento + 1;
					// incrementa il contatore degli eventi con doppia selezione
					count_eventi_doppi = count_eventi_doppi + 1;
//		alert("doppia: "+count_selezioni_evento );						
					// verifica che non sia stao superato il limite max delle selezioni del singolo evento
					if (count_selezioni_evento == max_selezioni_evento) {
//		alert("2 exit max selezioni per evento");
						exit_sub=1;
						exit=1;
						control=1;	// si ï¿½ verificata una condizione non accettabile, esce dal ciclo e non inserisce il nuovo evento
					}
					if (count_eventi_doppi > max_eventi_doppi) {
//		alert("2 exit max selezione eventi doppi");
						exit_sub=1;
						exit=1;
						control=1;	// si ï¿½ verificata una condizione non accettabile, esce dal ciclo e non inserisce il nuovo evento
					}
				}
	
				// verirfica il numero degli eventi doppi
				if (count_eventi_doppi > max_eventi_doppi) {
//		alert("3 exit max selezione eventi doppi");
					control=1;	// si ï¿½ verificata una condizione non accettabile, esce dal ciclo e non inserisce il nuovo evento
				}
				// verifica che non sia stato raggiunto il numero massimo di giocate
				if (giocate_array.length > max_num_giocate+count_eventi_doppi) {
//	 	alert(count_eventi_doppi);
					exit=1;
					control=1;
				}
				
			}
		    
		    // se la validazione non avesse riscontrato errori, inserisce l'evento
			if (control<0) {
				giocata_rif.value += quota+ "$";
				chg_bgcolor(id_td, bg_quota);
				
				//load_biglietto(biglietto_name, "&giocata="+giocata_rif.value);
				var puntata = document.getElementById("puntata");		
		
				//load_biglietto(biglietto_name, "&giocata="+giocata_rif.value+"&puntata="+puntata.value);
				load_biglietto_post(biglietto_name, "&puntata="+puntata.value, giocata_rif.value, $('#betting_touser').val());
				}
			
			}
		}
	}

	function check_codeve(codeve, giocata_sel) {
		// estrae i volori di CODEVE dell'evento attualmente indicizzato
		var codeve_sub = giocata_sel.split("|");
		// alert(codeve+" - "+codeve_sub[13]);
		if (codeve == codeve_sub[13]) {
			ret=1;
		}
		else {
			ret=0;
		}
		
		// funzionalità di controllo segni per COD EVE disabilitata
		ret=1;
		
		return ret;
	}
	
	function clear_avvenimenti(erase_giocata) {
		var giocata_rif = document.getElementById("giocata");
		var giocate = giocata_rif.value;
		var giocate_array = giocate.split("$");		
		
		//cambio il background della quota
		var quota_arr = "";
		var cod_pal = "";
		var cod_avv = "";
		var segno = "";

		var pal_avv = "";
		
		for (var index=0; index<giocate_array.length; index++)
		{
			//cambio il background della quota
			quota_arr = giocate_array[index].split("|");
			id_quota = quota_arr[1];
			cod_pal = quota_arr[2];
			cod_avv = quota_arr[3];
			segno = quota_arr[6];
			pal_avv = cod_pal+"."+cod_avv;

			rem_bgcolor(id_quota,pal_avv, segno, color_bg_row_even, color_bg_row_odd);
    	}
    	
    	if (erase_giocata==1) {
	    	$('#giocata_last').val($('#giocata').val());
			$('#giocata').val('');
    	}
	}
	
    function clear_biglietto(biglietto_name, info, color_bg_row) {

		var giocata_rif = document.getElementById("giocata");
	
		var giocate = giocata_rif.value;
		var giocate_array = giocate.split("$");
		
		//cambio il background della quota
		var quota_arr = "";
		var cod_pal = "";
		var cod_avv = "";
		var segno = "";

		var pal_avv = "";
		
		for (var index=0; index<giocate_array.length; index++)
		{
			if ((giocate_array[index] != null) && (giocate_array[index] != "")) {
				//cambio il background della quota
				quota_arr = giocate_array[index].split("|");
				id_quota = quota_arr[1];
				cod_pal = quota_arr[2];
				cod_avv = quota_arr[3];
				segno = quota_arr[6];
				pal_avv = cod_pal + "." + cod_avv;
				
				rem_bgcolor(id_quota, pal_avv, segno, color_bg_row_even, color_bg_row);
			}
    	}
    	
		$('#giocata_last').val($('#giocata').val());
		$('#giocata').val('');
        var msg_info = "";
        if (info!="") {
        	msg_info = "&msg="+info;
        }
        // mod 07/10/09		
		load_biglietto_post(biglietto_name, msg_info, $('#giocata').val(), $('#betting_touser').val());
        //go_back_campionato_url('div_interno_sport');
    }
    
    function remove_quota(biglietto_name, infos, quota, bgcolor_odd, bgcolor_even, reload_request, oth_bg) {
    	
		var giocata_rif = document.getElementById("giocata");    
	  	//rimuove dal biglietto la giocata
		update = replaceSubstring(infos, quota, "")
	
		giocata_rif.value = update;
		//cambio il background della quota
		var quota_arr = quota.split("|");
		id_quota = quota_arr[1];
		var cod_pal = quota_arr[2];
		var cod_avv = quota_arr[3];
		var segno = quota_arr[6];
	
		var pal_avv = cod_pal+"."+cod_avv;
		
		rem_bgcolor(id_quota,pal_avv, segno, bgcolor_even, bgcolor_odd, oth_bg);		 
		
		if (reload_request==1) {
			var puntata = document.getElementById("puntata");
			// mod 12/08/09
			//load_biglietto(biglietto_name, "&giocata="+update+"&puntata="+puntata.value+"&betting_touser="+$("#betting_touser").val());
			load_biglietto_post(biglietto_name, "&puntata="+puntata.value, update, $('#betting_touser').val());
		}
	}

	function remove_quota_sel(biglietto_name, quota, bgcolor_odd, bgcolor_even) {
		//cambio il background della quota
		var quota_arr = quota.split("|");
		var id_quota = quota_arr[1];
		var cod_pal = quota_arr[2];
		var cod_avv = quota_arr[3];
		var segno = quota_arr[6];
	
		var pal_avv = cod_pal+"."+cod_avv;
		
		rem_bgcolor(id_quota,pal_avv, segno, bgcolor_even, bgcolor_odd);
	}
		

    function set_quote(quota) {
		var giocata_rif = document.getElementById("giocata");    
		giocata_rif.value = quota;
	}
	
	function refresh_biglietto(biglietto_name, puntata) {
		var giocata_rif = document.getElementById("giocata");  
		// mod 12/08/09
		//load_biglietto(biglietto_name, "&giocata="+giocata_rif.value+"&puntata="+puntata+"&betting_touser="+$("#betting_touser").val());
		load_biglietto_post(biglietto_name, "&puntata="+puntata, giocata_rif.value, $('#betting_touser').val());
    }

	function go_biglietto(biglietto_name, puntata, stampa, username, min_value_p, max_value_p) {
		puntata =confirm_change_value(puntata, min_value_p, max_value_p, false);
		// verifica che l'utente abbia confermato il cambio dell'importo, altrimenti esce
		if (puntata==-1) return;

		var giocata_rif = document.getElementById("giocata");

		if ((username=='') || (username=='undefined')) {
			alert("Utente non selezionato");
		}
		else if (giocata_rif.value=="") {
			alert("Nessun evento selezionato");
		}
		else {
			var url_stampa='&stampa='+stampa;
			var url_username='&betting_touser='+username;			
			
			// richiama l'azione TICKETSALE di biglietto
				// mod 12/08/09			
				// load_biglietto(biglietto_name, "&giocata="+giocata_amp+"&act=ticketsale&puntata="+puntata+url_stampa+url_username);
			load_biglietto_post(biglietto_name, "&act=ticketsale&puntata="+puntata+url_stampa+url_username, giocata_rif.value, $('#betting_touser').val());			
		}
    }
	
    function go_sistema(biglietto_name, numero_colonne, url_add, play, stampa, username, min, max) {
    	var url_plus = "";
		var url_stampa='&stampa='+stampa;
		
		if ((username=='') || (username=='undefined')) {
			alert("Utente non selezionato");
		}
		else {
	    	for (index=0; index<numero_colonne; index++) {
	    		// verifica che la checkbox sia stata selezionata
	    		if (document.getElementById("sel_eventi_"+index).checked==true) {
	    			check = 1;
	    			valore = document.getElementById("importo_"+index).value;
	    			valore = confirm_change_value(valore, min, max, true);
	    			// verifica che l'utente abbia confermato il cambio dell'importo, altrimenti esce
	    			if (valore==-1) return;
	    		}
	    		else {
	    			check=0;
	    			valore=0;
	    		}
	    		url_plus = url_plus+"&c"+index+"="+check+"&p"+index+"="+valore+url_stampa;
	    	}
	    	url_plus = url_plus + document.getElementById("url_colonne_fisse").value;
	
			var giocata_rif = document.getElementById("giocata");
			
			if (play==true) {
				// richiama l'azione TICKETSALE di biglietto_sistema		
				var url_act="&act=ticketsale";
			}			
			else {
				// richiama l'azione TICKETCHECK di biglietto_sistema
				var url_act="&act=ticketcheck";
	    		$("#table_sistema").html('<img src="images/blank.gif" width="600" height="45%" alt="1"><br><center><img src="images/ajax-loader_bianco.gif" alt=""></center>');
			}
			load_biglietto_post(biglietto_name, "_sistema"+url_act+"&sistcorr=1"+url_plus+url_add, giocata_rif.value, $('#betting_touser').val());
		}
    }
    
	function call_sistema(biglietto_name, puntata, username) {
		var check_name="";
		var giocata_rif = document.getElementById("giocata");  
		
		if ((username=='') || (username=='undefined')) {
			alert("Utente non selezionato");
		}
		else if (giocata_rif.value=="") {
			alert("Nessun evento selezionato");
		}
		else {
			// definisce tutte le quote fisse

			var quote_fisse="";
			for (var index=1; index<26; index++) 
			{
				check_name='check_'+index;
				
				if (document.getElementById(check_name)) {
					// inserisce soltanto le checkbox selezionate
					if (document.getElementById(check_name).checked==true) 
					{
					  	quote_fisse = quote_fisse + "&f"+index+"="+document.getElementById(check_name).checked;
					}
				}
			}
			//load_biglietto(biglietto_name, "&giocata="+giocata_rif.value+"&act=sistcorr&puntata="+puntata+quote_fisse);
			
			load_biglietto_post(biglietto_name, "&act=sistcorr&puntata="+puntata+quote_fisse, giocata_rif.value, $('#betting_touser').val());
		}
    } 

	function insert_sistema() {
		var giocata_rif = document.getElementById("giocata");  
	
		// definisce tutte le quote fisse
		var quote_fisse="";
		var gruppi_sel = "";		
		for (var index=1; index<26; index++) 
		{
			check_name="check_"+index+"";
			if (document.getElementById(check_name)) {
				// inserisce soltanto le checkbox selezionate
				if (document.getElementById(check_name).checked==true) 
				{
				  	quote_fisse = quote_fisse + "&f"+index+"="+document.getElementById(check_name).checked;
				}
			}
		
			check_name="sel_eventi_"+index+"";
			puntata_name="importo_"+index+"";
			if (document.getElementById(check_name)) {
				// inserisce soltanto le checkbox selezionate
				if (document.getElementById(check_name).checked==true) 
				{
				  	gruppi_sel = gruppi_sel + "&g"+index+"="+document.getElementById(check_name).checked + "&p"+index+"="+document.getElementById(puntata_name).value;
				}
			}		
		}
		
		// verifica la selezione di almeno un gruppo di eventi
		if (gruppi_sel=="") alert("E' necessario selezionare almeno un gruppo di eventi.");
		
		var url_l = 'index.php?model=biglietto_sistema&giocata='+giocata_rif.value+'&sistcorr=1'+quote_fisse+gruppi_sel+"&p="+document.getElementById('puntata').value;
		//alert(url_l);
		carica(url_l,'#div_sport');
    }

	function calc(idx, min, max) {
		var imp=0;
		// verifica se la checkbox ï¿½ attiva o meno
		if (document.getElementById("sel_eventi_"+idx).checked==true) { 
			// verifica il superamento della sognlia min e max della puntata
			puntata = document.getElementById("importo_"+idx);
			
			if (puntata.value < min) {
				puntata.value = min.toFixed(0);
			}
			else
			if (puntata.value > max) {
				puntata.value = max.toFixed(0);
			}

		    // calcola il valore dell'importo			
			imp = document.getElementById("importo_"+idx).value * document.getElementById("puntate_gruppo_"+idx).innerHTML * 1.00; 
		} 
		else
		{
			// azzera l'importo
			imp = 0.00;
		}
		// assegna l'importo all'oggetto
		document.getElementById("importo_gruppo_"+idx).innerHTML=imp.toFixed(2);		
	}

	//function calc_posta(idx, min, max) {
	function calc_posta(idx, num_eventi, num_eventi_bonus, min, max) {
		var imp=0;
		var vinc=0;
		var bonus=0;
		var totale=0;
		var temp_win_1 = 0;
		puntata = document.getElementById("importo_"+idx);

		// verifica se la checkbox ï¿½ attiva o meno		
		if (document.getElementById("sel_eventi_"+idx).checked==true) {
			// verifica il superamento della soglia min e max della puntata
/*
			if (puntata.value < min) {
				puntata.value = min.toFixed(2);
			}
			else
			if (puntata.value > max) {
				puntata.value = max.toFixed(2);
			}
*/
			var puntata_x = confirm_change_value(puntata.value, min, max, true);

			// verifica che l'utente abbia confermato il cambio dell'importo, altrimenti esce
			if (puntata_x==-1) return;		
			
			puntata.value = puntata_x;
			
			// calcola il valore della vincita
			vinc = document.getElementById("importo_"+idx).value * document.getElementById("posta_"+idx).innerHTML * 1.00; 
			if (document.getElementById("bonus_perc_"+idx)) {
//				bonus = (vinc * document.getElementById("bonus_perc_"+idx).value) / 100;
				temp_win_1 = vinc;
				for(i=num_eventi_bonus;i<=num_eventi;i++) {
					temp_win_1 = temp_win_1 + (Math.round(((temp_win_1/100) * document.getElementById("bonus_perc_"+idx).value)*100)/100);
				}
				var bonus = temp_win_1 - vinc;
				
				totale = temp_win_1;
			}
			else {
				totale = vinc;
				bonus=0;
			}
			bonus = bonus.toFixed(2);
			totale = totale.toFixed(2);
			vinc = vinc.toFixed(2);
		}		
		else {
			// azzera il valore della vincita			
			vinc   = "0.00";
			bonus  = "0.00";
			totale = "0.00";
		}
		imp = puntata.value*1.00;
		imp = imp.toFixed(0);		
		
		// assegna l'importo e la vincita presunta	
		document.getElementById("importo_"+idx).value = imp;
		if (document.getElementById("importo_bonus_"+idx)!=null) $("#importo_bonus_"+idx).html(bonus);
		if (document.getElementById("vincita_colonna_"+idx) != null) $("#vincita_colonna_"+idx).html(vinc);
		if (document.getElementById("valore_totale_"+idx)!=null) $("#valore_totale_"+idx).html(totale);

		// verifica l'esistena della input hidden TOT_COLONNE
		if (document.getElementById("tot_colonne")) {
			var colonne_sistema = document.getElementById("colonne_sistema").value;
			var tot_importo=0;
			var tot_vincita_max=0;
			var tot_vincita_min=99999999;
			var tot_colonne=0;
			var tot_bonus=0;
			// ricerca tutte le checkbox
			for (a=0; a<colonne_sistema; a++) {
				if (document.getElementById("sel_eventi_"+a)) {
					// calcola i totali progressivi nel caso in cui la checkbox sia selezionata
					if (document.getElementById("sel_eventi_"+a).checked==true) {
						tot_colonne++;
						tot_importo = tot_importo + Number(document.getElementById("importo_"+a).value);
						tot_bonus   = tot_bonus + Number(document.getElementById("importo_bonus_"+a).innerHTML);
						if (Number(document.getElementById("valore_totale_"+a).innerHTML) > tot_vincita_max) tot_vincita_max = Number(document.getElementById("valore_totale_"+a).innerHTML);
						if (Number(document.getElementById("valore_totale_"+a).innerHTML) < tot_vincita_min) tot_vincita_min = Number(document.getElementById("valore_totale_"+a).innerHTML);
					}
				}
			}
			// aggiorna i risultati a video
			$("#tot_colonne").html(tot_colonne);
			$("#tot_importo").html((tot_importo * 1.00).toFixed(2));
			$("#tot_bonus").html((tot_bonus * 1.00).toFixed(2));
			$("#tot_vincita").html((tot_vincita_max * 1.00).toFixed(2));
		}

	}	
	
	function replaceSubstring(inputString, fromString, toString) {
	   // Goes through the inputString and replaces every occurrence of fromString with toString
	   var temp = inputString;
	   if (fromString == "") {
	      return inputString;
	   }
	   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
	      while (temp.indexOf(fromString) != -1) {
	         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
	         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
	         temp = toTheLeft + toString + toTheRight;
	      }
	   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
	      var midStrings = new Array("~", "`", "_", "^", "#");
	      var midStringLen = 1;
	      var midString = "";
	      // Find a string that doesn't exist in the inputString to be used
	      // as an "inbetween" string
	      while (midString == "") {
	         for (var i=0; i < midStrings.length; i++) {
	            var tempMidString = "";
	            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
	            if (fromString.indexOf(tempMidString) == -1) {
	               midString = tempMidString;
	               i = midStrings.length + 1;
	            }
	         }
	      } // Keep on going until we build an "inbetween" string that doesn't exist
	      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
	      while (temp.indexOf(fromString) != -1) {
	         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
	         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
	         temp = toTheLeft + midString + toTheRight;
	      }
	      // Next, replace the "inbetween" string with the "toString"
	      while (temp.indexOf(midString) != -1) {
	         var toTheLeft = temp.substring(0, temp.indexOf(midString));
	         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
	         temp = toTheLeft + toString + toTheRight;
	      }
	   } // Ends the check to see if the string being replaced is part of the replacement string or not
	   return temp; // Send the updated string back to the user
	} // Ends the "replaceSubstring" functio 
	
	function check_status(id) {
		return document.getElementById(id).checked;
	}
	
	function view_campionati_sel(sportId){		
		
    		var counter = dijit.byId("contatore_"+sportId).getValue();
    		var arr_campionati;
    		var j=0;
    		var str = "";
    		for(var i=1; i<=counter; i++){
    			  var elemento = dijit.byId("chk_"+sportId+"_"+i);
    		
    			if(elemento.getValue()=="on"){
    			    		   str = str+ dijit.byId("hid_"+i).getValue()+" , "; 	
    			    			}
    		}
    		
    		alert("Hai selezionato : "+str);
   
	}

function set_betting_touser(biglietto_name, username) {
	var giocata_rif   = document.getElementById("giocata");

	var puntata = document.getElementById("puntata");		
		
	load_biglietto_post(biglietto_name, "&puntata="+puntata.value, giocata_rif.value, username);
}

// converte un colore preso da style (FireFox lo fornisce in RGB) in un valore esadecimale,
//   altrimenti restituisce il valore passato come parametro
function rgbConvert(str) {
   var res="";

   if (str.indexOf('rgb', 0)==-1) {
       res = str;
   }
   else {
   	   str = str.replace(/rgb\(|\)/g, "").split(",");
	   str[0] = parseInt(str[0], 10).toString(16).toLowerCase();
	   str[1] = parseInt(str[1], 10).toString(16).toLowerCase();
	   str[2] = parseInt(str[2], 10).toString(16).toLowerCase();
	   str[0] = (str[0].length == 1) ? '0' + str[0] : str[0];
	   str[1] = (str[1].length == 1) ? '0' + str[1] : str[1];
	   str[2] = (str[2].length == 1) ? '0' + str[2] : str[2];     
	   
	   res = '#' + str.join("");
   }
   
   return (res);
}

// crea la div con scroll qualora non fosse piï¿½ disponibile nella pagina
function search_div() {
	var exist_div = document.getElementById("div_interno_sport");
	// verifica l'esistenza del div
	if (exist_div==null) {
		// aggiunge il div nella pagina all'interno del componente padre
		var exist_div_sport = document.getElementById("div_sport");
		if (exist_div_sport!=null) {
			// aggiunge i tag per l'inserimento di un div con lo scroller verticale!!
			//exist_div_sport.innerHTML = '<div id="div_interno_sport" style="height:550px;overflow-y: scroll; overflow-x: hidden;"> </div>';
			$("#div_sport").html('<div id="div_interno_sport" style="height:550px;overflow-y: scroll; overflow-x: hidden;"> </div>');
		}
	}
}

// visualizza il loader al centro orizzontale della pagina
function insert_loader(id_name) {
	$("#"+id_name).html("<center><img src='images/ajax-loader_bianco.gif' alt=''></center>");
}

function wnd_open_giochi(url, popup_name) {
	wnd_betting=window.open(url, popup_name, 'width=850,height=460,resizable=no');	
}

function checkPatternChars(nm,vlu,pattern,required){
  if ( required === undefined ) {
      required = false;
   } 
  if(!required && vlu==""){
    return true;
  }
  if (!pattern.test(vlu)){
  	document.getElementById(nm).value='';
    alert("Il campo "+nm+" non puo\' contenere caratteri speciali!");
    return false;
  }
  else { 
    return true; 
  }
}


function check_char_special(){
  var pattern;
  pattern = /^([a-zA-Z0-9\\_\-])+$/
  if(!checkPatternChars('username',document.getElementById("username").value,pattern,true))
  {
  	document.getElementById("username").focus();
  } 
 } 

function incrGiocoCorretto(stringa){
	var valore = $("#" + stringa).val();
	valore++;
	$("#" + stringa).val(valore);
}

function decrGiocoCorretto(stringa){
	var valore = $("#" + stringa).val();
	valore--;
	$("#" + stringa).val(valore);
}