﻿//<![CDATA[

var map;
 var geocoder;


function load() {
  map = new GMap2(document.getElementById("map"));
  map.setCenter(new GLatLng(34, 0), 1);
  geocoder = new GClientGeocoder();
 }




 function loadMap(latitude, longitude, zoom) {

     zoom = parseFloat(zoom);

     if (GBrowserIsCompatible()) {
         var map = new GMap2(document.getElementById("map"));
         map.addControl(new GSmallMapControl());
         map.addControl(new GMapTypeControl());
         map.setMapType(G_HYBRID_MAP);
         var center = new GLatLng(latitude, longitude);
         map.setCenter(center, zoom);
         geocoder = new GClientGeocoder();
         var marker = new GMarker(center);
         map.addOverlay(marker);
     }
 }


// addAddressToMap() is called when the geocoder returns an
// answer.  It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addAddressToMap(response,defaultArea) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
	notfound = 1;
	findLocation("Albufeira")
 } else {
	
	if (notfound = 1) {zoom = 9;} else {zoom = 14;}
	
	place = response.Placemark[0];
	 point = new GLatLng(place.Point.coordinates[1],
	place.Point.coordinates[0]);
	marker = new GMarker(point);
	map.setCenter(point, zoom);
	map.addControl(new GLargeMapControl());
  }
}


// showLocation() is called when you click on the Search button
// in the form.  It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation(addressSel) {
  var address = addressSel;
  geocoder.getLocations(address, addAddressToMap);
}

// findLocation() is used to enter the sample addresses into the form.
function findLocation(address) {
  addressSel = address;
  showLocation(addressSel);
}

