/*
e-Navigator - Copyright 2009
Utilizes the Google Maps v2 API
March 2009
Joe Wiesner
*/

/**** GLOBAL VARIABLES *** */

var map_ArrayPoints = [];                  //array that stores all the points that are plotted.
var map_Interactive_AJAXObject = null;
var map_Detail_Tab_Array = [];
var map_ClickOnDetail = false;                      
var map_PointName = '';
var map_ShowDebugInfo = false;
var map_AllowStreetView;
var map_clickedPixel;
var map_clickedIndex;
var map_ShowTooltips = false;
var map_UsesGoogleAnalytics;

/* *** Objects *** */
function map_Point()
{
    this.id = null;
    this.latlng = new GLatLng(0, 0);
    this.tooltipHtml = '';
    this.statsHtml = '';
    this.tooltipClassName = '';
    this.popupTabs = [];
    this.pushPin = null;
    this.pushPinShadow = null;
    this.iconHeight = 20;
    this.iconWidth = 20;
}

function Map_PointIconSet()
{
    this.iconImage = '/images/mapping/Default_Pin.gif';
    this.iconImageShadow = '';
    this.pushpinWidth = 15;
    this.pushpinHeight = 20;
    this.tooltipClassName = 'Map_Default_ToolTip';
    this.isGrouping = false;
    this.pushPinOrientation = 'BottomMiddle';
}

/*variables used for the Interactive Search*/
var map_LoadPointURL = '';
var map_LoadPointGroupingURL = '';
var map_MinGroupingZoomLevel = 0;
var map_LoadPointZoomLevel = 0;
var map_CenterPointOnClick = true;
var map_LoadMapAreaURL = '';

/* *********** */
var map_RequestCount_Area = 0;
var map_RequestCount_Group = 0;
var map_RequestCount_Point = 0;

/* ********************* */
function Map_browserIsIE(){if(navigator.userAgent.indexOf("MSIE") == -1){return false;}else{return true;}}

function Map_ClearPoints(){map.clearOverlays();map_ArrayPoints = [];}
function Map_HideMessage(){document.getElementById('Map_Message').style.display = 'none';}
function Map_HideDetails(){document.getElementById('Map_Detail').style.display = 'none';}
function Map_KillCookie(name){var mydate = new Date('January 1, 1970');document.cookie=name + ';expires=' + mydate.toGMTString();}
function Map_SetCookie(name, value){document.cookie=name + '=' + escape(value) + ';';}
function Map_SetCookieWithExp(name, value, exp){var mydate = new Date();mydate.setDate(mydate.getDate() + exp);document.cookie = name + '=' + escape(value) + '; expires=' + mydate.toGMTString();}
function Map_GetCookie(name){var index = document.cookie.indexOf(name + "="); if (index == -1) return null; index = document.cookie.indexOf("=", index) + 1; /* first character */ var endstr = document.cookie.indexOf(";", index); if (endstr == -1) endstr = document.cookie.length; /* last character */ return unescape(document.cookie.substring(index, endstr));}
function Map_SetDebugStatus(strVal){if(!map_ShowDebugInfo) return;if(strVal.length > 0) document.getElementById('Map_Debug_Status').innerHTML = strVal;else document.getElementById('Map_Debug_Status').innerHTML = 'Idle';}
function Map_HideHelp(){document.getElementById('Map_Help').style.display = 'none';}
function Map_ContextCenter(){var latlng = map.fromContainerPixelToLatLng(map_clickedPixel);map.panTo(latlng);}
function Map_ContextStreetView(){var latlng = map.fromContainerPixelToLatLng(map_clickedPixel);var lat = latlng.lat();var lng = latlng.lng();Map_LoadSVPanel(lat, lng);}
function Map_HideContextMenu(){var elem = document.getElementById('Map_ContextMenu');if(elem) elem.style.visibility = 'hidden';}            
function Map_HideToolTip(){if(map_ShowTooltips) document.getElementById('Map_ToolTip').style.display = 'none';}
function Map_SaveInteractiveParameters(oldlevel){if(map_IsInteractive){var center = map.getCenter();Map_SetCookie('eNavigator_Prev_CenterLat', center.lat());Map_SetCookie('eNavigator_Prev_CenterLng', center.lng());if(oldlevel) Map_SetCookie('eNavigator_Prev_ZoomLevel', oldlevel);Map_SetCookie('eNavigator_Prev_MapStyle', map.getCurrentMapType().getName());}}   
function Map_ShowLoadingMessage(){document.getElementById('Map_Loading').style.display = '';}
function Map_HideLoadingMessage(){document.getElementById('Map_Loading').style.display = 'none';}
function Map_TypeButtonHover(obj){obj.style.backgroundColor = '#007733';}
function Map_TypeButtonOut(obj){var pane = document.getElementById('Map_DashboardPane');if(pane){if(window.getComputedStyle) obj.style.backgroundColor = window.getComputedStyle(pane,null).getPropertyValue('backgroundColor');else obj.style.backgroundColor = pane.currentStyle['backgroundColor'];}}
function Map_ImageOver(obj){var source = obj.src;obj.src = source.replace(/normal/i, 'hover');}
function Map_ImageOut(obj){var source = obj.src;obj.src = source.replace(/hover/i, 'normal');}
function Map_ShowHelp() { Map_HideDetails(); document.getElementById('Map_Help').style.display = ''; }
function Map_SetZoom(zoom) { map.setZoom(zoom); }
function Map_SetCenter(lat, lng, zoom) { map.setCenter(new GLatLng(lat, lng), zoom); }

function Map_ShowMessage(strMessage, timeout)
{   
    var strhtml = '<table width="100%"><tr><td valign="top"></td>';    //jcw
    strhtml += '<td style="text-align:left;">';
    strhtml += strMessage;
    strhtml += '</td><td valign="top" align="right"><a href="javascript:Map_HideMessage();">';
    strhtml += '<img src="/_include/Common/Mapping_G_v1/images/redx.jpg" border="0" alt="close" /></a></td></tr></table>';
    
    var mapmessage = document.getElementById('Map_Message');
    mapmessage.innerHTML = strhtml;
    mapmessage.style.display = '';
    if (timeout > 0) window.setTimeout("document.getElementById('Map_Message').style.display = 'none';", timeout);
}

function Map_GetBoundaryLatLongURL(){
    //builds part of the query string that contains the min and max latitudes and longitudes of the map currently in the viewport
    var bounds = map.getBounds();
    var strUrl = 'VAR_Min_Lat1=' + bounds.getSouthWest().lat();
    var x = map.fromLatLngToContainerPixel(bounds.getNorthEast()).x;
    //the next line accounts for the pane(s) that hover over the top 1/2 inch or so of the map, and treats that as the northern boundary
    //instead of using the actual top of the map container.
    strUrl += '&VAR_Max_Lat1=' + map.fromContainerPixelToLatLng(new GPoint(x, map_paneHeight)).lat();
    strUrl += '&VAR_Min_Lng1=' + bounds.getSouthWest().lng();
    strUrl += '&VAR_Max_Lng1=' + bounds.getNorthEast().lng();
    return strUrl;
}

function Map_LoadInteractiveMapView()
{
    Map_ClearPoints();
    
    if (map_IsInteractive && map_LoadMapAreaURL.length != 0) {
    
        Map_ShowLoadingMessage();
        map_RequestCount_Area++;
        
        //Figure out which URL to use to get the XML representation of the map area to show
        var strUrl = map_LoadMapAreaURL;
        
        //Add QueryString Variables
        if(strUrl.indexOf('?') == -1) strUrl += '?';
        
        //Add Lat/Lng to the QueryString
        strUrl += Map_GetBoundaryLatLongURL();
        
        //Add Custom QueryString Variables
        var strQueryString = '';
        if(window.Map_CustomQueryString) strQueryString = Map_CustomQueryString();
        if(strQueryString.length > 0) strUrl += '&' + strQueryString;
        
        GDownloadUrl(strUrl, function(data, responseCode) {  
            if(responseCode == 200)
            {        
                Map_SetDebugStatus("Interactive Map - Map View Returned");
                var xmlDoc = GXml.parse(data);  
                    
                if (xmlDoc.documentElement.getAttribute('minlat') != null
                    && xmlDoc.documentElement.getAttribute('maxlat') != null
                    && xmlDoc.documentElement.getAttribute('minlng') != null
                    && xmlDoc.documentElement.getAttribute('maxlng') != null
                    
                    && xmlDoc.documentElement.getAttribute('minlat').length > 0
                    && xmlDoc.documentElement.getAttribute('maxlat').length > 0
                    && xmlDoc.documentElement.getAttribute('minlng').length > 0
                    && xmlDoc.documentElement.getAttribute('maxlng').length > 0
                    )
                {
                    var ne = new GLatLng(xmlDoc.documentElement.getAttribute('maxlat'), xmlDoc.documentElement.getAttribute('maxlng'));
                    var sw = new GLatLng(xmlDoc.documentElement.getAttribute('minlat'), xmlDoc.documentElement.getAttribute('minlng'));
                    var bounds = new GLatLngBounds(sw, ne);
                    var zoom = map.getBoundsZoomLevel(bounds);
                    map.setCenter(bounds.getCenter(), zoom);
                }
                else
                {
                    Map_LoadInteractivePoints();
                }
                    
                if(window.Map_InteractiveMapView_Loaded) Map_InteractiveMapView_Loaded();
            }
            else
            {
                Map_SetDebugStatus('Interactive Map - Error occurred loading map view');
                if(map_ShowDebugInfo)
                {
                    Map_ShowMessage('An Error (' + responseCode + ') Occurred loading map view.');
                    alert(request.data);
                }            
            }
        });
    }
    else {
        Map_LoadInteractivePoints();
    }
    window.setTimeout("if(map_ShowDebugInfo) Map_ShowDebugInfo()", 800);
}

function Map_CenterOnPoints() {
    if (map_ArrayPoints.length > 1) {
        var bounds = new GLatLngBounds();
        var x;
        for(x=0; x<map_ArrayPoints.length; x++) {bounds.extend(map_ArrayPoints[x].latlng);}
        var zoom = map.getBoundsZoomLevel(bounds);
        map.setZoom(zoom);
        map.setCenter(bounds.getCenter(), zoom);
        if(!map_IsInteractive) {
            
            //Check for pins hiding under the key and/or control button pane along the top of the map.  If there are any, zoom out 1.
            //On the interactive map, this step isn't necessary because the artificial northern boundary is accounted for before any query 
            //is run.
            var adjNorthBoundary = map.fromContainerPixelToLatLng(new GPoint(0, map_paneHeight + 3))
            for(x=0; x<map_ArrayPoints.length; x++) 
            {
                if(map_ArrayPoints[x].latlng.lat() >= adjNorthBoundary.lat()) 
                {
                    map.zoomOut();
                    break;
                }
            }
        }
    }
    else if(map_ArrayPoints.length == 1)
    {
        map.setCenter(map_ArrayPoints[0].latlng, 13);
    }
    
    if(window.Map_CenteredOnPoints) Map_CenteredOnPoints();
}

function Map_WriteDebugMessage(str){var mydate = new Date();document.getElementById('Map_Debug_Messages').innerHTML += str + '<br />';}
function Map_ClearDebugMessages(){document.getElementById('Map_Debug_Messages').innerHTML = '';}
function Map_ShowDebugInfo()
{
    document.getElementById('Map_Debug_Latitude').innerHTML = map.getCenter().lat();
    document.getElementById('Map_Debug_Longitude').innerHTML = map.getCenter().lng();
    document.getElementById('Map_Debug_Zoom').innerHTML = map.getZoom();
    document.getElementById('Map_Debug_PointCount').innerHTML = map_ArrayPoints.length;
    document.getElementById('Map_Debug_Interactive').innerHTML = map_IsInteractive;
    document.getElementById('Map_Debug_LoadPointURL').innerHTML = "<a href='" + map_LoadPointURL + "?" + Map_GetInteractiveMapUrlQueryString() + "' target='_blank'>" + map_LoadPointURL + "</a>";
    document.getElementById('Map_Debug_MinGroupingZoomLevel').innerHTML = map_MinGroupingZoomLevel;
    document.getElementById('Map_Debug_LoadPointGroupingURL').innerHTML = "<a href='" + map_LoadPointGroupingURL + "?" + Map_GetInteractiveMapUrlQueryString() + "' target='_blank'>" + map_LoadPointGroupingURL + "</a>";
    document.getElementById('Map_Debug_LoadPointZoomLevel').innerHTML = map_LoadPointZoomLevel;
    document.getElementById('Map_Debug_LoadMapAreaURL').innerHTML = "<a href='" + map_LoadMapAreaURL + "?" + Map_GetInteractiveMapUrlQueryString() + "' target='_blank'>" + map_LoadMapAreaURL + "</a>"
    document.getElementById('Map_Debug_RequestCountArea').innerHTML = map_RequestCount_Area;
    document.getElementById('Map_Debug_RequestCountGroup').innerHTML = map_RequestCount_Group;
    document.getElementById('Map_Debug_RequestCountPoint').innerHTML = map_RequestCount_Point;
}

function Map_ShowToolTip(marker, tooltipClassName)
{
    if(document.getElementById('Map_Detail').style.display != '')
    {
        //don't show tooltips when the bubble is open.  It's distracting.
        var tooltip = document.getElementById('Map_ToolTip');
        tooltip.innerHTML = marker.tooltip;
        tooltip.style.display = '';
        tooltip.className = tooltipClassName;
        var point = map.fromLatLngToContainerPixel(marker.getLatLng());
        tooltip.style.left = map.getContainer().offsetLeft + point.x + marker.getIcon().iconSize.width + 'px';
        tooltip.style.top = map.getContainer().offsetTop + point.y - marker.getIcon().iconSize.height + 'px';
    }
}

function Map_AddPoint(id, latitude, longitude, infoTabs, tooltipHtml, PointType, statsHtml)
{
    var MyPointIconSet = new Map_PointIconSet();
 
    var myPoint = new map_Point;
    myPoint.id = id;
    myPoint.latlng = new GLatLng(latitude, longitude);
    myPoint.tooltipHtml = tooltipHtml;
    myPoint.popupTabs = infoTabs;
    if(MyPointIconSet.SetType) 
    {
        MyPointIconSet.SetType(PointType);
        myPoint.tooltipClassName = MyPointIconSet.tooltipClassName;
        myPoint.iconHeight = MyPointIconSet.pushpinHeight;
        myPoint.iconWidth = MyPointIconSet.pushpinWidth;
    }
    map_ArrayPoints.push(myPoint);
        
    var myIcon = new GIcon();
    myIcon.image = MyPointIconSet.iconImage;
    myIcon.shadow = MyPointIconSet.iconImageShadow;
    myIcon.iconSize = new GSize(MyPointIconSet.pushpinWidth, MyPointIconSet.pushpinHeight);
    
    //set Orientation of marker
    if(MyPointIconSet.pushPinOrientation == 'Center')
        myIcon.iconAnchor = new GPoint(MyPointIconSet.pushpinWidth / 2, MyPointIconSet.pushpinHeight / 2);  
    else
        myIcon.iconAnchor = new GPoint(MyPointIconSet.pushpinWidth / 2, MyPointIconSet.pushpinHeight);  //should be BottomMiddle

    //myIcon.infoWindowAnchor = new GPoint(6, 0);    //infoWindow not in use at this time; we use the DOM object Map_Detail instead

    var marker = new GMarker(myPoint.latlng, { icon:myIcon });
    marker.tooltip = tooltipHtml;

    if(MyPointIconSet.isGrouping)    
        GEvent.addListener(marker, "click", function(){map.setCenter(myPoint.latlng, map_MinGroupingZoomLevel + 1);});
    else if(infoTabs != null && infoTabs.length > 0)
        GEvent.addListener(marker, "click", function(){Map_ShowDetails(id);});
    
    if(tooltipHtml != null && tooltipHtml.length > 0)
    {
        if(map_ShowTooltips)
        {
            GEvent.addListener(marker, "mouseover", function(){Map_ShowToolTip(marker, MyPointIconSet.tooltipClassName);});
            GEvent.addListener(marker, "mouseout", function(){Map_HideToolTip();});
        }
    }
    map.addOverlay(marker);
}

function Map_LoadBubbleWithHTML(url)
{
    var myIFrame = document.getElementById('Map_Detail_IFrame');
    
    GDownloadUrl(url, function(data, responseCode) {  
        var myDiv = document.createElement('div');
        myDiv.id = 'Map_Detail_IFrame_Content';
        
        if(responseCode == 200)
        {
            //The code below is a work around for a bug in setting a div's innerHTML property in IE
            var old = document.getElementById('Map_Detail_IFrame_Content');
            if(old) myIFrame.removeChild(old);
            myIFrame.innerHTML = '';
            
            myDiv.innerHTML = data;
            myIFrame.appendChild(myDiv);

            myIFrame.className = 'MapDetail';
            document.getElementById('Map_Detail_IFrame').style.display = '';
            
            function execJS(node)
            {
                var st = node.getElementsByTagName('SCRIPT');
                var strExec;
                for(var i=0; i<st.length; i++)
                {
                    strExec = st[i].text;
                    try
                    {
                        if(strExec.length != 0){eval(strExec);}
                    }
                    catch(e)
                    {
                        if(map_ShowDebugInfo){alert('Map Bubble Error:\nAn Error occured running the JavaScript in the tab content.');}
                    }
                }
            }
            execJS(myIFrame);
        }
        else
        {
            myDiv.innerHTML = 'error loading map detail; response code is ' + responseCode + '<br />url:<br />' + url;
            myIFrame.appendChild(myDiv);
        }
    });
}

function Map_Detail_Tab_Change(currentTab)
{
    document.getElementById('Map_Detail_IFrame').style.display = 'none';
    
    for(var i = 0; i <= map_Detail_Tab_Array.length - 1; i++)
    {
        if(currentTab == i)
            document.getElementById('Map_Detail_Tab_Number_' + i).className = 'Map_Bubble_Tab_Selected';
        else
            document.getElementById('Map_Detail_Tab_Number_' + i).className = 'Map_Bubble_Tab_UnSelected';
    }
    Map_LoadBubbleWithHTML(map_Detail_Tab_Array[currentTab]);
    if(map_ShowDebugInfo) document.getElementById('Map_Debug_CurrentBubbleURL').innerHTML = "<a href='" + map_Detail_Tab_Array[currentTab] + "' target='_blank'>" + map_Detail_Tab_Array[currentTab] + "</a>";
}

function Map_ShowDetails(id)
{   
    map_ClickOnDetail = true;
    var i;
    var idx = -1;
    if (document.getElementById('Map_Bubble_StreetLink')) document.getElementById('Map_Bubble_StreetLink').style.display = 'none';
                           
    for(i = 0; i < map_ArrayPoints.length; i++){if(id == map_ArrayPoints[i].id){idx = i;break;}}
    
    if(idx == -1) {
        Map_ShowMessage('Requested ' + map_PointName + ' (' + id + ') Not Found.');
    }   
    else {
        map_clickedIndex = idx;
        var popupTabHtml = '';
        var popupTabs = map_ArrayPoints[idx].popupTabs; 
        if(popupTabs.length > 0) {
            map_Detail_Tab_Array = [];
            for(i = 0; i < popupTabs.length; i++){map_Detail_Tab_Array[i] = popupTabs[i][1];}
            
            Map_LoadBubbleWithHTML(map_Detail_Tab_Array[0]);
          
            popupTabHtml += '<div id="Map_Bubble_Tab_Spacer">&nbsp;</div>';
    	    for(var i = 0; i < popupTabs.length; i++)
            {
                popupTabHtml += '<div class="Map_Bubble_Tab_UnSelected" onclick="javascript:Map_Detail_Tab_Change(' + i + ');" ';
                popupTabHtml += 'id="Map_Detail_Tab_Number_' + i + '" >';
                popupTabHtml += popupTabs[i][0];
			    popupTabHtml += '</div>';
            }
            
            var ctrlsHtml = '';
            ctrlsHtml += '<div style="float:right;padding:0px;"><img style="cursor:pointer" onclick="Map_HideDetails();" src="/_include/Common/Mapping_G_v1/images/bubble/close.gif" alt="Close" /></div>';
            ctrlsHtml += '<div style="display:none" id="Map_Bubble_StreetLink">';
            
            //if "map_UsesGoogleAnalytics" is true, the assumption is that the proper Google Analytics ID and and script has been set up in the site;
            //you'll see javascript errors if this is not done.
            if(map_UsesGoogleAnalytics) 
                ctrlsHtml += '<img style="cursor:pointer;" onclick="javascript:pageTracker._trackPageview(\'/mapbubble/streetview\');Map_LoadSVPanel(' + map_ArrayPoints[idx].latlng.lat() + ',' + map_ArrayPoints[idx].latlng.lng() + ');" onmouseover="Map_ImageOver(this);" onmouseout="Map_ImageOut(this);" src="/_include/Common/Mapping_G_v1/images/stview_normal.gif" alt="Street View" />';
            else
                ctrlsHtml += '<img style="cursor:pointer;" onclick="javascript:Map_LoadSVPanel(' + map_ArrayPoints[idx].latlng.lat() + ',' + map_ArrayPoints[idx].latlng.lng() + ');" onmouseover="Map_ImageOver(this);" onmouseout="Map_ImageOut(this);" src="/_include/Common/Mapping_G_v1/images/stview_normal.gif" alt="Street View" />';
            
            ctrlsHtml += '</div>';
            document.getElementById('Map_Detail_Tabs').innerHTML = popupTabHtml + ctrlsHtml;
            document.getElementById('Map_Detail_Tab_Number_0').className = 'Map_Bubble_Tab_Selected';
        }

        Map_EvalStreetView('Map_Bubble_StreetLink', map_ArrayPoints[idx].latlng.lat(), map_ArrayPoints[idx].latlng.lng());

        var offset = 0.0000900625;      
        //Drop this many degrees per zoom level.  
        //Has the effect of moving the marker below the vertical midpoint, which clears some room for the bubble
        //The bubble is in the DOM, and not a map control.  This means it can exceed the boundaries of the map container if it needs to.
        var zoom = map.getZoom();
        for (var x = zoom; x < 20; x++){offset = offset * 2;}
            
        map.panTo(new GLatLng(map_ArrayPoints[idx].latlng.lat() + offset, map_ArrayPoints[idx].latlng.lng()));
    } 
}

function Map_EvalStreetView(svLink, lat, lng)
{
    if(map_AllowStreetView)
    {
        //This function uses a callback for the Google StreetView service.
        //parameters are (1) the container ID (link/span/div/etc.) to unhide if SV is available, and (2) the geocode of the location in question.
        var sv = new GStreetviewClient();
        var svCallback = function(panoData)
        {
            if(panoData.code == 200)
                document.getElementById(svLink).style.display = '';
            else if(map_ShowDebugInfo)
                document.getElementById('Map_Debug_SV').innerHTML = panoData.code;
        };
        sv.getNearestPanorama(new GLatLng(lat,lng), svCallback);
    }
    else if(map_ShowDebugInfo) document.getElementById('Map_Debug_SV').innerHTML = 'Street View not activated for this client';
}

function Map_GetInteractiveMapUrlQueryString()
{
    // Add Lat/Lng to the QueryString
    var strQS = Map_GetBoundaryLatLongURL();
    
    //Add Custom QueryString Variables
    var strMapCustomQueryString = '';
    if(window.Map_CustomQueryString) strMapCustomQueryString = Map_CustomQueryString();
    if(strMapCustomQueryString.length > 0) strQS += '&' + strMapCustomQueryString;
    return strQS;
}

function Map_LoadInteractivePoints()
{
    //Only load points if the map is "Interactive".
    var curzoom = map.getZoom();
    
    Map_ClearPoints();
    
    if(map_IsInteractive && curzoom < map_LoadPointZoomLevel)
    {
        Map_HideLoadingMessage();
        Map_ShowMessage('Please zoom in closer to view ' + map_PointName + ' in the area you are searching.');
    }
    else if(map_IsInteractive)
    {
        if(curzoom >= map_LoadPointZoomLevel) document.getElementById('Map_Message').style.display = 'none';
        Map_SetDebugStatus('Interactive Map - Querying Server');
        
        var strURL = '';
        //The level we're at determines what kind of pin to use
        var isGroupPinLevel = (curzoom <= map_MinGroupingZoomLevel && map_LoadPointGroupingURL.length > 0);
        if(isGroupPinLevel)
        {
            strURL = map_LoadPointGroupingURL;
            map_RequestCount_Group++;
        }
        else
        {
            strURL = map_LoadPointURL;
            map_RequestCount_Point++;
        }

        /*Add QueryString Variables*/
        if(strURL.indexOf('?') == -1) strURL += '?';
        strURL += Map_GetInteractiveMapUrlQueryString();
        
        //GDownloadUrl is Google's browser-neutral xmlHttp wrapper, which handles ready state checking...so it simplifies the code.  Nice.
        GDownloadUrl(strURL, function(data, responseCode) {
            if (responseCode == 200) {
                var xmlDoc = GXml.parse(data);
                var points = xmlDoc.documentElement.getElementsByTagName('POINT');
                Map_SetDebugStatus('Interactive Map - Plotting ' + points.length + ' Points');

                if (points.length == 0) {
                    var strNoPointMessage = '';
                    var noPointMessage = xmlDoc.documentElement.getElementsByTagName('NOPOINTMESSAGE');
                    if (noPointMessage.length != 0) strNoPointMessage = noPointMessage[0].getAttribute('message');
                    if (strNoPointMessage.length != 0) Map_ShowMessage(strNoPointMessage);
                }
                else {
                    for (var i = 0; i < points.length; i++) {
                        if (!isGroupPinLevel) {
                            var arrPopupTabs = new Array();
                            var popupTabs = points[i].getElementsByTagName('popupTab');
                            for (var t = 0; t < popupTabs.length; t++) { arrPopupTabs[t] = [popupTabs[t].getAttribute('TabName'), popupTabs[t].getAttribute('TabPage')]; }
                        }
                        Map_AddPoint(points[i].getAttribute('id'), points[i].getAttribute('lat'), points[i].getAttribute('lng'), arrPopupTabs, points[i].getAttribute('tooltip'), points[i].getAttribute('PointType'), points[i].getAttribute('stats'));
                    }
                    Map_SetDebugStatus('Interactive Point - All Points Plotted');
                }
            }
            else {
                Map_SetDebugStatus('Interactive Point - Error occurred loading points');
                if (map_ShowDebugInfo) {
                    Map_ShowMessage('An Error (' + responseCode + ') Occurred Loading Points on the map.');
                    alert(data);
                }
                else {
                    Map_ShowMessage('No ' + map_PointName + ' could be found that match the criteria entered. Try zooming out to find nearby ' + map_PointName + '.');
                }
            }
            Map_HideLoadingMessage();
        });
    }
    window.setTimeout("if(map_ShowDebugInfo) Map_ShowDebugInfo()", 800);
}

function Map_LoadPointsFromXML(strUrl)
{
    //alert('load points from xml');
    if (strUrl == null) strUrl = '';
    if (strUrl.length == 0)
    {
        alert('Error Map_LoadPointsFromXML: The URL to load points from must be specified.');
    }
    else
    {
        var map_LoadPointsFromXML_Request = GXmlHttp.create();
        map_LoadPointsFromXML_Request.open("GET", strUrl, true);
        map_LoadPointsFromXML_Request.onreadystatechange = function(){
            if(map_LoadPointsFromXML_Request.readyState == 4)   
            {
                if(map_LoadPointsFromXML_Request.status != "200")
                {
                    Map_SetDebugStatus('Map_LoadPointsFromXML - Error occurred loading points');
                    if(map_ShowDebugInfo)
                    {
                        Map_ShowMessage('An Error (' + map_LoadPointsFromXML_Request.status + ') Occurred Loading Points on the map.');
                        alert(map_LoadPointsFromXML_Request.responseText);
                    }
                }
                else
                {
                    if(Map_browserIsIE())/*Internet Explorer*/
                    {
                        xmlDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
                        xmlDoc.loadXML(map_LoadPointsFromXML_Request.responseText);
                        if(xmlDoc.parseError.errorCode != 0)
                        {
                            if(map_ShowDebugInfo)
                            {
                                Map_ShowMessage("An error (" + xmlDoc.parseError.errorCode + ") occurred finding the requested points.");
                                alert(map_Interactive_AJAXObject.responseText);
                            }
                            else
                            {
                                Map_ShowMessage('No ' + map_PointName + ' could be found in the area you are searching that match the criteria entered.');
                            }
                            Map_HideLoadingMessage();
                            return;
                        }
                    }
                    else    /*Firefox, Safari, etc.*/
                    {
                        try
                        {
                            xmlDoc = map_LoadPointsFromXML_Request.responseXML;
                        }
                        catch(e)
                        {
                            Map_ShowMessage('An error occurred finding the requested points.');
                            Map_HideLoadingMessage();
                            return;
                        }
                    }

                    var points = xmlDoc.documentElement.getElementsByTagName("POINT");

                    Map_SetDebugStatus('Map_LoadPointsFromXML - Plotting ' + points.length + ' Points');
                    if (points.length == 0)
                    {
                        var strNoPointMessage = '';
                        var noPointMessage = xmlDoc.documentElement.getElementsByTagName("NOPOINTMESSAGE");
                        if (noPointMessage.length != 0) strNoPointMessage = noPointMessage[0].getAttribute('message');
                        if (strNoPointMessage.length != 0) Map_ShowMessage(strNoPointMessage);
                    }
                    else
                    {
                        for(var i = 0; i < points.length; i++)
                        {
                            var arrPopupTabs = new Array();
                            var popupTabs = points[i].getElementsByTagName('popupTab');
                            for(var t = 0; t < popupTabs.length; t++){arrPopupTabs[t] = [popupTabs[t].getAttribute('TabName'), popupTabs[t].getAttribute('TabPage')];}
                            Map_AddPoint(points[i].getAttribute('id'),points[i].getAttribute('lat'),points[i].getAttribute('lng'),arrPopupTabs,points[i].getAttribute('tooltip'),points[i].getAttribute('PointType'),points[i].getAttribute('stats'));
                        }
                        Map_SetDebugStatus('Map_LoadPointsFromXML - All Points Plotted');
                    }
                    Map_HideLoadingMessage();
                }
                if(map_ShowDebugInfo) Map_ShowDebugInfo(null);
                Map_HideLoadingMessage();
            }
        };
        map_LoadPointsFromXML_Request.send(null);
    }
}