
var xmlhttp = "";
var contentIds = "";
function httpRequest() {
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new XMLHttpRequest();
			} catch (e) {
				alert("对不起!您的浏览器不支持AJAX,请下载最新版本浏览器!");
			}
		}
	}
}

function getCookieVal (path) { 
	var endstr = window.document.cookie.indexOf (";", path); 
	if (endstr == -1)
		endstr = window.document.cookie.length; 
	return unescape(window.document.cookie.substring(path, endstr)); 
} 

function setcookie(path) {
	var exp = new Date();
	exp.setTime(exp.getTime() + 24 * 60 * 60 * 1000);
	document.cookie = "path=" + path + ";expires=" + exp.toGMTString();
}

function commend(bol, contentId, path) {
	var cooks = getCookieVal(path);
	if (cooks.split("=")[1] != path) {
		setcookie(path);
		httpRequest();
		if (bol == "YES")
			xmlhttp.open("get",
					"/comments/comments.action?method=commendAdd&contentId="
							+ contentId + "&commendNum=YES&num=" + new Date(),
					false);
		else
			xmlhttp
					.open("get",
							"/comments/comments.action?method=commendAdd&contentId="
									+ contentId + "&commendNum=NO&num="
									+ new Date(), false);
		contentIds = contentId;
		xmlhttp.onreadystatechange = callback;
		xmlhttp.send(null);
	}else
		alert("您已投过一次票,请明日再试!");
}

function callback() {
	if (xmlhttp.readystate == 4) {
		if (xmlhttp.status == 200) {
			var result = xmlhttp.responseText;
			alert(result);
			commendFind(contentIds);
		}
	}
}

function commendFind(contentIdss) {
	httpRequest();
	xmlhttp.open("post",
			"/comments/comments.action?method=commendFind&contentId="
					+ contentIdss + "&num=" + new Date(), false);
	xmlhttp.onreadystatechange = callbacks;
	xmlhttp.send(null);
}

function callbacks() {
	if (xmlhttp.readystate == 4) {
		if (xmlhttp.status == 200) {
			var results = xmlhttp.responseText;
			var str = results.split(",");
			document.getElementById("com").innerHTML = str[0] + "票";
			document.getElementById("uncom").innerHTML = str[1] + "票";
			if (str[0] == 0 && str[1] == 0) {
				document.getElementById("hong").style.width = "";
				document.getElementById("blue").style.width = "";
				document.getElementById("tuijindu").innerHTML = "";
				document.getElementById("hong").style.width = 0;
				document.getElementById("blue").style.width = 0;
				document.getElementById("tuijindu").innerHTML = 0;
			} else {
				document.getElementById("hong").style.width = "";
				document.getElementById("blue").style.width = "";
				document.getElementById("tuijindu").innerHTML = "";
				document.getElementById("hong").style.width = str[2];
				document.getElementById("blue").style.width = str[3];
				document.getElementById("tuijindu").innerHTML = str[2] + "%";
			}
		}
	}
}

function dianpin() {
	var pageRow = document.getElementById("pageRow");
	var currentPage = document.getElementById("currentPage").val;
	var contentId = document.getElementById("contentId").value;
	handleFind.handleFind(contentId, pageRow.val, currentPage,
			callbackForhandleFind);
}

function sye() {
	var pageRow = document.getElementById("pageRow").val;
	var currentPage = document.getElementById("currentPage").val;
	var contentId = document.getElementById("contentId").value;
	handleFind.handleFind(contentId, pageRow, 1, callbackForhandleFind);
}

function syiye() {
	var pageRow = document.getElementById("pageRow").val;
	var currentPage = document.getElementById("currentPage").val;
	var contentId = document.getElementById("contentId").value;
	handleFind.handleFind(contentId, pageRow, currentPage - 1,
			callbackForhandleFind);
}

function xyiye() {
	var pageRow = document.getElementById("pageRow").val;
	var currentPage = document.getElementById("currentPage").val;
	var contentId = document.getElementById("contentId").value;
	handleFind.handleFind(contentId, pageRow, currentPage + 1,
			callbackForhandleFind);
}

function wye() {
	var pageRow = document.getElementById("pageRow").val;
	var currentPage = document.getElementById("currentPage").val;
	var totalPage = document.getElementById("totalPage").val;
	var contentId = document.getElementById("contentId").value;
	handleFind.handleFind(contentId, pageRow, totalPage, callbackForhandleFind);
}

function styleDome(tds) {
	tds.style.border_bottom = '#999999 1px solid';
	tds.style.paddingbottom = '0px';
}

function callbackForhandleFind(map) {
	var tabs = document.getElementById("tabs");
	removeRow();
	for ( var i = 0; i < map.list.length; i++) {
		var tr = tabs.insertRow();
		var td1 = tr.insertCell();
		styleDome(td1);
		td1.innerHTML = "<DIV align=center>" + map.list[i].id + "</DIV>";
		var td2 = tr.insertCell();
		styleDome(td2);
		td2.innerHTML = "<DIV align=center>" + map.list[i].content
				+ "</DIV>";
		var td4 = tr.insertCell();
		styleDome(td4);
		td4.innerHTML = "<DIV align=center>"
				+ new Date(map.list[i].time).format('yyyy年MM月dd日') + "</DIV>";
	}
	document.getElementById("pageRow").val = map.pageRow;
	document.getElementById("pageRow").innerHTML = map.pageRow;
	document.getElementById("currentPage").innerHTML = map.currentPage;
	document.getElementById("currentPage").val = map.currentPage;
	document.getElementById("totalPage").innerHTML = map.totalPage;
	document.getElementById("totalPage").val = map.totalPage;
	document.getElementById("totalRow").innerHTML = map.totalRow;
	document.getElementById("totalRow").val = map.totalRow;
}

Date.prototype.format = function(format) {
	/*
	 * eg:format="yyyy-MM-dd hh:mm:ss";
	 */
	var o = {
		"M+" : this.getMonth() + 1, //month
		"d+" : this.getDate(), //day
		"h+" : this.getHours(), //hour
		"m+" : this.getMinutes(), //minute
		"s+" : this.getSeconds(), //second
		"q+" : Math.floor((this.getMonth() + 3) / 3), //quarter
		"S" : this.getMilliseconds()
	}

	if (/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	}

	for ( var k in o) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
					: ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
};

function subContent(list) {
	if (list.length <= 5)
		return list;
	else
		return list.substring(0, 4) + "...";
	return null;
}

function removeRow() {
	var tab = document.getElementById("tabs");
	var length = tab.rows.length;
	for ( var i = length - 1; i >= 0; i--) {
		tab.deleteRow(i);
	}
}

