
function eseguiRichiesta_pag(url,parameters) {

        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // Vedi note sotto
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Non riesco a creare una istanza XMLHTTP');
            return false;
        }
          http_request.onreadystatechange = function() { alertContents_pag(http_request); };		  
          http_request.open('POST', url, true);
          http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		  http_request.setRequestHeader("Content-length", parameters.length);
		  http_request.setRequestHeader("Connection", "close");
		  http_request.send(parameters);

    }

    function alertContents_pag(http_request) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				result = http_request.responseText;
              //document.getElementById('newsletter').innerHTML = result; 
			  //document.getElementById('loader').src="images/bianco.jpg";
            } else {
                alert('Si è verificato un problema con la richiesta');
            }
        }

    }

    
   function vai_pagamento(dona,nome,cognome,custom,note) {
     
	 var post_z ='dona=' + dona+'&nome='+nome+' '+cognome+'&custom='+custom+'&note='+note;
	 //eseguiRichiesta_pag('http://www.fonderieculturali.org/donaora.php', post_z);
	 //window.location.href='http://www.fonderieculturali.org/index.php?io=io';
	 //window.open('http://www.fonderieculturali.org/index.php?io=io','_blank');
	 var cpanel = 'https://checkout.iwsmile.it/Pagamenti/?ACCOUNT=701001833&AMOUNT='+dona+'&ITEM_NAME=Donazione+volontaria+-+'+nome+'+'+cognome+'&ITEM_NUMBER=01&QUANTITY=1&URL_OK=http%3A%2F%2Fwww.fonderieculturali.org%2Findex.php&URL_BAD=http%3A%2F%2Fwww.fonderieculturali.org%2Ferror.php&FLAG_ONLY_IWS=0&CUSTOM='+custom+'&MEMO='+note;
	//popupWin = window.open(cpanel,'dona_ora','menubar=yes,toolbar=yes,location=yes,directories=yes,titlebar=yes,status=yes,scrollbars=yes,resizable=yes');
		location.href = cpanel;

	 //return(false);
   }


function controlloModulo_donazione(){
	 
	 if(document.getElementById('nome').value==""){
		 alert("campo NOME mancante!");
		 document.getElementById('nome').focus();
		 return (false);
		 }
	if(document.getElementById('cognome').value==""){
		 alert("campo COGNOME mancante!");
		 document.getElementById('cognome').focus();
		 return (false);
		 }
	if(document.getElementById('via').value==""){
		 alert("campo INDIRIZZO mancante!");
		 document.getElementById('via').focus();
		 return (false);
		 }
	if(document.getElementById('citta').value==""){
		 alert("campo CITTA mancante!");
		 document.getElementById('citta').focus();
		 return (false);
		 }
	if(document.getElementById('cap').value==""){
		 alert("campo CAP mancante!");
		 document.getElementById('cap').focus();
		 return (false);
		 }
	if(document.getElementById('provincia').value==""){
		 alert("campo PROVINCIA mancante!");
		 document.getElementById('provincia').focus();
		 return (false);
		 }	
	if(document.getElementById('tel').value==""){
		 alert("campo TELEFONO mancante!");
		 document.getElementById('tel').focus();
		 return (false);
		 }	
	 if(document.getElementById('mail').value==""){
		 alert("campo E-MAIL mancante!");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	if(document.getElementById('dona').value==""){
		 alert("DONAZIONE mancante!");
		 document.getElementById('dona').focus();
		 return (false);
		 }
	if(document.getElementById('dona').value=="0"){
		if(document.getElementById('libero').value==""){
			 alert("DONAZIONE mancante!");
			 document.getElementById('libero').focus();
			 return (false);
			 }
		}
	StrMail=document.getElementById('mail').value;
	   if (StrMail.length>6){
		  var pos;   
		  var dotpos;
		  pos = StrMail.indexOf("@");
		  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);		 
			 }
		  pos=pos+1;
		  dotpos = StrMail.indexOf(".", pos);
		  if (dotpos > (StrMail.length-3) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);
			 }
		  Strmail=StrMail.substr(pos);
		  if ( (StrMail.length < 5) || (dotpos <= 0) )
			 {			 
			 alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);
			 }
		  }
	   else
		  {
		  alert("Il campo email non è stato inserito nel formato corretto.");
		  document.getElementById('mail').focus();
		  return (false);
		  }		
	 if(document.getElementById('codice').value==""){
		 alert("campo CODICE DI CONTROLLO mancante!");
		 document.getElementById('codice').focus();
		 return (false);
		 }
	 if(document.getElementById('privacy').checked==0){
		 alert("informativa sulla privacy non accettata!");		 
		 return (false);
		 }
	document.getElementById('action').value="invia";	
	return (true);
	//window.location='index3.php?idstruttura='+idstr+'&action=invia';
}

function controlloModulo_canNews(){
	 
	 if(document.getElementById('mail').value==""){
		 alert("campo E-MAIL mancante!");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	StrMail=document.getElementById('mail').value;
	   if (StrMail.length>6){
		  var pos;   
		  var dotpos;
		  pos = StrMail.indexOf("@");
		  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);		 
			 }
		  pos=pos+1;
		  dotpos = StrMail.indexOf(".", pos);
		  if (dotpos > (StrMail.length-3) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);
			 }
		  Strmail=StrMail.substr(pos);
		  if ( (StrMail.length < 5) || (dotpos <= 0) )
			 {			 
			 alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);
			 }
		  }
	   else
		  {
		  alert("Il campo email non è stato inserito nel formato corretto.");
		  document.getElementById('mail').focus();
		  return (false);
		  }		
	 if(document.getElementById('codice').value==""){
		 alert("campo CODICE DI CONTROLLO mancante!");
		 document.getElementById('codice').focus();
		 return (false);
		 }
	 if(document.getElementById('privacy').checked==0){
		 alert("informativa sulla prinacy non accettata!");		 
		 return (false);
		 }
	document.getElementById('action').value="invia";
	return (true);
	//window.location='index3.php?idstruttura='+idstr+'&action=invia';
}

function controlloModulo_partner(){
	 
	 if(document.getElementById('ente').value==""){
		 alert("campo ENTE mancante!");
		 document.getElementById('ente').focus();
		 return (false);
		 }
	if(document.getElementById('citta').value==""){
		 alert("campo CITTA mancante!");
		 document.getElementById('citta').focus();
		 return (false);
		 }
	if(document.getElementById('referente').value==""){
		 alert("campo REFERENTE mancante!");
		 document.getElementById('referente').focus();
		 return (false);
		 }	
	 if(document.getElementById('mail').value==""){
		 alert("campo E-MAIL mancante!");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	StrMail=document.getElementById('mail').value;
	   if (StrMail.length>6){
		  var pos;   
		  var dotpos;
		  pos = StrMail.indexOf("@");
		  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);		 
			 }
		  pos=pos+1;
		  dotpos = StrMail.indexOf(".", pos);
		  if (dotpos > (StrMail.length-3) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);
			 }
		  Strmail=StrMail.substr(pos);
		  if ( (StrMail.length < 5) || (dotpos <= 0) )
			 {			 
			 alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);
			 }
		  }
	   else
		  {
		  alert("Il campo email non è stato inserito nel formato corretto.");
		  document.getElementById('mail').focus();
		  return (false);
		  }
	 if(document.getElementById('iniziativa').value==""){
		 alert("campo INIZIATIVA mancante!");
		 document.getElementById('iniziativa').focus();
		 return (false);
		 }	
	 if(document.getElementById('strategia').value==""){
		 alert("campo STRATEGIA mancante!");
		 document.getElementById('strategia').focus();
		 return (false);
		 }	
	 if(document.getElementById('collaborazione').value==""){
		 alert("campo COLLABORAZIONE mancante!");
		 document.getElementById('collaborazione').focus();
		 return (false);
		 }	
	 if(document.getElementById('codice').value==""){
		 alert("campo CODICE DI CONTROLLO mancante!");
		 document.getElementById('codice').focus();
		 return (false);
		 }
	 if(document.getElementById('privacy').checked==0){
		 alert("informativa sulla privacy non accettata!");		 
		 return (false);
		 }
	document.getElementById('action').value="invia";
	return (true);
	//window.location='index3.php?idstruttura='+idstr+'&action=invia';
}

function controlloModulo_contatti(){
	 
	 if(document.getElementById('nome').value==""){
		 alert("campo NOME mancante!");
		 document.getElementById('nome').focus();
		 return (false);
		 }
	if(document.getElementById('cognome').value==""){
		 alert("campo COGNOME mancante!");
		 document.getElementById('cognome').focus();
		 return (false);
		 }
	if(document.getElementById('tel').value==""){
		 alert("campo TELEFONO mancante!");
		 document.getElementById('tel').focus();
		 return (false);
		 }	
	 if(document.getElementById('mail').value==""){
		 alert("campo E-MAIL mancante!");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	StrMail=document.getElementById('mail').value;
	   if (StrMail.length>6){
		  var pos;   
		  var dotpos;
		  pos = StrMail.indexOf("@");
		  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);		 
			 }
		  pos=pos+1;
		  dotpos = StrMail.indexOf(".", pos);
		  if (dotpos > (StrMail.length-3) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);
			 }
		  Strmail=StrMail.substr(pos);
		  if ( (StrMail.length < 5) || (dotpos <= 0) )
			 {			 
			 alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);
			 }
		  }
	   else
		  {
		  alert("Il campo email non è stato inserito nel formato corretto.");
		  document.getElementById('mail').focus();
		  return (false);
		  }
	 if(document.getElementById('com').value==""){
		 alert("campo COMUNICAZIONE mancante!");
		 document.getElementById('com').focus();
		 return (false);
		 }			
	 if(document.getElementById('codice').value==""){
		 alert("campo CODICE DI CONTROLLO mancante!");
		 document.getElementById('codice').focus();
		 return (false);
		 }
	 if(document.getElementById('privacy').checked==0){
		 alert("informativa sulla privacy non accettata!");		 
		 return (false);
		 }
	document.getElementById('action').value="invia";
	return (true);
	//window.location='index3.php?idstruttura='+idstr+'&action=invia';
}



function evidenzia(elemento){
	elemento.style.border = "1px solid #F65F13";	
	elemento.style.color = "#F65F13";
}

function non_evidenzia(elemento){
	elemento.style.border = "1px solid #CCCCCC";	
	elemento.style.color = "#000000";
}

function cambia_azione(azione, id_socio){	
	document.getElementById('action').value=azione;
	document.getElementById('id_socio').value=id_socio;
	}

function controlloModulo_addinfo(id_socio, azione){
	StrMail=document.getElementById('email_a').value;
	if(StrMail.length>1){
	   if (StrMail.length>6){
		  var pos;   
		  var dotpos;
		  pos = StrMail.indexOf("@");
		  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('email_a').focus();
			 return (false);		 
			 }
		  pos=pos+1;
		  dotpos = StrMail.indexOf(".", pos);
		  if (dotpos > (StrMail.length-3) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('email_a').focus();
			 return (false);
			 }
		  Strmail=StrMail.substr(pos);
		  if ( (StrMail.length < 5) || (dotpos <= 0) )
			 {			 
			 alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('email_a').focus();
			 return (false);
			 }
		  }
	   else
		  {
		  alert("Il campo email non è stato inserito nel formato corretto.");
		  document.getElementById('email_a').focus();
		  return (false);
		  }	 
	}
	if(document.getElementById('codice_a').value==""){
		 alert("campo CODICE DI CONTROLLO mancante!");
		 document.getElementById('codice_a').focus();
		 return (false);
		 }
	 if(document.getElementById('privacy_a').checked==0){
		 alert("informativa sulla prinacy non accettata!");		 
		 return (false);
		 }	
	document.getElementById('action').value=azione;	
	document.getElementById('id_socio').value=id_socio;
	return (true);
	

}
function controlloModulo_socio(){
	 
	 if(document.getElementById('nome').value==""){
		 alert("campo NOME mancante!");
		 document.getElementById('nome').focus();
		 return (false);
		 }
	if(document.getElementById('cognome').value==""){
		 alert("campo COGNOME mancante!");
		 document.getElementById('cognome').focus();
		 return (false);
		 }
	if(document.getElementById('nato_a').value==""){
		 alert("campo NATO A mancante!");
		 document.getElementById('nato_a').focus();
		 return (false);
		 }
	if(document.getElementById('nato_il').value==""){
		 alert("campo NATO IL mancante!");
		 document.getElementById('nato_il').focus();
		 return (false);
		 }
	if(document.getElementById('via').value==""){
		 alert("campo INDIRIZZO mancante!");
		 document.getElementById('via').focus();
		 return (false);
		 }
	if(document.getElementById('citta').value==""){
		 alert("campo CITTA mancante!");
		 document.getElementById('citta').focus();
		 return (false);
		 }
	if(document.getElementById('cap').value==""){
		 alert("campo CAP mancante!");
		 document.getElementById('cap').focus();
		 return (false);
		 }
	if(document.getElementById('provincia').value==""){
		 alert("campo PROVINCIA mancante!");
		 document.getElementById('provincia').focus();
		 return (false);
		 }
	if(document.getElementById('tel').value==""){
		 alert("campo TELEFONO mancante!");
		 document.getElementById('tel').focus();
		 return (false);
		 }
	 if(document.getElementById('mail').value==""){
		 alert("campo E-MAIL mancante!");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	StrMail=document.getElementById('mail').value;
	   if (StrMail.length>6){
		  var pos;   
		  var dotpos;
		  pos = StrMail.indexOf("@");
		  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);		 
			 }
		  pos=pos+1;
		  dotpos = StrMail.indexOf(".", pos);
		  if (dotpos > (StrMail.length-3) )
			 {
			alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);
			 }
		  Strmail=StrMail.substr(pos);
		  if ( (StrMail.length < 5) || (dotpos <= 0) )
			 {			 
			 alert("Il campo email non è stato inserito nel formato corretto.");
			 document.getElementById('mail').focus();
			 return (false);
			 }
		  }
	   else
		  {
		  alert("Il campo email non è stato inserito nel formato corretto.");
		  document.getElementById('mail').focus();
		  return (false);
		  }
	// if(document.getElementById('codfisc').value==""){
	//	 alert("campo CODICE FISCALE mancante!");
	//	 document.getElementById('codfisc').focus();
	//	 return (false);
	//	 }
	//	 else{
	//	var test=ControllaCF(document.getElementById('codfisc').value);
	//	if(test!="") {
	//		alert(test);
	//		document.getElementById('codfisc').focus();
	//		return(false);
	//		}
	//	 }
	if(document.getElementById('abilito').checked==0){
		 alert("accettazione dello statuto non sottoscritta!");		 
		 return (false);
		 }
	 if(document.getElementById('codice').value==""){
		 alert("campo CODICE DI CONTROLLO mancante!");
		 document.getElementById('codice').focus();
		 return (false);
		 }
	 if(document.getElementById('privacy').checked==0){
		 alert("informativa sulla prinacy non accettata!");		 
		 return (false);
		 }
	document.getElementById('action').value="invia";
	return (true);
	//window.location='index3.php?idstruttura='+idstr+'&action=invia';
}

	
	function cancella_mail(campo){
		if (campo.value=="inserisci la tua e-mail"){
			campo.value="";
		}
		else if (campo.value==""){
			campo.value="inserisci la tua e-mail";
		}
	}
	
	
	function eseguiRichiesta(url,parameters) {

        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // Vedi note sotto
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Non riesco a creare una istanza XMLHTTP');
            return false;
        }
		
          http_request.onreadystatechange = function() { alertContents(http_request); };	
		  
          http_request.open('POST', url, true);
          http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		  http_request.setRequestHeader("Content-length", parameters.length);
		  http_request.setRequestHeader("Connection", "close");
		  http_request.send(parameters);

    }

    function alertContents(http_request) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				result = http_request.responseText;
             	carica_news(result);			  
            } else {
                alert('Si è verificato un problema con la richiesta');
            }
        }

    }

function espandi(elemento){
	
	//dipendenze con funzione freccia
	elem_freccia = document.getElementById("contenitore"+elemento);
	if(elem_freccia){
		if(elem_freccia.style.zIndex>=3){
				elem_freccia.style.zIndex=2;
		}
		else elem_freccia.style.zIndex=3;
	}
	
	if(document.getElementById("elemento"+elemento).style.display=="none"){
			$("#elemento"+elemento).slideDown();
		}
		else
			$("#elemento"+elemento).slideUp();
		}
	
	function espandi_slider(){
		if(document.getElementById("slider").style.display=="none"){
			document.getElementById("slider").style.display="";
		}
		else
			document.getElementById("slider").style.display="none";
	}

 
 function eseguiRichiesta_nl(url,parameters) {

        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // Vedi note sotto
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Non riesco a creare una istanza XMLHTTP');
            return false;
        }
          http_request.onreadystatechange = function() { alertContents_nl(http_request); };		  
          http_request.open('POST', url, true);
          http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		  http_request.setRequestHeader("Content-length", parameters.length);
		  http_request.setRequestHeader("Connection", "close");
		  http_request.send(parameters);

    }

    function alertContents_nl(http_request) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				result = http_request.responseText;
              document.getElementById('newsletter').innerHTML = result; 
			  //document.getElementById('loader').src="images/bianco.jpg";
            } else {
                alert('Si è verificato un problema con la richiesta');
            }
        }

    }

    
   function get_newsletter(mail,page) {
     
	StrMail=document.getElementById('mailing-list-text').value;
	if (StrMail.length>6){
	  var pos;
	  var dotpos;
	  pos = StrMail.indexOf("@");
	  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mailing-list-text').focus();
		 return (false);		 
		 }
	  pos=pos+1;
	  dotpos = StrMail.indexOf(".", pos);
	  if (dotpos > (StrMail.length-3) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mailing-list-text').focus();
		 return (false);
		 }
	  Strmail=StrMail.substr(pos);
	  if ( (StrMail.length < 5) || (dotpos <= 0) )
		 {			 
		 alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mailing-list-text').focus();
		 return (false);
		 }
	  }
   else
	  {
	  alert("Il campo email non è stato inserito nel formato corretto.");
	  document.getElementById('mailing-list-text').focus();
	  return (false);
	  }
	 var post_z ='mail=' + mail+'&page='+page;
	 eseguiRichiesta_nl('http://www.fonderieculturali.org/news_letter_ajax.php', post_z);
	 return(false);
   }
   
   
   function freccetta(contenitore){
	  	//questa funzione ha dipendeze con esapndi()
		elem_freccia = document.getElementById("contenitore"+contenitore);
		elem_background = elem_freccia.style.background;
		elem_z_index = elem_freccia.style.zIndex;
		//uso zindex come flag stato
		if(elem_z_index == 1 || elem_z_index == ""){
			elem_freccia.style.background = "#FFFFFF url('images/pulsanti-dw.gif') no-repeat top left";
			elem_freccia.style.zIndex=2;			
		}	
		else if (elem_z_index == 2){
			 elem_freccia.style.background = "#FFFFFF url('images/pulsanti-sx.gif') no-repeat   top left";
			 elem_freccia.style.zIndex=1;
   		}
		else if (elem_z_index == 3){
			 elem_freccia.style.background = " #FFFFFF url('images/pulsanti-x-gray.gif') no-repeat   top left";
			 elem_freccia.style.zIndex=4;
   		}
		else if(elem_z_index == 4){
			 elem_freccia.style.background = " #FFFFFF url('images/pulsanti-x-orange.gif') no-repeat  top left";
			 elem_freccia.style.zIndex=3;
   		}
   }
   

/**************************************
    Controllo del Codice Fiscale
    Linguaggio: JavaScript
***************************************/

function ControllaCF(cf)
{
    var validi, i, s, set1, set2, setpari, setdisp;
    if( cf == '' )  return '';
    cf = cf.toUpperCase();
    if( cf.length != 16 )
        return "La lunghezza del codice fiscale non è\n"
        +"corretta: il codice fiscale dovrebbe essere lungo\n"
        +"esattamente 16 caratteri.\n";
    validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for( i = 0; i < 16; i++ ){
        if( validi.indexOf( cf.charAt(i) ) == -1 )
            return "Il codice fiscale contiene un carattere non valido `" +
                cf.charAt(i) +
                "'.\nI caratteri validi sono le lettere e le cifre.\n";
    }
    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) )
        return "Il codice fiscale non è corretto:\n"+
            "il codice di controllo non corrisponde.\n";
    return "";
}

