//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------

	
function setupBrowserDetect(){
  
  BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

}
	


//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function startLoadingAnimation() {
	$('loading_animation').style.visibility = 'visible';
}
//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function stopLoadingAnimation() {
	$('loading_animation').style.visibility = 'hidden';
}
//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function removePreloadedImages(evt) {
	$(this).stopObserving();
}
//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function preloadImage(url) {
	var img = new Image();
	img.src = url;
	
	Event.observe(img, "load", removePreloadedImages.bindAsEventListener(img));
}


//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function iurl(path) {
	return imageUrl() + path;
}

//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function stars(rating, mini) {
	var result = '';
	var img_base = iurl("ico/stars/stars_");
	if (mini) {
		img_base += 'small_';
	}
	
	var abr = Math.floor(rating + 0.25);
	img_base += abr;
	var img_full = img_base + '.png';
	var img_half = img_base + '_half.png';
	var dr = ((rating*10)%2);
	//alert(img_full);
	if (dr == 0) {
		result += '<img src="' + img_full + '" alt="'+abr+' stars">';
	} else {
		result += '<img src="' + img_half + '" alt="'+abr+'.5 stars">';					
	}
	
	return result;
}

//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function setElementHTML(id, html) {
	var e = $(id);
	e.innerHTML = html;
}


//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function getElementHTML(id) {
	var e = $(id);
	return e.innerHTML; 
}


//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function asyncGetJson(url, cb, eb) {
	var opt = {
			 method: 'get',			 
			 onSuccess: cb,
			 on404: function(){alert('404 error, unable to load.')},
			 onFailure: eb
			};
    return (new Ajax.Request(url+'&nocache='+(new Date()).getTime(), opt));
	// return (new Ajax.Request(url+'&nocache='+ cidadeAtual))	
}

//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------

function findImagesArray(marker) {
	for (var i in marker)
	{
		if (eval("typeof marker." + i) == "object")
		{
			try {
				if (eval("typeof marker." + i + "[0].src") != "undefined")
				{
					return i;
				}
			}
			catch (e) {}
		}
	}
	return '';
}


//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function GxMarkerNamespace() {
  var n4=(document.layers);
  var n6=(document.getElementById&&!document.all);
  var likesDXFilters = false;
  var ie=(document.all);
  if (ie) {
	var ua = navigator.userAgent;
	var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	if (re.exec(ua) != null) {
		var rv = parseFloat( RegExp.$1 );
		if (rv >= 7) { 
			likesDXFilters = true;
		} else if ((rv >= 6) && ((new RegExp("SV1")).exec(ua) != null)) { 
			likesDXFilters = true;
		}
	}
  }
  window.likesDXFilters = likesDXFilters;
  window.ie = ie;

  var o6=(navigator.appName.indexOf("Opera") != -1);
  var safari=(navigator.userAgent.indexOf("Safari") != -1);
            
  function GxMarker( a,      b,    tooltip,  clickURL, target, showHover, vNome) {
    this.ponto = a;
    this.nome = vNome;
   
    this.inheritFrom = GMarker;
    this.inheritFrom(a,b);
    if ( typeof tooltip != "undefined" ) {
        this.setTooltip( tooltip );
    }
	if(!target)
	   {this.target='_blank';}
	else
	  {this.target=target}
	this.clickURL = clickURL;
	this.imagesArray = '';
	this.oldImagePath = "";
	  
	
	this.events = new Array();

  }

  GxMarker.prototype = new GMarker(new GLatLng(1,1));

  GxMarker.prototype.setTooltip = function( string ) {
    this.tooltip = new Object();
    //this.tooltip.opacity  = 70;
    this.tooltip.contents = string;
  };

  GxMarker.prototype.showHighlight = function() {
                                       if (this.imagesArray.length == 0) {
                                          this.imagesArray = findImagesArray(this);
    	                               }
	                                   if (this.imagesArray.length != '') {
	                                     if (typeof this.hoverIcon == "undefined" ){ 
	                                       return;
	                                     }
		                                 if (this.oldImagePath.length == 0) {
			                                this.oldImagePath = this[this.imagesArray][0].src;
		                                 }
		                                 if (ie && likesDXFilters) {
			                                this[this.imagesArray][0].style.filter = 
			                                 	'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.hoverIcon.image + '")';

		                                 }else {
		                                  
			                                this[this.imagesArray][0].src = this.hoverIcon.image;
		                                 }
		                                 this[this.imagesArray][0].style.zIndex = 4999;
		                                 this.redraw(true);
	                                   }
                                     }

   GxMarker.prototype.removeHighlight = function() {
                                         if (typeof this.hoverIcon == "undefined" ){ 
	                                       return;
	                                      }
	                                      if (this.imagesArray.length == 0) {
    	                                     this.imagesArray = findImagesArray(this);
	                                      }
	                                      if (this.imagesArray.length > 0) {
		                                    if (ie && likesDXFilters) {
			                                  this[this.imagesArray][0].style.filter = 
				                                  'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.oldImagePath + '")';
		                                    }else{
			                                  this[this.imagesArray][0].src = this.oldImagePath;
		                                    }
		                                    this.oldImagePath = "";
		                                    this[this.imagesArray][0].style.zIndex = 4998;
		                                    this.redraw(true);
	                                      }
                                        }

   GxMarker.prototype.initialize = function( a ) {
                                        try {
                                          GMarker.prototype.initialize.call(this, a);
                                          // Setup the mouse over/out events
	  	                                  this.events.unshift(GEvent.bind(this, "mouseover", this, this.onMouseOver));
		                                  this.events.unshift(GEvent.bind(this, "mouseout",  this, this.onMouseOut));
		                                  this.events.unshift(GEvent.bind(this, "click",  this, this.onClick));
		                                  this.map = a;
                                        }catch(e) {
    	                                  console.error(e);
                                        }
                                   }

GxMarker.prototype.remove = function( a ) {
    GMarker.prototype.remove.call(this);
    if ( this.tooltipObject )
        //this.map.div.removeChild(this.tooltipObject);
        document.body.removeChild(this.tooltipObject);
	this.removeEvents();
   this.map = null;
}

GxMarker.prototype.onInfoWindowOpen = function() {
    this.hideMouseOver();
    GMarker.prototype.onInfoWindowOpen.call(this);
}

   GxMarker.prototype.onClick = function() {
       /*
	   if (this.clickURL)
       {
		window.open(this.clickURL, this.target);
	   }
	   */
	   //alert ( "onClick "+ this.ponto);
	  this.hideMouseOver();
	  vRotaBalao = true;
	  vRotaPontoDestino = this.ponto;
	  vRotaPontoOrigem = null;
	  vEndDestino = this.nome;
	 
	  this.mostraBalao();
   }



   GxMarker.prototype.mostraBalao= function() {
    
    
      
	  var vAuxHtml =    this.tooltip.contents + "<table border='0' bgcolor='white' >  "+
	                                          "   <tr><td>Rota </td> </tr> "+ 
	                                          "    <tr>  "+
	                                          "      <td>  "+
	                                          "         <select id='sel_rota_tipo'>  "+ 
                                              "             <option value ='1'>Origem</option> "+
                                              "             <option value ='2'>Destino</option> "+
                                              "         </select>      "+
	                                          "      </td>  "+
	                                          "      <td><input type='text' id = 'fname' name='fname' value=''/></td>" + 
	                                          "     <td><input type='image' src='scriptsGG/bt_ok_mapas.gif' border='0' onclick='doBuscaRota()'></td>"+
	                                          "    </tr> "+
	                                          "  </table>";	  
	  
	   vAuxHtml =  vAuxHtml.replace("Clique para fazer sua rota.","")
	   
	  this.openInfoWindowHtml(vAuxHtml  );
   }
  


   GxMarker.prototype.onMouseOver = function() {
                                      this.showMouseOver();
                                    };

   GxMarker.prototype.onMouseOut = function() {
     this.hideMouseOver();
   };

   GxMarker.prototype.showMouseOver = function() {
       if ( this.tooltip ) {
           if ( typeof this.tooltipObject == "undefined" ) {
               this.tooltipObject = document.createElement("div");
               this.tooltipObject.style.display    = "none";
               this.tooltipObject.style.position   = "absolute";
               this.tooltipObject.style.background = "#fff";
               this.tooltipObject.style.padding    = "0";
               this.tooltipObject.style.margin     = "0";
               this.tooltipObject.style.zIndex     = 50000;
               this.tooltipObject.innerHTML        = "<div class=\"markerTooltip\">" + this.tooltip.contents + "</div>";

/*
            var opacity = this.tooltip.opacity / 100;
            this.tooltipObject.style.MozOpacity = opacity;
            this.tooltipObject.style.filter     = "alpha(opacity=" + this.tooltip.opacity + ")";
            this.tooltipObject.style.opacity    = opacity;
*/
               document.body.appendChild(this.tooltipObject);
           }

		function getElementPosition(elem) {
		    var offsetTrail = elem;
		    var offsetLeft = 0;
		    var offsetTop = 0;
		    while (offsetTrail) {
		        offsetLeft += offsetTrail.offsetLeft;
		        offsetTop += offsetTrail.offsetTop;
		        offsetTrail = offsetTrail.offsetParent;
		    }
		    if (navigator.userAgent.indexOf("Mac") != -1 && 
		        typeof document.body.leftMargin != "undefined") {
		        offsetLeft += document.body.leftMargin;
		        offsetTop += document.body.topMargin;
		    }
		    return {left:offsetLeft, top:offsetTop};
		}

		
		var tlcLatLng = this.map.fromContainerPixelToLatLng(new GPoint(0,0), true);
		var tlcDivPixel = this.map.fromLatLngToDivPixel(tlcLatLng);
		var pointDivPixel = this.map.fromLatLngToDivPixel(this.getPoint());
		var c = new GPoint(pointDivPixel.x-tlcDivPixel.x, pointDivPixel.y-tlcDivPixel.y);
		var mapPos = getElementPosition(this.map.getContainer());

		this.tooltipObject.style.left = "-1000px";
        this.tooltipObject.style.top = "-1000px";
        this.tooltipObject.style.display = "block";

        var tipLeft = c.x - this.getIcon().iconAnchor.x + mapPos.left;
        if (tipLeft > (document.body.offsetWidth/2)) {
        	tipLeft -= this.tooltipObject.offsetWidth;
        } else {
        	tipLeft += this.getIcon().iconSize.width;
        }
        this.tooltipObject.style.left = tipLeft + "px";

        var tipTop = c.y - this.getIcon().iconAnchor.y + mapPos.top;
        if ((c.y + this.map.getContainer().offsetTop) > (this.map.getContainer().offsetHeight/2)) {
        	tipTop -= this.tooltipObject.offsetHeight;
        } else {
        	tipTop += this.getIcon().iconSize.height;
        }
        this.tooltipObject.style.top = tipTop + "px";
    this.showHighlight();
	}
	
}

   GxMarker.prototype.hideMouseOver = function() {
                                        if ( typeof this.tooltipObject != "undefined" ) {
                                             this.tooltipObject.style.display = "none";
                                        }
	                                    this.removeHighlight();
                                      }

   GxMarker.prototype.removeEvents = function () { 
                                       while (this.events.length > 0) { 
		                                 GEvent.removeListener(this.events.shift());
	                                   }
                                     }
   GxMarker.prototype.unload = function () {
	                             this.removeEvents(); 	 
	                             this.tooltipObject = null;
	                             this.tooltip = null;
	                             this.imagesArray = '';
	                             this.map = null;
	                             this.hoverIcon = null;
                               }
   function makeInterface(a) {
      var b = a || window;
      b.GxMarker = GxMarker;
   }
   makeInterface();
}

GxMarkerNamespace();


//////////////////////////
// Original maputil.js //
/////////////////////////

var SLICE_STYLE_NORMAL = 1;
var SLICE_STYLE_HIGHLIGHTED = 2;
var SLICE_STYLE_FADED = 3;

function ajustaNum ( num ) {

  
   var strNum = num + '';
   var tam = strNum.length;
  
   var vStr = strNum.substring(tam-1)
   var vRet = vStr;
   if (vRet == 0)
       vRet = 10
   return vRet;
}
//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------

function createSliceIcon(num, style) {
	var icon = new GIcon();
	if (num < 0) {
		icon.image = iurl('icones/') + ((style == SLICE_STYLE_HIGHLIGHTED) ? 'http://www.mapadeamericana.com.br/mapa/imagens/cab2_mapas2.png' : 'cab2_mapas2.png');
	} else {
		var style_dir;
		if (style == SLICE_STYLE_NORMAL) {
			style_dir = 'marker';
		} else if (style == SLICE_STYLE_HIGHLIGHTED) {
			style_dir = 'marker_highlighted';
		} else if (style == SLICE_STYLE_FADED) {
			style_dir = 'marker_faded';
		}
		if ( num > 10 ){
		   num = ajustaNum(num) ;
		
		}
		
		icon.image = iurl('icones/') + style_dir + '/' + num + '.png';
	}
	icon.iconSize = new GSize(24, 29);
	icon.shadow = iurl('icones/marker_shadow.png');
	icon.shadowSize = new GSize(30+15, 12+15);
	icon.iconAnchor = new GPoint(24, 29);
	icon.infoWindowAnchor = new GPoint(24, 29);
	icon.num = num;
	return icon;
};

//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------


function createVWIcon() {
	var icon = new GIcon();	
	//alert(iurl('icones/') );
	icon.image = iurl('icones/vw/') +  'lg_volks.png';	
	icon.iconSize = new GSize(21, 21);	
	icon.shadow = null;
	icon.shadowSize = new GSize(21, 21);
	icon.iconAnchor = new GPoint(21, 21);	
	icon.infoWindowAnchor = new GPoint(21, 21);
	icon.num = 1;
	return icon;
};

//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------


function createPesquisaIcon(vNum) {
    //return null;
    var vNomeIcone =  'pontoPesquisa.png';
    //alert(vNum);
    if ( vNum >  -2 ) {
      
       if (vNum == 1){
          //alert ( 'vNum = '+ vNum );
         vNomeIcone =  'dd-start.png';
       }else if(vNum == -1){
          vNomeIcone =  'dd-end.png';
       }else{ 
        vNomeIcone =  'hike.png';
        
       }
       
    }
     
	var icon = new GIcon();	
	//alert(iurl('icones/') );
	icon.image = iurl('icones/') +  vNomeIcone ;	
	icon.iconSize = new GSize(20, 29);	
	icon.shadow = iurl('map/marker_shadow.png');
	icon.shadow = null;
	icon.shadowSize = new GSize(20, 29);
	icon.iconAnchor = new GPoint(20, 29);	
	icon.infoWindowAnchor = new GPoint(20, 29);
	icon.num = 11;
	return icon;
};

//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function criaMarcaVW(pVetLocais) {
	point = new GPoint(pVetLocais['longitude'], pVetLocais['latitude']);
	var icon = createVWIcon();
	// render popup HTML
	var popupHTML = '<div   style="text-align: left; padding: 10px; background-color:white"><table cellspacing="0" cellpadding="0" border="0" bgcolor="white">';
	popupHTML += '<tr valign="top">';
	if (pVetLocais['photos'].length > 0) {
	     popupHTML += '<td>';
		bizPhotoUrl = fotosHostUrl + pVetLocais['photos'][0]['id'] ;
		preloadImage(bizPhotoUrl);
		popupHTML += '<img src="' + bizPhotoUrl + '"></td>';
		popupHTML += '<td><table ><tr><td><h3>' + pVetLocais['name'] + '</h3></td></tr>';
	}else{
	    popupHTML += '<td>&nbsp;</td>';
	    popupHTML += '<td><table ><tr><td><h3>' + pVetLocais['name'] + '</h3></td></tr>';;
	}
	var vAux =  pVetLocais['address1'];
  	if (pVetLocais['phone']) {
		popupHTML += '<tr><td><b>' + pVetLocais['phone'] + '</b></td></tr>';
	}
	
	if (pVetLocais['address1']) {
		popupHTML += '<tr><td>' + pVetLocais['address1'] + '</td></tr>';
	}
	if (pVetLocais['address2']) {
		popupHTML += '<tr><td>' + pVetLocais['address2'] + '</td></tr>';
	}
	/*
	popupHTML += '<tr><td>';

	if (pVetLocais['city']) {
		popupHTML += pVetLocais['city'] + ', ';
	}
	if (pVetLocais['state']) {
		popupHTML += pVetLocais['state'] + ' ';
	}
	if (pVetLocais['zip']) {
		popupHTML += pVetLocais['zip'];
	}
    popupHTML +=  '</td></tr>';
	
    */
	popupHTML += '</table></td></tr>';
	popupHTML += '<tr><td colspan="3" style="FONT-WEIGHT: bold; COLOR: blue" > Clique para fazer sua rota.</td></tr>';
	popupHTML += '</table></div>';

	// clickURL = '/biz/' + biz['id'];
	var vStr = pVetLocais['id'];
	clickURL = '';
	if (vStr)
      clickURL = 'http://' + pVetLocais['id'];
   
	return new GxMarker(point, icon, popupHTML, clickURL, false, 0, vAux );
};



//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function criaMarcaUsuario(pPonto) {
   //alert('criaMarcaUsuario(pPonto)' );
   //alert(pPonto.longitude);
	point = new GPoint(pPonto.longitude, pPonto.latitude);
	
	var icon = null;
	//icon = createPesquisaIcon(-2);
	// render popup HTML
	var popupHTML = '<div style="text-align: left; padding: 10px;background-color:white"><table cellspacing="0" cellpadding="0" border="0" bgcolor="white"><tr valign="top">';
	popupHTML += ' <td><h3>' + pPonto.nome + '</h3></td>';
	popupHTML += '</tr>';
	popupHTML += '<tr/><td> Endereço  : ' + pPonto.rua         + '</td></tr>';
	popupHTML += '<tr/><td> Bairro    : ' + pPonto.bairro      + '</td></tr>';
	popupHTML += '<tr/><td> Cidade    : ' + pPonto.cidade      + '</td></tr>';
    //popupHTML += '<tr/><td> Estado    : ' + pPonto.estado      + '</td></tr>';
    popupHTML += '<tr/><td> Latitude  : ' + pPonto.latitude    + '</td></tr>';
    popupHTML += '<tr/><td> Longitude : ' + pPonto.longitude   + '</td></tr>';
    popupHTML += '<tr><td colspan="2" style="FONT-WEIGHT: bold; COLOR: blue" > Clique para fazer sua rota.</td></tr>';
	popupHTML += '</table></div>';
	var vAux = pPonto.rua + ", " + pPonto.bairro;
	
	return new GxMarker(point, icon, popupHTML, '' , false, 0,vAux );
};


//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function criaMarcaDeLocal(pVetLocais, number, faded) {
	point = new GPoint(pVetLocais['longitude'], pVetLocais['latitude']);
	 var icon = createSliceIcon(number, faded ? SLICE_STYLE_FADED : SLICE_STYLE_NORMAL);
	 
	// render popup HTML
	 var vTD  = '';
	var popupHTML = '<div style="text-align: left; padding: 10px;background-color:white"><table cellspacing="0" cellpadding="0" border="0" bgcolor="white">';
	 popupHTML += '<tr valign="top">';
	if (pVetLocais['photos'].length > 0) {
	     popupHTML += '<td rowspan="10">';
		bizPhotoUrl = fotosHostUrl + pVetLocais['photos'][0]['id'] ;
		preloadImage(bizPhotoUrl);
		
		popupHTML += '<img src="' + bizPhotoUrl + '" width="75" height="75" ></td>';
		popupHTML += '<td rowspan="10"> <img src="' + imagesHostUrl + 'transparent.png" width="10" height="1" ></td>';
		
		popupHTML += '<td ><h3>' + pVetLocais['name'] + '</h3></td><tr>';
		
	}else{
	  
	    popupHTML += '<td ><h3>' + pVetLocais['name'] + '</h3></td></tr>';
	}
	var vAux =  pVetLocais['address1'];
  	if (pVetLocais['phone']) {
		popupHTML += '<tr>' + vTD + '<td> <b>' + pVetLocais['phone'] + '</b></td></tr>';
	}
	
	if (pVetLocais['address1']) {
		popupHTML += '<tr>' + vTD + '<td>' + pVetLocais['address1'] + '</td></tr>';
	}
	if (pVetLocais['address2']) {
		popupHTML += '<tr>' + vTD + '<td>' + pVetLocais['address2'] + '</td></tr>';
	}
	/*
	popupHTML += '<tr>' + vTD + '<td>' ;
	if (pVetLocais['city']) {
		popupHTML += pVetLocais['city'] + ', ';
	}
	if (pVetLocais['state']) {
		popupHTML += pVetLocais['state'] + ' ';
	}
	if (pVetLocais['zip']) {
		popupHTML += pVetLocais['zip'];
	}
    popupHTML +=  '</td></tr>';
    */
	if (pVetLocais['gasolina']) {
	    popupHTML += '<tr>' + vTD + '<td>' ;
		popupHTML +=  'Gasolina R$: ' + pVetLocais['gasolina'] + '</td></tr>';
		
	}
	
	if (pVetLocais['gnv']) {
	     popupHTML += '<tr>' + vTD + '<td>' ;
		popupHTML +=  'GNV      R$: ' + pVetLocais['gnv'] + '</td></tr>';
		
	}
	
	if (pVetLocais['alcool']) {
	    popupHTML += '<tr>' + vTD + '<td>' ;
		popupHTML +=  'Álcool   R$: ' + pVetLocais['alcool'] + '</td></tr>';
	}
	
	if (pVetLocais['diesel']) {
	    popupHTML += '<tr>' + vTD + '<td>' ;
		popupHTML +=  'Diesel   R$: ' + pVetLocais['diesel'] + '</td></tr>';
	
	}

	popupHTML += '</td></tr>';
	popupHTML += '<tr><td colspan="2" style="FONT-WEIGHT: bold; COLOR: blue" > Clique para fazer sua rota.</td></tr>';
	popupHTML += '</table></div>';
    // alert ( popupHTML);
	// clickURL = '/biz/' + biz['id'];
	var vStr = pVetLocais['id'];
	clickURL = '';
	if (vStr)
      clickURL = 'http://' + pVetLocais['id'];
   
	return new GxMarker(point, icon, popupHTML, clickURL,false, 1, vAux);
};

//-----------------------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------------------
function getAdjustedMapBounds(map, mapContainer) {
	var adjBounds = {};
	var topDead = 25;
	var leftDead = 10;
	var rightDead = 5;
 	var bounds = map.getBounds();
	var lonPerPix = (bounds.getNorthEast().lng() - bounds.getSouthWest().lng())/mapContainer.clientWidth;
	var latPerPix = (bounds.getNorthEast().lat() - bounds.getSouthWest().lat())/mapContainer.clientHeight;
	
	adjBounds['minlon'] = bounds.getSouthWest().lng() + leftDead*lonPerPix;
	adjBounds['maxlon'] = bounds.getNorthEast().lng() - rightDead*lonPerPix;
	adjBounds['minlat'] = bounds.getSouthWest().lat();
	adjBounds['maxlat'] = bounds.getNorthEast().lat() - topDead*latPerPix;
	return adjBounds;
};

