         var map = null;                  
     
         function GetMap(sender,stockistId)         
         {  
            if (sender != null)                      
                sender.style.display = 'none';

            map = new VEMap('stockist-' + stockistId + '-map');                                                          
            
            IAnson.Web.StockistLocator.WebService.GetMapDetails(stockistId,GetMapCallSucceedCallBack);                                    
         }
                 
         function AddPushpin(title,description)      
         {          
            var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());          
            shape.SetTitle(title);          
            shape.SetDescription(description);                      
            map.AddShape(shape);      
         }
     
         function FindLocation(location)
         {
              try         
              {            
                  map.Find(null, location);                  
              }         
              catch(e)         
              {            
                  alert(e.message);         
              }      
         }
         
        function GetAttribute(results,name)
        {
            for(i = 0; i < results.length; i++)
            {
                if(results[i].split(':')[0] == name)
                    return results[i].split(':')[1];
            }
            return null;
        }
        
        var results;
         
        function GetMapCallSucceedCallBack(result, eventArgs)
        {
            if (result != "")
            {
                results = result.split('@');                               
                var coordinates = GetAttribute(results,'Coordinates');
                
                if (coordinates != null)
                {
                    var coords = coordinates.split('x');
                    map.LoadMap(new VELatLong(parseInt(coords[0]),parseInt(coords[1])), 12 ,'r' ,false);                    
                    AddPushpin(GetAttribute(results,'Name'), GetAttribute(results, 'Address'));                       
                }                
                else
                {                    
                    map.LoadMap();
                    map.AttachEvent("onchangeview", OnMapChange);
                    FindLocation(GetAttribute(results, 'Address'));                                           
                }                
            }
            else
            {
                map.LoadMap();
            }
        }
        
        function OnMapChange(mapEvent)
        {
            AddPushpin(GetAttribute(results,'Name'), GetAttribute(results, 'Address'));
            
            map.DetachEvent("onchangeview", OnMapChange);
        }

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
