// JavaScript Document
// CREATING THE REQUEST
/*
function createRequestObject_sp()
{
	try
	{
		xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		alert('Sorry, but your browser doesn\'t support XMLHttpRequest.');
	}
	return xmlhttp;
}
*/

function createRequestObject_sp() {
			var ro;
			var browser = navigator.appName;
			if(browser == "Microsoft Internet Explorer"){
				ro = new ActiveXObject("Microsoft.XMLHTTP");
			}else{
				ro = new XMLHttpRequest();
			}
			return ro;
		}
		
var http = createRequestObject_sp();
var sess = createRequestObject_sp();

// IMAGE REFRESHING

function refreshimg()
{
	var url = 'components/com_agents/image_req.php';
	dorefresh(url, displayimg);
}

function dorefresh(url, callback)
{
	//sess.open('GET', 'components/com_agents/newsession.php', true);
	//sess.send(null);
	http.open('GET', url, true);
	http.onreadystatechange = displayimg;
	http.send(null);
}

function displayimg()
{
	if(http.readyState == 4)
	{
		var showimage = http.responseText;
		document.getElementById('hid_cap_id').value = showimage;
		document.getElementById('captchaimage').innerHTML = '<a href="index.php" onclick="refreshimg(); return false;" title="Click to refresh image"><img style="border: 1px solid #7f9db9;" src="images_2/image.php?captcha_id='+showimage+'" width="132" height="46" alt="Captcha image" /></a>';
		
	}
}

// SUBMISSION

/*function check()
{
	var submission = document.getElementById('captcha').value;
	var url = 'process.php?captcha=' + submission;
	docheck(url, displaycheck);
}*/

function docheck(url, callback)
{
	alert(url);
	http.open('GET', url, true);
	http.onreadystatechange = displaycheck;
	http.send(null);
}

function displaycheck()
{
	if(http.readyState == 4)
	{
		var showcheck = http.responseText;
		alert(showcheck+' Shocheck');
		if(showcheck == '1')
		{
			document.getElementById('captcha').style.border = '1px solid #49c24f';
			document.getElementById('captcha').style.background = '#bcffbf';
			alert('True');
			return true;
		}
		if(showcheck == '0')
		{
			document.getElementById('captcha').style.border = '1px solid #c24949';
			document.getElementById('captcha').style.background = '#ffbcbc';
			alert('False');
			return false;

		}
	}
}

function check_form(myForm)
	            {
					var submission = document.getElementById('captcha').value;
					var hid_cap_id = document.getElementById('hid_cap_id').value;
					
					if(myForm.user_name.value == ''){
						alert('Please complete the name field.');
						myForm.user_name.focus;
						return false;
					}else if(myForm.user_email.value == ''){
						alert('Please complete the email field.');
						myForm.user_email.focus;
						return false;
					}
					else if(hid_cap_id!=submission){
						alert('Verification Code doesn\'t match.');
						return false;
					}
					else{
						return true;	
					}
				}