﻿var map = null;
var pinID = 0;
function GetMap()
{
  map = new VEMap('MapDiv');
  map.LoadMap(new VELatLong(54.55, -4.5), 6 ,'r' ,false);
  map.AttachEvent("onchangeview", DoAjaxQuery);
  DoAjaxQuery();
}   
function ShowLoading()
{
  var el = document.createElement("div"); 
  el.setAttribute('id',"Loading");
  var curr_width = 759;
  var curr_height = 690;
  el.style.top = ((curr_height - 25) / 2) + "px";
  el.style.left = ((curr_width - 105) / 2) + "px";
  el.style.border = "1px solid gray";
  el.style.font = "12px arial";
  el.style.background = "White";
  el.style.padding = "2px";
  el.style.verticalAlign = "middle";
  el.innerHTML = "<img src='images/PointImage.png' /> Please Wait. Loading Agent data....";  
  map.AddControl(el);
}
function HideLoading()
{
  var el = document.getElementById("Loading");
  el.parentNode.removeChild(el);
}
function GetXmlHttp()
{
  var x = null;
  try
  {
    x = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e)
  {
    try
    {
      x = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e)
    {
      x = null;
    }      
  }
  if (!x && typeof XMLHttpRequest != "undefined")
  {
    x = new XMLHttpRequest();      
  }
  return x;
}
function DoAjaxQuery()
{
    var s=map.GetMapStyle();
    if (s!=VEMapStyle.Birdseye)
    {
       var url = "http://powering.expertagent.co.uk/GetAgencyData.aspx?";
       url += "tl=" + map.PixelToLatLong(new VEPixel(0, 0));
       var curr_width = 759;
       var curr_height = 690;

      url += "&w=" + curr_width;
      url += "&h=" + curr_height;
       
      url += "&br=" + map.PixelToLatLong(new VEPixel(curr_width, curr_height));
      url += "&z=" + map.GetZoomLevel();
      
      ShowLoading();

      var xmlhttp = GetXmlHttp();

      if (xmlhttp)
      {
        xmlhttp.open("GET", url, true);
        
        xmlhttp.onreadystatechange = function()
        {
          if (xmlhttp.readyState == 4)
          {
            var result = xmlhttp.responseText;
            eval(result);
          }
        }
        xmlhttp.send(null);
      }
   }
}


