	

	//=================================================================
	// Address Geocoder 
	//=================================================================


	var map;
	var geocoder;

	function loadAddressGeocoder() {
		map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(34, 0), 1);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
	}

	// showLocation() is called when you click on the Search button
	// in the form.  It geocodes the address entered into the form
	// and adds a marker to the map at that location.
	function showLocation() {
		//var first_name = document.forms[0].first_name.value;
		//var last_name = document.forms[0].last_name.value;
		var address = document.forms[0].address.value;
		var city = document.forms[0].city.value;
		var state = document.getElementById('state').value;
		var zip = document.forms[0].zip.value;

		var full_address=address+' '+city+','+state+' '+zip;
		//alert(full_address);
		geocoder.getLocations(full_address, addAddressToMap);
	}


	// addAddressToMap() is called when the geocoder returns an
	// answer.  It adds a marker to the map with an open info window
	// showing the nicely formatted version of the address and the country code.

	function addAddressToMap(response) {
		map.clearOverlays();
		if (!response || response.Status.code != 200) {
		   alert("Sorry, we were unable to geocode that address.");
		} else {
		   place = response.Placemark[0];
		   point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
		   marker = new GMarker(point);
		   map.setCenter(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]), 13);
		   map.addOverlay(marker);

		   latCoord = place.Point.coordinates[1];
		   document.getElementById('latCoord').value=latCoord;
		   lngCoord = place.Point.coordinates[0];
		   document.getElementById('lngCoord').value=lngCoord;

		   marker.openInfoWindowHtml(document.forms[0].first_name.value+' '+document.forms[0].last_name.value+
			 '<br/><b>Group Name: '+document.forms[0].group_name.value+'</b>'+
		     '<br/>'+place.address + '<br>' +
			 //'<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode + 
			 '<br/>Lat: '+place.Point.coordinates[1]+
			 '<br/>Lng: '+place.Point.coordinates[0]);
		}
	}

	

	

	// findLocation() is used to enter the sample addresses into the form.
	//function findLocation(address) {
	//document.forms[0].q.value = address;
	//showLocation();
	//}
	
	// This is like the showLocation() function but is customized for the Group Locator Form
	function showGroupLocation() {
		//var first_name = document.forms[0].first_name.value;
		//var last_name = document.forms[0].last_name.value;
		//var addr1 = document.forms[0].addr1.value;
		var addr1 = document.getElementById("addr1").value;
		//var city = document.forms[0].city.value;
		var city = document.getElementById("city").value;
		//var state = document.forms[0].state.value;
		var state = document.getElementById("state").value;
		//var zip = document.forms[0].zip.value;
		var zip = document.getElementById("zip").value;		

		var full_address=addr1+' '+city+','+state+' '+zip;
		//alert(full_address);
		geocoder.getLocations(full_address, addGroupAddressToMap);
	}

	
	function addGroupAddressToMap(response) {
		map.clearOverlays();
		if (!response || response.Status.code != 200) {
		   alert("Sorry, we were unable to geocode that address");
		} else {
		   //Page Specific Form Button
		   Show("submitBTN");
		   place = response.Placemark[0];
		   point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
		   marker = new GMarker(point);
		   map.setCenter(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]), 13);
		   map.addOverlay(marker);
		   
		   latCoord = place.Point.coordinates[1];
		   document.getElementById('lat').value=latCoord;
		   lngCoord = place.Point.coordinates[0];
		   document.getElementById('lng').value=lngCoord;
		  
		   marker.openInfoWindowHtml('<br/><b>Group Name:'+document.getElementById("name").value+'</b>'+
		   '<br/>'+place.address + '<br>' + '<br/>Lat: '+place.Point.coordinates[1]+'<br/>Lng: '+place.Point.coordinates[0]);
			 
			 
		}

		
	}

	//=================================================================
	// Query Based 
	//=================================================================


    var iconBlue = new GIcon(); 
    iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconBlue.iconSize = new GSize(12, 20);
    iconBlue.shadowSize = new GSize(22, 20);
    iconBlue.iconAnchor = new GPoint(6, 20);
    iconBlue.infoWindowAnchor = new GPoint(5, 1);

    var iconRed = new GIcon(); 
    iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
    iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconRed.iconSize = new GSize(12, 20);
    iconRed.shadowSize = new GSize(22, 20);
    iconRed.iconAnchor = new GPoint(6, 20);
    iconRed.infoWindowAnchor = new GPoint(5, 1);

	var iconPNP = new GIcon(); 
    iconPNP.image = 'http://www.stonecroft.org/elithica/images/design_images/pray_and_play/polka_pin.png';
    iconPNP.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
    iconPNP.iconSize = new GSize(24, 24);
    iconPNP.shadowSize = new GSize(28, 20);
    iconPNP.iconAnchor = new GPoint(6, 20);
    iconPNP.infoWindowAnchor = new GPoint(5, 1);

    var customIcons = [];
    customIcons["HQ"] = iconBlue;
    customIcons["Group"] = iconRed;
	customIcons["prayandplay"] = iconPNP;

	

	var map;
	var php_gmap_xml = "gmap_xml.php";
	var bounds = new GLatLngBounds();

	function changeQueryMap(new_url){
		php_gmap_xml=new_url;
		//alert(php_gmap_xml);
		loadQueryMap();
	}
	
	
    function loadQueryMap() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(38.9421495, -94.5465354), 3);
		//map.setCenter(new GLatLng(34, 0), 1);

		
        GDownloadUrl(php_gmap_xml, function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
            var group_name = markers[i].getAttribute("group_name");
			var group_number = markers[i].getAttribute("group_number");
			var email = markers[i].getAttribute("email");	
			var contact = markers[i].getAttribute("first_name")+' '+markers[i].getAttribute("last_name");
            var address = markers[i].getAttribute("address");
			//var info=contact+'<br/>'+address+'<br/><a href=\'mailto:'+email+'\'>'+email+'</a>';
			var type = markers[i].getAttribute("type");
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                    parseFloat(markers[i].getAttribute("lng")));
            var marker = createMarker(point, group_name, address, email, type, group_number);
			map.addOverlay(marker);
			
          }
			//Set Map to last point
			
			if(php_gmap_xml != "gmap_xml.php"){
				
				if(php_gmap_xml == "gmap_xml.php?country=CANADA"){
					map.setZoom(3);
				}else{
					if(php_gmap_xml == "gmap_xml.php?="){
						map.setZoom(2);
					}else{
						//alert(php_gmap_xml);
						map.setZoom(5);
						map.panTo(point);
					}
				}
				
			}else{
				
				map.setZoom(2);		
			}
			
	     });		
      }
	  
      
    }

    function createMarker(point, name, address, email, type, group_number) {
      var marker = new GMarker(point, customIcons[type]);
	  //var dir_form="<div style='width:235px;overflow:auto;'><form action='http://maps.google.com/maps' method='get'  target='_blank'><p><b>Want Directions?</b><img src='http://www.google.com/options/icons/maps.gif' style='float:left; margin-right:5px;margin-top:10px;'><label for='saddr'><br/>Enter your address<br/> or ZIP code here:</label><br/><input type='text' name='saddr' id='saddr' value='' style='font-family:arial; font-size:9pt;width:200px;'/><br/><input type='submit' value='Get Directions' class='standardBTN'/><input type='hidden' name='daddr' value='"+address+"' /><input type='hidden' name='hl' value='en' /></p>";
      //var html = "<img src='http://www.stonecroft.org/sc_email_logo.png' style='width:70px; height:40px;'><br/><b>" + name + "</b> <br/>" + address +"<br/><a href='http://www.stonecroftministries.org/glp/groupinfo.asp?grpno="+group_number+"' target='_BLANK'>Meeting Info</a><br/><a href='mailto:"+email+"'>"+email+"</a><br/>"+dir_form+"</div>";
      
	  if(type=="prayandplay"){	
		var html ="<div style='width:235px;overflow:auto;font-family:arial; font-size:9pt;'><img src='http://www.stonecroft.org/sc_email_logo.png' style='width:70px; height:40px;font-family:arial; font-size:8pt;'><img src='http://www.stonecroft.org/elithica/images/design_images/pray_and_play/polka_flower_green.png' style='float:left;margin-left:5px;'><br/><b style='color:#904FCE;'>" + name + "</b> <br/>" + address +"<br/>Contact Pauletta Staley at <a href='mailto:pstaley@stonecroft.org' >pstaley@stonecroft.org</a><br/><a href='http://www.stonecroft.org/elithica2/pray_and_play.php' target='_BLANK'>www.stonecroft.org/prayandplay</a><br/><u class='pointer' onclick=\"window.parent.Show('directions');window.parent.document.getElementById('daddr').value='"+address+", USA';\">Get Directions</u></div>";
			//Contact Pauletta Staley at pstaley@stonecroft.org
	  }else{
		var html = "<div style='width:235px;overflow:auto;font-family:arial; font-size:9pt;'><img src='http://www.stonecroft.org/sc_email_logo.png' style='width:70px; height:40px;font-family:arial; font-size:8pt;'><br/><b>" + name + "</b> <br/>" + address +"<br/><a href='mailto:"+email+"'>"+email+"</a><br/><u class='pointer' onclick=\"window.parent.Show('directions');window.parent.document.getElementById('daddr').value='"+address+", USA';\">Get Directions (will open below map)</u></div>";
      }
	  GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html);
      });
      return marker;
    }
 
	function changeMapLocation(){
		alert('yes');
		window.setTimeout(function() {
		  map.panTo(new GLatLng(37.4569, -122.1569));
		}, 500);
	
	}

	