
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\" >\u6570\u636e\u52a0\u8f7d\u4e2d...</font>";
var loading_fail_div = "<img src=\"" + siteUrl + "/images/loading/0504311.gif\" width=\"60\" height=\"13\" /><br><font color=\"#FF0000\" size=\"1\" >\u6570\u636e\u52a0\u8f7d\u5931\u8d25...</font>";
var isAdd = true;
  
	
    //创建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;
	var fromUrl = location.href;
	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+"&fromUrl="+fromUrl; 
                //打开连接
			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 = "\u67e5\u8be2\u9519\u8bef";
	}
}
function submitPoints() {
	var isload = 0;
	myCreateCookieKey();
	var ck = GetCookie(cookieKey);
	if (ck == cookieKey && cookieKey != null) {
		isload = 1;
		alert("\u8bf7\u4e0d\u8981\u91cd\u590d\u63d0\u4ea4\uff01");
		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;
	var fromUrl = location.href;
	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+"&fromUrl="+fromUrl;
            //打开连接
			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 = "\u67e5\u8be2\u9519\u8bef";
	}
}
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("\u8bc4\u8bba\u5185\u5bb9\u8d85\u8fc71000\u5b57\uff01");
		return false;
	}
	if (document.getElementById("contentShow").value.indexOf("<script") != -1 || document.getElementById("contentShow").value.indexOf("</") != -1) {
		alert("\u8bc4\u8bba\u5185\u5bb9\u542b\u6709\u7279\u6b8a\u5b57\u7b26!");
		return false;
	}
	if (document.getElementById("contentShow").value == "") {
		alert("\u5fc5\u987b\u586b\u5199\u8bc4\u8bba\u5185\u5bb9\uff01");
		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("\u8bf7\u4e0d\u8981\u9891\u7e41\u63d0\u4ea4\u6570\u636e");
		return false;
	}
	if (document.getElementById("contentShow").value == "") {
		alert("\u5fc5\u987b\u586b\u5199\u8bc4\u8bba\u5185\u5bb9\uff01");
		return false;
	}
	if (document.getElementById("contentShow").value.length > 1000) {
		alert("\u8bc4\u8bba\u5185\u5bb9\u8d85\u8fc71000\u5b57\uff01");
		return false;
	}
	if (document.getElementById("contentShow").value.indexOf("&") != -1 || document.getElementById("contentShow").value.indexOf("<script") != -1 || document.getElementById("contentShow").value.indexOf("</") != -1) {
		alert("\u8bc4\u8bba\u5185\u5bb9\u542b\u6709\u7279\u6b8a\u5b57\u7b26!");
		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 fromUrl = location.href;
	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=" + encodeURI(nickname) + "&nodeid=" + entityMpId + "&articleid=" + entityMpId + "&channelid=" + channelid + "&content=" + encodeURI(content) + "&fromUrl=" + fromUrl;
            //打开连接a
			xmlHttpSub.open("POST", url, true); 
             //设置回调函数
			xmlHttpSub.onreadystatechange = showEntitySubCommentContent;
            //发送请求
			xmlHttpSub.send(null);
		} else {
			document.commentformContent.contentShow.value = "";
			alert("\u62b1\u6b49\uff0c\u6682\u65f6\u4e0d\u80fd\u8bc4\u8bba!!");
		}
	}
	catch (e) {
          //document.getElementById("flag").innerHTML = "查询错误:" + e;
		alert(e);
		alert("\u62b1\u6b49\uff0c\u6682\u65f6\u4e0d\u80fd\u8bc4\u8bba!!!!");
	}
}
function showEntityCommentList(type, data, evt) {
	if (type == "error") {
		alert("\u8bfb\u53d6\u670d\u52a1\u5668\u6570\u636e\u65f6\u51fa\u9519");
	} else {
		if (data.replace(/(^\s*)|(\s*$)/g, "") == "\u8c22\u8c22") {
			alert("\u6570\u636e\u5df2\u7ecf\u63d0\u4ea4\uff0c\u8bf7\u7b49\u5f85\u5ba1\u6838!");
		} else {
			document.getElementById("showCommentContent").innerHTML = data;
		}
	}
}
function viewComment() {
	var fromUrl = window.location.href;
	document.commentform.period.value = document.getElementById("paperdatediv").innerText.replace(/(^\s*)|(\s*$)/g, "");
	document.commentform.method = "post";
	document.commentform.action = siteUrl + "/commentShowSave.do?method=listAllComments&fromUrl=" + fromUrl;
	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 = "\u67e5\u8be2\u9519\u8bef";
	}
}
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);
			isAdd = true;
			if (responseShow == "\u8c22\u8c22") {
				alert("\u6570\u636e\u5df2\u7ecf\u63d0\u4ea4\uff0c\u8bf7\u7b49\u5f85\u5ba1\u6838!");
				return false;
			} else {
				if (responseShow == "\u5931\u8d25") {
					alert("\u62b1\u6b49\uff0c\u6682\u65f6\u4e0d\u80fd\u8bc4\u8bba!!!");
					return false;
				} else {
					if (responseShow == "loginFail") {
						alert("\u7528\u6237\u540d\u6216\u5bc6\u7801\u4e0d\u6b63\u786e,\u8bf7\u786e\u8ba4\u662f\u5426\u6b63\u786e\u767b\u5f55!");
						return false;
					} else {
						if (responseShow != "\u8c22\u8c22" && responseShow != "\u5931\u8d25") {
							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();\">\u767b\u5f55</a><label><input type=\"checkbox\" name=\"isanonymous\" " + " id=\"isanonymous\" value=\"checkbox\" title=\"\u82e5\u52fe\u9009\uff0c\u5219\u533f\u540d\u8bc4\u8bba\" />\u533f\u540d</label>";
			document.getElementById("loginComment_div").innerHTML = _DIVF;
		}
	}
	catch (e) {
		var _DIVF = "<a href=\"#\" onclick=\"openLogin();\">\u767b\u5f55</a><label><input type=\"checkbox\" name=\"isanonymous\" " + " id=\"isanonymous\" value=\"checkbox\" title=\"\u82e5\u52fe\u9009\uff0c\u5219\u533f\u540d\u8bc4\u8bba\" />\u533f\u540d</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 = "\u60a8\u597d," + cArray[1] + "<label><input type=\"checkbox\" name=\"isanonymous\" " + " id=\"isanonymous\" value=\"checkbox\" title=\"\u82e5\u52fe\u9009\uff0c\u5219\u533f\u540d\u8bc4\u8bba\" />\u533f\u540d</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=\"\u82e5\u52fe\u9009\uff0c\u5219\u533f\u540d\u8bc4\u8bba\" />\u533f\u540d</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=\"\u82e5\u52fe\u9009\uff0c\u5219\u533f\u540d\u8bc4\u8bba\" />\u533f\u540d</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 & 65408)) {
			szRet += a.charAt(x);
		} else {
			if (!(wch & 61440)) {
				uch = "%" + (wch >> 6 | 192).toString(16) + "%" + (wch & 63 | 128).toString(16);
				szRet += uch;
			} else {
				uch = "%" + (wch >> 12 | 224).toString(16) + "%" + (((wch >> 6) & 63) | 128).toString(16) + "%" + (wch & 63 | 128).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;
}
function setCookie(name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	if (expires != null) {
		var LargeExpDate = new Date();
		LargeExpDate.setTime(LargeExpDate.getTime() + (expires * 1000 * 3600 * 24));
	}
	var cook = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + LargeExpDate.toGMTString()));
	document.cookie = cook;
}
function getCookie(Name) {
	var search = Name + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(offset, end));
		} else {
			return "";
		}
	}
}


