/**
 * 
 *
 * @author Paul Lauria
 * @package defaultPackage
 * @version 1.0
 * @copyright Pixel Lab Studios Ltd.
 */
var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject()	{
	var xmlHttp;
	
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)	{
			try {
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} catch (e) {}
		}
	}
	
	if (!xmlHttp)	{
		alert("Error creating XMLHttpRequest object.");
	} else {
		return xmlHttp;
	}
}

function process_callback()	{
	if (xmlHttp)	{
		try {
			var email = document.getElementById("txtEmail").value;
			var name = document.getElementById("txtName").value;
			var phone = document.getElementById("txtPhone").value;
			xmlHttp.open("GET", "http://www.ldpa.co.uk/callback_request.php?email=" + email + "&name=" + name + "&phone=" + phone, true);
			xmlHttp.onreadystatechange = nl_handleRequestStateChange;
			xmlHttp.send(null);
		} catch (e) {
			alert("Can't connect to server:\n" + e.toString());
		}
	}
}

function nl_handleRequestStateChange()	{
	if (xmlHttp.readyState == 4)	{
		if (xmlHttp.status == 200)	{
			try {
				nl_handleServerResponse();
			} catch (e) {
				alert("Error reading the response:\n" + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

function nl_handleServerResponse()	{
	var xmlResponse = xmlHttp.responseXML;
	if (!xmlResponse || !xmlResponse.documentElement)	{
		throw("Invalid XML Structure:\n" + xmlHttp.responseText);
	}
	var rootNodeName = xmlResponse.documentElement.nodeName;
	if (rootNodeName == "parseerror")	{
		throw("Invalid XML Structure:\n" + xmlHttp.responseText);
	}
	xmlRoot = xmlResponse.documentElement;
	
	if (rootNodeName != "response" || !xmlRoot.firstChild)	{
		throw("Invalid XML Structure:\n" + xmlHttp.responseText);
	}
	
	responseText = xmlRoot.firstChild.data;
	myDiv = document.getElementById("contactWrap");
	myDiv.innerHTML = responseText;
}

function try_again()	{
	formShow = '<div class="contactLeftCall">' +
					'<div class="contactBgCall">Name</div>' +
					'<div class="contactBg2Call">Email</div>' +
					'<div class="contactBg2Call">Phone No.</div>' +
					'</div>' +
					'<div class="contactRight2Call">' +
					'<div class="contactBg2Call"><input class="input" name="txtName" id="txtName" size="18" maxlength="30" value="" /></div>' +
					'<div class="contactBg2Call"><input class="input" name="txtEmail" id="txtEmail" size="18" maxlength="30" value="" /></div>' +
					'<div class="contactBg2Call"><input class="input" name="txtPhone" id="txtPhone" size="18" maxlength="30" value="" /></div>' +
					'</div>' +
					'<div class="submit"><input type="image" src="img/submit.gif" alt="Submit the Query" name="submit" onclick="process_callback();"/></div>';
	myDiv = document.getElementById("contactWrap");
	myDiv.innerHTML = formShow;
}