
function processCaptcha(text){
	//alert(text);
	if(document.getElementById('error_captcha')){document.getElementById('error_captcha').style.display = 'none';};
	if(document.getElementById('error_not_captcha')){document.getElementById('error_not_captcha').style.display = 'none';};
	if(document.getElementById('error_comment')){document.getElementById('error_comment').style.display = 'none';};

	if (text=='Error: Text empty'){
		document.getElementById('comment_form_submit').disabled=false;
		document.getElementById('loadImg').style.display = 'none';
		if(document.getElementById('comment_form_captcha')){
			document.getElementById('comment_form_captcha').src='/tools/comment_captcha.php?'+Math.random();
			document.getElementById('error_not_captcha').style.display = 'block';
		}else{
		}
		document.getElementById('error_comment').style.display = 'block';
		return;
	}
	if (text=='Error: captcha'){
		document.getElementById('comment_form_submit').disabled=false;
		document.getElementById('loadImg').style.display = 'none';
		document.getElementById('comment_form_captcha').src='/tools/comment_captcha.php?'+Math.random();
		document.getElementById('error_captcha').style.display = 'block';
		return;
	}
//	alert(text);
	location.href=text;
//	location.reload(true);
;
}

function processReqChange(req,callbackFunc){ 
	if (req.readyState==4){
		callbackFunc(req.responseText);
	}
}

function ajax(url,arr,callbackFunc,context,method) {
	if(!method) method='GET';
    if (window.XMLHttpRequest) {
        var req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        var msv= ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		for(var j=0;j<=msv.length;j++){ try { req = new ActiveXObject(msv[j]); if (req) break;} catch(e){;}}
    }
	var params='';
	if(method=='POST' && arr) 
		for (var s in arr)
			params+=encodeURIComponent(s)+'='+encodeURIComponent(arr[s])+'&';
//	req.callbackFunc=callbackFunc;
	var callbackF=callbackFunc;
	req.onreadystatechange=function() {processReqChange(req,callbackF)};
    req.open(method, url);//+'&rand='+Math.random(), true);
//	req.overrideMimeType('text/xml');
	if(method=='POST')
		req.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
//	alert(arr);
    req.send(params);
}
var commentForm;
var elements;
var arr;
function checkCAPTCHA(){
	document.getElementById('comment_form_submit').disabled="1";
	document.getElementById('loadImg').style.display = 'block';
	//return;
//	alert(captcha);
	commentForm=document.getElementById('comment_input_form').elements;
	arr={};
	for(i=0;i<commentForm.length;i++){
//		alert(commentForm[i].name);
		arr[commentForm[i].name]=commentForm[i].value;
	}
//		alert(arr[arr.length]=inp.value);
	ajax('/comments.php',arr,processCaptcha,null,'POST');
}


