var map;var geocoder;var mapMarkers = [];mapMarkers[]]=[];mapMarkers[]].push(null);document).ready(function($){$('input#zip').keyup(function(event){if(event.keyCode == 13){event.preventDefault();$('a#zipSearch').click();}});$('input#directions-to-start-addr').keyup(function(event){if(event.keyCode == 13){event.preventDefault();$('a#directions-to-submit').click();}});$('input#directions-from-destination-addr').keyup(function(event){if(event.keyCode == 13){event.preventDefault();$('a#directions-from-submit').click();}});$('a#zipSearch').click(function(event){event.preventDefault();$('#directions-from').hide();$('#directions-to').hide();$('div#singleResult').hide();$('#ui-slsearch-directions').text('');$('div#results').show();GetMapResults();});if(window.location.hash){var searchCriteria = window.location.hash.split('/');if(searchCriteria[1])$('input#zip').val(searchCriteria[1]);$('div#results').show();$('a#zipSearch').trigger('click');}$('#singleResult a#directions-from-submit').live('click',function(event){event.preventDefault();showDirections(getSingleAddressLine(),$('div#singleResult input#directions-from-destination-addr').val());});$('#singleResult a#directions-to-submit').live('click',function(event){event.preventDefault();showDirections($('div#singleResult input#directions-to-start-addr').val(),getSingleAddressLine());});$('div#results div#inner div#listing div.location h3, div#results div#inner div#listings div.location a').live('click',function(event){$('div#results').hide();event.preventDefault();var s = $(this).parent('.location'),sname = s.find('h3').text(),letter = s.find('.letter').text(),sphone = s.find('.phone').text(),sa1 = s.find('.address1').text(),sa2 = s.find('.address2').text(),scity = s.find('.city').text(),sstate = s.find('.state').text(),szip = s.find('.zip').text();sLocationNumber = s.find('#locationNumber').val();$('div#singleResult div#locationSingle h3').text(sname);$('div#singleResult div#locationSingle .letter').text(letter);$('div#singleResult div#locationSingle .address1 p').text(sa1);$('div#singleResult div#locationSingle .address2 p').text(sa2);$('div#singleResult div#locationSingle div p span.city').text(scity);$('div#singleResult div#locationSingle div p span.state').text(sstate);$('div#singleResult div#locationSingle div p span.zip').text(szip);$('div#singleResult div#locationSingle .phone p').text(sphone);$('div#singleResult div#locationSingle input#locationNumber').val(sLocationNumber);$('div#singleResult').show();});$('#to-opener').click(function(event){event.preventDefault();$('#directions-from').hide();$('#ui-slsearch-directions').text('');$('#directions-to').show();});$('#from-opener').click(function(event){event.preventDefault();$('#directions-to').hide();$('#ui-slsearch-directions').text('');$('#directions-from').show();});$('a#search-return').click(function(event){event.preventDefault();$('div#results').show();$('div#singleResult').hide();$('#directions-from').hide();$('#directions-to').hide();$('#ui-slsearch-directions').text('');});}function getSingleAddressLine(){var addrOut = '';addrOut += $('div#singleResult div#locationSingle .address1 p').text();addrOut += ', ' + $('div#singleResult div#locationSingle .address2 p').text();addrOut += ', ' + $('div#singleResult div#locationSingle p span.city').text();addrOut += ', ' + $('div#singleResult div#locationSingle p span.state').text();addrOut += ', ' + $('div#singleResult div#locationSingle p span.zip').text();return addrOut;}var directions;function showDirections(startAddress,endAddress){if(directions == undefined){var directionsPanel = document.getElementById('ui-slsearch-directions');directions = new GDirections(map,directionsPanel);GEvent.addListener(directions,"error",handleErrors);GEvent.addListener(directions,"load",onGDirectionsLoad);}$('#ui-slsearch-directions').text('');directions.load('from: ' + startAddress + ' US to: ' + endAddress);}function onGDirectionsLoad(){}function handleErrors(){if(directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS){alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + directions.getStatus().code);}else if(directions.getStatus().code == G_GEO_SERVER_ERROR){alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\nError code: " + directions.getStatus().code);}else if(directions.getStatus().code == G_GEO_MISSING_QUERY){alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions request, this means that no query was specified in the input.\nError code: " + directions.getStatus().code);}else if(directions.getStatus().code == G_GEO_BAD_KEY){alert("The given key is either invalid or does not match the domain for which it was given.\nError code: " + directions.getStatus().code);}else if(directions.getStatus().code == G_GEO_BAD_REQUEST){alert("A directions request could not be successfully parsed.\nError code: " + directions.getStatus().code);}else{alert("An unkown error occurred.");}}var curPage = 1;function GetMapResults(){var bookmarkURI = '#!/' + encodeURI($('input#zip').val());window.location = bookmarkURI;var letters =['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'];var dataLocation = "";dataLocation = xmlPath;$.get(dataLocation + "Zip=" + $('input#zip').val(),function(data){if($(data).find('Success').text()== "false"){$('div.searchError').text($(data).find('Message').text());$('div#results div#inner').hide();}else{$('div.searchError').text('');$('div#results div#inner div#listing').text('');$('div#results div#inner').show();}if($(data)!= undefined){if(GBrowserIsCompatible()){$('div#map').show();var map = new GMap2(document.getElementById('map'));map.setCenter(new GLatLng(0,0),0);geocoder = new GClientGeocoder();map.addControl(new GSmallMapControl());map.enableScrollWheelZoom();map.hideControls();GEvent.addListener(map,'mouseover',function(){map.showControls();});GEvent.addListener(map,'mouseout',function(){map.hideControls();});var bounds = new GLatLngBounds(0,0);}var i = 0;var items = 1;var iPagePosition = 1;var xml;if($.browser.msie && typeof data == "string"){xml = new ActiveXObject("Microsoft.XMLDOM");xml.async = false;xml.loadXML(data);}else{xml = data;}var mapMarkers =[];mapMarkers[items]=[];var count = 0;$(xml).find('StoreInformation').each(function(){var letter = letters[i];if(i >= 26){letter = letters[i - 26];}var StoreID = $(this).find('StoreID').text();var StoreName = $(this).find('DealerName').text();var StoreAddress1 = $(this).find('StreetAddress1').text();var StoreAddress2 = $(this).find('StreetAddress2').text();var StorePhone = $(this).find('PhoneNumber').text();var StoreCity = $(this).find('City').text();var StoreState = $(this).find('State').text();var StoreZip = $(this).find('ZipCode').text();$('div#results div#listing').append( "<div class='location'>" + "<div class='letter'>" + letter + "</div>" + "<input type='hidden' id='locationNumber' value='" + iPagePosition + "' />" + "<h3 id='location_" + StoreID + "'>" + StoreName + "</h3>" + "<div class='phone'><p>" + StorePhone + "</p></div>" + "<div class='address1'><p>" + StoreAddress1 + "</p></div>" + "<div class='address2'><p>" + StoreAddress2 + "</p></div>" + "<div><p><span class='city'>" + StoreCity + "</span>, <span class='state'>" + StoreState + "</span> <span class='zip'>" + StoreZip + "</span></p></div>" + "<div class='phone'><p>" + StorePhone + "</p></div>" + "</div>");var icon = new GIcon(G_DEFAULT_ICON,'http://www.google.com/mapfiles/marker' + letter + '.png');var address = $(this).find('StreetAddress1').text()+ " " + $(this).find('StreetAddress2').text()+ " " + $(this).find('City').text()+ " " + $(this).find('State').text()+ " " + $(this).find('ZipCode').text();geocoder.getLocations(address,function(point){if(!point || point.Status.code != 200){}else{plop = point.Placemark[0];place = new GLatLng(plop.Point.coordinates[1],plop.Point.coordinates[0]);var marker = new GMarker(place,{icon:icon});GEvent.addListener(marker,"click",function(){marker.openInfoWindowHtml("<strong>" + StoreName + "</strong><br />" + StoreAddress1 + " " + StoreAddress2 + "<br />" + StoreCity + " " + StoreState + ", " + StoreZip + "<br />" + StorePhone);$('#location_' + StoreID).trigger('click');});GEvent.addDomListener(document.getElementById('location_' + StoreID),'click',function(){marker.openInfoWindowHtml("<strong>" + StoreName + "</strong><br />" + StoreAddress1 + " " + StoreAddress2 + "<br />" + StoreCity + " " + StoreState + ", " + StoreZip + "<br />" + StorePhone);$('#location_' + StoreID).trigger('click');});mapMarkers[items].push(marker);for(var j in mapMarkers[items]){map.addOverlay(mapMarkers[items][j]);}bounds.extend(place);var zoomLevel = map.getBoundsZoomLevel(bounds);if(zoomLevel > 15){zoomLevel = 15;}map.setZoom(zoomLevel);map.setCenter(bounds.getCenter());}});++i;++iPagePosition;});$('div#results div#listing').append("<div class='clear'>&nbsp;</div>");$('div#results div#listing .location:nth-child(2n)').after("<div class='clear'>&nbsp;</div>");}});}