Type.registerNamespace("rb");rb.LocationSearch=function(a){rb.LocationSearch.initializeBase(this);this._locked=false;this._titleID=null;this._titleName=null;this._kioskID=null;this._kioskCache={};this._totalKiosks=0;this._kioskTemplateForList=null;this._kioskTemplateForInfoWindow=null;this._kioskTemplateForDirections=null;this._titleUrl=null;this._titleDetailUrl=null;this._cartUrl=null;this._cartItemCount=null;this._loc=null;this._locQuery=null;this._pageSize=null;this._currentPage=1;this._searchPane=null;this._directionsPane=null;this._locationText=null;this._onlyMcD=null;this._searchButton=null;this._selectedCtl=null;this._kioskItems=null;this._infoDiv=null;this._searchOpenCloseButton=null;this._searchFormBody=null;this._directionsResult=null;this._locationSearchBoxBack=null;this._locationSearchBox=null;this._locationSearchShown=false;this._locationText2=null;this._onlyMcD2=null;this._searchButton2=null;this._directionsBackButton=null;this._directionsSubmitButton=null;this._directionsStartBox=null;this._directionsShown=false;this._directionsLoc=null;this._directionsFormKiosk=null;this._routeTime=null;this._routeDistance=null;this._routeList=null;this._routeStart=null;this._routeEnd=null;this._googleClientID=null;this._googleKey=null;this._map=null;this._delegates={onKioskItemBind:Function.createDelegate(this,this._onKioskItemBind),onKioskItemClick:Function.createDelegate(this,this._onKioskItemClick),onAPILoaded:Function.createDelegate(this,this._onAPILoaded),onGeoCode:Function.createDelegate(this,this._onGeoCode),onDirections:Function.createDelegate(this,this._onDirections),onResultReceived:Function.createDelegate(this,this._onResultReceived),onMarkerShow:Function.createDelegate(this,this._onMarkerShow),onTitleAddedDelegate:Function.createDelegate(this,this._onTitleAdded),onPagingClickDelegate:Function.createDelegate(this,this._onPagingClick)};this._kioskTemplateDelegates={getKioskActionForList:Function.createDelegate(this,this._getKioskActionForList),getKioskActionForInfoWindow:Function.createDelegate(this,this._getKioskActionForInfoWindow),outsideOrInside:Function.createDelegate(this,this._outsideOrInside),getMarkerImagePath:Function.createDelegate(this,this._getMarkerImagePath)}};rb.LocationSearch.prototype={get_titleID:function(){return this._titleID},set_titleID:function(a){this._titleID=a},get_titleName:function(){return this._titleName},set_titleName:function(a){this._titleName=a},get_locQuery:function(){return this._locQuery},set_locQuery:function(a){this._locQuery=a},get_titleUrl:function(){return this._titleUrl},set_titleUrl:function(a){this._titleUrl=a},get_titleDetailUrl:function(){return this._titleDetailUrl},set_titleDetailUrl:function(a){this._titleDetailUrl=a},get_cartUrl:function(){return this._cartUrl},set_cartUrl:function(a){this._cartUrl=a},get_cartItemCount:function(){return this._cartItemCount},set_cartItemCount:function(a){this._cartItemCount=a},get_googleClientID:function(){return this._googleClientID},set_googleClientID:function(a){this._googleClientID=a},get_googleKey:function(){return this._googleKey},set_googleKey:function(a){this._googleKey=a},refresh:function(){if(this._directionsShown){if(this._directionsLoc){this.getDirections()}}else{if(this._loc&&this._kioskCache[this._currentPage]==null){this.getKiosks()}else{if(this._kioskCache[this._currentPage]!=null){this.bind()}}}},getKiosks:function(){this.lock();var a={latitude:this._loc.lat,longitude:this._loc.lng,radius:50,maxKiosks:50,mcdOnly:this._onlyMcD.checked,getInv:false,pageSize:this._pageSize,page:this._currentPage};if(this._locationSearchShown){a.mcdOnly=this._onlyMcD2.checked}if(this._titleID!=null){a.titleID=this._titleID}rb.Ajax.invoke("Kiosk","GetNearbyKiosks","",a,this._delegates.onResultReceived,this._baseDelegates.onPMFailDelegate)},clearKiosks:function(){this._kioskID=null;this._kioskCache={};this._totalKiosks=0},getDirections:function(){this.lock();var c=this._map.getMapPoint("startDir",this._directionsLoc.lat,this._directionsLoc.lng,this._map.getMarkerImage(rb.Util.getPath()+"/images/markers/dir_start.gif",24,22,11,12,11,12));var b=this._getKiosk(this._kioskID);var a=this._map.getMapPoint("endDir",b.Lat,b.Lng,this._map.getMarkerImage(rb.Util.getPath()+"/images/markers/dir_end.gif",24,22,11,12,11,12));this._map.updateMap([c,a]);this._map.getDirections(c,a)},bind:function(){if(!this._kioskCache[this._currentPage]){return}var a=new rb.Cache.PagedData(this._currentPage,this._pageSize,this._kioskCache[this._currentPage].profiles,true,this._totalKiosks);this.bindMap(a);this.bindList(a)},bindMap:function(c){var b=[];b.push(this._map.getMapPoint("searchLoc",this._loc.lat,this._loc.lng,this._map.getMarkerImage(rb.Util.getPath()+"/images/markers/star.gif",20,20,10,10,10,10)));for(var a=0;a<c.Data.length;a++){b.push(this._map.getMapPoint(c.Data[a].ID,c.Data[a].Lat,c.Data[a].Lng,this._map.getMarkerImage(this._getMarkerImagePath(c.Data[a]),25,34,12,17,12,17)))}this._map.updateMap(b)},bindRoute:function(b){if(!b){return}this._routeStart.innerHTML=this._directionsLoc.address;this._routeEnd.innerHTML=rb.Util.tokenReplace(this._getKioskTemplateForDirections(),this._getKiosk(this._kioskID));var a="";for(var c=0;c<b.steps.length;c++){a+="<li>"+b.steps[c].html+"</li>"}this._routeTime.innerHTML=b.time;this._routeDistance.innerHTML=b.distance;this._routeList.innerHTML=a;this._setDisplay(this._directionsResult,true)},bindList:function(a){this._kioskItems=[];this._viewer.bind(a);this._setListScroll()},toggleSearchFormState:function(){var a="open";var b="closed";if(Sys.UI.DomElement.containsCssClass(this._searchPane,"closed")){var a="closed";var b="open"}Sys.UI.DomElement.removeCssClass(this._searchPane,a);Sys.UI.DomElement.addCssClass(this._searchPane,b)},searchAddress:function(){this.lock();if(this._locationSearchShown){this._locQuery=this._locationText2.value;this._map.findAddress(this._locQuery);this._locationText.value=this._locQuery;this._onlyMcD.checked=this._onlyMcD2.checked}else{this._locQuery=this._locationText.value;this._map.findAddress(this._locQuery)}},searchAddressForDirections:function(){this.lock();var a=this._directionsStartBox.value;if(this._locQuery==a){this._directionsLoc=this._loc;this.getDirections()}else{this._map.findAddress(a)}},selectKiosk:function(b){var a=this._kioskItems[b];if(this._selectedCtl!=null){Sys.UI.DomElement.removeCssClass(this._selectedCtl,"selected")}this._selectedCtl=a;Sys.UI.DomElement.addCssClass(a,"selected")},showOrHideDirections:function(a){this._setDisplay(this._searchPane,!a);this._setDisplay(this._directionsPane,a);if(a){this._directionsStartBox.value=this._locationText.value;var b=this._getKiosk(this._kioskID);this._directionsFormKiosk.innerHTML=rb.Util.tokenReplace(this._getKioskTemplateForDirections(),b);this.searchAddressForDirections();this._directionsShown=true}else{this._directionsShown=false;this.bind();if(this._kioskID){this.selectKiosk(this._kioskID);this._setListScroll(this._kioskID)}}},lock:function(){this._locked=true;this._getControl("imgProgress").style.display=""},unlock:function(){this._locked=false;this._getControl("imgProgress").style.display="none"},showLocationSearchBox:function(a){if(a){this._locationSearchBoxBack.style.display="";this._locationSearchBox.style.display="";this._positionSearchBox()}else{this._locationSearchBox.style.display="none";this._locationSearchBoxBack.style.display="none"}this._locationSearchShown=a},_positionSearchBox:function(){var b=Sys.UI.DomElement.getBounds(this._getControl("mapPane"));this._locationSearchBoxBack.style.width=b.width+"px";this._locationSearchBoxBack.style.height=b.height+"px";this._locationSearchBoxBack.style.top=b.y+"px";this._locationSearchBoxBack.style.left=b.x+"px";var a=Sys.UI.DomElement.getBounds(this._locationSearchBox);this._locationSearchBox.style.top=(b.y+(b.height/2))-(a.height/2)+"px";this._locationSearchBox.style.left=(b.x+(b.width/2))-(a.width/2)+"px"},_onLoad:function(b,a){rb.LocationSearch.callBaseMethod(this,"_onLoad");this._map=new rb.Map(this._googleClientID,this._googleKey,{disableDefaultUI:true});this._map.addEventHandler("onAPILoaded",this._delegates.onAPILoaded);this._map.addEventHandler("onGeoCode",this._delegates.onGeoCode);this._map.addEventHandler("onMarkerShow",this._delegates.onMarkerShow);this._map.addEventHandler("onDirections",this._delegates.onDirections);this._map.loadAPI();this._searchPane=this._getControl("searchPane");this._directionsPane=this._getControl("directionsPane");this._viewer=$find("plvKiosk");this._viewer.set_itemTemplate(this._getKioskTemplateForList());this._viewer.set_itemTemplateDelegates(this._kioskTemplateDelegates);this._viewer.add_itemDataBind(this._delegates.onKioskItemBind);this._viewer.add_itemClick(this._delegates.onKioskItemClick);this._viewer.add_pagingClick(this._delegates.onPagingClickDelegate);this._pageSize=this._viewer.get_pageSize();this._searchOpenCloseButton=this._getControl("btnSearchOpenClose");this._searchFormBody=this._getControl("kioskSearchFormBody");this._locationText=this._getControl("txtSearchLocation");this._onlyMcD=this._getControl("chkOnlyMcD");this._searchButton=this._getControl("button_btnSearch");this._locationText2=this._getControl("locationDialog_txtSearchLocation2");this._onlyMcD2=this._getControl("chkOnlyMcD2");this._searchButton2=this._getControl("button_btnSearch2");this._locationSearchBoxBack=this._getControl("locationSearchBoxBack");this._locationSearchBox=this._getControl("locationSearchBox");this._directionsResult=this._getControl("directionsResult");this._directionsBackButton=this._getControl("button_btnDirectionsBack");this._directionsSubmitButton=this._getControl("button_btnDirectionsSubmit");this._directionsStartBox=this._getControl("txtDirectionsStart");this._directionsFormKiosk=this._getControl("directionsFormKiosk");this._routeTime=this._getControl("routeTime");this._routeDistance=this._getControl("routeDistance");this._routeList=this._getControl("routeList");this._routeStart=this._getControl("routeStart");this._routeEnd=this._getControl("routeEnd");$addHandlers(this._locationText,{keypress:this._onAddressKeyPress,keyup:this._onAddressKeyUp},this);$addHandlers(this._searchButton,{click:this._onSearchClick},this);$addHandlers(window,{resize:this._positionSearchBox},this);$addHandlers(this._locationText2,{keypress:this._onAddressKeyPress,keyup:this._onAddressKeyUp},this);$addHandlers(this._searchButton2,{click:this._onSearchClick},this);$addHandlers(this._getControl("locationDialog_searchBoxClose"),{click:this._closeLightbox},this);$addHandlers(this._searchOpenCloseButton,{click:this._onSearchOpenCloseClick},this);$addHandlers(this._directionsBackButton,{click:this._onDirectionsBackClick},this);$addHandlers(this._directionsSubmitButton,{click:this._onDirectionsSubmitClick},this);$addHandlers(this._directionsStartBox,{keypress:this._onAddressKeyPress,keyup:this._onAddressKeyUp},this);if(this._locQuery!=null){this._locationText.value=this._locQuery}this._locationText.focus();this._handleButtonEnabled();rb.Recording.RecordPage("Find A Redbox","Location Search")},_onAPILoaded:function(b,a){this._map.initMap("mapCanvas");if(this._locQuery!=null){this.searchAddress()}},_onAddressKeyPress:function(a){if(this._locked){return}if(a.charCode==Sys.UI.Key.enter){if(this._handleButtonEnabled()){if(this._directionsShown){this.searchAddressForDirections()}else{this.searchAddress()}}a.preventDefault()}if(a.charCode==Sys.UI.Key.esc){this._closeLightbox();a.preventDefault()}},_onAddressKeyUp:function(a){this._handleButtonEnabled()},_closeLightbox:function(){this.showLocationSearchBox(false);this._locationText.focus();this._handleButtonEnabled()},_onKioskItemClick:function(a,b){if(this._locked){return}var d=b.get_data();var c=this._getAction(b.get_ctls());this._handleKioskAction(c,d.ID)},_onPagingClick:function(c,a){if(this._locked){return}var b=this._currentPage+a.get_dir();if(b>0){this._currentPage=b;this.refresh()}},_handleKioskAction:function(a,b){if(this._locked){return}if(!a){return}if(b!=null){this._kioskID=b}switch(a){case"view":this._viewTitlesAtKiosk();break;case"rent":this._reserveTitle();break;case"select":this.selectKiosk(b);this._map.showMarker(b);break;case"directions":var c=this._getKiosk(this._kioskID);if(c&&c.Drv){this.showOrHideDirections(true)}break;case"titleDetail":this._viewTitleDetail();break}},_onSearchClick:function(b,a){if(this._locked){return}if(this._handleButtonEnabled()){this.clearKiosks();this.searchAddress()}},_onSearchOpenCloseClick:function(b,a){if(this._locked){return}this.toggleSearchFormState()},_onKioskItemBind:function(a,c){var d=c.get_ctl();var g=c.get_data();this._kioskItems[g.ID]=d;var e=$get("items"+g.ID,d);if(g.Drv==false){var f=$get("dd"+g.ID,d);var b=$get("dda"+g.ID,d);f.className="noDirections";f.title=this.Res.NoDrivingDirections}if(this._originalItemCss==null){this._originalItemCss=d.className}d.className=this._originalItemCss},_onGeoCode:function(b,a){if(this._directionsShown){this._directionsLoc=a;this.getDirections()}else{this._loc=a;this.getKiosks()}},_onDirections:function(b,a){this.bindRoute(a);this.unlock()},_onMarkerShow:function(g,b){var a=document.createElement("div");a.className="infoWindow";if(b.ID=="searchLoc"){a.innerHTML=String.format('<br/><div class="address">{0}</div>',this._loc.address)}else{this._kioskID=b.ID;var e=this._getKiosk(this._kioskID);var d=this._getKioskState(this._kioskID);this.selectKiosk(this._kioskID);if(b.clicked){this._setListScroll(this._kioskID)}a.innerHTML=rb.Util.tokenReplace(this._getKioskTemplateForInfoWindow(),e,this._kioskTemplateDelegates);if(e.Drv==false){var f=$get("ddInfo"+e.ID,a);var c=$get("ddaInfo"+e.ID,a);f.className="noDirections";f.title=this.Res.NoDrivingDirections}$addHandlers(a,{click:this._onInfoWindowClick},this)}this._map.showMarkerInfo(g,a)},_onInfoWindowClick:function(c,a){if(this._locked){return}var b=this._getInfoWindowAction(c.target);this._handleKioskAction(b)},_onDirectionsBackClick:function(b,a){if(this._locked){return}this.showOrHideDirections(false)},_onDirectionsSubmitClick:function(b,a){if(this._locked){return}this.searchAddressForDirections()},_getInfoWindowAction:function(b){if(Sys.UI.DomElement.containsCssClass(b,"infoWindow")){return null}var a=b.getAttribute("action");if(a){return a}else{return this._getInfoWindowAction(b.parentNode)}},_viewTitlesAtKiosk:function(){this.navigate(String.format(this._titleUrl,this._kioskID));this._recordSelectKiosk()},_viewTitleDetail:function(){this.navigate(String.format(this._titleDetailUrl,this._kioskID,this._titleID));this._recordSelectKiosk()},_reserveTitle:function(){this.lock();this._viewer.set_locked(true);rb.Ajax.invoke("Cart","AddItem",this._titleID,{buy:false,kiosk:this._kioskID},this._delegates.onTitleAddedDelegate,this._baseDelegates.onPMFailDelegate);this._recordAddItem()},_onResultReceived:function(b,c,a){this.unlock();if(this._locationSearchShown){this.showLocationSearchBox(false)}this._cacheKioskData(b);this._totalKiosks=b.totalKiosks;this.bind();this._recordSearchResult()},_handleButtonEnabled:function(){if(this._map.hasClientLocation()){return true}var b;var c;if(this._locationSearchShown){b=this._locationText2;c=this._searchButton2}else{if(this._directionsShown){b=this._directionsStartBox;c=this._directionsSubmitButton}else{b=this._locationText;c=this._searchButton}}var d=(b.value.length>0?"disabledButton":"defaultButton");var a=(b.value.length>0?"defaultButton":"disabledButton");Sys.UI.DomElement.removeCssClass(c,d);Sys.UI.DomElement.addCssClass(c,a);return b.value.length>0},_onTitleAdded:function(b,c,a){this._viewer.set_locked(false);rb.Util.updateCartQty(1);this.navigate(this._cartUrl)},_getKioskTemplateForList:function(){if(!this._kioskTemplate){this._kioskTemplate='<div id="k$[ID]"><div class="marker"><a action="select"><img src="$[getMarkerImagePath]"/></a></div>'+String.format('<div class="distance">$[Dist] {0}</div>',this.Res.Miles)+'<div class="locationBody"><div class="vendor"><a action="select">$[Vdr]</a> ($[outsideOrInside])</div><div class="address">$[Name]</div><div class="address">$[Addr]</div><div class="address">$[City], $[St] $[Zip]</div><div class="button">$[getKioskActionForList]</div>'+String.format('<div id="dd$[ID]" class="directionsLink"><a id="dda$[ID]" action="directions">{0}</a></div>',this.Res.GetDirections)+"</div></div>"}return this._kioskTemplate},_getKioskTemplateForInfoWindow:function(){if(!this._kioskTemplateForInfoWindow){this._kioskTemplateForInfoWindow='<div class="vendor">$[Vdr] ($[outsideOrInside])</div><div class="address">$[Name]</div><div class="address">$[Addr]</div><div class="cityStateZip">$[City], $[St] $[Zip]</div><div class="button">$[getKioskActionForInfoWindow]</div>'+String.format('<div id="ddInfo$[ID]" class="directionsLink"><a id="ddaInfo$[ID]" action="directions">{0}</a></div>',this.Res.GetDirections)}return this._kioskTemplateForInfoWindow},_getKioskTemplateForDirections:function(){if(!this._kioskTemplateForDirections){this._kioskTemplateForDirections='<div class="vendor">$[Vdr]</div><div class="address">$[Addr]</div><div class="address">$[City], $[St] $[Zip]</div>'}return this._kioskTemplateForDirections},_getKioskActionForList:function(a){return this._getKioskAction(a,false)},_getKioskActionForInfoWindow:function(a){return this._getKioskAction(a,true)},_getKioskAction:function(c,d){var a=this._getKioskState(c.ID);if(a!=null&&a.Online){if(this._titleID!=null){if(this._kioskHasTitle(a.Inv,this._titleID)){var b=this._getButtonMarkup(this.Res.Rent,"smallRedButton fixedSizeButton","rent");if(d){return String.format('<div class="rentBlock"><div class="titleName"><a action="titleDetail">{0}</a></div>{1}</div>',this._titleName,b)}else{return b}}else{return String.format('<div class="checkedOut">{0}</div><div class="otherTitlesLink"><a action="view">{1}</a></div>',this.Res.CheckedOut,this.Res.ViewOtherTitles)}}else{return this._getButtonMarkup(this.Res.ViewTitlesHere,"smallRedButton fixedSizeButton","view")}}else{return String.format('<div class="offline">{0}</div>',this.Res.NoOnlineRental)}},_getButtonMarkup:function(c,b,a){return String.format('<table cellspacing="0" cellpadding="0"><tr><td>{0}</td></tr></table>',this._getActionStyledImageMarkup(c,b,a))},_kioskHasTitle:function(a,b){if(a==null){return false}for(var c=0;c<a.length;c++){if(a[c].ID==b){return a[c].Qty>0}}return false},_outsideOrInside:function(a){return a.Ind?this.Res.Inside:this.Res.Outside},_getMarkerImagePath:function(c){var a=this._getKioskState(c.ID);var b="off";if(a!=null&&a.Online){b="on"}return String.format("{0}images/markers/marker_{1}_{2}.gif",rb.Util.getPath(),b,c._Idx)},_getKioskLocation:function(b){var a=this._getKiosk(this._kioskID);return{lat:a.Lat,lng:a.Lng,addressHTML:rb.Util.tokenReplace(this._getKioskTemplateForDirections(),a)}},_cacheKioskData:function(a){this._kioskCache[a.page]={profiles:a.profiles,profileDict:a.profiles.toDictionary("ID"),stateDict:a.states.toDictionary("KioskID")}},_getKiosk:function(a){if(this._kioskCache[this._currentPage]){return this._kioskCache[this._currentPage].profileDict[a]}return null},_getKioskState:function(a){if(this._kioskCache[this._currentPage]){return this._kioskCache[this._currentPage].stateDict[a]}return null},_setListScroll:function(b){if(b){var a=this._kioskItems[b];if(a.scrollIntoView){a.scrollIntoView(true)}}else{this._getControl("locationList").scrollTop=0}},_recordSearchResult:function(){var b={};var a=[];b.prop14=this._totalKiosks;b.prop15=this._locQuery;a.push("event14");rb.Recording.RecordAction("Location Search Results",b,a)},_recordSelectKiosk:function(a){var a=this._getKiosk(this._kioskID);if(!a){return}var b={prop6:a.Vdr,prop7:a.City+", "+a.St,prop13:a.Zip,state:a.St,zip:a.Zip};rb.Recording.RecordAction("Select a Redbox",b)},_recordAddItem:function(){var a=["scAdd"];if(this._cartItemCount==0){a.push("scOpen")}rb.Recording.RecordAction("Add to Cart",{products:";"+this._titleID},a)},dispose:function(){this._delegates=null;this._kioskTemplateDelegates=null;this._kioskItems=null;if(this._infoDiv!=null){$clearHandlers(this._infoDiv)}this._infoDiv=null;rb.LocationSearch.callBaseMethod(this,"dispose")}};rb.LocationSearch.registerClass("rb.LocationSearch",rb.ClientBase);