	/*
		Testa se la lunghezza del testo contenuto sia uguale
		a quella passata e passa il fuoco all'elemento successivo
	*/
	
	function changeFocus(InputObj, InputLen) {
		if (InputObj.value.length == InputLen) {
			var i;
			for (i = 0; i < InputObj.form.length; i++)
				if (InputObj.form.elements[i].name == InputObj.name)
					break;
	
			i += 1;
			if (i < InputObj.form.length)
				InputObj.form.elements[i].focus();
		}
	}


	/*
		Testa se la lunghezza del testo contenuto sia uguale
		a quella passata e passa il fuoco all'elemento corrente + offset
	*/
	
	function changeFocusOffset (InputObj, InputLen, offset) {
		if (InputObj.value.length == InputLen) {
			var i;
			for (i = 0; i < InputObj.form.length; i++)
				if (InputObj.form.elements[i].name == InputObj.name)
					break;
	
			i += offset;
			if (i < InputObj.form.length)
				InputObj.form.elements[i].focus();
		}
	}      

	function getFormElement (obj, offset) {
			var i;
			
			for (i = 0; i < obj.form.length; i++)
				
				if (obj.form.elements[i].name == obj.name)
					break;
			i += offset;

			if (i < obj.form.length)
				return obj.form.elements[i];
	}   

	function enableRadioOffset (InputObj, offset) {
			var i;
			for (i = 0; i < InputObj.form.length; i++)
				if (InputObj.form.elements[i].name == InputObj.name)
					break;
	
			i += offset;
			//alert(InputObj.form.elements[i].name);
			if (i < InputObj.form.length)
				InputObj.form.elements[i].checked = true;
	} 	  
	
	function adjustCF(filedCF) {
		var result = "";
		var value = "";
		var format = "LLLLLLNNLNNLNONL";
		var c, f;
		value = filedCF.value.toUpperCase();
		if (value.length == format.toString().length) {
			for (var i=0 ; i< format.length; i++) {
				c = "" + value.substring(i, i+1);
				f = "" + format.substring(i, i+1);
				if (f=="L" && c == "0") c = "O"
				if (f=="L" && c == "1") c = "I"
				if (f=="N" && c == "O") c = "0"
				if (f=="N" && c == "I") c = "1"
				result += c;
				
			}
			//alert(result);
		} else {
			result = filedCF.value;
		}
		return result;
		
	}
	  
	  
	  function adjustDate(myDate) {
                if (isNumeric(myDate)) {
                        //alert('Non sono stati inseriti i separatori');
                        if (myDate.toString().length == 6) {
                                var date = new Date();
                                myDate = myDate.toString();
                                myDate = myDate.substr(0,2) + '/' + myDate.substr(2,2)+'/'+((parseInt('20'+myDate.substr(4,2)) > (parseInt(date.getFullYear())+10))?'19':'20')+myDate.substr(4,2);                                
                                //myDate = parseDate(myDate, Array('dd','mm','yy'));
                                //myDate = formatDate(myDate, parseDateFormat(getLocaleInfo("shortDate")));
                        } else if (myDate.length == 8){
                                myDate = myDate.substr(0,2) + '/'+myDate.substr(2,2)+'/'+myDate.substr(4,4);                            
                                //myDate = parseDate(myDate, Array('dd','mm','yyyy'));
                                //myDate = formatDate(myDate, parseDateFormat(getLocaleInfo("shortDate")));
                        } else {
                                alert('Formato data non Corretto!');
                        }
                } else {
                                                // Corregge giorno e mese
                        if (isNumeric(myDate.substr(0,1)) && !isNumeric(myDate.substr(1,1))) {
                                                        //giorno con una cifra: "1/"
                                                        myDate = '0'+myDate;
                                                }
                        if ( isNumeric(myDate.substr(3,1)) && !isNumeric(myDate.substr(4,1)) ) {
                                                        //mese con una cifra: "01/1/06"
                                                        myDate =  myDate.substr(0,3)+'0'+myDate.substr(3,myDate.length-3);
                                                }

                        //Sostituisce tutti i separatori con '/'
                        if (myDate.toString().length == 8 && isNumeric(myDate.substr(0,2)+myDate.substr(3,2)+myDate.substr(6,2))) {
                               //Formato 01ç01ç06
                                                            var date = new Date();
                                myDate = myDate.substr(0,2) + '/'+myDate.substr(3,2)+'/'+((parseInt('20'+myDate.substr(6,2))> (date.getFullYear()+10))?'19':'20')+myDate.substr(6,2);                                
                        } else if (myDate.length == 10 && isNumeric(myDate.substr(0,2)+myDate.substr(3,2)+myDate.substr(6,4))){
                               //Formato 01ç01ç2006
                                myDate = myDate.substr(0,2) + '/'+myDate.substr(3,2)+'/'+myDate.substr(6,4);                            
                        } else {
                                alert('Formato data non Corretto!');
                        }
                }
                //alert(myDate);
                return myDate;
        }


	  function adjustTime(value) {
		  	var sep = '.';
			var err=0;
			var myDate = value;
                if (isNumeric(myDate)) {
					//alert('Non sono stati inseriti i separatori');
					if (myDate.toString().length == 3) {
							myDate = '0'+myDate.substr(0,1) + sep + myDate.substr(1,2);                                
					} else if (myDate.length == 4){
							myDate = myDate.substr(0,2) + sep + myDate.substr(2,2);                                
					} else {
							err=1;
					}
                } else {
					// Corregge l'ora
					if (myDate.toString().length == 4 && isNumeric(myDate.substr(0,1)) && !isNumeric(myDate.substr(1,1))) {
							//ora con una cifra: "9:"
							myDate = '0'+myDate;
					}
                }
 
				//Sostituisce tutti i separatori con ':'
				if (myDate.toString().length == 5 && isNumeric(myDate.substr(0,2)+myDate.substr(3,2))) {
				var h = myDate.substr(0,2);
					var n = myDate.substr(3,2);
					//verifica la correttezza dell'orario
					if (parseInt(h)<24 && parseInt(n)<60 && parseInt(h)>=0 && parseInt(n)>=0 ) {
						myDate = h + sep + n;
					} else {
						err=1;
					}
				}
				//alert(myDate);
				if (err==0) {
					return myDate;
				} else {
					alert('Formato data non Corretto!');
					return value;
				}

		 }


        function checkFieldDate(field) {
                var d;
                d = adjustDate(field.value);
                if (d != "") field.value = d;
        }
        
		function checkFieldTime(field) {
                var d;
                d = adjustTime(field.value);
                if (d != "") field.value = d;
        }
//*****************************
//Funzione che verifica che il campo in input sia numerico.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************

function isNumeric (value){
	var valid = "0123456789";
	var ok = "yes";
	var temp;
	for (var i=0; i<value.length; i++) {
			temp = "" + value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1")
					ok = "no";
	}
	if (ok == "no") {
			return false;
	}
	return true;
}
		
function isFieldNumeric (field){
	if (!isNumeric(field.value)) {
		alert("Valore non valido! Per questo campo sono ammessi solo numeri!");
		field.focus();
		field.select();
		return false;
   	}
	return true;
}


		
//*****************************
//Funzione che verifica che il campo in input sia numerico con segno.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************

function isDigitWithSign(field, divisa){
	var valid = "";
	var ok = "yes";
	var temp;
	var begin;

	if (divisa.toUpperCase() == "ITL")
		valid = "0123456789";
	else
		valid = "0123456789,";

   	if ( (field.value.substring(0, 1) == "+" ) || (field.value.substring(0, 1) == "-" ) ) begin = 1;
   	else  begin = 0;

	for (var i=begin; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = "no";
	}
	if (ok == "no") {
		if (divisa.toUpperCase() == "ITL")
			alert("Valore non valido! Per questo campo sono ammessi solo numeri con segno e senza virgola!");
		else
			alert("Valore non valido! Per questo campo sono ammessi solo numeri con segno!");

		field.focus();
		field.select();
		return false;
   	}
	return true;
}





//*****************************
//Funzione che verifica che la STRINGA in input sia alfabetico.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************

function isLetter (stringa){
	var valid = "abcdefghilmnopqrstuvzwyjkxABCDEFGHILMNOPQRSTUVZWYJKX";
	var ok = "yes";
	var temp;
	for (var i=0; i<stringa.length; i++) {
		temp = "" + stringa.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = "no";
	}
	if (ok == "no") {
		return false;
   	}
	return true;
}

//*****************************
//Funzione che verifica che il campo in input sia alfabetico.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************

function letter (field){
	var valid = "abcdefghilmnopqrstuvzwyjkxABCDEFGHILMNOPQRSTUVZWYJKX";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") {
			ok = "no";
		}
	}
	if (ok == "no") {
	    alert("Valore non valido! Per questo campo sono ammesse solo lettere!");
		field.focus();
		field.select();
		return false;
   	}
	return true;
}

//*****************************
//Funzione che verifica che il campo in input sia alfabetico o con spazi.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************

function letterWithSpace (field){
        var valid = "abcdefghilmnopqrstuvzwyjkx'ABCDEFGHILMNOPQRSTUVZWYJKX";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") {
			if (temp != " ")
   {
				ok = "no";
   }
		}
	}
	if (ok == "no") {
	    alert("Valore non valido! Per questo campo sono ammesse solo lettere!");
		field.focus();
		field.select();
		return false;
   	}
	return true;
}


//*****************************
//Funzione che verifica se un campo in input e' vuoto.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************


function isEmpty (field)
{  	if (field.value.length == 0)
		return true;
   	else
		return false;
}


//*******************************************************************
//Funzione che verifica che la data (gg,mm,aa) in input sia corretta.
//*******************************************************************

function verificaData (ggObj, mmObj, aaObj, dataObj ){

	var gg = togliSpazi(ggObj);
	var mm = togliSpazi(mmObj);
	var aa = togliSpazi(aaObj);
	var date = new String("");
        if(!((gg == "") && (mm == "") && (aa == ""))) {
                if( !(gg == "") && !(mm == "") && !(aa == "") ) {
			if(gg.length == 1) {
				ggObj.value = "0" + gg;
				gg = ggObj.value;
			}
			if(mm.length == 1) {
				mmObj.value = "0" + mm;
				mm = mmObj.value;
			}
			if(aa.length == 4) {
				dataObj.value = gg + "/" + mm + "/" + aa;
				if (!(chkdate(dataObj))) return false;
			}
			else return false;

		}
		else return false;

	}
	return true;
}

//*******************************************************************
//Funzione che verifica che la data in input sia corretta.
//*******************************************************************

function checkdate(objName) {
	var datefield = objName;
	if (chkdate(objName) == false) {
		datefield.select();
		alert("Data non valida. Inserire data valida.");
		datefield.focus();
		return false;
	}
	else {
		return true;
	}
}

function chkdate(objName) {
	//var strDatestyle = "US"; United States date style
	var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "01";
	strMonthArray[1] = "02";
	strMonthArray[2] = "03";
	strMonthArray[3] = "04";
	strMonthArray[4] = "05";
	strMonthArray[5] = "06";
	strMonthArray[6] = "07";
	strMonthArray[7] = "08";
	strMonthArray[8] = "09";
	strMonthArray[9] = "10";
	strMonthArray[10] = "11";
	strMonthArray[11] = "12";
	strDate = datefield.value;
	if (strDate.length < 1) {
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	        }
	}
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	if (strYear.length == 2) {
		if (strYear < 95)
			strYear = '20' + strYear;
		else
			strYear = '19' + strYear;
	}
	if (strYear.length == 3) {
		return false;
	}
	// US style

	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
			}
		}
		else {
			if (intday > 28) {
				err = 10;
				return false;
			}
		}
	}
	if (strDatestyle == "US") {
		datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
	}
	else {
		if (intday < 10)
			datefield.value = "0" + intday + "/" + strMonthArray[intMonth-1] + "/" + strYear;
		else
			datefield.value = intday + "/" + strMonthArray[intMonth-1] + "/" + strYear;
	}
	return true;
	}

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) {
			return true;
		}
	}
	else {
		if ((intYear % 4) == 0) {
			return true;
		}
	}
	return false;
}


function doDateCheck(from, to) {
	var ggFrom = new String(from.value.substring(0,2));
	var mmFrom = new String(from.value.substring(3,5));
	var aaFrom = new String(from.value.substring(6,10));
	var datafrom = new Number(aaFrom+mmFrom+ggFrom);
	var ggTo = new String(to.value.substring(0,2));
	var mmTo = new String(to.value.substring(3,5));
	var aaTo = new String(to.value.substring(6,10));
	var datato = new Number(aaTo+mmTo+ggTo);
	if (datafrom < datato)
		return true;
	else
		return false;
}

function doDateCheckE(from, to) {
	var ggFrom = new String(from.value.substring(0,2));
	var mmFrom = new String(from.value.substring(3,5));
	var aaFrom = new String(from.value.substring(6,10));
	var datafrom = new Number(aaFrom+mmFrom+ggFrom);
	var ggTo = new String(to.value.substring(0,2));
	var mmTo = new String(to.value.substring(3,5));
	var aaTo = new String(to.value.substring(6,10));
	var datato = new Number(aaTo+mmTo+ggTo);
	if (datafrom <= datato)
		return true;
	else
		return false;
}

//  End -->
//</script>
//</HEAD>
//<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->
//<BODY>
//<center>
//	<form>
//		<pre>
//			From date <input type=text name=from onBlur="checkdate(this)" size=11 maxlength=11>
//			To date   <input type=text name=to   onBlur="checkdate(this)" size=11 maxlength=11>
//			<input type=button name=formatbutton onClick="doDateCheck(this.form.from, this.form.to);" value="Check">
//		</pre>
//	</form>
//</center>
//<p><center>
//	<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
//	by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
//</center><p>
//<!-- Script Size:  4.34 KB -->
//The following date formats are accepted:
//mm-dd-yyyy, mm/dd/yyyy, mm.dd.yyyy, mm dd yyyy,
//mmm dd yyyy, mmddyyyy, m-d-yyyy, m/d/yyyy, m.d.yyyy,
//m d yyyy, mmm d yyyy, m-d-yy, m/d/yy, m.d.yy, m d yy,
//mmm d yy (yy is 20yy)
//(Accepted EU formats just switch month and day)

//********************************
// Funzione TXLenght(object):
// Controlla se il testo va oltre la dimensione predefinita di TextArea
// (nel caso del campo descrizione di Tesorerie 50 × 3 = 150 caratteri).

function TXLenght(obj) {
	if ((obj.scrollTop) != 0) {
		alert("Il campo non puo' contenere piu' di 150 caratteri!!");
		return false;
	} else
	return true;
}

//****************************************
// Funzione formatAmount(object,divisa): (3 Funzioni)
// Mette i punti nelle cifre, sistema i decimali
// (centesimi), e fa i controlli di validita';
// da chiamare su onBlur .

function checkComma(obj,type) {
	var z = 0;
	var commaOccur = 0;

	while (z < obj.value.length) {
		if (obj.value.substr(z,1)== ",") commaOccur++;
		if (type == "EUR") {
			if (commaOccur > 1) {
				alert("Cifra non valida, e' consentita al massimo una virgola.");
				return false;
			}
		}
		else {
			if (commaOccur > 0) {
				alert("Cifra non valida, non sono consentite virgole");
				return false;
			}
		}
		z++;
	}
	return true;
}

function isAmount(obj,type) {
	var valid
	var ok = "yes";
	var temp;

	switch(type) {
		case "EUR" :
			valid = "0123456789,";
			break;
		case "ITL" :
			valid = "0123456789";
			break;
		default :
			alert("Non e' stato specificato nella funzione il tipo di formato da adottare");
			ok = "no";
			break;
	}

	var begin = 0;
   	if ( (obj.value.substring(0, 1) == "+" ) || (obj.value.substring(0, 1) == "-" ) ) begin = 1;


	for (var i=begin; i<obj.value.length; i++) {
		temp = "" + obj.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = "no";
	}
	if (ok == "no") {
		return false;
   	}
	else {
		if (!checkComma(obj,type))
			return false;
		else
			return true;
	}
}

function formatAmount(obj,type) {
	var num = obj.value;
	if (num == "") {
		num = "";
		return true;
	}
	if (!isAmount(obj,type)) {
                alert("Cifra non valida 1");
		obj.focus();
		obj.select();
		return false;
	}
	num = num.toString().replace(',','.');
	num = num.toString().replace(/\$|\,/g,'');
	var neg = "";
	if (num.substring(0,1) == "-")
	{
		neg = "-";
		num = num.substring(1);
	}
	cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
	if (type == "ITL") {
		if (num.length > 13) {
			alert ("Questo importo non puo' essere piu' lungo di 13 cifre!");
			obj.focus();
			obj.select();
			return false;
		}
	}
	else {
		if (num.length > 13) {
			alert ("Questo importo non puo' avere piu' di 13 cifre intere");
			obj.focus();
			obj.select();
			return false;
		}
	}
	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));
	}
	if (type == "EUR") {
		obj.value = (neg + num + ',' + cents);
		return true;
	}
	else {
		obj.value = (neg + num);
		return true;
	}
}

//////////////////////////////////////////////////////////////////////////////////////
//  VARIANTE DELLA formatAmount CHE APPROSSIMA ALLA decSize-ESIMA CIFRA DECIMALE    //
//  L'IMPORTO,EVENTUALMENTE AGGIUNGENDO DEGLI ZERI ALLA PARTE DECIMALE.             //
//////////////////////////////////////////////////////////////////////////////////////

function formatAmountDec(obj,intSize,decSize)
{
	var num = obj.value;
	if (num == "") {
		num = "";
		return true;
	}
	if (!isAmount(obj,"EUR")) {
                alert("Cifra non valida 2");
		obj.focus();
		obj.select();
		return false;
	}
	var cost = 1;
	for (var i = 0; i < decSize; i++)
		cost = cost * 10;
	//alert("cost = "+cost);
	num = num.toString().replace(',','.');
	num = num.toString().replace(/\$|\,/g,'');
	//alert("Num 1 : "+num);
	var neg = "";
	if (num.substring(0,1) == "-")
	{
		neg = "-";
		num = num.substring(1);
	}
	//alert("Num 2 : "+num);
	cents = Math.floor((num*cost+0.5)%cost).toString();
	//alert("cents = "+cents);
	num = Math.floor((num*cost+0.5)/cost).toString();
	//alert("num 3 = "+num)
	if (num.length > intSize) {
		alert ("Questo importo non puo' avere piu' di "+intSize+" cifre intere");
		obj.focus();
		obj.select();
		return false;
	}
	while (cents.length < decSize)
		cents = "0" + cents;
	//alert(" new cents = "+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));
	}
	obj.value = (neg + num + ',' + cents);
	return true;
}

///////////////////////////////////  FINE VARIANTE formatAmount  /////////////////////////////


//****************************************
// Funzione unformatAmount(this.value):
// Toglie i punti nelle cifre e sistema i decimali
// (centesimi); da chiamare su onFocus

function unformatAmount (obj){
	var importo = new String(obj.value);
	var temp = new String(obj.value);
	temp = importo.replace (".","");
	var ciclo = true;
	if (temp == importo)
	{
		obj.value = importo;
		obj.focus();
		obj.select();
		return true;
	}
	while (ciclo == true){
		temp = importo.replace (".","");
		if (temp == importo)
		{
			obj.value = temp;
			obj.focus();
			obj.select();
			ciclo = false;
			return true;
		}
		importo = temp;
	}
	obj.value = importo;
	obj.focus();
	obj.select();
	return true;
}

////////////////// COPIA DI UNFORMAT E FORMAT SENZA FOCUS /////////////////////////////

function unformatAmountSF (obj){
	var importo = new String(obj.value);
	var temp = new String(obj.value);
	temp = importo.replace (".","");
	var ciclo = true;
	if (temp == importo)
	{
		obj.value = importo;
		return true;
	}
	while (ciclo == true){
		temp = importo.replace (".","");
		if (temp == importo)
		{
			obj.value = temp;
			ciclo = false;
			return true;
		}
		importo = temp;
	}
	obj.value = importo;
	return true;
}

function formatAmountSF(obj,type) {
	var num = obj.value;
	if (num == "") {
		num = "";
		return true;
	}
	if (!isAmount(obj,type)) {
                alert("Cifra non valida 3");
		return false;
	}
	num = num.toString().replace(',','.');
	num = num.toString().replace(/\$|\,/g,'');
	var neg = "";
	if (num.substring(0,1) == "-")
	{
		neg = "-";
		num = num.substring(1);
	}
	var cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
	if (type == "ITL") {
		if (num.length > 13) {
			alert ("Questo importo non puo' essere piu' lungo di 13 cifre!");
			return false;
		}
	}
	else {
		if (num.length > 13) {
			alert ("Questo importo non puo' avere piu' di 13 cifre intere");
			return false;
		}
	}
 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));
	}
	if (type == "EUR") {
		obj.value = (neg + num + ',' + cents);
  return true;
	}
	else {
		obj.value = (neg + num);
		return true;
	}
}

//////////////////////////// FINE COPIA UNFORMAT E FORMAT ///////////////////////////////

function UCase(obj)
{
	var valore = new String (obj.value);
	obj.value = valore.toUpperCase();
	return true;
}

function togliPunti (valore){
	var importo = new String(valore);
	var temp = new String(valore);
	temp = importo.replace (".","");
	var ciclo = true;
	if (temp == importo)
	{
		return temp.replace(",",".");
	}
	while (ciclo == true){
		temp = importo.replace (".","");
		if (temp == importo)
		{
			ciclo = false;
			return temp.replace(",",".");
		}
		importo = temp;
	}
	return temp.replace(",",".");
}

//Controlla se un valore numerico è zero
function isZero(obj){
	var num = obj.value;
	if ((num == "0")||(num == "0,00")||(num == ""))
		return true;
	else
		return false;
}

//Toglie gli spazi a destra del campo
function togliSpazi(obj){
	var appoggio = new String(obj.value);
	var ciclo = true;
	var lunghezza = new Number(appoggio.length);
	while (ciclo == true){
		ciclo = false;
		lunghezza = new Number(appoggio.length);
		temp = appoggio.substring(lunghezza-1,lunghezza);
		if (temp == " ")
		{
			appoggio = appoggio.substring(0,lunghezza-1);
			ciclo = true;
		}
	}
	obj.value = appoggio;
	return appoggio;
}

function formatAmountWithoutReturning0(obj, type) {
	if (isEmpty(obj))
		return false;
	else {
		return formatAmount(obj,type);
	}
}

// inserita da simona p. il 11/3/2002
function ctrlPunto() {
  // I CARATTERI UNICODE COMPRESI TRA 48 E 57 SONO LE CIFRE DA 0 A 9.
  if ((event.keyCode < 48) || (event.keyCode > 57)) {
        // IL CARATTERE UNICODE 46 E' IL PUNTO, IL 44 E' LA VIRGOLA E IL 45 E' IL MENO
        if (event.keyCode == 46) {
                event.keyCode = 44;
                return true;
        }
        else if (event.keyCode == 44) {
                return true;
        }
        else {
                return false;
        }
  }
  else {
        return true;
  }
}

// inserita da simona p. il 11/3/2002
function ctrlPuntoMeno() {
  // I CARATTERI UNICODE COMPRESI TRA 48 E 57 SONO LE CIFRE DA 0 A 9.
  if ((event.keyCode < 48) || (event.keyCode > 57)) {
        // IL CARATTERE UNICODE 46 E' IL PUNTO, IL 44 E' LA VIRGOLA E IL 45 E' IL MENO
        if (event.keyCode == 46) {
                event.keyCode = 44;
                return true;
        }
        else if ( (event.keyCode == 44) || (event.keyCode == 45) ) {
                return true;
        }
        else {
                return false;
        }
  }
  else {
        return true;
  }
}

// inserita da Massimo il 19/3/2002
// Permette di inserire solo i numeri da 0 a 9 e le lettere da a a z e da A a Z
// Utilizzata nel controllo del codice fiscale
function ctrlLetterAndDigit() {
  // I CARATTERI UNICODE COMPRESI TRA 48 E 57 SONO LE CIFRE DA 0 A 9.
  // I CARATTERI UNICODE COMPRESI TRA 65 E 90 SONO LE LETTERE MAIUSCOLE
  // I CARATTERI UNICODE COMPRESI TRA 97 E 122 SONO LE LETTERE MINUSCOLE
  if ( ((event.keyCode >= 48) && (event.keyCode <= 57)) ||
       ((event.keyCode >= 65) && (event.keyCode <= 90)) ||
       ((event.keyCode >= 97) && (event.keyCode <= 122))
     ) {
        return true;
       }
  else {
        return false;
  }
}

function cambiaCSS(file_scelto) {
   var elenco = document.getElementsByTagName("link");
   var tagstile;
   for (n=0;n<elenco.length;n++) if(elenco[n].media=="screen") tagstile = elenco[n];
   tagstile.href = file_scelto;
   
   setCookie("oloCMScss", file_scelto, 30)
}

function caricaCSS(file_scelto) {
	cambiaCSS(getCookie('oloCMScss'));
}

function setCookie(sNome, sValore, iGiorni) {
	var dtOggi = new Date()
	var dtExpires = new Date()
	dtExpires.setTime
	(dtOggi.getTime() + 24 * iGiorni * 3600000)
	document.cookie = sNome + "=" + escape(sValore) + "; expires=" + dtExpires.toGMTString();
}

// restituisce il valore del cookie sNome
function getCookie(sNome) {
	// genera un array di coppie "Nome = Valore" // NOTA: i cookies sono separati da ';'
	var asCookies = document.cookie.split("; ");
	// ciclo su tutti i cookies
	for (var iCnt = 0; iCnt < asCookies.length; iCnt++) {
		// leggo singolo cookie "Nome = Valore"
		var asCookie = asCookies[iCnt].split("=");
		if (sNome == asCookie[0]) { 
			return (unescape(asCookie[1]));
		}
	}

	// SE non esiste il cookie richiesto
	return("");
}

function delCookie(sNome) {
	setCookie(sNome, "");
}

//window.onload = function() {
//	caricaCSS();
//}

function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}

function fnSet() {
	var s_url = "http://www.arialambiente.it";
	var s_nn = "Il tuo browser non supporta l'impostazione automatica\n della HomePage. Occorre impostarla manualmente\n(per Firefox: menù strumenti,opzioni,tasto -Generale-) ";
	var s_op = "Il tuo browser non supporta l'impostazione automatica\n della HomePage. Occorre impostarla manualmente\n(per Firefox: menù strumenti,opzioni,tasto -Generale-)";
	var s_other = "Il tuo browser non supporta l'impostazione automatica\n della HomePage. Occorre impostarla manualmente\n(per Firefox: menù strumenti,opzioni,tasto -Generale-)";
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
	  oHomePage.style.behavior = "url('#default#homePage')"
	  oHomePage.setHomePage(s_url);
	  return true;
	} else if (navigator.appName == "Netscape") {
	  alert(s_nn);
	}  else if (navigator.appName == "Opera") {
	  alert(s_op);
	}
	else {
	  document.write("" + s_other + "");
	}
}
