﻿var googleGeocoder = new google.maps.Geocoder();;
var googleMap = null;
var hasMarkerPoints = false;
var googleMapZoom = 0;


function initializeMap(szMapId, lngZoom, szMapCenterAddress) {
    if (googleMapZoom != 0) {
        lngZoom = googleMapZoom;
    }
    
    var myOptions = {
      zoom: lngZoom,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    googleMap = new google.maps.Map(document.getElementById(szMapId), myOptions);
    centerMap(szMapCenterAddress);
    
    if (hasMarkerPoints) {
       addMarkerPoints();
    }
    
    setZoom(googleMapZoom);
}


function initializeMapByLatLong(szMapId, lngZoom, lngLat, lngLong) {
    if (googleMapZoom != 0) {
        lngZoom = googleMapZoom;
    }
    
    var myOptions = {
      zoom: lngZoom,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    googleMap = new google.maps.Map(document.getElementById(szMapId), myOptions);
    centerMapByLatLong(lngLat, lngLong);
    
    if (hasMarkerPoints) {
       addMarkerPoints();
    }
}


function centerMap(szAddress) {
    if (googleGeocoder) {
     googleGeocoder.geocode( { 'address': szAddress}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            googleMap.setCenter(results[0].geometry.location);
        } else {
          //alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }
}


function centerMapByLatLong(lngLat, lngLong) {
    googleMap.setCenter(new google.maps.LatLng(lngLat, lngLong));
}


function addMarker(szAddress, szTitle, szMarkerIcon) {
    if (googleGeocoder) {
     //alert("Geocoding Address");
     googleGeocoder.geocode( { 'address': szAddress}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (szMarkerIcon) {
                var marker = new google.maps.Marker({
                  map: googleMap, 
                  position: results[0].geometry.location,
                  title: szTitle,
                  icon: szMarkerIcon
                });
            }
            else {
                var marker = new google.maps.Marker({
                  map: googleMap, 
                  position: results[0].geometry.location,
                  title: szTitle
                });
            }
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }
}


function addMarkerByLatLong(lngLat, lngLong, szTitle, szMarkerIcon) {
    if (googleGeocoder) {
        if (szMarkerIcon) {
            var marker = new google.maps.Marker({
              map: googleMap, 
              position: new google.maps.LatLng(lngLat, lngLong),
              title: szTitle,
              icon: szMarkerIcon
            });    
        }
        else {
            var marker = new google.maps.Marker({
              map: googleMap, 
              position: new google.maps.LatLng(lngLat, lngLong),
              title: szTitle
            });    
        }
    }
}

