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 Chanage(id, type, obj)
{
	var newobj,patten;
	newobj = document.getElementsByName('address');
	y = 1;
	for(i=0;i<newobj.length;i++)
	{	
		y++;
		newobj[i].parentNode.className = 'server_title_mid';
		
	}
	obj.parentNode.className = 'server_title_mid2';
	var src = $showmov('vodcms_player').src;
	if (type =='sid' )
	{
		patten = /\&sid\=(\d+)/;
	}else{
		patten = /\&player\=(\d+)/;
	}
	$showmov('vodcms_player').src = src.replace(patten,'')+'&'+type+'='+id;
}
function CheckComemnt()
{
	if ($showmov('content').value=='')
	{
		alert('Please input comments!')
		$showmov('content').focus();
		return false;
	}
	if ($showmov('content').value.lenght>250)
	{
		alert('Comments must be within 250 characters!')
		$showmov('content').focus();
		return false;
	}
	return true;
}
function delcomment(id,obj)
{
	var result = parseInt(ajax('?mod=comments&action=del&id='+id));
	if (result == 200)
	{
		alert('Deleted!');
		obj.parentNode.parentNode.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode.parentNode.parentNode)
	}else if (result == 400)
	{
		alert('failed to delete it! You might do not have permission to delete it.');
	}else{
		alert('Unknown error occured!')
	}
}
function checkpass(v)
{
	var h = $showmov(v).parentNode.parentNode;
	var o = h.getElementsByTagName("div");
	var obj = o[1];
	if (v == 'oldpass')
	{
		if ( $showmov(v).value == '' )
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>Please input the password!';
			$showmov('submit').disabled =true
			t = false
		}else{
			obj.style.display = 'none';
			$showmov('submit').disabled =false;
			t = true
		}
		if ( ajax("index.php?mod=register&action=ajax&pass="+$showmov(v).value)  != 200 )
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>Invalid password';
			$showmov('submit').disabled =true
			t = false
		}else{
			obj.style.display = 'none';
			$showmov('submit').disabled =false;
			t = true
		}
	}else if (v == 'pass1')
	{
		if ( $showmov(v).value == '' )
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>Please input new password!';
			$showmov('submit').disabled =true
			t = false
		}else if( $showmov(v).value.length < 6 ){
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>Your password must have six characters at least.!';
			$showmov('submit').disabled =true
			t = false
		}else{
			obj.style.display = 'none';
			$showmov('submit').disabled =false
			t = true
		}
	}else if (v == 'pass2')
	{
		//alert(checkpass('pass1'));
		if ( $showmov(v).value != $showmov('pass1').value )
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>The password you entered twice do not match!';
			$showmov('submit').disabled =true
			t = false
		}else{
			obj.style.display = 'none';
			$showmov('submit').disabled =false
			t =true
		}
		if ($showmov('pass1').value == '' )
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>Please enter a new password!';
			$showmov('submit').disabled =true
			t = false
		}
	}
	return t
}
function register(v)
{
	var h = $showmov(v).parentNode.parentNode;
	var o = h.getElementsByTagName("div");
	var obj = o[1];
	if (v == 'username')
	{
		if ($showmov(v).value == '' )
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left> Please enter username!';
			$showmov('submit').disabled =true;
			$showmov(v).className = 'on_input';
			return false
		}else{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_right.gif style=float:left> Valid username!';
			$showmov('submit').disabled = false;
		}
		if (ajax("index.php?mod=register&action=ajax&username="+$showmov(v).value) != 200 )
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>This username has been taken, please choose another one.';
			$showmov('submit').disabled =true;
			$showmov(v).className = 'on_input';
			return false
		}
		if ( ($showmov(v).value.length <5) || ($showmov(v).value.length>30) )
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>Username must have 6-29 characters.';
			$showmov('submit').disabled =true;
			$showmov(v).className = 'on_input';
			return false
		}
	}
	if (v == 'password')
	{
		if ($showmov(v).value == '' || $showmov(v).value.length < 5)
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>Password must have six characters at least.';
			$showmov('submit').disabled =true;
			$showmov(v).className = 'on_input';
			return false
		}else{
			obj.style.display = 'none';
			$showmov('submit').disabled = false
		}
	}
	if (v == 'returnpass')
	{
		if ($showmov(v).value == '' || $showmov(v).value.length < 5)
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>Please enter a password with six characters at least.';
			$showmov('submit').disabled =true;
			$showmov(v).className = 'on_input';
			return false
		}
		if ($showmov(v).value != $showmov('password').value)
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>Confirm password do not match!';
			$showmov('submit').disabled =true;
			$showmov(v).className = 'on_input';
			return false;
		}else{
			obj.style.display = 'none';
			$showmov('submit').disabled = false;
		}
	}
	if (v == 'email')
	{
		if( !isEmail($showmov(v).value) )
		{
			obj.style.display = 'block';
			obj.innerHTML = '<img src=images/check_error.gif style=float:left>Invalid email address!';
			$showmov('submit').disabled =true;
			$showmov(v).className = 'on_input';
			return false
		}else{
			obj.style.display = 'none';
			$showmov('submit').disabled = false;
			
		}
	}
	return true
}
function isEmail(strEmail) {
	if(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(strEmail))
	{
		return true
	}else{
		return false;
	}
}
function CheckRegister()
{
	var t = register('username');
	var t = register('password');
	var t = register('returnpass');
	var t = register('email');
	return t
}
function news(url)
{
	newWidnow(url, "news","width=420,height=500");
}
function OpenWindow0(openurl)
{
	//window.showModelessDialog(openurl,window,"status:false;dialogWidth:540px;dialogHeight:430px;edge:Raised; enter: Yes; help: No; resizable: Yes; status: No");
	var paramet = 'toolbar=no,width=628,height=422,location=no,status=no,scrollbars=no,menubar=no,resizable=yes';
	newWindow =parent.window.open(openurl,"vodcms",paramet);
	//newWindow.focus();
}
function OpenWindow1(openurl)
{
	//window.showModelessDialog(openurl,window,"status:false;dialogWidth:540px;dialogHeight:430px;edge:Raised; enter: Yes; help: No; resizable: Yes; status: No");
	var paramet = 'toolbar=no,width=844,height=714,location=no,status=no,scrollbars=no,menubar=no,resizable=yes';
	newWindow =parent.window.open(openurl,"vodcms",paramet);
	//newWindow.focus();
}

function newWidnow(theURL,winName,features) { //v2.0
 
  parent.window.open(theURL,winName,features);

}
function Copy(ob)
{
	ob.select();
	js=ob.createTextRange();
	js.execCommand("Copy");
	alert("Copied!");
}
function jumpage(classid, ext)
{
	if($showmov('jumppage').value == '')
	{
		alert('Please enter page No.!');
		$showmov('jumppage').focus();
	}else{
	location.href = classid + '_' + $showmov('jumppage').value + ext;
	}
}
/*秀影图片自适应处理函数*/
function zoonImg(id, width)
{
	images = document.getElementById(id).getElementsByTagName("img");
	for (i = 0; i < images.length; i++)
	{
		img = images[i];
		img.onload = function()
		{
			w = this.width;
			h = this.height;
			if (w > width)
			{
				this.style.cursor = "hand";
				this.width = width;
				this.height = width / w * h;
			}
		}
	}
}

