﻿function load() {

      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
              
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
        
    	//accuracy = 8
    	ACCURACY_MULTIPLE = 6
    	
    
    // populate the reliability warning above the map
    function outputReliabilityWarning(accuracy, address) {
        var container = document.getElementById("mapAccuracy");
        var message = 'searching for address...'

        if(accuracy >=8) message = address;
        if(accuracy < 8) message = '<span class="alert">found street location only</span>';
        if(accuracy < 6) message = '<span class="alert">found suburb location only</span>';
        if(accuracy < 4) message = '<span class="alert">found state location only</span>';

        if (container) {
            container.innerHTML = message;
            if (message) container.style.display = 'block';
            else container.style.display = 'none';
        }
    }
    
    // Generate icon.
    function createIcon(accuracy) {
        var icon = new GIcon();
        var path = "http://www.aquatronics.com.au/images/"
        if (accuracy && accuracy == ACCURACY_MULTIPLE) {
            icon.image            = path + "map-pointer01.png";
            icon.printImage       = path + "map-pointer01.png";
            icon.mozPrintImage    = path + "map-pointer01.png";
            icon.shadow = path + "map-pointer01s.png";
            icon.iconSize = new GSize(60, 60);
        	icon.shadowSize = new GSize(95, 60);
        	icon.iconAnchor = new GPoint(1, 59);
        	icon.infoWindowAnchor = new GPoint(15, 28);
        }
        else if (accuracy && parseInt(accuracy) < 8) {
            icon.image            = path + "map-pointer01.png";
            icon.printImage       = path + "map-pointer01.png";
            icon.mozPrintImage    = path + "map-pointer01.png";
             icon.shadow = path + "map-pointer01s.png";
            icon.iconSize = new GSize(60, 60);
        	icon.shadowSize = new GSize(95, 60);
       		icon.iconAnchor = new GPoint(1, 59);
      	 	icon.infoWindowAnchor = new GPoint(15, 28);
        }
        else {
            icon.image            = path + "map-pointer01.png";
            icon.printImage       = path + "map-pointer01.png";
            icon.mozPrintImage    = path + "map-pointer01.png";
             icon.shadow = path + "map-pointer01s.png";
            icon.iconSize = new GSize(60, 60);
        	icon.shadowSize = new GSize(95, 60);
        	icon.iconAnchor = new GPoint(1, 59);
        	icon.infoWindowAnchor = new GPoint(15, 28);
        }

        return icon;
    }
    	
    	function addAddressToMap(response) {
          	map.clearOverlays();
            if (!response || response.Status.code != 200) {
              //alert("\"" + address + "\" not found");
              var container = document.getElementById("mapAccuracy");
       	      if (container) {
            	container.innerHTML = '<span class="alert">this address could not be plotted on the map</span>';
            }
            } else {
              place = response.Placemark[0];
              point = new GLatLng(place.Point.coordinates[1],
              					place.Point.coordinates[0]);
              map.setCenter(point, 15);
              var marker = new GMarker(point, createIcon(place.AddressDetails.accuracy));
              map.addOverlay(marker);
              
              GEvent.addListener(marker, "click", function() {
              	marker.openInfoWindowHtml("<strong>Aquatronics Marine</strong><br>23/10-18 Orchard Road<br>Brookvale 2100<br>NSW AUSTRALIA<br><br>Phone: +61 2 9905 5655<br>Fax: +61 2 9905 1635");
              });              
              
              //marker.openInfoWindowHtml(place.address + '<br>' +
              //	place.AddressDetails.Country.CountryNameCode);
             //outputReliabilityWarning(place.AddressDetails.Accuracy, place.address)
                          
            }
        }
    
    	// Create our "tiny" marker icon
        //var icon = new GIcon();
        //icon.image = "http://localhost:81/images207/map-pointer01.png";
        //icon.shadow = "http://localhost:81/images207/map-pointer01shadow.png";
        //icon.iconSize = new GSize(53, 40);
        //icon.shadowSize = new GSize(53, 40);
        //icon.iconAnchor = new GPoint(39, 4);
        //icon.infoWindowAnchor = new GPoint(5, 1);
        
        geocoder = new GClientGeocoder();
        if (geocoder) {
        geocoder.getLocations(address, addAddressToMap);
         
          
        
    }
    
    
    }
        
        
}
        

    
   