////////////////////////////////////////////////////////////////////////////////////////
var map;
var g_count = 0;
var g_index = 0;
var g_geocoder = new GClientGeocoder();
////////////////////////////////////////////////////////////////////////////////////////
window.onload = init;
window.onunload = GUnload;
////////////////////////////////////////////////////////////////////////////////////////
document.onkeypress = keyhandler;
function keyhandler(e) {
var charCode;
if (e && e.which) {
charCode = e.which;
} else if (window.event) {
e = window.event;
charCode = e.keyCode;
}
if (charCode == 13) {
var zip = document.getElementById('zip').value;
var city = document.getElementById('city').value.toLowerCase();
var state = document.getElementById('state').value.toUpperCase();
if (zip != '') {
onClickSearchZip();
}
else if (state != '') {
onClickSearchState();
}
else {
onClickSearchCountry();
}
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////////////
function init() {
document.getElementById("map").style.width = "643px";
map = new GMap2(document.getElementById("map"));
map.setMapType(G_NORMAL_MAP);
map.addControl(new GLargeMapControl());
map.setCenter(new GLatLng(39.3683, -93.691442), 3);
document.getElementById('sidebar').style.display = "none";
document.getElementById('zip').focus();
if (g_loc != '') {
document.getElementById('state').value = g_loc;
onClickSearchState();
}
}
////////////////////////////////////////////////////////////////////////////////////////
function hideMarkers() {
document.getElementById("map").style.width = "430px";
map.checkResize();
for (id in markers) {
markers[id].visible = false;
map.clearOverlays();
}
}
////////////////////////////////////////////////////////////////////////////////////////
function showMarkers() {
clearList();
addCountHeader();
g_index = 0;
for (id in markers) {
if (markers[id].visible == true) {
createMarker(id);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////
function onClickSearchZip() {
var zip = document.getElementById('zip').value;
if (zip == '') {
alert('Please enter a zip code');
document.getElementById('zip').focus();
return;
}
var addr = zip + ',USA';
var startZoom = 7;
var radius = document.getElementById('radiuszip').value;
if (radius == 5) {
startZoom = 11;
}
else if (radius == 10) {
startZoom = 9;
}
else if (radius == 20) {
startZoom = 8;
}
g_geocoder.getLatLng(addr, function(pointaddr) {
if (pointaddr) {
hideMarkers();
map.setCenter(pointaddr, startZoom);
g_count = 0;
for (id in markers) {
var distance = LatLon.distHaversine(pointaddr.lat(), pointaddr.lng(), markers[id].latitude, markers[id].longitude);
distance = distance * 0.621371192;
if (distance < radius) {
g_count++;
markers[id].visible = true;
markers[id].distance = distance.toString();
}
}
markers.sort(function(a, b) { return parseInt(a.distance) - parseInt(b.distance) });
showMarkers();
}
});
}
////////////////////////////////////////////////////////////////////////////////////////
function onClickSearchState() {
var city = document.getElementById('city').value.toLowerCase();
var state = document.getElementById('state').value.toUpperCase();
var radius = document.getElementById('radiusstate').value;
if (state == '') {
alert('Please select a state');
document.getElementById('state').focus();
return;
}
var addr = '';
var startZoom = 0;
if (city != '') {
addr = city + ',' + state + ',USA';
startZoom = 10;
}
else if (state != '') {
addr = state + ',USA';
startZoom = 6;
}
g_geocoder.getLatLng(addr, function(pointaddr) {
if (pointaddr) {
hideMarkers();
map.setCenter(pointaddr, startZoom);
g_count = 0;
for (id in markers) {
var distance = LatLon.distHaversine(pointaddr.lat(), pointaddr.lng(), markers[id].latitude, markers[id].longitude);
distance = distance * 0.621371192;
if (city != '' && state != '') {
if (distance < radius || (markers[id].state == state && markers[id].city == city)) {
g_count++;
markers[id].visible = true;
markers[id].distance = distance.toString();
}
}
else if (state != '') {
if (distance < radius || markers[id].state == state) {
g_count++;
markers[id].visible = true;
markers[id].distance = distance.toString();
}
}
}
if (city != '') {
markers.sort(function(a, b) { return parseInt(a.distance) - parseInt(b.distance) });
}
else {
markers.sort(function(a, b) { return (a.name > b.name) ? +1 : -1; });
}
showMarkers();
}
});
}
////////////////////////////////////////////////////////////////////////////////////////
function onClickSearchCountry() {
var country = document.getElementById('ctl00_ctl00_MainContent_CountryDropDownList').value.toLowerCase();
// get addr
var addr = country;
var startZoom = 3;
g_geocoder.getLatLng(addr, function(pointaddr) {
if (pointaddr) {
hideMarkers();
map.setCenter(pointaddr, startZoom);
g_count = 0;
for (id in markers) {
var distance = LatLon.distHaversine(pointaddr.lat(), pointaddr.lng(), markers[id].latitude, markers[id].longitude);
distance = distance * 0.621371192;
if (markers[id].country == country) {
g_count++;
markers[id].visible = true;
markers[id].distance = distance.toString();
}
}
markers.sort(function(a, b) { return (a.name > b.name) ? +1 : -1; });
showMarkers();
}
});
}
////////////////////////////////////////////////////////////////////////////////////////
function onStateChanged() {
document.getElementById('zip').value = '';
document.getElementById('ctl00_ctl00_MainContent_CountryDropDownList').value = '';
}
////////////////////////////////////////////////////////////////////////////////////////
function onCountryChanged() {
document.getElementById('zip').value = '';
document.getElementById('city').value = '';
document.getElementById('state').value = '';
}
////////////////////////////////////////////////////////////////////////////////////////
function createMarker(id) {
var pointData = markers[id];
if (pointData.latitude != 0) {
addMarker(id, new GLatLng(pointData.latitude, pointData.longitude));
}
}
////////////////////////////////////////////////////////////////////////////////////////
function addMarker(id, point) {
g_index++;
var pointData = markers[id];
var icon = new GIcon();
var iconimage = '';
if (g_index <= 25) {
iconimage = 'imagesx/mapicons/iconr' + g_index.toString() + '.png';
}
else if (g_index <= 50) {
iconimage = 'imagesx/mapicons/iconb' + (g_index - 25).toString() + '.png';
}
else if (g_index <= 75) {
iconimage = 'imagesx/mapicons/icong' + (g_index - 50).toString() + '.png';
}
else {
iconimage = 'imagesx/mapicons/iconr.png';
}
icon.image = iconimage;
icon.iconSize = new GSize(20, 34);
icon.iconAnchor = new GPoint(16, 16);
opts = {
"icon": icon,
"clickable": true,
"draggable": false,
"labelText": ''
};
var marker = new LabeledMarker(point, opts);
map.addOverlay(marker);
GEvent.addListener(
marker,
"mouseover",
function() {
popupLocation(id);
}
);
buildList(id, iconimage);
return marker;
}
////////////////////////////////////////////////////////////////////////////////////////
function popupLocation(id) {
var pointData = markers[id];
var content = getContent(id);
map.openInfoWindowHtml(new GLatLng(pointData.latitude, pointData.longitude), content);
}
////////////////////////////////////////////////////////////////////////////////////////
function buildList(id, iconimage) {
var pointData = markers[id];
var listItem = document.createElement('li');
var content = ""
content += "";
content += "
";
content += getContent(id);
content += "";
listItem.innerHTML = content;
document.getElementById('sidebar-list').appendChild(listItem);
}
////////////////////////////////////////////////////////////////////////////////////////
function addCountHeader() {
if (g_count == 0) {
var listItem = document.createElement('li');
listItem.innerHTML += "We are sorry but we did not find any locations that match your search. Please try again";
document.getElementById('sidebar-list').appendChild(listItem);
}
else {
var listItem = document.createElement('li');
listItem.innerHTML += "" + g_count.toString() + " Location(s) Found";
document.getElementById('sidebar-list').appendChild(listItem);
}
}
////////////////////////////////////////////////////////////////////////////////////////
function clearList() {
document.getElementById('sidebar').style.display = "block";
var ul = document.getElementById('sidebar-list');
var li = ul.firstChild;
while (li) {
ul.removeChild(li);
li = ul.firstChild;
}
}
////////////////////////////////////////////////////////////////////////////////////////
function lookupAddress(id) {
var pointData = markers[id];
g_geocoder.getLatLng(pointData.addr1, function(point) {
if (!point) {
g_geocoder.getLatLng(pointData.addr2, function(point) {
if (point) {
s = "update g_info set latitude = '" + point.lat() + "', longitude='" + point.lng() + "' where gymid = " + pointData.placeid + "
";
document.getElementById('latlng').innerHTML += s;
addMarker(id, point);
}
});
}
else {
s = "update g_info set latitude = '" + point.lat() + "', longitude='" + point.lng() + "' where gymid = " + pointData.placeid + "
";
document.getElementById('latlng').innerHTML += s;
addMarker(id, point);
}
});
}
////////////////////////////////////////////////////////////////////////////////////////