// JavaScript Document
//formatta il testo con html;
function showBaloon(message){
	var opentag = "<font style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; font-weight:normal;'><br>";
	var closetag = "</font>";		
	message = opentag + message + closetag;
	return message;
}

//posiziona la mappa sul country
function findCountry(countrytofind) {
		
		geocoder.getLatLng(
			countrytofind,
			function(point) {
			  if (!point) {
				  
			  } else {
				map.setCenter(point, 5);				
			  }
			}
		  );
		
}

//posiziona la mappa sulla regione
function findRegione(regionetofind) {		
		//aggiunge il country selezionato alla regione 
		//(a volte google map non č preciso con poche informazioni)
		regionetofind = regionetofind + "," + currentcountry;
		geocoder.getLatLng(
			regionetofind,
			function(point) {
			  if (!point) {
				  
			  } else {
				map.setCenter(point, 8);				
			  }
			}
		  );
		
}

//posiziona la mappa sulla citta
function findCitta(cittatofind) {
		//aggiunge la regione selezionata alla cittā 
		//(a volte google map non č preciso con poche informazioni)		
		cittatofind = cittatofind + "," + currentregione;
		geocoder.getLatLng(
			cittatofind,
			function(point) {
			  if (!point) {
				  
			  } else {
				map.setCenter(point, 13);				
			  }
			}
		  );
}

//cerca indirizzo e mostra il baloon
function findAddress(addresstofind,partnerid,baloonmessage) {
		
		geocoder.getLatLng(
			addresstofind,
			function(point) {
			  if (!point) {
				alert("Indirizzo non localizzabile sulla mappa : " + addresstofind);
			  } else {
				map.setCenter(point, 17);
				var marker = new GMarker(point,getIcon());								
					marker.baloonmessage = baloonmessage;
					marker.partnerid = partnerid;
				map.addOverlay(marker);
				marker.openInfoWindowHtml(showBaloon(baloonmessage));				
			  }
			}
		  );
}

//visualizza marker sulla mappa
function ShowMarkerOnMap(addresstolocate, partnerid, baloonmessage) {
		
		geocoder.getLatLng(
			addresstolocate,
			function(point) {
			  if (!point) {
				//alert("Indirizzo non trovato sulla mappa : " + addresstolocate);
			  } else {
				map.setCenter(point, 10);				
				var marker = new GMarker(point,getIcon());								
					marker.baloonmessage = baloonmessage;
					marker.partnerid = partnerid;
				map.addOverlay(marker);				
			  }
			}
		  );
		
}

//restisuice icona per il marker
function getIcon() {

	var icon = new GIcon();	
	icon.image = "http://dg.ogilvy.it/IBM_DealerLocator/" + "images/icona.png";		
	icon.iconSize = new GSize(41, 40);	
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);
	return icon;				
	
}