var minYear=1900;
var maxYear=2100;

// FUNZIONE PER CAMBIO TITOLO E SOTOTITOLO

function changeTitle(tit, subtit){

	var IE = navigator.appName.indexOf("Microsoft") != -1;

	htmTit=tit;
	htmSubTit=subtit;

	if(IE )
	{
		if( parent.midFrame.document.all.mid_titolo){
		  parent.midFrame.document.all.mid_titolo.innerText="";
		  parent.midFrame.document.all.mid_titolo.insertAdjacentHTML("beforeEnd",htmTit);
		}
		if( parent.midFrame.document.all.mid_sottotitolo){
		  parent.midFrame.document.all.mid_sottotitolo.innerText="";
		  parent.midFrame.document.all.mid_sottotitolo.insertAdjacentHTML("beforeEnd",htmSubTit);
		}
	} else {
		var range="";
		var docFrag="";

		if (parent.midFrame.document.getElementById('mid_titolo')) {
			parent.midFrame.document.getElementById('mid_titolo').innerText="";
			parent.midFrame.document.getElementById('mid_titolo').innerHTML="";
		}

	  //document.getElementById('mid_titolo').style.visibility="visible";
	  range = parent.midFrame.document.createRange();
	  range.setStartBefore(parent.midFrame.document.getElementById('mid_titolo'));
	  docFrag = range.createContextualFragment(htmTit);
	  parent.midFrame.document.getElementById('mid_titolo').appendChild(docFrag)

	  var range = "";
	  var docFrag = "";
	  parent.midFrame.document.getElementById('mid_sottotitolo').innerText="";
	  parent.midFrame.document.getElementById('mid_sottotitolo').innerHTML="";
	  //document.getElementById('mid_titolo').style.visibility="visible";
	  range = parent.midFrame.document.createRange();
	  range.setStartBefore(parent.midFrame.document.getElementById('mid_sottotitolo'));
	  docFrag = range.createContextualFragment(htmSubTit);
	  parent.midFrame.document.getElementById('mid_sottotitolo').appendChild(docFrag)
	}
}

function autoComplete (field, select, property, forcematch) {

	date = new Date();

	var found = false;

	var len = field.value.length;

	for (var i = 0; i < select.options.length; i++) {

		if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
			found=true;
			break;
			}

		if((select.options[i][property].toUpperCase().substr(len-1,1).charCodeAt()) < (field.value.toUpperCase().substr(-1).charCodeAt()))
			break;

	}


	if (found) { select.selectedIndex = i; }
	//else { select.selectedIndex = -1; }


	if (field.createTextRange) {
		if (forcematch && !found) {
			field.value=field.value.substring(0,field.value.length-1);
			return;
			}
		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
			var r1 = field.createTextRange();
			var oldValue = r1.text;
			var newValue = found ? select.options[i][property] : oldValue;
			if (newValue != field.value) {
				field.value = newValue;
				var rNew = field.createTextRange();
				rNew.moveStart('character', oldValue.length) ;
				rNew.select();
				}
			}
		}

}


// -----------------------------------------------------------
// FUZIONE CHE CONVALIDA CARATTERI AMMESSI IN UN CAMPO TESTO
// -----------------------------------------------------------
function ValidateChar(field, type, valid)
{
	// valid true or false per indicare se i caratteri nella stinga sono validi o no

	var str = field.value;

	switch(type)
	{
		case 'nome': // valori ammessi
			var strChar="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-\"' ";
			break;

		case 'login': // valori ammessi
			var strChar="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";
			break;

		case 'tel': // valori ammessi
			var strChar ='1234567890.,-/';
			break;

		case 'civico': // valori ammessi
			var strChar =':;!"£$%&()=?^[]~{}§°ç@<>||+*-';
			break;

		case 'txt': // valori ammessi
		case 'Txt': // valori ammessi
			var strChar =':;!"£$%&/()=?^[]~{}§°ç@<>||+*';
			break;

		case 'username': // valori ammessi
			var strChar ='1234567890:;!"£$%&/()=?^[]~{}§°ç@<>||+*-';
			break;

		case 'cap': // valori ammessi
			var strChar ='1234567890';
			break;

		case 'num': // valori ammessi
			var strChar ='1234567890';
			break;
	}


	for(i=0; i<str.length; i++)
	{

		t = str.charAt(i);

		if(valid)
		{
			if(strChar.indexOf(t)<0)
				str = str.split(t).join('');
		}else{
			if(strChar.indexOf(t)>=0)
				str = str.split(t).join('');
		}
	}

	if ((type=='Txt') && (str.length>0))
	  	{
    	//Creo un array di tutti i nomi
  		var str2 = str.split(' ');
		//Ciclo i nomi ci metto la maiuscola ad ogni uno e ci aggiungo lo spazio
    	str='';
		for(i=0; i<str2.length; i++)
			{
			if (i>0) str+=' ';
	      	str += str2[i].charAt(0).toUpperCase() + str2[i].substr(1,str2[i].length).toLowerCase();
			}
		}

field.value = str;

}








//	FUNZIONA CHE CONTROLLA SE UN CAMPO E' UN NUMERO
function isNumeric(field)
{
	if(isNaN(field.value))
		field.value=field.value.substr(0,(field.value.length-1));
}

// check for valid numeric strings
function IsValueNumeric(ATesto) {
	var sValidChars="0123456789.-";
	var sChar;
	var bResult=true;

	if (ATesto.length==0) return false;

	for (i=0;i<ATesto.length && bResult==true;i++) {
		sChar=ATesto.charAt(i);
		if (sValidChars.indexOf(sChar)==-1) {
			bResult=false;
		}
	}
	return bResult;
}

function select(a, changeTo)
{
	//alert(a.id+'  '+lineSel);
	if(a.id!=('tr'+lineSel))
	  a.style.backgroundColor = changeTo;
}

function selectNorm(a, changeTo)
{
	  a.style.backgroundColor = changeTo;
}

function NetscapeEventHandler_KeyDown(e) {
alert(e.which);
/*
	if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') {
		e.returnValue = false;
		e.cancel = true;
		e.preventDefault();
		return false;
	}
	return true;
*/
}


// funzione per formattare un campo come data
// Parametri : campo input
function MaskDataddmmyyyy (field, evt) {

/*
  var testo="";
  var selectedText = document.selection;

  //alert('name: '+field.name+'\ntype: '+field.type+'    \n\n\nname: '+selectedText.name+'\ntype: '+selectedText.type);

  if (selectedText.type == 'Text')
  {
     var newRange = selectedText.createRange();
	 testo = newRange.text;
  }
  if (testo.length>0 && testo==field.value)
	field.value='';
*/


  var charCode = (evt.charCode)?evt.charCode:((evt.which)?evt.which:evt.keyCode);
  //key = event.keyCode;
  key = charCode;

  if(key==8) // tasto cancella
  {
	 field.value = field.value.substr(0,field.value.length-1);
	 return false;
  }
  else if (key==9) // tasto tabulazione
  {
	 return true;
  }
  else
  {
	  switch (field.value.length) {
		case 0:
		  return String.fromCharCode(key)>='0' && String.fromCharCode(key)<'4';
		  break;
		case 1:
		  //secondo numero maggiore di 0. NO a giorno 00, se però primo numero > 0 allora ok a 0 come secondo numero, es: 10, 20, 30gg
		  if (field.value.substring(0,1)>=1){
			var valOk=0;
		  }else{
			var valOk=1;
		  }
		  if (field.value.substring(0,1)==3){
			var valOk1=1;
		  }else{
			var valOk1=9;
		  }
		  if (/\d/.test(String.fromCharCode(key)) && String.fromCharCode(key)>=valOk && String.fromCharCode(key)<=valOk1)
		  field.value=field.value+String.fromCharCode(key)+"/";
		  return false;
		  break;
		case 2:
		  key = '/'.charCodeAt();
		  return true;
		  break;
		case 3:
		  return String.fromCharCode(key)>='0' && String.fromCharCode(key)<'2';
		  break;
		case 4:
		  //Se il primo numero del mese è 1 possibilità di 10-11-12 (mesi) altrimenti 01-02-03 ecc. NO a mese 00
		  if (field.value.substring(4,3)=='1'){
			 if (/\d/.test(String.fromCharCode(key)) && String.fromCharCode(key)<='2')
				if (field.value.substring(0,2)=='31')
				{
					 if (/\d/.test(String.fromCharCode(key)) && (String.fromCharCode(key)=='0' || String.fromCharCode(key)=='2'))
						 field.value=field.value+String.fromCharCode(key)+"/";
				}
				else if (field.value.substring(0,2)<'31')
					 field.value=field.value+String.fromCharCode(key)+"/";
			 return false;
		 }else{
			 if (/\d/.test(String.fromCharCode(key)) && String.fromCharCode(key)>='1')
				if (field.value.substring(0,2)=='31')
				{
					 if (/\d/.test(String.fromCharCode(key)) && (String.fromCharCode(key)=='1' || String.fromCharCode(key)=='3' || String.fromCharCode(key)=='5' || String.fromCharCode(key)=='7' || String.fromCharCode(key)=='8'))
						 field.value=field.value+String.fromCharCode(key)+"/";
				}
				else if (field.value.substring(0,2)<'31' && field.value.substring(0,2)>'29')
				{
					 if (/\d/.test(String.fromCharCode(key)) && String.fromCharCode(key)!='2')
						 field.value=field.value+String.fromCharCode(key)+"/";
				}
				else if (field.value.substring(0,2)<='29')
				{
					 field.value=field.value+String.fromCharCode(key)+"/";
				}
	//		 field.value=field.value+String.fromCharCode(key)+"/";
			 return false;
		 }
		  break;
		case 5:
		  key = '/'.charCodeAt();
		  return true;
		  break;
		case 6:
			return String.fromCharCode(key)>='1' && String.fromCharCode(key)<'3';
			break;
		case 7:
			break;
		case 8:
			break;
		case 9:
			year = Number(Number(field.value.substring(6,9))+String.fromCharCode(key));
			var bisestile = true;
			if (Number((year/4)) != Number(Math.floor(year/4)))   bisestile = false;
			else if ((year/100) != Math.floor(year/100)) bisestile = true;
			else if ((year/400) != Math.floor(year/400)) bisestile = false;

			if (field.value.substring(0,2)=='29' && field.value.substring(3,5)=='02') // se febbraio e gg 29 solo anni bisestili
			{
				if (!bisestile)
				  return false;
			}
			return true;
		  //return /\d/.test(String.fromCharCode(event.keyCode));
		  break;
		default:
		  return false;
		  break;
	  }
   }
}

function openWin(nome, nomeFin, width, height, scrol)
{

var winWidth = screen.availWidth;
var winHeight = screen.availHeight;
var popupWidth = width;
var popupHeight = height;

if ( popupWidth == '')
	popupWidth = winWidth;

if ( popupHeight == '')
	popupHeight = winHeight;

var xCoord = ((winWidth-popupWidth)/2);
var yCoord = ((winHeight-popupHeight)/2);

if ( nomeFin == '')
	nomeFin = 'NuovaFinestra';

if ( scrol == '')
	scrol = 'yes';

myFenster=window.open(nome, nomeFin,'toolbar=no, scrollbars='+scrol+', width='+popupWidth+',height='+popupHeight+',left='+xCoord+',top='+yCoord+'screenX='+xCoord+',screenY='+yCoord+'');
myFenster.focus();
}

function Sleep(AMilliSeconds) {
	date=new Date();
	var curDate=null;

	do {
		var curDate=new Date();
	} while(curDate-date<AMilliSeconds);
}

_ONEORMORE = 1;
_JUSTONE =2;
InvioOk=false;

// controlla se sono selezionate delle voci in un elenco a discesa
// Parametri : elenco : elenco da controllare, how : indica il tipo di controllo (_ONEORMORE : 1 o più, _JUSTONE : 1 e solo 1)

function checkSelected(elenco, how)
  {
  if (how==_JUSTONE)
    {
	tot=0;
	for(t=0;t<elenco.length;t++)
	  if (elenco.options[t].selected) tot++;
	if (tot==0)
	  alert('Selezionare un valore');
	else
	  if (tot>1)
		alert('Selezionare un solo valore');
	return tot==1;
	}
  else
    if (how==_ONEORMORE)
	  {
	  tot=0;
	  for(t=0;t<elenco.length;t++)
  	    if (elenco.options[t].selected) tot++;
  	  if (tot==0)
  	    alert('Selezionare almeno un valore');
	  return tot>=1;
	  }
  }


_MOVE = 1;
_COPY =2;
InvioOk=false;

// Sposta le voci selezionate da un elenco ad un altro
// Parametri : elencosorg : elenco sorgente, elencodest : elenco destinazione, how : (se _MOVE sposta la selezione, con _COPY la copia)

function moveSelection(elencosorg, elencodest, how)
  {
//  var option0 = new Option("Red", "color_red")   var option1 = new Option("Blue", "color_blue")   var option2 = new Option("Yellow", "color_yellow")   var option3 = new Option("Green", "color_green")
//   for (var i=0; i < 4; i++) {      eval("inForm.selectTest.options[i]=option" + i)
	for(t=0;t<elencodest.length;t++)
		elencodest.options[t].selected = false;
	for(t=0;t<elencosorg.length;t++)
		if (elencosorg.options[t].selected)
			elencodest.options[elencodest.length]=new Option(elencosorg.options[t].text,elencosorg.options[t].value,false,true);
	if (how==_MOVE)
		for(t=elencosorg.length-1;t>=0;t--)
			if (elencosorg.options[t].selected)
				elencosorg.options[t]=null;
	// history.go(0);
    return true;
  }


// Seleziona tutte le voci di un elenco
// Parametri : elenco : elenco da selezionare

function selectAll(elenco)
{
	for(t=0;t<elenco.length;t++) elenco.options[t].selected = true;
	return true;
}

// Elimina le voci selezionate da un elenco
// Parametri : elenco : elenco da cui eliminare le voci
function deleteSelection(elenco)
  {
	for(t=elenco.length-1;t>=0;t--)
		if (elenco.options[t].selected)
			elenco.options[t]=null;
    return true;
  }

_TOP=1;
_BOTTOM=2;
// Aggiunge una voce ad un elenco
// Parametri : elenco : elenco a cui aggiungere la voce, Unique : se true impedisce l'inserimento di valori duplicati, Testo : testo dell'opzione, Valore: Value per l'opzione, DefaultSelected : true se la voce è selezionata di default, Selected : true se la voce è selezionata
//             ResetSelection : reimposta la selezione ogni volta, Position : _TOP oppure _BOTTOM inserisce in cima o in fondo
function addToSelection(elenco,Unique,Testo,Valore,DefaultSelected, Selected, ResetSelection, Position)
{
  Trovato=false;
  if (Unique)
  {
  	for (t=0;t<elenco.length;t++)
  	{
      var elencoValue=elenco.options[t].value;
      var elencoText=elenco.options[t].text;
      if ((Testo.toUpperCase()==elencoText.toUpperCase()) || (Valore.toUpperCase()==elencoValue.toUpperCase())) Trovato=true;
  	}
  }
  if (Trovato)
  {
    alert('Tentativo di inserire un valore duplicato');
    return false;
  }
  else
  {
    if (ResetSelection) for (t=0;t<elenco.length;t++) elenco.options[t].selected=false;
    if (Position==_TOP)
    {
    	var option = new Option();
    	elenco.options[elenco.length]=option;
		var number=elenco.length;
    	for (t=number-1;t>0;t--)
    	{
    		var opzionexhg=new Option (elenco.options[t-1].text,elenco.options[t-1].value,elenco.options[t-1].defaultSelected,elenco.options[t-1].selected);
      		elenco.options[t]=opzionexhg;
    	}
    }
  	var option = new Option(Testo,Valore,DefaultSelected,Selected);
  	elenco.options[((Position==_TOP)?0:elenco.length)]=option;
    return true;
  }
}



// Legge gli elenchi di modelli compresi in modelli-modulo.js
// Parametri : Tipo : Tipo di modello da leggere, Elenco : campo Select HTML dove inserire i valori
_HTMLMODULE = 1;
_CHIAVE = 0;
_VALORE = 1;

function GetModelli(Tipo,Elenco) {
	if (Tipo==_HTMLMODULE) {
		while (Elenco.length>0) Elenco.options[Elenco.length-1]=null;
		Elenco.options[Elenco.length]=new Option("-- Seleziona un Modello --",-1,false,true);
		for(t=0;t<_ModuliHtml.length;t++)
			Elenco.options[Elenco.length]=new Option(_ModuliHtml[t][_CHIAVE],t,false,false);
	}
}

// Legge un valore di modello da modelli-modulo.js
// Parametri : Tipo : Tipo di modello da leggere, Numero : numero del modello
function GetModello(Tipo,Numero) {
	if (Tipo==_HTMLMODULE) {
		return _ModuliHtml[Numero][_VALORE];
	}
}

// modifica i permessi per tutte le voci selezionate di un elenco a discesa
// Parametri : elenco : elenco da modificare, Lettura/Scrittura: True / False / Vuoto = legge valore corrente e lo nega,

function ChangePermission(elenco, Lettura, Scrittura)
{
	for(t=0;t<elenco.length;t++)
		if (elenco.options[t].selected)
	  	{
	  	Valore=elenco.options[t].value;
	  	OldLettura=Valore.charAt(Valore.indexOf('[')+1);
	  	OldScrittura=Valore.charAt(Valore.lastIndexOf('[')+1);
	  	if ((Lettura!="T" && Lettura!="F") || (Scrittura!="T" && Scrittura!="F"))
	  	{
	  		Lettura=OldLettura;
	  		Scrittura=OldScrittura;
	  		if (Lettura=="F" && Scrittura=="F")
	  			Lettura="T";
	  		else
	  			if (Lettura=="T" && Scrittura=="F")
	  				Scrittura="T";
	  			else
	  				if (Lettura=="T" && Scrittura=="T")
	  					Scrittura=Lettura="F";
	  	}
	  	Valore=Valore.substring(0,Valore.indexOf('['));
	  	Valore=Valore+'['+Lettura+']'+'['+Scrittura+']';
	  	Testo=elenco.options[t].text;
	  	Testo=Testo.substring(0,Testo.lastIndexOf(']')-6)+'['+Lettura+']'+' ['+Scrittura+']'+Testo.substring(Testo.lastIndexOf(']')+2,1000);
	  	elenco.options[t].value=Valore;
	  	elenco.options[t].text=Testo;
	  	}

}

function autoComplete (field, select, property, forcematch) {
	var found = false;
	for (var i = 0; i < select.options.length; i++) {
		if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
			found=true;
			break;
		}
	}

	if (found) { select.selectedIndex = i; }
	//else { select.selectedIndex = -1; }

	if (field.createTextRange) {
		if (forcematch && !found) {
			field.value=field.value.substring(0,field.value.length-1);
			return;
			}

		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";

		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
			var r1 = field.createTextRange();
			var oldValue = r1.text;
			var newValue = found ? select.options[i][property] : oldValue;
			if (newValue != field.value) {
				field.value = newValue;
				var rNew = field.createTextRange();
				rNew.moveStart('character', oldValue.length) ;
				rNew.select();
			}
		}
	}
}

function trim(AText) {
	if (!AText || AText=='') { return ''; }

//	var rex=/^\s+|\s+$/g;
	var sTesto=AText.replace(/\s+$|^\s+/g,"");
//	var rex=/\s+$|^\s+/g;
//	var rex= this.replace(/\s+$|^\s+/g,"");
//	sTesto=sTesto.replace(rex,'');
	return sTesto;
}

function SetFocus(AObject) {
	if (AObject) {
		var sNuovoStile=AObject.className;

		sNuovoStile=sNuovoStile.replace('Focused','');
		sNuovoStile=sNuovoStile.replace('MouseOver','');

		AObject.className=sNuovoStile+'Focused';
	}
}

function LeaveFocus(AObject) {
	if (AObject) {
		var sNuovoStile=AObject.className;

		sNuovoStile=sNuovoStile.replace('Focused','');
		sNuovoStile=sNuovoStile.replace('MouseOver','');

		AObject.className=sNuovoStile;
	}
}

function LabelError(AObject) {
	if (AObject) {
		var sNuovoStile=AObject.className;

		sNuovoStile=sNuovoStile.replace('_error','');

		AObject.className=sNuovoStile+'_error';
	}
}

function LabelNormal(AObject) {
	if (AObject) {
		var sNuovoStile=AObject.className;

		sNuovoStile=sNuovoStile.replace('_error','');

		AObject.className=sNuovoStile;
	}
}

function MouseIsOver(AObject) {
	if (AObject) {
		var sNuovoStile=AObject.className;

		sNuovoStile=sNuovoStile.replace('Focused','');
		sNuovoStile=sNuovoStile.replace('MouseOver','');

		AObject.className=sNuovoStile+'MouseOver';
	}
}

function MouseIsOut(AObject) {
	if (AObject) {
		var sNuovoStile=AObject.className;

		sNuovoStile=sNuovoStile.replace('Focused','');
		sNuovoStile=sNuovoStile.replace('MouseOver','');

		AObject.className=sNuovoStile;
	}
}

function ControlValue(AValore, ATipo, AUpper) {
	if (!AValore) return '';

	var sValid='';
	var sResult='';
	var sValore=trim(AValore);

	if (AUpper) {
		sValore=sValore.toUpperCase();
	}

	switch (ATipo) {
		case 'nome':
			sValid="àèéìòùÀÈÉÌÒÙabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-\"' ";
			break;
		case 'login':
			sValid="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";
			break;
		case 'alfanum':
			sValid="1234567890àèéìòùÀÈÉÌÒÙabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_*,.;\"' /@";
			break;
		case 'codfis':
			sValid="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
			break;
		case 'txt':
			sValid="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";
			break;
		case 'decimale_meta':
		case 'decimale':
		case 'euro':
			sValid='1234567890.,-';
			break;
		case 'tel':
			sValid='1234567890.-/';
			break;
		case 'cap':
			sValid ='1234567890';
			break;
		case 'ora':
			sValid ='1234567890.,:';
			break;
		case 'num':
			sValid ='1234567890';
			break;
		default:
			return sValore;
			break;
	}

	for (i=0;i<sValore.length;i++) {
		if (sValid.indexOf(sValore.charAt(i))>=0) {
//			if (ATipo=='tel') {
//				alert('sResult -->'+sResult+'<--\n'
//						'charAt('+i+') -->'+sValore.charAt(i)+'<--');
//			}
			sResult+=sValore.charAt(i);
		}
	}

	if (ATipo=='euro' || ATipo=='decimale' || ATipo=='decimale_meta' || ATipo=='ora') {
		var sTemp=sResult;
		var sUltimoSimbolo=',';
		var sAltroSimbolo='.';
		var iVirgola=0;
		var iPunto=0;
		var iUltimo=0;

		for (i=0;i<sTemp.length;i++) {
			if (sTemp.charAt(i)==',') {
				sUltimoSimbolo=',';
				sAltroSimbolo='.';
				iVirgola++;
				iUltimo=iVirgola;
				continue;
			}
			if (sTemp.charAt(i)=='.') {
				sUltimoSimbolo='.';
				sAltroSimbolo=',';
				iPunto++;
				iUltimo=iPunto;
				continue;
			}
			if (sTemp.charAt(i)==':') {
				sUltimoSimbolo=':';
				sAltroSimbolo='.';
				iPunto++;
				iUltimo=iPunto;
				continue;
			}
		}

		sValore='';
		for (i=0;i<sTemp.length;i++) {
			if (sTemp.charAt(i)==sUltimoSimbolo) {
				if (iUltimo>1) {
					iUltimo--;
				} else {
					sValore+=sTemp.charAt(i);
				}
				continue;
			}

			if (sTemp.charAt(i)!=sAltroSimbolo) {
				sValore+=sTemp.charAt(i);
			}
		}

		sValore=sValore.replace(sUltimoSimbolo,'.');
		if (ATipo=='euro') {
			sResult=FormatNumber(sValore);
		} else if (ATipo=='decimale_meta') {
			sValore=FormatNumber(sValore,1,'.');

			var fValore=parseFloat(sValore)-parseInt(sValore);
			fValore=fValore*10;
			if (fValore>0 && fValore!=5) {
				sResult='';
				for (i=0;i<sValore.length;i++) {
					if (i==sValore.length-1) {
						sResult+='5';
					} else {
						sResult+=sValore.charAt(i);
					}
				}
			} else {
				sResult=sValore;
			}
		} else if (ATipo=='ora') {
			sResult=FormatNumber(sValore,2,':');
			if (sResult.length<=4) { sResult='0'+sResult; }
		} else {
			sResult=sValore;
		}
	}

	return sResult;
}

function StringOfChar(AChar,ALength) {
	var sResult='';

	if (ALength>=0) {
		for (i=0;i<ALength;i++) {
			sResult+=AChar;
		}
	}

	return sResult;
}

function FormatNumber(AValue,ADecimalPlace,ADecimalSeparator,AThousandSeparator) {
	var sDecimalSeparator=',';
	if (ADecimalSeparator) { sDecimalSeparator=ADecimalSeparator; }

	var sThousandSeparator='.';

	if (AThousandSeparator) { sThousandSeparator=AThousandSeparator; }
	sThousandSeparator=((sDecimalSeparator==',')?'.':',');

	var iDecimalPlace=2;
	if (ADecimalPlace>=0) { iDecimalPlace=ADecimalPlace; }

	var sDecimal='';
	sDecimal=StringOfChar('0',iDecimalPlace);

//	var sValore=trim(AValue);
	var sValore=AValue;

	if (sValore=='' || isNaN(sValore) || parseFloat(sValore)==0) { return '0'+sDecimalSeparator+sDecimal; }

	iArrotonda=Math.pow(10,iDecimalPlace);
	sValore=Math.round(parseFloat(sValore)*iArrotonda).toString();
	sValore=trim(sValore);
	sSegno='';
	if (sValore.length>0) {
		if (sValore.charAt(0)=='-') {
			sSegno='-';
			sValore=trim(sValore.substr(1,sValore.length));
		}
	}

	while (sValore.length<=iDecimalPlace) {
		sValore=0+sValore;
	}

	var iPosizioneDec=0;
	var iPosizioneTho=0;
	var sResult='';
	var bSeparatoreInserito=false;
	for (i=sValore.length-1;i>=0;i--) {
		if (iPosizioneDec==iDecimalPlace && !bSeparatoreInserito) {
			sResult=sDecimalSeparator+sResult;
			bSeparatoreInserito=true;
		}
		iPosizioneDec++;

		if (bSeparatoreInserito && iPosizioneTho%3==0 && iPosizioneTho>0) {
			sResult=sThousandSeparator+sResult;
		}
		if (bSeparatoreInserito) { iPosizioneTho++; }

		sResult=sValore.charAt(i)+sResult;
	}

	sResult=sSegno+sResult;
	return sResult;
}

function isDate(AData) {
	var daysInMonth=DaysArray(12);
	var pos1=AData.indexOf('/');
	var pos2=AData.indexOf('/',pos1+1);
	var strMonth=AData.substring(0,pos1);
	var strDay=AData.substring(pos1+1,pos2);
	var strYear=AData.substring(pos2+1);
	strYr=strYear;

	if (strDay.charAt(0)=="0" && strDay.length>1) { strDay=strDay.substring(1); }
	if (strMonth.charAt(0)=="0" && strMonth.length>1) { strMonth=strMonth.substring(1); }
	for (var i=1;i<=3;i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) { strYr=strYr.substring(1); }
	}

	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);

	if (pos1==-1 || pos2==-1) {
		return "la data deve essere nel seguente formato: gg/mm/aaaa";
	}
	if (strMonth.length<1 || month<1 || month>12) {
		return "mese non valido";
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return "giorno non valido";
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return "l'anno deve essere di 4 cifre compreso tra il "+minYear+" ed il "+maxYear;
	}
	if (AData.indexOf('/',pos2+1)!=-1 || isInteger(stripCharsInBag(AData,'/'))==false){
		return "data non valida";
	}

	return "";
}

// controllo valore on_key_press
function force_value(AEvt,ATipo){
	var iCharCode=(AEvt.charCode)?AEvt.charCode:((AEvt.which)?AEvt.which:AEvt.keyCode);

	if ((iCharCode>=35 && iCharCode<=39) ||
		iCharCode==8 || // back
		iCharCode==9 || // tab
		iCharCode==13) {
		return true;
	}

	switch (ATipo) {
		case 'date':
			if (iCharCode==45 ||						// -
				iCharCode==47 ||						// /
				(iCharCode>=48 && iCharCode<=57)) {		// numeri
				return true;
			}
			break
		case 'float':
			if (iCharCode==44 ||						// ,
				iCharCode==46 ||						// .
				(iCharCode>=48 && iCharCode<=57)) {		// numeri
				return true;
			}
			break
		case 'hour':
			if (iCharCode==44 ||						// ,
				iCharCode==46 ||						// .
				(iCharCode>=48 && iCharCode<=57) ||		// numeri
				iCharCode==58 ||						// :
				iCharCode==59) {						// ;
				return true;
			}
			break
		case 'login':
			if ((iCharCode>=48 && iCharCode<=57) ||		// numeri
				(iCharCode>=65 && iCharCode<=90) ||		// lettere maiuscole
				(iCharCode>=97 && iCharCode<=122) ||	// lettere minuscole
				iCharCode==45 ||						// -
				iCharCode==46 ||						// .
				iCharCode==95) {						// _
				return true;
			}
			break
		case 'number':
			if (iCharCode>=48 && iCharCode<=57) {		// numeri
				return true;
			}
			break
		case 'tel':
			if (iCharCode==45 ||						// -
				iCharCode==46 ||						// .
				iCharCode==47 ||						// /
				(iCharCode>=48 && iCharCode<=57)) {		// numeri
				return true;
			}
			break
		default:
			return true;
			break;
	}

	return false;
}