// Map Javascript Functions


function mapLocation(loc) {
	var location_name = loc[0];
	var address = loc[1];
	var customer = loc[2];
	var what_installed = loc[3];
	var installation_date = loc[4];
	var type = loc[5];
	var lat = loc[6];
	var lng = loc[7];
		
	if (lat != null && lng != null) {
		createMarker(new GLatLng(lat,lng),location_name,address,customer,what_installed,installation_date,type);
	} else {
		geocoder.getLatLng(
			address,
			function(point) {
			  if (!point) {
				//alert(address + " not found");
			  } else {
				createMarker(point,location_name,address,customer,what_installed,installation_date,type);
			  }
			}
		);
	}
}

// Creates a marker whose info window displays the letter corresponding
// to the given index.
function createMarker(point, location_name, address, customer, what_installed, installation_date, type) {
	var iconType = "installation";
	if (type == 2) {
		iconType = "partner";	
	} else if (type == 3) {
		iconType = "support";	
	} else if (type == 4) {
		iconType = "headquarters";	
	}
	
	// Create new marker icons
	var icon = new GIcon(G_DEFAULT_ICON);
	icon.image = "images/icon_" + iconType + ".png";
	icon.shadow = "images/icon_shadow.png";
	icon.shadowSize = new GSize(21,34);
	icon.iconAnchor = new GPoint(19,34);
	var markerOptions = { icon:icon };
	
	var marker = new GMarker(point,markerOptions);
	var infowindow = "";
	infowindow += "<div class='infowindow'>";
	infowindow += "<strong class='locname'>" + location_name + "</strong><br />";
	infowindow += "<div class='data'>";
	infowindow += "<strong class='customer'>" + customer + "</strong><br />";
	infowindow += "<span class='address'>" + address + "</span><br />";
	if (what_installed.length > 0) infowindow += "What Was Installed: " + what_installed + "<br />";
	if (installation_date.length > 0) infowindow += "Installed in " + installation_date;
	//infowindow += "Lat/Lng: " + point.lat() + ", " + point.lng();
	infowindow += "</div></div>";
	
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(infowindow);
	});
	
	markers.push(marker);
	map.addOverlay(marker);
}
