
function check()
{
	var com_str = /\w+/;	
	var rtmp = /rtmp:\/\/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[a-zA-Z:\/]+/;
	var ts_reg = /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[:][0-9]+/;
	var num = /^\+?[1-9][0-9]*$/;　　//正整数 
	
	var appName = $("#appName").val();
	var liveName = $("#liveName").val();
	var alias = $("#alias").val();
	var isPush = $("#isPush").val();

	var url = $("#url").val()
	var width = $("#width").val()
	var height = $("#height").val()
	var frameRate = $("#frameRate").val()
	var samplingRate = $("#sampleRate").val()
	var vbitRate = $("#vBitRate").val()
	var abitRate = $("#aBitRate").val()
	var ts = $("#ts").val();
	var playbackDays = $("#keepPlaybackDays").val();
	var dataPath = $("#dataPath").val();
	
	if(!com_str.test(appName))
	{
		window.top.art.dialog({id:'dg_test34243', content:'应用名称格式错误,不允许有空格,内容为英文与数字组合!',time:1});		
		return false;
	}
	else if(!com_str.test(liveName))
	{
		window.top.art.dialog({id:'dg_test34243', content:'流名称格式错误,不允许有空格,内容为英文与数字组合!',time:1});		
		return false;
	}
	else if(alias == "")
	{
		window.top.art.dialog({id:'dg_test34243', content:'别名不能为空!',time:1});		
		return false;
	}
	
	if(ts == "1")
	{
		var tsAddress = $("#tsAddress").val();
		if(!ts_reg.test(tsAddress))
		{
			 window.top.art.dialog({id:'dg_test34243', content:'ts地址不正确!',time:1});		
			return false;
		}
	}
	
	if(!num.test(playbackDays))
	{
		window.top.art.dialog({id:'dg_test34243', content:'回播天数不正确!',time:1});		
		return false;
	}

	if(isPush == "false")
	{
		if(url == "")
		{
			window.top.art.dialog({id:'dg_test34243', content:'拉流URL不正确!',time:1});		
			return false;
		}
		if(!num.test(width) || !num.test(height))
		{
			window.top.art.dialog({id:'dg_test34243', content:'分辨率不正确!',time:1});		
			return false;
		}
		if(!num.test(width) || !num.test(height))
		{
			window.top.art.dialog({id:'dg_test34243', content:'分辨率不正确!',time:1});		
			return false;
		}
		if(!num.test(frameRate))
		{
			window.top.art.dialog({id:'dg_test34243', content:'帧率不正确!',time:1});		
			return false;
		}
		if(!num.test(samplingRate))
		{
			window.top.art.dialog({id:'dg_test34243', content:'采样率不正确!',time:1});		
			return false;
		}
		if(!num.test(vbitRate))
		{
			window.top.art.dialog({id:'dg_test34243', content:'视频比特率不正确!',time:1});		
			return false;
		}
		if(!num.test(abitRate))
		{
			window.top.art.dialog({id:'dg_test34243', content:'音频比特率不正确!',time:1});		
			return false;
		}
	}
	
	var autoCategory = $("#autoCategory").val(); 
	var recordName = $("#recordName").val();
	
	
	if(dataPath == "")
	{
		window.top.art.dialog({id:'dg_test34243', content:'录像存放路径不能为空!',time:1});		
		return false;
	}
	return true;
}
function init_edit_val(id)
{
	$.ajax({
		type:"POST",
		url:"handle/action/live.php",
		sync:false,
		data:{"action":"pre_edit","id":id},
		success:function(data)
		{

			var obj = null;
			try
			{
				obj = $.parseJSON(data);
			}
			catch(e)
			{
				window.top.art.dialog({id:"mesg",content:"获取数据失败!",time:1});
				return ;
			}


			//基本配置
			$("#appName").val(obj.appName);
			$("#liveName").val(obj.name);
			$("#alias").val(obj.alias);
			$("#right").val(obj.right);
			$("#dataPath").val(obj.dataPath.replace("\\","/"));

			//高级配置
			$("#outputMode").val(obj.outputMode);// 子码流模式  0推模式 1 拉模式
			$("#keepPlaybackDays").val(obj.keepPlaybackDays);
			$("#liveProperty").val(obj.liveProperty);

			var isPush = obj.push;
			$("#isPush").val(isPush+"");

			if(isPush)
				pull_select("true");
			else
				pull_select("false");

			$("#lazyPull").val(obj.lazyPull+"");

			$("#url").val(obj.pullStream.url)
			$("#vTransfer").val(obj.pullStream.vTransfer+"")
			$("#width").val(obj.pullStream.width)
			$("#height").val(obj.pullStream.height)
			$("#frameRate").val(obj.pullStream.frameRate)
			$("#vBitRate").val(obj.pullStream.vBitRate)
			$("#gop").val(obj.pullStream.gop)

			$("#aTransfer").val(obj.pullStream.aTransfer+"")
			$("#aBitRate").val(obj.pullStream.aBitRate)
			$("#sampleRate").val(obj.pullStream.sampleRate)

			choose_vtransfer(obj.pullStream.vTransfer+"");
			choose_atransfer(obj.pullStream.aTransfer+"");


			//ts & hls
			$("#enableTS").val(obj.enableTS+"")
			$("#enableHLS").val(obj.enableHLS+"")
			$("#tsAddress").val(obj.tsAddress)


			//录像相关
			$("#recordEnabled").val(obj.recordEnabled+"")
			$("#recordType").val(obj.recordType);

			var recordAppend = obj.recordAppend+"";
			$("#recordAppend").val(recordAppend);
			choose_record_type(recordAppend);

			$("#appendTime").val(obj.timeToApend);
			$("#intervalTime").val(obj.intervalTime);

			var format = obj.format
			if(format == "flv")
				$("#format").val("flv");
			else
				$("#format").val("mp4");

			$("#flvKeyframe").val(obj.flvKeyframe)
		}

	})

}

function ts_hls_oper()
{
	$.ajax({
		type:"POST",
		url:"handle/action/live.php",
		sync:false,
		data:{"action":"license"},
		success:function(data)
		{
			var obj = null;
			try
			{
				obj = $.parseJSON(data);
			}
			catch(e)
			{
				return ;
			}

			var ts_enable = obj.supportTS;
			var hls_enable = obj.supportHLS;
			if(ts_enable == true)
			{
				$("#ts_oper").show();
			}

			if(hls_enable == true)
			{
				$("#hls_oper").show();
			}

		}

	})

}


/**
 * 直播定时选择开启或关闭的处理事件
 * @param val
 * @return
 */
function live_time_sel(val)
{
	if(val == "true")
	{
		$("#liveProperty option").each(function(){
			
			if($(this).attr("value") != "3" )
			{
				$(this).attr("disabled",true);
			}
			else
			{
				$(this).attr("selected",true);
			}
		})
	}
	else if(val == "false")
	{
		$("#liveProperty option").each(function(){
			$(this).attr("disabled",false);	
			$(this).attr("selected",false);
		})
	}
}


function do_create_live_cate(div_id,localams)
{
	$.ajax({
		  type: "POST",
		  url: "/admin/live/group/liveGroupJSONList.action",
		 // data:{action:'list'},		 
		  //处理CGI返回的JSON数据
		  success: function(data)
		  {	
			var select_begin = "<select id='right' name='right' class='select' ></select>"
			$("#"+div_id).append(select_begin);
			
			//解析JSON			
			var obj = $.parseJSON(data);				
			if(obj != null && obj.length>0)
			{
				//add the root category
				for(var i=0;i<obj.length;i++)
				{
					var id = obj[i].id;					
					var name = obj[i].name.replace(/[ ]/g,"&nbsp;");
					var moduleType = obj[i].moduleType;//  1. 普通直播   2. 访谈类型    3.回播模式   4.轮播 5.导播	
					
					var option = "<option value='"+id+"'>"+name+"</option>"
					if(moduleType == 2 || moduleType == 4 || moduleType == 5)
					{
						if(localams == "127.0.0.1")
							$("#right").append(option);
					}
					else
					{
						$("#right").append(option);
					}
				}
			}
			else
			{
				$("#right").append("<option value='0'>请先创建直播组</option>");
			}
		  }
	});	
}



function pull_select(v)
{
	if(v == "false")
	{
		$("#pull_body").css("display","")
	}
	else
	{
		$("#pull_body").hide();
	}
}
function auto_category(v)
{
	if(v == "false")
	{
		$("#auto_category_body").hide();
	}
	else
	{
		$("#auto_category_body").css("display","")
	}
}
function choose_record_type(val)
{
	if(val == "true")//追加
	{
		$("#appendTime").val("5");
		$("#append_time_outer").css("display","");
	}
	else//手动  在选择手动录像时要将 追加时间设置为 0
	{
		$("#appendTime").val("0");
		$("#append_time_outer").hide();
	}
}

function choose_vtransfer(val)
{
	if(val == "false")
		$("#vinfo").hide();
	else
		$("#vinfo").show();
}
function choose_atransfer(val)
{
	if(val == "false")
		$("#ainfo").hide();
	else
		$("#ainfo").show();
}
