// JavaScript Document

var url = './Reportcaptcheck.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('Please enter correct code');
	  document.testimonialForm.code.value='';
	  document.testimonialForm.code.focus();
	  img = document.getElementById('captchaID'); 
	  //Change the image
	  img.src = './captcha/CaptchaSecurityImages.php?width=100&height=40&characters=5&' + Math.random();
	   return false;
	  }
	  var obj=document.testimonialForm;
	  obj.action="testimonials.php?action=add";
	  obj.submit();
   }
}

function checkcode(thecode) {
http.open("GET", url + escape(thecode), true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}