// JavaScript Document
/* Gary's Google Maps JS File
Some of this was borrowed from other people, but I lost the URLs. Sorry about that.
This is free to use, but please inlcude  this in your code and try to link back to my site

*/

// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(12, 20);
baseIcon.shadowSize = new GSize(15, 25);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);

var red = new GIcon(baseIcon);
red.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
var blue = new GIcon(baseIcon);
blue.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
var yellow = new GIcon(baseIcon);
yellow.image = "http://labs.google.com/ridefinder/images/mm_20_yellow.png";
var green = new GIcon(baseIcon);
green.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";
var purple = new GIcon(baseIcon);
purple.image = "http://labs.google.com/ridefinder/images/mm_20_purple.png";
var orange = new GIcon(baseIcon);
red.image = "http://labs.google.com/ridefinder/images/mm_20_orange.png";
var qm = new Array(); //array for markers 

function createMarker2(point, number, html, icon) {
	var marker = new GMarker(point,icon);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
		});
	qm.push(marker);
	return marker;
}

function GAddress( a ) {
  var xmlhttp = false;
  try {
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    xmlhttp = false;
   }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  var l = new Array();
  ///home/southtah/public_html/cgi-bin/
  xmlhttp.open("GET", "gaddress.cgi?a=" + escape(a), true);
  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) {
   
    l = xmlhttp.responseText.split(',');document.getElementById("latlon").value = l;
    if ( l[0] == '' )
	 alert( "Address Not Found\nPlease Try Again." );
     // c( null, a );
    else
		//myAddress = new GLatLng(37.4419, -122.1419);
		// long is first thing return, lat is second, this is reversed for what gmap wants. 
		map.setCenter(new GLatLng(l[1]-0, l[0]-0), 13);
		//c( l[0], l[1], a );
		var point = new GLatLng(l[1]-0, l[0]-0);
  		map.addOverlay(createMarker(point, 1));   }
  }
  xmlhttp.send(null)
}
// Creates a marker at the given point with the given number label
function createMarker(point, number, html) {
  var marker = new GMarker(point,G_DEFAULT_ICON);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}
function centerMap(lt, ln) {
	map.setCenter(new GLatLng(lt,ln));
}
function setupMarkers() {
  mgr = new GMarkerManager(map);
  mgr.addMarkers(qm, 4);

  mgr.refresh();
}