
var authorid;  //作者ID
var loginuser;  //观看者ID
$(function () {
	authorid = $("#authorid").val();
	loginuser = $("#loginuser").val();
});
function plshowpanel(vid, type) { //type 1 show more  0 show less 
	if (type == 1) {
		$("#plless_" + vid).hide();
		$("#plMorevidDescy_" + vid).hide();
		$("#plmore_" + vid).show();
		$("#plLessidDescy_" + vid).show();
	} else {
		$("#plless_" + vid).show();
		$("#plMorevidDescy_" + vid).show();
		$("#plmore_" + vid).hide();
		$("#plLessidDescy_" + vid).hide();
	}
}
function postcomment() {
	var content = $("#posttext").val();
	var devalue = $("#posttext").attr("defaultValue");
	if (content == "" || content == devalue) {
		return;
	}
	$("#posttextbtn").attr("disabled", "true");
	var commenterid = loginuser;
	var parentid = 0;
	var param = {"opusid":9, "commenterid":commenterid, "parentid":parentid, "content":content, "authorid":-1};
	t = new Date();
	$.post("/ajaxaction.do?method=postlivecomment&t=" + t.getTime(), param, function (json) {
		writeComment(json);
	}, "json");
}
function writeComment(json) {
	var len = json.length;
	var jlen = len - 1;
	//更新页面评论
	var result = new Array();
	for (var i = 0; i < jlen; i++) {
		var comform = json[i];
		result.push("<div class=\"text_box\">");
		result.push("<p class=\"return\">");
		if (comform.commenterid > 0) {
			result.push(" " + comform.commentername);
		} else {
			result.push("\u672a\u77e5\u6d41\u661f");
		}
		result.push("<span class=\"time\">\u65f6\u95f4\uff1a<strong>" + comform.createtime + "</strong></span></p>");
		result.push("<p>" + comform.content + "</p>");
		result.push("\t<div class=\"vspace\"></div>");
		result.push("</div>");
	}
	$("#commentul").html(result.join(""));
	$("#pagerightid").html(json[len - 1].page);
	$("#posttextbtn").attr("disabled", false);
	$("#total").html(json[len - 1].total);
	$("#posttext").val("");
}
function turnpage(p) {
	t = new Date();
	$.getJSON("/ajaxaction.do?method=turnlivepage&t=" + t.getTime(), {"page":p}, function (json) {
		writeComment(json);
	});
}
function showbox() {
	var posttextarea = document.getElementById("posttext");
	posttextarea.focus();
}
function changebg(id) {
	var _box = Dom.$id("channel_bar");
	var _li = Dom.$tagInNode("li", _box);
	for (i = 0; i < _li.length; i++) {
		_li[i].className = "";
	}
	var li = Dom.$id(id);
	if (li.className == "") {
		li.className = "cur";
	}
}
var _width = 480;
var _height = 384;
function change_c(id) {
	var url = "";
	//url = 'http://t.live.cctv.com/cctvwebplay/cctvplayer.html?channel='+id+'&&width='+_width+'&height='+_height;
	//http://t.live.cctv.com/cctvwebplay/cctvplayer.html?channel=cctv_p2p_cctv1&width=480&height=384&ad_local=2008.cctv.com/aamsz=live_ads/keyword=cctv1&logo=f
	url = "http://t.live.cctv.com/cctvwebplay/cctvplayer.html?channel=" + id + "&width=" + _width + "&height=" + _height;
	document.getElementById("cctv_p2p").src = url;
}
var now=new Date();
function printtimelist(array) {
	now = new Date();
	var n = 0;
	var j = 0;
	var text = "";
	var style = "cur";
	var chnlid = array[1].chnlid;
	var chnlurl = "";
	for (var i = 1; i < array.length - 1; i++) {
		if (((parseDate(array[i].starttime) > now) && (parseDate(array[i].starttime).getDate() == now.getDate()))) {
			if (array[i].prghead.length > 10) {
				header = array[i].prghead.substr(0, 10) + "...";
			} else {
				header = array[i].prghead;
			}
			if (array[i].url == "") {
				url = "!=''";
			} else {
				url = "='" + array[i].url + "'";
			}
			text += "<p class='" + style + "'><a class='l'>" + formatDate(array[i].starttime) + "</a><a href" + url + " target='_blank' title='" + array[i].prghead + "'>" + header + "</a></p>";
			style = "";
			j = i;
			n++;
		}
		if (n == 21) {
			break;
		}
	}
	if (n < 20) {
		text += "<div class='clear_float'/></div><h3>\u660e\u65e5\u8282\u76ee</h3>";
		while (n < 20) {
			if (array[j + 1].prghead.length > 10) {
				header = array[j + 1].prghead.substr(0, 10) + "...";
			} else {
				header = array[j + 1].prghead;
			}
			if (array[j + 1].url == "") {
				url = "!=''";
			} else {
				url = "='" + array[j + 1].url + "'";
			}
			text += "<p class=''><a class='l'>" + formatDate(array[j + 1].starttime) + "</a><a href" + url + " target='_blank' title='" + array[j + 1].prghead + "'>" + header + "</a></p>";
			j++;
			n++;
		}
	}
	
	if (array[1].chnl_name == "CCTV-4\u4e9a\u6d32") {
		chnl_name = "CCTV-4";
	} else {
		chnl_name = array[1].chnl_name;
	}
	document.getElementById("tr1").innerHTML = text;
}
function showlist( arrName )
{
	var arr = eval(arrName);
	printtimelist(arr);
}