﻿/**
* NrcapPlugsSDK FOR JavaScript 中外合资创世科技版权所有
* FileName.......: nrcapplugs.js
* Project........: WebClient
* Create DateTime: $Date: 2008/11/13 20:55:00 $
*/

NrcapPlugs = {
    version:"v2009.11.18",
    lastModifyTime:"",
    historyModifyNote:[
       {"time":"2008/11/13 20:55:00","note":"1. 创建js版插件封装接口文件\n"},
       {"time":"2008/11/14 16:01:00","note":"1. 创建初始化NrcapPlug对象方法\n"},
       {"time":"2008/11/16 13:01:00","note":"1. 创建资源列表\n"},
       {"time":"2008/11/17 10:57:00","note":"1. 获取站点及子资源描述\n"},
       {"time":"2008/11/20 10:09:00","note":"1. 编写资源树分类,排序方法\n2. 编写视频播放方法"},
       {"time":"2008/11/24 10:09:00","note":"1. 编写视频播放方法"},
       {"time":"2008/11/27 10:09:00","note":"1. 视频窗口响应事件\n2. 录像,音频功能\n3. 窗口重新绑定媒体库插件"},
       {"time":"2008/11/28 10:09:00","note":"1. 视频参数设置界面\n2. 视频参数获取,设置"},
       {"time":"2008/12/22 10:00:00","note":"1. 增加预览config命令"},
       {"time":"2008/12/22 10:00:00","note":"1. 增加连接状态不正确的错误描述信息"},
       {"time":"2009/03/06 15:15:00","note":"1. 修改测试反馈bug"},
       {"time":"2009/03/12 11:20:00","note":"1. 修改退出系统后清空事件队列内容"},
       {"time":"2009/03/12 11:20:00","note":"1. 增加验证GUID正则式\n2.增加设置,获取云台速度方法"},
       {}
    ],
    debug:false,    
    
    // 错误码
    NrcapError:
    {
        NRCAP_SUCCESS                                           :   0x0000,         // 操作成功
        NRCAP_ERROR_INIT_SOCKET_FAILED		                    :   0x000B,         // 初始化socket失败
        
        NRCAP_ERROR_LOADPLUG_NC                                 :   0x8001,         // NC未加载
        NRCAP_ERROR_LOADPLUG_NM                                 :   0x8002,         // NM未加载
        NRCAP_ERROR_LOADPLUG_BSP                                :   0x8003,         // BSP未加载
        NRCAP_ERROR_LOADPLUG_BSC                                :   0x8004,         // BSC未加载
        NRCAP_ERROR_LOADPLUG_DW                                 :   0x8005,         // DW未加载
        
        NRCAP_ERROR_INIT_NRCAPPLUG_FAILED                       :   0x6000,         // 初始化NrcapPlug对象失败
        NRCAP_ERROR_NRCAPPLUG_ISNULL                            :   0x6001,         // NrcapPlug为空
        
        NRCAP_ERROR_INIT_CONNECTION_FAILED                      :   0x6010,         // 初始化连接对象失败
        NRCAP_ERROR_CONNECTIONID_ALREADY_EXIST                  :   0x6011,         // 新创建连接ID已经存在
        NRCAP_ERROR_OPEN_CONNECT_FAILED                         :   0x6012,         // 连接失败
        NRCAP_ERROR_CONNECTIONID_FAILED                         :   0x6013,         // 连接ID不存在
        NRCAP_ERROR_DISCONNECTION_FAILED                        :   0x6014,         // 删除一个连接对象失败
        
        NRCAP_ERROR_CREATE_RESOURCELIST_FAILED                  :   0x6020,         // 获取资源失败
        NRCAP_ERROR_SORT_RESOURCE_FAILED                        :   0x6021,         // 对资源排序失败
        
        NRCAP_ERROR_INIT_WINDOW_FAILED                          :   0x6030,         // 初始化视频窗口失败
        NRCAP_ERROR_WINDOW_NOEXIST                              :   0x6031,         // 视频窗口不存在
        NRCAP_ERROR_PLAYVIDEO_FAILED                            :   0x6032,         // 播放视频失败
        NRCAP_ERROR_GETDESCRIPTION_FAILED                       :   0x6034,         // 资源树上查找节点失败
        NRCAP_ERROR_RESOURCEINDEXOF_FAILED                      :   0x6035,         // 资源树查找资源
        
        NRCAP_ERROR_VIDEOTOPPED                                 :   0x6036,         // 视频没有再播放
        NRCAP_ERROR_WINDOW_FAILED                               :   0x6037,         // 视频窗口不存在        
        NRCAP_ERROR_RECORD_FAILED                               :   0x6038,         // 录像失败
        NRCAP_ERROR_SNAP_FAILED                                 :   0x6039,         // 抓拍失败
        NRCAP_ERROR_PLAYAUDIO_FAILED                            :   0x603A,         // 播放音频失败
        NRCAP_ERROR_GET_BINDEDPTZ_FAILED                        :   0x603B,         // 获取云台GUID失败
        
        NRCAP_ERROR_GETCONFIG_FAILED                            :   0x7000,         // 获取CONFIG命令失败
        NRCAP_ERROR_SETCONFIG_FAILED                            :   0x7001          // 设置CONFIG命令失败
        
    },
    
            
    // Nrcap登录客户端的类型
    NrcapClientType:
    {
        resourceUser:0,
        configer:1,
        replayer:2
    },
    
    // Nrcap资源类型
    NrcapResourceType:
    {
	    station                                         :       "Station",						/* 站点 */
	    input_video                                     :       "Input Video",					/* 输入视频 */
	    input_audio                                     :       "Input Audio", 					/* 输入音频 */
	    output_video                                    :       "Output Video",                 /* 输出视频 */
	    output_audio                                    :       "Output Audio",					/* 输出音频 */
	    serial_port                                     :       "Serial Port",					/* 串口 */
	    ptz                                             :       "PTZ",							/* 云台 */
	    input_digital_line                              :       "Input Digital Line",           /* 输入数字线 */
	    output_digital_line                             :       "Output Digital Line",			/* 输出数字线 */
	    speaker                                         :       "Speaker",						/* 扬声器 */
	    storager                                        :       "Storager",						/* 存储器 */
	    platform_manager                                :       "Platform Manager",             /* 管理平台 */
	    archiver                                        :       "Archiver",                     /* 废弃类型 */
	    unrecognized                                    :       "unrecognized"                  /* 求知类型 */
    },
    
    // Nrcap站点类型
    NrcapStationType:
    {
        station:1,
        ces:2,
        ecoder:3,
        decoder:4,
        storager:5,
        mobile_gateway :6
    },
    
    NrcapDataFormat:
    {
        single:"single",                
        uchar:"uchar",
        ushort:"ushort",
        uint:"uint",
        ip:"ip",
        guid:"guid",
        string:"string",
        multi:"multi"
    },
    
    // Nrcap Control ID
    NrcapControlID:
    {
        Nrcap_GetStationGUID                                    :   0x00010000,         // 获取站点GUID
        Nrcap_GetGUIDDescription                                :   0x00010001,         // 获取资源的GUID描述
        Nrcap_GetStationChildrenGUIDArray                       :   0x00010002,         // 获取站点子资源GUID组
        Nrcap_GetChildrenGUIDDescriptionArray                   :   0x00010049          // 获取站点子资源GUID描述组
    },
    
    // Nrcap Configer ID
    NrcapConfigerID:
    {
        Nrcap_GetStationModel                                   :   0x000D,             // 获取站点类型
        Nrcap_GetBindedPTZ                                      :   0x0823,             // 获取绑定的云台GUID
        Nrcap_GetInputVideoBrightness                           :   0x0804,             // 获取视频亮度
        Nrcap_GetInputVideoContrast                             :   0x0805,             // 获取视频对比度
        Nrcap_GetInputVideoHue                                  :   0x0806,             // 获取视频色调
        Nrcap_GetInputVideoSaturation                           :   0x0807,             // 获取视频饱和度
        NRCAP_CFGID_PTZ_Speed                                   :   0x290A,             // PTZ移动的速度
        end:true
    },
    
    NrcapEventTypeID:
    {
        EVENT_USER                  :           0x0001,
        EVNET_PLATFORM              :           0x0002,
        EVENT_INPUTVIDEO            :           0x0003,
        
        EVENT_IOINPUT               :           0x0005,
        EVENT_STORAGER              :           0x0006,
        EVENT_PLATFORMMANAGER       :           0x0008,
        EVENT_CUSTOM                :           0x0009,
        EVENT_LINKAGEACTION         :           0x000A,
        EVENT_RESOURCE              :           0x000B,
        EVENT_STATUSNOTIFY          :           0x000C,
        EVENT_PLATFORMGEN           :           0x000D        
    },
    
    NrcapEvent:
    {
        "0x0001":       // 用户事件
        {
            "0x0000":
            {
                id:0x0000,
                description:"用户登录"
            },
            "0x0001":
            {
                id:0x0001,
                description:"用户退出"
            },
            "0x0002":
            {
                id:0x0002,
                description:"用户输入了错误的密码"
            }
        },
        "0x0002":       // 平台事件
        {
            "0x0000":
            {
                id:0x0000,
                description:"站点登录"
            },
            "0x0001":
            {
                id:0x0001,
                description:"站点退出"
            }
        },
        "0x0003":       // 输入视频事件
        {
            "0x0001":
            {
                id:0x0000,
                description:"信号丢失"
            },
            "0x0002":
            {
                id:0x0002,
                description:"信号恢复"
            },
            "0x0005":
            {
                id:0x0005,
                description:"帧测到移动"
            },
            "0x0006":
            {
                id:0x0006,
                description:"移动停止"
            }
        },
        "0x0005":       // 报警输入输出
        {
            "0x0002":
            {
                id:0x0002,
                description:"发生报警"
            }
        },
        "0x0006":       // 存储者事件
        {
            "0x0000":
            {
                id:0x0000,
                description:"磁盘空间不足"
            },
            "0x0001":
            {
                id:0x0001,
                description:"磁盘已满"
            },
            "0x0005":
            {
                id:0x0005,
                description:"用户存储空间不足"
            },
            "0x0006":
            {
                id:0x0006,
                description:"用户存储空间已满"
            },
            "0x0007":
            {
                id:0x0007,
                description:"启动文件系统失败"
            },
            "0x0008":
            {
                id:0x0008,
                description:"磁盘出现故障"
            }
        },
        "0x0008":       // 平台管理者事件
        {
            "0x0000":
            {
                id:0x0000,
                description:"添加新站点"
            },
            "0x0001":
            {
                id:0x0001,
                description:"删除站点"
            },
            "0x0002":
            {
                id:0x0002,
                description:"添加新用户"
            },
            "0x0003":
            {
                id:0x0003,
                description:"删除用户"
            },
            "0x0004":
            {
                id:0x0004,
                description:"用户修改了密码"
            }
        },
        "0x0009":       // 自定义事件
        {
            "0x0000":
            {
                id:0x0000,
                description:"自定义事件"
            }
        },
        "0x000A":       // 联动事件
        {
            "0x0000":
            {
                id:0x0000,
                description:"发送消息"
            },
            "0x0001":
            {
                id:0x0001,
                description:"发送报警"
            },
            "0x0002":
            {
                id:0x0002,
                description:"通过主窗口浏览"
            },
            "0x0003":
            {
                id:0x0003,
                description:"通过任意窗口浏览"
            },
            "0x0004":
            {
                id:0x0004,
                description:"文字对话"
            }
        },
        "0x000B":       // 资源事件
        {
            "0x0001":
            {
                id:0x0001,
                description:"资源上线"
            },
            "0x0002":
            {
                id:0x0002,
                description:"资源下线"
            },
            "0x0003":
            {
                id:0x0003,
                description:"子资源删除"
            },
            "0x0004":
            {
                id:0x0004,
                description:"子资源添加"
            }
        },
        "0x000C":       // 状态通知事件
        {
            "0x0001":
            {
                id:0x0001,
                description:"报警输出状态改变"
            },
            "0x0002":
            {
                id:0x0002,
                description:"云台控制级别改变"
            },
            "0x0003":
            {
                id:0x0003,
                description:"当前选择的视频通道发生改变"
            }
        },
        "0x000D":       // 平台产生事件
        {
            "0x0000":
            {
                id:0x0000,
                description:"内部固定定时事件"
            },
            "0x0001":
            {
                id:0x0001,
                description:"定时事件"
            },
            "0x0002":
            {
                id:0x0002,
                description:"手动报警事件"
            }
        }
     
    },
    
    // 插件对象的html元素
    ObjHtml:
    {
        nm:"<OBJECT id=\"@id\" name=\"@name\" CLASSID=\"CLSID:50C1C74B-233C-4790-8440-6426E46BE53E\" style=\"display:none;\" codebase=\"WebPlugs.cab#version=1,2009,2,23\">",
        nc:"<OBJECT id=\"@id\" name=\"@name\" CLASSID=\"CLSID:1791DA2F-1F07-49EA-818E-AE234A9CFF6B\" style=\"display:none;\" codebase=\"WebPlugs.cab#version=1,2009,2,23\">",
        bsp:"<OBJECT id=\"@id\" name=\"@name\" classid=\"clsid:A50B007E-8764-418B-9DCE-D485E0732EFD\" codebase=\"WebPlugs.cab#version=1,2009,2,23\" style=\"display:none;\"></OBJECT>",
        bsc:"<OBJECT id=\"@id\" name=\"@name\" classid=\"clsid:8A258A89-3FC5-4170-8D2B-2F2252301345\" codebase=\"WebPlugs.cab#version=1,2009,2,23\" style=\"display:none;\"></OBJECT>",
        wnd:"<OBJECT classid=\"CLSID:C1A33A67-A0F2-42E0-80B6-38EFBDD8AD18\" id=\"@id\" name=\"@name\" width=\"352\" height=\"288\" codebase=\"WebPlugs.cab#version=1,2008,12,24\" ><param name=\"_Version\" value=\"65536\"><param name=\"_ExtentX\" value=\"9313\"><param name=\"_ExtentY\" value=\"7620\"><param name=\"_StockProps\" value=\"0\"></OBJECT>",
        get:function(objname)
        {
            var htmlstr = "";
            switch(objname)
            {
                case "nm":
                    htmlstr = this.nm;
            	    break;
                case "nc":
                    htmlstr = this.nc;
            	    break;
                case "bsp":
                    htmlstr = this.bsp;
            	    break;
                case "bsc":
                    htmlstr = this.bsc;
            	    break;
                case "wnd":
                    htmlstr = this.wnd;
            	    break;
                default:
            }
            return htmlstr;
        }
    },
    
    // 定时器
    Timer:{
        openTimer:null
    },
    
    // 初始化NrcapPlug
    Plug:
    {
        inited:false,
        nc:null,
        nm:null,
        bsp:null,
        bsc:null
    },
    
	// 窗口样式
    WindowStyle:{
        enableFullScreen:false,     // 是否可以全屏
        enableMask:false            // 是否加载遮挡网格
    },   
	
	// 窗口事件类型
    WindowEvent:
    {
        onStop:{status:false,callback:null},
        onClick:{status:false,callback:null},
        onFullScreen:{status:false,callback:null},
        onRestore:{status:false,callback:null},
        onPop:{status:false,callback:null},
        onSnapshot:{status:false,callback:null},
        onStartRecord:{status:false,callback:null},
        onStopRecord:{status:false,callback:null},
        onPTZControl:{status:false,callback:null},
        onCustomMenuCommand:{status:false,menu:null,callback:null},
        onMenu_BigWnd:{status:false,callback:null},
        onTopMost:{status:false,callback:null},        
        onMaskClick:{status:false,callback:null},
        onMaskDrag:{status:false,callback:null},
        onMaskDragEnd:{status:false,callback:null}
    },
    
    // Connection对象组,没有定义成数组Array形式是为了通过key直接访问
    Connections:new Hash(),
    
    // 温馨提示
    WarmTip:{
        /*
         *	函数名		：Display
         *	函数功能	：显示温馨提示信息
         *	备注		：无
         *	作者		：Lingsen
         *	时间		：2008年11月14日
         *	返回值		：无
         *	参数说明	：无
         */
        Display:function()
        {  
            var objPlugsNoteBox = document.createElement("DIV");
            objPlugsNoteBox.setAttribute("id","PlugsNoteBox");
            document.getElementsByTagName("body").item(0).appendChild(objPlugsNoteBox);
            objPlugsNoteBox.style.zIindex="999";
            objPlugsNoteBox.style.position="absolute";
            objPlugsNoteBox.style.width="100%";
            objPlugsNoteBox.style.height="100%";
            objPlugsNoteBox.style.top="0";
            objPlugsNoteBox.style.left="0";
            objPlugsNoteBox.style.filter="Alpha(Opacity=75)";
            objPlugsNoteBox.style.filter.MozOpacity="0.8";
            objPlugsNoteBox.style.filter.Opacity="0.8";                
            objPlugsNoteBox.style.backgroundColor="#C3E2FF";
            objPlugsNoteBox.style.color= "#990011";
            objPlugsNoteBox.style.fontSize= "14px";
            objPlugsNoteBox.style.textAlign= "left";
            objPlugsNoteBox.style.lineHeight= "180%";
            objPlugsNoteBox.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;［<b>温馨提示</b>］ 插件装载失败，请您检查一下是否已经成功安装插件！&nbsp;&nbsp;请点击顶部安装ActiveX控件的提示条开始安装'网络视频监控'插件！如果没有安装提示条可能是因为您的IE安全级别设置过高,请您修改后再试．另外你可以通过下载插件安装包手动安装插件,&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"webplugs.exe\">这里下载</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"self\" onclick=\"location.reload();\">刷新重试</a>!";            
        },
        
        /*
         *	函数名		：None
         *	函数功能	：关闭温馨提示信息
         *	备注		：无
         *	作者		：Lingsen
         *	时间		：2008年11月14日
         *	返回值		：无
         *	参数说明	：无
         */
        None:function()
        {
            if(document.getElementById("PlugsNoteBox"))
            {
                document.getElementsByTagName("body").item(0).removeChild(document.getElementById("PlugsNoteBox"));
            }
        }
    },
  
    /*
     *	函数名		：ShowErrorMessage
     *	函数功能	：获取错误描述信息
     *	备注		：无
     *	作者		：Lingsen
     *	时间		：2008年11月14日
     *	返回值		：返回错误描述信息
     *	参数说明	：1个参数
     *		Number errorCode        错误码; 
     */
    ShowErrorMessage:function(errorCode)
    {
        var rv = "";
        switch(parseInt(errorCode))
        {
          case 0x0001:
            rv = "错误的地址格式";
            break;
          case 0x0002:
            rv = "错误的流类型";
            break;
          case 0x0003:
            rv = "没有注册回调函数或消息";
            break;
          case 0x0004:
            rv = "错误的索引或没有开始事件截取";
            break;
          case 0x0005:
            rv = "该索引已经开始事件截取";
            break;
          case 0x0006:
            rv = "错误的流信息没有开始数据截取";
            break;
          case 0x0007:
            rv = "该流已经开始数据截取";
            break;
          case 0x0008:
            rv = "加载文件失败";
            break;
          case 0x0009:
            rv = "图片文件过大";
            break;
          case 0x000A:
            rv = "非法的帧信息";
            break;
          case 0x000B:
            rv = "初始化socket失败";
            break;
          case 0x000C:
            rv = "错误的命令";
            break;
          case 0x000D:
            rv = "连接代理失败";
            break;
          case 0x1801:
            rv = "设置值与实际值不匹配";
            break;
          case 0x1802:
            rv = "属性不支持";
            break;
          case 0x1803:
            rv = "没有读权限或者不支持读操作";
            break;
          case 0x1804:
            rv = "没有控制权限";
            break;
          case 0x1805:
            rv = "不支持交叠,覆盖前面操作";
            break;
          case 0x1806:
            rv = "资源耗尽,操作失败";
            break;
          case 0x1807:
            rv = "无效的GUID";
            break;
          case 0x2001:
            rv = "主机或端口不可到达";
            break;
          case 0x2002:
            rv = "用户名不存在";
            break;
          case 0x2003:
            rv = "用户密码错误";
            break;
          case 0x2004:
            rv = "超过最大用户数目";
            break;
          case 0x2005:
            rv = "连接过程或访问超时";
            break;
          case 0x2006:
            rv = "socket发送出错";
            break;
          case 0x2007:
            rv = "认证过程出错";
            break;
          case 0x2008:
            rv = "会话结束或者不存在";
            break;
          case 0x2009:
            rv = "超过最大会话数目";
            break;
          case 0x200D:
            rv = "输入的调用参数有误";
            break;
          case 0x200E:
            rv = "没有权限";
            break;
          case 0x200F:
            rv = "响应错误";
            break;
          case 0x2010:
            rv = "内存分配出错";
            break;
          case 0x2015:
            rv = "得到对方地址出错";
            break;
          case 0x2016:
            rv = "创建socket句柄出错";
            break;
          case 0x2017:
            rv = "选择接收出错";
            break;
          case 0x2018:
            rv = "socket接收出错";
            break;
          case 0x2019:
            rv = "设置socket选项失败";
            break;
          case 0x201A:
            rv = "没有事件";
            break;
          case 0x201D:
            rv = "NC模块状态错误";
            break;
          case 0x201E:
            rv = "数据溢出错误";
            break;
          case 0x2027:
            rv = "初始化链表失败";
            break;
          case 0x2030:
            rv = "本次未接受完数据";
            break;
          case 0x2031:
            rv = "接收到控制命令的错误状态";
            break;
          case 0x2032:
            rv = "接收到重定向报文";
            break;
          case 0x203F:
            rv = "创建线程失败";
            break;
          case 0x2801:
            rv = "DCM模块状态错误";
            break;       
          case 0x2802:
            rv = "参数错误";
            break;       
          case 0x2803:
            rv = "缓冲区大小不够，piLen返回需要的最小空间,或者输入的缓冲数据太长";
            break;       
          case 0x2804:
            rv = "数据丢失或者因内部缓冲区满而策略性丢弃";
            break;       
          case 0x2805:
            rv = "句柄不可用";
            break;       
          case 0x2806:
            rv = "操作不支持";
            break;       
          case 0x2807:
            rv = "描述表用完";
            break;       
          case 0x2808:
            rv = "数据通道已经建立";
            break;       
          case 0x2809:
            rv = "数据通道关键字错误";
            break;       
          case 0x280A:
            rv = "数据通道类型错误";
            break;       
          case 0x280B:
            rv = "数据通道模式错误";
            break;       
          case 0x280C:
            rv = "函数返回数据错误";
            break;       
          case 0x280D:
            rv = "创建信号量错误";
            break;       
          case 0x280E:
            rv = "创建链表错误";
            break;       
          case 0x280F:
            rv = "创建链表节点错误";
            break;
          case 0x2810:
            rv = "创建线程错误";
            break;
          case 0x2811:
            rv = "创建SOCKET错误";
            break;
          case 0x2812:
            rv = "SOCKET连接错误";
            break;
          case 0x2813:
            rv = "SOCKET发送错误";
            break;
          case 0x2814:
            rv = "SOCKET Select错误";
            break;
          case 0x2815:
            rv = "SOCKET接收错误";
            break;
          case 0x2816:
            rv = "SOCKET绑定错误";
            break;
          case 0x2817:
            rv = "SOCKET加入组播组错误";
            break;
          case 0x2818:
            rv = "分配内存错误";
            break;
          case 0x2819:
            rv = "数据包错误";
            break;
          case 0x281A:
            rv = "网络超时";
            break;
          case 0x281B:
            rv = "数据帧类型错误";
            break;
          case 0x281C:
            rv = "用于非阻塞方式中返回当前无数据的情况";
            break;
          case 0x281D:
            rv = "设置发送缓冲区失败";
            break;
          case 0x281E:
            rv = "资源已经释放";
            break;
          case 0x6000:
            rv = "初始化NrcapPlug对象失败";
            break;
          case 0x6001:
            rv = "NrcapPlug为空";
            break;
          case 0x6010:
            rv = "初始化连接对象失败";          
            break;
          case 0x6011:
            rv = "新创建连接ID已经存在";
            break;
          case 0x6012:
            rv = "连接失败";
            break;
          case 0x6013:
            rv = "连接ID不存在";
            break;
          case 0x6014:
            rv = "删除一个连接对象失败";
            break;
          case 0x6020:
            rv = "获取资源失败";
            break;
          case 0x6021:
            rv = "对资源排序失败";
            break;
          case 0x6030:
            rv = "初始化视频窗口失败";
            break;
          case 0x6031:
            rv = "视频窗口不存在";
            break;
          case 0x6032:
            rv = "播放视频失败";
            break;
          case 0x6033:
            rv = "资源树上查找节点失败";
            break;
          case 0x6036:
            rv = "视频没有再播放";
            break;
          case 0x6037:
            rv = "视频窗口不存在";
            break;
          case 0x6038:
            rv = "录像失败";
            break;
          case 0x6039:
            rv = "抓拍失败";
            break;
          case 0x604A:
            rv = "播放音频失败";
            break;
          case 0x8001:
            rv = "NC未加载";
            break;
          case 0x8002:
            rv = "NM未加载";
            break;
          case 0x8003:
            rv = "BSP未加载";
            break;
          case 0x8004:
            rv = "BSC未加载";
            break;
          case 0x8005:
            rv = "DW未加载";
            break;
          case 0xFFF0:
            rv = "连接站点IP不正确!";
            break;
          case 0xFFF1:
            rv = "正在连接站点中";
            break;
          case 0xFFF2:
            rv = "创建线程失败";
            break;
          case 0x8FF0:
            rv = "还未连接,无法获取连接状态!";
            break;
          default:
            rv = "发生错误("+parseInt(errorCode)+")";
            break;
        }  
      return rv;
    },
    
    /*
     *	函数名		：GetStationType
     *	函数功能	：获取站点类型,新设备根据GUID直接判断,老设备要通过stationmodel判断
     *	备注		：无
     *	作者		：Lingsen
     *	时间		：2008年11月14日
     *	返回值		：返回站点类型
     *	参数说明	：1个参数
     *		Object node     站点描述对象; 
     */
    GetStationType:function(node)
    {
        var rv = "";
        switch(parseInt(node.guid.substr(3,1))) 
        {
            case NrcapPlugs.NrcapStationType.station:
                // 旧设备要通过stationmodel判断	
                if
                (
                    node.model.search("CNVS-404A") != -1 ||
                    node.model.search("CNVS-101A") != -1 ||
                    node.model.search("CNVS-101C") != -1 ||
                    node.model.search("CR300PT") != -1 ||
                    node.model.search("CM300") != -1 ||
                    node.model.search("CM500") != -1 ||
                    node.model.search("CB1020C") != -1 ||
                    node.model.search("CR5004M") != -1 ||
                    node.model.search("CR5024C") != -1 ||
                    node.model.search("CW1021C") != -1 ||
                    node.model.search("CW1020C") != -1 ||
                    node.model.search("CW1010C") != -1 ||
                   (node.model.length >= 7 && (node.model.search("CR") == 0 || node.model.search("CZ") == 0  ) && node.model.substr(6,1) == 'L' )
                )
                {
                    rv = "ecoder";
                }
                else if
                (
                    (node.model.search("CNVS-202D") != -1 || node.model.search("CNVS-101D") != -1) || 
                    (node.model.length >= 7 && (node.model.search("CR") == 0 || node.model.search("CZ") == 0) && node.model.substr(6,1) == 'D')
                )
                {
                    rv = "decoder";
                }
                else if(node.model.search("Storager") != -1)
                {
                    rv = "storager";
                }
                else if 
                (
                    node.model.search("CDMA网关") != -1 ||
                    node.model.search("101C Gateway") != -1  ||
                    node.model.search("CMVGW-I") != -1
                )
                {
                    rv = "mobile_gateway";
                }                
                break;			                                
            case NrcapPlugs.NrcapStationType.ecoder:
                rv = "ecoder";
                break;			                                
            case NrcapPlugs.NrcapStationType.decoder:
                rv = "decoder";
                break;			                                
            case NrcapPlugs.NrcapStationType.storager:
                rv = "storager";
                break;		                                
            case NrcapPlugs.NrcapStationType.mobile_gateway:
                rv = "mobile_gateway";
                break;
            default:
                break;
        }
        return rv;
    },
    guidRex : /^0x[a-z0-9]{32}$/i,
    
    /*
     *	函数名		：Init
     *	函数功能	：初始化NrcapPlug
     *	备注		：无
     *	作者		：Lingsen
     *	时间		：2008年11月14日
     *	返回值		：NrcapError.NRCAP_SUCCESS 表示成功,其它对应NrcapError
     *	参数说明	：无
     */
    Init:function()
    {        
        try
        {
            // 加载插件
            var nm = this.ObjHtml.get("nm").replace("id=\"@id\" name=\"@name\"","id=\"NrcapPlugNM\" name=\"NrcapPlugNM\"");
            var nc = this.ObjHtml.get("nc").replace("id=\"@id\" name=\"@name\"","id=\"NrcapPlugNC\" name=\"NrcapPlugNC\"");
            var bsp = this.ObjHtml.get("bsp").replace("id=\"@id\" name=\"@name\"","id=\"NrcapPlugBSP\" name=\"NrcapPlugBSP\"");
            var bsc = this.ObjHtml.get("bsc").replace("id=\"@id\" name=\"@name\"","id=\"NrcapPlugBSC\" name=\"NrcapPlugBSC\"");
            
            if(!document.getElementById("NrcapPlugBox"))
            {
                var objNrcapPlugsBox = document.createElement("DIV");
                objNrcapPlugsBox.setAttribute("id","NrcapPlugBox");
                document.getElementsByTagName("body").item(0).appendChild(objNrcapPlugsBox);
            }
            
            objNrcapPlugsBox.style.display = "none";
            objNrcapPlugsBox.innerHTML = nm;
            objNrcapPlugsBox.innerHTML += nc;
            objNrcapPlugsBox.innerHTML += bsp;
            objNrcapPlugsBox.innerHTML += bsc;

            // 检测插件是否加载完成
            if (typeof NrcapPlugNC.startup == "undefined")
            {
                this.WarmTip.display();
                if (this.debug)
                {
                    alert("NrcapPlugNC load error.");
                }
                return this.NrcapError.NRCAP_ERROR_LOADPLUG_NC;
            }
            
            if(typeof NrcapPlugNM.startup == "undefined")
            {
                this.WarmTip.display();
                if (this.debug)
                {
                    alert("NrcapPlugNM load error.");
                }
                return this.NrcapError.NRCAP_ERROR_LOADPLUG_NM;
            }
            
            if (typeof NrcapPlugBSC.clear == "undefined")
            {
                this.WarmTip.display();
                if (this.debug)
                {
                    alert("NrcapPlugBSC load error.");
                }
                return this.NrcapError.NRCAP_ERROR_LOADPLUG_BSC;
            }
            
            if (typeof NrcapPlugBSP.dump == "undefined")
            {
                this.WarmTip.display();
                if (this.debug)
                {
                    alert("NrcapPlugBSP load error.");
                }
                return this.NrcapError.NRCAP_ERROR_LOADPLUG_BSP;
            }
            
            this.Plug.nc = NrcapPlugNC;
            this.Plug.nm = NrcapPlugNM;
            this.Plug.bsp = NrcapPlugBSP;
            this.Plug.bsc = NrcapPlugBSC;
            // 插件加载完成,开始
            var rv = this.Plug.nm.startup(16);
            if(rv.split("#")[0] != 0x0000)
            {
	            if (this.debug)
	            {
	                alert("startup failed:"+rv.split("#")[0]);
	            }
	            return this.NrcapError.NRCAP_ERROR_INIT_SOCKET_FAILED;
            }
            
            if (this.debug)
            {
                this.Plug.nm.enableDebugMessage(1);
            }
            else
            {
                this.Plug.nm.enableDebugMessage(0);
            }
            
            this.Plug.inited = true;
            return this.NrcapError.NRCAP_SUCCESS;
        }
        catch(e)
        {
            this.WarmTip.Display();
            if (this.debug)
            {
                alert("NrcapInit:"+e.message);
            }
            throw e;
            return this.NrcapError.NRCAP_ERROR_INIT_NRCAPPLUG_FAILED;
        }
    },
    
    /*
     *	函数名		：UnLoad
     *	函数功能	：卸载NrcapPlug
     *	备注		：无
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：NrcapError.NRCAP_SUCCESS 表示成功,其它对应NrcapError
     *	参数说明	：无
     */
    UnLoad:function()
    {
        if(this.Event.status)
        {
            this.Event.Stop();
        }
        
        var keys = this.Connections.keys().toArray();
                
        for(var i = 0;i < keys.length;i++)
        {
            this.DisConnection(keys[i]);
        }
        NrcapPlugs.Event.eventInfoList = new Array();
        this.Plug.nm.cleanup();
        if(document.getElementById("NrcapPlugBox"))
        {
            document.getElementsByTagName("body").item(0).removeChild(document.getElementById("NrcapPlugBox"));
        }   
        return this.NrcapError.NRCAP_SUCCESS;
    },
    
    /*
     *	函数名		：CreateConnection
     *	函数功能	：新建一个连接对象,保存在Connections组里
     *	备注		：无
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回connectId,其它对应NrcapError
     *	参数说明	：6个参数
     *	        string  ip                  连接站点ip
     *	        string  port                连接站点端口
     *	        string  username            连接站点用户
     *	        string  password            连接站点密码
     *	        NrcapClientType  clientType   连接站点客户端类型
     *	        object  callbackFunc        连接成功回调函数
     */
    CreateConnection:function(autoConnect,connParam,clientType,callbackFunc)
    {
        try
        {
            if (!this.Plug.inited)
            {                
                return this.NrcapError.NRCAP_ERROR_INIT_NRCAPPLUG_FAILED; 
            }
            
            connectId = new Date().getTime()+""+parseInt(Math.random()*(9999-1000+1)+1000);
            
            if (this.Connections.get(connectId) != null)
            {
                // 新建连接id已经存在,不可创建
                return this.NrcapError.NRCAP_ERROR_CONNECTIONID_ALREADY;
            }

			// 建立完成一个Connection对象
			var conn = 
			{
			    "id":connectId,
			    "connectStastus":"idel",
			    connParam:null,
			    "session":null,
			    connectionType:"server",
			    inputVideoResource:null,
			    resource:null,
			    ResourceToSortmerge:function(rule)
			    {
			        var resource = new Hash();
			        resource.set("root",{"name":"根节点","description":null,resource:null});
			        resource.set("ecoder",{"name":"编码器",resource:new Hash()});
			        resource.set("decoder",{"name":"解码器",resource:new Hash()});
			        resource.set("storager",{"name":"存储器",resource:new Hash()});
			        resource.set("mobile_gateway",{"name":"移动视频网关",resource:new Hash()});
                    
                    // 特殊处理直连站点
			        if(this.resource.keys().length == 1 && this.resource.get(this.resource.keys()) && (NrcapPlugs.GetStationType(this.resource.get(this.resource.keys())) == "ecoder" || (NrcapPlugs.GetStationType(this.resource.get(this.resource.keys())) == "mobile_gateway" && parseInt(this.resource.get(this.resource.keys()).guid.substr(3,1)) == NrcapPlugs.NrcapStationType.station ) ))
			        {
			            this.connectionType = "station";
			            //alert(NrcapPlugs.GetStationType(this.resource.get(this.resource.keys())));
			            var tmp = this.resource.get(this.resource.keys());
			            //alert(tmp.name+","+tmp.description+","+tmp.guid)
			            resource.get("root").name = tmp.name;
			            resource.get("root").description = tmp;
                        if(tmp.childResource != null && tmp.childResource.keys().length > 0)
                        {
                            resource.get("root").resource = new Hash();
                            tmp.childResource.each
                            (
                                function(item)
                                {
                                    var childnode = item.value;                                    
                                    if(resource.get("root") != null)
                                    {
                                        resource.get("root").resource.set(childnode.guid,childnode);
                                    }
                                }
                            )
                        }			             
			           
			        }
			        else
			        {
			            this.resource.each
			            (
			                function(item)
			                {
			                    var node = item.value;		// 根节点			                
			                    resource.get("root").name = node.name;
			                    resource.get("root").description = node;
		                        if(node.childResource != null && node.childResource.keys().length > 0)
		                        {			                
		                            node.childResource.each
		                            (
		                                function(item)
		                                {
		                                    var childnode = item.value;			                            
		                                    var stationType = NrcapPlugs.GetStationType(childnode);			                            
		                                    if(resource.get(stationType) != null)
		                                    {
		                                        resource.get(stationType).resource.set(childnode.guid,childnode);
		                                    }
		                                }
		                            )
		                        }
			                }
			            )			        
			        }
			        this.resource = resource;			        
			    }
			 };			 
			this.Connections.set(connectId,conn);
			
			// 是否自动连接站点
			if(autoConnect)
			{
			    this.Open(connectId,connParam,clientType,callbackFunc);
			}
			return connectId;
        }
        catch(e)
        {
            
            if (this.debug)
            {
                alert("Connection:"+e.message);
            }
            throw e;
            return this.NrcapError.NRCAP_ERROR_INIT_CONNECTION_FAILED;
        }
    },
    
    /*
     *	函数名		：Open
     *	函数功能	：连接站点
     *	备注		：连接是异步发生,通过回调函数返回连接结果
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：7个参数
     *	        object  connectId           连接对象ID
     *	        string  ip                  连接站点ip
     *	        string  port                连接站点端口
     *	        string  username            连接站点用户
     *	        string  password            连接站点密码
     *	        NrcapClientType  clientType   连接站点客户端类型
     *	        object  callbackFunc        连接成功回调函数
     */
    Open:function(connectId,connParam,clientType,callbackFunc)
    {        
        try
        {
            if (typeof connectId == "undefined" || connectId == "")
            {                
                connectId = this.CreateConnection();
                if (connectId == this.NrcapError.NRCAP_ERROR_INIT_CONNECTION_FAILED)
                {
                    return this.NrcapError.NRCAP_ERROR_INIT_CONNECTION_FAILED;
                }
            }
            
            if(this.Connections.get(connectId) != null)
            {
                // 准备连接
                if (this.Plug.inited)
                {
                    if(this.Plug.nc == null || this.Plug.bsp == null | this.Plug.bsc == null)
                    {
                        return this.NrcapError.NRCAP_ERROR_NRCAPPLUG_ISNULL;
                    }
                    
                    // 开始连接
                    //rv = this.Plug.nc.openNonBlock(ip+":"+port, username, password,savepwd, clientType);                    
                    rv = this.Plug.nc.openNonBlock(connParam.path,connParam.username, connParam.password,clientType);
			        if (rv.split("#")[0] != 0x0000)
			        {
				        //return {"stationindex" : -1,"inputvideoindex" : -1}; // 应该调回调
				        alert("连接失败!"+this.ShowErrorMessage(rv.split("#")[0]));
				        return this.NrcapError.NRCAP_ERROR_OPEN_CONNECT_FAILED;
			        }

                    this.Connections.get(connectId).connectStatus = "connecting";
                    this.Connections.get(connectId).connParam = connParam;
//                    this.Connections.get(connectId).connParam.port = port;
//                    this.Connections.get(connectId).connParam.username = username;
//                    this.Connections.get(connectId).connParam.password = password;
//                    this.Connections.get(connectId).connParam.savepwd = savepwd;
		
			        var self = this;
			        this.Timer.openTimer = setInterval(function(){self.Open_callback(connectId,callbackFunc)},100);
                    return this.NrcapError.NRCAP_SUCCESS;
                }
                else
                {
                    return this.NrcapError.NRCAP_ERROR_INIT_NRCAPPLUG_FAILED;
                }
            }
            else
            {
                return this.NrcapError.NRCAP_ERROR_CONNECTIONID_FAILED;
            }            
        }
        catch(e)
        {
            if (this.debug)
            {
                alert(e.message);
            }
            throw e;
            return this.NrcapError.NRCAP_ERROR_OPEN_CONNECT_FAILED;
        }
    },
    
    /*
     *	函数名		：Open_callback
     *	函数功能	：异步连接站点完成后处理方法
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：2个参数
     *	        object  connectId           连接对象ID
     *	        object  callbackFunc        连接成功回调函数
     */
    Open_callback:function(connectId,callbackFunc)
    {
        var queryrv = this.Plug.nc.queryOpenResult();
        //alert("queryopenresult:"+queryrv)
        if (queryrv.split("#")[0] == 0x0000)
        {
            clearInterval(this.Timer.openTimer);
            // 先找connectID是否正确
            if(this.Connections.get(connectId) != null)
            {
			    // 1. 连接成功,保存session
			    this.Connections.get(connectId).session = parseInt(queryrv.split("#")[1]);
			    this.Connections.get(connectId).connectStastus = "connected";
			    
			    // 2. 开始获取资源
			    var rv = this.CreateResource(connectId);
			    if (rv == this.NrcapError.NRCAP_SUCCESS)
			    {
			        // 资源列表创建完成
			        // 把资源分类,编码器,解码器,
			        this.Connections.get(connectId).ResourceToSortmerge();
			    }
			    
			    // 3. 如果有回调函数,调用回调
			    if(typeof callbackFunc == "function")
			    {
			        callbackFunc(this.NrcapError.NRCAP_SUCCESS);
			    } 
			    return this.NrcapError.NRCAP_SUCCESS;
            }
            else
            {			    
			    // 3. 如果有回调函数,调用回调
			    if(typeof callbackFunc == "function")
			    {
			        callbackFunc(this.NrcapError.NRCAP_ERROR_CONNECTIONID_FAILED);
			    } 
                return this.NrcapError.NRCAP_ERROR_CONNECTIONID_FAILED;
            }
            
        }
		else if(queryrv.split("#")[0] != 0x0001)
		{
		    clearInterval(this.Timer.openTimer);
		    if(this.debug)
		    {
		        alert("Open_callback:"+this.ShowErrorMessage(queryrv.split("#")[0]));
		    }			    
		    // 3. 如果有回调函数,调用回调
		    if(typeof callbackFunc == "function")
		    {
		        callbackFunc(queryrv.split("#")[0]);
		    } 
		    return this.NrcapError.NRCAP_ERROR_CONNECTIONID_FAILED;
		}
    },
    
    /*
     *	函数名		：DisConnection
     *	函数功能	：删除一个连接对象
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：1个参数
     *	        object  connectId           连接对象ID
     */
    DisConnection:function(connectId)
    {
        if (!this.Plug.inited)
        {                
            return this.NrcapError.NRCAP_ERROR_INIT_NRCAPPLUG_FAILED; 
        }
       
        if (this.Connections.get(connectId) != null && this.Connections.get(connectId).session != null)
        {
            // 删除这个连接的窗口和视频            
            this.DiscardWindowsByConnectID(connectId);
            
            this.Plug.nc.close(this.Connections.get(connectId).session);
            var rv = this.Connections.unset(connectId);
            if (rv != null)
            {
                return this.NrcapError.NRCAP_SUCCESS;
            }
            else
            {
                return this.NrcapError.NRCAP_ERROR_DISCONNECTION_FAILED;
            }
        }
        else
        {
            return this.NrcapError.NRCAP_ERROR_CONNECTIONID_FAILED;
        }
    },
    
    /*
     *	函数名		：CreateResource
     *	函数功能	：创建资源列表
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：2个参数
     *	        object  connectId           连接对象ID
     *	        string  stationGuid         连接站点GUID
     */    
    CreateResource:function(connectId,stationGuid)
    {
        if (!this.Plug.inited)
        {                
            return this.NrcapError.NRCAP_ERROR_INIT_NRCAPPLUG_FAILED; 
        }
        
        if (this.Connections.get(connectId) != null && this.Connections.get(connectId).session != null)
        {
			if(typeof stationGuid == "undefined" || stationGuid == "")
			{
			    stationGuid = "0x00000000000000000000000000000000";
			}
			
			try
			{
		        this.Connections.get(connectId).resource = this.GetResourceEx(this.Connections.get(connectId).session);
			}
			catch(e)
			{
			    if (this.debug)
			    {
			        alert("CreateResource:创建资源列表异常("+e.message+")");
			    }
			    return this.NrcapError.NRCAP_ERROR_CREATE_RESOURCE_FAILED;
			}
			return this.NrcapError.NRCAP_SUCCESS;
        }
        else
        {
            return this.NrcapError.NRCAP_ERROR_CONNECTIONID_FAILED;
        }    
    },
    
    /*
     *	函数名		：GetResource
     *	函数功能	：获取资源
     *	备注		：注:在发生递归获取资源时bsp不能用同一个,否则分析会出错
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回资源hash列表 其它对应NrcapError
     *	参数说明	：3个参数
     *	        object  session             连接对象session
     *	        string  stationGuid         连接站点GUID
     *	        object  controlId           获取GUID描述的controlID
     */    
    GetResourceEx:function(session,stationGuid,controlId)
    {
        try
        {
            var rv = "";
            
            // 如果没有传入站点GUID,默认为根
            if(typeof stationGuid == "undefined" || stationGuid == "")
            {
                stationGuid = "0x00000000000000000000000000000000";
            }
            // 如果没有controlid,默认为获取站点GUID的control命令        
            if(typeof controlId == "undefined" || controlId == "")
            {
                controlId = this.NrcapControlID.Nrcap_GetStationGUID;// 0x00010000;
            }
            
            var resource = new Hash();
            var rv = null;
            
            // 建立一个临时的bsp插件分析资源列表
		    if(!document.getElementById("NrcapPlugBox"))
            {
                var objNrcapPlugsBox = document.createElement("DIV");
                objNrcapPlugsBox.setAttribute("id","NrcapPlugBox");
                document.getElementsByTagName("body").item(0).appendChild(objNrcapPlugsBox);
            }
            document.getElementById("NrcapPlugBox").innerHTML += this.ObjHtml.get("bsp").replace("id=\"@id\" name=\"@name\"","id=\"NrcapPlugBSP"+stationGuid+"\" name=\"NrcapPlugBSP"+stationGuid+"\"");

		    var t_bsp = document.getElementById("NrcapPlugBSP"+stationGuid);
		    if(!t_bsp)
		    {
		        if (this.debug)
		        {
		            alert("GetResourceEx:创建临时bsp对象出错");
		        }
		        return resource;
		    }
		    
            // 获取站点GUID
            if(controlId == this.NrcapControlID.Nrcap_GetStationGUID)
            {
	            rv = this.Plug.nc.control(session, stationGuid, controlId, 0, 0, 0);
	            if (rv.split("#")[0] != 0x0000)
	            {
		            if (this.debug)
		            {
		                alert("get station guid failed:"+rv.split("#")[0]);
		            }
		            return resource;
	            }
	            t_bsp.attachBuffer(parseInt(rv.split("#")[1]), parseInt(rv.split("#")[2]));
	            stationGuid = t_bsp.parseGuid();					
	            this.Plug.nc.dealloc(parseInt(rv.split("#")[1]));
	            
    	        // 获取站点GUID描述    	        
    	        rv = this.Plug.nc.control(session,stationGuid,this.NrcapControlID.Nrcap_GetGUIDDescription,0,0,0);
	            if (rv.split("#")[0] != 0x0000)
	            {
		            if (this.debug)
		            {
		                alert("get station description failed:"+this.ShowErrorMessage(rv.split("#")[0]));
		            }
		            return resource;         
	            }
	            t_bsp.attachBuffer(parseInt(rv.split("#")[1]), parseInt(rv.split("#")[2]));
			    var guid = t_bsp.parseGuid();
			    var type = t_bsp.parseString();		
			    var name = t_bsp.parseString();
			    var description = t_bsp.parseString();
			    var usable = t_bsp.parseUchar();
			    var enable = t_bsp.parseUchar();
			    var model = "cesserver";
	            this.Plug.nc.dealloc(parseInt(rv.split("#")[1])); 
	            
	            // 获取登录的StationModel
	            if(guid.substring(0,4) == "0x02")
	            {	            
	                // 中心管理服务器
	                model = "cesserver";
	            }
	            else
	            {
	                var model = this.Plug.nc.getStringConfig(session,guid,this.NrcapConfigerID.Nrcap_GetStationModel);
			        if (model.split("#")[0] == 0x0000 )
			        {
			            model = model.split("#")[1];
			        }
	                
	            }
	            
	            // 返回站点描述	               	        
	            var station = {"guid":stationGuid,"type":type,"model":model,"name":name,"description":description,"usable":usable,"enable":enable,"childResource":this.GetResourceEx(session,stationGuid,this.NrcapControlID.Nrcap_GetChildrenGUIDDescriptionArray)};
	         
	            resource.set(stationGuid,station);
            }
            else if(controlId == this.NrcapControlID.Nrcap_GetChildrenGUIDDescriptionArray)            // 获取站点资源GUID描述
            {
                var stationModel = this.Plug.nc.getStringConfig(session,stationGuid,this.NrcapConfigerID.Nrcap_GetStationModel);
		        if (stationModel.split("#")[0] == 0x0000 )
		        {
		            stationModel = stationModel.split("#")[1];
		        }
		        else
		        {
		            stationModel = "station"
		        }
		        //CMVGW-I
		        
		        if(stationModel.toLowerCase() == "cmvgw-i" && parseInt(stationGuid.substr(3,1)) == NrcapPlugs.NrcapStationType.station)
		        {
		            controlId = this.NrcapControlID.Nrcap_GetStationChildrenGUIDArray;
                    
			        rv = this.Plug.nc.control(session, stationGuid, controlId, 0, 0, 0);
    			    
			        if (rv.split("#")[0] != 0x0000)
			        {
				        if(this.debug) alert("get child guid array failed:"+this.ShowErrorMessage(rv.split("#")[0]));
				        
				        return null;
			        }
        			
			        t_bsp.attachBuffer(parseInt(rv.split("#")[1]), parseInt(rv.split("#")[2]));
    			    
			        var t_childnum = t_bsp.parseUint();
			        var t_childguids = new Array();
			        for(var i = 0;i < t_childnum;i++)
			        {
			            t_childguids.push(t_bsp.parseGuid());
			        }
			        this.Plug.nc.dealloc(parseInt(rv.split("#")[1]));
			       
			        
			        for(var i = 0;i < t_childnum;i++)
			        {
			            rv = this.Plug.nc.control(session,t_childguids[i],this.NrcapControlID.Nrcap_GetGUIDDescription,0, 0, 0);
			            if (rv.split("#")[0] != 0x0000)
	                    {
		                    if (this.debug)
		                    {
		                        alert("get station description failed:"+this.ShowErrorMessage(rv.split("#")[0]));
		                    }
		                    this.Plug.nc.dealloc(parseInt(rv.split("#")[1]));
		                    continue;
		                    //return resource;         
	                    }
	                    t_bsp.attachBuffer(parseInt(rv.split("#")[1]), parseInt(rv.split("#")[2]));
			            var guid = t_bsp.parseGuid();
			            var type = t_bsp.parseString();		
			            var name = t_bsp.parseString();
			            var description = t_bsp.parseString();
			            var usable = t_bsp.parseUchar();
			            var enable = t_bsp.parseUchar();

	                    var model = "resource";
	                    var station = {"guid":guid,"type":type,"model":model,"name":name,"description":description,"usable":usable,"enable":enable,"childResource":childResource};
    	                //alert(type)
	                    // platform_manager和archiver类型资源不用
	                    if (type != this.NrcapResourceType.platform_manager && type != this.NrcapResourceType.archiver && enable == 1)
	                    { 
	                        resource.set(guid,station);
	                    }
			            this.Plug.nc.dealloc(parseInt(rv.split("#")[1]));
			        }
		        }
		        else
		        {
                    //alert(resource.get(stationGuid).model);
                    
			        rv = this.Plug.nc.control(session, stationGuid, controlId, 0, 0, 0);
			        if (rv.split("#")[0] != 0x0000)
			        {
				        if (this.debug) alert("get child guid array failed:"+this.ShowErrorMessage(rv.split("#")[0]));
				        
				        return null;
			        }
        			
			        t_bsp.attachBuffer(parseInt(rv.split("#")[1]), parseInt(rv.split("#")[2]));
    			    
			        var t_childnum = t_bsp.parseUint();
			        //t_childnum = 0;
    			    //alert(t_childnum)
			        for(var i = 0;i < t_childnum;i++)
			        {			       
				        var guid = t_bsp.parseGuid();
				        var type = t_bsp.parseString();
				        var name = t_bsp.parseString();
				        var description = t_bsp.parseString();
				        var usable = t_bsp.parseUchar();
				        var enable = t_bsp.parseUchar();
				        var childResource = null;
	                    var model = "resource";
    	                
				        if(type.toLowerCase() == "station")
				        {
				            model = this.Plug.nc.getStringConfig(session,guid,this.NrcapConfigerID.Nrcap_GetStationModel);
				            if (model.split("#")[0] == 0x0000 )
				            {
				                model = model.split("#")[1];
				            }
				            else
				            {
				                if (this.debug) alert(this.ShowErrorMessage(model.split("#")[0]));
				            }
				            //alert(name+"model:"+rv)
				            //model = rv;
    				        
					        //childResource = this.GetResourceEx(session,guid,this.NrcapControlID.Nrcap_GetChildrenGUIDDescriptionArray);
				        }
    				    
				        t_bsp.parsePad4();
	                    var station = {"guid":guid,"type":type,"model":model,"name":name,"description":description,"usable":usable,"enable":enable,"childResource":childResource};
    	                
	                    // platform_manager和archiver类型资源不用
	                    if (type != this.NrcapResourceType.platform_manager && type != this.NrcapResourceType.archiver && enable == 1)
	                    { 
	                        resource.set(guid,station);
	                    }	                
			        }
		            this.Plug.nc.dealloc(parseInt(rv.split("#")[1]));
		        
		        }
		        
			    document.getElementById("NrcapPlugBox").removeChild($("NrcapPlugBSP"+stationGuid));
            }
        }
        catch(e)
        {
            if (this.debug)
            {
                alert("GetResource:获取"+stationGuid+"("+name+")"+"资源异常("+e.name+e.description+")");
            }            
            return resource;
        }     
        return resource;
    },  
    GetResource:function(session,stationGuid,controlId)
    {
        try
        {
            var rv = "";
            
            // 如果没有传入站点GUID,默认为根
            if(typeof stationGuid == "undefined" || stationGuid == "")
            {
                stationGuid = "0x00000000000000000000000000000000";
            }
            // 如果没有controlid,默认为获取站点GUID的control命令        
            if(typeof controlId == "undefined" || controlId == "")
            {
                controlId = this.NrcapControlID.Nrcap_GetStationGUID;// 0x00010000;
            }
            
            var resource = new Hash();
            var rv = null;
            
            // 建立一个临时的bsp插件分析资源列表
		    if(!document.getElementById("NrcapPlugBox"))
            {
                var objNrcapPlugsBox = document.createElement("DIV");
                objNrcapPlugsBox.setAttribute("id","NrcapPlugBox");
                document.getElementsByTagName("body").item(0).appendChild(objNrcapPlugsBox);
            }
            document.getElementById("NrcapPlugBox").innerHTML += this.ObjHtml.get("bsp").replace("id=\"@id\" name=\"@name\"","id=\"NrcapPlugBSP"+stationGuid+"\" name=\"NrcapPlugBSP"+stationGuid+"\"");

		    var t_bsp = document.getElementById("NrcapPlugBSP"+stationGuid);
		    if(!t_bsp)
		    {
		        if (this.debug)
		        {
		            alert("GetResource:创建临时bsp对象出错");
		        }
		        return resource;
		    }
		    
            // 获取站点GUID
            if(controlId == this.NrcapControlID.Nrcap_GetStationGUID)
            {
	            rv = this.Plug.nc.control(session, stationGuid, controlId, 0, 0, 0);
	            if (rv.split("#")[0] != 0x0000)
	            {
		            if (this.debug)
		            {
		                alert("get station guid failed:"+rv.split("#")[0]);
		            }
		            return resource;
	            }
	            t_bsp.attachBuffer(parseInt(rv.split("#")[1]), parseInt(rv.split("#")[2]));
	            stationGuid = t_bsp.parseGuid();					
	            this.Plug.nc.dealloc(parseInt(rv.split("#")[1]));
	            
    	        // 获取站点GUID描述    	        
    	        rv = this.Plug.nc.control(session,stationGuid,this.NrcapControlID.Nrcap_GetGUIDDescription,0,0,0);
	            if (rv.split("#")[0] != 0x0000)
	            {
		            if (this.debug)
		            {
		                alert("get station description failed:"+this.ShowErrorMessage(rv.split("#")[0]));
		            }
		            return resource;         
	            }
	            t_bsp.attachBuffer(parseInt(rv.split("#")[1]), parseInt(rv.split("#")[2]));
			    var guid = t_bsp.parseGuid();
			    var type = t_bsp.parseString();		
			    var name = t_bsp.parseString();
			    var description = t_bsp.parseString();
			    var usable = t_bsp.parseUchar();
			    var enable = t_bsp.parseUchar();
			    var model = "cesserver";
	            this.Plug.nc.dealloc(parseInt(rv.split("#")[1])); 
	            
	            // 获取登录的StationModel
	            if(guid.substring(0,4) == "0x02")
	            {	            
	                // 中心管理服务器
	                model = "cesserver";
	            }
	            else
	            {
	                var model = this.Plug.nc.getStringConfig(session,guid,this.NrcapConfigerID.Nrcap_GetStationModel);
			        if (model.split("#")[0] == 0x0000 )
			        {
			            model = model.split("#")[1];
			        }
	                
	            }
	            
	            // 返回站点描述	               	        
	            var station = {"guid":stationGuid,"type":type,"model":model,"name":name,"description":description,"usable":usable,"enable":enable,"childResource":this.GetResource(session,stationGuid,this.NrcapControlID.Nrcap_GetChildrenGUIDDescriptionArray)};
	         
	            resource.set(stationGuid,station);
            }
            else if(controlId == this.NrcapControlID.Nrcap_GetChildrenGUIDDescriptionArray)            // 获取站点资源GUID描述
            {
			    rv = this.Plug.nc.control(session, stationGuid, controlId, 0, 0, 0);
    			
			    if (rv.split("#")[0] != 0x0000)
			    {
				    if (this.debug) alert("get child guid array failed:"+this.ShowErrorMessage(rv.split("#")[0]));
				    
				    return null;
			    }
    			
			    t_bsp.attachBuffer(parseInt(rv.split("#")[1]), parseInt(rv.split("#")[2]));
			    
			    var t_childnum = t_bsp.parseUint();
			    //t_childnum = 0;
    			//alert(t_childnum)
			    for(var i = 0;i < t_childnum;i++)
			    {			       
				    var guid = t_bsp.parseGuid();
				    var type = t_bsp.parseString();
				    var name = t_bsp.parseString();
				    var description = t_bsp.parseString();
				    var usable = t_bsp.parseUchar();
				    var enable = t_bsp.parseUchar();
				    var childResource = null;	               
	                var model = "resource";
	                
				    if(type.toLowerCase() == "station")
				    {
				        var model = this.Plug.nc.getStringConfig(session,guid,this.NrcapConfigerID.Nrcap_GetStationModel);
				        if (model.split("#")[0] == 0x0000 )
				        {
				            model = model.split("#")[1];
				        }
				        else
				        {
				            alert(this.ShowErrorMessage(model.split("#")[0]));
				        }
				        //alert(name+"model:"+rv)
				        //model = rv;
				        
					    childResource = this.GetResource(session,guid,this.NrcapControlID.Nrcap_GetChildrenGUIDDescriptionArray);
				    }
				    
				    t_bsp.parsePad4();
	                var station = {"guid":guid,"type":type,"model":model,"name":name,"description":description,"usable":usable,"enable":enable,"childResource":childResource};
	                
	                // platform_manager和archiver类型资源不用
	                if (type != this.NrcapResourceType.platform_manager && type != this.NrcapResourceType.archiver)
	                { 
	                    resource.set(guid,station);
	                }	                
			    }
		        this.Plug.nc.dealloc(parseInt(rv.split("#")[1]));				
			    document.getElementById("NrcapPlugBox").removeChild($("NrcapPlugBSP"+stationGuid));
            }
        }
        catch(e)
        {
            if (this.debug)
            {
                alert("GetResource:获取"+stationGuid+"("+name+")"+"资源异常("+e.name+e.description+")");
            }            
            return resource;
        }     
        return resource;
    },
    
    /*
     *	函数名		：ResourceSort
     *	函数功能	：对资源进行排序
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回排序完成资源hash列表
     *	参数说明	：3个参数
     *	        object  resource           要排序的资源Hash列表
     *	        string  sorttype           排序关键字
     */
    ResourceSort:function(resource,sorttype)
    {
        try
        {
            var resourceSort = new Hash();        
            if(sorttype == "key")           // 1. 根据key即GUID排序
            {        
                var keys = resource.keys().sort();
                for(var i = 0;i < keys.length;i++)
                {
                    resourceSort.set(keys[i],resource.get(keys[i]));
                }
            }
            else if(sorttype = "name")      // 2. 根据站点名称排序
            {
                var names = new Array();
                resource.each
                (
                    function(item)
                    {
                        names.push([item.key,item.value.name]);
                    }
                )
                //names.sort(function(left,right){return left[1]<right[1]?-1:1});
                
                // 这种方法可以根据用本地特定的顺序来比较两个字符串
                names.sort(function(left,right){return left[1].localeCompare(right[1])});
                for(var i = 0;i < names.length;i++)
                {
                    resourceSort.set(names[i][0],resource.get(names[i][0]));
                }
            }
            else
            {
                resourceSort = resource;
            }
            return resourceSort;        
        }
        catch(e)
        {
            if (this.debug)
            {
                alert("ResourceSort:"+e.message+","+e.name);
                throw e;
                return resource;
            }
        }
    },
    
    /*
     *	函数名		：ResourceIndexOf
     *	函数功能	：从资源树里查找节点信息
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回节点对象
     *	参数说明	：1个参数
     *	        string  guid                节点GUID
     */
    ResourceIndexOf:function(guid)
    {
        try
        {
            var keys = this.Connections.keys().toArray();
            for(var i = 0;i < keys.length;i++)
            {
                var li = this.Connections.get(keys[i]).inputVideoResource;
                if(li.keys().toString().indexOf(guid.substr(21,12)) != -1)
                {
                    return true;
                }                
            }
            
            return false;
        }
        catch(e)
        {
            if(this.debug)
            {
                alert("ResourceIndexOf:"+e.message+","+e.name);                
            }
            return this.NrcapError.NRCAP_ERROR_RESOURCEINDEXOF_FAILED;
        }
    },
    
    /*
     *	函数名		：GetDesciption
     *	函数功能	：从资源树里查找节点信息
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回节点对象
     *	参数说明	：3个参数
     *	        string  connectId           连接ID
     *	        string  guid                节点GUID
     *	        string  parentIndexs        父节点索引组
     */
    GetDesciption:function(connectId,guid,parentIndexs)
    {
        try
        {
            if(parentIndexs)
            {            
                keys = parentIndexs.split(",");                
            }
            var node = this.Connections.get(connectId).inputVideoResource;
            for(var i = 1;i < keys.length;i++)
            {
                if(node.get(keys[i]))
                {                    
                    node = node.get(keys[i]).childResource;
                }            
            }
            return node.get(guid);
        }
        catch(e)
        {
            if(this.debug)
            {
                alert("GetDescription:"+e.message+","+e.name);                
            }
            return this.NrcapError.NRCAP_ERROR_GETDESCRIPTION_FAILED;
        }
    },
    
    /*
     *	函数名		：GetBindedPTZGuid
     *	函数功能	：根据视频GUID获取绑定的云台资源GUID
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回节点对象
     *	参数说明	：3个参数
     *	        string  connectId           连接ID
     *	        string  ivguid              视频GUID
     */
    GetBindedPTZGuid:function(connectId,ivguid)
    {
        try
        {
            if(!connectId || !this.Connections.get(connectId))
            {
                if(this.debug)
                {
                    alert("GetPTZGuid:connectId不正确!")
                }
                return this.NrcapError.NRCAP_ERROR_GET_BINDEDPTZ_FAILED;
            }
            
            if(!ivguid)
            {
                if(this.debug)
                {
                    alert("GetPTZGuid:input video guid 不正确!")
                }
                return this.NrcapError.NRCAP_ERROR_GET_BINDEDPTZ_FAILED;
            }
            
		    rv = this.Plug.nc.getGuidConfig(this.Connections.get(connectId).session, ivguid, this.NrcapConfigerID.Nrcap_GetBindedPTZ);
		    if (rv.split("#")[0] == 0x0000)						
		    {
			    ptzguid = rv.split("#")[1];
			    return ptzguid;
		    }
		    else
		    {
			    if (this.debug) alert("获取视频的云台GUID失败("+this.ShowErrorMessage(rv.split("#")[0])+")!");
			    
			    return this.NrcapError.NRCAP_ERROR_GET_BINDEDPTZ_FAILED;
		    }
        
        }
        catch(e)
        {
            if(this.debug)
            {
                alert("GetBindedPTZGuid:"+e.message+","+e.name);                
            }
            return this.NrcapError.NRCAP_ERROR_GET_BINDEDPTZ_FAILED;
        }
    },
    
    GetConfig:function(session,type,guid,configId)
    {
        try
        {
            var rv = this.NrcapError.NRCAP_ERROR_GETCONFIG_FAILED;
            switch(type)
            {
                case this.NrcapDataFormat.uchar:
                    rv = this.Plug.nc.getUcharConfig(session, guid, configId);
                    break;
                case this.NrcapDataFormat.uint:
                    rv = this.Plug.nc.getUintConfig(session, guid, configId);
                    break;
                case this.NrcapDataFormat.ushort:
                    rv = this.Plug.nc.getUshortConfig(session, guid, configId);                    
                    break;
                case this.NrcapDataFormat.string:
                    rv = this.Plug.nc.getStringConfig(session, guid, configId);
                    break;
                case this.NrcapDataFormat.single:
				    rv = this.Plug.nc.getSingleConfig(session,guid,configId);				
				    if (rv.split("#")[0] == 0x0000)
				    {
					    this.Plug.bsp.attachbuffer(parseInt(rv.split("#")[1]), parseInt(rv.split("#")[2]));				
					    len = this.Plug.bsp.parseUint();					
					    var buffer = "";
					    for(var i= 0;i < len;i++)
					    {
						    var t_uchar = this.Plug.bsp.parseUchar().toString(16).toUpperCase();
						    buffer += (t_uchar.length < 2 ? "0"+t_uchar : t_uchar);
					    }
					    this.Plug.nc.dealloc(parseInt(rv.split("#")[1]));
					    rv = "0x0000#"+buffer;
				    }
                    break;
                default:
                    break;
            }
        
        }
        catch(e)
        {
            if(this.debug)
            {
                alert("GetConfig:"+e.message+","+e.name);
            }
            
        }
        return rv;
    },
    
    SetConfig:function(session,type,guid,configId,value)
    {
        try
        {
            var rv = this.NrcapError.NRCAP_ERROR_SETCONFIG_FAILED;
            switch(type)
            {
                case this.NrcapDataFormat.uchar:
                    rv = this.Plug.nc.setUcharConfig(session, guid, configId,value,0);
                    break;
                case this.NrcapDataFormat.uint:
                    rv = this.Plug.nc.setUintConfig(session, guid, configId,value,0);
                    break;
                case this.NrcapDataFormat.ushort:
                    rv = this.Plug.nc.setUshortConfig(session, guid, configId,value,0);
                    break;
                case this.NrcapDataFormat.string:
                    rv = this.Plug.nc.setStringConfig(session, guid, configId,value,0);
                    break;
                case this.NrcapDataFormat.single:
				    this.Plug.bsc.clear();
//				    if(param == "snapshotschedule" || param == "uploadsnapshotschedule" || param == "uploadrecordschedule")
//				    {
//					    var len = value.length/2;
//					    this.bsc.addUint(len);	
//					    var xx = "";
//					    for(var i = 0;i < len;i++)
//					    {
//						    this.bsc.addUchar(parseInt("0x"+value.substr(i*2,2)));
//					    }
//				    }
//				    rv = this.Plug.nc.setSingleConfig(session, guid,configId, this.Plug.bsc.getbuffer(),this.Plug.bsc.getlength(),0);
				    this.Plug.bsc.clear();
                    break;
                default:
                    break;
            }
        
        }
        catch(e)
        {
            if(this.debug)
            {
                alert("SetConfig:"+e.message+","+e.name);
            }
            
        }
        return rv;
    },
    
    PreviewConfig:function(session,type,guid,configId,value)
    {
        try
        {
            var rv = this.NrcapError.NRCAP_ERROR_SETCONFIG_FAILED;
            switch(type)
            {
                case this.NrcapDataFormat.uchar:
                    rv = this.Plug.nc.previewUcharConfig(session, guid, configId,value,0);
                    break;
                case this.NrcapDataFormat.uint:
                    rv = this.Plug.nc.previewUintConfig(session, guid, configId,value,0);
                    break;
                case this.NrcapDataFormat.ushort:
                    rv = this.Plug.nc.previewUshortConfig(session, guid, configId,value,0);
                    break;
                case this.NrcapDataFormat.string:
                    rv = this.Plug.nc.previewStringConfig(session, guid, configId,value,0);
                    break;
                case this.NrcapDataFormat.single:
				    this.Plug.bsc.clear();
                    break;
                default:
                    break;
            }
        
        }
        catch(e)
        {
            if(this.debug)
            {
                alert("SetConfig:"+e.message+","+e.name);
            }
            
        }
        return rv;
    },
    
    Control:function()
    {
    
    },
    GetPTZSpeed:function(connectId,ivguid)
    {
        var rv = 0;
        var ptzguid = this.GetBindedPTZGuid(connectId,ivguid);
        if(this.guidRex.test(ptzguid))
        {
            rv = this.GetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.uchar,ptzguid,this.NrcapConfigerID.NRCAP_CFGID_PTZ_Speed);
            rv = parseInt(rv.split("#")[1]);
        }
        return rv;
    },
    SetPTZSpeed:function(connectId,ivguid,value)
    {
        var rv = 0;
        var ptzguid = this.GetBindedPTZGuid(connectId,ivguid);
        if(this.guidRex.test(ptzguid))
        {
            rv = this.SetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.uchar,ptzguid,this.NrcapConfigerID.NRCAP_CFGID_PTZ_Speed,value);//this.SetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.uchar,ptzguid,this.NrcapConfigerID.NRCAP_CFGID_PTZ_Speed);
            rv = parseInt(rv.split("#")[1]);
        }
        return rv;
    },
    
    GetInputVideoParam:function(connectId,ivguid,param)
    {
        var rv = 0;
        if(param == "brightness")
        {
            rv = this.GetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoBrightness);
        }
        else if(param == "contrast")
        {
            rv = this.GetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoContrast);
        }
        else if(param == "hue")
        {
            rv = this.GetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoHue);
        }
        else if(param == "saturation")
        {
            rv = this.GetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoSaturation);
        }
        
        if(!rv || rv == "" || rv == 0)
        {
            rv = 0;
        }
        else if(rv.split("#")[0] != 0x0000)
        {
            if (this.debug)
            {
                alert("GetInputVideoParam:"+rv+","+this.ShowErrorMessage(rv.split("#")[0]));
            }
           rv = 0;
        }
        else
        {
            rv = parseInt(rv.split("#")[1]);
        }
        return rv;
    },
    
    SetInputVideoParam:function(connectId,ivguid,param,value)
    {
        var rv = 0;
        if(param == "brightness")
        {
            rv = this.SetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoBrightness,value);
        }
        else if(param == "contrast")
        {
            rv = this.SetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoContrast,value);
        }
        else if(param == "hue")
        {
            rv = this.SetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoHue,value);
        }
        else if(param == "saturation")
        {
            rv = this.SetConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoSaturation,value);
        }
        
        if(rv != this.NrcapError.NRCAP_ERROR_SETCONFIG_FAILED)
        {
            rv = this.NrcapError.NRCAP_SUCCESS;
        }
        else
        {
            rv = this.NrcapError.NRCAP_ERROR_SETCONFIG_FAILED;
        }
        return rv;
    },
    
    PreviewInputVideoParam:function(connectId,ivguid,param,value)
    {
        var rv = 0;
        if(param == "brightness")
        {
            rv = this.PreviewConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoBrightness,value);
        }
        else if(param == "contrast")
        {
            rv = this.PreviewConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoContrast,value);
        }
        else if(param == "hue")
        {
            rv = this.PreviewConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoHue,value);
        }
        else if(param == "saturation")
        {
            rv = this.PreviewConfig(this.Connections.get(connectId).session,this.NrcapDataFormat.ushort,ivguid,this.NrcapConfigerID.Nrcap_GetInputVideoSaturation,value);
        }
        
        if(rv != this.NrcapError.NRCAP_ERROR_SETCONFIG_FAILED)
        {
            rv = this.NrcapError.NRCAP_SUCCESS;
        }
        else
        {
            rv = this.NrcapError.NRCAP_ERROR_SETCONFIG_FAILED;
        }
        return rv;
    },
    
    // Windows对象组,没有定义成数组Array形式是为了通过key直接访问
    Windows:new Hash(),
    
    /*
     *	函数名		：InitWindows
     *	函数功能	：初始化播放窗口
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回NRCAP_SUCCESS
     *	参数说明	：0个参数
     */
    InitWindows:function()
    {
        var keys = this.Windows.keys();
        for(var i = 0;i < keys.lenght;i++)        
        {
            this.DiscardWindow(keys[i]);
        }
        this.Windows = new Hash();
        return this.NrcapError.NRCAP_SUCCESS;
    },
    
    /*
     *	函数名		：CreateWindow
     *	函数功能	：初始化一个视频窗口对象
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回窗口对象 其它对应NrcapError
     *	参数说明	：3个参数
     *	        string          connectId               连接ID
     *	        string          containerId             视频窗口容器ID
     *	        WindowEvent     windowEvent             视频窗口需要绑定的事件
     */
    CreateWindow:function(connectId,containerId,windowEvent)
    {
        try
        {                
            if(!document.getElementById(containerId))
            {
                if (this.debug)
                {
                    alert("InitWindow:视频窗口容器不存在!");
                }
                return this.NrcapError.NRCAP_ERROR_INIT_WINDOW_FAILED;
            }
		    var t_wndname = containerId+"_wnd";		    
		    var t_nmname = new Date().getTime()+""+parseInt(Math.random()*(999-100+1)+100)+"_nm";
		    
		    var t_wndwidth = document.getElementById(containerId).offsetWidth-2;
		    var t_wndheight = document.getElementById(containerId).offsetHeight-2;
		   
            document.getElementById(containerId).innerHTML = "<OBJECT classid=\"CLSID:C1A33A67-A0F2-42E0-80B6-38EFBDD8AD18\" id=\""+t_wndname+"\" name=\""+t_wndname+"\" width=\""+t_wndwidth+"\" height=\""+t_wndheight+"\" codebase=\"WebPlugs.cab#version=1,2008,12,24\" style=\"border:1px solid #FFFFFF;\" ><param name=\"_Version\" value=\"65536\"><param name=\"_ExtentX\" value=\"9313\"><param name=\"_ExtentY\" value=\"7620\"><param name=\"_StockProps\" value=\"0\"></OBJECT>";
            
            if (!document.getElementById(t_nmname))
            {
                document.getElementById("NrcapPlugBox").innerHTML += "<OBJECT ID=\""+t_nmname+"\" name=\""+t_nmname+"\" CLASSID=\"CLSID:50C1C74B-233C-4790-8440-6426E46BE53E\" style=\"display:none;\" codebase=\"WebPlugs.cab#version=1,2009,2,23\"></OBJECT>" ;
            }
            
            if(!document.getElementById(t_wndname))
            {
                return this.NrcapError.NRCAP_ERROR_INIT_WINDOW_FAILED;
            }
            
            // 设置窗口样式
            document.getElementById(t_wndname).enableFullScreen(false);
            document.getElementById(t_nmname).enableMask(false);
            
            var wnd = {
                wnd:document.getElementById(t_wndname),
                nm:document.getElementById(t_nmname),
                wndname:t_wndname,
                nmname:t_nmname,
                connectId:connectId,
                ivguid:null,
                ptzguid:null,                
                style:{
                    enableFullScreen:false,
                    enableMask:false
                },
                status:{
                    playvideoing:false,
                    recording:false,
                    playaudioing:false,
                    upaudioing:false
                }
            };
            // 绑定窗口事件
            if(windowEvent)
            {
                this.WindowAttachEvent(windowEvent,wnd);
            }
            return wnd;
        }
        catch(e)
        {
            if (this.debug)
            {
                alert("CreateWindow:"+e.message+e.name);
            }
            throw e;
            return this.NrcapError.NRCAP_ERROR_INIT_WINDOW_FAILED;
        }
    },
    
    /*
     *	函数名		：ReCreateWindow
     *	函数功能	：初始化一个视频窗口对象
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回窗口对象 其它对应NrcapError
     *	参数说明	：1个参数
     *	        string  containerId           视频窗口容器ID
     */
    ReCreateWindow:function(containerId)
    {
        try
        {                
            if(!document.getElementById(containerId))
            {
                if (this.debug)
                {
                    alert("InitWindow:视频窗口容器不存在!");
                }
                return this.NrcapError.NRCAP_ERROR_INIT_WINDOW_FAILED;
            }
		    var t_wndname = containerId+"_wnd";
		    
		    var t_wndwidth = document.getElementById(containerId).offsetWidth-2;
		    var t_wndheight = document.getElementById(containerId).offsetHeight-2;		    
            
            document.getElementById(containerId).innerHTML = "<OBJECT classid=\"CLSID:C1A33A67-A0F2-42E0-80B6-38EFBDD8AD18\" id=\""+t_wndname+"\" name=\""+t_wndname+"\" width=\""+t_wndwidth+"\" height=\""+t_wndheight+"\" codebase=\"WebPlugs.cab#version=1,2008,12,24\" style=\"border:1px solid #FFFFFF;\" ><param name=\"_Version\" value=\"65536\"><param name=\"_ExtentX\" value=\"9313\"><param name=\"_ExtentY\" value=\"7620\"><param name=\"_StockProps\" value=\"0\"></OBJECT>";
                        
            if(!document.getElementById(t_wndname))
            {
                return this.NrcapError.NRCAP_ERROR_INIT_WINDOW_FAILED;
            }
            
            // 设置窗口样式
            document.getElementById(t_wndname).enableFullScreen(false);
            return document.getElementById(t_wndname);
        }
        catch(e)
        {
            if (this.debug)
            {
                alert("ReCreateWindow:"+e.message+e.name);
            }
            throw e;
            return this.NrcapError.NRCAP_ERROR_INIT_WINDOW_FAILED;
        }
    },
    
    /*
     *	函数名		：DiscardWindow
     *	函数功能	：按windowKey删除所视频窗口
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回NRCAP_SUCCESS
     *	参数说明	：1个参数
     *	        string  windowKey           视频窗口ID
     */
    DiscardWindow:function(windowKey)
    {
        if(this.Windows && this.Windows.get(windowKey))
        {
            if(this.Windows.get(windowKey).window.status.playvideoing)
            {
                this.StopVideo(this.Windows.get(windowKey).window);
            }
            if($(windowKey.replace("windowbox","window")))
            {
                $(windowKey.replace("windowbox","window")).innerHTML = "";
             
            }
            
            this.Windows.unset(windowKey);
        }
    },
    
    /*
     *	函数名		：DiscardWindowsByConnectID
     *	函数功能	：按connectId删除所有相关的视频窗口
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回NRCAP_SUCCESS
     *	参数说明	：1个参数
     *	        string          connectId               连接ID
     */
    DiscardWindowsByConnectID:function(connectId)
    {
        var keys = this.Windows.keys();
        
        for(var i = 0;i < keys.length;i++)
        {//alert(this.Windows.get(keys[i]).window.connectId)
            if(this.Windows && this.Windows.get(keys[i]) && this.Windows.get(keys[i]).window && this.Windows.get(keys[i]).window.connectId == connectId)
            {
                this.DiscardWindow(keys[i]);            
            }
        }
        this.Windows = new Hash();
        return this.NrcapError.NRCAP_SUCCESS;
    },
    
    /*
     *	函数名		：WindowAttachEvent
     *	函数功能	：绑定视频窗口事件
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：成功返回NRCAP_SUCCESS
     *	参数说明	：2个参数
     *	        WindowEvent     windowEvent          视频窗口需要绑定的事件
     *	        Window          objWnd               视频窗口
     */
    WindowAttachEvent:function(windowEvent,objWnd)
    {
        if(!objWnd || typeof objWnd != "object")
        {
            if(this.debug)
            {
                alert("窗口不存在,无法绑定窗口事件!");
            }
            return false;
        }
        
        if(windowEvent.onStop.status)
        {
            var stopCallBack = windowEvent.onStop.callback;
            //alert("attacheventstop"+callback)
			objWnd.wnd.attachEvent("onStop",function(){NrcapPlugs.FireStop(objWnd,stopCallBack);},false);	// 绑定窗口停止播放事件		
        }
        
        if(windowEvent.onClick.status)
        {
            var clickCallBack = windowEvent.onClick.callback;            
			objWnd.wnd.attachEvent("onClick",function(){NrcapPlugs.FireClick(objWnd,clickCallBack);},false);	// 绑定窗口单击事件		
        }
        //alert(windowEvent.onFullScreen.status);
        if(windowEvent.onFullScreen.status)
        {
			objWnd.wnd.attachEvent("onFullScreen",function(){NrcapPlugs.FireFullScreen(objWnd);},false);	// 绑定全屏事件		
        }
        
        if(windowEvent.onRestore.status)
        {
			objWnd.wnd.attachEvent("onRestore",function(){NrcapPlugs.FireRestore(objWnd);},false);	// 绑定恢复全屏事件
        }
        
        if (windowEvent.onPop.status)
        {
            objWnd.wnd.attachEvent("onPop",function(){NrcapPlugs.FirePop(objWnd);},false);
        }
        
        if (windowEvent.onPTZControl.status)
        {
            objWnd.wnd.attachEvent("onPTZControl",function(){NrcapPlugs.FirePTZControl(objWnd,arguments);},false);
        }
        
        if (windowEvent.onSnapshot.status)
        {
            objWnd.wnd.attachEvent("onSnapshot",function(){NrcapPlugs.FireSnapshot(objWnd);},false);	// 绑定抓拍事件
        }
        
        if (windowEvent.onStartRecord.status)
        {
            var startRecordCallBack = windowEvent.onStartRecord.callback;     
            objWnd.wnd.attachEvent("onStartRecord",function(){NrcapPlugs.FireStartRecord(objWnd,startRecordCallBack);},false);	// 绑定本地录像开始事件
        }   
        
        if (windowEvent.onStopRecord.status)
        {
            var stopRecordCallBack = windowEvent.onStopRecord.callback;     
            objWnd.wnd.attachEvent("onStopRecord",function(){NrcapPlugs.FireStopRecord(objWnd,stopRecordCallBack);},false);	// 绑定窗口本地录像停止事件
        }
        
        objWnd.wnd.attachEvent("onRefresh",function(){objWnd.nm.refresh();},false);	// 绑定窗口刷新事件
        if(windowEvent.onCustomMenuCommand.status)
        {
            for(var i = 0;i < windowEvent.onCustomMenuCommand.menu.length;i++)
            {
                objWnd.wnd.appendMainMenu(windowEvent.onCustomMenuCommand.menu[i].key,windowEvent.onCustomMenuCommand.menu[i].text);                
            }
            var customMenuCommandCallBack = windowEvent.onCustomMenuCommand.callback;     
            objWnd.wnd.attachEvent("onCustomMenuCommand",function(){NrcapPlugs.FireCustomMenuCommand(objWnd,customMenuCommandCallBack,arguments);},false);	// 绑定窗口刷新事件
        }          
        return true;
    },
    
    // 停止视频事件
    FireStop:function(objWnd,stopCallBack)
    {
        if(typeof objWnd == "object" )
        {
            if(typeof stopCallBack == "function"){stopCallBack();};            
		}
    },
    
    // 单击视频窗口事件
    FireClick:function(objWnd,clickCallBack)
    {
        if(typeof objWnd == "object" )
        {
            if(typeof clickCallBack == "function"){clickCallBack();};
		}
    },
    
    // 全屏视频事件
    FireFullScreen:function(objWnd)
    {
        if(typeof objWnd == "object" )
        {
		    objWnd.nm.attachDisplayWindow(objWnd.wnd.getWindowHandle());
		    objWnd.wnd.refresh();		   
		    objWnd.nm.setDDraw(1);
		}
    },
    
    // 恢复视频事件
    FireRestore:function(objWnd)
    {
		if(typeof objWnd == "object" )
		{			
			objWnd.nm.setDDraw(0);
			objWnd.nm.attachDisplayWindow(objWnd.wnd.getWindowHandle());
			//selfplugobj.popwindowflag = false;
		}
    },
    
    // 浮动小窗口事件
    FirePop:function(objWnd)
    {
		if(typeof objWnd == "object" )
		{	
			objWnd.nm.attachDisplayWindow(objWnd.wnd.getWindowHandle());
			objWnd.wnd.refresh();
			objWnd.nm.setDDraw(0);
		}
    },
    
    // 云台控制事件
    FirePTZControl:function(objWnd,t_arguments)
    {
		if(typeof objWnd == "object" )
		{
			if(t_arguments[0])
			{
			    this.PTZControl(objWnd,(t_arguments[0].toLowerCase().search("stop") != -1 ? "stop": "start"),t_arguments[0]);
			}
			
		}
    },
    
    // 抓拍事件
    FireSnapshot:function(objWnd)
    {
		if(typeof objWnd == "object" )
		{
			objWnd.nm.snapshot();
		}
    },
    
    // 开始录像事件
    FireStartRecord:function(objWnd,startRecordCallBack)
    {
		if(typeof objWnd == "object" )
		{	
			//objWnd.record(t_wndid);
			if(typeof startRecordCallBack == "function"){startRecordCallBack();};
		}
    },
    
    // 停止录像事件
    FireStopRecord:function(objWnd,stopRecordCallBack)
    {
		if(typeof objWnd == "object" )
		{	
			//objWnd.nm.stoprecord();
			if(typeof stopRecordCallBack == "function"){stopRecordCallBack();};
		}
    },
    
    // 云台控制事件
    FireCustomMenuCommand:function(objWnd,customMenuCommandCallBack,t_arguments)
    {
		if(typeof objWnd == "object" )
		{
			if(typeof customMenuCommandCallBack == "function"){customMenuCommandCallBack(t_arguments[0]);};
		}
    },
    
    // 重新新绑定视频窗口
    ReAttachDisplayWindow:function(ivguid,connectId,objWnd)
    {
		objWnd.nm.attachDisplayWindow(objWnd.wnd.getWindowHandle());
		objWnd.wnd.enableFullScreen(objWnd.style.enableFullScreen);
    },
    
    /*
     *	函数名		：PlayVideo
     *	函数功能	：播放视频
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：3个参数
     *	        string  ivguid           要播放视频GUID
     *	        string  connectId        视频所属连接ID
     *	        string  objWnd           视频窗口对象
     */
    PlayVideo:function(ivguid,connectId,objWnd)
    {
		try
		{
			if(objWnd.wnd)
			{
				objWnd.nm.attachDisplayWindow(objWnd.wnd.getWindowHandle());
				objWnd.wnd.enableFullScreen(objWnd.style.enableFullScreen);
				objWnd.nm.enableMask(objWnd.style.enableMask);
				objWnd.nm.setDDraw(0);
				rv = objWnd.nm.attachSessionHandle(this.Connections.get(connectId).session);
				rv = objWnd.nm.attachVideoByGuid(ivguid);
				rv = objWnd.nm.play();
				if(rv.split("#")[0] != 0x0000)
				{
					if(this.debug)
					{
					    alert("PlayVideo:"+this.ShowErrorMessage(rv.split("#")[0]));
					}
					objWnd.nm.detachVideo();
					objWnd.nm.detachSession();
					return this.NrcapError.NRCAP_ERROR_PLAYVIDEO_FAILED;
				}
				objWnd.ivguid = ivguid;
				
				// 获取云台GUID
				var ptzguid = this.GetBindedPTZGuid(connectId,ivguid);
				objWnd.ptzguid = (ptzguid != this.NrcapError.NRCAP_ERROR_GET_BINDEDPTZ_FAILED ? ptzguid :null);
				
				objWnd.connectId = connectId;
				objWnd.status.playvideoing = true;
			}
			else
			{
				if (this.debug)
				{
				    alert("PlayVideo:窗口不存在!");
				}
				return this.NrcapError.NRCAP_ERROR_WINDOW_NOEXIST;
			}
			return true;
		}
		catch(e)
		{
			if(this.debug)
			{
				alert("PlayVideo:"+e.message+","+e.name);
			}
			else
			{
				
			}
			return this.NrcapError.NRCAP_ERROR_PLAYVIDEO_FAILED;
		}
    },
    
    /*
     *	函数名		：StopVideo
     *	函数功能	：停止播放视频
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：1个参数
     *	        string  objWnd           视频窗口对象
     */
    StopVideo:function(objWnd)
    {  
		try
		{
			if(objWnd && objWnd.wnd)
			{
			    if(objWnd.status.recording)
			    {
			        this.RecordVideo(objWnd);
			    }
			    
			    if(objWnd.status.playaudioing)
			    {
			        this.PlayAudio(objWnd);
			    }
			    
			    if(objWnd.status.playupaudioing)
			    {
			        this.PlayUpAudio(objWnd);
			    }
			    
				objWnd.nm.stop();
				objWnd.wnd.enableFullScreen(0);
				objWnd.wnd.restore();
				objWnd.wnd.refresh();
				objWnd.nm.detachVideo();
				objWnd.nm.detachSession();
				objWnd.nm.refresh();
				objWnd.ivguid = null;
				objWnd.ptzguid = null;
				objWnd.connectId = null;
				objWnd.status.playvideoing = false;
			}
			else
			{
				if (this.debug)
				{
				    alert("StopVideo:窗口不存在!");
				}
				return this.NrcapError.NRCAP_ERROR_WINDOW_NOEXIST;
			}
			return true;
		}
		catch(e)
		{
			if(this.debug)
			{
				alert("StopVideo:"+e.message+","+e.name);
			}
			else
			{
				
			}
			return this.NrcapError.NRCAP_ERROR_STOPVIDEO_FAILED;
		}
    },
    
    /*
     *	函数名		：GetVideoStatus
     *	函数功能	：查询播放视频状态
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年12月25日
     *	返回值		：状态字符串
     *	参数说明	：1个参数
     *	        string  objWnd           视频窗口对象
     */
    GetVideoStatus:function(objWnd)
    {  
		try
		{
			if(objWnd && objWnd.wnd)
			{
				return objWnd.nm.getVideoStatus();
			}
			else
			{
				if (this.debug)
				{
				    alert("StopVideo:窗口不存在!");
				}
			}
		}
		catch(e)
		{
			if(this.debug)
			{
				alert("StopVideo:"+e.message+","+e.name);
			}
			return "";
		}
    },
    
    /*
     *	函数名		：RecordVideo
     *	函数功能	：本地录像视频
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：1个参数
     *	        string  objWnd           视频窗口对象
     */
    RecordVideo:function(objWnd)
    {
        try
        {
            if(objWnd && objWnd.wnd)
            {
                if(objWnd.status.playvideoing && !objWnd.status.recording)
                {
					var rv = objWnd.nm.startRecord();
					if(rv.split("#")[0] != 0x0000)
					{
						if (this.debug)
						{
						   alert("RecordVideo:录像失败"+this.ShowErrorMessage(rv.split("#")[0]));
						}
						return this.NrcapError.NRCAP_ERROR_RECORD_FAILED;
					}
					objWnd.status.recording = true;
					objWnd.wnd.setRecording(true);
					return this.NrcapError.NRCAP_SUCCESS;
                }
                else if (objWnd.status.playvideoing && objWnd.status.recording)
                {
					objWnd.nm.stopRecord();
					objWnd.status.recording = false;
					objWnd.wnd.setRecording(false);
                    return this.NrcapError.NRCAP_SUCCESS;
                }
                else
                {
                    // 窗口没有播放视频或者正在录像
                    return this.NrcapError.NRCAP_ERROR_VIDEOTOPPED;
                }
            }
            else
            {// 窗口不存在
                return this.NrcapError.NRCAP_ERROR_WINDOW_FAILED;
            }
        }
        catch(e)
        {
            if(this.debug)
            {
                alert(""+e.message+","+e.name);
            }
            
            return this.NrcapError.NRCAP_ERROR_RECORD_FAILED;
        }
    },
    
    /*
     *	函数名		：PlayAudio
     *	函数功能	：播放音频
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：1个参数
     *	        string  objWnd           视频窗口对象
     */
    PlayAudio:function(objWnd)
    {		
		try
		{
			if(objWnd && objWnd.wnd)
			{
				if(objWnd.status.playvideoing && !objWnd.status.playaudioing)
				{
					rv = objWnd.nm.playAudio();
					if(rv.split("#")[0] != 0x0000)
					{
						alert("播放声音失败:"+this.ShowErrorMessage(rv.split("#")[0]));
						return this.NrcapError.NRCAP_ERROR_PLAYAUDIO_FAILED;
					}
					
					objWnd.status.playaudioing = true;
                    return this.NrcapError.NRCAP_SUCCESS;
				}
			    else if(objWnd.status.playvideoing && objWnd.status.playaudioing)
			    {
    			    // 关闭声音
					objWnd.nm.stopAudio();
					objWnd.status.playaudioing = false;
			    }
			    else
			    {
                    // 窗口没有播放视频
                    return this.NrcapError.NRCAP_ERROR_VIDEOTOPPED;
			    }
			}
			else
			{
				if (this.debug) alert("窗口不存在");
			}
			return false;			
		}
		catch(e)
		{
            if(this.debug)
            {
                alert(""+e.message+","+e.name);
            }
            
            return this.NrcapError.NRCAP_ERROR_RECORD_FAILED;
		}
    },
    
    /*
     *	函数名		：PlayUpAudio
     *	函数功能	：播放音频
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：1个参数
     *	        string  objWnd           视频窗口对象
     */
    PlayUpAudio:function(objWnd)
    {		
		try
		{
			if(objWnd && objWnd.wnd)
			{
				if(objWnd.status.playvideoing && !objWnd.status.playupaudioing)
				{
					rv = objWnd.nm.startUpAudio();
					if(rv.split("#")[0] != 0x0000)
					{
						alert("开始输出音频失败:"+this.ShowErrorMessage(rv.split("#")[0]));
						return this.NrcapError.NRCAP_ERROR_PLAYAUDIO_FAILED;
					}
					
					objWnd.status.playupaudioing = true;
                    return this.NrcapError.NRCAP_SUCCESS;
				}
			    else if(objWnd.status.playvideoing && objWnd.status.playupaudioing)
			    {
    			    // 关闭声音
					objWnd.nm.stopUpAudio();
					objWnd.status.playupaudioing = false;
					return this.NrcapError.NRCAP_SUCCESS;
			    }
			    else
			    {
                    // 窗口没有播放视频
                    return this.NrcapError.NRCAP_ERROR_VIDEOTOPPED;
			    }
			}
			else
			{
				if (this.debug) alert("窗口不存在");
			}
			return false;			
		}
		catch(e)
		{
            if(this.debug)
            {
                alert(""+e.message+","+e.name);
            }
            
            return this.NrcapError.NRCAP_ERROR_RECORD_FAILED;
		}
    },
    
    /*
     *	函数名		：SnapShot
     *	函数功能	：抓拍视频
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：1个参数
     *	        string  objWnd           视频窗口对象
     */
    SnapShot:function(objWnd)
    {
        try
        {
            if(objWnd && objWnd.wnd)
            {
                if(objWnd.status.playvideoing)
                {
					objWnd.nm.snapshot();
					return this.NrcapError.NRCAP_SUCCESS;
                }
                else
                {
                    // 窗口没有播放视频
                    return this.NrcapError.NRCAP_ERROR_VIDEOTOPPED;
                }
            }
            else
            {// 窗口不存在
                return this.NrcapError.NRCAP_ERROR_WINDOW_FAILED;
            }
        }
        catch(e)
        {
            if(this.debug)
            {
                alert(""+e.message+","+e.name);
            }
            
            return this.NrcapError.NRCAP_ERROR_SNAPSHOT_FAILED;
        }
    },
    
    /*
     *	函数名		：SwapWindow
     *	函数功能	：置换播放窗口
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年12月11日
     *	返回值		：true,成功,false失败
     *	参数说明	：3个参数
     *	        object  destinationWindow           目的窗口
     *	        object  sourceWindow                源窗口
     */
    SwapWindow:function(destinationWindow,sourceWindow)
    {
        try
        {
            var ivguid = destinationWindow.ivguid;
            var ptzguid = destinationWindow.ptzguid;
            var connectId = destinationWindow.connectId;
            var nm = destinationWindow.nm;
            var nmname = destinationWindow.nmname;
            var status = destinationWindow.status;
            var style = destinationWindow.style;
            
            destinationWindow.nm = sourceWindow.nm;
            destinationWindow.nmname = sourceWindow.nmname;
            destinationWindow.status = sourceWindow.status;
            destinationWindow.ivguid = sourceWindow.ivguid;
            destinationWindow.ptzguid = sourceWindow.ptzguid;
            destinationWindow.style = sourceWindow.style;
            
            this.ReAttachDisplayWindow(sourceWindow.ivguid,sourceWindow.connectId,destinationWindow);
            
            sourceWindow.nm = nm;
            sourceWindow.nmname = nmname;
            sourceWindow.status = status;
            sourceWindow.ivguid = ivguid;
            sourceWindow.ptzguid = ptzguid;
            sourceWindow.style = style;
            
            this.ReAttachDisplayWindow(ivguid,connectId,sourceWindow);
        }
        catch(e)
        {
            if (this.debug)
            {
                alert(e.message+","+e.name);
                throw e;
            }
            return false;
        }
        return true;
    },
    
    /*
     *	函数名		：PTZControl
     *	函数功能	：云台控制
     *	备注		：
     *	作者		：Lingsen
     *	时间		：2008年11月21日
     *	返回值		：对应NrcapError
     *	参数说明	：3个参数
     *	        string  objWnd                 视频窗口对象
     *	        string  control                云台控制命令[启动,关闭]
     *	        string  direction              云台控制方向[放大,缩小,上,下,左,右等]
     */
    PTZControl:function(objWnd,control,direction)
    {
        try
        {
            if(objWnd && objWnd.wnd)
            {
                if(objWnd.status.playvideoing && objWnd.ptzguid != null)
                {
			        var ptzcontrolrv = 0x0000;	
				    if(control == "start")
				    {	        
			            switch(direction.toLowerCase())
			            {
				            case "turnup":
					            this.Plug.bsc.clear();
					            this.Plug.bsc.addUshort(0);
					            ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x00090103, this.Plug.bsc.getBuffer(), this.Plug.bsc.getLength(), 0);
					            break;
				            case "turndown":
					            this.Plug.bsc.clear();
					            this.Plug.bsc.addUshort(0);
					            ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x00090104, this.Plug.bsc.getBuffer(), this.Plug.bsc.getLength(), 0);
					            break;
				            case "turnleft":
					            this.Plug.bsc.clear();
					            this.Plug.bsc.addUshort(0);
					            ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x00090101, this.Plug.bsc.getBuffer(), this.Plug.bsc.getLength(), 0);
					            break;
				            case "turnright":
					            this.Plug.bsc.clear();
					            this.Plug.bsc.addUshort(0);
					            ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x00090102, this.Plug.bsc.getBuffer(), this.Plug.bsc.getLength(), 0);
					            break;
				            case "zoomout":
					            ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x0009010C, 0, 0, 0);
					            break;
				            case "zoomin":
					            ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x0009010D, 0, 0, 0);
					            break;
				            case "aperturea":
					            ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x00090106, 0, 0, 0);
					            break;
				            case "aperturem":
					            ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x00090107, 0, 0, 0);
					            break;
				            case "focusfar":
					            ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x00090109, 0, 0, 0);
					            break;
				            case "focusnear":
					            ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x0009010A, 0, 0, 0);
					            break;
				            default:
					            return false;
					            break;
			            }				
				    }
				    else
				    {        
			            switch(direction.toLowerCase())
			            {
				            case "turnup":
				            case "turndown":
				            case "turnleft":
				            case "turnright":
				            case "stopturn":
				                ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x00090105, 0, 0, 0);
					            break;
				            case "aperturea":
				            case "aperturem":
				            case "stopaperture":
				                ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x00090108, 0, 0, 0);
					            break;
				            case "focusfar":
				            case "focusnear":
				            case "stopfocus":
				                ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x0009010B, 0, 0, 0);
					            break;
				            case "zoomin":
				            case "zoomout":
				            case "stopzoom":
				                ptzcontrolrv = this.Plug.nc.control(this.Connections.get(objWnd.connectId).session, objWnd.ptzguid, 0x0009010E, 0, 0, 0);
					            break;
				            default:
					            return false;
					            break;
			            }			
				    }
				    
			        if (ptzcontrolrv.split("#")[0] != 0x0000)
			        {
				        if(this.debug)alert("PTZControl:发云台控制命令失败("+this.ShowErrorMessage(ptzcontrolrv.split("#")[0])+")");
				        this.Plug.nc.dealloc(parseInt(ptzcontrolrv.split("#")[1]));
				        return this.NrcapError.NRCAP_ERROR_PTZCONTROL_FAILED;
			        }
				    this.Plug.nc.dealloc(parseInt(ptzcontrolrv.split("#")[1]));
					return this.NrcapError.NRCAP_SUCCESS;
                }
                else
                {
                    // 窗口没有播放视频
                    return this.NrcapError.NRCAP_ERROR_VIDEOTOPPED;
                }
            }
            else
            {// 窗口不存在
                return this.NrcapError.NRCAP_ERROR_WINDOW_FAILED;
            }
        }
        catch(e)
        {
            if(this.debug)
            {
                alert("PTZControl:"+e.message+","+e.name);
            }
            
            return this.NrcapError.NRCAP_ERROR_SNAPSHOT_FAILED;
        }
    },
    
    Event:
    {
        status:false,
        interval:1000,
        eventInfoList:new Array(),
        timer:null,
        callback:null,
        Stop:function()
        {
            NrcapPlugs.Event.status = false;
            clearInterval(NrcapPlugs.Event.timer);
        },
        Start:function(callback)
        {
            NrcapPlugs.Event.callback = callback;
            NrcapPlugs.Event.timer = setInterval(NrcapPlugs.Event.WaitEvent,NrcapPlugs.Event.interval);
        },
        
        WaitEvent:function()
        {
            NrcapPlugs.Event.status = true;
            NrcapPlugs.Connections.each(
                function(item)
                {
                    if(item.value.session)
                    {
                        var rv = NrcapPlugs.Plug.nc.waitEvent(item.value.session);
                        
                        if(rv.split("#")[0] != 0x201A)
                        {
                            // GUID,MsgType,MsgID,时间,描述,特色描述
                            var eventInfo ={guid:null,msgType:null,msgId:null,msgTypeDescription:null,time:null,description:null,featureDesc:null,from:null};
                            if (rv.split("#")[0] == 0x2018)
                            {
                                if(typeof NrcapPlugs.Event.callback == "function")
                                {
                                    eventInfo.msgId = 0x2018;
                                    NrcapPlugs.Event.callback(eventInfo);
                                }
                                return false;
                            }
                            eventInfo.guid = rv.split("#")[1];
                            eventInfo.msgType = rv.split("#")[2];
                            eventInfo.msgId = rv.split("#")[3];
                            eventInfo.time = rv.split("#")[4];
                            eventInfo.description = rv.split("#")[5];
                            eventInfo.featureDesc = rv.split("#")[6];
                            
                            // 把平台管理者的GUID转换成平台本身的GUID
                            var guid = (eventInfo.guid.substr(5,1) == "C" ? eventInfo.guid.substr(0,5)+"0"+eventInfo.guid.substr(6): eventInfo.guid);
                            // 应该去找一下是在资源列表里
                            //var li = NrcapPlugs.Connections.get(ResourceUser.connectId).resource;
                            
                            if(!NrcapPlugs.ResourceIndexOf(guid))
                            {
                                return false;
                            }
                            var rev = NrcapPlugs.Plug.nc.control(item.value.session,guid,NrcapPlugs.NrcapControlID.Nrcap_GetGUIDDescription,0,0,0);
                            if (rev.split("#")[0] != 0x0000)
                            {
                                eventInfo.from = eventInfo.guid.substr(22,12);
                            }
                            else
                            {
                                NrcapPlugs.Plug.bsp.attachBuffer(parseInt(rev.split("#")[1]), parseInt(rev.split("#")[2]));
	                            NrcapPlugs.Plug.bsp.parseGuid();
	                            NrcapPlugs.Plug.bsp.parseString();
	                            var name = NrcapPlugs.Plug.bsp.parseString();		                        
                                NrcapPlugs.Plug.nc.dealloc(parseInt(rev.split("#")[1]));
                                eventInfo.from = name;
                            }
                           
                            //alert($H($H(NrcapPlugs.NrcapEvent).get(eventInfo.msgType.toString())).get(eventInfo.msgId.toString()).description);
                            if($H(NrcapPlugs.NrcapEvent).get(eventInfo.msgType.toString()) && $H($H(NrcapPlugs.NrcapEvent).get(eventInfo.msgType.toString())).get(eventInfo.msgId.toString()) )
                            {
                                eventInfo.msgTypeDescription = $H($H(NrcapPlugs.NrcapEvent).get(eventInfo.msgType.toString())).get(eventInfo.msgId.toString()).description;
                            }
                            else
                            {
                                eventInfo.msgTypeDescription = eventInfo.msgType;
                            }
                            
                            // 用户事件 
                            if ($H(NrcapPlugs.NrcapEvent).get(eventInfo.msgType))
                            {
                            
                                switch(eventInfo.msgType.toString())
                                {
                                    case "0x0001":      // 用户事件
                                        eventInfo.description = "用户:"+eventInfo.featureDesc.split(";")[0]+":"+eventInfo.featureDesc.split(";")[1];
                                        //eventInfo.featureDesc = "路径:"+eventInfo.featureDesc.split(";")[2]+":"+eventInfo.featureDesc.split(";")[3];
                                        eventInfo.featureDesc = "路径:"+eventInfo.featureDesc.split(";")[2]+":"+parseInt(eventInfo.featureDesc.split(";")[3]);
                                        break; 
                                    case "0x0002":      // 平台事件
                                        eventInfo.description = "描述:"+eventInfo.description;
                                        eventInfo.featureDesc = "备注:"+item.value.resource.get("root").name;
                                        break; 
                                    case "0x0003":      // 输入视频事件
                                        eventInfo.description = "描述:"+eventInfo.description;
                                        if(eventInfo.guid.substr(5,1) != 0)
                                        {
                                            var rev = NrcapPlugs.Plug.nc.control(item.value.session,eventInfo.guid.substr(0,5)+"0"+eventInfo.guid.substr(6),NrcapPlugs.NrcapControlID.Nrcap_GetGUIDDescription,0,0,0);
                                            if (rev.split("#")[0] != 0x0000)
                                            {
                                                eventInfo.featureDesc = "备注:"+eventInfo.name;
                                            }
                                            else
                                            {
                                                NrcapPlugs.Plug.bsp.attachBuffer(parseInt(rev.split("#")[1]), parseInt(rev.split("#")[2]));
	                                            NrcapPlugs.Plug.bsp.parseGuid();
	                                            NrcapPlugs.Plug.bsp.parseString();
	                                            var name = NrcapPlugs.Plug.bsp.parseString();		                        
                                                NrcapPlugs.Plug.nc.dealloc(parseInt(rev.split("#")[1]));
                                                eventInfo.featureDesc = "备注:"+name;
                                            }                                                                                
                                        }
                                        else
                                        {
                                            eventInfo.featureDesc = "备注:"+eventInfo.featureDesc;
                                        }                            
                                        
                                        break;
                                    case "0x0006":      // 存储者事件
                                        eventInfo.description = "描述:"+eventInfo.description;
                                        eventInfo.featureDesc = "备注:"+(eventInfo.featureDesc.toString().length <= 0 ? item.value.resource.get("root").name : eventInfo.featureDesc);      
                                        break;
                                    case "0x0008":      // 平台事件
                                        eventInfo.description = "描述:"+eventInfo.description;
                                        eventInfo.featureDesc = "备注:"+eventInfo.featureDesc.split(";")[0]+"&nbsp;:&nbsp;"+eventInfo.featureDesc.split(";")[1]+"&nbsp;:&nbsp;"+eventInfo.featureDesc.split(";")[2];
                                        break; 
                                    default:
                                        eventInfo.description = "描述:"+eventInfo.description;                                
                                        eventInfo.featureDesc = "备注:"+(eventInfo.featureDesc.toString().length <= 0 ? eventInfo.featureDesc : eventInfo.guid.substr(22,12)) ;
                                        break;
                                }                            
                                NrcapPlugs.Event.eventInfoList.push({guid:eventInfo.guid,msgType:eventInfo.msgType,msgId:eventInfo.msgId,msgTypeDescription:eventInfo.msgTypeDescription,time:eventInfo.time,description:eventInfo.description,featureDesc:eventInfo.featureDesc,from:eventInfo.from});
                                NrcapPlugs.Event.callback(eventInfo);
                                
                            }
                        }
                    }
                }
                
            )        
        }
    }
}