var MARKERPATHPREFIX = 'http://css.yamaha-motor-europe.com/dealerlocator/gmaps/img/markers/'; var PUSHPINSRC = 'http://css.yamaha-motor-europe.com/dealerlocator/yam/img/loc-pushpin.png'; var PINWIDTH = 32; var PINHEIGHT = 26; var PINANCHORX = 7; var PINANCHORY = 26; var defaultRadius = 100; var defaultCount = 5; var gDetailsPage = '/dealerlocator/detail.jsp'; var gCountry = 'RU'; var map; var geocoder; var defaultPoint; var markers; var gCurPage; var gCurrent; var gHasFilters = false; var gCenter; function initialize() { if (GBrowserIsCompatible()) { geocoder = new GClientGeocoder(); map = new GMap2(document.getElementById("mapcanvas")); geocoder.getLatLng(gCountry, function(latlng) { map.clearOverlays(); if (!latlng) { alert(address + ' not found'); } else { defaultPoint = latlng; map.setCenter(latlng, 2); } }); //Setting options map.enableDoubleClickZoom(); map.enableScrollWheelZoom(); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.removeMapType(G_SATELLITE_MAP); } var searchBtn = document.getElementById('searchBtn'); searchBtn.onclick= function() {searchLocations()}; setUpLinks(); var qs = document.getElementById('qs'); var dealername = document.getElementById('dealername'); document.onkeypress = function(event) { submitenter(document, event) } //qs.onkeypress = function(event) { submitenter(qs, event) } //dealername.onkeypress = function(event) { submitenter(qs, event) } } function submitenter(myfield,e) { var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; else return true; if (keycode == 13) { searchLocations(); return false; } else { return true; } } function generateSelect() { // Generates the country drop down based on the values held in the strings file - best way to make this // dynamic for yamaha? var c = document.getElementById( 'country' ), o, k; if ( !c ) return false; c.style.display = CountryDisplay ? CountryDisplay : 'inline'; var col = document.getElementById( 'countryCol' ), o, k; col.style.display = CountryDisplay ? CountryDisplay : 'inline'; c.disabled = CountryDisabled; while ( c.childNodes[0] ) c.removeChild( c.firstChild ); for ( k in CountryOptions ) { o = document.createElement( 'option' ); o.className = CountryOptions[k].coords; o.innerHTML = CountryOptions[k].value; o.value = k; if ( CountryOptions[k].selected ) { //MMYME.CountryCode = k; var selectedIndex = true; c.value = k; } c.appendChild( o ); } if ( typeof selectedIndex == 'undefined' ) c.value = c.options[0]['value']; c.value = gCountry; } function buildNav() { var selectElement = null; var ul = document.getElementById('MMprodcat'); for ( var cat in NavFilters ) { var li = document.createElement( 'li' ); var a = document.createElement( 'a' ); a.className = 'nav' + cat; a.name = cat; a.onclick = function() { buildSubNav( this ); return false; } a.href = '#'; a.setAttribute( 'title', NavFilters[cat]['alt'] ); li.appendChild( a ); ul.appendChild( li ); if (NavFilters[cat]['selected']) { selectElement = a; } } if (selectElement != null) { buildSubNav(selectElement); } } function buildSubNav(oObj){ gHasFilters = false; if ( gCurrent ) removeCssClass( "current", gCurrent ); addCssClass( "current", oObj ); gCurrent = oObj; var navtype = oObj.name; var filterlist = document.getElementById('MMfilter_list').getElementsByTagName( 'div' )[0]; // clear previous list while (filterlist.firstChild) filterlist.removeChild(filterlist.firstChild); prodtype = NavFilters[navtype] ? NavFilters[navtype].filters : undefined; if ( typeof prodtype != 'undefined' ) { var ul = document.createElement('ul'); for (z in prodtype) { var li = document.createElement('li'); var label = document.createElement( 'label' ); label.setAttribute( 'for', z ); var txt = document.createElement( 'span' ); txt.innerHTML = prodtype[z].desc; var inpt = document.createElement('input'); inpt.type = 'checkbox'; inpt.id = z; inpt.name = 'prod_filters'; if (!prodtype[z].searchable) { inpt.disabled = 'disabled'; } label.appendChild( inpt ); label.appendChild( txt ); li.appendChild( label ); ul.appendChild( li ); } filterlist.appendChild(ul); gHasFilters = true; } document.getElementById( 'options' ).style.display = ( gHasFilters ? 'block' : 'none' ); } function searchLocations() { var address = document.getElementById('qs').value; var dealername = document.getElementById('dealername').value; hideErrors(); if (address.length > 0 && address != Strings.address_example) { geocoder.getLatLng(address + ' ' + gCountry, function(latlng) { if (!latlng) { alert(address + ' not found'); } else { gCenter = latlng; if (dealername.length > 0 && dealername != Strings.dealer_example) { searchLocationsNear(latlng, dealername); } else { searchLocationsNear(latlng, ''); } } }); } else if (dealername.length > 0 && dealername != Strings.dealer_example) { searchByDealer(dealername); } else { handleErrors(Strings.enter_country_dealer); } } function searchByDealer(dealername) { var services = getServices(); var searchUrl = 'locator.jsp?name=' + dealername + '&country=' + gCountry + services; GDownloadUrl(searchUrl, handleLocatorData); } function searchLocationsNear(center, dealername) { var services = getServices(); var radius = defaultRadius; var searchUrl = 'locator.jsp?lat=' + center.lat() + '&lng=' + center.lng() + '&distance=' + radius + '&country=' + gCountry + '&name=' + dealername + services; GDownloadUrl(searchUrl, handleLocatorData); } function getServices() { var services = ""; if (gHasFilters){ var allinputs = document.getElementsByTagName('input'); for (var t = 0; t < allinputs.length; t++){ if (allinputs[t].name.match('prod_filters')){ if(allinputs[t].checked == true){ var filtervalue = ' ' + + ' '; if (services == "") { services = allinputs[t].id; } else { services = services + "," + allinputs[t].id; } } } }// for }//if hasfilters return "&services=" + services; } function handleLocatorData(data) { var xml = GXml.parse(data); var sidebar = document.getElementById('resultsdiv'); map.clearOverlays(); markers = xml.documentElement.getElementsByTagName('marker'); sidebar.innerHTML = ''; if (markers.length == 0) { hideTotals(); hidePagination(); // will hide pagination; handleErrors(Strings.err2); map.setCenter(defaultPoint, 2); return; } switchResultView(); var el = document.createElement ( 'table' ); var thead = document.createElement ( 'tHead' ); el.id = 'recordList'; el.className= 'sf_results_list'; var tbody = document.createElement ( 'tBody' ); tbody.id = "sidebarTB"; el.appendChild ( thead ); el.appendChild ( tbody ); var resultsdiv = document.getElementById("resultsdiv"); resultsdiv.appendChild(el); gCurPage = 0; showPagination(); showMarkerRange(gCurPage, defaultCount); showTotals(); } function handleErrors(errorMessage){ var err_message = document.getElementById('message1'); err_message.innerHTML = errorMessage; err_message.style.display = 'block'; err_message.className = 'error'; } function hideErrors() { var err_message = document.getElementById('message1'); err_message.innerHTML = ''; err_message.style.display = 'none'; err_message.className = 'error'; } function showMarkerRange(pageNum, count) { var bounds = new GLatLngBounds(); var tbodyParent = document.getElementById("sidebarTB"); removeChildrenFromNode(tbodyParent); map.clearOverlays(); for (var i = pageNum*count; i < pageNum*count + count && i < markers.length; i++) { var name = getNodeValue(markers[i], "name"); var address = getNodeValue(markers[i], "address"); var distance = parseFloat(getNodeValue(markers[i], "distance")); var point = new GLatLng(parseFloat(getNodeValue(markers[i], "lat")), parseFloat(getNodeValue(markers[i], "lng"))); var marker = createMarker(point, markers[i], i+1); map.addOverlay(marker); tbodyParent.appendChild( createResultsItem( markers[i], i+1, marker ) ); bounds.extend(point); } map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); var centerPin = createCenterPin(gCenter); map.addOverlay(centerPin); scrollToTop(); } function showTotals() { document.getElementById( 'bCrumb' ).innerHTML = '' + Strings.found + ' ' + markers.length + ' ' + Strings.dealers + ' ' + defaultRadius + ' km'; } function hideTotals() { document.getElementById( 'bCrumb' ).innerHTML = ''; } function createCenterPin(point) { var pinIcon = new GIcon(G_DEFAULT_ICON); pinIcon.image = PUSHPINSRC; pinIcon.shadow = ""; pinIcon.iconSize = new GSize(PINWIDTH, PINHEIGHT); pinIcon.iconAnchor = new GPoint(PINANCHORX, PINANCHORY); var markerOptions = {'icon':pinIcon }; var marker = new GMarker(point, markerOptions); return marker; } function createMarker(point, record, num) { var numIcon = new GIcon(G_DEFAULT_ICON); numIcon.iconSize = new GSize(37, 37); numIcon.iconAnchor = new GPoint(16, 37); numIcon.infoWindowAnchor = new GPoint(18, 1); numIcon.shadow = MARKERPATHPREFIX + 'marker_shadow.png'; numIcon.shadowSize = new GSize(50, 37); if (num < 10) { numIcon.image = MARKERPATHPREFIX + 'marker0' + num + '.png'; } else { numIcon.image = MARKERPATHPREFIX + 'marker' + num + '.png'; } var markerOptions = {'icon':numIcon }; var marker = new GMarker(point, markerOptions); var html = createInfoBoxContent(record, 1); GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); }); return marker; } function hidePagination() { var pagingSpan = document.getElementById("MMpage"); removeChildrenFromNode(pagingSpan); } function showPagination() { var pagingSpan = document.getElementById("MMpage"); var tbodyParent = document.getElementById("sidebarTB"); var p = document.createElement('p'); var aprev = document.createElement( 'a' ); var anext = document.createElement( 'a' ); var a_prevtext = '« ' + Strings.txt_page_prev; var a_nexttext = Strings.txt_page_next + ' »'; p.className = 'pagination'; aprev.href = '#'; aprev.onclick = function () { if (gCurPage > 0) { gCurPage--; removeChildrenFromNode(tbodyParent); showMarkerRange(gCurPage, defaultCount); } checkPaginationVis(aprev, anext); return false; } anext.href = '#'; anext.onclick = function () { if (gCurPage * defaultCount < markers.length) { gCurPage++; removeChildrenFromNode(tbodyParent); showMarkerRange(gCurPage, defaultCount); } checkPaginationVis(aprev, anext); return false; } aprev.innerHTML = a_prevtext; anext.innerHTML = a_nexttext; p.appendChild(aprev); p.appendChild(anext); checkPaginationVis(aprev, anext); removeChildrenFromNode(pagingSpan); pagingSpan.appendChild(p); } function checkPaginationVis(aprev, anext) { if (gCurPage * defaultCount + defaultCount > markers.length) { anext.className = "hiddenlink"; } else { anext.className = "next f_red bold"; } if (gCurPage == 0) { aprev.className = "hiddenlink"; } else { aprev.className = "prev f_red bold"; } } function switchResultView() { var mapcanvas = document.getElementById("mapcanvas"); var resultsdiv = document.getElementById("resultsdiv"); resultsdiv.className = "results_res"; mapcanvas.className = "mapviewer_res"; map.checkResize(); } /** * Creates the sidebar items */ function createResultsItem(record,num,marker){ var origaddress = document.getElementById('qs').value; var name = getNodeValue(record, "name"); var address = getNodeValue(record, "address"); var distance = parseFloat(getNodeValue(record, "distance")); var zip = getNodeValue(record, "zip"); var city = getNodeValue(record, "city"); var url = getNodeValue(record, "url");//record.getElementsByTagName("url")[0].childNodes[0].nodeValue; var tel = getNodeValue(record, "tel"); var cityonly = getNodeValue(record, "cityonly"); var vicinity_id = getNodeValue(record, "vicinity_id"); var span = document.createElement ( 'span' ); span.className = "recordNum"; span.appendChild(document.createTextNode(num || '' )); var a = document.createElement ( 'a' ); var a2 = document.createElement ( 'a' ); a.href = '#'; GEvent.addDomListener(a, 'click', function() { GEvent.trigger(marker, 'click'); return false; }); a2.href = '#'; a2.onclick = function () { prepRoute(record); return false;}; a.innerHTML = name; a.className = "recordName"; a2.innerHTML = Strings.plan_route; a2.style.marginLeft = '15px'; a2.style.fontWeight = 'bold'; var tr = document.createElement('tr'); var td = document.createElement('td'); var p1 = document.createElement('p'); var p2 = document.createElement('p'); var p3 = document.createElement('p'); var p4 = document.createElement('p'); var p5 = document.createElement('p'); var pcityonly = document.createElement('p'); var p6 = document.createElement('p'); var pc = document.createElement( 'p' ); var p7 = document.createElement('p'); //freetext pc.appendChild( document.createTextNode( zip || '' ) ); td.className = "tdlist"; p1.className = "p1"; // address p3.className = "p3"; // tel if(url && url.length > 0){ var a3 = document.createElement ( 'a' ); a3.className = 'link3'; if (url.substring(0,4) == 'http') { a3.href = url; } else { a3.href = 'http://' + url; } a3.target = '_blank' a3.innerHTML = Strings.web; } //var extra = ( dealername.getValue() == '' ? '&nodealer=true' : '&origdealer=' + dealername.getValue() ); var a4 = document.createElement ( 'a' ); a4.href = gDetailsPage + '?record=' + vicinity_id + '&start_address=' + origaddress; a4.innerHTML = Strings.ib_dealer_details; a4.style.marginLeft = '15px'; a4.style.fontWeight = 'bold'; p1.appendChild( document.createTextNode( address || '' ) ); p2.appendChild( document.createTextNode( city || '' ) ); if ( tel.length > 0) { p3.appendChild( document.createTextNode( Strings.tel + ' ' + tel || '' ) ); } if ( cityonly == 'true') { pcityonly.innerHTML = Strings.cityonly; pcityonly.className = 'a3'; } if ( distance > 0 && cityonly != 'true') { p5.innerHTML = Strings.distance_from + ' ' + distance.toFixed(1) + ' ' + 'km'; p5.className = 'a3'; } td.appendChild( span ); // number td.appendChild( a ); // name td.appendChild( p1 ); //if ( loc_country.value.toLowerCase() == 'gb' ) { // td.appendChild( p2 ); // td.appendChild( pc ); //} else { td.appendChild( pc ); td.appendChild( p2 ); //} td.appendChild( p3 ); if ( url ) { td.appendChild( a3 ); } // website p7.appendChild( document.createTextNode( 'TODO' || '' ) ); //if ( loc_country.value.toLowerCase() == 'it' ) { // td.appendChild( p7 ); //} td.appendChild( pcityonly ); td.appendChild( p5 ); td.appendChild( a2 ); // plan route td.appendChild( a4 ); // dealer details tr.appendChild( td ); return tr; } function scrollToTop() { var results=document.getElementById('resultsdiv'); results.scrollTop=0 } function getNodeValue(node, tagName) { var foundTags = node.getElementsByTagName(tagName); if (foundTags[0].childNodes.length > 0){ return foundTags[0].childNodes[0].nodeValue; } else { return ''; } } function removeChildrenFromNode(node) { if(node == undefined) { return; } while (node.hasChildNodes()) { node.removeChild(node.firstChild); } } function addCssClass( sCss, oElement ) { if ( ( ' ' + oElement.className + ' ' ).indexOf( sCss.trim() ) == -1 ) oElement.className = oElement.className.trim() + ' ' + sCss.trim(); return oElement; } function hasCssClass( sCss, oElement ) { return ( ' ' + oElement.className + ' ' ).indexOf( sCss.trim() ) > -1; } function removeCssClass( sCss, oElement ) { if ( ( ' ' + oElement.className + ' ' ).indexOf( sCss.trim() ) > -1 ) oElement.className = oElement.className.trim().replace( sCss.trim(), '' ).trim(); return oElement; } function createInfoBoxContent(record,num){ var origaddress = document.getElementById("qs").value; var dealername = getNodeValue(record, "name"); var address = getNodeValue(record, "address"); var distance = parseFloat(getNodeValue(record, "distance")); var zip = getNodeValue(record, "zip"); var city = getNodeValue(record, "city"); var url = getNodeValue(record, "url"); var tel = getNodeValue(record, "tel"); var vicinity_id = getNodeValue(record, "vicinity_id"); var tab_content = '
'; var country = gCountry;//loc_country.value.toLowerCase(); var name, pc, town, street, telephone, vicinity_id; name = ( dealername || '' ); pc = ( zip || '' ); street = ( address || '' ); town = ( city || '' ); telephone = ( tel || '' ); if ( num == '1' ) { tab_content += '

' + Strings.ib_dealer_details + '

'; tab_content += '

' + name + '

'; tab_content += '

' + street + '

'; tab_content += country == 'gb' ? '

' + town + '

' + pc + '

' : '

' + pc + '

' + town + '

'; if ( tel.length > 0 ) { tab_content += '

' + Strings.tel + ' ' + tel + '

'; } if (url.length > 0) { tab_content += '

' + Strings.web + '

'; } tab_content += ''; //tab_content += '

' + Strings.ib_dealer_details + '

'; } tab_content += ''; return tab_content; } function prepRoute( marker, sStart ){ var loc_qs = document.getElementById('qs').value; var dealername = getNodeValue(marker, "name") var routepage = 'route.jsp'; if ( loc_qs == '' && !sStart ) { return handleRoutePrep( marker ); } var urlargs = []; urlargs.push( dealername == '' ? 'nodealer=true' : 'origdealer=' + dealername ); urlargs.push( 'end_lat=' + getNodeValue(marker, "lat") ); urlargs.push( 'end_lng=' + getNodeValue(marker, "lng") ); urlargs.push( 'name=' + dealername ); if ( sStart ) { urlargs.push( 'start_address=' + sStart ); } else { urlargs.push( 'start_address=' + loc_qs ); } window.location = routepage + '?' + urlargs.join( '&' ); //x_loading.style.display = 'block'; } function handleRoutePrep( marker ) { var oClone = document.createElement( 'div' ); var oForm = document.createElement( 'div' ); var oOrig = document.getElementById( 'resultsdiv' ); var oDim = getOffsetPosition( oOrig ); var sHtml = ''; oClone.className = 'routeHandler'; oForm.className = 'routeHandlerInner'; oClone.style.left = oForm.style.left = oDim.left + 'px'; oClone.style.top = oForm.style.top = oDim.top + 'px'; sHtml = '
'; sHtml += ''; sHtml += ''; sHtml += '
'; sHtml += '
Close
'; oForm.innerHTML = sHtml; document.body.appendChild( oClone ); document.body.appendChild( oForm ); oForm.getElementsByTagName( 'form' )[0].onsubmit = function() { if ( this.routeStart && this.routeStart.value != '' ) prepRoute( marker, this.routeStart.value ); if ( oClone && oClone.parentNode ) oClone.parentNode.removeChild( oClone ); if ( oForm && oForm.parentNode ) oForm.parentNode.removeChild( oForm ); return false; } oForm.getElementsByTagName( 'a' )[0].onclick = function() { if ( oClone && oClone.parentNode ) oClone.parentNode.removeChild( oClone ); if ( oForm && oForm.parentNode ) oForm.parentNode.removeChild( oForm ); return false; } } function getOffsetPosition( oNode ) { var oDim = { top: oNode.offsetTop, left: oNode.offsetLeft }; while ( oNode = oNode.offsetParent ) { oDim.top += oNode.offsetTop; oDim.left += oNode.offsetLeft; } return oDim; } // Add a trim method to the string object String.prototype.trim = function() { return this.replace( /^\s+|\s+$/g, '' ); } function selectCountry(myCountry) { target = '?country=' + myCountry; document.location.href = target; } function setUpLinks() { // sets up the clear all | select all links for the filters, wrapping it in a try catch so it // doesn't throw errors on the details and print page try { var filter_list = document.getElementById( 'MMfilter_list' ); var options = document.getElementById( 'options' ); var selectAll = document.getElementById( 's_all' ); var clearAll = document.getElementById( 'c_all' ); var filters = options.parentNode.getElementsByTagName( 'input' ); selectAll.onclick = function() { for ( var i = 0; i < filters.length; i++ ) filters[i].checked = true; return false; } clearAll.onclick = function() { for ( var i = 0; i < filters.length; i++ ) filters[i].checked = false; return false; } } catch(e) {} }