xpow.comment = new Object();
xpow.comment.c = new Array();
xpow.comment.c['SUB_CMT_CONTENT'] = 'subcomments_'
xpow.comment.c['SUB_CMT_REEDITOR'] = 'subreform_'
xpow.comment.c['NEED_LOGIN'] = '您需要登陆才能继续当前的操作!'
xpow.comment.c['COMMENT_ISLOCK'] = '当前主题已被作者或管理员锁定,不能进行评论和当前操作!'
xpow.comment.c['COMMENT_SUCC'] = '评论成功!'
xpow.comment.c['CASE_PREFIX'] = '确实要'
xpow.comment.c['CASE_DELETE_COMMENT'] = '删除该评论吗?'
xpow.comment.c['ERR_CONTENT_NOCLEAR'] = '内容不能为空!'
xpow.comment.c['XHTML'] = ''
xpow.comment.c['CMT'] = '{$channel}.comment';
xpow.comment.JSN = xpow.JSN;
xpow.comment._pma_=''
xpow.comment.nologin = true;
xpow.comment.treeData = new XPOWS.shellTree();
xpow.comment.itemisLock = function(){ return ($('islock').value.toLowerCase() == 'false')?0:1 }
xpow.comment.isLogin = function(){  this.getParmas() ; return this._pma_.islogin}
xpow.comment.setData = function(key,val){this.treeData.addItem(key,val)}
xpow.comment.getData = function(key){return this.treeData.getItem(key)}
xpow.comment.dosendcomment = function(){this.doSendComment()}
xpow.comment.setcommentframe = function(channel){this.setCommentFrame(channel)}
xpow.comment.loadcomment = function(turl,channel){this.loadComment(turl,channel)}
xpow.comment.doRelog = function(){alert(this.c['NEED_LOGIN']);this.nologin = true;$(this.getCMT()).innerHTML = this.c['XHTML'];this.cmtClear()}
xpow.comment.doRelogs = function(){alert(this.c['NEED_LOGIN']);this.nologin = true;$(this.getCMT()).innerHTML = this.c['XHTML'];this.c['XHTML'] = '';this.setRecomment(this.getData('sn'))}
xpow.comment.cmtSuc = function(){alert(this.c['COMMENT_SUCC']);/*this.cmtClear();*/ window.location.reload()}
xpow.comment.getCMT = function(){ this.getParmas(); try{this.setData('channel',this._pma_.poststatu);return this.c['CMT'].Replace('channel',this.getData('channel'))}catch(e){alert("xpow.comment return(27) : 'channel' "+e.message)}}
xpow.comment.loadBox = function(){xpow.show2hide('_comments_')}
xpow.comment.setCommentFrame = function(channel){var v_sElemt;if($('vselemt')){v_sElemt = $('vselemt').value;$('vselemt').value = channel+'.comment'}}
xpow.comment.JSNinit = function(st){ this.getParmas(); xpow.JSN.Init(this._pma_.postdir,this._pma_.poststatu,1,st,0,1) }
xpow.comment.callBack = function(bt){if (!bt){alert('您的操作有误, 验证码不正确！');this.reLoad()}}
xpow.comment.getParmas = function(){ if (!$('_chn_comment_parmas'))return false; this._pma_ = eval($('_chn_comment_parmas').value); this._pma_ = _cmt_parmas}
xpow.comment.reLoad = function() {setTimeout("xpow.show2hide('_sendCmts_'); $('_sendCmt_').focus();User.Parse.Client()",300)}
xpow.comment.reLoadItem = function() {}

xpow.comment.cmtClear = function()
{
	if (this.getData('act')){$('_user_cmt_'+this.getData('sn')).focus()}
	this.setData('act',0);sn = this.getData('sn') 
	try{ $('comment_remark').value = ''}catch(e){ $(this.c['SUB_CMT_REEDITOR']+sn).value = ''}
}

xpow.comment.doSendComment = function()
{
	this.getCMT()
	var param={}
	param.oErr = xpow.point.Error
	param.remark = trim(doFilter($('comment_remark').value,3))
	param.validcode = trim(doFilter($('comment_validcode').value,3))
	if (param.remark == ''){param.oErr.setErr('msg0','评论内容不能为空！')}
	if (param.validcode == '' && !this._pma_.islogin){param.oErr.setErr('msg2','验证码不能为空！')}
	if (!param.oErr.foundErr){if (param.remark.length > 500){param.oErr.setErr('msg1','评论内容过长，请控制在500个字符以内！\n\n当前约 '+param.remark.length+' 字节')}}
	if (param.oErr.foundErr){
		param.oErr.Out(0,'username','',0)
	}else{
		this.JSNinit(this.getCMT())
		xpow.JSN.SendX('sendComment&dataId='+this._pma_.dataId+'&channel='+this._pma_.channel+'&poststatus='+this._pma_.poststatu+'&postst='+this._pma_.postst+'&skin='+this._pma_.skin+'&node='+this._pma_.node+this._pma_.append,JSON2Post(param))/**/		/**/
	}
}

xpow.comment.getItemVal = function()
{
	this.getCMT()
	var tChannel = $('poststatu').value, tHidLst = $t(tChannel+'.comment','input'),tRe = '';
	for (var i in tHidLst){if (i!='length' && tHidLst[i].id !='' && tHidLst[i].id !=undefined ){
	if (tHidLst[i].id=='append' ){ if ( tHidLst[i].value!='')tRe += tHidLst[i].value+xpow.JSN.aSyb}else{tRe += tHidLst[i].id+'='+tHidLst[i].value+xpow.JSN.aSyb}}}
	this.setCommentFrame(tChannel);
	return tRe.toString()
}

xpow.comment.loadComment = function(page,postst)
{
	this.getParmas()
	var tpma = this._pma_; if(page){tpma.page = page}
	if (postst){ tpma.postst = postst}
	this.JSNinit(this.getCMT())
	var tAct = 'action,dataId,poststatus,postst,channel,skin,node,page,cmturlapp'
	var tVal = 'loadcomment/'+tpma.dataId+'/'+tpma.poststatu+'/'+tpma.postst+'/'+tpma.channel+'/'+tpma.skin+'/'+tpma.node+'/'+tpma.page+'/cmturlapp='+tpma.append+'/tim.html'
	xpow.JSN.format(tAct,tVal)
}

xpow.comment.LoadComment = function()
{
	xpow.osEvent.attEvent('comment.view','ock','return false');$('comment.view').className=''
	tUrl = 'loadcomment&'+this.getItemVal().toReSymbol(xpow.JSN.aSyb,'&').toLeft(1)
	xpow.JSN.Init('','',1,'comment.view',0);xpow.JSN.Send(tUrl)
}

xpow.comment.setRecomment = function(sn)
{
	//if (!xpow.comment.hidden('login')){return}
	/*window.focus(); if (itemisLock()){alert(xpow.comment.c['COMMENT_ISLOCK']);return}*/
	var param = {}
	this.setData('sn',sn)
	param.editor = $(this.c['SUB_CMT_REEDITOR']+sn)
	param.content = $(this.c['SUB_CMT_CONTENT']+sn)
	this.doSlidUpDn(param.content,function(){  param.editor.value = ''})
	return false
}


xpow.comment.doSlidUpDn = function(content,callback){
	try{if (content.style.display == 'none'){jQuery(content).slideDown('slow',callback) }else{ jQuery(content).slideUp('slow',callback)}}catch(e){alert(e.message)}
} 

xpow.comment.doSubmitsub = function(sn)
{
	var param = {}
	param.err = false
	param.cmt = this.getCMT()
	tpma = this._pma_
	this.JSNinit(param.cmt)
	/*if (!this.isLogin()){
		param.err = true;
		this.setRecomment(this.getData('sn')); 
		return alert(this.c['NEED_LOGIN']);
	}*/
	param.remark = trim($(this.c['SUB_CMT_REEDITOR']+sn).value)
	param.action = (this.getData('act'))?'ed':'ad';
	param.touserid
	if (param.remark == ''){param.err = true;param.errmsg = this.c['ERR_CONTENT_NOCLEAR']}
	if (!param.err){
		var tpost = {}
		tpost.remark = param.remark
		tpost.iid=0
		tpost.r_id=$('r_id_'+sn).value
		tpost.page=tpma.page
		tpost.act=param.action
		tpost.touserid=param.touserid
		xpow.JSN.SendX('ascomment&dataId='+tpma.dataId+'&channel='+tpma.channel+'&skin='+tpma.skin+'&node='+tpma.node+'&page='+tpma.page+tpma.append+'&poststatus='+tpma.poststatu,JSON2Post(tpost));
	}else{
		alert(param.errmsg)
	}
	return false
}

xpow.comment.showCommentBox = function()
{
	if (!xpow.comment.hidden('login')){return}
	var content = $('_sendCmts_');this.cmtClear();window.focus()
	this.doSlidUpDn(content)
}


xpow.comment.hidden = function(type)
{
	switch(type){ case 'login': if (!this.isLogin()){ return xpow.point.Message.login() } }
	return true
}
xpow.comment.init = function()
{
	this.getParmas()
	if ($('sClient'))User.Parse.Client()
	if (!this._pma_.islogin ){ $j('.guestbook .vcode').css({'display':'block'})}
}

xpow.comment.Delete = function(pra,chn,sn)
{
	xpow.osEvent.catchSrc()
	var tpa = xpow.osEvent.cSrcElmt.parentNode.getAttribute('parmas')
	eval('_cmt_sub_tpa='+tpa)
	if (!confirm(this.c['CASE_PREFIX']+this.c['CASE_DELETE_COMMENT'])){return}
	try{
		$('cmt_re_sub_'+sn+'.'+_cmt_sub_tpa.ix).style.display = 'none'
	}catch(e){
		$('cmt_re_'+sn).style.display = 'none'
	}
	this.JSNinit('vsi')
	var prax = 'action,delid,dataId,channel,page,poststatus,skin,node,'
	pra = 'del'+pra
	xpow.JSN.format(prax,pra)
}

xpow.window.addOnLoad('xpow.comment.init()')
