function AdfAutoSuggestBehaviorImpl(a,b,d,e){this.Init(a,b,d,e)}
AdfAutoSuggestBehaviorImpl.InitClass=function(){this._POPUP_PANEL_ID="_afrAutoSuggest";this._ITEM_VALUE_ATTR="data-afr-value";this._ITEM_LABEL_ATTR="data-afr-label";this._SUGGEST_ITEMS_ID="_afrautosuggestpopup";this._SUGGEST_ITEM_ID="su";this._SMART_ITEM_ID="sm";this._POPUP_CONTAINER_DIV_ID="_afrautosuggestcontainer";this._MORE_LINK_ID="_afrautosuggestmorelink";this._BUSY_DIV_ID="_afrautosuggestbusydiv";this._POPUP_CONTAINER_STYLE="AFAutoSuggestItemsContainer";this._SUGGESTED_ITEM_STYLE="AFAutoSuggestItem";
this._MORE_LINK_STYLE="AFAutoSuggestMoreLink";this.SUGGEST_BUSY_STYLE="AFAutoSuggestBusyStyle"};AdfObject.createSubclass(AdfAutoSuggestBehaviorImpl,AdfAutoSuggestBehavior);AdfAutoSuggestBehaviorImpl.prototype.Init=function(a,b,d,e){AdfAutoSuggestBehaviorImpl.superclass.Init.call(this);this._isSmartListEnabled=a;this._minChars=b;this._maxSuggestedItems=d;this._isLOVComponent=e};AdfAutoSuggestBehaviorImpl.prototype.initialize=function(a){AdfPage.PAGE.scheduleTimer(this,this._initialize,a,0)};
AdfAutoSuggestBehaviorImpl.prototype._initialize=function(a){if(!AdfPage.PAGE.isAttachmentMode()){a.addEventListener(AdfUIInputEvent.KEY_UP_EVENT_TYPE,this._fireKeyUp,this);a.addEventListener(AdfUIInputEvent.KEY_DOWN_EVENT_TYPE,this._fireKeyDown,this);a.addEventListener(AdfUIInputEvent.CLICK_EVENT_TYPE,this._fireClick,this);a.addEventListener(AdfUIInputEvent.MOUSE_DOWN_EVENT_TYPE,this._fireMouseDown,this);a.addEventListener(AdfUIInputEvent.BLUR_EVENT_TYPE,this._fireBlur,this);a.addEventListener(AdfUIInputEvent.FOCUS_EVENT_TYPE,
this._fireFocus,this);this._autoCompleteDisabled=!1;this._requestId=0;this._itemsCache={};this._clickedInSuggestitems=!1;var b=a.getClientId();a=AdfDhtmlEditableValuePeer.getContentNode(a);a.setAttribute("role","combobox");a.setAttribute("aria-autocomplete","list");a.setAttribute("aria-owns",AdfRichUIPeer.createSubId(b,AdfAutoSuggestBehaviorImpl._SUGGEST_ITEMS_ID));a.setAttribute("aria-expanded","false")}};AdfAutoSuggestBehaviorImpl.isPopupVisible=function(a,b){return b.isPopupVisible(a,AdfAutoSuggestBehaviorImpl._POPUP_PANEL_ID)};
AdfAutoSuggestBehaviorImpl.showAutoSuggestPopup=function(a,b,d,e,f,g,h){var k=AdfPage.PAGE.findComponent(a);k&&(e&&1==e?k._smartList=d:h==k._requestId&&(e=k.getBehaviors(AdfAutoSuggestBehavior))&&(e._cacheSuggestedItems(b,d),e._showPopup(k,b,a,d,!1,f,g)))};
AdfAutoSuggestBehaviorImpl.prototype.getSuggestedItems=function(a){var b=AdfDhtmlEditableValuePeer.getContentNode(a).value;if(0!=b.trim().length){var d=[];a=this._filterSmartList(a._smartList,b);AdfAutoSuggestBehaviorImpl._convertToSelectItems(a,d);b=this._getSuggestedItemsFromCache(b);AdfAutoSuggestBehaviorImpl._convertToSelectItems(b,d);return d}};
AdfAutoSuggestBehaviorImpl._addBusyDiv=function(a,b,d,e){var f=a.createElement("div");d=AdfRichUIPeer.createSubId(d,AdfAutoSuggestBehaviorImpl._BUSY_DIV_ID);f.setAttribute("id",d);e=e.getStyleClass(AdfAutoSuggestBehaviorImpl.SUGGEST_BUSY_STYLE);AdfDomUtils.addCSSClassName(f,e);liElement=a.createElement("li");liElement.appendChild(f);AdfAgent.AGENT.elementsAdded(f);b.appendChild(liElement)};
AdfAutoSuggestBehaviorImpl._addMoreLink=function(a,b,d,e,f,g,h){if(!e&&f&&0<=f){AdfAutoSuggestBehaviorImpl._addSeparator(a,b);e=a.createElement("a");e.setAttribute("href","#");var k=AdfPage.PAGE.getDomWindow();f=AdfAgent.AGENT;k.AdfSafariMobileAgent&&f instanceof AdfSafariMobileAgent?e.setAttribute("onclick","void(0); return false;"):e.setAttribute("onClick","return false");d=AdfRichUIPeer.createSubId(d,AdfAutoSuggestBehaviorImpl._MORE_LINK_ID);e.setAttribute("id",d);e.setAttribute(AdfAutoSuggestBehaviorImpl._ITEM_VALUE_ATTR,
g);e.setAttribute("role","option");g=a.createTextNode(h.getTranslatedString("AFAutoSuggestMoreLinkLabel"));e.appendChild(g);AdfDomUtils.addCSSClassName(e,AdfAutoSuggestBehaviorImpl._MORE_LINK_STYLE);liElement=a.createElement("li");liElement.appendChild(e);f.elementsAdded(e);b.appendChild(liElement)}};
AdfAutoSuggestBehaviorImpl._addSuggestItems=function(a,b,d,e,f,g){var h=AdfPage.PAGE.getDomWindow(),k=AdfAgent.AGENT,h=h.AdfSafariMobileAgent&&k instanceof AdfSafariMobileAgent;g=g.getStyleClass(AdfAutoSuggestBehaviorImpl._SUGGESTED_ITEM_STYLE);var l=0;d=AdfRichUIPeer.createSubId(d,f?AdfAutoSuggestBehaviorImpl._SMART_ITEM_ID:AdfAutoSuggestBehaviorImpl._SUGGEST_ITEM_ID);for(var m in e){f=a.createElement("li");f.setAttribute("role","option");f.setAttribute("id",d+l++);f.setAttribute(AdfAutoSuggestBehaviorImpl._ITEM_VALUE_ATTR,
e[m]);h&&f.setAttribute("onclick","void(0)");var n=m;f.setAttribute(AdfAutoSuggestBehaviorImpl._ITEM_LABEL_ATTR,n);n=a.createTextNode(n);f.appendChild(n);AdfDomUtils.addCSSClassName(f,g);b.appendChild(f);k.elementsAdded(f)}};AdfAutoSuggestBehaviorImpl._addSeparator=function(a,b){var d=a.createElement("li"),e=a.createElement("hr");d.appendChild(e);b.appendChild(d)};
AdfAutoSuggestBehaviorImpl._adjustForScrollBars=function(a){var b=AdfAgent.AGENT.getComputedStyle(a),b=parseInt(b.maxHeight,10),d=a.scrollHeight,e=AdfPage.PAGE.getLocaleContext().isRightToLeft();a=AdfDomUtils.getChildElements(a);for(var f=0;f<a.length;f++){var g=a[f];d>b?e?g.style.paddingLeft="20px":g.style.paddingRight="20px":e?g.style.paddingLeft="":g.style.paddingRight=""}};
AdfAutoSuggestBehaviorImpl._convertToSelectItems=function(a,b){for(var d in a)if(a.hasOwnProperty(d)){var e=new AdfSelectItem(a[d],d);b.push(e)}};
AdfAutoSuggestBehaviorImpl._createPopupContent=function(a,b,d,e){var f=AdfRichUIPeer.createSubId(b,AdfAutoSuggestBehaviorImpl._SUGGEST_ITEMS_ID);b=AdfRichUIPeer.createSubId(b,AdfAutoSuggestBehaviorImpl._POPUP_CONTAINER_DIV_ID);a=AdfDhtmlEditableValuePeer.getContentNode(a);var g=e.getElementById(b),h=AdfPage.PAGE.getLookAndFeel().getStyleClass(AdfAutoSuggestBehaviorImpl._POPUP_CONTAINER_STYLE);g?g.innerHTML="":(g=d.createElement("div"),g.setAttribute("id",b),g.style.display="none");d=d.createElement("ul");
d.setAttribute("id",f);d.setAttribute("role","listbox");AdfDomUtils.addCSSClassName(d,h);g.appendChild(d);a.parentNode.appendChild(g);e.elementsAdded(g);return d};AdfAutoSuggestBehaviorImpl._isSuggestItemOrMoreLink=function(a){return"option"==a.getAttribute("role")};AdfAutoSuggestBehaviorImpl._updateSelectedStyle=function(a,b){var d=AdfDomUtils.addCSSClassName;b||(d=AdfDomUtils.removeCSSClassName);d(a,AdfRichUIPeer.SELECTED_STYLECLASS)};
AdfAutoSuggestBehaviorImpl.prototype._fireFocus=function(a){a=a.getSource();if(!this._autoCompleteDisabled){if(a&&a instanceof AdfUIEditableValue){var b=a.getPeer();b.bind(a);b.disableBrowserAutoComplete&&b.disableBrowserAutoComplete(a)}this._autoCompleteDisabled=!0}this._isSmartListEnabled&&!a._smartList&&AdfCustomEvent.queue(a,"_autoSuggest",{smartList:!0},!0,!0)};
AdfAutoSuggestBehaviorImpl.prototype._fireMouseDown=function(a){var b=a.getSource(),d=b.getPeer();d.bind(b);if(b&&b instanceof AdfUIEditableValue){var e=a.getNativeEventTarget(),f=e.getAttribute&&e.getAttribute(AdfAutoSuggestBehaviorImpl._ITEM_VALUE_ATTR),g=AdfDhtmlEditableValuePeer.getContentNode(b),h=b.getClientId(),k=AdfRichUIPeer.createSubId(h,AdfAutoSuggestBehaviorImpl._MORE_LINK_ID);if(e.id==k)d.preventNextValueSubmission(),this._clickedInSuggestitems=!0;else if(f&&0<f.length)(e=e.getAttribute(AdfAutoSuggestBehaviorImpl._ITEM_LABEL_ATTR))&&
0<e.length&&b.setProperty("_afrAutoSuggestLabel",e,!1,AdfUIComponent.PROPAGATE_ALWAYS),g.value=f,e=b.getValue(),null==e&&(e=AdfDhtmlInputBasePeer.getLastValue(g)),d.RunValidation(b,a.getNativeEventTarget()),f==e&&AdfValueChangeEvent.queue(b,e,b.getValue(),b.getAutoSubmit()),this._clickedInSuggestitems=!0;else for(a=AdfRichUIPeer.createSubId(h,AdfAutoSuggestBehaviorImpl._SUGGEST_ITEMS_ID),b=AdfRichUIPeer.createSubId(h,AdfAutoSuggestBehaviorImpl._BUSY_DIV_ID);e;){if(e.id==a){this._clickedInSuggestitems=
!0;AdfAgent.AGENT.getPlatform()==AdfAgent.IE_PLATFORM&&d.preventNextValueSubmission();break}else if(e==g||e.id==b)break;e=e.parentNode}}};AdfAutoSuggestBehaviorImpl.prototype._fireBlur=function(a){this._cancelSuggestTimer();a=a.getSource();a.getPeer().bind(a);AdfPage.PAGE.scheduleTimer(this,this._clearCache,null,100);this._cancelSmartListTimer();AdfPage.PAGE.getDataTransferService().getDTSState()==AdfDataTransferService.STATE_BUSY&&(a._requestId=this._requestId++)};
AdfAutoSuggestBehaviorImpl.prototype._fireClick=function(a){var b=a.getSource();if(b&&b instanceof AdfUIEditableValue){var d=b.getPeer();d.bind(b);a=a.getNativeEventTarget();if(AdfAutoSuggestBehaviorImpl.isPopupVisible(b,d)){var e=a.getAttribute(AdfAutoSuggestBehaviorImpl._ITEM_VALUE_ATTR),f=b.getClientId(),f=AdfRichUIPeer.createSubId(f,AdfAutoSuggestBehaviorImpl._MORE_LINK_ID);a.id==f?(e&&0<e.length&&this._isLOVComponent&&AdfLaunchPopupEvent.queue(b,!0),b.focus()):e&&0<e.length&&(this._cancelSmartListTimer(),
d.hidePopup(b,AdfAutoSuggestBehaviorImpl._POPUP_PANEL_ID),b.focus())}}};
AdfAutoSuggestBehaviorImpl.prototype._fireKeyUp=function(a){var b=AdfAgent.AGENT,d=b.getKeyCode(a.getNativeEvent());if(d!=AdfKeyStroke.ARROWLEFT_KEY&&d!=AdfKeyStroke.ARROWRIGHT_KEY){var e=void 0!==this._smartListTimerId;this._cancelSmartListTimer();var f=a.getSource();if(f&&f instanceof AdfUIEditableValue){var g=f.getPeer();g.bind(f);var h=AdfDhtmlEditableValuePeer.getContentNode(f);if(h){var k=h.value;if(0<k.replace(/\s*/,"").length){if(d==AdfKeyStroke.BACKSPACE_KEY||void 0!=this._nodeLength&&k.length!=
this._nodeLength||this._lastValue&&this._lastValue!=k)k=AdfPage.PAGE,this._timerId?k.rescheduleTimer(this._timerId,500):this._timerId=k.scheduleTimer(this,this._autoSuggest,f,500,{isSynchronized:!0})}else 0==k.length&&AdfAutoSuggestBehaviorImpl.isPopupVisible(f,g)&&g.hidePopup(f,AdfAutoSuggestBehaviorImpl._POPUP_PANEL_ID);delete this._nodeLength;delete this._lastValue;k=f.getClientId();switch(d){case AdfKeyStroke.ENTER_KEY:if(AdfAutoSuggestBehaviorImpl.isPopupVisible(f,g)){d=AdfRichUIPeer.createSubId(k,
AdfAutoSuggestBehaviorImpl._MORE_LINK_ID);if((e=this._getCurrentSelectedItemId(h))&&e==d)this._isLOVComponent&&AdfLaunchPopupEvent.queue(f,!0);else{var l;e&&(l=b.getElementById(e));l&&(b=l.getAttribute(AdfAutoSuggestBehaviorImpl._ITEM_LABEL_ATTR))&&0<b.length&&f.setProperty("_afrAutoSuggestLabel",b,!1,AdfUIComponent.PROPAGATE_ALWAYS);b=f.getValue();null==b&&(b=AdfDhtmlInputBasePeer.getLastValue(h));g.RunValidation(f,a.getNativeEventTarget());l&&l.getAttribute(AdfAutoSuggestBehaviorImpl._ITEM_VALUE_ATTR)==
b&&AdfValueChangeEvent.queue(f,b,f.getValue(),f.getAutoSubmit())}g.hidePopup(f,AdfAutoSuggestBehaviorImpl._POPUP_PANEL_ID);a.cancel();a.stopBubbling()}break;case AdfKeyStroke.ARROWDOWN_KEY:case AdfKeyStroke.ARROWUP_KEY:AdfAutoSuggestBehaviorImpl.isPopupVisible(f,g)&&(a=AdfRichUIPeer.createSubId(k,AdfAutoSuggestBehaviorImpl._SUGGEST_ITEMS_ID),a=b.getElementById(a),e&&(f=AdfRichUIPeer.createSubId(k,AdfAutoSuggestBehaviorImpl._BUSY_DIV_ID),f=b.getElementById(f))&&(g=f.parentElement,l=AdfDomUtils.getPreviousElement(g),
a.removeChild(g),b.elementsRemoved(f),a.removeChild(l)),this._selectNewItem(h,a,d==AdfKeyStroke.ARROWDOWN_KEY))}}}}};
AdfAutoSuggestBehaviorImpl.prototype._fireKeyDown=function(a){var b=a.getSource();if(b&&b instanceof AdfUIEditableValue){var d=b.getPeer();d.bind(b);var e=AdfDhtmlEditableValuePeer.getContentNode(b);AdfAgent.AGENT.getKeyCode(a.getNativeEvent())==AdfKeyStroke.ENTER_KEY&&AdfAutoSuggestBehaviorImpl.isPopupVisible(b,d)&&(b=b.getClientId(),a=this._getCurrentSelectedItemId(e),b=AdfRichUIPeer.createSubId(b,AdfAutoSuggestBehaviorImpl._MORE_LINK_ID),a&&a==b&&d.preventNextValueSubmission());this._nodeLength=
e.value.length;this._lastValue=e.value}};AdfAutoSuggestBehaviorImpl.prototype._firePopupClosed=function(a){a=AdfDhtmlEditableValuePeer.getContentNode(a);a.setAttribute("aria-expanded","false");a.removeAttribute("aria-activedescendant")};AdfAutoSuggestBehaviorImpl.prototype._firePopupOpening=function(a){AdfDhtmlEditableValuePeer.getContentNode(a).setAttribute("aria-expanded","true")};AdfAutoSuggestBehaviorImpl.prototype._getCurrentSelectedItemId=function(a){return a.getAttribute("aria-activedescendant")};
AdfAutoSuggestBehaviorImpl.prototype._autoSuggest=function(a){this._timerId=null;var b=a.getPeer();b.bind(a);AdfAutoSuggestBehaviorImpl.isPopupVisible(a,b)&&b.hidePopup(a,AdfAutoSuggestBehaviorImpl._POPUP_PANEL_ID);var b=AdfDhtmlEditableValuePeer.getContentNode(a),d=b.value,e=this._getSuggestedItemsFromCache(d);if(e)this._showPopup(a,d,a.getClientId(),e,!1,this._maxSuggestedItems,this._isLOVComponent);else if(d){e=!1;if(a._smartList){var f=this._filterSmartList(a._smartList,d);(e=!AdfCollections.isEmpty(f))&&
this._showPopup(a,d,a.getClientId(),f,!0,this._maxSuggestedItems,this._isLOVComponent)}d.length<this._minChars||(e?this._smartListTimerId=AdfPage.PAGE.scheduleTimer(this,this._queueAutoSuggestEvent,[a,d,b,this._maxSuggestedItems],2E3,{isSynchronized:!0}):this._queueAutoSuggestEvent([a,d,b,this._maxSuggestedItems]))}};AdfAutoSuggestBehaviorImpl.prototype._cancelSuggestTimer=function(){var a=this._timerId;a&&(AdfPage.PAGE.cancelTimer(a),delete this._timerId)};
AdfAutoSuggestBehaviorImpl.prototype._cancelSmartListTimer=function(){var a=this._smartListTimerId;a&&(AdfPage.PAGE.cancelTimer(a),delete this._smartListTimerId)};
AdfAutoSuggestBehaviorImpl.prototype._queueAutoSuggestEvent=function(a){delete this._smartListTimerId;var b=AdfPage.PAGE.getLookAndFeel();if(a[1]){var d=a[0],e=d.getPeer();e.bind(d);if(!AdfAutoSuggestBehaviorImpl.isPopupVisible(d,e)){var f=d.getClientId(),g=AdfDhtmlEditableValuePeer.getContentNode(d).ownerDocument,h=AdfAutoSuggestBehaviorImpl._createPopupContent(d,f,g,AdfAgent.AGENT);AdfAutoSuggestBehaviorImpl._addBusyDiv(g,h,f,b);this._showDropdown(d,e,f,h)}e=this._requestId++;d._requestId=e;AdfCustomEvent.queue(a[0],
"_autoSuggest",{submittedValue:a[1],emptyText:b.getTranslatedString("AFAutoSuggestEmptyText"),maxSuggestedItems:a[3],requestId:e},!0,!0)}};AdfAutoSuggestBehaviorImpl.prototype._filterSmartList=function(a,b){var d={},e;for(e in a)0==e.indexOf(b)&&(d[e]=a[e]);return d};
AdfAutoSuggestBehaviorImpl.prototype._selectNewItem=function(a,b,d){var e,f,g=this._getCurrentSelectedItemId(a);g?(e=AdfAgent.AGENT.getElementById(g),f=d?AdfDomUtils.getNextElementMatch(e,b,!0,AdfAutoSuggestBehaviorImpl._isSuggestItemOrMoreLink):AdfDomUtils.getPreviousElementMatch(e,b,AdfAutoSuggestBehaviorImpl._isSuggestItemOrMoreLink)):d&&(f=AdfDomUtils.getFirstElementMatch(b,!0,AdfAutoSuggestBehaviorImpl._isSuggestItemOrMoreLink));f&&(e&&AdfAutoSuggestBehaviorImpl._updateSelectedStyle(e,!1),AdfAutoSuggestBehaviorImpl._updateSelectedStyle(f,
!0),a.setAttribute("aria-activedescendant",f.id),f.scrollIntoView(),b=f.getAttribute(AdfAutoSuggestBehaviorImpl._ITEM_VALUE_ATTR))&&(a.value=b)};
AdfAutoSuggestBehaviorImpl.prototype._showPopup=function(a,b,d,e,f,g,h){var k=a.getPeer();k.bind(a);var l=AdfRichUIPeer.createSubId(d,AdfAutoSuggestBehaviorImpl._SUGGEST_ITEMS_ID),m=AdfDhtmlEditableValuePeer.getContentNode(a),n=m.ownerDocument,q=AdfAgent.AGENT,r=AdfPage.PAGE.getLookAndFeel(),t=!e.hasOwnProperty(r.getTranslatedString("AFAutoSuggestEmptyText"));if(AdfAutoSuggestBehaviorImpl.isPopupVisible(a,k)){l=q.getElementById(l);if(a=a=l.lastChild)q.elementsRemoved(a),l.removeChild(a);AdfAutoSuggestBehaviorImpl._addSuggestItems(n,
l,d,e,f,r);t&&h&&AdfAutoSuggestBehaviorImpl._addMoreLink(n,l,d,f,g,b,r)}else l=AdfAutoSuggestBehaviorImpl._createPopupContent(a,d,n,q),AdfAutoSuggestBehaviorImpl._addSuggestItems(n,l,d,e,f,r),1==f&&m.value.length>=this._minChars&&(AdfAutoSuggestBehaviorImpl._addSeparator(n,l),AdfAutoSuggestBehaviorImpl._addBusyDiv(n,l,d,r)),t&&h&&AdfAutoSuggestBehaviorImpl._addMoreLink(n,l,d,f,g,b,r),this._showDropdown(a,k,d,l);AdfAutoSuggestBehaviorImpl._adjustForScrollBars(l)};
AdfAutoSuggestBehaviorImpl.prototype._showDropdown=function(a,b,d,e){AdfObject.ensureClassInitialization(AdfRichPopup);var f={};f[AdfDhtmlPopupHints.TYPE]=AdfDhtmlPopupHints.TYPE_MENU;f[AdfDhtmlPopupHints.AUTODISMISS]=AdfDhtmlPopupHints.AUTODISMISS_MENU;f[AdfDhtmlPopupHints.FOCUS]=!1;f[AdfDhtmlPopupHints.CLOSE_ON_ESCAPE]=!0;f[AdfDhtmlPopupHints.CLOSE_HANDLER]=this.createCallback(this._firePopupClosed);f[AdfDhtmlPopupHints.CLOSE_HANDLER_PARAM]=a;f[AdfDhtmlPopupHints.OPENED_HANDLER]=this.createCallback(this._firePopupOpening);
f[AdfDhtmlPopupHints.OPENED_HANDLER_PARAM]=a;f[AdfRichPopup.HINT_ALIGN]=AdfRichPopup.ALIGN_AFTER_START;f[AdfRichPopup.HINT_LAUNCH_ID]=d;f[AdfRichPopup.HINT_ALIGN_ID]=AdfRichUIPeer.createSubId(d,"content");b.showPopup(a,e,f,AdfAutoSuggestBehaviorImpl._POPUP_PANEL_ID)};AdfAutoSuggestBehaviorImpl.prototype._cacheSuggestedItems=function(a,b){this._itemsCache[a]=b};AdfAutoSuggestBehaviorImpl.prototype._getSuggestedItemsFromCache=function(a){return this._itemsCache[a]};
AdfAutoSuggestBehaviorImpl.prototype._clearSuggestedItemsCache=function(){this._itemsCache={}};AdfAutoSuggestBehaviorImpl.prototype._clearCache=function(){this._clickedInSuggestitems||this._clearSuggestedItemsCache();this._clickedInSuggestitems=!1};