function changeBodyClass(from, to) {
	document.body.className = document.body.className.replace(from, to);
	return false;
}

//Create an icon for bandeira branca + price
	priceicon = new GIcon();
//	priceicon.shadow = "images/markers/shadow.png";
	priceicon.iconSize = new GSize(43, 29);
//	priceicon.shadowSize = new GSize(58, 29);
	priceicon.iconAnchor = new GPoint(23, 28);
	priceicon.infoWindowAnchor = new GPoint(90, 0);
//	priceicon.infoShadowAnchor = new GPoint(26, 13);
	priceicon.transparent = '/images/transparent.png';

    priceicon0 = new GIcon(priceicon);
	priceicon0.sprite = {image:"/images/mapsprite.png", width:43, height:29, top:0, left:497};
    priceicon1 = new GIcon(priceicon);
	priceicon1.sprite = {image:"/images/mapsprite.png", width:43, height:29, top:0, left:688};
    priceicon2 = new GIcon(priceicon);
	priceicon2.sprite = {image:"/images/mapsprite.png", width:43, height:29, top:0, left:540};		
    priceicon3 = new GIcon(priceicon);
	priceicon3.sprite = {image:"/images/mapsprite.png", width:43, height:29, top:0, left:583};
    priceicon4 = new GIcon(priceicon);	
	priceicon4.sprite = {image:"/images/mapsprite.png", width:43, height:29, top:0, left:626};


//Create an icon for the arrow
	var gClickMarker='';
	home = new GIcon();
	home.iconSize = new GSize(35, 31);
	home.iconAnchor = new GPoint(0, 0);
	home = new GIcon(home, "images/home_icon.png");		

var stopupdates=false;
var ttopen=false;	
var ftype=1;
var favoreg=1;
var stations = [0,1,2,3,4,5,6];
var mt=[];
var gmarkers=[];
var homeon = false;
var actions = false;
var slidezoom=false;
var slideprice=false;
var slidegas=false;
var runroutine;
var map;


var tooltip=function(){
 var id = 'tt';
 var left = 0;
 var maxw = 300;
 var speed = 10;
 var timer = 20;
 var endalpha = 95;
 var alpha = 0;
 var tt,t,c,b,h;
 var ie = document.all ? true : false;
 return{
  show:function(v,w){
   if(tt == null){
    tt = document.createElement('div');
    tt.setAttribute('id',id);
    c = document.createElement('div');
    c.setAttribute('id',id + 'cont');
    tt.appendChild(c);
    document.body.appendChild(tt);
    tt.style.opacity = 0;
    tt.style.filter = 'alpha(opacity=0)';
    document.onmousemove = this.pos;
   }
   tt.style.display = 'block';
   c.innerHTML = v;
   tt.style.width = w ? w + 'px' : '200px';
   tt.style.overflow = 'hidden';
   if(!w && ie){
    tt.style.width = tt.offsetWidth;
   }
  if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
  h = -20;
  clearInterval(tt.timer);
  tt.timer = setInterval(function(){tooltip.fade(1)},timer);
  },
  pos:function(e){
   var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
   var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
   tt.style.top = (u - h) + 'px';
   tt.style.left = (l + left) + 'px';
  },
  fade:function(d){
   var a = alpha;
   if((a != endalpha && d == 1) || (a != 0 && d == -1)){
    var i = speed;
   if(endalpha - a < speed && d == 1){
    i = endalpha - a;
   }else if(alpha < speed && d == -1){
     i = a;
   }
   alpha = a + (i * d);
   tt.style.opacity = alpha * .01;
   tt.style.filter = 'alpha(opacity=' + alpha + ')';
  }else{
    clearInterval(tt.timer);
     if(d == -1){tt.style.display = 'none'}
  }
 },
 hide:function(){
  clearInterval(tt.timer);
   tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
  }
 };
}();

function cleartrackers(){
 for (i=0; i < mt.length; i++) {
mt[i].disable();
 }  }

function trackmedown(){
 for (i=0;i<GeoTools.markers.length;i++) {
mt[i] = new MarkerTracker(GeoTools.markers[i], map, { iconScale:0, color:'#CD070E', weight:10, length:12, padding:5});         
      }
	stopupdates = true;
}

function createPriceMarker(info, lowest){

if (lowest == true) {
	if (info[17] !== 0) {
		priceicon = priceicon2;
	}
	else {
		priceicon = priceicon1;
	}
}
else {
	if (info[17] !== 0) {
		priceicon = priceicon3;
	}
	else {
		priceicon = priceicon0;
	}
}
		var point = new GLatLng(parseFloat(info[1]), parseFloat(info[5]));
		opts = {
			"icon": priceicon,
			"clickable": true,
			"labelText": info[3],
			"labelOffset": new GSize(-8, -25),
			"labelClass": 'pricelabel'
		};
		var marker = new LabeledMarker(point, opts);
		marker.data = info.clone();
		marker.id = info[0];
		marker.fave = info[8];
		marker.price = info[3];
		marker.rating = info[10];
		if (lowest==true){
			marker.lowprice=info[3];
		}
		else{marker.lowprice=false;}
		
GEvent.addListener(marker, "mouseover", function() {
  tooltip.show("<b>"+info[2]+"</b><br/><span style='font-size:9px;'>(clique para mais informações)</span>");
  ttopen=true;
});
GEvent.addListener(marker, "mouseout", function() {
  tooltip.hide();
  ttopen=false;
});
if (slidegas == true) {
	var element = [$('no_gas_img'), $('no_gas')];
	fixed_growl(element);
	slidegas = false;
}		
		GEvent.addListener(marker, "click", function(){
			gClickMarker = marker.getPoint() ; 
			StationBox(info);
			marker.openExtInfoWindow(
      map,
	  "simple_example_window",
      windowcontent,
      {beakOffset: 5}
    ); 

new Ajax.InPlaceEditor($('priceinfowindow'), '/mapa/price', {
		okControl:'link', 
		cancelText:'cancelar', 
		clickToEditText:'', 
		savingText:'Salvando', 
		rows:1, 
		size:4,
		onComplete: function (transport){
			if(typeof transport !== "undefined") {
				if (transport.responseText.match('login')){
					$('priceinfowindow').update('-,--');
					$('block').appear(); 
				}
				else if (transport.responseText.match('invalido')){
					$('priceinfowindow').update('???');
					growl_alert('Preço inválido','invalid_price',false);
				}
				else{
					$('priceinfowindow').update(':)');
					growl_alert('Preço registrado','good_price',false); 
					$('timeago').update('atualizado agora pouco por você!'); 
					new Effect.Highlight('timeago', { startcolor: '#cd070e',endcolor: '#ffffff' }); 
					}
			}
		}, 
		callback: function(form, value) { 
			return 'fueltype='+ftype+'&stationid='+info[0]+'&price='+escape(value); 
			}
			}
			);
	new Starbox('starbox_' + info[0], info[10], { ghosting: true , rerate: true});
$('starbox_' + info[0]).observe('starbox:rated', starboxThankYou);
		});
		return marker;
}

function StationBox(info){
	if (info[9]==1){votes_info=info[9]+' voto';}else{votes_info=info[9]+' votos';}
	if (info[17]==1){autu_info=info[17]+' autuação';}else{autu_info=info[17]+' autuações';}
	windowcontent = '\
<div id="infowindowwrapper" >\
<div id=distribuidora>' + info[2] + '<div id="close_info" onclick="map.closeExtInfoWindow(); return false;"></div></div>\
  <div class="grid-c1" style="text-align:left;">\
    <span id=stationname>' +
	info[12] +
	'</span><br style="clear:both" />\
	<span id=stationaddress>' +
	info[13] +
	'</span><br style="clear:both" />\
  </div>\
  <div class="grid-c2" onmouseover="tooltip.show(\'Dê sua nota para este posto\');" onmouseout="tooltip.hide();">\
  <div id=starbox_' +
	info[0] +
	' style="width:85px; height:17; display:block;"></div><span id=votes>' +
	votes_info +
	'</span>\
  </div>\
    <div style="clear:both; margin-bottom:8px; height:1px; width:10px;" /></div>\
    <div class="grid-c1">\
	<div id=priceinfowindow onmouseover="tooltip.show(\'Clique para atualizar o preço\');" onmouseout="tooltip.hide();">' +
	info[3] +
	'</div>\
	</div>\
  <div class="grid-c2">\
<ul id=pipe>';
	if (info[8] == null) {
			windowcontent = windowcontent + '\
<li class=notfavorite id=favorite_' +
		info[0] +
		' onclick="javascript:faveit(' +
		info[0] + ');pageTracker._trackEvent(\'Map\', \'Favorites\', \'Add or Remove\');return false;" onmouseover="tooltip.show(\'Adicionar aos favoritos\');" onmouseout="tooltip.hide();" >'
	}
	else {
		windowcontent = windowcontent + '\
<li class=yesfavorite id=favorite_' +
		info[0] +
		' onclick="javascript:faveit(' +
		info[0] +
		');pageTracker._trackEvent(\'Map\', \'Favorites\', \'Add or Remove\');return false;" onmouseover="tooltip.show(\'Remover dos favoritos\');" onmouseout="tooltip.hide();" >'
	}
	windowcontent = windowcontent + '<div id=fave_text class=infopipetext> favorito</div></li>\
<li class=skull onmouseover="tooltip.show(\'Total de autuações pela ANP\');" onmouseout="tooltip.hide();"><div class=infopipetext id=totalpirates>' +
	autu_info +
	'</div></li>\
</ul>\
<div class=grid-c2 ><a id=fave_text style=float:right;margin-top:15px;margin-right:3px; href=/posto/'+info[0]+'/'+info[18]+'/'+info[19]+' target=_blank >mais info&nbsp;»</a></div>\
  </div>\
    <div style="text-align:left;clear:both; margin-bottom:10px; height:1px; width:auto;" />';
	if (info[14] == '--') {
		windowcontent = windowcontent + '\
<span id=timeago class=smallblacktext>contribua atualizando o preço!</span></div>'
	}
	else {
		windowcontent = windowcontent + '\
<span id=timeago class=smallblacktext>' +
		info[14] +
		' por ' +
		info[7] +
		'</span></div>'
	}
	
	windowcontent = windowcontent + '</div>';
}

function freaky(point1, point2) {
map.panTo(new GLatLng(point1, point2));
    }
				
function init() {
        var normal = new GSmallZoomControl3D();
		map = new GMap2($("map"));
		map.addControl(normal);
		map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
		map.setMapType(G_NORMAL_MAP);
		geocoder = new GClientGeocoder();
		geocoder.setBaseCountryCode({countryCode:'BR'});
//		G_NORMAL_MAP.getMinimumResolution = function () { return 14 };
		var zoomlvl = map.getZoom();
				if (zoomlvl < 14 && slidezoom == false) {
					Event.observe(window, 'load', function() {
						growl_alert('Aproxime o zoom para ver os postos','zoom',true);
						slidezoom = true;
					});}
				else {
					GeoTools.updatemapmarkers(ftype, favoreg);
				}

		GEvent.addListener(map, 'moveend', loadnow);
		GEvent.addListener(map, "zoomend", function(){
				var zoomlvl = map.getZoom();
		if (zoomlvl >= 14) {
			if (slidezoom == true) {
				var element = [$('zoom_img'), $('zoom')];
				fixed_growl(element);
				slidezoom = false;
			}
		}			
		});
	}
			
	window.onunload = GUnload;

 
 function searchaddress(str){
 if (str == '' || str == 'buscar endereço ou CEP...') {
 	growl_alert('Endereço inválido, tente novamente','no_add',false);
 }
 else {
 	var url = '/searchengine?address=' + str;
 	new Ajax.Request(url, {
 		method: 'get',
 		onCreate: function loading(){
 			$("loading").show();
 		},
 		onComplete: function(request){
 			$("loading").hide();
 			destination = request.responseText;
 			if (destination == 'NO') {
				growl_alert('Endereço inválido, tente novamente','no_add',false);
 			}
 			else 
 				if (destination == 'NOT') {
					growl_alert('Ooooops aconteceu um erro na busca, tente mais tarde','no_add',false);
 				}
 				else {
					if (gClickMarker != '') {
					map.closeExtInfoWindow();
					}
					var zoomlvl = map.getZoom();
					var sniper = 15-zoomlvl;
 					var SplitGPS = destination.split(",");
 					var pointer = new GLatLng(parseFloat(SplitGPS[0]), parseFloat(SplitGPS[1]));
 					if (zoomlvl < 14) {
					map.setCenter(pointer,zoomlvl+sniper);
					}else {map.panTo(pointer);}
 					if (homeon == true) {
 						$('mtgt_home').remove();
 						homeon = false;
 						
 					}
 					var locate = new LabeledMarker(pointer, {
 						icon: home
 					});
					locate.id= 'home';
 					map.addOverlay(locate);
 					homeon = true;
 					GEvent.addListener(locate, "click", function(){
 						$('mtgt_home').remove();
 						homeon = false;
 					});

 					}	
 		}
 	});
 }
}

function faveit(id)
{
var url = "/mapa/favorites";
var pars = {
	id : id,
	window : window
};
				new Ajax.Request(url, {
					method: 'post',
					  onCreate: function loading (){$("loading").show();},
					onComplete: function close(){$("loading").hide();},
					parameters: pars
				});

}
function goadd() {
var url = '/mapa/load_view';
new Ajax.Request(url, {
	  method: 'post', 
  onCreate: function loading (){$("loading").show();}, 
  onComplete: function(request){
  	$("loading").hide();
		destination = request.responseText;
		if (destination == 'NOT!') {
			$('block').appear();
		}
		else if (destination == ', '){
			growl_alert('Você ainda não possui uma visão salva','no_save',false);
			
		}else{
					var zoomlvl = map.getZoom();
					var sniper = 15-zoomlvl;
 					var SplitGPS = destination.split(",");
 					var pointer = new GLatLng(parseFloat(SplitGPS[0]), parseFloat(SplitGPS[1]));
 					if (zoomlvl < 14) {
					map.setCenter(pointer,zoomlvl+sniper);
					}else {map.panTo(pointer);}
 					if (homeon == true) {
 						$('mtgt_home').remove();
 						homeon = false;
 						
 					}
 					var locate = new LabeledMarker(pointer, {
 						icon: home
 					});
					locate.id= 'home';
 					map.addOverlay(locate);
 					homeon = true;
 					GEvent.addListener(locate, "click", function(){
 						$('mtgt_home').remove();
 						homeon = false;
 					});
		}
	}
});
pageTracker._trackEvent('Map', 'Visão', 'Ir');
}

var GeoTools = {
markers: new Array(),
BulletIsFlying: false,
pricelabels: new Array(),
updatemapmarkers: function(type, favoreg){
				if (stopupdates == false) {
				cleartrackers();
				var zoomlvl = map.getZoom();
				var center = map.getCenter();	
				bounds = map.getBounds();
				minY = bounds.getNorthEast().lng();
				maxY = bounds.getSouthWest().lng();
				minX = bounds.getSouthWest().lat();
				maxX = bounds.getNorthEast().lat();
				GeoTools.pars = {
					minX: minX,
					maxX: maxX,
					minY: minY,
					maxY: maxY,
					ftypeid: type,
					reqid: favoreg,
					stations: stations.toString(),
					zoomlvl: zoomlvl
				}				


	if (!GeoTools.BulletIsFlying) {
		GeoTools.BulletIsFlying = true;
		new Ajax.Request('/mapa/get_pois', {
			method: 'post',
			onCreate: function loading(){
			$("loading").show();
			},
			onComplete: function close(){
				$("loading").hide();
				GeoTools.RainDanceOff();
			},
			parameters: GeoTools.pars,
			encoding: 'UTF-8'
		});
		GeoTools.pars = null;
	}
}
},

  RainDanceOff: function() {   
    if (GeoTools.pars){ 
      GeoTools.BulletIsFlying = true;
				new Ajax.Request('/mapa/get_pois', {
					method: 'post',
					onCreate: function loading (){$("loading").show();},
					onComplete: function close (){$("loading").hide(); GeoTools.RainDanceOff();pageTracker._trackEvent('Map', 'Get POIs');
					},
					parameters: GeoTools.pars,
					encoding: 	'UTF-8'
				});
      GeoTools.pars = null;
    } else 
      GeoTools.BulletIsFlying = false;
  },
profit: function() {   
    Event.observe(window, "resize", loadnow)
  },
updatemarkers: function(fireSale){
	var zoomlvl = map.getZoom();
	if ((zoomlvl >= 14 && favoreg == 1) || (stopupdates == false && favoreg != 1)) {
		var seen_number = false;
		var lowestvalue;
		pricelist = [];
		GeoTools.markers.each(function(useless){
			useless.used = false
		});
		fireSale.each(function(info){
		
			if (info[3] !== '-,--') {
				pricelistunit = ['\'' + info[1] + '\'', '\'' + info[2] + '\'', '\'' + info[3] + '\'', '\'' + info[5] + '\'', '\'' + info[0] + '\''];
				pricelist.push(pricelistunit);
			}
			
			if (info[3] !== '-,--' && seen_number == false) {
				lowestvalue = info[3];
				seen_number = true;
			}
			
			var marker = GeoTools.markers.find(function(marker){
				if (marker.id == info[0] && marker.price == info[3] && marker.rating == info[10] && marker.fave == info[8] && marker.lowprice == false) 
					return true
			})
			if (!marker) {
			
				if (info[3] == lowestvalue) {
					marker = createPriceMarker(info, true);
				}
				else {
					marker = createPriceMarker(info, false);
				}
						
				map.addOverlay(marker);
				GeoTools.markers.push(marker);
				
			}
			marker.used = true;
		});
		this.updatefireSale();
	}
	if (ttopen==true)  {
tooltip.hide();
  ttopen=false;}
},
	
  updatefireSale: function(markers) {
    var new_markers = new Array();
    GeoTools.markers.each(function(marker) {
      if (marker.used) 
        new_markers.push(marker);
      else 
        map.removeOverlay(marker);
    });
    GeoTools.markers = new_markers;    
		if (favoreg != 1) {
		trackmedown();
		}
  }
}
function add(){
var standard = map.getCenter();
var url = '/mapa/save_view';
new Ajax.Request(url, {
	  method: 'post', 
  onCreate: function loading (){$("loading").show();},  
  onComplete: function(request){
  	$("loading").hide();
			insert = request.responseText;
			if (insert == 'NOT!') {
			$('block').appear();
			}
			else {
				growl_alert('Visão salva com sucesso','ok_add',false);
			}
  },
parameters: {lat: map.getCenter().lat(),
	lng: map.getCenter().lng()}
});
pageTracker._trackEvent('Map', 'Visão', 'Salvar');
}

function arranize(){
$('sendit').style.background='#E6E6E6';
$('sendit').style.color='#000000';
stations=[];
var stationelements = document.stationselect.elements;
var howbig = stationelements.length;	
for (i=0; i<howbig; i++){
if(stationelements[i].checked==true)	{
stations.push(i);

}
}

if (stopupdates == true){
	stopupdates = false;
}
		var count =	$$('li.selected a.checkbox-select-others').size();
		if (count == 0) {
			$('brand_nav').update('todas as bandeiras');
			pageTracker._trackEvent('Map', 'Brand Filter', 'todas as bandeiras');
		}
		else if (count > 1) {
			$('brand_nav').update(count + ' bandeiras');
			pageTracker._trackEvent('Map', 'Brand Filter', count + ' bandeiras');
			}
		else {
			$$('li.selected a.checkbox-select-others').each(function (event){ 
			singlebrand=event.textContent;})
			pageTracker._trackEvent('Map', 'Brand Filter', singlebrand);
			$('brand_nav').update(singlebrand);
		}
		
		target_width = $('brandcontainer').getWidth();
		$('branderz').morph('width:'+target_width+'px;');
		
if (gClickMarker != '') {
map.closeExtInfoWindow();
}
GeoTools.updatemapmarkers(ftype,favoreg);
}

function loadnow(){
	if (gClickMarker!='') {
		var bounds = map.getBounds();
		minY = bounds.getNorthEast().lng();
		maxY = bounds.getSouthWest().lng();
		minX = bounds.getSouthWest().lat();
		maxX = bounds.getNorthEast().lat();
		
		var lngT =''
		var latT =''
		if  ( (gClickMarker.lng() > maxY) && (gClickMarker.lng() < minY) )  {
			 lngT = 1;
		} else {
			lngT =0 ;
			//$('simple_example_window').hide();
		}
		
		if ( (gClickMarker.lat() > minX) && (gClickMarker.lat() < maxX) ) {
			latT = 1 ;
		} else {
			//$('simple_example_window').hide();
			latT = 0;
		}
		if (lngT ==0 || latT ==0) {
			map.closeExtInfoWindow();
		}

		
		
	}
	//alert (gClickMarker) ; 
	var zoomlvl = map.getZoom();
			if (stopupdates == false) {
				if (zoomlvl >= 14 || stopupdates==true) {
					GeoTools.updatemapmarkers(ftype, favoreg);
				}
				else {
					map.clearOverlays();
					GeoTools.markers = [];
					$("loading").hide();
					homeon = false;
					if (slideprice == true) {
						var element = [$('no_price_img'), $('no_price')];
						fixed_growl(element);
						slideprice = false;
					} 
						if (slidegas == true) {
							var element = [$('no_gas_img'), $('no_gas')];
							fixed_growl(element);
							slidegas = false;
						}
					if (slidezoom == false) {
						growl_alert('Aproxime o zoom para ver os postos','zoom',true);
						slidezoom = true;
					}
				}
			}
}

function delquote(str){return (str=str.replace(/["']{1}/gi,""));} 

			document.observe('dom:loaded',function(){
init();

	$$('.checkbox-select-others').each(function (event) {
	    return $(event).observe('click', function(event) {
			$(Event.element(event)).up(1).addClassName('selected');
			$(Event.element(event)).up().previous().writeAttribute('checked', true);
			$('allstations').writeAttribute('checked', false);
			$('allstations').up().removeClassName('selected');
			$$('li.selected a.checkbox-select-others').each(function (event, count){  
					$('sendit').style.background='#cd070e';
					$('sendit').style.color='#FFFFFF';			
				
			}) 
		});
	});
	
	$$('.checkbox-deselect-others').each(function (event) {
		return $(event).observe('click', function(event) {
			$(Event.element(event)).up(1).removeClassName('selected');
			$(Event.element(event)).up().previous(1).writeAttribute('checked', false);
			$$('li.selected a.checkbox-select-others').each(function (event, count){  
				$('sendit').style.background='#cd070e';
				$('sendit').style.color='#FFFFFF';									   
			})		
			$$('#branderz li:not([class=selected])').each(function (event, count){
				  
if (count==9){
				$$('li a.checkbox-select-all').each(function (event){
					event.up().addClassName('selected');
					event.previous().writeAttribute('checked', true);})
					$('sendit').style.background='#cd070e';
					$('sendit').style.color='#FFFFFF';				
}
			})
	    });
	});
	
	$$('.checkbox-select-all').each(function (event) {
		return $(event).observe('click', function(event) {
			$(Event.element(event)).up(1).addClassName('selected');
			$(Event.element(event)).up().previous().writeAttribute('checked', true);
			$$('.checkbox-deselect-others').each(function (event){
				event.up().removeClassName('selected');
				event.previous(1).writeAttribute('checked', false);
				$('sendit').style.background='#cd070e';
				$('sendit').style.color='#FFFFFF';
			});
	   });
	});

});

function no_fave (){
	growl_alert('Você ainda não possui postos favoritos','no_fave',false);
}						
function gassy () {
	map.clearOverlays();
	if (slideprice == true) {
		var element = [$('no_price_img'), $('no_price')];
		fixed_growl(element);
		slideprice = false;
	}	
	if (slidegas == false) {
		growl_alert('Não existem postos para este tipo de combustível nesta região','no_gas',true);
		slidegas=true;}
}

function favo(){
	//resume here
	var zoomlvl = map.getZoom();
	if (zoomlvl >= 14) {
		stopupdates = false;
		GeoTools.updatemapmarkers(ftype, favoreg);
	}
	else {
		stopupdates = false;
		if (slidegas == true) {
			var element = [$('no_gas_img'), $('no_gas')];
			fixed_growl(element);
			slidegas = false;
		} 
		if (slideprice == true) {
			var element = [$('no_price_img'), $('no_price')];
			fixed_growl(element);
			slideprice = false;
		}
		if (slidezoom == true) {
			var element = [$('zoom_img'), $('zoom')];
			fixed_growl(element);
 			slidezoom = false;
		}
		if (slidezoom == false && favoreg==1 && zoomlvl < 14) {
			growl_alert('Aproxime o zoom para ver os postos','zoom',true);
			slidezoom = true;
		}
		if (favoreg == 1){
			cleartrackers();
			map.clearOverlays();
			GeoTools.markers = [];
			$("loading").hide();
			homeon=false;
		}
		if (favoreg != 1){
			GeoTools.updatemapmarkers(ftype, favoreg);
		}
		
	}
}

function SetValues(Form, CheckBox, Value)  
{  
    var objCheckBoxes = document.forms[Form].elements[CheckBox];  
    var countCheckBoxes = objCheckBoxes.length;  
    for(var i = 0; i < countCheckBoxes; i++)  
        objCheckBoxes[i].checked = Value;  
}

function pickfuel(x){
	if (stopupdates == true){stopupdates = false;} 
	var zoomlvl = map.getZoom();
	if (zoomlvl >= 14 || stopupdates == false) {

switch(x)
{
case 1:
fuel_label = 'álcool comum';
  break;
case 2:
fuel_label = 'gasolina comum';
  break;
case 3:
fuel_label = 'gasolina aditivada';
  break;
case 7:
fuel_label = 'álcool aditivado';
  break;
case 5:
fuel_label = 'diesel comum';
  break;
case 6:
fuel_label = 'gnv';
  break;
case 0:
fuel_label = 'diesel aditivado';
  break;
}

		ftype = x;
		$('fuel_nav').update(fuel_label);		
		target_width = $('fuelcontainer').getWidth();
		$('fuely').morph('width:'+target_width+'px;');		
		GeoTools.updatemapmarkers(ftype, favoreg);
	}
	pageTracker._trackEvent('Map', 'Fuel Filter', fuel_label);
if (gClickMarker != '') {
map.closeExtInfoWindow();
}
}

function fixed_growl(element){
var please = new Gr0wl.Smoke();
please.hide(element);
}
function growl_alert (message, id, fixed){
Growl.Smoke({
	title: '',
	text: message,
	image: 'images/logo_growl.png',
	duration: 3.0,
	id: id,
	fixed: fixed
})	
}

function gotoAddress(response) {
	$("loading").hide();
  if (!response || response.Status.code != 200) {
	 	growl_alert('Desculpe, não foi possível encontrar o local com essas informações.','no_add',false);
		pageTracker._trackEvent('Map', 'Search', 'Error');
  } else {
	pageTracker._trackEvent('Map', 'Search', 'Concluded');
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],
                        place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.setCenter(point);
  }
}


function showLocation(){
	$("loading").show();
	if (gClickMarker != '') {
map.closeExtInfoWindow();
}
	var address = document.address_search.q_address.value;
    geocoder.getLocations(address, gotoAddress);
}

Event.observe(window, 'load', GeoTools.profit)
logo_growl= new Image(); 
logo_growl.src="/images/logo_growl.png";
check_image= new Image(); 
check_image.src="images/checkmark1.png";