
    function addPostCode(zip,name) 
    {
      geocoder.geocode( { 'address': zip}, function(results, status) 
      {
      if (status == google.maps.GeocoderStatus.OK)
      {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location,
        name: zip,
        icon: 'images/googlemap_icon.png',
        shadow: 'images/googlemap_shadow.png'
        });
        markers.push(marker);
      

        if(typeof(name) != 'undefined')
        {
          // Create the infowindow with two DIV placeholders
          // One for a text string, the other for the StreetView panorama.
          var content = document.createElement("DIV");
          var title = document.createElement("DIV");
          title.innerHTML = name;
          content.appendChild(title);
    /*
    // enable this for streetview
    
          var streetview = document.createElement("DIV");
          streetview.style.width = "200px";
          streetview.style.height = "200px";
          content.appendChild(streetview);
    */
          var infowindow = new google.maps.InfoWindow({
            content: content
          });

          // Open the infowindow on marker click
          google.maps.event.addListener(marker, "click", function() {
            infowindow.open(map, marker);
          });
        
          // Handle the DOM ready event to create the StreetView panorama
          // as it can only be created once the DIV inside the infowindow is loaded in the DOM.
          google.maps.event.addListenerOnce(infowindow, "domready", function() {
            var panorama = new google.maps.StreetViewPanorama(streetview, {
                navigationControl: false,
                enableCloseButton: false,
                addressControl: false,
                linksControl: false,
                visible: true,
                position: marker.getPosition()
            });
          });
        }

      }
      else
      {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
        
        
        

/*

    // Zoom and center the map to fit the markers
    // This logic could be conbined with the marker creation.
    // Just keeping it separate for code clarity.
    var bounds = new google.maps.LatLngBounds();
    for (index in markers) 
    {
      var data = markers[index];
      bounds.extend(new google.maps.LatLng(data.lat, data.lng));
    }
    map.fitBounds(bounds);
        
        
        */
        
        
        
        
        
        
        
    }

    function checkZip(zip)
    {
        var distance = Number.MAX_VALUE;
        var index = 0;
        geocoder.geocode( { 'address': zip}, function(results, status)
        {
            if (status == google.maps.GeocoderStatus.OK)
            {
                for(ix=0; ix< markers.length; ix++)
                {
                    var tmp = getDistance(results[0].geometry.location, markers[ix].position);
                    if (tmp < distance)
                    {
                        distance = tmp;
                        index = ix;
                    }
                }
                alert('nearest zipcode is :' + markers[index].name);
            }
        });
    }

    function getDistance(latlng1, latlng2)
    {
        var R = 6371; // Radius of the earth in km
        var dLat = (latlng2.lat()-latlng1.lat()) * Math.PI / 180;  // Javascript functions in radians
        var dLon = (latlng2.lng()-latlng1.lng()) * Math.PI / 180;
        var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
            Math.cos(latlng1.lat()  * Math.PI / 180) * Math.cos(latlng2.lat()  * Math.PI / 180) *
            Math.sin(dLon/2) * Math.sin(dLon/2);
        var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
        var d = R * c; // Distance in km
        d = d * 0.621371192;
        return d;
    }
