﻿var grid=false;


function initializeMap(elemID) {

    var lat=52.119998657638156 //start map in edmonton
    var lng=-113.5986328125;      
    

    
    if (GBrowserIsCompatible()) {
    
        if (grid) {
            var mapcontainer = document.getElementById(elemID);
            mapcontainer.style.position="absolute";
            mapcontainer.style.top="0px";
            mapcontainer.style.left="0px";
            mapcontainer.style.width="100%";
            mapcontainer.style.height="100%";
        }
        //restrict zoom options...
        var mapTypes = G_DEFAULT_MAP_TYPES;
        for(var i = 0; i < mapTypes.length; i++) {
            mapTypes[i].getMaximumResolution = function(latlng){ return 15;};
            mapTypes[i].getMinimumResolution = function(latlng){ return 8;};
        }
        //init map
        var map = new GMap2(document.getElementById(elemID));
        map.setCenter(new GLatLng(lat, lng), 10);            
        map.setMapType(G_PHYSICAL_MAP );
        
        
        //UI Options
        var customUI = map.getDefaultUI();
        customUI.maptypes.physical=true;
        customUI.maptypes.normal=true;
        customUI.maptypes.satellite=true;
        customUI.maptypes.hybrid=true;
        
        map.setUI(customUI);
        
        //custom overlays
        
        
        var tilelayer = new GTileLayer(new GCopyrightCollection(), 0, 17);
        tilelayer.getTileUrl = function(tile, zoom) {
            if (grid) {
                return "http://maps.csg.ca/tiles/GridTile.ashx?x="+tile.x+"&y="+tile.y+"&s="+zoom;
                
            } else {                
                return "http://maps.csg.ca/tiles/overlay/"+tile.x+"-"+tile.y+"-"+zoom+".png";
            }
               
        };
        //tilelayer.getOpacity = function() {return 0.5;}
        map.addOverlay(new GTileLayerOverlay(tilelayer));

        map.enableContinuousZoom();       
        return map;
    } else {
        return null;
    }
}



function initializeMapCalgary(elemID) {

    var lat=50.870978137947134 //start map in calgary
    var lng=-114.05731201171875;      
 


    if (GBrowserIsCompatible()) {
    
        if (grid) {
            var mapcontainer = document.getElementById(elemID);
            mapcontainer.style.position="absolute";
            mapcontainer.style.top="0px";
            mapcontainer.style.left="0px";
            mapcontainer.style.width="100%";
            mapcontainer.style.height="100%";
        }
        //restrict zoom options...
        var mapTypes = G_DEFAULT_MAP_TYPES;
        for(var i = 0; i < mapTypes.length; i++) {
            mapTypes[i].getMaximumResolution = function(latlng){ return 9;};
            mapTypes[i].getMinimumResolution = function(latlng){ return 4;};
        }
        //init map
        var map = new GMap2(document.getElementById(elemID));
        map.setCenter(new GLatLng(lat, lng), 10);            
        map.setMapType(G_PHYSICAL_MAP );
        
        
        //UI Options
        var customUI = map.getDefaultUI();
        customUI.maptypes.physical=true;
        customUI.maptypes.normal=true;
        customUI.maptypes.satellite=true;
        customUI.maptypes.hybrid=true;
        
        map.setUI(customUI);
        
        //custom overlays
        
        
        var tilelayer = new GTileLayer(new GCopyrightCollection(), 0, 17);
        tilelayer.getTileUrl = function(tile, zoom) {
            if (grid) {
                return "http://maps.csg.ca/tiles/GridTile.ashx?x="+tile.x+"&y="+tile.y+"&s="+zoom;
                
            } else {                
                return "http://maps.csg.ca/tiles/overlay/"+tile.x+"-"+tile.y+"-"+zoom+".png";
            }
               
        };
        //tilelayer.getOpacity = function() {return 0.5;}
        map.addOverlay(new GTileLayerOverlay(tilelayer));

        map.enableContinuousZoom();       
        return map;
    } else {
        return null;
    }
}




function initializeMapEdmonton(elemID) {

    var lat=53.54432388395904 //start map in edmonton
    var lng=-113.48958492279053;      
    


    if (GBrowserIsCompatible()) {
    
        if (grid) {
            var mapcontainer = document.getElementById(elemID);
            mapcontainer.style.position="absolute";
            mapcontainer.style.top="0px";
            mapcontainer.style.left="0px";
            mapcontainer.style.width="100%";
            mapcontainer.style.height="100%";
        }
        //restrict zoom options...
        var mapTypes = G_DEFAULT_MAP_TYPES;
        for(var i = 0; i < mapTypes.length; i++) {
            mapTypes[i].getMaximumResolution = function(latlng){ return 9;};
            mapTypes[i].getMinimumResolution = function(latlng){ return 4;};
        }
        //init map
        var map = new GMap2(document.getElementById(elemID));
        map.setCenter(new GLatLng(lat, lng), 10);            
        map.setMapType(G_PHYSICAL_MAP );
        
        
        //UI Options
        var customUI = map.getDefaultUI();
        customUI.maptypes.physical=true;
        customUI.maptypes.normal=true;
        customUI.maptypes.satellite=true;
        customUI.maptypes.hybrid=true;
        
        map.setUI(customUI);
        
        //custom overlays
        
        
        var tilelayer = new GTileLayer(new GCopyrightCollection(), 0, 17);
        tilelayer.getTileUrl = function(tile, zoom) {
            if (grid) {
                return "http://maps.csg.ca/tiles/GridTile.ashx?x="+tile.x+"&y="+tile.y+"&s="+zoom;
                
            } else {                
                return "http://maps.csg.ca/tiles/overlay/"+tile.x+"-"+tile.y+"-"+zoom+".png";
            }
               
        };
        //tilelayer.getOpacity = function() {return 0.5;}
        map.addOverlay(new GTileLayerOverlay(tilelayer));

        map.enableContinuousZoom();       
        return map;
    } else {
        return null;
    }
}



function initializeMapRedDeer(elemID) {

    var lat=52.266741//start map in RedDeer
    var lng=-113.802295;      
    
    


    if (GBrowserIsCompatible()) {
    
        if (grid) {
            var mapcontainer = document.getElementById(elemID);
            mapcontainer.style.position="absolute";
            mapcontainer.style.top="0px";
            mapcontainer.style.left="0px";
            mapcontainer.style.width="100%";
            mapcontainer.style.height="100%";
        }
        //restrict zoom options...
        var mapTypes = G_DEFAULT_MAP_TYPES;
        for(var i = 0; i < mapTypes.length; i++) {
            mapTypes[i].getMaximumResolution = function(latlng){ return 24;};
            mapTypes[i].getMinimumResolution = function(latlng){ return 12;};
        }
        //init map
        var map = new GMap2(document.getElementById(elemID));
        map.setCenter(new GLatLng(lat, lng), 10);            
        map.setMapType(G_PHYSICAL_MAP );
        
        
        //UI Options
        var customUI = map.getDefaultUI();
        customUI.maptypes.physical=true;
        customUI.maptypes.normal=true;
        customUI.maptypes.satellite=true;
        customUI.maptypes.hybrid=true;
        
        map.setUI(customUI);
        
        //custom overlays
        
        
        var tilelayer = new GTileLayer(new GCopyrightCollection(), 0, 17);
        tilelayer.getTileUrl = function(tile, zoom) {
            if (grid) {
                return "http://maps.csg.ca/tiles/GridTile.ashx?x="+tile.x+"&y="+tile.y+"&s="+zoom;
                
            } else {                
                return "http://maps.csg.ca/tiles/overlay/"+tile.x+"-"+tile.y+"-"+zoom+".png";
            }
               
        };
        //tilelayer.getOpacity = function() {return 0.5;}
        map.addOverlay(new GTileLayerOverlay(tilelayer));

        map.enableContinuousZoom();       
        return map;
    } else {
        return null;
    }
}

function initializeMapSubdiv(elemID, slat, slng) {

    var lat = slat //start map in edmonton
    var lng = slng;      
    
    if (GBrowserIsCompatible()) {
    
        if (grid) {
            var mapcontainer = document.getElementById(elemID);
            mapcontainer.style.position="absolute";
            mapcontainer.style.top="0px";
            mapcontainer.style.left="0px";
            mapcontainer.style.width="100%";
            mapcontainer.style.height="100%";
        }
        //restrict zoom options...
        var mapTypes = G_DEFAULT_MAP_TYPES;
        for(var i = 0; i < mapTypes.length; i++) {
            mapTypes[i].getMaximumResolution = function(latlng){ return 26;};
            mapTypes[i].getMinimumResolution = function(latlng){ return 14;};
        }
        //init map
        var map = new GMap2(document.getElementById(elemID));
        map.setCenter(new GLatLng(lat, lng), 10);            
        map.setMapType(G_PHYSICAL_MAP );
        
        
        //UI Options
        var customUI = map.getDefaultUI();
        customUI.maptypes.physical=true;
        customUI.maptypes.normal=true;
        customUI.maptypes.satellite=true;
        customUI.maptypes.hybrid=true;
        
        map.setUI(customUI);
        
        //custom overlays
        
        var tilelayer = new GTileLayer(new GCopyrightCollection(), 0, 17);
        tilelayer.getTileUrl = function(tile, zoom) {
            if (grid) {
                //return "http://maps.csg.ca/tiles/GridTile.ashx?x="+tile.x+"&y="+tile.y+"&s="+zoom;
                
            } else {                
                //return "http://maps.csg.ca/tiles/overlay/"+tile.x+"-"+tile.y+"-"+zoom+".png";
            }
               
        };
        //tilelayer.getOpacity = function() {return 0.5;}
        map.addOverlay(new GTileLayerOverlay(tilelayer));

        map.enableContinuousZoom();       
        return map;
    } else {
        return null;
    }
}



/*
function addCommas(nStr)
{
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
	    x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
*/



