﻿      var map = null;
      var pushpin = 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/default/images/pushpin.gif';
                   
      function OnLoadFunction()
      {
         map = new VEMap('myMap');
         map.LoadMap();
         map.SetZoomLevel(1);
         map.ShowDisambiguationDialog (false);
         map.AttachEvent('onclick', OnMapClickEvent);  
         map.DeleteAllPushpins();
         pushpin = new VEPushpin(1,new VELatLong(40.73,-73.91),pushpin,"New York","New York NY");
         map.AddPushpin(pushpin);
         
      } 
     function SetLocation()
      {
       map.DeleteAllPushpins();
       
       var veLatLong = new VELatLong(document.getElementById(latID).value,document.getElementById(longID).value)
       map.SetCenter(veLatLong);
       
       pushpin = new VEPushpin(1,map.GetCenter(),pushpin,document.getElementById(placeID).value,document.getElementById(placeID).value);
       map.AddPushpin(pushpin);
       map.SetZoomLevel(6);  
         
      }      
    function OnMapClickEvent(e)
    {
       map.DeleteAllPushpins();
       
       map.SetCenter(e.view.LatLong);
       document.getElementById(latID).value =e.view.LatLong.Latitude;
       document.getElementById(longID).value =e.view.LatLong.Longitude;
       
       pushpin = new VEPushpin(1,e.view.LatLong,pushpin,"My Location","My Location");
       map.AddPushpin(pushpin);
       map.SetZoomLevel(6);  
       
    }
    function mySearch()
    {
        map.FindLocation(document.getElementById(searchTermID).value,onFoundLocationResults);
        map.SetZoomLevel(6);  
    }
    
    function onFoundLocationResults(findResults)
     {
        var results="More than one location was retruned. Please select the location you were looking for:<br>";
        for (x=0; x<findResults.length; x++)
        {
           results+="<a href='javascript:captureLocation(\""+findResults[x].ID+"\");'>"+findResults[x].ID+"</a><br>";
        }
        document.getElementById('events').innerHTML=results;
        
        
     }
    function captureLocation(locID)
    {
       map.DeleteAllPushpins();
       
       map.FindLocation(locID);
       var center = map.GetCenter();
       document.getElementById(latID).value =center.Latitude;
       document.getElementById(longID).value =center.Longitude;
       document.getElementById(placeID).value =locID;
       map.SetZoomLevel(6);  
       
       
       
       pushpin = new VEPushpin(100,center,pushpin,document.getElementById(placeID).value,document.getElementById(placeID).value);
       map.AddPushpin(pushpin);
       
    }
    function onFindResults(findResults)
     {
        var results="Find Results:\n";
        for (r=0; r < findResults.length; r++)
        {
           if (findResults[r].ID!=null) //VESearchResult objects
           {
              results+=findResults[r].ID + ": " + findResults[r].LatLong+"\n";
           }
           else if (findResults[r].Name!=null) //VEFindResult objects
           {
              results += findResults[r].Name + ", ";
              results += findResults[r].Description + ": ";
              results += findResults[r].Phone + "\n";
           }
        }
        alert(results);
    }