// JavaScript Document
var xmlhttpContactus;

function chkSubmit()
{
	var name;
	var email;
	var azenda;
	var phone;
	var message;
	
	name = document.getElementById('name').value;
	email = document.getElementById('email').value;
	azenda = document.getElementById('azenda').value;
	phone = document.getElementById('phone').value;
	message = document.getElementById('message').value;
	
	if (name=="")
	{
		alert('Inserisci il tuo nome');		
		document.getElementById('name').focus();
		return false;
	}
	
	if (email=="")
	{
		alert('Inserisci il tuo indirizzo e-mail');	
		document.getElementById('email').focus();
		return false;
	}
	
	if(email!="")
	{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email;
		if(reg.test(address) == false) 
		{
		alert('Indirizzo e-mail valido');
		document.getElementById('email').focus();
		return false;
		}
	}
	
	if (phone=="")
	{
		alert('Inserisci il tuo tel');		
		document.getElementById('phone').focus();
		return false;
	}
	
	
	
	xmlhttpContactus=GetXmlHttpObjectContact();
	if (xmlhttpContactus==null)
	{
	alert ("Browser does not support HTTP Request");
	return;
	}
	var url="sendMessage.php";
	url=url+"?name="+name;
	url=url+"&email="+email;
	url=url+"&azenda="+azenda;
	url=url+"&phone="+phone;
	url=url+"&message="+message;
	
	url=url+"&sid="+Math.random();
	
	
	xmlhttpContactus.onreadystatechange=stateChangedPrice;
	xmlhttpContactus.open("GET",url,true);
	xmlhttpContactus.send(null);
}

function stateChangedPrice()
{
	if (xmlhttpContactus.readyState==4)
	{
		document.getElementById('name').value='';
		document.getElementById('email').value='';
		document.getElementById('azenda').value='';
		document.getElementById('phone').value=''
		document.getElementById('message').value='';
		document.getElementById("txtHintContact").innerHTML=xmlhttpContactus.responseText;
	}
}

function GetXmlHttpObjectContact()
{
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.xmlhttpContactus");
	  }
	return null;
}

