﻿var map = null;
var pinPoint = null;
var pinPixel = null;
var searchTermID = '_ctl0_contentMain_q';
var latID = '_ctl0_contentSidebar_latitude';
var longID = '_ctl0_contentSidebar_longitude';
var placeID = '_ctl0_contentSidebar_place';
var pushpin = 'http://images.khapre.org/portal/service/themes/red/images/pushpin.gif';
var geocoder;
var marker;

function GetMap() {
    var latlng = new google.maps.LatLng(40.73, -73.91);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("myMap"),
        myOptions);
    geocoder = new google.maps.Geocoder();
    
}
function processResults(results, status) {
       var myPlace;
       if (status == google.maps.GeocoderStatus.OK) {
           if(marker!=null) marker.setMap(null);
           map.setCenter(results[0].geometry.location);
           myPlace = results[0].geometry.location;
           document.getElementById(latID).value = results[0].geometry.location.lat();
           document.getElementById(longID).value = results[0].geometry.location.lng();
           document.getElementById(placeID).value = results[0].address_components[0].long_name;
           marker = new google.maps.Marker({ map: map, position: results[0].geometry.location });  
        }
       else {
            alert("Geocode was not successful for the following reason: " + status);
        }
}
function mySearch() {
    geocoder.geocode({ 'address':  document.getElementById(searchTermID).value }, processResults);
}


