﻿var _xmlDoc = null;
 
function IsIE()
{
    var retValue = false
    if (window.navigator.userAgent.indexOf("MSIE")>=1)
    //如果浏览器为IE
    {
        retValue = true;
    }
    else //如果浏览器为Firefox
    {
        if(window.navigator.userAgent.indexOf("Firefox")>=1)
        {
           retValue =  false;
        }
    }
    
    return retValue;
} 
 
function $GetObj(paramId){
	return document.getElementById(paramId);
}
 
//Ajax 异步调用
var req;

function retrieveURL(url) {

    if (window.XMLHttpRequest) { // Non-IE browsers ,IE 7 也已经支持
	
     req = new XMLHttpRequest();

     req.onreadystatechange = processStateChange;

     try {
        req.open("POST", url, true);
     }
	catch (e){
       alert(e);
     }
 	req.send(null);
    } 
    else if (window.ActiveXObject) { // IE
	
      req = new ActiveXObject("Microsoft.XMLHTTP");

      if (req) {

        req.onreadystatechange = processStateChange;

        req.open("GET", url, true);

        req.send();

      }
    }
}

function processStateChange() {
   if (req.readyState == 4) { // Complete

   if (req.status == 200) { // OK response
   
       //$("load_pic_div").style.display = "none";
	  
	   //alert(req.responseText)
	  _xmlDoc = req.responseXML;
	 	  
	  var ppNodes;
	  
	  if(document.all){
	    ppNodes = _xmlDoc.selectNodes("//Root/Entry");
	  }
	  else{
	    ppNodes = _xmlDoc.getElementsByTagName("Entry");
	  }
	  
	  GerList(ppNodes);
    }else{
        alert("Problem: " + req.statusText);
	}
   }
}
 
function showResult(sTmp,childCount)
{	
	if(sTmp==0 || childCount>0){
		var address = "/Web/TvLm.ashx?param=" + sTmp;
		retrieveURL(address);

		//显示点击父栏目的简介
		if(sTmp!=0){
		    //$("ShowMSS").innerHTML = LmContentList[sTmp];
		    
		    //简介显示
		    $GetObj("TvLmImg").style.display = "block";
		    $GetObj("TvLmText").style.display = "block";
		    //$("TvLmImg").innerHTML = LmContentList[sTmp];
		    if(LmContentList[sTmp]!=""){
		        $GetObj("TvLmImg").innerHTML = "<img src='"+ LmContentList[sTmp] +"'>";
		        $GetObj("TvLmText").innerHTML = LmContentList_Text[sTmp];
		    }
		    else{
		        $GetObj("TvLmText").innerHTML = LmContentList_Text[sTmp]; 
		    }
		    
		    //隐藏视频显示以及视频列表
            $GetObj("container").style.display = "none";
            $GetObj("MovieList").style.display = "none";
			//alert(LmContentList[sTmp]);
		}
		else{
		    try{
		        $GetObj("ShowMSS").innerHTML = "";
		        
		        //播放器显示
		        $GetObj("TvLmImg").style.display = "none";
		        $GetObj("TvLmText").style.display = "none";
                $GetObj("container").style.display = "block";
                $GetObj("MovieList").style.display = "block";
		    }
		    catch(e){
		        ;
		    }
		}
	}
	else{
	    //$("ShowMSS").innerHTML = LmContentList[sTmp];
	    
	    //简介显示
        $GetObj("TvLmImg").style.display = "block";
        $GetObj("TvLmText").style.display = "block";
        //$("TvLmImg").innerHTML = LmContentList[sTmp];
        
        if(LmContentList[sTmp]!=""){
		      $GetObj("TvLmImg").innerHTML = "<img src='"+ LmContentList[sTmp] +"'>"; 
		      $GetObj("TvLmText").innerHTML = LmContentList_Text[sTmp];
		}
		else{
		      $GetObj("TvLmText").innerHTML = LmContentList_Text[sTmp]; 
		}
		    
        $GetObj("container").style.display = "none";
        $GetObj("MovieList").style.display = "none";
	    
		//alert(LmContentList[sTmp]);
	}
}


//简介内容
var LmContentList = new Array();
var LmContentList_Text = new Array();

function GerList(NodeList)
{
	var parentNode = $GetObj("_LmList");
	var LmTitleNode = $GetObj("_LmName");

	//先删除节点
	/*
	var childs = parentNode.childNodes;  
	for(var i = 0; i < childs.length; i++) {  
		//alert(childs[i].nodeName);  
		parentNode.removeChild(childs[i]);  
	} */

	//再创建节点

	var sLine = 0;
	for(var i=0;i<NodeList.length;i++){
		if(i==0){
			$GetObj("_LmList").innerHTML = "";
			$GetObj("_LmName").innerHTML = "";
			if(NodeList[0].getAttribute("parentLm")=="直播全频道"){
			    var LinkNode = document.createElement("A");
			    LinkNode.setAttribute("href","/Web/WebView.aspx?Lm_Id=176");
			   
			    //不区分浏览器，样式都加上
			    LinkNode.setAttribute("className","Chanel_Text");
			    LinkNode.setAttribute("class","Chanel_Text");
			    	    
			    LinkNode.appendChild(document.createTextNode("直播全频道"));
			    LmTitleNode.appendChild(LinkNode);
			}
			else{
			    LmTitleNode.appendChild(document.createTextNode(NodeList[0].getAttribute("parentLm")));
			}
		}

		var nodeChildList = NodeList[i].childNodes;
		var LinkNode = document.createElement("A");
		LinkNode.setAttribute("href","javascript:void showResult(\""+ nodeChildList[1].firstChild.nodeValue +"\",\""+ NodeList[i].getAttribute("ChildCount") +"\")");
		
		 //不区分浏览器，样式都加上
		LinkNode.setAttribute("className","Chanel_Text");
		LinkNode.setAttribute("class","Chanel_Text");
		
		LinkNode.appendChild(document.createTextNode(nodeChildList[0].firstChild.nodeValue));

		//alert(nodeChildList[3].text)
		LmContentList[parseInt(nodeChildList[1].firstChild.nodeValue)] = (nodeChildList[2].firstChild==null)?"":nodeChildList[2].firstChild.nodeValue; //图片数组
        LmContentList_Text[parseInt(nodeChildList[1].firstChild.nodeValue)] = (nodeChildList[3].firstChild ==null)?"暂无描述":nodeChildList[3].firstChild.nodeValue;    //文字数组
        
		//alert(nodeChildList[0].text + "\n" + nodeChildList[0].text.length)

		parentNode.appendChild(LinkNode);

		if(nodeChildList[0].firstChild.nodeValue.length==2){
			if(sLine==0){
				sLine++;
				parentNode.appendChild(document.createTextNode("   "));
			}
			else{
				sLine = 0;
				parentNode.appendChild(document.createElement("br"));
			}
		}
		else{
			if(nodeChildList[0].firstChild.nodeValue.length>2){
				parentNode.appendChild(document.createElement("br"));
			}
		}
}
	

	//添加操作栏
	try{
		parentNode.appendChild(document.createElement("hr"));
		if(NodeList[0].getAttribute("parentLm")!="直播全频道"){
			var LinkNode = document.createElement("A");
			LinkNode.setAttribute("href","javascript:void showResult(\""+ NodeList[0].getAttribute("UpLevelLmId") +"\")");
			
			 //不区分浏览器，样式都加上
		    LinkNode.setAttribute("className","Chanel_Text");
		    LinkNode.setAttribute("class","Chanel_Text");
			
			LinkNode.appendChild(document.createTextNode("->返回"));
			parentNode.appendChild(LinkNode);
		}
	}
	catch(e){
		;
	}
}

