﻿

var map = null;
var geocoder = null;

function geraMapa(localizacao, controle, tipo, close, cidade) {
    
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("mapa"));
        geocoder = new GClientGeocoder();
        if (tipo == "satélite") {
            map.setMapType(G_HYBRID_MAP);
        }
        showAddress(localizacao, close);
        if (controle) {
            map.addControl(new GLargeMapControl);
        }
        if(cidade != "")
        {
            var cidades = new Array();
            cidades = cidade.split('|');
            var noCidades = cidades.length;
            if (noCidades >= 1) {
                for (var i = 0; i < noCidades; i++) {
                    try{
                    	marcarRoteiro(cidades[i]);
                    }
                	catch (e) {
						// TODO: handle exception
					}
                }
            }
        }
        
    }

}
function marcarRoteiro(address) {
    if (geocoder) {
        geocoder.getLatLng(address,function(point) {
      if (!point) {
          
      } else {
          var marker = new GMarker(point);
          map.addOverlay(marker);}});
    }
}


function showAddress(address, zoom) {
    if (geocoder) 
    {
        geocoder.getLatLng(address, 
        function(point) 
        {
            if(address!=""){
	        	if (!point) {
	              
	            }
	            else 
	            {
	              map.setCenter(point, zoom);
	              var marker = new GMarker(point);
	              map.addOverlay(marker);
	            }
            }
        });
    }
}