var url = 'captcha/captcheck.php?code='; 
var captchaOK = 2; // 2 - not yet checked, 1 - correct, 0 - failed 

function getHTTPObject() {
	try { 
		req = new XMLHttpRequest(); 
	} 
	catch (err1) { 
		try { 
			req = new ActiveXObject("Msxml12.XMLHTTP"); 
		} 
		catch (err2) { 
			try { 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
			} 
			catch (err3) { 
				req = false; 
			} 
		} 
	} 
return req; 
} 

//This function is changed By Robin to handle Captcha Validation on Submit
function checkcode(thecode,FormToValidate) {
	
	http = getHTTPObject();
	http.open("GET", url + escape(thecode), true);
	http.onreadystatechange = function(){
		if ( http.readyState == 4 && http.status == 200) {
			captchaOK = http.responseText;
			if(captchaOK != 1) {
				$("#catchalabel").html('Invalid Text Entered, Try Again.');
				$("#catchalabel").css('display','block');
				thecode='';
				$("#captcha").focus();
				return false; 
			}
			FormToValidate.submit();
		}
	}
	http.send(null);
} 

function checkform(FormToValidate) { // First the normal form validation
// Now the Ajax CAPTCHA validation 
retval = checkcode($("#captcha").val(),FormToValidate);
return false;
} 

