/* <![CDATA[ */

// Store a handle to an Ajax object
var xmlHttp;

// This function attempts to obtain ajax functionality and returns a handle to an ajax request
function getajax()
{
	var xmlHttp;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer 6.0+
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			// Internet Explorer 5.5+
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				return null;
			}
    		} 
	} 

	return xmlHttp;
}

// This function POSTs data when javascript is enabled
function javasubmit()
{
	// Check to see if ajax is enabled, if so override the default form action
	if(xmlHttp)
	{
		// Prepare the data
		var data = "name=" + document.getElementById("name").value + "&";

		data += "email=" + document.getElementById("email").value + "&";

		data += "enquiry=" + document.getElementById("enquiry").value;

		// POST the data
		xmlHttp.onreadystatechange = postformhandler;

		xmlHttp.open("POST", "contactformsubmitajax.php", true);

		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", data.length);
		xmlHttp.setRequestHeader("Connection", "close");

		xmlHttp.send(data);

		return false;
	}
	else
	{
		return true;
	}
}

// This function handles the result of a sucessful ajax POST
function postformhandler()
{
	if(xmlHttp.readyState == 4)
	{
		// The POST is complete, check for the server's response
		if(xmlHttp.responseText == "1")
		{
			// Confirm sucessful form submission
			alert("Your Enquiry has been submitted sucessfully.");

			window.close();
		}
		else
		{
			// Confirm unsucessful form submission
			alert("There was an error submitting your enquiry, please try again later or use an alternative contact method.");
			
			window.close();
		}
	}
}

// This function identifies if ajax is avaliable and stores an ajax handle globally
function contactformsetup()
{
	xmlHttp = getajax();
}

/* ]]> */