
function inviaRichiesta(){

	
	document.getElementById("txtHintMail").innerHTML="";
	document.getElementById("txtLoadingMail").innerHTML="<center><img src='images/loading2.gif'></center>";
	
	var nome = document.getElementById("nome").value;
	var cellulare = document.getElementById("cellulare").value;
	var email = document.getElementById("email").value;
	var richieste = document.getElementById("richieste").value;
	
		
	if (nome == "" || cellulare == "" ||  richieste == "" || email == "")
	{
		document.getElementById("txtHintMail").innerHTML="<b><center><font style='color:#FF0000' style='font-size:11px'>Compilare tutti i campi.</font></b>";
		document.getElementById("txtLoadingMail").innerHTML="";
		return;
	}

	if (!validateEmail(email))
	{
		document.getElementById("txtHintMail").innerHTML="<b><center><font style='color:#FF0000' style='font-size:11px'>Email non corretta.</font></b>";
		document.getElementById("txtLoadingMail").innerHTML="";
		return;
	}
	
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }

	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
		document.getElementById("txtHintMail").innerHTML="";
		document.getElementById("txtLoadingMail").innerHTML="";
		
		}
	  }
	xmlhttp.open("GET","inviaRichiesta.php?nome="+nome+"&cellulare="+cellulare+"&email="+email+"&richieste="+richieste,true);
	xmlhttp.send();

}

function validateEmail(email) {
		var at = email.lastIndexOf("@");

		// Make sure the at (@) sybmol exists and  
		// it is not the first or last character
		if (at < 1 || (at + 1) === email.length)
			return false;

		// Make sure there aren't multiple periods together
		if (/(\.{2,})/.test(email))
			return false;

		// Break up the local and domain portions
		var local = email.substring(0, at);
		var domain = email.substring(at + 1);

		// Check lengths
		if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
			return false;

		// Make sure local and domain don't start with or end with a period
		if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
			return false;

		// Check for quoted-string addresses
		// Since almost anything is allowed in a quoted-string address,
		// we're just going to let them go through
		if (!/^"(.+)"$/.test(local)) {
			// It's a dot-string address...check for valid characters
			if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
				return false;
		}

		// Make sure domain contains only valid characters and at least one period
		if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
			return false;	

		return true;
	}

