var CreateAgentRemoteDesktop=function(e,t){var g={};"string"==typeof(g.CanvasId=e)&&(g.CanvasId=Q(e)),g.Canvas=g.CanvasId.getContext("2d"),g.scrolldiv=t,g.State=0,g.PendingOperations=[],g.tilesReceived=0,g.TilesDrawn=0,g.KillDraw=0,g.ipad=!1,g.tabletKeyboardVisible=!1,g.LastX=0,g.LastY=0,g.touchenabled=0,g.submenuoffset=0,g.touchtimer=null,g.TouchArray={},g.connectmode=0,g.connectioncount=0,g.rotation=0,g.protocol=2,g.debugmode=0,g.firstUpKeys=[],g.stopInput=!1,g.localKeyMap=!0,g.pressedKeys=[],g.sessionid=0,g.username,g.oldie=!1,g.CompressionLevel=50,g.ScalingLevel=1024,g.FrameRateTimer=100,g.FirstDraw=!1,g.ScreenWidth=960,g.ScreenHeight=700,g.width=960,g.height=960,g.onScreenSizeChange=null,g.onMessage=null,g.onConnectCountChanged=null,g.onDebugMessage=null,g.onTouchEnabledChanged=null,g.onDisplayinfo=null,g.accumulator=null;var v=["default","progress","crosshair","pointer","help","text","no-drop","move","nesw-resize","ns-resize","nwse-resize","w-resize","alias","wait","none","not-allowed","col-resize","row-resize","copy","zoom-in","zoom-out"];g.Start=function(){g.State=0,g.accumulator=null},g.Stop=function(){g.setRotation(0),g.UnGrabKeyInput(),g.UnGrabMouseInput(),g.touchenabled=0,null!=g.onScreenSizeChange&&g.onScreenSizeChange(g,g.ScreenWidth,g.ScreenHeight,g.CanvasId),g.Canvas.clearRect(0,0,g.CanvasId.width,g.CanvasId.height)},g.xxStateChange=function(e){if(g.State!=e)switch(g.State=e,g.CanvasId.style.cursor="default",e){case 0:g.Stop()}},g.send=function(e){1e.length)return void(g.accumulator=e);e=e.substring(8),s=8}if(r!=e.length&&0e.length)){switch(3!=a&&4!=a&&7!=a||(n=((255&(t=e.substring(4,r)).charCodeAt(0))<<8)+(255&t.charCodeAt(1)),o=((255&t.charCodeAt(2))<<8)+(255&t.charCodeAt(3)),0>32)+g.intToStr(32&o)):(g.recordedSize+=n.length,g.shortToStr(e)+g.shortToStr(t)+g.intToStr(n.length)+g.intToStr(o>>32)+g.intToStr(32&o)+n)}return g.SendKeyMsg=function(e,t){var n;null!=e&&((t=t||window.event).code&&0==g.localKeyMap?null!=(n=function(e){return e.code.startsWith("Key")&&4==e.code.length?e.code.charCodeAt(3):e.code.startsWith("Digit")&&6==e.code.length?e.code.charCodeAt(5):e.code.startsWith("Numpad")&&7==e.code.length?e.code.charCodeAt(6)+48:o[e.code]}(t))&&g.SendKeyMsgKC(e,n):(59==(n=t.keyCode)?n=186:173==n?n=189:61==n&&(n=187),g.SendKeyMsgKC(e,n)))},g.SendMessage=function(e){3==g.State&&g.send(String.fromCharCode(0,17)+g.shortToStr(4+e.length)+e)},g.SendKeyMsgKC=function(e,t){if(3==g.State)if("object"==typeof e)for(var n in e)g.SendKeyMsgKC(e[n][0],e[n][1]);else{if(1==e)-1==g.pressedKeys.indexOf(t)&&g.pressedKeys.unshift(t);else if(2==e){-1!=(n=g.pressedKeys.indexOf(t))&&g.pressedKeys.splice(n,1)}g.send(String.fromCharCode(0,g.InputType.KEY,0,6,e-1,t))}},g.sendcad=function(){g.SendCtrlAltDelMsg()},g.SendCtrlAltDelMsg=function(){3==g.State&&g.send(String.fromCharCode(0,g.InputType.CTRLALTDEL,0,4))},g.SendEscKey=function(){3==g.State&&g.send(String.fromCharCode(0,g.InputType.KEY,0,6,0,27,0,g.InputType.KEY,0,6,1,27))},g.SendStartMsg=function(){g.SendKeyMsgKC(g.KeyAction.EXDOWN,91),g.SendKeyMsgKC(g.KeyAction.EXUP,91)},g.SendCharmsMsg=function(){g.SendKeyMsgKC(g.KeyAction.EXDOWN,91),g.SendKeyMsgKC(g.KeyAction.DOWN,67),g.SendKeyMsgKC(g.KeyAction.UP,67),g.SendKeyMsgKC(g.KeyAction.EXUP,91)},g.SendTouchMsg1=function(e,t,n,o){3==g.State&&g.send(String.fromCharCode(0,g.InputType.TOUCH)+g.shortToStr(14)+String.fromCharCode(1,e)+g.intToStr(t)+g.shortToStr(n)+g.shortToStr(o))},g.SendTouchMsg2=function(e,t){var n,o="";for(var a in g.TouchArray)a==e?n=t:1==g.TouchArray[a].f?(n=65542,g.TouchArray[a].f=3,"START"+a):2==g.TouchArray[a].f?(n=262144,"STOP"+a):n=131078,o+=String.fromCharCode(a)+g.intToStr(n)+g.shortToStr(g.TouchArray[a].x)+g.shortToStr(g.TouchArray[a].y),2==g.TouchArray[a].f&&delete g.TouchArray[a];3==g.State&&g.send(String.fromCharCode(0,g.InputType.TOUCH)+g.shortToStr(5+o.length)+String.fromCharCode(2)+o),0==Object.keys(g.TouchArray).length&&null!=g.touchtimer&&(clearInterval(g.touchtimer),g.touchtimer=null)},g.SendMouseMsg=function(e,t){if(3==g.State&&null!=e&&null!=g.Canvas){if(!t)t=window.event;var n=g.Canvas.canvas.height/g.CanvasId.clientHeight,o=g.Canvas.canvas.width/g.CanvasId.clientWidth,a=g.GetPositionOfControl(g.Canvas.canvas),r=(t.pageX-a[0])*o,s=(t.pageY-a[1])*n;if(t.addx&&(r+=t.addx),t.addy&&(s+=t.addy),0<=r&&r<=g.Canvas.canvas.width&&0<=s&&s<=g.Canvas.canvas.height){var i=0,c=0;e==g.KeyAction.UP||e==g.KeyAction.DOWN?t.which?i=1==t.which?g.MouseButton.LEFT:2==t.which?g.MouseButton.MIDDLE:g.MouseButton.RIGHT:t.button&&(i=0==t.button?g.MouseButton.LEFT:1==t.button?g.MouseButton.MIDDLE:g.MouseButton.RIGHT):e==g.KeyAction.SCROLL&&(t.detail?c=120*t.detail*-1:t.wheelDelta&&(c=3*t.wheelDelta));var u="";u=e==g.KeyAction.DBLCLICK?String.fromCharCode(0,g.InputType.MOUSE,0,10,0,136,r/256&255,255&r,s/256&255,255&s):e==g.KeyAction.SCROLL?String.fromCharCode(0,g.InputType.MOUSE,0,12,0,0,r/256&255,255&r,s/256&255,255&s,c/256&255,255&c):String.fromCharCode(0,g.InputType.MOUSE,0,10,0,e==g.KeyAction.DOWN?i:2*i&255,r/256&255,255&r,s/256&255,255&s),g.Action==g.KeyAction.NONE?0==g.Alternate||g.ipad?(g.send(u),g.Alternate=1):g.Alternate=0:g.send(u)}}},g.GetDisplayNumbers=function(){g.send(String.fromCharCode(0,11,0,4))},g.SetDisplay=function(e){g.send(String.fromCharCode(0,12,0,6,e>>8,255&e))},g.intToStr=function(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,255&e)},g.shortToStr=function(e){return String.fromCharCode(e>>8&255,255&e)},g.onResize=function(){0!=g.ScreenWidth&&0!=g.ScreenHeight&&(g.Canvas.canvas.width==g.ScreenWidth&&g.Canvas.canvas.height==g.ScreenHeight||(g.FirstDraw&&(g.Canvas.canvas.width=g.ScreenWidth,g.Canvas.canvas.height=g.ScreenHeight,g.Canvas.fillRect(0,0,g.ScreenWidth,g.ScreenHeight),null!=g.onScreenSizeChange&&g.onScreenSizeChange(g,g.ScreenWidth,g.ScreenHeight,g.CanvasId)),g.FirstDraw=!1))},g.xxMouseInputGrab=!1,g.xxKeyInputGrab=!1,g.xxMouseMove=function(e){return 3==g.State&&g.SendMouseMsg(g.KeyAction.NONE,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},g.xxMouseUp=function(e){return 3==g.State&&g.SendMouseMsg(g.KeyAction.UP,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},g.xxMouseDown=function(e){return 3==g.State&&g.SendMouseMsg(g.KeyAction.DOWN,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},g.xxMouseDblClick=function(e){return 3==g.State&&g.SendMouseMsg(g.KeyAction.DBLCLICK,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},g.xxDOMMouseScroll=function(e){return 3!=g.State||(g.SendMouseMsg(g.KeyAction.SCROLL,e),!1)},g.xxMouseWheel=function(e){return 3!=g.State||(g.SendMouseMsg(g.KeyAction.SCROLL,e),!1)},g.xxKeyUp=function(e){return 3==g.State&&g.SendKeyMsg(g.KeyAction.UP,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},g.xxKeyDown=function(e){return 3==g.State&&g.SendKeyMsg(g.KeyAction.DOWN,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},g.xxKeyPress=function(e){return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},g.handleKeys=function(e){return 1!=g.stopInput&&3==desktop.State&&g.xxKeyPress(e)},g.handleKeyUp=function(e){if(1==g.stopInput||3!=desktop.State)return!1;if(g.firstUpKeys.length<5&&(g.firstUpKeys.push(e.keyCode),5==g.firstUpKeys.length)){var t=g.firstUpKeys.join(",");"16,17,91,91,16"!=t&&"16,17,18,91,92"!=t||(g.stopInput=!0)}return g.xxKeyUp(e)},g.handleKeyDown=function(e){return 1!=g.stopInput&&3==desktop.State&&g.xxKeyDown(e)},g.handleReleaseKeys=function(){var e=JSON.parse(JSON.stringify(g.pressedKeys));for(var t in e)g.SendKeyMsgKC(g.KeyAction.UP,e[t])},g.mousedblclick=function(e){return 1!=g.stopInput&&g.xxMouseDblClick(e)},g.mousedown=function(e){return 1!=g.stopInput&&g.xxMouseDown(e)},g.mouseup=function(e){return 1!=g.stopInput&&g.xxMouseUp(e)},g.mousemove=function(e){return 1!=g.stopInput&&g.xxMouseMove(e)},g.mousewheel=function(e){return 1!=g.stopInput&&g.xxMouseWheel(e)},g.xxMsTouchEvent=function(e){if(4!=e.originalEvent.pointerType){if(e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),"MSPointerDown"==e.type||"MSPointerMove"==e.type||"MSPointerUp"==e.type){var t=0,n=e.originalEvent.pointerId%256,o=e.offsetX*(Canvas.canvas.width/g.CanvasId.clientWidth),a=e.offsetY*(Canvas.canvas.height/g.CanvasId.clientHeight);"MSPointerDown"==e.type?t=65542:"MSPointerMove"==e.type?t=131078:"MSPointerUp"==e.type&&(t=262144),g.TouchArray[n]||(g.TouchArray[n]={x:o,y:a}),g.SendTouchMsg2(n,t),"MSPointerUp"==e.type&&delete g.TouchArray[n]}else alert(e.type);return!0}},g.xxTouchStart=function(e){if(3==g.State)if(e.preventDefault&&e.preventDefault(),0==g.touchenabled||1==g.touchenabled){if(1