﻿    var geocoder;
    var map;  
    function initialize() {
        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(40.738, -111.812);
        var myOptions = {      
            zoom: 10,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
                }
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);  
        var divitems = document.getElementsByTagName('DIV');
        for(var i=divitems.length-1; i >= 0; i--)
        {
            if(divitems[i].innerHTML.indexOf('Address') == 0)
                codeAddress(divitems[i].innerHTML.substr(12), divitems[i-1].innerHTML);
        }
        //var addresses = new Array(2);
        //addresses[0] = '1301 E 1975 S Bountiful, UT 84010';
        //addresses[1] = '1895 W 9640 S South Jordan, UT 84095';
        //for(n=0;n<2;n++){
        //    codeAddress(addresses[n]);
        //    }
    }
    function codeAddress(val,name) {
        var address = val;//document.getElementById("address").value;
        if(val == null || val.length == 0 || val == 'x')
            address = document.getElementById("address").value;
        //alert(address)
        geocoder.geocode( { address: address}, 
            function(results, status) {
                if (status == google.maps.GeocoderStatus.OK && results.length) {
                // You should always check that a result was returned, as it is        
                // possible to return an empty results object.        
                if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {          
                    map.set_center(results[0].geometry.location); 
                    var infowindow = new google.maps.InfoWindow({    content: "<div><h1>"+name+":</h1><br/> "+address+"</div>"});         
                    var marker = new google.maps.Marker({              
                    position: results[0].geometry.location,              
                    map: map, title: name
                }); 
                google.maps.event.addListener(marker, 'click', function() {  infowindow.open(map,marker);});       
            }      
        } else {
                alert("Geocode was unsuccessful due to: " + status);      
               }
        });
    }
