var _mappingInProgress = false;

function startUp() {
    getPolygons();
}
function getValueFromDDL(ddl)
{
    return ddl.options[ddl.selectedIndex].value;
}
function getPolygons()
{
    var startDate = getStartDate();
         
    setAndShowMessage('Loading Map Data...');    
        
    _mappingInProgress = true;
    
    map.clearOverlays();
        
    $.get('PickupHistoryDataRetriever.axd', { startdate: startDate  },
        function(polygons)
        {                        
            setAndShowMessage('Found and mapping ' + polygons.length + ' area(s).');
            
            //var currentPosition = 1;
                       
            $.each(polygons, function(i, pup) {
                addPolygonToMap(pup);
                //currentPosition++;
            });
            
            if (polygons.length > 0)
                setAndShowMessage(polygons.length + ' area(s) successfully mapped.');
            else
                setAndShowMessage('No areas to map for this date.');
            
        }, "json"
      );
      
      _mappingInProgress = false;
}
function setAndShowMessage(message) {
    $('#avlLoadingText:visible').show();
    $('#avlLoadingText').attr('innerHTML', message);
}
function addPolygonToMap(pup)
{
    var polyArray = new Array();
        
    $.each(pup.PolygonPoints, function(i, polyPoint) {
        polyArray.push(new GLatLng(polyPoint.Latitude, polyPoint.Longitude));       
    });
        
    var polygon = new GPolygon(polyArray, "#000", 2, 1, "#ff0000", 0.2);
    map.addOverlay(polygon); 
}

