// JavaScript Document

function kuaibaoBox_replayBtnClickHandle(e,o){
	var owner = o?o:$(this);
	var PublishersReplay = owner.closest(".Publishers").find(".PublishersReplay");
	PublishersReplay.html('<div style="text-align:center; line-height:16px; overflow:hidden; height:16px;"><img align="top" width="16" height="16" src="'+appPath+'common/images/load.gif" /> 正在加载...</div>'+PublishersReplay.html())
	if(!PublishersReplay.attr("load") || o){
		PublishersReplay.attr("load","true")
		$.get(appPath+"view-comment.action?rnd="+Math.random(),{
			archiveClz:"kuaibao",
			count:10,
			artID:owner.attr("vid")
		},function(d){
			PublishersReplay.html(d);
			loadrelpay(PublishersReplay)
			$(".kuaibaoBox_replayBtn[vid='"+owner.attr("vid")+"'] span").html("("+$("#commentPostingBox_"+owner.attr("vid")).attr("count")+")")
			checkTime()
		})
	}else{
		PublishersReplay.removeAttr("load")
		PublishersReplay.empty();
	}
	
}

function deleteKuaibaoreplayBtnClickHandle(e){
	var owner = $(this)
	$.get(appPath+"art-delComment.action",{
		commentID:owner.attr("cid")
	},function(d){
		if(d.success==true){
			if(d.msg=="deleteLinkSuccess"){
				kuaibaoBox_replayBtnClickHandle(null,$(".kuaibaoBox_replayBtn[vid='"+owner.attr("aid")+"']"))
			}else if(d.msg=="deleteSuccess"){
				owner.closest(".commentbox").slideUp()
			}else{
				owner.closest(".commentbox").find(".comment_content:first").text(d.msg)
			}
		}else{
			alert(d.msg)
		}
		
	})
}
function hidereplayDelte(e){
	$(this).find(".deleteKuaibaoreplayBtnSpan").css("visibility","hidden")
}
function showreplayDelte(e){
	var deleteKuaibaoBtnSpan = $(this).find(".deleteKuaibaoreplayBtnSpan");
	if(currentUserID == deleteKuaibaoBtnSpan.attr("uid"))
	deleteKuaibaoBtnSpan.css("visibility","visible")
}


function loadrelpay(o){
	$(".deleteKuaibaoreplayBtn").unbind("click",deleteKuaibaoreplayBtnClickHandle).bind("click",deleteKuaibaoreplayBtnClickHandle)
	o.find(".commentbox").each(function(){
		var firstid = $(this).attr("firstid");
		if(firstid!=0){
			if($(this).attr("len") % 2 == 1){
				$(this).addClass("comMod2")
			}else{
				$(this).addClass("comMod1")
			}
			$("#CommentReplyBox_"+$(this).attr("fid")).append($(this))
		}
	}).unbind("mouseenter",showreplayDelte).bind("mouseenter",showreplayDelte).unbind("mouseout",hidereplayDelte).bind("mouseout",hidereplayDelte)
	
	o.find(".pinglunReplay").click(function(e) {
		var cid = $(this).attr("cid")
		var content = $("#replyCommentBtn_textarea_"+cid).val();
		var artid = $(this).attr("aid");
		var firstid = $(this).attr("firstid")
		if(firstid==0){
			firstid = cid
		}
		postReplayToServer_rand4dsdfs(content,artid,firstid,cid,o)
	});
	
	o.find(".replyCommentBtn").bind("click",function(){
		$("#commentContentReplayForm_"+$(this).attr("cid")).toggle()
	})
	
	o.find(".commentSubmitBtn").bind("click",function(){
		var artid = $(this).attr("aid");
		var content = $("#content_"+artid).val();
		var firstid = $("#commentSubmitBtn_"+artid).attr("firstid")
		var cid = $("#commentSubmitBtn_"+artid).attr("cid")
		postReplayToServer_rand4dsdfs(content,artid,firstid,cid,o)
	})
}
function postReplayToServer_rand4dsdfs(content,artid,firstid,cid,o){
	if(content.length<=0){return false;}
	$.post(appPath+"art-addComment.action",{
		"content":content,
		"artid":artid,
		"firstcommentid":firstid,
		"commentid":cid,
		"comment_posterWebSite":"",
		"postMail":0
		},function(d){
			if(d.success==true){
				$(".pinglunReplay").each(function(index, element) {
				   $("#replyCommentBtn_textarea_"+$(this).attr("cid")).val("");
				});
				$("#content").val("");
				kuaibaoBox_replayBtnClickHandle(null,$(".kuaibaoBox_replayBtn[vid='"+artid+"']"))
			}else{
				alert(d.msg)
			}
	},"json")	
}
