$(function(){
	
	create_rtmp_host();

})
function init_prev_list(prevmode)
{
	//var prevmode = "${request.preview}"
	if(prevmode == "prevlist")
	{
		$("#prevlist").addClass("prevlistsel");
	}
	else
	{
		$("#list").addClass("listsel");
	}
}
function change_list(mode)
{
	if(mode == "prevlist")
	{
		window.location.href = "/admin/live/LiveListServlet?preview=prevlist";
	}
	else if(mode == "list")
	{
		window.location.href = "/admin/live/LiveListServlet?preview=list";
	}
}

function addDialog()
{
	window.top.art.dialog
	(
		{
			id:'add',iframe:'add_live.html', title:'添加直播列表', width:'800', height:'550', lock:true,window:'top'
		},
		function(){
			var d = window.top.art.dialog({id:'add'}).data.iframe;
			var form = d.document.getElementById('dosubmit');
			form.click();
			return false;
			}, 
		function()
		{
			window.top.art.dialog({id:'add'}).close()
		}
	);void(0);	
}

function addSubStream(id)
{
	window.top.art.dialog
	(
		{
			id:'output',iframe:'/live_substream.html?id='+id, title:'添加直播子码流', width:'500', height:'400', lock:true,window:'top'
		},
		function(){
			var d = window.top.art.dialog({id:'output'}).data.iframe;
			var form = d.document.getElementById('dosubmit');
			form.click();
			return false;
			}, 
		function()
		{
			window.top.art.dialog({id:'output'}).close()
		}
	);void(0);	
}

function delSubStream(id,name)
{		
	window.top.art.dialog
	(
		{
			id:'del',content:"确定要删除么?", title:'删除直播频道',lock:true
		},
		function(){			
			redirect("/handle/action/live.php?action=del_substream&id="+id+"&name="+name);
			return true;
		}, 
		function()
		{
			window.top.art.dialog({id:'del'}).close()
		}	
	)
}
function whilePlay(id)
{
	window.top.art.dialog
	(
		{
			id:'whilePlay',iframe:'/live_while_play.html?id='+id, title:'轮播列表', width:'800', height:'600', lock:true,window:'top'
		},
		function(){
			var d = window.top.art.dialog({id:'whilePlay'}).data.iframe;
			var form = d.document.getElementById('dosubmit');
			form.click();
			return false;
			}, 
		function()
		{
			window.top.art.dialog({id:'whilePlay'}).close()
		}
	);void(0);	
}


function liveReplace(id)
{
	window.top.art.dialog
	(
		{
			id:'liveReplace',iframe:'/live_replace.html?id='+id, title:'添加直播插播', width:'900', height:'600', lock:true,window:'top'
		},
		function(){
			var d = window.top.art.dialog({id:'liveReplace'}).data.iframe;
			var form = d.document.getElementById('dosubmit');
			form.click();
			return false;
			}, 
		function()
		{
			window.top.art.dialog({id:'liveReplace'}).close()
		}
	);void(0);	
}


function playUrl()
{
	var ids = "";
	$("#main_body :checkbox").each(function(i)
	{
		if($(this).attr("checked"))
		{
			var liveId = $(this).val();
			ids+= liveId + "@";
		}
	})
	
	//去掉最后一个 @
	ids = ids.substring(0,ids.lastIndexOf("@"));	
	
	if(ids == "")
	{
		window.top.art.dialog({id:'dg_test34243', content:'您未选择任何直播频道!',time:1});			
		return false;
	}
		
	window.top.art.dialog
	(
		{
			id:'playUrl',iframe:"/admin/live/generatePlayUrl.jsp?ids="+ids+"", title:'选择要生成URL的协议', width:'500', height:'350', lock:true,window:'top' 
		},
		function(){
			
			window.top.art.dialog({id:'playUrl'}).close();
			return false;
		}, 
		function()
		{
			window.top.art.dialog({id:'playUrl'}).close()
		}
	);void(0);	
}


function mobilePlay(id)
{

	window.top.art.dialog
	(
		{
			id:'output',iframe:'/live_qrcode.html?id='+id, title:'移动播放', width:'500', height:'450', lock:true,window:'top' 
		},
		function(){
			window.top.art.dialog({id:'output'}).close()
			return false;
			}, 
		function()
		{
			window.top.art.dialog({id:'output'}).close()
		}
	);void(0);	

}



function editDialog(id)
{
	window.top.art.dialog
	(
		{
			id:'edit',iframe:'/edit_live.html?id='+id, title:'编辑直播', width:'800', height:'550', lock:true
		},
		function(){
			var d = window.top.art.dialog({id:'edit'}).data.iframe;
			var form = d.document.getElementById('dosubmit');
			form.click();			
			return false;			
			}, 
		function()
		{
			window.top.art.dialog({id:'edit'}).close()
		}
	);void(0);	
}

function delDialog(id,appName)
{		
	window.top.art.dialog
	(
		{
			id:'del',content:"确定要删除么?", title:'删除直播频道',lock:true
		},
		function(){			
			redirect("/handle/action/live.php?action=del&appName="+appName+"&id="+id);
			return true;
		}, 
		function()
		{
			window.top.art.dialog({id:'del'}).close()
		}	
	)
}


function timeConfig(id)
{
	redirect('/live_record_time.html?id='+id);
}
function tvguid(id,liveName)
{
	redirect("/admin/live/tvguid/tVGuidList.action?liveName="+liveName+"&liveId="+id);	
}
function visit(id,liveName)
{
	redirect("/admin/live/visit/visitList.action?liveName="+liveName+"&liveId="+id);	
}
function furl(id)
{
	window.top.art.dialog
	(
		{
			id:'furl',iframe:'/live_furls.html?id='+id, title:'转发流配置', width:'500', height:'350', lock:true
		},
		function(){
			var d = window.top.art.dialog({id:'furl'}).data.iframe;
			var form = d.document.getElementById('dosubmit');
			form.click();			
			return false;			
			}, 
		function()
		{
			window.top.art.dialog({id:'furl'}).close()
		}
	);void(0);	

}

function extra(id)
{
	window.top.art.dialog
	(
		{
			id:'extra',iframe:'/admin/live/extra/updatePLiveExtraInfo.action?liveId='+id, title:'直播简介', width:'800', height:'350', lock:true
		},
		function(){
			var d = window.top.art.dialog({id:'extra'}).data.iframe;
			var form = d.document.getElementById('dosubmit');
			form.click();			
			return false;			
			}, 
		function()
		{
			window.top.art.dialog({id:'extra'}).close()
		}
	);void(0);

}

/**
 * 每3秒一次进行所有直播频道的码率的刷新
 * @return
 */
function refreshStream()
{
	do_refresh_stream()
	
	setInterval(function()
	{
		do_refresh_stream()
		
	},3000)	
			
}
/**
 * 刷新码率的实现方法
 * @return
 */
function do_refresh_stream()
{
	$.ajax({
	 	 type: "post",
	 	 url: "handle/action/live.php",
	 	 data:{action:'refresh_stream'},			  
		  //处理CGI返回的JSON数据
		  success: function(data)
		  {	
			  if(data != "")
			  {
				var obj = $.parseJSON(data);
				if(obj == null)
					return ;
				var size = obj.length;
				for(var i=0;i<size;i++)
				{
					var liveId = obj[i].id;
					var appName = obj[i].appName;
					var liveName = obj[i].liveName.replace("/","_");
					var bitRate = obj[i].bitRate;					
					var name = appName+"_"+liveName
					$("#stream_"+name).html(bitRate+"kb");
					
				}
			  }			  
		  }
	  })
}


function create_all_show()
{
	//var rtmp_ip = $("#rtmp_ip").val();
	var rtmp_ip = window.location.hostname;
	var rtmp_port = $("#rtmp_port").val();
	
	var flag = $("#selector").attr("checked");
	if(flag)
	{
		$("#main_body :checkbox").each(function(i){
			var id = $(this).attr("id");
			var alias = $(this).attr("name");
			$(this).attr("checked","checked");
			var url = "rtmp://"+rtmp_ip+":"+rtmp_port+"/"+alias;
			build_dom(url,id,alias);
		})
	}
	else
	{
		$("#main_body :checkbox").each(function(i){
			var id = $(this).attr("id");
			$(this).removeAttr("checked");			
			$("#outer"+id).remove();
		})
	
	}

}

function show_pre(id,alias)
{
	//var rtmp_ip = $("#rtmp_ip").val();
	var rtmp_ip = window.location.hostname;
	var rtmp_port = $("#rtmp_port").val();
	
	var flag = $("#box"+id).attr("checked");
	if(flag)
	{
		var url = "rtmp://"+rtmp_ip+":"+rtmp_port+"/"+alias;
		build_dom(url,id,alias);
		
		setTimeout(function(){
			$("#box"+id).attr("checked","true")
			},100)
			
	}
	else
	{
		$("#outer"+id).remove();

		setTimeout(function(){
			$("#box"+id).removeAttr("checked")
			},100)
	}
	
	
}
function ts_hls_oper(ts_enable,hls_enable,fw_enable)
{
	/*
	var ts_enable = '${beanLic.supportTS}';
	var hls_enable = '${beanLic.supportHLS}';
	var fw_enable = '${beanLic.supportRtmpFW}';
	*/
	if(ts_enable == "true")
	{
		$("div[name='ts_oper']").css("display","inline");
	}
	if(hls_enable == "true")
	{
		$("div[name='hls_oper']").css("display","inline");
	}
	if(fw_enable == "true")
	{
		$("div[name='fw_oper']").css("display","inline");
	}
}


function build_whole_page(channel_type)
{
	if(channel_type == undefined)
	{
		channel_type = 0;
	}
	window.top.art.dialog({id:"wait",content:"正在构建页面中...<img width=20 src='images/loading.gif'>"});
	$("#main_body").empty();
	$.ajax({
		type:"POST",
		url:"handle/action/live.php",
		sync:false,
		data:{"action":"list","channel_type":channel_type},
		success:function(data)
		{
			var obj = null;
			try
			{
				obj = $.parseJSON(data);
			}
			catch(e)
			{
				window.top.art.dialog({id:"mesg",content:"获取数据失败!",time:1});
				window.top.art.dialog({id:"wait"}).close();
				return ;
			}

			for(var i=0;i<obj.length;i++)
			{
				var id = obj[i]['id'];
				var name = obj[i]['name'];
				var appName = obj[i]['appName'];
				var alias = obj[i]['alias'];
				var createdDate = obj[i]['createdDate'];
				var dataPath = obj[i]["dataPath"];
				var liveStatus = obj[i]["liveStatus"];
				var publishStatus = obj[i]["publishStatus"];
				var recordEnabled = obj[i]["recordEnabled"];
				var recordStatus = obj[i]["recordStatus"];
				var recordType = obj[i]["recordType"];
				var right = obj[i]["right"];
				var enableHLS = obj[i]["enableHLS"];
				var enableTS = obj[i]["enableTS"];
				var tsAddress = obj[i]["tsAddress"];
				var format = obj[i]["format"];
				var tsStatus = obj[i]["tsStatus"];
				var hlsStatus = obj[i]["hlsStatus"];
				var push = obj[i]["push"];
				var lazyPull = obj[i]["lazyPull"];
				var recordAppend = obj[i]["recordAppend"];
				var flvKeyframe = obj[i]["flvKeyframe"];
				var playback = obj[i]["playback"];
				var keepPlaybackDays = obj[i]["keepPlaybackDays"];
				var liveProperty = obj[i]["liveProperty"];
				var ip = obj[i]["ip"];
				var type = obj[i]["type"];
				var outputMode = obj[i]["outputMode"];
				var intervalTime = obj[i]["intervalTime"];
				var timeToApend = obj[i]["timeToApend"];

				//获取转发流
				var forwardUrls = obj[i]["forwardUrls"];
				//获取子码流
				var outputs = obj[i]["outputs"];


				//初使用化流来源
				var stream_from = "";
				if(type == 0 && ip != "")
					stream_from = "流源:编码器"+ip+"";
				else if(type == 1)
					stream_from = "流源:拉流"+ip+"";
				else if(type == 2)
					stream_from = "流源:转码子流"+ip+"";
				else if(type == 3)
					stream_from = "流源:插播流"+ip+"";
				//初使化频道类型
				var live_channel_type = "";

				if(right == 1 || right ==0)
					live_channel_type = "普通直播";
				else if(right == 3)
					live_channel_type = "回播模式";
				else if(right == 4)
					live_channel_type = "轮播模式";
				else if(right == 5)
					live_channel_type = "导播模式";
				//初使化录像方式
				var record_type = "";
				if(recordType == 0)
					record_type = "手动";
				else if(recordType ==1)
					record_type = "定时";
				else if(recordType ==2)
					record_type = "有流则录像";
				//初使化正在直播图片显示状态
				var live_status = "";
				if(liveStatus)
					live_status = '<img src="images/icons/live.gif" title="正在直播">&nbsp';
				else
					live_status = '<img src="images/icons/live.png" title="未直播状态">&nbsp';
				//初使化录像图片显示状态
				var record_status = "";
				if(recordStatus)
					record_status = '<img src="images/icons/record.gif" title="正在录像">&nbsp';
				else
					record_status = '<img src="images/icons/record.png" title="未录像">&nbsp';
				//初使化正在转发流图片显示状态以及正在转发流的列表
				var forward_urls = "";
				var forward_status = "";
				if(forwardUrls != null)
				{
					for(var j=0;j<forwardUrls.length;j++)
					{
						var status = forwardUrls[j]["status"];
						var furl = forwardUrls[j]["url"];
						if(status == true)
						{
							forward_urls+=furl;
							forward_urls+="&nbsp;&nbsp;";
						}
					}
				}
				if(forward_urls != "")
					forward_status = '<img src="images/icons/stream.gif" title="正在转发流:'+forward_urls+'">&nbsp';
				else
					forward_status = '<img src="images/icons/stream.png" title="未转发流">&nbsp';

				//初使化TS图片显示状态
				var ts_status = "";
				if(tsStatus)
					ts_status = '<img src="images/icons/ts.gif" title="TS正在发流:'+tsAddress+'">&nbsp';
				else
					ts_status = '<img src="images/icons/ts.png" title="TS未发流">&nbsp';
				//初使化HLS图片显示状态
				var hls_status = "";
				if(hlsStatus)
					hls_status = '<img src="images/icons/hls.gif" title="HLS正在发流">&nbsp';
				else
					hls_status = '<img src="images/icons/hls.png" title="HLS未发流">&nbsp';

				//初使化定录功能
				var time_config = "";
				//在直播频道模式为 回播,轮播时不启用定录功能
				//录像方式设置为手动录像,有流即录像时不启用定录功能
				if(right != 3 & right != 4 && recordType != 2 && recordType != 0)
				{
					time_config = '<a href="javascript:;" onclick="timeConfig('+id+')"  class="ext_btn ext_btn_submit ext_btn_size" title="定时录像">定录</a>&nbsp';
				}

				//初使化轮播功能
				var while_play = "";
				if(right == 4)
					while_play = '<a href="javascript:;" onclick="whilePlay('+id+')" class="ext_btn ext_btn_submit ext_btn_size" title="轮播(虚拟直播)">轮播</a>&nbsp';
				//初使化导播功能
				var guid_play = "";
				if(right == 5)
					guid_play = '<a href="/live_guid_play.html?id='+id+'" target="_blank"  class="ext_btn ext_btn_submit ext_btn_size" title="导播">导播</a>&nbsp';

				//初使化停录和开录按钮功能
				var record_button = "";
				//liveProperty 为1时候，允许推流，不允许发布，不允许录像；为3时候，不允许推流，不允许发布，不允许录像
				if(liveProperty !=1 && liveProperty != 3 && recordEnabled)
				{
					// 直播组为访谈,回播,轮播,定时时,录像按钮不能使用
					if(right != 3 && right != 4 && recordType!=1)
					{
						if(recordStatus)
							record_button = '<a href="handle/action/live.php?action=stop_record&id='+id+'" class="ext_btn ext_btn_submit ext_btn_size">停录</a>&nbsp';
						else
							record_button = '<a href="handle/action/live.php?action=start_record&id='+id+'" class="ext_btn ext_btn_submit ext_btn_size">开录</a>&nbsp'
					}
				}
				//初使化TS开关按钮
				var ts_button = "";
				if(tsStatus)
					ts_button = '<a href="handle/action/live.php?action=pro_status&id='+id+'&type=ts&status=close" class="ext_btn ext_btn_submit ext_btn_size">TS关</a>&nbsp';
				else
					ts_button = '<a href="handle/action/live.php?action=pro_status&id='+id+'&type=ts&status=open" class="ext_btn ext_btn_submit ext_btn_size">TS开</a>&nbsp';
				//初使化HLS开关按钮
				var hls_button = "";
				if(hlsStatus)
					hls_button = '<a href="handle/action/live.php?action=pro_status&id='+id+'&type=hls&status=close" class="ext_btn ext_btn_submit ext_btn_size">HLS关</a>&nbsp';
				else
					hls_button = '<a href="handle/action/live.php?action=pro_status&id='+id+'&type=hls&status=open" class="ext_btn ext_btn_submit ext_btn_size">HLS开</a>&nbsp';

				//初使化断流发流开关按钮
				var liveproperty_button = "";
				if(liveProperty == 0)
					liveproperty_button = '<a href="handle/action/live.php?action=edit_publish&liveProperty=1&id='+id+'" class="ext_btn ext_btn_submit ext_btn_size">断流</a>&nbsp';
				else
					liveproperty_button = '<a href="handle/action/live.php?action=edit_publish&liveProperty=0&id='+id+'" class="ext_btn ext_btn_submit ext_btn_size">发流</a>&nbsp';

				//初使化是否含有子码流
				var sub_stream = "";
				if(outputs != null)
				{
					for(var jj=0;jj<outputs.length;jj++)
					{
						var width = outputs[jj]["width"];
						var height = outputs[jj]["height"];
						var frameRate = outputs[jj]["frameRate"];
						var bitRate = outputs[jj]["bitRate"];
						var sub_stream_name =  outputs[jj]["name"];
						var sub_stream_liveStatus = outputs[jj]["liveStatus"];

						var substream_create_type = "";
						var substream_live_status = "";
						if(outputMode == 0)
						{
							substream_create_type = "类型:推方式&nbsp;......";
						}
						else
						{
							substream_create_type = '类型:拉方式&nbsp;width:'+width+';height:'+height+';frameRate:'+frameRate+';bitRate:'+bitRate+'';
						}
						if(sub_stream_liveStatus)
							substream_live_status = '<img src="images/icons/live.gif" title="正在直播">&nbsp';
						else
							substream_live_status = '<img src="images/icons/live.png" title="未直播状态">&nbsp';

						sub_stream+='<tr height="16" id="40" >';
						sub_stream+='<td  align="center">';
						sub_stream+='<input title="'+sub_stream_liveStatus+'" value="'+id+'" type="checkbox" name="'+appName+'/'+name+'/'+sub_stream_name+'" id="box'+(i+1)+'_'+(jj+1)+'" onclick="show_pre(\''+(i+1)+'_'+(jj+1)+'\',\''+appName+'/'+name+'/'+sub_stream_name+'\')"/>';
						sub_stream+='</td>';
						sub_stream+='<td  align="left">	';
						sub_stream+='<div style="float: left;">';
						sub_stream+='└────';
						sub_stream+='</div>';
						sub_stream+='<div style="float: left;margin-left: 10px; color:#000;">';
						sub_stream+='<p style="text-align: left;color: #145FA8;overflow:hidden; ">'+appName+'/'+name+'/'+sub_stream_name+'';
						sub_stream+='</p>';
						sub_stream+='</div>';
						sub_stream+='</td>';
						sub_stream+='<td  align="center">';
						sub_stream+='<p style="text-align: left;">码流大小:<span id="stream_'+appName+'_'+name+'_'+sub_stream_name+'">...</span></p>';
						sub_stream+='</td>';
						sub_stream+='<td  align="left" colspan="2">';
						sub_stream+=''+substream_live_status+'';
						sub_stream+=''+substream_create_type+'';
						sub_stream+='</td>';
						sub_stream+='<td  align="left">';
						sub_stream+='<a target="_blank" href="/play_live.html?id='+id+'&substream='+sub_stream_name+'&right='+right+'" id="show" title="电脑观看" class="ext_btn ext_btn_submit ext_btn_size">电脑</a>';
						sub_stream+='<a  href="javascript:;" onclick="mobilePlay('+id+')" title="移动观看" class="ext_btn ext_btn_submit ext_btn_size">手机</a>';
						sub_stream+='<td  align="left">';
						sub_stream+='<a href="javascript:;" onclick="delSubStream(\''+id+'\',\''+sub_stream_name+'\')" title="删除" class="sp_a_but_cir sp_a_but_padding btn btn-danger">删除</a>';
						sub_stream+='</td>';
						sub_stream+='</tr>';

					}
				}

				//整个dom构建数
				var dom = '<tr>';
				dom+= '<td align="center">';
				dom+= '<input  title="'+liveStatus+'" value="'+id+'" type="checkbox" name="'+appName+'/'+name+'" id="box'+(i+1)+'" onclick="show_pre('+(i+1)+',\''+appName+'/'+name+'\')"/>';
				dom+= '</td>';
				dom+= '<td  align="center">';
				dom+= '<div style="float: left;">';
				dom+= '<img src="images/live_icon.png" width="50px" height="50px"  />';
				dom+= '</div>';
				dom+= '<div style="float: left;margin-left: 10px; color:#000;">';
				dom+= '<p style="text-align: left;color: #145FA8;overflow:hidden; ">'+appName+'/'+name+'</p>';
				dom+= '<p style="text-align: left;">别名:'+alias+'</p>';
				dom+= '<p style="text-align: left;">'+stream_from+'</p>';
				dom+= '<td align="left">';
				dom+= '<p style="text-align: left;">频道类型:'+live_channel_type+'</p>';
				dom+= '<p style="text-align: left;">录像方式:'+record_type+'</p>';
				dom+= '<p style="text-align: left;">码流大小:<span id="stream_'+appName+'_'+name+'">...</span></p>	';
				dom+= '</td>';
				dom+= '<td  align="left">';
				dom+= ''+live_status+'';
				dom+= ''+record_status+'';
				dom+= ''+forward_status+'';
				dom+= '<div name="ts_oper" style="display:none">';
				dom+= ''+ts_status+'';
				dom+= '</div>';
				dom+= '<div name="hls_oper" style="display:none">';
				dom+= ''+hls_status+'';
				dom+= '</div>';
				dom+= '</td>';
				dom+= '<td  align="left">';
				dom+= ''+time_config+'';
				dom+= '<div name="fw_oper" style="display:none">';
				dom+= '<a href="javascript:;" onclick="furl('+id+')" class="ext_btn ext_btn_submit ext_btn_size" title="转发流">转流</a>&nbsp';
				dom+= '</div>';
				dom+= '<a href="javascript:;" onclick="addSubStream('+id+')" class="ext_btn ext_btn_submit ext_btn_size" title="添加子码流">子流</a>&nbsp';
				dom+= '<a href="javascript:;" onclick="liveReplace('+id+')" class="ext_btn ext_btn_submit ext_btn_size" title="直播插播">插播</a>&nbsp';
				dom+= ''+while_play+'';
				dom+= ''+guid_play+'';
				dom+= '</td>';
				dom+= '<td  align="left">';
				dom+= '<a target="_blank" href="/play_live.html?id='+id+'&right='+right+'" id="show" title="电脑观看" class="ext_btn ext_btn_submit ext_btn_size">电脑</a>&nbsp';
				dom+= '<a  href="javascript:;" onclick="mobilePlay('+id+')" title="移动观看" class="ext_btn ext_btn_submit ext_btn_size" title="移动设备观看">手机</a>&nbsp';
				dom+= '</td>';
				dom+= '<td  align="left">';
				dom+= '<a href="javascript:;" onclick="delDialog('+id+',\''+appName+'\')" title="删除" class="ext_btn_red ext_btn_size">删除</a>&nbsp';
				dom+= '<a href="javascript:;" onclick="editDialog('+id+')" id="edit" title="编辑" class="ext_btn ext_btn_submit ext_btn_size">编辑</a>&nbsp';
				dom+= ''+record_button+'';
				dom+= '<div name="ts_oper" style="display:none">';
				dom+= ''+ts_button+'';
				dom+= '</div>';
				dom+= '<div name="hls_oper" style="display:none">';
				dom+= ''+hls_button+'';
				dom+= '</div>';
				dom+= ''+liveproperty_button+'';
				dom+= '</td>';
				dom+= '</tr>';
				dom+= ''+sub_stream+'';



				$("#main_body").append(dom);


			}

		}

	})

	setTimeout(function(){
		init_license();
	},300)
}


function change_live_type(type)
{
	$("#change_live a").each(function(){
			$(this).removeClass("on");
	})

	$("#change_live a").each(function(){

		if(parseInt($(this).attr("type")) == type)
		{
			$(this).addClass("on");
		}
	})


	build_whole_page(type);
}



function generateAPK()
{
	window.top.art.dialog
	(
		{
			id:'apk',iframe:'/admin/live/generateAPK.jsp', title:'机顶盒APK生成', width:'650', height:'120', lock:true
		},
		function(){
			var d = window.top.art.dialog({id:'apk'}).data.iframe;
			var form = d.document.getElementById('dosubmit');
			form.click();			
			return false;			
			}, 
		function()
		{
			window.top.art.dialog({id:'apk'}).close()
		}
	);void(0);
}

function build_dom(url,id,alias)
{
	var whole_url = "&src="+url+"&autoHideControlBar=true&streamType=live&autoPlay=true";
	var width = 180;
	var height = 180;
	//构建页面  dom
	var outer = "<div id='outer"+id+"' style='float:left;margin-left:15px;width:180px;height:200px;'></div>";
	
	var flashDom = "<object width='"+width+"' height='"+height+"' id='StrobeMediaPlayback'";
		flashDom+= "name='StrobeMediaPlayback' type='application/x-shockwave-flash'";
		flashDom+= "classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'>";
		flashDom+= "<param name='movie' value='StrobeMediaPlayback.swf' />";
		flashDom+= "<param name='quality' value='high' />";
		flashDom+= "<param name='bgcolor' value='#000000' />";
		flashDom+= "<param name='allowfullscreen' value='true' />";
		flashDom+= "<param name='flashvars' id='ieval' value='"+whole_url+"' />";
		flashDom+= "<embed src='StrobeMediaPlayback.swf' width='"+width+"'";
		flashDom+= "height='"+height+"' id='StrobeMediaPlayback' quality='high'";
		flashDom+= "bgcolor='#000000' name='StrobeMediaPlayback' allowfullscreen='true'";
		flashDom+= "pluginspage='http://www.adobe.com/go/getflashplayer' flashvars='"+whole_url+"'>";
		flashDom+= "</embed>";
		flashDom+= "</object>";	
				
	var alias = "<div style='color:#ff0235;text-align: center'>"+alias+"</div>"
		
	$("#preshow").append(outer);	
	$("#outer"+id).append(flashDom);
	$("#outer"+id).append(alias);

}
/**
 * 将端口号和IP地址存放程序自己在页面上对应的id为rtmp_port  rtmp_ip的 input隐藏域中
 * 用于播放RTMP流时使用,所以ip是外网IP
 * @return
 */
function create_rtmp_host()
{
	$.ajax({
		  type: "POST",
		  url: "/handle/action/live.php",
		  data:{action:'ip_port'},  
		 //处理CGI返回的JSON数据
		 success: function(data)
		 {
			var obj = $.parseJSON(data);
			var ip = obj.ip;
			var port = obj.port;
			var dom = "<input type='hidden' id='rtmp_ip' value="+ip+">";
				dom+="<input type='hidden' id='rtmp_port' value="+port+" >";
			$("body").append(dom);
		 }
	  });
}


