﻿var ActiveColor = "#FFFF99";
var IsProgram=true;
var UploadProgramIconSuccess=false;
function AjaxSubmitProgramInfoFinish( arg,context )
{
	var s = arg.substring(0,1);
	var cmd = arg.split(s);
	if( cmd[1]=="err" )
	{
		if( cmd[2]=="program" )
		{
			alert( cmd[3] );
			CancelProgram();
		}
	}
	else if (cmd[1]=="program")
	{
		if( cmd[2]=="1" )
		{
			var o = document.getElementsByTagName( "span" );
			for( var i=0;i<o.length;i++ )
			{
				var p=o[i].getAttribute("p");
				if( p=="1" && permission%2==0)
				{
					try{o[i].innerHTML = document.getElementById( o[i].id + "t" ).value ;}catch(e){}
				}
				else if( p=="3" && permission%7==0)
				{
					try{o[i].innerHTML = document.getElementById( o[i].id + "t" ).value ;}catch(e){}
				}
			}
			if( imgPath!=null )
			{
				var img=document.getElementById(imgid);
				img.src = imgPath ;img.style.width = imgWidth ;img.style.height = imgHeight ;
				img.onmouseover=Function("window.status=this.src;");
				img.onmouseout=Function("window.status='';");
				img.onclick=Function("window.open(this.src);");
				img.style.cursor="pointer";
				imgPath = null;
			}
			document.getElementById(_user).innerText=cmd[4];
			document.getElementById(_user).href="/u/"+escape(cmd[4])+"/";
			document.getElementById(_user).target="_blank";
			document.getElementById(_pminforow).style.display="";
			document.getElementById(_time).innerText=cmd[5];
			document.getElementById(_panelextendedinfo1).innerHTML=cmd[6];
			document.getElementById(_panelextendedinfo2).innerHTML=cmd[7];
			document.getElementById(_panelextendedinfo3).innerHTML=cmd[8];
			CancelProgram();
		}
		else
			document.getElementById( "lblProgramMessage" ).innerHTML = cmd[3] ;//失败

		document.getElementById("FunctionBlock").style.display = "none";
		document.getElementById("hrefUploadIcon1").style.display = "";
		document.getElementById("hrefUploadIcon2").style.display = "none";
	}
	else if(cmd[1]=="tag")
	{
		if(cmd[2]=="-1")
			document.getElementById( "lblProgramMessage" ).innerHTML="添加标签失败";
		else
		{
			document.getElementById("divTag").style.display="none";
			document.getElementById(_tags).innerHTML=cmd[3];
			document.getElementById(_userTags).innerHTML=cmd[4];
			if(cmd[3]=="")
			{
				
				document.getElementById(_tags).style.display="none";
			}
			else
				document.getElementById(_tags).style.display="";
			if(cmd[4]=="")
			{
				document.getElementById(_userTags).style.display="none";
			}
			else
				document.getElementById(_userTags).style.display="";
			
		}
	}
	AjaxLoaded();
}
function AjaxSubmitProgramInfoErr( arg,context )
{
	document.getElementById("lblMessage").innerText = arg ;
}
function EditProgram()
{
	if(IsLogin)
	{
		if(permission%2!=0 && permission%7!=0)
		{
			alert("对不起，您没有修改相关内容的权限。如果您希望能够修改相关内容，请联系我们的管理员，为您添加相应权限。");
			return;
		}
		var o = document.getElementsByTagName( "span" );
		for( var i=0;i<o.length;i++ )
		{
			document.getElementById("trExtendedInfo1").style.display = "";
			document.getElementById("trExtendedInfo2").style.display = "";
			document.getElementById("trExtendedInfo3").style.display = "";
			var p=o[i].getAttribute("p");
			if( p=="1" && permission%2==0)
			{
				var t = document.createElement( "input" );
				t.type = "text";t.style.width = "60%";t.value = o[i].innerHTML ;t.id=o[i].id + "t" ;
				t.setAttribute("p","1" );t.setAttribute("n",o[i].getAttribute("n") );
				if(o[i].getAttribute("n").substring(0,2)=="en")
				{
					if(o[i].getAttribute("n")=="en1"&&t.value=="")t.value="导演：";
					if(o[i].getAttribute("n")=="en2"&&t.value=="")t.value="编剧：";
					if(o[i].getAttribute("n")=="en3"&&t.value=="")t.value="主演：";
					t.style.width="60px";t.style.marginRight="10px";
				}
				if(o[i].getAttribute("n").indexOf("e")==0)t.maxLength=100;
				o[i].style.display = "none";
				o[i].parentNode.insertBefore( t,o[i] );
		        document.getElementById("hrefUploadIcon1").style.display = "none";
		        document.getElementById("hrefUploadIcon2").style.display = "";
			}
			else if( p=="3" && permission%7==0)
			{
				var t = document.createElement( "input" );
				t.type = "text";t.style.width = "60%";t.value = o[i].innerHTML ;t.id=o[i].id + "t" ;
				t.setAttribute("p","3" );t.setAttribute("n",o[i].getAttribute("n") );
				o[i].style.display = "none";
				o[i].parentNode.insertBefore( t,o[i] );
			}
		}
		document.getElementById("FunctionBlock").style.display = "";
		document.getElementById(epid).style.display = "none";
		SetElementsVisible("hrefEditProgramDesc","none");
		if( permission%7==0 )
		{
			document.getElementById(ca).style.display="none";
			document.getElementById(cate).style.display="";
		}
		ShowActiveColor(true);
		window.onbeforeunload=Function("event.returnValue='您修改的内容尚未提交。';");
	}
	else
		document.location.href="/login.aspx?ReturnUrl="+escape(document.location.href)+"&mode=edit";
}
function CancelProgram()
{
	document.getElementById("trExtendedInfo1").style.display = "none";
	document.getElementById("trExtendedInfo2").style.display = "none";
	document.getElementById("trExtendedInfo3").style.display = "none";
	var o = document.getElementsByTagName( "span" );
	for( var i=0;i<o.length;i++ )
	{
		var p=o[i].getAttribute("p");
		if( p=="1" || p=="2" || p=="3" )
			o[i].style.display = "";
	}
	o = document.getElementsByTagName( "input" );
	for( var i=o.length-1;i>=0;i-- )
	{
		var p=o[i].getAttribute("p");
		if( p=="1" || p=="2" || p=="3" )
			o[i].parentNode.removeChild( o[i] );
	}
	o = document.getElementsByTagName( "textarea" );
	for( var i=o.length-1;i>=0;i-- )
	{
		var p=o[i].getAttribute("p");
		if( p=="1" || p=="2" || p=="3" )
			o[i].parentNode.removeChild( o[i] );
	}
	document.getElementById(epid).style.display = "";
	SetElementsVisible("hrefEditProgramDesc","");
	document.getElementById("FunctionBlock").style.display = "none";
	SetElementsVisible("DescFunctionBlock","none");
	document.getElementById("hrefUploadIcon1").style.display = "";
	document.getElementById("hrefUploadIcon2").style.display = "none";
	document.getElementById( "lblProgramMessage" ).innerHTML = "" ;
	SetElementsVisible( "lblProgramDescMessage","");
	document.getElementById(cate).style.display="none";
	document.getElementById(ca).style.display="";
	ShowActiveColor( false );
	window.onbeforeunload=null;
}
function SubmitProgram()
{
	var split = "$";
	var cmd = split + "program" + split + pid;
	var o = document.getElementsByTagName( "input" );
	for( var i=0;i<o.length;i++ )
	{
		var p=o[i].getAttribute("p");
		if( (p=="1" && permission%2==0) || (p=="2" && permission%3==0) || (p=="3" && permission%7==0) )
		{
			if(o[i].value.indexOf(">")>-1 || o[i].value.indexOf("<")>-1 || o[i].value.indexOf("$")>-1 || o[i].value.indexOf("'")>-1)
			{
				o[i].focus();o[i].select();document.getElementById( "lblProgramMessage" ).innerHTML="节目信息中不能包含< > $ '等特殊字符";
				return;
			}
			cmd += split + o[i].getAttribute( "n" ) + split + o[i].value ;
		}
	}
	document.getElementById("FunctionBlock").style.display = "none";
	document.getElementById( "lblProgramMessage" ).innerHTML = "请稍候..." ;
	if( Uploading )
	{
		Submit = true ;
		return ;
	}
	if( imgPath!=null )
		cmd += split + "icon" + split + imgPath ;
	if(permission%7==0)
	{
		var category=document.getElementById(list).value;
		if(category!="选择类型...")
		{
			cmd+=split+"category"+split+category;
			//document.getElementById(cat).innerHTML=category;
			var cateHref="";
			switch (category)
			{
				case "电视剧": cateHref = "/p/0__1.htm"; break;
				case "电影": cateHref = "/p/2_%e7%94%b5%e5%bd%b1_1.htm"; break;
				case "体育": cateHref = "/p/2_%e4%bd%93%e8%82%b2_1.htm"; break;
				case "生活": cateHref = "/p/2_%e7%94%9f%e6%b4%bb_1.htm"; break;
				case "少儿": cateHref = "/p/2_%e5%b0%91%e5%84%bf_1.htm"; break;
				case "科教": cateHref = "/p/2_%e7%a7%91%e6%95%99_1.htm"; break;
				case "栏目": cateHref = "/p/1__1.htm"; break;
				default: break;
			}
			if (cateHref == "")
				document.getElementById(cat).innerHTML = category;
			else
				document.getElementById(cat).innerHTML = "<a href='"+cateHref+"' target='_blank'>"+category+"</a>";
		}
	}
	AjaxSubmitProgramInfo( cmd,null );
	AjaxLoading();
	window.onbeforeunload = null;
}
function EditProgramDesc(arg)
{
	if(IsLogin)
	{
		if(permission%3!=0)
		{
			alert("对不起，您没有修改相关内容的权限。如果您希望能够修改相关内容，请联系我们的管理员，为您添加相应权限。");
			return;
		}
		var s = arg.substring(0,1);
		var cmd = arg.split(s);
		var o = document.getElementsByTagName( "span" );
		for( var i=0;i<o.length;i++ )
		{
			var p=o[i].getAttribute("p");
			var n=o[i].getAttribute("n");
			if( p=="2" && n==cmd[2] && permission%3==0)
			{
				var t = document.createElement( "textarea" );
				t.style.height=Math.max(o[i].offsetHeight,100)+"px";t.style.width = "90%";t.id=o[i].id + "t" ;
				var s = o[i].innerText;
				while( s.indexOf("<BR>")>-1 || s.indexOf("<br>")>-1 )
					s = s.replace("<BR>","\r\n").replace("<br>","\r\n");
				if(s=="　　目前该节目还没有描述" ||  s=="　　目前该集还没有描述" || s=="目前该节目还没有描述" || s=="目前该集还没有描述")
					t.value = "" ;
				else t.value=s;
				t.setAttribute("p","2" );t.setAttribute("n",cmd[2] );
				o[i].style.display = "none";
				o[i].parentNode.insertBefore( t,o[i] );
				break;
			}
		}
		document.getElementById("DescFunctionBlock"+cmd[2]).style.display = "";
		document.getElementById(epid).style.display = "none";
	    document.getElementById("hrefUploadIcon1").style.display = "none";
	    document.getElementById("hrefUploadIcon2").style.display = "none";
		SetElementsVisible("hrefEditProgramDesc","none");
		window.onbeforeunload=Function("event.returnValue='您修改的内容尚未提交。';");
	}
	else
		document.location.href="/login.aspx?ReturnUrl="+escape(document.location.href)+"&mode=edit";
}
function SubmitProgramDesc(arg)
{
	var s = arg.substring(0,1);
	var cmd = arg.split(s);
	var retcmd = s + "program" + s + cmd[1];
	o = document.getElementsByTagName( "textarea" );
	for( var i=0;i<o.length;i++ )
	{
		var p=o[i].getAttribute("p");
		if( o[i].value.length>10000 )
		{
			o[i].focus();o[i].select();document.getElementById( "lblProgramDescMessage"+cmd[2] ).innerHTML="节目描述不能超过10000个字";
			return;
		}
		if(o[i].value.indexOf(">")>-1 || o[i].value.indexOf("<")>-1 || o[i].value.indexOf("$")>-1 || o[i].value.indexOf("'")>-1)
		{
			o[i].focus();o[i].select();document.getElementById( "lblProgramDescMessage"+cmd[2] ).innerHTML="节目描述不能包含< > $ '等特殊字符";
			return;
		}
		if(p=="2")
			retcmd += s + o[i].getAttribute( "n" ) + s + o[i].value ;
	}
	SetElementsVisible("DescFunctionBlock","none");
	document.getElementById( "lblProgramDescMessage"+cmd[2] ).innerHTML = "请稍候..." ;
	if( Uploading )
	{
		Submit = true ;
		return ;
	}
	AjaxProgramDesc( retcmd,null );
	AjaxLoading();
	window.onbeforeunload = null;
}
function SetElementsVisible(name,property)
{
	o = document.getElementById(name+"d");
	if(o!=null)
		o.style.display = property;
	for(var i=1;i<10;i++)
	{
		o = document.getElementById(name+"d"+i);
		if(o!=null)
			o.style.display = property;
		else
			break;
	}
}
function UploadProgramIcon()
{
	if(IsLogin)
	{
		if(permission%2!=0)
		{
			alert("对不起，您没有修改相关内容的权限。如果您希望能够修改相关内容，请联系我们的管理员，为您添加相应权限。");
			return;
		}
		UploadProgramIconSuccess=false;
		AttachImage();
		if(UploadProgramIconSuccess)
		    SubmitProgram();
	}
	else
		document.location.href="/login.aspx?ReturnUrl="+escape(document.location.href)+"&mode=edit";
}
function AttachImage()//Firefox
{
	IsProgram=true;
	var doc = window.frames["UploadFrame"].document;
	doc.getElementById("fileUpload").click();
	var file = doc.getElementById("fileUpload").value.toLowerCase();
	if( file!="" )
	{
		if( file.substr(file.length-4,4)==".jpg" || file.substr(file.length-4,4)==".gif" || file.substr(file.length-4,4)==".png" )
		{	
			imgPath = null;
			Uploading = true ;
			UploadProgramIconSuccess = true;
			doc.getElementById("btnSubmit").click();
		}
		else
		{
			doc.getElementById("fileUpload").value="";
			document.getElementById( "lblProgramMessage" ).innerHTML="节目预览图只能是jpg、gif或者png类型。请重新选择图片文件。";
			return ;
		}
	}
}
var imgPath,imgWidth,imgHeight,Uploading = false,Submit = false ;
function ShowIcon( path,w,h )
{
	if(IsProgram)
	{
		imgPath = path;imgWidth = w + "px";imgHeight = h + "px";
		document.getElementById( "lblProgramMessage" ).innerHTML = "" ;
		Uploading = false ;
		if( Submit ) SubmitProgram();
		Submit = false ;
	}
	else
	{
		imgPath = path;imgWidth = w + "px";imgHeight = h + "px";
		document.getElementById( "ErrorMessage" ).innerHTML = "" ;
		if( Submit ) SubmitStill();
		Submit = false ;
	}
}
function ShowActiveColor( active )
{
	if( permission%2==0 )
	{
		document.getElementById("TableTop").rows[0].cells[0].style.backgroundColor = active?ActiveColor:"";
	}
}
function AddTag()
{
	if(!IsLogin)
	{
		window.location.href="/Login.aspx?ReturnUrl="+escape(window.location.href)+"&mode=tag";
		return;
	}
	if(document.getElementById("divTag").style.display=="")
		document.getElementById("divTag").style.display="none";
	//document.getElementById("addTag").style.display="none";
	else
		document.getElementById("divTag").style.display="";
	document.getElementById("addTag").style.display="none";
}
function EditTag()
{
	if(!IsLogin)
	{
		window.location.href="/Login.aspx?ReturnUrl="+escape(window.location.href);
		return;
	}
	var tagText=document.getElementById("tagText");
	var strTag=tagText.value;
	//if(strTag.replace(" ","").length==0)
	//{
		//alert("标签不能为空");
		//return;
	//}
	AjaxSubmitProgramInfo("#tag#"+strTag,null);
}
function AjaxProgramDetails(arg,context)
{
	AjaxLoading();
	var newarg="#"+pid+arg;
	AjaxProgramDetail(newarg,context);
}
function AjaxProgramDetailFinish(arg,context)
{
	var s = arg.substring(0,1);
	var cmd = arg.split(s);
	switch(cmd[1])
	{
		case "err":
			alert(cmd[2]);
			break;
	}
	AjaxLoaded();
}
function AjaxProgramDetailErr(arg,context)
{
}
function SelectTab( n )
{
	document.getElementById( "tableDefault" ).style.display = (n==0?"":"none");
	document.getElementById( "tableStill" ).style.display = (n==1?"":"none");
	document.getElementById( "tableDesc" ).style.display = (n==2?"":"none");
	document.getElementById( "tableComment" ).style.display = (n==3?"":"none");
	document.getElementById( "tableResource" ).style.display = (n==4?"":"none");
	document.getElementById( "tableSelectTab" ).rows[0].cells[1].className=(n==0?"disabletab":"enabletab");
	document.getElementById( "tableSelectTab" ).rows[0].cells[3].className=(n==1?"disabletab":"enabletab");
	document.getElementById( "tableSelectTab" ).rows[0].cells[5].className=(n==2?"disabletab":"enabletab");
	document.getElementById( "tableSelectTab" ).rows[0].cells[7].className=(n==3?"disabletab":"enabletab");
	document.getElementById( "tableSelectTab" ).rows[0].cells[9].className=(n==4?"disabletab":"enabletab");
	if(n==0)
		IsProgram=true;
	if(n==1)
		IsProgram=false;
	if(n==2 && arguments.length==5)
		window.setTimeout("AjaxProgramDescs('#page#"+arguments[1]+"#"+arguments[2]+"#"+arguments[3]+"#"+arguments[4]+"',null)",0);
	if(n==4)
		window.setTimeout("RefreshResource()",0);
}
function SetRowVisible()
{
	document.getElementById( "tableDefaultContent" ).rows[7].style.display = (rowvisible%7==0?"":"none");
	document.getElementById( "tableDefaultContent" ).rows[6].style.display = (rowvisible%7==0?"":"none");
	document.getElementById( "tableDefaultContent" ).rows[5].style.display = (rowvisible%5==0?"":"none");
	document.getElementById( "tableDefaultContent" ).rows[4].style.display = (rowvisible%5==0?"":"none");
	document.getElementById( "tableDefaultContent" ).rows[3].style.display = (rowvisible%3==0?"":"none");
	document.getElementById( "tableDefaultContent" ).rows[2].style.display = (rowvisible%3==0?"":"none");
	document.getElementById( "tableDefaultContent" ).rows[1].style.display = (rowvisible%2==0?"":"none");
	document.getElementById( "tableDefaultContent" ).rows[0].style.display = (rowvisible%2==0?"":"none");
}
function AjaxProgramDescs(arg,context)
{
	AjaxLoading();
	AjaxProgramDesc(arg,context);
}
function AjaxProgramDescFinish(arg,context)
{
	var s = arg.substring(0,1);
	var cmd = arg.split(s);
	switch(cmd[1])
	{
		case "err":
			if( cmd[2]=="program" )
			{
				alert( cmd[3] );
				CancelProgram();
				SetElementsVisible("lblProgramMessage","none");
			}
			else
				alert(cmd[2]);
			break;
		case "page":
			var divs=document.getElementsByName("divDescription");
			for(var i=0;i<divs.length;i++)
			{
				if(divs[i].childNodes.length>0 && divs[i].childNodes[0].getAttribute("_editor")=="1")
				{
					divs[i].childNodes[0].innerHTML=cmd[3];
					break;
				}
			}
			break;
		case "program":
			if( cmd[2]=="1" )
			{
				var o = document.getElementsByTagName( "span" );
				for( var i=0;i<o.length;i++ )
				{
					var p=o[i].getAttribute("p");
					if( p=="2" && permission%3==0 && document.getElementById( o[i].id + "t" )!=null)
						o[i].innerHTML = cmd[7];
				}
				document.getElementById(_user).innerText=cmd[4];
				document.getElementById(_user).href="/u/"+escape(cmd[4])+"/";
				document.getElementById(_user).target="_blank";
				document.getElementById(_pminforow).style.display="";
				document.getElementById(_time).innerText=cmd[5];
				CancelProgram();
				document.getElementById( "lblProgramDescMessage"+cmd[6] ).innerHTML="";
			}
			else
				document.getElementById( "lblProgramDescMessage"+cmd[6] ).innerHTML = cmd[3] ;//失败
			SetElementsVisible("DescFunctionBlock","none");
			break;
	}
	document.getElementById("hrefUploadIcon1").style.display = "";
	document.getElementById("hrefUploadIcon2").style.display = "none";
	AjaxLoaded();
}
function AjaxProgramDescErr(arg,context)
{
}


//still

function SubmitStill()
{
	cmd="$Still$"+imgPath+"$"+programID;
	RefreshStill(cmd,null);
}
function UploadFinish( path,w,h )
{
	var img=document.getElementById(strImg);
	document.getElementById( "lblUploadImage" ).innerHTML = "^_^已经上传好了。";
	Uploading = false ;
	img.src = imgPath;
	img.style.height = imgHeight;
	img.style.width = imgWidth;
	img.onmouseover=Function("window.status=this.src;");
	img.onmouseout=Function("window.status='';");
	img.onclick=Function("window.open(this.src);");
	img.style.cursor="pointer"; 
	AjaxLoaded(); 
}
function UploadError(message)
{
	document.getElementById("ErrorMessage").style.display="";
	document.getElementById("ErrorMessage").innerHTML=message;
	document.getElementById("btnUploadImage").disabled = false;
	document.getElementById("lblUploadImage").innerHTML = "";
	document.getElementById("lblUploadImage").style.display = "none";
	AjaxLoaded();
}
var lastarg="#page#0", lastcontext=null;
function PageChanged(arg,context)
{
	if(arg==null&&context==null)
	{
		AjaxLoading();
		RefreshStill(lastarg+"#"+programID,lastcontext);
	}
	else
	{
		AjaxLoading();
		var split=arg.substring(0,1);
		var cmd=arg.split(split);
		if(cmd[1]=="page")
		{
			lastarg=arg;
			lastcontext=context;
			RefreshStill(arg+"#"+programID,context);
		}
	}
}

function DeleteStill(arg)
{
	//debugger
	AjaxLoading();
	var cmd="#delete#"+arg;
	RefreshStill(cmd,null);
}
function SetProgramIcon(arg,url)
{
	AjaxLoading();
	var cmd="#icon#"+arg;
	RefreshStill(cmd,url);
}

function ChangeStill(arg,context)
{
	var split=arg.substring(0,1);
	var cmd=arg.split(split);
	if(cmd[1]=="refresh")
	{
		programID=cmd[2];
		document.title=cmd[3]+" - e准 - 剧照";
		var stillTitle=document.getElementById(divstillssrclink);
		if(stillTitle!=null)
			stillTitle.innerHTML="<strong><a href='/p/"+cmd[4]+"/' target =_blank title='"+cmd[3]+"'>"+cmd[3]+"</a> 的剧照：</strong>";
		AjaxLoading();
		RefreshStill(arg,context);
	}
}

function RefreshStillFinish(arg,context)
{
	var still=document.getElementById(strStill);
	var split=arg.substring(0,1);
	var cmd=arg.split(split);
	if(cmd[1]=="page")
		still.innerHTML=cmd[2];
	else if(cmd[1]=="still")
	{
		still.innerHTML=cmd[3]; 
	}
	else if(cmd[1]=="delete")
	{
		if(cmd[2]=="-1")
		{
			var str="msg_"+cmd[4];
			var msg=document.getElementById(str);
			if(msg) 
				msg.Text="删除失败";
		}
		else
		{
			still.innerHTML=cmd[3];
			if(typeof(tbTab)!="undefined")
			{
				var tab=document.getElementById(tbTab);
				if(tab!=null)
					tab.rows[0].cells[3].innerHTML="剧照("+cmd[5]+")";
			}
			if(cmd[5]=="0")
			{
				document.location.reload();
			}
		}
	}
	else if(cmd[1]=="refresh")
		still.innerHTML=cmd[2];
	else if(cmd[1]=="icon")
	{
		location.href=context;
		return;
	} 
	AjaxLoaded();
}
function RefreshStillFinishErr(arg,context)
{
}
function SetDisplay()
{
	document.getElementById(strUpdate).style.display="";
}
function AttachStillImage()//Firefox
{
	IsProgram=false;
	if(IsLogin)
	{
		if(typeof(imgUpload)!="undefined")
		{
			var upload=document.getElementById(imgUpload);
			if(upload!=null)
			{
				upload.click();
				return;
			}
		}
		var doc = window.frames['uploadStill'].document;
		doc.getElementById("fileUpload").click();
		var file = doc.getElementById("fileUpload").value.toLowerCase();
		if( file!="" )
		{
			if( file.substr(file.length-4,4)==".jpg" || file.substr(file.length-4,4)==".gif" || file.substr(file.length-4,4)==".png" )
			{	
				Uploading = true ;
				Submit = true;
				document.getElementById("btnUploadImage").disabled = true;
				document.getElementById("lblUploadImage").style.display = "";
				document.getElementById("lblUploadImage").innerHTML = "正在上传图片，请稍后...";
				doc.getElementById("btnSubmit").click();
				AjaxLoading();
			}
			else
			{
				doc.getElementById("fileUpload").value="";
				document.getElementById("lblUploadImage").style.display = "";
				document.getElementById( "lblUploadImage" ).innerHTML="上传图片只能是jpg、gif或者png类型。请重新选择图片文件。";
				document.getElementById("ErrorMessage").innerHTML="";
				document.getElementById("ErrorMessage").style.display="none";
			}
		}
	}
	else
		top.document.location.href="/login.aspx?ReturnUrl="+escape(top.document.location.href)+"&mode=update";
}

//
function AjaxLatestStillsFinish(arg,context)
{
	var split=arg.substring(0,1);
	var cmd=arg.split(split);
	document.getElementById(divPrograms).innerHTML=cmd[2];
}

function AjaxLatestStillsFinishErr(arg,context)
{
}

//ScheduleAndUserCtl
function InitRefresh()
{
	var obj=new Refresh();
	var contain=GetEventContain("alert");
	contain.add(obj);
	var contain=GetEventContain("img");
	contain.add(obj);
}
function Refresh()
{
	this.EventFire=function(arg,context)
	{
		var cmd=arg.split('$');
		AjaxLoading();
		window.setTimeout("RefreshSelfWishlist('"+arg+"','')",0);
		window.setTimeout("RefreshEvent('"+arg+"','')",0);
	}
}

function RefreshAlert()
{
	RefreshSelfWishlist("","");
	RefreshEvent("$alert_refresh$","");
}
function RefreshEventFinish(arg,context)
{
	var split=arg.substring(0,1);
	var cmd=arg.split(split);
	if(cmd[2]!=""&&cmd[2]!=null&&document.getElementById(_tRelation).style.display=="none")
	{
		document.getElementById(_tRelation).style.display="";
	}
	if(cmd[1]=="alert_refresh")
	{
		if(cmd[2]!=""&&cmd[2]!=null)
		{
			if(document.getElementById(_trAlert).style.display=="none")
				document.getElementById(_trAlert).style.display="";
			document.getElementById(_divSend).innerHTML=cmd[2];
		}
		else
		{
			document.getElementById(_trAlert).style.display="none";
			document.getElementById(_divSend).innerHTML=cmd[2];
		}
	}
	else if(cmd[1]=="wishlist_refresh")
	{
		if(cmd[2]!=""&&cmd[2]!=null)
		{
			if(document.getElementById(_trCollt).style.display=="none")
				document.getElementById(_trCollt).style.display="";
			var div=document.getElementById(_divWishlist);
			div.innerHTML=cmd[2];
		}
		else
		{
			document.getElementById(_trCollt).style.display="none";
			document.getElementById(_divWishlist).innerHTML=cmd[2];
		}
	}
	if(document.getElementById(_trAlert).style.display=="none"&&document.getElementById(_trCollt).style.display=="none")
	{
		document.getElementById(_tRelation).style.display="none";
	}
	AjaxLoaded();
	var div=document.getElementById(_scheduleDiv);
    if(div==null)return;
	var st=div.scrollTop;
	div.outerHTML=div.outerHTML;
	div=document.getElementById(_scheduleDiv);
	div.scrollTop=st;
}
function RefreshEventFinishErr()
{
}
function CancelAlert(scid,context)
{
	if(scid!=""&&context!="")
		MPCallback("#alert_cancel#"+scid,context);
	return false;
}
function CancelSchedules(id)
{
	AjaxLoading();
	if(id!="")
	{
		var par="#schedule_cancel#"+id;
		MPCallback(par,null);
	}
	return false;
}
function setDisplay()
{
	var showRelation=document.getElementById(_tRelation);
	var alert=document.getElementById(_trAlert);
	var divSend=document.getElementById(_divSend);
	var collection=document.getElementById(_trCollt);
	var divWishlists=document.getElementById(_divWishlist);
	if(divSend.innerHTML!="")
		alert.style.display="";
	if(divWishlists.innerHTML!="")
		collection.style.display="";
	if(alert.style.display=="none"&&collection.style.display=="none")
		showRelation.style.display="none";
}
function SubmitResource()
{
	if(IsLogin)
	{
		var doc=window.frames['txtResource'].document;
		var HtmlEdit=doc.getElementById("HtmlEdit");
		var save=doc.getElementById("save");
		var clearText=doc.getElementById("clearText");
		save.click();
		var text=doc.getElementById("txt");
		var html=text.innerHTML.toLowerCase();
		var type=doc.getElementById("sltResourceType").value;
		while( html.indexOf(" ")>-1 )
			html = html.replace(" ","");
		while( html.indexOf("&nbsp;")>-1 )
			html = html.replace("&nbsp;","");
		var msg=document.getElementById("lblMessageResource");
		if( html.length==0 || html=="<div></div>")
		{
			msg.innerHTML = "文章内容不能为空";
			return false ;
		}
		if( html.indexOf("$")>-1)
		{
			msg.innerHTML = "文章内容不能包含 $ 等特殊字符";
			return false ;
		}
		if( html.length>5000 )
		{
			msg.innerHTML = "文章内容不能超过5000个字";
			return false ;
		}
		msg.innerHTML="";
		var split = "$";
	
		var cmd = split+"add"+split+pid+split+type+split+text.innerHTML;
		AjaxResource(cmd,null);
		AjaxLoading();
	}
	else
	{
	    var strrequeststring = "tab=resource";
	    if(top.document.location.href.indexOf("?")>-1)
	        strrequeststring = "&" + strrequeststring;
        else
	        strrequeststring = "?" + strrequeststring;
		top.document.location.href="/login.aspx?ReturnUrl="+escape(top.document.location.href.indexOf("resource")>-1?top.document.location.href:(top.document.location.href+strrequeststring))+"&mode=resource";
	}	
}
var _resourcePage=0;
function RefreshResource(n)
{
	if(n!=null)
		_resourcePage=n;
	else if(document.getElementById(_divResource).innerHTML!="")
		return;
	AjaxLoading();
	AjaxResource("$refresh$"+pid+"$"+_resourcePage);
}
function DeleteResource(resourceid)
{
	if(resourceid==null)
		return;
	AjaxLoading();
	AjaxResource("$delete$"+pid+"$"+resourceid);
}
function AjaxResourceFinish(arg,context)
{
	var split=arg.substring(0,1);
	var cmd=arg.split(split);
	switch(cmd[1])
	{
		case "refresh":
			document.getElementById(_divResource).innerHTML=cmd[2];
			break;
		case "err":
			var msg=document.getElementById("lblMessageResource");
			msg.innerHTML=cmd[2];
			break;
	}
	AjaxLoaded();
}
function AjaxResourceErr(arg,context)
{
}
function InitPPage()
{
	var t=document.getElementById("tbPrgRight");
	var div=document.getElementById("divDesc");
	if(t==null||t.parentNode.offsetHeight==0)
	{
		window.setTimeout(InitPPage,100);
		return;
	}
	if(div!=null&&div.offsetHeight>350)
	{
		div.style.overflow="hidden";
		div.style.height="285px";
		var more=document.createElement("DIV");
		div.parentNode.appendChild(more);
		more.innerHTML="<table width=100% height=50><tr><td valign=top id=__tddot>……</td><td align=right><a href='#' style=cursor:pointer; onclick='ShowMore(true,this);return false;' id='__pgmlink'>更多剧情></a></td></tr></table>";
		//if(div.getElementsByTagName("IMG").length>0)
		//	more.style.paddingLeft="240px";
	}
	t.rows[t.rows.length-1].style.height=(t.parentNode.offsetHeight-t.offsetHeight)+"px";
	t.style.height=t.parentNode.offsetHeight+"px";
}
function ShowMore(more,obj)
{
	var t=document.getElementById("tbPrgRight");
	t.rows[t.rows.length-1].style.height="auto";
	t.style.height="auto";
	var div=document.getElementById("divDesc");
	if(more)
	{
		div.style.overflow="";
		div.style.height="auto";
		obj.onclick=Function("ShowMore(false,this);return false;");
		document.getElementById("__tddot").innerHTML="";
		document.getElementById("__pgmlink").innerHTML="隐藏剧情";
	}
	else
	{
		div.style.overflow="hidden";
		div.style.height="285px";
		obj.onclick=Function("ShowMore(true,this);return false;");
		document.getElementById("__tddot").innerHTML="……";
		document.getElementById("__pgmlink").innerHTML="更多剧情>";
	}
	t.rows[t.rows.length-1].style.height=(t.parentNode.offsetHeight-t.offsetHeight)+"px";
	t.style.height=t.parentNode.offsetHeight+"px";
}
InitPPage();
function ClickFunctionButton(ButtonClientID)
{
    try
    {
        window.setTimeout("document.getElementById('"+ButtonClientID+"').click();",0);
    }
    catch(e){}
}
//加入我想看，或者取消我想看，节目页面
function InitProgramWantChanger()
{
	var obj=new ProgramWantChanger();
	var contain = GetEventContain("want_changed");
	contain.add(obj,"program");
}
function ProgramWantChanger()
{
	this.EventFire =  function(arg,context)
	{
		var split=arg.substring(0,1);
		var cmd=arg.split(split);
		var ids=cmd[3].split(',');
		var idPrefix="iwant",command="cancelwant",desc="我想看";
		if(cmd[1]=="cancelwant")
		{
			command="addtowant";
		}
		else if(cmd[1]=="addtopast")
		{
			idPrefix="ipast";command="cancelpast";desc="我看过";
		}
		else if(cmd[1]=="cancelpast")
		{
			idPrefix="ipast";command="addtopast";desc="我看过";
		}
		for(var i=0;i<ids.length;i++)
		{
			if(ids[i]!=null||ids[i]!="")
			{
				var iwant=document.getElementById(idPrefix+"_"+ids[i]);
				if(iwant!=null)
				{
					if(command=="cancelpast"||command=="cancelwant")
					{
						iwant.innerHTML="<span class='disabled2'><a href='#' onclick=\"MPCallback('#"+command+"#"+ids[i]+"',null);return false;\" title='取消'>√"+desc+"</a></span>";
					}
					else
					{
						iwant.innerHTML="<a href='#' onclick=\"MPCallback('#"+command+"#"+ids[i]+"',null);return false;\">"+desc+"</a>";
					}
				}
			}
		}
	}
}
InitProgramWantChanger();

function SwitchVideoTab(value,name)
{	
	var s=document.location.href;	
	var url=FormatUrl(s,name,value);
	url=FormatUrl(url,"page",0);
	document.location.href=url;	
}

function SwitchPage(value,name)
{	
	var s=document.location.href;	
	var regex = new RegExp("^http://www.ezhun.com/p/[0-9]{1,6}/videos/index_[0-9]{1,3}.htm");
	if(regex.test(s))
	{
		var start=s.indexOf("index_");
		var end=s.indexOf(".htm");	
		var oldIndex="index_"+s.substring(start+6,end);	
		var newIndex="index_"+value;	
		s=s.replace(oldIndex,newIndex)
	}
	document.location.href=s;	
}

function ScrollVideo(obj,down)
{
	if(obj.className=="disabled")return;
	
	var table=obj;
	while(table.tagName.toUpperCase()!="TABLE")
		table=table.parentNode;

	var offset=table.offsetTop;
	var height=table.rows[0].offsetHeight;
	if(down && offset/height>=table.rows.length)
	{
		obj.className="disabled";
		return;
	}
	if(!down && offset==0)
	{
		obj.className="disabled";
		return;
	}

	if(down)
		table.style.top=(offset-height)+"px";
	else
		table.style.top=(offset+height)+"px";
}
//专题入口
var isSport=document.getElementById("isSport");
if(typeof(isSport)!="undefined"&&isSport!=null)
{
	value=isSport.value;
	switchPhto();
}
function switchPhto()
{	
	if(value=="True")
	{
		if(document.getElementById("photo").style.display=="")
		{
			document.getElementById("photo").style.display="none";
			document.getElementById("photo1").style.display="";
		}
		else
		{
			document.getElementById("photo").style.display="";
			document.getElementById("photo1").style.display="none";
		}
		window.setTimeout(switchPhto,3000);
	}		
}