AdfRichUIPeer.createPeerClass(AdfDhtmlSelectOneListbasePeer, "AdfDhtmlSelectOneChoicePeer");
AdfDhtmlSelectOneChoicePeer.InitSubclass = function() {
  AdfRichUIPeer.addComponentPropertyGetters(this, AdfUIEditableValue.SUBMITTED_VALUE, AdfUISelectOne.SELECT_ITEMS, AdfRichSelectOneChoice.LABEL);
  AdfRichUIPeer.addComponentPropertyChanges(this, AdfRichSelectOneChoice.LABEL, AdfRichSelectOneChoice.DISABLED);
  AdfRichUIPeer.addComponentEventHandlers(this, AdfUIInputEvent.CLICK_EVENT_TYPE, AdfUIInputEvent.MOUSE_DOWN_EVENT_TYPE, AdfUIInputEvent.KEY_DOWN_EVENT_TYPE, AdfUIInputEvent.KEY_PRESS_EVENT_TYPE);
  var cap = AdfAgent.AGENT.getCapabilities();
  if(cap[AdfAgent.CAP_TOUCH_SCREEN] == AdfAgent.CAP_TOUCH_SCREEN_NONE) {
    AdfRichUIPeer.addComponentEventHandlers(this, AdfUIInputEvent.MOUSE_IN_EVENT_TYPE, AdfUIInputEvent.MOUSE_OUT_EVENT_TYPE)
  }
  this._TEXT_ID = "content";
  this._COMPACT = "compact";
  this._DROPDOWN_ID = "drop";
  this._POPUP_ID = "pop";
  this._POPUP_WRAPPER_ID = "popWrap";
  this._SPACER_ID = "sp";
  this._POPUP_PANEL_ID = "_afrSelectOnePopupPanel";
  this._HIGHLIGHTED_STYLE_CLASS = "p_AFHighlighted";
  this._TEMP_OPTION_KEY = "_adfTmpOpt"
};
AdfDhtmlSelectOneChoicePeer.prototype.needsFocusTargetStyleClass = function() {
  return true
};
AdfDhtmlSelectOneChoicePeer.prototype.LazyInitialize = function(component, domElement) {
  AdfDhtmlSelectOneChoicePeer.superclass.LazyInitialize.call(this, component, domElement);
  var domNode = AdfDhtmlEditableValuePeer.getContentNode(component, domElement);
  if(domNode) {
    if(!this._isCompact(component)) {
      AdfRichUIPeer.addEventHandlerToDomInstance(AdfDhtmlSelectOneChoicePeer, domNode, AdfDhtmlLookAndFeel.CHANGE_EVENT_TYPE);
      var options = domNode.options;
      if(options) {
        var length = options.length;
        for(i = 0;i < length;i++) {
          if(options[i].title == null || options[i].title == "") {
            options[i].title = options[i].text
          }
        }
      }
    }
  }
};
AdfDhtmlSelectOneChoicePeer.prototype.HandleComponentFocus = function(componentEvent) {
  AdfDhtmlSelectOneChoicePeer.superclass.HandleComponentFocus.call(this, componentEvent);
  var agent = AdfAgent.AGENT;
  var platform = agent.getPlatform();
  if(platform != AdfAgent.IE_PLATFORM) {
    return
  }
  var component = this.getComponent();
  var domElement = this.getDomElement();
  var domNode = AdfDhtmlEditableValuePeer.getContentNode(component, domElement);
  if(domNode) {
    if("true" != domNode.getAttribute("data-afr-init")) {
      if(domNode == AdfPage.PAGE.getActiveDomElement()) {
        if(agent.getVersion() == 9 || agent.getVersion() == 10) {
          domNode.blur()
        }
        AdfFocusUtils.focusElementDelayed(domNode, 1)
      }
      domNode.setAttribute("data-afr-init", true)
    }else {
      domNode.removeAttribute("data-afr-init")
    }
  }
};
AdfDhtmlSelectOneChoicePeer.prototype.HandleComponentMouseDown = function(componentEvent) {
  if(componentEvent.getEventPhase() == AdfBaseEvent.AT_TARGET_PHASE) {
    var component = componentEvent.getSource();
    if(this._isCompact(component) && !component.getDisabled()) {
      var nativeEvent = componentEvent.getNativeEvent();
      var eventTarget = AdfAgent.AGENT.getEventTarget(nativeEvent);
      var domElement = AdfRichUIPeer.getDomElementForComponent(component);
      if(domElement == eventTarget || AdfDomUtils.isAncestor(domElement, eventTarget)) {
        if(!this.isPopupVisible(component, AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID)) {
          this._showPopupPanel(component)
        }else {
          this.hidePopup(component, AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID)
        }
        this._mouseDownCalled = true
      }
      AdfFocusUtils.focusElement(this._getFocusElement(component))
    }
  }
};
AdfDhtmlSelectOneChoicePeer.prototype.HandleComponentClick = function(componentEvent) {
  if(componentEvent.getEventPhase() == AdfBaseEvent.AT_TARGET_PHASE) {
    AdfDhtmlSelectOneChoicePeer.superclass.HandleComponentClick.call(this, componentEvent);
    var component = componentEvent.getSource();
    if(this._isCompact(component)) {
      var target = componentEvent.getNativeEventTarget();
      if(this.IsItemEnabled(target)) {
        var newValue = target.getAttribute(AdfDhtmlSelectOneListbasePeer._ITEM_VALUE_EXPANDO);
        AdfDomUtils.removeCSSClassName(target, AdfDhtmlSelectOneChoicePeer._HIGHLIGHTED_STYLE_CLASS);
        var domElement = this.getDomElement();
        this.SetDisplayValue(component, domElement, newValue);
        this.Validate(component, newValue);
        this._returnToDropDown(component)
      }else {
        if(!this._mouseDownCalled && !this._closingPopup) {
          if(AdfAgent.IE_PLATFORM == AdfAgent.AGENT.getPlatform()) {
            this._showPopupPanel(component)
          }
        }
      }
      this._mouseDownCalled = false;
      this._closingPopup = false
    }
  }
};
AdfDhtmlSelectOneChoicePeer.prototype.HandleComponentKeyUp = function(componentEvent) {
  if(AdfBaseEvent.AT_TARGET_PHASE == componentEvent.getEventPhase() && AdfAgent.IE_PLATFORM == AdfAgent.AGENT.getPlatform() && AdfKeyStroke.ENTER_KEY == AdfAgent.AGENT.getKeyCode(componentEvent.getNativeEvent())) {
    var component = componentEvent.getSource();
    componentEvent.cancel();
    AdfDhtmlEditableValuePeer.getContentNode(component).blur();
    AdfFocusUtils.focusElement(this._getFocusElement(component))
  }
};
AdfDhtmlSelectOneChoicePeer.prototype.HandleComponentKeyPress = function(componentEvent) {
  this.StopArrowKeyBubbling(componentEvent)
};
AdfDhtmlSelectOneChoicePeer.prototype.HandleComponentKeyDown = function(componentEvent) {
  this.StopArrowKeyBubbling(componentEvent);
  if(componentEvent.getEventPhase() == AdfBaseEvent.AT_TARGET_PHASE) {
    var component = componentEvent.getSource();
    if(this._isCompact(component) && !component.getDisabled()) {
      var eventTarget = componentEvent.getNativeEventTarget();
      var evt = componentEvent.getNativeEvent();
      var keyCode = AdfAgent.AGENT.getKeyCode(evt);
      var domElement = this.getDomElement();
      var curValue = this.GetSubmittedValue(component, domElement);
      var oldSelectElement = this.FindItemElementWithValue(component, curValue);
      switch(keyCode) {
        case AdfKeyStroke.ESC_KEY:
          componentEvent.cancel();
          this._returnToDropDown(component);
          break;
        case AdfKeyStroke.ENTER_KEY:
          if(this.isPopupVisible(component, AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID)) {
            var contentNode = AdfDhtmlEditableValuePeer.getContentNode(component, domElement);
            var oldValue = contentNode.getAttribute(AdfDhtmlSelectOneListbasePeer._ITEM_VALUE_EXPANDO);
            if(oldValue != null) {
              contentNode.removeAttribute(AdfDhtmlSelectOneListbasePeer._ITEM_VALUE_EXPANDO);
              var curValue = this.GetSubmittedValue(component, domElement);
              if(curValue != oldValue) {
                this.Validate(component, curValue)
              }
            }
            if(AdfAgent.IE_PLATFORM == AdfAgent.AGENT.getPlatform()) {
              this._closingPopup = true
            }
            this._returnToDropDown(component);
            AdfFocusUtils.focusElement(this._getFocusElement(component))
          }else {
            if(keyCode == AdfKeyStroke.ENTER_KEY && !this.isPopupVisible(component, AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID)) {
              this._showPopupPanel(component)
            }
          }
          break;
        case AdfKeyStroke.TAB_KEY:
          if(this.isPopupVisible(component, AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID)) {
            this._returnToDropDown(component)
          }
          break;
        case AdfKeyStroke.ARROWDOWN_KEY:
          if(evt.altKey) {
            this._showPopupPanel(component);
            break
          }
        ;
        case AdfKeyStroke.ARROWUP_KEY:
          if(eventTarget.tagName == "A" && !this.isPopupVisible(component, AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID)) {
            this._showPopupPanel(component);
            break
          }
          var selectElement;
          if(keyCode == AdfKeyStroke.ARROWUP_KEY) {
            selectElement = this.GetPreviousEnabledItem(oldSelectElement)
          }else {
            selectElement = this.GetNextEnabledItem(oldSelectElement)
          }
          if(!selectElement) {
            selectElement = this.GetFirstEnabledItem(component)
          }
          var popupIsVisible = this.isPopupVisible(component, AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID);
          if(selectElement != oldSelectElement) {
            var newValue = "" + selectElement.getAttribute(AdfDhtmlSelectOneListbasePeer._ITEM_VALUE_EXPANDO);
            if(popupIsVisible) {
              var contentNode = AdfDhtmlEditableValuePeer.getContentNode(component, domElement);
              if(contentNode.getAttribute(AdfDhtmlSelectOneListbasePeer._ITEM_VALUE_EXPANDO) == null) {
                contentNode.setAttribute(AdfDhtmlSelectOneListbasePeer._ITEM_VALUE_EXPANDO, "" + curValue)
              }
              this.SetDisplayValue(component, domElement, newValue)
            }else {
              this.Validate(component, newValue)
            }
          }
          if(popupIsVisible) {
            componentEvent.cancel()
          }
          break
      }
    }
    if(AdfAgent.IE_PLATFORM == AdfAgent.AGENT.getPlatform() && AdfAgent.AGENT.getVersion() <= 8 && AdfKeyStroke.ENTER_KEY == AdfAgent.AGENT.getKeyCode(componentEvent.getNativeEvent())) {
      componentEvent.Event.returnValue = false
    }
  }
};
AdfDhtmlSelectOneChoicePeer.prototype.HandleComponentMouseOver = function(componentEvent) {
  if(componentEvent.getEventPhase() == AdfBaseEvent.AT_TARGET_PHASE) {
    var component = componentEvent.getSource();
    var target = componentEvent.getNativeEventTarget();
    if(this.IsItemEnabled(target)) {
      if(!AdfDomUtils.containsCSSClassName(target, AdfDhtmlSelectOneChoicePeer._HIGHLIGHTED_STYLE_CLASS)) {
        AdfDomUtils.addCSSClassName(target, AdfDhtmlSelectOneChoicePeer._HIGHLIGHTED_STYLE_CLASS)
      }
    }
  }
};
AdfDhtmlSelectOneChoicePeer.prototype.HandleComponentMouseOut = function(componentEvent) {
  if(componentEvent.getEventPhase() == AdfBaseEvent.AT_TARGET_PHASE) {
    var component = componentEvent.getSource();
    var target = componentEvent.getNativeEventTarget();
    if(this.IsItemEnabled(target)) {
      AdfDomUtils.removeCSSClassName(target, AdfDhtmlSelectOneChoicePeer._HIGHLIGHTED_STYLE_CLASS)
    }
  }
};
AdfDhtmlSelectOneChoicePeer.prototype.HandleDomChange = function(component, domEvent) {
  var domElement = this.getDomElement();
  this.Validate(component, this.GetSubmittedValue(component, domElement))
};
AdfDhtmlSelectOneChoicePeer.prototype.PopupClosed = function(component, contentDom, popupId) {
  if(popupId == AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID) {
    var popupWrapperId = AdfRichUIPeer.CreateSubId(component.getClientId(), AdfDhtmlSelectOneChoicePeer._POPUP_WRAPPER_ID);
    var parentDom = AdfAgent.AGENT.getElementById(popupWrapperId);
    parentDom.appendChild(contentDom);
    var domElement = AdfRichUIPeer.getDomElementForComponent(component);
    var contentNode = AdfDhtmlEditableValuePeer.getContentNode(component, domElement);
    var oldValue = contentNode.getAttribute(AdfDhtmlSelectOneListbasePeer._ITEM_VALUE_EXPANDO);
    if(oldValue != null) {
      contentNode.removeAttribute(AdfDhtmlSelectOneListbasePeer._ITEM_VALUE_EXPANDO);
      this.SetDisplayValue(component, domElement, oldValue)
    }
    AdfFocusUtils.focusElement(this._getFocusElement(component))
  }
};
AdfDhtmlSelectOneChoicePeer.prototype.VetoShowNoteWindow = function(component) {
  if(this._isCompact(component)) {
    if(this.isPopupVisible(component, AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID)) {
      return true
    }
  }
  return AdfDhtmlSelectOneChoicePeer.superclass.VetoShowNoteWindow.call(this)
};
AdfDhtmlSelectOneChoicePeer.prototype.GetNoteWindowAlignmentNode = function(component, rootNode) {
  return this._getFocusElement(component)
};
AdfDhtmlSelectOneChoicePeer.prototype.GetComponentMode = function(component) {
  return component.getMode()
};
AdfDhtmlSelectOneChoicePeer.prototype.SetDisplayValue = function(component, domElement, newValue) {
  var contentNode = AdfDhtmlEditableValuePeer.getContentNode(component, domElement);
  if(contentNode == null) {
    return
  }
  var readOnly = component.getReadOnly();
  AdfAssert.assertString(newValue);
  if(!readOnly) {
    var newSelectedItem = this.FindItemElementWithValue(component, newValue);
    if(this._isCompact(component)) {
      var curValue = this.GetSubmittedValue(component, domElement);
      var oldSelectElement = this.FindItemElementWithValue(component, curValue);
      var textValue;
      this.SelectItemElement(component, newSelectedItem, oldSelectElement);
      if(newSelectedItem == null) {
        this.AddEmptyOption(component, domElement)
      }
    }else {
      if(newSelectedItem) {
        var isRemovableItem = AdfAgent.AGENT.getAttribute(newSelectedItem, AdfDhtmlSelectOneChoicePeer._TEMP_OPTION_KEY);
        if(!isRemovableItem) {
          var firstOption = AdfDomUtils.getFirstDescendentElement(contentNode, "OPTION");
          isRemovableItem = AdfAgent.AGENT.getAttribute(firstOption, AdfDhtmlSelectOneChoicePeer._TEMP_OPTION_KEY);
          if(isRemovableItem) {
            contentNode.removeChild(firstOption)
          }
        }
        contentNode.title = newSelectedItem.title
      }
    }
    contentNode.value = newValue
  }
};
AdfDhtmlSelectOneChoicePeer.prototype.AddEmptyOption = function(component, domElement) {
  var clientId = component.getClientId();
  var popupId = AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlSelectOneChoicePeer._POPUP_ID);
  var popupElement = AdfAgent.AGENT.getElementById(popupId);
  var table = popupElement.firstChild;
  var newTr = table.insertRow(0);
  var newTd = selectedItem.cloneNode(true);
  var unselectedLabel = component.getUnselectedLabel();
  if(unselectedLabel == null) {
    unselectedLabel = ""
  }
  newTd.setAttribute(AdfDhtmlSelectOneListbasePeer._ITEM_VALUE_EXPANDO, "");
  newTd.firstChild.nodeValue = unselectedLabel;
  newTr.appendChild(newTd);
  AdfAgent.AGENT.elementsAdded(newTd)
};
AdfDhtmlSelectOneChoicePeer.prototype.GetItemElements = function(component) {
  if(this._isCompact(component)) {
    return AdfDhtmlSelectOneChoicePeer.superclass.GetItemElements.call(this, component)
  }
  var domElement = this.getDomElement();
  var domNode = AdfDhtmlEditableValuePeer.getContentNode(component, domElement);
  if(domNode == null) {
    return null
  }
  return domNode.options
};
AdfDhtmlSelectOneChoicePeer.prototype.GetComponentSelectItems = function(component, domElement) {
  if(this._isCompact(component)) {
    return AdfDhtmlSelectOneChoicePeer.superclass.GetComponentSelectItems.call(this, component, domElement)
  }
  return AdfDhtmlSelectOnePeer.GetSelectItemsFromOptions(component, domElement)
};
AdfDhtmlSelectOneChoicePeer.prototype.FindItemElementWithValue = function(component, itemValue) {
  if(this._isCompact(component)) {
    return AdfDhtmlSelectOneChoicePeer.superclass.FindItemElementWithValue.call(this, component, itemValue)
  }
  var domElement = this.getDomElement();
  var domNode = AdfDhtmlEditableValuePeer.getContentNode(component, domElement);
  if(domNode == null) {
    return null
  }
  var selectItems = new Array;
  var i;
  var options = domNode.options;
  var length = options.length;
  for(i = 0;i < length;i++) {
    if(options[i].value == itemValue) {
      return options[i]
    }
  }
  return null
};
AdfDhtmlSelectOneChoicePeer.prototype.GetInlineEditor = function(event) {
  return AdfDhtmlSimpleLabelEditor.getInlineEditor()
};
AdfDhtmlSelectOneChoicePeer.prototype.ComponentDisabledChanged = function(component, domElement, newValue, oldValue) {
  var domNode = AdfDhtmlEditableValuePeer.getContentNode(component, domElement);
  if(newValue == true) {
    AdfDomUtils.addCSSClassName(domElement, AdfRichUIPeer.DISABLED_STYLECLASS);
    domNode.setAttribute("disabled", "true")
  }else {
    AdfDomUtils.removeCSSClassName(domElement, AdfRichUIPeer.DISABLED_STYLECLASS);
    domNode.removeAttribute("disabled")
  }
};
AdfDhtmlSelectOneChoicePeer.prototype._returnToDropDown = function(component) {
  var clientId = component.getClientId();
  var popupId = AdfRichUIPeer.CreateSubId(component.getClientId(), AdfDhtmlSelectOneChoicePeer._POPUP_ID);
  var popupNode = AdfAgent.AGENT.getElementById(popupId);
  this.hidePopup(component, AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID);
  AdfFocusUtils.focusElement(this._getFocusElement(component))
};
AdfDhtmlSelectOneChoicePeer.prototype._showPopupPanel = function(component) {
  AdfObject.ensureClassInitialization(AdfRichPopup);
  var clientId = component.getClientId();
  var spacerId = AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlSelectOneChoicePeer._SPACER_ID);
  var spacerNode = AdfAgent.AGENT.getElementById(spacerId);
  var popupContentId = AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlSelectOneChoicePeer._POPUP_ID);
  var contentDom = AdfAgent.AGENT.getElementById(popupContentId);
  contentDom.parentNode.removeChild(contentDom);
  var popupHints = {};
  popupHints[AdfRichPopup.HINT_ALIGN] = AdfRichPopup.ALIGN_AFTER_START;
  if(this._isCompact(component)) {
    popupHints[AdfDhtmlPopupHints.FOCUS] = true;
    popupHints[AdfRichPopup.HINT_ALIGN_ID] = AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlSelectOneChoicePeer._DROPDOWN_ID)
  }else {
    popupHints[AdfDhtmlPopupHints.FOCUS] = false;
    popupHints[AdfRichPopup.HINT_ALIGN_ID] = AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlSelectOneChoicePeer._TEXT_ID)
  }
  this.showPopup(component, contentDom, popupHints, AdfDhtmlSelectOneChoicePeer._POPUP_PANEL_ID)
};
AdfDhtmlSelectOneChoicePeer.prototype._isCompact = function(component) {
  var mode = this.GetComponentMode(component);
  return mode == AdfDhtmlSelectOneChoicePeer._COMPACT
};
AdfDhtmlSelectOneChoicePeer.prototype._getFocusElement = function(component) {
  var elementId;
  if(this._isCompact(component)) {
    elementId = AdfRichUIPeer.CreateSubId(component.getClientId(), AdfDhtmlSelectOneChoicePeer._DROPDOWN_ID)
  }else {
    elementId = AdfRichUIPeer.CreateSubId(component.getClientId(), AdfDhtmlSelectOneChoicePeer._TEXT_ID)
  }
  return AdfAgent.AGENT.getElementById(elementId)
};
AdfDhtmlSelectOneChoicePeer.prototype.GetItemElementsParent = function(component) {
  var clientId = component.getClientId();
  if(this._isCompact(component)) {
    return AdfAgent.AGENT.getElementById(AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlSelectOneChoicePeer._POPUP_ID))
  }else {
    return AdfAgent.AGENT.getElementById(AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlSelectOneChoicePeer._TEXT_ID))
  }
};
