Type.registerNamespace("rb");rb.SearchBox=function(a){rb.SearchBox.initializeBase(this,[a]);this._textBox=null;this._suggestionList=null;this._suggestionItems=[];this._searchButton=null;this._img=null;this._textBoxActive=false;this._size=25;this._maxlen=50;this._anim=null;this._text="";this._prompt="";this._suggDelay=250;this._suggestionAction=null;this._maxsuggs=10;this._dataType="";this._matchContains=false;this._forceUpper=true;this._showSearch=true;this._idProp="ID";this._nameProp="Name";this._imgProp=null;this._suggestionPrefix="";this._suggestions=null;this._suggestionsVisible=false;this._selectedIndex=-1;this._itemUrl=null;this._searchUrl=null;this._imageUrl=null;this._resizeDelay=10;this._resizeAction=null;this._minChars=2;this._minCharsErr=null;this._filters=null;this._delegates={onSuggestionsReceived:Function.createDelegate(this,this._onSuggestionsReceived),requestSuggestions:Function.createDelegate(this,this._requestSuggestions),hideSuggestions:Function.createDelegate(this,this._hideSuggestions),onWindowResize:Function.createDelegate(this,this._onWindowResize),positionSuggestionList:Function.createDelegate(this,this._positionSuggestionList),listHidden:Function.createDelegate(this,this._listHidden),listShown:Function.createDelegate(this,this._listShown)}};rb.SearchBox.prototype={get_text:function(){var a=(this._textBoxActive?this._textBox.value:this._text);if(this._forceUpper){a=a.toUpperCase()}return a},set_text:function(a){this._text=a;if(this._textBox!=null){this._textBox.value=a;if(a==""){this._resetTextBox()}}},get_size:function(){return this._size},set_size:function(a){this._size=a},get_maxlen:function(){return this._maxlen},set_maxlen:function(a){this._maxlen=a},get_anim:function(){return this._anim},set_anim:function(a){this._anim=a},get_minChars:function(){return this._minChars},set_minChars:function(a){this._minChars=a},get_minCharsErr:function(){return this._minCharsErr},set_minCharsErr:function(a){this._minCharsErr=a},get_prompt:function(){return this._prompt},set_prompt:function(a){this._prompt=a},get_suggDelay:function(){return this._suggDelay},set_suggDelay:function(a){this._suggDelay=a},get_maxsuggs:function(){return this._maxsuggs},set_maxsuggs:function(a){this._maxsuggs=a},get_idProp:function(){return this._idProp},set_idProp:function(a){this._idProp=a},get_nameProp:function(){return this._nameProp},set_nameProp:function(a){this._nameProp=a},get_imgProp:function(){return this._imgProp},set_imgProp:function(a){this._imgProp=a},get_dataType:function(){return this._dataType},set_dataType:function(a){this._dataType=a},get_matchContains:function(){return this._matchContains},set_matchContains:function(a){this._matchContains=a},get_forceUpper:function(){return this._forceUpper},set_forceUpper:function(a){this._forceUpper=a},get_showSearch:function(){return this._showSearch},set_showSearch:function(a){this._showSearch=a},get_itemUrl:function(){return this._itemUrl},set_itemUrl:function(a){this._itemUrl=a},get_searchUrl:function(){return this._searchUrl},set_searchUrl:function(a){this._searchUrl=a},get_imgUrl:function(){return this._imageUrl},set_imgUrl:function(a){this._imageUrl=a},get_filters:function(){return this._filters},set_filters:function(a){this._filters=a},get_selectedIndex:function(){return this._selectedIndex},set_selectedIndex:function(a){if(a<0){a=0}if(a>=this._suggestionItems.length){a=this._suggestionItems.length-1}if(a==this._selectedIndex){return}this._toggleHighlight(a,true);this._toggleHighlight(this._selectedIndex,false);this._selectedIndex=a;this._toggleImage()},get_sort:function(){return[{Name:this._nameProp,Dir:1}]},add_suggestionSelect:function(a){this.get_events().addHandler("SuggestionSelect",a)},remove_suggestionSelect:function(a){this.get_events().removeHandler("SuggestionSelect",a)},raiseSuggestionSelect:function(c,d){var b=this.get_events().getHandler("SuggestionSelect");if(b){var a=new rb.BaseControl.DataEventArgs(c,d);b(this,a)}},add_suggestionSearch:function(a){this.get_events().addHandler("SuggestionSearch",a)},remove_suggestionSearch:function(a){this.get_events().removeHandler("SuggestionSearch",a)},raiseSuggestionSearch:function(c){var b=this.get_events().getHandler("SuggestionSearch");if(b){var a=new rb.SearchBox.TextChangedEventArgs(c);b(this,a)}},initialize:function(){rb.SearchBox.callBaseMethod(this,"initialize");this._buildSearchButton();this._buildTextBox();this._buildSuggestionList();this._buildImage();$addHandler(window,"resize",this._delegates.onWindowResize);this._suggestionAction=new rb.DelayedAction(this._delegates.requestSuggestions,this._suggDelay);this._resizeAction=new rb.DelayedAction(this._delegates.positionSuggestionList,this._resizeDelay)},_onLoad:function(b,a){rb.SearchBox.callBaseMethod(this,"_onLoad");this._positionSuggestionList();this._hideSuggestions(true);if(this._text.length>0){this._activateTextBox(this._text)}else{this._resetTextBox()}},dispose:function(){$clearHandlers(this._textBox);$clearHandlers(this._searchButton);$removeHandler(window,"resize",this._delegates.onWindowResize);rb.SearchBox.callBaseMethod(this,"dispose");this._delegates=null},_buildTextBox:function(){var a={type:"text",size:this._size,maxLength:this._maxlen};var b={focus:this._onTextBoxFocus,blur:this._onTextBoxBlur,keypress:this._onTextBoxKeyPress,keydown:this._onTextBoxKeyDown};this._textBox=this._createChildControl("input","searchBoxTextBox",null,a,b);this.get_element().appendChild(this._textBox)},_buildSearchButton:function(){if(this._showSearch){var a={click:this._onSearchClick};this._searchButton=this._createChildControl("div","searchButton","searchButton",null,a);this.get_element().appendChild(this._searchButton)}},_buildSuggestionList:function(){var a={click:this._onSuggestionListClick,mouseover:this._onSuggestionListMouseOver,mouseout:this._onSuggestionListMouseOut};this._suggestionList=this._createChildControl("ul","suggestionList","searchBoxSuggestionList",null,a);this._suggestionList.style.position="absolute";this.get_element().appendChild(this._suggestionList)},_positionSuggestionList:function(){var a=Sys.UI.DomElement.getBounds(this._textBox);this._suggestionList.style.top=(a.y+a.height)+"px";this._suggestionList.style.left=a.x+"px";this.placeOnTop(this._suggestionList,true);if(this._img){var b=rb.Pos.getBounds(this._img);this._img.style.left=(a.x-b.width)+"px";this._img.style.top=(a.y+a.height)+"px"}},_buildImage:function(){if(this._imgProp){this._img=this._createChildControl("img","searchImage");this._img.style.display="none";this._img.style.position="absolute";this._img.className="image";this.get_element().appendChild(this._img)}},_onWindowResize:function(){this._resizeAction.start()},_activateTextBox:function(a){this._textBox.className="textBoxActive";this._textBox.value=a;this._textBoxActive=true},_resetTextBox:function(){this._textBox.className="textBoxInitial";this._textBox.value=this._prompt;this._textBoxActive=false;this._suggestionPrefix=""},_requestSuggestions:function(){if(this._suggestionPrefix==this.get_text()){return}this._suggestionPrefix=this.get_text();if(this._suggestionPrefix.length==0){this._hideSuggestions();return}if(this._filters==null){this._filters={}}this._filters[this._nameProp]=this._suggestionPrefix;if(this.get_dataType()=="Title"){this._filters.ProductType=rb.ProductType.Movie;this._filters.FormatID=rb.ProductFormat.DVD}var a=new rb.Cache.Query(this.get_dataType(),"ID",1,this._maxsuggs);a.addStatement(this._filters,this.get_sort(),{beginsWith:!this._matchContains});rb.Cache.getData(a,this._delegates.onSuggestionsReceived,this._baseDelegates.onPMFailDelegate,true)},_onSuggestionsReceived:function(b,d){var e=b.Data;if(e.length==0){this._hideSuggestions();return}this._clearSuggestions();this._suggestions={};this._suggestionItems=[];var a;for(var c=0;c<e.length;c++){a=this._getItemKey(e[c]);this._suggestions[a]=e[c];this._suggestions[a].__index=c;this._addSuggestion(e[c])}if(this._suggestionItems.length>0){this._showSuggestions()}},_clearSuggestions:function(){this._suggestionList.innerHTML="";this._selectedIndex=-1;this._toggleImage()},_clearSelection:function(){this._toggleHighlight(this._selectedIndex,false);this._selectedIndex=-1;this._toggleImage()},_toggleImage:function(){if(this._img){this._setDisplay(this._img,(this._suggestionsVisible&&this._selectedIndex!=-1))}},_hideSuggestions:function(a){this.placeOnTop(this._suggestionList,false);if(this._anim!=null&&a!=true&&this._suggestionsVisible==true){this._positionSuggestionList();rb.dom.animate(this._suggestionList,this._anim.type,this._anim.odir,false,this._anim.etype,this._anim.edir,this._anim.len,this._anim.inte,null,this._delegates._listHidden)}else{this._listHidden()}this._suggestionsVisible=false;this._toggleImage()},_showSuggestions:function(a){this._suggestionList.style.display="";this.placeOnTop(this._suggestionList,true);if(this._anim!=null&&a!=true&&this._suggestionsVisible==false){this._positionSuggestionList();rb.dom.animate(this._suggestionList,this._anim.type,this._anim.odir,true,this._anim.etype,this._anim.edir,this._anim.len,this._anim.inte,null,this._delegates.listShown)}else{this._listShown()}this._suggestionsVisible=true;this._toggleImage()},_listShown:function(){},_listHidden:function(){this._suggestionList.style.display="none";this._clearSuggestions()},_addSuggestion:function(b){var a=new rb.SearchBox.Item(this,b);this._suggestionItems.push(a);this._suggestionList.appendChild(a.get_ctl())},_onTextBoxFocus:function(a,b){if(!this._textBoxActive){this._activateTextBox("")}this._textBox.select()},_onTextBoxBlur:function(a,b){if(a.target.value.length==0){this._resetTextBox()}setTimeout(this._delegates.hideSuggestions,250)},_onTextBoxKeyPress:function(a,b){if(a.charCode==Sys.UI.Key.enter){if(this._selectedIndex>-1){this._selectSuggestion(this._selectedIndex)}else{this._search(this.get_text())}this._hideSuggestions(true);a.stopPropagation();a.preventDefault()}},_onTextBoxKeyDown:function(a,b){this._suggestionAction.start();if(this._suggestionsVisible){if(a.keyCode==Sys.UI.Key.down){this._nextSuggestion()}else{if(a.keyCode==Sys.UI.Key.up){this._previousSuggestion()}else{if(a.keyCode==Sys.UI.Key.esc){this._hideSuggestions()}}}}},_onSearchClick:function(a,b){this._search(this.get_text())},_onSuggestionListClick:function(a,b){var c=this._suggestions[a.target.id];this._selectSuggestion(c.__index)},_onSuggestionListMouseOver:function(a,c){var b=this._suggestions[a.target.id];if(b!=null){this.set_selectedIndex(b.__index)}},_onSuggestionListMouseOut:function(a,b){this._clearSelection()},_selectSuggestion:function(b){var a=this._suggestionItems[b];if(a){var c=a.get_data();this.raiseSuggestionSelect(a.get_ctl(),a.get_data());this.set_text(c[this._nameProp]);this._hideSuggestions(true);this._suggestionAction.cancel();if(this._itemUrl!=null){document.location.href=String.format(this._itemUrl,c[this._idProp])}}},_search:function(a){a=a.trim();a=a.replace(/ +/g," ");if(this._showSearch){if(a.length<this._minChars){alert(this._minCharsErr);return}if(this._searchUrl!=null){document.location.href=String.format(this._searchUrl,a)}this.raiseSuggestionSearch(a)}},_nextSuggestion:function(){this.set_selectedIndex(this.get_selectedIndex()+1)},_previousSuggestion:function(){this.set_selectedIndex(this.get_selectedIndex()-1)},_toggleHighlight:function(c,a){var b=this._suggestionItems[c];if(b){b.toggleHighlight(a)}},_getItemKey:function(a){return"__sugg"+a[this._idProp]}};rb.SearchBox.registerClass("rb.SearchBox",rb.BaseControl);rb.SearchBox.Item=function(a,b){this._parent=a;this._data=b;this._selected=false;this._ctl=document.createElement("li");this._ctl.id=a._getItemKey(b);this._ctl.className="searchBoxSuggestion";this._ctl.innerHTML=b[a.get_nameProp()]};rb.SearchBox.Item.prototype={get_data:function(){return this._data},set_data:function(a){this._data=a},get_ctl:function(){return this._ctl},set_ctl:function(a){this._ctl=a},get_selected:function(){return this._selected},set_selected:function(a){this._selected=a},toggleHighlight:function(a){if(a){Sys.UI.DomElement.addCssClass(this._ctl,"suggestionHighlight")}else{Sys.UI.DomElement.removeCssClass(this._ctl,"suggestionHighlight")}if(this._parent._img&&a){this._parent._img.src=this._parent._imageUrl+this._data[this._parent._imgProp]}this._selected=a}};rb.SearchBox.Item.registerClass("rb.SearchBox.Item");rb.SearchBox.TextChangedEventArgs=function(a){this._text=a};rb.SearchBox.TextChangedEventArgs.prototype={get_text:function(){return this._text}};rb.SearchBox.TextChangedEventArgs.registerClass("rb.SearchBox.TextChangedEventArgs");