//var n = (document.layers) ? 1:0;
//var ie = (document.all) ? 1:0;
//var percorsoLayer;

//if (n)
//	percorsoLayer = "document.layers";
//else
//	percorsoLayer = "document.all";

//if ((location.hostname.toUpperCase() != "RC2051") && (location.hostname != "192.168.6.177"))
//{
//	if (n)
//	{
//		window.onkeypress = KeyPressed;
//		document.onkeypress = KeyPressed;
//	}
//	else
//	{
//		document.onkeydown = KeyPressed;
//		window.document.onkeydown = KeyPressed;
//	}
//	
//	if (document.layers)
//		window.captureEvents(Event.MOUSEDOWN);
//	
//	window.onmousedown=right;
//	document.onmousedown=right;
//}	
	

	
function right(evnt)
{	
	if (navigator.appName == 'Netscape' && (evnt.which == 3 || evnt.which == 2))
		return false;
	else
		if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3))
		{
			// disabilita il tasto dx 
			//alert ("Tasto destro non abilitato.");	
			//return false;
		}
		
	return true;
}

function PagePrintCentro(bPrinted)
{
	
	if (bPrinted)
	{
		if (n)
			top.frmToolBar.document.layers["stampa"].visibility="visible";
		else	
			top.frmToolBar.document.all["stampa"].visibility="visible";
	}
	else
	{
		if (n)
			top.frmToolBar.document.layers["stampa"].visibility="hidden";
		else	
			top.frmToolBar.document.all["stampa"].visibility="hidden";
	}
	return;	
}

function PagePrint(bPrinted)
{
	if (bPrinted)
	{
		if (n)
			top.frmToolBar.document.layers["stampa"].visibility="visible";
		else	
			top.frmToolBar.document.all["stampa"].visibility="visible";
		
	}
	else
		if (n)
			top.frmToolBar.document.layers["stampa"].visibility="hidden";
		else	
			top.frmToolBar.document.all["stampa"].visibility="hidden";
	
	return;
}

function ControlloFuoco() 
{
	var controllo = window.top.nascosto.GetStatusVar("angolo2000");
	
	if (controllo == "blocco")
	{
		window.blur;
		top.ang2000.requestFocus();
	}
}

function goBack()
{
	var sUrl;
		
	if (bLock)
		return;
			
	bLock = true;
	
	top.frmStatus.StartWait();
	
	sUrl = top.nascosto.DeleteElement();
	
	document.location = sUrl;
}

function ImgAct(imgName,nomeLayer)
{
	if (document.images)
	{
		imgOn = eval(imgName + "On.src");
		document.layers[nomeLayer].document [imgName].src = imgOn;
	}
}
     
function ImgInact(imgName,nomeLayer)
{
	if (document.images)
	{
		imgOff = eval(imgName + "Off.src");
		document.layers[nomeLayer].document [imgName].src = imgOff;
	}
}

function ImgAct1(imgName)
{
	if (document.images)
	{
		imgOn = eval(imgName + "On.src");
		document [imgName].src = imgOn;
	}
}

function ImgInact1(imgName)
{
	if (document.images)
	{
		imgOff = eval(imgName + "Off.src");
		document [imgName].src = imgOff;
	}
}

function Posizionamento(pagAtt)
{
	var hDoc;
	var hClip;
	//navigator.appName.cache.disk_cache_size = 0;	
	//location.replace();			
	//document.forms[0].reset();
	
	bLock = false;
	
	if (finePagPrec == true)
	{
		hClip = document.contenitore.clip.height;
		hDoc = document.contenitore.document.contenuti.document.height;
		diff = hDoc-hClip;
		document.contenitore.document.layers['contenuti'].moveTo(0,0-diff);
		document.form1.scorritab.value = pagAtt;
		iNumPage = pagAtt;
		finePagPrec = false;
	}
}

function RighePrec(topIniz, hscorr, radNome)
{ 
	var extra = Math.abs(document.layers['contenitore'].document.layers[0].top);
	var hClip = document.layers['contenitore'].clip.height;
	var hDoc = document.layers['contenitore'].document.layers['contenuti'].document.height;
	var diff = 0;
	var pagPrec;
	var timeoutId;
	var contTemp;
	
	//evnt.layerX += 5;
		
	if ( (!top.nascosto.document.applets.controlli.campoNumerico(document.form1.scorritab.value))||
		(document.form1.scorritab.value != iNumPage));
	
	document.form1.scorritab.value = iNumPage;
	
	if (extra  >= hscorr)
		document.contenitore.document.layers['contenuti'].moveBy(0,hscorr);
	else
	{
		if (extra > topIniz)
			document.contenitore.document.layers['contenuti'].moveTo(0,topIniz);
		else
		{
			if (document.form1.scorritab.value > 1)
			{
				if (bLock)
					return;
				
				bLock = true;
				
				pagPrec = parseInt(document.form1.scorritab.value) - 1;
				fileName = "../../Comuni/Altri/Alt-01_VisualizzaDatiTabella.asp?NomeFile=" + radNome + "_" + pagPrec + ".asp";
				finePagPrec = true;
				document.contenitore.document.contenuti.src = fileName;
				bLock = false;
			}
		}
	}
}

function RigheSucc(hscorr, numPag, radNome)
{
	var extra = Math.abs(document.layers['contenitore'].document.layers['contenuti'].top);
	var hClip = document.layers['contenitore'].clip.height;
	var hDoc = document.layers['contenitore'].document.layers['contenuti'].document.height;
	var diff=0;
	var stop;
	var pagSucc;
	
	//evnt.screenX += 58;	
	//evnt.layerX -= 8;
			
	if ( (!top.nascosto.document.applets.controlli.campoNumerico(document.form1.scorritab.value))||
		(document.form1.scorritab.value != iNumPage));
	
	document.form1.scorritab.value = iNumPage;
		
	if ((extra + hClip + hscorr) <= hDoc)
		document.contenitore.document.layers['contenuti'].moveBy(0,0-hscorr);
	else
	{
		diff = hDoc - (extra + hClip);
					
		if (diff > 21)
		//N.B. 21 è la distanza in pixel dall'ultima riga della tabella alla fine del documento;
		//se si dovesse cambiare la formattazione della tabella si dovrebbe ricalcolare anche questa 
		//quantità... basta "scommentare l'allert che segue"
		{
			//alert("diff: " + diff);
			//stop = diff + 2;
			stop = diff;
			document.contenitore.document.layers['contenuti'].moveBy(0,0-stop);
		}
		else
		//deve andare alla pagina succ se questa esiste
		{
			if (bLock)
				return;
			
			bLock = true;
							
			if (document.form1.scorritab.value < numPag)
			{
				pagSucc = parseInt(document.form1.scorritab.value) + 1;
				fileName = "../../Comuni/Altri/Alt-01_VisualizzaDatiTabella.asp?NomeFile=" + radNome + "_" + pagSucc + ".asp";
									
				eval("document.contenitore.document.contenuti.src='" + fileName + "'");
				eval("document.contenitore.document.layers['contenuti'].moveTo(0,0)");
					
				//sfogliaPagina('document.contenitore.document.contenuti','fileName');

				document.form1.scorritab.value = pagSucc;		
				iNumPage = pagSucc;
			}
			
			bLock = false;
		}
	}
}
	
function PaginaPrec(numPag, radNome)
{
	var pagPrec;
	
	if (bLock)
		return;
			
	bLock = true;
	
	//evnt.layerX += 5;
	if ( (!top.nascosto.document.applets.controlli.campoNumerico(document.form1.scorritab.value))||
		(document.form1.scorritab.value != iNumPage));
	
	document.form1.scorritab.value = iNumPage;
					
	pagPrec = parseInt(document.form1.scorritab.value) - 1;
	
	if (pagPrec >= 1)
	{
		fileName = "../../Comuni/Altri/Alt-01_VisualizzaDatiTabella.asp?NomeFile=" + radNome + "_" + pagPrec + ".asp";
		eval("document.contenitore.document.contenuti.src='" + fileName + "'");
		eval("document.contenitore.document.layers['contenuti'].moveTo(0,0)");
		document.form1.scorritab.value = pagPrec;
		iNumPage = pagPrec;
	}
	
	bLock = false;
}

function PaginaSucc(numPag, radNome)
{
	var pagSucc;
	
	if (bLock)
		return;
			
	bLock = true;
	
	if ( (!top.nascosto.document.applets.controlli.campoNumerico(document.form1.scorritab.value))||
		(document.form1.scorritab.value != iNumPage));
		
	document.form1.scorritab.value = iNumPage;
	
	pagSucc = parseInt(document.form1.scorritab.value) + 1;
	
	if (pagSucc <= numPag)
	{
		//fileName = radNome + "_" + pagSucc + ".asp";
		fileName = "../../Comuni/Altri/Alt-01_VisualizzaDatiTabella.asp?NomeFile=" + radNome + "_" + pagSucc + ".asp";
		eval("document.contenitore.document.contenuti.src='" + fileName + "'");
		eval("document.contenitore.document.layers['contenuti'].moveTo(0,0)");
		document.form1.scorritab.value = pagSucc;
		iNumPage = pagSucc;
	}
	
	bLock = false;
}

function VaiAPag(carattere, numPag, radNome)
{
	var pagSucc;
	var valPrec;
	var lung;
	var posIni;
	var posFin;
	
	if (carattere == 13)
	{
		if (bLock)
			return;
		
		if (!top.nascosto.document.applets.controlli.campoNumerico(document.form1.scorritab.value))
		{
			alert("Occorre inserire un numero!");
			return;
		}	
		
		pagSucc = parseInt(document.form1.scorritab.value)
		
		if (pagSucc != "")
		{
			if ((pagSucc <= numPag) && (pagSucc >=1))
			{
				bLock = true;
				
				//fileName = radNome + "_" + pagSucc + ".asp"; 
				fileName = "../../Comuni/Altri/Alt-01_VisualizzaDatiTabella.asp?NomeFile=" + radNome + "_" + pagSucc + ".asp";
				eval("document.contenitore.document.contenuti.src='" + fileName + "'");
				eval("document.contenitore.document.layers['contenuti'].moveTo(0,0)");
				document.form1.scorritab.value = pagSucc;
				iNumPage = pagSucc;
			}
			else
			{
				alert("Introdurre un numero compreso tra 1 e " + numPag + "!");
				document.form1.scorritab.value = iNumPage;
			}
		}
		else
		{
			//non e' stato introdotto il numero di pag.
			alert("E' necessario introdurre il numero della pagina cui si desidera spostarsi");
			document.form1.scorritab.value = iNumPage;
		}
		
		bLock = false;
	}	
}	
	
/*function AbilitaSalv()
{
	if (consentiSalv == true)
		return true;
	else 
		return false;
}
*/

function PulisciCampi(nomeForm)
{
	var i = 0;
	var ind = 3;
	var lung = eval("document." + nomeForm + ".elements.length");
	
	for (i = 0; i < lung; i++)
	{
		if ((eval("document." + nomeForm + ".elements[" + i + "].type")) == "text")
			eval("document." + nomeForm + ".elements[" + i + "].value=''");
			
		if ((eval("document." + nomeForm + ".elements[" + i + "].type")) == "select-one")
			eval("document." + nomeForm + ".elements[" + i + "].selectedIndex=0");
			
		if ((eval("document." + nomeForm + ".elements[" + i + "].type")) == "checkbox")
			eval("document." + nomeForm + ".elements[" + i + "].checked=false");
	}
	
	for (i = 0; i < lung; i++)
	{
		if ((eval("document." + nomeForm + ".elements[" + i + "].type")) == "text")
		{	
			eval("document." + nomeForm + ".elements[" + i + "].focus()");
			break;
		}
	}
}

function SetFocus(nomeForm, nLgth, fldFrom, fldTo, chkName)
{
	if (chkName != "")
		if (eval("document." + nomeForm + "." + chkName + ".checked"))
			eval("document." + nomeForm + "." + chkName + ".checked = false");
	
	if (eval("document." + nomeForm + "." + fldFrom + ".value.length == " + nLgth))
	{
		eval("document." + nomeForm + "." + fldTo + ".focus()");
		eval("document." + nomeForm + "." + fldTo + ".select()");
	}
}

function ErrorFunc (msg, url, line)
{
	var indice;
	
	indice = url.indexOf ('?');
	urlDef = url.substring (0, indice);
					
	alert("Error: \n" + msg + "\n" + "al line: " + line + "\n" + "in: " + urlDef);
	
	top.nascosto.SetStatusVar("angolo2000", "sblocco");
	
    return true;
}

function ClearDate(nomeForm, nomeCampo, gI, mI, aI, gF, mF, aF, OneDate)
{
	eval("document." + nomeForm + "." + gI + ".value =''");
	eval("document." + nomeForm + "." + mI + ".value =''");
	eval("document." + nomeForm + "." + aI + ".value =''");
	
	if (!OneDate)
	{
		eval("document." + nomeForm + "." + gF + ".value =''");
		eval("document." + nomeForm + "." + mF + ".value =''");
		eval("document." + nomeForm + "." + aF + ".value =''");
	}
					
	eval("document." + nomeForm + "." + nomeCampo + ".checked = false");
	eval("document." + nomeForm + "." + gI + ".focus()");
}
			
function InserimentoData(dDay, dMonth, dYear, nomeForm, nomeCampo, gI, mI, aI, gF, mF, aF, OneDate)
{	
	/* dDay, dMonth, dYear rappresentano i parametri relativi alla data attuale e 
	vanno passati da server;
	nomeCampo...;
	gI, mI, aI, gF, mF, aF sono i nomi dei campi cui andare ad indìserire la data attuale;
	OneDate parametro per individuare se va valorizzata una o più date;
	*/
	var aux;

	if (eval("!document." + nomeForm + "." + nomeCampo + ".checked"))
		ClearDate(nomeForm, nomeCampo, gI, mI, aI, gF, mF, aF, OneDate);
	else
	{
		if (dDay < 10)
		{
			aux =  "0" + dDay;
			eval("document." + nomeForm + "." + gI + ".value = '" + aux + "'");
					
			if (!OneDate)
				eval("document." + nomeForm + "." + gF + ".value = '" + aux + "'");
		}
		else
		{
			eval("document." + nomeForm + "." + gI + ".value = '" + dDay + "'");
					
			if (!OneDate)
				eval("document." + nomeForm + "." + gF + ".value = '" + dDay + "'");
		}
									
		if (dMonth < 10)
		{
			aux =  "0" + dMonth;
			eval("document." + nomeForm + "." + mI + ".value = '" + aux + "'");
			
			if (!OneDate)
				eval("document." + nomeForm + "." + mF + ".value = '" + aux + "'");
		}
		else
		{
			eval("document." + nomeForm + "." + mI + ".value = '" + dMonth + "'");
					
			if (!OneDate)
				eval("document." + nomeForm + "." + mF + ".value = '" + dMonth + "'");
		}
						
		eval("document." + nomeForm + "." + aI + ".value = '" + dYear + "'");
				
		if (!OneDate)
			eval("document." + nomeForm + "." + aF + ".value = '" + dYear + "'");
	}
}

function CheckDate(nomeForm, nomeG, nomeM, nomeA)
{
	var giorno;
	var mese;
	var anno;
	var lungG;
	var lungM;
	var lungA;
	var nuovoG;
	var nuovoM;
	var risultato = true;
	
	with(eval("document." + nomeForm))
	{
		giorno = eval(nomeG + ".value");
		mese = eval(nomeM + ".value");
		anno = eval(nomeA + ".value");
		lungG = eval(nomeG + ".value" + ".length");
		lungM = eval(nomeM + ".value" + ".length");		
	
		if (!(top.nascosto.document.applets.controlli.controlloData(giorno,mese,anno)))
		{
			alert("Attenzione: è stata inserita una data non valida");
			eval("document." + nomeForm + "." + nomeG + ".focus()");
			risultato = false;
		}
		else
		{
			if (anno < 1900)
			{
				alert("Attenzione: è stata inserita una data non valida");
				eval("document." + nomeForm + "." + nomeA + ".focus()");
				risultato = false;
			}
			else
			{
				if (lungG < 2)
				{
					nuovoG = "0" + giorno;
					eval("document." + nomeForm + "." + nomeG + ".value = '" + nuovoG + "'");
				}
				
				if (lungM < 2)
				{
					nuovoM = "0" + mese;
					eval("document." + nomeForm + "." + nomeM + ".value = '" + nuovoM + "'");
				}
			}
		}
	}
	return risultato;
}

function ControllaPeriodo(nomeForm, gI, mI, aI, gF, mF, aF, gO, mO, aO)
{
	var gIni;
	var mIni;
	var aIni;
	var gFin;
	var mFin;
	var aFin;
	var noErrore = true;
	var esisteDataInizio = false;


	gIni = eval("document." + nomeForm + "." + gI + ".value");
	mIni = eval("document." + nomeForm + "." + mI + ".value");
	aIni = eval("document." + nomeForm + "." + aI + ".value");
	gFin = eval("document." + nomeForm + "." + gF + ".value");
	mFin = eval("document." + nomeForm + "." + mF + ".value");
	aFin = eval("document." + nomeForm + "." + aF + ".value");
		
	if ((gIni != "") || (mIni != "") || (aIni != ""))
	{
		esisteDataInizio = true;
	
		if (CheckDate(nomeForm, gI, mI, aI))
		{
			if(!(top.nascosto.document.applets.controlli.confrontoDate (gIni, mIni , aIni, gO, mO, aO, "<=")) )
			{
				alert("E' stata inserita una data di inizio periodo successiva a quella odierna");
				eval("document." + nomeForm + "." + gI + ".focus()");
				noErrore = false;
			}
		}
		else 
			noErrore = false;
	}
		
	if ((noErrore == true) && ((gFin != "") ||
				          (mFin != "") ||
				          (aFin != "")))
	{
		if (CheckDate(nomeForm, gF, mF, aF))
		{
			if(!(top.nascosto.document.applets.controlli.confrontoDate (gFin, mFin , aFin, gO, mO, aO, "<=")))
			{
				alert("E' stata inserita una data di fine periodo successiva a quella odierna");
				eval("document." + nomeForm + "." + gF + ".focus()");
				noErrore = false;
			}
			else
				if (esisteDataInizio)
				//eseguo il controllo sulla data solo se 
				{
					if(!(top.nascosto.document.applets.controlli.confrontoDate (gIni, mIni , aIni, gFin, mFin, aFin, "<=")))
					{
						alert("E' stata inserita una data di inizio successiva a quella di fine");
						eval("document." + nomeForm + "." + gF + ".focus()");
						noErrore = false;
					}
				}
		}
		else
			noErrore = false;
	}	
	return noErrore;
}

function EliminaSpazi(stringa)
{
	var i, lung;
	
	lung = stringa.length;
	senzaSpazi = "";
	
	for (i=0; i<lung; i++)
	{
		if (stringa.substring(i,i+1)==" ")
			senzaSpazi += "+";
		else
			senzaSpazi += stringa.substring(i,i+1);
	}
	
	return senzaSpazi;
}

function RilevaCampi(nomeForm)
{
	var i;
	var lung = eval("document." + nomeForm + ".elements.length");
	var parametri = "";
	var nomeCampo;
	var valCampo;
	var senzaSpazi;
	
	for (i = 0; i < lung; i++)
	{
		if ((eval("document." + nomeForm + ".elements[" + i + "].type")) == "text")
		{
			nomeCampo = eval("document." + nomeForm + ".elements[" + i + "].name");
			
			valCampo = eval("document." + nomeForm + ".elements[" + i + "].value");
			
			if (parametri != "")
				parametri += "&";
			
			parametri += nomeCampo + "=" + valCampo;
		}
		
		if (eval("document." + nomeForm + ".elements[" + i + "].type") == "select-one")
		{
			nomeCampo = eval("document." + nomeForm + ".elements[" + i + "].name");
			
			valCampo = eval("document." + nomeForm + ".elements[" + i + "].selectedIndex");
			
			//valCampo = eval("document." + nomeForm + ".elements[" + i + "].options[document." + nomeForm + ".elements[" + i + "].selectedIndex].value")
			
			if (parametri != "")
				parametri += "&";
			
			parametri += nomeCampo + "=" + valCampo;
		}
		
		if (eval("document." + nomeForm + ".elements[" + i + "].type") == "checkbox")
		{
			nomeCampo = eval("document." + nomeForm + ".elements[" + i + "].name");
			
			if (eval("document." + nomeForm + ".elements[" + i + "].checked"))
				valCampo = "1";
			else
				valCampo = "0";
			
			if (parametri != "")
				parametri += "&";
			
			parametri += nomeCampo + "=" + valCampo;
		}
	}
	
	senzaSpazi = EliminaSpazi(parametri);
	
	return senzaSpazi;
}

function TestaPlugin()
{
	var i, strFileName;
		
	for (i = 0; i < navigator.plugins.length; i++)
	{
		strFileName = navigator.plugins[i].filename;
			 
		if (strFileName.indexOf("NPSerialNT.dll")!= -1)
			return true;
	}
	
	return false;
}

function ErrorCallBack (co)
{
	var hwnd;
	
	hwnd = window.open('','WindowError');
	
	hwnd.document.write("Error Call Back<BR><BR><BR>");
	hwnd.document.write("status = " + co.status + "<BR><BR>");	
	hwnd.document.write("message = " + co.message + "<BR><BR>");
	hwnd.document.write("context = " + co.context + "<BR><BR>");
	hwnd.document.write("data = " + co.data);
}

//funzione che controlla se "numero" e' numerico
function isNumber(numero)
{
	var numStr="0123456789";
	var thisChar;
	var counter = 0;
	for (var i=0; i<numero.length; i++)
	{
		thisChar = numero.substring(i, i+1);
		if (numStr.indexOf(thisChar) != -1)
			counter++;
	}
	if (counter == numero.length)
		return true;
	else 
		return false;
}

//funzione che controlla se "numero" e' numerico (accetta anche decimali)
function isNumberDec(numero)
{
	var numStr="0123456789.";
	var thisChar;
	var counter = 0;
	var virgola = 0;
	for (var i=0; i<numero.length; i++)
	{
		thisChar = numero.substring(i, i+1);
		if (numStr.indexOf(thisChar) != -1)
			counter++;
		if (thisChar == ".")
			virgola++
	}
	if ((counter == numero.length) && (virgola <= 1))
		return true;
	else 
		return false;
}
	
function confrontaDate(data1, data2, oper) 
{
	var DateObj1 = new Date(getAnno(data1), getMese(data1) - 1, getGiorno(data1));
	var DateObj2 = new Date(getAnno(data2), getMese(data2) - 1, getGiorno(data2));
				
	var a = DateObj1.getVarDate();		
	var b = DateObj2.getVarDate();		
				
	return eval("a" + oper + "b");
}

//funzione che controlla che la data finale sia >= a quella iniziale
function checkCrono(giornoDa,meseDa,annoDa,giornoA,meseA,annoA)
{
	if (annoA < annoDa)
	{
		alert("La data finale deve essere maggiore o uguale alla data iniziale");		
		return false;
	}
	if (annoA > annoDa)
		return true;
		
	if (meseA < meseDa)
	{
		alert("La data finale deve essere maggiore o uguale alla data iniziale");	
		return false;
	}
	
	if (meseA > meseDa)
		return true;
	
	if (giornoA < giornoDa)
	{
		alert("La data finale deve essere maggiore o uguale alla data iniziale");		
		return false;
	}
	return true;
}

//funzione che controlla che la data sia reale (numerica/esistente)
function realData(giorno, mese, anno, msgErr)
{
	lungG = giorno.length;
	lungM = mese.length;				
	lungA = anno.length;

	if (AlfaNumerico(giorno,"N1") == false || AlfaNumerico(mese,"N1") == false || AlfaNumerico(anno,"N1") == false) ///!
	{
		alert("Data " + msgErr + ": non e' nel formato corretto (gg/mm/aaaa)");
		return false;
	}


	if (lungM != 2 || lungG != 2 || lungA < 4)
	{
		alert("Data " + msgErr + ": Inserire la data completa nel formato gg/mm/aaaa");	
		return false;
	}

	giorno = parseInt(giorno,10);
	mese = parseInt(mese,10);

	ris = isValidDate(giorno,mese,anno,msgErr)
	if (!ris)
		return false;
				
	return true;	
}

//funzione che lega 2 combo (codice a descrizione)
function associa(nomeForm,nome)
{
	nomeass = nome + "D";
	indice = eval("document." + nomeForm + ".elements[" + "nome].selectedIndex");
	valore = eval("document." + nomeForm + "." + nome + "[" + indice + "].value");
	max = eval("document." + nomeForm + ".elements[nomeass].length");
	for (i=0;i<max;i++)
	{
		if (eval("document." + nomeForm + "." + nomeass + "[" + i + "].value") == valore)
		{
			eval("document." + nomeForm + "." + nomeass + ".selectedIndex = " + i);
			return;
		}
	}		
}

//funzione che lega 2 combo (descrizione a codice)
function associaD(nomeForm,nome)
{
	nomeass = nome + "D";
	indice = eval("document." + nomeForm + ".elements[" + "nomeass].selectedIndex");
	valore = eval("document." + nomeForm + "." + nomeass + "[" + indice + "].value");
	max = eval("document." + nomeForm + ".elements[nome].length");
	for (i=0;i<max;i++)
	{
		if (eval("document." + nomeForm + "." + nome + "[" + i + "].value") == valore)
		{
			eval("document." + nomeForm + "." + nome + ".selectedIndex = " + i);
			return;
		}
	}		
}

//funzione che all'invio su una text inserisce una specifica data e 
//passa il focus ad un determinato campo
function insertDate(t,nomeForm,nomeG,nomeM,nomeA,nomeSucc)
{
	document.captureEvents(Event.KEYPRESS);
	document.onkeypress = blockA;
	tipo=t;
	myForm=nomeForm;
	giorno=nomeG;
	mese=nomeM;
	anno=nomeA;
	succ=nomeSucc;
}

function blockA(e) 
{
	var keyChar = e.which;
	var tipo;
	var myForm;
	var giorno;
	var mese;
	var anno;
	var succ;
	
	wholeString = eval("document." + myForm + "." + giorno + ".value");
	wholeString = wholeString + eval("document." + myForm + "." + mese + ".value");
	wholeString = wholeString + eval("document." + myForm + "." + anno + ".value");

	if ((keyChar == 13) && (wholeString == ""))
	{
		oggi = new Date();
		oggig = oggi.getDate();
		oggim = oggi.getMonth() + 1;
		oggia = oggi.getFullYear();
		
		if (tipo == 'i')
		{
			if (oggig < 10)
				oggig = "0" + oggig
			if (oggim < 10)
				oggim = "0" + oggim
			eval("document." + myForm + "." + giorno + ".value = '" + oggig + "'");
			eval("document." + myForm + "." + mese + ".value = '" + oggim + "'");
			eval("document." + myForm + "." + anno + ".value = " + oggia);
		}
		else if (tipo == 'f')
		{
			nGiorniMese = [31,28,31,30,31,30,31,31,30,31,30,31];		
			fineg = nGiorniMese[oggim-1];		
			if (oggig < 10)
				oggig = "0" + oggig
			if (oggim < 10)
				oggim = "0" + oggim
			eval("document." + myForm + "." + giorno + ".value = '" + fineg + "'");
			eval("document." + myForm + "." + mese + ".value = '" + oggim + "'");
			eval("document." + myForm + "." + anno + ".value = " + oggia);
		}
	eval("document." + myForm + "." + succ + ".focus()");
	}
}

function rilascia()
{
	document.releaseEvents(Event.KEYPRESS);
}

//funzione che controlla che quella inserita sia una data valida
function isValidDate(giorno, mese, anno, msgErr)
{
	dataV = false;
	if (anno > 1900)
	{
		nGiorniMese = [31,28,31,30,31,30,31,31,30,31,30,31];
		annoBisestile = (anno%4 == 0  && anno%100 != 0) || anno%400 == 0;
		if (mese < 13 && mese > 0)
		{
			if (giorno <= nGiorniMese[mese-1] && giorno > 0)
			{
				dataV = true;
			}
			else
			{
				if (mese ==2 && annoBisestile && giorno==29)
					dataV=true;
				else
				{
					dataV = false;
					alert("Data " + msgErr + ": Giorno non valido");
				}
			}
		}
		else
		{
			dataV=false;
			alert("Data " + msgErr + ": Mese non valido");
		}
	}
	else
	{
		dataV=false;
		alert("Data " + msgErr + ": Inserire una data posteriore al 1900");
	}

	return dataV;
}

//funzione che controlla che la data sia minore di quella odierna	
function dataPrec(data)
{	
	g = data.substring(0,2);	
	m = data.substring(3,5);	
	a = data.substring(6);	

	dataodierna = new Date();
	dataodiernaa = dataodierna.getFullYear();
	dataodiernam = dataodierna.getMonth() + 1;
	dataodiernag = dataodierna.getDate();

	if (a < dataodiernaa)
	{
		return true;
	}
	diffa = dataodiernaa - a;
	if ((diffa == 0) && (m < dataodiernam))
	{
		return true;
	}
	diffm = dataodiernam - m;
	if ((diffm == 0) && (g < dataodiernag))
	{
		return true;
	}
	return false;
}

//funzione che arrotonda un numero decimale con una data approssimazione 
function arrotonda(val,digits,round) 
{
    divfactor=1;
    for (j=0;j<digits;j++) 
    {
        divfactor*=10;
    }
    if (round) 
    {
        val2=Math.round(val*divfactor);
    }
    else 
    {
        val2=Math.floor(val*divfactor);
    }
    val2/=divfactor;

	val2 = "" + val2;
    posP = val2.indexOf(".");

    lung = val2.length;
    if ((lung-posP) == 0) 
        val2 += "00";
    if ((lung-posP) == 1) 
        val2 += "0";

    return val2
}

function PulisciCampiFrame(nomeFrame,nomeForm)
{
	var i = 0;
	var ind = 3;
	var lung = eval("parent.frames." + nomeFrame +".document." + nomeForm + ".elements.length")
	
	for (i = 0; i < lung; i++)
	{
		if ((eval("parent.frames." + nomeFrame +".document." + nomeForm + ".elements[" + i + "].type")) == "text")
			eval("parent.frames." + nomeFrame +".document." + nomeForm + ".elements[" + i + "].value=''")
		if ((eval("parent.frames." + nomeFrame +".document." + nomeForm + ".elements[" + i + "].type")) == "select-one")
			eval("parent.frames." + nomeFrame +".document." + nomeForm + ".elements[" + i + "].selectedIndex=0")
		if ((eval("parent.frames." + nomeFrame +".document." + nomeForm + ".elements[" + i + "].type")) == "checkbox")
			eval("parent.frames." + nomeFrame +".document." + nomeForm + ".elements[" + i + "].checked=false")
	}
	
	for (i = 0; i < lung; i++)
	{
		if ((eval("parent.frames." + nomeFrame +".document." + nomeForm + ".elements[" + i + "].type")) == "text")
		{	
			eval("parent.frames." + nomeFrame +".document." + nomeForm + ".elements[" + i + "].focus()")
			break;
		}
	}
}

function goBackFrame()
{
	var sUrl;
	if (bLock)
		return;
	bLock = true;
	top.frmStatus.StartWait();
	sUrl = window.top.nascosto.DeleteElement();
	parent.location = sUrl;
}

function CodingPassword(str, sKey)    
{
	var _str = "";
	var cnt;
	var _cnt;
	var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ,.:;!?/\|@#$%^&*()[]{}<>+=-_«»+-%";
		
	for (cnt = 0; cnt <= str.length; cnt++)
		for(_cnt = 0; _cnt <= letters.length; _cnt++)
			if (letters.substring(_cnt, _cnt + 1) == str.substring(cnt, cnt + 1))
			{     
				vv = _cnt + 13; 
				_str = _str + letters.substring(vv, vv + 1); 
			}
		
	return (_str);
}

//********************************************************************
//********************************************************************
//********************************************************************

//Verifica se un campo di tipo radio è attivo o no
//function VerificaRadio(posizione)
//{
//	var num_ele;
//	var esito = false;
//			
//	if (document.forms.length > 0)
//	{			
//		num_ele = posizione.elements.length;
//		for (var i=0; i < num_ele; i++)
//		{
//			if ((posizione.elements[i].type == "radio") && (posizione.elements[i].checked  == true))
//				esito = true;
//		}	
//	}
//	return esito;
//}

//Funzione per il controllo delle date
function isDate(data)
{
	var lungData;	
	var i;
	var sep = 0;
	var giorno = "";
	var mese = "";
	var anno = "";
		
	lungData = data.length;

	for (i=0; i <=lungData - 1 ; i++) 
	{
		if (data.charAt(i) == "/") 
		{
			sep = sep + 1;				
		}
		else 
		{
			if (sep == 0)
				giorno = giorno + data.charAt(i);
			if (sep == 1)
				mese = mese + data.charAt(i);
			if (sep == 2)
				anno = anno + data.charAt(i);

		}
	}
	if (sep != 2)
	{
		//alert("Inserire una data valida Es: dd/mm/aaaa");
		return false;	
	}
	else 
	{
		if ((AlfaNumerico(giorno,"N1") == false) || (giorno > 31) || (giorno == "") || (giorno == 0) || ((mese == 2) && (giorno > 29)))
		{
			//alert("il giorno non e' valido");
			return false;	
		}
		if (((mese == 11 || mese == 4 || mese == 6 || mese == 9) && giorno > 30) || (AlfaNumerico(mese,"N1") == false) || (mese > 12) || (mese == "") || (mese == 0)) 
		{
			//alert("il mese non e' valido");
			return false;	
		}
		if ((!isBisestile(anno) && ((mese == 2) && (giorno >= 29))) || (AlfaNumerico(anno,"N1") == false) || (anno < 1800) || (anno == "") || (anno.length > 4) || (anno == 0)) 
		{
			//alert("l' anno non e' valido");
			return false;	
		}			
	}			
	return true;
}

//Funzione per il controllo degli anni bisestili	
function isBisestile(anno)
{
	var resto1 = 0;
	var resto2 = 0;
	var resto3 = 0;

	resto1 = anno%4;
	resto2 = anno%100;
	resto3 = anno%400;
						
	if (resto1 == 0 && (resto2 != 0 || resto3 == 0))
		return true;
	else
		return false;
}
	
//Funzione per prelevare il campo giorno da una stringa data
function getGiorno(data) 
{
	var lungData;	
	var I;
	var sep = 0;
	var giorno = "";
	var mese = "";
	var anno = "";
			
	lungData = data.length;
			
	// verifico che ci siano due separatori e prendo i valori tra i separatori

	for (I=0; I <=lungData - 1 ; I++) 
	{
		if (data.charAt(I) == "/") 
			sep = sep + 1;				
		else {
			if (sep == 0)
				giorno = giorno + data.charAt(I);
			if (sep == 1)
				mese = mese + data.charAt(I);
			if (sep == 2)
				anno = anno + data.charAt(I);
		}
	}
	return giorno;
}
	
//Funzione per prelevare il campo mese da una stringa data
function getMese(data) 
{
	var lungData;	
	var I;
	var sep = 0;
	var giorno = "";
	var mese = "";
	var anno = "";
			
	lungData = data.length;
			
	// verifico che ci siano due separatori e prendo i valori tra i separatori

	for (I=0; I <=lungData - 1 ; I++) 
	{
		if (data.charAt(I) == "/") 
			sep = sep + 1;				
		else 
		{
			if (sep == 0)
				giorno = giorno + data.charAt(I);
			if (sep == 1)
				mese = mese + data.charAt(I);
			if (sep == 2)
				anno = anno + data.charAt(I);
		}
	}
	return mese;
}

//Funzione per prelevare il campo anno da una stringa data
function getAnno(data) 
{
	var lungData;	
	var I;
	var sep = 0;
	var giorno = "";
	var mese = "";
	var anno = "";
			
	lungData = data.length;
			
	// verifico che ci siano due separatori e prendo i valori tra i separatori

	for (I=0; I <=lungData - 1 ; I++) 
	{
		if (data.charAt(I) == "/") 
			sep = sep + 1;				
		else 
		{
			if (sep == 0)
				giorno = giorno + data.charAt(I);
			if (sep == 1)
				mese = mese + data.charAt(I);
			if (sep == 2)
				anno = anno + data.charAt(I);
		}
	}
	return anno;
}

//funzione che preleva il valore di un campo di tipo select-one
function getCmbValue(name) 
{
	var valore = "";
	var indice = name.selectedIndex;

	if( indice != -1)
	{
		valore = name.options[indice].value;
	}
	return valore;
}

// Controlla se un indirizzo e-mail e' valido
function isEmail(stringa)
{
	var i,ii;
	var j;
	var k,kk;
	var jj;
	var len;

	// Per essere valido si e' supposto che un indirizzo e-mail deve avere le seguenti caratteristiche:
	//
    // - deve avere un simbolo "@" ed un "."
    // - deve avere almeno un carattere prima della "@"
    // - deve avere almeno un carattere dopo la "@" e prima del "."
    // - deve avere almeno 2 caratteri dopo il "."

    if (stringa.length > 0)
    {
		i=stringa.indexOf("@");
		ii=stringa.indexOf("@",i+1);
		j=stringa.indexOf(".",i);
		k=stringa.indexOf(",");
		kk=stringa.indexOf(" ");
		jj=stringa.lastIndexOf(".")+1;
		len=stringa.length;
		if ((i>0) && (j>(1+1)) && (k==-1) && (ii==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3))
		{}
		else 
		{
				return false;
		}
	}
    return true;
}

//funzione che controlla i campi tipo ora
function isTime(stringa)
{
	var lunghezza_stringa;
	var separatore = 0;
	var ora = "";
	var minuti = "";

	lunghezza_stringa = stringa.length;
	for (var i=0; i <=lunghezza_stringa - 1 ; i++)
	{
		if (stringa.charAt(i) == ":") 
			separatore = separatore + 1;				
		else 
		{
			if ((separatore == 0))
				ora = ora + stringa.charAt(i);
			if ((separatore == 1))
				minuti = minuti + stringa.charAt(i);
		}
	}
	if ((AlfaNumerico(ora,"N1") == false) || (ora < 0) || (ora > 23))
		return false;	
	if ((AlfaNumerico(minuti,"N1") == false) || (minuti < 0) || (minuti > 59))
		return false;	
}

//funzione che controlla i numeri di telefono
function isPhone(numero)
{
	var stringa_controllo="0123456789/- ";
	var elemento;
	var contatore = 0;
	for (var i=0; i<numero.length; i++)
	{
		elemento = numero.substring(i, i+1);
		if (stringa_controllo.indexOf(elemento) != -1)
			contatore++;
	}
	if (contatore == numero.length)
		return true;
	else 
		return false;
}

//funzione che controlla se un campo è di tipo codice fiscale
function isCodiceFiscale(stringa)
{
	var primo_gruppo;
	var secondo_gruppo;
	var terzo_gruppo;
	var quarto_gruppo;
	var lunghezza_stringa;
	
	lunghezza_stringa = stringa.length;
	if (lunghezza_stringa != 16)
		return false
	else
	{
		primo_gruppo = stringa.substring(0, 3);
		secondo_gruppo = stringa.substring(3, 6);
		terzo_gruppo = stringa.substring(6, 11);
		quarto_gruppo = stringa.substring(11, 16);
		if ((AlfaNumerico(primo_gruppo,"A2") == false) || (AlfaNumerico(secondo_gruppo,"A2") == false))
			return false
		else
			if ((AlfaNumerico(terzo_gruppo,"B2") == false) || (AlfaNumerico(quarto_gruppo,"B2") == false))
				return false
	}
}

//Funzione che inserisce la data odierna in dei campi specifici 
//abilitando o disabilitando la proprieta readonly per essi
function ValorizzaCampiData(campo1,campo2,campo3,stato)
{
	//alert("ValorizzaCampiData")
	var data_odierna = new Date()
	var giorno	= "";
	var mese	= "";

	giorno = data_odierna.getDate();
	if ((giorno <= 9) && (giorno >=1)) giorno = "0" + giorno;
	mese = data_odierna.getMonth() + 1;
	if ((mese <= 9) && (mese >=1)) mese = "0" + mese;		

	if (stato == true)
	{
		eval("document." + document.forms[0].name + "." + campo1 + ".value = giorno");
		eval("document." + document.forms[0].name + "." + campo2 + ".value = mese");
		eval("document." + document.forms[0].name + "." + campo3 + ".value = data_odierna.getYear()");
		eval("document." + document.forms[0].name + "." + campo1 + ".readOnly = true");
		eval("document." + document.forms[0].name + "." + campo2 + ".readOnly = true");
		eval("document." + document.forms[0].name + "." + campo3 + ".readOnly = true");
	}
	else
	{
		eval("document." + document.forms[0].name + "." + campo1 + ".readOnly = false");
		eval("document." + document.forms[0].name + "." + campo2 + ".readOnly = false");
		eval("document." + document.forms[0].name + "." + campo3 + ".readOnly = false");		
	}
}	

//funzione per il controllo della alfanumericità
//-------------------------------------------------------------------
//I parametri da passare saranno:
//
//	STRINGA:		rappresenta la stringa di catatteri da controllare
//
//	CONTROLLO:		stringa di due caratteri (il primo alfabetico ed
//					il secondo numerico che indicheranno i controlli
//					da fare
//
//	Tipi di CONTROLLO:		A1	Albabetico Minuscolo
//							A2	Albabetico Maiuscolo
//							A3	Albabetico Maiuscolo + Minuscolo + Spazio
//							B1	AlbaNumerico Minuscolo
//							B2	AlbaNumerico Maiuscolo
//							B3	AlbaNumerico Maiuscolo + Minuscolo + Spazio + Punto
//							N1	Numerico Intero
//							N2	Numerico Decimale
//
//-------------------------------------------------------------------
function AlfaNumerico(stringa,controllo)
{
	var virgola = 0;
	var elemento = "";
	var contatore = 0;
	var StrSpazio = " ";
	var StrPunto = ".";
	var StrVirgola = ",";
	var StrNumerico = "0123456789";
	var StrAlfabeticoMinuscolo = "abcdefghilmnopqrstuvzwyjkx@€#°.&()+-%!:;";
	var StrAlfabeticoMaiuscolo = "ABCDEFGHILMNOPQRSTUVZWYJKX@€#°.&()+-%!:;";
	var StrAlfabetoAccentato="àèìòù";
	var strApice="'-/_" + "\"";
	switch (controllo)
	{
		//Alfabetico Minuscolo
		case "A1" :
		{
			StrRicerca = StrAlfabeticoMinuscolo;
			//alert(StrRicerca);
		}
		break;
		//Alfabetico Maiuscolo
		case "A2" :
		{
			StrRicerca = StrAlfabeticoMaiuscolo;
			//alert(StrRicerca);
		}
		break;
		//Alfabetico Maiuscolo e Minuscolo con Spazio
		case "A3" :
		{
			StrRicerca = StrAlfabeticoMaiuscolo + StrAlfabeticoMinuscolo + StrSpazio;
			//alert(StrRicerca);
		}
		break;
		//AlfaNumerico Minuscolo
		case "B1" :
		{
			StrRicerca = StrAlfabeticoMinuscolo + StrNumerico;
			//alert(StrRicerca);
		}
		break;
		//AlfaNumerico Maiuscolo
		case "B2" :
		{
			StrRicerca = StrAlfabeticoMaiuscolo + StrNumerico;
			//alert(StrRicerca);
		}
		break;
		//AlfaNumerico Maiuscolo e Minuscolo con Spazio
		case "B3" :
		{
			StrRicerca = StrAlfabeticoMaiuscolo + StrAlfabeticoMinuscolo + StrNumerico + StrSpazio + StrVirgola + StrPunto  + strApice + StrAlfabetoAccentato;
			//alert(StrRicerca);
		}
		break;
		//Numerico Intero
		case "N1" :
		{
			StrRicerca = StrNumerico + ',';
			//alert(StrRicerca);
		}
		break;
		//Numerico Decimale
		case "N2" :
		{
			StrRicerca = StrNumerico + StrVirgola;
			//alert(StrRicerca);
		}
		break;
		case "N3" :
		{
			StrRicerca = StrNumerico + StrVirgola + StrPunto;
			//alert(StrRicerca);
		}
		break;
		case "N4" :
		{
			StrRicerca = StrNumerico;
			//alert(StrRicerca);
		}
		break;				
	}
	
	for (var y=0; y<stringa.length; y++)
	{
		elemento = stringa.substring(y, y+1);
		if (StrRicerca.indexOf(elemento) != -1)
			contatore++;
		if ((controllo == "N2") && (elemento == ","))
			virgola++;
	}
	
	if (controllo == "N2")
		if ((contatore == stringa.length) && (virgola <= 1))
			return true;
		else 
			return false;
	else
		if (contatore == stringa.length)
			return true;
		else 
			return false;	
}

//Esegue vari controlli sui campi di una form
function VerificaCampi(intForm)
{
	var controllo_obbligatorio;
	var controllo_tipo;
	var stringa_msg;
	var id_campo;
	var valore_campo;
	var num_ele;
	var giorno = "";
	var mese = "";
	var anno = "";
	var esito = true;	
	var temp = 0;
	var posizione
	
	if ((intForm!=0) && (intForm!=""))  
		posizione = eval("document." + document.forms[intForm].name);
	else
		posizione = eval("document." + document.forms[0].name);
		
	if (document.forms.length > 0)
	{			
		num_ele = document.forms[intForm].elements.length//posizione.elements.length;
		for (var i=0; i < num_ele; i++)
			if ((posizione.elements[i].type != "hidden") &&  (posizione.elements[i].type != "file"))
			{
				id_campo = posizione.elements[i].id;
				valore_campo = posizione.elements[i].value;
				controllo_tipo = id_campo.charAt(5);
				controllo_obbligatorio = id_campo.charAt(4);
				stringa_msg = id_campo.substring(7,id_campo.length);
				switch (posizione.elements[i].type)
				{
					//Controllo campi di tipo password
					case "password" :
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
						if ((posizione.elements[i].value != "") && (AlfaNumerico(valore_campo,"B3") == false))
						{
							alert("Dati inseriti non di tipo alfa-numerico");
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}						
					break;					
					//Controllo campi di tipo text
					case "text" : 
						//Controllo particolare per le date quando solo dei campi sono valorizzati
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "N") &&(controllo_tipo == "D"))
							if ((posizione.elements[i+1].value != "") || (posizione.elements[i+2].value != ""))
							{
								alert("Data non valida");
								posizione.elements[i].focus();
								esito = false;
								return esito;
								exit;
							}
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "N") &&(controllo_tipo == "M"))
							if ((posizione.elements[i-1].value != "") || (posizione.elements[i+1].value != ""))
							{
								alert("Data non valida");
								posizione.elements[i-1].focus();
								esito = false;
								return esito;
								exit;
							}
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "N") &&(controllo_tipo == "Y"))
							if ((posizione.elements[i-2].value != "") || (posizione.elements[i-1].value != ""))
							{
								alert("Data non valida");
								posizione.elements[i].focus();
								esito = false;
								return esito;
								exit;
							}
						// Controllo campi obbligatori
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
						if (posizione.elements[i].value != "")
							switch (controllo_tipo)
							{
								//Controllo se il campo e' di tipo alfabetico
								case "A" :
									if (AlfaNumerico(valore_campo,"A3") == false)
									{
										alert("Dati inseriti non di tipo alfabetico");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo numerico
								case "N" :
									if (AlfaNumerico(valore_campo,"N3") == false)
									{
										alert("Dati inseriti non di tipo numerico");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								case "B" :
									if (AlfaNumerico(valore_campo,"N4") == false)
									{
										alert("Dati inseriti non di tipo numerico");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo e-mail
								case "E" :
									if (isEmail(valore_campo) == false)
									{
										alert("Dati inseriti non di tipo e-mail");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo numero-telefonico
								case "P" :
									if (isPhone(valore_campo) == false)
									{
										alert("Dati inseriti non di tipo numero-telefono");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo time									
								case "T" :
									if (isTime(valore_campo) == false)
									{
										alert("Dati inseriti non di tipo ora");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo data-campi-non-separati
								case "G" :
									if (isDate(valore_campo) == false)
									{
										alert("Dati inseriti non di tipo data");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo data-campi-separati: giorno
								case "D" :
									giorno = posizione.elements[i].value;
								break;
								//Controllo se il campo e' di tipo data-campi-separati: mese
								case "M" :
									mese = posizione.elements[i].value;
								break;
								//Controllo se il campo e' di tipo data-campi-separati: anno
								case "Y" :
									anno = posizione.elements[i].value;
									if ((AlfaNumerico(giorno,"N1") == false) || (giorno > 31) || (giorno == 0) || ((mese == 2) && (giorno > 29)))
									{
										alert("Dati relativi al giorno non validi");
										posizione.elements[i-2].focus();
										esito = false;
										return esito;
										exit;
									}
									if (((mese == 11 || mese == 4 || mese == 6 || mese == 9) && giorno > 30) || (AlfaNumerico(mese,"N1") == false) || (mese > 12) || (mese == 0))
									{
										alert("Dati relativi al mese non validi");
										posizione.elements[i-1].focus();
										esito = false;
										return esito;
										exit;
									}
									if ((!isBisestile(anno) && ((mese == 2) && (giorno >= 29))) || (AlfaNumerico(anno,"N1") == false) || (anno < 1800) || (anno == 0))
									{
										alert("Dati relativi all'anno non validi");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo codice fiscale
								case "C" :
									if (isCodiceFiscale(valore_campo) == false)
									{
										alert("Dati inseriti non di tipo codice fiscale");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}								
								break; 
								//Controllo se il campo e' di tipo Currency
								case "I" :
									if ((AlfaNumerico(valore_campo,"N2") == false) )
									{
										alert("Dati inseriti non di tipo Valuta");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;

								case "H" :
									if (AlfaNumerico(valore_campo,"B3") == false)
									{
										alert("Dati inseriti non di tipo alfa-numerico");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;								
							}
					break;
					//Controllo campi di tipo textarea
					case "textarea" :
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
					break;					
					//Controllo campi di tipo checkbox
					case "checkbox" :
						if ((posizione.elements[i].checked  == false) && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
					break;
					//Controllo campi di tipo radio					
					case "radio" :
						if ((posizione.elements[i].checked  == false) && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
					break;					
					//Controllo campi di tipo select-one
					case "select-one" :
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
					break;
				}	
		}
	}
	return esito;
}

//Esegue vari controlli sui campi di una form con la presenza di Layer
function VerificaCampiLayer(pos)
{
	var controllo_obbligatorio;
	var controllo_tipo;
	var stringa_msg;
	var id_campo;
	var valore_campo;
	var num_ele;
	var giorno = "";
	var mese = "";
	var anno = "";
	var esito = true;	
	var temp = 0;
	var posizione

	//if (pos == "N")
	//	posizione = eval("document." + document.forms[0].name);
	//else
		posizione = eval(pos);
		
	if (document.forms.length > 0)
	{			
		num_ele = posizione.elements.length;
		for (var i=0; i < num_ele; i++)
			if (posizione.elements[i].type != "hidden")
			{
				id_campo = posizione.elements[i].id;
				valore_campo = posizione.elements[i].value;
				controllo_tipo = id_campo.charAt(5);
				controllo_obbligatorio = id_campo.charAt(4);
				stringa_msg = id_campo.substring(7,id_campo.length);
				switch (posizione.elements[i].type)
				{
					//Controllo campi di tipo password
					case "password" :
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
						if ((posizione.elements[i].value != "") && (AlfaNumerico(valore_campo,"B3") == false))
						{
							alert("Dati inseriti non di tipo alfa-numerico");
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}						
					break;					
					//Controllo campi di tipo text
					case "text" : 
						//Controllo particolare per le date quando solo dei campi sono valorizzati
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "N") &&(controllo_tipo == "D"))
							if ((posizione.elements[i+1].value != "") || (posizione.elements[i+2].value != ""))
							{
								alert("Data non valida");
								posizione.elements[i].focus();
								esito = false;
								return esito;
								exit;
							}
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "N") &&(controllo_tipo == "M"))
							if ((posizione.elements[i-1].value != "") || (posizione.elements[i+1].value != ""))
							{
								alert("Data non valida");
								posizione.elements[i-1].focus();
								esito = false;
								return esito;
								exit;
							}
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "N") &&(controllo_tipo == "Y"))
							if ((posizione.elements[i-2].value != "") || (posizione.elements[i-1].value != ""))
							{
								alert("Data non valida");
								posizione.elements[i].focus();
								esito = false;
								return esito;
								exit;
							}
						// Controllo campi obbligatori
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
						if (posizione.elements[i].value != "")
							switch (controllo_tipo)
							{
								//Controllo se il campo e' di tipo alfabetico
								case "A" :
									if (AlfaNumerico(valore_campo,"A3") == false)
									{
										alert("Dati inseriti non di tipo alfabetico");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo numerico
								case "N" :
									if (AlfaNumerico(valore_campo,"N3") == false)
									{
										alert("Dati inseriti non di tipo numerico");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								case "B" :
									if (AlfaNumerico(valore_campo,"N4") == false)
									{
										alert("Dati inseriti non di tipo numerico");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo e-mail
								case "E" :
									if (isEmail(valore_campo) == false)
									{
										alert("Dati inseriti non di tipo e-mail");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo numero-telefonico
								case "P" :
									if (isPhone(valore_campo) == false)
									{
										alert("Dati inseriti non di tipo numero-telefono");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo time									
								case "T" :
									if (isTime(valore_campo) == false)
									{
										alert("Dati inseriti non di tipo ora");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo data-campi-non-separati
								case "G" :
									if (isDate(valore_campo) == false)
									{
										alert("Dati inseriti non di tipo data");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo data-campi-separati: giorno
								case "D" :
									giorno = posizione.elements[i].value;
								break;
								//Controllo se il campo e' di tipo data-campi-separati: mese
								case "M" :
									mese = posizione.elements[i].value;
								break;
								//Controllo se il campo e' di tipo data-campi-separati: anno
								case "Y" :
									anno = posizione.elements[i].value;
									if ((AlfaNumerico(giorno,"N1") == false) || (giorno > 31) || (giorno == 0) || ((mese == 2) && (giorno > 29)))
									{
										alert("Dati relativi al giorno non validi");
										posizione.elements[i-2].focus();
										esito = false;
										return esito;
										exit;
									}
									if (((mese == 11 || mese == 4 || mese == 6 || mese == 9) && giorno > 30) || (AlfaNumerico(mese,"N1") == false) || (mese > 12) || (mese == 0))
									{
										alert("Dati relativi al mese non validi");
										posizione.elements[i-1].focus();
										esito = false;
										return esito;
										exit;
									}
									if ((!isBisestile(anno) && ((mese == 2) && (giorno >= 29))) || (AlfaNumerico(anno,"N1") == false) || (anno < 1800) || (anno == 0))
									{
										alert("Dati relativi all'anno non validi");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								//Controllo se il campo e' di tipo codice fiscale
								case "C" :
									if (isCodiceFiscale(valore_campo) == false)
									{
										alert("Dati inseriti non di tipo codice fiscale");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}								
								break; 
								//Controllo se il campo e' di tipo partita iva
								case "V" :
									if ((AlfaNumerico(valore_campo,"N1") == false) || (valore_campo.length < 11))
									{
										alert("Dati inseriti non di tipo partita iva");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;
								case "H" :
									if (AlfaNumerico(valore_campo,"B3") == false)
									{
										alert("Dati inseriti non di tipo alfa-numerico");
										posizione.elements[i].focus();
										esito = false;
										return esito;
										exit;
									}
								break;								
							}
					break;
					//Controllo campi di tipo textarea
					case "textarea" :
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
					break;					
					//Controllo campi di tipo checkbox
					case "checkbox" :
						if ((posizione.elements[i].checked  == false) && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
					break;
					//Controllo campi di tipo radio					
					case "radio" :
						if ((posizione.elements[i].checked  == false) && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
					break;
					//Controllo campi di tipo select-one
					case "select-one" :
						if ((posizione.elements[i].value == "") && (controllo_obbligatorio == "S"))
						{
							alert("Campo obbligatorio: " + stringa_msg);
							posizione.elements[i].focus();
							esito = false;
							return esito;
							exit;
						}
					break;
				}	
		}
	}
	return esito;
}

//Verifica se almeno una chiave di ricerca è stata selezionata
function ControlloVuoto()
{
	var num_ele;
	var posizione;

	posizione = eval("document." + document.forms[0].name);
	if (document.forms.length > 0)
	{			
		num_ele = posizione.elements.length;
		//alert(num_ele);
		for (var i=0; i < num_ele; i++)
		{
			//alert(i);
			if (posizione.elements[i].type != "hidden")
			{
				switch (posizione.elements[i].type)
				{
					//Controllo campi di tipo password
					case "password" :
						if (posizione.elements[i].value != "")
							return true;
					break;					
					//Controllo campi di tipo text
					case "text" : 
						if (posizione.elements[i].value != "")
							return true;
					break;
					//Controllo campi di tipo checkbox
					case "checkbox" :
						if (posizione.elements[i].checked  == true)
							return true;
					break;
					//Controllo campi di tipo select-one
					case "select-one" :
						if (posizione.elements[i].value != "")
							return true;
					break;
				}
			}
		}	
	}
	alert("Effettuare almeno una scelta");
}

//Verifica se due date sono entrambe valorizzate
function ControlloDataDoppia(ggIn,mmIn,aaIn,ggOut,mmOut,aaOut)
{
	var num_ele;
	var posizione;
	var id_campo;
	var controllo_tipo;
	var contatore = 0;
	var data_inizio;
	var data_fine;
	
	posizione = eval("document." + document.forms[0].name);
	if (document.forms.length > 0)
	{			
		num_ele = posizione.elements.length;
		for (var i=0; i < num_ele; i++)
		{
			if (posizione.elements[i].type != "hidden")
			{
				id_campo = posizione.elements[i].id;
				controllo_tipo = id_campo.charAt(5);
				if (posizione.elements[i].type == "text")
				{
					if ((controllo_tipo == "D") || (controllo_tipo == "M") || (controllo_tipo == "Y"))
					{
						if (posizione.elements[i].value != "")
						{
							contatore = contatore + 1
						}
					}
				}
			}
		}	
	}
	if (contatore == 0)
		return true;
	if ((contatore == 6) || (contatore == 12))
	{

		//data_inizio = ConcatenaData('Txt_GiornoInizio','Txt_MeseInizio','Txt_AnnoInizio','inizio');
		data_inizio = ConcatenaData(ggIn,mmIn,aaIn,'inizio');
		//alert(data_inizio);
		//data_fine = ConcatenaData('Txt_GiornoFine','Txt_MeseFine','Txt_AnnoFine','fine');			
		data_fine = ConcatenaData(ggOut,mmOut,aaOut,'fine');			
		//alert(data_fine);
		if (data_inizio > data_fine)
		{
			alert("Date non valide");
			return false;
		}
		else
			return true;
	}
	alert("Valorizzare entrambe le date");
}

//Verifica se almeno un CheckBox è selezionato
function ControllaSelezionaCheckBox()
{
	var num_ele;
	var posizione;

	posizione = eval("document." + document.forms[0].name);
	if (document.forms.length > 0)
	{			
		num_ele = posizione.elements.length;
		for (var i=0; i < num_ele; i++)
		{
			if (posizione.elements[i].type != "hidden")
				if (posizione.elements[i].type == "checkbox")
					if (posizione.elements[i].checked  == true)
						return true
		}
	}
	alert("Selezionare almeno un record");
}

//controlla che sia selezionato uno ed un solo record
function ControllaSelezionaCheckBox1()
{
		var num_ele;
		var posizione;
		var cnt = 0
		
		posizione = eval("document." + document.forms[0].name);
		if (document.forms.length > 0)
		{			
			num_ele = posizione.elements.length;
			for (var i=0; i < num_ele; i++)
			{
				if (posizione.elements[i].type != "hidden")
					if (posizione.elements[i].type == "checkbox")
						if (posizione.elements[i].checked  == true)
							cnt = cnt + 1
			}
		}
		if(cnt == 0)
			alert("Selezionare un record");
		if(cnt > 1)
			alert("Non è possibile selezionare più di un record");
}	

//Seleziona tutti i CheckBox presenti in una pagina
function SelezionaCheckBox()
{
	var num_ele;
	var posizione;

	posizione = eval("document." + document.forms[0].name);
	if (document.forms.length > 0)
	{			
		num_ele = posizione.elements.length;
		for (var i=0; i < num_ele; i++)
		{
			if (posizione.elements[i].type != "hidden")
				if (posizione.elements[i].type == "checkbox")
					if (posizione.elements[i].checked  == false)
						posizione.elements[i].checked = true
		}
	}		
	Seleziona()
}
	
//Deseleziona tutti i CheckBox presenti in una pagina
function DeselezionaCheckBox()
{
	var num_ele;
	var posizione;

	posizione = eval("document." + document.forms[0].name);
	if (document.forms.length > 0)
	{			
		num_ele = posizione.elements.length;
		for (var i=0; i < num_ele; i++)
		{
			if (posizione.elements[i].type != "hidden")
				if (posizione.elements[i].type == "checkbox")
					if (posizione.elements[i].checked  == true)
						posizione.elements[i].checked = false
		}
	}		
	//Seleziona()
}

//Concatena i campi data aggiungendo un orario standard
function ConcatenaData(campo1,campo2,campo3,ctrl)
{		
	var giorno	= ""
	var mese	= ""
	var anno	= ""
	var data	= ""		

	giorno = eval("document." + document.forms[0].name + "." + campo1 + ".value")
	if(giorno.length == 1)
		giorno = "0" + giorno
		
	mese = eval("document." + document.forms[0].name + "." + campo2 + ".value")
	if(mese.length == 1)
		mese = "0" + mese
		
	anno = eval("document." + document.forms[0].name + "." + campo3 + ".value")
	
	data = anno + mese + giorno
	
	if((ctrl == "inizio") && (data != ""))
		data = data + "000000"
		
	if ((ctrl == "fine") && (data != ""))
		data = data + "235959"

	return data
}

function CompletaData(campo1,campo2,campo3)
{
	var giorno	= "";
	var mese	= "";
	var anno	= "";
	var data	= "";		

	giorno = eval("document." + document.forms[0].name + "." + campo1 + ".value");
	if (giorno.length == 1) giorno = "0" + giorno;
	mese = eval("document." + document.forms[0].name + "." + campo2 + ".value");
	if (mese.length == 1) mese = "0" + mese;
	anno = eval("document." + document.forms[0].name + "." + campo3 + ".value");

	
	var campo1
	var campo2
	var campo3
	
	campo1 = eval("document." + document.forms[0].name + "." + campo1) 
	campo2 = eval("document." + document.forms[0].name + "." + campo2) 
	campo3 = eval("document." + document.forms[0].name + "." + campo3) 
	
	
	campo1.value = giorno
	campo2.value = mese
	campo3.value = anno	
	
	return
}

//Verifica che la data iniziale sia minore di quella finale
function VerificaDate(inizio,fine)
{
	var DataInizio = ""
	var DataFine = ""
	
	DataInizio = inizio.substring(0,8);
	DataFine = fine.substring(0,8);
	posizione = eval("document." + document.forms[0].name);
	
	if (DataInizio > DataFine)
	{
		alert("Data inizio maggiore di data fine");
		posizione.elements[0].focus();
		return false;
		exit;
	}	
	return true;
}

function SetStatusBar(value)
{
	var Itl = value * 1936.27
	var ItlTemp = arrotonda(Itl,0,1) 
	top.frmStatus.document.objStatusBar.Panels.Item(2).text = FormattaImporti(ItlTemp)
}

function ResetStatusBar()
{
	top.frmStatus.document.objStatusBar.Panels.Item(2).text = ""
}


function FormattaImporti(value)
{
	var pos = value.search(".")
	var dec = ""
	var int = ""
	
	if(pos)
	{
		var dec = value.substr(pos,value.lenght)
		alert (dec)
		var int = value.substr(1,pos)
		alert (int)
	}
	else
	{
		int = value	
		var lng = int.length 
		var tempIn = int		
		var tempOut = ""
		var counter = 1
		for(j=lng;j>0;j--)
		{
				crt = tempIn.charAt(j-1)
				if(counter > 3)
				{
					tempOut = tempOut + "."
					counter = 1
				}
				tempOut = tempOut + crt
				counter++
		}
		var lng = tempOut.length 
		tempIn = ""
		for(j=lng;j>0;j--) // reverse 
		{
			tempIn = tempIn + tempOut.charAt(j-1)
		}

	}	
	if(dec != "")
		return(tempIn + "," + dec)
	else
		return(tempIn)
}

//Funzione di conversione Lire-Euro
function ConversioneLireEuro(valore)
{
	valore = valore / 1936.27
	valore = arrotonda(valore,2,1)
	return valore
}

//Funzione di conversione Euro-Lire
function ConversioneEuroLire(valore)
{
	valore = valore * 1936.27
	valore = arrotonda(valore,2,1)
	return valore
}

//Funzione per il controllo delle eventuali modifiche apportate
function VerificaModifiche() 
{
	var mod = false
	var	posizione

	posizione = eval("document." + document.forms[0].name);

	if (document.forms.length > 0) 
	{
		var Ele = posizione.elements.length;

		for (var i=0; i < Ele; i++) 
		{
			//Controllo generale
			if ((posizione.elements[i].type != "hidden") && (posizione.elements[i].type != "select-one") && (posizione.elements[i].type != "checkbox"))
				if (posizione.elements[i].defaultValue != posizione.elements[i].value)
				{
					//alert("modifica altri");
					mod = true;
				}
			//Controllo separato per i checkbox ed i radio buttom
			if ((posizione.elements[i].type == "checkbox") || (posizione.elements[i].type == "radio"))
				if (posizione.elements[i].defaultChecked != posizione.elements[i].checked)
				{
					//alert("modifica per checkbox o radio");
					mod = true;
				}
			//Controllo separato per i select-one
			if (posizione.elements[i].type == "select-one")
			{
				var indice 
					
				indice = eval("document." + document.forms[0].name + "." + posizione.elements[i].name + ".selectedIndex");

				if (eval("document." + document.forms[0].name + "." + posizione.elements[i].name + ".options[" + indice + "].defaultSelected") !=
					eval("document." + document.forms[0].name + "." + posizione.elements[i].name + ".options[" + indice + "].selected"))
					{
						//alert("modifica per select-one");
						mod = true;						
					}						
			}
		}		
	}
	return mod;
}
	


// la funzione FormattaImporto viene chiamata dall'evento onfocus che si verifica sui campi importo
function FormattaImporto(Campo)
{
	var OldImporto,NewImporto;
	var i,Posizione;
		
	Posizione = eval(document.forms[0].name + "." + Campo);		
	OldImporto = Posizione.value;
	NewImporto = "";
		
	if (OldImporto != "")
	{
		for (i=0;i<OldImporto.length;i++)
		{
			if (OldImporto.substr(i,1) != '.')
				NewImporto = NewImporto.toString() + OldImporto.substr(i,1).toString();
				
		}			
	}
	Posizione.value = NewImporto;
	
}
	
// la funzione ControlloImporto viene chiamata dall'evento onblur che si verifica sui campi importo
function ControlloImporto(Campo)
{

	var OldImporto,NewImporto,ImportoOriginale,OldImportoAppo;
	var Trovato = false;
	var esc = false;
	var FlagMeno = false;
	var i,j,NumeroCifre,PosizioneVirgola,Cifra,PosizioneCifra,CifraDecimale,NumeroVirgole,Posizione;
	var Carattere,Meno;
	
	Posizione = eval(document.forms[0].name + "." + Campo);		
	NewImporto = "";
	OldImporto = Posizione.value;
	OldImportoAppo = "";  			
	Meno = "";

	if (OldImporto.substr(0,1) == '-')
	{
		FlagMeno = true;
		Meno = OldImporto.substr(0,1);
		OldImporto = OldImporto.substr(1,OldImporto.length);	
	}
		
	// Controlliamo che il testo non sia vuoto	
	if (OldImporto.length == 0) 
	{
		Posizione.value = '0';
		return true;
	}


	// Controlliamo se il testo è tutti zero
	i=0;
	Carattere = OldImporto.substr(i,1);
	if (Carattere == '0')
	{
		while ((OldImporto.substr(i,1) =='0') || (OldImporto.substr(i,1) ==',') || (OldImporto.substr(i,1) =='.') )
			i++;

		if (i== OldImporto.length)
		{
			Posizione.value = '0';
			return true;
		}
	}



	i=0;
	//Scorriamo tutta la stringa	
	while (i < OldImporto.length)
	{
		j=i;
		Carattere = OldImporto.substr(i,1);
		
		//Controlliamo la presenza di caratteri vuoti nella stringa
		if (Carattere == ' ')
		{
			alert("Importo errato!");
			return false;		
		}

		if (Carattere != ",") 
		{
			if ((isNaN(Carattere)) && (Carattere != '-') && (Carattere != '.')) 
			{
				alert("Importo errato!");
				return false;
			}
			
		}
		
		if ((Carattere == "-") && (i != '0'))
		{
			alert("Importo errato!");
			return false;
		}	
				
		//Se ci sono diversi 0 all'inizio ne lasciamo solo uno
		if ((Carattere == '0') && (i == 0))
		{
			j++;
			//scorriamo gli eventuali zero
			while (OldImporto.substr(j,1) == '0') 
				j++;	
			
			if (OldImporto.substr(j,1) == ',')
			{
				OldImportoAppo = "0";

			}
		}
		
		i=j;

		if (j<OldImporto.length)
		{
			Carattere = OldImporto.substr(i,1);
			OldImportoAppo = OldImportoAppo + Carattere;
			j++;
		}
		else
			OldImportoAppo = '0';
		
		i++;
	}
	

	OldImporto = OldImportoAppo;
	if (OldImporto != "")	
	{
		
		NumeroVirgole = 0;
							
		for (i=0;i<OldImporto.length;i++)
		{
			if (OldImporto.substr(i,1) != '.')
				NewImporto = NewImporto.toString() + OldImporto.substr(i,1).toString();
			
			if (OldImporto.substr(i,1) == ',')
				NumeroVirgole = parseInt(NumeroVirgole,10) + 1;
		}
			
					
		if (parseInt(NumeroVirgole,10) <= 1)
		{			
			OldImporto = NewImporto;
			
			i=0;
			while ((i<OldImporto.length) && (Trovato==false))
			{
				if (OldImporto.substr(i,1)==",")
				{
					Trovato = true;
					PosizioneVirgola = i; 
				}
				i++;
			}
			
			if (NumeroVirgole != 0)
			{
				CifraDecimale = OldImporto.substr(PosizioneVirgola+1,OldImporto.length);
				PosizioneCifra = PosizioneVirgola-1;
			}
			else
			{
				CifraDecimale = "";
				PosizioneCifra = OldImporto.length - 1;
			}
				
			if (PosizioneCifra != -1)
			{
				NumeroCifre = 0;
				Cifra = "";
				i=1;
		
				while (PosizioneCifra >= 0)
				{
					if (NumeroCifre != 3)
					{	
						NumeroCifre = NumeroCifre + 1;
						Cifra = OldImporto.substr(PosizioneCifra,1).toString() + Cifra.toString();
						PosizioneCifra--;
					}
					else
					{
						NumeroCifre = 0;
						Cifra = "." + Cifra;
					}
				} 
				
				if (CifraDecimale != "")	
					Posizione.value = Cifra + "," + CifraDecimale.toString();		
				else
					Posizione.value = Cifra;
			}
			else
			{
				alert("Importo errato!");
				return false;
			}		
		}
		else
		{
			alert("Importo errato!");
			return false;
		}
	}
	
	Posizione.value = Meno + Posizione.value;
	return true;
}

//La funzione EliminaPunti viene chiamata dalla funzione Ricalcola che si trova all'interno delle pag. ASP.
// A tale funzione viene passato il valore contenuto nel campo input-box
function EliminaPunti(CifraOld)
{
	var CifraNew,CifraFinale;
	var i;
		
	
	CifraNew = "";	
	if (CifraOld != "")
	{
		for (i=0;i<CifraOld.length;i++)
		{
			if (CifraOld.substr(i,1) != '.')
				CifraNew = CifraNew.toString() + CifraOld.substr(i,1).toString();
		}			

		CifraFinale = "";
	
		for (i=0;i<CifraNew.length;i++)
		{
			if (CifraNew.substr(i,1) != ',')	
				CifraFinale = CifraFinale + CifraNew.substr(i,1);
			else
				CifraFinale = CifraFinale + '.';
	
		}
	
	//	alert("CifraFinale=" + CifraFinale);			

		return CifraFinale;			
	}
}	


function ConvertiPuntoInVirgola(CifraOld)
{
	CifraFinale = "";
	
	for (i=0;i<CifraOld.length;i++)
	{
		if (CifraOld.substr(i,1) != '.')	
			CifraFinale = CifraFinale + CifraOld.substr(i,1);
		else
			CifraFinale = CifraFinale + ',';
	}
	
	return CifraFinale;			
	
	
}

function DoppioClickCheck(NomeCheck)
{
	var Posizione;

	Posizione = eval(document.forms[0].name + "." + NomeCheck);		
	
	if (Posizione.checked==true)
	{
		Posizione.click();
		Posizione.click();
	}
	
}