﻿/********************************************************************
 *
 * Manages Incidents RSSs
 * Author: TTI, Gabriel Torres
 * Date:   January 25, 2008
 *
 *******************************************************************/

var veLayerIncidents = new VEShapeLayer();
//incident refresh rate 
var iIncidentRefRate = 300000;  //5 minute
var kIncidentRSSFile = "RSS/Incidents.xml?";

// Configure message signs icons
// Created: Gabriel, 5/15/07
function ConfigureIncidentIcons(layer)
{
    var sTite, sStatus;
    var iShapes = layer.GetShapeCount();
    for(var i=0; i < iShapes; ++i) {
        var shape = layer.GetShapeByIndex(i);
        sTitle = shape.GetTitle();
        sStatus = sTitle.substring(sTitle.length-1,sTitle.length);        
    
        if (sStatus == "*")    
        {
            shape.SetCustomIcon("<img src='../Images/clearedincident.gif' />");
            sTitle = sTitle.substring(0,sTitle.length-1);
            shape.SetTitle(sTitle);
        }
        else
            shape.SetCustomIcon("<img src='../Images/activeincident.gif' />");
    }
}

// Load incident xml
// Created: Gabriel, 7/24/07
function LoadIncidents(go)
{   
    showProgressIndicator("Updating incidents");
    if (!go)
        setTimeout(function() { LoadIncidents(1); }, iAsyncDelay);
    else {
        veLayerIncidents.DeleteAllShapes();      
        var veShapeSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, 
                            kIncidentRSSFile + GetRan(), veLayerIncidents);
        map.ImportShapeLayerData(veShapeSpec, ConfigureIncidentIcons, false);
        window.status = "Incidents updated";
        hideProgressIndicator();
    }
}