/*
	- createAjax.js [create ajax request for sendMail.php]

*/

var xmlHttp = createXmlHttpRequestObject();

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject()
{
	var xmlHttp;
	//Internet Explorer
	if(window.ActiveXObject)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = false;
		}
	}
	//Mozilla or other browsers
	else
	{
		try
		{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlHttp = false;
		}
	}
	
	if (!xmlHttp)
	alert("Error creating the XMLHttpRequest object.");
	else
	return xmlHttp;
}

function process()
{ 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		fname = encodeURIComponent(document.getElementById("first_name").value);
		lname = encodeURIComponent(document.getElementById("last_name").value);
		email = document.getElementById("email").value;

		var queryString = "?fname=" + fname + "&lname=" + lname + "&email=" + email;
		xmlHttp.open("GET", "sendMail.php" + queryString, true);

		
		xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
}

function handleServerResponse()
{
	if (xmlHttp.readyState == 4)
	{	
		if (xmlHttp.status == 200)
		{
			xmlResponse = xmlHttp.responseXML;
			xmlDocumentElement = xmlResponse.documentElement;
			returnMessage = xmlDocumentElement.firstChild.data;
 		
		}
		else
		{
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}
