function c_ajax()
{
	this.request=false;
	if(window.XMLHttpRequest)
		this.request = new XMLHttpRequest();
	else
		if(window.ActiveXObject)
		{
			this.request = new ActiveXObject("Microsoft.XMLHTTP");
			if(!this.request)
				this.request = new ActiveXObject("Msxml2.XMLHTTP");
		}
	if(!window.a_ajax)
		window.a_ajax=new Array();
	this.numb=a_ajax.length;
	a_ajax[this.numb]=this;
}

c_ajax.prototype.exec = function()
{
	if(!this.hand)
		return;
	if(!this.request)
		return;
	if(this.request.readyState == 4)
		if(this.request.status == 200 || this.request.status == 304)
			this.hand(this,this.request.responseText);
}

c_ajax.prototype.post = function(s_url,f_hand,a_data)
{
	var s_data='';

	if(!this.request)
		return false;
	if(a_data)
		for(var name in a_data)
			s_data+=encodeURIComponent(name)+"="+encodeURIComponent(a_data[name])+"&";
	if(f_hand)
		this.hand=f_hand;
	var numb = this.numb;
	this.request.onreadystatechange = function(){a_ajax[numb].exec();}
	this.request.open("POST",s_url,true);
	this.request.setRequestHeader("X-Referrer",document.location);
	this.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	this.request.setRequestHeader("Content-length", s_data.length);
	this.request.setRequestHeader("Connection", "close");
	this.request.send(s_data);
	return true;
}

c_ajax.prototype.get = function(s_url,f_hand,a_data)
{
	var s_data='';

	if(!this.request)
		return false;
	if(a_data)
		for(var name in a_data)
			s_data+=encodeURIComponent(name)+"="+encodeURIComponent(a_data[name])+"&";
	if(f_hand)
		this.hand=f_hand;
	var numb = this.numb;
	this.request.onreadystatechange = function(){a_ajax[numb].exec();}
	if(s_data)
		if(s_url.indexOf("?")==-1)
			s_url=s_url+'?'+s_data;
		else
			s_url=s_url+'&'+s_data;
	this.request.open("GET",s_url,true);
	this.request.setRequestHeader("X-Referrer",document.location);
	this.request.send(null);
	return true;
}

function comment_submit(f,lang)
{
	var load=new c_ajax();
	load.form=f;
	load.lang=lang;
	load.data=new Array();
	load.data['TEXT']=f.elements['TEXT'].value;
	load.data['PATH']=f.elements['PATH'].value;
	if(f.elements['MAIL'])
		load.data['MAIL']=f.elements['MAIL'].value;
	if(f.elements['NAME'])
		load.data['NAME']=f.elements['NAME'].value;
	load.post("/users/register/comment.html",comment_submit_hand,load.data);
}

function comment_submit_hand(ajax,text)
{
	if(text=='OK')
	{
		ajax.form.elements['TEXT'].value='';
		comment_box();
		if(ajax.lang=='ru')
			alert('Спасибо! Ваш комментарий будет опубликован после проверки администрацией сайта');
		else
			if(ajax.lang=='uk')
				alert('Дякуємо! Ваш коментарій буде опублікований після перевірки адміністрацією сайту');
			else
				alert('Thank you!');
		return;
	}
	alert(text);
}

function comment_box()
{
	if(!document.getElementById("commentbox"))
		return;
	if(document.getElementById("commentbox").style.display=="block")
		document.getElementById("commentbox").style.display="none";
	else
		document.getElementById("commentbox").style.display="block";
}
