//FTP ALBERO______________________________________________________________
function visu(zona){
	document.getElementById(zona).style.display=='none' ? document.getElementById(zona).style.display='block' : document.getElementById(zona).style.display='none'
}
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);
	}
}
//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 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,colore){
		window.opener.document.getElementById(campo).style.backgroundColor='#FFFFFF';	
	}
//FORM UTENTI___________________________________________________________________________________
function utenti_form(){
	err='';
	colore='#FEE75F';
	with(document){
		if ((getElementById('tipo').value == '4')&&(getElementById('software').value == '')){
			err="  - Il campo SOFTWARE HOUSE e' obbligatorio\n" + err;
			getElementById('software').focus();
			color2('software',colore);
		}
		if ((getElementById('tipo').value == '3')&&(getElementById('regione').value == '')){
			err="  - Il campo REGIONE e' obbligatorio\n" + err;
			getElementById('regione').focus();
			color2('regione',colore);
		}
		if ((getElementById('tipo').value == '2')&&(getElementById('azienda').value == '')){
			err="  - Il campo AZIENDA e' obbligatorio\n" + err;
			getElementById('azienda').focus();
			color2('azienda',colore);
		}
		if ((getElementById('tipo').value == '1')&&(getElementById('azienda').value == '')){
			err="  - Il campo AZIENDA e' obbligatorio\n" + err;
			getElementById('azienda').focus();
			color2('azienda',colore);
		}
		if (getElementById('tipo').value == ''){
			err="  - Il campo TIPO UTENTE e' obbligatorio\n" + err;
			getElementById('tipo').focus();
			color2('tipo',colore);
		}
		if (getElementById('passw').value == ''){
			err="  - Il campo PASSWORD e' obbligatorio\n" + err;
			getElementById('passw').focus();
			color2('passw',colore);
		}
		if (getElementById('utente').value == ''){
			err="  - Il campo NOME UTENTE e' obbligatorio\n" + err;
			getElementById('utente').focus();
			color2('utente',colore);
		}
		if (err!=''){
			alert('Attenzione!!!Riscontrati i seguenti errori:\n\n' + err)
		}else{
			invia('utenti_form');
		}
	}
}
