// Global variables to mark the sector and the map.
var currentViewId = "all";
var currentMapId = "map1";

// The sectors.
var viewLabels = new Object();
viewLabels['all'] = "GCRO";
viewLabels['rsd'] = "RSD";
viewLabels['education'] = "Education";
viewLabels['health'] = "Health / Hospitals";
viewLabels['historic'] = "Historic / Cultural";
viewLabels['works'] = "Public Works";
viewLabels['safety'] = "Public Safety / Criminal Justice";

// The searches.
var searchLabels = new Hash();
searchLabels.set('keyword', 'By facility name');
searchLabels.set('jurisdiction', 'By county/parish');
searchLabels.set('congressional', 'By congressional district');
searchLabels.set('cityPlaces', 'By city');
searchLabels.set('project', 'By project number');
searchLabels.set('address', 'By address (5 mile radius)');
searchLabels.set('disaster', 'By disaster');

// The searchers.
var searchers = new Hash();

// The form HTML for the different searches.
var searchFormHTMLs = new Hash();

// Has the search panel been already created?
var searchPanelCreated = false;

// The active searcher.
var activeSearcher;

// Set up the event handlers for the sector switches. The 'click' event will be
// handled for all the tabs named by 'ids'.
var ids = ["all", "rsd", "education", "health", "historic", "works", "safety"];
YAHOO.util.Event.addListener(ids, "click", showSectorByClickingSectorTab);

// Set up the event handler for the "View Public Assistance..." link in all.html.
// The callback function will simulate the user navigating to the RSD tab.
YAHOO.util.Event.addListener("viewpa", "click", showSectorByClickingViewPALink);

function showSectorByClickingSectorTab(e) {
    showSector(this.id);
}

function showSectorByClickingViewPALink(e) {
    // Set the active tab to the RSD.
    tabView.set('activeIndex', 1);
    
    // Do the other housekeeping work associated with switching a sector.
    showSector("rsd");
}

function showSector(sectorId) {
    // Set the current view id for future reference.
    currentViewId = sectorId;
    
    // Prepare the request for turning the desired layer on.
    var requestParameters = new Array();
    requestParameters.push("x=-1");
    requestParameters.push("y=-1");
    
    // Set up the wait message.
    var waitMessage = "Performing operation, please wait...";

    // Issue the request for turning the desired layer on.
    GCROUtils.performCommand("composite.jsf", true, "switch", currentViewId, 
        requestParameters, MapUpdateResponseHandler, waitMessage);
    
    // Hide the controls in the case of rsd.  
    if (viewLabels[currentViewId] == "RSD") {
    	$('mapviewcontrols').style.display='none';
    } else {
    	$('mapviewcontrols').style.display='inline';
    }
}

// Initialize the tab view.
var tabView = new YAHOO.widget.TabView("contentTabs");

