
  var reqw,msdId_div,addType_div,e;
	var cookieKey,cookieKeySupportOrAgainst;
	var channelid,articleid,nodeid,entitytype,paperdate,period;
	var xmlHttp = false;
	var xmlHttpSub = false;
	var xmlHttpScore = false;
  var loading_div = "<img src=\""+siteUrl+"/images/loading/0504310.gif\" width=\"40\" height=\"40\" /><font color=\"#0000FF\" size=\"1\" >数据加载中...</font>";
  var loading_fail_div  = "<img src=\""+siteUrl+"/images/loading/0504311.gif\" width=\"60\" height=\"13\" /><br><font color=\"#FF0000\" size=\"1\" >数据加载失败...</font>";
  var isAdd = true;
  
	  // var siteUrl = ""; 
    //创建XMLHTTP对象
    function getXMLHTTPObj()
    {
        var C = null;
        try
            {
                C = new ActiveXObject("Msxml2.XMLHTTP");
            }
        catch(e) 
       {
           try
           {
               C = new ActiveXObject("Microsoft.XMLHTTP");
           }
           catch(sc)
          {
              C = null;
          }
       }
       if( !C && typeof XMLHttpRequest != "undefined" )
       {
           C = new XMLHttpRequest();
       }
       return C;
     }
     
     ////////////////////////////// cookie处理
     
 	  function myCreateCookieKey()
	  {   
	      
		    entitytype = document.commentform.entitytype.value;
		    paperdate = getPaperDate(document.getElementById("paperdatediv").innerText);
		    channelid = document.commentform.channelid.value;
		    nodeid = document.commentform.nodeid.value ;
		    if (entitytype==2)
		    {
			      articleid = document.commentform.articleid.value ; 
			      cookieKey = entitytype + "#" + channelid + "#" + nodeid + "#" + articleid + "#" + paperdate + "#"; 
		    }else{
            cookieKey = entitytype + "#" + channelid + "#" + nodeid + "#" + paperdate + "#";  
		    }
	   }
	  
	   function myCreateCookieKeySupportOrAgainst(type,entitytype,entityuid)
	   {   
         cookieKeySupportOrAgainst = entitytype + "#" + entityuid + "#" + type + "#";  
	   }
	   function SetCookie(){
         myCreateCookieKey();
		     var expires = new Date ();
		     expires.setTime(expires.getTime() + 31 * (24 * 60 * 60 * 1000));
		     document.cookie = cookieKey + "=" + escape(cookieKey) + "; expires=" + expires.toGMTString();
		  }
	   function SetCookieSupportOrAgainst(){
		     myCreateCookieKeySupportOrAgainst();
		     var expires = new Date ();
		     expires.setTime(expires.getTime() + 31 * (24 * 60 * 60 * 1000));
		     document.cookie = cookieKeySupportOrAgainst + "=" + escape(cookieKeySupportOrAgainst) + "; expires=" + expires.toGMTString();
		 }
	   function GetCookie(name) {
		     var dc = document.cookie;
		     var prefix = name + "=";
		     var begin = dc.indexOf("; " + prefix);
		     if (begin == -1)
		     {
			       begin = dc.indexOf(prefix);
			      if (begin != 0) 
			          return null;
			   }else {
			       begin += 2;
		     }
		     var end = document.cookie.indexOf(";", begin);
		     if (end == -1)
		     {
			       end = dc.length;
			   }
		     return unescape(dc.substring(begin + prefix.length, end));
	    } 
      ///////////////////////////// 评分
	    //回调处理函数
    function updatePageScore() 
    {
        try {
            if (xmlHttpScore.readyState == 1) 
            {
                // = "正在加载连接对象......";
                document.getElementById("scorediv").innerHTML =  loading_div;
            }

          if (xmlHttpScore.readyState == 4) 
          {
              var response = xmlHttpScore.responseText; 
              document.getElementById("scorediv").innerHTML = response;
           }
       }catch (e) 
      {
          //document.getElementById("flag").innerHTML = "回调处理错误:" + e;
	        document.getElementById("scorediv").innerHTML =  loading_fail_div;
	     }
    }
     function createStarsPage()
     {  
	       var isload =1;
	       var weburl = siteUrl + "/scoreInfotShowSave.do?method=saveScore";
         document.commentform.period.value = document.getElementById("paperdatediv").innerText.replace(/(^\s*)|(\s*$)/g, "");
	       var period = document.commentform.period.value;
	       var channelid = document.commentform.channelid.value;
	       var entitytype = document.commentform.entitytype.value;
	       if (entitytype==2){
	           articleid = document.commentform.articleid.value;
	       }
	       var nodeid = document.commentform.nodeid.value;
         try
         {
             if( xmlHttpScore && xmlHttpScore .readyState != 0 )
             {
                 xmlHttpScore.abort();
             }
             xmlHttpScore = getXMLHTTPObj();
             if( xmlHttpScore )
             {
                //构造查询连接字符串
                var url =weburl + "&period="+period+"&channelid="+channelid+"&entitytype="+entitytype+"&articleid="+articleid+"&nodeid="+nodeid+"&isload="+isload; 
                //打开连接
                xmlHttpScore.open("GET", url, true);
                //设置回调函数
                xmlHttpScore.onreadystatechange = updatePageScore;
                //发送请求
               xmlHttpScore.send(null);
            } else{
                // document.getElementById("flag").innerHTML = "XMLHTTP对象创建失败";
            }
         } catch (e) {
             //document.getElementById("flag").innerHTML = "查询错误:" + e;
		         document.getElementById("scorediv").innerHTML =  "查询错误" ;
         }

     }
	  function submitPoints()
	  { 
	      var isload =0;
	      myCreateCookieKey();
	   	  var ck = GetCookie(cookieKey);
		   if (ck == cookieKey && cookieKey !=null)
		   { 
		       isload =1;
		       alert("请不要重复提交！");
			     return;  
		   }
	     var weburl = siteUrl+"/scoreInfotShowSave.do?method=saveScore";
         document.commentform.period.value = document.getElementById("paperdatediv").innerText.replace(/(^\s*)|(\s*$)/g, "");
	     var period = document.commentform.period.value;
	     var channelid = document.commentform.channelid.value;
	     var entitytype = document.commentform.entitytype.value;
	     if (entitytype==2){
	         articleid = document.commentform.articleid.value;
	     }
	     var nodeid = document.commentform.nodeid.value;
	     var score = document.commentform.score.value;
       try{
          if( xmlHttpScore && xmlHttpScore .readyState != 0 )
          {
               xmlHttpScore.abort();
          }
          xmlHttpScore = getXMLHTTPObj();
          if( xmlHttpScore )
          {
             //构造查询连接字符串
             var url =weburl + "&period="+period+"&channelid="+channelid+"&entitytype="+entitytype+"&articleid="+articleid+"&nodeid="+nodeid+"&score="+score+"&isload="+isload;
            //打开连接
             xmlHttpScore.open("GET", url, true); 
		         SetCookie();
             //设置回调函数
             xmlHttpScore.onreadystatechange = updatePageScore;
            //发送请求
            xmlHttpScore.send(null);
          }else{
             // document.getElementById("flag").innerHTML = "XMLHTTP对象创建失败";
          }
        } catch (e) {
          //document.getElementById("flag").innerHTML = "查询错误:" + e;
	        document.getElementById("scorediv").innerHTML =  "查询错误" ;
      }
    }
   function pv(d)
   {
       document.commentform.score.value = d;
    } 
   function getPaperDate(datestr)
   {
       var dstr = datestr.replace(/(^\s*)|(\s*$)/g, "");
       return dstr;
   }
  /////////////////////////////////评论
  function submitCheckBak()
  {
 	    if(document.getElementById("contentShow").value.length>1000){
	        alert("评论内容超过1000字！");
	        return false;
	    }
	    if(document.getElementById("contentShow").value.indexOf("<script")!=-1 ||document.getElementById("contentShow").value.indexOf("<\/")!=-1){
	         alert("评论内容含有特殊字符!");
	         return false;
	    }
	    if(document.getElementById("contentShow").value == "")
	    {
	        alert("必须填写评论内容！"); 
	        return false;
	 }
	  document.commentform.period.value = document.getElementById("paperdatediv").innerText.replace(/(^\s*)|(\s*$)/g, "");
	  document.commentform.isanonymous.value = document.commentformContent.isanonymous.checked;  
	  document.commentform.content.value = document.commentformContent.contentShow.value;  
    document.commentform.method="post";
    document.commentform.action= siteUrl+"/commentShowSave.do?method=saveCommentMessage";
	  document.commentform.target="iframeborder";
 	  document.commentform.submit(); 
 	  document.commentform.isanonymous.value = "";  
	  document.commentform.content.value = "";    
  }
  function submitCheck()
	{ 
		  if (isAdd != true)
		   {
		   	   alert("请不要频繁提交数据");
		   	   return false;
		   }
		  if(document.getElementById("contentShow").value == "")
	    {
	        alert("必须填写评论内容！"); 
	        return false;
	    }
      if(document.getElementById("contentShow").value.length>1000){
	        alert("评论内容超过1000字！");
	        return false;
	    }
	    if(document.getElementById("contentShow").value.indexOf("&")!=-1 || document.getElementById("contentShow").value.indexOf("<script")!=-1 ||document.getElementById("contentShow").value.indexOf("<\/")!=-1){
	         alert("评论内容含有特殊字符!");
	         return false;
	    }

	  var period = document.getElementById("paperdatediv").innerText.replace(/(^\s*)|(\s*$)/g, "");
	  var isanonymous = document.commentformContent.isanonymous.checked;  
	  var content = document.commentformContent.contentShow.value; 
	  var entitytype  = document.commentform.entitytype.value; 
	  var nickname = document.commentform.nickname.value;  
	   
	  var entityMpId;
	  if (entitytype ==1)
	  {
	       entityMpId =  document.commentform.nodeid.value; 	
	   	
	  }else
	  {
	   	   entityMpId = document.commentform.articleid.value; 	
	  }
	  var channelid  = document.commentform.channelid.value;
    try{
          if( xmlHttpSub && xmlHttpSub .readyState != 0 )
          {
               xmlHttpSub.abort();
          }
         xmlHttpSub = getXMLHTTPObj();
         
         if( xmlHttpSub )
         {	 
          	  isAdd = false;
          	   if (isanonymous == true)
          	   {
          	   	     document.commentform.content.value = "";
          	         document.commentformContent.contentShow.value ="";
          	   	}
          	   	
           	 var weburl = siteUrl + "/commentShowSave.do?method=saveCommentMessage";
             //构造查询连接字符串
             var url =weburl + "&period="+period+"&isanonymous="+isanonymous+"&entitytype="+entitytype+"&nickname="+nickname+"&nodeid="+entityMpId+"&articleid="+entityMpId+"&channelid="+channelid+"&content="+content;
            //打开连接a
              
             xmlHttpSub.open("POST", url, true); 
             //设置回调函数
             
             xmlHttpSub.onreadystatechange = showEntitySubCommentContent;
            //发送请求
            xmlHttpSub.send(null);
             
         }else{
          	 document.commentformContent.contentShow.value = ""; 
             alert("抱歉，暂时不能评论!") ;
         }
    } catch (e) {
          //document.getElementById("flag").innerHTML = "查询错误:" + e;
	        alert("抱歉，暂时不能评论!") ;
      }
	}
	function showEntityCommentList(type, data, evt)
	{ 

		if (type == 'error')
		{
			   alert('读取服务器数据时出错');
		}
		else
		{
			   if (data.replace(/(^\s*)|(\s*$)/g, "") == "谢谢") 
			   {
			    	 alert("数据已经提交，请等待审核!");
			   }else
			  {
			     document.getElementById("showCommentContent").innerHTML = data;
			  }  
		}
	} 
  function viewComment(){
	  
 	     document.commentform.period.value = document.getElementById("paperdatediv").innerText.replace(/(^\s*)|(\s*$)/g, "");
       document.commentform.method="post";
       document.commentform.action= siteUrl+"/commentShowSave.do?method=listAllComments";
	     document.commentform.target="_blank";
 	     document.commentform.submit(); 
 	}
   function showEntityComment(){ 
    	 userLoginComment();
	     var weburl = siteUrl + "/commentShowSave.do?method=listTopComments";
       document.commentform.period.value = document.getElementById("paperdatediv").innerText.replace(/(^\s*)|(\s*$)/g, "");
	     var period = document.commentform.period.value;
	     var channelid = document.commentform.channelid.value;
	     var entitytype = document.commentform.entitytype.value;
	     var articleid;
	     if (entitytype==2){
	        articleid = document.commentform.articleid.value;
	     }
	     var nodeid = document.commentform.nodeid.value;
       try
       {
           if( xmlHttp && xmlHttp .readyState != 0 )
          {
              xmlHttp.abort();
          }
         xmlHttp = getXMLHTTPObj();
         if( xmlHttp )
         {
             //构造查询连接字符串
             var url =weburl + "&period="+period+"&channelid="+channelid+"&entitytype="+entitytype+"&articleid="+articleid+"&nodeid="+nodeid; 

             //打开连接
             xmlHttp.open("GET", url, true);
             //设置回调函数
 
             xmlHttp.onreadystatechange = showEntityCommentContent;
            //发送请求
            xmlHttp.send(null);
         } else{
           // document.getElementById("flag").innerHTML = "XMLHTTP对象创建失败";
         }
       } catch (e) {
          //document.getElementById("flag").innerHTML = "查询错误:" + e;
		      document.getElementById("showCommentContent").innerHTML =  "查询错误" ;
       }
   }
  function showEntityCommentContent() 
  { 
      try {
          if (xmlHttp.readyState == 1) 
          {
              // = "正在加载连接对象......";
	            document.getElementById("showCommentContent").innerHTML =  loading_div ;
          }
        if (xmlHttp.readyState == 4) 
        {
           var response = xmlHttp.responseText; 
           document.getElementById("showCommentContent").innerHTML = xmlHttp.responseText;
       }
     } catch (e) 
    {
        //document.getElementById("flag").innerHTML = "回调处理错误:" + e;
	     document.getElementById("showCommentContent").innerHTML =  loading_fail_div;
    }
 }
  function showEntitySubCommentContent() 
  { 
      try {

        if (xmlHttpSub.readyState == 4) 
        {
           var response = xmlHttpSub.responseText;
           var responseShow =  response.replace(/(^\s*)|(\s*$)/g, "");
           //alert(responseShow);t
           isAdd = true;
           if (responseShow == "谢谢")  
			     {
			    	  alert("数据已经提交，请等待审核!"); 
			    	  return false;
			     }else if (responseShow == "失败")  
			     {
			      	
			      	alert("抱歉，暂时不能评论!");
			      	return false;
			     }
			     else if (responseShow == "loginFail")
			    {
			        alert("用户名或密码不正确,请确认是否正确登录!");
			      	return false;
			    } 
           else if (responseShow != "谢谢" &&  responseShow != "失败")
			    {
			     	 document.commentformContent.contentShow.value = ""; 
			        document.getElementById("showCommentContent").innerHTML = xmlHttpSub.responseText;
			    }           
       }
     } catch (e) 
    {
	     document.getElementById("showCommentContent").innerHTML =  loading_fail_div;
    }
 }
    function userLoginComment(){ 
	   var weburl = siteUrl + "/sso/getUserInfo.jsp";
       try
       {
           if( xmlHttpSub && xmlHttpSub .readyState != 0 )
          {
              xmlHttpSub.abort();
          }
         xmlHttpSub = getXMLHTTPObj();
         if( xmlHttpSub )
         {
             //构造查询连接字符串
             var url =weburl;

             //打开连接
             xmlHttpSub.open("GET", url, true);
             //设置回调函数
 
             xmlHttpSub.onreadystatechange = showLoginComment;
            //发送请求
            xmlHttpSub.send(null);
         } else{
           	 var _DIVF = "<a href=\"#\" onclick=\"openLogin();\">登录</a><label><input type=\"checkbox\" name=\"isanonymous\" "+" id=\"isanonymous\" value=\"checkbox\" title=\"若勾选，则匿名评论\" />匿名</label>";
			        document.getElementById("loginComment_div").innerHTML =  _DIVF;
         }
       } catch (e) {
         			var _DIVF = "<a href=\"#\" onclick=\"openLogin();\">登录</a><label><input type=\"checkbox\" name=\"isanonymous\" "+" id=\"isanonymous\" value=\"checkbox\" title=\"若勾选，则匿名评论\" />匿名</label>";
			        document.getElementById("loginComment_div").innerHTML =  _DIVF;
       }
   } 
  function showLoginComment() 
  { 
      try {
        if (xmlHttpSub.readyState == 4) 
        {
           var response = xmlHttpSub.responseText;
           var responseShow =  response.replace(/(^\s*)|(\s*$)/g, "");
           if (responseShow.indexOf("###")>4)  
			     {
			      	 
			      	var cArray = responseShow.split("###");
			      	var _DIVS =  "您好," +cArray[1] +"<label><input type=\"checkbox\" name=\"isanonymous\" "+" id=\"isanonymous\" value=\"checkbox\" title=\"若勾选，则匿名评论\" />匿名</label>";
			    	  document.getElementById("loginComment_div").innerHTML =  _DIVS;
			    	  return false;
			     }else 
			     {
			      	
			      	var _DIVF = "<label><input type=\"checkbox\" name=\"isanonymous\" "+" id=\"isanonymous\" value=\"checkbox\" checked=\"checked\" title=\"若勾选，则匿名评论\" />匿名</label>";
			        document.getElementById("loginComment_div").innerHTML =  _DIVF;
			      	return false;
			     }          
       }
     } catch (e) 
    {
	     			var _DIVF = "<label><input type=\"checkbox\" name=\"isanonymous\" "+" id=\"isanonymous\" value=\"checkbox\" checked=\"checked\" title=\"若勾选，则匿名评论\" />匿名</label>";
			      document.getElementById("loginComment_div").innerHTML =  _DIVF;
    }
 }
 function openLogin()
{

    var nHeight = 560;
    var nWidth = 700; 
    var nTop = Math.ceil((window.screen.Height - nHeight) / 2 ) - 50;
    var nLeft = Math.ceil((window.screen.width - nWidth) / 2 );
    var webUrl = siteUrl + "/sso/sso.jsp" ;
    window.open(webUrl,"actioninfo","height="+nHeight+",width="+nWidth+",top="+nTop+",left="+nLeft+",status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes");


}
function dorecom(){
	
	var weburl = siteUrl + "/comment/client/sendmain.jsp";
	document.getElementById('commentform').action= weburl;	
	window.open('','_recomwin','width=400,height=300');	
	document.getElementById('commentform').target="_recomwin";	
	document.getElementById('commentform').recom_weburl.value = location.href;
	document.getElementById('commentform').submit();	
}	

function toUTF8(a){
    var wch,x,uch="",szRet="";
    for (x=0; x<a.length; x++){
    wch=a.charCodeAt(x);
    if (!(wch & 0xFF80)){
    szRet += a.charAt(x);
    }
    else if (!(wch & 0xF000)){
    uch = "%" + (wch>>6 | 0xC0).toString(16) +
    "%" + (wch & 0x3F | 0x80).toString(16);
    szRet += uch;
    }
    else{
    uch = "%" + (wch >> 12 | 0xE0).toString(16) +
    "%" + (((wch >> 6) & 0x3F) | 0x80).toString(16) +
    "%" + (wch & 0x3F | 0x80).toString(16);
    szRet += uch;
    }
    }
    return(szRet);
}
function encodeHtml(str){
    var encodedStr = "" ; 
    if (str=="") return encodedStr ;
    else {
        for (var i = 0 ; i < str.length ; i ++){
            encodedStr += "&#" + str.substring(i, i + 1).charCodeAt().toString(10) + ";" ;
        }
    }
    return encodedStr ;
}
