
	var url = 'captcheck.php?code=';
	var captchaOK = 2;  // 2 - not yet checked, 1 - correct, 0 - failed
	function gId(id) 
	{
		if(document.getElementById) return document.getElementById(id);
		else return false
	}
	
	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('Zadaný kód není správný. Zkuste to znovu. (The entered code was not correct.)');
				gId("captcha_code").value='';
				gId("captcha_code").focus();
				return false;
			}
			gId("form_1").submit();
		}
	}

	function checkcode(thecode) {
		http.open("GET", url + escape(thecode), true);
		http.onreadystatechange = handleHttpResponse;
		http.send(null);
	}

	function checkform() {
		// First the normal form validation
		if(gId("captcha_code").value=='') {
			alert('Prosím opište text z obrázku. Please enter the string from the displayed image');
			gId("captcha_code").value='';
			gId("captcha_code").focus();
			return false;
		}
		// Now the Ajax CAPTCHA validation
		checkcode(gId("captcha_code").value);
		return false;
	}


