var ratetext = "太差劲了！,不怎样。,还可以。,真不错。,太棒了！".split(',');
var opusid;  //作品ID
var authorid;  //作者ID
var loginuser;  //观看者ID

function mn(x){
	for (var i=1; i<=x; i++) {
		document.getElementById("img" + i).src = "/image/dot_star.gif";
	}
	for (var i=x+1; i<=5; i++) {
		document.getElementById("img" + i).src = "/image/dot_empstar.gif";
	}
	document.getElementById("mt").innerHTML = "<span class=fs01>" + ratetext[x-1] + "</span>";
}

function mf(x){
	for (var i=1; i<=x; i++) {
		document.getElementById("img" + i).src = "/image/dot_star.gif";
	}
	for (var i=x+1; i<=5; i++) {
		document.getElementById("img" + i).src = "/image/dot_empstar.gif";
	}
}

//$(document).ready(function() {
$(function(){
	authorid = $("#authorid").val();
	opusid = $("#opusid").val();
	loginuser = $("#loginuser").val();
});

function initqklist() {
	t = new Date();
	//察看是否有临时节目单
	$.getJSON("/quickajax.do?method=initquick&t=" + t.getTime(), {'opusid':$("#opusid").val(), 'pid':$("#pid").val(), 'index':$("#index").val()}, function(json) {
		if (json.count > 0) {
			showquickbox(json);
		}
	});
}

function dosubmit(){
	var idcard=document.shareform.Idcard.value;
	var opusid=document.shareform.opusid.value;
	if (idcard == "") {
		alert("请输入身份证号码再投票。");
		return ;
	}else{
		if(checkIdcard(idcard)=="验证通过!"){
			ballot(idcard,opusid)
		}else{
			alert(checkIdcard(idcard));
			return ;
		}
	}
	
}
function ballot(idcard,opusid) {
	t = new Date();
	var param = {"idcard":idcard, "opusid":opusid};
	$.getJSON("/ajaxaction.do?method=ballot&t=" + t.getTime(), param, function(json) {
	     if (json.result == 1) {
				alert("投票成功。");
			} else if (json.result == 0) {
				alert("今天你投票已经超过5次，不能再投了！");
			} else if (json.result == -1) {
				alert("投票失败，请稍候再试！");
			} 
		});
	
}
//评分
function dorate1(rate,opusid) {
	t = new Date();
	$.getJSON("/ajaxaction.do?method=rating&t=" + t.getTime(), {"rate":rate, "opusid":opusid}, function(json) {
		if (true == json.result) {
			alert("投票成功。");
		}else{
			alert("投票失败，请稍候再试！");
		}
	});
}
function dorate(rate) {
	t = new Date();
	$.getJSON("/ajaxaction.do?method=rating&t=" + t.getTime(), {"rate":rate, "opusid":opusid}, function(json) {
		if (true == json.result) {
			var count = 1 + parseInt($("#ratecount").val());
			var result = [
				"<div id='mt' style='margin-right:0;_padding-top:3px; padding-bottom:6px;'><span class='fs01'>投票：" + count + "</span></div>",
				"<div class='mt_img' style='margin-right:0;'>"
			];
			for (var i=1; i<=rate; i++) {
				result.push("<img id='img' src='/image/dot_star.gif' />");
			}
			for (var i=rate+1; i<=5; i++) {
				result.push("<img id='img' src='/image/dot_empstar.gif' />");
			}
			result.push("</div>");
			$("#ratetd").html(result.join(''));
		}
	});
	setTimeout(reloadopus,1000);
}
function reloadopus()
{
	this.location.href="/opus/"+opusid+".html";
}
//举报
function doexposure() {
	var reason = $("#expselid").val();
	if (reason == 0) {
		return ;
	}
	$.getJSON("/ajaxaction.do?method=exposure", {"opusid":opusid, "userid":loginuser, "reason":reason}, function(e){
		cancelbox("exposure");
		$("#expspanid").html("举报");
	});
}

//收藏
function dofavorite() {
	var isfav = $("#favcheckid").attr("checked");
	var opuslistid = $("#favselid").val();
	if (opuslistid == 0 && !isfav) {
		return ;
	}
	t = new Date();
	$.getJSON("/ajaxaction.do?method=favorite&t=" + t.getTime(), {"opusid":opusid, "userid":loginuser, "isfav":isfav, "opuslistid":opuslistid}, function(json) {
		if (json.result) {
			if (opuslistid != "new") {
				cancelbox("favorite");
			} else {
				var url = $("#param").val();
				location.href = "/user/edit_playlist_info.do?cp_vid=" + opusid + "&url=" + url;
			}
		}
	});
}

function joingroup() {
	var joingroup = ["["];
	$("#joindivid").find("input[@type=checkbox]").each(function(i) {
		if ($(this).attr("checked")) {
			var value = $(this).val().split(",");
			if (joingroup.join('') != "[") {
				joingroup.push(",");
			}
			joingroup.push("{'gid':" + value[0] + ", 'vStrategy':" + value[1] + ", 'isowner':'" + value[2] + "'}");
		}		
	});
	joingroup.push("]");
	if (joingroup.join('') == "[]") {
		return;
	}
	t = new Date();
	$.getJSON("/ajaxaction.do?method=joingroup&t=" + t.getTime(), {"opusid":opusid, "group":joingroup.join('')}, function(json){
		if (json.result) {
			alert("添加成功");
			cancelbox("joingroup");
		}
	});
}

function changetag(act) {
	if ("more" == act) {
		$("#lesstag").css("display", "none");
		$("#moretag").css("display", "block");
	} else {
		$("#lesstag").css("display", "block");
		$("#moretag").css("display", "none");
	}
}

function turnpage(p) {
	t = new Date();
	$.getJSON("/ajaxaction.do?method=turncompage&t=" + t.getTime(), {"page":p, "opusid":opusid}, function(json) {
		var jlen = json.length-1;
		//更新页面评论
		var result = new Array();
		for (var i=0; i<jlen; i++) {
			var comform = json[i];
			if (i == 0) {
				result.push("<div class='text_box tb_type_video'>");
			} else if (i!=0 && !comform.isreply) {
				result.push("</div>");
				result.push("<div class='text_box tb_type_video'>");
			}
			if (comform.isreply) {
				result.push("<div class='text_box tb_type_video sj_24'>");
			}
			if (comform.commenterid > 0) {
				result.push("<p class='room'><span class='ttl'><a title='" + comform.commentername + "' href='"+ comform.commenterspace + "'>" + comform.commentername + "</a>");
			} else {
				result.push("<p class='room'><span class='ttl'>未知流星" + comform.commentername);
			}
			result.push("&nbsp;<span class='runtime'>时间：<b>" + comform.createtime + "</b></span>&nbsp;<span style=\"float:right;margin-top:-18px;\"><span id=\"importantcomment_"+comform.id+"\"><a href=\"javascript:importantc(1,'"+comform.id+"');\"><img src=\"/image/tj.jpg\"  /></a></span><span style=\"margin-left:12px;\"id=\"unimportantcomment_"+comform.id+"\"><a href=\"javascript:importantc(-1,'"+comform.id+"');\"><img src=\"/image/fd.jpg\"  /></a></span></span>");
			result.push("</span>");
			result.push("<span class='runtime'>" + comform.content + "</span>");
			result.push("</p>");
			result.push("<div class='MoreBottom' style=' margin-bottom:0px;'><a href='javascript:showbox(\"replycom\", " + comform.id + ");'>[回复]</a></div>");
			result.push("<div id='" + comform.id + "' style='display:none;width:500px'>");
			result.push("<div class='message_box'>");
			result.push("<textarea id='replaytext" + comform.id + "' onblur='if(this.value==\"\"){this.value=this.defaultValue;}' onfocus='if(this.value==this.defaultValue){this.value=\"\";}' class='leave_message_txt'>发表评论：</textarea>");
			result.push("</div>");
			result.push("<div class='message_btn_box'>");
			result.push("<input id='replaytext" + comform.id + "btn' type='button' value='提 交' onclick='postcomment(\"replaytext" + comform.id + "\", \"replay\", \"" + comform.parentid + "\");' class='submit_btn' style='border:1px solid #eee; background: #EC9400; color:#fff; height:20px; overflow:hidden; padding:2px 2px 0px; margin-top:0px;'/>");
			result.push("<input type='button' value='取 消' onclick='$(\"#replaytext\" + " + comform.id + ").val(\"发表评论：\");cancelbox(" + comform.id + ");' class='submit_btn' style='border:1px solid #eee; background: #EC9400; color:#fff; height:20px; overflow:hidden; padding:2px 2px 0px; margin-top:0px;'/>");
			result.push("</div>");
			result.push("<div class='vspace'></div>");
			result.push("</div>");
			result.push("<div class='clear_float'></div>");
			if (comform.isreply) { //回复
				result.push("</div>");
			}
		}
		if (jlen > 0) {
			result.push("</div>");
		}
		$("#commentdiv").html(result.join(''));
		
		//更新翻页
		$("b.current_page").html(p);
		$("span.tpb_right").html(json[jlen].page);

	});
}

function showbox(type, id) {
	if (type == "postcom") {
		//if ($("#isactive").val() == '1') {
			$("#posttext2")[0].focus();
		//} else {
			//alert("请先登陆并激活帐号，再发表您的评论。");
		//}
	} else if (type == "replycom") {
		//if ($("#isactive").val() == '1') {
			if (id != null && (typeof id != 'undefined') && id != "") {
				$("#"+ id).css("display", "block");				
			}
		//} else {
			//alert("请先登陆并激活帐号，再发表您的评论。");
		//}
	} else if (type == "favorite") {
		if (loginuser == '0') {
			alert("请先登录，再收藏此作品。");
		} else {
			$("#joingroup").hide();
			$("#exposure").hide();
			t = new Date();
			$.getJSON("/ajaxaction.do?method=favoption&t=" + t.getTime(), {"userid":loginuser}, function(json) {
				var favcount = json[json.length-1];
				$("#favcountid").html(favcount);
				
				var result = ["<select name='favsel' id='favselid'>",
			  		"<option value='0' selected>——请选择——</option>"];
				for (var i=0; i<json.length-1; i++) {
					result.push("<option value=" + json[i].opuslistid+ ">" + json[i].title + " (" + json[i].opuscount + "个视频)</option>");
				}
				result.push("<option value='new'>[ 新建节目单 ]</option>");
				result.push("</select>");
				$("#favselspanid").html(result.join(''));
				$("#favcheckid").attr("checked", true);
			});
			$("#" + type).show();
		}
	} else if (type == "share") {
		if (loginuser == '0') {
			alert("请先登录，再分享此作品。");
		} else {
			window.open('/opus/mi_halve.jsp?opusid=' + opusid + '&userid=' + loginuser, 'Share', 'width=580,height=480,resizable=yes,scrollbars=yes,status=0');
		}
	}else if (type == "ballot") {
		window.open('/opus/ballot.jsp?opusid=' + opusid , 'ballot', 'width=310,height=100,resizable=yes,scrollbars=yes,status=0');
	}  else if (type == "joingroup") {
		if (loginuser == '0') {
			alert("请先登录，再添加到星吧客。");
		} else {
			$("#exposure").hide();
			$("#favorite").hide();
			t = new Date();
			$.getJSON("/ajaxaction.do?method=groupoption&t=" + t.getTime(), {"userid":loginuser}, function(json) {
				if (json.length == 0) {
					$("#joindivid").html("您还没有加入任何<a href='/teams/mygrouplist.do' class='blue'>星吧客</a>。");
				} else {
					var result = ["<h3>请选择星吧客</h3>", "<span id='groupspanid'>"];
					for (var i=0; i<json.length; i++) {
						result.push("<input name='group' id='groupid' type='checkbox' value='" + json[i].gid + "," + json[i].vStrategy + "," + json[i].isowner + "' />" + json[i].gname + "（视频：" + json[i].gcount + "）");
						if (json[i].isowner != "") {
							result.push("（<span style='color:#0066FF'>群主</span>）");
						}
						result.push("<br/>");
					}
					result.push("</span>");
					result.push("<div class='vspace'></div>")
					result.push("<div><input name='groupbutton' id='groupbuttonid' type='button' value='添加入星吧客' onclick='joingroup()'/></div>");
					result.push("<div class='clear_float'></div>");
					$("#joindivid").html(result.join(''));
				}
			});
			$("#" + type).show();
		}
	} else if (type == "diy") {
		if (loginuser == '0') {
			alert("请先登录，再收藏素材。");
		} else {
			$.getJSON("/ajaxaction.do?method=diy", {"opusid":opusid, "userid":loginuser}, function(e){
				$("#diyid").html("成功收藏为素材");
			});
		}
	} else if (type == "exposure") {
		if (loginuser == '0') {
			alert("请先登录，再举报此作品。");
		} else {
			$("#joingroup").hide();
			$("#favorite").hide();
			$.getJSON("/ajaxaction.do?method=expoption", {},function(json) {
				var result = ["<select name='expsel' id='expselid'>",
					"<option value='0' selected>——请选择——</option>"]
				for (var i=0; i<json.length; i++) {
					result.push("<option value=" + json[i].id+ ">" + json[i].title + "</option>");
				}
				result.push("</select>");
				$("#expselspanid").html(result.join(''));
			});
			$("#" + type).show();
		}
	} else if (type == "subscribe") {
		if (loginuser == '0') {
			alert("请先登录，再订阅。");
		} else {
			subscribe();
		}
	}
}

function postcomment(id, type, pid) {
	var content = $("#" + id).val();
	var devalue = $("#" + id).attr("defaultValue");
	if (content == "" || content == devalue) {
		return ;
	}
	$("#" + id + "btn").attr("disabled","true");
	var commenterid = loginuser;
	var parentid;
	if (type == "post") {
		parentid = 0;
	} else {
		parentid = pid;
	}
	var param = {"opusid": opusid, "commenterid": commenterid, 
				 "parentid": parentid, "content": content, "authorid":authorid};
	t = new Date();
	$.post("/ajaxaction.do?method=postcomment&t=" + t.getTime(), param, function(xml) {
	     if ($(xml).text() == -1) {
	     	alert("您的评论被拒绝。");
	     } else if ($(xml).text() == 0) {
	     	alert("您的评论提交失败，请重试。");
	     } else {
	     	alert("您的评论已提交，请等待管理员审核。");
	     }
   	});
   	
   //	location.reload();
   window.location.href="/opus/"+opusid+".html";
}

function important(value) {
	$.getJSON("/ajaxaction.do?method=important", {"opusid":opusid, "value":value, "authorid":authorid, "loginuser":loginuser}, function(json) {
		$("#important").html("推荐到首页(" + json.important + ")");
		$("#unimportant").html("反对上首页(" + json.unimportant + ")");
	});
	setTimeout(reloadopus,1000);
}
function importantc(value,commentid) {
	$.getJSON("/ajaxaction.do?method=importantc", {"commentid":commentid, "value":value, "authorid":authorid, "loginuser":loginuser}, function(json) {
		$("#importantcomment_"+commentid).html("<img src=\"/image/tj.jpg\"/>(" + json.important + ")");
		$("#unimportantcomment_"+commentid).html("<img src=\"/image/fd.jpg\"/>(" + json.unimportant + ")");
	});
	
	setTimeout(reloadopus,1000);
}

function copyaddress(elemid) {
	var textit = $("#" + elemid).val();
	if (window.clipboardData) {
		window.clipboardData.setData("Text",textit);
	} else {
		var flashcopier = 'flashcopier';
		if( !document.getElementById(flashcopier) ) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		var divinfo = '<embed src="/flash/_clipboard.swf" FlashVars="clipboard='+textit+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
	document.getElementById(elemid).select();
}

function subscribe() {
	t = new Date();
	$.getJSON("/ajaxaction.do?method=subscribe&t=" + t.getTime(), {"loginuserid":loginuser, "authorid":authorid}, function(json) {
		if (json.result) {
			$("#subscribeid").html("您已订阅成功。");
		}
	});
}

function showpanel( vid,type )//type 1 show more  0 show less
{
	if(type==1)
	{
		$('#less_'+vid).hide();
		$('#MorevidDescy_'+vid).hide();
		$('#more_'+vid).show();
		$('#LessidDescy_'+vid).show();
	}
	else{
		$('#less_'+vid).show();
		$('#MorevidDescy_'+vid).show();
		$('#more_'+vid).hide();
		$('#LessidDescy_'+vid).hide();
	}
}

function cancelbox(elmid) {
	$("#" + elmid).hide();
}

function showbloghelp(type) {
	var bloghelpdiv = $("#bloghelpdiv");
	if ("msn" == type) {
		bloghelpdiv.html("<div id=\"msnblog\" style=\"width:492px; height:210px; background-color:white\">"
							  + "    <div style=\"width:492px; clear:both; background:url(/style/img/bg_md_hd.gif) repeat-x left top; height:25px; line-height:26px; margin:0px; padding-left:10px; text-align:right;\">"
				    		  +	"        <a href=\"javascript:deleteblog('msnblog')\"><img src=\"/images/opus/gb.gif\" border=\"0\"/></a>"
							  +	"	 </div>"
							  + "    <div style=\"width:475px; height:23px; margin:8px 8px 0 8px ; text-align:left; color:#A0410D; border-bottom:1px solid #CCCCCC\">将播放器显示到你的MSN Spaces！</div>"
		                      + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
			                  + "        <div style=\" float:left\"><img src=\"/images/opus/msn.gif\" /></div>"
          			          + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">1.只须一步<br />我们会帮你把节目发布到你的MSN Spaces发布编辑框！"
				              + "            <br /><br /><br /><br /><input type=\"button\" id=\"nextbutton\" name=\"Submit\" onclick=\"copytoblog('msn')\" value=\"下一步\" />"
			                  + "        </div>"
                       		  + "    </div>"
                          	  + "</div>");
	} else if ("qzone" == type) {
		var url = $("#pluginid").val();
		bloghelpdiv.html("<div id=\"qqblog\" style=\"width:492px; height:210px; background-color:white\">"
							  + "    <div style=\"width:492px; height:14px; clear:both; background:url(/style/img/bg_md_hd.gif) repeat-x left top; height:25px; line-height:26px; margin:0px; padding-left:10px; text-align:right;\">"
							  + "        <a href=\"javascript:deleteblog('qqblog')\"><img src=\"/images/opus/gb.gif\" border=\"0\"/></a>"
							  + "    </div>"
							  + "    <div style=\"width:475px; height:23px; margin:8px 8px 0 8px ; text-align:left; color:#A0410D; border-bottom:1px solid #CCCCCC\">将播放器显示到你的QQ空间！</div>"
							  + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
							  + "        <div style=\" float:left\"><img src=\"/images/opus/qq_1.gif\" width=\"300\" height=\"128\" /></div>"
							  + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">1.新建模块<br/>点击自定义、新建模块，选择“视频模块”，然后保存。</div>"
							  + "    </div>"
							  + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
							  + "        <div style=\" float:left\"><img src=\"/images/opus/qq_2.gif\" width=\"293\" height=\"111\" /></div>"
							  + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">2.插入代码<br/>在视频连接中输入我们提供的节目代码。<br/>"
							  + "            <input name=\"textfield\" id=\"copyblogtextid\" type=\"text\" size=\"14\" value=\"" + url + "\" />"
							  + "            <br/>"
							  + "            <input type=\"button\" id=\"nextbutton\" name=\"Submit\" onclick=\"copytoblog('qzone')\" value=\"  复制代码  \" />"
							  + "        </div>"
							  + "    </div>"
							  + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
							  + "        <div style=\" float:left\"><img src=\"/images/opus/qq_3.gif\" width=\"218\" height=\"120\" /></div>"
							  + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">3.保存<br/>保存所有选项，返回界面查看你的节目！</div>"
							  + "    </div>"
							  + "</div>");
	} else if ("sina" == type) {
		var url = $("#pluginid").val();
		bloghelpdiv.html("<div id=\"sinablog\" style=\"width:492px; height:210px; background-color:white\">"
		                      + "    <div style=\"width:492px; height:14px; clear:both; background:url(/style/img/bg_md_hd.gif) repeat-x left top; height:25px; line-height:26px; margin:0px; padding-left:10px; text-align:right;\">"
		                      + "        <a href=\"javascript:deleteblog('sinablog')\"><img src=\"/images/opus/gb.gif\" border=\"0\"/></a>"
		                      + "    </div>"
		                      + "    <div style=\"width:475px; height:23px; margin:8px 8px 0 8px ; text-align:left; color:#A0410D; border-bottom:1px solid #CCCCCC\">将播放器显示到你的新浪博客！</div>"
		                      + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
		                      + "        <div style=\" float:left\"><img src=\"/images/opus/sina_1.gif\" width=\"300\" height=\"130\" /></div>"
		                      + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">1.写新文章<br/>开始写新的Blog文章，选中编辑器下方的“显示源代码”，切换到源代码编辑。</div>"
		                      + "    </div>"
		                      + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
		                      + "        <div style=\" float:left\"><img src=\"/images/opus/sina_2.gif\" width=\"295\" height=\"128\" /></div>"
		                      + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">2.插入代码<br/>在代码框中输入我们提供的代码，再次选中“显示源代码”，返回普通编辑。<br/>"
		                      + "            <input name=\"textfield\" id=\"copyblogtextid\" type=\"text\" size=\"14\" value=\"" + url + "\" />"
		                      + "            <br/>"
		                      + "            <input type=\"button\" id=\"nextbutton\" name=\"Submit\" onclick=\"copytoblog('sina')\" value=\"  复制代码  \" />"
		                      + "        </div>"
		                      + "    </div>"
		                      + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
		                      + "        <div style=\" float:left\"><img src=\"/images/opus/sina_3.gif\" width=\"193\" height=\"135\" /></div>"
		                      + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">3.发布文章<br/>现在可以返回你的博客查看你的节目了！</div>"
		                      + "    </div>"
		                      + "</div>");
	} else if ("blogcn" == type) {
		var url = $("#pluginid").val();
		bloghelpdiv.html("<div id=\"blogcn\" style=\"width:492px; height:210px; background-color:white\">"
		                      + "    <div style=\"width:492px; height:14px; clear:both; background:url(/style/img/bg_md_hd.gif) repeat-x left top; height:25px; line-height:26px; margin:0px; padding-left:10px; text-align:right;\">"
		                      + "        <a href=\"javascript:deleteblog('blogcn')\"><img src=\"/images/opus/gb.gif\" border=\"0\"/></a>"
		                      + "    </div>"
		                      + "    <div style=\"width:475px; height:23px; margin:8px 8px 0 8px ; text-align:left; color:#A0410D; border-bottom:1px solid #CCCCCC\">将播放器显示到你的Blog CN！</div>"
		                      + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
		                      + "        <div style=\" float:left\"><img src=\"/images/opus/blogcn_1.gif\" width=\"298\" height=\"128\" /></div>"
		                      + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">1.新建模块<br/>点击自定义、新建模块，选择“视频模块”，然后保存。</div>"
		                      + "    </div>"
		                      + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
		                      + "        <div style=\" float:left\"><img src=\"/images/opus/blogcn_2.gif\" width=\"291\" height=\"115\" /></div>"
		                      + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">2.插入代码<br/>在视频连接中输入我们提供的节目代码。<br/>"
		                      + "            <input name=\"textfield\" id=\"copyblogtextid\" type=\"text\" size=\"14\" value=\"" + url + "\" />"
		                      + "            <br/>"
		                      + "            <input type=\"button\" id=\"nextbutton\" name=\"Submit\" onclick=\"copytoblog('blogcn')\" value=\"  复制代码  \" />"
		                      + "        </div>"
		                      + "    </div>"
		                      + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
		                      + "        <div style=\" float:left\"><img src=\"/images/opus/blogcn_3.gif\" width=\"293\" height=\"131\" /></div>"
		                      + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">3.保存<br/>保存所有选项，返回界面查看你的节目！</div>"
		                      + "    </div>"
		                      + "</div>");
	} else if ("blogbus" == type) {
		var url = $("#pluginid").val();
		bloghelpdiv.html("<div id=\"blogbus\" style=\"width:492px; height:210px; background-color:white\">"
		                      + "    <div style=\"width:492px; height:14px; clear:both; background:url(/style/img/bg_md_hd.gif) repeat-x left top; height:25px; line-height:26px; margin:0px; padding-left:10px; text-align:right;\">"
		                      + "        <a href=\"javascript:deleteblog('blogbus')\"><img src=\"/images/opus/gb.gif\" border=\"0\"/></a>"
		                      + "    </div>"
		                      + "    <div style=\"width:475px; height:23px; margin:8px 8px 0 8px ; text-align:left; color:#A0410D; border-bottom:1px solid #CCCCCC\">将播放器显示到你的blogbus！</div>"
		                      + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
		                      + "        <div style=\" float:left\"><img src=\"/images/opus/blogbus_1.gif\" width=\"294\" height=\"129\" /></div>"
		                      + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">1.写新日志<br/>登陆blogbus，打开新日志界面，在工具栏中点击“Flash” 按钮。</div>"
		                      + "    </div>"
		                      + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
		                      + "        <div style=\" float:left\"><img src=\"/images/opus/blogbus_2.gif\" width=\"297\" height=\"130\" /></div>"
		                      + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">2.插入代码<br/>在小窗口的Flash URL中输入我们提供的代码。<br/>"
		                      + "            <input name=\"textfield\" id=\"copyblogtextid\" type=\"text\" size=\"14\" value=\"" + url + "\" />"
		                      + "            <br/>"
		                      + "            <input type=\"button\" id=\"nextbutton\" name=\"Submit\" onclick=\"copytoblog('blogcn')\" value=\"  复制代码  \" />"
		                      + "        </div>"
		                      + "    </div>"
		                      + "    <div style=\"width:475px; height:130px; margin:12px 8px 0 8px ;\">"
		                      + "        <div style=\" float:left\"><img src=\"/images/opus/blogbus_3.gif\" width=\"297\" height=\"130\" /></div>"
		                      + "        <div style=\" float:right; margin:5px 10px 0 0; width:120px; text-align:left;\">3.发布日志<br/>发表并重建日志，返回主页查看你的节目！</div>"
		                      + "    </div>"
		                      + "</div>");
	}
	bloghelpdiv.show();
	bloghelpdiv[0].focus();
}

function deleteblog(elmid) {
	$("#bloghelpdiv").hide();
}

function copytoblog(type) {
	var nbutton = $("#nextbutton");
	nbutton.attr("disabled", "true");
	if ("msn" == type) {
		var opustitle = $("#opustitle").text();
		var opusurl = $("#host").val() + $("#param").val();
		var opusimg = $("#showpicUrl").val();
		var url = "http://spaces.msn.com/BlogIt.aspx?Title=" 
			  + encodeURIComponent(opustitle) 
		      + "&SourceURL=" + opusurl 
		      + "&description=<a href='" + opusurl + "'>" 
		      + "<img src='" + opusimg + "' border='0'/></a>";
		window.open(url, "_blank");
	} else {
		copyaddress('copyblogtextid');
	}
}

function addquicklist(opusid) {
	t = new Date();
	$.getJSON("/quickajax.do?method=addandget&t="+t.getTime(), {'opusid':opusid}, function(json) {
		$("a[@name=add"+opusid+"]").each(function() {
			$(this).removeClass("video_img");
			$(this).unbind("hover");
			$(this).addClass("video_img_done");
		});
		
		if (json.count > 0 && json.opus !== undefined && json.opus != null) {
			if ($("#quickspan").children().length == 0) {
				showquickbox(json);
			} else {
				addopusinlist(json);
			}
		}
	});
}

function addopusinlist(jsonP) {
	$("#qkcount").html(jsonP.count);
	var result = new Array();
	if (jsonP.opus.length === undefined ) {
		var opusform = jsonP.opus;
		result.push("<tr id='qktr" + opusform.opusid + "'>");
		result.push("<td height='70' width='30' align='center' valign='middle' bgcolor='#ffffff'><span id='qkindex" + opusform.opusid + "'>" + jsonP.count + "</span></td>");
		result.push("<td width='90' align='center' valign='middle' bgcolor='#ffffff'><a href='" + opusform.playUrl + "'><img src='" + opusform.showpicUrl + "' width='80' height='60' /></a></td>");
		result.push("<td width='55%' valign='middle' bgcolor='#ffffff'><div><b ><a style='color:#0066FF;' href='" + opusform.playUrl + "'>" + opusform.title + "</a></b></div><br />播客：" + opusform.nickname + "<br /></td>");
		result.push("<td width='60' align='center' valign='middle' bgcolor='#ffffff'><b>"+ opusform.playtime + "</b></td>");
		result.push("<td width='30' align='center' valign='middle' bgcolor='#ffffff'><a href='javascript:delqkopus(" + opusform.opusid + ")'><img src='/image/sc.gif' /></a></td>");
		result.push("</tr>");
	} else {
		var cur = jsonP.current;
		for (var i=0; i<jsonP.opus.length; i++) {
			var opusform = jsonP.opus[i];
			if (cur == i) {
				result.push("<tr id='qktr" + opusform.opusid + "'>");
				result.push("<td height='70' width='30' align='center' valign='middle' bgcolor='#FFFCDD'><span id='qkindex" + opusform.opusid + "'>" + (i+1) + "</span></td>");
				result.push("<td width='90' align='center' valign='middle' bgcolor='#FFFCDD'><a href='" + opusform.playUrl + "'><img src='" + opusform.showpicUrl + "' width='80' height='60' /></a></td>");
				result.push("<td width='55%' valign='middle' bgcolor='#FFFCDD'><div><b ><a style='color:#0066FF;' href='" + opusform.playUrl + "'>" + opusform.title + "</a></b></div><br />播客：" + opusform.nickname + "<br />&lt;&lt;<b>正在播放</b></td>");
				result.push("<td width='60' align='center' valign='middle' bgcolor='#FFFCDD'><b>"+ opusform.playtime + "</b></td>");
				result.push("<td width='30' align='center' valign='middle' bgcolor='#FFFCDD'><a href='javascript:delqkopus(" + opusform.opusid + ")'><img src='/image/sc.gif' /></a></td>");
				result.push("</tr>");				
			} else {
				result.push("<tr id='qktr" + opusform.opusid + "'>");
				result.push("<td height='70' width='30' align='center' valign='middle' bgcolor='#ffffff'><span id='qkindex" + opusform.opusid + "'>" + (i+1) + "</span></td>");
				result.push("<td width='90' align='center' valign='middle' bgcolor='#ffffff'><a href='" + opusform.playUrl + "'><img src='" + opusform.showpicUrl + "' width='80' height='60' /></a></td>");
				result.push("<td width='55%' valign='middle' bgcolor='#ffffff'><div><b ><a style='color:#0066FF;' href='" + opusform.playUrl + "'>" + opusform.title + "</a></b></div><br />播客：" + opusform.nickname + "<br /></td>");
				result.push("<td width='60' align='center' valign='middle' bgcolor='#ffffff'><b>"+ opusform.playtime + "</b></td>");
				result.push("<td width='30' align='center' valign='middle' bgcolor='#ffffff'><a href='javascript:delqkopus(" + opusform.opusid + ")'><img src='/image/sc.gif' /></a></td>");
				result.push("</tr>");
			}
		}
	}
	$("#qktb").append(result.join(''));
}

function showquickbox(jsonP) {
	if (jsonP.nextopus !== undefined && jsonP.nextopus != null) {
		var qkbox = getqkBox(jsonP.nextopus, jsonP.count, jsonP.checked, jsonP.current);
		$("#quickspan").append(qkbox.join(''));
		$("#showhideA").toggle(
			function () {
			    $("#qkbody1").hide();
			    $("#qkbody2").hide();
			  },
			function () {
			    $("#qkbody1").show();
			    $("#qkbody2").show();
			  }
		);
		addopusinlist(jsonP);
	} else {
		t = new Date();
		$.getJSON("/quickajax.do?method=getnextopus&t=" + t.getTime(), {'opusid':opusid, 'pid':$("#pid").val(), 'index':$("#index").val()}, function(json){
			if (json.nextopus !== undefined && json.nextopus != null) {
				var qkbox = getqkBox(json.nextopus, jsonP.count, jsonP.checked, 0);
				$("#quickspan").append(qkbox.join(''));
				$("#showhideA").toggle(
					function () {
					    $("#qkbody1").hide();
					    $("#qkbody2").hide();
					  },
					function () {
					    $("#qkbody1").show();
					    $("#qkbody2").show();
					  }
				);
			}
			addopusinlist(jsonP);
		});
	}
}

function delqkopus(opusid) {
	var index = document.getElementById("qkindex" + opusid).innerHTML;
	t = new Date();
	$.getJSON("/quickajax.do?method=delqkopus&t=" + t.getTime(), {'index':index}, function(json) {
		if (json.result) {
			var count = json.count;
			if (count == 0) {
				$("#quickspan").children().remove();
				return ;
			}
			$("#qkcount").html(json.count);
			var next = $("#qktr" + opusid).next();
			$("#qktr" + opusid).remove();
			var i=0;
			for (var i=index; i<=count; i++) {
				var nextid = next.attr("id");
				nextid = nextid.replace(/qktr([^\.]+)*/gi,"$1");
				var idx = document.getElementById("qkindex" + nextid).innerHTML;
				var newidx = parseInt(idx)-1;
				document.getElementById("qkindex" + nextid).innerHTML = "" + newidx;
				next = next.next();
			}
		}
	});
}

function getqkBox(nextopus, count, checked, cur) {
	if (cur < 0) {
		cur = 0;
	}
	var playall = "/opus/subplay.do?opusid=0&pid=-100&index=" + cur;
	
	var qkbox = ["<tr>"
					, "<td bgcolor='#eeeeee' align='center' valign='middle' width='100' height='50'><b>临时节目单</b></td>"
					, "<td bgcolor='#eeeeee' align='right' valign='middle' width='100'><a href='" + playall + "'><img src='/image/p_btn.gif' width='40' height='30' /></a></td>"
					, "<td bgcolor='#eeeeee' align='left' valign='middle' width='100'><a href='" + playall + "' style='color:#0066FF'><b>播放所有</b></a><br />视频：<span id='qkcount'>" + count + "</span></td>"
					, "<td bgcolor='#eeeeee' align='right' valign='middle' width='100'><a href='" + nextopus.playUrl + "'><img id='qknextimg' src='" + nextopus.showpicUrl + "' width='60' height='45' /></a></td>"
					, "<td bgcolor='#eeeeee' align='left' valign='middle' width='100'><a href='" + nextopus.playUrl + "' style='color:#0066FF'><b>播放下一个</b></a><div id='qknextname' style='width:90px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;'>" + nextopus.title + "</div></td>"
					, "<td bgcolor='#eeeeee' align='center' valign='middle' width='100'><a href='javascript:void(0);' id='showhideA'><img alt='显示或隐藏临时节目单' src='/image/n_btn.gif' width='40' height='30' /></a></td>"
					, "</tr>"
					, "<tr id='qkbody1'>"
					, "<td colspan='6' bgcolor='#ffffff'>"
					, "<div>"
					, "<table width='100%' bgcolor='#eeeeee' cellspacing='1'>"
					, "<tbody id='qktb'>"
					, "</tbody>"
					, "</table>"
					, "</div>"
					, "</td>"
					, "</tr>"
					, "<tr id='qkbody2'>"
					, "<td colspan='6' bgcolor='#ffffff'>"
					, "<table width='100%' bgcolor='#cccccc' cellspacing='0'>"
					, "<tbody>"
					, "<tr>"
					, "<td width='40%' bgcolor='#eeeeee' align='left' valign='middle' height='25'><input name='' id='quicktype' type='checkbox' value='' onclick='changetype();' " + checked + "/> 从临时节目单中移除观看过的视频</td>"
					, "<td width='30%' bgcolor='#eeeeee' align='center' valign='middle' ></td>"
					, "<td width='30%' bgcolor='#eeeeee' align='right' valign='middle'><b><a href='/user/myhistory.do?type=temp' style='color:#0066FF'>管理</a> | <a href='/user/edit_playlist_info.do?ql=1' style='color:#0066FF'>保存</a> | <a href='javascript:clearqk();' style='color:#0066FF'>清空</a></b>&nbsp;&nbsp;</td>"
					, "</tr>"
					, "</tbody>"
					, "</table>"
					, "</td>"
					, "</tr>"];
					//<a href='' style='color:#0066FF'>显示所有视频</a>
	return qkbox;
}

function changetype() {
	var checked = $("#quicktype").attr("checked");
	var ch = "";
	if (checked) {
		ch = "checked";
	}
	$.post("/ajax/quicktype.jsp", {'checked':ch}, function(xml){;});
}

function clearqk() {
	$.getJSON("/quickajax.do?method=clearqk", {}, function(json) {
		$("#quickspan").children().remove();
	});
}