﻿// JavaScript Document

function comm(id,logAuthor,logAuthorID){
	if($("#comments"+id).css("display")!="none"){
		//$("#com_ttl"+id).removeClass("com_ttl");
		$("#comments"+id).hide();
	}
	else{
		//$("#com_ttl"+id).addClass("com_ttl");
		$("#comments"+id).show();
		$.ajax({type:"GET",contenttype :"application/x-www-form-urlencoded;charset=utf-8",url:"/ajaxpage/comment-default-list.asp",dataType:"html",data:"bid="+id+"&logAuthor="+escape(logAuthor)+"&logAuthorID="+escape(logAuthorID),beforeSend:function(XMLHttpRequest){$('#comm-main'+id).html('<div style=" text-align:center; margin:10px auto;"><img src="/images/dirayImg/commload.gif" width="24" height="24" /></div>');},success:function(msg){$('#comm-main'+id).html(msg);},complete:function(XMLHttpRequest,textStatus){},error:function(ajax,e){alert(e);}});
	}
}

function re_comm(id){
	if($("#recom-form-"+id).css("display")!="none"){
		$("#recom-select-"+id).removeClass("recom-select");
		$("#recom-form-"+id).hide();
	}
	else{
		$(".recom-select").removeClass("recom-select");
		$(".recom-form").hide();
		$("#recom-select-"+id).addClass("recom-select");
		$("#recom-form-"+id).show();
	}
}


function checklen(obj,id){
		id=id || "tno" ;
		
		var lenE = obj.value.length;
		var maxlength=obj.getAttribute("maxlength");
		var lenC = 0;
		var num=maxlength - lenC - lenE;
		var tno=document.getElementById(id);

		if(tno!=null)
			tno.innerHTML =lenC+lenE;
		if (num < 0) {
		var tmp = 0;
		var cut = obj.value.substring(0,maxlength);
		for (var i=0; i<cut.length; i++){
		tmp += 1;///[u4E00-u9FA5uF900-uFA2D]/.test(cut.charAt(i)) ? 2 : 1;
		if (tmp > maxlength) break;
		}
		obj.value = cut.substring(0, i);
		}
	}


function qchkform(bid,pid){
	var v=$("#recom-input-cnt-"+pid).val();
	if(v==""){
		$("#waittingdiv"+pid).show();$("#waittingdiv"+pid).html('请填一点内容！');setTimeout(function(){$("#waittingdiv"+pid).hide();},1000);
		return false;
	}
	
	$.post("/ajaxpage/comment-default-list.asp",{act:"chkrecomm",Blog_ID:bid,pid:pid},function(msg){ 
		if(msg=="")
			{qsubmitcomment(bid,pid);}
		else 
			{$("#waittingdiv"+pid).show();$("#waittingdiv"+pid).html('您已经回复过了哦！');setTimeout(function(){$("#waittingdiv"+pid).hide();},2000);
		return false;}
		},"html");
}    

function qsubmitcomment(bid,pid){
	var v=$("#recom-input-cnt-"+pid).val();
	var logAuthor=$("#logAuthor"+bid).val();
	var logAuthorID=$("#logAuthorID"+bid).val();
	$.ajax({
		   type:"get",contenttype :"application/x-www-form-urlencoded;charset=utf-8",url:"/ajaxpage/comment-default-list.asp",dataType:"html",data:"act=save&bID="+bid+"&pID="+pid+"&logAuthor="+escape(logAuthor)+"&logAuthorID="+logAuthorID+"&message="+escape(v), 
		   beforeSend:function(XMLHttpRequest){$("#waittingdiv"+pid).show();$("#waittingdiv"+pid).html('<img src="/images/dirayImg/com-wait.gif" width="16"  height="16" align="absmiddle"/> 正在提交数据…')},
		   success:function(msg){if(msg.indexOf("毅力值")>0){ $("#waittingdiv"+pid).html('评论发表成功！');setTimeout(function(){Refcomm(bid,logAuthor,logAuthorID);},500);}else{$("#waittingdiv"+pid).html(msg);setTimeout(function(){$("#waittingdiv"+pid).hide();},1000);}}
		   });
}

function chkform(id){
	var v=$("#com-input-cnt-"+id).val();
	var logAuthor=$("#logAuthor"+id).val();
	var logAuthorID=$("#logAuthorID"+id).val();
	if(v==""){
		$("#com-waittingdiv"+id).show();$("#com-waittingdiv"+id).html('请填一点内容！');setTimeout(function(){$("#com-waittingdiv"+id).hide();},1000);
		return false;
	}
	
	$.post("/ajaxpage/comment-default-list.asp",{act:"chkcomm",Blog_ID:id},function(msg){
		if(msg=="")
			{submitcomment(id);}
		else 
			{$("#com-waittingdiv"+id).show();$("#com-waittingdiv"+id).html('您已经评论过了哦！');setTimeout(function(){$("#com-waittingdiv"+id).hide();},2000);
		return false;}
		},"html");
}    
     
function submitcomment(id){
	var v=$("#com-input-cnt-"+id).val();
	var logAuthor=$("#logAuthor"+id).val();
	var logAuthorID=$("#logAuthorID"+id).val();
	$.ajax({
		   type:"get",contenttype :"application/x-www-form-urlencoded;charset=utf-8",url:"/ajaxpage/comment-default-list.asp",dataType:"html",data:"act=save&bID="+id+"&logAuthor="+escape(logAuthor)+"&logAuthorID="+logAuthorID+"&message="+escape(v), 
		   beforeSend:function(XMLHttpRequest){$("#com-waittingdiv"+id).show();$("#com-waittingdiv"+id).html('<img src="/images/dirayImg/com-wait.gif" width="16"  height="16" align="absmiddle"/> 正在提交数据…')},
		   success:function(msg){if(msg.indexOf("毅力值")>0){ $("#com-waittingdiv"+id).html('评论发表成功！');setTimeout(function(){Refcomm(id,logAuthor,logAuthorID);},500);}else{$("#com-waittingdiv"+id).html(msg);setTimeout(function(){$("#com-waittingdiv"+id).hide();},1000);}}
		   });
}

function Refcomm(id,logAuthor,logAuthorID){
	$.ajax({type:"GET",contenttype :"application/x-www-form-urlencoded;charset=utf-8",url:"/ajaxpage/comment-default-list.asp",dataType:"html",data:"bid="+id+"&logAuthor="+escape(logAuthor)+"&logAuthorID="+escape(logAuthorID),beforeSend:function(XMLHttpRequest){},success:function(msg){$('#comm-main'+id).html(msg);},complete:function(XMLHttpRequest,textStatus){},error:function(ajax,e){alert(e);}});	
}















