/*================================================================
Modify Date:2013-7-24
Author：linwenzhong
Copyright:www.Kesion.com  bbs.kesion.com
Version:KesionCMS V9.5
营销QQ：4000080263
==================================================================*/
//ajax 控件
function PageAjax(){
	if(window.XMLHttpRequest){
		return new XMLHttpRequest();
	} else if(window.ActiveXObject){
		return new ActiveXObject("Microsoft.XMLHTTP");
	} 
	throw new Error("XMLHttp object could be created.");
}
var loader=new PageAjax;
function ajaxLoadPage(url,request,method,fun)
{ 
	method=method.toUpperCase();
	if (method=='GET')
	{
		urls=url.split("?");
		if (urls[1]=='' || typeof urls[1]=='undefined')
		{
			url=urls[0]+"?"+request;
		}
		else
		{
			url=urls[0]+"?"+urls[1]+"&"+request;
		}
		request=null;
	}
	loader.open(method,url,true);
	if (method=="POST")
	{
		loader.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	}
	loader.onreadystatechange=function(){
	     eval(fun+'()');
	}
	loader.send(request);
 }
  //评论支持
  function Support(channelid,infoid,postid,id,typeid,installdir)
  { 
    try{
		 $.ajax({
		   type: "POST",
		   url: installdir+'plus/Comment.asp',
		   data:'action=Support&channelid='+channelid+'&infoid='+infoid+'&postid='+postid+'&Type='+typeid+'&id=' +id,
		   success: function(s){
				if (s=='good'){
				   $("#d"+id).html(parseInt($("#d"+id).html())+1);
				}else if (s=='bad'){
				 	$("#c"+id).html(parseInt($("#c"+id).html())+1);
			    }
				else tipsShow(s);
		   }
		});

	
	}
	catch(e){CreateJs(installdir+'plus/Comment.asp?action=Support&channelid='+channelid+'&infoid='+infoid+'&postid='+postid+'&Type='+typeid+'&id=' +id);}
  }

 //回复
 var box='';
function replyCmt(postId,channelid,infoid,quoteId,installdir){
	box=$.dialog({id:'quotebox',lock:true,title:'引用回复',content:"url:" +installdir+"plus/comment.asp?action=ShowQuote&channelid="+channelid+"&infoid="+infoid+"&quoteid="+quoteId+"&postId="+postId,width:500,height:240,min:false,max:false});
}
 //当前页,频道ID,栏目ID，信息ID,Action,InstallDir
function Page(curPage,channelid,infoid,action,maxperpage,installdir){
   this._channelid = channelid;
   this._infoid    = infoid;
   this._action    = action;
   this._maxperpage= maxperpage;
   this._url       = installdir +"plus/comment.asp";
   
   this._c_obj="c_"+infoid;
   this._p_obj="p_"+infoid;
   this._installdir=installdir;
   this._page=curPage;
     loadDate(1,0);
   }
function loadDate(p,postload){
    this._page=p;
   var loadurl=_url+"?postload="+postload+"&channelid="+_channelid+"&infoid="+_infoid+"&from3g="+from3g+"&maxperpage="+_maxperpage+"&action=" +_action+"&page="+p;
 try{
			   var xhr=new PageAjax();
			   xhr.open("get",loadurl,true);
			   xhr.onreadystatechange=function (){
	         if(xhr.readyState==1){
			  }else if(xhr.readyState==4){
				 if (xhr.status==200)
				 {   
					  show(xhr.responseText);
				 }
			}
	   }
    xhr.send(null); 
	}catch(e){

		CreateJs(loadurl);
	}

}
function CreateJs(loadurl)
{
     var head = document.getElementsByTagName("head")[0]; 
	 var js = document.createElement("script"); 
	 js.src = loadurl+'&printout=js'; 
	 head.appendChild(js);   
}

function show(s)
{
  if (s.indexOf("ks:page")==-1){
	 $(".cmtnum").html(parseInt($(".cmtnum").html())+1);
	 $("#cc_"+this._infoid).prepend(s);
  }else{
	  var pagearr=s.split("{ks:page}")
	  var pageparamarr=pagearr[1].split("|");
	  count=pageparamarr[0];    
	  perpagenum=pageparamarr[1];
	  pagecount=pageparamarr[2];
	  itemunit=pageparamarr[3];   
	  itemname=pageparamarr[4];
	  pagestyle=pageparamarr[5];
	  pagestyle=1;
	  if (this._page>1){
	   $("#cc_"+this._infoid).append(pagearr[0]);
	  }else{
	   $("#"+_c_obj).html(pagearr[0]);
	  }
      pagelist();
  }
}

function pagelist(){
     var statushtml="";
	 if (parseInt(this.pagecount)<=parseInt(this._page)){
	 statushtml="<div id=\"cmtloadtips\" style=\"cursor:pointer;height:30px;line-height:30px;background:#888;font-weight:bold;color:#fff;text-align:center;\">已加载完全部内容</div>"
	 }
	 else{
	 statushtml="<div id=\"cmtloadtips\" style=\"cursor:pointer;height:30px;line-height:30px;background:#888;font-weight:bold;color:#fff;text-align:center;\" onclick=\"nextPage()\">加载更多内容</div>"
	 }

  if (this.pagecount!=""&&this.count!=0)
	 {
	 $("#"+this._p_obj).html('<div style="margin-top:8px">'+statushtml+'</div>');
	 }
}

function nextPage()
{
   if(this._page<this.pagecount){
      loadDate(this._page+1,0);
	  $("#cmtloadtips").html("正在加载中..");
   }
   else
      tipsShow("已经到最后一页了");
}

function tipsShow(str){
	 if (from3g==1){
		  alert(str);
	 }else{
		 KesionJS.Alert(str);
	 }
}