- var markersArray = [];
- var infowindow;
- function addMarker(location,green)
- {
- marker = new google.maps.Marker(
- {
- position: location,
- map: map
- });
- if (green)
- {
- marker.setIcon("markergreen.png");
- }
- markersArray.push(marker);
- }
- // Removes the overlays from the map, but keeps them in the array
- function clearOverlays()
- {
- if (markersArray)
- {
- for (i in markersArray)
- {
- markersArray[i].setMap(null);
- }
- }
- }
- // Shows any overlays currently in the array
- function showOverlays()
- {
- if (markersArray)
- {
- for (i in markersArray)
- {
- markersArray[i].setMap(map);
- }
- }
- }
- // Deletes all markers in the array by removing references to them
- function deleteOverlays()
- {
- if (markersArray)
- {
- for (i in markersArray)
- {
- markersArray[i].setMap(null);
- }
- markersArray.length = 0;
- }
- }
- $(document).ready(function ()
- {
- $.getJSON('api.php?m=counties', function (data)
- {
- $.each(data, function (i, item)
- {
- $('#county').append('<option value="' + item.county_name + '">' + item.county_name + '</option>');
- $('#afCounty').append('<option value="' + item.county_name + '">' + item.county_name + '</option>');
- });
- });
- if (document.getElementById('mload').value == 'do')
- {
- initialize();
- updateHlMarkers();
- }
- });
- function countyChanged()
- {
- var sCounty = document.getElementById('county').value;
- if (sCounty.length > 0)
- {
- $('#town').find('option').remove().end().append('<option value="notselected" selected>--Area--</option>').val('--Area--');
- $.getJSON('api.php?m=towns&p1=' + sCounty, function (data)
- {
- $.each(data, function (i, item)
- {
- $('#town').append('<option value="' + item.town + '">' + item.town + '</option>');
- $("#town").fadeIn('slow');
- });
- });
- }
- }
- function afCountyChanged()
- {
- $.getJSON('api.php?m=cCo&p1=' + document.getElementById('afCounty').value, function (data)
- {
- $.each(data, function (i, item)
- {
- var crd = new google.maps.LatLng(item.latitude, item.longitude);
- map.setCenter(crd);
- map.setZoom(10);
- });
- });
- var sCounty = document.getElementById('afCounty').value;
- if (sCounty.length > 0)
- {
- $('#afTown').find('option').remove().end().append('<option value="notselected" selected>--Area--</option>').val('--Area--');
- $.getJSON('api.php?m=towns&p1=' + sCounty, function (data)
- {
- $.each(data, function (i, item)
- {
- $('#afTown').append('<option value="' + item.town + '">' + item.town + '</option>');
- });
- });
- }
- }
- function submitStation()
- {
- var rVal = true;
- if (document.getElementById('afCounty').value == 'notselected')
- {
- alert('Please select a county!');
- rVal = false;
- }
- else if (document.getElementById('afTown').value == 'notselected')
- {
- alert('Please select a town!');
- rVal = false;
- }
- else if (!document.getElementById('address1').value)
- {
- alert('Please enter an address!');
- rVal = false
- }
- else if (!document.getElementById('latf').value)
- {
- alert('Please select the station location on the map!');
- rVal = false;
- }
- else if (!document.getElementById('email').value)
- {
- alert('Please enter a valid email!');
- rVal = false;
- }
- else if (isNaN(document.getElementById('pprice').value) || isNaN(document.getElementById('dprice').value) || document.getElementById('dprice').value.length < 0 || document.getElementById('pprice').value.length < 0)
- {
- alert('Please enter a valid price, in cents!');
- rVal = false;
- }
- else if (!document.getElementById('sname').value)
- {
- alert('Please enter a station name!');
- rVal = false;
- }
- return rVal;
- }
- function scCountyChanged()
- {
- $.getJSON('api.php?m=cCo&p1=' + document.getElementById('afCounty').value, function (data)
- {
- $.each(data, function (i, item)
- {
- var crd = new google.maps.LatLng(item.latitude, item.longitude);
- map.setCenter(crd);
- map.setZoom(10);
- });
- });
- updateMarkers();
- }
- function scTownChanged()
- {
- if (document.getElementById('afTown').value != 'notselected')
- {
- if (document.getElementById('afTown').value != 'Other')
- {
- $.getJSON('api.php?m=cTo&p1=' + document.getElementById('afTown').value, function (data)
- {
- $.each(data, function (i, item)
- {
- var crd = new google.maps.LatLng(item.latitude, item.longitude);
- map.setCenter(crd);
- map.setZoom(12);
- });
- });
- }
- else
- {
- scCountyChanged();
- }
- }
- updateMarkers();
- }
- function updateHlMarkers()
- {
- deleteOverlays();
- purgeResTable();
- var temp = true;
- if (document.getElementById('afCounty').value == "notselected")
- {
- $.getJSON('api.php?p1=petrol&m=hl1', function (data) {
- $.each(data, function (i, item)
- {
- var loc = new google.maps.LatLng(item.latitude, item.longitude);
- var markerMsg = '<div style="height:80px"><a href="petrol-stations.php?id=' + item.id + '">' + item.name + '</a><br/><b>' + item.address + '</b><br />Petrol: ' + item.petrol + 'c<br />Diesel: ' + item.diesel + 'c</div>';
- addMarker(loc,temp);
- if (!infowindow)
- {
- infowindow = new google.maps.InfoWindow(
- {
- content: markerMsg
- });
- }
- google.maps.event.addListener(markersArray[markersArray.length - 1], 'click', buildClickHandler(markersArray[markersArray.length - 1], markerMsg));
- temp = false;
- });
- });
- }
- else if (document.getElementById('afTown').value == "notselected")
- {
- $.getJSON('api.php?m=hl2&p1=petrol&p2=' + document.getElementById('afCounty').value, function (data)
- {
- $.each(data, function (i, item)
- {
- var loc = new google.maps.LatLng(item.latitude, item.longitude);
- var markerMsg = '<div style="height:80px"><a href="petrol-stations.php?id=' + item.id + '">' + item.name + '</a><br/><b>' + item.address + '</b><br />Petrol: ' + item.petrol + 'c<br />Diesel: ' + item.diesel + 'c</div>';
- addMarker(loc,temp);
- if (!infowindow)
- {
- infowindow = new google.maps.InfoWindow(
- {
- content: markerMsg
- });
- }
- google.maps.event.addListener(markersArray[markersArray.length - 1], 'click', buildClickHandler(markersArray[markersArray.length - 1], markerMsg));
- temp = false;
- });
- });
- }
- else
- {
- $.getJSON('api.php?m=hl3&p1=petrol&p2=' + document.getElementById('afCounty').value + '&p3=' + document.getElementById('afTown').value, function (data)
- {
- $.each(data, function (i, item)
- {
- var loc = new google.maps.LatLng(item.latitude, item.longitude);
- var markerMsg = '<div style="height:80px"><a href="petrol-stations.php?id=' + item.id + '">' + item.name + '</a><br/><b>' + item.address + '</b><br />Petrol: ' + item.petrol + 'c<br />Diesel: ' + item.diesel + 'c</div>';
- addMarker(loc,temp);
- if (!infowindow)
- {
- infowindow = new google.maps.InfoWindow(
- {
- content: markerMsg
- });
- }
- google.maps.event.addListener(markersArray[markersArray.length - 1], 'click', buildClickHandler(markersArray[markersArray.length - 1], markerMsg));
- temp = false;
- });
- });
- }
- if (document.getElementById('afCounty').value == "notselected")
- {
- temp = true;
- $.getJSON('api.php?p1=diesel&m=hl1', function (data) {
- $.each(data, function (i, item)
- {
- alert(temp);
- var loc = new google.maps.LatLng(item.latitude, item.longitude);
- var markerMsg = '<div style="height:80px"><a href="petrol-stations.php?id=' + item.id + '">' + item.name + '</a><br/><b>' + item.address + '</b><br />Petrol: ' + item.petrol + 'c<br />Diesel: ' + item.diesel + 'c</div>';
- addMarker(loc,temp);
- if (!infowindow)
- {
- infowindow = new google.maps.InfoWindow(
- {
- content: markerMsg
- });
- }
- google.maps.event.addListener(markersArray[markersArray.length - 1], 'click', buildClickHandler(markersArray[markersArray.length - 1], markerMsg));
- temp = false;
- });
- });
- }
- else if (document.getElementById('afTown').value == "notselected")
- {
- temp = true;
- $.getJSON('api.php?m=hl2&p1=diesel&p2=' + document.getElementById('afCounty').value, function (data)
- {
- $.each(data, function (i, item)
- {
- alert(temp);
- var loc = new google.maps.LatLng(item.latitude, item.longitude);
- var markerMsg = '<div style="height:80px"><a href="petrol-stations.php?id=' + item.id + '">' + item.name + '</a><br/><b>' + item.address + '</b><br />Petrol: ' + item.petrol + 'c<br />Diesel: ' + item.diesel + 'c</div>';
- addMarker(loc,temp);
- if (!infowindow)
- {
- infowindow = new google.maps.InfoWindow(
- {
- content: markerMsg
- });
- }
- google.maps.event.addListener(markersArray[markersArray.length - 1], 'click', buildClickHandler(markersArray[markersArray.length - 1], markerMsg));
- temp = false;
- });
- });
- }
- else
- {
- temp = true;
- $.getJSON('api.php?m=hl3&p1=diesel&p2=' + document.getElementById('afCounty').value + '&p3=' + document.getElementById('afTown').value, function (data)
- {
- $.each(data, function (i, item)
- {
- alert(temp);
- var loc = new google.maps.LatLng(item.latitude, item.longitude);
- var markerMsg = '<div style="height:80px"><a href="petrol-stations.php?id=' + item.id + '">' + item.name + '</a><br/><b>' + item.address + '</b><br />Petrol: ' + item.petrol + 'c<br />Diesel: ' + item.diesel + 'c</div>';
- addMarker(loc,temp);
- if (!infowindow)
- {
- infowindow = new google.maps.InfoWindow(
- {
- content: markerMsg
- });
- }
- google.maps.event.addListener(markersArray[markersArray.length - 1], 'click', buildClickHandler(markersArray[markersArray.length - 1], markerMsg));
- temp = false;
- });
- });
- }
- }
- function hlChanged(wasC)
- {
- if (wasC)
- {
- $.getJSON('api.php?m=cCo&p1=' + document.getElementById('afCounty').value, function (data)
- {
- $.each(data, function (i, item)
- {
- var crd = new google.maps.LatLng(item.latitude, item.longitude);
- map.setCenter(crd);
- map.setZoom(10);
- });
- });
- $('#afTown').find('option').remove().end().append('<option value="notselected" selected>--Area--</option>').val('--Area--');
- $.getJSON('api.php?m=towns&p1=' + document.getElementById('afCounty').value, function (data)
- {
- $.each(data, function (i, item)
- {
- $('#afTown').append('<option value="' + item.town + '">' + item.town + '</option>');
- });
- });
- }
- if (document.getElementById('afTown').value != 'notselected')
- {
- if (document.getElementById('afTown').value != 'Other')
- {
- $.getJSON('api.php?m=cTo&p1=' + document.getElementById('afTown').value, function (data)
- {
- $.each(data, function (i, item)
- {
- var crd = new google.maps.LatLng(item.latitude, item.longitude);
- map.setCenter(crd);
- map.setZoom(12);
- });
- });
- }
- else
- {
- $.getJSON('api.php?m=cCo&p1=' + document.getElementById('afCounty').value, function (data)
- {
- $.each(data, function (i, item)
- {
- var crd = new google.maps.LatLng(item.latitude, item.longitude);
- map.setCenter(crd);
- map.setZoom(10);
- });
- });
- }
- }
- updateHlMarkers();
- }
- function buildClickHandler(marker, message)
- {
- return function ()
- {
- infowindow.setContent(message);
- infowindow.open(map, marker);
- }
- }
- function updateMarkers()
- {
- deleteOverlays();
- purgeResTable();
- $.getJSON('api.php?m=stations&p1=' + document.getElementById('afCounty').value + '&p2=' + document.getElementById('afTown').value, function (data)
- {
- $.each(data, function (i, item)
- {
- var loc = new google.maps.LatLng(item.latitude, item.longitude);
- var markerMsg = '<div style="height:80px"><a href="petrol-stations.php?id=' + item.id + '">' + item.name + '</a><br/><b>' + item.address + '</b><br />Petrol: ' + item.petrol + 'c<br />Diesel: ' + item.diesel + 'c</div>';
- addMarker(loc);
- if (!infowindow)
- {
- infowindow = new google.maps.InfoWindow(
- {
- content: markerMsg
- });
- }
- google.maps.event.addListener(markersArray[markersArray.length - 1], 'click', buildClickHandler(markersArray[markersArray.length - 1], markerMsg));
- $('#resTable tr:last').after('<tr><td><a href="petrol-stations.php?id=' + item.id + '">' + item.name + '</a></td><td>' + item.town + ', Co. ' + item.county + '</td><td>' + item.petrol + '</td><td>' + item.diesel + '</td></tr>');
- $("#resDiv").fadeIn('slow');
- });
- });
- }
- function purgeResTable()
- {
- $("#resTable").find("tr:gt(0)").remove();
- }