map = {};

var globNELat = "NELat";
var globNELong = "NELong";
var globSWLat = "SWLat";
var globSWLong = "SWLong";
var globZoom = "Zoom";

var veMap;
var midLat;
var midLong;
var zoom;
var view;
var polyPoints;
var startAddress;
var isStatic;
var supportBirdsEye;
var newMapWidth;
var newMapHeight;
var isProcessing = false;
var cachedCoordinates = new Array();
var submitForm = 1;
var parecelSet = 0;
var companyID;
var bestview = false;
var activeView = "map";
var MapUIImagePath = "/Map/images/"; // TODO: Make the path configurable for flexibility to use custom images



map.browserNotSupported = function()
{
	document.getElementById('divMap').style.visibility='hidden';
	document.getElementById('MapNotSupported').style.display='block';
}
//Map
/*function to Load VE Map
	parameters:
		latitude
		longitude
		zoom - The zoom level to display. Valid values range from 1 through 19. 
		style - Valid values are a for aerial, h for hybrid, o for oblique (bird's eye), and r for road.
		isLocked - A Boolean value that specifies whether the map view is displayed as a fixed map that the user cannot change. 
*/
map.initMap = function()
{
    //if (browserDetect.isSupportedBrowser())
	//{
	    browserDetect.firefox2Fix();
        		
        // if configured to resize, resize map div before loading the map
		if (resizeMapWidthDiff > 0)
		    document.getElementById('divMap').style.width = map.getMapWidth() + 'px';  
		if (resizeMapHeightDiff > 0)
		    document.getElementById('divMap').style.height = map.getMapHeight() + 'px';  
		        
		map.renderMap();
	//}
	//else
	//{
	//	map.browserNotSupported();
	//}
}
map.renderMap = function() {
    try {
        veMap = new VEMap('divMap');
        veMap.LoadMap(new VELatLong(parseFloat(midLat), parseFloat(midLong)), zoom, view, isStatic, VEMapMode.Mode2D, false);

    }
    catch (e) {
        browserDetect.browserNotSupported();
    }
    if (isStatic == 1) // if static map - change cursor from hand to pointer
    {
        document.getElementById("divMap").childNodes[0].style.cursor = "default";
        window.onresize = null;
    }
    else {
        // show mini map
        map.ShowMiniMap(0, mapHeight - 150);

        try {
            if (polyPoints != "") {
                Shape.DrawPolygon(polyPoints);
            }
        }
        catch (e) { }
        map.resizeMap(); // if not static map - resize map on window resize
        if (map.isPOIEnabled())
            POI.displayPOI();

        map.toggleParcelLines();
        //if (document.getElementById('chkParcel') && document.getElementById('chkParcel').checked)
        //    map.toggleParcelLines(true);
    }

    // turn on new v6 features
    veMap.SetMouseWheelZoomToCenter(false); // zoom on the mouse location
    veMap.SetMapStyle(VEMapStyle.Shaded);
    
    // attach map event
    veMap.AttachEvent('onendcontinuouspan', map.onEndPan);
    veMap.AttachEvent('onendpan', map.onEndPan);
    veMap.AttachEvent('onendzoom', map.onEndZoom);
    veMap.AttachEvent("onchangemapstyle", map.onChangeMapStyle);
    map.HideMiniMap(); // Hide mini map by default

    // HACK ALERT SB 11/14/2008
    // This will (eventually) be replaced with a better autosuggest implementation that doesn't need it
    if (typeof _allAutoSuggests != 'undefined')
        veMap.AttachEvent('onmousedown', function() { for (var i = 0, len = _allAutoSuggests.length; i < len; i++) { _allAutoSuggests[i].hideDiv(); } });


    if (!supportBirdsEye) // hide bird's eye
        hide('MSVE_navAction_ObliqueMapView');


    if (GetCookie("MapSearch_MapExpanded") == "1")
        map.Expand();

    if (startAddress != "") // if org is not geocoded, startAddress will be passed to the map control
    {
        map.GotoFirst(startAddress);
        self.setTimeout('map.setLatLongValues();', 800);
    }
    if (view != "") {
        if (view == 'b')
            veMap.SetZoomLevel(zoom);
        self.setTimeout("map.setView(view);", 1500);
    }
}
map.onEndPan = function(e)
{
    map.setLatLongValues();
    if (map.isPOIEnabled())
        POI.displayPOI();    

}
map.onEndZoom = function(e)
{
    map.setLatLongValues();
    if (map.isPOIEnabled())
        POI.displayPOI();   
    map.toggleParcelLines(); 
}
map.onChangeMapStyle = function(e)
{
    if (veMap.GetMapStyle() == VEMapStyle.Road)
    {
        map.setView('r');
    }
}
map.Expand = function()
{
    map.resizeMapHeight(mapHeightFixed + 200);
    hide('map_expand');
    display('map_shrink');
    SetCookie("MapSearch_MapExpanded", "1", 10);
}
map.Shrink = function()
{
    map.resizeMapHeight(mapHeightFixed);
    display('map_expand');
    hide('map_shrink');
    SetCookie("MapSearch_MapExpanded", "0", 10);
}
window.onresize = function() {
    //if (activeView == "map")
        map.resizeMap();
    //else
     //   resizeIFrameW(document.getElementById("SearchResultsFrame"), "100%");
}
map.resizeMapWidth = function(width)
{
    resizeMapWidthDiff = width;
    map.resizeMap();
}
map.resizeMapHeight = function(height)
{
    mapHeight = height;
    map.resizeMap();
}
map.resizeMap = function() {
    // check if map exists and resize values are set    
    var newMapWidthOld = newMapWidth;
    var newMapHeightOld = newMapHeight;
    newMapWidth = mapWidth;
    newMapHeight = mapHeight;

    if (veMap && (resizeMapWidthDiff > 0 || resizeMapHeightDiff > 0)) {
        // get current map center
        var lat = veMap.vemapcontrol.GetCenterLatitude();
        var lon = veMap.vemapcontrol.GetCenterLongitude();

        // if configured to resize, get new height and width
        if (resizeMapWidthDiff > 0)
            newMapWidth = map.getMapWidth();
        if (resizeMapHeightDiff > 0)
            newMapHeight = map.getMapHeight();

        if ((newMapWidthOld != newMapWidth && (newMapWidth > newMapWidthOld + 20 || newMapWidth < newMapWidthOld - 20)) || newMapHeightOld != newMapHeight) {
            
	
	veMap.vemapcontrol.Resize(newMapWidth, newMapHeight); // resize map
             if (newMapWidthOld == undefined || (newMapWidth > newMapWidthOld + 40 || newMapWidth < newMapWidthOld - 40)) {
            } else {
                submitForm = 0;
            }  

            // move mini map if height changed
            if (newMapHeightOld != newMapHeight) {
                map.ShowMiniMap(0, newMapHeight - 150);
                map.HideMiniMap(); // hide by default
            }
            // Processing layer needs to cover entire map
            if (document.getElementById('tblProcessing')) {
                document.getElementById('tblProcessing').style.width = newMapWidth + 'px';
                if (map.isPOIEnabled())
                    document.getElementById('tblProcessing').style.height = newMapHeight + 28 + 'px'; // + POI Panel Height
                else
                    document.getElementById('tblProcessing').style.height = newMapHeight + 'px'; // + POI Panel Height
            }


            if (document.getElementById('divBirdsEye'))
                document.getElementById('divBirdsEye').style.left = (newMapWidth - 465) / 2 + 'px';

            if (document.getElementById('mapsearch-advisory-box')) {
                document.getElementById('mapsearch-advisory-box').style.left = (newMapWidth + 50) / 2 + 'px';
                document.getElementById('mapsearch-advisory-box').style.top = (newMapHeight - 50) / 2 + 'px';
            }
            if (document.getElementById('divSelectLocation'))
                document.getElementById('divSelectLocation').style.left = (newMapWidth - 300) / 2 + 'px';

            if (document.getElementById('MapWidth'))
                document.getElementById('MapWidth').value = newMapWidth;
            if (document.getElementById('mapsearch-right'))
                document.getElementById('mapsearch-right').style.width = newMapWidth + 9 + 'px';
            if (activeView == "gallery")
                self.setTimeout("resizeIFrameW(document.getElementById('SearchResultsFrame'), '100%')", 800);
            //try { positionAdvisory(); } catch (e) { }
        }
    }
}
map.getMapWidth = function()
{
		var x;
		if (self.clientWidth) // all except Explorer
			x = self.innerWidth;
		else if (document.documentElement && document.documentElement.clientWidth) // Explorer 6 Strict Mode
			x = document.documentElement.clientWidth;
		else if (document.body) // other Explorers
			x = document.body.clientWidth;

		x = x - resizeMapWidthDiff; 
		
		if (x < mapWidth) // New mapWidth should not be less than the configured mapWidth
		    x = mapWidth
		    
		return x;
}
map.getMapHeight = function()
{
		var x;
		if (self.clientHeight) // all except Explorer
			x = self.innerHeight;
		else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
			x = document.documentElement.clientHeight;
		else if (document.body) // other Explorers
			x = document.body.clientHeight;

		x = x - resizeMapHeightDiff; 
		
		if (x < mapHeight) // New mapHeight should not be less than the configured mapHeight
		    x = mapHeight;
		    
		return x;
}
map.moveDashboard = function(left)
{
    if(document.getElementById('MSVE_navAction_container'))
    {
        document.getElementById('MSVE_navAction_container').style.position = 'relative';
        document.getElementById('MSVE_navAction_container').style.left = left + 'px';
    }
}
map.getZoomLevel = function()
{
    return veMap.GetZoomLevel();
}
map.PanToLatLong = function(lat, lon, submit)
{
    veMap.vemapcontrol.PanToLatLong(lat,lon);
    submitForm = submit;
}
map.moveMap = function(lat, lon, zoom, submit)
{
    var LL = new VELatLong(lat, lon);
    veMap.SetCenterAndZoom(LL, zoom);
    //veMap.vemapcontrol.PanToLatLong(lat,lon);
    //self.setTimeout("veMap.SetZoomLevel(zoom)", 1000);   
    submitForm = submit;
}
map.setLatLongValues = function() {
    if (veMap) {//alert('set');
        var c = document.getElementById('divMap');
        var mapZoom = veMap.GetZoomLevel();

        ne_LatLong = veMap.PixelToLatLong(new VEPixel(c.offsetWidth, 0));
        sw_LatLong = veMap.PixelToLatLong(new VEPixel(0, c.offsetHeight));


        if (document.getElementById(globNELat)) document.getElementById(globNELat).value = ne_LatLong.Latitude;
        if (document.getElementById(globNELong)) document.getElementById(globNELong).value = ne_LatLong.Longitude;
        if (document.getElementById(globSWLat)) document.getElementById(globSWLat).value = sw_LatLong.Latitude;
        if (document.getElementById(globSWLong)) document.getElementById(globSWLong).value = sw_LatLong.Longitude;
        if (document.getElementById(globZoom)) document.getElementById(globZoom).value = mapZoom;

        //map.populateNeighborhoods(ne_LatLong.Latitude, ne_LatLong.Longitude, sw_LatLong.Latitude, sw_LatLong.Longitude, mapZoom);

        if (activeView != "map")
            submitForm = 0;
        if (submitForm != 0)
            map.submitSearch();

        submitForm = 1;
    }
}
map.submitSearch = function()
{
    if (document.getElementById('searchCriteria') && veMap.GetMapStyle() != VEMapStyle.Birdseye && document.getElementById('draw_cancel').style.display == 'none') 
	    Search.submit(); 
}
map.setView = function(view)
{
	switch(view)
	{
		case 'r':
			veMap.SetMapStyle(VEMapStyle.Shaded); // hill shaded road view
			break;
		case 's':
			veMap.SetMapStyle(VEMapStyle.Shaded); // hill shaded road view
			break;
		case 'h':
			veMap.SetMapStyle(VEMapStyle.Hybrid);
			break;
		case 'a':
			veMap.SetMapStyle(VEMapStyle.Aerial);
			break;
		case 'b':
		    if (veMap.IsBirdseyeAvailable())
		    {
			    veMap.SetMapStyle(VEMapStyle.Birdseye);
			    veMap.SetZoomLevel(2);   
			}
			else
			   veMap.SetMapStyle(VEMapStyle.Hybrid); 
			break;
		
	}
}

map.toggleProcessing = function(display)
{
    if (display == 1)
    {
        isProcessing = true;
        document.getElementById('divProcessing').style.visibility = 'visible';  
    }
    else
    {
        isProcessing = false;
        document.getElementById('divProcessing').style.visibility = 'hidden';  
    }
}

map.cacheArea = function()
{//alert('caching');
    // get coordinates

    var neLat = document.getElementById("NELat").value;
    var neLong = document.getElementById("NELong").value;
    var swLat = document.getElementById("SWLat").value;
    var swLong = document.getElementById("SWLong").value; 
    // store coordinates
    cachedCoordinates[0] = neLat;
    cachedCoordinates[1] = neLong;
    cachedCoordinates[2] = swLat;
    cachedCoordinates[3] = swLong;
}

map.isInCachedArea = function()
{
    // get coordinates
    var neLat = document.getElementById("NELat").value;
    var neLong = document.getElementById("NELong").value;
    var swLat = document.getElementById("SWLat").value;
    var swLong = document.getElementById("SWLong").value; 
    
    // check against stored coordinates
    if (neLat <= parseFloat(cachedCoordinates[0]) && 
        neLat >= parseFloat(cachedCoordinates[2]) &&
        neLong <= parseFloat(cachedCoordinates[1]) &&
        neLong >= parseFloat(cachedCoordinates[3]) &&
        swLat <= parseFloat(cachedCoordinates[0]) && 
        swLat >= parseFloat(cachedCoordinates[2]) &&
        swLong <= parseFloat(cachedCoordinates[1]) &&
        swLong >= parseFloat(cachedCoordinates[3]))
    {
        return true;
    }
    else
    {
        return false;
    }
}

map.Find = function(loc) // just find location and return results
{
    veMap.Find(null, loc, null, null, null, null, null, null, false, false, FindCallback);
    //VEMap.Find(what, where, findType, shapeLayer, startIndex, numberOfResults, showResults, createResults, useDefaultDisambiguation, setBestMapView, callback);
    //veMap.Find(null, val);
}
map.SmartFind = function(loc)
{
    if (loc != '' && loc != 'undefined')
    {
        if (loc.indexOf(",") > -1 && loc.substring(loc.indexOf(","),loc.length).length > 2)
            map.Goto(loc + ',usa');
        else
            map.Find(loc + ',usa'); 
    }
}
map.GotoFirst = function(loc,zoomin) // go to the first location found
{
    if (loc != '' && loc != 'undefined')
    {
        veMap.Find(null, loc, VEFindType.Businesses, null, null, null, null, null, true, true, null);
    }
    if (zoomin == 1)
        self.setTimeout("veMap.SetZoomLevel(map.getZoomLevel() + 2)", 500);
    self.setTimeout('map.setLatLongValues()',500);
}

map.Goto = function(loc) // Pan map to the location
{
    if (loc != '' && loc != 'undefined')
    {
        hide('divSelectLocation');
        SetCorrectCityValue(loc);
        map.GotoFirst(loc); 
    }
}
map.GotoAndFlag = function(loc) {
    pushpin.deletePin('1_999');
    map.GotoFirst(loc, 1);
    if (loc.length > 0) {   // add address pin
        self.setTimeout("pushpin.addPin('1_999', veMap.vemapcontrol.GetCenterLatitude(), veMap.vemapcontrol.GetCenterLongitude(), 34, '', '" + loc + "');", 1000); 
    }
}
map.ShowTraffic = function()         
{            
	map.LoadTraffic(true);            
	map.ShowTrafficLegend(50,50);            
	map.SetTrafficLegendText("Traffic");         
}         
map.ClearTraffic = function()         
{            
	map.ClearTraffic();         
}
function SetCorrectCityValue(loc)
{
    if (document.getElementById('SearchType') && document.getElementById('SearchType').value == 1 && document.getElementById('Search_SearchCriteria_City') && document.getElementById('Search_SearchCriteria_City').value != '')
    {
        if (loc.indexOf(",") > -1)
            loc = loc.substring(0,loc.indexOf(","));
        if (loc.indexOf("(") > -1)
            loc = loc.substring(0,loc.indexOf("("));
        document.getElementById('Search_SearchCriteria_City').value = loc;
    }
}
function FindCallback(layer, resultsArray, places, hasMore, veErrorMessage)
{
    var list = "";
    if (places.length > 1)
    {
        for(i=0;i<places.length;i++)
        {
            list+="<a href=\"javascript:map.Goto('" + places[i].Name + "')\">" + places[i].Name + "</a><br/><br/>";
        }   
        display('divSelectLocation');
        document.getElementById('divSelectLocationList').innerHTML = list;
    }
    else
        map.Goto(places[0].Name);
}
map.toggleParcelLines = function()
{
    if (veMap)
    {
        try
        {
            if (map.getZoomLevel() >= 16 && veMap.GetMapStyle() != VEMapStyle.Birdseye) // show parcel lines at zoom 16
            {
                //veMap.SetMapStyle(VEMapStyle.Hybrid);
                //add DMPs pws layer
                //SetParcelLayerVisibility(veMap, false);
                if (parecelSet == 0)
                {
                   if (typeof (veMap.parcelLayer) == "undefined")
                        AddDMPParcelLayer(veMap);
                    else
                       SetParcelLayerVisibility(veMap, true); 
                    parecelSet = 1;
                }   
            }
            else
            {
                parecelSet = 0;
                SetParcelLayerVisibility(veMap, false);
            }
            if (map.getZoomLevel() >= 17 || veMap.GetMapStyle() == VEMapStyle.Birdseye)
                display('MSVE_navAction_ObliqueMapView');
            else
                hide('MSVE_navAction_ObliqueMapView');
        }
        catch(e){}
    }
}
map.ShowMiniMap = function()
{
    map.ShowMiniMap(0, map.getMapHeight-150);
}
map.ShowMiniMap = function(x,y)
{
    if (veMap && view != 'b')
    {
        veMap.ShowMiniMap(x,y);    
        if (y != 'undefined' && y > 0 && document.getElementById('divMiniMapToggle'))
            document.getElementById('divMiniMapToggle').style.top = y+136;
        hide('MSVE_minimap_resize');
        hide('minimap_show');
        display('minimap_hide');
    }
    else
    {
        hide('minimap_show');
        hide('minimap_hide');   
    }
}
map.HideMiniMap = function()
{
    if (veMap)
    {
        veMap.HideMiniMap();    
        display('minimap_show');
        hide('minimap_hide');
    }
}
map.isPOIEnabled = function()
{
    if (document.getElementById('mapPOIControl'))
        return true;
    else
        return false;
}
map.toggleMapControl = function()
{
    if (document.getElementById('MSVE_lowerContainer'))
    {
        if (document.getElementById('MSVE_lowerContainer').style.visibility == 'hidden')
        {
            document.getElementById('MSVE_lowerContainer').style.visibility = 'visible';
            document.getElementById('MSVE_navAction_header').innerHTML = "<div id=toggleDashboard><a>Hide</a></div>";
        }
        else
        {
            document.getElementById('MSVE_lowerContainer').style.visibility = 'hidden';
            document.getElementById('MSVE_navAction_header').innerHTML = "<div id=toggleDashboard><a>Show</a></div>";
        }
    }
}
var arrayLocations;
map.GetDirections = function(arrLocations)
{
    arrayLocations = arrLocations;
    map.toggleProcessing(1); 
    var options = new VERouteOptions();            
    options.RouteCallback = onGotRoute;      
    // So the map doesn't change:
    if (document.getElementById('divRoute'))
        options.SetBestMapView = false;
    options.ShowDisambiguation = true;
    options.DistanceUnit   = VERouteDistanceUnit.Mile;
    //options.UseMWS = true;
    if (veMap)
        veMap.GetDirections(arrLocations, options);
    else
        self.setTimeout("veMap.GetDirections(arrLocations, options);", 1000); // wait and execute
}
function onGotRoute(route)         
{           
    var divDisplay = document.getElementById('divRoute');
    var divPrint = document.getElementById('divPrintRoute');
    var routeInfo="";  
	var legs     = route.RouteLegs;          
    var turnNum       = 0;  // The turn #
    if (divPrint)
	    routeInfo+= '<table width="100%" border="0" cellspacing="2" cellpadding="2" class="dd_txt">'; 
	else
	    routeInfo+= '<table width="175" border="0" cellspacing="2" cellpadding="2" class="dd_txt">'; 
	//routeInfo+= '<tr class="searchResults_colHeader"><td></td><td width="150">Direction</td><td width="30">Miles</td></tr>'
	routeInfo+= '<tr><td colspan="4" class="dd_tableHeader1">';
	routeInfo+= 'Total Distance: ' + route.Distance.toFixed(1) + ' miles';            
	routeInfo+= '<br/>Total Time: ' + GetTime(route.Time) + '</td></tr>';  
	for(var i = 0; i < legs.length ;i++)               
	{   
	    var leg = legs[i];   
	    var turn = null;
	    var legNum = i + 1;
	    
	    if (divPrint)
	    {
	            routeInfo += '<tr><td colspan="4" class="dd_tableHeader2" nowrap="nowrap"><b>From: </b>' + GetLocationFromArray(i) + 
                '<br/><b>To: </b>' + GetLocationFromArray(i+1) +
                //'<br/><b>Distance: </b>' + leg.Distance.toFixed(1) + ' miles' +
                '<br/><b>Time: </b>' + GetTime(leg.Time) + '</td></tr>';
	    }
	    else
	    {
            routeInfo += '<tr><td colspan="4" class="dd_tableHeader2" nowrap="nowrap"><b>From: </b>' + GetLocationFromArray(i).substring(0,20) + '...' + 
                '<br/><b>To: </b>' + GetLocationFromArray(i+1).substring(0,22) + '...' +
                //'<br/><b>Distance: </b>' + leg.Distance.toFixed(1) + ' miles' +
                '<br/><b>Time: </b>' + GetTime(leg.Time) + '</tr><td>';
        }
	    for(var j = 0; j < leg.Itinerary.Items.length; j ++)               
        {   
            turn = leg.Itinerary.Items[j];
		    routeInfo+= '<tr>';
    		
		    if (i == 0 && j == 0)
			    routeInfo+= '<td align="center" class="hseparator"><img src="/Map/Images/DrivingDirection/pin_Start.gif"/></td>'
		    else if (i == legs.length-1 && j == leg.Itinerary.Items.length-1)
			    routeInfo+= '<td align="center" class="hseparator"><img src="/Map/Images/DrivingDirection/pin_End.gif"/></td>'
		    else
			    routeInfo+= '<td align="center" class="hseparator"><div class="dd_number">' + turnNum + '</div></td>'
		    routeInfo+= '<td class="hseparator">' + turn.Text + '</td>';                  
		    routeInfo+= '<td class="hseparator">';
		    if (turn.Distance != null)
			    routeInfo+= turn.Distance.toFixed(1);                  
		    routeInfo+= '</td></tr>';
		    turnNum++;
		}
	}            
	routeInfo+= '</table>';
	
	if (DrivingDirection)
	    DrivingDirection.SetDirections(routeInfo);
	map.toggleProcessing(0); 
	
} 
/*
function onGotRoute(route)         
{           
    // Unroll route           
    var legs     = route.RouteLegs;           
    var turns    = "<b>Total distance: " + route.Distance.toFixed(1) + " mi</b><br/>";           
    var numTurns = 0;           var leg      = null;           
    
    // Get intermediate legs            
    for(var i = 0; i < legs.length; i++)            
    {               
        // Get this leg so we don't have to derefernce multiple times               
        leg = legs[i];  // Leg is a VERouteLeg object                                 
        // Unroll each intermediate leg               
        var turn = null;  // The itinerary leg                                 
        for(var j = 0; j < leg.Itinerary.Items.length; j ++)               
        {                  
            turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object                  
            numTurns++;                  
            turns += numTurns + ". " + turn.Text + " (" + turn.Distance.toFixed(1) + " mi)<br/>";               
        }            
    }            
           
}
*/
function GetTime(time)
{
    if(time == null)
    {
       return("");
    }

    if(time > 60)
    {                                 // if time == 100
       var seconds = time % 60;       // seconds == 40
       var minutes = time - seconds;  // minutes == 60
       minutes     = minutes / 60;    // minutes == 1


       if(minutes > 60)
       {                                     // if minutes == 100
          var minLeft = minutes % 60;        // minLeft    == 40
          var hours   = minutes - minLeft;   // hours      == 60
          hours       = hours / 60;          // hours      == 1

          return(hours + " hrs, " + minLeft + " mins, " + seconds + " secs");
       }
       else
       {
          return(minutes + " mins, " + seconds + " secs");
       }
    }
    else
    {
       return(time + " secs");
    }
}
        
function GetLocationFromArray(num)
{
    return arrayLocations[num];
}


map.plotComps = function(latLons) {
    try
    {
        trap = function() { return true; }
        veMap.AttachEvent("onmousewheel", trap);
    }
    catch(e){}
    var arrLatLon = latLons.split(':');
    var len = arrLatLon.length;
    for (var i = 0; i < len; i++) {
        if (arrLatLon[i] == '')
            continue;
        var latLon = arrLatLon[i].split(',');
        var lat = latLon[0];
        var lon = latLon[1];
        if (lat != '' && lon != '' && lat != 'undefined' && lon != 'undefined')
            pushpin.addPin('comp_' + i, lat, lon, 'listing_' + (i + 1), '', '');
    }
}

map.populateNeighborhoods = function(neLat, neLon, swLat, swLon, zoom)
{
    var div = document.getElementById('divNeighborhood');
    if (!div)
        return;
        
    var obj = document.getElementById('Neighborhood');
    //obj.length = 0; // cleanup the dropdown
    if (map.getZoomLevel() >= 10 && veMap.GetMapStyle() != VEMapStyle.Birdseye) 
    {
        message.displayLoading('NeighborhoodLoading', 12);
        obj.style.display = 'none';
        message.setInnerHTML('divNeighborhoodInfo', 'Retrieving Neighborhoods in this Area');
        GetNeighborhoods('nelat=' + neLat + '&nelon=' + neLon + '&swlat=' + swLat + '&swlon=' + swLon + '&zoom=' + zoom, obj);
    }
    else
    {
        obj.style.display = 'none';
        message.setInnerHTML('divNeighborhoodInfo', 'Zoom in to view Neighborhoods');
        message.setTitle('icNeighborhoodInfo', 'Zoom in to view Neighborhoods'); 
    }
}
var xmlhttp_n;
function GetNeighborhoods(qs, obj)
{
    xmlhttp_n = null;
    if (qs == 'undefined' || qs == '')
        return;
    // prepare AJAX call
    var url = '/Map/AJAX/GetBoundary.aspx?neighborhoods=1&cid=' + companyID + '&' + qs;

    xmlhttp_n = ajax.GetXmlHttpObject();
    xmlhttp_n.open('GET', url, true);
    xmlhttp_n.onreadystatechange = function() 
    {
        if (xmlhttp_n.readyState != 4 || xmlhttp_n.status != 200)  { return; }
        try 
        {
            var neighborhoods = xmlhttp_n.responseText;
            if (!obj)
                return;
            obj.length = 0; // cleanup the dropdown
            if (neighborhoods == 'undefined' || neighborhoods.length <= 0)
            {
                obj.style.display = 'none';
                message.setInnerHTML('divNeighborhoodInfo', 'No Neighborhood Found');
                message.setTitle('icNeighborhoodInfo', 'No Neighborhood Found'); 
                return;
            }
            var arrNeighborhoods = neighborhoods.split(';');
            var len = arrNeighborhoods.length;
            var selVal = document.getElementById('selNeighborhood').value; 
            if (len > 0)
            {
                
                message.setTitle('icNeighborhoodInfo', 'The list below shows all neighborhoods in the nearby map area. Select a neighborhood to see it outlined on the map or zoom out the map to see more neighborhoods.'); 
                addOption(obj, new Option('- Select Neighborhood -',""));
           
                for(var i=0; i<len; i++)
                {
                    var neighborhood = arrNeighborhoods[i].split(':');
                    var opt = document.createElement('option');
                    opt.text = neighborhood[1];
                    opt.value = neighborhood[0];
                    if (neighborhood[0] == selVal)
                        opt.selected = "selected";
                    //alert(i + ': ' + neighborhood[1] + " - " + neighborhood[0]);
                    addOption(obj, opt);
                }
                
                hide('divNeighborhoodInfo');
                obj.style.display = ''; 
            }
        } 
        catch(e) 
        {
            obj.style.display = 'none';
            message.setInnerHTML('divNeighborhoodInfo', e.message);
        }
        finally
        {
            message.hideLoading('NeighborhoodLoading');
            xmlhttp_n = null;
        }
    }   
     xmlhttp_n.send(null);
}
