﻿var _host = '/';
function InitCommment(){
	var r = 0; while(r < 0.1){r = Math.random()} 
	var d = Math.floor(r*100000000)
	document.write("<input type='hidden' name='d' value='"+d+"' />");
	document.write("<img src='"+_host+"handler/ch.ashx?d="+d+"' style='float:left;margin-right:5px' />");
}
function trim(string){return string.replace(/(^\s+)|(\s+$)/g, "")}
function validate(){
	_('errorText').h();_('errorCode').h();
	if(trim(_('text').v()).length==0) {_('errorText').s(); return false}
	_('addComment').$.submit();
	return false;
}
function comentParent(id,e,page){
	if(id == _('parent').v() && !page){
		var ac = _('addComment');
		if(ac.isS()) ac.h(); else ac.s();
		if(id==0) _('btnCom').c(_('btnCom').c()=='opn'?'cls':'opn');
		return false
	}
	if(_('parent').v()==0)_('btnCom').c('cls');
	_('parent').v(id);
	if(id==0)_('btnCom').c('opn')
	if(!page)_('addComment').s();
	var tmp = _("addComment").$;
	_("addComment").$.parentNode.removeChild(_("addComment").$);
	e.parentNode.parentNode.appendChild(tmp);
	return false;
}
var curP = 1;
function rate(id,b){_.get(_host+'handler/rateComment.ashx?nid='+_('nid').v()+'&cid='+id+'&p='+curP+(b?'&positive=1':''),rateEnd)}
function rateEnd(d){eval('var i = '+d);_('t'+i.id).t(i.t);_('p'+i.id).t(i.p);_('n'+i.id).t(i.n)}
function commPage(p){
	curP = p;
	var url = _host+'news/'+_('nid').v()+'/comments'+((p==1)?('.htm'):('/'+p+'.htm'))
	_.get(url,commPageEnd); 
	_.url("#comment")
}
function commPageEnd(d){
	if(_('btnCom').$!=null)
		comentParent(0, _('btnCom').$,true)
	if(_('addComment').$!=null)
		_('addComment').h()
	
	_('comBody').t(d)
}