// 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 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 ShowHideLayer(divID) {
	var box = document.getElementById(divID);	
		
	if(box.style.display == "none" || box.style.display=="") {
		box.style.display = "block"; 		
	}
	else {
		box.style.display = "none";		
	}
}
function displaycheck()
{
	if(http.readyState == 4)
	{
		var showcheck = http.responseText;
		if(showcheck == '1')
		{
			document.getElementById('captcha').style.border = '3px solid #49c24f';
			document.getElementById('captcha').style.background = '#bcffbf';
			
//new_application.new_application_submit.disabled=true;
//new_application.new_application_submit.value='Submiting ... Please wait ...';
//ShowHideLayer('mainContent');ShowHideLayer('popup');
var box = document.getElementById('mainContent');
var box2 = document.getElementById('popup');
box.style.display = "none";
box2.style.display = "block";

			document.new_application.submit();
						
		}
		if(showcheck == '0')
		{
			document.getElementById('captcha').style.border = '3px solid #c24949';
			document.getElementById('captcha').style.background = '#ffbcbc';

		}
	}
}
