﻿
    var pointerLat = 0;
    var pointerLong = 0;
    var pointerTitle = "";
    var pointerVisible = false;
    var pointerToDisplay = false;
    var initiatePointer = false;
    
    var newPointVisible = false;
    
    var PushPinList = new Array();
    var OLD_LatMin = 0;
    var OLD_LatMax = 0;
    var OLD_LongMin = 0;
    var OLD_LongMax = 0;      
    var OLD_ZoomLevel = 0;     
    var LatMin = 0;
    var LatMax = 0;
    var LongMin = 0;
    var LongMax = 0;      
    var ZoomLevel = 0;  
    var rmvPinLink = false;
    var pinHandl = false;  
    
    var PushPinReInit = false;
    var map;
    var doRelocate = true;
    // -------------------------------------------------------------------------------------
    // Gestion de la carte
    // -------------------------------------------------------------------------------------
     function clearMap()
     {
        map.DeleteAllPushpins();
        map.DeleteAllPolylines();
        pointerVisible = false;
        PushPinList=new Array();
     }
     
     function clearUnSeenPushPin()
     {
     
            
        for(var i=0; i< PushPinList.length; i++){
         try{
             var latitude = PushPinList[i].pin.LatLong.Latitude;
             var longitude = PushPinList[i].pin.LatLong.Longitude;
             if(latitude>LatMax || latitude<LatMin || longitude>LongMax || longitude<LongMin ) 
                    map.DeletePushpin(PushPinList[i].code);   
                    PushPinList.splite(i,1);    
          }catch(err){
              //  alert(err.message); alert(PushPinList[i].pin);
            }
        }
        
        

        pointerVisible = false;
     }    
     
      
    
    function DrawPoly()
     {
       var points = new Array(
          new VELatLong(45.01188,-111.06687),
          new VELatLong(45.01534,-104.06324),
          new VELatLong(41.01929,-104.06),
          new VELatLong(41.003,-111.05878)
          );

       poly = new VEPolygon('1',points);
       poly.SetOutlineWidth(3);
       poly.SetOutlineColor(new VEColor(0,150,100,1.0));
       poly.SetFillColor(new VEColor(0,150,100,0.5));
       
       var mypoly = new VEPolyline('1', points, new VEColor(0,150,100,0.5), 2);

       map.AddPolyline(mypoly);
       // map.AddPolygon(poly);
       map.SetMapView(points);
     }	      
     
     function endPan()
     {
     }   
     

     function GetMap()
     {
        map = new VEMap('myMap');        

        map.onLoadMap = hide3D;   
         
        try{
         map.LoadMap(new VELatLong(35.7719999, 10.5434), 1, 'r', false);
         map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
        }catch(err){
            alert(err);
        }
        
        map.AttachEvent("onclick", userHasCLicked) ;
        
        map.AttachEvent("onchangeview", viewHasChanged);

        VEPushpin.ShowDetailOnMouseOver = true;
        VEPushpin.OnMouseOverCallback = pinPointed;
        
     }  
     
   function hide3D()
   {
        if(document.getElementById('MSVE_navAction_modeCell')){
            var element = document.getElementById('MSVE_navAction_modeCell');
            element.parentNode.removeChild(element);
        }  
        if (document.all)
        {
            if(document.getElementById('MSVE_navAction_leftBackground'))
            {
                var element = document.getElementById('MSVE_navAction_leftBackground');
                element.style.height = "200px";
            }  
         }
         else
             document.getElementById('myMap').addEventListener('DOMMouseScroll',zoomMap, false);  
         
 
 }      
 
     function zoomMap(e)
     {
          e = e ? e : window.event;
          var wheelData = e.detail ? e.detail : e.wheelDelta;
          if (wheelData<0)
            map.ZoomIn();
          else map.ZoomOut();
     }
    
    function AddPointerAndCenter(Lat,Long)
    {
        if(Lat != 0 && Long != 0 && Long != "" && Lat != ""  )
        {
           var points = new VELatLong(Lat.replace(",","."),Long.replace(",","."));
           map.SetCenter(points);
           AddPointer("", Lat.replace(",","."),Long.replace(",","."));
        }
    }
    
     function AddPointer(Title, Lat, Long)
     {
        pointerLat = Lat;
        pointerLong = Long;
        pointerTitle = Title;
        pointerTitle = pointerTitle.replace("'","&#39;");
        pointerToDisplay = true;
        drawPointer();
     }   
     
     function removePointer()
     {
        if (pointerVisible)
        {
            pointerVisible = false;
            map.DeletePushpin(1000);
        }
        pointerToDisplay = false;
     }
        
     function drawPointer()
     {
        if (pointerToDisplay)
        {
            // if (pointerVisible)
            // {
            //     pointerVisible = false;
            //     map.DeletePushpin(1000);
            // }
            // else
            try {map.DeletePushpin(1000);}
            catch (err) {}
            var pin = new VEPushpin(1000, new VELatLong(pointerLat , pointerLong), "images/pointer2.gif",
                      pointerTitle,"");
            map.AddPushpin(pin);
            pointerVisible = true;
            
        }
     }  
    
     function AddAPin(Code, Img, Type, Title, Lat, Long)
     {
            var pinTitle = Title;
            pinTitle = pinTitle.replace("'","&#39;");
            pinID = Code + "_" + Type;
            var PinImg = null;
            var extraTxt = "";
            if (Img.length > 1)
                PinImg = Img; 
            else           
                PinImg = "images/prest/map/" + Type + ".png";
            var internalLink = "";
            if (createMode)
            {
                if (Type == 16)
                    internalLink = "+ <a href='javascript:countryHasBeenSelected(\""+ pinID +"\","+ Lat +","+ Long +")'>choisir ce pays pour la nouvelle fiche</a>"+extraTxt;
                else
                {
                if (Type == 17)
                    internalLink = "+ <a href='javascript:cityHasBeenSelected(\""+ pinID +"\","+ Lat +","+ Long +")'>choisir cette ville pour la nouvelle fiche</a>"+extraTxt;
                else
                    internalLink = "+ <a href='javascript:lavHasBeenSelected(\""+ pinID +"\","+ Lat +","+ Long +")'>choisir ce lieu pour la nouvelle fiche</a>"+extraTxt;
                }
            }
            else
            {
                internalLink = "+ <a href='javascript:rechargeInfoDecouverte("+Type+",\""+pinID+"\")'>Accès à la fiche de ce lieu</a>"+extraTxt;
            }
            try {  
                if (rmvPinLink) internalLink = "";                         
                return AddClickablePin(pinID,new VELatLong(Lat , Long), PinImg, pinTitle, internalLink);
                }
            catch (ex)
            {
            }
     } 
     
     function AddAPinPV(Code, Img, Type, Title, Lat, Long,Pays,Ville)
     {
            var pinTitle = Title;
            pinTitle = pinTitle.replace("'","&#39;");
            pinID = Code + "_" + Type;
            var PinImg = null;
            var extraTxt = "";
            if (Img.length > 1)
                PinImg = Img; 
            else           
                PinImg = "images/prest/map/" + Type + ".png";
            var internalLink = "";
            internalLink = "+ <a href='javascript:rechargeInfoDecouverte("+Type+",\""+pinID+"\")'>Plus d'info</a>";
            internalLink += "<br/>+ <a href='javascript:insertElementInSelection("+Type+",\""+Lat+"\",\""+Long+"\",\""+Code+"\",\""+Title+"\",\""+Pays+"\",\""+Ville+"\")'>Ajouter au voyage</a>"+extraTxt;
            try {  
                if (rmvPinLink) internalLink = "";                         
                return AddClickablePin(pinID,new VELatLong(Lat , Long), PinImg, pinTitle, internalLink);
                }
            catch (ex)
            {
            }
     } 
     
    function AddClickablePin(pinID,location, icon_url, title, details, iconStyle)
    {
	    var pin = new VEPushpin(pinID, location, icon_url, title, details, iconStyle);
	    map.AddPushpin(pin);	
	    

	        
	    var element = document.getElementById(pinID);
	    element.onclick = EventHandlerOnClick;
	    return pin;
    }
    
    function EventHandlerOnClick(e)
    {
	    if (e!=null)
	    {
	        if (pinHandl) handlePinclick(e.currentTarget.id + "_" + map.GUID);
	        else document.getElementById(e.currentTarget.id + "_" + map.GUID).onmouseover();
	    } else
	    {
	        if (pinHandl) handlePinclick(window.event.srcElement.id);
	        else document.getElementById(window.event.srcElement.id).onmouseover();
	    }
    }
    
    function pinIsInList(pCode){
        for(var i in PushPinList){
            if(PushPinList[i].code==pCode) return true;        
        }
        return false;
    }
     

    //--------------- Gestion de VE ----------------------------
     var map = null;
     var pinID = 1;
     var lastPointedPin = null;
     var pinX = null;
     var pinY = null;
     var showClick = false;
     var layerid = 1;
     var poly = null;
      
    function onFeedLoad(feed)
    {
        //DoAlert('RSS or Collection loaded. There are '+feed.length+' items in this list.');
    }
    
    function AddMyLayer(type,source,icon)
    {
        var veLayerSpec = new VELayerSpecification();
        veLayerSpec.Type = type;
        veLayerSpec.ID = layerid;
        veLayerSpec.LayerSource = source;
        veLayerSpec.Method = 'get';
        veLayerSpec.FnCallback = onFeedLoad;
        veLayerSpec.IconUrl = icon;
        map.AddLayer(veLayerSpec);
    	
        layerid++;
    }  
                                    
     function userHasCLicked(e)
     {    
        if (showClick) 
        { 
            var loc = map.PixelToLatLong(new VEPixel(e.mapX, e.mapY));
            manageUserClick(loc.Latitude,loc.Longitude,e.zoomLevel);    
		}
     }
     
     function pinPointed(x, y, title, details)
     {
        lastPointedPin = unescape(title);
        pinX = x;
        pinY = y;
     }
     
     function FindLoc()
     {            
     	map.FindLocation(document.getElementById('txtWhere').value);
     }
     
     // ------------------------ Affichage des pins sur la carte -----------
function ListDetLAVList(Type,Query)
{
    // Type : 1 = Lieux à visiter 
    //            Query = nom de la ville typiquement
   var searchParameters = new Object();
    searchParameters.LavType = Type;
    searchParameters.queryString = Query;

    MWLavService.getLavList(searchParameters, LAVDet2OnRequestComplete);
}

function ListDetLAVList_s()
{
    MWLavService.getDetLAVList("", LAVDet2OnRequestComplete);
}

function ListDetLAVList_i(Latitude, Longitude, ZoomLevel, Origin)
{
    if (!itineraryOnly)
    {
        var searchParDec = new Object();
        searchParDec.Latitude = Latitude;
        searchParDec.Longitude = Longitude;
        searchParDec.ZoomLevel = ZoomLevel;
        searchParDec.Origin = Origin;
        searchParDec.Type = mapSelectId;

        if (Latitude != null && Longitude != null && ZoomLevel!= 1)
            MWLavService.getDecLAVList(searchParDec, LAVDet3OnRequestComplete);
    }
}

 function LAVDet3OnRequestComplete(result)
 {  
    OLD_LatMax= LatMax;
    OLD_LatMin = LatMin;
    OLD_LongMin = LongMin;
    OLD_LongMax = LongMax; 
    OLD_ZoomLevel = ZoomLevel; 

    LatMax = map.PixelToLatLong(new VEPixel(1,1)).Latitude;
    LongMin = map.PixelToLatLong(new VEPixel(1,1)).Longitude;
    LatMin = map.PixelToLatLong(new VEPixel(myMap.offsetWidth,myMap.offsetHeight)).Latitude;
    LongMax = map.PixelToLatLong(new VEPixel(myMap.offsetWidth,myMap.offsetHeight)).Longitude; 
    ZoomLevel = map.GetZoomLevel();     

    if(OLD_ZoomLevel == map.GetZoomLevel() && !PushPinReInit) clearUnSeenPushPin();
    else clearMap();   
   // clearMap();
    
    pointerVisible = false;
    LAVDet2OnRequestComplete(result);
    
    PushPinReInit = false;
 }
 
 
 var setPinsFromResultIntervalMethod = function(){};
 var setPinsFromResultIntervalID;
 
 function setPinsFromResult(result){
    window.clearInterval(setPinsFromResultIntervalID);
    
    var counter = 0;
    if(result) counter = result.length;
    
    

    setPinsFromResultIntervalMethod = function(){
       var myMap = document.getElementById("myMap");    
    

        var cpt=0;
        /*
        var _LatMin = LatMin;
        var _LatMax = LatMax;
        var _LongMin = LongMin;
        var _LatMin = LongMax;        
        */
                
       while (cpt <200000 && counter > 0 )
       {

               counter --;
                var item = result[counter];
               // if(counter==1) { alert(ZoomLevel); alert(OLD_ZoomLevel);   alert(ZoomLevel!=OLD_ZoomLevel );}
               if(counter>0){
                    if((item.Lattitude>=LatMin && item.Lattitude<=LatMax && item.Longitude>=LongMin && item.Longitude<=LongMax)  && (PushPinReInit || ZoomLevel!=OLD_ZoomLevel || item.Lattitude<OLD_LatMin || item.Lattitude>OLD_LatMax || item.Longitude<OLD_LongMin || item.Longitude>OLD_LongMax)){
                        if(item.Lattitude != 0 && item.Longitude != 0)
                        {
                           var pin = AddAPin(item.Code, "", item.Type,  item.Name,    item.Lattitude, item.Longitude);
                           
                            PushPinList.push({pin:pin,code:item.Code});
                           cpt++;
                        }
                    }
               }
       }
       if(counter == 0 ){
                window.clearInterval(setPinsFromResultIntervalID);

       }
      
    };
    
    intervalID = window.setInterval("setPinsFromResultIntervalMethod();", 200);
 }
 

 function LAVDet2OnRequestComplete(result)
 {         
   //setPinsFromResult(result);
  
    var cpt =0;
   for (var i=0; i < result.length; i++)
   {   // if(!pinIsInList(result[i].Code)){
   
        var item = result[i]; 
        
            if ((item.Lattitude>=LatMin && item.Lattitude<=LatMax && item.Longitude>=LongMin && item.Longitude<=LongMax)  
                && 
                (PushPinReInit || ZoomLevel!=OLD_ZoomLevel || item.Lattitude<OLD_LatMin || item.Lattitude>OLD_LatMax || item.Longitude<OLD_LongMin || item.Longitude>OLD_LongMax))
            {
                if(item.Lattitude != 0 && item.Longitude != 0)
                {
                   var pin = AddAPinPV(item.Code, "", item.Type,  item.Name,    item.Lattitude, item.Longitude,  item.Pays, item.Ville);
                   
                    PushPinList.push({pin:pin,code:item.Code});
                   cpt++;
                }
            }
        
   }
  

   
   if (initiatePointer)
   {
       for (var i=0; i < result.length; i++)
       {
            if (result[i].Type == ELETYPE && result[i].Code == ELECODE)
            {
                pointerLat = result[i].Lattitude;
                pointerLong = result[i].Longitude;
                pointerTitle = result[i].Name;
                pointerTitle = pointerTitle.replace("'","&#39;");
                pointerToDisplay = true;
           }
       }
       initiatePointer = false;
   }

   
   drawPointer();
 }

//---------------- Affichage des itinéraires sur la carte -----------------------------
function showSelection()
{
    LoadItinerary(19, "");
}

function showItinerary(Code)
{
    LoadItinerary(13, Code);
    rechargeDetail(2, Code);
}

var currentType=0;

function LoadItinerary(Type, Query)
{
    clearMap();
    itineraryOnly = true;
    
    // Query = code du parcours
   var searchParameters = new Object();
    searchParameters.LavType = Type;
    searchParameters.queryString = Query;
    currentType = Type;
    
    MWLavService.getLavList(searchParameters, ITILoadOnRequestComplete);
}

function LoadItinerary_s()
{
    MWLavService.getDetLAVList("", ITILoadOnRequestComplete);
}

 function ITILoadOnRequestComplete(result)
 { 
       if (result.length > 0)
       {
           var multipoints = false;
            
           var points = new Array();
           for (var i=0; i < result.length; i++)
           {
               if(result[i].Lattitude != 0 && result[i].Longitude != 0)
               {
                   points.push(new VELatLong(result[i].Lattitude,result[i].Longitude));
                   if (i>0)
                    if (result[i].Lattitude != result[i-1].Lattitude || result[i].Longitude != result[i-1].Longitude)
                        multipoints = true;
               }
           }
           poly = new VEPolygon('1',points);
           poly.SetOutlineWidth(3);
           poly.SetOutlineColor(new VEColor(0,150,100,1.0));
           poly.SetFillColor(new VEColor(0,150,100,0.5));       
           var mypoly = new VEPolyline('1', points, new VEColor(0,150,100,0.5), 2);
           
           if (currentType != 10) map.AddPolyline(mypoly);                    

           if (multipoints)
               map.SetMapView(points);
           else
               map.SetCenterAndZoom(new VELatLong(result[0].Lattitude,result[0].Longitude), 5);
           
           
            for (var i=0; i < result.length; i++)
            {
                if(result[i].Lattitude != 0 && result[i].Longitude != 0)
                {                
                    AddAPin(result[i].Code, "", result[i].Type,  result[i].Name,    result[i].Lattitude, result[i].Longitude);
                }
            }
        }
 }
 
  // --------------------------------------------------------------
  // Gestion du zoom et de la localisation courante sur la carte
  // --------------------------------------------------------------
    function SetCurrentViewZoneComplete(theValue) {
        if (typeof(MWSearchService) == 'function') {
            MWSearchService.getCurrentGeoViewZone(theValue, onSetCurrentViewZoneComplete);
        }else{
            setTimeout("SetCurrentViewZoneComplete('" + theValue + "')", 500);
        }
    }
  
    function onSetCurrentViewZoneComplete(result)
    {
       // alert(result.Lattitude_1 + "-" + result.Longitude_1 + "-" + result.Lattitude_2 + "-" + result.Longitude_2);
        PushPinReInit = true;
        if(result.Lattitude_1 != 0 && result.Longitude_1  != 0 && result.Lattitude_2 !=0 && result.Longitude_2 !=0 && result.Lattitude_2 != result.Lattitude_1 && result.Longitude_2 != result.Longitude_1)
        {
           if (doRelocate) 
           {
           var points = new Array(new VELatLong(result.Lattitude_1,result.Longitude_1),new VELatLong(result.Lattitude_2,result.Longitude_2));
           map.SetMapView(points);
           }
           else viewHasChanged();
        }
        else
        {
            if(result.Lattitude_1 != 0 && result.Longitude_1  != 0)
            {
               if (doRelocate) 
               {
                   map.SetCenterAndZoom(new VELatLong(result.Lattitude_1,result.Longitude_1), result.zoomLevelMin);
                   if (map.GetCenter().Latitude-result.Lattitude_1< 0.0001 &&  map.GetCenter().Longitude-result.Longitude_1< 0.0001 && map.GetZoomLevel()==result.zoomLevelMin)
                   {
                      viewHasChanged();
                      // result.Lattitude_1 -= 0.001;
                   }
               }
               else viewHasChanged();
            }
        }
        doRelocate = true;
    }


    MW.Map_Class = function(){
        var me = this;   
        //CONSTANTES
        this.DEFAULT_MODE = 0;
        this.CITY_MODE = 1;

        
        this._lastSearchedCity;
            
        this.DisplayMode = this.DEFAULT_MODE;   
    
        this.displayPopup = false;
    
        //ACCESSORS
        this.currentMap = function(){
            return window.map;
        };
        
        this.itemList;
        
        this.GetMap = function(pParams)
        {
            map = new VEMap('myMap');

            try{
                map.LoadMap(new VELatLong(35.7719999, 10.5434), 1, 'r', false);
                map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);                
            }catch(err){
                alert(err);
            }
			//map.AttachEvent("onclick", userHasCLicked);
            if(pParams.userHasClicked) map.AttachEvent("onclick", pParams.userHasClicked);
            else map.AttachEvent("onclick", userHasCLicked);

            VEPushpin.ShowDetailOnMouseOver = true;
            VEPushpin.OnMouseOverCallback = pinPointed;

        };
        
        this.userHasCLicked = function(e)
        {    
            if (showClick) 
            { 
                manageUserClick(e.view.LatLong.Latitude,e.view.LatLong.Longitude,e.view.zoomLevel);    
            }
        };
        
        //LOADING
        this.loadProductList = function(pList){
            if(pList.length && pList.length>0){                
                jQuery("#myMapWaiter").show();  
                jQuery("#myMapWaiter").css('width',jQuery("#myMap")[0].offsetWidth);               
                MWLavService.getLAVListFromProductCodeList(pList,this.onSelectItemListComplete,null,null,null,{caller:this});
            }
        };   
        
        this.loadIATAList = function(pList){
             if(pList.length && pList.length>0){                
                jQuery("#myMapWaiter").show();  
                jQuery("#myMapWaiter").css('width',jQuery("#myMap")[0].offsetWidth);               
                MWLavService.getLAVListFromIATAList(pList,this.onSelectItemListComplete,null,null,null,{caller:this});
            } 
        }

        
        this.loadTravelItems = function(){                 
			try{
				this.currentMap().DetachEvent("onchangeview",ChangeViewHandler);
				this.currentMap().AttachEvent("onchangeview",ChangeViewHandler);				
	             MWLavService.getLAVListFromTravel(this.onLoadProductListComplete,null,null,null,{caller:this});
				jQuery("#myMapWaiter").show();
	            jQuery("#myMapWaiter").css('width',jQuery("#myMap")[0].offsetWidth);  
			 }catch(err){}
        };    
        
        
        //DISPLAYING
         this.localiseProductList = function(pList){
            if(pList.length && pList.length>0){                
                jQuery("#myMapWaiter").show();  
                jQuery("#myMapWaiter").css('width',jQuery("#myMap")[0].offsetWidth);               
                MWLavService.getLAVListFromProductCodeList(pList,this.onSelectItemListComplete,null,null,null,{caller:this, noRefresh:true});
            }
        }; 
               
        
        
        this.switchScenarioDisplay = function(){ 
 			MW_FLASH.map.flashMap.switchScenarioDisplay();        
        }   
        
        
        this.getCountryByName = function(pCountryName){        
				
            MWLavService.getCountriesListByNames(pCountryName,this.onSelectItemListComplete,null,null,null,{caller:this});
        };            
        
        this.getCityByName = function(pCountryName, pCityName, pReload){  
			
            if(pCityName.length>2 && (pCityName != this._lastSearchedCity || pReload) ) {
			    if(pCountryName=="0")pCountryName=null;
                MWLavService.getCityByName(pCountryName, pCityName, this.onSelectItemListComplete, null, null, null, {caller:this});
			}
            this._lastSearchedCity = pCityName;
        }
        
        this.getCitiesByView = function(){
		    var mapWidth = map.GetWidth();
			var mapHeight = map.GetHeight();
           LatMax = map.PixelToLatLong(new VEPixel(0,0)).Latitude;
           LatMin = map.PixelToLatLong(new VEPixel(mapWidth, mapHeight)).Latitude;
           LongMin = map.PixelToLatLong(new VEPixel(0,0)).Longitude;
           LongMax = map.PixelToLatLong(new VEPixel(mapWidth, mapHeight)).Longitude; 
           MWLavService.getHasPkCityList(LatMax, LatMin, LongMax, LongMin, OLD_LatMax, OLD_LatMin, OLD_LongMax, OLD_LongMin, this.onItemListComplete, null, null, null, {caller:this, clear:(OLD_LatMax+OLD_LatMin+OLD_LongMin+OLD_LongMax)==0});
           OLD_LatMax= LatMax;
            OLD_LatMin = LatMin;
            OLD_LongMin = LongMin;
            OLD_LongMax = LongMax; 
        }
		
		this.getCountriesByView = function(){
		   var mapWidth = map.GetWidth();
		   var mapHeight = map.GetHeight();
           LatMax = map.PixelToLatLong(new VEPixel(0,0)).Latitude;
           LatMin = map.PixelToLatLong(new VEPixel(mapWidth, mapHeight)).Latitude;
           LongMin = map.PixelToLatLong(new VEPixel(0,0)).Longitude;
           LongMax = map.PixelToLatLong(new VEPixel(mapWidth, mapHeight)).Longitude; 
           MWLavService.getCountryList(LatMax, LatMin, LongMax, LongMin, OLD_LatMax, OLD_LatMin, OLD_LongMax, OLD_LongMin, this.onItemListComplete, null, null, null, {caller:this, clear:(OLD_LatMax+OLD_LatMin+OLD_LongMin+OLD_LongMax)==0});
           OLD_LatMax= LatMax;
           OLD_LatMin = LatMin;
           OLD_LongMin = LongMin;
           OLD_LongMax = LongMax; 
        }
        
		this.getLavListGeneric = function(pUniversalCode, pCityCode, pOwnerID, pCategory, pOnResultAction){
           MWLavService.getLavListGeneric(pUniversalCode, pCityCode, pOwnerID, pCategory, this.onItemListBoundComplete, null, null, null, {caller:this, clear:(OLD_LatMax+OLD_LatMin+OLD_LongMin+OLD_LongMax)==0, onResultAction:pOnResultAction});
        }        
        
        this.onItemListComplete= function(result, info, context){
			if(context.clear) MW_FLASH.map.flashMap.clearItems();	
            MW_FLASH.map.flashMap.setItems(result);   

        }        
        
        this.onItemListBoundComplete= function(result, info, context){
			MW_FLASH.map.flashMap.clearItems();	

            MW_FLASH.map.flashMap.setItems(result);  
            if(context.onResultAction){
                if(result.length == 0) context.onResultAction(false);
                else context.onResultAction(true);
            }
            context.caller.onLoadProductListComplete(result, info, context);
            viewHasChanged_flash();
        }     
        
        this.onSelectItemListComplete = function(result, info, context){
            if(!context.noRefresh && MW_FLASH.map && MW_FLASH.map.flashMap && MW_FLASH.map.flashMap.addSelectedItems){
                MW_FLASH.map.flashMap.addSelectedItems(result);
            }
            context.caller.onLoadProductListComplete(result, info, context);
            viewHasChanged_flash();
        }        
        
        this.onLoadProductListComplete = function(result, info, context){
            jQuery("#myMapWaiter").hide();
            context.caller.itemList = result;
            if(!MW_FLASH.map.flashMap){
                clearMap();
                for (var i=0; i < result.length; i++)
                {                 
                    var item = result[i];                 
                        if(item.Lattitude != 0 && item.Longitude != 0)
                        {
                           var pin = AddAPin(item.Code, "", item.Type,  item.Name,    item.Lattitude, item.Longitude);
                           
                            PushPinList.push({pin:pin,code:item.Code});   
                            
                               
                        }   
                }
            }

            context.caller.setViewFromLAVList(result, info, context);
        };       
        
        this.positionOnItem = function(itemCode){
            
        };      
        
        this.setViewFromLAVList = function(result, info, context){
           if (result.length > 0)
           {
                if (result.length == 1)var multipoints = false;
                
               var points = new Array();
               for (var i=result.length-1; i >=0 ; i--) 
               {
                   if(result[i].Lattitude != 0 && result[i].Longitude != 0)
                   {
                       points.push(new VELatLong(result[i].Lattitude,result[i].Longitude));
                   }
               }


               
			   this.currentMap().DetachEvent("onchangeview",ChangeViewHandler);	
			   this.currentMap().AttachEvent("onchangeview",ChangeViewHandler);	

               map.SetMapView(points);
               if(MW.Map.onItemGeolocalisation) MW.Map.onItemGeolocalisation(650,300);    
             /*  if( points.length == 1 ){
                   if(!result[0].ZoomMin) result[0].ZoomMin = 13;
                   map.SetCenterAndZoom(new VELatLong(result[0].Lattitude,result[0].Longitude), result[0].ZoomMin);
                   MW.Map.displayPopup = true;
                   MW.Map.onItemGeolocalisation(650,300);    
               }    */ 
            }
        };       
 
        
    }
    
    MW.Map = new MW.Map_Class();    
    
    (function()
{
    var mouseEvt;
    if (typeof document.createEvent !== 'undefined')
    {
        mouseEvt = document.createEvent('MouseEvents');
    }
    if (mouseEvt && mouseEvt.__proto__ && mouseEvt.__proto__.__defineGetter__)
    {
        mouseEvt.__proto__.__defineGetter__('pageX', function()
        {
            return this.clientX + window.pageXOffset;
        });
        mouseEvt.__proto__.__defineGetter__('pageY', function()
        {
            return this.clientY + window.pageYOffset;
        });
    }
})();



