

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.isDraggedArray = [];
        this.isResizedArray = [];
        this.zIndexArray = [];
        this.leftArray = [];
        this.topArray = [];
        this.height = 0;
        this.width = 0;
        this.heightArray = [];
        this.widthArray = [];
        this.isLiveResizingMode = true;
        this.isPopupPositionCorrectionOn = true;
        this.SSLSecureBlankUrl = "";
        this.windowElements = new Object();
        this.hideBodyScrollWhenModal = true;
        
        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.PopUp = new ASPxClientEvent();
        this.Resize = new ASPxClientEvent();
        this.Shown = 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 (__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);

            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;
            }
        }
    },
    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);
        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);            
                if (this.popupAction == "LeftMouseClick" || this.popupAction == "RightMouseClick"){
                    _aspxAttachEventToElement(popupElement, "mousedown", aspxPEMEvent);
                    var modalElement = this.GetWindowModalElement(index);
                    if(_aspxIsExists(modalElement))
                        _aspxAttachEventToElement(modalElement, "mousedown", aspxPWMEMDown);
                }
                
                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;
    },
    ShowWindowContentUrl: function(index){
        if(__aspxMozilla || __aspxSafari){
            var contentIFrameDiv = this.GetWindowContentIFrameDivElement(index);
            var contentIFrame = this.GetWindowContentIFrameElement(index);
            if(_aspxIsExists(contentIFrameDiv))
                contentIFrameDiv.style.height = "100%";
            if(_aspxIsExists(contentIFrame))
                contentIFrame.style.height = contentIFrameDiv.clientHeight + "px";
        }
        this.LoadWindowContentUrl(index);
    },
    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.src = url;
    },
    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);
        }
    },
    
    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 && _aspxIsExists(this.GetWindowModalElement(index)))
            popupPosition.position -= isX ? _aspxGetDocumentScrollLeft() : _aspxGetDocumentScrollTop();
        if(__aspxIE && !__aspxIE55 && popupElement != null && _aspxIsExistsAbsoluteOrRelativePosParent(popupElement))
            popupPosition.position -= _aspxGetIEDocumentClientOffset(isX);
        return popupPosition;
    },
    GetClientPopupPosX: function(element, popupElement, x){
        var mainElement = this.GetWindowMainCell(element);
        var popupPosition = _aspxGetPopupAbsoluteX(mainElement, 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, 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){
            var min = isX ? _aspxGetDocumentScrollLeft() : _aspxGetDocumentScrollTop();
            var max = min + (isX ? _aspxGetDocumentClientWidth() : _aspxGetDocumentClientHeight());
            max -= (isX ? element.offsetWidth + this.shadowWidth : element.offsetHeight + this.shadowHeight);
            
            if (popupPosition.position > max) popupPosition.position = max;
            if (popupPosition.position < min) popupPosition.position = min;
        }
        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 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, null, clientX, clientY, true);

            this.DoShowWindowModalElement(index);
            var isAnimationNeed = this.enableAnimation && !isMoving;
            if (isAnimationNeed){
                this.StartAnimation(element, index, horizontalPopupPosition, verticalPopupPosition);
            }
            else {
                this.SetWindowPos(index, element, clientX, clientY, false);
                _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)
                _aspxHideBodyScroll();
            _aspxSetElementDisplay(modalElement, true);
            aspxGetPopupControlCollection().AdjustModalElementBounds(modalElement);
            _aspxSetElementVisibility(modalElement, true);
            aspxGetPopupControlCollection().RegisterVisibleModalElement(modalElement);
        }
    },
    DoHideWindow: function(index){
        if (!this.InternalIsWindowVisible(index)) return;
        
        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);
            
            this.RaiseCloseUp(index);
        }
    },
    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)
                _aspxRestoreBodyScroll();
            _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);
    },
    SetFFTextCurFixShowing: function(index, value, isSetVisibility){
        if(__aspxFirefox && _aspxIsExists(this.GetWindowModalElement(index))){
            var fixDiv = this.GetTextCurFixDiv(index);
            if(_aspxIsExists(fixDiv)){
                if(isSetVisibility)
                    _aspxSetElementVisibility(fixDiv, value);
                _aspxSetElementDisplay(fixDiv, value);
            }
        }        
    },
    SetWindowPos: function(index, element, x, y, saveToCache){
        if(saveToCache){
            this.SetIsDragged(index, true);
            this.SetWindowLeft(index, x);
            this.SetWindowTop(index, y);
            this.UpdateWindowsStateInputElement();
            this.UpdateWindowsStateCookie();
        } 
        if(element != null){
            _aspxSetStylePosition(element, x, y);
            this.DoShowWindowIFrame(index, x, y, __aspxInvalidDimension, __aspxInvalidDimension);
        }
    },

    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);
            }
            var correctedHeight = 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;
    },
    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);
        var gragXOffset = _aspxGetAbsoluteX(element) - _aspxGetEventX(evt) - _aspxGetIEDocumentClientOffset(true);
	    var gragYOffset = _aspxGetAbsoluteY(element) - _aspxGetEventY(evt) - _aspxGetIEDocumentClientOffset(false);
	    gragXOffset = _aspxPrepareClientPosForElement(gragXOffset, element, true);
	    gragYOffset = _aspxPrepareClientPosForElement(gragYOffset, element, false);
        aspxGetPopupControlCollection().InitDragObject(this, index, gragXOffset, gragYOffset);
    },
    OnDrag: function(index, x, y) {
        var element = this.GetWindowElement(index);
        if(element != null){
            _aspxSetStylePosition(element, x, y);        
            this.SetWindowLeft(index, x);
            this.SetWindowTop(index, y);
                        
            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();
	},
	
	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, newLeft);
            this.SetWindowTop(index, newTop);
        }
	},
	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);
        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);
        }
	},
	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 && height >= 0){
            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 (__aspxMozilla){// 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))
                contentIFrameDiv.style.height = "100%";
            if(_aspxIsExists(contentIFrame))
                contentIFrame.style.height = "100%";
        }
	},
	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);
        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();
    },
    // 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);
        }
    },
    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);
        }
    },
    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);
        }
    },
    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;
        this.SetClientWindowSize(index, width, height);
        var iFrame = this.GetWindowIFrame(index);
        if(_aspxIsExists(iFrame))
            _aspxSetStyleSize(iFrame, 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, x, y);
    },
    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);
    },
    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){
	        element.innerHTML = 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);
	    this.SetWindowContentIFrameUrl(index, url);
	    var src = (__aspxIE && !this.IsWindowVisible(window)) ? this.SSLSecureBlankUrl : url;
	    if (element == null)
	        this.CreateWidnowContentIFrameElement(index, src);
	    else
	        element.src = src;
    },
    RefreshWindowContentUrl: 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, true);
        } else
            this.DoShowWindowAtPos(index, __aspxInvalidDimension, __aspxInvalidDimension, false, false, false);
    },
    CreateWidnowContentIFrameElement: 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";
        }
        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";
        iframe.src = 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;
    },
    SetWindowContentIFrameUrl: function(index, url){
        if(0 <= index && index < this.contentUrlArray.length)
            this.contentUrlArray[index] = url;
        else
            this.contentUrl = url;
    },
    
    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.resizeControl = null;
        this.resizeIndex = -2;
        this.resizeCursor = "";
        this.resizePanel = null;
        
        this.selectBanned = false;
    },

    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 pos = id.lastIndexOf(__aspxPCWIdSuffix);
            var name = id.substring(0, pos);
            var index = id.substr(pos + __aspxPCWIdSuffix.length);
            var popupControl = aspxGetPopupControlCollection().Get(name);
            if(popupControl != null && (
             (popupControl.closeAction != "CloseButton" && popupControl.closeAction != "None") || applyToAll)){
                popupControl.DoHideWindow(parseInt(index));
            }
        }
    },
    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){
        var x = _aspxPrepareClientPosForElement(0, element, true);
        var y = _aspxPrepareClientPosForElement(0, element, false);
        _aspxSetStylePosition(element, x, y);
        if(__aspxNS) _aspxSetStyleSize(element, 1, 1);
        var width = this.GetDocumentWidth();
        var height = this.GetDocumentHeight();
        _aspxSetStyleSize(element, width, height);
    },
    GetDocumentWidth: function(){
        var bodyWidth = document.body.offsetWidth;
        var docWidth = document.documentElement.offsetWidth;
        var bodyScrollWidth = document.body.scrollWidth;
        var docScrollWidth = document.documentElement.scrollWidth;
        return this.GetMaxDimensionOf(bodyWidth, docWidth, bodyScrollWidth, docScrollWidth);
    },
    GetDocumentHeight: function(){
        var bodyHeight = document.body.offsetHeight;
        var docHeight = document.documentElement.offsetHeight;
        var bodyScrollHeight = document.body.scrollHeight;
        var docScrollHeight = document.documentElement.scrollHeight;
        return this.GetMaxDimensionOf(bodyHeight, docHeight, bodyScrollHeight, docScrollHeight);
    },
    GetMaxDimensionOf: function(){
        var max = __aspxInvalidDimension;
        for (var i = 0; i < arguments.length; i++){
            if(max < arguments[i])
                max = arguments[i];
        }
        return max;
    },
    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("aspxPEMOutTimer(\"" + name + "\", " + index + ")", timeout);
    },
    
    InitDragObject: function(control, index, x, y){
        this.draggingControl = control;
        this.draggingWindowIndex = index;
        this.gragXOffset = x;
        this.gragYOffset = y;
        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);
    },
    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);
        }
    },
    
    OnMouseDown: function(evt){
        var srcElement = _aspxGetEventSource(evt);
        this.DoHideAllWindows(srcElement, "", 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 = _aspxFindParentPopupElementByEvent(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.AdjustModalElementsBounds();
    },
    OnScroll: function(evt){
        this.AdjustModalElementsBounds();
    },
    OnSelectStart: function(){
        return !this.selectBanned;
    },
    OverStop: function(){
        this.overControl = null;
        this.overWindowIndex = -1;
    },
    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);                
    },
    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;
    }
});

function aspxPEMOverTimer(name, index){
    aspxGetPopupControlCollection().DoShowAtCurrentPos(name, index);
}
function aspxPEMOutTimer(name, index){
    var pc = aspxGetPopupControlCollection().Get(name);
    aspxGetPopupControlCollection().OverStop();
    if(pc != null) pc.DoHideWindow(index);
}

function aspxPWCBClick(name, index){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) pc.OnCloseButtonClick(index);
}
function aspxPWCBMDown(evt){
    return _aspxCancelBubble(evt);
}
function aspxPEMOver(evt){
    var element = _aspxFindParentPopupElementByEvent(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 aspxPWMEMDown(evt){
    var element = _aspxGetEventSource(evt);
	if (element != null){ // Prevent re-popup after ModalElement MouseDown + PopupElemen MouseUp
	    var popupElement = element.DXModalPopupControl.GetPopupElement(element.DXModalPopupWindowIndex);
	    popupElement.isPopuped = true;
	}
}
function aspxPEMEvent(evt){
	var element = _aspxFindParentPopupElementByEvent(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){
    var pc = aspxGetPopupControlCollection().Get(name);
    if(pc != null) {
        pc.OnActivateMouseDown(evt, index);
        pc.OnMouseDown(evt, index, true);
    }
    if (!__aspxIE) // Prevent image dragging
        evt.preventDefault();
	return aspxPWCBMDown(evt);
}
function aspxPWGripMDown(evt, name, index){
    aspxPWMDown(evt, name, index, false);
    return aspxPWCBMDown(evt);
}
function aspxPWMDown(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);
}


_aspxAttachEventToDocument("mousedown", aspxPopupControlDocumentMouseDown);
function aspxPopupControlDocumentMouseDown(evt){
    if (_aspxFindParentPopupElementByEvent(evt, aspxTestPopupControlElement) == null)// For mozilla
        return aspxGetPopupControlCollection().OnMouseDown(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);
}