function ChiudiModulo() {
  document.getElementById('InviaAdAmico').style.visibility="hidden";
  document.getElementById('InviaAdAmicoModulo').style.visibility="hidden";
}
function AttivaModulo() {
  document.getElementById('InviaAdAmicoModulo').innerHTML = document.getElementById('InviaAdAmicoModuloNascosto').innerHTML;
  document.getElementById('InviaAdAmico').style.visibility="";
  document.getElementById('InviaAdAmicoModulo').style.visibility="";
}
// make asynchronous HTTP request using the XMLHttpRequest object 
function InviaModulo() {
  // setStatusInfo('<img src=\'/euro/ajaxload.gif\' width=\'16\' height=\'16\' alt=\'\' />');
  NomeMittente = document.forms['ModuloInvio'].NomeMittente.value;
  EmailDestinatario = document.forms['ModuloInvio'].EmailDestinatario.value;
  Testo = document.forms['ModuloInvio'].Testo.value;
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // execute the ratesxml.php page from the server
    var UrlToRequest = "./inviaAmico.php";
    UrlToRequest += "?NomeMittente=" + NomeMittente; 
    UrlToRequest += "&EmailDestinatario=" + EmailDestinatario; 
    UrlToRequest += "&Testo=" + Testo; 
    xmlHttp.open("GET", UrlToRequest, true);  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponseModulo;
    // make the server request
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('InviaModulo()', 1000);
}
// executed automatically when a message is received from the server
function handleServerResponseModulo() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) {
        // read the message from the server
        var result = xmlHttp.responseText;
        if (result != "") {
          document.getElementById('InviaAdAmicoModulo').innerHTML = result;
          window.setTimeout("ChiudiModulo()",3000);
        }
    }
    // a HTTP status different than 200 signals an error
    else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
