var isFirstTime = true;

function onDoubleClickObject(mapObject)
{

    //make sure a user is logged in before handling this event.
    //to check that user is logged the page displayed in the "menu"
    //frame will not be ???.aspx
    //if( document.location.href.indexOf("Viewer.aspx") > 0 )
    //    return;
	
	var map = getMap();
	var selection = map.getSelection();

	var mgCollection = selection.getMapObjectsEx(mapObject.getMapLayer().getName());
	if(mgCollection.isEmpty()){
		return;
	}
		
	if(mapObject.getMapLayer().getLayerSetup() == null) {
		return;
	}
	
	var strDebug = "The Id Value: " + mapObject.getKey();
	strDebug += "\nThe Legend Value: " + mapObject.getMapLayer().getLegendLabel();	
	strDebug += "\nThe Layer Name: " + mapObject.getMapLayer().getName();
	strDebug += "\nThe Key Column Name: " + mapObject.getMapLayer().getLayerSetup().getSdpKeyColumn();
	strDebug += "\nThe Table Name: " + mapObject.getMapLayer().getLayerSetup().getSdpFeatureTable();
	//alert(strDebug);      
		
    var url = "./Reports/political_report.aspx?layer="+mapObject.getMapLayer().getName()+"&district="+mapObject.getKey();
    url += "&IdColumn="+mapObject.getMapLayer().getLayerSetup().getSdpKeyColumn();
    url += "&LegendLabel="+mapObject.getMapLayer().getLegendLabel();
    var options = "status=no,toolbar=no,directories=no,scrollbars=yes,menubar=no,resizable=yes,width=355,height=340";
    openWindow(url, "report", options);
    
    
}

function onViewChanging(map){
	
	//toggleLayers(map);
	//toggleGroups(map);
   
}
function onViewChanged( map){
	
	if(isFirstTime){
		map.setAutoRefresh(false);	
		toggleLayers(map);
		toggleGroups(map);
		map.setAutoRefresh(true);
		isFirstTime = false;
		map.refresh();
	}
}
function toggleLayers( map){
   var col = map.getMapLayers();   
   for(i = 0; i < col.size(); i++){
		var obj = col.item(i);	
		for(j = 0; j < showLayers.length; j++){
			var layerName = showLayers[j].split('|')[0];
			if(obj.getName() == layerName){
				obj.setVisibility((showLayers[j].split('|')[1] == 'On'));
				obj.setShowInLegend(true);
			}
        }
   }   
}


function toggleGroups( map){
   var col = map.getMapLayerGroups();   
   for(i = 0; i < col.size(); i++){
		var obj = col.item(i);	
		//alert('Group Name: ' +obj.getName());
		for(j = 0; j < showLayers.length; j++){
			var layerName = showLayers[j].split('|')[0];
			if(obj.getName() == layerName){
				obj.setVisibility((showLayers[j].split('|')[1] == 'On'));
				obj.setShowInLegend(true);
			}
        }
   }   
}

function onMapLoaded( map)
{
	isFirstTime = true;
   //alert('onMapLoaded');
}
function onBeginLayout( p,s)
{
   //alert('onBeginLayout');
}

