﻿// (c) 2010 CodePlex Foundation
(function(){var b="ExtendedAutoComplete";function a(){var o="itemOut",n="itemOver",m="itemSelected",l="hiding",k="shown",j="showing",i="populated",h="populating",z="showOnlyCurrentWordInCompletionListItem",y="completionListElementID",x="enableCaching",w="servicePath",v="serviceMethod",u="minimumPrefixLength",t="completionSetCount",s="completionList",r="completionInterval",g="black",f="white",e="hidden",q="mouseover",p="mousedown",d="blur",c=true,b=false,a=null;Type.registerNamespace("Sys.Extended.UI");Sys.Extended.UI.AutoCompleteBehavior=function(e){var d=this;Sys.Extended.UI.AutoCompleteBehavior.initializeBase(d,[e]);d._servicePath=a;d._serviceMethod=a;d._contextKey=a;d._useContextKey=b;d._minimumPrefixLength=3;d._completionSetCount=10;d._completionInterval=1e3;d._completionListElementID=a;d._completionListElement=a;d._textColor="windowtext";d._textBackground="window";d._popupBehavior=a;d._popupBehaviorHiddenHandler=a;d._onShowJson=a;d._onHideJson=a;d._timer=a;d._cache=a;d._currentPrefix=a;d._selectIndex=-1;d._focusHandler=a;d._blurHandler=a;d._bodyClickHandler=a;d._completionListBlurHandler=a;d._keyDownHandler=a;d._mouseDownHandler=a;d._mouseUpHandler=a;d._mouseOverHandler=a;d._tickHandler=a;d._enableCaching=c;d._flyoutHasFocus=b;d._textBoxHasFocus=b;d._completionListCssClass=a;d._completionListItemCssClass=a;d._highlightedItemCssClass=a;d._delimiterCharacters=a;d._firstRowSelected=b;d._showOnlyCurrentWordInCompletionListItem=b;d._webRequest=a};Sys.Extended.UI.AutoCompleteBehavior.prototype={initialize:function(){var b=this;Sys.Extended.UI.AutoCompleteBehavior.callBaseMethod(b,"initialize");$common.prepareHiddenElementForATDeviceUpdate();b._popupBehaviorHiddenHandler=Function.createDelegate(b,b._popupHidden);b._tickHandler=Function.createDelegate(b,b._onTimerTick);b._focusHandler=Function.createDelegate(b,b._onGotFocus);b._blurHandler=Function.createDelegate(b,b._onLostFocus);b._keyDownHandler=Function.createDelegate(b,b._onKeyDown);b._mouseDownHandler=Function.createDelegate(b,b._onListMouseDown);b._mouseUpHandler=Function.createDelegate(b,b._onListMouseUp);b._mouseOverHandler=Function.createDelegate(b,b._onListMouseOver);b._completionListBlurHandler=Function.createDelegate(b,b._onCompletionListBlur);b._bodyClickHandler=Function.createDelegate(b,b._onCompletionListBlur);b._timer=new Sys.Timer;b.initializeTimer(b._timer);var c=b.get_element();b.initializeTextBox(c);if(b._completionListElementID!==a)b._completionListElement=$get(b._completionListElementID);if(b._completionListElement==a){b._completionListElement=document.createElement("ul");b._completionListElement.id=b.get_id()+"_completionListElem";if(Sys.Browser.agent===Sys.Browser.Safari)document.body.appendChild(b._completionListElement);else c.parentNode.insertBefore(b._completionListElement,c.nextSibling)}b.initializeCompletionList(b._completionListElement);b._popupBehavior=$create(Sys.Extended.UI.PopupBehavior,{id:b.get_id()+"PopupBehavior",parentElement:c,positioningMode:Sys.Extended.UI.PositioningMode.BottomLeft},a,a,b._completionListElement);b._popupBehavior.add_hidden(b._popupBehaviorHiddenHandler);b._onShowJson&&b._popupBehavior.set_onShow(b._onShowJson);b._onHideJson&&b._popupBehavior.set_onHide(b._onHideJson)},dispose:function(){var b=this;b._onShowJson=a;b._onHideJson=a;if(b._popupBehavior){b._popupBehaviorHiddenHandler&&b._popupBehavior.remove_hidden(b._popupBehaviorHiddenHandler);b._popupBehavior.dispose();b._popupBehavior=a}if(b._timer){b._timer.dispose();b._timer=a}var c=b.get_element();if(c){$removeHandler(c,"focus",b._focusHandler);$removeHandler(c,d,b._blurHandler);$removeHandler(c,"keydown",b._keyDownHandler);$removeHandler(b._completionListElement,d,b._completionListBlurHandler);$removeHandler(b._completionListElement,p,b._mouseDownHandler);$removeHandler(b._completionListElement,"mouseup",b._mouseUpHandler);$removeHandler(b._completionListElement,q,b._mouseOverHandler)}if(b._bodyClickHandler){$removeHandler(document.body,"click",b._bodyClickHandler);b._bodyClickHandler=a}b._popupBehaviorHiddenHandler=a;b._tickHandler=a;b._focusHandler=a;b._blurHandler=a;b._keyDownHandler=a;b._completionListBlurHandler=a;b._mouseDownHandler=a;b._mouseUpHandler=a;b._mouseOverHandler=a;Sys.Extended.UI.AutoCompleteBehavior.callBaseMethod(b,"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,d,this._blurHandler);$addHandler(a,"keydown",this._keyDownHandler)},initializeCompletionList:function(c){var b=this;if(b._completionListCssClass)Sys.UI.DomElement.addCssClass(c,b._completionListCssClass);else{var a=c.style;a.textAlign="left";a.visibility=e;a.cursor="default";a.listStyle="none";a.padding="0px";a.margin="0px! important";if(Sys.Browser.agent===Sys.Browser.Safari){a.border="solid 1px gray";a.backgroundColor=f;a.color=g}else{a.border="solid 1px buttonshadow";a.backgroundColor=b._textBackground;a.color=b._textColor}}$addHandler(c,p,b._mouseDownHandler);$addHandler(c,"mouseup",b._mouseUpHandler);$addHandler(c,q,b._mouseOverHandler);$addHandler(c,d,b._completionListBlurHandler);$addHandler(document.body,"click",b._bodyClickHandler)},_currentCompletionWord:function(){var b=this,f=b.get_element(),c=f.value,d=c;if(b.get_isMultiWord()){var a=b._getCurrentWordStartIndex(),e=b._getCurrentWordEndIndex(a);if(e<=a)d=c.substring(a);else d=c.substring(a,e)}return d},_getCursorIndex:function(){return this.get_element().selectionStart},_getCurrentWordStartIndex:function(){var a=this;for(var g=a.get_element(),f=g.value.substring(0,a._getCursorIndex()),b=0,c=-1,d=0;d<a._delimiterCharacters.length;++d){var e=f.lastIndexOf(a._delimiterCharacters.charAt(d));if(e>c)c=e}b=c;if(b>=a._getCursorIndex())b=0;return b<0?0:b+1},_getCurrentWordEndIndex:function(d){for(var e=this.get_element(),f=e.value.substring(d),a=0,c=0;c<this._delimiterCharacters.length;++c){var b=f.indexOf(this._delimiterCharacters.charAt(c));if(b>0&&(b<a||a==0))a=b}return a<=0?e.value.length:a+d},get_isMultiWord:function(){return this._delimiterCharacters!=a&&this._delimiterCharacters!=""},_getTextWithInsertedWord:function(d){var b=this,h=d,j=0,i=b.get_element(),c=i.value;if(b.get_isMultiWord()){var a=b._getCurrentWordStartIndex(),e=b._getCurrentWordEndIndex(a),f="",g="";if(a>0)f=c.substring(0,a);if(e>a)g=c.substring(e);h=f+d+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(){var a=this;a._completionListElement.innerHTML="";a._selectIndex=-1;a._flyoutHasFocus=b;a.raiseHidden(Sys.EventArgs.Empty)},_highlightItem:function(d){var a=this;for(var h=a._completionListElement.childNodes,e=0;e<h.length;e++){var b=h[e];if(b._highlighted){if(a._completionListItemCssClass){Sys.UI.DomElement.removeCssClass(b,a._highlightedItemCssClass);Sys.UI.DomElement.addCssClass(b,a._completionListItemCssClass)}else if(Sys.Browser.agent===Sys.Browser.Safari){b.style.backgroundColor=f;b.style.color=g}else{b.style.backgroundColor=a._textBackground;b.style.color=a._textColor}a.raiseItemOut(new Sys.Extended.UI.AutoCompleteItemEventArgs(b,b.firstChild.nodeValue,b._value))}}if(a._highlightedItemCssClass){Sys.UI.DomElement.removeCssClass(d,a._completionListItemCssClass);Sys.UI.DomElement.addCssClass(d,a._highlightedItemCssClass)}else if(Sys.Browser.agent===Sys.Browser.Safari)d.style.backgroundColor="lemonchiffon";else{d.style.backgroundColor="highlight";d.style.color="highlighttext"}d._highlighted=c;a.raiseItemOver(new Sys.Extended.UI.AutoCompleteItemEventArgs(d,d.firstChild.nodeValue,d._value))},_onCompletionListBlur:function(){this._hideCompletionList()},_onListMouseDown:function(d){var a=this;if(d.target!==a._completionListElement){a._setText(d.target);a._flyoutHasFocus=b}else a._flyoutHasFocus=c},_onListMouseUp:function(){try{this.get_element().focus()}catch(b){}},_onListMouseOver:function(e){var a=this,c=e.target;if(c!==a._completionListElement)for(var d=a._completionListElement.childNodes,b=0;b<d.length;++b)if(c===d[b]){a._highlightItem(c);a._selectIndex=b;break}},_onGotFocus:function(){var a=this;a._textBoxHasFocus=c;a._flyoutHasFocus&&a._hideCompletionList();a._minimumPrefixLength==0&&!a.get_element().value&&a._timer.set_enabled(c)},_onKeyDown:function(d){var a=this;a._textBoxHasFocus=c;a._timer.set_enabled(b);var e=d.keyCode?d.keyCode:d.rawEvent.keyCode;if(e===Sys.UI.Key.esc){a._hideCompletionList();d.preventDefault()}else if(e===Sys.UI.Key.up){if(a._selectIndex>0){a._selectIndex--;a._handleScroll(a._completionListElement.childNodes[a._selectIndex],a._selectIndex);a._highlightItem(a._completionListElement.childNodes[a._selectIndex]);d.stopPropagation();d.preventDefault()}}else if(e===Sys.UI.Key.down){if(a._selectIndex<a._completionListElement.childNodes.length-1){a._selectIndex++;a._handleScroll(a._completionListElement.childNodes[a._selectIndex],a._selectIndex);a._highlightItem(a._completionListElement.childNodes[a._selectIndex]);d.stopPropagation();d.preventDefault()}}else if(e===Sys.UI.Key.enter)if(a._selectIndex!==-1){a._setText(a._completionListElement.childNodes[a._selectIndex]);d.preventDefault()}else a.hidePopup();else if(e===Sys.UI.Key.tab)a._selectIndex!==-1&&a._setText(a._completionListElement.childNodes[a._selectIndex]);else a._timer.set_enabled(c)},_handleScroll:function(e,c){var a=this._completionListElement,b=$common.getBounds(e),d=this._completionListElement.childNodes.length;if(b.height*c-(a.clientHeight+a.scrollTop)>=0)a.scrollTop+=b.height*c-(a.clientHeight+a.scrollTop)+b.height;if(b.height*(d-(c+1))-(a.scrollHeight-a.scrollTop)>=0)a.scrollTop-=b.height*(d-(c+1))-(a.scrollHeight-a.scrollTop)+b.height;if(a.scrollTop%b.height!==0)if(b.height*(c+1)-(a.clientHeight+a.scrollTop)>=0)a.scrollTop-=a.scrollTop%b.height;else a.scrollTop+=b.height-a.scrollTop%b.height},_handleFlyoutFocus:function(){var b=this;if(!b._textBoxHasFocus)if(!b._flyoutHasFocus){if(b._webRequest){b._webRequest.get_executor().abort();b._webRequest=a}b._hideCompletionList()}},_onLostFocus:function(){var a=this;a._textBoxHasFocus=b;a._timer.set_enabled(b);window.setTimeout(Function.createDelegate(a,a._handleFlyoutFocus),500)},_onMethodComplete:function(d,b){this._webRequest=a;this._update(b,d,c)},_onMethodFailed:function(){this._webRequest=a},_onTimerTick:function(g,e){var c=this;c._timer.set_enabled(b);if(c._servicePath&&c._serviceMethod){var d=c._currentCompletionWord();if(d.trim().length<c._minimumPrefixLength){c._currentPrefix=a;c._update("",a,b);return}if(c._currentPrefix!==d||d==""&&c._minimumPrefixLength==0){c._currentPrefix=d;if(d!=""&&c._cache&&c._cache[d]){c._update(d,c._cache[d],b);return}var e=new Sys.CancelEventArgs;c.raisePopulating(e);if(e.get_cancel())return;var f={prefixText:c._currentPrefix,count:c._completionSetCount};if(c._useContextKey)f.contextKey=c._contextKey;if(c._webRequest){c._webRequest.get_executor().abort();c._webRequest=a}c._webRequest=Sys.Net.WebServiceProxy.invoke(c.get_servicePath(),c.get_serviceMethod(),b,f,Function.createDelegate(c,c._onMethodComplete),Function.createDelegate(c,c._onMethodFailed),d);$common.updateFormToRefreshATDeviceBuffer()}}},_setText:function(d){var c=this,g=d&&d.firstChild?d.firstChild.nodeValue:a;c._timer.set_enabled(b);var f=c.get_element(),e=f.control,h=c._showOnlyCurrentWordInCompletionListItem?c._getTextWithInsertedWord(g):g;if(e&&e.set_text)e.set_text(h);else f.value=h;$common.tryFireEvent(f,"change");c.raiseItemSelected(new Sys.Extended.UI.AutoCompleteItemEventArgs(d,g,d?d._value:a));c._currentPrefix=c._currentCompletionWord();c._hideCompletionList()},_update:function(m,d,p){var b=this;if(p&&b.get_enableCaching()){if(!b._cache)b._cache={};b._cache[m]=d}if(!b._textBoxHasFocus||m!=b._currentCompletionWord()){b._hideCompletionList();return}if(d&&d.length){b._completionListElement.innerHTML="";b._selectIndex=-1;for(var j=a,h=a,k=a,i=0;i<d.length;i++){var c=a;if(b._completionListElementID)c=document.createElement("div");else c=document.createElement("li");if(j==a)j=c;try{var l=Sys.Serialization.JavaScriptSerializer.deserialize("("+d[i]+")");if(l&&l.First){h=l.First;k=l.Second}else{h=d[i];k=h}}catch(r){h=d[i];k=d[i]}var q=b._showOnlyCurrentWordInCompletionListItem?h:b._getTextWithInsertedWord(h);c.appendChild(document.createTextNode(q));c._value=k;c.__item="";if(b._completionListItemCssClass)Sys.UI.DomElement.addCssClass(c,b._completionListItemCssClass);else{var e=c.style;e.padding="0px";e.textAlign="left";e.textOverflow="ellipsis";if(Sys.Browser.agent===Sys.Browser.Safari){e.backgroundColor=f;e.color=g}else{e.backgroundColor=b._textBackground;e.color=b._textColor}}b._completionListElement.appendChild(c)}var o=$common.getBounds(b.get_element());b._completionListElement.style.width=Math.max(1,o.width-2)+"px";b._completionListElement.scrollTop=0;b.raisePopulated(Sys.EventArgs.Empty);var n=new Sys.CancelEventArgs;b.raiseShowing(n);if(!n.get_cancel()){b.showPopup();if(b._firstRowSelected&&j!=a){b._highlightItem(j);b._selectIndex=0}}}else b._hideCompletionList()},get_onShow:function(){return this._popupBehavior?this._popupBehavior.get_onShow():this._onShowJson},set_onShow:function(b){var a=this;if(a._popupBehavior)a._popupBehavior.set_onShow(b);else a._onShowJson=b;a.raisePropertyChanged("onShow")},get_onShowBehavior:function(){return this._popupBehavior?this._popupBehavior.get_onShowBehavior():a},onShow:function(){this._popupBehavior&&this._popupBehavior.onShow()},get_onHide:function(){return this._popupBehavior?this._popupBehavior.get_onHide():this._onHideJson},set_onHide:function(b){var a=this;if(a._popupBehavior)a._popupBehavior.set_onHide(b);else a._onHideJson=b;a.raisePropertyChanged("onHide")},get_onHideBehavior:function(){return this._popupBehavior?this._popupBehavior.get_onHideBehavior():a},onHide:function(){this._popupBehavior&&this._popupBehavior.onHide()},get_completionInterval:function(){return this._completionInterval},set_completionInterval:function(a){if(this._completionInterval!=a){this._completionInterval=a;this.raisePropertyChanged(r)}},get_completionList:function(){return this._completionListElement},set_completionList:function(a){if(this._completionListElement!=a){this._completionListElement=a;this.raisePropertyChanged(s)}},get_completionSetCount:function(){return this._completionSetCount},set_completionSetCount:function(a){if(this._completionSetCount!=a){this._completionSetCount=a;this.raisePropertyChanged(t)}},get_minimumPrefixLength:function(){return this._minimumPrefixLength},set_minimumPrefixLength:function(a){if(this._minimumPrefixLength!=a){this._minimumPrefixLength=a;this.raisePropertyChanged(u)}},get_serviceMethod:function(){return this._serviceMethod},set_serviceMethod:function(a){if(this._serviceMethod!=a){this._serviceMethod=a;this.raisePropertyChanged(v)}},get_servicePath:function(){return this._servicePath},set_servicePath:function(a){if(this._servicePath!=a){this._servicePath=a;this.raisePropertyChanged(w)}},get_contextKey:function(){return this._contextKey},set_contextKey:function(b){var a=this;if(a._contextKey!=b){a._contextKey=b;a.set_useContextKey(c);a.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(x)}},get_completionListElementID:function(){return this._completionListElementID},set_completionListElementID:function(a){if(this._completionListElementID!=a){this._completionListElementID=a;this.raisePropertyChanged(y)}},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(z)}},add_populating:function(a){this.get_events().addHandler(h,a)},remove_populating:function(a){this.get_events().removeHandler(h,a)},raisePopulating:function(b){var a=this.get_events().getHandler(h);a&&a(this,b)},add_populated:function(a){this.get_events().addHandler(i,a)},remove_populated:function(a){this.get_events().removeHandler(i,a)},raisePopulated:function(b){var a=this.get_events().getHandler(i);a&&a(this,b)},add_showing:function(a){this.get_events().addHandler(j,a)},remove_showing:function(a){this.get_events().removeHandler(j,a)},raiseShowing:function(b){var a=this.get_events().getHandler(j);a&&a(this,b)},add_shown:function(a){this.get_events().addHandler(k,a)},remove_shown:function(a){this.get_events().removeHandler(k,a)},raiseShown:function(b){var a=this.get_events().getHandler(k);a&&a(this,b)},add_hiding:function(a){this.get_events().addHandler(l,a)},remove_hiding:function(a){this.get_events().removeHandler(l,a)},raiseHiding:function(b){var a=this.get_events().getHandler(l);a&&a(this,b)},add_hidden:function(a){this.get_events().addHandler(e,a)},remove_hidden:function(a){this.get_events().removeHandler(e,a)},raiseHidden:function(b){var a=this.get_events().getHandler(e);a&&a(this,b)},add_itemSelected:function(a){this.get_events().addHandler(m,a)},remove_itemSelected:function(a){this.get_events().removeHandler(m,a)},raiseItemSelected:function(b){var a=this.get_events().getHandler(m);a&&a(this,b)},add_itemOver:function(a){this.get_events().addHandler(n,a)},remove_itemOver:function(a){this.get_events().removeHandler(n,a)},raiseItemOver:function(b){var a=this.get_events().getHandler(n);a&&a(this,b)},add_itemOut:function(a){this.get_events().addHandler(o,a)},remove_itemOut:function(a){this.get_events().removeHandler(o,a)},raiseItemOut:function(b){var a=this.get_events().getHandler(o);a&&a(this,b)}};Sys.Extended.UI.AutoCompleteBehavior.registerClass("Sys.Extended.UI.AutoCompleteBehavior",Sys.Extended.UI.BehaviorBase);Sys.registerComponent(Sys.Extended.UI.AutoCompleteBehavior,{name:"autoComplete"});Sys.Extended.UI.AutoCompleteBehavior.descriptor={properties:[{name:r,type:Number},{name:s,isDomElement:c},{name:y,type:String},{name:t,type:Number},{name:u,type:Number},{name:v,type:String},{name:w,type:String},{name:x,type:Boolean},{name:z,type:Boolean}]};Sys.Extended.UI.AutoCompleteItemEventArgs=function(d,e,c){var b=this;Sys.Extended.UI.AutoCompleteItemEventArgs.initializeBase(b);b._item=d;b._text=e;b._value=c!==undefined?c:a};Sys.Extended.UI.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}};Sys.Extended.UI.AutoCompleteItemEventArgs.registerClass("Sys.Extended.UI.AutoCompleteItemEventArgs",Sys.EventArgs)}if(window.Sys&&Sys.loader)Sys.loader.registerScript(b,["ExtendedTimer","ExtendedAnimationBehavior","ExtendedPopup"],a);else a()})();
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();