function $showmov(v)
{
	return document.getElementById(v);
}
function ajax(url) 
{ 
	var showmov = null; 
	if ( window.XMLHttpRequest )
	{
		showmov = new XMLHttpRequest();
	}else{
		showmov = new ActiveXObject("Msxml2.XMLHTTP");
	}
	showmov.open("GET",url,false);
	showmov.send(null);
	if(showmov.readyState == 4 && showmov.status == 200){
		return showmov.responseText;
	}else{
		alert(showmov.status)
		return false;
	}
	delete(showmov);
}
function in_array(string, findstr)
{
	var i;
	arraydata = string.split(",");
	for(i=0;i<arraydata.length;i++)
	{
		if (arraydata[i] == findstr)
		{
			return true
		}
	}
	return false;
}
function CheckSel(Voption,Value)
{
	var obj = document.getElementById(Voption);
	for (i=0;i<obj.length;i++){
		if (obj.options[i].value==Value){
		obj.options[i].selected=true;
		break;
		}
	}
}
function chkradio(Obj,Val)
{
	if (Obj)
	{
	for (i=0;i<Obj.length;i++){
		if (Obj[i].value==Val){
		Obj[i].checked=true;
		break;
		}
	}
	}
}


function CheckAll(v,tag)
{
	/*
	控制 checkbox全选或者方选
	*/
	checkbox=document.getElementsByName(tag);
	for(i=0;i<checkbox.length;i++){
		checkbox[i].checked=v
	}
}

  /* 
   * 检测CHECKBOX是否有一个被选中
   * 参数 ename 为CHECKBOX名称
   * 返回：有选中对象就返回true，反之返回false
   */
function checkselect(ename){
 n = document.getElementsByName(ename);
 for(i = 0; i < n.length; i++){
   if(n[i].checked){
	return true;
   }
 }
 return false;
}
function delconfirm(txt)
{
	if(txt == undefined)
	{
		txt="确定要删除吗";	
	}
	if(confirm(txt))
	{
		return true;	
	}
	return false;
}
function classOption(parentid, position, lable , name)
{
	if (typeof(name) == 'undefined')
	{
		name = 'classid';
	}
	var position = position ? parseInt(position) : parseInt(0);
	var data = ajax("?mod=class.ajax&action=getResult&parentid="+parentid);
	var obj = document.getElementById('class');
	var objs = obj.getElementsByTagName("DIV");
	var html = '';
	var array = data.split("\n");
	var tmp = '';
	var i =0;
	while(objs.length > position)
	{
		obj.removeChild(obj.lastChild)
		i++;
	}
	if (parentid == '')
	{
		return false;
	}
	if (data){
		
		html = '<select name="'+name+'" onchange="classOption(this.value,'+(position+1)+',\''+lable+'\')">';
		html = html + '<option value="">请选择分类</option>';
		for (key in array)
		{
			tmp = array[key].split("=");
			if( in_array( lable, tmp[1]) == true ){
				html = html + '<option value="'+tmp[1]+'" selected="selected" >'+tmp[0]+'</option>';
			}else{
				html = html + '<option value="'+tmp[1]+'">'+tmp[0]+'</option>';
			}
		}
		html = html + '</select>';
		var div = document.createElement("DIV");
		div.className = 'selectop'
		div.innerHTML = html;
		obj.appendChild(div);
	}
}
function initialize(classid, node , lable, name)
{
	if (typeof(name) == 'undefined')
	{
		name = 'classid';
	}
	var string = ajax("?mod=class.ajax&action=getParent&classid="+classid);
	var array = string.split(",");
	for(key in array){
		classOption(array[key], key, string, name);
	}
	
}
function addClass(name)
{
	var obj = document.getElementById('class').getElementsByTagName('SELECT');
	var newobj = document.getElementById('data');
	var classid = obj[obj.length-1].value;
	if ( classid == 0){
		alert('请选择子类!');
		return false;
	}
	var pstring = ajax("?mod=class.ajax&action=getitle&classid="+classid);
	var text = '<div style="float:left; clear:left"><div style="float:left">'+pstring+'</div><div>&nbsp;&nbsp;<a href="#" onclick="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);return false">移除</a><input type="hidden" name="classid[]" value="'+classid+'" /></div></div>';
	var objs = newobj.getElementsByTagName("INPUT");
	if (objs.length>=3)
	{
		return false;
	}
	for(i=0;i<objs.length;i++)
	{
		if ( parseInt(objs[i].value) == parseInt(classid))
		{
			return false;
		}
	}
	newobj.innerHTML = newobj.innerHTML + text;
}
function addServer()
{	
	var objs = $showmov('serverid');
	var text = objs.options[objs.selectedIndex].text;
	var sid = objs.value;
	var html = '';
	if(typeof($showmov('server_content').getElementsByTagName) != 'undefined'){
		var obj = $showmov('server_content').getElementsByTagName('INPUT');
		for(i=0;i<obj.length;i++)
		{
			if( parseInt(obj[i].value) == parseInt(sid))
			{
				return false;
			}
		}
	}
	html = '<div style="float:left; width:auto;clear:left; color:red;"><div style="float:left">'+text+'</div><div style="float:left">&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);return false">移除</a><input type="hidden" name="server[]" value="'+sid+'" </div></div>';
	$showmov('server_content').innerHTML = $showmov('server_content').innerHTML + html;
	
}
function makeAddress()
{
	//var obj = $showmov('divpatch');
	var obj = $showmov('urladdress');
	var start = parseInt($showmov('start').value);
	var end = parseInt($showmov('end').value);
	var ext = $showmov('ext').value;
	var prefix = $showmov('prefix').value;
	var alt = '';
	var html = '';
	for(i=start;i<=end;i++)
	{
		if (end>3)
		{
			if (i<10){
				alt = '0'+i;
				filename = prefix+'0'+i+ext;
			}else{
				alt = i;
				filename = prefix+i+ext;
			}
		}else{
			filename = prefix+i+ext;
		}
		if (end<=3)
		{
			if (i ==1 )
			{
				alt = "A";
			}
			if (i == 2)
			{
				alt = "B";
			}
			if ( i == 3 )
			{
				alt = "C";
			}
		}
		html = html + '<div style="float:left; width:650px;padding-bottom:3px;"><input name="url[]" type="text" id="textfield" size="30" value="'+filename+'" />';
		html = html + '标题\n<input name="alt[]" type="text" id="label" size="8" value="'+alt+'"  />';
		html = html + '排序\n<input name="sort[]" type="text" id="label20" size="4" value="'+i+'"  />';
		html = html + '备用参数\n<input name="parmes[]" type="text" id="label21" size="5" />&nbsp;<a href="#" onclick="this.parentNode.parentNode.removeChild(this.parentNode);return false">移出</a></div>';

	}
	obj.innerHTML = html;
}
function addmovie()
{
	if ($showmov('title').value == '' )
	{
		alert('请填写影片名称!');
		$showmov('title').focus();
		return false;
	}
	if (document.getElementsByName('classid[]').length>0){
		if ( isnull_array('classid[]')===false )
		{
			alert('请选择分类后点添加分类!');
			$showmov('addclass').focus();
			return false;
		}
	}
	if (checkselect('player[]') === false)
	{
		alert('必须选择一个播放器!');
		return false;
	}
	if (isnull_array('server[]') === false)
	{
		alert('必须选择一个服务器!');
		return false;
	}
	if ( typeof($showmov('mode1')) =='null')
	{
		if (document.form2.url.value == '')
		{
			alert('请填写节目路径信息');
			document.form2.url.focus();
			return false;
		}
	}else if ($showmov('mode1').checked == true){
		if ( isnull_array('url[]') === false )
		{
			alert('您还没有生成点播路径名!\n请填写好路径信息后点地址生成!');
			return false;
		}
	}else{
		if (document.form2.url.value == '')
		{
			alert('请填写节目路径信息');
			document.form2.url.focus();
			return false;
		}
	}
	return true;
}
function isnull_array(name)
{
	var obj = document.getElementsByName(name);
	for(i=0;i<obj.length;i++)
	{
		if (obj[i].value)
		{
			return true;
		}
	}
	return false;
}
function delurl(urlid, movid)
{
	ajax('?mod=remove&action=del&act=url&urlid='+urlid+'&movid='+movid);
}
function removie(movid,obj)
{
	ajax('?mod=remove&action=del&act=movie&movid='+movid);
	obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
	
}
function removeuser(uid,obj)
{
	if( confirm('确认删除会员资料吗?') ==true){
		ajax('?mod=remove&action=del&act=members&uid='+uid);
		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
		return true;
	}else{
		return false;
	}
	
}
function trClick(obj)
{
	var nobj = obj.getElementsByTagName('input');
	var cname = obj.className;
	//nobj[i].checked = true;
	
	if ( cname.indexOf('trclick')!=-1 )
	{
		obj.className = cname.replace('trclick ','');
		for(i=0;i<nobj.length;i++)
		{
			nobj[i].checked = false;
		}
	}else{
		cname = cname.replace('trclick ','');
		obj.className = 'trclick ' +cname ;
		for(i=0;i<nobj.length;i++)
		{
			nobj[i].checked = true;
		}
	}
}
function tr_hover(obj)
{
	var cname = obj.className;
	cname = cname.replace(' td_visited','');
	cname = cname.replace(' td_hover','');
	obj.className = cname + ' td_hover';
}
function tr_visited(obj)
{
	var cname = obj.className;
	cname = cname.replace(' td_visited','');
	cname = cname.replace(' td_hover','');
	obj.className = cname.replace(' td_hover','')+ ' td_visited';
}
function changeMode(value)
{
	if (value == 1)
	{
		$showmov('makeurl').style.display = 'none';
		$showmov('urladdress').innerHTML = '<textarea name="url" cols="70" style=" height:200px;"></textarea>';
	}else{
			$showmov('makeurl').style.display = 'block';
			$showmov('urladdress').innerHTML = '';
	}
}
function showMenu(o)
{
	var obj = o.parentNode.parentNode.parentNode.parentNode;
	if (obj.childNodes[1].style.display == 'none'){
		obj.childNodes[1].style.display = 'block';
		o.innerHTML = '<font color="red">收缩子菜单</font>';
	}else{
		obj.childNodes[1].style.display = 'none';
		o.innerHTML = '<font color="red">展开子菜单</font>';
	}
}
function checkPer(obj)
{
	var result = obj.checked;
	var op = obj.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('input');
	for(i= 0; i<op.length ; i ++)
	{
		op[i].checked = result;
	}
}
function manageView(obj, selectview)
{
	
	var op = obj.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('input');
	var pobj = obj.parentNode.getElementsByTagName('input');
	var result = false;
	if (selectview == true)
	{
		
		var check = true;
		if (obj.checked == true){
			pobj[0].checked = check;
		}
	}
	for(i=1; i<op.length ; i ++)
	{
		if (op[i].checked == true)
		{
			result = true;
			break;
		}
	}
	op[0].checked = result;
	for(i = 1 ; i<pobj.length; i ++)
	{
		if (pobj[i].checked == true)
		{
			pobj[0].checked = true;
			return true;
		}
	}
	
}
function checkplayer()
{
	if ($showmov('title').value == '')
	{
		alert('请填写标题信息!');
		$showmov('title').focus();
		return false;
	}
	if ($showmov('tag').value == '')
	{
		alert('请填写唯一调用标记!');
		$showmov('tag').focus();
		return false;
	}
	if ($showmov('player').value == '')
	{
		alert('请填写播放器代码!');
		$showmov('player').focus();
		return false;
	}
	return true;
}