// checkCaptcha() Sends code to page to check match
function checkCaptcha()
{
	getCode = document.getElementById('security_code').value;
	
	newUrl = "check_captcha.php?code="+getCode;
	sendRequest(newUrl,captchaResponse);
}

// captchaResponse() Return valid or not valid
function captchaResponse()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		getResponse = xmlHttp.responseText;
		
		if (getResponse == 1)
		{
			document.form1.submit();
		}
		else
		{
			alert("The code you entered does not match the code displayed.  Please try again");
		}
	}
}

//sendRequest() sends url to relevant ajax page
function sendRequest(getUrl,getResponse)
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = getUrl;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = getResponse;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// GetXmlHttpObject() initialises new ajax object
function GetXmlHttpObject()
{
	var xmlHttp = null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
