(function($) { $.lotpath = $.lotpath || {}; $.fn.postalCodeAutoComplete = function() { var method = typeof arguments[2] == 'string' && arguments[2]; var args = method && Array.prototype.slice.call(arguments, 1) || arguments; return this.each(function() { if (method) { var postalCodeAutoComplete = $.data(this, 'postal-code-auto-complete'); postalCodeAutoComplete[method].apply(postalCodeAutoComplete, args); } else new $.lotpath.postalCodeAutoComplete(this, args[0] || {}); }); }; $.lotpath.postalCodeAutoComplete = function(el, options) { var defaults = { dataSource: '/Search/GetLocationJSON', postalCodeOnly: false, onSelect: null, /* Element Styles */ boxStyle: { 'position': 'absolute', 'display': 'block', 'background-color': '#fff', 'border': 'solid 1px #ccc', 'overflow': 'auto', 'z-index': '555' }, itemStyle: { 'font-family': 'Verdana, Helvetica, Sans-Serif', 'font-size': '0.7em', 'font-weight': 'normal', 'line-height': '100%', 'overflow': 'hidden', 'padding': '2px 2px' }, itemHoverStyle: { 'background-color': '#4FAAFF', 'cursor': 'pointer', 'color': '#fff' }, itemHoverOffStyle: { 'background-color': '#fff', 'cursor': 'pointer', 'color': '#666' } }; var opts = $.extend({}, defaults, options); var o = $.meta ? $.extend({}, opts, this.data()) : opts; $(el).attr('autocomplete', 'off'); this.element = el; this.postalCodeOnly = o.postalCodeOnly; this.onSelect = o.onSelect; this.isActive = false; this.items = ''; this.itemFocus = 0; this.previousSearch = ''; this.selectedPostalCode = ''; this.selectedCityState = ''; this.box = '#' + $(el).attr('id').replace(/\./g, '') + '-box'; this.timeoutId = null; this.dataSource = o.dataSource; this.boxStyle = o.boxStyle; this.itemStyle = o.itemStyle; this.itemHoverStyle = o.itemHoverStyle; this.itemHoverOffStyle = o.itemHoverOffStyle; $.data(el, 'postal-code-auto-complete', this); this.initialize(); }; $.extend($.lotpath.postalCodeAutoComplete.prototype, { initialize: function() { $(this.element).bind('click', { obj: this }, this.hClick); $(this.element).bind('focus', { obj: this }, this.hFocus); $(this.element).bind('blur', { obj: this }, this.hBlur); $(this.element).bind('keydown', { obj: this }, this.hItemKeyDown); }, /* Event Handlers */ hClick: function(event) { event.preventDefault(); event.stopPropagation(); var object = event.data.obj; if (object.isActive) { object.removeAll(); return; } $(object.element).unbind('focus', object.hFocus); $(object.element).focus(); }, hFocus: function(event) { var object = event.data.obj; object.removeAll(); $(object.element).unbind('focus', object.hFocus); }, hBlur: function(event) { var object = event.data.obj; $(object.element).bind('focus', { obj: object }, object.hFocus); }, hButtonClick: function(event) { event.preventDefault(); event.stopPropagation(); var object = event.data.obj; if (object.isActive) { object.removeAll(); return; } $(object.element).unbind('focus', object.hFocus); $(object.element).focus(); object.showSelectBox(); }, hItemClick: function(event) { var object = event.data.obj; object.setSelectedValue(); object.removeAll(); }, hClickOutside: function(event) { var object = event.data.obj; object.removeAll(); }, hItemMouseOver: function(event) { var object = event.data.obj; var i = $.inArray($(event.target).get()[0], $(object.box + '> *').get()); $(object.box + ' .item').css(object.itemHoverOffStyle); $(event.target).css(object.itemHoverStyle); object.itemFocus = i; }, hItemMouseOut: function(event) { }, hItemKeyDown: function(event) { var object = event.data.obj; switch (event.keyCode) { case 9: object.itemTab(); break; case 13: event.preventDefault(); object.itemEnter(); break; case 27: object.removeAll(); break; case 40: object.itemDown(); break; case 38: event.preventDefault(); event.stopPropagation(); object.itemUp(); break; default: object.typeSearch(String.fromCharCode(event.which)); break; } }, /* UI Methods */ removeAll: function() { $('.box').empty().remove(); $('body').unbind(); $(window).unbind(); this.isActive = false; }, renderItems: function() { var html = ''; var isText = isNaN(($(this.element).val())); $(this.items).each(function(i) { if (isText && !this.postalCodeOnly) { html += '<div id="item-' + i + '" class="item">' + this.city + ', ' + this.state + '</div>'; } else { html += '<div id="item-' + i + '" class="item">' + this.postalCode + ' - ' + this.city + ', ' + this.state + '</div>'; } }); $(this.box).append(html); this.addBehaviorsToItems(); }, renderSelectBox: function() { var self = this; var height = (this.items.length > 11) ? '200px' : ''; var id = this.box.replace('#', ''); var id = id.replace(/\./g, ''); $('body').append('<div id="' + id + '" class="box"></div>'); $(this.box).css(this.boxStyle); $(this.box).css('height', height); $(this.box).css('width', $(this.element).outerWidth() - 2 + 'px'); this.positionSelectBox(); $(window).resize(function() { self.adjustSelectBoxPosition(); }); }, positionSelectBox: function() { var pos = $(this.element).offset(); $(this.box).css({ 'left': pos.left + 'px', 'top': (pos.top + $(this.element).outerHeight()) + 'px' }); }, adjustSelectBoxPosition: function() { this.positionSelectBox(); }, showSelectBox: function() { this.removeAll(); if (this.items.length == 0) return; this.isActive = true; this.renderSelectBox(); this.renderItems(); $('.item:eq(' + this.itemFocus + ')').css(this.itemHoverStyle); $('body').bind('click', { obj: this }, this.hClickOutside); }, typeSearch: function(character) { var self = this; var regex = new RegExp(/\w/i); if (!regex.test(character) && (character.charCodeAt(0) != 8)) return; this.timeoutId = setTimeout(function() { self.limitItems(); }, 600); }, limitItems: function() { if (this.timeoutId == null) return; var self = this; var text = $(this.element).val().toLowerCase(); if (this.resetItems()) return; if (!this.isNewSearch(text)) return; this.previousSearch = text; var url = this.dataSource + '/' + text; $.getJSON(url, function(data) { self.items = data.locations; self.showSelectBox(); }); }, isNewSearch: function(text) { if (text == this.previousSearch) { if (this.items.length > 0) { this.showSelectBox(); } else { return false; } } return true; }, resetItems: function() { var text = $(this.element).val().toLowerCase(); if (text == '') { this.items = ''; this.previousSearch = ''; this.removeAll(); return true; } return false; }, setSelectedValue: function() { var selectedText; this.selectedPostalCode = this.items[this.itemFocus].postalCode; this.selectedCityState = this.items[this.itemFocus].city + ', ' + this.items[this.itemFocus].state; if (!isNaN(($(this.element).val()))) { selectedText = this.selectedPostalCode; $(this.element).val(selectedText); } else { selectedText = this.selectedCityState; $(this.element).val(selectedText); } if (this.onSelect != null) { this.onSelect.apply(this, [this.selectedCityState]); } $(this.element).triggerHandler('change'); }, clearSelection: function() { }, itemDown: function() { if (this.items.length == 0) return; if ((this.itemFocus + 1) >= this.items.length) { this.highlightItem(); return; } this.itemFocus++; this.highlightItem(); }, itemUp: function() { if (this.items.length == 0) return; if ((this.itemFocus - 1) < 0) { this.highlightItem(); return; } this.itemFocus--; this.highlightItem(); }, highlightItem: function() { $('.item').css(this.itemHoverOffStyle); $('.item:eq(' + this.itemFocus + ')').css(this.itemHoverStyle); this.setSelectedValue(); }, itemTab: function() { clearTimeout(this.timeoutId); this.timeoutId = null; if (this.isActive) { this.setSelectedValue(); this.removeAll(); } }, itemEnter: function() { if (this.isActive) { this.setSelectedValue(); this.removeAll(); } }, addBehaviorsToItems: function() { $(this.box + ' > .item').css(this.itemStyle); $(this.box + ' > .item').bind('click', { obj: this }, this.hItemClick); $(this.box + ' > .item').bind('mouseover', { obj: this }, this.hItemMouseOver); $(this.box + ' > .item').bind('mouseout', { obj: this }, this.hItemMouseOut); } }); })(jQuery);/** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * http: * http: * */ /** * Create a cookie with the given name and value and other optional parameters. * * @example $.cookie('the_cookie', 'the_value'); * @desc Set the value of a cookie. * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); * @desc Create a cookie with all available options. * @example $.cookie('the_cookie', 'the_value'); * @desc Create a session cookie. * @example $.cookie('the_cookie', null); * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain * used when the cookie was set. * * @param String name The name of the cookie. * @param String value The value of the cookie. * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. * If set to null or omitted, the cookie will be a session cookie and will not be retained * when the the browser exits. * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will * require a secure protocol (like HTTPS). * @type undefined * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ /** * Get the value of a cookie with the given name. * * @example $.cookie('the_cookie'); * @desc Get the value of a cookie. * * @param String name The name of the cookie. * @return The value of the cookie. * @type String * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); } var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } };var searchInitValue = 'Enter a product, brand, or organization'; var traceInitValue = 'Enter a traceable item number'; var locationWatermark = 'Enter a postal code or city'; var slides = ['map', 'shopping', 'food']; var traceSamples = ['trace_sample_1', 'trace_sample_2', 'trace_sample_3', 'trace_sample_4']; var currentSlide = null; var currentTraceSample = null; var slideTimeout; var slideTimeoutInterval = 10000; $(document).ready(function() { $('#search-button, #trace-button').css('cursor', 'pointer'); $('#search-input, #trace-input').bind('keypress', null, hInputKeyPress); $('#search-button, #trace-button').bind('click', null, hSearchClick); $('#search-input').val(searchInitValue); $('#trace-input').val(traceInitValue); $('#location').val(locationWatermark) .bind('keypress', hLocalKeyPress) .focus(function() { if ($(this).val() == locationWatermark) { $(this).val(''); } }) .blur(function() { if ($(this).val() == '') { $(this).val(locationWatermark); } }) .removeAttr('disabled') .postalCodeAutoComplete(); $('#local-go').bind('click', null, hLocalClick) .mouseover(function() { $(this).css('cursor', 'pointer'); }); $("#search-input").focus(function() { if ($(this).val() == searchInitValue) { $(this).val(''); } }).blur(function() { if ($(this).val() == '') { $(this).val(searchInitValue); } }); $("#trace-input").focus(function() { if ($(this).val() == traceInitValue) { $(this).val(''); } }).blur(function() { if ($(this).val() == '') { $(this).val(traceInitValue); } }); if ($.cookie('distMiles') != null) { $('#miles').val($.cookie('distMiles')); } if ($.cookie('distLocation') != null) { $('#location').val($.cookie('distLocation')); } $('#link-map, #link-shopping, #link-food').bind('click', null, hSlideChange); rotateSlide(); rotateTraceSample(); preloadImages('/Content/images/app/trace_sample_2.jpg' , '/Content/images/app/trace_sample_3.jpg' , '/Content/images/app/trace_sample_4.jpg' , '/Content/images/flash_slide01.jpg' , '/Content/images/flash_slide02.jpg' , '/Content/images/flash_slide03.jpg'); if (deconcept.SWFObjectUtil.getPlayerVersion().major < 6) { insertStaticImages(); } }); function insertStaticImages() { $('#map').append('<img src="/Content/images/flash_slide01.jpg" />'); $('#shopping').append('<img src="/Content/images/flash_slide02.jpg" />'); $('#food').append('<img src="/Content/images/flash_slide03.jpg" />'); } function rotateSlide() { if (currentSlide == null) { currentSlide = 0; } else if (currentSlide == slides.length - 1) { currentSlide = 0; } else { currentSlide++; } slideChange(slides[currentSlide]); resetTimer(); } function rotateTraceSample() { if (currentTraceSample == null) { currentTraceSample = 0; } else if (currentTraceSample == traceSamples.length - 1) { currentTraceSample = 0; } else { currentTraceSample++; } $('#trace-sample').attr('src', '/Content/images/app/' + traceSamples[currentTraceSample] + '.jpg'); setTimeout('rotateTraceSample()', 5000); } function resetTimer() { if (slideTimeout != null) clearTimeout(slideTimeout); slideTimeout = setTimeout('rotateSlide()', slideTimeoutInterval); } function hInputKeyPress(event) { if (event.keyCode == 13) { if ($(this).attr('id') == 'trace-input') { $('#trace-button').triggerHandler('click'); } else { $('#search-button').triggerHandler('click'); } } } function hSearchClick(event) { if ($(this).attr('id') == 'trace-button') { if ($('#trace-input').val() == traceInitValue || $('#trace-input').val() == '') return false; location.href = '/Trace?q=' + escape($('#trace-input').val()); } else { if ($('#search-input').val() == searchInitValue || $('#search-input').val() == '') return false; location.href = '/Search?q=' + escape($('#search-input').val()); } } function hLocalKeyPress(event) { if (event.keyCode == 13) { $('#local-go').triggerHandler('click'); } } function hLocalClick(event) { var $loc = $('#location'); if ($loc.val() == '' || $loc.val() == locationWatermark) return; $.cookie('distMiles', $('#miles').val(), { path: '/', expires: 10 }); $.cookie('distLocation', $loc.val(), { path: '/', expires: 10 }); location.href = '/Search?q=&mi=' + $('#miles').val() + '&loc=' + $loc.val(); } function hSlideChange(event) { var id = $(this).attr('id'); id = id.split("-")[1]; slideChange(id); event.preventDefault(); currentSlide = $.inArray(id, slides); clearTimeout(slideTimeout); } function slideChange(id) { $('#flash-left p').css('display', 'none'); $('#flash-right div').css('display', 'none'); $('#link-map, #link-shopping, #link-food').removeClass('active-slide'); $('#' + id).css('display', 'block'); $('#text-' + id).css('display', 'block'); $('#link-' + id).addClass('active-slide'); } function preloadImages() { for (var i = 0; i < arguments.length; i++) { $("<img>").attr("src", arguments[i]); } }