// (c) 2010 CodePlex Foundation (function(){function n(){Type.registerNamespace("Sys.Extended.UI");Sys.Extended.UI.AutoCompleteBehavior=function(n){Sys.Extended.UI.AutoCompleteBehavior.initializeBase(this,[n]);this._servicePath=null;this._serviceMethod=null;this._contextKey=null;this._useContextKey=!1;this._minimumPrefixLength=3;this._completionSetCount=10;this._completionInterval=1e3;this._completionListElementID=null;this._completionListElement=null;this._textColor="windowtext";this._textBackground="window";this._popupBehavior=null;this._popupBehaviorHiddenHandler=null;this._onShowJson=null;this._onHideJson=null;this._timer=null;this._cache=null;this._currentPrefix=null;this._selectIndex=-1;this._focusHandler=null;this._blurHandler=null;this._bodyClickHandler=null;this._completionListBlurHandler=null;this._keyDownHandler=null;this._mouseDownHandler=null;this._mouseUpHandler=null;this._mouseOverHandler=null;this._tickHandler=null;this._enableCaching=!0;this._flyoutHasFocus=!1;this._textBoxHasFocus=!1;this._completionListCssClass=null;this._completionListItemCssClass=null;this._highlightedItemCssClass=null;this._delimiterCharacters=null;this._firstRowSelected=!1;this._showOnlyCurrentWordInCompletionListItem=!1;this._webRequest=null};Sys.Extended.UI.AutoCompleteBehavior.prototype={initialize:function(){Sys.Extended.UI.AutoCompleteBehavior.callBaseMethod(this,"initialize");$common.prepareHiddenElementForATDeviceUpdate();this._popupBehaviorHiddenHandler=Function.createDelegate(this,this._popupHidden);this._tickHandler=Function.createDelegate(this,this._onTimerTick);this._focusHandler=Function.createDelegate(this,this._onGotFocus);this._blurHandler=Function.createDelegate(this,this._onLostFocus);this._keyDownHandler=Function.createDelegate(this,this._onKeyDown);this._mouseDownHandler=Function.createDelegate(this,this._onListMouseDown);this._mouseUpHandler=Function.createDelegate(this,this._onListMouseUp);this._mouseOverHandler=Function.createDelegate(this,this._onListMouseOver);this._completionListBlurHandler=Function.createDelegate(this,this._onCompletionListBlur);this._bodyClickHandler=Function.createDelegate(this,this._onCompletionListBlur);this._timer=new Sys.Timer;this.initializeTimer(this._timer);var n=this.get_element();this.initializeTextBox(n);this._completionListElementID!==null&&(this._completionListElement=$get(this._completionListElementID));this._completionListElement==null&&(this._completionListElement=document.createElement("ul"),this._completionListElement.id=this.get_id()+"_completionListElem",Sys.Browser.agent===Sys.Browser.Safari?document.body.appendChild(this._completionListElement):n.parentNode.insertBefore(this._completionListElement,n.nextSibling));this.initializeCompletionList(this._completionListElement);this._popupBehavior=$create(Sys.Extended.UI.PopupBehavior,{id:this.get_id()+"PopupBehavior",parentElement:n,positioningMode:Sys.Extended.UI.PositioningMode.BottomLeft},null,null,this._completionListElement);this._popupBehavior.add_hidden(this._popupBehaviorHiddenHandler);this._onShowJson&&this._popupBehavior.set_onShow(this._onShowJson);this._onHideJson&&this._popupBehavior.set_onHide(this._onHideJson)},dispose:function(){this._onShowJson=null;this._onHideJson=null;this._popupBehavior&&(this._popupBehaviorHiddenHandler&&this._popupBehavior.remove_hidden(this._popupBehaviorHiddenHandler),this._popupBehavior.dispose(),this._popupBehavior=null);this._timer&&(this._timer.dispose(),this._timer=null);var n=this.get_element();n&&($removeHandler(n,"focus",this._focusHandler),$removeHandler(n,"blur",this._blurHandler),$removeHandler(n,"keydown",this._keyDownHandler),$removeHandler(this._completionListElement,"blur",this._completionListBlurHandler),$removeHandler(this._completionListElement,"mousedown",this._mouseDownHandler),$removeHandler(this._completionListElement,"mouseup",this._mouseUpHandler),$removeHandler(this._completionListElement,"mouseover",this._mouseOverHandler));this._bodyClickHandler&&($removeHandler(document.body,"click",this._bodyClickHandler),this._bodyClickHandler=null);this._popupBehaviorHiddenHandler=null;this._tickHandler=null;this._focusHandler=null;this._blurHandler=null;this._keyDownHandler=null;this._completionListBlurHandler=null;this._mouseDownHandler=null;this._mouseUpHandler=null;this._mouseOverHandler=null;Sys.Extended.UI.AutoCompleteBehavior.callBaseMethod(this,"dispose")},initializeTimer:function(n){n.set_interval(this._completionInterval);n.add_tick(this._tickHandler)},initializeTextBox:function(n){n.autocomplete="off";$addHandler(n,"focus",this._focusHandler);$addHandler(n,"blur",this._blurHandler);$addHandler(n,"keydown",this._keyDownHandler)},initializeCompletionList:function(n){if(this._completionListCssClass)Sys.UI.DomElement.addCssClass(n,this._completionListCssClass);else{var t=n.style;t.textAlign="left";t.visibility="hidden";t.cursor="default";t.listStyle="none";t.padding="0px";t.margin="0px! important";Sys.Browser.agent===Sys.Browser.Safari?(t.border="solid 1px gray",t.backgroundColor="white",t.color="black"):(t.border="solid 1px buttonshadow",t.backgroundColor=this._textBackground,t.color=this._textColor)}$addHandler(n,"mousedown",this._mouseDownHandler);$addHandler(n,"mouseup",this._mouseUpHandler);$addHandler(n,"mouseover",this._mouseOverHandler);$addHandler(n,"blur",this._completionListBlurHandler);$addHandler(document.body,"click",this._bodyClickHandler)},_currentCompletionWord:function(){var u=this.get_element(),t=u.value,r=t,n,i;return this.get_isMultiWord()&&(n=this._getCurrentWordStartIndex(),i=this._getCurrentWordEndIndex(n),r=i<=n?t.substring(n):t.substring(n,i)),r},_getCursorIndex:function(){return this.get_element().selectionStart},_getCurrentWordStartIndex:function(){for(var u=this.get_element(),f=u.value.substring(0,this._getCursorIndex()),n=0,i=-1,r,t=0;ti&&(i=r);return n=i,n>=this._getCursorIndex()&&(n=0),n<0?0:n+1},_getCurrentWordEndIndex:function(n){for(var u=this.get_element(),f=u.value.substring(n),t=0,r,i=0;i0&&(r0&&(f=r.substring(0,t));u>t&&(e=r.substring(u));i=f+n+e}return i},_hideCompletionList:function(){var n=new Sys.CancelEventArgs;(this.raiseHiding(n),n.get_cancel())||this.hidePopup()},showPopup:function(){this._popupBehavior.show();this.raiseShown(Sys.EventArgs.Empty)},hidePopup:function(){this._popupBehavior?this._popupBehavior.hide():this._popupHidden()},_popupHidden:function(){this._completionListElement.innerHTML="";this._selectIndex=-1;this._flyoutHasFocus=!1;this.raiseHidden(Sys.EventArgs.Empty)},_highlightItem:function(n){for(var r=this._completionListElement.childNodes,t,i=0;i0&&(this._selectIndex--,this._handleScroll(this._completionListElement.childNodes[this._selectIndex],this._selectIndex),this._highlightItem(this._completionListElement.childNodes[this._selectIndex]),n.stopPropagation(),n.preventDefault()):t===Sys.UI.Key.down?this._selectIndex=0&&(i.scrollTop+=r.height*t-(i.clientHeight+i.scrollTop)+r.height);r.height*(u-(t+1))-(i.scrollHeight-i.scrollTop)>=0&&(i.scrollTop-=r.height*(u-(t+1))-(i.scrollHeight-i.scrollTop)+r.height);i.scrollTop%r.height!=0&&(r.height*(t+1)-(i.clientHeight+i.scrollTop)>=0?i.scrollTop-=i.scrollTop%r.height:i.scrollTop+=r.height-i.scrollTop%r.height)},_handleFlyoutFocus:function(){this._textBoxHasFocus||this._flyoutHasFocus||(this._webRequest&&(this._webRequest.get_executor().abort(),this._webRequest=null),this._hideCompletionList())},_onLostFocus:function(){this._textBoxHasFocus=!1;this._timer.set_enabled(!1);window.setTimeout(Function.createDelegate(this,this._handleFlyoutFocus),500)},_onMethodComplete:function(n,t){this._webRequest=null;this._update(t,n,!0)},_onMethodFailed:function(){this._webRequest=null},_onTimerTick:function(n,t){var i,t,r;if(this._timer.set_enabled(!1),this._servicePath&&this._serviceMethod){if(i=this._currentCompletionWord(),i.trim().length