/********************************************************************
*					comment.js
*				------------------
*		开始时间：2007.8.25
*		版 权：江敬城
*		Email：min43@163.com
*		编 号：comment.js，v1.0，2007.8.27 10:58，江敬城
*
********************************************************************/

// 评论通用处理JS

if( typeof(def_cnSubstr) == "undefined")
{
	// 默认需要截取的字节长度 1个汉字占2个字节
	var def_strlen = 30;
	
	// 文字显示不全时，默认的后缀
	var def_Ext = '...';
	
	// 默认的强制图片高度和宽度
	var def_imgWidth = 23;
	var def_imgHeight = 23;
	
	// 限制显示的图片数目
	var def_imgLimit = 3;
	
	// 换行符<br>的替换字符串
	var BrReplaceStr = " ";
	
	// 标志已经加载了字符截取函数
	var def_cnSubstr = true;
	
	function cnSubstr(str, len)
	{
		if(!str || !len) return '';
	
		var a = 0;
		var i = 0;
		var temp = '';
		
		for(i=0;i<str.length;i++)
		{
			if (str.charCodeAt(i)>255)	a+=2;
				else a++;
	
			if(a > len)
			{
				return temp;
			}
			temp += str.charAt(i);
		}
		
		return str;
	}
	
	function FixWidthHeight(imgstr, width, height)
	{
		if(imgstr.length = 0) return '';
		
		if(width == null) width = def_imgWidth;
		if(height == null) height = def_imgHeight;
		
		var pattern = "(<img .*?)>";
		var re = new RegExp(pattern, "i");
		imgstr = imgstr.replace(re, "$1 width=\""+width+"\" height=\""+height+"\" />");
		
		return imgstr;
	}
	
	function GetSubStr(str, len, ext, ignore_img, imgLimit)
	{
		var strlen = str.length;
		
		if(len == null || !len) len = def_strlen;
		
		if(!str || !len) return '';
		
		if(ext == null || ext.length == 0) ext = def_Ext;
		if(ignore_img == null || ignore_img.length == 0) ignore_img = false;
		if(imgLimit == null || imgLimit.length == 0) imgLimit = def_imgLimit;
		
		
		var pattern9 = "<br>";
		var re9 = new RegExp(pattern9, "gim");
		str = str.replace(re9, BrReplaceStr);
		
		if(ignore_img)
		{
			var pattern = "<img .*?>";
			var re = new RegExp(pattern, "gim");
			str = str.replace(re, "");
		}
		else
		{
			var i = 0;
			var pattern = "<img .*?>";
			var re = new RegExp(pattern, "gim");
			var r = str.match(re);
			str = str.replace(re, function() {i+=1; if(i > imgLimit) return ''; return "#"+i+"#";});
			
			i = -1;
			var pattern2 = "#([0-9]+)#";
			var re2 = new RegExp(pattern2, "gim");
			str = cnSubstr(str, len).replace(re2, function() {i+=1; return FixWidthHeight(r[i]);});
			
			var pattern3 = "#[0-9]*?$";
			var re3 = new RegExp(pattern3, "gim");
			str = str.replace(re3, "");
			
			if(str.length < strlen) str += ext;
		}
		
		return str;
	}
}

// 显示最新评论
function get_newcommentinfo(DivId, ListNum)
{
	if(nc_userList.length<=0 || nc_conList.length<=0) return;
	if(ListNum == null || ListNum < 1) ListNum = 10;
	
	var str = "";
	var temArray = new Array();
	
	for (var i=0,j=0; i<nc_userList.length; i++)
	{
		if(i >= ListNum) break;
		temArray[j++] = "<div class=\"commentinfo\"> <a href=\"" + nc_urlList[i] + "\" target=\"_blank\"  class=\"menu12type\">" + nc_titleList[i] + "</a> </div>";
		temArray[j++] = "<div class=\"userinfo\"> <span  class=\"menu12t\">" + nc_userList[i] + " 说： &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp; Time:" + nc_timeList[i] + "</span></div>";
		temArray[j++] = "<div class=\"txt10tg\" id =\"conlist" + [i]+ "\">" + nc_conList[i] + "</div>";
	}
	str = temArray.join("");
	temArray = null;
	
	if(document.getElementById(DivId) != null)
		document.getElementById(DivId).innerHTML = str;
}


// 显示一周内的热门评论
function get_lastweekcommentinfo(DivId, ListNum)
{
	if(lwc_titleList.length<=0 || lwc_connumList.length<=0) return;
	if(ListNum == null || ListNum < 1) ListNum = 10;
	
	var str = "";
	var temArray = new Array();
	var j = 0;
	
	temArray[j++] = "<table  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"cmsTable\">";
	for (var i=0; i<lwc_titleList.length; i++)
	{
		if(i >= ListNum) break;
		
		temArray[j++] = "  <tr>";
		temArray[j++] = "    <td class=\"r_rank\">" + (i+1) + "</td><td>&nbsp;<a title=\""+lwc_titleList[i]+"\" href=\"" + lwc_conurlList[i] + "\" target=\"_blank\" class=\"txt2\">" + GetSubStr(lwc_titleList[i], 25, '..') + "</a>[<a href=\"" + lwc_urlList[i] + "\" target=\"_blank\" class=\"txt3\">查看原文</a>]</td>";
		temArray[j++] = "  </tr>";
	}
	temArray[j++] = "</table>";
	
	str = temArray.join("");
	temArray = null;
	
	if(document.getElementById(DivId) != null)
		document.getElementById(DivId).innerHTML = str;
}


// 显示本周热门评论
function get_currweekcommentinfo(DivId, ListNum)
{
	if(lwc_titleList.length<=0 || lwc_connumList.length<=0) return;
	if(ListNum == null || ListNum < 1) ListNum = 10;
	
	var str = "";
	var temArray = new Array();
	var j = 0;
	
	for (var i=0; i<lwc_titleList.length; i++){
		if(i >= ListNum) break;		
		temArray[j++] = '<li><a class="source" href="' + lwc_urlList[i] + '">[查看源文]</a><a class="title" href="'+ lwc_conurlList[i] +'">'+GetSubStr(lwc_titleList[i], 50, '..') +'</a>';		
		temArray[j++] = '<span>'+lwc_connumList[i]+'</span></li>';
	}
	
	str = temArray.join("");
	temArray = null;
	
	if(document.getElementById(DivId) != null)
		document.getElementById(DivId).innerHTML = str;
}

// 显示一个月内的热门评论
function get_lastmonthcommentinfo(DivId, ListNum)
{
	if(lmc_titleList.length<=0 || lmc_connumList.length<=0) return;
	if(ListNum == null || ListNum < 1) ListNum = 10;
	
	var str = "";
	var temArray = new Array();
	var j = 0;
	
	temArray[j++] = "<table  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"cmsTable\">";
	for (var i=0; i<lmc_titleList.length; i++)
	{
		if(i >= ListNum) break;
		
		temArray[j++] = "  <tr>";
		temArray[j++] = "    <td class=\"r_rank\">" + (i+1) + "</td><td>&nbsp;<a title=\""+lmc_titleList[i]+"\" href=\"" + lmc_conurlList[i] + "\" target=\"_blank\" class=\"txt2\">" + GetSubStr(lmc_titleList[i], 30, '...') + "</a>[<a href=\"" + lmc_urlList[i] + "\" target=\"_blank\" class=\"txt2\">文</a>]</td>";
		temArray[j++] = "  </tr>";
	}
	temArray[j++] = "</table>";
	
	str = temArray.join("");
	temArray = null;
	
	if(document.getElementById(DivId) != null)
		document.getElementById(DivId).innerHTML = str;
}

//显示精彩评论列表
function get_recommendReply(DivId, ListNum)
{
	if(infoid_arr.length<=0){
		return false;	
	}
	if(ListNum == null || ListNum < 1){
		 ListNum = 10;
	}
	
	var str = "";
	var temArray = new Array();
	var j = 0;
	
	temArray[j++] = '<h3><span>精华评论</span></h3><ul class="m_spl">';
	for (var i=0; i<infoid_arr.length; i++)
	{
		if(i >= ListNum){
			break;
		}
		if(uc_uid_arr[i] != 0){
			temArray[j++] = '<li><div class="m_sinfo"><a href="http://i.81813.com/?controller=userinfo&uid='+uc_uid_arr[i]+'" class="m_name">'+nickname_arr[i]+'</a>';
		}else{
			temArray[j++] = '<li><div class="m_sinfo"><a href="#" class="m_name">'+nickname_arr[i]+'</a>';
		}
		
		if(ctype_arr[i] == 'zx'){
			temArray[j++] = '&nbsp;对咨询&lt;&lt;&nbsp;<a href="'+url_arr[i]+'">'+title_arr[i]+'</a>&gt;&gt;的评论</div>';
		}else{
			temArray[j++] = '&nbsp;对新闻&lt;&lt;&nbsp;<a href="'+url_arr[i]+'">'+title_arr[i]+'</a>&gt;&gt;的评论</div>';
		}
		
		temArray[j++] = '<div class="m_cinfo vspace10">'+content_arr[i]+'<span class="m_arr"></span></div></li>';
	}
	temArray[j++] = '</ul>';
	
	str = temArray.join("");
	temArray = null;
	
	if(document.getElementById(DivId) != null){
		document.getElementById(DivId).innerHTML = str;
	}
}


// 显示一个周内的热门回复
function get_lastweekreplyinfo(DivId, ListNum)
{
	if(lwr_titleList.length<=0 || lwr_dbnumList.length<=0) return;
	if(ListNum == null || ListNum < 1) ListNum = 10;
	
	var str = "";
	var temArray = new Array();
	var j = 0;
	
	temArray[j++] = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"table2\">";
	for (var i=0; i<lwr_titleList.length; i++)
	{
		if(i >= ListNum) break;
		
		temArray[j++] = "  <tr>";
		temArray[j++] = "    <td class=\"txt2\"><a href=\"" + lwr_urlList[i] + "\" target=\"_blank\" class=\"txt2\">" + GetSubStr(lwr_titleList[i], 36, '..') + "</a></td>";
		temArray[j++] = "  </tr>";
		//temArray[j++] = "  <tr>";
		//temArray[j++] = "    <td class=\"menu12t\"><p style=\"text-indent:2em;\">" + lwr_conList[i] + "</p></td>";
		//temArray[j++] = "  </tr>";
		
	}
	temArray[j++] = "</table>";
	
	str = temArray.join("");
	temArray = null;
	
	if(document.getElementById(DivId) != null)
		document.getElementById(DivId).innerHTML = str;
}

// 显示一个月内的热门回复
function get_lastmonthreplyinfo(DivId, ListNum)
{
	if(lmr_titleList.length<=0 || lmr_dbnumList.length<=0) return;
	if(ListNum == null || ListNum < 1) ListNum = 10;
	
	var str = "";
	var temArray = new Array();
	var j = 0;
	
	temArray[j++] = "<table width=\"95%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"table2\">";
	for (var i=0; i<lmr_titleList.length; i++)
	{
		if(i >= ListNum) break;
		
		temArray[j++] = "  <tr>";
		temArray[j++] = "    <td class=\"txt2\"><a href=\"" + lmr_urlList[i] + "\" target=\"_blank\" class=\"txt2\">" + GetSubStr(lmr_titleList[i], 36, '..') + "</a></td>";
		temArray[j++] = "  </tr>";
		//temArray[j++] = "  <tr>";
		//temArray[j++] = "    <td class=\"menu12t\"><p style=\"text-indent:2em;\">" + lmr_conList[i] + "</p></td>";
		//temArray[j++] = "  </tr>";
		
	}
	temArray[j++] = "</table>";
	
	str = temArray.join("");
	temArray = null;
	
	if(document.getElementById(DivId) != null)
		document.getElementById(DivId).innerHTML = str;
}

// 获取/显示评论内容
function getcommentinfo(DivId, ListNum, isReturn)
{
	if(userList.length<=0 || conList.length<=0) return;
	if(DivId == null) DivId = "commentinfoDiv";
	if(ListNum == null || ListNum < 1)
		ListNum = userList.length;
	else
		ListNum  = (ListNum > userList.length) ? userList.length : ListNum;
	if(isReturn == null) isReturn= false;
	
	var str = "";
	for(i=0; i<userList.length; i++)
	{
		str += "<TABLE cellSpacing=0 cellPadding=0 border=0 width=570><tr><td class=more1 style=padding:3px;>"+userList[i]+"  说：</td></tr><tr><td class=more2 style=padding:3px;> "+GetSubStr(conList[i])+" </td></tr><tr><td background=http://tp.91.com/images/01.gif><img src=http://tp.91.com/images/01.gif width=3 height=3></td></tr></table>";
	}
	
	if(isReturn) return str;
	
	if(document.getElementById(DivId) != null)
		document.getElementById(DivId).innerHTML = str;
}

//选择表情后
function switchStatus(){
	objComment.style.color = "#000";
	calLeft();
	firstLoad = false;
	var allFace = document.getElementById("all_face");
	allFace.style.display="none";
	objComment.focus();

}
//切换表情包
function change_face(a,b){
	for(i= 0 ;i<left_face.length;i++){											
		right_face[i].style.display = "none";
		right_face[b].style.display = '';
		left_face[i].className = "";
		left_face[a].className = "on_face";
	}
}
//检查剩余字数
function calLeft(){
  objCleft.innerHTML = 400 - objComment.value.length;
if (objComment.value.length > 400 ){
  alert("评论不能超过400个字!");
  objComment.value=objComment.value.substring(0,400);
  }
}
//随机显示快速评论
function pickArr(num, array){	
	var temp_array = new Array();
	temp_array = array.slice(0);//复制数组
	if (firstLoad){//页面载入后立即显示一条随机评论
		var arrIndex = Math.floor(Math.random()*temp_array.length);
		objComment.value = temp_array[arrIndex].replace(/　/g, "\r\n");
		objComment.style.color = "#888";
	}
	refreshArr(num, array);
}
//刷新快速评论
function refreshArr(num, array){
	var temp_array = new Array();
	objR_con.innerHTML = '';
	temp_array = array.slice(0);//复制数组
	for (var i = 0; i<num; i++) {
		if (temp_array.length>0) {
			var arrIndex = Math.floor(Math.random()*temp_array.length);
			var oLi = doc.createElement("li");
			var oA = doc.createElement("a");
			var oText = doc.createTextNode(temp_array[arrIndex]);
			oA.appendChild(oText);
			oA.href="javascript:;";
			oA.title=oA.innerHTML.replace(/　/g, "\r\n");
			oA.onclick = function (e){
				//if (firstLoad) objComment.value = this.innerHTML;
				//else objComment.value += this.innerHTML;
				objComment.value = this.innerHTML.replace(/　/g, "\r\n");
				objComment.style.color = "#000";
				calLeft();
				firstLoad = false;
				objComment.focus();
			}
			oLi.appendChild(oA);;
			objR_con.appendChild(oLi);
			temp_array.splice(arrIndex, 1);//将已输出的元素从数组里删除
		} else {break; }
	}
	
}

//生成一套表情代码
function genSmilies(source,sep,width){
	var sstr = "";
	end = source.length;
	tdLeft = end%sep;
	for (i=1; i<=end; i++){
		var tmpArr = new Array();
		tmpArr = source[i-1].split(".");
		if(i==1) {sstr+="<table width=\"100%\" border=\"0\" 	<tr>";	}
		sstr += "<td><img src=\"http://image.91.com/pz91/images/smile/"+tmpArr[0]+".gif\" title=\""+tmpArr[1]+"\" width=\""+width+"\" height=\""+width+"\" onClick=\"setFace(\'[f="+tmpArr[0]+"]\');switchStatus()\" /></td>";
		
		if(i%sep == 0 && i!=end){//如果达到行尾
			sstr+="</tr><tr>";
		}		
	}
	if(tdLeft>0){
		sstr+="<td colspan="+tdLeft+"></td></tr></table>";
	}else{
		sstr+="</tr>";
	}	
	return sstr;
	
}
//显示表情选择框
function showSmiliesCon(){
	var allFace = document.getElementById("all_face");
	allFace.style.display="";
	}
//鼠标点击任意处，隐藏表情框
document.onclick = function (event){      
	var e = event || window.event;
	var elem = e.srcElement||e.target;		   
	while(elem)   
	{    
		if(elem.id == "all_face"||elem.id == "smilies")   
		{   
				return;   
		}   
		elem = elem.parentNode;        
	}	
	var allFace = document.getElementById("all_face");
	if(allFace) allFace.style.display="none"; 
}
//输出表情代码
function showSmilies(){
var o = "<div class=\"smilies\" id=\"smilies\">";
o += "    <a onclick=\"showSmiliesCon();\" style=\"cursor:pointer\"><img src=\"http://image.91.com/pz91/images/smile/insert_face.gif\"></a>";
o += "</div>";
o += "<div id=\"all_face\" class=\"all_face\" style=\"display:none\">";
o += "    <div class=\"title\">选择表情<a onclick=\"document.getElementById(\'all_face\').style.display=\'none\'\">关闭</a></div>";
o += "    <div class=\"category\">";
o += "        <ul id=\"left_allface\">";
o += "            <li onclick=\"change_face(0,0)\" class=\"on_face\">91游</li>";
o += "            <li onclick=\"change_face(1,1)\">土匪鸡</li>";
o += "            <li onclick=\"change_face(2,2)\">乌龟GG</li>";
o += "            <li onclick=\"change_face(3,3)\">小僵尸</li>";
o += "            <li onclick=\"change_face(4,4)\">乡村熊</li>";
o += "        </ul>";
o += "        <div class=\"fix_empty\"></div>";
o += "    </div>";
o += "    <div class=\"right_con\">";
o += "        <div id=\"right_face\" class=\"right_face\">";
o += "        	<div>";

var s_title1 = new Array("1.哈哈大笑","2.开心","3.鼓掌","4.无语","5.大心","6.汗","7.打哈欠","8.疑问","9.hoho","10.惊讶",
						"11.加油","12.激动","13.不同意","14.害羞","15.不是介个样子滴","16.同意","17.晕","18.寒","19.气愤","20.撒娇",
						"21.装酷","22.仰慕","23.头晕","24.大哭","25.大笑","26.偷笑","27.嗯嗯","28.幻想","29.悲伤","30.困惑")
o += genSmilies(s_title1,8,23);

o += "            </div>";
o += "            <div style=\"display:none\">";

var s_title2 = new Array("1072.翻脸","1073.吃惊","1074.晕倒","1075.没钱","1076.单挑","1077.不知道","1078.有的是钱","1079.来啊","1080.弹吉他","1081.真好吃",
						"1083.闪","1084.耍刀","1085.双截棍","1086.救命啊","1087.转晕了")
o += genSmilies(s_title2,4,50);

o += "            </div>";
o += "            <div style=\"display:none\">";

var s_title3 = new Array("1059.开心","1060.吃惊","1061.打劫啊","1062.可怕啊","1063.抄袭","1064.嘻嘻","1065.伤心","1066.累","1067.爬过","1068.上学",
						"1069.哇---","1070.猥亵","1071.吓---")
o += genSmilies(s_title3,4,50);

o += "            </div>";
o += "            <div style=\"display:none\">";

var s_title4 = new Array("1088.吹符","1089.发呆","1090.睡觉","1091.吐舌头","1092.乌云","1093.小僵尸闭嘴","1094.小僵尸发火","1095.小僵尸耍宝","1096.小僵尸炸弹","1097.一队路过",
						"1098.着火")
o += genSmilies(s_title4,4,50);

o += "            </div>";
o += "            <div style=\"display:none\">";

var s_title5 = new Array("1039.拜拜","1040.鄙视你","1041.变身","1042.吃玉米","1043.鬼脸","1044.奸笑","1045.呕吐","1046.飘过","1047.掐脸","1057.装酷");
o += genSmilies(s_title5,4,50);

o += "            </div>";
o += "        </div>";
o += "    </div>";
o += "</div>";
document.writeln(o);	
}

var doc = window.document;
var firstLoad = true;
var comments = new Array('这就是传说中的沙发么',
					   '自插双目，扶墙而出',
					   '露珠湿沙壁，暮有晓寂寂',
					   '又是这种文章，我手欠',
					   '好文，必须顶！',
					   '我的心久久不能平静，好文啊',
					   '我一辈子都没有像今天这么开心',
					   '太恶心了，顶上去让大家跟我同恶心',
					   '小编功力不够就不要出来了',
					   '跪求下载地址~~~',
					   '鄙视标题党',
					   '哈哈，太搞笑了',
					   '友情支持',
					   '我是来打酱油的',
					   '又看见你在上网了，你怎么总在网上呀？你的学习任务完成了吗？你父母不为你着急吗？',
					   '此文带给我的震撼，犹如闪电瞬间通过全身，雷得外焦里嫩',
					   '本人过去、现在以及将来都不认识作者',
					   '哥回复 不代表小盆友你帅　哥回复 不代表小女女你水灵　哥回复 不代表您多有才华　哥回复 不代表您有多牛X　哥回复 不代表您值得哥在这浪费手劲　哥回复 不代表哥寂寞 只是哥想要包子了',
					   '看到此文，智商上的优越感油然而生',
					   '你就是那不落的太阳，照亮了大地，拯救了苍生，世界因你而美丽！',
					   '此评论来自91.com，可能是系统自动发送，与本人一点关系都没有，谢绝各种形式的跨省追捕。',
					   '雷就一个字，雷我很多次',
					   '此文真是一派胡言，真可谓：“两个黄鹂鸣翠柳，不知所云；一行白鹭上青天，不知所往”。',
					   '在逐行逐句地看完此文后，我的心久久不能压抑的喜悦，震动了整个生命！怎会有如此精妙绝伦的好文？'
					   );
