
//This is a nearly clone version of heatmap.js, so that the preview map work parralel with the main heatmap on the main page

var CWjustCheckAll=false;
	
function CWtoggleOverlay(carrier, show)
{   
    var ind;
    if(CWjustCheckAll==true)
    {
        for(ind=0; ind < maxcarrier; ind++)
        {
            CWcarrierDisplay[ind]=false;           
        }
        
        CWjustCheckAll=false;
        
        CWtoggleOverlay(carrier,show);
        
        return;
    }
    
    //alert('toggle overlay');
    //determine the index of this carrier  
    index=-1;
    for(ind=0; ind< maxcarrier; ind++)
    {
        if (carrierID[ind]==carrier)
        {
            index=ind;
            break;
        }
    }
    
    //toggle this carrier's displayability
    if(index!=-1)
        CWcarrierDisplay[index]=show;    
    
    //reset query strings
    carriers="";
    colors="";
    
    
    
    //make up query strings
    for(ind=0; ind < maxcarrier; ind++)
    {  
        if(CWcarrierDisplay[ind]==true)
        {
            carriers += carrierID[ind] + "_";
            colors += color[ind] + "_";
        }
    }   
        
        
    //create and replace overlay        
    bounds = new GLatLngBounds( new GLatLng(-90, -180), new GLatLng(90, 180));
    copyright = new GCopyright( 'MaxMindLLC', bounds, 0, "(c) 2008 MaxMindLLC" + "<http://www.example.org/>");
    copyrights = new GCopyrightCollection();
    copyrights.addCopyright(copyright);            
    CWheatmap = new GTileLayer(copyrights, 10, 0);
    CWheatmap.getTileUrl = function (tile, zoom) 
        {                                           
        url = 'GetHeatMap.aspx?';             
        startpixx = tile.x * 256 - 90; 
        endpixx = tile.x * 256 + 256 + 90;            
        startpixy = tile.y * 256 - 90; 
        endpixy = tile.y * 256 + 256 + 90;                    
                    
        currentProjection = G_NORMAL_MAP.getProjection();                
        gp1=currentProjection.fromPixelToLatLng(new GPoint(startpixx, startpixy),zoom);
        gp2=currentProjection.fromPixelToLatLng(new GPoint(endpixx, endpixy),zoom);                             
        		    
        url += "frLat=" + gp1.lat(); 
        url += "&toLat=" +  gp2.lat();       
        url += "&frLong=" +  gp1.lng();
        url += "&toLong=" + gp2.lng();
        url += "&imgWidth=" + 256;
        url += "&imgHeight=" + 256;
        url += "&colorScheme=" + colors;
        url += "&carrier=" + carriers;
        url += "&zoom=" + zoom;
        url += "&cacheInfo=" + zoom + "-" + tile.x + "-" + tile.y + "-" + carriers + "-" + colors;        
        return url;			
        }
    CWheatmap.isPng = function () {return true;}
    CWheatmap.getOpacity = function () {return 1.0;}              
    if(CWMHMoverlay)
        CWmap.removeOverlay(CWMHMoverlay);
    CWMHMoverlay=new GTileLayerOverlay(CWheatmap);      
    CWmap.addOverlay(CWMHMoverlay);	                    
    CWrefreshComments();
}

function CWisCarrierChecked(cariName)
{    
    var j=0;
    for(j=0; j< maxcarrier; j++)
    {
        if (carrierName[j] == cariName) //why not trim()?
        {
            return CWcarrierDisplay[j];
            break;            
        }
    }
    return false;
}

function CWisCarrierIDChecked(cariID)
{
    var j=0;
    for(j=0; j< maxcarrier; j++)
    {
        if (carrierID[j] == cariID)
        {
            return CWcarrierDisplay[j];
            break;            
        }
    }
    return false;
}