
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 ts_hls_oper()
{
	$.ajax({
		type:"POST",
		//url:"handle/action/live.php",
		url:"/admin/GetLicenseInfo",
		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 select_take(v)
{
	if(v == "true")
	{
		$("#take_body").css("display","")
	}
	else
	{
		$("#take_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 record_type(val)
{
	if(val == "time")//时间
	{
		$("#intervalTime").val();
		$("#splitFileSize").val("0");
		$("#time_type").show();
		$("#much_type").hide();
	}
	else//大小
	{
		$("#splitFileSize").val();
		$("#intervalTime").val("0");
		$("#much_type").show();
		$("#time_type").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();
}
