        var url = 'forms/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;

         }

        }



        function checkcode(thecode) {

        http.open("GET", url + escape(thecode), false);

        http.onreadystatechange = handleHttpResponse;

        http.send(null);

        }

        

        function checkform(frm) {


        // First the normal form validation

        if(frm.firstname.value=='') {

          alert('Please complete the "first name" field');

          frm.firstname.focus();

          return false;

          }

        if(frm.lastname.value=='') {

          alert('Please complete the "last name" field');

          frm.lastname.focus();

          return false;

          }

        if(frm.email.value=='') {

          alert('Please complete the "email" field');

          frm.email.focus();

          return false;

          }

        if(frm.tel.value=='') {

          alert('Please complete the "telephone" field');

          frm.tel.focus();

          return false;

          }

	if(frm.form_name.value=='contact') {

		if(!frm.Property_To_Buy.checked && !frm.Property_To_Sell.checked) {

	          alert('Please indicate whether you are looking to buy and/or sell a Property');

        	  frm.Property_To_Buy.focus();
	
        	  return false;

	          }
	}


        if(frm.code.value=='') {

          alert('Please enter the string from the displayed image');

          frm.code.value='';

          frm.code.focus();

          return false;

          }

          // Now the Ajax CAPTCHA validation
          
          checkcode(frm.code.value)

          if(captchaOK != 1) 
          {
            alert('The entered code was not correct. Please try again');
			frm.code.value='';
			
			frm.code.focus();
			
			return false;

		  }
		  else
		  {
          	frm.submit();
		  }
        }      

