    //<![CDATA[
    
    if (GBrowserIsCompatible()) { 

    
    var geo;
    var reasons=[];
	var tpDesordem=[];

	var dadosDesordem=[];

	var gmarkers=[];

    var informacoesDesordem=new Array([],[]);

	var indexVector = 0;

    var geocoder;
		var map;

    function load() {
      map = new GMap(document.getElementById("map"));
      map.setCenter(new GLatLng( -22.893790,-43.297178), 11);

      var uiOptions = map.getDefaultUI();
          //uiOptions.zoom.scrollwheel = true;  van

	  map.setUI(uiOptions);

		map._lastCenter=map.getCenter();
	
		GEvent.addListener(map, 'moveend', function() 
				{ map._lastCenter=map.getCenter(); });
		GEvent.addListener(map, 'resize', function()
				{ map.setCenter(map._lastCenter); });


      // ====== Create a Client Geocoder ======
      geo = new GClientGeocoder(); 

      // ====== Array for decoding the failure codes ======
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "O endereço pesquisado não pode ser localizado. Por favor, verifique se esta correto e tente novamente.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";


	  geocoder = new GClientGeocoder();	

    }


		function localizaEnd(endereco) {

			for (i=0; i<informacoesDesordem.length; i++ ) {
               if (informacoesDesordem[i][0]==endereco) {
					//map.setCenter( gmarkers[i].getPoint(), zoomneed); 
					GEvent.trigger(gmarkers[i], "click");
					break;
               }
            }

           
        }


		function resetMarks() {

		   map.clearOverlays();

		}


	  function setAddresses(data) {
						// Retrieve the latitude and longitude
			point = new GLatLng(data.latitude, data.longitude);
			
			iconMarker =  new GIcon(G_DEFAULT_ICON);
		    iconMarker.iconSize = new GSize(32, 32);

			
			iconMarker.image = data.iconeDesordem;
		

			// Create a marker
			marker = createMarker(point, iconMarker, formataInformacoes(data) );

			marker.tipoMarcador = data.idTipoDesordem;

			//Necessario p abrir a informacao depois
			gmarkers.push(marker);
			
			// Add the marker to map
			map.addOverlay(marker);

      }


	function tpCheckClick(tipo) {
		var chb = document.getElementById("chkDesordem"+tipo);
		for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].tipoMarcador == tipo) {
			
			if (chb.checked)
                gmarkers[i].show();
            else 
				gmarkers[i].hide();
          }
        }
	

    }


     // ====== Plot a marker after positive reponse to "did you mean" ======
      function place(lat,lng) {
        var point = new GLatLng(lat,lng);
        map.setCenter(point,16); 
        map.addOverlay(new GMarker(point));

      }


   //Oque acontece se houver 2 pontos ou mais no mesmo ponto, mas contendo informacoes e tipos diferentes?
	function mostraInclusao(lat, lon) {
        var point = new GMarker(new GLatLng(lat,lon));
  		map.setCenter(new GLatLng(lat,lon), 15);
		 
		for (var i=0; i < gmarkers.length; i++) {
			
			if (gmarkers[i].getLatLng().toString()  == point.getLatLng().toString() )
               GEvent.trigger(gmarkers[i],'click');
        }

    }

	function marcarInclusao(lat, lng) {

      var point = new GLatLng(lat, lng);
	  map.setCenter(point, 16);
	  map.addOverlay(new GMarker(point));	
    }


   function formataInformacoes(data) {
       		
       var infFormatada ="";
		var statu;
		switch(data.status)
		{
	
			case 'Em analise':
				statu="<div >"+data.status+"</div>";
			break;
			case 'Encaminhado':
				statu="<div >"+data.status+"</div>";
			break;
			case 'Finalizado':
				statu="<div >"+data.status+"</div>";
			break;
		}
        

            if(data.foto!=""){

                infFormatada = ''+
					  '<div "id="divInfMapDenuncia">'+
					  '	<h2>'+data.endereco+' - '+data.bairro+'</h2>'+
					  ' 	<div charset=utf-8 id="dvConteudoDesordem">'+
					  ' 	<div id="dvMapaImagem">'+'<img src="'+data.foto+'"style="width: 400px;">'+ '</div>'+
					  '     <div id="dvMapaInformacoes">'+
                      '     	<label class="classMapaInformacoes">Status:</label>'+statu+
                      '         <label class="classMapaInformacoes">Tipo de den&uacute;ncia:</label>'+ data.descTipoDesordem+
                      '         <label class="classMapaInformacoes">Data da den&uacute;ncia:</label>'+ data.dataInclusao+
                      '     </div>'+

                                          '     <div class="dvDescricao"><p>'+data.descDesordem +'</p></div>';

            }
            else{
            infFormatada = ''+
					  '<div "id="divInfMapDenuncia">'+
					  '	<h2>'+data.endereco+' - '+data.bairro+'</h2>'+
					  ' 	<div charset=utf-8 id="dvConteudoDesordem">'+
					  //' 	<div id="dvMapaImagem">'+'<img src="">'+ '</div>'+
					  '     <div id="dvMapaInformacoes">'+
                      '     	<label class="classMapaInformacoes">Status:</label>'+statu+ 
                      '         <label class="classMapaInformacoes">Tipo de den&uacute;ncia:</label>'+ data.descTipoDesordem+
                      '         <label class="classMapaInformacoes">Data da den&uacute;ncia:</label>'+ data.dataInclusao+
                      '     </div>'+
					 
                                          '     <div class="dvDescricao"><p>'+data.descDesordem +'</p></div>';
            }
					  if (data.denunciaAnonima!="S") {
                      	infFormatada += ''+                            
                        '<label class="classMapaInformacoes">Nome:</label>'+ data.nomeReclamante+ 
			'<label class="classMapaInformacoes">E-Mail:</label>'+ data.emailReclamante+'';
                     }
					 
                                         
                                         
                                         
                infFormatada += '';   //van ini
                
		switch(data.status)
		{

			case 'Em analise':
				infFormatada += ''+"<div class='divAcompanhamento-emAnalise'><h3>"+data.status+"</h3>";
			break;
			case 'Encaminhado':
				infFormatada += ''+"<div class='divAcompanhamento-Encaminhado'><h3>"+data.status+"</h3>";
			break;
			case 'Finalizado':
				infFormatada += ''+"<div class='divAcompanhamento-Finalizado'><h3>"+data.status+"</h3>";
			break;
		}
                







					 infFormatada += ''+'<p><label class="classMapaInformacoes">'+data.acomp+':</label></p><p>'+data.msg+'</p>';
                                         
                                        
               infFormatada += '</div></div></div>'; // van fim
            
			
         	
/*			  infFormatada+="<strong>Endereço: </strong>"+data.endereco+"<br>"+
							"<strong>Bairro: </strong>"+data.bairro+"<br>";
	
              infFormatada+="<strong>Tipo de desordem: </strong>"+data.descTipoDesordem+"<br>"+	
						   "<strong>Descricao: </strong>"+data.descDesordem+"<br>";

		if (data.foto!="") {
           infFormatada+="<strong>Foto: </strong><br><img src=\""+data.foto+"\">";
         }
         infFormatada += "</div>";
         */
         
		  
		return infFormatada;
   }	




	function createMarker(point, iconMarker, informacoes) {
		var marker = new GMarker(point, iconMarker);		
			GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindowHtml(informacoes);
		});
		
		return marker;
	}

	

	  function mostraEnderecoInclusao(endereco) {
// 			var final = "";
//  			for (var index in endereco.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare) {
//  				final+="\n "+ index +"=>"+endereco[index];
//              }				

			var vecEndFull = endereco.address.split(" - ");
			var vecBairro     = vecEndFull[1].split(",");

			var latitude = endereco.Point.coordinates[1];
			var longitude = endereco.Point.coordinates[0];

			var enderecoGMaps = endereco.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare.ThoroughfareName;

			document.getElementById("search").value=enderecoGMaps;

			document.getElementById("hdnAddr").value=enderecoGMaps;
						
			document.getElementById("hdnNeigh").value=vecBairro[0];
						 			
			document.getElementById("hdnCity").value="Rio de Janeiro";
		 	
			document.getElementById("hdnLat").value= latitude;

			document.getElementById("hdnLong").value= longitude;		

			map.clearOverlays(); 

			marcarInclusao(latitude,longitude);
	
      }	

      
      function setLocalSelect(local) {
          var dados = local.split("|");
          
          setLocal(dados[0],dados[1],dados[2]);
      }
        
	  function setLocal(address, lat,lng) {

			var vecEndFull = address.split("-");
			var vecEnd     = vecEndFull[1].split(",");
			var vecState   = vecEndFull[2].split(",");		

         	document.getElementById("search").value=address;

	        document.getElementById("search").value=vecEndFull[0];

			document.getElementById("hdnAddr").value=vecEndFull[0]; 
			document.getElementById("hdnNeigh").value=vecEnd[0];

			

			document.getElementById("hdnCity").value="Rio de Janeiro";

			document.getElementById("hdnLat").value=lat;
	
			document.getElementById("hdnLong").value=lng;

			document.getElementById("btnSearch").style.display="none";
	
			//document.getElementById("btnConfirmar").style.display="block";

			marcarInclusao(lat,lng);
                       confirmarAddress(); }

       
		function confirmarAddress() { 
			document.getElementById("enderecos").innerHTML = ""; 
			document.getElementById("btnSearch").style.display="block"; 
			//document.getElementById("btnConfirmar").style.display="none";					      
}


      // ====== Geocoding ======
      function showAddress() {
        var search = document.getElementById("search").value;
		document.getElementById("enderecos").innerHTML = "";
		
			if (search.replace(/^\s+|\s+$/,'')=="") {
			return false;  
			}
			else {

				if (document.getElementById("hdnCity").value!="") {
					search += " - "+document.getElementById("hdnCity").value;
				}
		
				if (document.getElementById("hdnState").value!="") {
					search += " - "+document.getElementById("hdnState").value;
				}
		
			
		
				// ====== Perform the Geocoding ======        
				geo.getLocations(search, function (result)
				{

			
					if (result.Status.code == G_GEO_SUCCESS) {
						var resultado=new Array();
						
						for (var i=0; i<result.Placemark.length; i++) {
							//alert(result.Placemark[i].AddressDetails.Country.AdministrativeArea.Locality.LocalityName);
							if (result.Placemark[i].AddressDetails.Country.AdministrativeArea.Locality.LocalityName=="Rio de Janeiro") {
								//validar tambem o endereco para evitar bizarrices como - Rua Goias, 333
								resultado.push(result.Placemark[i]);
							}
						}

					    if (resultado.length > 1) {
							var optMontada =  "<select onChange='setLocalSelect(this.value);' id='selResultadosEnderecos' size='4' style='width:350px;overflow:auto;position:absolute;' >";
							//document.getElementById("enderecos").innerHTML = "<select id=\"selResultadosEnderecos\" size=\"3\">";
							for (var i=0; i < resultado.length; i++) {
								var p = resultado[i].Point.coordinates;
								//document.getElementById("enderecos").innerHTML += "<br>"+(i+1)+": <a href='javascript:map.clearOverlays();setLocal(\""+resultado[i].address +"\","+p[1]+","+p[0]+");'>"+ resultado[i].address+"</a>";
								
								//optMontada += "<option onClick='setLocal(\""+resultado[i].address +"\","+p[1]+","+p[0]+");'>"+ resultado[i].address+"</option>";
								optMontada += '<option  value="'+resultado[i].address +'|'+p[1]+'|'+p[0]+'">'+ resultado[i].address+'</option>';
								


							}
							optMontada += "</select>";
							document.getElementById("enderecos").innerHTML = optMontada;

						}
						else {
			
							mostraEnderecoInclusao(resultado[0]);
                        }

						document.getElementById("btnInclude").disabled=false;

					}


					// ====== Decode the error status ======
					else {

					var reason="Code "+result.Status.code;

						if (reasons[result.Status.code]) {
							reason = reasons[result.Status.code]
						} 

						alerta(reason);

					}
				}
				);
			}
		
		}  

    }
    
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }

    //]]>
