﻿       var map = null;
       var shape   = null;
       var lyr = null;
       var ids = "";
        
        function ShapeHandler(e)      
        {        
          var msg;         
          if (e.eventName == "onclick")         
          {            
          if (e.leftMouseButton)               
             msg = "onclick (left mouse button)  event";            
          else if (e.rightMouseButton)               
            msg = "onclick (right mouse button)  event";            
          else if (e.leftMouseButton)               
            msg = "onclick (middle mouse button)  event";         
          }
          else         
          {            
          msg = e.eventName + " event.";         
          }        
           document.getElementById('resultDiv').innerHTML=msg;
        }
        
       function GetMap()         
             {      
             if (lyr == null)  
              {         
             map = new VEMap('myMap');  
             map.LoadMap(new VELatLong(stLat,stLon), stZoom ,'m' ,false);
             GetMapView();
              }
              
             }      
             
        function GetMapView()
         {
         
            view = map.GetMapView();
            center = map.GetCenter();
            zoom = map.GetZoomLevel();
            
            topleft = view.TopLeftLatLong;
            bottomright = view.BottomRightLatLong;
            topright = view.TopRightLatLong;
            bottomleft = view.BottomLeftLatLong;
            document.getElementById('mapVars').value = center+","+zoom;
            document.getElementById('mapDims').value = topleft+","+bottomright;
             homes(topleft.Latitude,topleft.Longitude,bottomright.Latitude,bottomright.Longitude);
         }  
        
         function homes(ullat,ullon,lrlat,lrlon)
              {
            
              stURL = staticFile;
              map.DeleteAllShapeLayers();
                       
              lyr = new VEShapeLayer();
              
            var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS,stURL,lyr);
                    try
                      {
                      map.ImportShapeLayerData(veLayerSpec,onFeedLoad,1);
                      map.AttachEvent("onclick", callColorPin);
                      }
                      catch(err)
                      {
                       alert('Your search did not return any listings.');
                      }
          
              }
              
        function onFeedLoad()
         {
        
            if (map.GetZoomLevel() > 13)
            {
            map.SetZoomLevel(13);
            }

          
          
           if (lyr != null)  
              {
             
                  var ppCnt = 0;
                  ppCnt = lyr.GetShapeCount();
                    if(ppCnt <1)
                    {
                       //             alert('ppCnt = 0?' + ppCnt);
                    }
                    else
                    {
                     //alert('ppCnt > 0' + ppCnt);
                    }
                    
                    for (var i=0;i<ppCnt;i++)
                    {
                     
                      shape = lyr.GetShapeByIndex(i);
                      desc = shape.GetDescription();
                      sid = shape.GetID();
                    }
               }
               getLot_PinArray();
         }
             
       function getLot_PinArray()
        {
        var selids="";
        var elseids="";
         
            if (lyr != null)  
              {
              var ppCnt = 0;
              ppCnt = lyr.GetShapeCount();
                
                for (var i=0;i<ppCnt;i++)
                {
                 
                    shape = lyr.GetShapeByIndex(i);
                    shape.SetCustomIcon("<img src='inc/"+shape.IconId+"'/>");
                    if(shape.GetCustomIcon()!= null)
                    {
                    selids+=" "+shape.GetTitle()+",";
                    }
                    else
                    {
                   elseids+=" "+shape.GetTitle()+",";
                    }
                }
            document.getElementById('txtSel').value = selids;
            document.getElementById('txtElse').value = elseids;
            
            }
        }
             
                
        
        function callColorPin(e)
         {
            if(e.elementID != null)
            {
                 colorPin(e.elementID);
            }
            else
            {
               return false;
            }
         }
    
        function colorPin(pinID)
        {
       //  alert('colorpin. '+pinID);
                    shape = map.GetShapeByID(pinID);
                    shape.SetCustomIcon("<img src='inc/"+shape.IconId+"'/>");
                    getLot_PinArray();
        } 
       
       