var pl_count = 0;

//盖楼
function hfgl(){
	var params = "idDiscuss=&idNews=" + idNews + "&plCount=" + pl_count;
	$.ajax({
	   	type: "POST",
	   	url: CTX + "/html/common/pl/getPl_form1.jsp",
	   	data: params,
	   	success: function(msg){
	   		document.getElementById("div_pl").innerHTML = msg;
	   		bindFormPl();
		}
	});
}

//发表评论
function bindFormPl(){
	var options = {
      	beforeSubmit: 	showRequest,
      	success:       	showResponse
	};
	$('#form_pl').ajaxForm(options);
}

function showRequest(formData, jqForm){
	var content = $("#content").val();
	var validationCode = $("#validationCode").val();
	var anonymous =document.getElementsByName("anonymous");
	var anonymous_flag="";
	if(anonymous.length > 0){
		for(var i=0; i<anonymous.length; i++){
			if(anonymous[i].checked){
				anonymous_flag = anonymous[i];
			}
		}
		if(anonymous_flag == ""){
			alert("请先登录！");
			return false;
		}
	}
	if(content==""){
		alert("评论内容必填");
		$("#content").focus();
		return false;
	}
	if(validationCode==""){
		alert("验证码必填");
		$("#validationCode").focus();
		return false;
	}
	return true;
}

function showResponse(responseText, statusText){
	responseText= $.trim(responseText);
	if(responseText != '' && responseText == 'true'){
		alert("发表评论成功，感谢您的参与!");
		window.location = CTX + "/html/common/pl.html?idNews=" + idNews;
	}else{
		alert("验证码错误!");
	}
}

function getValidationCode(){
	var imageSrc = document.getElementById("image").src;
	if(imageSrc == ""){
		document.getElementById('image').src=CTX + '/jsp/common/validationCode.jsp?f='+Math.random();
	}
	document.getElementById('image').style.display = "";
}

//获取评论数量
var idNews;
function getCount(){
	var params = "idNews=" + idNews + "&type=0";
	$.ajax({
	   	type: "POST",
	   	url: CTX + "/jsp/common/plCount.jsp",
	   	data: params,
	   	success: function(msg){
	   		msg = $.trim(msg);
	   		pl_count = msg;
	   		if(parseInt(msg) > 0){
	   			document.getElementById("pl").innerHTML = msg;
	   			document.getElementById("pl_1").innerHTML = msg;
	   			document.getElementById("div_1").style.display = "";
	   		}
		}
	});
}

getCount();
hfgl();