function validateFormAffluenza () {
	var msgObbligatorio = "";
	if(isRequired("commandAffluenza.rilevamento"))
	{		
		msgObbligatorio = msgObbligatorio+"\n Il Campo Rilevamento e' obbligatorio";
	}

	if(isRequired("commandAffluenza.denominazione"))
	{		
		msgObbligatorio = msgObbligatorio+"\n Il Campo Comuni/Circoscrizione e' obbligatorio";
	}
	if(isRequired("totaleVotanti"))
	{		
		msgObbligatorio = msgObbligatorio+"\n Il CampoTotale Votanti e' obbligatorio";
	}
	
	if(!isRequired("totaleVotanti"))
	{

		if(!isNumero("totaleVotanti"))
		{
			msgObbligatorio = msgObbligatorio+"\n Il campo Campo Totale Votanti e' numerico";
		}
		else {
			if(!controllaZero(document.getElementById("totaleVotanti").value))
				msgObbligatorio = msgObbligatorio+"\n Valore numerico non corretto nel campo Totale Votanti";
		}
	}
	
	if(msgObbligatorio != null && msgObbligatorio!=""){
		alert(msgObbligatorio);
		return false;
	}else 
		return true;
}

function validateFormModAffluenza () {
	var msgObbligatorio = "";
	if(isRequired("commandAffluenza.rilevamento"))
	{		
		msgObbligatorio = msgObbligatorio+"\n Il Campo Rilevamento e' obbligatorio";
	}

	if(isRequired("commandAffluenza.denominazione"))
	{		
		msgObbligatorio = msgObbligatorio+"\n Il Campo Comuni/Circoscrizione e' obbligatorio";
	}
	if(msgObbligatorio != null && msgObbligatorio!=""){
		alert(msgObbligatorio);
		return false;
	}
	else 
		return true;
}



function validateFormModAffluenzaVotanti(){
	var msgObbligatorio = "";

	if(isRequired("commandAffluenza.totaleVotanti"))
	{		
		msgObbligatorio = msgObbligatorio+"\n Il Campo Totale Votanti e' obbligatorio";
	}

	if(!isRequired("commandAffluenza.totaleVotanti"))
	{
		if(!isNumero("commandAffluenza.totaleVotanti"))
		{
			msgObbligatorio = msgObbligatorio+" \n Il campo Totale Votanti e' numerico";

		}
		else {
			if(!controllaZero(document.getElementById("totaleVotanti").value))
				msgObbligatorio = msgObbligatorio+"\n Valore numerico non corretto nel campo Totale Votanti";
		}
	}
	if(msgObbligatorio != null && msgObbligatorio!=""){
		alert(msgObbligatorio);
		return false;
	}
	else 
		return true;
}
/****************************** Inseriemnto Voti Presidenti e Liste *****************************/
function validaCampiPresidenti () {
	//alert("Entro nella funzione validaCampiPresidenti");
	//alert("sezioni scru---->"+document.getElementById("sezioniScru").value);
	//alert("sezioni tot---->"+document.getElementById("totSezioni").value);
	if(document.getElementById("sezioniScru").value == document.getElementById("totSezioni").value)
	{
		//alert("Entro nell'if");
		document.getElementById("votiNonValidi").readOnly=false;
		document.getElementById("votiNonValidi").style.backgroundColor="white";
		document.getElementById("schedeBianche").readOnly=false;
		document.getElementById("schedeBianche").style.backgroundColor="white";
		document.getElementById("votiSoloPre").readOnly=false;
		document.getElementById("votiSoloPre").style.backgroundColor="white";
	}
	else{
		document.getElementById("votiNonValidi").readOnly=true;
		document.getElementById("votiNonValidi").style.backgroundColor="#E3E8EA";
		document.getElementById("votiNonValidi").value="0";
		document.getElementById("schedeBianche").readOnly=true;
		document.getElementById("schedeBianche").style.backgroundColor="#E3E8EA";
		document.getElementById("schedeBianche").value="0";
		document.getElementById("votiSoloPre").readOnly=true;
		document.getElementById("votiSoloPre").style.backgroundColor="#E3E8EA";
		document.getElementById("votiSoloPre").value="0";
	}
}

function validaCampiVotiPresidenti() {
	//alert("Entro nella funzione validaCampiVotiPresidenti");
	//alert("lunghezza presidenti---->"+document.getElementById("lunghezzaPresidenti").value);
	for(var i=0; i<document.getElementById("lunghezzaPresidenti").value;i++){
		if(!isRequired("votiValidiPre") && document.getElementById("votiValidiPre").value!=0 && isNumero("votiValidiPre"))
		{
			//alert("Entro anche nell'if");
				document.getElementById("numeroVotiPre"+i).readOnly=false;
				document.getElementById("numeroVotiPre"+i).style.backgroundColor="white";
				
		}
		else
		{
			document.getElementById("numeroVotiPre"+i).readOnly=true;
			document.getElementById("numeroVotiPre"+i).style.backgroundColor="#E3E8EA";
			document.getElementById("numeroVotiPre"+i).value="0";

		}
	}
}

function validaCampiVotiListe() {
	//alert("Entro nella funzione validaCampiVotiListe");
	
	for(var i=0; i<document.getElementById("lunghezzaPresidenti").value;i++){
		//alert("Entro nel primo for");
		for(var j=0; j<document.getElementById("lunghezzaListe["+i+"]").value;j++){
			//alert("document.getElementById('lunghezzaListe')"+document.getElementById("lunghezzaListe["+i+"]").value);
			//alert("entro nel secondo for");
			if(!isRequired("votiValidiLista") && document.getElementById("votiValidiLista").value!=0 && isNumero("votiValidiLista"))
			{
				//alert("Entro anche nell'if");
					document.getElementById("presidenti"+i+".numeroVotiLista"+j).readOnly=false;
					document.getElementById("presidenti"+i+".numeroVotiLista"+j).style.backgroundColor="white";
					
			}
			else
			{
				document.getElementById("presidenti"+i+".numeroVotiLista"+j).readOnly=true;
				document.getElementById("presidenti"+i+".numeroVotiLista"+j).style.backgroundColor="#E3E8EA";
				document.getElementById("presidenti"+i+".numeroVotiLista"+j).value="0";
	
			}
		}
	}
}




function validateFormConsigliereVoto () {
	var msgObbligatorio = "";
	
	if(isRequired("sezioniScru"))
	{		
		msgObbligatorio = msgObbligatorio+"\n Il Campo Sezioni Scrutinate e' obbligatorio";
	}
	
	if(!isRequired("sezioniScru"))
	{
		if(!isNumero("sezioniScru"))
		{
			msgObbligatorio = msgObbligatorio+"\n Il campo Campo Sezioni Scrutinate e' numerico";
		}
		else if( isNumero("sezioniScru"))
		{
			
				if(!controllaZero(document.getElementById("sezioniScru").value))
					msgObbligatorio = msgObbligatorio+"\n Valore numerico non corretto nel campo Sezioni Scrutinate";
			
			var totSez = parseInt( document.getElementById( "sezioniScru" ).value, 10 );
			alert( "Totale sez Numerico " + totSez);
			if( totSez <= 0  ){
				
				msgObbligatorio = msgObbligatorio+"\n Il campo Campo Sezioni Scrutinate deve essere diverso da zero";
				alert( "Sono if Totale sez Numerico " + totSez);
			}
			else  if( totSez != 0  )
			{
				var totSez = parseInt( document.getElementById( "sezioniScru" ).value, 10 );
				var sez = parseInt( document.getElementById( "sez" ).value, 10 );
				
				if( totSez > sez  )
					msgObbligatorio = msgObbligatorio+"\n Il campo Campo Sezioni Scrutinate non puņ essere superiore al campo Totale Sezioni";
			}
			
		}
	}

	var num=document.getElementById("numConsi").value;
	var totale = 0; 
	for (i=0; i<num; i++){
		
		alert( "Totale sez Numerico " + totSez);
		eval("var nome = 'nome" + i + "'");		
		
		eval("var voti = 'voti" + i + "'");		
		// verifico se la prima riga e' valorizzata o nome cognome o comune nascita degli altri
			
			if(!isRequired(voti))
			{
				if(!isNumero(voti))
				{
					msgObbligatorio = msgObbligatorio+"\n Il campo Voti  del consigliere "+nome+"  e' numerico";
				}
				else {
					if(!controllaZero(document.getElementById(voti).value))
						msgObbligatorio = msgObbligatorio+"\n Valore numerico non corretto nel campo Voti del consigliere "+nome+"";
				}
				totale = totale + parseInt( voti, 10 );
				
			}
			else if( isRequired(voti))
			{
				document.getElementById(voti).value=0;	
			}
			 					
		}	
	
	if(!isRequired("totaleVoti"))
	{
		
		if(!isNumero("totaleVoti"))
		{
			msgObbligatorio = msgObbligatorio+"\n Il campo Campo Totale e' numerico";
		}
		else {
			if(!controllaZero(document.getElementById("totaleVoti").value))
				msgObbligatorio = msgObbligatorio+"\n Valore numerico non corretto Totale";
		}
	}
	
	if( totale != 0 ){
		
		if(isRequired("totaleVoti"))
		{		
			msgObbligatorio = msgObbligatorio+"\n Il Campo Totale e' obbligatorio";
		}
		else if(!isRequired("totaleVoti")){
			
			if( isNumero("totaleVoti"))
			{
				
				if( totale !=  parseInt( document.getElementById("totaleVoti").value, 10 ))
					msgObbligatorio = msgObbligatorio+"\n Il Campo Totale deve coincidere con la somma dei voti dei singoli consiglieri";
						
			}
		}
		
		
	}
	if(msgObbligatorio != null && msgObbligatorio!=""){
		alert(msgObbligatorio);
		return false;
	}
	else 
		return true;
	}
	
/****************************** Fine Inserimento Voti Presidenti e Liste *****************************/
/****************************** MICHELE Inserimento Voti Presidenti ***********************************/
function validetePresidentiVoti () {
	//alert("Entro nella funzione validetePresidentiVoti");
	//alert("sezioni scru---->"+document.getElementById("sezioniScru").value);
	//alert("sezioni tot---->"+document.getElementById("totSezioni").value);
	if(document.getElementById("sezioniScru").value == document.getElementById("totSezioni").value)
	{
		//alert("Entro nell'if");
		document.getElementById("votiNonValidi").readOnly=false;
		document.getElementById("votiNonValidi").style.backgroundColor="white";
		document.getElementById("schedeBianche").readOnly=false;
		document.getElementById("schedeBianche").style.backgroundColor="white";
		document.getElementById("votiSoloPre").readOnly=false;
		document.getElementById("votiSoloPre").style.backgroundColor="white";
	}
	else{
		document.getElementById("votiNonValidi").readOnly=true;
		document.getElementById("votiNonValidi").style.backgroundColor="#E3E8EA";
		document.getElementById("votiNonValidi").value="0";
		document.getElementById("schedeBianche").readOnly=true;
		document.getElementById("schedeBianche").style.backgroundColor="#E3E8EA";
		document.getElementById("schedeBianche").value="0";
		document.getElementById("votiSoloPre").readOnly=true;
		document.getElementById("votiSoloPre").style.backgroundColor="#E3E8EA";
		document.getElementById("votiSoloPre").value="0";
	}
}

function validateCampiPresidentiVoti() {
	//alert("Entro nella funzione validateCampiPresidentiVoti");
	//alert("lunghezza presidenti---->"+document.getElementById("lunghezzaPresidenti").value);
	for(var i=0; i<document.getElementById("lunghezzaPresidenti").value;i++){
		if(!isRequired("votiValidiPre") && document.getElementById("votiValidiPre").value!=0 && isNumero("votiValidiPre"))
		{
			//alert("Entro anche nell'if");
				document.getElementById("numeroVotiPre"+i).readOnly=false;
				document.getElementById("numeroVotiPre"+i).style.backgroundColor="white";
				
		}
		else
		{
			document.getElementById("numeroVotiPre"+i).readOnly=true;
			document.getElementById("numeroVotiPre"+i).style.backgroundColor="#E3E8EA";
			document.getElementById("numeroVotiPre"+i).value="0";

		}
	}
}

function validateCampiListeVoti() {
	//alert("Entro nella funzione validaCampiVotiListe");
	
	for(var i=0; i<document.getElementById("lunghezzaPresidenti").value;i++){
		//alert("Entro nel primo for");
		for(var j=0; j<document.getElementById("lunghezzaListe["+i+"]").value;j++){
			//alert("document.getElementById('lunghezzaListe')"+document.getElementById("lunghezzaListe["+i+"]").value);
			//alert("entro nel secondo for");
			if(!isRequired("votiValidiLista") && document.getElementById("votiValidiLista").value!=0 && isNumero("votiValidiLista"))
			{
				//alert("Entro anche nell'if");
					document.getElementById("presidenti"+i+".numeroVotiLista"+j).readOnly=false;
					document.getElementById("presidenti"+i+".numeroVotiLista"+j).style.backgroundColor="white";
					
			}
			else
			{
				document.getElementById("presidenti"+i+".numeroVotiLista"+j).readOnly=true;
				document.getElementById("presidenti"+i+".numeroVotiLista"+j).style.backgroundColor="#E3E8EA";
				document.getElementById("presidenti"+i+".numeroVotiLista"+j).value="0";
	
			}
		}
	}
}




function validateFormVoti () {

	var msgObbligatorio = "";
	
	if(isRequired("sezioniScru"))
	{	

		msgObbligatorio = msgObbligatorio+"\n Il Campo Sezioni Scrutinate e' obbligatorio";
	}
	
	if(!isRequired("sezioniScru"))
	{
		if(!isNumero("sezioniScru"))
		{
			msgObbligatorio = msgObbligatorio+"\n Il campo Campo Sezioni Scrutinate e' numerico";
		}
		else if( isNumero("sezioniScru"))
		{
			
				if(!controllaZero(document.getElementById("sezioniScru").value))
					msgObbligatorio = msgObbligatorio+"\n Valore numerico non corretto nel campo Sezioni Scrutinate";
			
			var totSez = parseInt( document.getElementById( "sezioniScru" ).value, 10 );
			alert( "Totale sez Numerico " + totSez);
			if( totSez <= 0  ){
				
				msgObbligatorio = msgObbligatorio+"\n Il campo Campo Sezioni Scrutinate deve essere diverso da zero";
				alert( "Sono if Totale sez Numerico " + totSez);
			}
			else  if( totSez != 0  )
			{
				var totSez = parseInt( document.getElementById( "sezioniScru" ).value, 10 );
				var sez = parseInt( document.getElementById( "sez" ).value, 10 );
				
				if( totSez > sez  )
					msgObbligatorio = msgObbligatorio+"\n Il campo Campo Sezioni Scrutinate non puņ essere superiore al campo Totale Sezioni";
			}
			
		}
	}

		
	
	/*if(!isRequired("totaleVoti"))
	{
		
		if(!isNumero("totaleVoti"))
		{
			msgObbligatorio = msgObbligatorio+"\n Il campo Campo Totale e' numerico";
		}
		else {
			if(!controllaZero(document.getElementById("totaleVoti").value))
				msgObbligatorio = msgObbligatorio+"\n Valore numerico non corretto Totale";
		}
	}
	
	if( totale != 0 ){
		
		if(isRequired("totaleVoti"))
		{		
			msgObbligatorio = msgObbligatorio+"\n Il Campo Totale e' obbligatorio";
		}
		else if(!isRequired("totaleVoti")){
			
			if( isNumero("totaleVoti"))
			{
				
				if( totale !=  parseInt( document.getElementById("totaleVoti").value, 10 ))
					msgObbligatorio = msgObbligatorio+"\n Il Campo Totale deve coincidere con la somma dei voti dei singoli consiglieri";
						
			}
		}
		
		
	}*/
	if(msgObbligatorio != null && msgObbligatorio!=""){
		alert(msgObbligatorio);
		return false;
	}
	else 
		return true;
	}
/****************************** FINE Inserimento Voti Presidenti  *****************************/
