// This code was derived from the help documentation located at
// http://code.google.com/apis/maps/documentation/
// It appears that you may use the code and its derivations as long as it
// meets the terms of service:
// http://code.google.com/apis/maps/faq.html#tos_commercial
// It appears that the code is available as open-source; which open-source license,
// though, is unclear.
// ------------------------------------------------------------------------------------------------------------------- //
function loadmap() 
{

  if (GBrowserIsCompatible()) 
  {
    var lcDataID = getquerystring("DataID");
    var lcXMLPath = "Data/" + lcDataID + ".xml";
    var loMap = new GMap2(document.getElementById("MapArea"));

    loMap.addControl(new GLargeMapControl());
    loMap.addControl(new GMapTypeControl());
    loMap.addControl(new GScaleControl());
    loMap.addMapType(G_PHYSICAL_MAP);      

		var loSmallMap = new GOverviewMapControl(new GSize(180,180));
		loMap.addControl(loSmallMap); 
    loSmallMap.auto=false;

    GDownloadUrl(lcXMLPath, function(data, responseCode) 
    {
      var xml = GXml.parse(data);
      var loQuickMap = xml.documentElement.getElementsByTagName("xquickmap");
      for (var i = 0; i < loQuickMap.length; i++) 
      {
        var loPoint = new GLatLng(parseFloat(loQuickMap[i].getAttribute("y")),
                                  parseFloat(loQuickMap[i].getAttribute("x")));

        var lcLabel = loQuickMap[i].getAttribute("mapid");
        if (lcLabel == "-1")
        {
          loMap.setCenter(loPoint, 13);

          var lcHint = "Target Property Centroid";
          var lcInformation = loQuickMap[i].getAttribute("describe");

          var loMarker = createMarker(loPoint, lcHint, lcInformation);
          loMap.addOverlay(loMarker);

          if (i != 0)
          {
            alert("The Target Property must be the first row. Otherwise, setCenter gets called after loMap.addOverlay and the map will not work.");
          }
        }
        else
        {
          var lcHint = "Map ID# " + loQuickMap[i].getAttribute("mapid");
          var lcInformation = loQuickMap[i].getAttribute("describe");

          var loMarker = createMarker(loPoint, lcHint, lcInformation);
          loMap.addOverlay(loMarker);
        }
      }
    });

  }
}
// ------------------------------------------------------------------------------------------------------------------- //
function createMarker(toPoint, tcTextTip, tcInformation) 
{
  var loCreateMarker = new GMarker(toPoint, {title:tcTextTip});

  GEvent.addListener(loCreateMarker, "click", function() 
  {
    loCreateMarker.openInfoWindowHtml(tcInformation);
  });	

  return loCreateMarker;
}
// ------------------------------------------------------------------------------------------------------------------- //
function getquerystring(tcTag) 
{
  var lcTemp = window.location.search;
  var lcSearch = lcTemp.substring(1);

  var laPairs = lcSearch.split('&');

  for (var i = 0; i < laPairs.length; i++)
  {
    var lnIndex = laPairs[i].indexOf('=');
    var lcKey = laPairs[i].substring(0, lnIndex);
    var lcValue = laPairs[i].substring(lnIndex + 1);

    if (lcKey == tcTag)
    {
      return (lcValue);
    }
  }

  return ("");
}
// ------------------------------------------------------------------------------------------------------------------- //

