<!-- Begin
/****************************************************************************************
'* Google Maps API Interface                                                            *
'*--------------------------------------------------------------------------------------*
'* Abstract: Display Google Maps on trips, services and other pages shows in "map" div  *
'* Copyright (C) 2006-2010 Prosirius Technologies LLC                                   *
'* You may not download, install, run, use, view, share or modify this program or its   *
'* derivative works without a signed Software License Agreement from Prosirius          *
'* Technologies. US Federal and State Law prohibits these actions if you do not have    *
'* said License. Additional requirements exist. Please email Prosirius Technologies at: *
'* support@prosirius.com for more information.                                          *
'* Last Update: 02-28-07                                                                *
*****************************************************************************************/

    //<![CDATA[

    function showGoogleMap () {

		var position_marker = null;
		var poly_line = null;
		var first_marker = null;
		var bErr = false;
		var markerCount = 0;
		
		try
			{ markerCount = document.GoogleMap.markercount.value-0; }
		catch (e)
			{ bErr = true }

		if ((bErr == false) && (markerCount > 0))
			{
			// Get non-array elements first
    		// the -0 is used to force the variable to numeric
			zom = document.GoogleMap.mapzoom.value-0;
			ovr = document.GoogleMap.mapoverview.value-0;
			ctl = document.GoogleMap.mapcontrol.value-0;
			if ((zom < 1) || ( zom > 17 ))
				zom = 12;

			if (GBrowserIsCompatible()) { 

				function createMarker(point,mOptions,html) {
					if (mOptions != null) {
						var marker = new GMarker(point, mOptions);
					} else {
						var marker = new GMarker(point);
					}
					GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml(html);
					});
				return marker;
				}

				if (ovr == 1) {
					function showPosition(marker, point) {

						if (position_marker != null) {
					      map.removeOverlay(position_marker);
					    }
						if (poly_line != null) {
					      map.removeOverlay(poly_line);
					    }
						// Add Green Marker when clicked
					    position_marker = new GMarker(point, markerOptions);
					    map.addOverlay(position_marker);
						
						// Get Distance in meters from first point
						var f1Point = new GLatLng(first_glt, first_gln); 
						var num_meters = point.distanceFrom(f1Point);
						var dist_type = " miles"
						if (num_meters > 500) {
							var num_dist = Math.round(((num_meters) / 1609.34)*1000)/1000; 
						} else {
							var num_dist = Math.round(((num_meters) * 3.2808399)*1000)/1000; 
							dist_type = " feet"
						}

						// Add Poly Line
						poly_line = new GPolyline([point,f1Point], "#ff0000", 6);
						map.addOverlay(poly_line);
						
						// Add Balloon popup
					    var posmsg = "Position marked is<br />\n";
					    posmsg += "Lat: " + Math.round(point.lat().toString()*1000000)/1000000 + ", ";
					    posmsg += "Long: " + Math.round(point.lng().toString()*1000000)/1000000 + "<br />\n";
						posmsg += "Distance is " + num_dist + dist_type;
						position_marker.openInfoWindowHtml(posmsg);

					  }
				}
				
				var map = new GMap2(document.getElementById("map"));
				var greenIcon = new GIcon(G_DEFAULT_ICON);
				greenIcon.image = "images/icons/greenmap.png";
				markerOptions = { icon:greenIcon };

				if (ctl == 1) {
					map.addControl(new GSmallMapControl());
					map.addControl(new GMapTypeControl());
				}
				if (ovr == 1)
					map.addControl(new GOverviewMapControl());

				// Add listeners for show / hide controls
				map.hideControls();
				GEvent.addListener(map, "mouseover", function(){
					map.showControls();
				});
				GEvent.addListener(map, "mouseout", function(){
					map.hideControls(); 
				});
			
				// Go into loop and get all lat / long pairs
				var glt, gln, pnm, point, marker;

			    for (var i = 0; i < markerCount; ++i) {
				try
					{ 
					pnm = document.getElementById('marker_' + i).value;
					glt = document.getElementById('mapgpslat_' + i).value-0;
					gln = document.getElementById('mapgpslong_' + i).value-0;
					point = new GLatLng(glt,gln);
					if (i==0) { // Use first marker to center map and use default marker
						map.setCenter(point,zom);
						first_marker = createMarker(point,null,'<div>' + pnm + '</div>')
						map.addOverlay(first_marker);
						first_glt = glt;
						first_gln = gln;
					} else { // Use green marker
						marker = createMarker(point,markerOptions,'<div>' + pnm + '</div>')
						map.addOverlay(marker);
					}
					}
				catch (e)
					{ bErr = true }
				}

				// Add position clicking only on larger maps
				if (ovr == 1) 
				    GEvent.addListener(map, "click", showPosition);
			}
		}
    }

    //]]>
// End -->
