    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

    function initialize() {
		if(document.getElementById('local_gmap')){
		  if (GBrowserIsCompatible()) {      
			map = new GMap2(document.getElementById("map_canvas"));
			gdir = new GDirections(map, document.getElementById("directions"));
			geocoder = new GClientGeocoder();

			GEvent.addListener(gdir, "load", onGDirectionsLoad);
			GEvent.addListener(gdir, "error", handleErrors);
			inicia_mapa();
			
			map2 = new GMap2(document.getElementById("map_canvasNew"));
			gdir2 = new GDirections(map2, document.getElementById("directionsNew"));
			geocoder2 = new GClientGeocoder();

			GEvent.addListener(gdir2, "load", onGDirectionsLoad);
			GEvent.addListener(gdir2, "error", handleErrors);
			inicia_mapaNew();
			
			//setDirections("-19.930236,-43.921645", "-19.930236,-43.921645", "pt_BR");
		  }
	  	}
	}
    
	// Ícone Terrazzas
	 var marcaTerrazzas = new GIcon();
      //marcaTerrazzas.image = "imgs/logo_google_maps.png";
      //marcaTerrazzas.shadow = "imgs/sombra_logo_google_maps.png";
	  marcaTerrazzas.image = "http://www.mapadigital.net/wp-content/themes/mapadigital-v1/images/map-marker.gif";
      marcaTerrazzas.shadow = "http://maps.google.com/mapfiles/shadow50.png";
      marcaTerrazzas.iconSize = new GSize(36, 42);
      marcaTerrazzas.shadowSize = new GSize(54, 34);
      marcaTerrazzas.iconAnchor = new GPoint(9, 34);
      marcaTerrazzas.infoWindowAnchor = new GPoint(9, 2);
      marcaTerrazzas.infoShadowAnchor = new GPoint(18, 25);
      //marcaTerrazzas.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
      //marcaTerrazzas.printImage = "imgs/logo_google_maps.png";
      //marcaTerrazzas.mozPrintImage = "imgs/logo_google_maps.png";
	  
	 var baseIcon = new GIcon();
      //baseIcon.image = "imgs/logo_google_maps.png";
      //baseIcon.shadow = "imgs/sombra_logo_google_maps.png";
	  baseIcon.image = "http://www.mapadigital.net/wp-content/themes/mapadigital-v1/images/map-marker.gif";
      baseIcon.shadow = "http://maps.google.com/mapfiles/shadow50.png";
      baseIcon.iconSize = new GSize(36, 42);
      baseIcon.shadowSize = new GSize(54, 34);
      baseIcon.iconAnchor = new GPoint(9, 34);
      baseIcon.infoWindowAnchor = new GPoint(9, 2);
      baseIcon.infoShadowAnchor = new GPoint(18, 25);
      //baseIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
      //baseIcon.printImage = "imgs/logo_google_maps.png";
      //baseIcon.mozPrintImage = "imgs/logo_google_maps.png";

	
	function inicia_mapa(){
		// Pega valores do Oito
		var local = document.getElementById('local_gmap').value;
		//var html = document.getElementById('html_gmap').value;
		geocoder.getLatLng(
			local,
			function(point) {
			  if (!point) {
				mensagem("O endereço do edifício nao pode ser encontrado ("+local+").");
			  } else {
				map.setCenter(point, 16);
				var marker = new GMarker(point,marcaTerrazzas);
				map.addOverlay(marker);
				//marker.openInfoWindowHtml(html);
			  }
			}
		
		);

	}
	
	
	function inicia_mapaNew(){
		// Pega valores do Oito
		var local2 = document.getElementById('local_gmapNew').value;
		//var html2 = document.getElementById('html_gmapNew').value;
		geocoder2.getLatLng(
			local2,
			function(point2) {
			  if (!point2) {
				mensagem("O endereço do edifício nao pode ser encontrado ("+local+").");
			  } else {
				map2.setCenter(point2, 16);
				var marker2 = new GMarker(point2,baseIcon);
				map2.addOverlay(marker2);
				//marker2.openInfoWindowHtml(html2);
			  }
			}
		
		);

	}
	
    function setDirections(fromAddress, toAddress, locale) {
		//document.getElementById("trajeto").style.display = 'block';
		//document.getElementById("validador").style.display = 'none';

		gdir.load("from: " + fromAddress + " to: " + toAddress,
        	        { "locale": locale });
		gdir2.load("from: " + fromAddress + " to: " + toAddress,
        	        { "locale": locale });
	}

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     mensagem("O endereço informado nao foi encontrado, talvez ele ainda nao tenha sido mapeado pelo GoogleMaps");
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     mensagem("As coordenadas informadas nao foram encontradas, certifique-se de ter escrito no padrao");
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     mensagem("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_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     mensagem("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)
	     mensagem("O caminho solicitado n&atilde;o pode ser construído, verifique se informou corretamente seu endereço");
	    
	   else mensagem("Erro desconhecido");
	   
	}

	function onGDirectionsLoad(){
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}
	
	function mensagem(msg){
		document.getElementById("validador_msg").innerHTML = msg;
		document.getElementById("validador").style.display = 'block';
	}