         var xmlHttpReq = false;

         // crea l'oggetto xmlHttp e gli assegna un handler di risposta.
         function CreateXmlHttpReq(handler) {

                  var obj_xmlHttp = false;

                  try {
                       obj_xmlHttp = new XMLHttpRequest();
                       obj_xmlHttp.overrideMimeType('text/xml');
                  }catch(e) {
                       try {
                            obj_xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                       }catch(e){
                            obj_xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                       }
                  }
                  obj_xmlHttp.onreadystatechange = handler;
                  return obj_xmlHttp;
         }

         // la funzione handler assegnata all'oggetto xmlHttp
         function JS_Response() {

                  e = document.getElementById("risultato");

                  if(xmlHttpReq.readyState == 4) {
                     strResponse = xmlHttpReq.responseText;
                     switch (xmlHttpReq.status) {
                             // pagina non trovata
                             case 404:
                                  e.innerHTML = "Errore: la pagina chiamata non esiste.";
                             break;
                             case 500:
                                  e.innerHTML = "Errore: il server non risponde.";
                             break;
                             // unico caso in cui č tutto OK!
                             case 200:
                                  e.innerHTML = strResponse;
								  document.mdmContattaci.nome.value="";
								  document.mdmContattaci.cognome.value="";
								  document.mdmContattaci.email.value="";
								  document.mdmContattaci.confemail.value="";
								  document.mdmContattaci.azienda.value="";
								  document.mdmContattaci.via.value="";
								  document.mdmContattaci.citta.value="";
								  document.mdmContattaci.cap.value="";
								  document.mdmContattaci.prov.value="";
								  document.mdmContattaci.oggetto.value="";
								  document.mdmContattaci.testo.value="";					  
								  
                             break;
                     }
                  }else{
                     e.innerHTML = "Operazione in corso. Attendere...";
                  }
         }

         // formatta i dati per essere spediti in POST
         function formData2QueryString(docForm) {

                  var strSubmit       = "";
                  var strLastElemName = "";
                  var r               = Math.random();
                  var formElem;

                  for(i=0; i<docForm.elements.length; i++) {
                      formElem = docForm.elements[i];
                      switch(formElem.type) {
                             case "text":
                             case "select-one":
                             case "hidden":
                             case "password":
                             case "textarea":
                                   strSubmit += formElem.name + "=" + escape(formElem.value) + "&"
                             break;
                      }
                  }
                  // aggiunge un numero rand x problemi di cache su IE
                  strSubmit += "rand="+escape(r);
                  return(strSubmit);
         }

         // prende i dati dal form ed esegue la chiamata all'oggetto xmlHttp
         // uso: getDati(nomeForm, method, pagina.php);
         function getDati(docForm, metodo, strUrl) {

                  var strDati = "";

                  /*for(i=0; i<docForm.elements.length; i++) {
                      if(docForm.elements[i].value == "") {
                         return(alert("Il campo: "+docForm.elements[i].name+" non puņ essere vuoto."));
                      }
                  }*/

                  strDati = formData2QueryString(docForm);

                  // chiamata all'oggetto xmlHttpReq
                  xmlHttpReq = CreateXmlHttpReq(JS_Response);
                  xmlHttpReq.open(metodo, strUrl, true);
                  xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                  xmlHttpReq.send(strDati);
         }