﻿var geocoder;
var map;
var propAddress;
var propCity;
var propCompany;

function initialize() {
    initializemap("map_canvas");
}

function initializemap(mapDivId) { 

    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(58.753, 17.009);
    var myOptions = {
        zoom: 14,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
//    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    propAddress = document.getElementById(mapDivId+'propAddress').value;
    propCity = document.getElementById(mapDivId+'propCity').value;
    propCompany = document.getElementById(mapDivId+'propCompany').value;

    geocoder.geocode({ 'address': propAddress + ', ' + propCity }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            document.getElementById(mapDivId).parentNode.style.display = "";
            map = new google.maps.Map(document.getElementById(mapDivId), myOptions);
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                title: propCompany,
                position: results[0].geometry.location
            });
        } else {
            
            document.getElementById(mapDivId).parentNode.style.display = "none";
            /*alert("Geocode was not successful for the following reason: " + status);*/
        }
    });
}

/*window.onload = initialize;*/
