
var url = '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; } 
var http = getHTTPObject(); 
// We create the HTTP Object 
function handleHttpResponse() { 
if (http.readyState == 4) { 
captchaOK = http.responseText; 
if(captchaOK != 1) 
{ alert('The entered code was not correct. Please try again.');
newCaptcha(); 
document.commentForm.captcha.value=''; 
document.commentForm.captcha.focus(); 
return false; } document.commentForm.submit(); } } 
function checkcode(thecode) { 
http.open("GET", url + escape(thecode), true); 
http.onreadystatechange = handleHttpResponse; 
http.send(null); } 

function checkform() { 
document.commentForm.source.value="YES"; 
// indicate form checked by JS

// First the normal form validation 
/*
if(document.commentForm.user.value=='') { 
alert('Please enter a name.'); 
document.commentForm.user.focus(); 
return false; } 
	*/
if(document.commentForm.captcha.value=='') { 
alert('Please enter your code (the letters in the image displayed below).'); 
document.commentForm.captcha.value=''; 
document.commentForm.captcha.focus(); 
return false; } 
// Now the Ajax CAPTCHA validation 
checkcode(document.commentForm.captcha.value); 
return false; } 

      image = "captcha.php" //name of the image
      function newCaptcha() {
      tmp = new Date();
      tmp = "?"+tmp.getTime();
      document.images["captchaImage"].src = image+tmp; 
      }
      Start();
