var default_lat = 50.0; var default_lng = 14.4; var default_radius = 10; var zoom_level = 6; var map_width = "100%"; var map_height = "350px"; var special_text = ""; var units = "km"; var limit = "50"; var plugin_url = "http://www.restaurace.net/wp-content/plugins/simplemap/"; var autozoom = false; var default_domain = ".cz"; var address_format = "town postalcode"; var visit_website_text = "Detail"; var get_directions_text = "Get Directions"; var location_tab_text = "Location"; var description_tab_text = "Description"; var phone_text = "Phone"; var fax_text = "Fax"; var tags_text = "Tags"; var noresults_text = "No results found"; var map; var geocoder; function codeAddress() { geocoder = new GClientGeocoder(); var d_address = document.getElementById("default_address").value; //alert(address); geocoder.getLatLng(d_address, function(latlng) { document.getElementById("default_lat").value = latlng.lat(); document.getElementById("default_lng").value = latlng.lng(); }); } function codeNewAddress() { if (document.getElementById("store_lat").value != '' && document.getElementById("store_lng").value != '') { document.new_location_form.submit(); } else { geocoder = new GClientGeocoder(); var address = ''; var street = document.getElementById("store_address").value; var city = document.getElementById("store_city").value; var state = document.getElementById("store_state").value; var country = document.getElementById("store_country").value; if (street) { address += street + ', '; } if (city) { address += city + ', '; } if (state) { address += state + ', '; } address += country; geocoder.getLatLng(address, function(latlng) { document.getElementById("store_lat").value = latlng.lat(); document.getElementById("store_lng").value = latlng.lng(); document.new_location_form.submit(); }); } } function codeChangedAddress() { geocoder = new GClientGeocoder(); var address = ''; var street = document.getElementById("store_address").value; var city = document.getElementById("store_city").value; var state = document.getElementById("store_state").value; var country = document.getElementById("store_country").value; if (street) { address += street + ', '; } if (city) { address += city + ', '; } if (state) { address += state + ', '; } address += country; geocoder.getLatLng(address, function(latlng) { document.getElementById("store_lat").value = latlng.lat(); document.getElementById("store_lng").value = latlng.lng(); }); } function searchLocations(categories) { var address = document.getElementById('addressInput').value; address = address.replace(/&/gi, " "); geocoder.getLatLng(address, function(latlng) { if (!latlng) { latlng = new GLatLng(150,100); searchLocationsNear(latlng, address, "search", "unlock", categories); } else { searchLocationsNear(latlng, address, "search", "unlock", categories); } }); } function searchLocationsNear(center, homeAddress, source, mapLock, categories) { if (document.getElementById('radiusSelect')) { if (units == 'mi') { var radius = parseInt(document.getElementById('radiusSelect').value); } else if (units == 'km') { var radius = parseInt(document.getElementById('radiusSelect').value) / 1.609344; } } else { if (units == 'mi') { var radius = parseInt(default_radius); } else if (units == 'km') { var radius = parseInt(default_radius) / 1.609344; } } if (source == 'auto_all') { var searchUrl = plugin_url + 'actions/create-xml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=infinite&namequery=' + homeAddress + '&limit=0&categories=' + categories; } else { var searchUrl = plugin_url + 'actions/create-xml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius + '&namequery=' + homeAddress + '&limit=' + limit + '&categories=' + categories; } GDownloadUrl(searchUrl, function(data) { var xml = GXml.parse(data); var markers = xml.documentElement.getElementsByTagName('marker'); map.clearOverlays(); var results = document.getElementById('results'); results.innerHTML = ''; if (markers.length == 0) { results.innerHTML = '

' + noresults_text + '

'; map.setCenter(new GLatLng(default_lat,default_lng), zoom_level); return; } var bounds = new GLatLngBounds(); for (var i = 0; i < markers.length; i++) { var name = markers[i].getAttribute('name'); var address = markers[i].getAttribute('address'); var address2 = markers[i].getAttribute('address2'); var city = markers[i].getAttribute('city'); var state = markers[i].getAttribute('state'); var zip = markers[i].getAttribute('zip'); var country = markers[i].getAttribute('country'); var distance = parseFloat(markers[i].getAttribute('distance')); var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')), parseFloat(markers[i].getAttribute('lng'))); var url = markers[i].getAttribute('url'); var phone = markers[i].getAttribute('phone'); var fax = markers[i].getAttribute('fax'); var special = markers[i].getAttribute('special'); var category = markers[i].getAttribute('category'); var tags = markers[i].getAttribute('tags'); if (markers[i].firstChild) { var description = markers[i].firstChild.nodeValue; } else { var description = ''; } var marker = createMarker(point, name, address, address2, city, state, zip, country, homeAddress, url, phone, fax, special, category, tags, description); map.addOverlay(marker); var sidebarEntry = createSidebarEntry(marker, name, address, address2, city, state, zip, country, distance, homeAddress, phone, fax, url, special, category, tags, description); results.appendChild(sidebarEntry); bounds.extend(point); } if (source == "search") { map.setCenter(bounds.getCenter(), (map.getBoundsZoomLevel(bounds) - 1)); } else if (mapLock == "unlock") { map.setCenter(bounds.getCenter(), autozoom); } }); } function stringFilter(s) { filteredValues = "emnpxt%"; // Characters stripped out var i; var returnString = ""; for (i = 0; i < s.length; i++) { // Search through string and append to unfiltered values to returnString. var c = s.charAt(i); if (filteredValues.indexOf(c) == -1) returnString += c; } return returnString; } function createMarker(point, name, address, address2, city, state, zip, country, homeAddress, url, phone, fax, special, category, tags, description) { var marker = new GMarker(point); var mapwidth = Number(stringFilter(map_width)); var mapheight = Number(stringFilter(map_height)); var maxbubblewidth = Math.round(mapwidth / 1.5); var maxbubbleheight = Math.round(mapheight / 2.2); var fontsize = 12; var lineheight = 12; var titleheight = 3 + Math.floor((name.length + category.length) * fontsize / (maxbubblewidth * 1.5)); //var titleheight = 2; var addressheight = 2; if (address2 != '') { addressheight += 1; } if (phone != '' || fax != '') { addressheight += 1; if (phone != '') { addressheight += 1; } if (fax != '') { addressheight += 1; } } var tagsheight = 3; var linksheight = 2; var totalheight = (titleheight + addressheight + tagsheight + linksheight + 1) * fontsize; if (totalheight > maxbubbleheight) { totalheight = maxbubbleheight; } var html = '
'; html += '

' + name + '
' + category + '

'; html += '

' + address; if (address2 != '') { html += '
' + address2; } if (address_format == 'town, province postalcode') { html += '
' + city + ', ' + state + ' ' + zip + '

'; } else if (address_format == 'town province postalcode') { html += '
' + city + ' ' + state + ' ' + zip + '

'; } else if (address_format == 'town-province postalcode') { html += '
' + city + '-' + state + ' ' + zip + '

'; } else if (address_format == 'postalcode town-province') { html += '
' + zip + ' ' + city + '-' + state + '

'; } else if (address_format == 'postalcode town, province') { html += '
' + zip + ' ' + city + ', ' + state + '

'; } else if (address_format == 'postalcode town') { html += '
' + zip + ' ' + city + '

'; } else if (address_format == 'town postalcode') { html += '
' + city + ' ' + zip + '

'; } if (phone != '') { html += '

' + phone_text + ': ' + phone; if (fax != '') { html += '
' + fax_text + ': ' + fax; } html += '

'; } else if (fax != '') { html += '

' + fax_text + ': ' + fax + '

'; } if (tags != '') { html += '

' + tags_text + ': ' + tags + '

'; } var dir_address = address + ',' + city; if (state) { dir_address += ',' + state; } if (zip) { dir_address += ',' + zip; } if (country) { dir_address += ',' + country; } html += ' '; html += '
'; if (description != '') { var numlines = Math.ceil(description.length / 40); var newlines = description.split('
').length - 1; var totalheight2 = 0; if (description.indexOf(' maxbubbleheight) { totalheight2 = maxbubbleheight; } var html2 = '
' + description + '
'; GEvent.addListener(marker, 'click', function() { marker.openInfoWindowTabsHtml([new GInfoWindowTab(location_tab_text, html), new GInfoWindowTab(description_tab_text, html2)], {maxWidth: maxbubblewidth}); window.location = '#map_top'; }); } else { GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html, {maxWidth: maxbubblewidth}); window.location = '#map_top'; }); } return marker; } function createSidebarEntry(marker, name, address, address2, city, state, zip, country, distance, homeAddress, phone, fax, url, special, category, tags, description) { var div = document.createElement('div'); // Beginning of result var html = '
'; // Flagged special if (special == 1 && special_text != '') { html += '
' + special_text + '
'; } // Name & distance html += '
'; html += '

' + name; if (distance.toFixed(1) != 'NaN') { if (units == 'mi') { html+= ' ' + distance.toFixed(1) + ' miles'; } else if (units == 'km') { html+= ' ' + (distance * 1.609344).toFixed(1) + ' km'; } } html += '

'; // Address html += '
' + address; if (address2 != '') { html += '
' + address2; } if (address_format == 'town, province postalcode') { html += '
' + city + ', ' + state + ' ' + zip + '
'; } else if (address_format == 'town province postalcode') { html += '
' + city + ' ' + state + ' ' + zip + '
'; } else if (address_format == 'town-province postalcode') { html += '
' + city + '-' + state + ' ' + zip + ''; } else if (address_format == 'postalcode town-province') { html += '
' + zip + ' ' + city + '-' + state + ''; } else if (address_format == 'postalcode town, province') { html += '
' + zip + ' ' + city + ', ' + state + ''; } else if (address_format == 'postalcode town') { html += '
' + zip + ' ' + city + ''; } else if (address_format == 'town postalcode') { html += '
' + city + ' ' + zip + ''; } // Phone & fax numbers html += '
'; if (phone != '') { html += phone_text + ': ' + phone; } if (fax != '') { html += '
' + fax_text + ': ' + fax; } html += '
'; // Links section html += ''; html += '
'; // End of result html += ''; div.innerHTML = html; div.style.cursor = 'pointer'; div.style.margin = 0; GEvent.addDomListener(div, 'click', function() { GEvent.trigger(marker, 'click'); }); GEvent.addDomListener(div, 'mouseover', function() { //div.style.backgroundColor = '#eee'; }); GEvent.addDomListener(div, 'mouseout', function() { //div.style.backgroundColor = '#fff'; }); return div; }