

var __aspxPCWIdSuffix = "_PW";

function ASPxPCResizeCursorInfo(horizontalDirection, verticalDirection, horizontalOffset, verticalOffset){
    this.horizontalDirection = horizontalDirection;
    this.verticalDirection = verticalDirection;
    this.horizontalOffset = horizontalOffset;
    this.verticalOffset = verticalOffset;
    this.course = verticalDirection + horizontalDirection;
}
ASPxClientPopupControl = _aspxCreateClass(ASPxClientControl, {
    constructor: function(name){
        this.constructor.prototype.constructor.call(this, name);

        this.leadingAfterInitCall = true; // popup container must correct size before it's content
        this.adjustInnerControlsSizeOnShow = true;

        this.animationDelay = 30;
        this.animationMaxDelay = 400;        
        this.appearAfter = 300;
        this.disappearAfter = 500;
        this.allowResize = false;
        this.enableAnimation = true;
        
        this.allowCorrectYOffsetPosition = true; // Used by ASPxDropDownEdit
        this.contentUrl = "";
        this.contentUrlArray = [];
        this.cookieName = "";
        this.closeAction = "OuterMouseClick";
        this.popupAction = "LeftMouseClick";
        this.popupElementID = "";
        this.popupElementIDArray = [];
        this.showOnPageLoad = false;
        this.showOnPageLoadArray = [];
        this.popupHorizontalAlign = __aspxNotSetAlignIndicator;
        this.popupVerticalAlign = __aspxNotSetAlignIndicator;
        this.popupHorizontalOffset = 0;
        this.popupVerticalOffset = 0;
        this.shadowHeight = 5;
        this.shadowWidth = 5;
        this.windows = []; 
        this.windowCount = 0;
        this.isDragged = false;
        this.isResized = false;
        this.zIndex = -1;
        this.left = 0;
        this.top = 0;
        this.iframeLoading = false;
        this.isDraggedArray = [];
        this.isResizedArray = [];
        this.zIndexArray = [];
        this.leftArray = [];
        this.topArray = [];
        this.height = 0;
        this.width = 0;
        this.heightArray = [];
        this.widthArray = [];
        this.iframeLoadingArray = [];
        this.isLiveResizingMode = true;
        this.isPopupPositionCorrectionOn = true;
        this.SSLSecureBlankUrl = "";
        this.windowElements = new Object();
        this.hideBodyScrollWhenModal = true;
        this.autoUpdatePosition = false;
        this.isNeedPopupedSet = false;
        this.cachedSize = null;
        this.cachedSizeArray = [];
        this.fakeDragDiv = null;
        
        this.popupElement = null;
        this.popupElements = [];
        this.headerHeight = 0;
        this.headerHeightArray = [];
        this.footerHeight = 0;
        this.footerHeightArray = [];
        this.ResizeBorderSize = 6;
        this.ResizeCornerBorderSize = 20;
        
        this.CloseButtonClick = new ASPxClientEvent();
        this.CloseUp = new ASPxClientEvent();
        this.Closing = new ASPxClientEvent();
        this.PopUp = new ASPxClientEvent();
        this.Resize = new ASPxClientEvent();
        this.Shown = new ASPxClientEvent();
        this.BeforeResizing = new ASPxClientEvent();
        this.AfterResizing = new ASPxClientEvent();
        
        aspxGetPopupControlCollection().Add(this);
    },
    Initialize: function(){
        this.InitializeArrays();
        if (this.HasDefaultWindow())
            this.InitializeWindow(-1);
        for(var i = 0; i < this.popupElementIDArray.length; i ++) 
            this.InitializeWindow(i);

        this.constructor.prototype.Initialize.call(this);
    },
    AfterInitialize: function(){
        if (this.HasDefaultWindow())
            this.AfterInitializeWindow(-1);
        for(var i = 0; i < this.popupElementIDArray.length; i ++) 
            this.AfterInitializeWindow(i);
        this.constructor.prototype.AfterInitialize.call(this);
    },
    
    InitializeArrays: function(){
        if (this.GetWindowCountCore() > 0){
            if (this.contentUrlArray.length == 0)
                this.InitializeArray(this.contentUrlArray, "");
            if (this.popupElementIDArray.length == 0)
                this.InitializeArray(this.popupElementIDArray, "");
            if (this.showOnPageLoadArray.length == 0)
                this.InitializeArray(this.showOnPageLoadArray, false);
            if (this.isDraggedArray.length == 0)
                this.InitializeArray(this.isDraggedArray, false);
            if (this.isResizedArray.length == 0)
                this.InitializeArray(this.isResizedArray, false);
            if (this.zIndexArray.length == 0)
                this.InitializeArray(this.zIndexArray, -1);                
            if (this.leftArray.length == 0)
                this.InitializeArray(this.leftArray, 0);
            if (this.topArray.length == 0)
                this.InitializeArray(this.topArray, 0);
            if (this.widthArray.length == 0)
                this.InitializeArray(this.widthArray, 0);
            if (this.heightArray.length == 0)
                this.InitializeArray(this.heightArray, 0);
            if (this.cachedSizeArray.length == 0)
                this.InitializeArray(this.cachedSizeArray, null);
            if (this.iframeLoadingArray.length == 0)
                this.InitializeArray(this.iframeLoadingArray, false);
            if (__aspxIE){
                if (this.headerHeightArray.length == 0)
                    this.InitializeArray(this.headerHeightArray, -1);
                if (this.footerHeightArray.length == 0)
                    this.InitializeArray(this.footerHeightArray, -1);
            }
        }
    },
    InitializeArray: function(array, value){
        for (var i = 0; i < this.GetWindowCountCore(); i++)
            array[i] = value;
    },
    InitializeWindow: function(index){
        this.GetPopupElement(index);
        var element = this.GetWindowElement(index);
        if (element != null){
            element.onresize = new Function("aspxPWResize(\""+ this.name + "\",\"" + element.id + "\");");
            if (__aspxIE)
                this.AttachOnDragStartEventToWindowImages(index);
            this.InitIFrame(index);

            element.isHiding = false;
            element.isIEContentHeightInit = false;
            element.isPopupPositionCorrectionOn = this.isPopupPositionCorrectionOn || !this.GetShowOnPageLoad(index);
            if (this.GetShowOnPageLoad(index) && this.GetZIndex(index) > 0){
                this.FirstShowWindow(index, false);
                aspxGetPopupControlCollection().SetWindowElementZIndex(element, this.GetZIndex(index));
                element.isPopupPositionCorrectionOn = true;
            }
        }
    },
    InitIFrame: function(index){
        var contentIFrameElement = this.GetWindowContentIFrameElement(index);
        if(_aspxIsExists(contentIFrameElement)){
            contentIFrameElement.popupControlName = this.name;
            contentIFrameElement.pcWndIndex = index;
            _aspxAttachEventToElement(contentIFrameElement, "load", aspxPCIframeLoad);
        }
    },
    AfterInitializeWindow: function(index){
        if (this.GetShowOnPageLoad(index) && this.GetZIndex(index) < 0){
            this.FirstShowWindow(index, true);
            
            var element = this.GetWindowElement(index);
            if (element != null)
                element.isPopupPositionCorrectionOn = true;     
            
        }
    },
    // fix: ondragstart event is not valid for XHTML
    AttachOnDragStartEventToWindowImages: function(index) {            
        this.AttachChildImagesPreventDragStartEvent(this.GetWindowHeaderElement(index));
        this.AttachChildImagesPreventDragStartEvent(this.GetWindowFooterElement(index));
    },
    AttachChildImagesPreventDragStartEvent: function(parentElem) {
        var images = parentElem == null ? null : _aspxGetElementsByTagName(parentElem, "img");
        if (images != null) {        
            for(var i = 0; i < images.length; i ++)
                images[i].ondragstart = new Function("return _aspxPreventDragStart(event)");        
         }    
    },
    
    FirstShowWindow: function(index, allowChangeZIndex){
        var isFreeWindow = this.GetIsDragged(index);
        var x = __aspxInvalidPosition;
        var y = __aspxInvalidPosition;
        if (isFreeWindow){
            x = this.GetWindowLeft(index);
            y = this.GetWindowTop(index);
            var popupHorizontalOffsetBackup = this.popupHorizontalOffset;
            var popupVerticalOffsetBackup = this.popupVerticalOffset;
            this.popupHorizontalOffset = 0;
            this.popupVerticalOffset = 0;
        }
        var enableAnimationBackup = this.enableAnimation;
        this.enableAnimation = false;
        
        this.DoShowWindowAtPos(index, x, y, isFreeWindow, false, allowChangeZIndex);
        
        this.enableAnimation = enableAnimationBackup;
        if (isFreeWindow){
            this.popupHorizontalOffset = popupHorizontalOffsetBackup ;
            this.popupVerticalOffset = popupVerticalOffsetBackup;
        }
    },
    GetIsDragged: function(index){
        if(0 <= index && index < this.isDraggedArray.length)
            return this.isDraggedArray[index];
        return this.isDragged;
    },
    SetIsDragged: function(index, value){
        if(0 <= index && index < this.isDraggedArray.length)
            this.isDraggedArray[index]=value;
        else            
            this.isDragged=value;
    },
    GetIsResized: function(index){
        if(0 <= index && index < this.isResizedArray.length)
            return this.isResizedArray[index];
        return this.isResized;
    },
    SetIsResized: function(index, value){
        if(0 <= index && index < this.isResizedArray.length)
            this.isResizedArray[index]=value;
        else            
            this.isResized=value;
    },
    HasDefaultWindow: function() {
        return this.GetWindowCountCore() == 0;
    },
    GetCurrentLeft: function(index){
        return this.GetPosition(index, true);
    },
    GetCurrentTop: function(index){
        return this.GetPosition(index, false);
    },
    GetHeaderHeight: function(index){
        if(0 <= index && index < this.headerHeightArray.length)
            return this.headerHeightArray[index];
        return this.headerHeight;
    },
    GetFooterHeight: function(index){
        if(0 <= index && index < this.footerHeightArray.length)
            return this.footerHeightArray[index];
        return this.footerHeight;
    },
    SetHeaderHeight: function(index, height){
        if(0 <= index && index < this.headerHeightArray.length)
            this.headerHeightArray[index] = height;
        else
            this.headerHeight = height;
    },
    SetFooterHeight: function(index, height){
        if(0 <= index && index < this.footerHeightArray.length)
            return this.footerHeightArray[index] = height;
        else 
            this.footerHeight = height;
    },
    GetPosition: function(index, isLeft){
        if(0 <= index && index < this.GetWindowCountCore())
            return  isLeft ? this.leftArray[index] : this.topArray[index];
        return  isLeft ? this.left : this.top;
    },
    GetPopupElement: function(index){
        var popupElement = this.GetPopupElementInternal(index);
        var modalElement = this.GetWindowModalElement(index);
        if(_aspxIsExists(modalElement))
            _aspxAttachEventToElement(modalElement, "mousedown", aspxPWMEMDown);
                        
        if(!_aspxIsExistsElement(popupElement)){
            var popupElement = _aspxFindPopupElementById(this.GetPopupElementID(index));
            if(_aspxIsExistsElement(popupElement)) {
                popupElement.DXPopupControl = this;
                popupElement.DXPopupWindowIndex = index;
                popupElement.isPopuped = false;
                
                if (this.popupAction == "LeftMouseClick")
                    _aspxAttachEventToElement(popupElement, "mouseup", aspxPEMEvent);
                else if (this.popupAction == "RightMouseClick")
                    _aspxAttachEventToElement(popupElement, "contextmenu", aspxPEMEvent);
                else if (this.popupAction == "MouseOver"){
                    _aspxAttachEventToElement(popupElement, "mouseover", aspxPEMOver);            
                    _aspxAttachEventToElement(this.GetWindowElement(index), "mouseover", aspxPWEMOver);
                }                    
                if (this.popupAction == "LeftMouseClick" || this.popupAction == "RightMouseClick"){
                    _aspxAttachEventToElement(popupElement, "mousedown", aspxPEMEvent);
                    this.isNeedPopupedSet = true;
                }
                
                this.SetPopupElementInternal(index, popupElement);
            }
        }
        return popupElement;
    },
    GetPopupElementInternal: function(index){
        if(0 <= index && index < this.GetWindowCountCore())
            return this.popupElements[index];
        return this.popupElement;
    },
    SetPopupElementInternal: function(index, element){
        if(0 <= index && index < this.GetWindowCountCore())
            this.popupElements[index] = element;
        else
            this.popupElement = element;
    },
    GetPopupElementID: function(index){
        if(0 <= index && index < this.GetWindowCountCore())
            return this.popupElementIDArray[index];
        return this.popupElementID;
    },
    GetShowOnPageLoad: function(index){
        if(0 <= index && index < this.showOnPageLoadArray.length)
            return this.showOnPageLoadArray[index];
        return this.showOnPageLoad;
    },
    GetWindowCountCore: function(){
        return (this.windows.length > 0) ? this.windows.length : this.windowCount;
    },
    GetWindowIFrame: function(index){
        var element = this.GetWindowElement(index);
        var iFrame = element.overflowElement;
        if(!_aspxIsExists(iFrame)){
            iFrame = this.FindWindowIFrame(index);
            element.overflowElement = iFrame;
        }
        return iFrame;
    },
    FindWindowIFrame: function(index){
        return _aspxGetElementById(this.name + "_DXPWIF" + index);
    },
    GetWindowModalElement: function(index){
        var element = this.GetWindowElement(index);
        if(!_aspxIsExists(element)) return;
        
        var modalElement = element.modalElement;
        if(!_aspxIsExists(modalElement)){
            modalElement = this.FindWindowModalElement(index);
            element.modalElement = modalElement;
            if(_aspxIsExists(modalElement)){
                modalElement.DXModalPopupControl = this;
                modalElement.DXModalPopupWindowIndex = index;
            }
        }
        return modalElement;
    },
    FindWindowModalElement: function(index){
        return _aspxGetElementById(this.name + "_DXPWMB" + index);
    },
    GetWindowElementId: function(index){
        return this.name + __aspxPCWIdSuffix + index;
    },
    GetWindowElement: function(index){
        if(!_aspxIsExistsElement(this.windowElements[index]))
            this.windowElements[index] = _aspxGetElementById(this.GetWindowElementId(index));
        return this.windowElements[index];
    },
    GetWindowChild: function(index, idPostfix){
        return _aspxGetChildById(this.GetWindowElement(index), this.name + idPostfix);
    },
    GetWindowContentIFrameDivElementID: function(index){
        return this.name + "_CIFD" + index;
    },
    GetWindowContentIFrameDivElement: function(index){
        return this.GetWindowChild(index, "_CIFD" + index);
    },
    GetWindowContentIFrameElementId: function(index){
        return this.name + "_CIF" + index;
    },
    GetWindowContentIFrameElement: function(index){
        return this.GetWindowChild(index, "_CIF" + index);
    },
    GetWindowContentIFrameUrl: function(index){
        if(0 <= index && index < this.contentUrlArray.length)
            return this.contentUrlArray[index];
        return this.contentUrl;
    },
    SetWindowContentIFrameUrl: function(index, url){
        if(0 <= index && index < this.contentUrlArray.length)
            this.contentUrlArray[index] = url;
        else
            this.contentUrl = url;
    },
    ShowWindowContentUrl: function(index){
        var contentIFrame = this.GetWindowContentIFrameElement(index);
        if(__aspxNetscapeFamily || __aspxWebKitFamily){
            var contentIFrameDiv = this.GetWindowContentIFrameDivElement(index);
            if(_aspxIsExists(contentIFrameDiv))
                this.AdjustIFrameDivHeight(this.GetWindowClientTable(index), contentIFrameDiv, contentIFrame);
            if(_aspxIsExists(contentIFrame))
                contentIFrame.style.height = contentIFrameDiv.clientHeight + "px";
        }
        this.LoadWindowContentUrl(index);
        if(_aspxIsExists(contentIFrame) && contentIFrame.DXReloadAfterShowRequired){
            this.RefreshWindowContentUrl(this.GetWindow(index));
            contentIFrame.DXReloadAfterShowRequired = false;
        }
    },
    LoadWindowContentUrl: function(index){
        var url = this.GetWindowContentIFrameUrl(index);
        this.LoadWindowContentFromUrl(index, url);
    },
    LoadWindowContentFromUrl: function(index, url){
        var element = this.GetWindowContentIFrameElement(index);
        if(_aspxIsExists(element) && element.src != url && element.DXSrcRaw != url){
            this.SetSrcToIframeElement(index, element, url);
            this.SetWindowContentIFrameUrl(index, element.src); // B130888
        }
    },
    SetSrcToIframeElement: function(index, iframeElement, src){
        this.SetIframeLoading(index, true);
        iframeElement.src = src;
	    iframeElement.DXSrcRaw = src;
    },
    GetWindowContentElement: function(index){
        return this.GetWindowChild(index, "_PWC" + index);
    },
    GetWindowHeaderElement: function(index){
        return this.GetWindowChild(index, "_PWH" + index);
    },
    GetWindowHeaderGripElement: function(index){
        return this.GetWindowChild(index, "_FGRP" + index);
    },
    GetWindowFooterElement: function(index){
        return this.GetWindowChild(index, "_PWF" + index);
    },
    GetWindowIndex: function(element){
        var id = element.id;
        var pos = id.lastIndexOf(__aspxPCWIdSuffix);
        return parseInt(id.substr(pos + __aspxPCWIdSuffix.length));
    },
    GetWindowMainCell: function(element){
        return this.GetWindowMainTable(element).rows[0].cells[0];
    },
    GetWindowMainTable: function(element){
        var index = this.GetWindowIndex(element);
        var shadowTable = this.GetWindowChild(index, "_PWST" + index);
        return shadowTable != null ? shadowTable : element;
    },
    GetWindowClientTable: function(index){
        return this.GetWindowChild(index, "_CLW" + index);
    },
    GetWindowLeft: function(index){
        if(0 <= index && index < this.leftArray.length)
            return this.leftArray[index];
        return this.left;
    },
    SetWindowLeft: function(index, left){
        if(0 <= index && index < this.leftArray.length)
            this.leftArray[index] = left;
        else
            this.left = left;
    },
    GetWindowHeightInternal: function(index){
        if(0 <= index && index < this.heightArray.length)
            return this.heightArray[index];
        return this.height;
    },
    SetWindowHeight: function(index, height){
        if(0 <= index && index < this.heightArray.length)
            this.heightArray[index] = height;
        else 
            this.height = height;
    },
    GetWindowWidthInternal: function(index){
        if(0 <= index && index < this.widthArray.length)
            return this.widthArray[index];
        return this.width;
    },
    SetWindowWidth: function(index, width){
        if(0 <= index && index < this.widthArray.length)
            this.widthArray[index] = width;
        else 
            this.width = width;
    },
    GetWindowTop: function(index){
        if(0 <= index && index < this.topArray.length)
            return this.topArray[index];
        return this.top;
    },
    SetWindowTop: function(index, top){
        if(0 <= index && index < this.topArray.length)
            return this.topArray[index] = top;
        else
            return this.top = top;
    },
    GetWindowsStateInputElement: function(){
        return _aspxGetElementById(this.name + "WS");
    },
    GetZIndex: function(index){
        if (0 <= index && index < this.zIndexArray.length)
            return this.zIndexArray[index];
        return this.zIndex;
    },
    GetCurrentZIndex: function(index){
        var element = this.GetWindowElement(index);
        if(element != null) {
            if(element.style.zIndex != "") 
                return element.style.zIndex;
            if(0 <= index && index < this.GetWindowCountCore())
                return  this.zIndexArray[index];
            return this.zIndex;
        }
    },
    GetCurrentWindowWidth: function(index){
        var element = this.GetWindowElement(index);
        if(element != null) {
            var mainCell = this.GetWindowMainCell(element);
            if(mainCell.firstChild.offsetWidth > 0)
                return mainCell.firstChild.offsetWidth;
            return this.GetWindowWidthInternal(index);
        }
    },
    GetCurrentWindowHeight: function(index){
        var element = this.GetWindowElement(index);
        if(element != null) {
            var mainCell = this.GetWindowMainCell(element);
            if(mainCell.firstChild.offsetHeight > 0)
                return mainCell.firstChild.offsetHeight;
            return this.GetWindowHeightInternal(index);
        }
    },
    GetIframeLoading: function(index){
        if (0 <= index && index < this.iframeLoadingArray.length)
            return this.iframeLoadingArray[index];
        return this.iframeLoading;
    },
    SetIframeLoading: function(index, value){
        if(0 <= index && index < this.iframeLoadingArray.length)
            this.iframeLoadingArray[index] = value;
        else
            this.iframeLoading = value;
    },
    
    GetClientPopupPos: function(element, popupElement, pos, isX, isDragged){
        var index = this.GetWindowIndex(element);
        var popupPosition = null;
        
        if (isDragged)
            popupPosition = new _aspxPopupPosition(this.GetPosition(index, isX), false);
        else
            popupPosition = isX ? this.GetClientPopupPosX(element, popupElement, pos) : this.GetClientPopupPosY(element, popupElement, pos);
        popupPosition.position = _aspxPrepareClientPosForElement(popupPosition.position, element, isX);
        
        if(__aspxFirefox && __aspxBrowserVersion < 3 && _aspxIsExists(this.GetWindowModalElement(index)))
            popupPosition.position -= isX ? _aspxGetDocumentScrollLeft() : _aspxGetDocumentScrollTop();
        if(__aspxIE && __aspxBrowserVersion > 5.5 && popupElement != null && _aspxIsExistsAbsoluteOrRelativePosParent(popupElement))
            popupPosition.position -= _aspxGetIEDocumentClientOffset(isX);
        return popupPosition;
    },
    GetClientPopupPosX: function(element, popupElement, x){
        var mainElement = this.GetWindowMainCell(element);
        var popupPosition = _aspxGetPopupAbsoluteX(mainElement, this.shadowWidth,popupElement, this.popupHorizontalAlign, this.popupHorizontalOffset, 
            x, this.GetWindowLeft(this.GetWindowIndex(element)));
        return this.CorrectPopupPositionForClientWindow(element, popupPosition, true);
    },
    GetClientPopupPosY: function(element, popupElement, y){
        var mainElement = this.GetWindowMainCell(element);
        var popupPosition = _aspxGetPopupAbsoluteY(mainElement, this.shadowHeight, popupElement, this.popupVerticalAlign, this.popupVerticalOffset, 
            y, this.GetWindowTop(this.GetWindowIndex(element)));
        return (this.allowCorrectYOffsetPosition ? this.CorrectPopupPositionForClientWindow(element, popupPosition, false) : popupPosition);
    },
    CorrectPopupPositionForClientWindow: function(element, popupPosition, isX){
        if (element.isPopupPositionCorrectionOn){
            popupPosition.position = _aspxAdjustPositionToClientScreen(element, 
                isX ? this.shadowWidth : this.shadowHeight, popupPosition.position, isX);
        }
        return popupPosition;
    },
    DoShowWindow: function(index, evt){
        if (!this.InternalIsWindowVisible(index)){
            var x = _aspxGetEventX(evt);
            var y = _aspxGetEventY(evt);
            this.DoShowWindowAtPos(index, x, y, false, true, true);
        }
    },
    DoShowWindowAtPos: function(index, x, y, ignorePopupElement, closeOtherWindows, allowChangeZIndex){
        var element = this.GetWindowElement(index);
        if(element != null){
            if (this.adjustInnerControlsSizeOnShow) {
                var windowContent = this.GetWindowContentElement(index);
                var collection = aspxGetControlCollection();
                collection.CollapseControls(windowContent, __aspxCheckSizeCorrectedFlag);
            }
            
            this.FFTextCurFixShow(index, true);
            if (closeOtherWindows)
                aspxGetPopupControlCollection().DoHideAllWindows(null, this.GetWindowElementId(index), false);
        
            var isMoving = this.InternalIsWindowVisible(index);
            _aspxSetElementDisplay(element, true);
            
            if(__aspxIE && !element.isIEContentHeightInit){
                element.isIEContentHeightInit = true;
                this.GetWindowContentElement(index).style.height = "0px";
                this.CorrectContentCellHeight(element, false); //Header and footer height initialization for resizing
            }
            
            var cachedSize = this.GetWindowCachedSize(index);
            if(cachedSize != null){
                this.SetWindowSize(this.GetWindow(index), cachedSize.width, cachedSize.height);
                this.ResetWindowCachedSize(index);
            }
            
            var popupElement = ignorePopupElement ? null : this.GetPopupElement(index);
            var isDragged = this.GetIsDragged(index);
            var horizontalPopupPosition = this.GetClientPopupPos(element, popupElement, x, true, isDragged);
            var verticalPopupPosition = this.GetClientPopupPos(element, popupElement, y, false, isDragged);

            var clientX = horizontalPopupPosition.position;
            var clientY = verticalPopupPosition.position;
            this.SetWindowPos(index, element, clientX, clientY);

            this.DoShowWindowModalElement(index);
            var isAnimationNeed = this.enableAnimation && !isMoving;
            if (isAnimationNeed)
                this.StartAnimation(element, index, horizontalPopupPosition, verticalPopupPosition);
            else
                _aspxSetElementVisibility(element, true);

            if (!isMoving){
                aspxGetPopupControlCollection().RegisterVisibleWindow(element);
                this.RaisePopUp(index);
                if(!this.enableAnimation)
                    this.RaiseShowen(index);
            }
            if (allowChangeZIndex){
                aspxGetPopupControlCollection().ActivateWindowElement(element);
            }
            
            // Prevent bug in Netscape. First window showing, window is under its modalelement undependet on zIndex
            if(!isAnimationNeed && __aspxNetscape && _aspxIsExists(this.GetWindowModalElement(index))){
                _aspxSetElementDisplay(element, false);
                _aspxSetElementDisplay(element, true);
            }
            
            this.ShowWindowContentUrl(index);

            if (this.adjustInnerControlsSizeOnShow) {
                collection.AdjustControls(windowContent, __aspxCheckSizeCorrectedFlag);
            }
        }
    },
    DoShowWindowIFrame: function(index, x, y, width, height){
        if (!this.renderIFrameForPopupElements) return;
        
        var element = this.GetWindowElement(index);
        var iFrame = this.GetWindowIFrame(index);
        if(_aspxIsExists(element) && _aspxIsExists(iFrame)){
            var cell = this.GetWindowMainCell(element);
            if (width < 0)
                width = cell.offsetWidth;
            if (height < 0)
                height = cell.offsetHeight;
            _aspxSetStyleSize(iFrame, width, height);
            if (x != __aspxInvalidPosition && y != __aspxInvalidPosition)
                _aspxSetStylePosition(iFrame, x, y);
            _aspxSetElementDisplay(iFrame, true);
        }
    },
    DoShowWindowModalElement: function(index){
        var modalElement = this.GetWindowModalElement(index);
        if(_aspxIsExists(modalElement)){
            if(this.hideBodyScrollWhenModal && !this.IsWindowVisible(this.GetWindow(index)))
                _aspxHideBodyScroll();
            _aspxSetElementDisplay(modalElement, true);
            aspxGetPopupControlCollection().AdjustModalElementBounds(modalElement);
            _aspxSetElementVisibility(modalElement, true);
            aspxGetPopupControlCollection().RegisterVisibleModalElement(modalElement);
        }
    },
    DoHideWindowCore: function(index){
        this.FFTextCurFixHide(index, true);
        var element = this.GetWindowElement(index);
        if(element != null){
            element.isHiding = true;
            this.SetIsDragged(index, false);
            this.UpdateWindowsStateInputElement();
            this.UpdateWindowsStateCookie();
            element.isHiding = false;
            
            _aspxStopAnimation(element);
            
            _aspxSetElementVisibility(element, false);
            _aspxSetElementDisplay(element, false);
            
            this.DoHideWindowModalElement(element);
            this.DoHideWindowIFrame(element);
            
            aspxGetPopupControlCollection().UnregisterVisibleWindow(element);
        }
    },
    DoHideWindow: function(index){
        if (!this.InternalIsWindowVisible(index)) return;
        
        var cancel = this.RaiseClosing(index);

        if(!cancel){
            this.DoHideWindowCore(index);
            this.RaiseCloseUp(index);
        }
        return cancel;
    },
    DoHideWindowIFrame: function(element){
        if (!this.renderIFrameForPopupElements) return;

        var iFrame = element.overflowElement;
        if(_aspxIsExists(iFrame))
            _aspxSetElementDisplay(iFrame, false);
    },
    DoHideWindowModalElement: function(element){
        var modalElement = element.modalElement;
        if(_aspxIsExists(modalElement)){
            aspxGetPopupControlCollection().UnregisterVisibleModalElement(modalElement);
            if(this.hideBodyScrollWhenModal) {
                if(__aspxWebKitFamily)
                    aspxGetPopupControlCollection().LockScrollEvent();
                _aspxRestoreBodyScroll();
                if(__aspxWebKitFamily)
                    aspxGetPopupControlCollection().UnlockScrollEvent();
            }
            _aspxSetStyleSize(modalElement, 1, 1);
            _aspxSetElementVisibility(modalElement, false);
            _aspxSetElementDisplay(modalElement, false);
        }
    },
    SetWindowDisplay: function(index, value){
        var pcwElement = this.GetWindowElement(index);
        this.SetFFTextCurFixShowing(index, value, false);
        _aspxSetElementDisplay(pcwElement, value);
    },
    GetTextCurFixDiv: function(index){
        return _aspxGetElementById(this.name + "_" + "TCFix" + index);
    },
    FFTextCurFixShow: function(index, isSetVisibility){
        this.SetFFTextCurFixShowing(index, true, isSetVisibility);
    },
    FFTextCurFixHide: function(index, isSetVisibility){
        this.SetFFTextCurFixShowing(index, false, isSetVisibility);
    },
    IsFFTextCurFixRequired: function(index){
        return __aspxFirefox && _aspxIsExists(this.GetWindowModalElement(index));
    },
    SetFFTextCurFixShowing: function(index, value, isSetVisibility){
        if(this.IsFFTextCurFixRequired(index)){
            var fixDiv = this.GetTextCurFixDiv(index);
            if(_aspxIsExists(fixDiv)){
                if(isSetVisibility)
                    _aspxSetElementVisibility(fixDiv, value);
                _aspxSetElementDisplay(fixDiv, value);
            }
        }        
    },
    SetWindowPos: function(index, element, x, y){
        _aspxSetStylePosition(element, x, y);
        this.DoShowWindowIFrame(index, x, y, __aspxInvalidDimension, __aspxInvalidDimension);

        this.SetIsDragged(index, true);
        this.SetWindowLeft(index, _aspxGetAbsoluteX(element));
        this.SetWindowTop(index, _aspxGetAbsoluteY(element));
        this.UpdateWindowsStateInputElement();
        this.UpdateWindowsStateCookie();
    },

    CorrectContentCellHeight: function(element, isResizing){
        if (__aspxIE){
            var index = this.GetWindowIndex(element);
            var clientTable = this.GetWindowClientTable(index);
            var headerCell = this.GetWindowHeaderElement(index);
            var contentCell = this.GetWindowContentElement(index);
            var footerCell = this.GetWindowFooterElement(index);
            
            var windowMainCell = this.GetWindowMainCell(element);
            var mainCellHeight = windowMainCell.clientHeight - this.GetTwoVerticalPaddingSize(windowMainCell);
            var headerHeight = _aspxIsExists(headerCell) ? headerCell.offsetHeight : 0;
            var footerHeight = _aspxIsExists(footerCell) ? footerCell.offsetHeight : 0;
            if (isResizing){
                headerHeight = this.GetHeaderHeight(index);
                footerHeight = this.GetFooterHeight(index);
            }
            else{
                this.SetHeaderHeight(index, headerHeight);
                this.SetFooterHeight(index, footerHeight);
            }
            // (Math.max for IE8)
            var correctedHeight = Math.max(0, mainCellHeight - headerHeight - footerHeight);
            
            contentCell.style.height = correctedHeight + "px";
            var verticalsPaddings = contentCell.offsetHeight - correctedHeight;
            contentCell.style.height = correctedHeight - verticalsPaddings + "px";
        }
    },
    GetTwoVerticalPaddingSize: function(element){
        var heightWithBorders = element.clientHeight;
        var paddingTopBackup = element.style.paddingTop;
        var paddingBottomBackup = element.style.paddingBottom;
        element.style.paddingTop = "0px";
        element.style.paddingBottom = "0px";
        var heightWithoutBorders = element.clientHeight;
        element.style.paddingTop = paddingTopBackup;
        element.style.paddingBottom = paddingBottomBackup;
        return (heightWithBorders - heightWithoutBorders);
    },
    InternalIsWindowVisible: function(index){
        var element = this.GetWindowElement(index);
        return (element != null) ? _aspxGetElementVisibility(element) : false;
    },
    InternalIsWindowDisplayed: function(index){
        var element = this.GetWindowElement(index);
        return (element != null) ? _aspxGetElementDisplay(element) : false;
    },
    OnActivate: function(index){
        var element = this.GetWindowElement(index);
        if (element != null)
            aspxGetPopupControlCollection().ActivateWindowElement(element);
    },
    OnAnimationTimer: function(index){
        var animationDivElement = this.GetWindowElement(index);
        if(_aspxIsExists(animationDivElement)){
            var element = this.GetWindowMainTable(animationDivElement);
            var mainCell = this.GetWindowMainCell(animationDivElement);
            var iframeElement = this.GetWindowIFrame(index);
            
            _aspxOnAnimationTimer(animationDivElement, element, mainCell, iframeElement, this.animationDelay, this.animationMaxDelay,__aspxPCAnimationAccelerator);
        }
    },
    OnAnimationStop: function(index){
        this.RaiseShowen(index);
    },
    OnDragStart: function(evt, index){
        this.SetIsDragged(index, true);
        this.ShowDragCursor(index);
        var element = this.GetWindowElement(index);
        if(_aspxIsExists(this.GetWindowContentIFrameElement(index)))
            this.HideIframeElementBeforeDragging(index);        
        var gragXOffset = _aspxGetAbsoluteX(element) - _aspxGetEventX(evt) - _aspxGetIEDocumentClientOffset(true);
        var gragYOffset = _aspxGetAbsoluteY(element) - _aspxGetEventY(evt) - _aspxGetIEDocumentClientOffset(false);
        var xClientCorrection = _aspxGetPositionElementOffset(element, true);
        var yClientCorrection = _aspxGetPositionElementOffset(element, false);
        gragXOffset -= xClientCorrection;
        gragYOffset -= yClientCorrection;
        aspxGetPopupControlCollection().InitDragObject(this, index, gragXOffset, gragYOffset, xClientCorrection, yClientCorrection);
    },
    OnDrag: function(index, x, y, xClientCorrection, yClientCorrection) {
        var element = this.GetWindowElement(index);
        if(element != null){
            _aspxSetStylePosition(element, x, y);        
            this.SetWindowLeft(index, x + xClientCorrection);
            this.SetWindowTop(index, y + yClientCorrection);
                        
            var iFrame = element.overflowElement;
            if(_aspxIsExists(iFrame))
                _aspxSetStylePosition(iFrame, x, y);
            if (__aspxOpera) 
                _aspxClearSelection();
        }
    },
    OnDragStop: function(index) {
        var element = this.GetWindowElement(index);
        this.HideDragCursor(index);
        this.UpdateWindowsStateInputElement();
        this.UpdateWindowsStateCookie();
        if(_aspxIsExists(this.GetWindowContentIFrameElement(index)))
            this.ShowIframeElementAfterDragging(index);
    },
    HideIframeElementBeforeDragging: function(index){
        var iframeElement = this.GetWindowContentIFrameElement(index);
        if(__aspxIE){
            this.CreateFakeDragDiv(iframeElement);
            _aspxSetElementDisplay(iframeElement, false);
        } else
            _aspxSetElementVisibility(iframeElement, false);
    },
    ShowIframeElementAfterDragging: function(index){
        var iframeElement = this.GetWindowContentIFrameElement(index);
        if(this.fakeDragDiv != null){
            this.RemoveFakeDragDiv(iframeElement);
            _aspxSetElementDisplay(iframeElement, true);
        } else
            _aspxSetElementVisibility(iframeElement, true);
    },
    CreateFakeDragDiv: function(iframe) {
        this.fakeDragDiv = document.createElement("div");
        _aspxSetStyleSize(this.fakeDragDiv, iframe.offsetWidth, iframe.offsetHeight);        
        iframe.parentElement.appendChild(this.fakeDragDiv);
    },
    RemoveFakeDragDiv: function(iframe) {
        iframe.parentElement.removeChild(this.fakeDragDiv);
        this.fakeDragDiv = null;
    },
    CreateResizePanel: function(index){
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        var resizePanel = document.createElement("DIV");
        element.parentNode.appendChild(resizePanel);
        resizePanel.style.overflow = "hidden";
        resizePanel.style.position = "absolute";
        resizePanel.style.zIndex = __aspxPopupControlZIndex + aspxGetPopupControlCollection().visiblePopupWindowIds.length * 2 + 2;
        if (!this.isLiveResizingMode)
            resizePanel.style.border = "black 1px dotted";
        return resizePanel;
    },
    OnResizeStart: function(evt, index){
            if (!aspxGetPopupControlCollection().IsResizeInint()){
            this.SetIsResized(index, true);
            var cursor = this.CreateResizeCursorInfo(evt, index);
            if (cursor.course != ""){
                var resizePanel = this.CreateResizePanel(index);
                this.UpdateResizeCursor(resizePanel, cursor.verticalDirection, cursor.horizontalDirection);
                aspxGetPopupControlCollection().InitResizeObject(this, index, cursor, resizePanel);
                this.OnResize(evt, index, cursor, resizePanel);
            }
        }
        return aspxGetPopupControlCollection().IsResizeInint();
    },
    OnResize: function(evt, index, cursor, resizePanel){
        this.OnResizePanel(evt, index, cursor, resizePanel);
        if (this.isLiveResizingMode)
            this.OnResizeWindow(index, cursor, resizePanel);
        if (!__aspxIE) 
            _aspxClearSelection();
    },
    OnResizePanel: function(evt, index, cursor, resizePanel){
        var x = _aspxGetEventX(evt);
        var y = _aspxGetEventY(evt);
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        var clientWindow = this.GetWindowClientTable(index);
        
        var left = _aspxGetAbsoluteX(mainCell);
        var top = _aspxGetAbsoluteY(mainCell);
        var newLeft = _aspxGetAbsoluteX(element);
        var newTop  = _aspxGetAbsoluteY(element);
        var newHeight = mainCell.offsetHeight;
        var newWidth = mainCell.offsetWidth;

        if(cursor.horizontalDirection == "e")
            newWidth = x - newLeft + cursor.horizontalOffset + 1;
        if(cursor.verticalDirection == "s")
            newHeight = y - newTop + cursor.verticalOffset + 1;
        if(cursor.horizontalDirection == "w") {
            newLeft = _aspxPrepareClientPosForElement(x, element, true) - cursor.horizontalOffset;
            newWidth = newWidth - (x - left) + cursor.horizontalOffset;
        }else
            newLeft = _aspxPrepareClientPosForElement(newLeft, element, true);
        if(cursor.verticalDirection == "n"){
            newTop =_aspxPrepareClientPosForElement(y, element, false) - cursor.verticalOffset;
            newHeight = newHeight - (y - top) + cursor.verticalOffset;
        }else
            newTop = _aspxPrepareClientPosForElement(newTop, element, false);

        if(!this.isLiveResizingMode){// Correction for both side border size
            newWidth -= 2; 
            newHeight -= 2;
        }
        
        if(newWidth > 0 && newHeight > 0) {
            _aspxSetStylePosition(resizePanel, newLeft - _aspxGetIEDocumentClientOffset(true), newTop - _aspxGetIEDocumentClientOffset(false));
            _aspxSetStyleSize(resizePanel, newWidth, newHeight);
            
            this.SetWindowLeft(index, _aspxGetAbsoluteX(element));
            this.SetWindowTop(index, _aspxGetAbsoluteY(element));
        }
    },
    OnResizeWindow: function(index, cursor, resizePanel){
        this.SetClientWindowSize(index, resizePanel.offsetWidth, resizePanel.offsetHeight);
        
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        var heightCorrection = mainCell.offsetHeight - resizePanel.offsetHeight;
        var widthCorrection = mainCell.offsetWidth - resizePanel.offsetWidth;
        var left = _aspxGetAbsoluteX(resizePanel) - (cursor.horizontalDirection == "w" ? widthCorrection : 0) - _aspxGetIEDocumentClientOffset(true);
        var top  = _aspxGetAbsoluteY(resizePanel) - (cursor.verticalDirection == "n" ?  heightCorrection : 0) - _aspxGetIEDocumentClientOffset(false);
        left = _aspxPrepareClientPosForElement(left, element, true);
        top = _aspxPrepareClientPosForElement(top, element, false);
        
        _aspxSetStylePosition(element, left, top);
        if(this.InternalIsWindowVisible(index)) // B139249
            this.DoShowWindowIFrame(index, left, top, __aspxInvalidDimension, __aspxInvalidDimension);
    },
    OnResizeStop: function(evt, index, cursor, resizePanel){
        if(this.allowResize){
            if (!this.isLiveResizingMode) {
                var collection = aspxGetControlCollection();
                var windowElement = this.GetWindowElement(index);
                collection.CollapseControls(windowElement);
                this.OnResizeWindow(index, cursor, resizePanel);
            }
            this.CreateResizeCursorInfo(evt, index);
            this.UpdateWindowsStateInputElement();
            this.UpdateWindowsStateCookie();
            this.RaiseResize(index);
            if (!this.isLiveResizingMode)
                collection.AdjustControls(windowElement);
        }
    },
    OnMouseDownModalElement: function(evt, index) {
        aspxGetPopupControlCollection().DoHideAllWindows(_aspxGetEventSource(evt), "", false);
        if (this.isNeedPopupedSet) {
            var popupElement = this.GetPopupElement(index);
            popupElement.isPopuped = true;
        }
    },
    SetClientWindowSize: function(index, width, height){
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        var clientWindow = this.GetWindowClientTable(index);
        var windowHorizontalTwoBorderSize = mainCell.offsetWidth - clientWindow.offsetWidth;
        var windowVerticalTwoBorderSize = mainCell.offsetHeight - clientWindow.offsetHeight;
        
        var contentIFrameDiv = this.GetWindowContentIFrameDivElement(index);
        var contentIFrame = this.GetWindowContentIFrameElement(index);
        
        width -= windowHorizontalTwoBorderSize;
        height -= windowVerticalTwoBorderSize;
        if(width < 0) width = 0;
        if(height < 0) height = 0;
	        
        this.RaiseBeforeResizing(index);
        if (__aspxIE){
            this.GetWindowContentElement(index).style.height = "0px";
            mainCell.style.height = "0px"; // Prevent some time mainCell height persistance and increase PC whole height
        } else {
            if (_aspxIsExists(contentIFrame))
                contentIFrame.style.height = "0px";
            if(_aspxIsExists(contentIFrameDiv)) 
                contentIFrameDiv.style.height = "0px";
        }
        _aspxSetStyleSize(clientWindow, width, height);

        _aspxSetStyleSize(mainCell, width, height);
        if (__aspxNetscapeFamily){// Prevent Mozilla invalid horizontal resizing panel in ContentControl
            _aspxSetElementDisplay(element, false);
            _aspxSetElementDisplay(element, true);
        }
        _aspxSetStyleSize(element, clientWindow.offsetWidth + this.shadowWidth + windowHorizontalTwoBorderSize, clientWindow.offsetHeight + this.shadowHeight + windowVerticalTwoBorderSize);
        this.CorrectContentCellHeight(element, true);
        
        this.SetWindowWidth(index, clientWindow.offsetWidth);
        this.SetWindowHeight(index, clientWindow.offsetHeight);
        
        if(_aspxIsExists(contentIFrameDiv))
            this.AdjustIFrameDivHeight(clientWindow, contentIFrameDiv, contentIFrame);
        if(_aspxIsExists(contentIFrame))
            contentIFrame.style.height = "100%";
        this.RaiseAfterResizing(index);
    },
    GetIsSafariGreater4OrChromeGreater2: function(){
        return (__aspxSafari && __aspxBrowserVersion >= 4) || (__aspxChrome  && __aspxBrowserVersion >= 2);
    },
    AdjustIFrameDivHeight: function(clientWindow, contentIFrameDiv, contentIFrame){
        if(this.GetIsSafariGreater4OrChromeGreater2())
            this.AdjustIFrameDivHeight_Safari4(contentIFrameDiv);
        else if((__aspxOpera && __aspxBrowserVersion >= 9.5) || __aspxFirefox)
            this.AdjustIFrameDivHeight_OperaGreaterThan95_FireFox(clientWindow, contentIFrameDiv, contentIFrame);
        else
            contentIFrameDiv.style.height = "100%";
    },
    AdjustIFrameDivHeight_Safari4: function(contentIFrameDiv){
        var firstClientHeight = this.GetElementClientHeight(contentIFrameDiv.parentNode);
        contentIFrameDiv.style.height = firstClientHeight + "px";
        var secontClientHeight = this.GetElementClientHeight(contentIFrameDiv.parentNode);
        contentIFrameDiv.style.height = (2 * firstClientHeight - secontClientHeight) + "px";
    },
    AdjustIFrameDivHeight_OperaGreaterThan95_FireFox: function(clientWindow, contentIFrameDiv, contentIFrame){
        var clientWindowHeight = clientWindow.offsetHeight;
        
        contentIFrameDiv.style.height = "100%";
        var contentIFrameDivHeight = contentIFrameDiv.offsetHeight;
        contentIFrameDiv.style.height = contentIFrameDivHeight + "px";
        var clientWindowHeightDifference = clientWindow.offsetHeight - clientWindowHeight;
        contentIFrameDiv.style.height = (contentIFrameDivHeight - clientWindowHeightDifference) + "px";
	},
    GetElementClientHeight: function(element){
        if(this.GetIsSafariGreater4OrChromeGreater2() && element.tagName == "TD")
            return _aspxWebKit3TDRealInfo.GetClientHeight(element);
        return element.clentHeight;
    },
    SetWindowCachedSize: function(index, width, height) {
        if(0 <= index && index < this.heightArray.length)
            this.cachedSizeArray[index] = new _aspxSize(width, height);
        else 
            this.cachedSize = new _aspxSize(width, height);
    },
    GetWindowCachedSize: function(index) {
        if(0 <= index && index < this.heightArray.length)
            return this.cachedSizeArray[index];
        else 
            return this.cachedSize;
    },
    ResetWindowCachedSize: function(index) {
        if(0 <= index && index < this.heightArray.length)
            this.cachedSizeArray[index] = null;
        else 
            this.cachedSize = null;
    },
    CreateResizeCursorInfo: function(evt, index){
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        var clientWindow = this.GetWindowClientTable(index);
        var headerElement = this.GetWindowHeaderElement(index);
        var left = _aspxGetAbsoluteX(mainCell);
        var top = _aspxGetAbsoluteY(mainCell);
        var x = _aspxGetEventX(evt);
        var y = _aspxGetEventY(evt);

        var leftOffset = Math.abs(x - left);
        var rightOffset = Math.abs(x - left - mainCell.offsetWidth + 1);
        var topOffset = Math.abs(y - top);
        var bottomOffset = Math.abs(y - top - mainCell.offsetHeight + 1);

        var cursorInfo = this.CreateResizeBorderCursorInfo(index, leftOffset, rightOffset, topOffset, bottomOffset);
        
        var gripCell = this.GetWindowHeaderGripElement(index);
        if (gripCell) {
            var gripCursorInfo = this.CreateGripCursorInfo(index, mainCell, gripCell, rightOffset, bottomOffset);
            if (_aspxIsExists(gripCursorInfo))
                cursorInfo = gripCursorInfo;
        }
        this.UpdateResizeCursor(clientWindow, cursorInfo.verticalDirection, cursorInfo.horizontalDirection);
        this.UpdateResizeCursor(mainCell, cursorInfo.verticalDirection, cursorInfo.horizontalDirection);
        
        if (_aspxIsExists(headerElement))
            this.UpdateResizeCursor(headerElement, cursorInfo.verticalDirection, cursorInfo.horizontalDirection);
        return cursorInfo;
    },
    CreateGripCursorInfo: function(index, mainCell, gripCell, rightOffset, bottomOffset){
        var gripWidth  = mainCell.offsetWidth - (_aspxGetAbsoluteX(gripCell) - _aspxGetAbsoluteX(mainCell));
        var gripHeight = mainCell.offsetHeight - (_aspxGetAbsoluteY(gripCell) - _aspxGetAbsoluteY(mainCell));
        
        if (gripHeight > bottomOffset && gripWidth > rightOffset) 
            return new ASPxPCResizeCursorInfo("e", "s", rightOffset, bottomOffset);
        return null;
    },
    CreateResizeBorderCursorInfo: function(index, leftOffset, rightOffset, topOffset, bottomOffset){
        var ResizeBorderSize = this.ResizeBorderSize;
        var verticalDirection = this.GetResizeVerticalCourse(ResizeBorderSize, topOffset, bottomOffset);
        
        ResizeBorderSize = verticalDirection != "" ? this.ResizeCornerBorderSize : this.ResizeBorderSize;
        var horizontalDirection = this.GetResizeHorizontalCourse(ResizeBorderSize, leftOffset, rightOffset);
        
        if (verticalDirection == "" && horizontalDirection != "")
            verticalDirection = this.GetResizeVerticalCourse(this.ResizeCornerBorderSize, topOffset, bottomOffset);
        
        var horizontalOffset = leftOffset < rightOffset ? leftOffset : rightOffset;
        var verticalOffset = topOffset < bottomOffset ? topOffset : bottomOffset;
        return new ASPxPCResizeCursorInfo(horizontalDirection, verticalDirection, horizontalOffset, verticalOffset);
    },
    GetResizeVerticalCourse: function(ResizeBorderSize, topOffset, bottomOffset){
        if (ResizeBorderSize > topOffset) return "n";
        if (ResizeBorderSize > bottomOffset) return "s";
        return "";
    },
    GetResizeHorizontalCourse: function(ResizeBorderSize, leftOffset, rightOffset){
        if (ResizeBorderSize > leftOffset) return "w";
        if (ResizeBorderSize > rightOffset) return "e";
        return "";
    },
    UpdateResizeCursor: function(element, verticalDirection, horizontalDirection){
        var cursor = verticalDirection +  horizontalDirection;
        if (cursor != ""){
            cursor += "-resize";
            this.ShowTemporaryCursor(element, cursor);
        }
        else
            this.HideTemporaryCursor(element);
    },
    ShowTemporaryCursor: function(element, cursor){
        _aspxChangeStyleAttribute(element, "cursor", cursor);
    },
    HideTemporaryCursor: function(element){
        _aspxRestoreStyleAttribute(element, "cursor");
    },
    ResizeWindowIFrame: function(index){
        if (!this.renderIFrameForPopupElements) return;
        if (!this.InternalIsWindowVisible(index)) return;
        
        var iFrame = this.GetWindowIFrame(index);
        if(_aspxIsExists(iFrame)){    
            var cell = this.GetWindowMainCell(this.GetWindowElement(index));
            _aspxSetStyleSize(iFrame, cell.offsetWidth, cell.offsetHeight);
        }
    },
    
    ShowDragCursor: function(index){
        var dragElement = this.GetDragElement(index);
        if (dragElement)
            this.ShowTemporaryCursor(dragElement, "move");
    },
    HideDragCursor: function(index){
        var dragElement = this.GetDragElement(index);
        if(dragElement != null)
            this.HideTemporaryCursor(dragElement);
    },
    GetDragElement: function(index){
        var headerElement = this.GetWindowHeaderElement(index);
        var element = this.GetWindowElement(index);
        if (element != null)
            return (headerElement != null ? headerElement : this.GetWindowMainCell(element));
        return null;
    },
    
    OnActivateMouseDown: function(evt, index){
        this.OnActivate(index);
    },
    OnCloseButtonClick: function(index){
        this.RaiseCloseButtonClick(index);
        if(this.closeAction != "None")
            this.DoHideWindow(index);
    },
    OnMouseDown: function(evt, index, isDraggingAllowed){
        if(_aspxGetIsLeftButtonPressed(evt)){
            _aspxClearSelection();
            var isResizing = false;
            if (this.allowResize)
                isResizing = this.OnResizeStart(evt, index);
            if (isDraggingAllowed && !isResizing)
                this.OnDragStart(evt, index);

        }
    },
    OnMouseMove: function(evt, index){
        this.CreateResizeCursorInfo(evt, index);
    },
    
    StartAnimation: function(animationDivElement, index, horizontalPopupPosition, verticalPopupPosition){
        var element = this.GetWindowMainTable(animationDivElement);

        var clientX = horizontalPopupPosition.position;
        var clientY = verticalPopupPosition.position;
        
        var args = "(\"" + this.name + "\", " + index + ")";
        var onTimerString = "aspxPCATimer" + args;
        var onAnimStopCallString = "aspxPCAStop" + args;
        _aspxInitAnimationDiv(animationDivElement, clientX, clientY, onTimerString, onAnimStopCallString);
        
        var horizontalDirection = _aspxGetAnimationHorizontalDirection(horizontalPopupPosition, this.popupHorizontalAlign, this.popupVerticalAlign);
        var verticalDirection = _aspxGetAnimationVerticalDirection(verticalPopupPosition, this.popupHorizontalAlign, this.popupVerticalAlign);
        
        var xPos = horizontalDirection * animationDivElement.offsetHeight;
        var yPos = verticalDirection * animationDivElement.offsetWidth;
        
        _aspxSetStylePosition(element, xPos, yPos);
            
        _aspxSetElementVisibility(animationDivElement, true);
        this.DoShowWindowIFrame(index, clientX, clientY, 0, 0);

        animationDivElement.timerID = window.setTimeout(animationDivElement.onTimerString, this.animationDelay);
    },
    GetWindowsState: function(){
        var state = "";
        if (this.HasDefaultWindow()){
            state += this.GetWindowState(-1);
        }
        for(var i = 0; i < this.GetWindowCountCore(); i ++) {
            state += this.GetWindowState(i);
            if(i < this.GetWindowCountCore() - 1) state += ";";
        }
        return state;
    },
    GetWindowState: function(index){
        var element = this.GetWindowElement(index);
        if (element != null){
            var mainCell = this.GetWindowMainCell(element);
            var visibleFlag = (!this.InternalIsWindowVisible(index) || element.isHiding) ? "0" : "1";
            var isDraggedFlag = this.GetIsDragged(index) ? "1" : "0";
            var zIndex = this.GetCurrentZIndex(index);
            var isResized = this.GetIsResized(index);
            var isResizedFlag = isResized ? "1" : "0";
            var width = isResized ? this.GetCurrentWindowWidth(index) : 0;
            var height = isResized ? this.GetCurrentWindowHeight(index) : 0;
            var state = visibleFlag + ":" + isDraggedFlag + ":" + zIndex + ":" + 
                this.GetCurrentLeft(index) + ":" + this.GetCurrentTop(index) + ":" + isResizedFlag + ":" +
                width + ":" + height;
            return state;
        }
        return "";
    },
    UpdateWindowsStateCookie: function(){
        if(this.cookieName == "") return;
        
        _aspxDelCookie(this.cookieName);
        _aspxSetCookie(this.cookieName, this.GetWindowsState());
    },
    UpdateWindowsStateInputElement: function(){
        var element = this.GetWindowsStateInputElement();
        if(element != null) element.value = this.GetWindowsState();
    },
    OnIFrameLoad: function(index){
        this.SetIframeLoading(index, false);
    },
    // API
    CreateWindows: function(windowsNames){
        for (var i = 0; i < windowsNames.length; i ++){
            var window = new ASPxClientPopupWindow(this, i, windowsNames[i]);
            _aspxArrayPush(this.windows, window);
        }
    },
    RaiseCloseButtonClick: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.CloseButtonClick.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.CloseButtonClick.FireEvent(this, args);
        }
    },
    RaiseClosing: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        var cancel = false;
        if(!this.Closing.IsEmpty()){
            var args = new ASPxClientPopupWindowCancelEventArgs(false, window);
            this.Closing.FireEvent(this, args);
            cancel = args.cancel;
        }
        return cancel;
    },
    RaiseCloseUp: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.CloseUp.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.CloseUp.FireEvent(this, args);
        }
    },
    RaisePopUp: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.PopUp.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.PopUp.FireEvent(this, args);
        }
    },
    RaiseResize: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.Resize.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.Resize.FireEvent(this, args);
        }
    },
    RaiseBeforeResizing: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.BeforeResizing.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.BeforeResizing.FireEvent(this, args);
        }
    },
    RaiseAfterResizing: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.AfterResizing.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.AfterResizing.FireEvent(this, args);
        }
    },
    RaiseShowen: function(index){
        var window = index < 0 ? null : this.GetWindow(index);
        if(!this.Shown.IsEmpty()){
            var args = new ASPxClientPopupWindowEventArgs(false, window);
            this.Shown.FireEvent(this, args);
        }
    },
    AdjustSize: function() {
        return this.SetSize(0, 0);
    },
    GetHeight: function(){
        return this.GetWindowHeight(null);
    },
    GetWidth: function(){
        return this.GetWindowWidth(null);
    },
    SetSize: function(width, height){
        this.SetWindowSize(null, width, height);
    },
    GetWindowHeight: function(window){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        return mainCell.offsetHeight;
    },
    GetWindowWidth: function(window){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowElement(index);
        var mainCell = this.GetWindowMainCell(element);
        return mainCell.offsetWidth;
    },
    SetWindowSize: function(window, width, height){
        var index = (window != null) ? window.index : -1;
        if(this.InternalIsWindowDisplayed(index)) {
            this.SetClientWindowSize(index, width, height);
            var iFrame = this.GetWindowIFrame(index);
            if(_aspxIsExists(iFrame))
                _aspxSetStyleSize(iFrame, width, height);
        } else
            this.SetWindowCachedSize(index, width, height);
    },
    IsVisible: function(){
        return this.InternalIsWindowVisible(-1);
    },
    GetContentHTML: function(){
        return this.GetContentHtml();
    },
    SetContentHTML: function(html){
        this.SetContentHtml(html);
    },
    GetContentHtml: function(){
        return this.GetWindowContentHtml(null);
    },
    SetContentHtml: function(html){
        this.SetWindowContentHtml(null, html);
    },
    GetContentIFrame: function(window){
        return this.GetWindowContentIFrame(null);
    },
    GetContentUrl: function(){
        return this.GetWindowContentUrl(null);
    },
    SetContentUrl: function(url){
        this.SetWindowContentUrl(null, url);
    },
    RefreshContentUrl: function(){
        this.RefreshWindowContentUrl(null);
    },
    Show: function(){
        this.ShowWindow(null);
    },
    ShowAtElement: function(htmlElement){
        this.ShowWindowAtElement(null, htmlElement);
    },
    ShowAtElementByID: function(id){
        var htmlElement = document.getElementById(id);
        this.ShowWindowAtElement(null, htmlElement);
    },
    ShowAtPos: function(x, y){
        this.ShowWindowAtPos(null, Math.round(x), Math.round(y));
    },
    BringToFront: function(){
        this.BringWindowToFront(null);
    },
    Hide: function(){
        this.HideWindow(null);
    },
    IsWindowVisible: function(window){
        var index = (window != null) ? window.index : -1;
        return this.InternalIsWindowVisible(index);
    },
    GetWindow: function(index){
        return (0 <= index && index < this.windows.length) ? this.windows[index] : null;
    },
    GetWindowByName: function(name){
        for(var i = 0; i < this.windows.length; i ++)
            if(this.windows[i].name == name) return this.windows[i];
        return null;
    },
    GetWindowCount: function(){
        return this.GetWindowCountCore();
    },
    ShowWindow: function(window){
        var index = (window != null) ? window.index : -1;
        this.DoShowWindowAtPos(index, __aspxInvalidPosition, __aspxInvalidPosition, false, false, true);
    },
    ShowWindowAtElement: function(window, htmlElement){
        var index = (window != null) ? window.index : -1;
        var popupElementBackup = this.GetPopupElement(index);
        this.SetPopupElementInternal(index, htmlElement);
        this.ShowWindow(window);
        this.SetPopupElementInternal(index, popupElementBackup);
    },
    ShowWindowAtElementByID: function(window, id){
        var htmlElement = document.getElementById(id);
        this.ShowWindowAtElement(window, htmlElement);
    },
    ShowWindowAtPos: function(window, x, y){
        var index = (window != null) ? window.index : -1;
        this.DoShowWindowAtPos(index, x, y, true, false, true);
    },
    BringWindowToFront: function(window){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowElement(index); 
        aspxGetPopupControlCollection().ActivateWindowElement(element);
    },
    HideWindow: function(window){
        var index = (window != null) ? window.index : -1;
        this.DoHideWindow(index);
    },
    GetWindowContentHTML: function(window){
        return this.GetWindowContentHtml(window);
    },
    SetWindowContentHTML: function(window, html){
        this.SetWindowContentHtml(window, html);
    },
    GetWindowContentHtml: function(window){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowContentElement(index);
        return (element != null) ? element.innerHTML : "";
    },
    SetWindowContentHtml: function(window, html){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowContentElement(index);
        if(element != null){
            _aspxSetInnerHtml(element, html);
            this.ResizeWindowIFrame(index);
        }
    },
    GetWindowContentIFrame: function(window){
        var index = (window != null) ? window.index : -1;
        return this.GetWindowContentIFrameElement(index);
    },
    GetWindowContentUrl: function(window){
        var index = (window != null) ? window.index : -1;
        if(!this.IsWindowVisible(window))
            return this.GetWindowContentIFrameUrl(index);
        var element = this.GetWindowContentIFrameElement(index);
        return (element != null) ? element.src : "";
    },
    SetWindowContentUrl: function(window, url){
        var index = (window != null) ? window.index : -1;
        var element = this.GetWindowContentIFrameElement(index);
        var windowVisible = this.IsWindowVisible(window);
        if(windowVisible && element != null)
            this.ShowIframeElementAfterDragging(index);
        this.SetWindowContentIFrameUrl(index, url);
        var src = (__aspxIE && !windowVisible) ? this.SSLSecureBlankUrl : url;
        if (element == null)
            this.CreateWindowContentIFrameElement(index, src);
        else
            this.SetSrcToIframeElement(index, element, src);
    },
    RefreshWindowContentUrl: function(window){
        var index = (window != null) ? window.index : -1;
        if(__aspxIE)
            this.RefreshWindowContentUrlIE(index, window);
        else
            this.RefreshWindowContentUrlCommon(window);
    },
    RefreshWindowContentUrlIE: function(index, window){
        var windowVisible = this.InternalIsWindowVisible(index);
        if(windowVisible)
            this.RefreshWindowContentUrlIECore(index, window);
        else{
            var iframe = this.GetWindowContentIFrameElement(index);
            if(_aspxIsExists(iframe))
                iframe.DXReloadAfterShowRequired = true;
        }
    },
    RefreshWindowContentUrlIECore: function(index, window){
        try{
            if(!this.GetIframeLoading(index)){
                var iframe = this.GetWindowContentIFrameElement(index);
                if(_aspxIsExists(iframe))
                    iframe.contentWindow.location.reload();
            }
        } catch(e) {
            this.RefreshWindowContentUrlCommon(window);
        }
    },
    RefreshWindowContentUrlCommon: function(window){
        this.SetWindowContentUrl(window, this.GetWindowContentUrl(window));
    },
    UpdatePosition: function(){
        this.UpdatePositionAtElement(this.GetPopupElement(-1));
    },
    UpdatePositionAtElement: function(popupElement){
        this.UpdateWindowPositionAtElement(null, popupElement);
    },
    UpdateWindowPosition: function(window){
        var index = (window != null) ? window.index : -1;
        this.UpdateWindowPositionAtElement(window, this.GetPopupElement(index));
    },
    UpdateWindowPositionAtElement: function(window, popupElement){
        var index = (window != null) ? window.index : -1;
        this.UpdateWindowPositionInternal(index, popupElement);
    },
    
    UpdateWindowPositionInternal: function(index, popupElement){
        var element = this.GetWindowElement(index);
        if(this.InternalIsWindowVisible(index) && element != null){
            var horizontalPopupPosition = this.GetClientPopupPos(element, popupElement, __aspxInvalidPosition, true, false);
            var verticalPopupPosition = this.GetClientPopupPos(element, popupElement, __aspxInvalidPosition, false, false);
            this.SetWindowPos(index, element, horizontalPopupPosition.position, verticalPopupPosition.position);
        } else
            this.DoShowWindowAtPos(index, __aspxInvalidDimension, __aspxInvalidDimension, false, false, false);
        
    },
    TryAutoUpdatePosition: function(){
        if(this.autoUpdatePosition) 
            this.UpdatePosition();   
    },
    CreateWindowContentIFrameElement: function(index, src){
        var content = this.GetWindowContentElement(index);
        var iframeParent = content;
        content.innerHTML = "";

        var iframe = this.CreateContentIFrameElement(index, src);
        var iframeDiv = null;
        if(!__aspxIE){
            iframeDiv = this.CreateContentIFrameDivElement(index);
            content.appendChild(iframeDiv);
            iframeParent = iframeDiv;
        }
        iframeParent.appendChild(iframe);
        if(!__aspxIE){
            if(__aspxOpera)
                iframe.style.height = "100%";
            else
                iframe.style.height = iframeDiv.clientHeight + "px";
        }
        this.InitIFrame(index);
        return iframe;
    },
    CreateContentIFrameElement: function(index, src){
        var iframe = document.createElement("IFRAME");
        iframe.id = this.GetWindowContentIFrameElementId(index);
        iframe.scrolling = "auto";
        iframe.frameBorder = 0;
        iframe.style.width = "100%";
        iframe.style.height = __aspxIE ? "100%" : "0px";
        this.SetSrcToIframeElement(index, iframe, src);
        return iframe;
    },
    CreateContentIFrameDivElement: function(index){
        var iframeDiv = document.createElement("DIV");
        iframeDiv.id = this.GetWindowContentIFrameDivElementID(index);
        iframeDiv.style.width = "100%";
        iframeDiv.style.height = "100%";
        return iframeDiv;
    },
    GetWindowHeaderTextCell: function(index){
        return this.GetWindowChild(index, "_PWH" + index + "T");
    },
    GetWindowHeaderImageCell: function(index){
        return this.GetWindowChild(index, "_PWH" + index + "I");
    },
    GetWindowFooterTextCell: function(index){
        return this.GetWindowChild(index, "_PWF" + index + "T");
    },
    GetWindowFooterImageCell: function(index){
        return this.GetWindowChild(index, "_PWF" + index + "I");
    },
    GetWindowHeaderImageUrl: function(index){
        var element = this.GetWindowHeaderImageCell(index);
        if(element != null){
            var img = _aspxGetChildByTagName(element, "IMG", 0);
            if(img != null)
                return img.src;
        }
        return "";
    },
    SetWindowHeaderImageUrl: function(index, url){
        var element = this.GetWindowHeaderImageCell(index);
        if(element != null){
            var img = _aspxGetChildByTagName(element, "IMG", 0);
            if(img != null)
                img.src = url;
        }
    },
    GetWindowFooterImageUrl: function(index){
        var element = this.GetWindowFooterImageCell(index);
        if(element != null){
            var img = _aspxGetChildByTagName(element, "IMG", 0);
            if(img != null)
                return img.src;
        }
        return "";
    },
    SetWindowFooterImageUrl: function(index, url){
        var element = this.GetWindowFooterImageCell(index);
        if(element != null){
            var img = _aspxGetChildByTagName(element, "IMG", 0);
            if(img != null)
                img.src = url;
        }
    },
    GetWindowHeaderNavigateUrl: function(index){
        var element = this.GetWindowHeaderTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.href;
        }
        element = this.GetWindowHeaderImageCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.href;
        }
        return "";
    },
    SetWindowHeaderNavigateUrl: function(index, url){
        var element = this.GetWindowHeaderTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.href = url;
        }
        var element = this.GetWindowHeaderImageCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.href = url;
        }
    },
    GetWindowFooterNavigateUrl: function(index){
        var element = this.GetWindowFooterTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.href;
        }
        element = this.GetWindowFooterImageCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.href;
        }
        return "";
    },
    SetWindowFooterNavigateUrl: function(index, url){
        var element = this.GetWindowFooterTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.href = url;
        }
        var element = this.GetWindowFooterImageCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.href = url;
        }
    },
    GetWindowHeaderText: function(index){
        var element = this.GetWindowHeaderTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.innerHTML;
            else
                return element.innerHTML;
        }
        return "";
    },
    SetWindowHeaderText: function(index, text){
        var element = this.GetWindowHeaderTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.innerHTML = text;
            else
                element.innerHTML = text;
        }
    },
    GetWindowFooterText: function(index){
        var element = this.GetWindowFooterTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                return link.innerHTML;
            else
                return element.innerHTML;
        }
        return "";
    },
    SetWindowFooterText: function(index, text){
        var element = this.GetWindowFooterTextCell(index);
        if(element != null){
            var link = _aspxGetChildByTagName(element, "A", 0);
            if(link != null)
                link.innerHTML = text;
            else
                element.innerHTML = text;
        }
    },
    GetHeaderImageUrl: function(){
        return this.GetWindowHeaderImageUrl(-1);
    },
    SetHeaderImageUrl: function(value){
        this.SetWindowHeaderImageUrl(-1, value);
    },
    GetFooterImageUrl: function(){
        return this.GetWindowFooterImageUrl(-1);
    },
    SetFooterImageUrl: function(value){
        this.SetWindowFooterImageUrl(-1, value);
    },
    GetHeaderNavigateUrl: function(){
        return this.GetWindowHeaderNavigateUrl(-1);
    },
    SetHeaderNavigateUrl: function(value){
        this.SetWindowHeaderNavigateUrl(-1, value);
    },
    GetFooterNavigateUrl: function(){
        return this.GetWindowFooterNavigateUrl(-1);
    },
    SetFooterNavigateUrl: function(value){
        this.SetWindowFooterNavigateUrl(-1, value);
    },
    GetHeaderText: function(){
        return this.GetWindowHeaderText(-1);
    },
    SetHeaderText: function(value){
        this.SetWindowHeaderText(-1, value);
    },
    GetFooterText: function(){
        return this.GetWindowFooterText(-1);
    },
    SetFooterText: function(value){
        this.SetWindowFooterText(-1, value);
    },

    GetVisible: function(){
        return this.IsVisible();
    },
    SetVisible: function(visible){
        if(visible && !this.IsVisible())
            this.Show();
        else if(!visible && this.IsVisible())
            this.Hide();
    }
});
ASPxClientPopupControl.GetPopupControlCollection = function(){
    return aspxGetPopupControlCollection();
}
ASPxClientPopupControlCollection = _aspxCreateClass(ASPxClientControlCollection, {
    constructor: function(){
        this.constructor.prototype.constructor.call(this);
        
        this.draggingControl = null;
        this.draggingWindowIndex = -1;
        this.gragXOffset = 0;
        this.gragYOffset = 0;
        this.visibleModalElements = new Array();
        this.visiblePopupWindowIds = new Array();
        this.zIndex = __aspxPopupControlZIndex;
        
        this.overControl = null;
        this.overWindowIndex = -1;
        this.overXPos = __aspxInvalidPosition;
        this.overYPos = __aspxInvalidPosition;
        this.appearTimerID = -1;
        this.disappearTimerID = -1;
        this.scrollEventLockCount = 0;
       
        this.resizeControl = null;
        this.resizeIndex = -2;
        this.resizeCursor = "";
        this.resizePanel = null;
        
        this.selectBanned = false;
        
        this.SaveScrollState();
    },
    GetPopupWindowFromID: function(id){
        var pos = id.lastIndexOf(__aspxPCWIdSuffix);
        var name = id.substring(0, pos);
        var index = id.substr(pos + __aspxPCWIdSuffix.length);
        var popupControl = aspxGetPopupControlCollection().Get(name);
        return new _aspxPopupWindow(popupControl, index);
    },

    DoHideAllWindows: function(srcElement, excptId, applyToAll){
        for(var i = this.visiblePopupWindowIds.length - 1; i >= 0 ; i --){
            var id = this.visiblePopupWindowIds[i];

            if(id == excptId) continue;
            if(srcElement != null && _aspxGetParentById(srcElement, id) != null) continue;

            var popupWindow = this.GetPopupWindowFromID(id);
            if(popupWindow.popupControl != null && (
             (popupWindow.popupControl.closeAction != "CloseButton" && popupWindow.popupControl.closeAction != "None") || applyToAll)){
                popupWindow.popupControl.DoHideWindow(parseInt(popupWindow.windowIndex));
            }
        }
    },
    DoShowAtCurrentPos: function(name, index){
        var pc = this.Get(name);
        if(pc != null && !pc.InternalIsWindowVisible(index))
            pc.DoShowWindowAtPos(index, this.overXPos, this.overYPos, false, true, true);
    },
    
    ActivateWindowElement: function(element){
        var visibleWindowsCount = this.visiblePopupWindowIds.length;
        if (__aspxPopupControlZIndex <= element.style.zIndex && element.style.zIndex != visibleWindowsCount * 2 + __aspxPopupControlZIndex){
            this.DeleteWindowFromZIndexOrder(element);
        }
        this.SetWindowElementZIndex(element, __aspxPopupControlZIndex + visibleWindowsCount * 2);
    },
    DeleteWindowFromZIndexOrder: function(element){
        for(var i = this.visiblePopupWindowIds.length - 1; i >= 0 ; i--){
            var windowElement = _aspxGetElementById(this.visiblePopupWindowIds[i]);
            if(!_aspxIsExists(windowElement))
                _aspxArrayRemoveAt(this.visiblePopupWindowIds, i);
            else if (windowElement.style.zIndex > element.style.zIndex) 
                this.SetWindowElementZIndex(windowElement, windowElement.style.zIndex - 2);
        }
    },
    SetWindowElementZIndex: function(element, zIndex){
        element.style.zIndex = zIndex;
        var iFrame = element.overflowElement;
        if(_aspxIsExists(iFrame))
            iFrame.style.zIndex = zIndex - 1;
        var modalElement = element.modalElement;
        if(_aspxIsExists(modalElement))
            modalElement.style.zIndex = zIndex - 1;
        this.UpdateWindowsStateInputElement(element.id);
        this.UpdateWindowsStateCookie(element.id);
    }, 
    AdjustModalElementsBounds: function(){
        for(var i = 0; i < this.visibleModalElements.length; i++)
            this.AdjustModalElementBounds(this.visibleModalElements[i]);
    },
    AdjustModalElementBounds: function(element){
        if(!_aspxIsExistsElement(element)) return;
        var x = _aspxPrepareClientPosForElement(0, element, true);
        var y = _aspxPrepareClientPosForElement(0, element, false);
        _aspxSetStylePosition(element, x, y);
        if(__aspxNetscapeFamily) _aspxSetStyleSize(element, 1, 1);
        _aspxSetStyleSize(element, _aspxGetDocumentWidth(), _aspxGetDocumentHeight());
    },
    ClearAppearTimer: function(){
        this.appearTimerID = _aspxClearTimer(this.appearTimerID);
    },
    ClearDisappearTimer: function(){
        this.disappearTimerID = _aspxClearTimer(this.disappearTimerID);    
    },
    IsAppearTimerActive: function(){
        return this.appearTimerID > -1;
    },
    IsDisappearTimerActive: function(){
        return this.disappearTimerID > -1;
    },
    SetAppearTimer: function(name, index, timeout){
        this.appearTimerID = _aspxSetTimeout("aspxPEMOverTimer(\"" + name + "\", " + index + ")", timeout);
    },
    SetDisappearTimer: function(name, index, timeout){
        this.disappearTimerID = _aspxSetTimeout("aspxPWDisappearTimer(\"" + name + "\", " + index + ")", timeout);
    },
    GetDocScrollDifference: function(){
        return new _aspxScrollDifference(_aspxGetDocumentScrollLeft() - this.docScrollLeft, _aspxGetDocumentScrollTop() - this.docScrollTop);
    },
    IsDocScrolled: function(scroll){
        return scroll.horizontal != 0 || scroll.vertical != 0;
    },
    SaveScrollState: function(){
        this.docScrollLeft = _aspxGetDocumentScrollLeft();
        this.docScrollTop = _aspxGetDocumentScrollTop();
    },
    
    InitDragObject: function(control, index, x, y, xClientCorrection, yClientCorrection){
        this.draggingControl = control;
        this.draggingWindowIndex = index;
        this.gragXOffset = x;
        this.gragYOffset = y;
        this.xClientCorrection = xClientCorrection;
        this.yClientCorrection = yClientCorrection;
        this.selectBanned = true;
    },
    InitOverObject:  function(control, index, evt){
        this.overControl = control;
        this.overWindowIndex = index;
        this.SaveCurrentMouseOverPos(evt);    
    },
    InitResizeObject:  function(control, index, cursor, resizePanel){
        this.resizeControl = control;
        this.resizeIndex = index;
        this.resizeCursor = cursor;
        this.resizePanel = resizePanel;
        this.selectBanned = true;
    },
    IsResizeInint : function(){
        return this.resizeControl != null;
    },
    ClearDragObject: function(){
        this.draggingControl = null;
        this.draggingWindowIndex = -1;
        this.gragXOffset = 0;
        this.gragYOffset = 0;
        this.selectBanned = this.resizeControl != null;
    },
    ClearResizeObject: function(){
        this.resizeControl = null;
        this.resizeIndex = -2;
        this.resizeCursor = "";
        this.selectBanned = this.draggingControl != null;
        this.resizePanel.parentNode.removeChild(this.resizePanel);
    },
    Drag: function(evt){
        var x = _aspxGetEventX(evt) + this.gragXOffset;
        var y = _aspxGetEventY(evt) + this.gragYOffset;
        this.draggingControl.OnDrag(this.draggingWindowIndex, x, y, this.xClientCorrection, this.yClientCorrection);
    },
    DragStop: function(){
        this.draggingControl.OnDragStop(this.draggingWindowIndex);
        this.ClearDragObject();
    },
    ResizeStop: function(evt){
        this.resizeControl.OnResizeStop(evt, this.resizeIndex, this.resizeCursor, this.resizePanel);
        aspxGetPopupControlCollection().ClearResizeObject();
    },
    
    OnPWMouseMove: function(evt, name, index){
        if (this.draggingControl == null && 
            this.overControl == null && 
            this.resizeControl == null){
            var pc = aspxGetPopupControlCollection().Get(name);
            if(pc != null) pc.OnMouseMove(evt, index);
        }
    },
    OnPWMouseOver: function(evt){
        if (!_aspxIsExists(this.overControl) || _aspxIsExists(this.draggingControl)) return;
        if(this.IsOverPopupWindow(evt))
            this.ClearDisappearTimer();
    },
    IsOverPopupWindow: function(evt){
        return _aspxFindEventSourceParentByTestFunc(evt, aspxTestOverPopupWindowElement) != null;
    },
    
    OnDocumentMouseDown: function(evt){
        var popupElement = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupControlElement);
        var excptId = popupElement == null ? "" :
            popupElement.DXPopupControl.GetWindowElementId(popupElement.DXPopupWindowIndex);
        this.OnMouseDownCore(evt, excptId);
    },
    OnMouseDown: function(evt){
        this.OnMouseDownCore(evt, "");
    },
    OnMouseDownCore: function(evt, excptId){
        if(this.IsDocumentIsCoveredByModalElement())
            return;
        var srcElement = _aspxGetEventSource(evt);
        this.DoHideAllWindows(srcElement, excptId, false);
        aspxGetPopupControlCollection().ClearAppearTimer();
    },
    OnMouseMove: function(evt){
        if(this.draggingControl != null){
            if(__aspxIE && !_aspxGetIsLeftButtonPressed(evt)) 
                return this.DragStop();
            else
                this.Drag(evt);
        }
        else if(this.overControl != null){
            this.OnMouseOver(evt);
        }
        else if(this.resizeControl != null){
            if(__aspxIE && !_aspxGetIsLeftButtonPressed(evt)) 
                this.ResizeStop(evt);
            else
                this.resizeControl.OnResize(evt, this.resizeIndex, this.resizeCursor, this.resizePanel);
        }
    },
    OnMouseOver: function(evt){
        var element = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupControlOverElement);
        if (element != null){
            this.ClearDisappearTimer();
            this.SaveCurrentMouseOverPos(evt);
            return _aspxCancelBubble(evt);
        }
        this.OnMouseOut();
    },
    OnMouseOut: function(){
        if (!_aspxIsExists(this.overControl) || _aspxIsExists(this.draggingControl)) return;
        this.ClearAppearTimer();
        if(this.overControl.closeAction == "MouseOut"  && this.overControl.InternalIsWindowVisible(this.overWindowIndex)){
            if (!this.IsDisappearTimerActive())
                this.SetDisappearTimer(this.overControl.name, this.overWindowIndex, this.overControl.disappearAfter);
        }
        else
            this.OverStop();
    },
    OnMouseUp: function(evt){
        if(this.draggingControl != null)        
            this.DragStop();
        if(this.resizeControl != null)        
            this.ResizeStop(evt);
    },
    OnResize: function(evt){
        this.AutoUpdateElementsPosition();
        this.AdjustModalElementsBounds();
    },
    OnScroll: function(evt){
        if(this.scrollEventLockCount > 0)
            return;
        var scroll = this.GetDocScrollDifference();
        if(this.IsDocScrolled(scroll)){ // B33975
            this.CorrectPositionAtScroll(scroll);
            this.AdjustModalElementsBounds();
            this.SaveScrollState();
        }
    },
    LockScrollEvent: function() {
        this.scrollEventLockCount++;
    },
    UnlockScrollEvent: function() {
        this.scrollEventLockCount--;
    },
    CorrectPositionAtScroll: function(scroll){
        for(var i = 0; i < this.visiblePopupWindowIds.length; i++){
             var popupWindow = this.GetPopupWindowFromID(this.visiblePopupWindowIds[i]);
             var popupControl = popupWindow.popupControl;
             if(popupControl != null){
                 var isNeedFix = popupControl.IsFFTextCurFixRequired(popupWindow.windowIndex);
                 if(popupControl.autoUpdatePosition && !isNeedFix) 
                    popupWindow.popupControl.TryAutoUpdatePosition();   
                 else if(!popupControl.autoUpdatePosition && isNeedFix) // B131803
                    this.FFScrollEmulation(scroll, popupWindow);
             }
        } 
    },
    FFScrollEmulation: function(scroll, popupWindow){
        var windowElement = popupWindow.popupControl.GetWindowElement(popupWindow.windowIndex);
        windowElement.style.left = (windowElement.offsetLeft - scroll.horizontal) + "px";
        windowElement.style.top = (windowElement.offsetTop - scroll.vertical) + "px";
    },
    OnSelectStart: function(){
        return !this.selectBanned;
    },
    OverStop: function(){
        this.overControl = null;
        this.overWindowIndex = -1;
    },
    OnPWDisappearTimer: function(name, index){
        var pc = this.Get(name);
        if(pc != null){
            if(!pc.DoHideWindow(index))
                this.OverStop();        
            else
                this.ClearDisappearTimer();
        }
    },
    SaveCurrentMouseOverPos: function(evt){
        this.overXPos = _aspxGetEventX(evt);
        this.overYPos = _aspxGetEventY(evt);
    },
    RegisterVisibleModalElement: function(element){
        if(_aspxArrayIndexOf(this.visibleModalElements, element) == -1)
            _aspxArrayPush(this.visibleModalElements, element);
    },
    UnregisterVisibleModalElement: function(element){
        _aspxArrayRemove(this.visibleModalElements, element);
    },
    RegisterVisibleWindow: function(element){
        if(_aspxArrayIndexOf(this.visiblePopupWindowIds, element.id) == -1)
            _aspxArrayPush(this.visiblePopupWindowIds, element.id);
    },
    UnregisterVisibleWindow: function(element){
        this.DeleteWindowFromZIndexOrder(element);
        _aspxArrayRemove(this.visiblePopupWindowIds, element.id);
    },
    
    UpdateWindowsStateCookie: function(id){
        var pos = id.lastIndexOf(__aspxPCWIdSuffix);
        var name = id.substring(0, pos);
        var popupControl = aspxGetPopupControlCollection().Get(name);
        if(popupControl != null)
           popupControl.UpdateWindowsStateCookie(false);                
    },
    UpdateWindowsStateInputElement: function(id){
        var pos = id.lastIndexOf(__aspxPCWIdSuffix);
        var name = id.substring(0, pos);
        var popupControl = aspxGetPopupControlCollection().Get(name);
        if(popupControl != null)
           popupControl.UpdateWindowsStateInputElement(false);                
    },
    AutoUpdateElementsPosition: function() {
          for(var i = 0; i < this.visiblePopupWindowIds.length; i++){
                var popupWindow = this.GetPopupWindowFromID(this.visiblePopupWindowIds[i]);
                var popupControl = popupWindow.popupControl;
                if(popupControl != null && popupControl.InternalIsWindowVisible(popupWindow.windowIndex))
                    popupControl.TryAutoUpdatePosition();
          }
    },
    IsDocumentIsCoveredByModalElement: function() {
        for(var i = 0; i < this.visiblePopupWindowIds.length; i++){
                var popupWindow = this.GetPopupWindowFromID(this.visiblePopupWindowIds[i]);
                var popupControl = popupWindow.popupControl;
                if(popupControl != null && _aspxIsExists(popupControl.GetWindowModalElement(popupWindow.windowIndex)))
                    return true;
        }
        return false;
    },
    HideAllWindows: function(){
        this.DoHideAllWindows(null, "", true);
    }
});

var __aspxPopupControlCollection = null;
function aspxGetPopupControlCollection(){
    if(__aspxPopupControlCollection == null)
        __aspxPopupControlCollection  = new ASPxClientPopupControlCollection();
    return __aspxPopupControlCollection;
}
ASPxClientPopupWindow = _aspxCreateClass(null, {
    constructor: function(popupControl, index, name){
        this.popupControl = popupControl;
        this.index = index;
        this.name = name;
    },
    GetHeaderImageUrl: function(){
        return this.popupControl.GetWindowHeaderImageUrl(this.index);
    },
    SetHeaderImageUrl: function(value){
        this.popupControl.SetWindowHeaderImageUrl(this.index, value);
    },
    GetFooterImageUrl: function(){
        return this.popupControl.GetWindowFooterImageUrl(this.index);
    },
    SetFooterImageUrl: function(value){
        this.popupControl.SetWindowFooterImageUrl(this.index, value);
    },
    GetHeaderNavigateUrl: function(){
        return this.popupControl.GetWindowHeaderNavigateUrl(this.index);
    },
    SetHeaderNavigateUrl: function(value){
        this.popupControl.SetWindowHeaderNavigateUrl(this.index, value);
    },
    GetFooterNavigateUrl: function(){
        return this.popupControl.GetWindowFooterNavigateUrl(this.index);
    },
    SetFooterNavigateUrl: function(value){
        this.popupControl.SetWindowFooterNavigateUrl(this.index, value);
    },
    GetHeaderText: function(){
        return this.popupControl.GetWindowHeaderText(this.index);
    },
    SetHeaderText: function(value){
        this.popupControl.SetWindowHeaderText(this.index, value);
    },
    GetFooterText: function(){
        return this.popupControl.GetWindowFooterText(this.index);
    },
    SetFooterText: function(value){
        this.popupControl.SetWindowFooterText(this.index, value);
    }
});
ASPxClientPopupWindowEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
    constructor: function(processOnServer, window){
        this.constructor.prototype.constructor.call(this);
        this.window = window;
    }
});
ASPxClientPopupWindowCancelEventArgs = _aspxCreateClass(ASPxClientCancelEventArgs, {
    constructor: function(processOnServer, window){
        this.constructor.prototype.constructor.call(this, processOnServer);
        this.window = window;
    }
});

function _aspxPopupWindow(popupControl, windowIndex){
    this.popupControl = popupControl;
    this.windowIndex = windowIndex;
}
function _aspxScrollDifference(horizontal, vertical){
    this.horizontal = horizontal;
    this.vertical = vertical;
}

function aspxPEMOverTimer(name, index){
    aspxGetPopupControlCollection().DoShowAtCurrentPos(name, index);
}
function aspxPWDisappearTimer(name, index){
    aspxGetPopupControlCollection().OnPWDisappearTimer(name, index);
}

function aspxPWCBClick(evt, name, index){
    if(__aspxIE || __aspxOpera)
        _aspxEmulateDocumentOnMouseDown(evt); 
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) pc.OnCloseButtonClick(index);
}
function aspxPWCBMDown(evt){
    return _aspxCancelBubble(evt);
}
function aspxPEMOver(evt){
    var element = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupControlElement);
    if (element != null) {
        var popupControl = element.DXPopupControl;
        var index = element.DXPopupWindowIndex;
        if (!popupControl.InternalIsWindowVisible(index)){
            aspxGetPopupControlCollection().SetAppearTimer(popupControl.name, index, popupControl.appearAfter);
            aspxGetPopupControlCollection().InitOverObject(popupControl, index, evt);
        }
    }
}
function aspxPWEMOver(evt){
    aspxGetPopupControlCollection().OnPWMouseOver(evt);
}
function aspxPWMEMDown(evt){
    var element = _aspxGetEventSource(evt);
    if (element != null) // Prevent re-popup after ModalElement MouseDown + PopupElemen MouseUp
        element.DXModalPopupControl.OnMouseDownModalElement(evt, element.DXModalPopupWindowIndex);
}
function aspxPEMEvent(evt){
    var element = _aspxFindEventSourceParentByTestFunc(evt, aspxTestPopupControlElement);
    if (element != null){
        if (evt.type == "mousedown"){
            if (element.DXPopupControl.InternalIsWindowVisible(element.DXPopupWindowIndex))
                element.isPopuped = true;
            else
                element.isPopuped = false;
            aspxGetPopupControlCollection().OnMouseDown(evt);                    
        }
        else{
            if (element.DXPopupControl.popupAction=="RightMouseClick" || _aspxGetIsLeftButtonPressed(evt)){
                if (element.DXPopupControl.popupAction=="RightMouseClick")
                    _aspxPreventContextMenu(evt);
                if (!(element.isPopuped && element.DXPopupControl.closeAction == "OuterMouseClick"))
                    element.DXPopupControl.DoShowWindow(element.DXPopupWindowIndex, evt);
                if (element.DXPopupControl.closeAction == "MouseOut")
                    aspxGetPopupControlCollection().InitOverObject(element.DXPopupControl, element.DXPopupWindowIndex, evt);
                return false;
            }
        }
    }
}
function aspxPWDGMDown(evt, name, index){
    return aspxPWMDown(evt, name, index, true);
}
function aspxPWGripMDown(evt, name, index){
    aspxPWMDownCore(evt, name, index, false);
    return aspxPWCBMDown(evt);
}
function aspxPWMDown(evt, name, index, isWindowContentDraggingAllowed){
    aspxPWMDownCore(evt, name, index, isWindowContentDraggingAllowed);
    if(isWindowContentDraggingAllowed){ // B150637
        if (!__aspxIE) // Prevent image dragging
            evt.preventDefault();
        return _aspxCancelBubble(evt); // B150501
    }
}
function aspxPWMDownCore(evt, name, index, isDraggingAllowed){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) {
        pc.OnActivateMouseDown(evt, index);
        pc.OnMouseDown(evt, index, isDraggingAllowed);
    }
}
function aspxPWResize(name, index){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) pc.ResizeWindowIFrame(index);
}
function aspxPWMMove(evt, name, index){
    aspxGetPopupControlCollection().OnPWMouseMove(evt, name, index);
}
function aspxPCATimer(name, index){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) pc.OnAnimationTimer(index);
}
function aspxPCAStop(name, index){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) pc.OnAnimationStop(index);
}
function aspxPCIframeLoad(evt){
    var srcElement = _aspxGetEventSource(evt);
    if(_aspxIsExists(srcElement)){
        var pcName = srcElement.popupControlName;
        var pcWndIndex = srcElement.pcWndIndex;
        if(_aspxIsExists(pcName)){ 
            var pc = aspxGetPopupControlCollection().Get(pcName);
            pc.OnIFrameLoad(pcWndIndex);
        }
    }
}


_aspxAttachEventToDocument("mousedown", aspxPopupControlDocumentMouseDown);
function aspxPopupControlDocumentMouseDown(evt){
    aspxGetPopupControlCollection().OnDocumentMouseDown(evt);
}
_aspxAttachEventToDocument("mouseup", aspxPopupControlDocumentMouseUp);
function aspxPopupControlDocumentMouseUp(evt){
    return aspxGetPopupControlCollection().OnMouseUp(evt);    
}
_aspxAttachEventToDocument("mousemove", aspxPopupControlDocumentMouseMove);
function aspxPopupControlDocumentMouseMove(evt){
    if(typeof(aspxGetPopupControlCollection) != "undefined")
        aspxGetPopupControlCollection().OnMouseMove(evt);    
}
_aspxAttachEventToDocument("mouseout", aspxPopupControlDocumentMouseOut);
function aspxPopupControlDocumentMouseOut(){
    if(typeof(aspxGetPopupControlCollection) != "undefined")
        aspxGetPopupControlCollection().OnMouseOut();    
}
_aspxAttachEventToElement(window, "resize", aspxPopupControlWindowResize);
function aspxPopupControlWindowResize(evt){
    aspxGetPopupControlCollection().OnResize(evt);    
}
_aspxAttachEventToElement(window, "scroll", aspxPopupControlWindowScroll);
function aspxPopupControlWindowScroll(evt){
    aspxGetPopupControlCollection().OnScroll(evt);    
}
_aspxAttachEventToDocument("selectstart", aspxPopupControlDocumentSelectStart);
function aspxPopupControlDocumentSelectStart(evt){
    var ret = aspxGetPopupControlCollection().OnSelectStart(evt);    
    if(!ret) return false; // B95132 returning true can affect another control handler result. So we have to return false/undefined
}
function aspxTestPopupControlElement(element){
    return (_aspxIsExists(element.DXPopupControl) && _aspxIsExists(element.DXPopupWindowIndex));
}
function aspxTestPopupControlOverElement(element){
    var collection = aspxGetPopupControlCollection();
    var windowId = collection.overControl.GetWindowElementId(collection.overWindowIndex);
    var popupElementId = collection.overControl.GetPopupElement(collection.overWindowIndex).id;
    return (element.id == windowId || element.id == popupElementId);
}
function aspxTestOverPopupWindowElement(element){
    var collection = aspxGetPopupControlCollection();
    var windowId = collection.overControl.GetWindowElementId(collection.overWindowIndex);
    var popupWindowElementId = collection.overControl.GetWindowElementId(collection.overWindowIndex);
    return (element.id == popupWindowElementId);
}
