//TASTO PREMUTO INVIO -> INVIO FORM_________________________________________
	function invio_form(e,modulo) {
		e=e||window.event;
		if (e.keyCode == 13){
			document.getElementById(modulo).submit();	
		}
	} 
//TASTO PREMUTO INVIO -> ESEGUI FUNCTION____________________________________
	function invio_fun(e,fun) {
		e=e||window.event;
		if (e.keyCode == 13){
			eval(fun);
		}
	}
//BLANK FTP________________________________________________________________
function procedura_ftp(id){
	with(document){
		getElementById('id').value=id;
		getElementById('blank').action='blank_ftp.cfm';
		invia('blank');
	}
}

//BLANK FORM________________________________________________________________
function procedura_doc(pos){
	with(document){
		getElementById('pos').value=pos;
		getElementById('blank').action='blank.cfm';
		invia('blank');
	}
}

//FORM CONTATTI_____________________________________________________________
function contatti(){
	err='';
	colore='#FFFFDD';
	with(document){
	if (!getElementById('privacy').checked){
		err="  - E' obbligatorio autorizzare il trattamento dei propri dati personali\n" + err;
		color2('privacy',colore);
	}
	if (getElementById('testo').value == ''){
		err="  - Il campo Domanda e' obbligatorio\n" + err;
		getElementById('testo').focus();
		color2('testo',colore);
	}
	if (getElementById('categoria').value == ''){
		err="  - Il campo Categoria e' obbligatorio\n" + err;
		getElementById('categoria').focus();
		color2('categoria',colore);
	}
	if (getElementById('email').value!=getElementById('email2').value){
		err="  - L'indirizzo E-mail e la conferma sono diversi\n" + err;
		getElementById('email2').focus();
		color2('email2',colore);
	}
	if (getElementById('email2').value == ''){
		err="  - Il campo Conferma E-mail e' obbligatorio\n" + err;
		getElementById('email2').focus();
		
		color2('email2',colore);
	}
	if (!isEmail(getElementById('email2').value)){
		err="  - L'indirizzo e-mail inserito nel campo Conferma E-mail e' errato\n" + err;
		getElementById('email2').focus();
		color2('email2',colore);
	}
	if (getElementById('email').value == ''){
		err="  - Il campo E-mail e' obbligatorio\n" + err;
		getElementById('email').focus();
		color2('email',colore);
	}
	if (!isEmail(getElementById('email').value)){
		err="  - Indirizzo e-mail inserito nel campo E-mail e' errato\n" + err;
		getElementById('email').focus();
		color2('email',colore);
	}
	if (getElementById('professione').value == ''){
		err="  - Il campo Professione e' obbligatorio\n" + err;
		getElementById('professione').focus();
		color2('professione',colore);
	}
	if (getElementById('nome').value == ''){
		err="  - Il campo Nome e Cognome e' obbligatorio\n" + err;
		getElementById('nome').focus();
		color2('nome',colore);
	}
	}
	if (err!=''){
		alert('Attenzione!!!Riscontrati i seguenti errori:\n\n' + err)
	}else{
		invia('modulo');
	}
}
//ENTRA IN TELEMACO
function telemaco_enter(){
	document.getElementById('accesso').target='_blank';
	invia('accesso');
}
//FORM ASSISTENZA TELEMACO_____________________________________________________________
function telemaco(){
	err='';
	colore='#FFFFDD';
	with(document){
	if (!getElementById('privacy').checked){
		err="  - E' obbligatorio autorizzare il trattamento dei propri dati personali\n" + err;
		color2('privacy',colore);
	}
	if (getElementById('testo').value == ''){
		err="  - Il campo Domanda e' obbligatorio\n" + err;
		getElementById('testo').focus();
		color2('testo',colore);
	}
	if (getElementById('email').value!=getElementById('email2').value){
		err="  - L'indirizzo E-mail e la conferma sono diversi\n" + err;
		getElementById('email2').focus();
		color2('email2',colore);
	}
	if (getElementById('email2').value == ''){
		err="  - Il campo Conferma E-mail e' obbligatorio\n" + err;
		getElementById('email2').focus();
		
		color2('email2',colore);
	}
	if (!isEmail(getElementById('email2').value)){
		err="  - L'indirizzo e-mail inserito nel campo Conferma E-mail e' errato\n" + err;
		getElementById('email2').focus();
		color2('email2',colore);
	}
	if (getElementById('email').value == ''){
		err="  - Il campo E-mail e' obbligatorio\n" + err;
		getElementById('email').focus();
		color2('email',colore);
	}
	if (!isEmail(getElementById('email').value)){
		err="  - Indirizzo e-mail inserito nel campo E-mail e' errato\n" + err;
		getElementById('email').focus();
		color2('email',colore);
	}
	if (getElementById('nome').value == ''){
		err="  - Il campo Nome e Cognome e' obbligatorio\n" + err;
		getElementById('nome').focus();
		color2('nome',colore);
	}
	}
	if (err!=''){
		alert('Attenzione!!!Riscontrati i seguenti errori:\n\n' + err)
	}else{
		invia('modulo');
	}
}
//RICARICA PREPAGATI__________________________________________________________________________________________
function ricarica(){
	err='';
	colore='#FFFFDD';
	with(document){
	if  (((getElementById('diritti').value).indexOf(' ')!=-1)||((getElementById('diritti').value).indexOf(',')!=-1)||((getElementById('diritti').value).indexOf('.')!=-1)){
		err="  - Nel campo Diritti di Segreteria non devono essere immessi spazi o numeri decimali\n" + err;
		getElementById('diritti').focus();
		getElementById('diritti').select();
		color2('diritti',colore);
	}
	if  (isNaN(getElementById('diritti').value)){
		err="  - Il campo Diritti di Segreteria deve essere numerico\n" + err;
		getElementById('diritti').focus();
		getElementById('diritti').select();
		color2('diritti',colore);
	}else if ((getElementById('diritti').value<50)&&(getElementById('diritti').value!="")){
		err="  - Il campo Diritti di Segreteria deve essere un valore pari o superiore a 50 Euro\n" + err;
		getElementById('diritti').focus();
		getElementById('diritti').select();
		color2('diritti',colore);
	}
	if (getElementById('diritti').value == ''){
		err="  - Il campo Diritti di Segreteria e' obbligatorio\n" + err;
		getElementById('diritti').focus();
		color2('diritti',colore);
	}
	if  (((getElementById('tariffa').value).indexOf(' ')!=-1)||((getElementById('tariffa').value).indexOf(',')!=-1)||((getElementById('tariffa').value).indexOf('.')!=-1)){
		err="  - Nel campo Tariffe non devono essere immessi spazi o numeri decimali\n" + err;
		getElementById('tariffa').focus();
		getElementById('tariffa').select();
		color2('tariffa',colore);
	}
	if  (isNaN(getElementById('tariffa').value)){
		err="  - Il campo Tariffe deve essere numerico\n" + err;
		getElementById('tariffa').focus();
		getElementById('tariffa').select();
		color2('tariffa',colore);
	}else if ((getElementById('tariffa').value<50)&&(getElementById('tariffa').value!="")){
		err="  - Il campo Tariffe deve essere un valore pari o superiore a 50 Euro\n" + err;
		getElementById('tariffa').focus();
		getElementById('tariffa').select();
		color2('tariffa',colore);
	}
	if (getElementById('tariffa').value == ''){
		err="  - Il campo Tariffe e' obbligatorio\n" + err;
		getElementById('tariffa').focus();
		color2('tariffa',colore);
	}
	}
	if (err!=''){
		alert('Attenzione!!!Riscontrati i seguenti errori:\n\n' + err)
	}else{
		if (confirm("Confermare la ricarica Effettuata?\n  - Premere OK per inviare la ricarica\n  - Premere ANNULLA per annullare l'operazione di ricarica.")){
			document.getElementById('modulo').action='ricarica2.cfm';
			invia('modulo');
		}
	}
}
//CONTROMARCHE__________________________________________________________________________________________
function contromarche(){
	err='';
	colore='#FFFFDD';
	with(document){
	if  (((getElementById('arti').value).indexOf(' ')!=-1)||((getElementById('arti').value).indexOf(',')!=-1)||((getElementById('arti').value).indexOf('.')!=-1)){
		err="  - Nel campo Certificati RAME non devono essere immessi spazi o numeri decimali\n" + err;
		getElementById('arti').focus();
		getElementById('arti').select();
		color2('arti',colore);
	}
	if  (getElementById('arti').value==''){
		err="  - Il campo Certificati RAME e' obbligatorio\n" + err;
		getElementById('arti').focus();
		getElementById('arti').select();
		color2('arti',colore);
	}
	if  (isNaN(getElementById('arti').value)){
		err="  - Il campo Certificati RAME deve essere numerico\n" + err;
		getElementById('arti').focus();
		getElementById('arti').select();
		color2('arti',colore);
	}
	if  (((getElementById('stor').value).indexOf(' ')!=-1)||((getElementById('stor').value).indexOf(',')!=-1)||((getElementById('stor').value).indexOf('.')!=-1)){
		err="  - Nel campo Certificati ARGENTO non devono essere immessi spazi o numeri decimali\n" + err;
		getElementById('stor').focus();
		getElementById('stor').select();
		color2('stor',colore);
	}
	if  (getElementById('stor').value==''){
		err="  - Il campo Certificati ARGENTO e' obbligatorio\n" + err;
		getElementById('stor').focus();
		getElementById('stor').select();
		color2('stor',colore);
	}
	if  (isNaN(getElementById('stor').value)){
		err="  - Il campo Certificati ARGENTO deve essere numerico\n" + err;
		getElementById('stor').focus();
		getElementById('stor').select();
		color2('stor',colore);
	}
	if  (((getElementById('iscr').value).indexOf(' ')!=-1)||((getElementById('iscr').value).indexOf(',')!=-1)||((getElementById('iscr').value).indexOf('.')!=-1)){
		err="  - Nel campo Certificati ORO non devono essere immessi spazi o numeri decimali\n" + err;
		getElementById('iscr').focus();
		getElementById('iscr').select();
		color2('arti',colore);
	}
	if  (getElementById('iscr').value==''){
		err="  - Il campo Certificati ORO e' obbligatorio\n" + err;
		getElementById('iscr').focus();
		//getElementById('iscr').select();
		color2('iscr',colore);
	}
	if  (isNaN(getElementById('iscr').value)){
		err="  - Il campo Certificati ORO deve essere numerico\n" + err;
		getElementById('iscr').focus();
		getElementById('iscr').select();
		color2('iscr',colore);
	}
	}
	if (err!=''){
		alert('Attenzione!!!Riscontrati i seguenti errori:\n\n' + err)
	}else{
		if (confirm("Confermare la richiesta di bollini?\n  - Premere OK per inviare la richiesta\n  - Premere ANNULLA per annullare la ricarica.")){
			document.getElementById('modulo').action='contromarche2.cfm';
			invia('modulo');
		}
	}
}
//POPUP______________________________________________________________________________
function popup(pag){
		window.open(pag,'Ricevuta',"left=300px,top=200px,width=500px,height=350px,resizable=no,scrollbars=no");
}
//SCOMPARSA RICOMPARSA_______________________________________________________________
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';
	}
}
//ASSEGFNA CAMPO______________________________________________________________________
	function assegna(campo,valore){
		document.getElementById(campo).value=valore;
	}
//INVIO FORM__________________________________________________________________________
	function invia(modulo){
		document.getElementById(modulo).submit();
	}
//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);
	}
//TARGET BLANK________________________________________________________________________
	function blank(collegamento){
		window.open(collegamento);
	}
//Colora Campo DEFAULT________________________________________________________________
	function color(campo){
		document.getElementById(campo).style.backgroundColor='#ffffff';	
	}
//Colora campo ERRORE_________________________________________________________________
	function color2(campo,colore){
		document.getElementById(campo).style.backgroundColor=colore;	
	}

//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}
		}
	}
}
//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.length==4){
				if ((anno < 1900) || (anno > 2100)){
					appo=false
				}
			}else{
				if ((anno < 0) || (anno > 99)){
					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 controllo EMAIL______________________________________________________________
function isEmail(campo){
	appo=true
	if (campo!=''){
		if (trim(campo).indexOf(' ')!=-1){appo=false;}
		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;
}
//Controllo FORM________________________________________________________________________
function controllaform(nomeform,campi,desc,data,data_desc,numerico,numerico_desc,condizione,condizione_desc){
	with(document){
		err="";
		colore='#EEF088';
		for (var i=numerico.length-1;i>=0;i--){
			if (isNaN(getElementById(numerico[i]).value)){
				err="  - Il campo "+numerico_desc[i]+" deve essere numerico\n" + err;
				getElementById(numerico[i]).focus();
				color2(getElementById(numerico[i]).id,colore);
			}
		}
		for (var i=data.length-1;i>=0;i--){
			if (isData(getElementById(data[i]).value)==false){
				err="  - Il campo "+data_desc[i]+" deve essere una data in formato gg/mm/aaaa\n" + err;
				getElementById(data[i]).focus();
				color2(getElementById(data[i]).id,colore);
			}
		}
		for (var i=campi.length-1;i>=0;i--){
			if (getElementById(campi[i]).value == ''){
				err="  - Il campo "+desc[i]+" e' obbligatorio\n" + err;
				getElementById(campi[i]).focus();
				color2(getElementById(campi[i]).id,colore);
			}
		}
		for (var i=0;i<=condizione.length-1;i++){
			if (eval(condizione[i])==true){
				err=err + "  - " + condizione_desc[i] + "\n";
			}
		}
		if (err!=""){
			alert('Attenzione! Riscontrati degli Errori:\n\n'+err);
			return false;
		}
	}
}
//funzione LEFT__________________________________________________________________________________________
function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
//funzione RIGHT__________________________________________________________________________________________
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 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 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
}
