﻿Type.registerNamespace("AjaxControlToolkit");AjaxControlToolkit.AutoCompleteBehavior=function(A){AjaxControlToolkit.AutoCompleteBehavior.initializeBase(this,[A]);this._servicePath=null;this._serviceMethod=null;this._contextKey=null;this._useContextKey=false;this._minimumPrefixLength=3;this._completionSetCount=10;this._completionInterval=1000;this._completionListElementID=null;this._completionListElement=null;this._completionListWidth=300;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=true;this._flyoutHasFocus=false;this._textBoxHasFocus=false;this._completionListCssClass=null;this._completionListItemCssClass=null;this._highlightedItemCssClass=null;this._delimiterCharacters=null;this._firstRowSelected=false;this._showOnlyCurrentWordInCompletionListItem=false;this._webRequest=null};AjaxControlToolkit.AutoCompleteBehavior.prototype={initialize:function(){AjaxControlToolkit.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 A=this.get_element();this.initializeTextBox(A);if(this._completionListElementID!==null){this._completionListElement=$get(this._completionListElementID)}if(this._completionListElement==null){this._completionListElement=document.createElement("ul");this._completionListElement.id=this.get_id()+"_completionListElem";if(Sys.Browser.agent===Sys.Browser.Safari){document.body.appendChild(this._completionListElement)}else{A.parentNode.insertBefore(this._completionListElement,A.nextSibling)}}this.initializeCompletionList(this._completionListElement);this._popupBehavior=$create(AjaxControlToolkit.PopupBehavior,{id:this.get_id()+"PopupBehavior",parentElement:A,positioningMode:AjaxControlToolkit.PositioningMode.BottomLeft},null,null,this._completionListElement);this._popupBehavior.add_hidden(this._popupBehaviorHiddenHandler);if(this._onShowJson){this._popupBehavior.set_onShow(this._onShowJson)}if(this._onHideJson){this._popupBehavior.set_onHide(this._onHideJson)}},dispose:function(){this._onShowJson=null;this._onHideJson=null;if(this._popupBehavior){if(this._popupBehaviorHiddenHandler){this._popupBehavior.remove_hidden(this._popupBehaviorHiddenHandler)}this._popupBehavior.dispose();this._popupBehavior=null}if(this._timer){this._timer.dispose();this._timer=null}var A=this.get_element();if(A){$removeHandler(A,"focus",this._focusHandler);$removeHandler(A,"blur",this._blurHandler);$removeHandler(A,"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)}if(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;AjaxControlToolkit.AutoCompleteBehavior.callBaseMethod(this,"dispose")},initializeTimer:function(A){A.set_interval(this._completionInterval);A.add_tick(this._tickHandler)},initializeTextBox:function(A){A.autocomplete="off";$addHandler(A,"focus",this._focusHandler);$addHandler(A,"blur",this._blurHandler);$addHandler(A,"keydown",this._keyDownHandler)},initializeCompletionList:function(A){if(this._completionListCssClass){Sys.UI.DomElement.addCssClass(A,this._completionListCssClass)}else{var B=A.style;B.textAlign="left";B.visibility="hidden";B.cursor="default";B.listStyle="none";B.padding="0px";B.margin="0px! important";if(Sys.Browser.agent===Sys.Browser.Safari){B.border="solid 1px gray";B.backgroundColor="white";B.color="black"}else{B.border="solid 1px buttonshadow";B.backgroundColor=this._textBackground;B.color=this._textColor}}$addHandler(A,"mousedown",this._mouseDownHandler);$addHandler(A,"mouseup",this._mouseUpHandler);$addHandler(A,"mouseover",this._mouseOverHandler);$addHandler(A,"blur",this._completionListBlurHandler);$addHandler(document.body,"click",this._bodyClickHandler)},_currentCompletionWord:function(){var A=this.get_element();var E=A.value;var C=E;if(this.get_isMultiWord()){var D=this._getCurrentWordStartIndex();var B=this._getCurrentWordEndIndex(D);if(B<=D){C=E.substring(D)}else{C=E.substring(D,B)}}return C},_getCursorIndex:function(){return this.get_element().selectionStart},_getCurrentWordStartIndex:function(){var D=this.get_element();var E=D.value.substring(0,this._getCursorIndex());var A=0;var F=-1;for(var C=0;C<this._delimiterCharacters.length;++C){var B=E.lastIndexOf(this._delimiterCharacters.charAt(C));if(B>F){F=B}}A=F;if(A>=this._getCursorIndex()){A=0}return A<0?0:A+1},_getCurrentWordEndIndex:function(A){var E=this.get_element();var F=E.value.substring(A);var B=0;for(var D=0;D<this._delimiterCharacters.length;++D){var C=F.indexOf(this._delimiterCharacters.charAt(D));if(C>0&&(C<B||B==0)){B=C}}return B<=0?E.value.length:B+A},get_isMultiWord:function(){return(this._delimiterCharacters!=null)&&(this._delimiterCharacters!="")},_getTextWithInsertedWord:function(E){var H=E;var I=0;var B=this.get_element();var A=B.value;if(this.get_isMultiWord()){var F=this._getCurrentWordStartIndex();var C=this._getCurrentWordEndIndex(F);var D="";var G="";if(F>0){D=A.substring(0,F)}if(C>F){G=A.substring(C)}H=D+E+G}return H},_hideCompletionList:function(){var A=new Sys.CancelEventArgs();this.raiseHiding(A);if(A.get_cancel()){return }this.hidePopup()},showPopup:function(){this._popupBehavior.show();this.raiseShown(Sys.EventArgs.Empty)},hidePopup:function(){if(this._popupBehavior){this._popupBehavior.hide()}else{this._popupHidden()}},_popupHidden:function(){this._completionListElement.innerHTML="";this._selectIndex=-1;this._flyoutHasFocus=false;this.raiseHidden(Sys.EventArgs.Empty)},_highlightItem:function(C){var B=this._completionListElement.childNodes;for(var A=0;A<B.length;A++){var D=B[A];if(D._highlighted){if(this._completionListItemCssClass){Sys.UI.DomElement.removeCssClass(D,this._highlightedItemCssClass);Sys.UI.DomElement.addCssClass(D,this._completionListItemCssClass)}else{if(Sys.Browser.agent===Sys.Browser.Safari){D.style.backgroundColor="white";D.style.color="black"}else{D.style.backgroundColor=this._textBackground;D.style.color=this._textColor}}this.raiseItemOut(new AjaxControlToolkit.AutoCompleteItemEventArgs(D,D.firstChild.nodeValue,D._value))}}if(this._highlightedItemCssClass){Sys.UI.DomElement.removeCssClass(C,this._completionListItemCssClass);Sys.UI.DomElement.addCssClass(C,this._highlightedItemCssClass)}else{if(Sys.Browser.agent===Sys.Browser.Safari){C.style.backgroundColor="lemonchiffon"}else{C.style.backgroundColor="highlight";C.style.color="highlighttext"}}C._highlighted=true;this.raiseItemOver(new AjaxControlToolkit.AutoCompleteItemEventArgs(C,C.firstChild.nodeValue,C._value))},_onCompletionListBlur:function(A){this._hideCompletionList()},_onListMouseDown:function(A){if(A.target!==this._completionListElement){this._setText(A.target);this._flyoutHasFocus=false}else{this._flyoutHasFocus=true}},_onListMouseUp:function(A){this.get_element().focus()},_onListMouseOver:function(D){var C=D.target;if(C!==this._completionListElement){var B=this._completionListElement.childNodes;for(var A=0;A<B.length;++A){if(C===B[A]){this._highlightItem(C);this._selectIndex=A;break}}}},_onGotFocus:function(A){this._textBoxHasFocus=true;if(this._flyoutHasFocus){this._hideCompletionList()}if((this._minimumPrefixLength==0)&&(!this.get_element().value)){this._timer.set_enabled(true)}},_onKeyDown:function(B){this._timer.set_enabled(false);var A=B.keyCode?B.keyCode:B.rawEvent.keyCode;if(A===Sys.UI.Key.esc){this._hideCompletionList();B.preventDefault()}else{if(A===Sys.UI.Key.up){if(this._selectIndex>0){this._selectIndex--;this._handleScroll(this._completionListElement.childNodes[this._selectIndex],this._selectIndex);this._highlightItem(this._completionListElement.childNodes[this._selectIndex]);B.stopPropagation();B.preventDefault()}}else{if(A===Sys.UI.Key.down){if(this._selectIndex<(this._completionListElement.childNodes.length-1)){this._selectIndex++;this._handleScroll(this._completionListElement.childNodes[this._selectIndex],this._selectIndex);this._highlightItem(this._completionListElement.childNodes[this._selectIndex]);B.stopPropagation();B.preventDefault()}}else{if(A===Sys.UI.Key.enter){if(this._selectIndex!==-1){this._setText(this._completionListElement.childNodes[this._selectIndex]);B.preventDefault()}else{this.hidePopup()}}else{if(A===Sys.UI.Key.tab){if(this._selectIndex!==-1){this._setText(this._completionListElement.childNodes[this._selectIndex])}}else{this._timer.set_enabled(true)}}}}}},_handleScroll:function(D,B){var A=this._completionListElement;var E=$common.getBounds(D);var C=this._completionListElement.childNodes.length;if(((E.height*B)-(A.clientHeight+A.scrollTop))>=0){A.scrollTop+=(((E.height*B)-(A.clientHeight+A.scrollTop))+E.height)}if(((E.height*(C-(B+1)))-(A.scrollHeight-A.scrollTop))>=0){A.scrollTop-=(((E.height*(C-(B+1)))-(A.scrollHeight-A.scrollTop))+E.height)}if(A.scrollTop%E.height!==0){if(((E.height*(B+1))-(A.clientHeight+A.scrollTop))>=0){A.scrollTop-=(A.scrollTop%E.height)}else{A.scrollTop+=(E.height-(A.scrollTop%E.height))}}},_handleFlyoutFocus:function(){if(!this._textBoxHasFocus){if(!this._flyoutHasFocus){if(this._webRequest){this._webRequest.get_executor().abort();this._webRequest=null}this._hideCompletionList()}else{}}},_onLostFocus:function(){this._textBoxHasFocus=false;this._timer.set_enabled(false);window.setTimeout(Function.createDelegate(this,this._handleFlyoutFocus),500)},_onMethodComplete:function(A,B){this._webRequest=null;this._update(B,A,true)},_onMethodFailed:function(C,A,B){this._webRequest=null},_onTimerTick:function(B,A){this._timer.set_enabled(false);if(this._servicePath&&this._serviceMethod){var D=this._currentCompletionWord();if(D.trim().length<this._minimumPrefixLength){this._currentPrefix=null;this._update("",null,false);return }if((this._currentPrefix!==D)||((D=="")&&(this._minimumPrefixLength==0))){this._currentPrefix=D;if((D!="")&&this._cache&&this._cache[D]){this._update(D,this._cache[D],false);return }var A=new Sys.CancelEventArgs();this.raisePopulating(A);if(A.get_cancel()){return }var C={prefixText:this._currentPrefix,count:this._completionSetCount};if(this._useContextKey){C.contextKey=this._contextKey}if(this._webRequest){this._webRequest.get_executor().abort();this._webRequest=null}this._webRequest=Sys.Net.WebServiceProxy.invoke(this.get_servicePath(),this.get_serviceMethod(),false,C,Function.createDelegate(this,this._onMethodComplete),Function.createDelegate(this,this._onMethodFailed),D);$common.updateFormToRefreshATDeviceBuffer()}}},_setText:function(B){var E=(B&&B.firstChild)?B.firstChild.nodeValue:null;this._timer.set_enabled(false);var A=this.get_element();var D=A.control;var C=this._showOnlyCurrentWordInCompletionListItem?this._getTextWithInsertedWord(E):E;if(D&&D.set_text){D.set_text(C)}else{A.value=C}$common.tryFireEvent(A,"change");this.raiseItemSelected(new AjaxControlToolkit.AutoCompleteItemEventArgs(B,E,B?B._value:null));this._currentPrefix=this._currentCompletionWord();this._hideCompletionList()},_update:function(G,J,L){if(L&&this.get_enableCaching()){if(!this._cache){this._cache={}}this._cache[G]=J}if((!this._textBoxHasFocus)||(G!=this._currentCompletionWord())){this._hideCompletionList();return }if(J&&J.length){this._completionListElement.innerHTML="";this._selectIndex=-1;var O=null;var N=null;var K=null;for(var F=0;F<J.length;F++){var D=null;if(this._completionListElementID){D=document.createElement("div")}else{D=document.createElement("li")}if(O==null){O=D}try{var E=Sys.Serialization.JavaScriptSerializer.deserialize("("+J[F]+")");if(E&&E.First){N=E.First;K=E.Second}else{N=E;K=E}}catch(H){N=J[F];K=J[F]}var M=this._showOnlyCurrentWordInCompletionListItem?N:this._getTextWithInsertedWord(N);D.appendChild(document.createTextNode(M));D._value=K;D.__item="";if(this._completionListItemCssClass){Sys.UI.DomElement.addCssClass(D,this._completionListItemCssClass)}else{var C=D.style;C.padding="0px";C.textAlign="left";C.textOverflow="ellipsis";if(Sys.Browser.agent===Sys.Browser.Safari){C.backgroundColor="white";C.color="black"}else{C.backgroundColor=this._textBackground;C.color=this._textColor}}this._completionListElement.appendChild(D)}var I=$common.getBounds(this.get_element());var B=I.width-2;if(this._completionListWidth>B){B=this._completionListWidth}this._completionListElement.style.width=Math.max(B,I.width-2)+"px";this._completionListElement.scrollTop=0;this.raisePopulated(Sys.EventArgs.Empty);var A=new Sys.CancelEventArgs();this.raiseShowing(A);if(!A.get_cancel()){this.showPopup();if(this._firstRowSelected&&(O!=null)){this._highlightItem(O);this._selectIndex=0}}}else{this._hideCompletionList()}},get_onShow:function(){return this._popupBehavior?this._popupBehavior.get_onShow():this._onShowJson},set_onShow:function(A){if(this._popupBehavior){this._popupBehavior.set_onShow(A)}else{this._onShowJson=A}this.raisePropertyChanged("onShow")},get_onShowBehavior:function(){return this._popupBehavior?this._popupBehavior.get_onShowBehavior():null},onShow:function(){if(this._popupBehavior){this._popupBehavior.onShow()}},get_onHide:function(){return this._popupBehavior?this._popupBehavior.get_onHide():this._onHideJson},set_onHide:function(A){if(this._popupBehavior){this._popupBehavior.set_onHide(A)}else{this._onHideJson=A}this.raisePropertyChanged("onHide")},get_onHideBehavior:function(){return this._popupBehavior?this._popupBehavior.get_onHideBehavior():null},onHide:function(){if(this._popupBehavior){this._popupBehavior.onHide()}},get_completionInterval:function(){return this._completionInterval},set_completionInterval:function(A){if(this._completionInterval!=A){this._completionInterval=A;this.raisePropertyChanged("completionInterval")}},get_completionList:function(){return this._completionListElement},set_completionList:function(A){if(this._completionListElement!=A){this._completionListElement=A;this.raisePropertyChanged("completionList")}},get_completionSetCount:function(){return this._completionSetCount},set_completionSetCount:function(A){if(this._completionSetCount!=A){this._completionSetCount=A;this.raisePropertyChanged("completionSetCount")}},get_minimumPrefixLength:function(){return this._minimumPrefixLength},set_minimumPrefixLength:function(A){if(this._minimumPrefixLength!=A){this._minimumPrefixLength=A;this.raisePropertyChanged("minimumPrefixLength")}},get_serviceMethod:function(){return this._serviceMethod},set_serviceMethod:function(A){if(this._serviceMethod!=A){this._serviceMethod=A;this.raisePropertyChanged("serviceMethod")}},get_servicePath:function(){return this._servicePath},set_servicePath:function(A){if(this._servicePath!=A){this._servicePath=A;this.raisePropertyChanged("servicePath")}},get_contextKey:function(){return this._contextKey},set_contextKey:function(A){if(this._contextKey!=A){this._contextKey=A;this.set_useContextKey(true);this.raisePropertyChanged("contextKey")}},get_useContextKey:function(){return this._useContextKey},set_useContextKey:function(A){if(this._useContextKey!=A){this._useContextKey=A;this.raisePropertyChanged("useContextKey")}},get_enableCaching:function(){return this._enableCaching},set_enableCaching:function(A){if(this._enableCaching!=A){this._enableCaching=A;this.raisePropertyChanged("enableCaching")}},get_completionListElementID:function(){return this._completionListElementID},set_completionListElementID:function(A){if(this._completionListElementID!=A){this._completionListElementID=A;this.raisePropertyChanged("completionListElementID")}},get_completionListCssClass:function(){return this._completionListCssClass},set_completionListCssClass:function(A){if(this._completionListCssClass!=A){this._completionListCssClass=A;this.raisePropertyChanged("completionListCssClass")}},get_completionListItemCssClass:function(){return this._completionListItemCssClass},set_completionListItemCssClass:function(A){if(this._completionListItemCssClass!=A){this._completionListItemCssClass=A;this.raisePropertyChanged("completionListItemCssClass")}},get_highlightedItemCssClass:function(){return this._highlightedItemCssClass},set_highlightedItemCssClass:function(A){if(this._highlightedItemCssClass!=A){this._highlightedItemCssClass=A;this.raisePropertyChanged("highlightedItemCssClass")}},get_delimiterCharacters:function(){return this._delimiterCharacters},set_delimiterCharacters:function(A){if(this._delimiterCharacters!=A){this._delimiterCharacters=A;this.raisePropertyChanged("delimiterCharacters")}},get_firstRowSelected:function(){return this._firstRowSelected},set_firstRowSelected:function(A){if(this._firstRowSelected!=A){this._firstRowSelected=A;this.raisePropertyChanged("firstRowSelected")}},get_showOnlyCurrentWordInCompletionListItem:function(){return this._showOnlyCurrentWordInCompletionListItem},set_showOnlyCurrentWordInCompletionListItem:function(A){if(this._showOnlyCurrentWordInCompletionListItem!=A){this._showOnlyCurrentWordInCompletionListItem=A;this.raisePropertyChanged("showOnlyCurrentWordInCompletionListItem")}},get_completionListWidth:function(){return this._completionListWidth},set_completionListWidth:function(A){this._completionListWidth=A},add_populating:function(A){this.get_events().addHandler("populating",A)},remove_populating:function(A){this.get_events().removeHandler("populating",A)},raisePopulating:function(A){var B=this.get_events().getHandler("populating");if(B){B(this,A)}},add_populated:function(A){this.get_events().addHandler("populated",A)},remove_populated:function(A){this.get_events().removeHandler("populated",A)},raisePopulated:function(A){var B=this.get_events().getHandler("populated");if(B){B(this,A)}},add_showing:function(A){this.get_events().addHandler("showing",A)},remove_showing:function(A){this.get_events().removeHandler("showing",A)},raiseShowing:function(A){var B=this.get_events().getHandler("showing");if(B){B(this,A)}},add_shown:function(A){this.get_events().addHandler("shown",A)},remove_shown:function(A){this.get_events().removeHandler("shown",A)},raiseShown:function(A){var B=this.get_events().getHandler("shown");if(B){B(this,A)}},add_hiding:function(A){this.get_events().addHandler("hiding",A)},remove_hiding:function(A){this.get_events().removeHandler("hiding",A)},raiseHiding:function(A){var B=this.get_events().getHandler("hiding");if(B){B(this,A)}},add_hidden:function(A){this.get_events().addHandler("hidden",A)},remove_hidden:function(A){this.get_events().removeHandler("hidden",A)},raiseHidden:function(A){var B=this.get_events().getHandler("hidden");if(B){B(this,A)}},add_itemSelected:function(A){this.get_events().addHandler("itemSelected",A)},remove_itemSelected:function(A){this.get_events().removeHandler("itemSelected",A)},raiseItemSelected:function(A){var B=this.get_events().getHandler("itemSelected");if(B){B(this,A)}},add_itemOver:function(A){this.get_events().addHandler("itemOver",A)},remove_itemOver:function(A){this.get_events().removeHandler("itemOver",A)},raiseItemOver:function(A){var B=this.get_events().getHandler("itemOver");if(B){B(this,A)}},add_itemOut:function(A){this.get_events().addHandler("itemOut",A)},remove_itemOut:function(A){this.get_events().removeHandler("itemOut",A)},raiseItemOut:function(A){var B=this.get_events().getHandler("itemOut");if(B){B(this,A)}}};AjaxControlToolkit.AutoCompleteBehavior.registerClass("AjaxControlToolkit.AutoCompleteBehavior",AjaxControlToolkit.BehaviorBase);AjaxControlToolkit.AutoCompleteBehavior.descriptor={properties:[{name:"completionInterval",type:Number},{name:"completionList",isDomElement:true},{name:"completionListElementID",type:String},{name:"completionSetCount",type:Number},{name:"minimumPrefixLength",type:Number},{name:"serviceMethod",type:String},{name:"servicePath",type:String},{name:"enableCaching",type:Boolean},{name:"showOnlyCurrentWordInCompletionListItem",type:Boolean}]};AjaxControlToolkit.AutoCompleteItemEventArgs=function(A,C,B){AjaxControlToolkit.AutoCompleteItemEventArgs.initializeBase(this);this._item=A;this._text=C;this._value=(B!==undefined)?B:null};AjaxControlToolkit.AutoCompleteItemEventArgs.prototype={get_item:function(){return this._item},set_item:function(A){this._item=A},get_text:function(){return this._text},set_text:function(A){this._text=A},get_value:function(){return this._value},set_value:function(A){this._value=A}};AjaxControlToolkit.AutoCompleteItemEventArgs.registerClass("AjaxControlToolkit.AutoCompleteItemEventArgs",Sys.EventArgs);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();