﻿var pxp_server	= null;
var default_dir = new String();	// 默认下载路径 
var hc;
var msg="";
var msg_flag=false;
var cookiekey="UCANTV_VT_COOKIE"
var clientHeight=0;
var wrong_uninstall=false;
var pgmaddcount=0;
var flagAllFile=false;
var languageFlag="cn";
//var urlfilename=new String();//另存为的页面里让路径带文件名
//var LOCALHOSTURLPGM=new String("http://192.168.0.178:8080/");
var LOCALHOSTURLPGM=new String("http://www.ucantv.com/");
//DownLoad Managerment Center Http Url:
var downloadMgrUrl=new String("http://central.ucantv.com/mediamgr/");
//BackStat Managerment Center Http Url:
var statMgrUrl=new String("http://www.ucantv.com/servlet/StatServlet?");
////DownLoad Managerment Center Http page;
var downloadMgrPage=new String("/mymedia.html");
var VersionNum="0.60.1024.1"   //设置最新版本的编号
// 选择路径
function select_dir()
{
	if( pxp_server == null )check_pxp();	
	$('pxp_Submit2').disabled=true;
	$('pxp_Submit3').disabled=true;
	$('pxp_Submit4').disabled=true;
	var a='';
	var b='';
	var c='';
	try{
	 a=$('pxp_Submit2').href;
	 b=$('pxp_Submit3').href;
	 c=$('pxp_Submit4').href;
	 $('pxp_Submit2').href="javascript:void(doNothing())";
	 $('pxp_Submit3').href="javascript:void(doNothing())";
	 $('pxp_Submit4').href="javascript:void(doNothing())";
	}
	catch(e){
	}
	var strpath = pxp_server.SelectSaveDir("请选择节目保存路径", "选择保存路径");
	if( strpath.length > 0 )
	{
		$('pxp_txtpath').innerText = strpath;
		
	}
	$('pxp_Submit2').disabled=false;
	$('pxp_Submit3').disabled=false;
	$('pxp_Submit4').disabled=false;
	try{
	  $('pxp_Submit2').href=a;
	  $('pxp_Submit3').href=b;
	  $('pxp_Submit4').href=c;
	}
	catch(e){
	}
}


// 开始下载 
function begin_download( savepath )
{   
	
	//alert(window.parent.frames["view"].document.getElementById("wmplaydiv"));
	if( pxp_server == null )
	{
		
		set_pxp();
	}
	
	if( pxp_server.BeginDownLoad( savepath ) != 0 )
		alert( '下载失败!');
		
	//clearlistwm("wmplaydiv");
}
function clearlistwm(a){
  var models=document.getElementById(a);
  while(models.childNodes.length>0){
    models.removeChild(models.childNodes[0]);
  }
}
// 取消下载 
function cancel_download()
{	
	pxp_server.CancelDownLoad();
}

// 初始化
function init()
{
	//if( pxp_server == null )
	//{
		//set_pxp();
	//}
	
	//default_dir = pxp_server.GetDefaultDataDir();
	
	//$('pxp_txtpath').innerText = default_dir;
	var datedir=pxp_server.GetVariable("datadir");
	
	if(datedir==null||datedir=="")datedir=pxp_server.GetDefaultDataDir();
	$('pxp_txtpath').innerText = datedir;
	$('pxp_txtfilename').innerText = urlfilename;
}
function init_all(a)
{
	//if( pxp_server == null )
	//{
		//set_pxp();
	//}
	
	//default_dir = pxp_server.GetDefaultDataDir();
	
	//$('pxp_txtpath').innerText = default_dir;
	var datedir=pxp_server.GetVariable("datadir");
	if(datedir==null||datedir=="")datedir=pxp_server.GetDefaultDataDir();
	$('pxp_txtpath').innerText = datedir;
	$('pxp_txtfilename').innerText = a;
}


	function show_down_dialog( surl )
	{
		//alert(surl.indexOf("file=")+5);
		//alert(surl.indexOf("|len"));
		//alert(surl);
		//urlfilename=surl.substring(surl.indexOf("file=")+5,surl.indexOf("|len"));
		//alert(document.getElementById("urlname").value);
		flagAllFile=false;
		var aaa=surl.substring(surl.indexOf("|file=")+6,surl.indexOf("|len"));
		if(surl.substring(surl.indexOf("|ffa=")+5,surl.lastIndexOf("|"))!=""){
		  urlfilename=surl.substring(surl.indexOf("|ffa=")+5,surl.lastIndexOf("|"))+aaa.substring(aaa.lastIndexOf("."));
		}
		else{
		  urlfilename=aaa;
		}
		var update_url="SPServ/webpxp/bottom/update.htm"
		var download_url="http://www.ucantv.com/download.htm";
	    var appendBody=false;
	    var dom=null;
	    if($("pxpDiagDownloadout")==null){
			dom=document.createElement("div");
			dom.setAttribute("id","pxpDiagDownloadout");
			appendBody=true;
		}
		else{
		   dom=$("pxpDiagDownloadout");
		}
			if(cp_flag=="default"){
			dom.innerHTML=plugin_html();
			}
			else if(cp_flag=="unextv"){
			 dom.innerHTML=plugin_html_unextv();
			}
			else if(cp_flag=="tcl"){			 dom.innerHTML=plugin_html_tcl();
			}
			if(appendBody)
            document.body.appendChild(dom);
		if(cp_flag=="unextv"){
			 update_url=LOCALHOSTURLPGM+"SPServ/webpxp/cctv/update.htm"
			 download_url="SPServ/webpxp/cctv/download.htm"
		}
		 else if(cp_flag=="tcl"){
			 download_url="http://www.ucantv.com/download_tcl.htm"
		}
	
		document.getElementById("urlname").value=urlfilename;
		document.getElementById("surlname").value=surl;
		/*得到隐藏域的值, 用于控制播放的文件
		surl0=surl.substring(surl.indexOf("hc=")+3,surl.indexOf("hc=")+19);
		try{
			window.parent.frames["bottom"].window.frames["view"].document.getElementById("playHashCode").value=surl0;
			window.parent.frames["bottom"].window.frames["view"].document.getElementById("playFlag").value="true";	
		}catch(e){
			window.opener.parent.window.frames["bottom"].window.frames["view"].document.getElementById("playHashCode").value=surl0;
			window.opener.parent.window.frames["bottom"].window.frames["view"].document.getElementById("playFlag").value="true";
		}
		*/
		var downloadFlag=true;
		try{
		  if(window.parent.frames["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display!=null&&window.parent.frames

["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display=="block"){
		
         downloadFlag=false;
     
		//以前clt的弹出窗口
		//pxp_server.ShowDownDlg(surl);
	      }
		
		}
		catch(e){
		 
		 downloadFlag=true;
		}
		
		if(downloadFlag){
		if( !check_pxp() ){
		   if(error_msg!=null&&error_msg!=""){
		    alert(error_msg);
		    return;
		  }
		  var locationStr =download_url;
      void(window.open(locationStr,null,"height=250,width=420,status=no,toolbar=no,menubar=no,location=no,scrollbars=no"));
      //add by xym cookie 
     
      addCookie(cookiekey,surl,2); 
      //alert(getCookie(cookiekey));
      //deleteCookie(cookiekey); 
      pgm_cookie();  
      //  
      
		  return;
		}
		
	   
		
		//alert(surl.substring(surl.indexOf("hc=")+3,surl.indexOf("hc=")+19));
		//alert(pxp_server.IsPgmExist(surl.substring(surl.indexOf("hc=")+3,surl.indexOf("hc=")+19)))
		if(pxp_server.IsPgmExist(surl.substring(surl.indexOf("hc=")+3,surl.indexOf("hc=")+19))==1){
			alert("该文件已下载过!");

			return;
		}
			
		//弹出层,用于点击节目后下载的另存为层
		createBgDiv();
		//alert(pxp_server.IsSigninOK)
	    if(pxp_server.IsSigninOK<0){
	     wait_diag(surl)
	     msg_flag=true;
	     window.setTimeout("PGM_Wait_FireWall()",6000);
	     return;
	    }
		download_diag(surl);
	
       }
	}
	
    function show_down_dialog_array( surls )
	{
	    flagAllFile=true;
	    pgmaddcount=0;
		//alert(surl.indexOf("file=")+5);
		//alert(surl.indexOf("|len"));
		//alert(surl);
		//urlfilename=surl.substring(surl.indexOf("file=")+5,surl.indexOf("|len"));
		//alert(document.getElementById("urlname").value);
		
		var update_url="SPServ/webpxp/bottom/update.htm"
		var download_url="http://www.ucantv.com/download.htm";
	     var appendBody=false;
	     var dom=null;
	     if($("pxpDiagDownloadout")==null){
			dom=document.createElement("div");
			dom.setAttribute("id","pxpDiagDownloadout");
			appendBody=true;
		 }
		 else{
		   dom=$("pxpDiagDownloadout");
		 }
			if(cp_flag=="default"){
			dom.innerHTML=plugin_html_all();
			}
			else if(cp_flag=="unextv"){
			 dom.innerHTML=plugin_html_unextv();
			}
			else if(cp_flag=="tcl"){
			 dom.innerHTML=plugin_html_tcl();
			}
			if(appendBody)
            document.body.appendChild(dom);
		
		if(cp_flag=="unextv"){
			 update_url=LOCALHOSTURLPGM+"SPServ/webpxp/cctv/update.htm"
			 download_url="SPServ/webpxp/cctv/download.htm"
		}
		 else if(cp_flag=="tcl"){
			 download_url="http://www.ucantv.com/download_tcl.htm"
		}
		
		urlfilename=new Array();
		
		surlarray=new Array();
		for(var i=0;i<surls.length;i++){
		  var surl=surls[i];
		  var aaa=surl.substring(surl.indexOf("|file=")+6,surl.indexOf("|len"));
		  if(surl.substring(surl.indexOf("|ffa=")+5,surl.lastIndexOf("|"))!=""){
		  urlfilename[i]=surl.substring(surl.indexOf("|ffa=")+5,surl.lastIndexOf("|"))+aaa.substring(aaa.lastIndexOf("."));
		  }
		  else{
		  urlfilename[i]=aaa;
		  }
		  surlarray[i]=surl;
		  
		}
		document.getElementById("urlname").value=urlfilename;
		document.getElementById("surlname").value=surlarray;
		
		var downloadFlag=true;
		try{
		  if(window.parent.frames["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display!=null&&window.parent.frames

["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display=="block"){
		
         downloadFlag=false;
     
		//以前clt的弹出窗口
		//pxp_server.ShowDownDlg(surl);
	      }
		
		}
		catch(e){
		 
		 downloadFlag=true;
		}
		if(downloadFlag){
		if( !check_pxp() ){
		   if(error_msg!=null&&error_msg!=""){
		    alert(error_msg);
		    return;
		  }
		  var locationStr =download_url;
      void(window.open(locationStr,null,"height=250,width=420,status=no,toolbar=no,menubar=no,location=no,scrollbars=no"));
      //add by xym cookie 
     
      //addCookie(cookiekey,surlarray,2); 
      //alert(getCookie(cookiekey));
      //deleteCookie(cookiekey); 
      //pgm_cookie();  
      //  
      
		  return;
		}
		
		
	    var array1=new Array();
	    var array2=new Array();
	    var newCount=0;
	    var temp_file="";
		for(var i=0;i<surlarray.length;i++){
		 
		  var surl=surlarray[i];
		  
		  if(pxp_server.IsPgmExist(surl.substring(surl.indexOf("hc=")+3,surl.indexOf("hc=")+19))==1){
		   temp_file=temp_file+" "+urlfilename[i];
			
		  }
		  else{
		   array1[newCount]=surlarray[i];
		   array2[newCount++]=urlfilename[i];
		  }
		
		 
	    
		}
		if(temp_file!="")alert("要下载的节目中存在已经下载过的节目，将不会重新下载！");
		surlarray=array1;
		urlfilename=array2;
		document.getElementById("urlname").value=urlfilename;
		document.getElementById("surlname").value=surlarray;
	    if(surlarray.length>0){
	      //弹出层,用于点击节目后下载的另存为层
	      createBgDiv();
	     if(pxp_server.IsSigninOK<0){
	     wait_diag(surl)
	     msg_flag=true;
	     window.setTimeout("PGM_Wait_FireWall_All()",6000);
	     return;
	     }
	      download_diag_all(surlarray,urlfilename);
	    }
		
		
		
	
       }
	}
//add xym 推荐节目	
function pgm_recommend(r_type,r_name){

  var r_url=window.location.href
  var r_flag=false;
  for(var i=0;i<CASE_ARRAY.length;i++){
    if(r_type==CASE_ARRAY[i]){
      r_flag=true;
      break;
    }
  }
  if(!r_flag)return;
  var download_url="http://www.ucantv.com/download.htm";
  var appendBody=false;
  var dom=null;
  if($("pxpDiagDownloadout")==null){
	dom=document.createElement("div");
	dom.setAttribute("id","pxpDiagDownloadout");
	appendBody=true;
  }
  else{
	dom=$("pxpDiagDownloadout");
  }
  if(cp_flag=="default"){
	dom.innerHTML=plugin_html();
  }
  else if(cp_flag=="unextv"){
	dom.innerHTML=plugin_html_unextv();
  }
  else if(cp_flag=="tcl"){			 
    dom.innerHTML=plugin_html_tcl();
  }
  if(appendBody)
    document.body.appendChild(dom);
  var downloadFlag=true;
  try{
    if(window.parent.frames["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display!=null&&window.parent.frames["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display=="block"){
	  downloadFlag=false;
    }
  }
  catch(e){
	downloadFlag=true;
  }
  if(downloadFlag){
    if( !check_pxp() ){
     if(error_msg!=null&&error_msg!=""){
		alert(error_msg);
		return;
	 }
	 var locationStr =download_url;
     void(window.open(locationStr,null,"height=250,width=420,status=no,toolbar=no,menubar=no,location=no,scrollbars=no"));
     return;
	}
   r_xml='<cmd type=\"magnet\" im=\"'+r_type+'\" url=\"'+r_url+'\" name=\"'+r_name+'"/>';
   if(pxp_server.IsSigninOK<0){
      createBgDiv();
	  wait_diag_recommend()
	  msg_flag=true;
	  window.setTimeout("PGM_Wait_FireWall_Recommend()",6000);
	  return;
	}
	pxp_server.ProcessCmd(r_xml);
	r_xml="";
  }
   
}
	
//add ch 用于设置当窗体大小改变后弹出下载的层显示的位置	
function onresizeEvent(){
	
	if(document.getElementById("pxpDiagDownload")!=null){
		if(document.getElementById("backgroundDiv")!=null && document.getElementById("backgroundDiv").style.display==""){
		//alert("ok");
		with(document.getElementById("pxpDiagDownload").style){
                  top = (document.body.clientHeight-84)/2
                  left = (document.body.clientWidth-300)/2;
              }
	}
	}
}	
	
	
	
//当用户下载文件时弹出的层,用于用户选路径或
function createBgDiv(){
		if(document.getElementById("backgroundDiv")==null){
        id = "backgroundDiv";
        offHeight = window.screen.height;
        var div = document.createElement("DIV");
        div.id = id;
        div.style.left = 0;
        div.style.top = 0;
        div.style.width=document.body.scrollWidth;
        div.style.height = document.body.scrollHeight;
        div.style.position = "absolute";
        div.style.display = "";
        div.style.zIndex = "999";
        div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=1)";
        div.style.backgroundColor="#EEEEEE";
        //div.style.display="none";
        document.body.appendChild(div);
        }else{
        	document.getElementById("backgroundDiv").style.display="";
        }
        
    }
 function encodeURL(url){
 if (window.RegExp && window.encodeURIComponent)
 {
     return encodeURIComponent(url); 
 } 
}
function addpgm(){
	var flagfilename=document.getElementById("pxp_txtfilename").value;
	//修改 dhh 20080708
/*
	if((flagfilename.length>30)||(flagfilename.indexOf("。")!=-1)||(flagfilename.indexOf("，")!=-1)||(flagfilename.indexOf(",")!=-1)||

(flagfilename.indexOf("\\")!=-1) || flagfilename==""||(flagfilename.indexOf("&")!=-1)||(flagfilename.indexOf("<")!=-1)||(flagfilename.indexOf(">")!=-1)||

(flagfilename.indexOf("\"")!=-1)||(flagfilename.indexOf(".")!=flagfilename.lastIndexOf("."))){
		alert("您输入的文件名格式不正确!");
		return
	}*/
	var serverFile=document.getElementById("pxpDiagDownload").value.substring(document.getElementById("pxpDiagDownload").value.indexOf("file=")

+5,document.getElementById

("pxpDiagDownload").value.indexOf("|len"));
	var serverHashcode=document.getElementById("pxpDiagDownload").value.substring(document.getElementById("pxpDiagDownload").value.indexOf("hc=")

+3,document.getElementById

("pxpDiagDownload").value.indexOf("|ffa"));
 try{
   PGM_Down_Stat(serverHashcode,serverFile)
 }
 catch(e){
  	alert(e)
}
	pxp_server.AddPgm(document.getElementById("pxpDiagDownload").value,document.getElementById("pxp_txtpath").value,document.getElementById

("pxp_txtfilename").value,serverFile);
	document.getElementById("pxpDiagDownload").style.display="none";
	if(document.getElementById("backgroundDiv")!=null){
		document.getElementById("backgroundDiv").style.display="none";
	}
	pxp_server=null;
	if(cp_flag=="unextv"){
	  window.opener = null;
	  window.open("","_self");
	  window.close();
	}
	
}
function addpgmall(){
    pgmaddcount++;
	var flagfilename=document.getElementById("pxp_txtfilename").value;
	//修改 dhh 20080708
/*	if((flagfilename.length>30)||(flagfilename.indexOf("。")!=-1)||(flagfilename.indexOf("，")!=-1)||(flagfilename.indexOf(",")!=-1)||

(flagfilename.indexOf("\\")!=-1) || flagfilename==""||(flagfilename.indexOf("&")!=-1)||(flagfilename.indexOf("<")!=-1)||(flagfilename.indexOf(">")!=-1)||

(flagfilename.indexOf("\"")!=-1)||(flagfilename.indexOf(".")!=flagfilename.lastIndexOf("."))){
		alert("您输入的文件名格式不正确!");
		return
	}*/
	var serverFile=document.getElementById("pxpDiagDownload").value.substring(document.getElementById("pxpDiagDownload").value.indexOf("file=")

+5,document.getElementById

("pxpDiagDownload").value.indexOf("|len"));
	var serverHashcode=document.getElementById("pxpDiagDownload").value.substring(document.getElementById("pxpDiagDownload").value.indexOf("hc=")

+3,document.getElementById

("pxpDiagDownload").value.indexOf("|ffa"));
 try{
   PGM_Down_Stat(serverHashcode,serverFile)
 }
 catch(e){
  	alert(e)
}
	pxp_server.AddPgm(document.getElementById("pxpDiagDownload").value,document.getElementById("pxp_txtpath").value,document.getElementById

("pxp_txtfilename").value,serverFile);
   
	document.getElementById("pxpDiagDownload").style.display="none";
	if(document.getElementById("backgroundDiv")!=null){
		document.getElementById("backgroundDiv").style.display="none";
	}
	try{
	  surlarray=surlarray.split(',');
	}
	catch(e){
	}
	try{
	  urlfilename=urlfilename.split(',');
	}
	catch(e){
	}
	if(pgmaddcount<surlarray.length){
	 if(window.confirm("多文件下载使用同样的存储方式?")==0){
	    download_diag_all(surlarray[pgmaddcount],urlfilename[pgmaddcount]);
	    flagAllFile=true;
         return;
	    }
    else{
      while(pgmaddcount<surlarray.length){
        serverFile=surlarray[pgmaddcount].substring(surlarray[pgmaddcount].indexOf("file=")+5,surlarray[pgmaddcount].indexOf("|len"));
        serverHashcode=surlarray[pgmaddcount].substring(surlarray[pgmaddcount].indexOf("hc=")+3,surlarray[pgmaddcount].indexOf("|ffa"));
        PGM_Down_Stat(serverHashcode,serverFile);
        pxp_server.AddPgm(surlarray[pgmaddcount],document.getElementById("pxp_txtpath").value,urlfilename[pgmaddcount],serverFile);
        pgmaddcount++
     }
     pgmaddcount=0;
    }
    }
    pxp_server=null;
	if(cp_flag=="unextv"){
	  window.opener = null;
	  window.open("","_self");
	  window.close();
	}
}
function hid(){
	document.getElementById("pxpDiagDownload").style.display="none";
	if(document.getElementById("backgroundDiv")!=null){
		document.getElementById("backgroundDiv").style.display="none";
	}
	pxp_server=null;
}


function versions(){
	var version1=pxp_server.GetVersion();
	if(version1==""){
	 wrong_uninstall=true;
	return false;
	}
	var versionArray1=version1.split(".");
　　var versionArray2=VersionNum.split(".");
    if(versionArray1[2].length<3){
      return false;
    }
	if(versionArray1[2].length!=4){
		versionArray1[2]="0"+versionArray1[2]
	}
	if(versionArray2[2].length!=4){
			versionArray2[2]="0"+versionArray2[2]
	}
   var oldVersion_temp=versionArray1[0]+""+versionArray1[1]+""+versionArray1[2]+""+versionArray1[3];
   var newVersion_temp=versionArray2[0]+""+versionArray2[1]+""+versionArray2[2]+""+versionArray2[3];
   var oldVersion="";
   var newVersion="";
   for(var i=1;i<=oldVersion_temp.length;i++){
	 if(oldVersion_temp.substring(i-1,i)!="0"){
		oldVersion=oldVersion_temp.substr(i-1);
		break;
	 }
   }
   for(var i=1;i<=newVersion_temp.length;i++){
	 if(newVersion_temp.substring(i-1,i)!="0"){
		newVersion=newVersion_temp.substr(i-1);
		break;
	 }
   }
	var a=eval(oldVersion);
	var b=eval(newVersion);
	if(a<b){
	  return false;
	}
	else{
	return true;
	}
	
}

//add by xym 
//add cookie
function addCookie(name,value,expireHours){
   var cookieString=name+"="+escape(value);
    //判断是否设置过期时间
   if(expireHours>0){
   var date=new Date();
   date.setTime(date.getTime()+expireHours*3600*1000); // 转换为毫秒
   cookieString=cookieString+"; expires="+date.toGMTString()+";path=/";
}
   document.cookie=cookieString;
}
//GetCookie
function getCookie(name){
  var strCookie=document.cookie;
  var arrCookie=strCookie.split("; "); // 将多cookie切割为多个名/值对
  for(var i=0;i<arrCookie.length;i++){ // 遍历cookie数组，处理每个cookie对
  var arr=arrCookie[i].split("="); // 找到名称为userId的cookie，并返回它的值
  if(arr[0]==name)
   return unescape(arr[1]);
  }
  return "";
}
//DeleteCookie
function deleteCookie(name){
  var date=new Date();
  date.setTime(date.getTime()-10000); // 删除一个cookie，就是将其过期时间设定为一个过去的时间
  document.cookie=name+"=v; expires="+date.toGMTString()+";path=/";
}
//cookie Timer()
function pgm_cookie(){
  var s=getCookie(cookiekey);
   var downloadFlag=true;
   try{
		if(window.parent.frames["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display!=null&&window.parent.frames

["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display=="block"){
		
         downloadFlag=false;
     
		//以前clt的弹出窗口
		//pxp_server.ShowDownDlg(surl);
	      }
		
		}
		catch(e){
		 downloadFlag=true;
		}
		try {
		var temp=window.parent.frames["bottom"].frames["view"]; 
                var diag_flag=null;
                try{
                    diag_flag=window.parent.frames["bottom"].frames["view"].document.getElementById("diag_flag");	
                    if(s!=""&&downloadFlag&&diag_flag!=null&&diag_flag.value=="yes"&&check_pxp()&&versions()){
                        show_down_dialog(s);
                        deleteCookie(cookiekey);
                     }
                    else if(s==""&&downloadFlag&&diag_flag!=null&&diag_flag.value=="yes"&&check_pxp()&&versions()){
                       return;
                     }
                    else{
                     window.setTimeout("pgm_cookie()",800);
                    }
               }
              catch(e){
               window.setTimeout("pgm_cookie()",800);
               }   
                }
         catch(e){
                    if(s!=""&&check_pxp()){
                      show_down_dialog(s);
                      deleteCookie(cookiekey);
                   }
                   else if(s==""&&check_pxp()){
                      return;
                   }
                   else{
                   window.setTimeout("pgm_cookie()",800);
                   }
                }
 		
  
  
}
//cookie Timer()
function pgm_cookie_all(){
  var s=getCookie(cookiekey).split;
   var downloadFlag=true;
   try{
		if(window.parent.frames["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display!=null&&window.parent.frames

["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display=="block"){
		
         downloadFlag=false;
     
		//以前clt的弹出窗口
		//pxp_server.ShowDownDlg(surl);
	      }
		
		}
		catch(e){
		 downloadFlag=true;
		}
		try {
		var temp=window.parent.frames["bottom"].frames["view"]; 
                var diag_flag=null;
                try{
                    diag_flag=window.parent.frames["bottom"].frames["view"].document.getElementById("diag_flag");	
                    if(s!=""&&downloadFlag&&diag_flag!=null&&diag_flag.value=="yes"&&check_pxp()&&versions()){
                        show_down_dialog(s);
                        deleteCookie(cookiekey);
                     }
                    else if(s==""&&downloadFlag&&diag_flag!=null&&diag_flag.value=="yes"&&check_pxp()&&versions()){
                       return;
                     }
                    else{
                     window.setTimeout("pgm_cookie()",800);
                    }
               }
              catch(e){
               window.setTimeout("pgm_cookie()",800);
               }   
                }
         catch(e){
                    if(s!=""&&check_pxp()){
                      show_down_dialog(s);
                      deleteCookie(cookiekey);
                   }
                   else if(s==""&&check_pxp()){
                      return;
                   }
                   else{
                   window.setTimeout("pgm_cookie()",800);
                   }
                }
 		
  
  
}
//movie.jsp onload()作为更新时弹出刚才点击的节目,要求满足下面页面已经完全加载完成的条件
function page_onload(){
   var s=getCookie(cookiekey);
   var downloadFlag=true;
   try{
		if(window.parent.frames["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display!=null&&window.parent.frames

["bottom"].frames["view"].document.getElementById("logoutInfoDiv").style.display=="block"){
		
         downloadFlag=false;
     
		//以前clt的弹出窗口
		//pxp_server.ShowDownDlg(surl);
	      }
		
		}
		catch(e){
		 downloadFlag=true;
		}
		var diag_flag=null;
	try{
	  diag_flag=window.parent.frames["bottom"].frames["view"].document.getElementById("diag_flag");	
	  if(s!=""&&downloadFlag&&diag_flag!=null&&diag_flag.value=="yes"&&check_pxp()&&versions()){
      show_down_dialog(s);
      deleteCookie(cookiekey);
   }
   else{
   window.setTimeout("page_onload()",800);
   }
	
	}
	catch(e){
	  window.setTimeout("page_onload()",800);
	}
   
   
}
//
//add by xym
function download_diag(surl){
    var httd=pxp_server.IsPgmExist(surl.substring(surl.indexOf("hc=")+3,surl.indexOf("hc=")+19));
    httd=pxp_server.IsPgmExist(surl.substring(surl.indexOf("hc=")+3,surl.indexOf("hc=")+19));
    httd=pxp_server.IsPgmExist(surl.substring(surl.indexOf("hc=")+3,surl.indexOf("hc=")+19));
   if(httd==1){
			      with(document.getElementById("pxpDiagDownload").style){
                  zIndex = 1000; 
                  top = (document.body.clientHeight-84)/2+document.body.scrollTop
                  left = (document.body.clientWidth-300)/2;
          
                  display = "none";
                  position = "absolute";
                  height="200px";
	                width="360px";
                }
			             alert("该文件已下载过!");
                        try{
			                  document.getElementById("backgroundDiv").style.display="none";
                         }
                        catch(e){
                        }
			             return;
    }
   document.getElementById("pxpDiagDownload").value=surl;

   if(msg!="")
   document.getElementById("pxpDiagDownload").innerHTML=msg;
   init();
   if(clientHeight==0){
     clientHeight=document.body.clientHeight;
   }
   
   with(document.getElementById("pxpDiagDownload").style){
                  zIndex = 1000; 
                  top = (document.body.clientHeight-84)/2+document.body.scrollTop
                  left = (document.body.clientWidth-300)/2;
          
                  display = "block";
                  position = "absolute";
                  height="200px";
	              width="360px";
    }
    
}
function download_diag_all(surl,urlname){
   try{
    surl=surl.split(',');
   
   }
   catch(e){
   }
   try{
     urlname=urlname.split(',');
   }
   catch(e){
   }
   var array1=new Array();
   var array2=new Array();
   var newCount=0;
   var temp_file="";
   for(var i=0;i<surl.length;i++){
		 
		  var surls=surl[i];
		  
		  if(pxp_server.IsPgmExist(surls.substring(surls.indexOf("hc=")+3,surls.indexOf("hc=")+19))==1){
		   temp_file=temp_file+" "+urlname[i];
			
		  }
		  else{
		   array1[newCount]=surl[i];
		   array2[newCount++]=urlname[i];
		  }
		
		 
	    
	}
   if(temp_file!="")alert("要下载的节目中存在已经下载过的节目，将不会重新下载！");
   surl=array1;
   urlname=array2;
   document.getElementById("urlname").value=urlname;
   document.getElementById("surlname").value=surl;
   //是否还存在可以下载的
   if(surl.length>0){
   document.getElementById("pxpDiagDownload").value=surl[0];
   if(msg!="")
   document.getElementById("pxpDiagDownload").innerHTML=msg;
   init_all(urlname[0]);
   if(clientHeight==0){
     clientHeight=document.body.clientHeight;
   }
   
    with(document.getElementById("pxpDiagDownload").style){
                  zIndex = 1000; 
                  top = (document.body.clientHeight-84)/2+document.body.scrollTop
                  left = (document.body.clientWidth-300)/2;
          
                  display = "block";
                  position = "absolute";
                  height="200px";
	              width="360px";
     }
    }
    else{
     
       try{
			  document.getElementById("backgroundDiv").style.display="none";
			 
           }
       catch(e){
       }
       try{
             with(document.getElementById("pxpDiagDownload").style){
                  zIndex = 1000; 
                  top = (document.body.clientHeight-84)/2+document.body.scrollTop
                  left = (document.body.clientWidth-300)/2;
          
                  display = "none";
                  position = "absolute";
                  height="200px";
	                width="360px";
              }
       }
       catch(e){
       }
    }
    
}
function error_diag(a,surl){
   if(clientHeight==0){
     clientHeight=document.body.clientHeight;
   }
   document.getElementById("pxpDiagDownload").value=surl;
   document.getElementById("pxpDiagDownload").innerHTML=PXP_WaitOver_Button(a);
   with(document.getElementById("pxpDiagDownload").style){
                  zIndex = 1000; 
                  top = (clientHeight-84)/2+document.body.scrollTop;
                  left = (document.body.clientWidth-300)/2;
                  backgroundColor = "#ffffff"; 
                  display = "block";
                  position = "absolute";
                  height="40px";
	              width="360px";
    }
}
function wait_diag(surl){
   if(clientHeight==0){
     clientHeight=document.body.clientHeight;
   }
   document.getElementById("pxpDiagDownload").value=surl;
   msg=document.getElementById("pxpDiagDownload").innerHTML;
   if(cp_flag=="default")
   document.getElementById("pxpDiagDownload").innerHTML=PXP_WaitMsg("优看影视正在初始化，请稍候...如果长期等待，请刷新页面");
   else
   document.getElementById("pxpDiagDownload").innerHTML=PXP_WaitMsg("WEBPXP正在初始化，请稍候...如果长期等待，请刷新页面");
   with(document.getElementById("pxpDiagDownload").style){
                  zIndex = 1000; 
                  top = (clientHeight-84)/2+document.body.scrollTop;
                  left = (document.body.clientWidth-300)/2;
                  backgroundColor = "#ffffff"; 
                  display = "block";
                  position = "absolute";
                  height="30px";
	              width="360px";
    }
}
function wait_diag_recommend(){
 if(clientHeight==0){
     clientHeight=document.body.clientHeight;
   }
   if(cp_flag=="default")
   document.getElementById("pxpDiagDownload").innerHTML=PXP_WaitMsg("优看影视正在初始化，请稍候...如果长期等待，请刷新页面");
   else
   document.getElementById("pxpDiagDownload").innerHTML=PXP_WaitMsg("WEBPXP正在初始化，请稍候...如果长期等待，请刷新页面");
   with(document.getElementById("pxpDiagDownload").style){
                  zIndex = 1000; 
                  top = (clientHeight-84)/2+document.body.scrollTop;
                  left = (document.body.clientWidth-300)/2;
                  backgroundColor = "#ffffff"; 
                  display = "block";
                  position = "absolute";
                  height="30px";
	              width="360px";
    }
}
function PXP_WaitOver_Button(a){
     var msg1='';
	 msg1=msg1+'<div align="center"><table>';
	 if(cp_flag=="default")
	 msg1=msg1+'<tr align="center"><td><font size="2">优看影视初始化失败..错误:'+getErrorDesc(a+"")+' 代号:'+a+'请刷新重试！</font></td><tr>'
	 else
	 msg1=msg1+'<tr align="center"><td><font size="2">WEBPXP初始化失败..错误:'+getErrorDesc(a+"")+' 代号:'+a+'请刷新重试！</font></td><tr>'
	 msg1=msg1+'<tr align="center"><td><input type="button" value="取消" onclick="hid();"></td><tr>'
	 msg1=msg1+'</table><div>';
	 return msg1;
}
//定时刷新,防止被防火墙拦截(不是通过管理页进入的方式,如CCTV);
function PGM_Wait_FireWall(){
  msg_flag=false;
  var a=null;
  try{
  a=document.getElementById("pxpDiagDownload");
  }
  catch(e){
   return;
  }
  
  if(a.style.display=="block"&&!msg_flag){
    if(pxp_server.IsSigninOK()==0){
      download_diag(document.getElementById("surlname").value);
	  return;
    }
     if(pxp_server.IsSigninOK()<-1){
        error_diag(pxp_server.IsSigninOK());
        pxp_server.ServiceExit();
        return;
     }
  }
  else{
   return;
  }
  window.setTimeout("PGM_Wait_FireWall()",1000);
}
//启动推荐时等待防火墙
function PGM_Wait_FireWall_Recommend(){
  msg_flag=false;
  var a=null;
  try{
  a=document.getElementById("pxpDiagDownload");
  }
  catch(e){
   return;
  }
  if(a.style.display=="block"&&!msg_flag){
    if(pxp_server.IsSigninOK()==0){
      if(r_xml!="")pxp_server.ProcessCmd(r_xml);
      with(document.getElementById("pxpDiagDownload").style){
        zIndex = 1000; 
        top = (clientHeight-84)/2+document.body.scrollTop;
        left = (document.body.clientWidth-300)/2;
        display = "none";
        position = "absolute";
        height="200px";
	    width="360px";
       }
      try{
	  document.getElementById("backgroundDiv").style.display="none";
      }
      catch(e){
      }
	  return;
    }
     if(pxp_server.IsSigninOK()<-1){
        error_diag(pxp_server.IsSigninOK());
        pxp_server.ServiceExit();
        return;
     }
  }
  else{
   return;
  }
  window.setTimeout("PGM_Wait_FireWall_Recommend()",1000);
}
//启动推荐时推荐事件产程后处理
function pgm_event_recommend(){
  msg_flag=false;
  var a=null;
  try{
  a=document.getElementById("pxpDiagDownload");
  }
  catch(e){
   return;
  }
  if(a.style.display=="block"&&!msg_flag){
      if(r_xml!="")pxp_server.ProcessCmd(r_xml);
      with(document.getElementById("pxpDiagDownload").style){
        zIndex = 1000; 
        top = (clientHeight-84)/2+document.body.scrollTop;
        left = (document.body.clientWidth-300)/2;
        display = "none";
        position = "absolute";
        height="200px";
	    width="360px";
       }
      try{
	  document.getElementById("backgroundDiv").style.display="none";
      }
      catch(e){
      }
	  return;
  }
  else{
   return;
  }
}
function PGM_Wait_FireWall_All(){
  msg_flag=false;
  var a=null;
  try{
  a=document.getElementById("pxpDiagDownload");
  }
  catch(e){
   return;
  }
  
  if(a.style.display=="block"&&!msg_flag){
    if(pxp_server.IsSigninOK()==0){
      download_diag_all(document.getElementById("surlname").value,document.getElementById("urlname").value);
	  return;
    }
     if(pxp_server.IsSigninOK()<-1){
        error_diag(pxp_server.IsSigninOK());
        pxp_server.ServiceExit();
        return;
     }
  }
  else{
   return;
  }
  window.setTimeout("PGM_Wait_FireWall_All()",1000);
}
//统计功能Get
function PGM_Down_Stat(serverHashcode,serverFile){	 
   var URL=statMgrUrl; 
   var files=encodeURL(serverFile);
   var url=statMgrUrl+"time="+Math.random()+"&type=DOWNPGM&hashcode="+serverHashcode+"&file="+files; 
   var js_obj=null;   
   if(document.getElementById("pxp_stat")!=null){
 
    js_obj=	document.getElementById("pxp_stat") ;
     document.body.removeChild(js_obj);
   } 
   js_obj= document.createElement( "script" ); 
   js_obj.setAttribute( "id" , "pxp_stat");
　 js_obj.setAttribute( "src" , url); 
　 document.body.appendChild(js_obj);
}

//POST
function PGM_Down_Stat_Post(serverHashcode,serverFile){	 
   try{
    var URL=statMgrUrl; 
    var files=encodeURL(serverFile);
    var url=statMgrUrl+"time="+Math.random()+"&type=DOWNPGM&hashcode="+serverHashcode+"&file="+files; 
    document.getElementById("pxp_hc").value=serverHashcode;
    var forms=null;
  
     forms=document.getElementById("pxp_stat_form");
     forms.action=url;
     void(forms.submit());
  
   }
   catch(e){
   }
   
   
   
  
  
  
}



























