// JavaScript Document
	  
	function eseguiRichiestaHTTP(xmlhttp, url, asinc, returnFunction) {
//creazione oggetto xmlhttp
	  
	  /*@cc_on @*/
	  /*@if (@_jscript_version >= 5)
	  // JScript gives us Conditional compilation, we can cope with old IE versions.
	  // and security blocked creation of the objects.
	  try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (e) {
		try {
		  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		  xmlhttp = false;
		}
	  }
	  @end @*/	  	  
	  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp=false;
		}
	  }
	  if (!xmlhttp && window.createRequest) {
		try {
		  xmlhttp = window.createRequest();
		} catch (e) {
		  xmlhttp=false;
		}
	  }

	  //faccio la richiesta
	  	xmlhttp.open("GET", url, asinc);
	  	xmlhttp.send(null);
	  	if (asinc) xmlhttp.onreadystatechange = returnFunction;
	  
	  //var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	  //if (!xmlDoc.loadXML(xmlhttp.responseText)) {
		//errore da qualche parte
		//if (xmlhttp.responseText.length>0)
		//alert("["+xmlhttp.responseText+"]");
	  //};
	  //return xmlDoc;
	  //alert(xmlhttp.responseText);
	  return xmlhttp;
	}	

	function eseguiRichiestaHTTPPOST(xmlhttp, url, asinc, returnFunction, params) {
//creazione oggetto xmlhttp
	  
	  /*@cc_on @*/
	  /*@if (@_jscript_version >= 5)
	  // JScript gives us Conditional compilation, we can cope with old IE versions.
	  // and security blocked creation of the objects.
	  try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (e) {
		try {
		  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		  xmlhttp = false;
		}
	  }
	  @end @*/	  	  
	  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp=false;
		}
	  }
	  if (!xmlhttp && window.createRequest) {
		try {
		  xmlhttp = window.createRequest();
		} catch (e) {
		  xmlhttp=false;
		}
	  }

	  //faccio la richiesta
		xmlhttp.open("POST", url, asinc);
		
		//Send the proper header information along with the request
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.send(params);
	  	
		if (asinc) xmlhttp.onreadystatechange = returnFunction;
	  
	  return xmlhttp;
	}		

	
	function getHtml(xmlhttp) {

		if(xmlhttp.readyState === 4) {
			if(xmlhttp.status == 200)
			  	return xmlhttp.responseText.replace(/\n/g,"");
			else 
				alert("Operazione fallita, errore numero " + xmlhttp.status);
		}
	}
	
	function insertHtml(ele, xmlhttp) {
		
		if(xmlhttp.readyState === 4) {
			if(xmlhttp.status == 200) {
			  	var htmlText = xmlhttp.responseText.replace(/\n/g,"");
				//alert(newText);
				if (document.getElementById) {
					//Internet explorer

					document.getElementById(ele).innerHTML = htmlText;
				}
				else if (document.all) {
					//mozilla
					document.all[ele].innerHTML = htmlText;
				}
			}
			else alert("Operazione fallita, errore numero " + xmlhttp.status);
		}
	} 
	
	//uso:
	//xmlhttp = eseguiRichiestaHTTP(xmlhttp, url, false);
	//insertHtml("hot_stuff", xmlhttp) oppure document.write(getHtml(xmlhttp));

	function sendMail() {
	
		var mail = document.forms['mailForm'].mail.value;
		var messaggio = document.forms['mailForm'].messaggio.value;
		
		if (mail.length == 0) {
			alert("L'indirizzo mail è vuoto!\nMail address is empty!");
			return;
		} else if (mail.indexOf(" ") > -1) {
			alert("L'indirizzo mail contiene spazi!\nMail address contains blanks!");
			return;
		} else if (mail.indexOf("@") == -1) {
			alert("Nell'indirizzo email manca la @!\nMissing @ in mail address!");
			return;
		} else if (mail.indexOf(".") == -1) {
			alert("Nell'indirizzo email manca il .!\nMissing . in mail address!");
			return;
		} else if (messaggio.length == 0) {
			alert("Il messaggio è vuoto!\nMessage is empty!");
			return;
		} else

		var parms= "name=" + escape(document.forms['mailForm'].nome.value) + "&from=" + escape(mail) + "&subject=" + escape(document.forms['mailForm'].oggetto.value) + "&body=" + escape(messaggio);
		var xmlhttp = eseguiRichiestaHTTPPOST(xmlhttp, "sendMail2.php?timeStamp=" + new Date().getTime(), false, null, parms);
		if(xmlhttp.readyState === 4 && xmlhttp.status == 200 && xmlhttp.responseText.indexOf("OK") > -1) {
			alert("Mail inviata con successo! Questo sito funziona alla grande!\nMail successfully sent! This site works!");
		} else {
			alert("Errore invio mail, comunica subito a 7skies che il suo sito fa cagare!\nSend mail error, please tell 7skies that this site sucks!");	
		}
		
		document.forms['mailForm'].reset();
	
	}