function CalcPosition(A,B){this.X=A;this.Y=B;this.Add=function(D){var C=new CalcPosition(this.X,this.Y);if(D!=null){if(!isNaN(D.X)){C.X+=D.X}if(!isNaN(D.Y)){C.Y+=D.Y}}return C};this.Subtract=function(D){var C=new CalcPosition(this.X,this.Y);if(D!=null){if(!isNaN(D.X)){C.X-=D.X}if(!isNaN(D.Y)){C.Y-=D.Y}}return C};this.Min=function(D){var C=new CalcPosition(this.X,this.Y);if(D==null){return C}if(!isNaN(D.X)&&this.X>D.X){C.X=D.X}if(!isNaN(D.Y)&&this.Y>D.Y){C.Y=D.Y}return C};this.Max=function(D){var C=new CalcPosition(this.X,this.Y);if(D==null){return C}if(!isNaN(D.X)&&this.X<D.X){C.X=D.X}if(!isNaN(D.Y)&&this.Y<D.Y){C.Y=D.Y}return C};this.Bound=function(C,E){var D=this.Max(C);return D.Min(E)};this.Check=function(){var C=new CalcPosition(this.X,this.Y);if(isNaN(C.X)){C.X=0}if(isNaN(C.Y)){C.Y=0}return C};this.Apply=function(C){if(typeof (C)=="string"){C=document.getElementById(C)}if(C==null){return }if(!isNaN(this.X)){C.style.left=this.X+"px"}if(!isNaN(this.Y)){C.style.top=this.Y+"px"}}}function hookEvent(B,A,C){if(typeof (B)=="string"){B=document.getElementById(B)}if(B==null){return }if(B.addEventListener){B.addEventListener(A,C,false)}else{if(B.attachEvent){B.attachEvent("on"+A,C)}}}function unhookEvent(B,A,C){if(typeof (B)=="string"){B=document.getElementById(B)}if(B==null){return }if(B.removeEventListener){B.removeEventListener(A,C,false)}else{if(B.detachEvent){B.detachEvent("on"+A,C)}}}function cancelEvent(A){A=A?A:window.event;if(A.stopPropagation){A.stopPropagation()}if(A.preventDefault){A.preventDefault()}A.cancelBubble=true;A.cancel=true;A.returnValue=false;return false}function getMousePos(A){A=A?A:window.event;var B;if(isNaN(A.layerX)){B=new CalcPosition(A.offsetX,A.offsetY)}else{B=new CalcPosition(A.layerX,A.layerY)}return correctOffset(B,pointerOffset,true)}function getEventTarget(A){A=A?A:window.event;return A.target?A.target:A.srcElement}function absoluteCursorPosition(A){A=A?A:window.event;if(isNaN(window.scrollX)){return new CalcPosition(A.clientX+document.documentElement.scrollLeft+document.body.scrollLeft,A.clientY+document.documentElement.scrollTop+document.body.scrollTop)}else{return new CalcPosition(A.clientX+window.scrollX,A.clientY+window.scrollY)}}function dragObject(A,D,E,H,L,J,G,C){if(typeof (A)=="string"){A=document.getElementById(A)}if(A==null){return }if(E!=null&&H!=null){var P=E.Min(H);H=E.Max(H);E=P}var O=null;var I=null;var K=false;var M=false;var F=false;function Q(S){if(K||!M||F){return }K=true;if(L!=null){L(S,A)}O=absoluteCursorPosition(S);if(A.style.left!=undefined&&A.style.left>0){I=new CalcPosition(parseInt(A.style.left),parseInt(A.style.top))}else{var U=curtop=0;var T=A;if(T.offsetParent){do{U+=T.offsetLeft;curtop+=T.offsetTop}while(T=T.offsetParent)}I=new CalcPosition(U-8,curtop-8)}I=I.Check();hookEvent(document,"mousemove",N);hookEvent(document,"mouseup",B);return cancelEvent(S)}function N(T){if(!K||F){return }var S=absoluteCursorPosition(T);S=S.Add(I).Subtract(O);S=S.Bound(E,H);S.Apply(A);if(J!=null){J(S,A)}return cancelEvent(T)}function B(S){R();return cancelEvent(S)}function R(){if(!K||F){return }unhookEvent(document,"mousemove",N);unhookEvent(document,"mouseup",B);O=null;I=null;if(G!=null){G(A)}K=false}this.Dispose=function(){if(F){return }this.StopListening(true);A=null;D=null;E=null;H=null;L=null;J=null;G=null;F=true};this.StartListening=function(){if(M||F){return }M=true;hookEvent(D,"mousedown",Q)};this.StopListening=function(S){if(!M||F){return }unhookEvent(D,"mousedown",Q);M=false;if(S&&K){R()}};this.IsDragging=function(){return K};this.IsListening=function(){return M};this.IsDisposed=function(){return F};if(typeof (D)=="string"){D=document.getElementById(D)}if(D==null){D=A}if(!C){this.StartListening()}};
