/*
QUESTA FUNZIONE CONTROLLA CHE SIA PRESENTE UN PARAMETRO DI RICERCA ED IN SEGUITO EFFETTUA IL SUBMIT
PARAMETRI: nessuno
VALORE DI RITORNO: nessuno
*/
function go_search()
{
	if (document.ric_libera.key.value != "")
		document.ric_libera.submit();
	else alert('Inserire un termine valido da ricercare');
	document.ric_libera.key.focus();
	return;
}

/*
Svuota un campo dal contenuto (serve per i campi readonly)
PARAMETRI: nomeCampo
VALORE DI RITORNO: nessuno
*/
function SvuotaCampo(nomeCampo)
{
	document.getElementById(nomeCampo).value = "";
	return;
}
/*
SEMPLICE FUNZIONE CHE EFFETTUA IL REDIRECT VERSO UNA PAGINA
PARAMETRI: string url |contenente l'url di destinazione
VALORE DI RITORNO: nessuno
*/
function redirect(url)
	{
	window.location=url;
	}

/*
SEMPLICE FUNZIONE CHE APRE UNA PICCOLA PAGINA DI POPUP PER IL CALENDARIO
PARAMETRI: string url |contenente l'url di destinazione
VALORE DI RITORNO: nessuno
*/
function OpenFrm(Link)
	{
	windowFrm=window.open(Link,"","toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=0,width=300,height=200");
	}
function Apri(Link)
	{
	windowFrm=window.open(Link,"","toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=0,width=350,height=200");
	}
function ApriGenerico(Link,larg,alt)
	{
	windowFrm=window.open(Link,"","toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width="+larg+",height="+alt+"");
	}
	
/*
QUESTA FUNZIONE SI OCCUPA DI RENDERE VISIBILE O INVISIBILE UN QUALSIASI ELEMENTO HTML (DIV PER ESEMPIO.). 
IN AUTOMATICO RICAVA LO STATO ATTUALE DELL'ELEMENTO E LO MODIFICA DI CONSEGUENZA
PARAMETRI: string sDiscriminante |contenente il nome dell'elemento da processare
VALORE DI RITORNO: nessuno
*/
function ShowAndHide(sDiscriminante)	
	{
	//alert(sDiscriminante);
	//alert(document.getElementById(sDiscriminante).style.display);
	if (document.getElementById(sDiscriminante).style.display  == "none")
		{
		document.getElementById(sDiscriminante).style.display="";
		//document.getElementById("img"+sDiscriminante).src='/web/catalogo/immagini/unexpand.gif';	
		}
	else
		{
		document.getElementById(sDiscriminante).style.display="none";
		//document.getElementById("img"+sDiscriminante).src='/web/catalogo/immagini/expand.gif';
		}
	 
	}
function ShowAndHide2(sDiscriminante,action)	
	{
	var ie4=document.all;
	var ns6=document.getElementById&&!document.all;
	if(ie4)
		{
		if (action == "hide")
			{
			document.getElementById(sDiscriminante).style.display="none";
			}
		else
			{
			document.getElementById(sDiscriminante).style.display="block";
			}
		}
	if(ns6)
		{
		if (action == "hide")
			{
			document.getElementById(sDiscriminante).style.display="none";
			}
		else
			{
			document.getElementById(sDiscriminante).style.display="table-row";
			}
		}
	}
/*
QUESTA E' UNA FUNZIONE SPECIFICA PER FAR APPARIRE LE FORM PER ACQUISTARE
PARAMETRI: string sDiscriminante |contenente il nome della form da mostrare
VALORE DI RITORNO: nessuno
*/
function ShowForm(sDiscriminante)	
	{
	if (sDiscriminante == "kgmt")
		{
			antagonista = "conf"
			for (i=1;i<=2;i++)
				{
				document.getElementById(sDiscriminante+i).style.display="block";
				}
			for (i=1;i<=2;i++)
				{
				document.getElementById(antagonista+i).style.display="none";
				}
		}
    else
		{
			antagonista = "kgmt"
			for (i=1;i<=2;i++)
				{
				document.getElementById(sDiscriminante+i).style.display="block";
				}
			for (i=1;i<=2;i++)
				{
				document.getElementById(antagonista+i).style.display="none";
				}
     	}
		
 
	}

/*
QUESTA E' UNA FUNZIONE EFFETTUA LA CONVERSIONE E CAMBIA I VALORI NEI TEXTBOX
PARAMETRI: string myfield, event, bho
VALORE DI RITORNO: true o false
NB se ritorna false il carattere non viene scritto e nulla succede
*/	
function ConversioneValori(myfield, e, dec)
	{
	var key;
	var keychar;
	
	//ricavo la key premuta ed il codice relativo ad essa
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	//Se premo backspace entro qua
	if (key == 8)
		{
		//estraggo il contenuto in MT
		contenutoMt = document.getElementById("MT").value
		//visto che ho premuto il back devo eliminare l'ultimo carattere del contenuto MT
		contenutoMtAdesso = contenutoMt.substring(0,contenutoMt.length-1);
		//effettuo il calcolo
		qta = contenutoMtAdesso * document.getElementById("KGMT").value;
		//sostituisco il valore all'interno del box QTA arrotondato con 2 decimali
		document.getElementById("QTA").value = qta.toFixed(2);
	   	return true;
		}
		
	//Se premo un numero entro qua
	else if ((("0123456789.").indexOf(keychar) > -1))
		{
		//estraggo il contenuto in MT e lo concateno alla key appena premuta
		contenutoMtAdesso = document.getElementById("MT").value + keychar;
		//effettuo il calcolo
		valoreConvertito =contenutoMtAdesso * document.getElementById("KGMT").value;
		//se il risultato è numerico lo accetto senno lo setto a zero
		if (!isNaN(valoreConvertito))
			qta = valoreConvertito
		else
			qta = 0
		//sostituisco il valore all'interno del box QTA arrotondato con 2 decimali
		document.getElementById("QTA").value = qta.toFixed(2);
		return true;
		}	
	else
	   return false;
	}