//FTP ALBERO______________________________________________________________
function visu(zona){
	document.getElementById(zona).style.display=='none' ? document.getElementById(zona).style.display='block' : document.getElementById(zona).style.display='none'
}
function visufiltro(zona,filtro){
	if (filtro==1){
		document.getElementById(zona).style.display='block';
		color(zona);
	}else{
		document.getElementById(zona).style.display='none';
		setValue(zona,'');
	}
}
function cambia(imm,imm2){
	if (document.getElementById(imm).style.display=='none'){
		document.getElementById(imm2).style.display='none';
		document.getElementById(imm).style.display='block';
	}else{
		document.getElementById(imm).style.display='none';
		document.getElementById(imm2).style.display='block';
	}
}
function cambia_filtro(imm,imm2,filtro){
	if (document.getElementById(imm).style.display=='none'){
		document.getElementById(imm2).style.display='none';
		document.getElementById(imm).style.display='block';
		assegna(filtro,0);
	}else{
		document.getElementById(imm).style.display='none';
		document.getElementById(imm2).style.display='block';
		assegna(filtro,1);
	}
}
//TASTO PREMUTO INVIO -> INVIO FORM_________________________________________
function isInvioPressed(e,modulo) {
	e=e||window.event;
	if (e.keyCode == 13){
		document.getElementById(modulo).submit();	
	}
} 
//TASTO PREMUTO INVIO -> ESEGUI FUNCTION____________________________________
function isInvioPressed2(e,modulo) {
	e=e||window.event;
	if (e.keyCode == 13){
		eval(modulo);
	}
}
//TASTO PREMUTO INVIO -> Aggiorna attuale____________________________________
function isInvioPressedAttuale(e) {
	e=e||window.event;
	if (e.keyCode == 13){
		assegna('attuale','1');
	}
}
//assegna campo_____________________________________________________________
	function assegna(campo,valore){
		document.getElementById(campo).value=valore;
	}
//invio form________________________________________________________________
	function invia(modulo){
		document.getElementById(modulo).submit();
	}
//TARGET BLANK______________________________________________________________
	function blank(collegamento){
		window.open(collegamento);
		return false;
	}
//POP UP____________________________________________________________________
	function openWindow(collegamento,nomeFinestra,larghezza,altezza,sinistra,alto) {
		larghFinestra=larghezza;
		altezFinestra=altezza; 
		sinistraFinestra=sinistra;
		altoFinestra=alto; 
		window.open(collegamento,nomeFinestra,"left="+sinistraFinestra+",top="+altoFinestra+",width=" +larghFinestra+",resizable=yes,scrollbars=yes,height="+altezFinestra);
	}
//POP UP CENTRO______________________________________________________________________________
function popup(pag){
		//larg=250;
		//alte=250;
		//alto=screen.height/2-(larg/2);
		//sini=screen.width/2-(alt/2);
		larg=screen.width/2;
		alte=screen.height/2;
		alto=(screen.height/2)-(alte/2);
		sini=(screen.width/2)-(larg/2);
		window.open(pag,'',"left="+sini+",top="+alto+",width="+larg+",height="+alte+",resizable=yes,scrollbars=yes");
}
//POP UP FISSo____________________________________________________________________
	function openWindowFisso(collegamento,nomeFinestra,larghezza,altezza,sinistra,alto) {
		larghFinestra=larghezza;
		altezFinestra=altezza; 
		sinistraFinestra=sinistra;
		altoFinestra=alto; 
		window.open(collegamento,nomeFinestra,"left="+sinistraFinestra+",top="+altoFinestra+",width=" +larghFinestra+",resizable=no,scrollbars=no,height="+altezFinestra);
	}
//POP UP FISSo 2____________________________________________________________________
	function openWindowFisso2(collegamento,nomeFinestra,larghezza,altezza,sinistra,alto) {
		larghFinestra=larghezza;
		altezFinestra=altezza; 
		sinistraFinestra=sinistra;
		altoFinestra=alto; 
		window.open(collegamento,nomeFinestra,"left="+sinistraFinestra+",top="+altoFinestra+",width=" +larghFinestra+",resizable=no,scrollbars=yes,height="+altezFinestra);
	}
//Valore Assoluto Data_____________________________________________________
	function datetonumber(data){
		if ((data=='')||(!isData(data))){
			valore=0;
		}else{
			arr_data=data.split("/");
			giorno=arr_data[0];
			mese=arr_data[1];
			anno=arr_data[2];
			if (mese.length==1){mese='0'+mese}
			if (giorno.length==1){giorno='0'+giorno}
			valore=anno+mese+giorno;
		}
		return valore;
	}
//AUMENTA DIMINUISCI DIMENSIONE CARATTERI______________________________________________
function dimensione(tipo,contenitore,to){
		//if (getElementById(contenitore).style.fontSize==''){getElementById(contenitore).style.fontSize="100%"}
		if (tipo=='+'){document.getElementById(contenitore).style.fontSize=to+"px"}
		if (tipo=='-'){document.getElementById(contenitore).style.fontSize=to+"px"}
}
//Controllo DATA____________________________________________________________
	function isData(data){
	  if(data!=''){
		  if (data.indexOf("/")==-1){appo=false}else{appo=true}
		  if (appo){
			arr_data=data.split("/");
			if (arr_data.length!=3){appo=false}else{appo=true}
		  }
		  
		  if (appo){
			giorno=arr_data[0];
			mese=arr_data[1];
			anno=arr_data[2];
			if ((isNaN(giorno)) || (isNaN(mese)) || (isNaN(anno))){appo=false}else{appo=true}
		  }
		  
		  if (appo){
			if ((mese < 0) || (mese > 12)){
				appo=false
			}
			if ((giorno < 0) || (giorno > 31)){
				appo=false
			}
			if ((anno < 1900) || (anno > 2100)){
				appo=false
			}
		  }
		  
		  if (appo){
			if ((mese=='11')||(mese=='4')||(mese=='04')||(mese=='6')||(mese=='06')||(mese=='9')||(mese=='09')){
				if (giorno > 30){appo=false}
			}
			if ((mese=='2')||(mese=='02')){
				if (anno%4==0){
					if (giorno > 29){appo=false}
				}else{
					if (giorno > 28){appo=false}
				}
			}
		  }
	  }else{
	  	appo=true
	  }
	  return appo;
	}
//Funzione DESTRA_________________________________________________________
	function right(str, n){
    	if (n <= 0)
       		return "";
    	else if (n > String(str).length)
       		return str;
    	else {
       		var iLen = String(str).length;
       		return String(str).substring(iLen, iLen - n);
    	}
	}
//Funzione SINISTRA_______________________________________________________
	function left(str, n){
		if (n <= 0)
			return "";
		else if (n > String(str).length)
			return str;
		else
			return String(str).substring(0,n);
	}
//Funzione LTRIM__________________________________________________________
function lTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
//Funzione RTRIM__________________________________________________________
function rTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");	
}
//Funzione TRIM___________________________________________________________
function trim( value ) {
	return lTrim(rTrim(value));
}
//Funzione CODICE FISCALE_________________________________________________
	function isCF(cf){
		if (cf!=''){
			var validi, i, s, set1, set2, setpari, setdisp;
			cf = cf.toUpperCase();
			if (cf.length != 16){appo=false}else{appo=true}
			if (appo){
				validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
				for(i=0;i<16;i++){
					if(validi.indexOf(cf.charAt(i))==-1){
						appo=false;
					}
				}
			}
			if (appo){
				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)){
					appo=false;
				}
			}
		}else{
			appo=true;	
		}
		return appo
	}
//Funzione EMAIL_______________________________________________________
	function isEmail(campo){
		appo=true
		if (campo!=''){
			campo=campo.split('@');
			if (campo.length!=2){appo=false;}
			if (appo){
				if ((campo[0].length < 2) || (campo[1].length < 5)){
					appo=false;
				}
			}
			if (appo){
				campo=campo[1].split('.');
				if(campo.length < 2){appo=false}
				if (appo){
					if (campo[0].length<2){appo=false}
				}
				if(appo){
					if (campo[1].length<2){appo=false}
				}
			}
		}
		return appo;
	}
//Colora campo ERRORE_________________________________________________________________
	function color2(campo,colore){
		document.getElementById(campo).style.backgroundColor=colore;	
	}
//Colora Campo DEFAULT________________________________________________________________
	function color(campo){
		document.getElementById(campo).style.backgroundColor='#FFFFFF';	
	}
//Colora campo OPENER_________________________________________________________________
	function color_opener(campo){
		window.opener.document.getElementById(campo).style.backgroundColor='#FFFFFF';	
	}
//Gestione CAMPO di TESTO_____________________________________________________________
function campo(nome,attuale,testo,opzione){
	with(document){
		if ((opzione=='focus')||(opzione==1)){
			if (attuale==testo){getElementById(nome).value=''}
		}
		if ((opzione=='blur')||(opzione==0)){
			if (attuale==''){getElementById(nome).value=testo}
		}
	}
}
//Prendi Title_________________________________________________________________________
function getTitle(nome){
	if (document.getElementById(nome)!=null){
		return trim(document.getElementById(nome).getAttribute('title').toUpperCase());
	}else{
		return "";
	}
}
//Conta caratteri_________________________________________________________________________
function getLength(nome){
	if (document.getElementById(nome)!=null){
		return document.getElementById(nome).value.length;
	}else{
		return 0;
	}
}
//Supera caratteri_________________________________________________________________________
function isLength(nome,n){
	if (getLength(nome)>n){
		return false;
	}else{
		return true;
	}
}
//E'numerico_________________________________________________________________________
function isNumeric(valore){
	if (valore!=""){
		return !isNaN(valore);
	}else{
		return true
	}
}
//Prendi Valore_________________________________________________________________________
function getValue(nome){
	if (document.getElementById(nome)!=null){
		return trim(document.getElementById(nome).value);
	}else{
		return "";
	}
}
//Setta Valore_________________________________________________________________________
function setValue(nome,valore){
	if (document.getElementById(nome)!=null){
		document.getElementById(nome).value=valore;
	}
}
//Setta Valore Opener__________________________________________________________________
function setValueOpener(nome,valore){
	if (window.opener.document.getElementById(nome)!=null){
		window.opener.document.getElementById(nome).value=valore;
	}
}
//c'e valore_________________________________________________________________________
function isValue(nome){
	if (getValue(nome)!=''){
		return true;
	}else{
		return false;	
	}
}
//Prendi Spunta_________________________________________________________________________
function isChecked(nome){
	if (document.getElementById(nome).checked){
		return true;
	}else{
		return false;
	}
}
//Controllo FORM________________________________________________________________________
function ctrl_form(campo,data,numero,email){
with(document){
	err="";
	ultimo="";
	colore="#EEF088";
	
	campo=campo.split(",");
	data=data.split(",");
	numero=numero.split(",");
	email=email.split(",");
	
	if (email!=''){
		for (var i=email.length-1;i>=0;i--){
			if (!isEmail(getValue(email[i]))){
				err="  - Il campo " + getTitle(email[i]) + " non e' un indirizzo e-mail valido.\n" + err;
				color2(email[i],colore);
				ultimo=email[i];
			}
		}
	}

	if (numero!=''){
		for (var i=numero.length-1;i>=0;i--){
			if (!isNumeric(getValue(numero[i]))){
				err="  - Il campo " + getTitle(numero[i]) + " deve essere un numero.\n" + err;
				color2(numero[i],colore);
				ultimo=numero[i];
			}
		}
	}

	if (data!=''){
		for (var i=data.length-1;i>=0;i--){
			if (!isData(getValue(data[i]))){
				err="  - Il campo " + getTitle(data[i]) + " deve essere una data in formato gg/mm/aaaa.\n" + err;
				color2(data[i],colore);
				ultimo=data[i];
			}
		}
	}
	
	if (campo!=''){
		for (var i=campo.length-1;i>=0;i--){
			if (!isValue(campo[i])){
				err="  - Il campo " + getTitle(campo[i]) + " e' obbligatorio.\n" + err;
				color2(campo[i],colore);
				ultimo=campo[i];
			}
		}
	}

	if (err!=""){
		alert('Attenzione!\nRiscontrati i seguenti Errori:\n\n'+err);
		if (ultimo!=''){document.getElementById(ultimo).focus();}
		return false;
	}else{
		return true
	}

}
}
//funzione massimo di caratteri in una textarea___________________________________________________________
function maxchr(campo,maxc){
	with(document){
		att=getElementById(campo).value.length;
		if (att>maxc){
			getElementById(campo).value=left(getElementById(campo).value,maxc);	
		}
	}
}
//Funzione CODICE FISCALE_________________________________________________________________________________
function isCF(cf){
	var validi, i, s, set1, set2, setpari, setdisp;
	cf = cf.toUpperCase();
	if ((cf=='')||(cf.length != 16)){appo=false}else{appo=true}
	if (appo){
		validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		for(i=0;i<16;i++){
			if(validi.indexOf(cf.charAt(i))==-1){
				appo=false;
			}
		}
	}
	if (appo){
		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)){
			appo=false;
		}
	}
	return appo
}
//accoda al campo lista_____________________________________________________________
	function aggiungivalore(campo,valore){
		valore=valore.replace(/@/g,"'");
		if ((window.opener.document.getElementById(campo).value.indexOf(valore + ' | '))=='-1'){
				window.opener.document.getElementById(campo).value+= valore + " | ";
		}
	}
//rimuovi dal campo_____________________________________________________________
	function rimuovivalore(campo,valore){
		valore=valore.replace(/@/g,"'");
		window.opener.document.getElementById(campo).value=window.opener.document.getElementById(campo).value.replace(valore + ' | ','');
	}
//accoda al campo semplice_____________________________________________________________
	function aggiungifine(campo,valore){
		valore=valore.replace('§',"'");
		window.opener.document.getElementById(campo).value+= valore;
	}
//COPIA_____________________________________________________________________
	function copia(area){
		var appoggio=eval("document.getElementById('"+area+"')");
		appoggio.focus();
		appoggio.select();
		intervallo=appoggio.createTextRange();
		intervallo.execCommand("Copy");
	}
