
var MAX_ITEMS = 20, taotao_pane_id = "id_apiPane", KEY_WORD_YJ = "[\u5047]";
var taotao_sr = new Array("\u7f51\u9875", "QQ", "QZONE", "QQ\u7b7e\u540d", "\u77ed\u4fe1", "\u624b\u673a\u4e0a\u7f51", "MSN", "MSN\u7b7e\u540d", "\u624b\u673aQQ", "\u5f69\u4fe1", "\u8ba2\u9605", "", "QQ\u72b6\u6001");
function LK(str) {
	return document.createElement(str);
}
function LL(str) {
	return document.getElementById(str);
}
function LG(str, target) {
	var re = new RegExp("http(s)?://([a-z0-9?.=%&-_;#\\/])+", "ig");
	if (target == "_blank") {
		str = str.replace(re, "<a target='_blank' href='$&'>$&</a>");
	} else {
		str = str.replace(re, "<a href='$&'>$&</a>");
	}
	return str;
}
function LH(str) {
	if (typeof (str) == "string") {
		str = str.replace(/[\r\n\t\0]/g, "");
		return str;
	}
}
function LE(str, target) {
	str = LH(str);
	var re = /(\[URL=(.[^\[]*)\])(.*?)(\[\/URL\])/ig;
	if (target == "_blank") {
		str = str.replace(re, "<A HREF=$2 TARGET=_blank>$3</A>");
	} else {
		str = str.replace(re, "<A HREF=$2>$3</A>");
	}
	return str;
}
function initApi() {
	if (typeof taotao_qq == "undefined") {
		alert("we can not get qq num,show nothing...!");
		return;
	}
	if (typeof taotao_num == "undefined" || taotao_num <= 0 || taotao_num > 20) {
		taotao_num = 20;
	}
	if (typeof taotao_type == "undefined" || taotao_type < 0 || taotao_type > 1) {
		taotao_type = 0;
	}
}
function LI(url) {
	g_cximg = null;
	g_cximg = new Array();
	var re = /\[IMG\](.+?)\[\/IMG\]/ig, tt = url.match(re);
	g_ubbcon = url.replace(re, "");
	for (var i = 0; i < tt.length; ++i) {
		g_cximg[g_cximg.length] = tt[i].replace(re, "$1");
	}
}
function LF(str) {
	if (str.substr(0, 3) == KEY_WORD_YJ) {
		str = "<font style=\"color:red\">" + KEY_WORD_YJ + "</font>" + str.substr(3, str.length - 3);
	}
	return str;
}
function doApi(obj) {
	if (obj.ret != 0) {
		pane.innerHTML = "\u5bf9\u4e0d\u8d77\uff01\u6682\u65f6\u65e0\u6cd5\u83b7\u53d6\u6ed4\u6ed4\u7684\u5520\u53e8,\u8bf7\u7a0d\u5019\u91cd\u8bd5...";
		return;
	}
	var qq = obj.ui.qq, name = obj.ui.name, usn = obj.ui.usn, rank = obj.ui.rank, lrank = obj.ui.lrank, rec = obj.rec;
	var arr = obj.posts, i = 0, data, pane = LL(taotao_pane_id), li, span, a, bD = false;
	for (i = 0; i < arr.length; i++) {
		data = arr[i];
		li = LK("li");
		li.style.wordBreak = "break-all";
		li.style.height = "auto";
		li.style.overflowY = "auto";
		if (obj.type == 1) {
			a = LK("a");
			a.style.marginRight = "8px";
			a.innerText = data.nm;
			a.textContent = data.nm;
			a.href = "http://www.taotao.com/space.shtml?qq=" + data.qq;
			li.appendChild(a);
			if (data.pqq) {
				li.appendChild(document.createTextNode("@"));
				a = LK("a");
				a.style.marginRight = "8px";
				a.innerText = data.pnm;
				a.textContent = data.pnm;
				a.href = "http://www.taotao.com/space.shtml?qq=" + data.pqq;
				li.appendChild(a);
			}
		}
		span = LK("span");
		if (data.sr == 10) {
			span.innerHTML = LE(data.cn, "_blank");
		} else {
			if (data.sr == 9) {
				LI(data.cn);
				var cxlen = g_cximg.length;
				span.innerHTML = g_ubbcon + "&nbsp;<a target=\"_blank\" href=\"http://www.taotao.com/caixin.shtml?qq=" + qq + "&tid=" + data.id + "\">\u70b9\u51fb\u67e5\u770b\u5f69\u4fe1</a>";
			} else {
				span.innerHTML = LF(LG(data.cn, "_blank"));
			}
		}
		li.appendChild(span);
		span = LK("span");
		span.style.marginLeft = "8px";
		a = LK("a");
		a.style.color = "#929091";
		//if (parseInt(data.pqq) > 0) {
			//a.href = "http://www.taotao.com/reply.shtml?pid=" + data.pid + "&pqq=" + data.pqq + "&uid=" + data.id;
		//} else {
		//	a.href = "http://www.taotao.com/reply.shtml?pid=" + data.id + "&pqq=" + qq + "&uid=" + data.id;
		//}
		a.innerHTML = LJ(data.time);
		li.appendChild(span);
		span.appendChild(a);
		span = LK("span");
		span.style.marginLeft = "4px";
		
		li.appendChild(span);
		pane.appendChild(li);
	}
}
function LJ(t) {
	if (t.charAt(1) != ",") {
		return t;
	}
	if (t.length < 2) {
		return "";
	}
	var n = t.charAt(0), v = t.substr(2, t.length), s = "";
	if (n == 1) {
		s = "\u7ea6&nbsp;" + v + "&nbsp;\u79d2\u524d";
	} else {
		if (n == 2) {
			s = "\u7ea6&nbsp;" + v + "&nbsp;\u5206\u949f\u524d";
		} else {
			if (n == 3) {
				s = "\u7ea6&nbsp;" + v + "&nbsp;\u5c0f\u65f6\u524d";
			} else {
				if (n == 4) {
					s = "\u7ea6&nbsp;1&nbsp;\u5929\u524d";
				} else {
					if (n == 5) {
						s = "\u7ea6&nbsp;3&nbsp;\u5929\u524d";
					} else {
						if (n == 6) {
							s = "\u7ea6&nbsp;1&nbsp;\u5468\u524d";
						} else {
							if (n == 7) {
								s = v;
							}
						}
					}
				}
			}
		}
	}
	return s;
}
function inclApi() {
	var src = "http://www.taotao.com/cgi-bin/msgj?qq=" + taotao_qq + "&num=" + taotao_num + "&t=" + taotao_type, htm = "<div>" + "<ul id=" + taotao_pane_id + " style=\"margin-bottom:5px\">" + "</ul>" + "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">" + "<tr>" + "<td align=\"left\">" + "</td>" + "<td align=\"right\">" + "</td>" + "</tr>" + "</table>" + "</div>";
	window.document.write(htm);
	window.document.write("<sc" + "ript type=\"text/javascript\" charset=\"utf-8\" src=\"" + src + "\"></" + "script>");
}
initApi();
inclApi();

