/// <reference path="Extjs_Intellisense.js" />
/// <reference path="src/data/XmlStore.js" />
/// <reference path="addjs/Base.js" />
/// <reference path="addjs/XmlTreeLoader.js" />
/// <reference path="addjs/defvar.js" />
//by zfuwen

function ChangeIpFormInt(strInt)
{
    strInt=parseInt(strInt);
    var strip="";
    var b1=(strInt&0xff);
    var b2=((strInt>>8)&0xff);
    var b3=((strInt>>16)&0xff);
    var b4=((strInt>>24)&0xff);
    strip=""+b1+"."+b2+"."+b3+"."+b4;
    return strip;
}





//var have_AdvPTZRight=0;//云台
//var have_PTZRight=0;//云台
//var have_DevMNGRight=0;//设备管理
//var have_SURVEILRight=0;//视频监控
//var have_USRMNGRight=0;//用户管理
//var have_VideoReplayRight=0;//回放
//var have_AudioControlRight=0;//对讲
//var have_BCControlRight=0;//广播
//var have_TVWallRight=0;//电视
//var have_AlarmMngRight=0;//告警管理
//var have_ContentDeleteRight=0;//录像管理



function HtmlEncode(strmsg)
{
    strmsg=strmsg.replace(/&/g,"&amp;");
    strmsg=strmsg.replace(/\"/g,"&quot;");
    strmsg=strmsg.replace(/>/g,"&gt;");
    strmsg=strmsg.replace(/</g,"&lt;");
    return strmsg;
}




//<Response Code="33" MasterDevCount="9" Result ="0">
//<Master Id="860030001" Name="凌总桌上测试机"  Type="3" GroupId="860030001"  DomainId="86003" DevCount="3"  IpAddr="1683531968"  CommPort="1033"  LoginName="admin"  LoginPassword="123456"  PTZRight="1"  SURVEILRight="1"  VideoReplayRight="1"  AudioControlRight="1"  BCControlRight="1"  AlarmMngRight="1"  >
//<Camera Id="860030002" Name="凌总桌上测试机" MasterId="860030001" Type="1" IsDoubleStream="1" WithPTZ="1" WithAudioIn="1" WithAudioOut="1" VSSId="4" ConnType="0" MFSCmdIP="0" MFSCmdPort="0" IpAddr="1683531968" CommPort="1033" LoginName="admin" LoginPassword="123456" VSSCmdIP="-1437030208" VSSCmdPort="554" />
Ext.app.CameraLoader = Ext.extend(Ext.ux.tree.TreeFromXml,{
    reader:new Ext.data.XmlReader({record: 'Master/Camera'}),
    processAttributes : function(attr)
    {
        if(attr.tagName=="Response")
        {
            attr.id=this.AddId+"root";
            //attr.text = "<span class='x-treenode-zfw-group1 x-tree-node-indent x-tree-node-el' >设备列表</span>";
            attr.text = GetDefaultLang("lang_devlistname","设备列表");
            attr.leaf = false;
            attr.expanded=true;
            attr.allowDrag=false;
            attr.cls=" x-treenode-zfw-group1";
            attr.icon="resources/images/camera/groupnode.gif";
        }else if(attr.tagName=="Master")
        {//主设备
            attr.id=this.AddId+"g"+attr.Id;
            //attr.text ="<span class='x-treenode-zfw-group2 x-tree-node-indent x-tree-node-el' >"+ attr.Name+"</span>";
            attr.text = HtmlEncode(attr.Name);
            attr.leaf = false;
            attr.expanded=true;  
            attr.allowDrag=false;
            attr.cls=" x-treenode-zfw-group2";            
            var tipmsg="";
            var icofile=getTreeNodeStatusFile(attr.DeviceState,true);   
            attr.icon=icofile;//"resources/images/camera/mastnodeoff.gif";
            tipmsg+=GetDefaultLang("lang_masterdevid","主设备ID:{id}").replace("{id}",attr.Id);
            tipmsg+="<br/>"+GetDefaultLang("lang_domainid","所属域ID:{id}").replace("{id}",attr.DomainId);
            tipmsg+="<br/>"+GetDefaultLang("lang_groupid","所属组ID:{id}").replace("{id}",attr.GroupId);
            tipmsg+="<br/>"+GetDefaultLang("lang_devcount","从设备数:{count}").replace("{count}",attr.DevCount);
            //attr.icon="resources/images/default/tree/folder.gif"
            //tipmsg+="<br/>IP地址:"+ChangeIpFormInt(attr.IpAddr);
            //tipmsg+="<br/>通信端口:"+attr.CommPort;
            //attr.qtip=tipmsg;
        }else if(attr.tagName=="DevGroup")
        {//DevGroup设备组
            attr.id=this.AddId+"d_g"+attr.Id;
            //attr.text ="<span class='x-treenode-zfw-group2 x-tree-node-indent x-tree-node-el' >"+ attr.Name+"</span>";
            attr.text = HtmlEncode(attr.Name);
            attr.leaf = false;
            attr.expanded=true;  
            attr.allowDrag=false;
            attr.cls=" x-treenode-zfw-group2";            
            var tipmsg="";
            attr.icon="resources/images/camera/groupnode.gif";
            tipmsg+=GetDefaultLang("lang_masterdevid","主设备ID:{id}").replace("{id}",attr.Id);
            tipmsg+="<br/>"+GetDefaultLang("lang_domainid","所属域ID:{id}").replace("{id}",attr.DomainId);
            tipmsg+="<br/>"+GetDefaultLang("lang_groupid","所属组ID:{id}").replace("{id}",attr.GroupId);
            tipmsg+="<br/>"+GetDefaultLang("lang_devcount","从设备数:{count}").replace("{count}",attr.DevCount);
            //attr.icon="resources/images/default/tree/folder.gif"
            //tipmsg+="<br/>IP地址:"+ChangeIpFormInt(attr.IpAddr);
            //tipmsg+="<br/>通信端口:"+attr.CommPort;
            //attr.qtip=tipmsg;
        }
        else
        {
            attr.id=this.AddId+"c"+attr.Id;
            //attr.text ="<span class='x-treenode-zfw-group3 x-tree-node-indent x-tree-node-el' >"+ attr.Name+"</span>";
            attr.text = HtmlEncode(attr.Name);
            attr.leaf = true;
            attr.expanded=true;
            attr.allowDrag=false;            
            var icofile=getTreeNodeStatusFile(attr.DeviceState,false);            
            attr.icon=icofile;//"resources/images/camera/offline.gif";
            attr.RemoteRecord=false;
            attr.LocateRecord=false;
            attr.OnLineCode=0;
            attr.cls=" x-treenode-zfw-group3";
            var tipmsg="";
            
            tipmsg+=""+GetDefaultLang("lang_ipctipid","从设备ID:{id}").replace("{id}",attr.Id);
            tipmsg+="<br/>"+GetDefaultLang("lang_ipctipname","设备名称:{name}").replace("{name}",HtmlEncode(attr.Name));
            tipmsg+="<br/>"+GetDefaultLang("lang_vsstipip","VSS服务IP:{ip}").replace("{ip}",ChangeIpFormInt(attr.VSSCmdIP));
            tipmsg+="<br/>"+GetDefaultLang("lang_vsstipport","VSS服务端口:{port}").replace("{port}",attr.VSSCmdPort);
            tipmsg+="<br/>"+GetDefaultLang("lang_ipctipip","IP地址:{ip}").replace("{ip}",ChangeIpFormInt(attr.IpAddr));
            tipmsg+="<br/>"+GetDefaultLang("lang_tipctipport","通信端口:{port}").replace("{port}",attr.CommPort);
            if(attr.WithPTZ=="1")
            {
                tipmsg+="<br/>"+GetDefaultLang("lang_haveptztip","云台:有");
            }else
            {
                tipmsg+="<br/>"+GetDefaultLang("lang_noptztip","云台:无");
            }
            if(attr.WithAudioIn=="1")
            {
                tipmsg+="<br/>"+GetDefaultLang("lang_haveaudioinputtip","音频输入:有");
            }else
            {
                tipmsg+="<br/>"+GetDefaultLang("lang_noaudioinputtip","音频输入:无");
            }
            if(attr.WithAudioOut=="1")
            {
                tipmsg+="<br/>"+GetDefaultLang("lang_haveaudiooutputtip","音频输出:有");
            }else
            {
                tipmsg+="<br/>"+GetDefaultLang("lang_haveaudioutputtip","音频输出:无");
            }
            //attr.qtip=tipmsg;
        }
    }
});



__NotNeedSendStopWhileNotShowError=true;

function PlayVideoByNode(node,nowplayid,streamtype,needshowError)
{
       if(streamtype!=1 && streamtype!="1")
       {
            streamtype=0;
       }else
       {
            streamtype=1;
       }
       
    //#define VS_VISITSTREAM_NO_FIRBID		0	//不禁止任何码流
    //#define VS_VISITSTREAM_FIRBID_0		1	//禁止第0路(CIF)
    //#define VS_VISITSTREAM_FIRBID_1		2	//禁止第1路(D1)
    //#define VS_VISITSTREAM_FIRBID_BOTH	3	//禁止第0路、第1路
     try
     {
           var allowCifStream=node.attributes["VisitStreamOption"];
           allowCifStream=parseInt(allowCifStream);
           if( streamtype==0 && (allowCifStream==0 || allowCifStream==2) )
           {//  允许连接cif   
           
           }else if( streamtype==1 && (allowCifStream==0 || allowCifStream==1) )
           {//  允许连接d1    
             
           }else
           {
                if(needshowError)
                {
                    oldAlert(GetDefaultLang("lang_notallowvideo110","此设备不允许访问视频流!"));
                }
                return false;
           }
       }catch(eeee){}
              
              
        var searhplan=GetTablPanel();
       //searhplan.activate('showrealtime');
       searhplan.selectRealObj=node;
       var player=GetPlayerById(nowplayid);
       selectPlayerId=nowplayid;//一定要加这个,才能正常
       var cameraId=node.attributes["Id"];
       LastPlayModeNeedShow[cameraId]=needshowError;
       for(var idx=1;idx<=Max_play_Count;idx++)
       {
            if(selectPlayerId!= ("player"+idx) )
            {
                if(playobjDevIdList["player"+idx]==cameraId)
                {
                    if(needshowError)
                    {
                        oldAlert(GetDefaultLang("lang_videohavepalye111","此视频已在经第{idx}个窗口上播放!").replace("{idx}",idx));
                    }
                    return false;
                }
            }
       }
       WriteWebLog("使用["+nowplayid+"],播放Camera="+cameraId);
       var allowshowvideo=GetRightByDevId(cameraId,"video");
       if(allowshowvideo!="")
       {
            if(needshowError)
            {
                oldAlert(allowshowvideo);
                //oldAlert("您无权对此设备进行实时监控!");
            }
            return false;
       }
       player.Stop();
       var videoport=player.GetBindPort();
       if(videoport>0 && videoport<65535)
       {
            var loginobj=$("loginobj");                       
            if(playobjDevIdList[selectPlayerId]!=null && playobjDevIdList[selectPlayerId]!="")
            {
                if(!__NotNeedSendStopWhileNotShowError || needshowError )
                {//如果是程序进行重连，则不发停止视频流
                    if(PlayVideoTypeList[selectPlayerId]==="1" || PlayVideoTypeList[selectPlayerId]===1)
                    {//如果当前正在播放D1
                        loginobj.StopDeviceMonitor(playobjDevIdList[selectPlayerId],1);
                        WriteWebLog("停止视频流:CameraId="+playobjDevIdList[selectPlayerId]+",stream type="+1);
                    }else if(PlayVideoTypeList[selectPlayerId]==="0" || PlayVideoTypeList[selectPlayerId]===0)
                    {
                        loginobj.StopDeviceMonitor(playobjDevIdList[selectPlayerId],0);
                        WriteWebLog("停止视频流:CameraId="+playobjDevIdList[selectPlayerId]+",stream type="+1);
                    }
                    
                    if(__userFCom)
                    {                                                               
                        var obj=$("audioobj");
                        if(LastTackCameraId!="" && LastTackCameraId==playobjDevIdList[selectPlayerId])
                        {
                            WriteWebLog("停止对讲"+LastTackCameraId);
                            var stopret=obj.FCom_StopTalk(LastTackCameraId);
                            main_but_startaudio.setText(GetDefaultLang("lang_startaudio","启动对讲"));
                            LastTackCameraId="";
                        }
                    }else
                    {     
                        var obj=loginobj;
                        if(LastTackCameraId!="" && LastTackCameraId==playobjDevIdList[selectPlayerId])
                        {
                            WriteWebLog("停止对讲"+LastTackCameraId);
                            var stopret=obj.StopTalk(LastTackCameraId);//stop 
                            if(stopret!=0)
                            {
                                if(needshowError)
                                {
                                    oldAlert(GetDefaultLang("lang_stopaudioerror112","停止对讲失败"));
                                }
                            }else
                            {
                                SetStartAudioDisable();
                                main_but_startaudio.setText(GetDefaultLang("lang_startaudio","启动对讲"));
                                LastTackCameraId="";
                            }
                        }
                    }    
                }
            }
            WriteWebLog("请求视频流:CameraId="+cameraId+",videoport="+videoport);      
            //loginobj.StopDeviceMonitor(cameraId,0);//停止以前的流
            //loginobj.StopDeviceMonitor(cameraId,1);//停止以前的流
            loginobj.InviteDeviceMonitor(cameraId,streamtype,videoport,0);//camid,流id,recvport,轮询id
            playobjDevIdList[selectPlayerId]=cameraId;
            LastPlayVideoPort[selectPlayerId]=videoport;
            PlayVideoTypeList[selectPlayerId]=""+streamtype;//流0表cif
            var videoType=main_but_d1;//Ext.get("ChangeVideoType");
            var playidvalue=parseInt(selectPlayerId.replace(/[^0-9]+/g,""));
            if(playidvalue>=0 && playidvalue<=Max_play_Count)
            {
                WriteWebLog("保存播放信息:"+playidvalue+",devid="+cameraId+","+streamtype);                
                var ret=loginobj.SetPlaySchemeInfo(3,"",playidvalue,""+cameraId+" "+streamtype);
            }
            if(streamtype==1)
            {
                videoType.setText(GetDefaultLang("lang_switchcif","切换子码流"));
            }else
            {
                videoType.setText(GetDefaultLang("lang_switchd1","切换主码流"));
            }
       }else
       {
            WriteWebLog("视频流端口错误:CameraId="+cameraId+",videoport="+videoport);
       }
}

__LastMasterNode=null;
__LastGroupNode=null;

var cameraReader1=new Ext.app.CameraLoader({AddId:'r'}); 
function GetRelaTimeTree()
{
    if(treeRealTime==null)
    {
        treeRealTime = new Ext.tree.TreePanel({
                title:GetDefaultLang("lang_ipclistform", '摄像机列表'),
                id: 'realtree-panel',
                region: 'center',
                cls:'overflowhiddenclass',
                bodyStyle:'overflow:hidden;',
                margins: '2 2 0 2',
                autoScroll: true,
                rootVisible: false,
                //useArrows: true,
                animate: false,
                containerScroll: true,
                border: false,
                enableDrag:true,
                root:new Ext.tree.TreeNode({id: 'root_camera',text : 'root',draggable : false,autoScroll: false,expanded : false})                ,
                listeners:
                {
                    resize:function()
                    { 
                        try
                        {
                            ResizeLeftTreePlan();
                        }catch(eee){}
                    }
                    ,show:function()
                    {  
                        try
                        {
                            ResizeLeftTreePlan();
                        }catch(eevv){}
                    }
                }          
            });
            
            
            
//            treeRealTime.on('afterrender',function(node,event)
//            {
//                try
//                {//
//                    treeRealTime.root.firstChild.collapseChildNodes(true,true);
//                }catch(ee){}
//            });
            
            
            
            treeRealTime.on('dblclick',function(node,event)
            {
                try
                {
                    if(node.isLeaf())
                    {
                        var tab=GetTablPanel();
                        var seltab=tab.getActiveTab();        
                        var selectTabId="";
                        if(seltab)
                        {
                            selectTabId=seltab.getId();
                        }
                        var selectsecond=false;
                        if(selectTabId=="showrealtime")
                        {
                           var nowplayid=selectPlayerId;                                              
                           if(nowplayid==undefined || nowplayid=="" || nowplayid.replace(/player[1-4]/g,"")!="" )
                           {
                              selectPlayerId= nowplayid="player1";
                           }
                           if(__playAudioDevId!=node.attributes["Id"])
                           {
                               StopAudioByDeviceId(__playAudioDevId);
                               if(LastTackCameraId=="")
                               {//只有在没对讲时才播放声音
                                   __playAudioDevId=node.attributes["Id"];
                                   SaveConfigToFile(7,__playAudioDevId);
                               }else
                               {
                                    __playAudioDevId="";
                                   SaveConfigToFile(7,"0");
                               }
                           }
                           try
                           {
                                //#define VS_VISITSTREAM_NO_FIRBID		0	//不禁止任何码流
                                //#define VS_VISITSTREAM_FIRBID_0		1	//禁止第0路(CIF)
                                //#define VS_VISITSTREAM_FIRBID_1		2	//禁止第1路(D1)
                                //#define VS_VISITSTREAM_FIRBID_BOTH	3	//禁止第0路、第1路
                                var allowCifStream=node.attributes["VisitStreamOption"];
                                allowCifStream=parseInt(allowCifStream);
                                if(allowCifStream==0 || allowCifStream==2)
                                {
                                     PlayVideoByNode(node,nowplayid,0,true);  //camid,流id,recvport,轮询id,播放cif   
                                }else if(1==allowCifStream)
                                {
                                     PlayVideoByNode(node,nowplayid,1,true);  //camid,流id,recvport,轮询id,播放cif    
                                }else
                                {
                                     oldAlert(GetDefaultLang("lang_notallowvideoerror113","此设备不允许访问视频流!"));
                                }
                            }catch(eevv1){}
                       }
                       else if(selectTabId=="showplayback")
                       {
                            var searhplan=GetTablPanel();
                            var grid=GetSearchResultGrid();
                            searhplan.selectPlayBackOjb=grid.SelectDevNode= node;
                            $("selectcamera").innerText=GetDefaultLang("lang_notselectdevtext",",当前选择设备:{name}").replace("{name}",node.text);
                            $("selectdevid").value=grid.DevId=node.attributes["Id"];
                        }       
                    }
                }catch(eevvee){}
            }
            );
                        
            
            treeRealTime.on('click',function(node,event)
            {
                if(node.isLeaf())
                {
                    var tab=GetTablPanel();
                    var seltab=tab.getActiveTab();        
                    var selectTabId="";
                    if(seltab)
                    {
                        selectTabId=seltab.getId();
                    }              
                    var grid=GetSearchResultGrid();
                    if(selectTabId=="showplayback")
                    { 
                        var searhplan=GetTablPanel();
                        searhplan.selectPlayBackOjb=grid.SelectDevNode= node;
                        $("selectcamera").innerText=GetDefaultLang("lang_notselectdevtext",",当前选择设备:{name}").replace("{name}",node.text);
                        $("selectdevid").value=grid.DevId=node.attributes["Id"];
                    }                    
                    else
                    {
                        var playerid="";
                        var devid=""+node.attributes["Id"];
                        for(var idx=1;idx<=Max_play_Count;idx++)
                        {
                            playerid="player"+idx;
                            if(devid==playobjDevIdList[playerid] )
                            {
                                OnPlayerMouseEvent(playerid,0x0202,0,0);
                            }
                        }
                    }                        
                }else
                {
                    if(node.getDepth()<=1)
                    {
                        if(!node.isExpanded())
                        {
                            node.isExpanded();
                        }
                    }else
                    {//__LastMasterNode=null;  __LastGroupNode=null;
                        if(node.attributes["tagName"]!="DevGroup")
                        {
                            if(!node.isExpanded())
                            {
                                if(LastSelectGroupNode && LastSelectGroupNode!=node)
                                {
                                    LastSelectGroupNode.collapse();
                                }
                                node.expand();
                                LastSelectGroupNode=node;
                            }else
                            {
                                node.collapse();
                                LastSelectGroupNode=null;
                            }
                        }else
                        {
                            if(!node.isExpanded())
                            {
                                if(__LastGroupNode && __LastGroupNode!=node)
                                {
                                    __LastGroupNode.collapse();
                                }
                                node.expand();
                                __LastGroupNode=node;
                            }else
                            {
                                node.collapse();
                                __LastGroupNode=null;
                            }
                        }
                    }
                }
            });

    }
    return treeRealTime;
}




//<Master Id="860030001" Name="凌总桌上测试机"  Type="3" GroupId="860030001"  DomainId="86003" DevCount="3"  
//IpAddr="1683531968"  CommPort="1033"  LoginName="admin"  LoginPassword="123456"  
//PTZRight="1"  SURVEILRight="1"  VideoReplayRight="1"  AudioControlRight="1"  
//BCControlRight="1"  AlarmMngRight="1"  >

function GetRightByGroupNode(groupnode,righttype)
{
    if(!groupnode || !groupnode.attributes)
    {
        return GetDefaultLang("lang_nodeverror120","没有找到设备信息");
    }
    if(righttype=="ptz")
    {
        if(have_PTZRight===0 || have_PTZRight==="0")
        {
            return GetDefaultLang("lang_righterror121","此用户没有云台控制权限");
        }
        var ptzright=parseInt(groupnode.attributes["PTZRight"],10);
        if(ptzright==1)
        {
            return "";
        }else
        {
            return GetDefaultLang("lang_righterror123","此用户没有对此设备云台控制权限");
        }
    }else if(righttype=="replay")
    {
        if(have_VideoReplayRight===0 || have_VideoReplayRight==="0")
        {
            return GetDefaultLang("lang_righterror124","此用户没有回放视频权限");
        } 
        var videoright=parseInt(groupnode.attributes["VideoReplayRight"],10);
        if(videoright==1)
        {
            return "";
        }else
        {
            return GetDefaultLang("lang_righterror125","此用户没有对此设备视频回放权限");
        }
    }else if(righttype=="audio")
    {
        if(have_AudioControlRight===0 || have_AudioControlRight==="0")
        {
            return GetDefaultLang("lang_righterror126","此用户没有音频对讲权限");
        } 
        var audioright=parseInt(groupnode.attributes["AudioControlRight"],10);
        if(audioright==1)
        {
            return "";
        }else
        {
            return GetDefaultLang("lang_righterror127","此用户没有对此设备音频对讲权限");
        }
    }else if(righttype=="video")
    {
        if(have_SURVEILRight===0 || have_SURVEILRight==="0")
        {
            return GetDefaultLang("lang_righterror128","此用户没有实时监控权限");
        } 
        var surveilright=parseInt(groupnode.attributes["SURVEILRight"],10);
        if(surveilright==1)
        {
            return "";
        }else
        {
            return GetDefaultLang("lang_righterror129","此用户没有对此设备进行实时监控权限");
        }
    }else if(righttype=="bbcaudio")
    {
        if(have_BCControlRight===0 || have_BCControlRight==="0")
        {
            return GetDefaultLang("lang_righterror130","此用户没有广播权限");
        } 
        var bbcright=parseInt(groupnode.attributes["BCControlRight"],10);
        if(bbcright==1)
        {
            return "";
        }else
        {
            return  GetDefaultLang("lang_righterror131","此用户没有对此设备广播权限");
        }
    }else if(righttype=="alarm")
    {
        if(have_AlarmMngRight===0 || have_AlarmMngRight==="0")
        {
            return  GetDefaultLang("lang_righterror132","此用户没有查询告警权限!");
        } 
        var alarmright=parseInt(groupnode.attributes["AlarmMngRight"],10);
        if(alarmright==1)
        {
            return "";
        }else
        {
            return  GetDefaultLang("lang_righterror133","此用户没有对此设备告警管理权限");
        }
    }   
    return  GetDefaultLang("lang_righterror134","此用户没有权限进行此操作");
}





//function GetRightByGroupNode(groupnode,righttype)
//{
//    if(!groupnode || !groupnode.attributes)
//    {
//        return false;
//    }
//    if(righttype=="ptz")
//    {
//        if(have_PTZRight===0 || have_PTZRight==="0")
//        {
//            return false;
//        } 
//        if(groupnode.attributes["PTZRight"]=="1")
//        {
//            return true;
//        }
//    }else if(righttype=="replay")
//    {
//        if(have_VideoReplayRight===0 || have_VideoReplayRight==="0")
//        {
//            return false;
//        } 
//        if(groupnode.attributes["VideoReplayRight"]=="1")
//        {
//            return true;
//        }        
//    }else if(righttype=="audio")
//    {
//        if(have_AudioControlRight===0 || have_AudioControlRight==="0")
//        {
//            return false;
//        } 
//        if(groupnode.attributes["AudioControlRight"]=="1")
//        {
//            return true;
//        }        
//    }else if(righttype=="video")
//    {
//        if(have_SURVEILRight===0 || have_SURVEILRight==="0")
//        {
//            return false;
//        } 
//        if(groupnode.attributes["SURVEILRight"]=="1")
//        {
//            return true;
//        }        
//    }else if(righttype=="bbcaudio")
//    {
//        if(have_BCControlRight===0 || have_BCControlRight==="0")
//        {
//            return false;
//        } 
//        if(groupnode.attributes["BCControlRight"]=="1")
//        {
//            return true;
//        }        
//    }else if(righttype=="alarm")
//    {
////        if(have_AlarmMngRight===0 || have_AlarmMngRight==="0")
////        {
////            return false;
////        } 
//        if(groupnode.attributes["AlarmMngRight"]=="1")
//        {
//            return true;
//        }        
//    }
//   
//    return false;
//}



//<Camera Id="860030002" Name="凌总桌上测试机" MasterId="860030001" 
//Type="1" IsDoubleStream="1" WithPTZ="1" WithAudioIn="1" WithAudioOut="1" VSSId="4"
// ConnType="0" MFSCmdIP="0" MFSCmdPort="0" IpAddr="1683531968" CommPort="1033"
// LoginName="admin" LoginPassword="123456" VSSCmdIP="-1437030208" VSSCmdPort="554" />
function GetRightByCameraNode(camNode,righttype)
{
    if(camNode && camNode.parentNode)
    {
        if(!camNode.attributes)
        {
            return  GetDefaultLang("lang_righterror140","没有找到此设备信息");
        }
        if(righttype=="ptz")
        {
            var withptz=parseInt(camNode.attributes["WithPTZ"],10);
            if(withptz!=1)
            {//无云台
                return GetDefaultLang("lang_righterror141","此设备没有云台");
            }
        }else if(righttype=="audio")
        {
            var withautioin=parseInt(camNode.attributes["WithAudioIn"],10);
            if(withautioin!=1)
            {//无云台
                return GetDefaultLang("lang_righterror142","此设备没有输入音频");
            }
        }
        return GetRightByGroupNode(camNode.parentNode,righttype);//查看是否有云台控制权限
    }
    return GetDefaultLang("lang_righterror143","没有权限进行此操作");
}





function GetRightByDevId(devId,righttype)
{
    var  tree=GetRelaTimeTree();
    if(tree)
    {
        var groupnode=tree.root.findChild("id","rg"+devId,true);
        if(groupnode!=null && groupnode.attributes!=null)
        {
            return GetRightByGroupNode(groupnode,righttype);
        }
        var camNode=tree.root.findChild("id","rc"+devId,true);
        return GetRightByCameraNode(camNode,righttype);
    }
    return GetDefaultLang("lang_righterror144","没有权限进行此操作");
}



function GetRightByGroupId(groupid,righttype)
{
    var  tree=GetRelaTimeTree();
    if(tree)
    {
        var groupnode=tree.root.findChild("id","rg"+groupid,true);
        return GetRightByGroupNode(groupnode,righttype);
    }
    return GetDefaultLang("lang_righterror145","没有权限进行此操作");
}



//GetRelaTimeTree();

var haveAttachEvent=false; 
function DoAttachLoginEvent()
{
    haveAttachEvent=true;
    var obj=$("loginobj");
    obj.attachEvent("OnInterfaceXMLResp",OnLoginObj);
}


function ReloadTree()
{
    if(__user_function_to_readcamera)
    {
        var realtree=GetRelaTimeTree();
        var allXml="<xml>"+$("loginobj").GetIPCListByUser()+"</xml>";    
        WriteWebLog("开始读取列表IPC，长度为:"+allXml.length);
        cameraReader1.LoadFromXml(allXml,realtree.root);
    }
}

___lastPlayVideoConfigStr="";

//播放视频
function PlayVideoByConfig(str)
{
    try
    {
        if(___lastPlayVideoConfigStr==str)
        {
            WriteWebLog("自动播放,列表为:"+str+",和上一次相同，退出!");
            return false;
        }
        WriteWebLog("自动播放,列表为:"+str);
        if(str==undefined || str==null || str=="")
        {
            return 0;
        }
        var realtree=GetRelaTimeTree();
        var strls=str.split("\r\n");
        var templastconfig="\r\n"+___lastPlayVideoConfigStr+"\r\n";
        for(var idx=0;idx<strls.length;idx++)
        {
            if(idx>=Max_play_Count)
            {//  太多了,只有四个  
                break;
            }
            if(templastconfig.replace("\r\n"+strls[idx]+"\r\n","")!=templastconfig)
            {//  說明上一次已經在播放了，直接跳過   
                continue;
            }
            var itemls=strls[idx].split(",");
            if(itemls.length>=2)
            {
                var lastnotplay="";
                var nowplayid="player"+(idx+1);            
                for(var pidx=0;pidx<Max_play_Count;pidx++)
                {            
                    var devid=playobjDevIdList["player"+(pidx+1)];
                    var stremtype=PlayVideoTypeList["player"+(pidx+1)]; 
                    if(devid=="")
                    {
                        if(lastnotplay=="")
                        {
                            lastnotplay="";
                        }   
                    }else if(itemls[0]==devid)
                    {
                        lastnotplay="";
                        nowplayid=devid;
                        break;
                    }
                }
                if(lastnotplay!="")
                {
                    nowplayid=lastnotplay;
                }
                if(playobjDevIdList[nowplayid]==itemls[0] && PlayVideoTypeList[nowplayid]==itemls[1])
                {//  相同视频流在播放  
                    continue;
                }
                var node=realtree.root.findChild("Id",""+itemls[0],true);
                if(node)
                {
                    var streamId=parseInt(itemls[1]);
                    PlayVideoByNode(node,nowplayid,streamId,false);
                    //oldAlert(nowplayid+"播放"+itemls[0]+","+itemls[1]);
                }
            }
        }
    }catch(eevvv){}
}