var xmlhttp

function sendEnquireForm()
{
	//alert(validateEnquireForm())
	if(validateEnquireForm() == true)
	{ 
		
		document.getElementById('submit').src='images/sent1.gif'
		
		url = "enquireProp.php"
	
		vars = "Name=" + document.getElementById('name').value
		vars= vars+ "&Tel=" + document.getElementById('telephone').value
		vars= vars+ "&Email=" + document.getElementById('email').value
		vars= vars+ "&Comments=" + document.getElementById('Comments').value
		vars= vars+ "&PropRef=" + document.getElementById('PropRef').value
		vars= vars+ "&EmailTo=" + document.getElementById('EmailTo').value
		
		//alert(vars)
	
		// code for Mozilla, etc.
		if (window.XMLHttpRequest)
		{
			xmlhttp=new XMLHttpRequest()
			xmlhttp.onreadystatechange=contstate_Change
			xmlhttp.open("POST",url,true)
			xmlhttp.setRequestHeader("Method", "POST "+ url +" HTTP/1.1");
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlhttp.send(vars)
			//alert("sent MOZ")
			}
		// code for IE
		else if (window.ActiveXObject)
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			if (xmlhttp)
		    {
		    	xmlhttp.onreadystatechange=contstate_Change
		    	xmlhttp.open("POST",url,true)
		    	xmlhttp.setRequestHeader("Method", "POST "+ url +" HTTP/1.1");
				xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		    	xmlhttp.send(vars)
		    	//alert("sent IE")
		    }
		 }
	}
}

function contstate_Change()
{
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{
			txt = xmlhttp.responseText
			//alert(txt)

			if (txt.indexOf("SUCCESS") != -1)
			{
				alert("Thanks for your enquiry.\n\nWe will contact you as soon as possible.")
			}
			if (txt.indexOf("FAIL") != -1)
			{
				alert("ERROR PHP: Your enquiry was not received due to techncial problems.\n\nPlease try submitting the form again or email us directly: info@cyprusresalesdirect.com")
			}
			
		}
		else
		{
			alert("ERROR 404: Your enquiry was not received due to techncial problems.\n\nPlease try submitting the form again or email us directly:: info@cyprusresalesdirect.com")
		}
	}
}
