var map;
var gdir;
var address;
       	
    	function initMap(name, url, street1, street2, city, state, zip) {
      			if (GBrowserIsCompatible()) {
      				var themap = new GMap2(document.getElementById("initmap"));

        			
        			themap.addControl(new GSmallMapControl());
    				themap.addControl(new GMapTypeControl());
    				

					
    				
        			var geocoder = new GClientGeocoder();
        			
					initaddress = street1 + ", " + city + ", " + state + " " + zip; 
					var displayAddress = "<b>" + name + "</b>";
					
					if (street2=='null')
					{
						displayAddress = displayAddress + "<br>"+ street1 +"<br>"+ city +", " + state + " " + zip;
					}
					else
					{
						displayAddress = displayAddress + "<br>"+ street1 +"<br>"+ street2 + "<br>" + city +", " + state + " " + zip;
					
					}
					geocoder.getLatLng(
						initaddress,
						function(point) {
							if (!point) {
								alert(initaddress + " not found");
							} else {
								themap.setCenter(point, 15);
								var marker = new GMarker(point);
								themap.addOverlay(marker);
								//marker.openInfoWindowHtml(displayAddress, { maxWidth : 150 });
								//map.savePosition();
								
							}
						}
					)
        			
  				}
  				
  				
  			}
       
    	function loadMap(name, url, street1, street2, city, state, zip) {
      			if (GBrowserIsCompatible()) {
      				map = new GMap2(document.getElementById("map"));
      				// clear any direction from previous get directions
      				if (gdir!=null) {
    					gdir.clear();
    				}
        			
        			map.addControl(new GLargeMapControl());
    				map.addControl(new GMapTypeControl());
    				

					
    				
        			var geocoder = new GClientGeocoder();
        			
					address = street1 + ", " + city + ", " + state + " " + zip; 
					var displayAddress = "<b>" + name + "</b>";
					
					if (street2=='null')
					{
						displayAddress = displayAddress + "<br>"+ street1 +"<br>"+ city +", " + state + " " + zip;
					}
					else
					{
						displayAddress = displayAddress + "<br>"+ street1 +"<br>"+ street2 + "<br>" + city +", " + state + " " + zip;
					
					}
					geocoder.getLatLng(
						address,
						function(point) {
							if (!point) {
								alert(address + " not found");
							} else {
								map.setCenter(point, 15);
								var marker = new GMarker(point);
								map.addOverlay(marker);
								marker.openInfoWindowHtml(displayAddress, { maxWidth : 150 });
								//map.savePosition();
								
							}
						}
					)
        			
  				}
  				
  				
  			}
  			
  			function setDirections(fromAddress) {
  				var panel = document.getElementById("panel");

      			if (gdir!=null) {
    				gdir.clear();
    			}
				// new instance of get directions because there is new map
    			gdir = new GDirections(map, panel);
    			
      			gdir.load("from: " + fromAddress + " to: " + address, { "locale": "en" });
      			
    		}
			 
  			window.onunload = GUnload;
