function conferma_cancellazione_mercati(){	
	if (!confirm("ATTENZIONE!!!!!!\nSei sicuro di voler cancellare il mercato selezionato?")){
			return false;
	}
	
	return true;
}
function controlla_modera_ges_mercati(numero_mercati_finestre_presenti,scelta_rosa,numero_giocatori
		  							  ,tipo_mercato_old, numero_cambi_old,sost_gioc_out_old,mercato_old){

	if (document.form_moderatore_gestione_mercati.mercato.value == 'S'){	
		if(document.form_moderatore_gestione_mercati.tipo_mercato.value == 0){
			alert ("Attenzione devi specificare il tipo di mercato");
			return false;
		}
		////controllo sul numero dei cambi per il mercato sempre aperto
		if (document.form_moderatore_gestione_mercati.tipo_mercato.value == 2){
			if(trim(document.form_moderatore_gestione_mercati.ma_numero_cambi.value) ==""){
				alert("attenzione il campo numero cambi non può essere vuoto");
				document.form_moderatore_gestione_mercati.ma_numero_cambi.focus();
				return false;
			}
			if(!controlla_numero(document.form_moderatore_gestione_mercati.ma_numero_cambi)){
				alert("attenzione il campo numero cambi deve essere numerico");
				document.form_moderatore_gestione_mercati.ma_numero_cambi.focus();
				return false;
			}
			if(parseInt(document.form_moderatore_gestione_mercati.ma_numero_cambi.value) < 1){
				alert("attenzione il numero dei cambi deve essere almeno 1");			
				document.form_moderatore_gestione_mercati.ma_numero_cambi.focus();
				return false;
			}
			//se prima e dopo le modifiche rimane un mercato sempre aperto e non hai modificato
			//il numero dei cambi e la sostituzione dei fuori Serie A
			//significa che non hai effettuato modifiche e do errore
			if (tipo_mercato_old == 2 && numero_cambi_old == document.form_moderatore_gestione_mercati.ma_numero_cambi.value
				&& sost_gioc_out_old == document.form_moderatore_gestione_mercati.sost_gratis_fuori_lista.value){
				alert("attenzione non hai effettuato modifiche");
				return false;				
			}
		}
		
		////controlli per il mercato a finestre
		if (document.form_moderatore_gestione_mercati.tipo_mercato.value == 1){
			if(document.form_moderatore_gestione_mercati.mc_num_mercati.value ==0){
				alert("attenzione il campo numero mercati non può essere vuoto");
				document.form_moderatore_gestione_mercati.mc_num_mercati.focus();
				return false;
			}else{
				//controlli per i mercati a finestre da inserire
				for(i = 1; i<=(document.form_moderatore_gestione_mercati.mc_num_mercati.value - numero_mercati_finestre_presenti);i++){
					if (document.getElementById('giornata_mercato_' + i).value ==0){
						alert("attenzione il campo giornata del mercato da aggiungere numero " + i + " non può essere vuoto");
						document.getElementById('giornata_mercato_' + i).focus();
						return false;
					}
					for(j = (i +1); j<=(document.form_moderatore_gestione_mercati.mc_num_mercati.value - numero_mercati_finestre_presenti);j++){
						if (parseInt(document.getElementById('giornata_mercato_' + i).value) ==
							parseInt(document.getElementById('giornata_mercato_' + j).value)){
							alert("attenzione il campo giornata del mercato da aggiungere numero " + i + " deve essere diverso del campo giornata del mercato da aggiungere numero " + j);
							document.getElementById('giornata_mercato_' + j).focus();
							return false;
						}
					}
					
					////controllo numero_cambi_i
					if(trim(document.getElementById('numero_cambi_' + i).value) ==""){
						alert("attenzione il campo numero cambi del mercato da aggiungere " + i + " non può essere vuoto");
						document.getElementById('numero_cambi_' + i).focus();
						return false;
					}
					if(!controlla_numero(document.getElementById('numero_cambi_' + i))){
						alert("attenzione il campo numero cambi del mercato da aggiungere " + i + " deve essere numerico");
						document.getElementById('numero_cambi_' + i).value="";	
						document.getElementById('numero_cambi_' + i).focus();
						return false;
					}
					if(document.getElementById('numero_cambi_' + i).value==0){
						alert("attenzione il campo numero cambi del mercato da aggiungere " + i + " deve essere maggiore di 0");
						document.getElementById('numero_cambi_' + i).value="";	
						document.getElementById('numero_cambi_' + i).focus();
						return false;
					}	
					if(parseInt(document.getElementById('numero_cambi_' + i).value) > 
						numero_giocatori){
						alert("attenzione il numero massimo di cambi è pari al numero di giocatori della rosa cioè: " + numero_giocatori);
						document.getElementById('numero_cambi_' + i).value="";	
						document.getElementById('numero_cambi_' + i).focus();
						return false;
					}
				    ////controllo crediti_aggiuntivi_i se se scelta rosa tipo gazzetta	
					if(scelta_rosa ==1){
						if(document.getElementById('crediti_aggiuntivi_' + i).value ==""){
							alert("attenzione il campo crediti aggiuntivi del mercato da aggiungere " + i + " non può essere vuoto");
							document.getElementById('crediti_aggiuntivi_' + i).focus();
							return false;
						}
						if(!controlla_numero(document.getElementById('crediti_aggiuntivi_' + i))){
							alert("attenzione il campo crediti aggiuntivi del mercato da aggiungere " + i + " deve essere numerico");
							document.getElementById('crediti_aggiuntivi_' + i).value="";	
							document.getElementById('crediti_aggiuntivi_' + i).focus();
							return false;
						}	
						if(parseInt(document.getElementById('crediti_aggiuntivi_' + i).value) < 0){
							alert("attenzione il campo crediti aggiuntivi del mercato da aggiungere " + i + " deve essere positivo");
							document.getElementById('crediti_aggiuntivi_' + i).focus();
							return false;
						}
					}
					
					//scelgo io il numero dei cambi per ruolo
					if (document.getElementById('cambi_tutti_' + i).checked == false){						
						////controllo numero_portieri_i
						if(document.getElementById('num_cambi_portiere_' + i).value ==""){
							alert("attenzione il campo numero portieri del mercato da aggiungere " + i + " non può essere vuoto");
							document.getElementById('num_cambi_portiere_' + i).focus();
							return false;
						}
						if(!controlla_numero(document.getElementById('num_cambi_portiere_' + i))){
							alert("attenzione il campo numero portieri del mercato da aggiungere " + i + " deve essere numerico");
							document.getElementById('num_cambi_portiere_' + i).value="";	
							document.getElementById('num_cambi_portiere_' + i).focus();
							return false;
						}	
						if(parseInt(document.getElementById('num_cambi_portiere_' + i).value) < 0){
							alert("attenzione il campo numero portieri del mercato da aggiungere deve essere positivo");
							document.getElementById('num_cambi_portiere_' + i).focus();
							return false;
						}
						
						////controllo num_cambi_difensori_i
						if(document.getElementById('num_cambi_difensori_' + i).value ==""){
							alert("attenzione il campo numero difensori del mercato da aggiungere " + i + " non può essere vuoto");
							document.getElementById('num_cambi_difensori_' + i).focus();
							return false;
						}
						if(!controlla_numero(document.getElementById('num_cambi_difensori_' + i))){
							alert("attenzione il campo numero difensori del mercato da aggiungere " + i + " deve essere numerico");
							document.getElementById('num_cambi_difensori_' + i).value="";	
							document.getElementById('num_cambi_difensori_' + i).focus();
							return false;
						}	
						if(parseInt(document.getElementById('num_cambi_difensori_' + i).value) < 0){
							alert("attenzione il campo numero difensori del mercato da aggiungere deve essere positivo");
							document.getElementById('num_cambi_difensori_' + i).focus();
							return false;
						}
						
						////controllo num_cambi_centrocampisti_i
						if(document.getElementById('num_cambi_centrocampisti_' + i).value ==""){
							alert("attenzione il campo numero centrocampisti del mercato da aggiungere " + i + " non può essere vuoto");
							document.getElementById('num_cambi_centrocampisti_' + i).focus();
							return false;
						}
						if(!controlla_numero(document.getElementById('num_cambi_centrocampisti_' + i))){
							alert("attenzione il campo numero centrocampisti del mercato da aggiungere " + i + " deve essere numerico");
							document.getElementById('num_cambi_centrocampisti_' + i).value="";	
							document.getElementById('num_cambi_centrocampisti_' + i).focus();
							return false;
						}	
						if(parseInt(document.getElementById('num_cambi_centrocampisti_' + i).value) < 0){
							alert("attenzione il campo numero centrocampisti del mercato da aggiungere " + i + " deve essere positivo");
							document.getElementById('num_cambi_centrocampisti_' + i).focus();
							return false;
						}
						
						////controllo num_cambi_attaccanti_i
						if(document.getElementById('num_cambi_attaccanti_' + i).value ==""){
							alert("attenzione il campo numero attaccanti del mercato da aggiungere " + i + " non può essere vuoto");
							document.getElementById('num_cambi_attaccanti_' + i).focus();
							return false;
						}
						if(!controlla_numero(document.getElementById('num_cambi_attaccanti_' + i))){
							alert("attenzione il campo numero attaccanti del mercato da aggiungere " + i + " deve essere numerico");
							document.getElementById('num_cambi_attaccanti_' + i).value="";	
							document.getElementById('num_cambi_attaccanti_' + i).focus();
							return false;
						}
						if(parseInt(document.getElementById('num_cambi_attaccanti_' + i).value) < 0){
							alert("attenzione il campo numero attaccanti del mercato da aggiungere " + i + " deve essere positivo");
							document.getElementById('num_cambi_attaccanti_' + i).focus();
							return false;
						}

						
						if (parseInt(document.getElementById('numero_cambi_' + i).value) !=(
							parseInt(document.getElementById('num_cambi_portiere_' + i).value) + 
							parseInt(document.getElementById('num_cambi_difensori_' + i).value) + 
							parseInt(document.getElementById('num_cambi_centrocampisti_' + i).value) + 
							parseInt(document.getElementById('num_cambi_attaccanti_' + i).value))){
							
							alert("attenzione il NUMERO TOTALE dei cambi del mercato da aggiungere " + i + " deve essere uguale alla SOMMA dei cambi per ogni ruolo");
							return false;
						}
									
					}// fine scelgo io il numero dei cambi per ruolo
								
				}//fine for	

				//controlli per i mercati a finestre da modificare o cancellare
				for(i = 1; i<=numero_mercati_finestre_presenti;i++){
					if (document.getElementById('giornata_mercato_presente_' + i).value ==0){
						alert("attenzione il campo giornata del mercato presente numero " + i + " non può essere vuoto");
						document.getElementById('giornata_mercato_presente_' + i).focus();
						return false;
					}
					for(j = (i +1); j<=(numero_mercati_finestre_presenti);j++){
						if (parseInt(document.getElementById('giornata_mercato_presente_' + i).value) ==
							parseInt(document.getElementById('giornata_mercato_presente_' + j).value)){
							alert("attenzione il campo giornata del mercato presente numero " + i + " deve essere diverso del campo giornata del mercato presente numero " + j);
							document.getElementById('giornata_mercato_presente_' + j).focus();
							return false;
						}
					}
					
					////controlli incrociati con le giornate di mercato da inserire se presenti
					////non deve essere presente la stessa giornata in nessun mercato
					if ((document.form_moderatore_gestione_mercati.mc_num_mercati.value - numero_mercati_finestre_presenti) > 0){
						for(k = 1; k<=(document.form_moderatore_gestione_mercati.mc_num_mercati.value - numero_mercati_finestre_presenti);k++){
							if (parseInt(document.getElementById('giornata_mercato_presente_' + i).value) ==
								parseInt(document.getElementById('giornata_mercato_' + k).value)){
								alert("attenzione il campo giornata del mercato da aggiungere numero " + k + " già esiste nel mercato presente numero " + i);
								document.getElementById('giornata_mercato_' + k).focus();
								return false;
							}
						}											
					}
					
					////controllo numero_cambi_i
					if(trim(document.getElementById('numero_cambi_presente_' + i).value) ==""){
						alert("attenzione il campo numero cambi del mercato presente " + i + " non può essere vuoto");
						document.getElementById('numero_cambi_presente_' + i).focus();
						return false;
					}
					if(!controlla_numero(document.getElementById('numero_cambi_presente_' + i))){
						alert("attenzione il campo numero cambi del mercato presente " + i + " deve essere numerico");
						document.getElementById('numero_cambi_presente_' + i).value="";	
						document.getElementById('numero_cambi_presente_' + i).focus();
						return false;
					}
					if(document.getElementById('numero_cambi_presente_' + i).value==0){
						alert("attenzione il campo numero cambi del mercato presente " + i + " deve essere maggiore di 0");
						document.getElementById('numero_cambi_presente_' + i).value="";	
						document.getElementById('numero_cambi_presente_' + i).focus();
						return false;
					}	
					if(parseInt(document.getElementById('numero_cambi_presente_' + i).value) > 
						numero_giocatori){
						alert("attenzione il numero massimo di cambi è pari al numero di giocatori della rosa cioè: " + numero_giocatori);
						document.getElementById('numero_cambi_presente_' + i).value="";	
						document.getElementById('numero_cambi_presente_' + i).focus();
						return false;
					}
				    ////controllo crediti_aggiuntivi_i se scelta rosa tipo gazzetta	
					if(scelta_rosa ==1){
						if(document.getElementById('crediti_aggiuntivi_presente_' + i).value ==""){
							alert("attenzione il campo crediti aggiuntivi del mercato presente " + i + " non può essere vuoto");
							document.getElementById('crediti_aggiuntivi_presente_' + i).focus();
							return false;
						}
						if(!controlla_numero(document.getElementById('crediti_aggiuntivi_presente_' + i))){
							alert("attenzione il campo crediti aggiuntivi del mercato da presente " + i + " deve essere numerico");
							document.getElementById('crediti_aggiuntivi_presente_' + i).value="";	
							document.getElementById('crediti_aggiuntivi_presente_' + i).focus();
							return false;
						}	
						if(parseInt(document.getElementById('crediti_aggiuntivi_presente_' + i).value) < 0){
							alert("attenzione il campo crediti aggiuntivi del mercato presente " + i + " deve essere positivo");
							document.getElementById('crediti_aggiuntivi_presente_' + i).focus();
							return false;
						}
					}
					
					//scelgo io il numero dei cambi per ruolo
					if (document.getElementById('mercato_finestre_presenti_mod_' + i).value ==1){
						if (document.getElementById('cambi_tutti_presente_' + i).checked == false){
						////controllo numero_portieri_i
							if(document.getElementById('num_cambi_portiere_presente_' + i).value ==""){
								alert("attenzione il campo numero portieri del mercato presente " + i + " non può essere vuoto");
								document.getElementById('num_cambi_portiere_presente_' + i).focus();
								return false;
							}
							if(!controlla_numero(document.getElementById('num_cambi_portiere_presente_' + i))){
								alert("attenzione il campo numero portieri del mercato presente " + i + " deve essere numerico");
								document.getElementById('num_cambi_portiere_presente_' + i).value="";	
								document.getElementById('num_cambi_portiere_presente_' + i).focus();
								return false;
							}	
							if(parseInt(document.getElementById('num_cambi_portiere_presente_' + i).value) < 0){
								alert("attenzione il campo numero portieri del mercato presente deve essere positivo");
								document.getElementById('num_cambi_portiere_presente_' + i).focus();
								return false;
							}
						
							////controllo num_cambi_difensori_i
							if(document.getElementById('num_cambi_difensori_presente_' + i).value ==""){
								alert("attenzione il campo numero difensori del mercato presente " + i + " non può essere vuoto");
								document.getElementById('num_cambi_difensori_presente_' + i).focus();
								return false;
							}
							if(!controlla_numero(document.getElementById('num_cambi_difensori_presente_' + i))){
								alert("attenzione il campo numero difensori del mercato presente " + i + " deve essere numerico");
								document.getElementById('num_cambi_difensori_presente_' + i).value="";	
								document.getElementById('num_cambi_difensori_presente_' + i).focus();
								return false;
							}	
							if(parseInt(document.getElementById('num_cambi_difensori_presente_' + i).value) < 0){
								alert("attenzione il campo numero difensori del mercato presente deve essere positivo");
								document.getElementById('num_cambi_difensori_presente_' + i).focus();
								return false;
							}						
							////controllo num_cambi_centrocampisti_i
							if(document.getElementById('num_cambi_centrocampisti_presente_' + i).value ==""){
								alert("attenzione il campo numero centrocampisti del mercato presente " + i + " non può essere vuoto");
								document.getElementById('num_cambi_centrocampisti_presente_' + i).focus();
								return false;
							}
							if(!controlla_numero(document.getElementById('num_cambi_centrocampisti_presente_' + i))){
								alert("attenzione il campo numero centrocampisti del mercato presente " + i + " deve essere numerico");
								document.getElementById('num_cambi_centrocampisti_presente_' + i).value="";	
								document.getElementById('num_cambi_centrocampisti_presente_' + i).focus();
								return false;
							}	
							if(parseInt(document.getElementById('num_cambi_centrocampisti_presente_' + i).value) < 0){
								alert("attenzione il campo numero centrocampisti del mercato presente " + i + " deve essere positivo");
								document.getElementById('num_cambi_centrocampisti_presente_' + i).focus();
								return false;
							}
						
							////controllo num_cambi_attaccanti_i
							if(document.getElementById('num_cambi_attaccanti_presente_' + i).value ==""){
								alert("attenzione il campo numero attaccanti del mercato presente " + i + " non può essere vuoto");
								document.getElementById('num_cambi_attaccanti_presente_' + i).focus();
								return false;
							}
							if(!controlla_numero(document.getElementById('num_cambi_attaccanti_presente_' + i))){
								alert("attenzione il campo numero attaccanti del mercato presente " + i + " deve essere numerico");
								document.getElementById('num_cambi_attaccanti_presente_' + i).value="";	
								document.getElementById('num_cambi_attaccanti_presente_' + i).focus();
								return false;
							}
							if(parseInt(document.getElementById('num_cambi_attaccanti_presente_' + i).value) < 0){
								alert("attenzione il campo numero attaccanti del mercato presente " + i + " deve essere positivo");
								document.getElementById('num_cambi_attaccanti_presente_' + i).focus();
								return false;
							}

						
							if (parseInt(document.getElementById('numero_cambi_presente_' + i).value) !=(
								parseInt(document.getElementById('num_cambi_portiere_presente_' + i).value) + 
								parseInt(document.getElementById('num_cambi_difensori_presente_' + i).value) + 
								parseInt(document.getElementById('num_cambi_centrocampisti_presente_' + i).value) + 
								parseInt(document.getElementById('num_cambi_attaccanti_presente_' + i).value))){
							
								alert("attenzione il NUMERO TOTALE dei cambi del mercato presente " + i + " deve essere uguale alla SOMMA dei cambi per ogni ruolo");
								return false;
							}
									
						}// fine scelgo io il numero dei cambi per ruolo
					}			
				}//fine for	
				
			}//numero mercati !=0
					
		}//fine ho scelto il mercato a giornate fisse	
    }

}


function tutti_ruoli(blocco_i){
	if (document.getElementById('cambi_tutti_' + blocco_i).checked != true){
		document.getElementById('p_portiere_'+ blocco_i).style.display = 'block';	
		document.getElementById('p_difensori_'+ blocco_i).style.display = 'block';	
		document.getElementById('p_centrocampisti_'+ blocco_i).style.display = 'block';	
		document.getElementById('p_attaccanti_'+ blocco_i).style.display = 'block';	
	}else{
		document.getElementById('p_portiere_'+ blocco_i).style.display = 'none';	
		document.getElementById('p_difensori_'+ blocco_i).style.display = 'none';	
		document.getElementById('p_centrocampisti_'+ blocco_i).style.display = 'none';	
		document.getElementById('p_attaccanti_'+ blocco_i).style.display = 'none';	
	}

}

function tutti_ruoli_presente(blocco_i){
	if (document.getElementById('cambi_tutti_presente_' + blocco_i).checked != true){
		document.getElementById('p_portiere_presente_'+ blocco_i).style.display = 'block';	
		document.getElementById('p_difensori_presente_'+ blocco_i).style.display = 'block';	
		document.getElementById('p_centrocampisti_presente_'+ blocco_i).style.display = 'block';	
		document.getElementById('p_attaccanti_presente_'+ blocco_i).style.display = 'block';	
	}else{
		document.getElementById('p_portiere_presente_'+ blocco_i).style.display = 'none';	
		document.getElementById('p_difensori_presente_'+ blocco_i).style.display = 'none';	
		document.getElementById('p_centrocampisti_presente_'+ blocco_i).style.display = 'none';	
		document.getElementById('p_attaccanti_presente_'+ blocco_i).style.display = 'none';	
	}

}

function abi_dis_ma(){
	document.form_moderatore_gestione_mercati.submit();
}

function moderatore_scegli_tipo_mercato(){
	document.form_moderatore_gestione_mercati.submit();	
}

function moderatore_ab_dis_mercato(){
	document.form_moderatore_gestione_mercati.submit();	
}

function controlla_modera_ges_lega(nome_torneo_old,giornata_iniziale_old,giornata_finale_old,
          giornata_finale_iscrizioni_old ,giornata_finale_rosa_old,modalita_old,punti_squadra_casa_old,
		scelta_rosa_old,crediti_iniziali_old,password_torneo_old,modificatore_difesa_old){
		
	if (trim(document.form_moderatore_gestione_lega.nome_torneo.value) == nome_torneo_old && 
	    trim(document.form_moderatore_gestione_lega.giornata_iniziale.value) == giornata_iniziale_old && 
		trim(document.form_moderatore_gestione_lega.giornata_finale.value) == giornata_finale_old && 
		trim(document.form_moderatore_gestione_lega.giornata_finale_iscrizioni.value) == giornata_finale_iscrizioni_old && 
		trim(document.form_moderatore_gestione_lega.giornata_finale_rosa.value) == giornata_finale_rosa_old && 
	    trim(document.form_moderatore_gestione_lega.modalita.value) == modalita_old && 
		trim(document.form_moderatore_gestione_lega.punti_squadra_casa.value) == punti_squadra_casa_old && 
		trim(document.form_moderatore_gestione_lega.scelta_rosa.value) == scelta_rosa_old && 
		trim(document.form_moderatore_gestione_lega.crediti_iniziali.value) == crediti_iniziali_old && 
	    trim(document.form_moderatore_gestione_lega.password_torneo.value) == password_torneo_old && 
		trim(document.form_moderatore_gestione_lega.modificatore_difesa.value) == modificatore_difesa_old){
		
		alert("attenzione non hai modificato nessun campo");		
		return false;	    
	}

	if (parseInt(document.form_moderatore_gestione_lega.giornata_finale.value) < 
		parseInt(document.form_moderatore_gestione_lega.giornata_iniziale.value) ){
		alert ("Attenzione la giornata di fine lega è minore della giornata di inizio lega");
		return false;
	}
	
	if ((parseInt(document.form_moderatore_gestione_lega.giornata_finale.value) - 
		parseInt(document.form_moderatore_gestione_lega.giornata_iniziale.value) + 1) <
		2){
		alert ("Attenzione una lega deve durare minimo 2 giornate");
		return false;
	}

	if (parseInt(document.form_moderatore_gestione_lega.giornata_finale_iscrizioni.value) > 
		parseInt(document.form_moderatore_gestione_lega.giornata_finale_rosa.value) ){
		alert ("Attenzione la giornata finale di inserimento rosa non deve essere minore della giornata finale delle iscrizioni");
		return false;
	}


	
	if ((parseInt(document.form_moderatore_gestione_lega.giornata_finale_iscrizioni.value)  
		< parseInt(document.form_moderatore_gestione_lega.giornata_iniziale.value))
		||(parseInt(document.form_moderatore_gestione_lega.giornata_finale_iscrizioni.value)  
		> parseInt(document.form_moderatore_gestione_lega.giornata_finale.value))){
		alert ("Attenzione la giornata finale delle iscrizioni deve essere compresa tra la giornata iniziale e finale");
		return false;
	}
	
	if ((parseInt(document.form_moderatore_gestione_lega.giornata_finale_rosa.value)  
		< parseInt(document.form_moderatore_gestione_lega.giornata_iniziale.value))
		||(parseInt(document.form_moderatore_gestione_lega.giornata_finale_rosa.value)  
		> parseInt(document.form_moderatore_gestione_lega.giornata_finale.value))){
		alert ("Attenzione la giornata finale di inserimento rosa deve essere compresa tra la giornata iniziale e finale");
		return false;
	}

	
	////controllo i crediti solo se la scelta rosa è Compravendita stesso giocatore
	if(document.form_moderatore_gestione_lega.scelta_rosa.value ==1){
		if(trim(document.form_moderatore_gestione_lega.crediti_iniziali.value) ==""){
			alert("attenzione il campo crediti iniziali non può essere vuoto");			
			return false;
		}
		if(!controlla_numero(document.form_moderatore_gestione_lega.crediti_iniziali)){
			alert("attenzione il campo crediti iniziali deve essere numerico");					
			return false;
		}	
		if(parseInt(document.form_moderatore_gestione_lega.crediti_iniziali.value) < 0){
			alert("attenzione il campo crediti iniziali deve essere positivo");			
			return false;
		}
    }
	//controllo il nome della lega
    if(trim(document.form_moderatore_gestione_lega.nome_torneo.value) ==""){
		alert("attenzione il campo nome lega non può essere vuoto");			
		return false;
	}
	
	if(!controlla_valori_permessi(document.form_moderatore_gestione_lega.nome_torneo,0)){
		alert("attenzione il campo nome lega contiene un carattere non consentito");		
		return false;
	}
    
	//controllo la password di lega
    if(trim(document.form_moderatore_gestione_lega.password_torneo.value) ==""){
		alert("attenzione il campo password lega non può essere vuoto");			
		return false;
	}
	
	if(document.form_moderatore_gestione_lega.password_torneo.value.length < 10){
		alert("attenzione la password di lega deve avere almeno lunghezza 10");		
		return false;
	}	
	
	if(!controlla_valori_permessi(document.form_moderatore_gestione_lega.password_torneo,1)){
		alert("attenzione il campo password lega contiene un carattere non consentito");		
		return false;
	}

	
	
}

function moderatore_cambia_giornata_iniziale(){
	document.form_moderatore_gestione_lega.giornata_finale_iscrizioni.value = 
		document.form_moderatore_gestione_lega.giornata_iniziale.value;
	document.form_moderatore_gestione_lega.giornata_finale_rosa.value = 
		document.form_moderatore_gestione_lega.giornata_iniziale.value;
	document.form_moderatore_gestione_lega.submit();	
}

function moderatore_ab_disab_punti_casa(){
	if (document.form_moderatore_gestione_lega.modalita.value == 1){
		document.getElementById('p_punti_casa_scontri_diretti').style.display = 'none';
	}else{	
		document.getElementById('p_punti_casa_scontri_diretti').style.display = 'block';			
	}
	
}

function moderatore_ab_disab_crediti_iniziali(){	
	if (document.form_moderatore_gestione_lega.scelta_rosa.value == 2){
		document.getElementById('p_crediti_iniziali').style.display = 'none';
	}else{	
		document.getElementById('p_crediti_iniziali').style.display = 'block';			
	}
	
}

function moderatore_dis_ab_partecipante(){
	if(document.form_moderatore_gestione_partecipanti.abilitazione_giocatore_prima.value == document.form_moderatore_gestione_partecipanti.abilitazione_giocatore_dopo.value){
		alert("attenzione non hai modificato nessun campo");		
		return false;
	}
	if (document.form_moderatore_gestione_partecipanti.abilitazione_giocatore_dopo.value =='N' && !confirm("ATTENZIONE!!!!!!\nSei sicuro di voler disabilitare un tuo partecipante")){
			return false;
	}
	return true;
}
function controlla_elenco_iniziali(){
	
	if (document.form_moderatore_gestione_partecipanti.elenco_iniziali.value ==''){
		document.form_moderatore_gestione_partecipanti.elenco_squadre.value = '';
	}
	document.form_moderatore_gestione_partecipanti.submit();	

}

function controlla_elenco_squadre(){
	document.form_moderatore_gestione_partecipanti.submit();	
}

function conferma_ins_calendario_moderatore(){	
	if (!confirm("ATTENZIONE!!!!!!\nSei sicuro di voler generare il calendario? \nIl calendario potrà essere generato una sola volta")){
			return false;
	}
	
	return true;
}


function controlla_file_ges_tornei(){

	if (document.form_gestione_tornei.elenco_file.value ==''){
		document.form_gestione_tornei.elenco_tornei.value = '';
	}
	document.form_gestione_tornei.submit();	

}

function controlla_tornei_ges_tornei(){
	
	document.form_gestione_tornei.submit();	

}

function controlla_admin_ges_squadre(nome_squadra_old, nome_partecipante_old, e_mail_old, 
user_old, password_old, abilitazione_old)
{
    if (trim(document.form_gestione_squadra_2.nome_squadra.value) == nome_squadra_old && 
	    trim(document.form_gestione_squadra_2.nome_partecipante.value) == nome_partecipante_old && 
		trim(document.form_gestione_squadra_2.e_mail.value) == e_mail_old && 
		trim(document.form_gestione_squadra_2.user.value) == user_old && 
		trim(document.form_gestione_squadra_2.password.value) == password_old && 
		trim(document.form_gestione_squadra_2.abilitazione.value) == abilitazione_old){
		
		alert("attenzione non hai modificato nessun campo");		
		return false;	    
	}
	var i = 0;
	var numero = 0;
	var nomi = new Array(5);
	
	nomi[0] = "nome squadra";
	nomi[1] = "nome o nickname";
	nomi[2] = "e-mail";
	nomi[3] = "user";
	nomi[4] = "password";

	numero = 5;
	for(i = 0;i < numero;i++ ){
		if(!controlla_campo_vuoto(document.form_gestione_squadra_2.elements[i])){
			alert("attenzione il campo " + nomi[i] + " è vuoto");	
			//document.form_gestione_squadra_2.elements[i].focus();
			return false;
		}
	}	
	
	//non permetto di inserire valori non consentiti
	for(i = 0;i < numero;i++ ){
		if (i == 0 || i == 1 ){
			if(!controlla_valori_permessi(document.form_gestione_squadra_2.elements[i],0)){
				alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");					
				//document.form_gestione_squadra_2.elements[i].focus();
				return false;
			}

		}else if (i == 3 || i==4) {
			if(!controlla_valori_permessi(document.form_gestione_squadra_2.elements[i],1)){
				alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");		
				//document.form_gestione_squadra_2.elements[i].focus();
				return false;
			}
			
		}else if (i == 2) {
			if(!controlla_valori_permessi(document.form_gestione_squadra_2.elements[i],2)){
				alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");		
				//document.form_gestione_squadra_2.elements[i].focus();
				return false;
			}
		}
	}
	
	//la password e la user devono avere lunghezza almeno 6

	if(document.form_gestione_squadra_2.elements[3].value.length < 6){

		alert("attenzione il campo " + nomi[3] + " deve essere di lunghezza almeno 6");			
		//document.form_gestione_squadra_2.elements[3].focus();
		return false;

	}
	
	if(document.form_gestione_squadra_2.elements[4].value.length < 6){

		alert("attenzione il campo " + nomi[4] + " deve essere di lunghezza almeno 6");			
		//document.form_gestione_squadra_2.elements[4].focus();
		return false;

	}		
			
	//controllo che il campo e-mail contenga un @ e almeno un punto
	if(!controlla_e_mail(document.form_gestione_squadra_2.elements[2])){	
		alert("attenzione il campo " + nomi[2] + " deve contenere una @ e almeno un punto");		
		//document.form_gestione_squadra_2.elements[2].focus();
		return false;
	}
	
}

function controlla_ges_gestione_utente(nome_squadra_old, user_old, password_old,
e_mail_old,nome_partecipante_old,squadre_stesso_id_univoco)
{
    if (trim(document.form_ges_gestione_utente.nome_squadra.value) == nome_squadra_old && 
	    trim(document.form_ges_gestione_utente.nome_partecipante.value) == nome_partecipante_old && 
		trim(document.form_ges_gestione_utente.e_mail.value) == e_mail_old && 
		trim(document.form_ges_gestione_utente.ges_user.value) == user_old && 
		trim(document.form_ges_gestione_utente.ges_password.value) == password_old){
		
		alert("attenzione non hai modificato nessun campo");		
		return false;	    
	}
	var i = 0;
	var numero = 0;
	var nomi = new Array(5);
	
	nomi[0] = "nome squadra";      
	nomi[1] = "user";  
	nomi[2] = "password";            
	nomi[3] = "e-mail";              
	nomi[4] = "nome o nickname";

	numero = 5;
	for(i = 0;i < numero;i++ ){
		if(!controlla_campo_vuoto(document.form_ges_gestione_utente.elements[i])){
			alert("attenzione il campo " + nomi[i] + " è vuoto");	
			return false;
		}
	}	
	
	//non permetto di inserire valori non consentiti
	for(i = 0;i < numero;i++ ){
		if (i == 0 || i == 4 ){
			if(!controlla_valori_permessi(document.form_ges_gestione_utente.elements[i],0)){
				alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");					
				return false;
			}

		}else if (i == 1 || i==2) {
			if(!controlla_valori_permessi(document.form_ges_gestione_utente.elements[i],1)){
				alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");		
				return false;
			}
			
		}else if (i == 3) {
			if(!controlla_valori_permessi(document.form_ges_gestione_utente.elements[i],2)){
				alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");		
				return false;
			}
		}
	}
	
	//la password e la user devono avere lunghezza almeno 6

	if(document.form_ges_gestione_utente.elements[1].value.length < 6){
		alert("attenzione il campo " + nomi[1] + " deve essere di lunghezza almeno 6");			
		return false;

	}
	
	if(document.form_ges_gestione_utente.elements[2].value.length < 6){
		alert("attenzione il campo " + nomi[2] + " deve essere di lunghezza almeno 6");			
		return false;
	}		
			
	//controllo che il campo e-mail contenga un @ e almeno un punto
	if(!controlla_e_mail(document.form_ges_gestione_utente.elements[3])){	
		alert("attenzione il campo " + nomi[3] + " deve contenere una @ e almeno un punto");		
		return false;
	}
	if (squadre_stesso_id_univoco > 0 && (trim(document.form_ges_gestione_utente.ges_user.value) != user_old ||
		trim(document.form_ges_gestione_utente.ges_password.value) != password_old)){
		if (!confirm("ATTENZIONE!!!!!!\nIl cambio di user e/o di password verrà applicato a tutte le squadre da te gestite")){
			return false;
		}
	}
}

function controlla_moderatore_gestione_utente(user_old, password_old,
e_mail_old,nome_partecipante_old,squadre_stesso_id_univoco)
{
	if (trim(document.form_ges_gestione_utente.nome_partecipante.value) == nome_partecipante_old && 
		trim(document.form_ges_gestione_utente.e_mail.value) == e_mail_old && 
		trim(document.form_ges_gestione_utente.ges_user.value) == user_old && 
		trim(document.form_ges_gestione_utente.ges_password.value) == password_old){
		
		alert("attenzione non hai modificato nessun campo");		
		return false;	    
	}
	var i = 0;
	var numero = 0;
	var nomi = new Array(4);
	
	nomi[0] = "user";  
	nomi[1] = "password";            
	nomi[2] = "e-mail";              
	nomi[3] = "nome o nickname";

	numero = 4;
	for(i = 0;i < numero;i++ ){
		if(!controlla_campo_vuoto(document.form_ges_gestione_utente.elements[i])){
			alert("attenzione il campo " + nomi[i] + " è vuoto");	
			return false;
		}
	}	
	
	//non permetto di inserire valori non consentiti
	for(i = 0;i < numero;i++ ){
		if (i == 3 ){
			if(!controlla_valori_permessi(document.form_ges_gestione_utente.elements[i],0)){
				alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");					
				return false;
			}

		}else if (i == 0 || i==1) {
			if(!controlla_valori_permessi(document.form_ges_gestione_utente.elements[i],1)){
				alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");		
				return false;
			}
			
		}else if (i == 2) {
			if(!controlla_valori_permessi(document.form_ges_gestione_utente.elements[i],2)){
				alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");		
				return false;
			}
		}
	}
	
	//la password e la user devono avere lunghezza almeno 6

	if(document.form_ges_gestione_utente.elements[0].value.length < 6){
		alert("attenzione il campo " + nomi[0] + " deve essere di lunghezza almeno 6");			
		return false;

	}
	
	if(document.form_ges_gestione_utente.elements[1].value.length < 6){
		alert("attenzione il campo " + nomi[1] + " deve essere di lunghezza almeno 6");			
		return false;
	}		
			
	//controllo che il campo e-mail contenga un @ e almeno un punto
	if(!controlla_e_mail(document.form_ges_gestione_utente.elements[2])){	
		alert("attenzione il campo " + nomi[2] + " deve contenere una @ e almeno un punto");		
		return false;
	}
	if (squadre_stesso_id_univoco > 0 && (trim(document.form_ges_gestione_utente.ges_user.value) != user_old ||
		trim(document.form_ges_gestione_utente.ges_password.value) != password_old)){
		if (!confirm("ATTENZIONE!!!!!!\nIl cambio di user e/o di password verrà applicato a tutte le leghe da te gestite")){
			return false;
		}
	}
}



function controlla_file_ges_squadre(){

	if (document.form_gestione_squadra.elenco_file.value ==''){
		document.form_gestione_squadra.elenco_tornei.value = '';
	}
	document.form_gestione_squadra.submit();	

}

function controlla_tornei_ges_squadre(){
	
	if (document.form_gestione_squadra.elenco_tornei.value ==''){
		document.form_gestione_squadra.elenco_squadre.value = '';
	}
	document.form_gestione_squadra.submit();	

}

function controlla_squadre_ges_squadre(){
	document.form_gestione_squadra.submit();	
}


function Conferma_mercato(tipo_mercato){
	if (tipo_mercato == 1){
		if (!confirm("ATTENZIONE!!!!!!\nSei sicuro di voler salvare il tuo mercato? \nNon potrai più tornare indietro inoltre il tuo mercato in questa giornata sarà finito \nRicordati che devi fare tutti i cambi a tua disposizione in una sola volta.")){
			return false;
		}
	}else{
		if (!confirm("ATTENZIONE!!!!!!\nSei sicuro di voler salvare il tuo mercato?")){
			return false;
		}
	}
	return true;
}

function ControllaCompra_r_m(){
	if(parseInt(document.finestra_mercato.riga_colorata_destra.value) == -1){
		alert("Attenzione devi selezionare a DESTRA il giocatore da comprare");
		return false;
	}
	return true;
}

function ControllaVendi_r_m(){
	if(parseInt(document.finestra_mercato.riga_colorata_sinistra.value) == -1){
		alert("Attenzione devi selezionare a SINISTRA il giocatore da vendere");
		return false;
	}
	return true;
}


function ColoraRigaSinistra(i){
	document.getElementById('giocatori_sinistra_' + i).className ='riga_colorata';	
	if(parseInt(document.finestra_mercato.riga_colorata_sinistra.value) != -1){
		document.getElementById('giocatori_sinistra_' + parseInt(document.finestra_mercato.riga_colorata_sinistra.value)).className ='riga_noncolorata';
	}
	if(parseInt(document.finestra_mercato.riga_colorata_destra.value) != -1){
		document.getElementById('giocatori_destra_' + parseInt(document.finestra_mercato.riga_colorata_destra.value)).className ='riga_noncolorata';
		document.finestra_mercato.riga_colorata_destra.value = -1;
	}
	document.finestra_mercato.riga_colorata_sinistra.value = i;
	document.finestra_mercato.post_venduto.value = document.getElementById('pre_post_venduto_' + i).value;
	
}

function ColoraRigaDestra(i){
	document.getElementById('giocatori_destra_' + i).className ='riga_colorata';	
	
	if(parseInt(document.finestra_mercato.riga_colorata_sinistra.value) != -1){
		document.getElementById('giocatori_sinistra_' + parseInt(document.finestra_mercato.riga_colorata_sinistra.value)).className ='riga_noncolorata';
		document.finestra_mercato.riga_colorata_sinistra.value = -1;
	}
	if(parseInt(document.finestra_mercato.riga_colorata_destra.value) != -1){
		document.getElementById('giocatori_destra_' + parseInt(document.finestra_mercato.riga_colorata_destra.value)).className ='riga_noncolorata';
	}
	document.finestra_mercato.riga_colorata_destra.value = i;
	document.finestra_mercato.post_comprato.value = document.getElementById('riga_destra_' + i).value.substr(4,3);
}
function cambia_ruolo(numero_giocatori){
	document.finestra_mercato.submit();
}

function Diventa_invisibile(numero_giocatori){
	var i= 0;
	
	for(i = 0;i < numero_giocatori;i++ ){
		if(document.finestra_mercato.club.value == 'TUT' && parseInt(document.finestra_mercato.crediti.value) == 6 ){
			document.getElementById("giocatori_destra_" + i).style.display = "";
		}else if (document.finestra_mercato.club.value != 'TUT' && parseInt(document.finestra_mercato.crediti.value) == 6){
			if(document.getElementById('riga_destra_' + i).value.substr(0,3) != document.finestra_mercato.club.value){
				document.getElementById("giocatori_destra_" + i).style.display = "none";
			}else{
				document.getElementById("giocatori_destra_" + i).style.display = "";
			}	
		}else if (document.finestra_mercato.club.value == 'TUT' && parseInt(document.finestra_mercato.crediti.value) != 6){			
			if(document.getElementById('riga_destra_' + i).value.substr(3,1) != parseInt(document.finestra_mercato.crediti.value)){
				document.getElementById("giocatori_destra_" + i).style.display = "none";
			}else{
				document.getElementById("giocatori_destra_" + i).style.display = "";
			}
		}else{
			if(document.getElementById('riga_destra_' + i).value.substr(0,3) != document.finestra_mercato.club.value ||
					document.getElementById('riga_destra_' + i).value.substr(3,1) != parseInt(document.finestra_mercato.crediti.value)){				
				document.getElementById("giocatori_destra_" + i).style.display = "none";	
			}else{
				document.getElementById("giocatori_destra_" + i).style.display = "";
			}		
		} 
	}


}

function controlla_login (){
	var nomi = new Array(2);
	nomi[0] = "user";
	nomi[1] = "password";
	var i= 0;
	for(i = 0;i < 2;i++ ){
		if(!controlla_campo_vuoto(document.form_login.elements[i])){
			alert("attenzione il campo " + document.form_login.elements[i].name + " è vuoto");	
			return false;
		}
	}		
	// non permetto di inserire valori non consentiti
	for(i = 0;i < 2;i++ ){
		if(!controlla_valori_permessi(document.form_login.elements[i],1)){
			alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");		
			document.form_login.elements[i].value = "";
			document.form_login.elements[i].focus();
			return false;
		}
	}		
	//user e password devono avere lunghezza almeno 6
	for(i = 0;i < 2;i++ ){
		if(document.form_login.elements[i].value.length < 6){
			alert("attenzione il campo " + nomi[i] + " deve avere almeno lunghezza 6");		
			document.form_login.elements[i].value = "";
			return false;
		}
	}
}




function controlla_hai_dimenticato (opposta){
	
	var nomi = new Array(3);
	nomi[0] = opposta;
	nomi[1] = "identificativo";
	nomi[2] = "e-mail";
	var i= 0;



	for(i = 0;i < 3;i++ ){
		if(!controlla_campo_vuoto(document.form_hai_dimenticato.elements[i])){
			alert("attenzione il campo " + nomi[i] + " è vuoto");	
			return false;
		}
	}

	// non permetto di inserire valori non consentiti

	for(i = 0;i < 2;i++ ){
		if(!controlla_valori_permessi(document.form_hai_dimenticato.elements[i],1)){
			alert("attenzione il campo " + nomi[i] + " contiene un carattere non consentito");		
			document.form_hai_dimenticato.elements[i].value = "";
			document.form_hai_dimenticato.elements[i].focus();
			return false;
		}
	}
	if(!controlla_valori_permessi(document.form_hai_dimenticato.elements[2],2)){
			alert("attenzione il campo " + nomi[2] + " contiene un carattere non consentito");		
			document.form_hai_dimenticato.elements[2].value = "";
			document.form_hai_dimenticato.elements[2].focus();
			return false;
	}
	
	//user o password devono avere lunghezza almeno 6


	if(document.form_hai_dimenticato.elements[0].value.length < 6){

		alert("attenzione il campo " + nomi[0] + " deve avere almeno lunghezza 6");		

		document.form_hai_dimenticato.elements[0].value = "";

		return false;

	}
	//l'identificativo deve avere lunghezza 10
	
	if(document.form_hai_dimenticato.elements[1].value.length != 10){

		alert("attenzione il campo " + nomi[1] + " deve avere lunghezza 10");		

		document.form_hai_dimenticato.elements[1].value = "";

		return false;

	}
	
	//controllo che il campo e-mail contenga un @ e almeno un punto
	if(!controlla_e_mail(document.form_hai_dimenticato.elements[2])){

		alert("attenzione il campo " + nomi[2] + " deve contenere una @ e almeno un punto");		

		document.form_hai_dimenticato.elements[2].focus();

		return false;

	}

}

function contr_ins_formazione(giocatori_totali){

	var i= 0;
	var j =0;
	var titolare;
	var riserva_tribuna;
	var pos_tit;
	var pos_ris_trib; 
	var ruolo_tit; 
	var ruolo_ris_trib;
	var numero= 0;
	var conta_dif = 0;
	var conta_centr = 0;
	var conta_att = 0;
	var trovato = false;

		

	for(i=0;i<11;i++){
		if(document.getElementsByName("titolare")[i].checked){
			trovato = true;
			break;
		}
	}

	

	if(!trovato){
		alert("Attenzione devi selezionare il titolare");
		return false;
	}

	trovato = false;	

	for(i=0;i<(giocatori_totali -11);i++){
		if(document.getElementsByName("ris_trib")[i].checked){
			trovato = true;
			break;
		}
	}	

	if(!trovato){
		alert("Attenzione devi selezionare il giocatore dalla panchina o dalla tribuna");
		return false;
	}
	for(i=0;i<11;i++){
		if(document.getElementsByName("titolare")[i].checked){
			break;
		}
	}
	
	titolare = document.getElementsByName("titolare")[i].value;
	for(j=0;j<(giocatori_totali -11);j++){
		if(document.getElementsByName("ris_trib")[j].checked){
			break;
		}
	}

	riserva_tribuna = document.getElementsByName("ris_trib")[j].value;

	for(i = 0;i < titolare.length; i++){
		if(titolare.charAt(i) == "|"){
			pos_tit = titolare.substr(0,i);
			ruolo_tit = titolare.substr(i+1);
			break;

		}
	}

	for(i = 0;i < riserva_tribuna.length; i++){
		if(riserva_tribuna.charAt(i) == "|"){
			pos_ris_trib = riserva_tribuna.substr(0,i);
			ruolo_ris_trib = riserva_tribuna.substr(i+1);
			break;
		}
	}
	
	//////////portiere///////////
	if(pos_tit == 0){
		if(ruolo_ris_trib != 0){
			alert("Attenzione in prima posizione della formazione titolare ci deve essere per forza un portiere");
			return false;
		}	
	}
	////////////////////////////


	/////////////rispetto dei moduli//////////////////
	for(i=1;i<11;i++){
		if(!document.getElementsByName("titolare")[i].checked){
			for(j = 0;j < document.getElementsByName("titolare")[i].value.length; j++){
				if(document.getElementsByName("titolare")[i].value.charAt(j) == "|"){
					if(document.getElementsByName("titolare")[i].value.substr(j+1) == 1){
						conta_dif ++;
					}else if(document.getElementsByName("titolare")[i].value.substr(j+1) == 2){
						conta_centr ++;
					}else if(document.getElementsByName("titolare")[i].value.substr(j+1) == 3){
						conta_att ++;
					} 
					break;
				}
			}
		}

	}


	if (ruolo_ris_trib == 1){
		conta_dif ++;
	}else if (ruolo_ris_trib == 2){
		conta_centr ++;
	}else if (ruolo_ris_trib == 3){
		conta_att ++;
	}
	if(conta_dif < 3 || conta_dif > 5 || conta_centr < 3 || conta_centr > 5 || conta_att < 1 || conta_att > 3 || (conta_dif + conta_centr + conta_att)!= 10){
		alert ("Attenzione i moduli permessi sono: 3-4-3, 3-5-2, 4-5-1, 4-4-2, 4-3-3, 5-4-1, 5-3-2");
		return false;
	}
	//////////////////////////////////////////////////
	return true;
}




function contr_ins_panchina(tot_giocatori){

	var i= 0;

	var j =0;
	
	var selezionati = 0;
	
	var trovato = false;
	
	var panchinaro1;

	var panchinaro2;
	
	var tagliaerba;
	
	var pos_ris1;

	var ruolo_ris1; 
	
	var pos_trib; 

	var ruolo_trib;

	var pos_ris2;
	
	var ruolo_ris2; 
	
	
	for(i=11;i<18;i++){

		if(document.getElementsByName("panchina" + i)[0].checked){

			selezionati ++;

		}

	}
	
	for(i=0;i<(tot_giocatori - 18);i++){
		
		if(document.getElementsByName("tribuna")[i].checked){
			trovato = true;
			break;

		}

	}	
	
	
	
	
	if(selezionati ==0){
	
		alert("Attenzione devi selezionare almeno un giocatore della panchina");		
		return false;
		
	}

	if(selezionati == 1 && trovato == false){
		alert("Attenzione devi selezionare 2 giocatori");
		return false;
	}
	
	

	for(i=11;i<18;i++){

		if(document.getElementsByName("panchina" + i)[0].checked){

			break

		}

	}
	
	panchinaro1 = document.getElementsByName("panchina" + i)[0].value;
	
	if (selezionati == 2){
	
		for(j=11;j<18;j++){

			if((document.getElementsByName("panchina" + j)[0].checked) && (j!=i)){

				break;

			}

		}
		panchinaro2 = document.getElementsByName("panchina" + j)[0].value;
	}	
	
	
	if (selezionati == 1){

		for(j=0;j<(tot_giocatori - 18);j++){	

			if(document.getElementsByName("tribuna")[j].checked){

				break;

			}
		}
		tagliaerba = document.getElementsByName("tribuna")[j].value;	
	}
	
	for(i = 0;i < panchinaro1.length; i++){

		if(panchinaro1.charAt(i) == "|"){

			pos_ris1 = panchinaro1.substr(0,i);

			ruolo_ris1 = panchinaro1.substr(i+1);

			break;

		}
	}	
	
	if(selezionati == 2){
		
		for(i = 0;i < panchinaro2.length; i++){

			if(panchinaro2.charAt(i) == "|"){

				pos_ris2 = panchinaro2.substr(0,i);

				ruolo_ris2 = panchinaro2.substr(i+1);

				break;

			}
		}
	
	}else{

		for(i = 0;i < tagliaerba.length; i++){
	
			if(tagliaerba.charAt(i) == "|"){

				pos_trib = tagliaerba.substr(0,i);

				ruolo_trib = tagliaerba.substr(i+1);

				break;

			}

		}

	}	

	//////////portiere///////////

	
	if(selezionati == 2){
		
		if((pos_ris1 == 11 && ruolo_ris2 !=0) ||(pos_ris2 == 11 && ruolo_ris1 != 0)){
			
			alert("Attenzione in prima posizione nella panchina ci deve essere per forza un portiere");
			
			for(j=11;j<18;j++){

				if(document.getElementsByName("panchina" + j)[0].checked){

					document.getElementsByName("panchina" + j)[0].checked=false;
				}

			}
			return false;
			
		}
	}else{

		if(pos_ris1 == 11  && ruolo_trib !=0){
			
			alert("Attenzione in prima posizione nella panchina ci deve essere per forza un portiere");
			for(i=0;i<(tot_giocatori - 18);i++){

				if(document.getElementsByName("tribuna")[i].checked){
		
					document.getElementsByName("tribuna")[i].checked=false;
					break;
				}
			}	
			return false;
		}
				
	}
	

}





function contr_panchinaro(l,tot_giocatori){
	
	
	var selezionati_panchina = 0;
	var selezionati_tribuna = false;
	
	for(j=11;j<18;j++){

		if(document.getElementsByName("panchina" + j)[0].checked && j !=l){

			selezionati_panchina ++;

		}

	}
	
	for(i=0;i<(tot_giocatori - 18);i++){

		if(document.getElementsByName("tribuna")[i].checked){

			selezionati_tribuna = true;

			break;

		}

	}
	
	if(selezionati_panchina >= 2 ||(selezionati_panchina ==1 && selezionati_tribuna)){
		
		alert("Attenzione hai selezionato più di due giocatori");
		
		for(j=11;j<18;j++){

			if(document.getElementsByName("panchina" + j)[0].checked && j !=l){

				document.getElementsByName("panchina" + j)[0].checked=false;
			}

		}
		
		for(i=0;i<(tot_giocatori - 18);i++){

			if(document.getElementsByName("tribuna")[i].checked){
		
				document.getElementsByName("tribuna")[i].checked=false;
				break;
			}
		}	
	}
	
}



function contr_tribuna(l){
	
	
	var selezionati_panchina = 0;
	
	for(j=11;j<18;j++){

		if(document.getElementsByName("panchina" + j)[0].checked){

			selezionati_panchina ++;

		}

	}
	
	if(selezionati_panchina >= 2){
		
		alert("Attenzione hai selezionato più di due giocatori");
		
		for(j=11;j<18;j++){

			if(document.getElementsByName("panchina" + j)[0].checked){

				document.getElementsByName("panchina" + j)[0].checked=false;
			}

		}
	}
	
}




function controlla_rigoristi(){
	var i =0;
	var trovato;
	if (document.form_conf_form.se_rigoristi.value == true){
		for(i=1;i<12;i++){
			if(document.getElementsByName("ordine_rig" +i)[0].value==" "
			|| document.getElementsByName("ordine_rig" +i)[0].value=="  "){
				alert ("Attenzione niente spazi vuoti");
				return false;
			}
			
			
			if(document.getElementsByName("ordine_rig" +i)[0].value!=""){
				if(!controlla_numero(document.getElementsByName("ordine_rig" +i)[0])){
					alert ("Attenzione solo numeri");
					document.getElementsByName("ordine_rig" +i)[0].value = "";
					document.getElementsByName("ordine_rig" +i)[0].select();
					return false;

				}
				if((parseInt(document.getElementsByName("ordine_rig" +i)[0].value) > 11)||
					(parseInt(document.getElementsByName("ordine_rig" +i)[0].value) < 1)){
					alert ("Attenzione solo numeri tra 1 e 11");
					document.getElementsByName("ordine_rig" +i)[0].value = "";
					document.getElementsByName("ordine_rig" +i)[0].select();
					return false;
				
				}
				for(j=1;j<12 && j!=i;j++){
					if(parseInt(document.getElementsByName("ordine_rig" +j)[0].value)==
						parseInt(document.getElementsByName("ordine_rig" +i)[0].value)){
						alert ("Attenzione solo numeri diversi");
						document.getElementsByName("ordine_rig" +i)[0].value = "";
						document.getElementsByName("ordine_rig" +i)[0].select();
						return false;	
						
						}					
				
				}

				trovato = false;
				for(j=1;j<12;j++){
					if(parseInt(document.getElementsByName("ordine_rig" +j)[0].value)==
					(parseInt(document.getElementsByName("ordine_rig" +i)[0].value)-1)&&
					(parseInt(document.getElementsByName("ordine_rig" +i)[0].value)!=1)){
						trovato = true;
						break;
					}
					
					
				}
				if(!trovato && (parseInt(document.getElementsByName("ordine_rig" +i)[0].value) != 1)){
					alert ("Attenzione manca il rigorista numero " + 
					(parseInt(document.getElementsByName("ordine_rig" +i)[0].value)-1));
					document.getElementsByName("ordine_rig" +i)[0].value = "";
					document.getElementsByName("ordine_rig" +i)[0].select();
					return false;
				
				}
			
			
			}
			
		
		}
		
	}
}


