﻿var repairForm = {
	map: Object,
	mapLinks: Object,
	rows: Object,
	init: function() {
		this.rows = $("#serviceCenters tr");
		this.mapLinks = $("#serviceCenters .MapLink");

		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("sidebarMap"));
			$("#sidebarMap").css("display", "none");
		    geocoder = new GClientGeocoder();
			this.mapLinks.click(function() {
				repairForm.rows.each(function() {
					$(this).removeClass("Selected");
				});
		
//				var latLonString = $(this).attr("rel");
//				var lonIndex = latLonString.indexOf("&lon=");
//				var lat = latLonString.substring(4, lonIndex);

//				var lon = latLonString.substring(lonIndex + 5);

//				repairForm.focusMap(lat, lon);
				$(this).parent().parent().addClass("Selected");

				$("#sidebarMap").css("display", "block");

				return false;
			});
				}
	
	},
	focusMap: function(lat, lng) {
		if (map != null) {
			map.setCenter(new GLatLng(lat, lng), 13);
			map.setUIToDefault();
		}
	}
}
function showAddress(address) {
    if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
              if (!point) {
                  alert(address + " not found");
              } else {
                  map.setCenter(point, 13);
                  var marker = new GMarker(point);
                  map.addOverlay(marker);
                  marker.openInfoWindowHtml(address);
              }
          }
        );
    }
}

function initializeRepairForm() {
	repairForm.init();
}

$(function() {
	initializeRepairForm();
});

$(window).unload(function() {
	try { GUnload(); } catch (err) { }
});
