function AdfDhtmlSimpleFloat() {
  this.Init()
}
AdfObject.createSubclass(AdfDhtmlSimpleFloat, AdfDhtmlPopupWindow);
AdfDhtmlSimpleFloat.InitClass = function() {
  this._DRAG_STYLECLASS = "p_AFDrag";
  this._INACTIVE_STYLECLASS = "p_AFInactive";
  this._CONTENT_ID = "contentContainer";
  this._BACKGROUND_EXPANDO = "data-afr-panelwindowbackground";
  this._TITLE_ID = "_ttxt";
  this._POPUP_INITIAL_FOCUS_LIVE_CONTENT_ID = "AFPopupInitialFocusLiveContent"
};
AdfDhtmlSimpleFloat.prototype.Init = function() {
  AdfDhtmlSimpleFloat.superclass.Init.call(this)
};
AdfDhtmlSimpleFloat.prototype.getContainedComponentClientId = function() {
  return this._containedComponentId
};
AdfDhtmlSimpleFloat.prototype.GetFocusContent = function() {
  var agent = AdfAgent.AGENT;
  var domWindow = agent.getDomWindow();
  if(domWindow.AdfSafariMobileAgent && agent instanceof AdfSafariMobileAgent) {
    return AdfDhtmlSimpleFloat.superclass.GetFocusContent.call(this)
  }
  var peer = this._getContainedComponentPeer();
  var subId = AdfRichUIPeer.CreateSubId(peer.getComponent().getClientId(), AdfDhtmlSimpleFloat._CONTENT_ID);
  var element = AdfAgent.AGENT.getElementById(subId);
  if(element && AdfAgent.AGENT.getPlatform() == AdfAgent.GECKO_PLATFORM) {
    element.tabIndex = -1
  }
  if(element) {
    if(AdfFocusUtils.containsFocus(element)) {
      element = AdfPage.PAGE.getActiveDomElement()
    }else {
      element = AdfFocusUtils.getFirstTabStop(element)
    }
  }
  if(!element) {
    if(peer instanceof AdfDhtmlDialogPeer) {
      element = peer.getDefaultButtonDom(this.getContainedComponentClientId())
    }
    if(!element) {
      element = peer.getDomElement()
    }
  }
  return element
};
AdfDhtmlSimpleFloat.prototype.setContent = function(selectorContent) {
  AdfDhtmlSimpleFloat.superclass.setContent.call(this, selectorContent);
  var mainElement = this._getMainElement(selectorContent);
  this.setShadowAnchor(mainElement);
  var containedComponent = AdfRichUIPeer.getFirstAncestorComponent(mainElement);
  this._containedComponentId = containedComponent.getClientId()
};
AdfDhtmlSimpleFloat.prototype.setAccessibleAttrs = function(hints) {
  var wrapper = this.getElement();
  var peer = this._getContainedComponentPeer();
  var contentId = AdfRichUIPeer.CreateSubId(peer.getComponent().getClientId(), AdfDhtmlSimpleFloat._CONTENT_ID);
  var titleId = AdfRichUIPeer.CreateSubId(peer.getComponent().getClientId(), AdfDhtmlSimpleFloat._TITLE_ID);
  wrapper.setAttribute("role", "dialog");
  wrapper.setAttribute("aria-describedby", contentId);
  wrapper.setAttribute("aria-labelledby", titleId);
  if(hints[AdfDhtmlPopupHints.MODAL]) {
    wrapper.setAttribute("aria-modal", "true")
  }
};
AdfDhtmlSimpleFloat.prototype.announceOpeningViaLiveRegion = function(hints) {
  if(hints && !hints[AdfDhtmlPopupHints.FOCUS]) {
    var laf = AdfPage.PAGE.getLookAndFeel();
    var documentClientId = AdfPage.PAGE.getDocumentClientId();
    var liveContainerId = AdfRichUIPeer.CreateSubId(documentClientId, AdfDhtmlDocumentPeer._GLOBAL_LIVE_CONTAINER_ID);
    var liveContainer = AdfAgent.AGENT.getElementById(liveContainerId);
    var domWindow = AdfPage.PAGE.getDomWindow();
    var liveTextKey = domWindow.AdfSafariMobileAgent && AdfAgent.AGENT instanceof AdfSafariMobileAgent ? "af_panelWindow.INITIAL_FOCUS_LIVE_TEXT_MOBILE" : "af_panelWindow.INITIAL_FOCUS_LIVE_TEXT";
    var liveContent = laf.getTranslatedString(liveTextKey);
    AdfAgent.AGENT.setTextContent(liveContainer, liveContent)
  }
};
AdfDhtmlSimpleFloat.prototype.removeAccessibleAttrs = function() {
  var documentClientId = AdfPage.PAGE.getDocumentClientId();
  var liveContainerId = AdfRichUIPeer.CreateSubId(documentClientId, AdfDhtmlDocumentPeer._GLOBAL_LIVE_CONTAINER_ID);
  var liveContainer = AdfAgent.AGENT.getElementById(liveContainerId);
  if(liveContainer) {
    AdfAgent.AGENT.setTextContent(liveContainer, "")
  }
};
AdfDhtmlSimpleFloat.prototype._getMainElement = function(content) {
  var tables = content.getElementsByTagName("table");
  var mainElement = tables[0];
  AdfAssert.assert(mainElement, "Main Element of floating window must be a table");
  return mainElement
};
AdfDhtmlSimpleFloat.prototype.setDragElement = function(dragElement) {
  this._dragElement = dragElement;
  if(this._repositionable) {
    this._repositionable.destroy();
    delete this._repositionable
  }
};
AdfDhtmlSimpleFloat.prototype.getModal = function(modal) {
  return this._modal
};
AdfDhtmlSimpleFloat.prototype.setModal = function(modal) {
  this._modal = modal
};
AdfDhtmlSimpleFloat.prototype.getInitialFocus = function(initialFocus) {
  return this._initialFocus
};
AdfDhtmlSimpleFloat.prototype.setInitialFocus = function(initialFocus) {
  this._initialFocus = initialFocus
};
AdfDhtmlSimpleFloat.prototype.activate = function() {
  this.raiseToFront();
  this.showAsActive();
  var shadowAnchor = this.getShadowAnchor();
  if(AdfDhtmlShadowDecorator.hasShadowDecorator(shadowAnchor)) {
    AdfDhtmlShadowDecorator.moveShadowDecorator(shadowAnchor)
  }
  if(!AdfFocusUtils.containsFocus(this.GetFocusContent()) && !AdfFocusUtils.isFocusChangePending()) {
    this.FocusOnFirstElement(true)
  }
};
AdfDhtmlSimpleFloat.prototype.showAsActive = function() {
  var containedComponentDomElement = this._getContainedComponentDomElement();
  var childNodes = containedComponentDomElement.childNodes, childCount = childNodes.length;
  for(var i = 0;i < childCount;i++) {
    var childNode = childNodes[i];
    var childStyle = childNode.style;
    if(childNode.getAttribute(AdfDhtmlSimpleFloat._BACKGROUND_EXPANDO) != null) {
      childStyle.display = "none"
    }
  }
  AdfDomUtils.removeCSSClassName(containedComponentDomElement, AdfDhtmlSimpleFloat._INACTIVE_STYLECLASS);
  this.raiseToFront();
  var anchor = this.getShadowAnchor();
  if(AdfDhtmlShadowDecorator.hasShadowDecorator(anchor)) {
    AdfDhtmlShadowDecorator.moveShadowDecorator(anchor);
    AdfDhtmlShadowDecorator.showShadowDecorator(anchor, true)
  }
};
AdfDhtmlSimpleFloat.prototype.showAsInActive = function() {
  var agent = AdfAgent.AGENT;
  var rootElement = this.getElement();
  var rootStyle = rootElement.style;
  var zIndex = rootStyle.zIndex;
  var borderTolerance = 2;
  var containedComponentDomElement = this._getContainedComponentDomElement();
  var w = containedComponentDomElement.offsetWidth;
  var h = containedComponentDomElement.offsetHeight;
  var childNodes = containedComponentDomElement.childNodes, childCount = childNodes.length;
  for(var i = 0, backgroundIndex = 0;i < childCount;i++) {
    var childNode = childNodes[i];
    var childStyle = childNode.style;
    if(childNode.getAttribute(AdfDhtmlSimpleFloat._BACKGROUND_EXPANDO) != null) {
      childStyle.zIndex = zIndex - 1;
      childStyle.marginLeft = backgroundIndex + "px";
      childStyle.marginTop = 3 - backgroundIndex + "px";
      childStyle.width = Math.max(0, w - borderTolerance - 2 * backgroundIndex) + "px";
      childStyle.height = Math.max(0, h - borderTolerance - 2 * (3 - backgroundIndex)) + "px";
      childStyle.display = "block";
      backgroundIndex++
    }else {
      childStyle.zIndex = zIndex
    }
  }
  AdfDomUtils.addCSSClassName(containedComponentDomElement, AdfDhtmlSimpleFloat._INACTIVE_STYLECLASS);
  var anchor = this.getShadowAnchor();
  if(AdfDhtmlShadowDecorator.hasShadowDecorator(anchor)) {
    AdfDhtmlShadowDecorator.moveShadowDecorator(anchor);
    AdfDhtmlShadowDecorator.showShadowDecorator(anchor, true)
  }
};
AdfDhtmlSimpleFloat.prototype.CreateDomElement = function() {
  var page = AdfPage.PAGE;
  var popupDiv = page.getDomDocument().createElement("div");
  var contentElement = popupDiv;
  if(this.NeedsCloseLink()) {
    var domDocument = page.getDomDocument();
    var linkDiv = domDocument.createElement("div");
    popupDiv.appendChild(linkDiv);
    var laf = page.getLookAndFeel();
    var closeLabel = laf.getTranslatedString("af_popup.TIP_DISMISS");
    linkDiv.innerHTML = '\x3ca href\x3d"javascript:;" style\x3d"position:absolute;top:-999px;" ' + 'onclick\x3d"var popupDiv \x3d this.parentNode.parentNode;' + "var contentDiv \x3d AdfDomUtils.getChildElements(popupDiv)[1];" + "var label \x3d popupDiv.getAttribute('aria-labelledby');" + "var compId \x3d label.split('::')[0];" + "var comp \x3d AdfPage.PAGE.findComponentByAbsoluteId(compId);" + "var peer \x3d comp.getPeer();" + "peer.bind(comp);" + 'peer.Cancel();"\x3e' + closeLabel + "\x3c/a\x3e";
    var contentDiv = domDocument.createElement("div");
    popupDiv.appendChild(contentDiv);
    contentElement = contentDiv
  }
  this.SetContentParent(contentElement);
  return popupDiv
};
AdfDhtmlSimpleFloat.prototype.SetContentParent = function(contentParentElement) {
  this._contentElement = contentParentElement
};
AdfDhtmlSimpleFloat.prototype.GetContentParent = function() {
  return this._contentElement
};
AdfDhtmlSimpleFloat.prototype.GetAnimationDurationSkinProperty = function() {
  var peer = this._getContainedComponentPeer();
  AdfAssert.assertPrototype(peer, AdfRichUIPeer);
  return peer.getAnimationDurationSkinProperty()
};
AdfDhtmlSimpleFloat.prototype.GetAnimateSkinProperty = function() {
  var peer = this._getContainedComponentPeer();
  AdfAssert.assertPrototype(peer, AdfRichUIPeer);
  return peer.getAnimateSkinProperty()
};
AdfDhtmlSimpleFloat.prototype.ShouldHideOnClip = function() {
  return false
};
AdfDhtmlSimpleFloat.prototype.handleComponentRemoved = function() {
  if(!this._bindInited) {
    return
  }
  AdfDhtmlShadowDecorator.removeShadowDecorator(this.getShadowAnchor());
  if(this._repositionable) {
    this._repositionable.destroy();
    delete this._repositionable
  }
};
AdfDhtmlSimpleFloat.prototype.handleBindToComponent = function() {
  if(this._repositionable) {
    return
  }
  this.setShadowAnchor(this._getMainElement(this.getContent()));
  var afterAnimation = !this.isAnimating();
  if(afterAnimation) {
    this.CreateShadow(afterAnimation)
  }
  var component = AdfPage.PAGE.findComponent(this._containedComponentId);
  if(component) {
    var peer = component.getPeer();
    peer.bind(component);
    this.setDragElement(peer.getDragElement());
    this.initializeRepositionable()
  }
};
AdfDhtmlSimpleFloat.prototype.initializeRepositionable = function() {
  if(this._repositionable) {
    return
  }
  var repositionable = this._repositionable = new AdfRepositionable(this, this._dragElement);
  repositionable.setDragStartHandler(this._dragStartHandler);
  repositionable.setDragEndHandler(this._dragEndHandler)
};
AdfDhtmlSimpleFloat.prototype.HandleEscapeKey = function(event) {
  var peer = this._getContainedComponentPeer();
  if(peer && peer.handleEscapeKey) {
    peer.handleEscapeKey(event)
  }else {
    AdfDhtmlSimpleFloat.superclass.HandleEscapeKey.call(this.event)
  }
};
AdfDhtmlSimpleFloat.prototype.DoShow = function(hints) {
  if(!this._bindInited) {
    this._bindInited = true;
    this.handleBindToComponent()
  }
  this.setDragElement(hints[AdfDhtmlPopupHints.DRAG_ELEMENT]);
  this.setModal(hints[AdfDhtmlPopupHints.MODAL]);
  var dialogManager = AdfDhtmlDialogManager.getInstance();
  dialogManager.registerDialog(this);
  var leftPercentage = hints[AdfDhtmlPopupHints.LEFT_POSITION];
  if(leftPercentage && isNaN(leftPercentage)) {
    leftPercentage = parseFloat(leftPercentage)
  }
  this._leftPercentage = leftPercentage;
  var topPercentage = hints[AdfDhtmlPopupHints.TOP_POSITION];
  if(topPercentage && isNaN(topPercentage)) {
    topPercentage = parseFloat(topPercentage)
  }
  this._topPercentage = topPercentage;
  AdfDhtmlSimpleFloat.superclass.DoShow.call(this, hints);
  if(this._dragElement) {
    this.initializeRepositionable()
  }
  var modal = this._modal;
  if(modal) {
    AdfPage.PAGE.getModalityManager().pushModal(this.getElement())
  }
  if(hints[AdfDhtmlPopupHints.FOCUS]) {
    dialogManager.activateDialog(this)
  }
  if(modal && hints[AdfDhtmlPopupHints.RESTORE_IMMEDIATE] && AdfDhtmlSimpleFloat._isMessageDialogVisible()) {
    var zorderScope = this.getZorderScope();
    if(AdfDhtmlPopupHints.ZORDER_SCOPE_BODY != zorderScope) {
      AdfPage.PAGE.showMessages()
    }
  }
};
AdfDhtmlSimpleFloat._isMessageDialogVisible = function() {
  var page = AdfPage.PAGE;
  var docId = page.getDefaultMessageHandlerComponentId();
  var docComp = page.findComponent(docId);
  var popups = docComp.getPeer().getAllPopups(docComp);
  var count = 0;
  for(i in popups) {
    count++
  }
  return count > 0
};
AdfDhtmlSimpleFloat.prototype.destroy = function() {
  AdfDhtmlDialogManager.getInstance().unregisterDialog(this);
  var page = AdfPage.PAGE;
  if(this._modal) {
    page.getModalityManager().popModal(this.getElement())
  }
  if(this._repositionable) {
    this._repositionable.destroy();
    delete this._repositionable
  }
  AdfDhtmlSimpleFloat.superclass.destroy.call(this)
};
AdfDhtmlSimpleFloat.prototype._getContainedComponentPeer = function() {
  var containedPeer = null;
  if(this._containedComponentId != null) {
    var containedComponent = AdfPage.PAGE.findComponent(this._containedComponentId);
    if(containedComponent != null) {
      containedPeer = containedComponent.getPeer();
      containedPeer.bind(containedComponent)
    }
  }
  return containedPeer
};
AdfDhtmlSimpleFloat.prototype._getContainedComponentDomElement = function() {
  var containedPeer = this._getContainedComponentPeer();
  if(containedPeer != null) {
    return containedPeer.getDomElement()
  }
  return null
};
AdfDhtmlSimpleFloat.prototype._dragStartHandler = function() {
  var containedComponentDomElement = this._getContainedComponentDomElement();
  AdfDomUtils.addCSSClassName(containedComponentDomElement, AdfDhtmlSimpleFloat._DRAG_STYLECLASS);
  if(AdfDhtmlShadowDecorator.hasShadowDecorator(this.getShadowAnchor())) {
    AdfDhtmlShadowDecorator.showShadowDecorator(this.getShadowAnchor(), false)
  }
  this._isDragging = true;
  if(this.getAlignElement()) {
    this.setAlignElement(null);
    this.Position(AdfRichPopup.ALIGN_OVERLAP)
  }
};
AdfDhtmlSimpleFloat.prototype._dragEndHandler = function() {
  var containedComponentDomElement = this._getContainedComponentDomElement();
  AdfDomUtils.removeCSSClassName(containedComponentDomElement, AdfDhtmlSimpleFloat._DRAG_STYLECLASS);
  if(AdfDhtmlShadowDecorator.hasShadowDecorator(this.getShadowAnchor())) {
    AdfDhtmlShadowDecorator.showShadowDecorator(this.getShadowAnchor(), true)
  }
  delete this._isDragging;
  this.setPosition(this.getTop(), this.getLeft())
};
AdfDhtmlSimpleFloat.prototype.handleActivate = function(focusOnFirstElement) {
  var mgr = AdfDhtmlDialogManager.getInstance();
  if(mgr.getActiveDialog() == this) {
    return false
  }
  if(mgr.activateDialog(this)) {
    if(focusOnFirstElement) {
      this.FocusOnFirstElement();
      return true
    }
    return true
  }
  return false
};
AdfDhtmlSimpleFloat.prototype.isAnimating = function() {
  if(this._isDragging) {
    return true
  }else {
    return AdfDhtmlSimpleFloat.superclass.isAnimating.call(this)
  }
};
AdfDhtmlSimpleFloat.prototype.setDragging = function(dragging) {
  this._isDragging = dragging
};
AdfDhtmlSimpleFloat.prototype.setShadowVisibility = function(visible) {
  var shadowAnchor = this.getShadowAnchor();
  if(visible) {
    if(!AdfDhtmlShadowDecorator.hasShadowDecorator(shadowAnchor)) {
      AdfDhtmlShadowDecorator.createShadowDecorator(shadowAnchor, this.getElement().parentNode)
    }
  }else {
    if(AdfDhtmlShadowDecorator.hasShadowDecorator(shadowAnchor)) {
      AdfDhtmlShadowDecorator.removeShadowDecorator(this.getShadowAnchor())
    }
  }
};
AdfDhtmlSimpleFloat.prototype.getAlignPosition = function() {
  if(this.getAlignElement()) {
    return null
  }
  var agent = AdfAgent.AGENT;
  var isRTL = AdfPage.PAGE.getLocaleContext().isRightToLeft();
  var windowHeight = agent.getWindowHeight();
  var windowWidth = agent.getWindowWidth();
  var docScrollTop = agent.getBrowserViewportScrollTop();
  var docScrollLeft = agent.getBrowserViewportScrollLeft();
  if(docScrollTop > 0 && agent.getPlatform() == AdfAgent.GECKO_PLATFORM) {
    windowHeight = Math.min(windowHeight, agent.getDomDocument().body.clientHeight)
  }
  var w = this.getWidth();
  var h = this.getHeight();
  var topPercentage = this._topPercentage;
  var leftPercentage = this._leftPercentage;
  if(!leftPercentage) {
    leftPercentage = 0.5
  }
  if(!topPercentage) {
    topPercentage = 0.5
  }
  var dir = isRTL ? -1 : 1;
  var top = Math.max(0, Math.round(windowHeight * topPercentage - h / 2)) + docScrollTop;
  var left = Math.max(0, Math.round(windowWidth * leftPercentage - dir * (w / 2))) + dir * docScrollLeft;
  var ydelta = windowHeight + docScrollTop - (top + h);
  if(ydelta < 0) {
    top = Math.max(docScrollTop, top + ydelta)
  }
  var xdelta = windowWidth + docScrollLeft - (left + dir * w);
  if(xdelta < 0) {
    left = Math.max(docScrollLeft, left + xdelta)
  }
  var pos = {y:top, x:left};
  this.setAlignPosition(pos);
  return pos
};
AdfDhtmlSimpleFloat.prototype.setPosition = function(positionTop, positionLeft) {
  if(this.getAlignElement()) {
    AdfDhtmlSimpleFloat.superclass.setPosition.call(this, positionTop, positionLeft);
    return
  }
  if(!this.isAnimating()) {
    var popupId = this.getPopupClientId();
    AdfAssert.assertString(popupId);
    var popup = AdfPage.PAGE.findComponent(popupId);
    if(popup && popup instanceof AdfRichPopup) {
      var hints = {};
      hints[AdfDhtmlPopupHints.LEFT_POSITION] = this._leftPercentage;
      hints[AdfDhtmlPopupHints.TOP_POSITION] = this._topPercentage;
      hints[AdfRichPopup.HINT_ALIGN] = AdfRichPopup.ALIGN_OVERLAP;
      hints[AdfRichPopup.HINT_ALIGN_ID] = "";
      popup.getPeer().syncPrivateProperties(popup, hints, true)
    }
    AdfDhtmlSimpleFloat.superclass.setPosition.call(this, positionTop, positionLeft);
    return
  }
  var agent = AdfAgent.AGENT;
  var windowHeight = agent.getWindowHeight();
  var windowWidth = agent.getWindowWidth();
  var docScrollTop = agent.getBrowserViewportScrollTop();
  var docScrollLeft = agent.getBrowserViewportScrollLeft();
  if(docScrollTop > 0 && agent.getPlatform() == AdfAgent.GECKO_PLATFORM) {
    windowHeight = Math.min(windowHeight, agent.getDomDocument().body.clientHeight)
  }
  var thisHeight = this.getHeight();
  var thisWidth = this.getWidth();
  var topPercentage = 0;
  if(windowHeight > thisHeight) {
    topPercentage = (positionTop - docScrollTop + thisHeight / 2) / windowHeight
  }
  var leftPercentage = 0;
  if(windowWidth > thisWidth) {
    leftPercentage = (positionLeft - docScrollLeft + thisWidth / 2) / windowWidth
  }
  if(!isNaN(topPercentage) && !isNaN(leftPercentage) && topPercentage < 1 && leftPercentage < 1) {
    var top = topPercentage == 0 ? docScrollTop : positionTop;
    var left = leftPercentage == 0 ? docScrollLeft : positionLeft;
    this._topPercentage = topPercentage;
    this._leftPercentage = leftPercentage;
    AdfDhtmlSimpleFloat.superclass.setPosition.call(this, top, left)
  }
};
AdfDhtmlSimpleFloat.prototype.getFirstTabStop = function() {
  return this.GetFocusContent()
};
