// JavaScript Document

//Funzione per controllare che TUTTI i campi di un form siano compilati
function CheckForm(id)
{
	var f=document.getElementById(id).elements;
	var errore=0;
	
	for(i=0;i<f.length;i++)
	{
		if(f[i].value=="" || f[i].value==null)
		{
			errore=1;
		}
	}
	if(errore>0)
	{
		alert('Attenzione! Compilare tutti i campi del modulo');
		return false;
	}else{
		return true;
	}
}


function DomandaEl()
{
	if(confirm('ATTENZIONE! l\'eliminazione è irreversibile. Eliminare definitivamente l\'utente?'))
	{
		return true;
	}else{
		return false;
	}
}


function switchForm(id1)
{
 var ogg = document.getElementById(id1);
  if (ogg.style.display == 'block') {
    ogg.style.display = 'none';

  } else {
    ogg.style.display = 'block';

  }

}




function Invalidate(indice)
{
	var stato=document.getElementById('g1'+indice+'1').disabled;
	var toChange=true;
	if(stato)
	{
		toChange=false;
	}
		
		var stato1=document.getElementById('toTake'+indice).checked;
		document.getElementById('toTakeS'+indice+'2').checked=stato1;
		document.getElementById('toTakeS'+indice+'3').checked=stato1;
		document.getElementById('prezzo'+indice).disabled=toChange;
		
		for(j=1;j<4;j++)
		{
			document.getElementById('g1'+(indice+j)).disabled=toChange;
			document.getElementById('m1'+(indice+j)).disabled=toChange;
			document.getElementById('g2'+(indice+j)).disabled=toChange;
			document.getElementById('m2'+(indice+j)).disabled=toChange;
		}
		

}


function InvalidateS(indice,indic)
{
	var stato=document.getElementById('g1'+indice+indic).disabled;
	var toChange=true;
	if(stato)
	{
		toChange=false;
	}

		if(document.getElementById('toTake'+indice).checked==false && document.getElementById('toTakeS'+indice+indic).checked==true){
			document.getElementById('toTake'+indice).checked=true;
			Invalidate(indice);
		}

			document.getElementById('g1'+indice+indic).disabled=toChange;
			document.getElementById('m1'+indice+indic).disabled=toChange;
			document.getElementById('g2'+indice+indic).disabled=toChange;
			document.getElementById('m2'+indice+indic).disabled=toChange;
}


function checkValore(valore)
{
	var reg = /^[\d]{1,17}(,[\d]{1,2})?$/;
	if (reg.test(valore)==false) 
	{
	alert('Attenzione. Inserire solo numeri interi seguiti da una virgola e da 2 cifre decimali. /n Esempio: 1024,50');
	document.getElementById('prezzo'+ritorno).value='0,00';
	document.getElementById('prezzo'+ritorno).focus();
	}

}


//funzione per far apparire scomparire sottomenu in un menu ad albero
function showHide(nome,tot)
{

var stato;
stato=document.getElementById(nome+(tot-2)).style.display;
var cambiain;


if(stato=='block' || stato=='')
{
	cambiain='none';	
}else{
	cambiain='block';
}


for(i=0;i<(tot-1);i++)
{

document.getElementById(nome+i).style.display=cambiain;
}


}

//funzione per cambiare il disegno del pulsante del menu
function bottone(categoria,numero)
{
	
	
	
	if(document.getElementById(categoria+'1imga'+numero).style.display=='block' || document.getElementById(categoria+'1imga'+numero).style.display=='')
	{
		document.getElementById(categoria+'1imga'+numero).style.display='none';
		document.getElementById(categoria+'2imga'+numero).style.display='block';
	}else{
		document.getElementById(categoria+'1imga'+numero).style.display='block';
		document.getElementById(categoria+'2imga'+numero).style.display='none';
		
		//chiudiMenu(categoria,numero);
	}
	
}


function showHideT(idM)
{
 var cambiain;
 var stato;
 
 stato=document.getElementById(idM).style.display;
 
 if(stato== 'block' || stato==''){
 cambiain='none';
  }else{
  cambiain='block';
  }
  
  document.getElementById(idM).style.display=cambiain;
  
  bottoneT(idM);
}

//funzione per cambiare il disegno del pulsante del menu
function bottoneT(categoria)
{
	
	
	
	if(document.getElementById(categoria+'1imga').style.display=='block' || document.getElementById(categoria+'1imga').style.display=='')
	{
		document.getElementById(categoria+'1imga').style.display='none';
		document.getElementById(categoria+'2imga').style.display='block';
	}else{
		document.getElementById(categoria+'1imga').style.display='block';
		document.getElementById(categoria+'2imga').style.display='none';
		
		//chiudiMenu(categoria,numero);
	}
	
}


