﻿// JavaScript to add Google Map to Voter Information

// Get the address and map it
    var map;
    var geocoder;
    var locationname;
    var locationendaddress;
    var locationstartaddress;
    
    function initialize() {
      if (GBrowserIsCompatible()){   
      map = new GMap2(document.getElementById("divViewMap"));
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl(),new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(250,5)));
      //map.addControl(new GOverviewMapControl());
      map.setCenter(new GLatLng(34, 0), 15);
      map.enableScrollWheelZoom();
      map.enableContinuousZoom();
      geocoder = new GClientGeocoder();
      GEvent.addListener(document.getElementsByTagName("body"),"unload",GUnload);
      mapLocation();
      }else{
      alert("Your browser is not compatible with Google Maps!");
      }
      
    }
      
      function GetAddressLocations(name,start,end) {
          locationname = name;
          locationstartaddress = start;
          locationendaddress = end;     
          geocoder.getLocations(locationendaddress, addAddressToMap);
    }
      
         
    // This function adds the address to the map  
   function addAddressToMap(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Sorry, we could not find that address!");
      } else {
        
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        var getDir = locationstartaddress;
        map.addOverlay(marker);
        locationaddress = place.address;     
        //marker.openInfoWindowHtml('<br />' + '<span style="font-weight:bold">Polling Location address:</span>' + '<br />' + place.address + '<br />');
        getDirectionsTo(getDir);
      }
    }
    
    // function to get driving directions
    function getDirectionsTo(response){
        place = response;
        var viewdirections = document.getElementById("divGetDirections");
        var directions = new GDirections(map, viewdirections );
        directions.load("from: " + locationstartaddress + " to: " + locationendaddress);
        //directions.load("from: " + startPoint + " to: " + endPoint);
        map.closeInfoWindow(); 
     
   }
       
    
    
function printMe()
  {
     window.print();
     return false;
  }  
  
