///////////////////////////////////////////////////////////////////////////
//内容评论扩展插件
///////////////////////////////////////////////////////////////////////////
var ajaxPluginReviewPageSize = 5;//每页显示的评论数
function ajaxPluginReview(ccid,id)
{
	if(PluginReview==null)
	{
		$("#ajaxPluginReview").hide();
		return;
	}
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxPluginReview&id="+id+"&ccid="+ccid+"&time="+(new Date().getTime()),
		url:		site.Dir + "extends/review/ajax.aspx",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			$("#ajaxPluginReview").setTemplateURL(site.Dir + "extends/review/templates/_review.htm?time="+(new Date().getTime()), null, {filter_data: true});
			$("#ajaxPluginReview").processTemplate(d);
		}
	});
}
function ajaxPluginReviewCount(ccid,id)
{
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxPluginReviewCount&id="+id+"&ccid="+ccid+"&time="+(new Date().getTime()),
		url:		site.Dir + "extends/review/ajax.aspx",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			$("#ajaxPluginReviewCount_"+id).text(d.count);
		}
	});
}
function ajaxPluginReviewAdd(ccid,id)
{
	var uName=$("#reviewName").val();
	var uCode=$("#reviewCode").val();
	var parentid=$("#reviewParentId").val();
	var content=$("#reviewContent").val();
	if(!uName) {
		alert("用户名不能为空!");
		return;
	}
	if(uName.length>16){
		alert("用户名太长!");
		return;
	}
	if(uCode == "" || uCode.toLowerCase() != JumbotCms.Cookie.get("ValidateCode").toLowerCase()){
		alert('校验码错误');
		return;
	}
	if(!content || content.length<5) {
		alert("评论字符太少!");
		return;
	}
	if(content.length>200){
		alert("评论字符太多!");
		return;
	}
	$("#btnReviewAdd").attr("disabled","disabled");
	
	$.ajax({
		type:		"post",
		dataType:	"html",
		data:		"ccid="+ccid+"&id="+id+"&parentid="+parentid+"&name="+encodeURIComponent(uName)+"&code="+encodeURIComponent(uCode)+"&content="+encodeURIComponent(content),
		url:		site.Dir + "extends/review/ajax.aspx?oper=ajaxPluginReviewAdd&time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			if(d=="ok")
			{
				$("#reviewContent").val("");
				$("#reviewCode").val("");
				if(parentid=="0")
					alert("成功发表评论");
				else
					alert("成功回复评论");
				ajaxList(ccid,id,1);
				$("#btnReviewAdd").attr("disabled","");
				$OBJ('imgCode').src=_jcms_SetUrlRefresh(site.Dir + 'plus/getcode.aspx');
			}
			else
			{
				alert(d);
			}
		}
	});
}
function ajaxPluginReviewDelete(ccid,id,reviewid)
{
	$.ajax({
		type:		"post",
		dataType:	"html",
		data:		"reviewid="+reviewid,
		url:		site.Dir + "extends/review/ajax.aspx?oper=ajaxPluginReviewDel&time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			if(d=="ok")
			{
				ajaxList(ccid,id,1);
			}
			else
			{
				alert(d);
			}
		}
	});
}
function ajaxPluginReviewReply2(parentid)
{
	$("#reviewParentId").val(parentid);
	$("#reviewContent").val("");
	$("#reviewContent")[0].focus();
}
function ajaxPluginReviewUserInfo()
{
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxPluginReviewUserInfo&time="+(new Date().getTime()),
		url:		site.Dir + "extends/review/ajax.aspx",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(data){
			if(data.username=="")
			{
				$("#reviewName").val("匿名游客");
				$(".reviewName").html("匿名游客");
				$("#guest_btn").show();
			}
			else{
				$("#reviewName").val(data.username);
				$(".reviewName").html(data.username);
			}
		}
	});
}