// <![CDATA[

$("#fcomm").submit(function(){
   check();
   return false;
});

$("#img_captcha").click(function(){
  dorefresh();
});

function createRequestObject() {
	try {
		xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e){
		
	}
	return xmlhttp;
}

var http = createRequestObject();
var http2 = createRequestObject();

function dorefresh()
{
	http2.open('POST', '/assets/files/nospam/image_req.php', true);
	http2.onreadystatechange = displayimg;
	http2.send(null);
}

function displayimg() {
	if(http2.readyState == 4) { 
		var showimage = http2.responseText;
		$("img#img_captcha").attr({ 
	        src: showimage
	    });
	}
}

function check() {
	var submission = document.getElementById('vericode').value;
	var url = '/assets/files/nospam/process.php?captcha=' + submission;
	http.open('GET', url, true);
	http.onreadystatechange = displaycheck;
	http.send(null);
}

function displaycheck() {
	if (http.readyState == 4) {
		var showcheck = http.responseText;
		if (showcheck === "0") {
		    dorefresh();
		}
		else {
			$("#fcommsubmit").click();
			return true;
		}
	}
}
// ]]>
