var votes=
{
	xmlhttp: false,
	phpscript: '/myforum/msgvote.php',
	
	
	init: function()
	{
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				this.xmlhttp = false;
			}
		}
		if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
			this.xmlhttp = new XMLHttpRequest();
		}
	},
	
	send: function(vars,events)
	{
		this.xmlhttp.open("POST",this.phpscript,true);
		this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
		this.xmlhttp.setRequestHeader('x-sender', 'forum_kirishi_ru')
		this.xmlhttp.onreadystatechange=function(xmlhttp,events)
		{
			return function()
			{
				if(xmlhttp.readyState==4)
				{
					if(xmlhttp.status == 200) {
						if(typeof events=='object')
						{
							if(typeof events.onSuccess=='function')
							{
								events.onSuccess(xmlhttp.responseText);
							}
						}
					}else{
						events.onError(xmlhttp.status);
					}
				}
			}
		}(this.xmlhttp,events);
		this.xmlhttp.send(vars);
	},
	
	msgup: function(msg_id)
	{
		if(!this.xmlhttp)
			this.init();
		if(!this.xmlhttp)
			return;
		vars='mode=msgvoteup&msg_id='+msg_id;
		this.send(vars,{
			onSuccess: function(data)
			{
				try{
					eval('o='+data);
				}catch(e){
					//alert('Ой, произошла какая-то ошибка. Попробуйте перезагрузить страницу и нажать ещё раз!');
					//alert(e.message + "\n" + data);
					return true;
				}
				msg_id=o.msg_id;
				try{
					id=document.getElementById('is_voted_'+msg_id);
					id.style.display='inline';
					hid=document.getElementById('voted_mng_'+msg_id);
					hid.style.display='none';
					if(o.mcount>0)
					{
						mid=document.getElementById('msg_minus_'+msg_id);
						mid.style.display='inline';
						mid.innerHTML=o.mcount;
					}
					if(o.pcount>0)
					{
						pid=document.getElementById('msg_plus_'+msg_id);
						pid.style.display='inline';
						pid.innerHTML=o.pcount;
					}
				}catch(e){
					alert(e.message);
				}
			},
			onError: function(errorCode)
			{
				alert(errorCode);
			}
		});
		
		return false;
	},
	
	msgdn: function(msg_id)
	{
		if(!this.xmlhttp)
			this.init();
		if(!this.xmlhttp)
			return;
		vars='mode=msgvotedn&msg_id='+msg_id;
		this.send(vars,{
			onSuccess: function(data)
			{
				try{
					eval('o='+data);
				}catch(e){
					//alert(e.message + "\n" + data);
					return true;
				}
				msg_id=o.msg_id;
				try{
					id=document.getElementById('is_voted_'+msg_id);
					id.style.display='inline';
					hid=document.getElementById('voted_mng_'+msg_id);
					hid.style.display='none';
					if(o.mcount>0)
					{
						mid=document.getElementById('msg_minus_'+msg_id);
						mid.style.display='inline';
						mid.innerHTML=o.mcount;
					}
					if(o.pcount>0)
					{
						pid=document.getElementById('msg_plus_'+msg_id);
						pid.style.display='inline';
						pid.innerHTML=o.pcount;
					}
				}catch(e){
					alert(e.message);
				}
			},
			onError: function(errorCode)
			{
				alert(errorCode);
			}
		});
		
		return false;
	},
	
	catmarkread: function(forum_id,obj)
	{
		if(!this.xmlhttp)
			this.init();
		if(!this.xmlhttp)
			return;
		vars='mode=catmarkread&forum_id='+forum_id;
		this.send(vars,{
			onSuccess: function(data)
			{
				try{
					eval('o='+data);
				}catch(e){
					//alert(e.message + "\n" + data);return false;
					return true;
				}
				var answer=o.answer;
				if(answer=='error')return true;
				var forum_id=o.forum_id;
				try
				{
					iid=document.getElementById('img_razd_'+forum_id);
					if(iid)iid.src=iid.src.replace(/_new/,'');
					
					lid=document.getElementById('lnk_razd_'+forum_id);
					if(lid)lid.className=lid.className.replace(/_sel/,'');
					
					if(obj)obj.style.display="none";
				}catch(e){}
			},
			onError: function(errorCode)
			{
				alert(errorCode);
			}
		});
		return false;
	},
	
	thmarkread: function(theme_id,obj)
	{
		if(!this.xmlhttp)
			this.init();
		if(!this.xmlhttp)
			return;
		vars='mode=thmarkread&theme_id='+theme_id;
		this.send(vars,{
			onSuccess: function(data)
			{
				try{
					eval('o='+data);
				}catch(e){
					//alert(e.message + "\n" + data);return false;
					return true;
				}
				var answer=o.answer;
				if(answer=='error')return true;
				var theme_id=o.theme_id;
				try
				{
					iid=document.getElementById('img_th_'+theme_id);
					if(iid)iid.src=iid.src.replace(/_new/,'');
					
					iid=document.getElementById('img_last_'+theme_id);
					if(iid)iid.src=iid.src.replace(/newest/,'latest');
					
					if(obj.parentNode && obj.parentNode.parentNode)
					{
						var p=obj.parentNode.parentNode;
						pages=p.getElementsByTagName('A');
						for(n=0,nl=pages.length;n<nl;n++)
						{
							if(pages[n].id=='new_page')
								pages[n].id='';
						}
					}
					if(obj)obj.style.display="none";
				}catch(e){}
			},
			onError: function(errorCode)
			{
				alert(errorCode);
			}
		});
		return false;
	}
}

//votes.msgup(100);