﻿// "Includes"
//   UtilityJScript.js
//       getCookie, setCookie
//   Constants.js

// ***************** GLOBAL VARIABLES *************** 
  // The map and map data service
    var VE_map = null;         // VE Map control
    var VE_dataLayer = null;   // Shape layer containing event pins/icons
   
  // Mouse and map Event state 
    var VE_blockNextMouseMove = false; // handle the "any click" sends a mouse move problem.
    var VE_panPending = false;         // handle the "any press" starts a pan problem.
    var VE_panning = false;            // is the map panning?
    var bIsIEBrowser = true;
    
  //  var VE_zooming = false;            // is the map zooming?   
    
  // double click detection
    var VE_lastClickTime = 0;
    var VE_lastClickX = -10;
    var VE_lastClickY = -10;
    
  // Search/Locator icon
    var VE_locationLayer = null;       // shape layer containing the search icon
    var VE_locatorPin = null;          // pin/icon of latest hot spot
  
  // dynamic construction of map div  http://msdn2.microsoft.com/en-us/library/cc189089(VS.95).aspx
  // Silverlight Object tag reference
    var VE_SLHtml = "<object id=\"idVEMapOverlay\"" +
                         " data=\"data:application/x-silverlight-2,\"" +
                         " type=\"application/x-silverlight-2\"" + 
                         " width=\"100%\"" +
                         " height=\"100%\">" +
                         "<param name=\"enableRedrawRegions\" value=\"false\" />" +
                         "<param name=\"enableFramerateCounter\" value=\"false\" />" +
                         "<param name=\"source\" value=\"ClientBin/SilverlightMapOverlay.xap\"/>" +
                         "<param name=\"maxFramerate\" value=\"30\" />" +
                         "<param name=\"onerror\" value=\"onSilverlightError\" />" +
                         "<param name=\"background\" value=\"Transparent\" />" +
                         "<param name=\"windowless\" value=\"true\" />" +
                         "<a href=\"http://go.microsoft.com/fwlink/?LinkID=114576&amp;v=2.0\"" +
                         " style=\"text-decoration: none;\">" +
                         "<img src=\"http://go.microsoft.com/fwlink/?LinkId=108181\" alt=\"Get Microsoft Silverlight\" style=\"border-style: none\" /></a></object>";

  // track the keydown (Mac fix)
    var VE_keyDown = "";

//--------------------------------------------------------------------//
// Some event over-rides to prevent browser/event issues              //
//  1) SL not getting mouse moves -- set to handled at the doc level  //
//        to that the active X control receives it instead            //
//--------------------------------------------------------------------//
  var IE = document.all ? true : false;	
  if (!IE) 
    {
    window.captureEvents(Event.MOUSEMOVE);
    window.captureEvents(Event.KEYDOWN);
    window.captureEvents(Event.KEYUP);
    bIsIEBrowser = false;	
    }
    
// try to grab key at doc level    
document.onkeydown = function keydownDoc(e)
  {
	if (!IE){ VE_keyDown = e.which; }
	if (IE) { VE_keyDown = event.keyCode; }
  return false;
  }    
document.onkeyup = function keyupDoc()
  {
  VE_keyDown = "";
  return false;
  }    
document.onmousemove = function mouseMoveSilverlight(e)
  {
  // IE vs. "Other" and mouse position
    return true; // let SL have it all the time -- since it's running in all divs
  /*  
    var x;
    var y;
    if (IE) 
      {
      x = event.clientX;
  	  y = event.clientY;
      } 
    else 
      {
      x = e.pageX;
      y = e.pageY;
      }
    
  // only need to know that it's in the map div
    var mapDiv = document.getElementById('div_VEMap');
    if(mapDiv == null) return;
    
  // get positions (px stripped)  
    var left = parseInt(mapDiv.style.left, 10);
    var top = parseInt(mapDiv.style.top, 10);
    var right = left + parseInt(mapDiv.style.width, 10);
    var bottom = top + parseInt(mapDiv.style.height, 10);
  
  // always let silverlight have it if it's in the map div
    if((x >= left) && (x <= right) &&
       (y >= top) && (y <= bottom))
      return true; 
  */   
  }
//--------------------------------------------------------------------------//
// Error loading the silverlight plugin -- display different content        //
//--------------------------------------------------------------------------//
function slLoadError(sender, args)
  {
  alert(args._error.errorType);
  alert(args._error.errorCode);
  alert(args._error.errorMessage);
  }
  
  
//--------------------------------------------------------------------------//
// pageLoad() -- When the main page has loaded, this method is called.      //
//               Use it to load the map and do any other initializing that  //
//               is required                                                //
//--------------------------------------------------------------------------//
function pageLoad() 
  {
  // now check for SL installation
    var version = "2.0.30923.0"; 
    var isInstalled = Silverlight.isInstalled(version);
    if(isInstalled == false)
      {
        window.location.href = "installSl.html";
        return;
      }
  // otherwise, wait for the plugin to be loaded and clear there
  }
//--------------------------------------------------------------------------//
// Instead of keying off of the page load, instead key off of the title bar //
// instance of silverlight loading correctly.  Then chain that into the map //
// overlay instance loading correctly                                       //
//--------------------------------------------------------------------------//
function slLoaded()
  {
  // turn off the splash screen
    var divIdSplash = document.getElementById('pageLoader'); 
    if(divIdSplash != null)
      divIdSplash.style.display = "none"; 
  // Fill the map div with the VE map control
    VE_GetMap();       
  // Insert the silverlight overlay INSIDE the map div  
    VE_InsertOverlay();
  }
  
//--------------------------------------------------------------------------//
// VE_GetMap() -- Initialize the VE map widget here and initialize settings,//
//             settings are loaded from cookies if they exist               //
//--------------------------------------------------------------------------//
function VE_GetMap()
  {
  // If the map hasn't been defined...get it
    if(VE_map == null)
      {
      // pull the cookied values if they exist
        var originLat = getCookie(const_cookieName_originLat);
        var originLon = getCookie(const_cookieName_originLon);
        var originZoom = getCookie(const_cookieName_originZoom);
      // settings  
        if(originLat != "" && originLon != "" && originZoom != "")
          {
          origin = new VELatLong(parseFloat(originLat),parseFloat(originLon));	
          zoom = parseInt(originZoom);	
          }
        else
          {
          origin = new VELatLong(const_VEMapOriginLat, const_VEMapOriginLon);
          zoom = const_VEMapZoom;
          }
      // create it    
        VE_map = new VEMap('div_VEMap');
        VE_map.SetClientToken(veClientToken); // veClientToken is setup during server side Page_load
        VE_map.LoadMap(origin, zoom);
        VE_map.SetMapStyle(VEMapStyle.Hybrid);
        VE_map.SetMouseWheelZoomToCenter(false);  // zoom to cursor
     
     // set up view options   
       document.getElementById("MSVE_navAction_FlatlandMapMode").style.display = "none"; 
       document.getElementById("MSVE_navAction_View3DMapMode").style.display = "none"; 
       document.getElementById("MSVE_navAction_ObliqueMapView").style.display = "none"; 
     
      // disable the native bubbles
      //map.AttachEvent("onmouseover", function(e){return true;});
        
      // add event capture hooks 
        // mouse
          // OFF -- not captured by silverlight so ignore
          //         VE_map.AttachEvent("onmouseover",   JSVE_MouseOverride);  // FireFox sending this event to eventballoon when light box comes up -- not trapped so just block it
          //         VE_map.AttachEvent("onmouseout",    JSVE_MouseOverride);  // FireFox sending this event to eventballoon when light box comes up -- not trapped so just block it
          VE_map.AttachEvent("ondoubleclick", JSVE_MouseOverride);  // catch it in firefox to disable it in special circumstances
          //         VE_map.AttachEvent("onmousewheel",  JSVE_MouseOverride); 
          VE_map.AttachEvent("onmousemove",   JSVE_MouseOverride);
          VE_map.AttachEvent("onmouseup",     JSVE_MouseOverride);
          VE_map.AttachEvent("onmousedown",   JSVE_MouseOverride); 
          VE_map.AttachEvent("onclick",       JSVE_MouseOverride);
        // map
          //         VE_map.AttachEvent("onstartzoom",  JSVE_MouseOverride);
          VE_map.AttachEvent("onendzoom",    JSVE_MouseOverride);
          VE_map.AttachEvent("onstartpan",   JSVE_MouseOverride);
          VE_map.AttachEvent("onendpan",     JSVE_MouseOverride); 
          //         VE_map.AttachEvent("onendcontinuouspan",     JSVE_MouseOverride); 
          VE_map.AttachEvent("onviewchange", JSVE_MouseOverride); 
        // keyboard
          VE_map.AttachEvent("onkeydown", VE_CatchKeyDown);
          VE_map.AttachEvent("onkeyup",   VE_CatchKeyUp);
        
        // With fluid layout, override window onresize for cross-browser compatibility
          window.onresize = VE_MapDivResize;
    }
  // if the map is still NULL then it's an error    
    if(VE_map == null)
      util_Error("Could not create the Virtual Earth Map");
    else // fire up the lat49 jscript
      Lat49_InitAds();
  } 

//--------------------------------------------------------------------------------//
// VE_InsertOverlay() -- place the silverlight overlay div INSIDE the map div so  //
//                       that silverlight can render over the map.                //  
//--------------------------------------------------------------------------------//
function VE_InsertOverlay()
  {
  // access the two divs
    var mapDiv = document.getElementById('div_VEMap');
    var overlayDiv = document.getElementById('div_VEMapOverlay');
    
  // if both exist, set the child relationship and the content of the overlay    
    if((mapDiv != null) && (overlayDiv != null))
      {
      mapDiv.appendChild(overlayDiv);
      overlayDiv.innerHTML = VE_SLHtml;
      VE_SLHtml_inserted = true;
      }
    else 
      util_Error("div_VEMap or div_VEMapOverlay is null");
  }

//--------------------------------------------------------------------------------//
// Override all of the mouse events and pass them into the silverlight control    //
// first.  If the event is processed, "turn it off" so the VE control ignores it. //
//--------------------------------------------------------------------------------//
function JSVE_MouseOverride(e)
  {
  // A lot of ugly special cases here -- hopefully handled when the SL/VE 
  // control comes out
  
    /*
    * 
    * http://msdn2.microsoft.com/en-us/library/bb412543.aspx
    * An event handler can disable the default Virtual Earth 
    * action associated with that event by returning true. 
    * If the event handler does not return a value or returns 
    * false, the default action occurs after any actions 
    * defined in the event handler.
    * 
    */
    /*
        Empirical testing has shown that e.leftMouseButton is ALWAYS true in Firefox, except 
        during an actual Right-click event, which will come in as an "onclick" event.
        
        A start pan event is fired on click.  Only set internal VE_panning to true if
        a start pan is followed by a mouse move.
    */
    
  // make sure the map exists
    if (VE_map == null) return false;

    //if(e.eventName != "onmousemove")
    //  {
    //  util_DebugMessage(e.eventName + "  VE_keyDown: " + VE_keyDown);
    //  }


  // Always handle these in the map control  
  // set navigation cookies on EndPan, EndZoom or viewchange
    if(e.eventName == "onendpan" || e.eventName == "onendzoom" || e.eventName == "onchangeview")
      {
      // recover origin and zoom
        var origin = VE_map.GetCenter();
	      var zoom = VE_map.GetZoomLevel();
	    // set the cookie   
        setCookie('originLat', origin.Latitude, 365);
        setCookie('originLon', origin.Longitude, 365);
  	    setCookie('originZoom', zoom, 365);
	    // clear panning flag
	      if(e.eventName == "onendpan")
	        VE_panning = false;
	    // trigger lat49 update
	      Lat49_UpdateAdsByLatLon(origin.Latitude, origin.Longitude, zoom);
      } // cookie update

  // double click detection -- must be before panning issues, since onmousemove happens all the frigging time!
  // if ((bIsIEBrowser == true) && (e.eventName == "onmouseup")) // when SHOULD be getting dclick, not getting a second down event
    if (e.eventName == "onmouseup") // when SHOULD be getting dclick, not getting a second down event
      {
      var currentDate = new Date();
      var thisMilli = currentDate.valueOf();
      var dMS = thisMilli - VE_lastClickTime;
      var vMapX = e.mapX;
      var vMapY = e.mapY;
      var dx = Math.abs(vMapX - VE_lastClickX);
      var dy = Math.abs(vMapY - VE_lastClickY);
      if ((bIsIEBrowser == true) &&
          (dMS < 500) &&
          (dx < 5) && (dy < 5))
        {
        // zoom in
          IEZoom(e);
          return true;
        }
      VE_lastClickTime = thisMilli;
      VE_lastClickX = vMapX;
      VE_lastClickY = vMapY;
    }
  // now for firefox, on a double click, the VE_lastClickTime test should still work
  // this check is required so that the same blocking can be done as with IE and
  // an event click
    if (e.eventName == "ondoubleclick")
      {
      var currentDate = new Date();
      var thisMilli = currentDate.valueOf();
      var dMS = thisMilli - VE_lastClickTime;
      if (dMS > 500)
        return true;
      }
   
  // panning, set the flag to track panning
  // "onstartpan" is being issued on every mouse down, but not 
  //    neccessarily canceled on a click (although the control does stop panning)
  // Sequence is: (lclick)  mousedown -- startpan -- mouseup    ???? why no click
  //              (rclick)  mousedown -- startpan -- mouseup -- click 
  //              (pan)     mousedown -- startpan -- mouseup -- endpan
  // The following checks are to set the panning flag to reflect the control state
    if(VE_blockNextMouseMove && (e.eventName == "onmousemove"))
      {
      VE_blockNextMouseMove = false;
      return false;
      }
      
    if(e.eventName == "onmousedown")
      {
      if(Lat49_OverLat49Div(e.mapX, e.mapY) == true)
        return true;
      }  
      
  // Mac-right click "fix"
    if((VE_keyDown == 16) && (OSName == "MacOS"))
      {
      if(e.eventName == "onclick" || e.eventName == "onmouseup")
        {
        e.eventName = "onclick";
        e.rightMouseButton = true;
        //VE_keyDown = ""; can't reset, Mac sends single keydown, no repeat (configurable)
        }
      }
      
    if(e.eventName == "onclick")
      {
      VE_panning = false;
      VE_panPending = false;
      VE_blockNextMouseMove = true;  
      if(bIsIEBrowser == true)
        VE_lastClickTime = 0;
      }
    if(e.eventName == "onstartpan")
      {
      VE_panPending = true;
      return false;
      }
    if(VE_panPending && e.eventName == "onmousemove")
      {
      VE_panning = true;
      VE_panPending = false;
      }
    if(VE_panning && (e.eventName != "onmousemove" && e.eventName != "onmouseup"))
      VE_panning = false;
        

  // zooming, set the flag to track panning,
  //  if(e.eventName == "onstartzoom")
  //    VE_zooming = true;
  //  else if(e.eventName == "onendzoom")
  //    VE_zooming = false;
  // if panning ignore clicks, etc.. A lot of messy code to handle this case..
    if(VE_panning)
      return false; 
       
  // if SL ovleray is not up and running yet, block redirect to SL
    if(!util_overlayLoaded)
      return false;

  // dynamically access the scriptable member to pass the event data to
    var slDivID = document.getElementById('idVEMapOverlay');
    if(slDivID == null) return false;
    var overlayCtl = slDivID.content.div_VEMapOverlay_SLScriptReference;
    if(overlayCtl == null) return false;

    if(e.eventName != "onmousemove")
      {
      var retValue = overlayCtl.VE_MouseOverride(e, bIsIEBrowser);
      if(retValue != 0)
        VE_lastClickTime = 0;
      if(retValue == 1) // handled, block it
        return true;  
      }
    return false;  
  }


 
//--------------------------------------------------------------------------//
// In IE the double click is being blocked because of SL interaction, so    //
// simulate the double click by zooming in                                  //
//--------------------------------------------------------------------------//
function IEZoom(e)
  {
  var vMapX = e.mapX;
  var vMapY = e.mapY;
  var vZoomLevel = e.zoomLevel;
  var latlon = VE_PixelToLatLon(vMapX, vMapY);
  if(vZoomLevel < 19) vZoomLevel = vZoomLevel + 1;
  VE_SetCenterAndZoomLevel(vZoomLevel, latlon.Latitude, latlon.Longitude);
  }  
  
//--------------------------------------------------------------------------//
// VE_CatchKeyDown() -- VE has shortcut (press "3") to jump to 3D mode      //
//                      which needs to be blocked to prevent 3D mode        //
//--------------------------------------------------------------------------//
function VE_CatchKeyDown(e)
  {
  VE_keyDown = e.keyCode;
  if(e.keyCode == 51 ||  // 3D
     e.keyCode == 66 ||  // birds eye
     e.keyCode == 79)    // birds eye
    return true;
  return false;  
  }    
function VE_CatchKeyUp(e)
  {
  VE_keyDown = "";
  return false;
  }    
//-------------------------------------------------------------------------------//
// Map style changing (terrain tile feed, goal is to block a change to birds eye //
//-------------------------------------------------------------------------------//
//function JSVE_ChangeMapStyle(mapEvent)
//  {
//  if(mapEvent.mapStyle == "b")
//    VE_map.SetMapStyle(VEMapStyle.Hybrid);
//  }
  
//--------------------------------------------------------------------------------//
// VE_PanMap(dx, dy) -- pan the VEMap by the input number of pixels               //
//--------------------------------------------------------------------------------//
function VE_PanMap(dx, dy)
  {
  // make sure the map exists
    if(VE_map == null) return;
    VE_map.Pan(dx, dy);
    VE_panning = false;
    VE_panPending = false;
  }
//--------------------------------------------------------------------------------//
// VE_PanMapLatLong(lat, lon) -- pan the VEMap to the target lat/lon              //
//--------------------------------------------------------------------------------//
function VE_PanMapLatLon(lat, lon)
  {
  // make sure the map exists
    if(VE_map == null) return;
    var latLong = new VELatLong(lat, lon);	
    VE_map.PanToLatLong(latLong);
    VE_panning = false;
    VE_panPending = false;
  }
  
//--------------------------------------------------------------------------------//
// VE_SetCenterAndZoomLevel(zoom, lat, lon) -- zoom and position in one move      //
//--------------------------------------------------------------------------------//
function VE_SetCenterAndZoomLevel(zoom, lat, lon)
  {
    if(VE_map == null) return;
    var latLong = new VELatLong(lat, lon);	
    VE_map.SetCenterAndZoom(latLong, zoom);
  }
//--------------------------------------------------------------------------------//
// VE_GetZoomLevel() -- returns the current zoom level                            //
//--------------------------------------------------------------------------------//
function VE_GetZoomLevel()
  {
  if(VE_map == null) return 1;
  return VE_map.GetZoomLevel();
  }
//--------------------------------------------------------------------------------//
// VE_SetZoomLevel(int zoomLevel) -- set controls zoom level (1-20) externally    //
//--------------------------------------------------------------------------------//
function VE_SetZoomLevel(zoom)
  {
  if(VE_map != null && zoom >=1 && zoom <= 19) 
    {
    VE_map.SetZoomLevel(zoom);
    }
  }
  
//--------------------------------------------------------------------------------//
// VE_SetCenter(lat, lon) -- immediate jump to a centered lat, lon                //
//--------------------------------------------------------------------------------//
function VE_SetCenter(lat, lon)
  {
  // make sure the map exists
    if(VE_map == null) return;
    var ll = new VELatLong(lat, lon);
    VE_map.SetCenter(ll);
    VE_panning = false;
    VE_panPending = false;
  }  
//--------------------------------------------------------------------------------//
// VE_GetCenter() -- get coordinates of current views center                      //
//--------------------------------------------------------------------------------//
function VE_GetCenter(lat, lon)
  {
  // make sure the map exists
    if(VE_map == null) return;
    var latlon = VE_map.GetCenter();
    return latlon;
  }  
  
  
  
//--------------------------------------------------------------------------------//
// VE_PixelToLatLon(x, y) -- convert map(x,y) to a lat lon pair                   //
//--------------------------------------------------------------------------------//
function VE_PixelToLatLon(x, y)
  {
  // make sure the map exists
    if(VE_map == null) 
      return null;
  // put the location into a VEPixel object
    var pixel  = new VEPixel(x, y);
  // convert to LatLon  
    var latlon = VE_map.PixelToLatLong(pixel);
  // return
    return latlon;
  }
//--------------------------------------------------------------------------------//
// VE_LatLonToPixel(lat, lon) -- convert lat,lon to map(x,y) at current zoom      //
//--------------------------------------------------------------------------------//
function VE_LatLonToPixel(lat, lon)
  {
  // make sure the map exists
    if(VE_map == null) 
      return null;
  // put the location into a VELatLon object
    var latlon  = new VELatLong(lat, lon);
  // convert to LatLon  
    var pixel = VE_map.LatLongToPixel(latlon);
  // return
    return pixel;
  }
  
//--------------------------------------------------------------------------------//
// VE_FeedEvents(clusters) -- update shapes in the map with the clusters          //
// in the input array                                                             //
//--------------------------------------------------------------------------------//
function VE_FeedEvents(clusters)
  {
  // clear it
    if(VE_dataLayer != null)
      VE_map.DeleteShapeLayer(VE_dataLayer);
  
    VE_dataLayer = new VEShapeLayer();
    var length = clusters.length;
    for(i = 0; i < length; i++)
      {
        var cluster = clusters[i];
        var lat = cluster.Lat;
        var lon = cluster.Lon;
        var newShape = new VEShape(VEShapeType.Pushpin, new VELatLong(lat, lon));
        var numIds = cluster.EventIds.length;
        var desc = "ID's in this cluster:  ";
        var iconName = cluster.IconName;
        for(var j = 0; j < numIds; j++)
          {
            desc += cluster.EventIds[j] + ", ";
          }
        newShape.SetDescription(desc);

      // "correctPNG()" right here        
        if(Sys.Browser.agent == Sys.Browser.InternetExplorer && (Sys.Browser.version == 6))
          {
          var divText = "<div STYLE=\"position:relative;" +
                                     "height:32px;" +
                                     "width:32px;" +
                                     "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='icons/" + iconName  + "',sizingMethod='scale');\"></div>";
          newShape.SetCustomIcon(divText);
          }
        else 
          newShape.SetCustomIcon("<img src='icons/" + iconName + "' width='32' height='32'/>");        

        VE_dataLayer.AddShape(newShape);
      }
     VE_map.AddShapeLayer(VE_dataLayer); 
  }
//-----------------------------------------------------------------------------//
// VE_SetLocatorIcon() -- show/hide the locator icon                           //  
//-----------------------------------------------------------------------------//
function VE_SetLocatorIcon(show, lat, lon)  
  {
  // allocate if required
    if(VE_locationLayer == null)
      {
      VE_locationLayer = new VEShapeLayer();
      VE_map.AddShapeLayer(VE_locationLayer);
      }
  // get the icon
    if(VE_locationLayer.GetShapeCount() == 0)
      {
      VE_locatorPin = new VEShape(VEShapeType.Pushpin, new VELatLong(lat, lon));   
      // -- commented out, broken in all but IE8
      // "correctPNG()" right here        
        if(Sys.Browser.agent == Sys.Browser.InternetExplorer && (Sys.Browser.version == 6))
          {
          var divText = "<div STYLE=\"position:relative;" +
                                  "height:86px;width:71px;" +
                                  "left:-51px;top:-68px;" +
                                  "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='icons/locator.png',sizingMethod='image');\"></div>";
          VE_locatorPin.SetCustomIcon(divText);
          }
        else 
          {  
          var pin = "<div style=\'position:relative;left:-51px;top:-68px;\'><img src=\'icons/locator.png\'></div>"
          VE_locatorPin.SetCustomIcon(pin);
          }
      VE_locationLayer.AddShape(VE_locatorPin);
      }
    else
      {
      var pts = VE_locatorPin.GetPoints();
      pts[0].Latitude = lat;
      pts[0].Longitude = lon;
      VE_locatorPin.SetPoints(pts);
      }  
  // show or hide?
    if(show == true)
      VE_locationLayer.Show();
    else       
      VE_locationLayer.Hide();
  }    
  
//------------------------------------------------------------------------//
// searchMap(route) -- call from silverlight to execute a map search      //  
//------------------------------------------------------------------------//
function VE_SearchMap(address)
  {
  if(VE_map == null) return;
  
  VE_map.Find(null,  // what
              address, // where
              null,  // find type
              null,  // search pin target (shapelayer)
              0,     // first result
              1,     // number of results (1-20)
              false, // show results
              false, // create results -- create pushpins, don's use callback
              true,  // disambiguation
              true,  // set best view
              VE_SearchMapCallBack); // no call back
  }
//---------------------------------------------------------------------------------//
// Call back function to enable setting a search/locator icon                      //  
//---------------------------------------------------------------------------------//
function VE_SearchMapCallBack(layer, resultsArray, places, hasMore, veErrorMessage)
  {
  if(places != null)
    VE_SetLocatorIcon(true, places[0].LatLong.Latitude, places[0].LatLong.Longitude);
  else
    {
    if(veErrorMessage != "")
       util_Message(veErrorMessage);
    else
       util_Message("Search returned:  No locations");
    return;
    }
  }  

//--------------------------------------------------------------------------//
// mapDivResize() -- Browser window resize                                  //
//--------------------------------------------------------------------------//
function VE_MapDivResize()
  {
  // make sure there's something to work with!
    if(VE_map == null) return;
    
    var bodyDiv = document.getElementById('appContent');
    if(bodyDiv == null) return;
    var mapDiv = document.getElementById('div_VEMap');
    if(mapDiv == null) return;
    
    var x = bodyDiv.clientWidth;
    var y = bodyDiv.clientHeight;    
    VE_map.Resize(x, y); 
    
  // call lat49div window so it can re-position  
    Lat49_Resize(x, y);
  }
