// CREATING THE REQUEST
function createRequestObject()
{
	try
	{
		xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		alert('Sorry, but your browser doesn\'t support XMLHttpRequest.');
	}
	return xmlhttp;
}
var http = createRequestObject();
var sess = createRequestObject();
// IMAGE REFRESHING
function refreshimg()
{
	var url = 'image_req.php';
	dorefresh(url, displayimg);
}
function dorefresh(url, callback)
{
	sess.open('POST', 'newsession.php', true);
	sess.send(null);
	http.open('POST', url, true);
	http.onreadystatechange = displayimg;
	http.send(null);
}
function displayimg()
{
	if(http.readyState == 4)
	{
		var showimage = http.responseText;
		document.getElementById('captchaimage').innerHTML = showimage;
	}
}
// SUBMISSION
function check()
{
	var secure1 = document.getElementById('security1').value;
	var secure2 = document.getElementById('security2').value;
	var secure3 = document.getElementById('security3').value;
	
	secure1 = parseInt(secure1);
	secure2 = parseInt(secure2);
	secure3 = parseInt(secure3);
	
	if(secure1+secure2 != secure3)
	{
		alert('Incorrect Validation Code.');
		document.getElementById('security3').focus();
		return false;
	} else {
		document.forms[0].submit();
	}
	
/*	var submission = document.getElementById('captcha').value;
	var url = '../process.php?captcha=' + submission;
	docheck(url, displaycheck); */
}
function docheck(url, callback)
{
	http.open('GET', url, true);
	http.onreadystatechange = displaycheck;
	http.send(null);
}
function displaycheck()
{
	
	if(http.readyState == 4)
	{
		
		var showcheck = http.responseText;
		
	
		
		if(showcheck == '1')
		{
			captchaTrue()
		}
		if(showcheck == '0')
		{
			captchaFalse();
		}
	}
	return 0;
}
function captchaFalse()
{
	alert("Image code is invalid");
	document.getElementById('captcha').focus();
	return false;
	

}
function captchaTrue()
{
	
	document.forms[0].submit();
}