			//
			// CHECK KEY PRESS
			// 
			function checkKeyPress()
			{
				if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;					
		    }
		    //
			function validateNumber()
			{											
				if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;					
		    }
		    //
			// 
			// 			
			function checkTel()
			{																			
				alert(event.keyCode);				
				if ((event.keyCode < 48 || event.keyCode > 57) || event.keyCode != 43) event.returnValue = false;					
		    }
			//
			// CHECK FORMAT DATE
			// 			
			
			function CheckFormatDate(sDate)
			{
		
				var sMsg = "";
				var sGiorno = "";
				var sMese = "";
				
				if (sDate.length != 0)
				{
					if  ( (sDate.length != 8) && (sDate.length != 10) )
						sMsg = 'La lunghezza della data non è valida!\n(formati ammessi: DD/MM/YY o DD/MM/YYYY)';
					else
					{		
						if  ( !( (sDate.substr(2,1) == '/') && (sDate.substr(5,1) == '/') ) )
							sMsg = 'La data inserita non è valida! \n(formati ammessi: DD/MM/YY o DD/MM/YYYY)';
						else
						{
							sGiorno = (sDate.substr(0,1) == '0' ? sDate.substr(1,1) : sDate.substr(0,2) ) ;
							sMese	= (sDate.substr(3,1) == '0' ? sDate.substr(4,1) : sDate.substr(3,2) ) ;
							// Debugging 
							//alert( parseInt(sGiorno) + ' - ' + parseFloat(sMese) );
							if ( (parseInt(sGiorno) > 31) || (parseInt(sMese) > 12) || (parseInt(sGiorno) < 1) || (parseInt(sMese) < 1)  )
								sMsg = 'Giorno o mese non validi!';
						}	

					}
			
					if (sMsg != '')
					{						
						window.event.returnValue = false; 						
						alert(sMsg);
						window.event.srcElement.focus();
						return(false);
					}
				}
			}
			//
			// Controllo della data
			//
			function IsValidDate(sDate,oObject)
			{
			obj = sDate.replace(/[^\d]/g,"0");
   
   
			gg = (obj.substr(0,1) == '0' ? sDate.substr(1,1) : sDate.substr(0,2) ) ;
			mm = (obj.substr(3,1) == '0' ? sDate.substr(4,1) : sDate.substr(3,2) ) ;
   
			//gg = obj.substr(0,2);
			//mm = obj.substr(3,2);
			aa = obj.substr(6,4);
   
			strdata = gg + "/" + mm + "/" + aa;
   
			data = new Date(parseInt(aa),parseInt(mm)-1,parseInt(gg));
			daa = data.getFullYear().toString();
			dmm = (data.getMonth()+1).toString();
			dmm = dmm.length==1?"0"+dmm:dmm
			dgg=data.getDate().toString();
			dgg=dgg.length==1?"0"+dgg:dgg
			dddata=dgg+"/"+dmm+"/"+daa
						
			if ((dddata!=strdata)&&(oObject.value!=''))
			   {			  
			   alert("La data inserita non è valida!" + "\n" + "Inserire una data corretta di" + "\n" + "questo tipo: [dd/mm/yyyy].");			   
			   oObject.focus();
			   oObject.value=""; 			   			 
			   }
			}
			//
			// Controllo Partita IVA
			//
			function ControllaPIVA(pi)
			{						
				//
				var sMsg = "";
				//				
				if( pi == '' )  return '';
				if( pi.length != 11 )
				{
					alert("La lunghezza della partita iva non è corretta.\n" + "Digitare 11 cifre.\n");					
					window.event.srcElement.focus();
					return false;
				}
																																							
				s = 0;
				for( i = 0; i <= 9; i += 2 )
					s += pi.charCodeAt(i) - '0'.charCodeAt(0);
				for( i = 1; i <= 9; i += 2 ){
					c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
					if( c > 9 )  c = c - 9;
					s += c;
				}
				if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )		
				{						
					alert( "La partita iva non è valida!");							
					window.event.srcElement.focus();
					return false;
				}
										
			}
			
			function ControllaInOut(pmValue)
			{				
				if (pmValue == '0,00')
				{					
					window.event.srcElement.value='';
				}
			}
			
			
			//
			// Controlla codice fiscale
			//
			function ControllaCF(cf)
			{
				var sMsg = '';
				var validi, i, s, set1, set2, setpari, setdisp;
				if( cf == '' )
				{
					sMsg = '';
				}else{
					cf = cf.toUpperCase();
					if( cf.length != 16 )
					{
						sMsg = "La lunghezza del codice fiscale non è corretta:\n"
						+ "il codice fiscale deve essere"
						+ " di 16 caratteri!\n";
					}else{
						validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
						for( i = 0; i < 16; i++ ){
							if( validi.indexOf( cf.charAt(i) ) == -1 )
								sMsg = "Il codice fiscale contiene un carattere non valido " +
									cf.charAt(i) +
									"'.\nI caratteri validi sono le lettere e le cifre.\n";
						}
						if (sMsg == '' )
						{						
							set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
							set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
							setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
							setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
							s = 0;
							for( i = 1; i <= 13; i += 2 )
								s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
							for( i = 0; i <= 14; i += 2 )
								s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
							if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
							{
								sMsg = "Il codice fiscale non è corretto:\nil codice di controllo non corrisponde.\n";
							}
						}
					}
					
				}
				if (sMsg != '' )
				{
					alert (sMsg);
					window.event.srcElement.focus();
					return false;
				}
			}
			//
			// Show Div
			//
			function ShowDiv(sText)
			{								
				if (sText.length > 15)
				{														
					oDiv.style.position = "absolute";																					
					oDiv.style.top = document.body.scrollTop + event.clientY + 20 ; 
					oDiv.style.left = 8 //document.body.scrollLeft + event.clientX -120;										
					oDiv.style.visibility='visible';
					oDiv.innerText = ' ' + sText;
				}else{
					oDiv.style.visibility='hidden';
				}
			}
			//
			function HideDiv()
			{
				oDiv.style.visibility='hidden';
			}			
			//
			// Inserimento solo numerico
			//
			function isNumeric(pmNum)
			{			  
			   if(isNaN(pmNum))
			   {			      
			      event.srcElement.value = "";
			      event.srcElement.focus();	
			      alert("Inserire valori numerici!");
			      return;		      
			   }
			}
			//
			// Inserimento quantità corretta
			//
			function isQuantity(pmNum)
			{			  				
			   if (isNaN(pmNum)||(pmNum=="")||(pmNum==0))
			   {						     
			      event.srcElement.value = "";
			      event.srcElement.focus();	
			      alert("Inserire una quantità valida!");
			      return;		      
			   }
			}
			//
			// Format Currency
			//
			function FormatCurrency(num)
			{
				var punto
				var virgola
				punto = num.indexOf('.')
				virgola = num.indexOf(',')
				
				if (punto != -1)
				{
					num = num.toString().replace(/\$|\./g,'');
					
				}
				if(virgola != -1)
				{
					num = num.toString().replace(/\$|\,/g,'.');
				}
				if(isNaN(num))
					num = "0";
					sign = (num == (num = Math.abs(num)));
					num = Math.floor(num*100+0.50000000001);
					cents = num%100;
					num = Math.floor(num/100).toString();
					if(cents<10)
					cents = "0" + cents;
					for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
						num = num.substring(0,num.length-(4*i+3))+'.'+
						num.substring(num.length-(4*i+3));
						return (((sign)?'':'-') + num + ',' + cents);				
			}
			//
			// Controllo email valida
			//	
			function CheckEmail(indirizzo)
			{
				if (indirizzo != "")
				{
					if (window.RegExp)
					{
					  var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
					  var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
					  var regnv = new RegExp(nonvalido);
					  var regv = new RegExp(valido);
					  if (!regnv.test(indirizzo) && regv.test(indirizzo))
					    return true;
					  return false;
					}else {				
					  if(indirizzo.indexOf("@") >= 0)
					    return true;
					  return false;
					}
				}else{
					return true;
				}				
			}
			//			
			//
			//
			function openWin(PageName,Width,Height)
			{
				var hWin
				var left = (screen.width - Width)/2; //360;
				var top = (screen.height - Height)/2; // 117;
				var sOption;

				if (hWin != null) hWin.close();
					sOption = 'Width=' + Width + ',';
					sOption += 'Height=' + Height + ',';
					sOption += 'resizable=no,';
					sOption += 'Title="test",';
					sOption += 'scrollbars =no,';
					sOption += 'left=' + left + ',';
					sOption += 'top=' + top + ',';
					hWin = window.open(PageName,'',sOption,true);
			}
			//			
			function openWinlista(PageName,Width,Height)
			{
				var hWin
				var left = (screen.width - Width)/2; //360;
				var top = (screen.height - Height)/2; // 117;
				var sOption;

				if (hWin != null) hWin.close();
					sOption = 'width=' + Width + ',';
					sOption += 'height=' + Height + ',';
					sOption += 'resizable=no,';					
					sOption += 'scrollbars =yes,';
					sOption += 'left=' + left + ',';
					sOption += 'top=' + top + ',';					
					sOption += 'toolbar=yes';	
					hWin = window.open(PageName,'',sOption,true);
			}
