	var map;
  var gdir;
  var geocoder = null;
   var addressMarker;
  google.load("maps", "2.93");
  
	  function initialize() {
	       // Initialize default values
				
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
		map.setCenter(new GLatLng (40.046713,-74.198143), 13);
		var pos = new GLatLng (40.046713,-74.198143)
		//map.addOverlay(new GMarker(pos));
				 var marker = new GMarker(pos);
		 
		
        var html = "<div style='width:200px'><div style='font-family:verdana,arial,sans-serif;font-size:11px;line-height: 13px;'>New Hampshire Commons 90 Corbin, Lakewood, NJ 09701</div></div>";

        map.addOverlay(marker);	 
 GEvent.addListener(marker, 'click', function() { map.enableInfoWindow();marker.openInfoWindowHtml(html); });
	
				var mapControl = new GMapTypeControl();
				map.addControl(mapControl);
				map.addControl(new GLargeMapControl());



	       // If ClientLocation was filled in by the loader, use that info instead
	       if (google.loader.ClientLocation) {
						latlng = new google.maps.LatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
	       		//setDirections(getFormattedLocation(), "51 dr girling drive haverstraw ny");
						//setFromForm();
	
	
	          
					}
					else {
						var latlng = new google.maps.LatLng(40.046713,-74.198143);
			     // var location = "Showing default location for map: New York, NY";
						//setDirections("New York, NY", "51 dr girling drive haverstraw ny");
						//setFromForm();
											  
					}

					//document.getElementById("location").innerHTML = location;
    }
    
		function setDirections(fromAddress, toAddress) {
      gdir.load("from: " + fromAddress + " to: " + toAddress);
			
		}

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad(){ 
	}
 function getFormattedLocation() {
    if (google.loader.ClientLocation.address.country_code == "US" &&
      google.loader.ClientLocation.address.region) {
      return google.loader.ClientLocation.address.city + ", " 
          + google.loader.ClientLocation.address.region.toUpperCase();
    } else {
      return  google.loader.ClientLocation.address.city + ", "
          + google.loader.ClientLocation.address.country_code;
    }
  }

  function setFromForm(){
		//document.getElementById("fromAddress").value=getFormattedLocation();
	}


// Removes Value of input box onFocus
	function tbTest_focus(e,o){
	if(o.firstTime){return}
	o.firstTime=true;
	o.value="";
}


// Switches the values of toAddress and fromAddress
function switchDirections() {
		a=document.getElementById("toAddress").value;
		b=document.getElementById("fromAddress").value;
		setDirections(a,b);
		writeTo(a,b);
}

// Returns toAddress and fromAddress to their original values
function writeTo(fromvar,tovar) {
// flip the directions
		firstLoc=fromvar;
		nextLoc=tovar;
		document.getElementById("fromAddress").value=(firstLoc);
		document.getElementById("toAddress").value=("90 Corbin, Lakewood, NJ 09701");
}
			
