﻿// Google Maps helper functions

var geocoder;
var map;

function mapinitialize() { 
    geocoder = new google.maps.Geocoder();
    var myOptions = {      
        zoom: 1,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map"), myOptions);
}

function codeAddress(address) {
    if (address != "null" && geocoder) {
        geocoder.geocode({ 'address': address }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                map.setZoom(16);
                var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location });
                //$("[id$='map']").css("visibility", "visible");
            }
            else {
                // this will clear the map
                mapinitialize();
            }

        });
    }
}
