
        var url = '/forms/captcheck.php?captchacode=';
        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.\n you entered ['+document.myform.captcha.value+"]");
              document.myform.captchacode.value='';
              document.myform.captchacode.focus();
              return false;
              }
              document.myform.submit();
           }
        }

        function checkcode(thecode) {
        http.open("GET", url + escape(thecode), true);
        http.onreadystatechange = handleHttpResponse;
        http.send(null);
        }
        
        function checkform() {
        	// First the normal form validation
		var temp = document.myform.required_fields.value.split(',');
		var red = 0;
		for (a in temp ) {
			//alert(document.myform[temp[a]].value);
        		if(document.myform[temp[a]].value=='') {
				red = 1;
          			document.myform[temp[a]].focus();
				document.myform[temp[a]].style.backgroundColor = '#ffcccc';
			} else {
				document.myform[temp[a]].style.backgroundColor = '#ffffff';
			}
          	}
		if (red) {
          		alert('Please complete the items marked in pink.');
          		return false;
		}
        	if(document.myform.captchacode.value=='') {
          		alert('Please enter the numbers from the displayed image');
          		document.myform.captchacode.value='';
          		document.myform.captchacode.focus();
          		return false;
          	}
          	// Now the Ajax CAPTCHA validation
          	checkcode(document.myform.captchacode.value);
          	return false;
        }      
        
        

