var WhereToBuy = { TabContainerObject: function() { return $find(PageIDs.TabContainer); }, TabContainerElement: function() { return $('#' + PageIDs.TabContainer).get(0); }, TabElementObject: function() { return $find(PageIDs.TabWhereToBuy); }, TabElementContext: function() { return $('#' + PageIDs.TabWhereToBuy); }, Activate: function() { this.TabContainerObject().set_activeTab(this.TabElementObject()); this.TabContainerElement().scrollIntoView(true); } } var Krillion = { HasProduct: function(_productId) { var retValue = false; jQuery.ajax( { type: "post", url: "krillionservice.asmx/ConfirmProduct", contentType: "application/json", data: jQuery.toJSON( { productId: "" + _productId } ), dataType: "json", async: false, cache: false, success: function (data) { retValue = data.d; }/*, error: function (XMLHttpRequest, textStatus, errorThrown) {}, complete: function (XMLHttpRequest, textStatus) {}*/ } ); return retValue; }, GetProductAsync: function(_productId, _zipCode, _callback) { jQuery.ajax( { type: "post", url: "krillionservice.asmx/GetAvailableRetailers", contentType: "application/json; charset=utf-8", data: jQuery.toJSON( { productId: "" + _productId, zipCode: "" + _zipCode } ), dataType: "json", async: true, cache: false, success: function (data) { _callback(data); }/*, error: function (XMLHttpRequest, textStatus, errorThrown) {}*/, complete: function (XMLHttpRequest, textStatus) { KrillionUI.LoadingIndicator.Hide(); } } ); } } var KrillionUI = { ShowAll: true, JSONObject: null, ProductId: null, ZipCode: null, NumRetailers: 0, Init: function() { GMarker.prototype.IconIndex = -1; GMarker.prototype.label = null; }, AddRetailer: function(inventoryItem, filter, itemNum) { var location = null; var html = ""; var x = 0; do { if(x >= inventoryItem.LocationsWithAvailability.LocationAvailabilityList.length) return false; location = inventoryItem.LocationsWithAvailability.LocationAvailabilityList[x++] } while(filter == "1" && location.Availability.Status != "in_stock" && location.Availability.ProductBuyUrl.Type != "buyOnline"); x--; //point to current location var numLoc = inventoryItem.LocationsWithAvailability.LocationAvailabilityList.length; if(filter == "1") { numLoc = 0; for(var i = x; i < inventoryItem.LocationsWithAvailability.LocationAvailabilityList.length; i++) if(!(location.Availability.Status != "in_stock" && location.Availability.ProductBuyUrl.Type != "buyOnline")) numLoc++; } for(var i = x; i < inventoryItem.LocationsWithAvailability.LocationAvailabilityList.length; i++) { if(filter == "1" && location.Availability.Status != "in_stock" && location.Availability.ProductBuyUrl.Type != "buyOnline") continue; //var xp = "inventoryItem[@index=" + inventoryItem.Index + "]/locationsWithAvailability/locationWithAvailability[@index=" + location.Index + "]"; var status = { imgsrc: null, row1: null, row2: null, row3: null }; status.imgsrc = ""; if(location.Availability.Status == "in_stock") status.row1 = "Available"; else if(location.Availability.Status != "in_stock" && location.Availability.ProductBuyUrl.Type == "buyOnline") { status.row1 = "Available Online"; if(location.Availability.Status == "out_of_stock" || location.Availability.Status == "ship_to_store") status.row2 = "Out-Of-Stock Locally"; if(location.Availability.Status != "ship_to_store") status.row3 = "Ship to Store Delivery Available"; } else { //location.Availability.Status == "unknown" etc. status.row1 = "Contact Store"; status.imgsrc = ""; } var statustxt = "
" + "
\"\"" + status.row1 + "
" + (status.row2 == null ? "" : "" + status.row2 + "") + "
" + (status.row3 == null ? "" : "
" + status.row3 + "
"); var hasStoreNumber = (location.Location.Address.StoreNumber && location.Location.Address.StoreNumber != '' && location.Location.Address.StoreNumber != null && location.Location.Address.StoreNumber != undefined); var hasStoreCode = (location.Location.StoreCode && location.Location.StoreCode != '' && location.Location.StoreCode != null && location.Location.StoreCode != undefined); var rowId = (hasStoreNumber ? location.Location.Address.StoreNumber : (hasStoreCode ? location.Location.StoreCode : "")); var retailerName = (hasStoreNumber ? inventoryItem.Retailer.Name : inventoryItem.Retailer.Code); if((retailerName == null || retailerName.length == 0) && inventoryItem.Retailer.Name && inventoryItem.Retailer.Name.length > 0) retailerName = inventoryItem.Retailer.Name; html += " x ? " class=\"additionallocation forceprint\"" : "") + ((rowId.length > 0) ? (" id=\"rr_" + escape(rowId) + "\"") : "") + ">" + "" + (inventoryItem.Retailer.LogoUrl == null || i > x ? "" : "\""") + "" + "" + " x ? " topborder" : "") + "\" style=\"width: 475px;\">
" + /*250px*/ location.Location.Address.StoreName + ((location.Location.Address.StoreLabel != null && location.Location.Address.StoreLabel.length > 0) ? " - " + location.Location.Address.StoreLabel : "") + "
" + location.Location.Address.Street1 + "
" + location.Location.Address.City + ", " + location.Location.Address.State + " " + location.Location.Address.Zip + "
" + /*"Click for phone number
" +*/ "
" + location.Location.Phone + "
" + (location.Location.StoreUrl && location.Location.StoreUrl.length > 0 ? "Visit the " + location.Location.Address.StoreName + " website

" : "
") + "\"\"Distance to the location - " + location.Location.Distance + " mi" + "
" + /*" x ? " topborder" : "") + "\" style=\"width: 225px;\">
" + statustxt + "
" +*/ " x ? " topborder" : "") + " noprint\" style=\"width: 170px;\">
" + (location.Availability.ProductBuyUrl.Url != null ? "" + PageData.SeeApplianceButton + "
" : "") + "
" + " x ? " topborder" : "") + " noprint\" style=\"width: 115px; border-right: none;\">" + "
" + (rowId.length > 0 && retailerName && retailerName.length > 0 ? "Email A Friend
Text To Cell
" : "" ) + "View Map
" + "" + "" + (i == x && numLoc-1 > x ? "" + " x ? " topborder" : "") + " noprint\" colspan=\"3\">
[+] Click to view " + (numLoc-1) + " more " + location.Location.Address.StoreName + " locations
" + "" : "" ); //data=\"" + $.toJSON({ num : (inventoryItem.LocationsWithAvailability.LocationAvailabilityList.length - 1), storeName: location.Location.Address.StoreName }).replace(/\"/g,"|!|") + "\" //next location = inventoryItem.LocationsWithAvailability.LocationAvailabilityList[i+1]; } html += ""; $("#wtb_retailers").append(html); this.NumRetailers++; return true; }, UpdateProduct: function(data) { var num = 0; if(!(data.d.Response == null || data.d.Response.InventoryItems.InventoryItemList == null)) { num = data.d.Response.InventoryItems.InventoryItemList.length; } $("#wtb_results").html("You have searched for " + KrillionUI.ZipCode + " and we have found " + num + " results."); $("#wtb_results").show(); if(data.d.Response == null || data.d.Response.InventoryItems.InventoryItemList == null || data.d.Response.InventoryItems.InventoryItemList.length == 0) return; this.JSONObject = data.d.Response; this.LoadingIndicator.Hide(); this.NumRetailers = 0; $("#wtb_options").show(); this.ApplyFilter($('#show_filter').attr('value')); this.UpdateView(); }, ApplyFilter: function(filter) { $("#wtb_retailers").html(""); this.NumRetailers = 0; var retval = false; for(var i = 0; i < this.JSONObject.InventoryItems.InventoryItemList.length; i++) { if(this.AddRetailer(this.JSONObject.InventoryItems.InventoryItemList[i], filter, i) == true) retval = true; } if(retval == false) $("#wtb_retailers").html("No locations matching current filter..."); }, DoUpdate: function() { var productId = $('#' + PageIDs.ModelD).attr("value").toLowerCase(); var zipCode = $('#' + PageIDs.ZipCode2).attr("value").toLowerCase();//.replace(/\s+/g, ''); if(productId != "" && this.ValidateZip(zipCode) && KrillionUI.ZipCode != zipCode) { KrillionUI.ProductId = productId; KrillionUI.ZipCode = zipCode; KrillionUI.ShowAll = true; KrillionUI.SetShowAllLabel($("#wtb_expandAll").get()[0]); $('#show_filter').attr("value", "0"); KrillionUI.ResetView(); KrillionUI.LoadingIndicator.Show(); Krillion.GetProductAsync(KrillionUI.ProductId, KrillionUI.ZipCode, function(data) { KrillionUI.UpdateProduct(data); }); } }, ValidateZip: function(zip) { if(/^[0-9]{5}([- \/]{0,1}[0-9]{4})?$/.test(zip) == true) { $('#user_zipCode2_error').hide(); return true; } else { $('#user_zipCode2_error').show(); return false; } }, ToggleAllRetailers: function(obj) { var al = $('.retailer a.toggleretailer'); al.each(function() { KrillionUI.ToggleRetailer(this, KrillionUI.ShowAll); }); KrillionUI.ShowAll = (KrillionUI.ShowAll != true); KrillionUI.SetShowAllLabel(obj); }, SetShowAllLabel : function(obj) { if(!KrillionUI.ShowAll) obj.innerHTML = "Collapse All"; else obj.innerHTML = "Expand All"; }, ToggleRetailer: function(link, show) { //var parameters = $.secureEvalJSON(link.getAttribute("data").replace(/\|!\|/g, "\"")); var loc = this.JSONObject.InventoryItems.InventoryItemList[parseInt(link.getAttribute("id").match(/toggleretailer\-([0-9]+)/)[1])]; var parameters = { num: (loc.LocationsWithAvailability.LocationAvailabilityList.length - 1), retailerName: loc.LocationsWithAvailability.LocationAvailabilityList[0].Location.Address.StoreName }; var al = $(link).closest('table').find('tr.additionallocation'); /*if(show) al.toggle(show); else al.toggle();*/ if(show != undefined) { if(show) { al.show(); } else { al.hide(); } } else if(al.is(":hidden") || al.eq(0).css("display") == "none") { al.show(); } else { al.hide(); } $(link).html((al.css("display") == "none" ? "[+] Click to view " + parameters.num + " more " + parameters.retailerName + " locations" : "[-] Click to hide all " + parameters.retailerName + " locations")); }, GMap: null, //GEOCache: null, //GEOCoder: null, CurrentView: 0, IconArray : ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"], markers : null, ResetView: function() { this.GMap = null; GUnload(); this.markers = null; $(".retailer tr").removeClass("map-selected"); $("#map_canvas").hide(); }, SetView: function(id) { this.CurrentView = parseInt(id); this.UpdateView(); }, UpdateView: function() { if(this.CurrentView == 0) { //list view $("input[name=show_as]")[0].checked = true; $("input[name=show_as]")[1].checked = false; $(".retailer tr").removeClass("map-selected"); $("#map_canvas").hide(); $(".distance").children(".marker").hide(); } else if(this.CurrentView == 1) { //map view $("input[name=show_as]")[0].checked = false; $("input[name=show_as]")[1].checked = true; if(GBrowserIsCompatible() && this.ZipCode != null) { var k = 0; this.markers = new Array(); for(var i = 0, l = this.JSONObject.InventoryItems.InventoryItemList.length; i < l; i++) { for(var x = 0, l2 = this.JSONObject.InventoryItems.InventoryItemList[i].LocationsWithAvailability.LocationAvailabilityList.length; x < l2; x++) { var location = this.JSONObject.InventoryItems.InventoryItemList[i].LocationsWithAvailability.LocationAvailabilityList[x]; if($('#show_filter').attr('value') == "1" && location.Availability.Status != "in_stock" && location.Availability.ProductBuyUrl.Type != "buyOnline") continue; var geo = location.Location.GeoCode; var lat = geo.Latitude * (180 / Math.PI), lng = geo.Longitude * (180 / Math.PI); this.markers[k] = this.CreateMarker(lat, lng, k, location.Location.Address.StoreName + ((location.Location.Address.StoreLabel != null && location.Location.Address.StoreLabel.length > 0) ? " - " + location.Location.Address.StoreLabel : "")); this.markers[k].location = location.Location; this.markers[k].label = (k+1 <= this.IconArray.length ? this.IconArray[k] : null); k++; } } if(this.GMap == null) { //init map this.GMap = new GMap2($("#map_canvas").get()[0], { size: new GSize(parseInt($("#map_canvas").css("width")), parseInt($("#map_canvas").css("height"))) }); var bz = this.GetMarkerBoundsAndZoom(this.markers); this.GMap.setCenter(bz.bounds.getCenter(), bz.zoom); //this.GEOCache = new GGeocodeCache(); //this.GEOCoder = new GClientGeocoder(this.GEOCache); KrillionUI.GMap.setUIToDefault(); } this.GMap.clearOverlays(); for(var i = 0; i < this.markers.length; i++) { var location = this.markers[i].location; this.GMap.addOverlay(this.markers[i]); var hasStoreNumber = (location.Address.StoreNumber && location.Address.StoreNumber != ''); var hasStoreCode = (location.StoreCode && location.StoreCode != ''); var rowId = (hasStoreNumber ? location.Address.StoreNumber : (hasStoreCode ? location.StoreCode : "")); var retailerRow = $("#rr_" + escape(rowId)); KrillionUI.BindShowMarkerInfoBox(this.markers[i], retailerRow); KrillionUI.BindShowSelectedRetailerRow(this.markers[i], retailerRow); KrillionUI.DisplayMarkerOnRetailer(retailerRow, this.markers[i]); this.markers[i].bindInfoWindowHtml("

" + location.Address.StoreName + ((location.Address.StoreLabel != null && location.Address.StoreLabel.length > 0) ? " - " + location.Address.StoreLabel : "") + "


" + location.Address.Street1 + "
" + location.Address.City + ", " + location.Address.State + " " + location.Address.Zip + "
" + "" + location.Phone + "

" + "Distance to the location - " + location.Distance + " mi" ); } $("#map_canvas").show(); } } }, DisplayMarkerOnRetailer: function(retailer, marker) { if(marker.IconIndex < 0) return; var m = $(retailer).find(".distance").children(".marker"); m.attr("src", marker.getIcon().image); m.show(); }, CreateMarker: function(lat, lng, index, title) { var point = new GLatLng(lat, lng, false); var markerIcon = new GIcon(G_DEFAULT_ICON); if(index + 1 <= this.IconArray.length) markerIcon.image = "http://www.google.com/intl/en_ALL/mapfiles/marker"+this.IconArray[index]+".png"; var marker = new GMarker(point, { title: title, icon: markerIcon }); if(index + 1 <= this.IconArray.length) marker.IconIndex = index; else marker.IconIndex = -1; return marker; }, GetMarkerBoundsAndZoom: function(markers) { var minLat = null, minLng = null, maxLat = null, maxLng = null; for(var i = 0; i < markers.length; i++) { var lat = markers[i].getLatLng().lat(); var lng = markers[i].getLatLng().lng(); if(lat > maxLat || i == 0) maxLat = lat; if(lat < minLat || i == 0) minLat = lat; if(lng > maxLng || i == 0) maxLng = lng; if(lng < minLng || i == 0) minLng = lng; } var div = document.createElement("div"); var map = new GMap2(div, { size: new GSize(parseInt($("#map_canvas").css("width")), parseInt($("#map_canvas").css("height"))) }); var paddingDeg = 0.005; var bounds = new GLatLngBounds(new GLatLng(minLat-paddingDeg, minLng-paddingDeg), new GLatLng(maxLat+paddingDeg, maxLng+paddingDeg)); var zoomFit = map.getBoundsZoomLevel(bounds); delete map; delete div; return { bounds: bounds, zoom: zoomFit }; }, BindShowMarkerInfoBox: function(marker, retailerRow) { if(retailerRow) { retailerRow.bind("click", function() { if(KrillionUI.CurrentView == 1 && KrillionUI.GMap != null && marker) { GEvent.trigger(marker, "click"); $("#map_canvas").get(0).scrollIntoView(true); } } ); } }, BindShowSelectedRetailerRow: function(marker, retailerRow) { if(marker && retailerRow) GEvent.addListener(marker, "click", function() { KrillionUI.ShowSelectedRetailerRow(retailerRow); }); }, ShowSelectedRetailerRow: function(retailerRow) { $(".retailer tr").removeClass("map-selected"); if(retailerRow) { retailerRow.addClass("map-selected"); var toggle = $("#" + retailerRow.attr("id") + "_toggle"); if(toggle) toggle.addClass("map-selected"); } }, GenerateStaticUrlFromGMap2: function(gmap2) { var center = gmap2.getCenter().toUrlValue(); var zoom = gmap2.getZoom(); var size = (gmap2.getSize().width > 640 ? 640 : gmap2.getSize().width) + "x" + gmap2.getSize().height; //current gmap static limit is 640x640 var maptype = "roadmap"; if(gmap2.getCurrentMapType() === G_NORMAL_MAP) maptype = "roadmap"; else if(gmap2.getCurrentMapType() === G_SATELLITE_MAP) maptype = "satellite"; else if(gmap2.getCurrentMapType() === G_PHYSICAL_MAP) maptype = "terrain"; else if(gmap2.getCurrentMapType() === G_HYBRID_MAP) maptype = "hybrid"; var url = "http://maps.google.com/maps/api/staticmap?center=" + center + "&zoom=" + zoom + "&size=" + size + "&maptype=" + maptype + "&sensor=false&format=png"; var markers = new Array(); for(var i = 0; i < this.markers.length; i++) { var marker = this.markers[i]; if(marker.label != null) { url += "&markers=label:" + marker.label + "|" + marker.getLatLng().toUrlValue(); } else { markers.push(marker.getLatLng().toUrlValue()); } } if(markers.length > 0) { url += "&markers=" + markers.join("|"); } return url; } } KrillionUI.LoadingIndicator = { Id: null, Step: 0, Bars: 20, Show: function() { $("#wtb_results").hide(); $("#wtb_options").hide(); this.Animate(); this.Id = window.setInterval(function() { KrillionUI.LoadingIndicator.Animate(); }, 25); }, Hide: function() { if(this.Id != null) { window.clearInterval(this.Id); this.Id = null; this.Step = 0; $("#wtb_retailers").html(""); } }, Animate: function() { if(this.Id != null) { var dots = ""; for(var i = 0; i < this.Bars; i++) { if(i == this.Step%(this.Bars+1)) dots += ""; dots += "|"; } if(this.Step%(this.Bars+1) != this.Bars) dots += ""; $("#wtb_retailers").html("
" + dots + "
"); this.Step++; } } } $(document).ready(function() { KrillionUI.Init(); });