﻿/**********节目单频道页*********/
function FormatUrl( url,name,value )
{
	while(url.indexOf("#")>-1)url=url.replace("#","");
	var newQuery = "" ;
	var done = false ;
	var query=""
	if(url.indexOf("?")>-1)
		query=url.substr(url.indexOf("?"));
	if( query!="?" && query!="" )
	{
		query = query.substr(1);
		var namevalue = query.split( "&" );
		for( var i=0;i<namevalue.length;i++ )
		{
			var nv = namevalue[i].split( "=" );
			if( nv[0].toLowerCase()==name.toLowerCase() )
			{
				newQuery += (name + "=" + escape(value) + "&");
				done = true ;
			}
			else
				newQuery += (nv[0] + "=" + nv[1] + "&") ;
		}
	}
	if( !done )
		newQuery += (name + "=" + escape(value) + "&");
	
	if( newQuery.length>0 )
		newQuery = newQuery.substring( 0,newQuery.length-1 ) ;
	var newUrl=url;
	if(url.indexOf("?")>-1)newUrl=url.substr(0,url.indexOf("?"));
	return newUrl+ "?" + newQuery ;
}
/**Topbar.ascx**/
function SwitchArea(value)//切换地区同时设置cookie
{
	var arr=value.split("|");
	var area=arr[0];
	var deChannel=unescape(arr[1]);
	SetCookie("areaID",area,365,"/","tvguide.ent.sina.com.cn",false);
	var s=document.location.href.toLowerCase();
	if(s.indexOf("#")>-1)
		s=s.substring(0,s.indexOf("#"));
	if((s.search("/customsearch")>-1) || (s.search("/search")>-1) )
	{
		var url=FormatUrl(s,"areaID",area);
	}
	else
	{
	    var url=s.replace(/\/[0-9]+\//,'/'+area+'/');
	}
	if(s.search("/channel.aspx")>-1)
	{
		url=FormatUrl(url,"areaID",area);
		url=FormatUrl(url,"channel",deChannel);
	}
	if(url.search("/channel/")>-1)
	{
		url=url.replace(/(\/channel\/[0-9]+\/)[0-9a-zA-Z\+]+\//,'$1'+deChannel+"/");
		url=url.replace(/(\/channel\/[0-9]+\/)[^/\.]+\.html/,'$1'+deChannel+".html");
	}
	if(url.search("/customsearch")>-1)
	{
	   var d=new Date();
	   var y=d.getFullYear();
	   var m=(d.getMonth()+1)<10?"0"+(d.getMonth()+1):(d.getMonth()+1);
	   var r=d.getDate()<10?"0"+d.getDate():d.getDate();
	   url="/channel/"+area+"/cctv1/"+y+m+r+".html";
	}
	document.location.href=url;
}
function ShowArea()
{
	
	var slt=document.getElementById("hd_cities");
	slt.style.display="block";
	var a=document.getElementById("hd_areabutton");
	a.style.display="none";
}
function $(objname){return document.getElementById(objname);}
function ExpandChannel(groupID,link)
{
	var display=$("channellist_"+groupID).style.display;
	$("channellist_"+groupID).style.display=display==""?"none":"";
	link.parentNode.parentNode.className=display==""?"group":"groupfocus";
	var tabbodyChildren=link.parentNode.parentNode.parentNode.getElementsByTagName("div");
	for(i=0;i<tabbodyChildren.length;i++)
	{
		var child=tabbodyChildren[i];
		if(child.id.substr(0,12)=="channellist_" && !isNaN(parseInt(child.id.substr(12,child.id.length-12))) && child.id.substr(12,child.id.length-12)!=groupID)
		{
			if (child.style.display=="")
			{
    			child.style.display="none";
	    		if($("group_"+child.id.substr(12,child.id.length-12)))$("group_"+child.id.substr(12,child.id.length-12)).className="group";
			}
		}
	}
}
function ExpandTab(tabID,link)
{
	var display=$("tabbd_"+tabID).style.display;
	$("tabbd_"+tabID).style.display=display==""?"none":"";
	link.parentNode.className=display==""?"tab":"tabfocus";
	var grouplistChildren=link.parentNode.parentNode.getElementsByTagName("div");
	for(i=0;i<grouplistChildren.length;i++)
	{
		var child=grouplistChildren[i];
		if(child.id.substr(0,6)=="tabbd_" && !isNaN(parseInt(child.id.substr(6,child.id.length-6))) && child.id.substr(6,child.id.length-6)!=tabID)
		{
			if (child.style.display=="")
			{
				child.style.display="none";
				if($("tab_"+child.id.substr(6,child.id.length-6)))$("tab_"+child.id.substr(6,child.id.length-6)).className="tab";
			}
		}
	}
}
function DisplayMore(id1,id2)
{
	document.getElementById(id2).style.display="";
	document.getElementById(id1).style.display="none";
}
function queryString(key)
{
	key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+key+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}
function Search()
{
	var key=$("search_text").value;
	while(key.indexOf(" ")==0)key=key.replace(" ","");
	while(key.indexOf("　")==0)key=key.replace("　","");
	if(key=="")
	{
		alert("请输入要查找的关键词。");
		return false;
}
var t = "program";
if ($("search_button").className == "v_buttom")
    t = "iptv";
document.location.href = "/search.aspx?p=" + t + "&key=" + escape(key) + "&page=0";
	return true;
}
function SearchSchedule() {
    var key = $("txt_schedule_key").value;
    while (key.indexOf(" ") == 0) key = key.replace(" ", "");
    while (key.indexOf("　") == 0) key = key.replace("　", "");
    if (key == "") {
        alert("请输入要查找的关键词。");
        return false;
    }
    document.location.href = "/search.aspx?p=schedule&key=" + escape(key) + "&page=0";
    return true;
}
function GetPageType()
{
    var type = document.getElementById("IndexPage").value;
	ChangeUrl(type);
	if(location.href.indexOf("/ent/") > -1)
	type="ent";
	else if(location.href.indexOf("/movie/") > -1)
	type="movie";
	else if(location.href.indexOf("/sport/") > -1)
	type="sport";
	else if(location.href.indexOf("/p/") > -1 || location.href.indexOf("/#error_program") > -1|| location.href.indexOf("/teleplay/") > -1)
		type="program";
if (location.href.indexOf("p=iptv") > -1 || location.href.indexOf("/v/") > -1 || location.href.indexOf("/video/") > -1)
    type = "iptv";
else if (location.href.indexOf("p=schedule") > -1 || location.href.indexOf("/channel/") > -1 || location.href.indexOf("/category/") > -1|| location.href.indexOf("/playing/") > -1)
    type = "schedule";
else if (location.href.indexOf("search.aspx") > -1)
    type = "program";
	return type;
}
function GetSiteMember()
{
	var member=document.getElementById("Member").value;
	if(member.indexOf(",program,")>-1)
	{
	    document.getElementById("programUrl").style.display = "";
	    document.getElementById("programUrl1").style.display = "";
	    document.getElementById("programUrl2").style.display = "";
	    document.getElementById("programUrl3").style.display = "";
	}
	if(member.indexOf(",schedule,")>-1)
	{
		document.getElementById("scheduleUrl").style.display="";
	}
	if(member.indexOf(",iptv,")>-1)
	{
		document.getElementById("iptvUrl").style.display="";
	}
}
function ChangeUrl(type)
{	
	if(type=="program")
	    document.getElementById(type + "Url").innerHTML = "<a href='/'>电视剧场</a>";
	if(type=="schedule")
	    document.getElementById(type + "Url").innerHTML = "<a href='/'>搜视指南 </a>";
	if(type=="iptv")
	    document.getElementById(type + "Url").innerHTML = "<a href='/'>网络视频导航</a>";
}
function vmarquee(lh,speed,delay,id)
{
	var t;
	var p=false;
	var o=document.getElementById(id);
	if(o==null)return;
	o.innerHTML+=o.innerHTML;
	o.onmouseover=function(){p=true}
	o.onmouseout=function(){p=false}
	o.scrollTop = 0;
	function start()
	{
		t=setInterval(scrolling,speed);
		if(!p) o.scrollTop += 2;
	}
	function scrolling()
	{
		if(o.scrollTop%lh!=0)
		{
			o.scrollTop += 2;
			if(o.scrollTop>=o.scrollHeight/2) o.scrollTop = 0;
		}
		else
		{
			clearInterval(t);
			setTimeout(start,delay);
		}
	}
	setTimeout(start,delay);
}
//显示可拖拽的窗口
function DraggableWin(url,width,height,title,titleColor)
{
	var left,top,html=document.documentElement,stop=html.scrollTop,sleft=html.scrollLeft,tcolor="#e0e0e0";
	if(titleColor!=null)tcolor=titleColor;
	title="<b>"+title+"</b>";
	left=sleft+html.offsetWidth/2-width/2;
	top=stop+html.offsetHeight/2-height/2;
	var mask=document.createElement("DIV");
	mask.style.width="100%";//(document.body.clientWidth-500)+"px";
	mask.style.height=(Math.max(document.body.offsetHeight+20,html.offsetHeight-5)+160)+"px";
	mask.className="mask";
	mask.id="maskdiv";
	if(!document.all)
		mask.style.opacity=0.5;
	document.body.appendChild(mask);
	
	ShowSelectObject(false);
	var div=document.createElement("DIV");
	div.className="divwin";
	div.id="win"+Math.random();
	div.style.left=left+"px";
	div.style.top=top+"px";
	div.style.width=width+"px";
	div.style.height=height+"px";
	div.style.zIndex=1001;
	div.innerHTML="<table class=divwinbar border=0 cellpadding=0 cellspaceing=0 bgcolor="+tcolor+"><tr><td onmousedown=StartDrag(this) onmouseup=StopDrag(this) onmousemove=Drag(this) id='popuptitle'>"+title+"</td><td id='closeWin' style='width:20px;cursor:pointer;' onclick='CloseWin(this)'><img src='http://www.ezhun.com/skin/images/cancel.gif' title=取消></td></tr></table>";
	var iframe=document.createElement("IFRAME");
	div.appendChild(iframe);
	iframe.style.width="100%";
	iframe.style.height="100%";
	iframe.frameBorder="no";
	iframe.allowtransparency="false";
	iframe.id="w"+Math.random();
	document.body.appendChild(div);
	if(document.all)
		document.frames[iframe.id].document.location.href=url;
	else
		document.getElementById(iframe.id).contentWindow.document.location.href=url;
}
function WinChange()
{
	var mask=document.getElementById("maskdiv");
	var html=document.documentElement;
	if(mask==null)return;
	mask.style.width="100%";
	mask.style.height=(Math.max(document.body.offsetHeight+20,html.offsetHeight-5)+160)+"px";
}
window.onresize=WinChange;
function ShowSelectObject(visible)
{
	var select=document.getElementsByTagName("SELECT");
	for(var i=0;i<select.length;i++)
	{
		if(visible&&select[i].getAttribute("_h"))
		{
			select[i].style.visibility="";
			select[i].removeAttribute("_h");
		}
		else if(select[i].style.visibility!="hidden")
		{
			select[i].style.visibility="hidden";
			select[i].setAttribute("_h","1");
		}
	}
	var objects=document.getElementsByTagName("OBJECT");
	for(var i=0;i<objects.length;i++)
	{
		if(visible&&objects[i].getAttribute("_h"))
		{
			objects[i].style.visibility="";
			objects[i].removeAttribute("_h");
		}
		else if(objects[i].style.visibility!="hidden")
		{
			objects[i].style.visibility="hidden";
			objects[i].setAttribute("_h","1");
		}
	}
	var iframes=document.getElementsByTagName("IFRAME");
	for(var i=0;i<iframes.length;i++)
	{
		if(visible&&iframes[i].getAttribute("_h"))
		{
			iframes[i].style.visibility="";
			iframes[i].removeAttribute("_h");
		}
		else if(iframes[i].style.visibility!="hidden")
		{
			iframes[i].style.visibility="hidden";
			iframes[i].setAttribute("_h","1");
		}
	}
}
function CloseWin(obj)
{
	var mask=document.getElementById("maskdiv");
	mask.parentNode.removeChild(mask);
	//mask.outerHTML="";
	var oldwin=obj.parentNode.parentNode.parentNode.parentNode;
	oldwin.parentNode.removeChild(oldwin);
	ShowSelectObject(true);
}
function SwitchTab(index)
{
	if($("td_right").getElementsByTagName("TABLE").length==0)return;
	var t,tr,f_tr,f_td,td;
	t=$("td_right").getElementsByTagName("TABLE")[0];
	f_td=t.rows[0].cells[index];
	td=t.rows[0].cells[(index+1)%2];
	f_tr=t.rows[index+1];
	tr=t.rows[(index+1)%2+1];
	f_td.className="tab_focus";
	td.className="tab";
	f_tr.style.display="";
	tr.style.display="none";
}
function ShowList(n,obj)
{	
	var o=obj.parentNode;
	o.cells[0].className="tab";
	o.cells[1].className="tab";
	obj.className="tab_focus";
	while(obj.tagName.toLowerCase()!="table")obj=obj.parentNode;
	obj.rows[1].style.display="none";
	obj.rows[2].style.display="none";
	obj.rows[n].style.display="";
}
//收藏
function favorite()
{
	window.external.AddFavorite(location.href, document.title);
}
function menu_my2(name, num, p) {
    var my;
    my = $(name);

    if (my.last == undefined) {
        var i = p;
        while (true) {
            var Cont = $("Cont" + name + i);
            if (Cont == null) break;
            if (Cont.style.display != "none") {
                if ($("Cont" + name + i + "1") == null)
                    my.last = i;
                else {
                    var j = 1;
                    while (true) {
                        var Cont = $("Cont" + name + i + j);
                        if (Cont == null) break;
                        if (Cont.style.display != "none") {
                            my.last = i + "" + j;
                            my.p = i;
                            break;
                        }
                        j++;
                    }
                }
                break;
            }
            i++;
        }
    }
    if (p != my.last && num != my.last) {
        var Menu = $("Menu" + name + my.last);
        var Cont = $("Cont" + name + my.last);
        var Img = Menu.getElementsByTagName('img')[0];
        Menu.className = "Menub";
        Cont.style.display = "none";
        Img.src = '/skin/images/sxt08.gif';
    }
    if (my.p != undefined && p != my.p && num != my.p) {
        var Menu = $("Menu" + name + my.p);
        var Cont = $("Cont" + name + my.p);
        var Img = Menu.getElementsByTagName('img')[0];
        Menu.className = "Menub";
        Cont.style.display = "none";
        Img.src = '/skin/images/sxt08.gif';
    }
    var Menu = $("Menu" + name + num);
    var Cont = $("Cont" + name + num);
    var Img = Menu.getElementsByTagName('img')[0];

    if (Cont.style.display == "none") {
        Menu.className = "Menub";
        Cont.style.display = "block";
        Img.src = '/skin/images/sxt09.gif';
    }
    else {
        Menu.className = "Menub";
        Cont.style.display = "none";
        Img.src = '/skin/images/sxt08.gif';
    }

    my.last = num;
    my.p = p;

}
//设置cookie
function SetCookie(name,value,expires,path,domain,secure)
{	
	var expDate = new Date();
	expDate.setDate(expDate.getDate()+expires);
	var expString = ((expires==null) ? "" : (";expires="+expDate.toGMTString()));
	var pathString = ((path==null) ? "" : (";path="+path));
	var domainString = ((domain==null) ? "" : (";domain="+domain));
	var secureString = ((secure==true) ? ";secure" : "" );
	document.cookie = name + "=" + escape(value) + expString + pathString + domainString + secureString;
}
function SetFocusChannel(obj)
{
    var ulChildren=obj.parentNode.parentNode.getElementsByTagName("li");
	for(i=0;i<ulChildren.length;i++)
	{
		ulChildren[i].className="";
	}
	obj.parentNode.className="selectd";
	document.title=obj.innerHTML+"_电视节目表_新浪网";
}