
    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
    var posicao;
    var gicons = [];
	var point;
    var latitude, longitude;
    var directionsPanel;
    var directions;
	/*
		----------------------------------------------------------------------------------
		----------------------------------------------------------------------------------
		
					funçoes do mapa da pagina principal
	
	*/
    function load_rota_simples() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        //setDirections_rota_simples("R. Glaziou, 124 - Pilares, Rio de Janeiro - RJ", "R. Dois - Cidade Universitária, Rio de Janeiro - RJ");
		setDirections_rota_simples(document.form.from.value,document.form.to.value);
      }
    }
    
    function setDirections_rota_simples(fromAddress,toAddress) {
      gdir.load("from: " + fromAddress + " to: " + toAddress);
    }

    function handleErrors(){
        if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
        {
          alert("Endereço não encontrado")
        }
        if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
        {
          alert("Preencher os campos")
        }
	   
	}

	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...
	}


    //]]>
	/*
		----------------------------------------------------------------------------------
		----------------------------------------------------------------------------------
		
						funçoes dos mapas simples copacabana, engenhao e etc
	
	*/
	function site_maino() {
		window.open("http://www.maino-geosistemas.com", "Maino","");
	}

    function load_mapa_simples() {
		map = new GMap(document.getElementById("map"));
		mostraMapa_simples();
		var zoomHTML = "<center>";
		//display_desativado();
     }
	function zoomCtl(lvl)
	  {
			map.zoomTo(lvl);
  	  }
      
	  //função que define a direção e manda os pontos da nova posição
	  function pan(dir)
		{
			var bounds = map.getBoundsLatLng();
			var xCenter = bounds.minX + (bounds.maxX - bounds.minX) / 2;
			var yCenter = bounds.minY + (bounds.maxY - bounds.minY) / 2;
			if(dir=="north") map.recenterOrPanToLatLng(new GPoint(xCenter, bounds.maxY));
			if(dir=="east")  map.recenterOrPanToLatLng(new GPoint(bounds.maxX, yCenter));
			if(dir=="south") map.recenterOrPanToLatLng(new GPoint(xCenter, bounds.minY));
			if(dir=="west")  map.recenterOrPanToLatLng(new GPoint(bounds.minX, yCenter));
		}
		function mostraPonto(point,msg,icone) {
		  seleciona_icone(icone);
		  var marker = new GMarker(point,{icon: gicons[icone]});
		  GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(msg);
		  } );
		  map.addOverlay(marker);
          marker.openInfoWindowHtml(msg);  
       }
    
   		 function seleciona_icone(icone) {
		  sombra="icones/shadow.PNG";
	      // adicionando o icone
	      gicons[icone] = new GIcon();
	      gicons[icone].image = icone;
	      gicons[icone].shadow =sombra;
	      gicons[icone].iconSize = new GSize(32,32);
	      gicons[icone].shadowSize = new GSize(24, 24);
	      gicons[icone].iconAnchor = new GPoint(8, 24);
	      gicons[icone].infoWindowAnchor = new GPoint(8, 24);
	    }
      
		  /*  função responsavel por editar e definir um novo controle de zoom */ 
            function TextualZoomControl() { 
              }
            TextualZoomControl.prototype = new GControl();
            TextualZoomControl.prototype.initialize = function(map) {
            var container = document.createElement("div");
            var zoomInDiv = document.createElement("div");
            this.setButtonStyle_(zoomInDiv);
            container.appendChild(zoomInDiv);
            zoomInDiv.appendChild(document.createTextNode("Aproximar"));
            GEvent.addDomListener(zoomInDiv, "click", function() {
              map.zoomIn();
            });
            var zoomOutDiv = document.createElement("div");
            this.setButtonStyle_(zoomOutDiv);
            container.appendChild(zoomOutDiv);
            zoomOutDiv.appendChild(document.createTextNode("Afastar"));
            GEvent.addDomListener(zoomOutDiv, "click", function() {
              map.zoomOut();
            });
            map.getContainer().appendChild(container);
            return container;
          }
          TextualZoomControl.prototype.getDefaultPosition = function() {
            return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
          }
          function verificar_zoom()
            {
              
               var zoom = map.getZoom(); 
               if(zoom<18)
                {
                  zoomCtl(map.getZoomLevel() - 1)
                }
            }

            function centralizar_mapa()
              {
				map.setCenter(point, 16);
			  }



          //propriedade css dos botoes
          TextualZoomControl.prototype.setButtonStyle_ = function(button) {
            button.style.textDecoration = "";
            button.style.color = "336699";
            button.style.backgroundColor = "white";
            button.style.font = "small verdana";
            button.style.border = "1px solid black";
            button.style.padding = "1px";
            button.style.marginBottom = "3px";
            button.style.textAlign = "center";
            button.style.width = "6em";
            button.style.cursor = "pointer";
          }
     /*   fim da função de definição de controle de zoom */
     <!--    -->
     function display_ativo()
      {
            //alterando a posição da barra de acordo com o div do mapa
            var mapa_left=parseInt(document.getElementById("map").style.left);
            var mapa_tam=parseInt(document.getElementById("map").style.width);
            var map_top=parseInt(document.getElementById("map").style.top);
            var opc_tam=parseInt(document.getElementById("opc").style.width);
            //posicionando
            posicao_opc=(mapa_tam+mapa_left);
            posicao_opc=posicao_opc-opc_tam;
            document.getElementById("opc").style.left=posicao_opc;
            document.getElementById("img_tipo").style.left=posicao_opc+5;
            document.getElementById("movimentacao").style.left=posicao_opc+20;
            document.getElementById("zoom").style.left=posicao_opc+12;
            //document.getElementById("centralizar").style.left=posicao_opc+5 ;
            //alinhando o top
            document.getElementById("opc").style.top=map_top;
      }
      function display_desativado()
      {
            var mapa_left=parseInt(document.getElementById("map").style.left);
            var mapa_tam=parseInt(document.getElementById("map").style.width);
            var opc_tam=parseInt(document.getElementById("opc").style.width);
            posicao_opc=(mapa_left+mapa_tam);
            posicao_opc=posicao_opc-10;
            document.getElementById("opc").style.left=posicao_opc;
            document.getElementById("mostrar").style.left=posicao_opc-73;

      }

       function estado_ativo()
        {
      
          //alterando o tamanho do div
            document.getElementById("opc").style.width="200px";
             display_ativo(); 
            //document.getElementById("opc").style.left=posicao_opc
            //alterando o display do zoom
            document.getElementById("tbl_zoom").style.display='block';
          //alterando o display das imagens
            document.getElementById("tbl_movimentacao").style.display='block'
            //alterando o display dos tipos
            document.getElementById("tbl_tipo").style.display='block';
                   //alterando o display da seta
            document.getElementById("tbl_mostrar").style.display='none';
                       // alterando o display do centralizar
          //document.getElementById("tbl_centralizar").style.display='block';  
             
            //---
        }
           function estado_inativo()
        {
          //alterando o tamanho do div
            document.getElementById("opc").style.width="10px";
             display_desativado();
          //alterando o display do zoom
            document.getElementById("tbl_zoom").style.display='none';
          //alterando o display das imagens
          document.getElementById("tbl_movimentacao").style.display='none'
            //alterando o display dos tipos
            document.getElementById("tbl_tipo").style.display='none';
             //alterando o display da seta
            document.getElementById("tbl_mostrar").style.display='block';
            // alterando o display do centralizar
          //document.getElementById("tbl_centralizar").style.display='none';  
        }
        function seleciona_tipo(img)
          {
            if(img=="ruas")
              {
                document.getElementById("img_rua").src="img_botoes/ruas_sel.png";
                document.getElementById("img_satelite").src="img_botoes/satelite.png";
                document.getElementById("img_ambos").src="img_botoes/ambos.png";
                document.getElementById("mapa_tipo").value="G_NORMAL_MAP"
              }
             if(img=="satelite")
              {
                document.getElementById("img_satelite").src="img_botoes/satelite_sel.png";
                document.getElementById("img_rua").src="img_botoes/ruas.png";
                document.getElementById("img_ambos").src="img_botoes/ambos.png";
                document.getElementById("mapa_tipo").value="G_SATELLITE_MAP"
              }
                 if(img=="ambos")
              {
                document.getElementById("img_ambos").src="img_botoes/ambos_sel.png";
                document.getElementById("img_rua").src="img_botoes/ruas.png";
                document.getElementById("img_satelite").src="img_botoes/satelite.png";
                document.getElementById("mapa_tipo").value="G_HYBRID_MAP"
              }
            
          
          }
        function imagem_over(img)
          {
            if(img=="ruas")
              {
              document.getElementById("img_rua").src="img_botoes/ruas_sel.png";
              }
            if(img=="satelite")
              {
              document.getElementById("img_satelite").src="img_botoes/satelite_sel.png";
              }  
             if(img=="ambos")
              {
              document.getElementById("img_ambos").src="img_botoes/ambos_sel.png";
              }
          }              
        function imagem_out(img)
          {
             if(img=="ruas")
              {
              document.getElementById("img_rua").src="img_botoes/ruas.png";
              }
            if(img=="satelite")
              {
              document.getElementById("img_satelite").src="img_botoes/satelite.png";
              }  
             if(img=="ambos")
              {
              document.getElementById("img_ambos").src="img_botoes/ambos.png";
              }      
          
          }
         function contato()
          {
            window.opener.document.frm_contato.submit();
            window.close();
          }
          
          	/*
		----------------------------------------------------------------------------------	
						funçoes relativas a cada mapa dos mapas simples
		
			*/
         function mostraMapa_simples() {
      point = new GLatLng(0,0);
      map.setCenter(point, 16, G_MAP_TYPE);
      lat =document.getElementById("lat_mapa").value;
      lng =document.getElementById("lng_mapa").value;
      endereco =document.getElementById("endereco_mapa").value;
      icone ="icones/tack_red.PNG"
      img_adicional=document.getElementById("img_adicional_mapa").value;
      msg="<table class='body' width='300px'><tr><td align='center'><img src="+img_adicional+" style='filter:alpha(opacity=90);-moz-opacity:.90;opacity:.90;  width:90px; height:100px;'></img></center></td><tr><tr><td><b><center>" + endereco + "</center></b></td></tr></table>"; //mensagem q será emitida no evento on-click                    
      point = new GLatLng(lat,lng);
      map.setCenter(point, 16, G_MAP_TYPE);  //centralizando e definindo o tipo de visualização
		  mostraPonto(point,msg,icone);  
      }
      
  	/*
		----------------------------------------------------------------------------------
		----------------------------------------------------------------------------------
		
						funçoes dos mapa_exemplo (rota)
	
	*/    
  	
  	function mostra_mapa(page) {
		window.open(page,"Mapa","width=750,height=550")
	}

    function load_exemplo() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(-22.864847,-43.220011), 13);
        geocoder = new GClientGeocoder();
      }
    }

    function showendereco(endereco) {
    map.clearOverlays();
      if (geocoder) {
        geocoder.getLatLng(
          endereco,
          function(point) {
            if (!point) {
            alert("Endereço não encontrado");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point, {draggable: true});
              GEvent.addListener(marker, "dragstart", function() {
              map.closeInfoWindow();
            });
             GEvent.addListener(marker, "dragend", function() {
            // é nescessario adicionador o evento e pegar as coordenadas e mandar para os inputs hiddens
            latitude=marker.getPoint().lat();
            longitude=marker.getPoint().lng();
           });
              map.addOverlay(marker);
              latitude=point.lat(); // aqui eu pego os valores indepedentes do evento
              longitude=point.lng();
            }
          }
        );
      }
    }

    function showmapa(endereco,descricao)
      {
        if (geocoder) {
        geocoder.getLatLng(
          endereco,
          function(point) {
            if (!point) {
            alert("Endereço não encontrado");
            } else {
              url="gmap/mapas-simples/mapas.php?lat=" + latitude + "&lng=" + longitude + "&desc=" + descricao + " ";
              window.open(url,'popup','width=750,height=560,scrolling=auto,top=0,left=0');
            }
          }
        );
      }
    }

    
    function validar()
      {
        showendereco(document.getElementById("endereco").value);
       
      }
    function ver_mapa()
      {
         showmapa(document.getElementById("endereco").value,document.getElementById("descricao").value);
      }
      
      	/*
		----------------------------------------------------------------------------------
		----------------------------------------------------------------------------------
		
					funçoes relativas ao mapa maino
	
	*/
      	
    function load_maino() {
          map = new GMap(document.getElementById("map"));
          var zoomHTML = "<center>";
          GDownloadUrl("data.xml", mostraMapa_maino);
      }
      
       //função que define a direção e manda os pontos da nova posição
      function mostraMapa_maino(data, responseCode) {
          var xml = GXml.parse(data);
          var ponto = xml.documentElement.getElementsByTagName("logradouro");
          for(var i=0;i<ponto.length;i++) {
            lat=ponto[i].getAttribute("lat");
            lng=ponto[i].getAttribute("lng");
            endereco=ponto[i].getAttribute("endereco");
            empresa=ponto[i].getAttribute("empresa");
            adicional=ponto[i].getAttribute("adicional");
            tel=ponto[i].getAttribute("tel");
            cel=ponto[i].getAttribute("cel");
            icone=ponto[i].getAttribute("img");
            extensao=ponto[i].getAttribute("img_tipo")
			img_adicional=ponto[i].getAttribute("img_add")
            img_adicional_tipo=ponto[i].getAttribute("img_add_tipo")
            msg="<table class='body'><tr><td align='center'><img src="+img_adicional+img_adicional_tipo+" style='filter:alpha(opacity=90);-moz-opacity:.90;opacity:.90; '></img></center></td><tr><td><b>" + empresa + "</b></td></tr><tr><td>" + adicional + "</td></tr><tr><td>" + endereco + "</td></tr><tr><td>" + "tel: " + tel + "    -    " + "cel: " + cel + "</td></tr></table>"; //memsagem q será emitida no evento on-click                    
            var point = new GLatLng(lat,lng);
            if (i==0) {
              map.setCenter(point, 14, G_MAP_TYPE);  //centralizando e definindo o tipo de visualização
            }
            mostraPonto(lat, lng, msg, icone, i);  
          }
          lerReferencia_maino(xml)
      }
    function lerReferencia_maino(dados)
      {
       var ponto = dados.documentElement.getElementsByTagName("referencia");
       for(var i=0;i<ponto.length;i++)
        {
          lat=ponto[i].getAttribute("lat");
          lng=ponto[i].getAttribute("lng");
          descricao=ponto[i].getAttribute("descricao");
          icone=ponto[i].getAttribute("img");
          extensao=ponto[i].getAttribute("img_tipo")
          msg="<br><label class='body' align='left'><center><b>"+descricao+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></center></label>"
          mostraReferencia(lat,lng,msg,icone)
        }
      }
        
          /*  função responsavel por editar e definir um novo controle de zoom */ 
         
          function verificar_zoom()
            {
              
               var zoom = map.getZoom(); 
               if(zoom<18)
                {
                  zoomCtl(map.getZoomLevel() - 1)
                }
            }
          function mapa_center_maino()
            {
                   GDownloadUrl("data.xml",centralizar_mapa);
            }
            function centralizar_mapa_maino(data,responseCode)
              {
                 //centraliza o mapa na posiçãio inicial
              xml = GXml.parse(data);
              var tipo_mapa=document.getElementById("mapa_tipo").value;
              var ponto = xml.documentElement.getElementsByTagName("logradouro");
               for(var i=0;i<ponto.length;i++) 
                {
                  lat=ponto[i].getAttribute("lat");
                  lng=ponto[i].getAttribute("lng");
                   if (i==0)
                   {
                       var point = new GLatLng(lat,lng);
                    }
                }
                      if(tipo_mapa=="G_NORMAL_MAP")
                          {
                            map.setCenter(point, 14,G_NORMAL_MAP);
                          }
                      if(tipo_mapa=="G_SATELLITE_MAP")
                          {
                            map.setCenter(point, 14,G_SATELLITE_MAP);
                          }      
                     if(tipo_mapa=="G_HYBRID_MAP")
                          {
                            map.setCenter(point, 14,G_HYBRID_MAP);
                          }                     
                     if(tipo_mapa=="")
                          {
                            map.setCenter(point, 14,G_NORMAL_MAP);
                          }        
              }
     
       
