// JScript File

/*******************************************************************************/
// Global properties

    var overlayCount=0;

    var map;		    // the Google map
	var groups = 0;		// number of groups
	var overlays = [];  // keep track of group overlays
	var GLogON = false;
	GLogON = true;
	var activeTab_arr;
	var activeLayers = [];
	var t;
	
    var startTime = new Date();      // start time to keep track of performance
    var debugPerformance = 0;
    var countThreadAJAX = 0;
    var countThreadAJAX2 = 0;
    var countThreadAJAXForGrid = 0;
    var debugThreadAJAX = 0;

	var ck_toolbar;
	var ck_legend;
	var ck_zoom;
	var ck_center;
	var ck_advisories;
	var ck_bordercameras;
	var ck_portcameras;
	var ck_trafficcameras;
	var ck_bordercrossings;
	var ck_ferryterminals;
	var ck_airport;
	var ck_portofvancouver;
	var ck_weather;
	var ck_transitstations;
	var ck_transitbusroutes;
	var ck_skytrainroutes;
	var ck_truckroutes;
	var ck_dangerousgoodsroutes;

	var ck_boundaries;
	var ck_bikeroute1;
	var ck_westcoastexpress;

	var previousCenterPoint;
	var originalInfoCenterPoint;
	
	var infoWindowHasBeenOpened = false;

    var previousZoom;

    // The allowed region which the whole map must be within
    var allowedBounds = new GLatLngBounds(new GLatLng(48.70,-124.05), new GLatLng(50.2,-122.15));
    
    // Cookies Name used for Map interaction with Grid related
	// x1,y1 being southwest coordinate
	// x2,y2 being northeast coordinate
	var x1CookieName = 'x1MapSWCoordinate';
	var x2CookieName = 'y1MapSWCoordinate';
	var y1CookieName = 'x2MapNECoordinate';
	var y2CookieName = 'y2MapNECoordinate';
	var PanOrZoomPostbackCookieName = 'PanOrZoomPostbackCookieName';
	var ZoomLevelCookieName = 'ZoomLevelCookieName';
	
	// Used for the bus routes grid
	var activeBusRoutesCookieName = 'activeBusRoutes';
	var highlightBusRouteCookieName = 'highlightBusRoute';
	var activeBusRoutesStopsCookieName = 'activeBusRoutesStops';
	
	// Used for the full screen bus routes grid
	var FSactiveBusRoutesCookieName = 'FSactiveBusRoutes';
	var FShighlightBusRouteCookieName = 'FShighlightBusRoute';
	var FSactiveBusRoutesStopsCookieName = 'FSactiveBusRoutesStops';	
	
	var TEMPactiveBusRoutesCookieName = 'TEMPactiveBusRoutes';
	var TEMPactiveBusRoutesStopsCookieName = 'TEMPactiveBusRoutesStops';
	
	var savedBusRoutesCookieName = 'savedBusRoutesCookieName';
	var savedBusRoutesStopsCookieName = 'savedBusRoutesStops';	
	
	var savedMotoristsBusRoutesCookieName = 'savedMotoristsBusRoutes';
	var savedMotoristsBusRoutesStopsCookieName = 'savedMotoristsBusRoutesStops';	
	var savedTransitBusRoutesCookieName = 'savedTransitBusRoutesCookieName';
	var savedTransitBusRoutesStopsCookieName = 'savedTransitBusRoutesStops';	
	var savedCyclingBusRoutesCookieName = 'savedCyclingBusRoutes';
	var savedCyclingBusRoutesStopsCookieName = 'savedCyclingBusRoutesStops';	
	var savedGatewaysBusRoutesCookieName = 'savedGatewaysBusRoutes';
	var savedGatewaysBusRoutesStopsCookieName = 'savedGatewaysBusRoutesStops';	
	var savedVisitorsBusRoutesCookieName = 'savedVisitorsBusRoutes';
	var savedVisitorsBusRoutesStopsCookieName = 'savedVisitorsBusRoutesStops';	
	var savedCommericalBusRoutesCookieName = 'savedCommericalBusRoutes';
	var savedCommercialBusRoutesStopsCookieName = 'savedCommercialBusRoutesStops';	

    
    var activeMotoristsLayersCookieName = 'activeMotoristsLayers';
    var activeTransitLayersCookieName = 'activeTransitLayers';
    var activeCyclingLayersCookieName = 'activeCyclingLayers';
    var activeGatewaysLayersCookieName = 'activeGatewaysLayers';
    var activeVisitorsLayersCookieName = 'activeVisitorsLayers';
    var activeCommericalsLayersCookieName = 'activeCommercialLayers';                    

    // Use to transfer active layers between 3/4 size map and full size map
    var activeFullScreenLayersCookieName = 'activeFullScreenLayers';         

    // Cookie names used for interactive map full screen
    var FullScreenMapCenterCookieName = 'FullScreenMapCenterCookieName'; 
    var FullScreenZoomLevelCookieName = 'FullScreenZoomLevelCookieName';  
    
    // Cookie names used for storing Pan/Zoom values per tab for regular map
    var MotoristsMapCenterCookieName = 'MotoristsMapCenterCookieName'; 
    var MotoristsZoomLevelCookieName = 'MotoristsZoomLevelCookieName';  
    var TransitMapCenterCookieName = 'TransitMapCenterCookieName'; 
    var TransitZoomLevelCookieName = 'TransitZoomLevelCookieName';  
    var CyclingMapCenterCookieName = 'CyclingMapCenterCookieName'; 
    var CyclingZoomLevelCookieName = 'CyclingZoomLevelCookieName';  
    var GatewaysMapCenterCookieName = 'GatewaysMapCenterCookieName'; 
    var GatewaysZoomLevelCookieName = 'GatewaysZoomLevelCookieName';  
    var VisitorsMapCenterCookieName = 'VisitorsMapCenterCookieName'; 
    var VisitorsZoomLevelCookieName = 'VisitorsZoomLevelCookieName';  
    var CommercialMapCenterCookieName = 'CommercialMapCenterCookieName'; 
    var CommercialZoomLevelCookieName = 'CommercialZoomLevelCookieName';  


    var FullScreenBusRoutesFlagCookie = 'FullScreenBusRoutesFlag';  
    
    var iMoveVersionCookieName = 'iMoveVersionCookie';  
    var iMoveVersion = '3.6';      

    var iMoveTestingCookieName = 'iMoveTestingCookie';  
    
    var iMoveIEBrowserNoticeCookieName = 'iMoveIEBrowserNoticeCookie';  
    var iMoveSafariBrowserNoticeCookieName = 'iMoveSafariBrowserNoticeCookie';  

    // Used to store which datagrid tab we are working on
    //var DataGridTabCookieName = 'DataGridTabCookieName';

    // default service for retrieving XML data response for the grid or map
    // This declaration needs to come before the "xmlRootPathCommon" declaration.
    var xmlRootPathService ="/ATISServices/Services/";

    // default path for retrieving XML data for the grid or map
    var xmlRootPathCommon = "";
    
    retrieveResourceLocation('XmlFilesUrl');
    
    var xmlRootPathBusRoutes = "";
    retrieveResourceLocationBusRoutes('XmlFilesUrlForBusRoutes');
    
    // Used to retrieve system parameters table values from database
    var GlobalSystemParams = [];

    // relative path to get xml response
    var RegionsXmlResponsePath = "/ATISServices/Services/Regions.aspx";
    var EventsXmlResponsePath = "/ATISServices/Services/Events.aspx";
    var CameraGroupsXmlResponsePath = "/ATISServices/Services/CameraGroups.aspx";
    var CamerasXmlResponsePath = "/ATISServices/Services/Cameras.aspx";
    var BusRoutesGridXmlResponsePath = "/ATISServices/Services/BusRoutesGrid.aspx";
//    var loadingMessageHTML = "<table height='30px' cellpadding=0 cellspacing=0 style='background-color:#ffffff;'  style='border-top: 2px solid #2557AC;border-bottom: 2px solid #2557AC;border-left: 2px solid #2557AC;border-right: 2px solid #2557AC;' width='250px'><tr><td ><b><font color=black>Loading, please wait.</font> </b></td></tr></table>";				    
    var loadingMessageHTML = "<img src='/ATIS/App_Themes/atis/images/loading.gif' alt='Loading Data'>";				        
    //var loadingMessageHTML = "<img src='/ATIS/App_Themes/atis/images/testloading.jpg' alt='Loading Data'>";				        
    var gridLoadingMessageHTML = "<table width=560px><tr><td><img src='/ATIS/App_Themes/atis/images/loading.gif' alt='Loading Data'></td><td><table cellpadding=3 cellspacing=3 style='width=300px; background-color:#ffffff; border-top: 3px solid #686868;border-bottom: 3px solid #686868;border-left: 3px solid #686868;border-right: 3px solid #686868;' ><tr><td ><font color='red'><b>Note:</font>&nbsp;<font color='black'>Loading grid data.</font></b></td></tr></table></td></tr></table>";
    var warningMessageHTML = "<table><tr><td width=5px>&nbsp;</td><td><table cellpadding=3 cellspacing=3 style='background-color:#ffffff; border-top: 1px solid #000000;border-bottom: 1px solid #000000;border-left: 1px solid #000000;border-right: 1px solid #000000;' ><tr><td ><font color='red'>Warning:</font>&nbsp;<font color='black'>Loading several layers at once will decrease map performance.</font></td></tr></table></td></tr></table>";				    
    //var warningMessageHTML = "<table  cellpadding=0 cellspacing=0  ><tr><td ><b><font color=red>Warning:</font>&nbsp;<font color=black>Loading several layers at once will decrease performance.</font></b></td></tr></table>";				    

    // The following are used for map and grid related operations, and
    // thus have been moved here from InteractiveMapWithGrid.js.
    
    // ids for filters used for Advisories such as Region, Type, Severity
    var AdvisoryRegionSelectName = "Advisory_ddlRegion";
    var AdvisorySeveritySelectName = "Advisory_ddlSeverity";
    
    // ids for filters used for Camera Groups such as Name, Description, Region
    var CameraGroupNameSelectName = "CameraGroup_ddlName";
    var CameraGroupDescriptionSelectName = "CameraGroup_ddlDescription";
    var CameraGroupRegionSelectName = "CameraGroup_ddlRegion";
    
    // ids for filters used for Camaeras such as Region, Type, Status
    var CameraRegionSelectName = "Camera_ddlRegion";
    var CameraStatusSelectName = "Camera_ddlStatus";

    // indicates whether to recenter bus route on map
    var isRecenterBusRouteOnMap = false;

    // indicating if we are on the fullscreen map or not
    var isFullScreenMap = false;
    
    
    //<DREWCODE>
    //Variables used by the XML Document when reading the Border Crossing information
    var xmlDoc;
    var xmlDocDescription = "";
    var xmlDocTag_ID = "";
    var xmlDocTag_TAG = "";

    
    var fireFoxGridCount = 0;
    var fireFoxGridHasLoaded = false;
    
    var divLoading = null;
    var divWarning = null;
    var divLoadingGrid = null;


/*******************************************************************************/
// Functions

//*******************************************************************************
// Function:     Load()
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Loads and initializes all of the map data and settings
//
// Parameters:   n/a
// Returns:
// Calls:        InitGroupLayers(); retrieveCookie(); newCookie(); checkATISBoundaries();
// Called By:    Map onLoad() function
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//  Michael Chu  Sep 1, 2006 Add map/grid interaction code in pan and zoom movement events. 
//*******************************************************************************
function load(width, height) {

//alert("start loading now");	


if (debugPerformance)
    PrintElapseTime("start load");

// Debug variable (set to 1 to debug)
var debug = 0;
	
if (debug)
    alert('load map');
	
// For some reason the following commented code will break in FireFox
/***************************************************************************
//	<% Session["loadedOnce"] = false; %>    //was true
//	
//	// check which tab we're on
//	t = String( "<% =Request[ "t" ] %>" );

//	if( t=="" ) t="Motorists";
***************************************************************************/

    //Write the iMove Version to a cookie
    AddOrRemovePartialCookieValue(iMoveVersionCookieName, iMoveVersion, true);  


//	 //Write the iMove testing message, and store in cookie
//	 var testingCookie = Get_Cookie( iMoveTestingCookieName );  
//	 if (testingCookie == null){
//  
//	     //alert("Welcome to iMove! This site is a pre-release Beta, or Lab, version of an Advanced Traveller Information System for the Lower Mainland. Please be aware that the incidents on the site are sometimes fictitious placeholders used to test the system and should not be relied upon or interpreted as accurate. Content is constantly being added to the site as its' development progresses and we always welcome your input and comments. Please use the feedback link at the bottom of each page to share your thoughts. Use this site at your own risk.");
//	     alert("Welcome to iMove! This site is a pre-release Beta, or Lab, version of an Advanced Traveller Information System for the Lower Mainland. Please be aware that the incidents on the site are sometimes fictitious placeholders used to test the system and should not be relied upon or interpreted as accurate. Content is continually being added to the site as its development progresses and we always welcome your input and comments. Please use the feedback link at the bottom of each page to share your thoughts. Use this site at your own risk TransLink takes no responsibility for the accuracy or completeness of the information presented in this site.");

//	     AddOrRemovePartialCookieValue(iMoveTestingCookieName , "testing_accepted", true);  
//            
//        } else {
//	  //we already have the cookie do nothing
//	 }     

    //check to see if we are using Safari, and show the alert
    if (saf == true){        
        var safariCookie = Get_Cookie( iMoveSafariBrowserNoticeCookieName );  
	     if (safariCookie == null){      
             alert("iMove uses Google Maps to display traveller information. Google Maps is not compatible with versions of Safari earlier than 1.2.4, so if you are using an earlier version please update your version of Safari (http://www.apple.com/safari/download/), or use another browser to access this site. Sorry for any inconvenience.");
	         AddOrRemoveFourteenDayPartialCookieValue(iMoveSafariBrowserNoticeCookieName , "Safari_warning_accepted", true);                  
            } else {
	          //we already have the cookie do nothing
	         }
    }

    //check to see if we are using IE, and show the alert
//    if (ie == true){        
//        var iECookie = Get_Cookie( iMoveIEBrowserNoticeCookieName );  
//	     if (iECookie == null){      
//             alert("iMove uses Google Maps to display traveller information. There are known performance and stability issues with Internet Explorer and Google Maps. We strongly recommend using another browser such as Firefox (http://www.firefox.com) or Safari (http://www.apple.com/safari/download/) to browse the site until these issues are resolved. Sorry for any inconvenience.");
//	         AddOrRemoveFourteenDayPartialCookieValue(iMoveIEBrowserNoticeCookieName , "IE_warning_accepted", true);                  
//            } else {
	          //we already have the cookie do nothing
//	         }
  //  }


    // Load system parameters from xml files
    LoadSystemParams();

	// set initial width & height of map
	var m = document.getElementById( "map" );
	//m.style.width = width;
	m.style.width = "100%";
	m.style.height = height;

if (debugPerformance)
    PrintElapseTime("document.getElementById( map )");

	if( GBrowserIsCompatible() ) {
	
        // set the HTML for the <DIV> which contains the google map buttons 
        var cgiGoogleMapIconsHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td><div id='divMapButtonMap'><img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/map_on.gif' alt='Show street map' border='0' /></div></td><td>&nbsp;</td><td><div id='divMapButtonSat'><img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/satellite_reg.gif' alt='Show satellite imagery' border='0' /></div></td><td>&nbsp;</td><td><div id='divMapButtonHybrid'><img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/hybrid_reg.gif' alt='Show imagery with street names' border='0' /></div></td></tr></table>";
        document.getElementById("divMapButtons").innerHTML= cgiGoogleMapIconsHTML;        
	
        //new lines added for scroll wheel zoom
        //var mapobj = document.getElementById("map"); 
        //map = new GMap2(mapobj); 

		// create map and map controls
		map = new GMap2( document.getElementById( "map" ) );  
		map.addControl( new GLargeMapControl() );
        map.addControl(new CGIMapTypeControl());  // CGI customized map/satellite/hybrid options    	            
		
		//map.addControl( new GMapTypeControl() );   //the Map/Satellite/Hybrid options
		map.addControl( new GScaleControl() );
		//map.addControl( new GOverviewMapControl() );
	    map.enableDoubleClickZoom();  // enable double clicking on map for zoom level and centering
	    
	    map.enableContinuousZoom();
	    map.enableScrollWheelZoom(); 


        //new lines added for scroll wheel zoom
        //map.enableContinuousZoom(); 

        //new lines added for scroll wheel zoom
        //GEvent.addDomListener(mapobj, "DOMMouseScroll", wheelZoom); 
        //GEvent.addDomListener(mapobj, "mousewheel", wheelZoom); 
   
	    
        //map.addControl(new OurTypeControl());	  //original customized map/satellite/hybrid options  
        
        // Position the loading message div element
        var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(250,150));
        pos.apply(document.getElementById("divLoading"));
        map.getContainer().appendChild(document.getElementById("divLoading")); 

        //pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(150,0));
        //pos.apply(document.getElementById("divWarning"));
        //map.getContainer().appendChild(document.getElementById("divWarning")); 

        // Assign the loading message div element
        document.getElementById("divLoading").innerHTML= loadingMessageHTML;
        
        // Assign the warning message div element
        //document.getElementById("divWarning").innerHTML= warningMessageHTML;
        

    showLoading();
    window.setTimeout(hideLoading,3500); 
    
    
    GEvent.addDomListener(map.getContainer(), "DOMMouseScroll", wheelevent);
map.getContainer().onmousewheel = wheelevent; 
              

if (debugPerformance)
    PrintElapseTime("GBrowserIsCompatible");

		GEvent.addListener(map, "infowindowopen", function() {

            //alert("start info window open");
            
            infoWindowHasBeenOpened = true;            

		    // set original position of map before opening info window
		     originalInfoCenterPoint=previousCenterPoint;
		     
		     //alert("end info window open, infowindow opened is:" + infoWindowHasBeenOpened);

		    }
		 );

		GEvent.addListener(map, "infowindowclose", function() {

		     // move the user back to their original position before opening the info window
		     //map.setCenter(originalInfoCenterPoint,previousZoom);

		     //alert("close info window, switch infowindow flag");
		     
		     window.setTimeout(function() { map.panTo(originalInfoCenterPoint);}, 25);
		     
		     infoWindowHasBeenOpened = false;
		     
		     //alert("done closing info window, infowindow opened is:" + infoWindowHasBeenOpened);

		    }
		 );



		GEvent.addListener(map, "infowindowbeforeclose", function() {
		     //alert("info window before close");
		    }
		 );




if (debugPerformance)
    PrintElapseTime("infowindowclose");

		// add a move listener to capture map move start
		GEvent.addListener( map, "zoom", function() {
		
		//alert("zoom here");
				//markTime( 5 );
//GLog.write(" zoom start" );	
			}
		);
		
		// add a move listener to capture map move end
		GEvent.addListener( map, "zoomend", function() {
		
		//alert("zoom end here");
				//markTime( 6 );
//GLog.write(" zoom end" );			


if (debug)
    alert('zoomend');
                // Reload results on both map and grids since
			    // only data within map boundaries and satisfaction of specified 
			    // zoom level are shown.


            if (infoWindowHasBeenOpened == true){
                //do not call PanZoomHandler() if map is moving becuase of infowindow opening
                //alert("moveend - we are NOT going to call pan zoom handler");
            } else {
                //do call PanZoomHanlder() to refresh the page data
                //alert("moveend - we ARE going to call pan zoom handler, b/c map window is not open");
                PanAndZoomHandler();    
            }	  

		        //PanAndZoomHandler();
		        
		        // Check if layers turned on satisfy zoom level,
		        // is needed to turn off
		        ZoomLevelChecks();
		        
		        //document.getElementById("divLoading").innerHTML= loadingMessageHTML;								
		        //alert("done zooming");
		        
        //GLog.write(" done 174" );		    		
        		        
if (debug)		        
    alert('done zoomend PanAndZoomHandler');
			}
		);
		
if (debugPerformance)
    PrintElapseTime("zoomend");
    
		// add a move listener to capture map move start
		GEvent.addListener( map, "move", function() {
		
		//alert("move here");
		
		//GEvent.addListener( map, "movestart", function() {		
				//markTime( 3 );				
                //GLog.write(" move start here" );	                				
               // document.getElementById("divLoading").innerHTML= loadingMessageHTML;								
			}
		);

		// add a move listener to capture map move end
		GEvent.addListener( map, "moveend", function() {
		
		
			// store map positions
			previousCenterPoint = map.getCenter() ;
			previousZoom = map.getZoom() ;

			// check map boundaries to make sure they are within ATIS boundaries
			checkATISBoundaries();
			
                //GLog.write(" move end here" );
                //GLog.write(" done 200" );		    		
		        //markTime( 4 );
			
if (debug)
    alert('moveend');
    
			// Reload results on both map and grids since
			// only data within map boundaries and satisfaction of specified 
			// zoom level are shown.
    
    //alert("moveend - start pan zoom handler, infowindow opened is:" + infoWindowHasBeenOpened);
    
            if (infoWindowHasBeenOpened == true){
                //do not call PanZoomHandler() if map is moving becuase of infowindow opening
                //alert("moveend - we are NOT going to call pan zoom handler");
            } else {
                //do call PanZoomHanlder() to refresh the page data
                //alert("moveend - we ARE going to call pan zoom handler, b/c map window is not open");
                PanAndZoomHandler();    
            }	    

		    //PanAndZoomHandler();
		    
		    //alert("done moving");
        // this will clear out the display message
        //GLog.write(" done pan/zoom 212" );
        
        //alert("moveend - done pan zoom handler, infowindow opened is:" + infoWindowHasBeenOpened);	    
		    
if (debug)
    alert('done moveend PanAndZoomHandler');
            
			}
		);

if (debugPerformance)
    PrintElapseTime("moveend");

		// Get the list of map types
		var mt = map.getMapTypes();

		// restrict the range of zoom levels by overwriting the
		// getMinimumResolution() and getMaximumResolution() methods
		for( var i=0; i<mt.length; i++ ) {

			//mt[i].getMinimumResolution = function() { return 8; }
			mt[i].getMinimumResolution = function() { return 9; }
			//mt[i].getMaximumResolution = function() { return 15; }
			//mt[i].getMaximumResolution = function() { return 17; }
		}

if (debugPerformance)
    PrintElapseTime("getMinimumResolution");

        // set default map center and zoom level
        SetDefaultMapCenterAndZoomLevel();
        
        //GLog.write(" done map zoom level 242" );

if (debugPerformance)
    PrintElapseTime("load");
    
	}

    showLoading();
    
    
    // The following looks for a variable that is appended to the query string
    // ie. href="/ATIS/InteractiveMapFullScreen?v=F" 
    var queryString = location.search.substring(1);
    var pos = queryString.indexOf('=');
    //var fullScreenFlag = queryString.substring(pos+1,queryString.length);

    var fullScreenFlag = getQueryVariable("v");  
    
    //alert(fullScreenFlag);   


//var zoom = getQueryVariable("Zoom");     

    //check to see if we are using the full screen map from the query string URL
    if (fullScreenFlag == "F"){
    
        document.getElementById("imgFullScreen").style.display= "none";
        document.getElementById("imgSaveButton").style.display= "none"; 
        document.getElementById("imgClearButton").style.display= "none"; 
        
        //switch the fullscreen map flag
        isFullScreenMap = true;   
        
        //load full screen map layers from cookie       
        LoadFullScreenMapInfo();  

    } else if ( fullScreenFlag == "C" ) {
    
        //alert("do something here");

        document.getElementById("imgFullScreen").style.display= "none";
        document.getElementById("imgSaveButton").style.display= "none"; 
        document.getElementById("imgResetButton").style.display= "none"; 
        document.getElementById("imgClearButton").style.display= "none";         

        
        //switch the fullscreen map flag, for bus route cookies
        isFullScreenMap = true;   
      
        // Load the custom full screen map , this is from the hyperlinks in the CMS
        LoadFullScreenCustomMapInfo();
        
    } else {
        
        //we are on the regular size map
        isFullScreenMap = false;   
        
        //load default tap layers for regular map page
        InitializeDefaultMapLayers();  
    }
    
    window.setTimeout(hideLoading, 2000);

}

//return the Duration Period for the Event in text format
function returnDurationMessage( lDuration ){

	var lDurationMessage;
	
	lDuration = parseInt(lDuration);

	if (lDuration == 0){
		//alert("0 message");
		//set message equal to until further notice, when is 0
		lDurationMessage = "Until Further Notice";

	} else if ( lDuration > 0 && lDuration < 721 ) {
		//alert("hours message");
		//do hours calculations
		if ( lDuration > 0 && lDuration < 91 ){
			lDurationMessage="1 hour";
		} else if ( lDuration > 90 && lDuration < 152 ) {
			lDurationMessage="2 hours";
		} else if ( lDuration > 150 && lDuration < 211 ) {
			lDurationMessage="3 hours";
		} else if ( lDuration > 210 && lDuration < 271 ) {
			lDurationMessage="4 hours";
		} else if ( lDuration > 270 && lDuration < 331 ) {
			lDurationMessage="5 hours";
		} else if ( lDuration > 330 && lDuration < 391 ) {
			lDurationMessage="6 hours";
		} else if ( lDuration > 390 && lDuration < 451 ) {
			lDurationMessage="7 hours";
		} else if ( lDuration > 450 && lDuration < 511 ) {
			lDurationMessage="8 hours";
		} else if ( lDuration > 510 && lDuration < 571 ) {
			lDurationMessage="9 hours";
		} else if ( lDuration > 570 && lDuration < 631 ) {
			lDurationMessage="10 hours";
		} else if ( lDuration > 630 && lDuration < 691 ) {
			lDurationMessage="11 hours";
		} else if ( lDuration > 690 && lDuration < 751 ) {
			lDurationMessage="12 hours";
		} else if ( lDuration > 750 && lDuration < 811 ) {
			lDurationMessage="13 hours";
		} else if ( lDuration > 810 && lDuration < 871 ) {
			lDurationMessage="14 hours";
		} else if ( lDuration > 870 && lDuration < 931 ) {
			lDurationMessage="15 hours";
		} else if ( lDuration > 930 && lDuration < 991 ) {
			lDurationMessage="16 hours";
		} else if ( lDuration > 990 && lDuration < 1051 ) {
			lDurationMessage="17 hours";
		} else if ( lDuration > 1050 && lDuration < 1171 ) {
			lDurationMessage="18 hours";
		} else if ( lDuration > 1170 && lDuration < 1231 ) {
			lDurationMessage="19 hours";
		} else if ( lDuration > 1230 && lDuration < 1291 ) {
			lDurationMessage="20 hours";
		} else if ( lDuration > 1290 && lDuration < 1351 ) {
			lDurationMessage="21 hours";
		} else if ( lDuration > 1350 && lDuration < 1411 ) {
			lDurationMessage="22 hours";
		} else if ( lDuration > 1410 && lDuration < 1471 ) {
			lDurationMessage="23 hours";
		} else if ( lDuration > 1470 && lDuration < 1531 ) {
			lDurationMessage="1 days 1 hours";
		} else if ( lDuration > 1530 && lDuration < 1591 ) {
			lDurationMessage="1 days 2 hours";
		} else if ( lDuration > 1590 && lDuration < 1651 ) {
			lDurationMessage="1 days 3 hours";
		} else if ( lDuration > 1650 && lDuration < 1711 ) {
			lDurationMessage="1 days 4 hours";
		} else if ( lDuration > 1710 && lDuration < 1771 ) {
			lDurationMessage="1 days 5 hours";
		} else if ( lDuration > 1770 && lDuration < 1831 ) {
			lDurationMessage="1 days 6 hours";
		} else if ( lDuration > 1830 && lDuration < 1891 ) {
			lDurationMessage="1 days 7 hours";
		} else if ( lDuration > 1890 && lDuration < 1951 ) {
			lDurationMessage="1 days 8 hours";
		} else if ( lDuration > 1950 && lDuration < 2011 ) {
			lDurationMessage="1 days 9 hours";
		} else if ( lDuration > 2010 && lDuration < 2071 ) {
			lDurationMessage="1 days 10 hours";
		} else if ( lDuration > 2070 && lDuration < 2131 ) {
			lDurationMessage="1 days 11 hours";
		} else if ( lDuration > 2130 && lDuration < 2191 ) {
			lDurationMessage="1 days 12 hours";
		} else if ( lDuration > 2190 && lDuration < 2251 ) {
			lDurationMessage="1 days 13 hours";
		} else if ( lDuration > 2250 && lDuration < 2311 ) {
			lDurationMessage="1 days 14 hours";
		} else if ( lDuration > 2310 && lDuration < 2371 ) {
			lDurationMessage="1 days 15 hours";
		} else if ( lDuration > 2370 && lDuration < 2431 ) {
			lDurationMessage="1 days 16 hours";
		} else if ( lDuration > 2430 && lDuration < 2491 ) {
			lDurationMessage="1 days 17 hours";
		} else if ( lDuration > 2490 && lDuration < 2551 ) {
			lDurationMessage="1 days 18 hours";
		} else if ( lDuration > 2550 && lDuration < 2611 ) {
			lDurationMessage="1 days 19 hours";
		} else if ( lDuration > 2610 && lDuration < 2671 ) {
			lDurationMessage="1 days 20 hours";
		} else if ( lDuration > 2670 && lDuration < 2731 ) {
			lDurationMessage="1 days 21 hours";
		} else if ( lDuration > 2730 && lDuration < 2791 ) {
			lDurationMessage="1 days 22 hours";
		} else if ( lDuration > 2790 && lDuration < 2851 ) {
			lDurationMessage="1 days 23 hours";
		} else if ( lDuration > 2850 && lDuration < 2911 ) {
			lDurationMessage="2 days 1 hours";
		} else if ( lDuration > 2910 && lDuration < 2971 ) {
			lDurationMessage="2 days 2 hours";
		} else if ( lDuration > 2970 && lDuration < 3031 ) {
			lDurationMessage="2 days 3 hours";
		} else if ( lDuration > 3030 && lDuration < 3091 ) {
			lDurationMessage="2 days 4 hours";
		} else if ( lDuration > 3090 && lDuration < 3151 ) {
			lDurationMessage="2 days 5 hours";
		} else if ( lDuration > 3150 && lDuration < 3211 ) {
			lDurationMessage="2 days 6 hours";
		} else if ( lDuration > 3210 && lDuration < 3271 ) {
			lDurationMessage="2 days 7 hours";
		} else if ( lDuration > 3270 && lDuration < 3331 ) {
			lDurationMessage="2 days 8 hours";
		} else if ( lDuration > 3330 && lDuration < 3391 ) {
			lDurationMessage="2 days 9 hours";
		} else if ( lDuration > 3390 && lDuration < 3451 ) {
			lDurationMessage="2 days 10 hours";
		} else if ( lDuration > 3450 && lDuration < 3511 ) {
			lDurationMessage="2 days 11 hours";
		} else if ( lDuration > 3510 && lDuration < 3571 ) {
			lDurationMessage="2 days 12 hours";
		} else if ( lDuration > 3570 && lDuration < 3631 ) {
			lDurationMessage="2 days 13 hours";
		} else if ( lDuration > 3630 && lDuration < 3691 ) {
			lDurationMessage="2 days 14 hours";
		} else if ( lDuration > 3690 && lDuration < 3751 ) {
			lDurationMessage="2 days 15 hours";
		} else if ( lDuration > 3750 && lDuration < 3811 ) {
			lDurationMessage="2 days 16 hours";
		} else if ( lDuration > 3810 && lDuration < 3871 ) {
			lDurationMessage="2 days 17 hours";
		} else if ( lDuration > 3870 && lDuration < 3931 ) {
			lDurationMessage="2 days 18 hours";
		} else if ( lDuration > 3930 && lDuration < 3991 ) {
			lDurationMessage="2 days 19 hours";
		} else if ( lDuration > 3990 && lDuration < 4111 ) {
			lDurationMessage="2 days 20 hours";
		} else if ( lDuration > 4110 && lDuration < 4171 ) {
			lDurationMessage="2 days 21 hours";
		} else if ( lDuration > 4170 && lDuration < 4231 ) {
			lDurationMessage="2 days 22 hours";
		} else if ( lDuration > 4230 && lDuration < 4291 ) {
			lDurationMessage="2 days 23 hours";
		} else if ( lDuration > 4290 && lDuration < 4351 ) {
			lDurationMessage="2 days 24 hours";
		}

	} else if ( lDuration > 4320 ) {
		//do the days calculations .. divide by 1440 minutes in a day
		var lDaysCalc = Math.round(lDuration/1440);
		lDurationMessage = lDaysCalc + " days";
	} else {	
		lDurationMessage = "undefined";
	}
	
	return lDurationMessage;
}



function wheelevent(e)
{
	
	//if(document.getElementById("prevent").checked){
		if (!e){
			e = window.event
		}

		if (e.preventDefault){
			e.preventDefault()
		}

		e.returnValue = false;
	//}
}





function wheelZoom(a) { 
    if ((a.detail || -a.wheelDelta) < 0) 
        //map.zoomIn(); 
    map.zoomIn(null, null, true); 
    else 
        //map.zoomOut(); 
        map.zoomOut(null, true); 

//map.zoomIn(null, null, true); 
//map.zoomOut(null, true); 


}

function showLoading(){
    document.getElementById("divLoading").innerHTML= loadingMessageHTML;
}

function hideLoading(){
    document.getElementById("divLoading").innerHTML= "";
}

function showWarning(){
   document.getElementById("divWarning").innerHTML= warningMessageHTML;
}

function hideWarning(){
    document.getElementById("divWarning").innerHTML= "";
}

function showLoadingGrid(){
// Debug variable (set to 1 to debug)
var debug = 0;
if (debug)
    PrintElapseTime("showLoadingGrid(): start");

    document.getElementById("divLoadingGrid").innerHTML= gridLoadingMessageHTML;
}

function hideLoadingGrid(){
// Debug variable (set to 1 to debug)
var debug = 0;
if (debug)
    PrintElapseTime("hideLoadingGrid(): end");

    document.getElementById("divLoadingGrid").innerHTML= "";
}

//Define our custom "Map/Hybrid/Satellite" options for the map ...
function OurTypeControl() {
}
OurTypeControl.prototype = new GControl();
OurTypeControl.prototype.initialize = function(map) {
	var container = document.createElement("div");
	
	var normctrl = document.createElement("div");
	this.setButtonStyle_(normctrl);
	container.appendChild(normctrl);
	normctrl.appendChild(document.createTextNode("Map"));
	GEvent.addDomListener(normctrl, "click", function() {
		map.setMapType(G_NORMAL_MAP);
	});

    //add the spacer between the items
	var spacer = document.createElement("div");
	this.setSpacerStyle_(spacer);	
	container.appendChild(spacer);
	spacer.appendChild(document.createTextNode(" "));


	var hybridctrl = document.createElement("div");
	this.setButtonStyle_(hybridctrl);
	container.appendChild(hybridctrl);
	hybridctrl.appendChild(document.createTextNode("Hybrid"));
	GEvent.addDomListener(hybridctrl, "click", function() {
		map.setMapType(G_HYBRID_MAP);
	});

    //add the spacer between the items
	var spacer2 = document.createElement("div");
	this.setSpacerStyle_(spacer2);	
	container.appendChild(spacer2);
	spacer2.appendChild(document.createTextNode(" "));

	var satctrl = document.createElement("div");
	this.setButtonStyle_(satctrl);
	container.appendChild(satctrl);
	satctrl.appendChild(document.createTextNode(" Satellite "));
	GEvent.addDomListener(satctrl, "click", function() {			
		map.setMapType(G_SATELLITE_MAP);
	});

	map.getContainer().appendChild(container);
	return container;
}

OurTypeControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(5, 45));
}


OurTypeControl.prototype.setButtonStyle_ = function(button) {
	button.style.color = '#000000';	
	button.style.backgroundColor = '#FFFFFF';	
	button.style.textAlign = 'center';
	button.style.padding = '2px';
	button.style.fontSize = '8pt';	
	button.style.borderColor = '#000000';
	button.style.borderWidth = '1px';
	button.style.borderStyle = 'solid';
	button.style.marginWidth = '1px';
	button.style.cursor = 'pointer';	
	button.style.width = '70px';
	
}   

// This is the empty spacer div between the "Map/Satellite/Hybrid options"
OurTypeControl.prototype.setSpacerStyle_ = function(button) {
	button.style.textAlign = 'center';
	button.style.padding = '2px';
	button.style.fontSize = '10pt';
	button.style.borderWidth = '0px';
	button.style.borderStyle = 'solid';
	button.style.marginWidth = '1px';
	button.style.cursor = 'hand';	
}  
  
//*** Brians map control

function CGIMapTypeControl() {
}
CGIMapTypeControl.prototype = new GControl();
CGIMapTypeControl.prototype.initialize = function(map) {
	
	var controlsContainer = document.getElementById("divMapButtons");
	
	var mapCtrl1 = document.getElementById("divMapButtonMap");	
//	this.setButtonStyle_(mapCtrl1);
	GEvent.addDomListener(mapCtrl1, "click", function() {
		switchGoogleMapIcons( "Map" );
		map.setMapType(G_NORMAL_MAP);
	});

	var mapCtrl2 = document.getElementById("divMapButtonSat");	
//	this.setButtonStyle_(mapCtrl3);
	GEvent.addDomListener(mapCtrl2, "click", function() {
		switchGoogleMapIcons( "Satellite" );
		map.setMapType(G_SATELLITE_MAP);
	});


	var mapCtrl3 = document.getElementById("divMapButtonHybrid");	
//	this.setButtonStyle_(mapCtrl2);
	GEvent.addDomListener(mapCtrl3, "click", function() {
		switchGoogleMapIcons( "Hybrid" );
		map.setMapType(G_HYBRID_MAP);
	});


	map.getContainer().appendChild(controlsContainer);
	return controlsContainer;
}

CGIMapTypeControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(5, 40));
}

CGIMapTypeControl.prototype.setButtonStyle_ = function(button) {
	button.style.color = '#000000';	
	button.style.backgroundColor = '#FFFFFF';	
	button.style.textAlign = 'center';
	button.style.padding = '0px';
	button.style.fontSize = '8pt';	
	button.style.borderColor = '#000000';
	button.style.borderWidth = '1px';
	button.style.borderStyle = 'solid';
	button.style.marginWidth = '1px';
	button.style.cursor = 'pointer';	
	button.style.width = '70px';
	button.style.height = '15px';
	
}  
  
//Switch the google map icons when user clicks between different map views
function switchGoogleMapIcons( aMapMode ){
    
    //update the appropriate cookie
    switch( aMapMode ) 
    {    
        case "Map" : {
            document.getElementById("divMapButtonMap").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/map_on.gif' alt='Show street map' border='0' />";
            document.getElementById("divMapButtonSat").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/satellite_reg.gif' alt='Show satellite imagery' border='0' />";
            document.getElementById("divMapButtonHybrid").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/hybrid_reg.gif' alt='Show imagery with street names' border='0' />";            
            break; 
        }
        case "Satellite" : {
            document.getElementById("divMapButtonMap").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/map_reg.gif' alt='Show street map' border='0' />";
            document.getElementById("divMapButtonSat").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/satellite_on.gif' alt='Show satellite imagery' border='0' />";
            document.getElementById("divMapButtonHybrid").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/hybrid_reg.gif' alt='Show imagery with street names' border='0' />";            
            break; 
        }
        case "Hybrid" : {
            document.getElementById("divMapButtonMap").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/map_reg.gif' alt='Show street map' border='0' />";
            document.getElementById("divMapButtonSat").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/satellite_reg.gif' alt='Show satellite imagery' border='0' />";
            document.getElementById("divMapButtonHybrid").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/hybrid_on.gif' alt='Show imagery with street names' border='0' />";            
            break; 
        }
        default: {
            document.getElementById("divMapButtonMap").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/map_on.gif' alt='Show street map' border='0' />";
            document.getElementById("divMapButtonSat").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/satellite_reg.gif' alt='Show satellite imagery' border='0' />";
            document.getElementById("divMapButtonHybrid").innerHTML = "<img class='cursorHand' src='/ATIS/App_Themes/ATIS/images/hybrid_reg.gif' alt='Show imagery with street names' border='0' />";            
            break; 
        }    
    }
}


//*******************************************************************************
// Function:     PrintElapseTime()
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.5
// Date:         Oct 13 2006
//
// Description:  Prints elapse time. This helps debug performance issues.
//               Remarks: Global variable startTime must be initialized.
//
// Parameters:   
// Returns:      
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function PrintElapseTime(s) {

if (s==null)
    s = "";

// test performance
var t = new Date().getTime() - startTime.getTime();
GLog.write(t + " " + s);

}

//<DREWCODE>
//*******************************************************************************
// Function:     xmLDoc_loadXML()
// Author:       drew.mcfarland@cgi.com
// Project:      iMove Build - 0.1
// Date:         Mar 02 2007
//
// Description:  Opens the XMl document and calls the xml_GetData() function to get the Border Crossing information
//
// Parameters:   None
// Returns:      None.
// Calls:        
// Called By:    createListener() When handling the extra data for the Border Crossing icon.
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function xmlDoc_loadXML()
{
    //load xml file
    // code for IE
    if (window.ActiveXObject)
    {
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async=false;
        xmlDoc.load("http://www.i-move.ca/XML/highWaySigns.xml");
        xmlDoc_getData();
    }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument)
    {
        xmlDoc=document.implementation.createDocument("","",null);
	xmlDoc.async=false;
        xmlDoc.onload=xmlDoc_getData;
        xmlDoc.load("http://www.i-move.ca/XML/highWaySigns.xml");
    }
    else
    {
        alert('Your browser cannot handle this script');
    };
}

//*******************************************************************************
// Function:     xmLDoc_getText(oNode)
// Author:       drew.mcfarland@cgi.com
// Project:      iMove Build - 0.1
// Date:         Mar 02 2007
//
// Description:  Traverses all the child nodes of the <msgPhase1> tag in order to make sure it gets all the information in the tag.
//
// Parameters:   None
// Returns:      sText - The data in the <msgPhase1> tag.
// Calls:        
// Called By:    xmlDoc_getData()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function xmlDoc_getText(oNode) {
    var sText = "";
    for (var i=0; i<oNode.childNodes.length; i++) {
        if (oNode.childNodes[i].hasChildNodes()) {
            sText += xmlDoc_getText(oNode.childNodes[i]);
        } else {
            sText += oNode.childNodes[i].nodeValue;
        }
    }
    return sText;
}

//*******************************************************************************
// Function:     xmLDoc_getData()
// Author:       drew.mcfarland@cgi.com
// Project:      iMove Build - 0.1
// Date:         Mar 02 2007
//
// Description:  Gets the data from the <msgPhase1> tag of the XML Document (For the Border Crossing)
//
// Parameters:   None
// Returns:      None. (* Sets the xmlDocDescription variable with the data from the <msgPhase1> tag.
// Calls:        
// Called By:    xmlDoc_loadXML() When handling the extra data for the Border Crossing icon.
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function xmlDoc_getData()
{
    var Signs, sign, element, thisone;
    Signs = xmlDoc.getElementsByTagName("Signs");
    for (iSigns=0; iSigns<Signs.length; iSigns++) {
        sign = Signs[iSigns].getElementsByTagName("sign");
        for (isign=0; isign<sign.length; isign++) {
            thisone = false;
            for (element=0; element<sign[isign].childNodes.length; element++) {
                if (sign[isign].childNodes[element].nodeName=="id" && xmlDoc_getText(sign[isign].childNodes[element])==xmlDocTag_ID) {
                    thisone = true;
                }
                if (sign[isign].childNodes[element].nodeName==xmlDocTag_TAG && thisone==true) {
		    xmlDocDescription = xmlDoc_getText(sign[isign].childNodes[element]);
                }
            }
        }
    }
}




//*******************************************************************************
// Function:     SetDefaultMapCenterAndZoomLevel()
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.1
// Date:         Sep 01 2006
//
// Description:  Sets default map center and zoom level.
//
// Parameters:   None
// Returns:      None
// Calls:        None
// Called By:    Load() 
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function SetDefaultMapCenterAndZoomLevel() {

// Debug variable (set to 1 to debug)
var debug = 0;

var hasSavedBefore = 0;

if (debug)
    alert('ck_center:' + ck_center);

    // save cookie information for current tab's cookie
    var activeTab = Get_Cookie( 'activeTab' );    

    //update the appropriate cookie
    switch( activeTab ) 
    
    {
                   
        case "Motorists" : {            
            
            //grab the motorists saved settings cookie
            var savedTab = Get_Cookie( MotoristsMapCenterCookieName );    
            
            if (savedTab != null){
            
                //set the map zoom level for the fullscreen map from the cookie
                var SavedMapZoomLevel = Get_Cookie(MotoristsZoomLevelCookieName); 
                var SavedMapCenter = Get_Cookie(MotoristsMapCenterCookieName);      
                
                //switch the flag, saying the user has saved settings in the past
                hasSavedBefore = 1;  
            }            
            break; 
        }
    
        case "Transit" : {
            //grab the motorists saved settings cookie
            var savedTab = Get_Cookie( TransitMapCenterCookieName );    
            
            if (savedTab != null){
            
                //set the map zoom level for the fullscreen map from the cookie
                var SavedMapZoomLevel = Get_Cookie(TransitZoomLevelCookieName); 
                var SavedMapCenter = Get_Cookie(TransitMapCenterCookieName);      
                
                //switch the flag, saying the user has saved settings in the past
                hasSavedBefore = 1;  
            }            
            
            break; 
        }
        case "Cycling" : {
            //grab the motorists saved settings cookie
            var savedTab = Get_Cookie( CyclingMapCenterCookieName );    
            
            if (savedTab != null){
            
                //set the map zoom level for the fullscreen map from the cookie
                var SavedMapZoomLevel = Get_Cookie(CyclingZoomLevelCookieName); 
                var SavedMapCenter = Get_Cookie(CyclingMapCenterCookieName);      
                
                //switch the flag, saying the user has saved settings in the past
                hasSavedBefore = 1;  
            }            
            
            break; 
        }
        case "Gateways" : {
            //grab the motorists saved settings cookie
            var savedTab = Get_Cookie( GatewaysMapCenterCookieName );              
            if (savedTab != null){
            
                //set the map zoom level for the fullscreen map from the cookie
                var SavedMapZoomLevel = Get_Cookie(GatewaysZoomLevelCookieName); 
                var SavedMapCenter = Get_Cookie(GatewaysMapCenterCookieName);      
                
                //switch the flag, saying the user has saved settings in the past
                hasSavedBefore = 1;  
            }            
            
            break; 
        }
        case "Visitors" : {
            //grab the motorists saved settings cookie
            var savedTab = Get_Cookie( VisitorsMapCenterCookieName );    
            
            if (savedTab != null){
            
                //set the map zoom level for the fullscreen map from the cookie
                var SavedMapZoomLevel = Get_Cookie(VisitorsZoomLevelCookieName); 
                var SavedMapCenter = Get_Cookie(VisitorsMapCenterCookieName);      
                
                //switch the flag, saying the user has saved settings in the past
                hasSavedBefore = 1;  
            }            
            
            break; 
        }
        case "Commercial" : {
            //grab the motorists saved settings cookie
            var savedTab = Get_Cookie( CommercialMapCenterCookieName );    
            
            if (savedTab != null){
            
                //set the map zoom level for the fullscreen map from the cookie
                var SavedMapZoomLevel = Get_Cookie(CommercialZoomLevelCookieName); 
                var SavedMapCenter = Get_Cookie(CommercialMapCenterCookieName);      
                
                //switch the flag, saying the user has saved settings in the past
                hasSavedBefore = 1;  
            }            
            
            break; 
        }
        default: {
        
            break;
        }    

    }

    if (hasSavedBefore == 0 ){
        // user has not any saved settings for the tab, load default map center
        var center_arr=ck_center.split( "," );
        map.setCenter( new GLatLng( center_arr[0].substr( 1, center_arr[0].length ), center_arr[1].substr( 0, center_arr[0].length-1 ) ), parseInt( ck_zoom ) );
    } else {
        //user has saved settings for the tab they are loading, use those settings
        var center_arr=SavedMapCenter.split( "," );
        map.setCenter( new GLatLng( center_arr[0].substr( 1, center_arr[0].length ), center_arr[1].substr( 0, center_arr[0].length-1 ) ), parseInt( SavedMapZoomLevel ) );
    }
	
if (debugPerformance)
    PrintElapseTime("SetDefaultMapCenterAndZoomLevel");
}



//*******************************************************************************
// Function:     checkATISBoundaries()
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Limits the lat + long of the map to include lower mainland are only
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    Load() 
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

// If the map position is out of range, move it back
function checkATISBoundaries() {
	// Perform the check and return if OK
	if (allowedBounds.contains(map.getCenter())) {
	  return;
	}
	// It`s not OK, so find the nearest allowed point and move there
	var C = map.getCenter();
	var X = C.lng();
	var Y = C.lat();

	var AmaxX = allowedBounds.getNorthEast().lng();
	var AmaxY = allowedBounds.getNorthEast().lat();
	var AminX = allowedBounds.getSouthWest().lng();
	var AminY = allowedBounds.getSouthWest().lat();

	if (X < AminX) {X = AminX;}
	if (X > AmaxX) {X = AmaxX;}
	if (Y < AminY) {Y = AminY;}
	if (Y > AmaxY) {Y = AmaxY;}
	
	map.setCenter(new GLatLng(Y,X));
}

//======================================================================//
//=== TextualMapMenuControl  information removed from here           ===//
//======================================================================//

//======================================================================//
//=== GMarker customizations                                         ===//
//======================================================================//
GMarker.prototype.id = false;
GMarker.prototype.group = false;

//======================================================================//
//=== GPolyline customizations                                       ===//
//======================================================================//
GPolyline.prototype.id = false;
GPolyline.prototype.group = false;

//======================================================================//
//=== GMap customizations                                            ===//
//======================================================================//
//=== Extend the addOverlays function                                ===//
//======================================================================//
GMap2.prototype.addGroupOverlays=function( overlayType, groupOverlays, groupId, optParameter1 ) {

// Debug variable (set to 1 to debug)
var debug = 0;
	
	// This creates, in the map.overlays array, an entry for the id of the overlay,
	// and the group of the overlay if it does not exist. It adds a reference to the original overlay
	// in both locations so it is available in each of the following ways

overlayCount = overlayCount+1;

//alert("overlayCount 1 is: " + overlayCount);

if (debug)
{
	    alert("add " + groupOverlays.length + " Overlays for group: " + groupId + "\r\n");
}
    
	for( i=0; i<groupOverlays.length; i++ ) {
		
			// need to group the overlays for toggling
			// has this overlay been marked for a group
			if( groupOverlays[i].group ) {
			
				// add a new empty entry for this group in the groups array
				if( !overlays['groups'] ) {
					overlays['groups']=[];
				}

				// if this group doesn't exist yet then create it and add it to the groups array
				if( !overlays[groupOverlays[i].group] ) {
				
					// create the group
					overlays[groupOverlays[i].group]=[];
if (debug)
    alert("Create new array for overlays["+groupOverlays[i].group+"]");

					// enumerate the available groups with a key of 'groups' ie. overlays[1]="BorderCameras"
					overlays['groups'].push( groupOverlays[i].group );
					
if (debug)
    alert("overlays['groups'].push( "+groupOverlays[i].group+" )");
				}

				// Finally add the overlay to the group's array as both an index (0,1,2,3) and as an associative array ('id1', 'id2')
				overlays[groupOverlays[i].group].push( groupOverlays[i] );
				overlays[groupOverlays[i].group][groupOverlays[i].id] = groupOverlays[i];
			}
		
	}

if (debug)
{
    if (overlays != null)
        if (overlays['groups'] != null)
            alert("After adding: overlays['groups'].length: " + overlays['groups'].length);
}
	
if (debug)
{   
    alert("If checkbox is checked, re-add overlays on the map for group: " + groupId);
}
    
    // if there are existing overlays for the data
	// the map also needs to be updated based on those data
    var checkboxName = GetMapLayerCheckBoxName( groupId, optParameter1 );
	tgChk = document.getElementById( checkboxName );

if (debug)
    alert("checkboxName: " + checkboxName + " tgChk: " + tgChk);
    
	if (tgChk != null)
	{
	    //alert("checkboxName is: " + checkboxName + " checked = " + tgChk.checked);
	    
	    if (tgChk.checked)
	    {
	    
	        // SPECIAL CASE: Show Bus Route markers layer 
	        // if it is Zoom Level 14 or higher
	        
	        //alert("checkboxName2 is: " + checkboxName + " checked = " + tgChk.checked);
	        
	        var transitMarkersLayerName;
    
            //build the Transit marker layer name dynamically, if optional parameter is passed
            if (optParameter1 != null ){
                transitMarkersLayerName = "layer_TRA_Public_Marker_" + optParameter1;
            }
            
            switch( groupId ) {
	
                // dynamic layer names for the bus routes
		        case transitMarkersLayerName:  
		        {
	                if (MapZoomLevelCheck( 9 ))
	                {
if (debugPerformance)
    PrintElapseTime("generateGroupMarkers(): start toggleGroup()");

	                    toggleGroup( groupId, true ); // show bus route markers layer
if (debugPerformance)    	                
    PrintElapseTime("generateGroupMarkers(): end toggleGroup()");
                    }
                    
                    break;
                }
                case "layer_MilLine_Marker":
                case "layer_ExpoLine_Marker":
                {   //only toggle the skytrain markers level on by default if we are zoom level or greater
                                        
                    if (MapZoomLevelCheck( 11 ))
	                {
	                    toggleGroup( groupId, true ); // show expo line markers
                    }
                    break;
                }
                default: 
                {
                   //alert("hello 1 ?");
                   
                    toggleGroup( groupId, true ); // show other layers all the time
                    
                    //alert("hello 1a ?");
                    
                    break;
                }
            }
	    }
	}
	else
	{


//alert("hello 2 ?");

        //We need to turn on all bus route polylines that have been saved, when there 
        //is no checkbox on the UI. This occurs for all saved bus routes.
        
        var transitTestInt;
        var lTransitTest=0;

        //check to see if this a public transit layer
        transitTestInt = groupId.indexOf('layer_TRA_Public_Polyline');   
        if (transitTestInt != -1){        

//alert("hello 3 ?");
            toggleGroup( groupId, true ); // always turn on polylines                             
        }
        


	    //SPECIAL CASE FOR TOGGLING ON DEFAULT BUS ROUTES WHEN CHECKBOX IS NOT ON UI
	    //switch( groupId ) {
            // dynamic layer names for the bus routes
            //case "layer_TRA_Public_Polyline_10":  
		    //case "layer_TRA_Public_Polyline_162":  
		    //case "layer_TRA_Public_Polyline_165":
		    //case "layer_TRA_Public_Polyline_194":{
		        //toggleGroup( groupId, true ); // always turn on polylines
		        //break;    
		    //}
		    //case "layer_TRA_Public_Marker_162":
		    //case "layer_TRA_Public_Marker_165":
		    //case "layer_TRA_Public_Marker_194": {
                
                //if (MapZoomLevelCheck( 14 ))
                //{
                    //toggleGroup( groupId, true ); // only turn on markers when zoom level is 14 or higher
                //}                        		    							
                
		      //  break;        

            //}
          //  default: break;
        //}

	}
	
	tgChk = null;
	
//alert("overlayCount 2 is: " + overlayCount);

if (overlayCount>10){
   // showWarning();
}else{
    //hideWarning();
}
	

};   

//======================================================================//
//=== Extend the removeOverlays function                             ===//
//======================================================================//
GMap2.prototype.removeGroupOverlays=function( overlayType, groupId, optParameter1 ) {

overlayCount = overlayCount - 1;

// Debug variable (set to 1 to debug)
var debug = 0;

if (debug)
    alert("Remove existing overlays on the map for group: " + groupId);
    
    // if there are existing overlays for the data
	// the map also needs to be updated based on those data
    var checkboxName = GetMapLayerCheckBoxName( groupId, optParameter1 );		
	tgChk = document.getElementById( checkboxName );



	// Currently, there is only one scenario where layers can be turned off
	// without associated checkboxes. That happens when the bus routes layers
	// needs to be turned off when user click on Reset button on the grid. 
	if (tgChk == null && optParameter1 != null)
    	{
	    toggleGroup( groupId, false );
	}
	else if (tgChk.checked)
	{
	    // All other scenarios should fall into here as associated checkbox
	    // on the menu should not be null.
        toggleGroup( groupId, false );
	}


	// This removes, in the map.overlays array, an entry for the id of the overlay,
	// and the group of the overlay. 
if (debug)
{
	alert("removeGroupOverlays: " + groupId);
	alert("remove overlays["+groupId+"].length: "+overlays[groupId].length);
}
    // Get reference to the current group of overlays
    var groupOverlays = overlays[groupId];

	for( i=groupOverlays.length - 1; i>=0; i-- ) {

if (debug)
    alert("Overlay id: " + overlayI.id + " should be removed.");
    
			// need to remove the overlaysgroup the overlays for toggling
			// has this overlay been marked for a group
			if( groupOverlays[i].group ) {
			    
				// Finally remove the overlays from the group's array
				// by setting that group
				
				if (debug)
				{
				    alert('Remove array value index at:' + i);
				    alert('remove the array value for group: '+groupOverlays[i].group);
				    alert('overlays['+groupOverlays[i].group+'].length: ' +overlays[groupOverlays[i].group].length);
				    alert('groupOverlays['+i+'].id: '+groupOverlays[i].id);
				}
			
			    // Remove associative array element based on overlay id	
				delete overlays[groupOverlays[i].group][groupOverlays[i].id];
				
				// Remove array element based on index
				overlays[groupOverlays[i].group].splice( i, 1 );
			}
	}
    
    // Remove the group in the array
    delete overlays[groupId];
        
	// remove the group in the groups array
    if( overlays['groups'] ) {
    
if (debug)
    alert("remove the groupId" + groupId + " from the array overlays['groups'].");
    
        for( j=0; j<overlays['groups'].length; j++ ) 
            if (overlays['groups'][j] == groupId)
                indexSpliceGroup = j;
    
        overlays['groups'].splice( indexSpliceGroup, 1 );
        groups--;
    }

if (debug)
{
    alert("Groups length after removal: "+overlays['groups'].length);
    
    for( j=0; j<overlays['groups'].length; j++ ) 
        alert("Groups Left: "+overlays['groups'][j]);
}

//alert("overlayCount 3 is: " + overlayCount);

if (overlayCount>10){
    //showWarning();
}else{
   // hideWarning();
}

};   

   

//*******************************************************************************
// Function:     filterMapBoundariesAndZoomLevel()
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.2
// Date:         Sep 05 2006
//
// Description:  Returns the query string for filtering
//               based on map boundaries and zoom level.
//
// Parameters:   
// Returns:      Returns the query string for filtering
//               based on map boundaries and zoom level.
// Calls:        
// Called By:    filterXXX() - where XXX can be one of the types of data
//                             such as advisories, cameras, etc.
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function filterMapBoundariesAndZoomLevel() {

// Debug variable (set to 1 to debug)
var debug = 0;

if (debug)
    alert('filterMapBoundariesAndZoomLevel');
    
    // Update the map and grid results
    // Retrieve the map coordinates and store them in cookies
    
    // find map coordinates
    var bounds = map.getBounds();
    var x1y1 = bounds.getSouthWest();
    var x2y2 = bounds.getNorthEast();
    var x1 = x1y1.lng();
    var y1 = x1y1.lat();
    var x2 = x2y2.lng();
    var y2 = x2y2.lat();

if (debug)
    alert('x1:' + x1 + ',' + 'y1:' + y1 + '<br />' +'x2:' + x2 + ',' + 'y2:' + y2);
    
    //find zoom level
    var zoom = map.getZoom();
if (debug)
    alert('zoomlevel:' + zoom);
            
    // The following has been commented out because it is no longer needed to store
    // the map coordinates and zoom level into cookies to communicate with server side.
//    // Store into cookies
//    Set_Cookie(x1CookieName, x1);
//    Set_Cookie(y1CookieName, y1);
//    Set_Cookie(x2CookieName, x2);
//    Set_Cookie(y2CookieName, y2);
//    Set_Cookie(PanOrZoomPostbackCookieName, true);
//    Set_Cookie(ZoomLevelCookieName, zoom);
                
    // Build individual query string for map coordinates
    x1QS = "";
    if (x1 != null)
        x1QS = "x1=" + x1;
if (debug)
    alert('x1QS: ' + x1QS);
    
    y1QS = "";
    if (y1 != null)
        y1QS = "y1=" + y1;
    
    x2QS = "";
    if (x2 != null)
        x2QS = "x2=" + x2;
            
    y2QS = "";
    if (y2 != null)
        y2QS = "y2=" + y2;
        
    zoomQS = "";
    if (zoom != null && zoom >= 0)
        zoomQS = "zoom=" + zoom;

    // Build query string
    queryString = "";
       
    if (x1QS != "")
    {    
        if (queryString != "")
            queryString += "&" + x1QS;
        else
            queryString = x1QS;
    }
    if (y1QS != "")
    {
        if (queryString != "")
            queryString += "&" + y1QS;
        else
            queryString = y1QS;
    }
    if (x2QS != "")
    {
        if (queryString != "")
            queryString += "&" + x2QS;
        else
            queryString = x2QS;
    }
    if (y2QS != "")
    {
        if (queryString != "")
            queryString += "&" + y2QS;
        else
            queryString = y2QS;
    }
    if (zoomQS != "")
    {
        if (queryString != "")
            queryString += "&" + zoomQS;
        else
            queryString = zoomQS;
    }

if (debug)
    alert('queryString: ' + queryString);
    
    return queryString;
}

//*******************************************************************************
// Function:     ResetHandler
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.3
// Date:         Sep 11, 2006
//
// Description:  Reload the map with advisories and cameras based on default criteria.
//               If map consists of advisories and cameras data, it will remove data 
//               and overlays, and re-add the data and overlays based 
//               default filtered criteria.
//
// Parameters:   
// Returns:      
// Calls:        LoadMapData(), LoadGridData()
// Called By:    Reset button on the map or reset button on the filter By search bar
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************    
function ResetHandler() {
    
    // The following methods need to be executed first before calling the 
    // SetDefaultMapCenterAndZoomLevel() function to pan/zoom map
    // because the filter criteria will be used each time
    ResetHTMLSelectOptions();
    ResetHTMLCheckboxes();
    ClearGridRelatedCookiesForTab();
    
    InitializeFilterBarCriteria();
    
    SetDefaultMapCenterAndZoomLevel();
    
    // manually call load grid data for special cases        
    LoadGridDataWhenNotPanAndZoom();

}

//*******************************************************************************
// Function:     ToggleLegend
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  This functions toggle the legend off and on when clicked
//
// Parameters:	 Div tag name
// Returns:	     n/a
// Calls:        n/a      
// Called By:    Click of Legend button on map    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function ToggleLegend( divName ){

	// Toggle the div off or on
	if( document.getElementById(divName).style.display == 'none')
	{
		document.getElementById(divName).style.display='inline';
	} else {
		document.getElementById(divName).style.display='none';
	}

	divName=null;
}


//*******************************************************************************
// Function:     ToggleDivs
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Description of function
//
// Parameters:   Div tag name to be toggled
// Returns:
// Calls:        HideAllLayersDivs() 
// Called By:    Click of toolbar images
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function ToggleDivs( divName ){

	//show the div tag if not already displayed
	if( document.getElementById(divName).style.display == 'none')
	{		
		//show the appropriate div tag that was clicked
		document.getElementById(divName).style.display='inline';

	} else {		
		document.getElementById(divName).style.display='none';
	}

	//reset divName
	divName=null;

}


//*******************************************************************************
// Function:     ToggleToolBarDiv
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Function shows/hides the toolbar when clicked
//
// Parameters:
// Returns:
// Calls:        
// Called By:    On click of the toolbar button in the interactive map control
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function ToggleToolBarDiv(){
			
	//show the toolbar icons if they are not currently displayed
	if( document.getElementById("divIcons").style.display == 'none')
	{
		document.getElementById("divIcons").style.display='inline';
	} 
	else
	{
		//hide all sub divs when we are closing the toolbar
		document.getElementById("divIcons").style.display='none';

	}
}


//*******************************************************************************
// Function:     createListener()
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Create listener and handler for the marker when it is clicked
//
// Parameters:   Marker that was clicked
// Returns:      Information displayed in the info box for the marker 
// Calls:        
// Called By:    When google maps marker is clicked
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function createListener( marker, optParameter1 ) {

	//GEvent.addListener( marker, "mouseover", function() {
	GEvent.addListener( marker, "click", function() {
	
   var publicTransitMarkersLayerName;  
   var blueBusTransitMarkersLayerName;  
    
    //build the Transit marker layer name dynamically, if optional parameter is passed
    if (optParameter1 != null ){

        publicTransitMarkersLayerName = "layer_TRA_Public_Marker_" + optParameter1;
        blueBusTransitMarkersLayerName = "layer_TRA_BlueBus_Marker_" + optParameter1;
    }    
    
	switch( String( marker.group ) ) {
	
        // dynamic layer names for the bus routes
//bus_test
        case "layer_Test_Route73Markers":
        case "layer_Test_Route218Markers":
        case "layer_Test_PerfTestMarkers":
        case "layer_Test_Route9Markers":
        case publicTransitMarkersLayerName:
        case blueBusTransitMarkersLayerName:	        
		case "layer_BusRouteTest_Marker":  {
		    							
    		//createTabbedMarker( marker, ["<table class='InfoBoxes' border=0 cellpadding=3 cellspacing=3 ><tr> <td width=60px>Stop:</td><td colspan=2><b>#"+marker.stopId+", "+marker.direction+"</b></td></tr><tr> <td valign=top>Location:</td> <td colspan=2 width=200px><b>"+marker.stopName+", "+marker.region+"</b></td></tr><tr> <td >Plan a trip:</td><td colspan=2><A target=_blank HREF='"+marker.planTripFromURL+"'><b>From this stop</b></A> -- <A target=_blank HREF='"+marker.planTripToURL+"'><b>To this stop</b></A></td></tr><tr> <td></td> <td colspan=2><A target=_blank HREF='"+marker.nextBusURL+"'><b>Next bus at this stop</b></A></td></tr><tr> <td colspan=3><U><b>Routes that stop here:</b></U></td></tr></table><div class='BusRouteStopsInfoWindowBody'><table>"+ marker.stopRoutesString+"</table></div>"], ["BusStop"] );
    		marker.openInfoWindowHtml("<table class='InfoBoxes' border=0 cellpadding=3 cellspacing=3 ><tr> <td width=60px>Stop:</td><td colspan=2><b>#"+marker.stopId+", "+marker.direction+"</b></td></tr><tr> <td valign=top>Location:</td> <td colspan=2 width=200px><b>"+marker.stopName+", "+marker.region+"</b></td></tr><tr> <td >Plan a trip:</td><td colspan=2><A target=_blank HREF='"+marker.planTripFromURL+"'><b>From this stop</b></A> -- <A target=_blank HREF='"+marker.planTripToURL+"'><b>To this stop</b></A></td></tr><tr> <td></td> <td colspan=2><A target=_blank HREF='"+marker.nextBusURL+"'><b>Next bus at this stop</b></A></td></tr><tr> <td colspan=3><U><b>Routes that stop here:</b></U></td></tr></table><div class='BusRouteStopsInfoWindowBody'><table>"+ marker.stopRoutesString+"</table></div>" );
		  break;        

        }
	
	    // Events Layer
    	case "layer_CurInc": 
        case "layer_CurCon": 
        case "layer_CurEv": 
        case "layer_EV_FutCon": 
        case "layer_EV_FutEv": 
        case "layer_EV_FutSrvc": 
        case "layer_EventsReal": {

            // default path to the image folder
            var rootImagePath="/ATIS/App_Themes/ATIS/images/";
            
            // variable to store the path to the icon image
		    var iconImage;
		    
		    //alert("yap event1");
		
            switch( String( marker.group ) ) {

                //Set the icon image's name for each type
                case "layer_CurInc" : { iconImage=rootImagePath+"atis-i-curincidents.gif"; break; }
                case "layer_CurCon" :  { iconImage=rootImagePath+"atis-i-curconstruction.gif";  break; } 	
                case "layer_CurEv" : { iconImage=rootImagePath+"atis-i-curevents.gif"; break; }         
                case "layer_EV_FutCon" :  { iconImage=rootImagePath+"atis-i-futconstruction.gif"; break; } 	
                case "layer_EV_FutEv" :  { iconImage=rootImagePath+"atis-i-futevents.gif"; break; } 	
                case "layer_EV_FutSrvc" :  { iconImage=rootImagePath+"atis-i-futserdisrupt.gif"; break; } 	
                           
   		        default: break;
		    }
			
			//alert("yap event2");
			
			//createTabbedMarker( marker, ["<table width=250px border=0><tr><td align=left>   <table class='InfoBoxes'  border=0 ><tr>	<td valign=top rowspan=3 width=25px>		<img hspace=3 vspace=3 border=0  src="+iconImage+">	</td>	<td width=190px>		<B>#"+marker.number+" <U>"+marker.shortdescr+"</B></U>	</td></tr><tr>	<td><b>"+marker.type+" : " +marker.priority+ "</b> </td></tr><tr>	<td><b>"+marker.status+"</b> </td></tr></table> </td></tr><tr><td align=left> <div class='EventsInfoWindowBody'><table  class='InfoBoxes' width=215px border=0 ><tr>	<td  >Address:</td><td width=180px><b>"+marker.address+"</b> </td></tr><tr>	<td >Start Time: </td><td><b>"+marker.started+"</b> </td></tr><tr>	<td >Updated: </td><td><b>"+marker.updatedDate+"</b> </td></tr><tr>	<td >Duration: </td><td><b>"+marker.durationPeriod+"</b> </td></tr><tr>	<td valign=top>Additional: </td><td><b>"+marker.longdescr+"</b> </td></tr><tr>	<td valign=top>Advice: </td><td><b>"+marker.advice+"</b> </td></tr></table></div>  </td></tr></table>"], ["Events Test"] );
			marker.openInfoWindowHtml("<table width=250px border=0><tr><td align=left>   <table class='InfoBoxes'  border=0 ><tr>	<td valign=top rowspan=3 width=25px>		<img hspace=3 vspace=3 border=0  src="+iconImage+">	</td>	<td width=190px>		<B>#"+marker.number+" <U>"+marker.shortdescr+"</B></U>	</td></tr><tr>	<td><b>"+marker.type+" : " +marker.priority+ "</b> </td></tr><tr>	<td><b>"+marker.status+"</b> </td></tr></table> </td></tr><tr><td align=left> <div class='EventsInfoWindowBody'><table  class='InfoBoxes' width=215px border=0 ><tr>	<td  >Address:</td><td width=180px><b>"+marker.address+"</b> </td></tr><tr>	<td >Start Time: </td><td><b>"+marker.started+"</b> </td></tr><tr>	<td >Updated: </td><td><b>"+marker.updatedDate+"</b> </td></tr><tr>	<td >Duration: </td><td><b>"+marker.durationPeriod+"</b> </td></tr><tr>	<td valign=top>Additional: </td><td><b>"+marker.longdescr+"</b> </td></tr><tr>	<td valign=top>Advice: </td><td><b>"+marker.advice+"</b> </td></tr></table></div>  </td></tr></table>");
			break;
		} 
		    
        // Cameras Layer
		case "layer_CAM_Border": 
		case "layer_CAM_TrafficInt": 
		case "layer_CAM_TrafficHigh":  
		case "layer_CAM_Port": 
		case "layer_CamerasReal": {
		    		    
            // Encode the string passed as query string
            DescriptionEncoded = URLEncode(marker.shortDescr);
            
            //alert(marker.ImageUrl);
            
            //check to see if the ImageUrl has MOT "getFile.aspx", and then append timestamp at the back with "&" symbol

        var lImageTestTemp = marker.ImageUrl;        
        var lImageTest=0;
        var lImageNewURL;
        var lImageNewSrcURL;

        //check to see if image is from the new MOT data
        lImageTest = lImageTestTemp.indexOf('getFile.aspx');   

        if (lImageTest != -1){        
            //alert("yes: " + lImageTestTemp);            
            ImageURLEncoded = URLEncode(marker.ImageUrl);
            
            //create the new image on click URL
            lImageNewURL = ImageURLEncoded + getTimeStampAndQueryString();
            
            //create the new image source URL                            
            lImageNewSrcURL = marker.ImageUrl + getTimeStampAndQueryString();
            
        } else {
            //alert("no: " + lImageTestTemp);            
            ImageURLEncoded = URLEncode(marker.ImageUrl);
            
            //create the new image on click URL
            lImageNewURL = ImageURLEncoded + getTimeStampQueryString();
            
            //create the new image source URL                            
            lImageNewSrcURL = marker.ImageUrl + getTimeStampQueryString();
        }
                  

        //alert(lImageNewURL);

            marker.openInfoWindowHtml("<table class='InfoBoxes' border=0><tr><td rowspan=3 width=105px>" + 
                                "<a href='#' onclick=\"window.open('/IndividualCamera?PictureURL="+lImageNewURL+"&Name="+DescriptionEncoded+"','_blank','width=450,height=550')\">" +
                                "<img border=0 width=100px height=100px src='"+lImageNewSrcURL+"'></a></a></td>" + 
                                "<td valign=top width=150px><B><U>"+marker.shortDescr+"</B></U></td></tr><tr>" +
                                "<td valign=top>Camera is pointing "+marker.primaryDirection+" </td></tr><tr><td>&nbsp; </td></tr></table>" );

                                 //old camera picture lines
                                //"<a href='#' onclick=\"window.open('/IndividualCamera?PictureURL="+ImageURLEncoded+getTimeStampQueryString()+"&Name="+DescriptionEncoded+"','_blank','width=450,height=550')\">" +
                                //"<img border=0 width=100px height=100px src='"+marker.ImageUrl+getTimeStampQueryString()+"'></a></a></td>" + 


			break;

		}

        //this is the generic service listener for info boxes
        //case "layer_Border" : *** Note: commented out for Drew's new method below ****

case "layer_USBorder" :  
        
        case "layer_RAIL_Railroads" : 
        case "layer_ViaRail" : 
        case "layer_RAIL_RockyMtn" :         
        case "layer_Amtrak" :         
        case "layer_RAIL_RailAccess" : 
        
        case "layer_IntAir" :
        case "layer_RegAir" :
        case "layer_AIR_HrbrAir" :
        case "layer_AIR_WestCoastAir" :
        case "layer_AIR_Helijet" :

        case "layer_MA_Ports" :
	    case "layer_MA_CruiseLines" :
	    case "layer_MA_CustomEntry" :
	    case "layer_MA_FalseCreek" :
	    case "layer_MA_MarineAccess" :

        case "layer_Albion":        
	    case "layer_BCFerries" :
        case "layer_TRA_Boundaries_Marker":
        case "layer_TRA_SeaBus_Marker":
        case "layer_TRA_Greyhound" : { 

		    //createTabbedMarker( marker, ["<table border=0 cellpadding=3 cellspacing=3 width=250px><tr><td colspan=2 align='left'><a target=_blank href='"+marker.link+"'><img height='"+marker.imgHeight+"' width='100px' alt='"+marker.name+"' border=0 src='"+marker.image+"' /></a></td></tr><tr><td align='left'>Name:</td><td align='left'><b>"+marker.name+"</b> </td></tr><tr><td colspan=2 align='left'><a href='"+marker.link+"' target=_blank><b>Visit Website</b></a></td></tr>  <tr><td valign=top align='left'>Description:</td><td><div class='ServiceDescText'><table align=left><tr><td valign=top align=left><b>"+marker.description+"</b> </td> </tr></table></div></td> </tr></table>"], ["Ferry Terminal"] );
		    marker.openInfoWindowHtml("<table border=0 cellpadding=3 cellspacing=3 width=250px><tr><td colspan=2 align='left'><a target=_blank href='"+marker.link+"'><img height='"+marker.imgHeight+"' width='100px' alt='"+marker.name+"' border=0 src='"+marker.image+"' /></a></td></tr><tr><td align='left'>Name:</td><td align='left'><b>"+marker.name+"</b> </td></tr><tr><td colspan=2 align='left'><a href='"+marker.link+"' target=_blank><b>Visit Website</b></a></td></tr>  <tr><td valign=top align='left'>Description:</td><td><div class='ServiceDescText'><table align=left><tr><td valign=top align=left><b>"+marker.description+"</b> </td> </tr></table></div></td> </tr></table>");
			break;
		}

        //*** Note: Drew's new Border method to grab xml data from the Highways sign****
        
        //TODO:  Brian new US border layer below
        
        //case "layer_USBorder" :  
        case "layer_Border" : { 
			//Initialize the Variables
			var description = "";
			xmlDocDescription = "";
			xmlDocTag_ID = "";
			xmlDocTag_TAG = "";

			//If the <HIGHWAYSIGN> tag is in the Marker's Description, then add the XML data
			if (marker.description.indexOf("<HIGHWAYSIGN") != -1) {

				//Example Data Tag for marker.description
				//<HIGHWAYSIGN id='14222305720482' tag='msgPhase1'></HIGHWAYSIGN><BR/><BR/>Peace Arch Border Crossing
				var xmlDocTag;
				var xmlDocTag_ATTR;
				var xmlDocTag_ATTR2;

				//Reduce the xmlDocTag down to
				//<HIGHWAYSIGN id='14222305720482' tag='msgPhase1'>
				xmlDocTag = marker.description.substring(0,marker.description.indexOf("</HIGHWAYSIGN>"));

				//Get the 2 ATTRIBUTES of the <HIGHWAYSIGN> tag and place them in the correct variables
				xmlDocTag_ATTR = xmlDocTag;
				//Replace all the Double-Quotes with Single-Quotes (Makes further code easier)
				while (xmlDocTag_ATTR.indexOf('"') != -1) {
					xmlDocTag_ATTR = xmlDocTag_ATTR.replace('"',"'");
				}

				//Determine which ATTRIBUTE is first
				xmlDocTag_ATTR2 = xmlDocTag_ATTR.substring(xmlDocTag_ATTR.indexOf("=")-3,xmlDocTag_ATTR.indexOf("="));
				xmlDocTag_ATTR2 = xmlDocTag_ATTR2.toUpperCase();
				if (xmlDocTag_ATTR2==' ID') {
					xmlDocTag_ATTR = xmlDocTag_ATTR.substring(xmlDocTag_ATTR.indexOf("='")+2,xmlDocTag_ATTR.length);
					xmlDocTag_ID = xmlDocTag_ATTR.substring(0,xmlDocTag_ATTR.indexOf("'"));
				} else {
					xmlDocTag_ATTR = xmlDocTag_ATTR.substring(xmlDocTag_ATTR.indexOf("='")+2,xmlDocTag_ATTR.length);
					xmlDocTag_TAG = xmlDocTag_ATTR.substring(0,xmlDocTag_ATTR.indexOf("'"));
				}

				//Advance the xmlDocTag_ATTR variable forward one position
				xmlDocTag_ATTR = xmlDocTag_ATTR.substring(xmlDocTag_ATTR.indexOf("=")+1,xmlDocTag_ATTR.length);

				//Determine which ATTRIBUTE is second
				xmlDocTag_ATTR2 = xmlDocTag_ATTR.substring(xmlDocTag_ATTR.indexOf("=")-3,xmlDocTag_ATTR.indexOf("="));
				xmlDocTag_ATTR2 = xmlDocTag_ATTR2.toUpperCase();
				if (xmlDocTag_ATTR2==' ID') {
					xmlDocTag_ATTR = xmlDocTag_ATTR.substring(xmlDocTag_ATTR.indexOf("='")+2,xmlDocTag_ATTR.length);
					xmlDocTag_ID = xmlDocTag_ATTR.substring(0,xmlDocTag_ATTR.indexOf("'"));
				} else {
					xmlDocTag_ATTR = xmlDocTag_ATTR.substring(xmlDocTag_ATTR.indexOf("='")+2,xmlDocTag_ATTR.length);
					xmlDocTag_TAG = xmlDocTag_ATTR.substring(0,xmlDocTag_ATTR.indexOf("'"));
				}

				//As long as we have an ID to get data for, then get the data, otherwise we are on a Border Crossing icon which does not require extra data.
				if (xmlDocTag_ID != "" && xmlDocTag_TAG != "") {
					xmlDoc_loadXML();
				}

				//Create the Description for the Border Crossing popup in the GoogleMap.
				//	We make sure that any extra data (from the XML file) is displayed first.
				description += xmlDocDescription;
			}
			description += marker.description;

			//Create the popup in the Google Map.
	        	marker.openInfoWindowHtml("<table border=0 cellpadding=3 cellspacing=3 width=250px><tr><td colspan=2 align='left'><a target=_blank href='"+marker.link+"'><img height='"+marker.imgHeight+"' alt='"+marker.name+"' border=0 src='"+marker.image+"' /></a></td></tr><tr><td align='left'>Name:</td><td align='left'><b>"+marker.name+"</b> </td></tr><tr><td colspan=2 align='left'><a href='"+marker.link+"' target=_blank><b>Visit Website</b></a></td></tr>  <tr><td valign=top align='left'>Description:</td><td><div class='ServiceDescText'><table align=left><tr><td valign=top align=left><b>"+description+"</b> </td> </tr></table></div></td> </tr></table>" );
			break;
		}

      
        case "layer_ROD_HwaySigns" : { 
		
		    marker.openInfoWindowHtml("<table  class='InfoBoxes' width=225px cellspacing=3 cellpadding=3 border=0 ><tr>	<td valign=top>Message:</td>	<td width=180px valign=top><b>"+marker.msgPhase1+"</b> </td></tr><tr>	<td >Updated: </td>	<td>"+marker.lastUpdateTime+" </td></tr></table>" );
			break;
		}	
		
		// Other layers				

		case "layer_Weather": {
		
		//alert("yap weather");
			//createTabbedMarker( marker, ["<table class='InfoBoxes' border=0><tr><td><div class='WeatherRealInfoWindowBody'><table class='InfoBoxes' border=0>  <tr>  <td colspan=3>	<u><b>Current Conditions:</b></U>&nbsp;&nbsp;"+marker.current_forecast+"  </td> </tr> <tr>   <td rowspan=2 ><img border=0 src='"+marker.current_icon+"' ></td>   <td>TEMP</td>   <td><b>"+marker.current_temperature+"<b></td> </tr> <tr>     <td >WIND</td>     <td><b>"+marker.current_wind+"</b></td> </tr> <tr>     <td></td>     <td colspan=2 class='WeatherSmall'>"+marker.current_date+" <br>"+marker.current_station+"  </font></td> </tr>    <tr>      <td colspan=3><b>"+ marker.short1name +": " +marker.short1forecast +"</b></td> </tr><tr>   <td rowspan=3 valign=top ><img border=0 src='/atis/app_themes/atis/images/weather_icons/"+marker.short1icon+".gif' ></td>   <td >TEMP</td>   <td ><b>"+marker.short1temp+"</b></td> </tr> <tr>    <td >P.O.P.</td>    <td><B>"+marker.short1pop+"</B></td> </tr> <tr>    <td>WIND</td>    <td><b>"+marker.short1wind+"</b></td> </tr><tr><td colspan=3>&nbsp;</td></tr><tr>      <td colspan=3><b>"+ marker.short2name +": " +marker.short2forecast +"</b></td> </tr><tr>   <td rowspan=3 valign=top><img border=0 src='/atis/app_themes/atis/images/weather_icons/"+marker.short2icon+".gif' ></td>   <td >TEMP</td>  <td ><b>"+marker.short2temp+"</b></td> </tr> <tr>    <td >P.O.P.</td>    <td><B>"+marker.short2pop+"</B></td> </tr> <tr>    <td>WIND</td>    <td><b>"+marker.short2wind+"</b></td> </tr><tr><td colspan=3>&nbsp;</td></tr><tr>      <td colspan=3><b>"+ marker.short3name +": " +marker.short3forecast +"</b></td> </tr><tr>   <td rowspan=3 valign=top><img border=0 src='/atis/app_themes/atis/images/weather_icons/"+marker.short3icon+".gif' ></td>   <td >TEMP</td>  <td ><b>"+marker.short3temp+"</b></td> </tr> <tr>    <td >P.O.P.</td>    <td><B>"+marker.short3pop+"</B></td> </tr> <tr>    <td>WIND</td>    <td><b>"+marker.short3wind+"</b></td> </tr><tr><td colspan=3>&nbsp;</td></tr><tr>      <td colspan=3><b>"+ marker.short4name +": " +marker.short4forecast +"</b></td> </tr><tr>   <td rowspan=3 valign=top><img border=0 src='/atis/app_themes/atis/images/weather_icons/"+marker.short4icon+".gif' ></td>   <td >TEMP</td>  <td ><b>"+marker.short4temp+"</b></td> </tr> <tr>    <td >P.O.P.</td>    <td><B>"+marker.short4pop+"</B></td> </tr> <tr>    <td>WIND</td>    <td><b>"+marker.short4wind+"</b></td> </tr></table></div> <tr><td>&copy; 2007  The Weather Network &nbsp;&nbsp;&nbsp;<a  href=\"#\" id=\"_ctl0_HeaderControl1_weatherLink\" class=\"footNav\" onclick=\"window.open('/Weather?region=" + marker.site_name + "','_blank','width=660,height=670,scrollbars=yes');return false;\">more</a></td></tr></table>    "], ["Current"] );
			marker.openInfoWindowHtml("<table class='InfoBoxes' border=0><tr><td><div class='WeatherRealInfoWindowBody'><table class='InfoBoxes' border=0>  <tr>  <td colspan=3>	<u><b>Current Conditions:</b></U>&nbsp;&nbsp;"+marker.current_forecast+"  </td> </tr> <tr>   <td rowspan=2 ><img border=0 src='"+marker.current_icon+"' ></td>   <td>TEMP</td>   <td><b>"+marker.current_temperature+"<b></td> </tr> <tr>     <td >WIND</td>     <td><b>"+marker.current_wind+"</b></td> </tr> <tr>     <td></td>     <td colspan=2 class='WeatherSmall'>"+marker.current_date+" <br>"+marker.current_station+"  </font></td> </tr>    <tr>      <td colspan=3><b>"+ marker.short1name +": " +marker.short1forecast +"</b></td> </tr><tr>   <td rowspan=3 valign=top ><img border=0 src='/atis/app_themes/atis/images/weather_icons/"+marker.short1icon+".gif' ></td>   <td >TEMP</td>   <td ><b>"+marker.short1temp+"</b></td> </tr> <tr>    <td >P.O.P.</td>    <td><B>"+marker.short1pop+"</B></td> </tr> <tr>    <td>WIND</td>    <td><b>"+marker.short1wind+"</b></td> </tr><tr><td colspan=3>&nbsp;</td></tr><tr>      <td colspan=3><b>"+ marker.short2name +": " +marker.short2forecast +"</b></td> </tr><tr>   <td rowspan=3 valign=top><img border=0 src='/atis/app_themes/atis/images/weather_icons/"+marker.short2icon+".gif' ></td>   <td >TEMP</td>  <td ><b>"+marker.short2temp+"</b></td> </tr> <tr>    <td >P.O.P.</td>    <td><B>"+marker.short2pop+"</B></td> </tr> <tr>    <td>WIND</td>    <td><b>"+marker.short2wind+"</b></td> </tr><tr><td colspan=3>&nbsp;</td></tr><tr>      <td colspan=3><b>"+ marker.short3name +": " +marker.short3forecast +"</b></td> </tr><tr>   <td rowspan=3 valign=top><img border=0 src='/atis/app_themes/atis/images/weather_icons/"+marker.short3icon+".gif' ></td>   <td >TEMP</td>  <td ><b>"+marker.short3temp+"</b></td> </tr> <tr>    <td >P.O.P.</td>    <td><B>"+marker.short3pop+"</B></td> </tr> <tr>    <td>WIND</td>    <td><b>"+marker.short3wind+"</b></td> </tr><tr><td colspan=3>&nbsp;</td></tr><tr>      <td colspan=3><b>"+ marker.short4name +": " +marker.short4forecast +"</b></td> </tr><tr>   <td rowspan=3 valign=top><img border=0 src='/atis/app_themes/atis/images/weather_icons/"+marker.short4icon+".gif' ></td>   <td >TEMP</td>  <td ><b>"+marker.short4temp+"</b></td> </tr> <tr>    <td >P.O.P.</td>    <td><B>"+marker.short4pop+"</B></td> </tr> <tr>    <td>WIND</td>    <td><b>"+marker.short4wind+"</b></td> </tr></table></div> <tr><td>&copy; 2007  The Weather Network &nbsp;&nbsp;&nbsp;<a  href=\"#\" id=\"_ctl0_HeaderControl1_weatherLink\" class=\"footNav\" onclick=\"window.open('/Weather?region=" + marker.site_name + "','_blank','width=660,height=670,scrollbars=yes');return false;\">more</a></td></tr></table>    ");
			break;
	
			
		} case "layer_TRA_Exch": {
			marker.openInfoWindowHtml("<table width='300px' class='InfoBoxes'><tr><td><font color='#0D258F'><b>"+marker.exchangeName+"</b></font></td></tr><tr><td><div class='ExchangesInfoWindowBody'>" + marker.exchangeTable + "</div></td></tr></table> " );
			break;

		} case "layer_WstCstExpr_Marker": {
			marker.openInfoWindowHtml("<table class='InfoBoxes'><tr><td> <b>West Coast Express Stop: </b><br><br>" + marker.stopName + "<br/></td></tr></table> " );
			break;

		} case "layer_ROD_FacStatus": {
			marker.openInfoWindowHtml("<table class='InfoBoxes' ><tr><td> <b>" + marker.name+ "</b></td></tr><tr><td>&nbsp;</td></tr><tr><td>" + marker.state + "</td></tr></table> " );
			break;

		} case "layer_Parking":  {
						
			//marker.openInfoWindowHtml("<table class='InfoBoxes'><tr><td> <b>Park and Ride: </b><br><br>" + marker.name + "<br/></td></tr></table> " );
			marker.openInfoWindowHtml("<table width='300px' class='InfoBoxes' cellspacing=3 cellpadding=3><tr><td colspan=2><b>" + marker.name + "</b></td></tr><tr><td>Address:</td><td><b>" + marker.address + "</b></td></tr><tr><td>Access:</td><td><b>" + marker.access + "</b></td></tr><tr><td>Associated Exchange:</td><td><b>" + marker.associatedExchange + "</b></td></tr><tr><td>Number of Stalls:</td><td><b>" + marker.numberOfStalls + "</b></td></tr><tr><td>Rates:</td><td><b>" + marker.rates + "</b></td></tr><tr><td>Notes:</td><td><b>" + marker.notes + "</b></td></tr></table> " );
			break;

		} case "layer_ROD_NonKeyLandmarks": 
		  case "layer_ROD_Landmarks":  {

			marker.openInfoWindowHtml("<table width=250px class='InfoBoxes' cellspacing=3 cellpadding=3><tr><td><b>" + marker.name + "</b></td></tr><tr><td>" + marker.address + "</td></tr></table> " );
			break;

        } case "layer_COM_Weigh":  {
		
			marker.openInfoWindowHtml("<table class='InfoBoxes' cellspacing=3 cellpadding=3><tr><td colspan=2><b>Weight Station</b></td></tr><tr><td>Region:</td><td><b>" + marker.region + "</b></td></tr><tr><td>City:</td><td><b>" + marker.city + "</b></td></tr><tr><td>Organization:</td><td><b>" + marker.organization + "</b></td></tr><tr><td>Street Name:</td><td><b>" + marker.streetName + "</b></td></tr></table> " );
			break;
			
		} case "layer_COM_Restrictions":  {
						
			marker.openInfoWindowHtml("<table width=250px class='InfoBoxes'><tr><td> <b>Dangerous Goods Restriction: </b><br><br>" + marker.name + "<br/></td></tr><tr><td><br>" + marker.descr + "</td></tr></table> " );
			break;

		}
		
		 case "layer_MilLine_Marker":
		 case "layer_ExpoLine_Marker": {
			marker.openInfoWindowHtml("<table class='InfoBoxes'><tr><td> <b>Skytrain Stop: </b><br><br>" + marker.stopName + "<br/></td></tr></table> " );
			break;

		} default: {
				marker.openInfoWindowHtml(
				"<b>Group: </b>" + marker.group + "<br/>" +
				"<b>ID: </b>" + marker.id + "<br/><br/>" );
		}
	}
      }
   );
}

//*******************************************************************************
// Function:     createTabbedMarker
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Create a tabbed marker and set up the event window. 
//		 This version accepts a variable number of tabs, passed in the
//		 arrays htmls[] and labels[].
//
// Parameters:   marker, htmls[], labels[]
// Returns:      tabbed marker
// Calls:        
// Called By:    CreateListener    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function createTabbedMarker( marker, htmls, labels ) {

	// adjust the width so that the info window is large enough for this many tabs
	if( htmls.length > 2 ) htmls[0] = '<div style="width:150px">' + htmls[0] + '</div>';

	//if( htmls.length > 2 ) htmls[0] = '<div style="width:'+htmls.length*88+'px">' + htmls[0] + '</div>';
	var tabs = [];
	for( var i=0; i<htmls.length; i++ ) tabs.push( new GInfoWindowTab( labels[i], htmls[i]  ) );
	marker.openInfoWindowTabsHtml( tabs );
	return marker;
}


//*******************************************************************************
// Function:     toggleButtonGroup
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Function toggles on/off the button group that was clicked on the map
//
// Parameters:   Control to be toggled
// Returns:
// Calls:        toggleGroup   
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function toggleButtonGroup( control, group, button ) {

// Debug variable (set to 1 to debug)
var debug = 0;

if (debug)
    alert("control: " + control + " & group: " + group + " & button: " + button);
    	
	//toggle on the group that was checked off on the map
	if( control.checked ) {
		toggleGroup( group, true );
		activeLayers.push( control.id );

	//toggle off the group that was checked off on the map
	} else {

		toggleGroup( group, false );
		for( i=0;i<activeLayers.length;i++ ) {
			if( control.id == activeLayers[i] ) activeLayers.splice( i, 1 );
        }
   }
}

//*******************************************************************************
// Function:     toggleGroup
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Toggles the passed overlay on/off
//
// Parameters:   Group to be toggled, and visibility
// Returns:
// Calls:        
// Called By:    toggleButtonGroup
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function toggleGroup( group, show ) {

// Debug variable (set to 1 to debug)
var debug = 0;


    if (overlays[group] != null){        
       // alert("Toggle Group: " + group + " to show: " + show + " with length: " + overlays[group].length);
    }else{        
        //alert("Toggle Group: " + group + " to show: " + show + " with length: null");
    }    


    if (overlays[group] == null)
    {
if (debug)
    alert("overlays["+group+"] is null");
    
        return;
    }

	//add the group overlay if it is to be shown on the map, or else remove it
	for(x=0; x<overlays[group].length; x++ ) {
	    
		if ( show ) 
		{
if (debug)
    alert("Show overlays[" + group + "][" + x + "]: " + overlays[group][x].id);
    
		   map.addOverlay( overlays[group][x] ); 
		   
        }
        else 
        {
if (debug)
    alert("Hide overlays[" + group + "][" + x + "]: " + overlays[group][x].id);
    
            map.removeOverlay( overlays[group][x] );
        }
	}
	
if (debug)
    alert("FINISH ToggleGroup()");
}

//*******************************************************************************
// Function:     generateShadowIcon
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Function generates a clickable shadowed GIcon for the map
//
// Parameters:   Image location, image width, image height, and shadow file
// Returns:      Icon for map
// Calls:        
// Called By:    InitGroupLayers()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function generateShadowIcon( hasShadow, imageLocation, iconWidth, iconHeight, imageShadow, shadowWidth, shadowHeight ) {
	// Create a base icon for all of our markers that specifies the shadow, icon dimensions, etc.
	var baseIcon = new GIcon();

    //return a GIcon with a shadow
    if (hasShadow==true){
    
	    if (imageShadow==null){
		    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	    } else {
		    baseIcon.shadow = imageShadow
	    }

	    if (iconWidth==null){
		    iconWidth=20;
		    iconHeight=34;
	    }

	    if (shadowWidth==null){
		    shadowWidth=20;
		    shadowHeight=34;
	    }

	    baseIcon.iconSize = new GSize(iconWidth, iconHeight);
	    baseIcon.shadowSize = new GSize(shadowWidth,shadowHeight);	
	    baseIcon.iconAnchor = new GPoint(5, 17);
	    baseIcon.infoWindowAnchor = new GPoint(5, 1);
	    baseIcon.infoShadowAnchor = new GPoint(18, 25);

	    var icon = new GIcon(baseIcon);
	    icon.image = imageLocation;

	    return icon;

    //return a GIcon without a shadow
    } else {
    

        if (imageShadow==null){
		    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	    } else {
		    baseIcon.shadow = imageShadow;
	    }

	    if (iconWidth==null){
		    iconWidth=20;
		    iconHeight=34;
	    }

	    baseIcon.iconSize = new GSize(iconWidth, iconHeight);
	    baseIcon.shadowSize = new GSize(0,0);
	    baseIcon.iconAnchor = new GPoint(5, 5);
	    baseIcon.infoWindowAnchor = new GPoint(5, 1);	
	    var icon = new GIcon(baseIcon);
	    icon.image = imageLocation;

	    return icon;
    
    }	    
}


//*******************************************************************************
// Function:     regenerateGroupMarkers
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.2
// Date:         Sep 01 2006
//
// Description:  Regenerate markers for events or cameras
//
// Parameters:   Group name, xml data file, icon
// Returns:      Group of markers
// Calls:        
// Called By:    LoadMapData()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//  Michael Chu  Nov 10, 2006 Remove code for removing existing overlays
//                            and move into new function RemoveLayerIfLayerExists()
//                            which will be called by generateGroupMarkers() and
//                            generateGroupPolylines()
//*******************************************************************************
function regenerateGroupMarkers( groupId, datafile, icon, optParameter1 ) {

// Debug variable (set to 1 to debug)
var debug = 0;

if (debug)
    alert('RegenerateGroupMarkers: ' + groupId);
   
    
 	
	    // generate group markers
        generateGroupMarkers(groupId, datafile, icon, optParameter1 );

if (debug)
{
    if (overlays != null)
        if (overlays['groups'] != null)
        {
            alert("After add: overlays['groups'].length: " + overlays['groups'].length);
            for( j=0; j<overlays['groups'].length; j++ ) 
                alert("overlays['groups'][" + j + "]: " + overlays['groups'][j]);
        }
 }

}

//*******************************************************************************
// Function:     hasGroupLayer
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.2
// Date:         Sep 06 2006
//
// Description:  Check if a layer's data has been loaded in memory
//
// Parameters:   Group id - group layer name
// Returns:      True if layer data exists in memeory, otherwise false.
// Calls:        
// Called By:    regenerateGroupMarkers()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function hasGroupLayer( groupId ) {

// Debug variable (set to 1 to debug)
var debug = 0;

if (debug)
    alert("hasGroupLayer(): " + groupId);
    
    if (overlays != null)
        if (overlays['groups'] != null)
        {
if (debug)
    alert("overlays['groups'].length: " + overlays['groups'].length);
    
            for( j=0; j<overlays['groups'].length; j++ ) 
            {
if (debug)
{
    alert("j: " + j);
    alert("overlays['groups'][" + j + "]: " + overlays['groups'][j]);
    alert("groupId: " + groupId);    
}
                if (overlays['groups'][j] == groupId)
                    return 1;
            }
        }   
    return 0;
}


//*******************************************************************************
// Function:     generateGroupMarkers
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.2
// Date:         Sep 06 2006
//
// Description:  Generate markers for advisories, or cameras.
//
// Parameters:   Group name, xml data file, icon
// Returns:      Group of markers
// Calls:        
// Called By:    InitGroupLayers()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//  Michael Chu  Sep 06 2006 Refactor the functions generateEventGroupMarkers(), 
//                           generateCameraGroupMarkers() to using this function 
//                           instead.
//*******************************************************************************
function generateGroupMarkers( groupId, datafile, icon, optParameter1 ) {

showLoading();

//debugger

    var transitMarkersLayerName;
    
    //build the Transit marker layer name dynamically, if optional parameter is passed
    if (optParameter1 != null ){
        transitMarkersLayerName = "layer_TRA_Public_Marker_" + optParameter1;
    }


// Debug variable (set to 1 to debug)
var debug = 0;

    var data = [];

if (debug)
    alert('datafile: ' + datafile);
    
    //document.getElementById("divLoading").innerHTML= loadingMessageHTML;								
    
//debugCouldNotReadMemoryError(datafile, "generateMarker");
if (debugThreadAJAX)
{
    countThreadAJAX++;
    
    if (countThreadAJAX > 2)
        alert("countThreadAJAX: " + countThreadAJAX);
}   

    // append timestamp so data returned are fresh
    datafile = timeStampUrl(datafile);

    // download markers data from xml
    GDownloadUrl( datafile, function( data, responseCode ) {

if (debugPerformance)
    PrintElapseTime("generateGroupMarkers(): start parsing datafile for markers: " + datafile);

if (debugThreadAJAX)
{
    countThreadAJAX--;
}   
    
    
    //document.getElementById("divLoading").innerHTML= loadingMessageHTML;								
    
    //alert("download url started");

if (debug)
    alert('GDownloadUrl passed: ' + datafile);
        
        // Remove existing layer
        RemoveLayerIfLayerExists(groupId, optParameter1);
        
	    var xml = GXml.parse( data );
	    var xmlMarkers = [];
	    var markers = [];
	    var points = [];
	    
	    //new array for marker mouseover tooltips
	    var tooltips = [];
	    
	    // XML file related variables
    	var childElementName = "";  // the first child element of the root
    	var childNodeLatLong = -1; // the index of the node that contains the latitude and longitude
    	
    	var toggleBasedOnZoomLevel = false;
    	
    	switch( groupId ) {

    	    // Events Layer
            case "layer_MilLine_Marker":
    	    case "layer_ExpoLine_Marker": {
		        childElementName = "stop";	
		        childNodeLatLongName = "point";
			    break;
		    } 

//bus_test
        case "layer_Test_Route73Markers":
            case "layer_Test_Route218Markers":
            case "layer_Test_PerfTestMarkers":
            case "layer_Test_Route9Markers":
    	    case "layer_BusRouteTest_Marker": {
		        childElementName = "stop";	
		        childNodeLatLongName = "point";
			    break;
		    } 
    
            //this is the dynamic transit markers layer
    	    case transitMarkersLayerName: {

		        childElementName = "stop";	
		        childNodeLatLongName = "point";
		        
                // SPECIAL CASE: toggle off bus route markers 
                // if under specified zoom level
                
                toggleBasedOnZoomLevel = true;
                
			    break;
		    } 
    	
    	    // Events Layer
    	    case "layer_CurInc": 
    	    case "layer_CurCon": 
    	    case "layer_CurEv": 
    	    case "layer_EV_FutCon": 
    	    case "layer_EV_FutEv": 
    	    case "layer_EV_FutSrvc": 
    	    case "layer_EventsReal": {
    	    
    	    //alert("yap turning events on ");
    	    
		        childElementName = "event";	
		        childNodeLatLongName = "primaryPoint";
			    break;
		    } 
		    
		    // Cameras Layer
		    case "layer_CAM_Border": 
		    case "layer_CAM_TrafficInt": 
		    case "layer_CAM_TrafficHigh":  
		    case "layer_CAM_Port": 
		    case "layer_CamerasReal": {
		    		    
		        childElementName = "camera";	
		        childNodeLatLongName = "point";
			    break;
		    }
		    
		    // Commercial Layer
    	    case "layer_COM_Restrictions" : { 
		    		    
		        childElementName = "restriction";	
		        childNodeLatLongName = "point";
			    break;
		    }

		    case "layer_COM_Weigh" : {
		    
		        childElementName = "weighStation";	
		        childNodeLatLongName = "point";
			    break;
		    }
	        
	        //Brian: new US border layer
	        case "layer_USBorder" :
	        case "layer_Border" :
	        case "layer_BCFerries" :

	        case "layer_IntAir" :
	        case "layer_RegAir" : { 
		    		    
		        childElementName = "service";	
		        childNodeLatLongName = "point";
			    break;
		    }
		    
		    //Weather layers
            case "layer_Weather" : { 
                
                childElementName = "SITE";	
		        childNodeLatLongName = "point";
                break; 
            } 

            // Road Layers
            case "layer_ROD_HwaySigns" : { 
                childElementName = "sign";	
		        childNodeLatLongName = "point";
                break; 
            } 
            case "chk_ROD_Cong" : { 
                childElementName = "detector";	
		        childNodeLatLongName = "point";
                break; 
            } 

            case "layer_Parking" : { 
		    		    
		        childElementName = "park";	
		        childNodeLatLongName = "point";
			    break;
		    }

            case "layer_ROD_NonKeyLandmarks" : 
            case "layer_ROD_Landmarks" : { 
    
		        childElementName = "landMark";	
		        childNodeLatLongName = "point";
			    break;
		    }

            case "layer_ROD_FacStatus" : { 
		    		    
		        childElementName = "center";	
		        childNodeLatLongName = "point";
			    break;
		    }
            
            //Transit layers
            case "layer_TRA_Exch" : { 
		    		    
		        childElementName = "exchange";	
		        childNodeLatLongName = "point";
			    break;
		    }
  
            case "layer_TRA_Greyhound" :  { 
		    		    
		        childElementName = "service";	
		        childNodeLatLongName = "point";
			    break;
		    }
		    
            case "layer_TRA_SeaBus_Marker" : { 
		    		    
		        childElementName = "stop";	
		        childNodeLatLongName = "point";
			    break;
		    }

            case "layer_TRA_Boundaries_Marker" : { 
   
		        childElementName = "boundary";	
		        childNodeLatLongName = "point";
			    break;
		    }

            case "layer_WstCstExpr_Marker" : { 
   
		        childElementName = "stop";	
		        childNodeLatLongName = "point";
			    break;
		    }		    

            // Marine Layers
            case "layer_Albion":
            case "layer_MA_CustomEntry" :
	        case "layer_MA_FalseCreek" :
	        case "layer_MA_MarineAccess" :
            case "layer_MA_CruiseLines" : 
            case "layer_MA_Ports" : { 
		    		    
		        childElementName = "service";	
		        childNodeLatLongName = "point";
			    break;
		    }
        
            // Air Layers
//            case "chk_AIR_IntAir" :
            case "chk_AIR_RegAir" :
  
            case "layer_AIR_HrbrAir" :
            case "layer_AIR_WestCoastAir" :
            case "layer_AIR_Helijet" : { 
		    		    
		        childElementName = "service";	
		        childNodeLatLongName = "point";
			    break;
		    }
        
            // Rail Layers
            case "layer_RAIL_Railroads" : 
            case "layer_ViaRail" : 
            case "layer_RAIL_RockyMtn" : 
            case "layer_Amtrak" : 
            case "layer_RAIL_RailAccess" : { 
            
                childElementName = "service";	
		        childNodeLatLongName = "point";
			    break;
		    }
            
            // Cycling Layer
            // All polylines - no work here
		    default: break;
		}

//alert("childElementName is: " + childElementName);

    	// Parse the markers from the file and store into array
    	xmlMarkers = xml.documentElement.getElementsByTagName(childElementName);

//alert("in markers section 2 now");
//alert('xmlMarkers.length: ' + xmlMarkers.length);

if (debug)
    alert('xmlMarkers.length: ' + xmlMarkers.length);

//document.getElementById("divLoading").innerHTML= loadingMessageHTML;	

if (xmlMarkers.length>10){
      window.setTimeout(hideLoading, 1000); 
} else {
    hideLoading();
}

        //alert("gen markers 2 start now");							    
        
	    // Create point object based on longitude and latitude and store into array of points
	    for( var i=0; i<xmlMarkers.length; i++ ) {
    		
		    //grab the lat + long for the Event
		    var point = new GLatLng( parseFloat( getAttributeNodeValue(xmlMarkers[i], childNodeLatLongName, "lat") ), parseFloat( getAttributeNodeValue(xmlMarkers[i], childNodeLatLongName, "long") ) );
		    //var point = new GLatLng( parseFloat( xmlMarkers[i].childNodes[childNodeLatLong].getAttribute( "lat" ) ), parseFloat( xmlMarkers[i].childNodes[childNodeLatLong].getAttribute( "long" ) ) );
		    points.push( point );
    		
		    switch( groupId ) {    

            case "layer_MilLine_Marker":
    	    case "layer_ExpoLine_Marker": {
			        points[i].stopName = new String( getNodeValue(xmlMarkers[i], "name") );  
			        
			        tooltips[i] = "Skytrain: " + points[i].stopName;
			              				
       			   break;
		    } 


    	        case "layer_BusRouteTest_Marker": {
			        points[i].stopName = new String( getNodeValue(xmlMarkers[i], "stopName") );        				
			        break;
		        }  

    	        case "layer_WstCstExpr_Marker": {
			        points[i].stopName = new String( getNodeValue(xmlMarkers[i], "name") );
			        
			        tooltips[i] = "West Coast Express: " + points[i].stopName;
			        break;
		        }  

    	      //dynamic Bus Stops Layer
//bus_test
            case "layer_Test_Route73Markers":
            case "layer_Test_Route218Markers":
        case "layer_Test_PerfTestMarkers":
    	      case "layer_Test_Route9Markers":
    	      case transitMarkersLayerName: {
    	         	        
    	           var timeTableURLString;
    	           var timeTableURLBigString;
    	           var nextBusURLString;
    	           var lFromHourDropDown;
                   var lFromMinuteDropDown;
                   var lFromMeridiemDropDown;
                   var lStopAbbr;
                   var systemDate = new Date();  //get the system date
                   
                   points[i].stopId = new String( getNodeValue(xmlMarkers[i], "stopId") );        				
                   points[i].stopName = new String( getNodeValue(xmlMarkers[i], "stopName") );        				
                   points[i].region = new String( getNodeValue(xmlMarkers[i], "region") );        				
                   points[i].direction = new String( getNodeValue(xmlMarkers[i], "direction") );        				

                    tooltips[i] = "Bus Stop: " + points[i].stopName;

                    // need to concatenate stopId at the end of the next Bus URL 
                   //nextBusURLString = new String( getNodeValue(xmlMarkers[i], "nextBusURL") );        				
                   nextBusURLString = getSystemParameter("NextBusURL");
                   
                    // in the nextBusURLString from the XML document, we need to change the "%26" back
                    // to the "&" sign for the link to work correctly
                    nextBusURLString = nextBusURLString.replace(/%26/g,"&");
                

                    //Building Next URL String: we need to fill in (1) FromHourDropDown (hour of day), 
                    //(2)FromMinuteDropDown (minute of day), (3)FromMeridiemDropDown (am/pm switch)
                    // based from the system time , and (4) StopID (StopAbbr)

                    lStopAbbr = points[i].stopId;

                    lFromHourDropDown = systemDate.getHours();
                    lFromMinuteDropDown = systemDate.getMinutes();
                    
                    if (lFromHourDropDown > 11){
                        //set hours for PM
                        lFromMeridiemDropDown="p";
                    }else{
                        //set hours for AM
                        lFromMeridiemDropDown="a";
                    }
                                        
                    // Build the URL string to look like this:
                    // &FromHourDropDown=400&FromMinuteDropDown=35&FromMeridiemDropDown=p&StopAbbr=54332
                    
                    // concatenate the stopId at the end of the nextBusURL 
                   nextBusURLString += "&FromHourDropDown="+lFromHourDropDown+"00&FromMinuteDropDown="+lFromMinuteDropDown+"&FromMeridiemDropDown="+lFromMeridiemDropDown+"&StopAbbr="+lStopAbbr;
                    
                   //set the NextBusURL based on the dynamic URL
                   points[i].nextBusURL = nextBusURLString;                  
                   
                   var planTripToURLString;
                   var planTripFromURLString;

                    // add the stop ID to the end of the URL
                    planTripToURLString = getSystemParameter("PlanTripToURL") + lStopAbbr;
                    planTripToURLString = planTripToURLString.replace(/%26/g,"&");                    
                    points[i].planTripToURL = planTripToURLString;

                    // add the stop ID to the end of the URL
                    planTripFromURLString = getSystemParameter("PlanTripFromURL") + lStopAbbr;
                    planTripFromURLString = planTripFromURLString.replace(/%26/g,"&");                    
                    points[i].planTripFromURL = planTripFromURLString;

                  
                   //timeTableURLString = new String( getNodeValue(xmlMarkers[i], "timeTableURL") );
                   timeTableURLString = getSystemParameter("TimeTableURL");
		           timeTableURLString = timeTableURLString.replace(/%26/g,"&");
                    
                    var stopRoutesBigString="";
                    var stopRouteString="";

                    // parse the <stopRoutes> tag for each Stop, and create a table row for each
                    var stopRoutesNodes = xmlMarkers[i].getElementsByTagName("stopRoutes");
                    
		                    for( var j=0; j<stopRoutesNodes.length; j++ ) {
                    					                   
		                        // Get all childNodes that are of element node type
		                        var elementChildNodes = getElementChildNodes( stopRoutesNodes[j] );
                    		    
			                    //loop through each StopRoute child nodes		
			                    for( var k=0; k<elementChildNodes.length; k++ ) {		

				                    //grab ID and Name for each StopRoute			
				                    var stopRouteID = elementChildNodes[k].getAttribute( "id" ) ;
                                    		    var stopRouteName = elementChildNodes[k].getAttribute( "name" ) ;
                                    		    timeTableURLBigString = timeTableURLString + stopRouteID;

                                   		    //create the table row for the Info Box
		                                    stopRouteString = "<tr><td valign=top align=left><b>"+ stopRouteID + "</b> - <A target=_blank href='"+ timeTableURLBigString +"'> " + stopRouteName + "</a></td></tr>";
                  				    stopRoutesBigString = stopRoutesBigString + stopRouteString;
                  				    stopRouteString = "";
                  				    timeTableURLBigString = "";
    		                           }
		                    }

                   //set the Stop routes string for the info box
                   points[i].stopRoutesString = stopRoutesBigString;
  		           break;
		        }  	    

                //Transit layers
                case "layer_TRA_Exch" : { 
    		    		    
		            //exchange name
		            points[i].exchangeName = new String( getNodeValue(xmlMarkers[i], "name") );
		            
		            tooltips[i] = "Transit Exchange: " + points[i].exchangeName + " \n... Click for more";	

                  var stopRouteBigString="";
                  var stopRouteString="";
                  var stopNames;  
                  
                  var transitExchangeURL;                
                  var transitExchangeURLBigString;   

                  transitExchangeURL = getSystemParameter("TimeTableURL");
                  transitExchangeURL = transitExchangeURL.replace(/%26/g,"&");                    

                    var routeNodes = [];  
                    var routeChildNodes = [];                                                     

                    // parse the <stopRoutes> tag for each Stop, and create a table row for each
                    var stopNodes = xmlMarkers[i].getElementsByTagName("stop");
                    
                    // add the exchange name as the top row of the table
                    stopRouteBigString = "<table border=0 width=270px>";
                    
                    for( var j=0; j<stopNodes.length; j++ ) {
	                        
	                        var stopId = stopNodes[j].getAttribute( "stopId" ) ;
	                        var stopName = stopNodes[j].getAttribute( "stopName" ) ;
	                        
	                        stopRouteString = "<tr><td valign=top align=left><b>Stop #"+stopId +": "+ stopName + "</b></td></tr>";
	                        
	                        // add the STOP name to the top row of the table
	                        stopRouteBigString += stopRouteString;  
	                        
	                        // parse the <routes> tag for each Stop, and create a table row for each
                            routeNodes = stopNodes[j].getElementsByTagName("routes");
                                                        
                            // Get all childNodes that are of element node type                           
		                    routeChildNodes = getElementChildNodes( routeNodes[0] );
		                        
			                    //loop through each StopRoute child nodes		
			                    for( var h=0; h<routeChildNodes.length; h++ ) {		

                                    //grab ID and Name for each StopRoute			
				                    var stopRouteNumber = routeChildNodes[h].getAttribute( "routeNumber" ) ;
				                    var stopRouteDirection = routeChildNodes[h].getAttribute( "routeDirection" ) ;
                                    var stopRouteName = routeChildNodes[h].getAttribute( "routeName" ) ;
                                    
                                    transitExchangeURLBigString = transitExchangeURL + stopRouteNumber;                               

                                    //create the table row for the Info Box
                                    stopRouteString = "<tr><td valign=top align=left><a target=_blank href='"+ transitExchangeURLBigString +"'>"+ stopRouteDirection + " - " + stopRouteName + "</td></tr>";
                  				    
                  				    // add the routes list to the table
                  				    stopRouteBigString += stopRouteString;                  				    
                  				    
    		                    }
    		                    
    		                    // add a spacer row between each Stop
    		                    stopRouteString = "<tr><td>&nbsp;</td></tr>";
    		                        		                    
                  				stopRouteBigString += stopRouteString;                  				    
                            		                        		                        			                    
		                    }		                   
                    
                    stopRouteBigString += "</table>";
                    
                    points[i].exchangeTable = stopRouteBigString;
                                      
  		           break;
		        }  	    

                // Events Layer
    	        case "layer_CurInc": 
    	        case "layer_CurCon": 
    	        case "layer_CurEv": 
    	        case "layer_EV_FutCon": 
    	        case "layer_EV_FutEv": 
    	        case "layer_EV_FutSrvc": 
    	        case "layer_EventsReal": {
        		
			        //grab all the event details			
			        points[i].shortdescr = new String( getNodeValue(xmlMarkers[i], "shortDescr") );
			        points[i].type = new String( getNodeValue(xmlMarkers[i], "type") );
			        points[i].priority = new String( getNodeValue(xmlMarkers[i], "priority") );
			        points[i].status = new String( getNodeValue(xmlMarkers[i], "status") );
			        points[i].address = new String( getNodeValue(xmlMarkers[i], "address") );
			        points[i].started = new String( getNodeValue(xmlMarkers[i], "started") );
			        points[i].updatedDate = new String( getNodeValue(xmlMarkers[i], "updateDate") );						
			        
			        var lDuration = new String( getNodeValue(xmlMarkers[i], "durationPeriod") );
			        points[i].durationPeriod = returnDurationMessage(lDuration);

			        points[i].longdescr = new String( getNodeValue(xmlMarkers[i], "longDescr") );						
			        points[i].advice = new String( getNodeValue(xmlMarkers[i], "advice") );
                    points[i].number = new String( getNodeValue(xmlMarkers[i], "number") );

                    tooltips[i] = points[i].type + ": " + points[i].address + " \n... Click for more";	                    
        				
			        break;

		        }  
    		
		    // Cameras Layer
		    case "layer_CAM_Border": 
		    case "layer_CAM_TrafficInt": 
		    case "layer_CAM_TrafficHigh":  
		    case "layer_CAM_Port": 
		    case "layer_CamerasReal": {
    		    
		            points[i].primaryImageUrl = new String( getNodeValue(xmlMarkers[i], "primaryImageUrl") );			
			        points[i].primaryDirection = new String( getNodeValue(xmlMarkers[i], "primaryDirection") );
			        points[i].ImageUrl = new String( getNodeValue(xmlMarkers[i], "imageUrl") );			
			        points[i].shortDescr = new String( getNodeValue(xmlMarkers[i], "shortDescr") );	
        			
        			tooltips[i] = "Camera: " + points[i].shortDescr + " \n... Click for more";	                    
        			
			        // make the camera direction a word in the info box
			        if (points[i].primaryDirection == "S" ){				
				        points[i].primaryDirection = "South";
        							
			        } else if ( points[i].primaryDirection == "N" ) {
				        points[i].primaryDirection = "North";				

			        } else if ( points[i].primaryDirection == "E" ) {
				        points[i].primaryDirection = "East";				

			        } else if ( points[i].primaryDirection == "W" ) {
				        points[i].primaryDirection = "West";
        				
			        } else {
				        //alert(points[i].primaryDirection);			
			        }
        			
			        break;

		        } 
    		    
		        //Weather layers
                case "layer_Weather" : { 
                    
		            var unknownForecastInt;
		            var unknownWeatherTest = new String( getAttributeNodeValue(xmlMarkers[i], "OBS", "FORECAST_TEXT_EN") );
                    
                    unknownForecastInt = unknownWeatherTest.indexOf('Unknown');   
                    
                    if (unknownForecastInt != -1){        
                        //weather icon is unknown, do not show icon     			        
     			        points[i].current_icon = "unknown";
     			        break;
     			        
                    } else {                            
		                //weather icon is not unknown, do regular		                
                    
                        //SITE node
                        
                        var siteNameRegular = new String( xmlMarkers[i].getAttribute("NAME") );
		                siteNameEncoded = new String( xmlMarkers[i].getAttribute("NAME") );
        		        points[i].site_name = URLEncode(siteNameEncoded);
			        
	    		        //OBS node		
	    		        points[i].current_forecast = new String( getAttributeNodeValue(xmlMarkers[i], "OBS", "FORECAST_TEXT_EN") );
    		            points[i].current_temperature = new String( getAttributeNodeValue(xmlMarkers[i], "OBS", "TEMPERATURE") + " C" );
			            points[i].current_wind = new String( getAttributeNodeValue(xmlMarkers[i], "OBS", "WIND_SPEED") + " KM/H " + getAttributeNodeValue(xmlMarkers[i], "OBS", "WIND_DIR") );
			            points[i].current_date = new String( getAttributeNodeValue(xmlMarkers[i], "OBS", "DATE") );
			            points[i].current_station = new String( getAttributeNodeValue(xmlMarkers[i], "OBS", "STATION") );		
			            points[i].current_icon = new String("/atis/app_themes/atis/images/weather_icons/" + getAttributeNodeValue(xmlMarkers[i], "OBS", "ICON") + ".gif");

                        
                        tooltips[i] = siteNameRegular + ": " + points[i].current_forecast + " \n... Click for more";	                    
    			        
			            var periodNodes = getSpecificElementChildNodes( xmlMarkers[i], "PERIOD" )
    			        
			            // PERIOD 1 node	
			            if (periodNodes[0] != null)		
			            {
			                points[i].short1name = new String( periodNodes[0].getAttribute( "NAME_EN" ) );		
			                
			                if (points[i].short1name == "Tonight"){
			                    points[i].short1name = "Overnight";
			                }
			                
			                points[i].short1forecast = new String( periodNodes[0].getAttribute( "FORECAST_TEXT_EN" ) );
			                points[i].short1temp = new String( periodNodes[0].getAttribute( "TEMPERATURE" ) + " C" );
			                points[i].short1pop = new String( periodNodes[0].getAttribute( "POP" ) + " %");
			                points[i].short1wind = new String( periodNodes[0].getAttribute( "WIND_SPEED" ) + " KM/H " + periodNodes[0].getAttribute( "WIND_DIR" ) );
			                points[i].short1icon = new String( periodNodes[0].getAttribute( "ICON" ) );
                        }
                        
			            // PERIOD 2 node
                        if (periodNodes[1] != null)		
			            {
			                points[i].short2name = new String( periodNodes[1].getAttribute( "NAME_EN" ) );		

			                if (points[i].short2name == "Tonight"){
			                    points[i].short2name = "Overnight";
			                }

			                points[i].short2forecast = new String( periodNodes[1].getAttribute( "FORECAST_TEXT_EN" ) );
			                points[i].short2temp = new String( periodNodes[1].getAttribute( "TEMPERATURE" ) + " C" );
			                points[i].short2pop = new String( periodNodes[1].getAttribute( "POP" ) + " %");
			                points[i].short2wind = new String( periodNodes[1].getAttribute( "WIND_SPEED" ) + " KM/H " + periodNodes[0].getAttribute( "WIND_DIR" ) );
			                points[i].short2icon = new String( periodNodes[1].getAttribute( "ICON" ) );
                        }			

			            // PERIOD 3 node	
			            if (periodNodes[2] != null)		
			            {
			                points[i].short3name = new String( periodNodes[2].getAttribute( "NAME_EN" ) );		

			                if (points[i].short3name == "Tonight"){
			                    points[i].short3name = "Overnight";
			                }
			                points[i].short3forecast = new String( periodNodes[2].getAttribute( "FORECAST_TEXT_EN" ) );
			                points[i].short3temp = new String( periodNodes[2].getAttribute( "TEMPERATURE" ) + " C" );
			                points[i].short3pop = new String( periodNodes[2].getAttribute( "POP" ) + " %");
			                points[i].short3wind = new String( periodNodes[2].getAttribute( "WIND_SPEED" ) + " KM/H " + periodNodes[0].getAttribute( "WIND_DIR" ) );
			                points[i].short3icon = new String( periodNodes[2].getAttribute( "ICON" ) );
                        }				

			            // PERIOD 4 node			
			            if (periodNodes[3] != null)		
			            {
			                points[i].short4name = new String( periodNodes[3].getAttribute( "NAME_EN" ) );		

			                if (points[i].short4name == "Tonight"){
			                    points[i].short4name = "Overnight";
			                }
			                points[i].short4forecast = new String( periodNodes[3].getAttribute( "FORECAST_TEXT_EN" ) );
			                points[i].short4temp = new String( periodNodes[3].getAttribute( "TEMPERATURE" ) + " C" );
			                points[i].short4pop = new String( periodNodes[3].getAttribute( "POP" ) + " %");
			                points[i].short4wind = new String( periodNodes[3].getAttribute( "WIND_SPEED" ) + " KM/H " + periodNodes[0].getAttribute( "WIND_DIR" ) );
			                points[i].short4icon = new String( periodNodes[3].getAttribute( "ICON" ) );
                        }
                    
                    } // end of 
    				
			        break;
                } 

                // Road Layers


                case "layer_ROD_HwaySigns" : { 
                
                    var message;
                    var signMessage1;
                    var signMessage2;                
                    
                    points[i].organization = new String( getNodeValue(xmlMarkers[i], "organization") );
			        points[i].linkDirection = new String( getNodeValue(xmlMarkers[i], "linkDirection") );			
			        points[i].type = new String( getNodeValue(xmlMarkers[i], "type") );	
			        points[i].streetName = new String( getNodeValue(xmlMarkers[i], "street") );	
			        points[i].lastUpdateTime = new String( getNodeValue(xmlMarkers[i], "lastUpdate") );	
			        points[i].region = new String(getNodeValue(xmlMarkers[i], "regionName") );	

			        signMessage1 = new String( getNodeValue(xmlMarkers[i], "msgPhase1") );	
			        signMessage2 = new String( getNodeValue(xmlMarkers[i], "msgPhase2") );	

                    // if there are 2 messages, create a line break between the messages
                    if (signMessage2==""){
                        message = signMessage1;   
                        
                        tooltips[i] = signMessage1;	                    
                    
                    } else {
                        message = signMessage1 + "<br><br>" + signMessage2;
                        
                        tooltips[i] = signMessage1 + " \n" + signMessage2;	                                        
                    
                    }
                      
                    //re-assign the message back to message 1 for the info box
			        points[i].msgPhase1 = message;
			        break; 
                } 
                case "chk_ROD_Cong" : { 
                    //TODO Change to layer congestion rather than detectors
                    points[i].center = new String( xmlMarkers[i].childNodes[1].text );			
			        points[i].approachDirection = new String( xmlMarkers[i].childNodes[3].text );
			        points[i].lanesNumber = new String( xmlMarkers[i].childNodes[4].text );			
			        points[i].streetName = new String( xmlMarkers[i].childNodes[5].text );	
			        points[i].region = new String( xmlMarkers[i].childNodes[6].text );	
			        points[i].period = new String( xmlMarkers[i].childNodes[7].text );	
			        points[i].vehCount = new String( xmlMarkers[i].childNodes[8].text );			
			        points[i].occupancy = new String( xmlMarkers[i].childNodes[9].text );	
			        points[i].avgSpeed = new String( xmlMarkers[i].childNodes[10].text );	
			        points[i].congestionLevel = new String( xmlMarkers[i].childNodes[11].text );	
			        points[i].lane1Status = new String( xmlMarkers[i].childNodes[12].text );
			        points[i].lane2Status = new String( xmlMarkers[i].childNodes[13].text );
			        break;
                } 
       
                case "layer_Parking" : { 

    		    	points[i].name = new String( getNodeValue(xmlMarkers[i], "name") );			
    		    	points[i].address = new String( getNodeValue(xmlMarkers[i], "address") );			
    		    	points[i].access = new String( getNodeValue(xmlMarkers[i], "access") );			
    		    	points[i].associatedExchange = new String( getNodeValue(xmlMarkers[i], "associatedExchange") );			
    		    	points[i].numberOfStalls = new String( getNodeValue(xmlMarkers[i], "stallsNumber") );			
    		    	points[i].notes = new String( getNodeValue(xmlMarkers[i], "notes") );
    		    	points[i].rates = new String( getNodeValue(xmlMarkers[i], "rates") );

                    tooltips[i] = "Park & Ride: " + points[i].name + " \n... Click for more";	                                        
    		    	
                    break;
		        }
                
                case "layer_ROD_NonKeyLandmarks" : 
                case "layer_ROD_Landmarks" : { 

    		    	points[i].name = new String( getNodeValue(xmlMarkers[i], "name") );			
    		    	points[i].address = new String( getNodeValue(xmlMarkers[i], "Address") );			
    		    	points[i].type = new String( getNodeValue(xmlMarkers[i], "type") );	
    		    	
    		    	tooltips[i] = "Landmark: " + points[i].name + " \n... Click for more";	                                        		
    		    	
    		    	var hospitalCheck=0;
    		    	var iconTypeCheck = points[i].type;
    		    	var landmarkIcon;
    		    	
                    hospitalCheck = iconTypeCheck.indexOf('HOSPITAL'); 

                    if (hospitalCheck != -1){
                    //SPECIAL CASE:  If Landmark type = "HOSPITAL" , use the hospital landmarks icon
    		    	    points[i].icon = "/ATIS/App_Themes/atis/images/PNG/hospital.png";
                    } else {
                        points[i].icon = "/ATIS/App_Themes/atis/images/PNG/landmarks.png";
                    }   		    	
 		    	
  		    	    hospitalCheck=0;   
                    break;
		        }
                
                case "layer_ROD_FacStatus" : { 
    		    		    
		            points[i].name = new String( getNodeValue(xmlMarkers[i], "name") );	
		            points[i].state = new String( getNodeValue(xmlMarkers[i], "state") );		            
			        points[i].icon = new String("/atis/app_themes/atis/images/facility_icons/" + getNodeValue(xmlMarkers[i], "icon") + ".png");
		            
		            var lTemp = points[i].name + " \n" + points[i].state;
		            
		           //replace all <br> tags with \n for carriage return
		           tooltips[i] = lTemp.replace(/<br>/g," \n");
		           
			        break;
		        }

		        // Commercial Layer
		        case "layer_COM_Weigh" : {
    		    
		            points[i].region = new String( getNodeValue(xmlMarkers[i], "region") );			
			        points[i].city = new String( getNodeValue(xmlMarkers[i], "city") );			
			        points[i].organization = new String( getNodeValue(xmlMarkers[i], "organization") );	
			        points[i].streetName = new String( getNodeValue(xmlMarkers[i], "streetName") );	
			        
			        tooltips[i] = "";	                                        		

			        break;
		        }

                case "layer_COM_Restrictions" : { 
    		    		    
		            points[i].name = new String( getNodeValue(xmlMarkers[i], "name") );	
		            points[i].descr = new String( getNodeValue(xmlMarkers[i], "descr") );			            

                    tooltips[i] = "Dangerous Goods Restrictions: " + points[i].name + " \n... Click for more";	                                        				            
			        
			        break;
		        }

 	            //new US border layer
 	            case "layer_USBorder" :
                case "layer_Albion":
 	            case "layer_Border" :
	            case "layer_BCFerries" :
	            case "layer_IntAir" :
	            case "layer_RegAir" : 
                case "layer_TRA_Boundaries_Marker" :                 
                case "layer_TRA_SeaBus_Marker" : 
                case "layer_TRA_Greyhound" : 
                case "layer_MA_CruiseLines" : 
                case "layer_MA_Ports" : 
                case "layer_MA_CustomEntry" :
	            case "layer_MA_FalseCreek" :
	            case "layer_MA_MarineAccess" :
                case "layer_AIR_HrbrAir" :
                case "layer_AIR_WestCoastAir" :
                case "layer_AIR_Helijet" : 
                case "layer_RAIL_Railroads" : 
                case "layer_ViaRail" : 
                case "layer_RAIL_RockyMtn" : 
                case "layer_Amtrak" : 
                case "layer_RAIL_RailAccess" : { 
                
		            points[i].name = new String( getNodeValue(xmlMarkers[i], "name") );			
			        points[i].type = new String( getNodeValue(xmlMarkers[i], "type") );
			        points[i].description = new String( getNodeValue(xmlMarkers[i], "descr") );			
			        points[i].link = new String( getNodeValue(xmlMarkers[i], "linkURL") );	
			        points[i].image = new String( getNodeValue(xmlMarkers[i], "imgURL") );	
			        points[i].icon = new String( getNodeValue(xmlMarkers[i], "icon") );	
			        points[i].iconWidth = new String( getNodeValue(xmlMarkers[i], "iconWidth") );				        
			        points[i].iconHeight = new String( getNodeValue(xmlMarkers[i], "iconHeight") );	
			        points[i].shadowIcon = new String( getNodeValue(xmlMarkers[i], "shadowIcon") );	
			        points[i].shadowIconWidth = new String( getNodeValue(xmlMarkers[i], "shadowIconWidth") );	
			        points[i].shadowIconHeight = new String( getNodeValue(xmlMarkers[i], "shadowIconHeight") );				        
                    points[i].imgHeight = "50px";		
                    
                    tooltips[i] = points[i].name + " \n... Click for more";	                                        				            		        
			        
// grab all icon stuff here 


                    //if no image is found, use the default blank image
                    if (points[i].image==""){
                        points[i].image= "/ATIS/App_Themes/atis/images/atis-blankImage.gif" ;                    
                        points[i].imgHeight = "0px";		
                    }

			        break;
		        }

                
                // Cycling Layer
                // All polylines - no work here
    			
                default: break;
    		
  	        }
	    } // end for loop

    //alert("gen markers part 3");
    
	    for( var i=0; i<points.length; i++ ) {
	    
	        var unknownWeatherTest;
    		
             // create Icons from XML data for Weather and generic services layers
              switch( groupId ) {
 
                     // build weather icon from XML data
     	            case "layer_Weather": {

 			            unknownWeatherTest = points[i].current_icon;
                        
                        if (unknownWeatherTest == "unknown"){        
                            //weather icon is unknown, do not show icon
         			        icon = generateShadowIcon( false, points[i].current_icon, 0, 0 );
                        } else {                            
 			                //weather icon is known, do regular
 			                icon = generateShadowIcon( false, points[i].current_icon, 44, 35 );       							        
                        }

 			            break;
 		            }  
 
                     case "layer_ROD_FacStatus" : { 
                        icon = generateShadowIcon( true, points[i].icon, 20, 20, "/ATIS/App_Themes/atis/images/facility_icons/facility_shadow.png", 37, 19 );       							                        
			            break;
		            }

                    case "layer_ROD_NonKeyLandmarks" : 
                    case "layer_ROD_Landmarks" : {                          
                         icon = generateShadowIcon( true, points[i].icon, 19, 18, "/ATIS/App_Themes/atis/images/PNG/landmarks-s.png", 37, 19 );       							                        
                         break;
                     }
 
                     // build Icon for generic services files from XML data

                     case "layer_USBorder" : { 
                        icon = generateShadowIcon( true, "/ATIS/App_Themes/atis/images/PNG/USborder.png", 18, 9, "/ATIS/App_Themes/atis/images/PNG/USborder-s.png", 39, 9 );       							                        
			            break;
		            }

                     case "layer_Border" : { 
                        icon = generateShadowIcon( true, "/ATIS/App_Themes/atis/images/PNG/CANborder.png", 18, 9, "/ATIS/App_Themes/atis/images/PNG/CANborder-s.png", 39, 9 );       							                        
			            break;
		            }


 	                case "layer_Albion" :
 	                case "layer_BCFerries" :
 	                case "layer_IntAir" :
 	                case "layer_RegAir" : 
                     case "layer_TRA_Greyhound" : 
                     case "layer_MA_CruiseLines" : 
                     case "layer_MA_Ports" : 
                     case "layer_AIR_HrbrAir" :
                     case "layer_AIR_WestCoastAir" :
                     case "layer_AIR_Helijet" : 
                     case "layer_RAIL_Railroads" : 
                     case "layer_ViaRail" : 
                     case "layer_RAIL_RockyMtn" : 
                     case "layer_Amtrak" : 
                     case "layer_RAIL_RailAccess" : { 
     	            
                         icon = generateShadowIcon( true, points[i].icon, points[i].iconWidth, points[i].iconHeight, points[i].shadowIcon, points[i].shadowIconWidth, points[i].shadowIconHeight );       							                        
                         break;
                     
                     }
                      default: break;
 		        }
    		
    		
		    // Create a new marker based on specific point and icon
		    //var marker = new GMarker( points[i], icon );   //no tooltip
  		    var marker = new GMarker( points[i], {icon:icon, title:tooltips[i] }); 


            // Set the group the marker belongs to
		    marker.group = new String( groupId );
    		
		    // Set the unique id for this marker in this group
		    marker.id = new String( groupId + '_' + i );
    		
		    switch( groupId ) {

            case "layer_MilLine_Marker":
    	    case "layer_ExpoLine_Marker": {
			        marker.stopName = new String( points[i].stopName ); 
       			   break;
		    } 

    	        case "layer_WstCstExpr_Marker": {
			        marker.stopName = new String( points[i].stopName );       							        			        
			        break;
		        }  


    	        case "layer_BusRouteTest_Marker": {
			        marker.stopName = new String( points[i].stopName );        							        
			        break;
		        }  

//bus_test
                case "layer_Test_Route9Markers":                
    	        case transitMarkersLayerName: {
    	           	       
			        marker.stopId = new String( points[i].stopId );        							        
			        marker.stopName = new String( points[i].stopName );        							        
			        marker.region = new String( points[i].region );        							        
			        marker.direction = new String( points[i].direction );        							        
			        marker.nextBusURL = new String( points[i].nextBusURL );        							        
			        marker.planTripToURL = new String( points[i].planTripToURL );        							        
			        marker.planTripFromURL = new String( points[i].planTripFromURL );        							        			        			        
			        marker.timeTableURL = new String( points[i].timeTableURL );        							        			        			        
			        marker.stopRoutesString = new String( points[i].stopRoutesString );       							        			        			        
			        break;
		        }  
    		
                // Events Layer
    	        case "layer_CurInc": 
    	        case "layer_CurCon": 
    	        case "layer_CurEv": 
    	        case "layer_EV_FutCon": 
    	        case "layer_EV_FutEv": 
    	        case "layer_EV_FutSrvc": 
    	        case "layer_EventsReal": {


//alert("event marker here ..");
        	    
    	            marker.shortdescr = new String( points[i].shortdescr );				
				    marker.type = new String( points[i].type );				
				    marker.priority = new String( points[i].priority );
				    marker.status = new String( points[i].status );
				    marker.address = new String( points[i].address );
				    marker.started = new String( points[i].started );
				    marker.updatedDate = new String( points[i].updatedDate );				
				    marker.durationPeriod = new String( points[i].durationPeriod );
				    marker.longdescr = new String( points[i].longdescr );				
				    marker.advice = new String( points[i].advice );
				    marker.number = new String( points[i].number );
    				
				    break;
    	        }
    		
		    // Cameras Layer
		    case "layer_CAM_Border": 
		    case "layer_CAM_TrafficInt": 
		    case "layer_CAM_TrafficHigh":  
		    case "layer_CAM_Port": 
		    case "layer_CamerasReal": {
    		    	
				    marker.primaryImageUrl = new String( points[i].primaryImageUrl );				
				    marker.primaryDirection = new String( points[i].primaryDirection );
				    marker.ImageUrl = new String( points[i].ImageUrl );
				    marker.shortDescr = new String( points[i].shortDescr );
    								
				    break;
		        }
    		    
		        //Weather layers
                case "layer_Weather" : { 
	               
                        marker.site_name = new String( points[i].site_name );
                       				
			            marker.current_forecast = new String( points[i].current_forecast );
			            marker.current_temperature = new String( points[i].current_temperature );
			            marker.current_wind = new String( points[i].current_wind );								
			            marker.current_date = new String( points[i].current_date );
			            marker.current_station = new String( points[i].current_station );
			            marker.current_icon = new String( points[i].current_icon );

			            marker.short1name = new String( points[i].short1name );				
			            marker.short1forecast = new String( points[i].short1forecast );
			            marker.short1temp = new String( points[i].short1temp );
			            marker.short1pop = new String( points[i].short1pop );
			            marker.short1wind = new String( points[i].short1wind );
			            marker.short1icon = new String( points[i].short1icon );
        				
			            marker.short2name = new String( points[i].short2name );				
			            marker.short2forecast = new String( points[i].short2forecast );
			            marker.short2temp = new String( points[i].short2temp );
			            marker.short2pop = new String( points[i].short2pop );
			            marker.short2wind = new String( points[i].short2wind );
			            marker.short2icon = new String( points[i].short2icon );

			            marker.short3name = new String( points[i].short3name );				
			            marker.short3forecast = new String( points[i].short3forecast );
			            marker.short3temp = new String( points[i].short3temp );
			            marker.short3pop = new String( points[i].short3pop );
			            marker.short3wind = new String( points[i].short3wind );
			            marker.short3icon = new String( points[i].short3icon );

			            marker.short4name = new String( points[i].short4name );				
			            marker.short4forecast = new String( points[i].short4forecast );
			            marker.short4temp = new String( points[i].short4temp );
			            marker.short4pop = new String( points[i].short4pop );
			            marker.short4wind = new String( points[i].short4wind );
			            marker.short4icon = new String( points[i].short4icon );
				    
			        break;
                } 

                // Road Layers
                case "layer_ROD_HwaySigns" : { 
                    
                    marker.organization = new String( points[i].organization );
			        marker.linkDirection = new String( points[i].linkDirection );			
			        marker.type = new String( points[i].type );	
			        marker.msgPhase1 = new String( points[i].msgPhase1 );	
			        marker.msgPhase2 = new String( points[i].msgPhase2 );	
			        marker.streetName = new String( points[i].streetName );	
			        marker.lastUpdateTime = new String( points[i].lastUpdateTime );	
			        marker.region = new String( points[i].region );	
			        break; 
                } 
                case "chk_ROD_Cong" : { 
                    
                    marker.center = new String( points[i].center );			
			        marker.approachDirection = new String( points[i].approachDirection );
			        marker.lanesNumber = new String( points[i].lanesNumber );			
			        marker.streetName = new String( points[i].streetName );	
			        marker.region = new String( points[i].region );	
			        marker.period = new String( points[i].period );	
			        marker.vehCount = new String( points[i].vehCount );			
			        marker.occupancy = new String( points[i].occupancy );	
			        marker.avgSpeed = new String( points[i].avgSpeed );	
			        marker.congestionLevel = new String( points[i].congestionLevel );	
			        marker.lane1Status = new String( points[i].lane1Status );
			        marker.lane2Status = new String( points[i].lane2Status );
			        break;
                } 

                case "layer_ROD_FacStatus" : { 
			        marker.name = new String( points[i].name );
			        marker.state = new String( points[i].state );
	            		            			            
			        break;
		        }

		        case "layer_USBorder" : 
		        case "layer_Border" : { 
    		    		    
		            marker.name = new String( points[i].name );			
			        marker.type = new String( points[i].type );
			        marker.description = new String( points[i].description );			
			        marker.link = new String( points[i].link );	
			        marker.image = new String( points[i].image );	
			        marker.icon = new String( points[i].icon );	
			        break;
		        }
                case "layer_Parking" : { 
    		    		    
		            marker.name = new String( points[i].name );
		            marker.address = new String( points[i].address );
		            marker.access = new String( points[i].access );
		            marker.associatedExchange = new String( points[i].associatedExchange );
		            marker.numberOfStalls = new String( points[i].numberOfStalls );
		            marker.notes = new String( points[i].notes );	
		            marker.rates = new String( points[i].rates );	
		            
			        break;
		        }

                case "layer_ROD_NonKeyLandmarks" : 
                case "layer_ROD_Landmarks" : { 

    		    	marker.name = new String( points[i].name );
    		    	marker.address = new String( points[i].address );
    		    	marker.type = new String( points[i].type );
    		    	marker.icon = new String( points[i].icon );
   		    	
                    break;
		        }
                
                //Transit layers
                case "layer_TRA_Exch" : { 
    		    		    
		            marker.exchangeName = new String( points[i].exchangeName );	
		            marker.exchangeTable = new String( points[i].exchangeTable );	
		            
			        break;
		        }

                case "layer_RegAir" : 
                case "layer_TRA_Boundaries_Marker" :                 
                case "layer_TRA_SeaBus_Marker" :                 
                case "layer_TRA_Greyhound" : 
                case "layer_BCFerries" : 
                case "layer_IntAir" : {                
   
		            marker.name = new String( points[i].name );			
			        marker.type = new String( points[i].type );
			        marker.description = new String( points[i].description );			
			        marker.link = new String( points[i].link );	
			        marker.image = new String( points[i].image );	
			        marker.icon = new String( points[i].icon );	
			        marker.imgHeight = new String( points[i].imgHeight );
			        break;
		        }

                // Commercial Layer
		        case "layer_COM_Weigh" : {
    		    
		            marker.region = new String( points[i].region );			
			        marker.city = new String( points[i].city );
			        marker.organization = new String( points[i].organization );			
			        marker.streetName = new String( points[i].streetName );	
			        
			        break;
		        }

                case "layer_COM_Restrictions" : { 
    		    		    
		            marker.name = new String( points[i].name );	
		            marker.descr = new String( points[i].descr );			            
			        break;
		        }
    		    
	        
                // Marine Layers
                case "layer_Albion" :
                case "layer_MA_CustomEntry" :
	            case "layer_MA_FalseCreek" :
	            case "layer_MA_MarineAccess" :
	            case "layer_MA_CruiseLines" : 
                case "layer_MA_Ports" : { 
    		    		    
		            marker.name = new String( points[i].name );			
			        marker.type = new String( points[i].type );
			        marker.description = new String( points[i].description );			
			        marker.link = new String( points[i].link );	
			        marker.image = new String( points[i].image );	
			        marker.icon = new String( points[i].icon );	
			        marker.imgHeight = new String( points[i].imgHeight );
			        break;
		        }
            
                // Air Layers
                case "layer_AIR_HrbrAir" :
                case "layer_AIR_WestCoastAir" :
                case "layer_AIR_Helijet" : { 
    		    		    
		            marker.name = new String( points[i].name );			
			        marker.type = new String( points[i].type );
			        marker.description = new String( points[i].description );			
			        marker.link = new String( points[i].link );	
			        marker.image = new String( points[i].image );	
			        marker.icon = new String( points[i].icon );
			        marker.imgHeight = new String( points[i].imgHeight );	
			        break;
		        }
            
                // Rail Layers                
                case "layer_RAIL_Railroads" : 
                case "layer_ViaRail" : 
                case "layer_RAIL_RockyMtn" : 
                case "layer_Amtrak" : 
                case "layer_RAIL_RailAccess" : { 

		            marker.name = new String( points[i].name );			
			        marker.type = new String( points[i].type );
			        marker.description = new String( points[i].description );			
			        marker.link = new String( points[i].link );	
			        marker.image = new String( points[i].image );	
			        marker.icon = new String( points[i].icon );
                    marker.imgHeight = new String( points[i].imgHeight );
			        break;
		        }

                // Cycling Layer
                // All polylines - no work here

			    default: break;
		    }

            // if we are working with weather data, we only want to add "non unknown" weather icons
            if (groupId == "layer_Weather"){
            
                if (unknownWeatherTest == "unknown"){
                    //only add the marker if it is not unknown, do nothing here
                } else {
                    //add the weather marker here, since it is not unknown
                    markers.push( marker );                                
                }

            } else {

		        // Store markers in array for all other layers
		        markers.push( marker );            
            }
    		

	    } // end for loop

//alert("bottom markers length is " + markers.length);  

//if (markers.length>10){
//    /window.setTimeout(hideLoading, 3000);  
//}

	    // Add event listener and handler when marker is clicked
	    for( var j=0; j<markers.length; j++ ) {
		    // Use function closure to deal with object array
		    // otherwise click listener will not react as expected.
		    createListener( markers[j], optParameter1 );
	    }

	    // Global variable to store number of groups
	    groups++;
	    
    //alert(" bottom marker layer is " + 	groupId);  
    
    //alert(markers);  
    
if (debugPerformance)
    PrintElapseTime("generateGroupMarkers(): end parsing datafile");

if (debugPerformance)
    PrintElapseTime("generateGroupMarkers(): start addGroupOverlays for markers");
        
	    // group these overlays
	    map.addGroupOverlays( "Marker", markers, groupId, optParameter1 );

if (debugPerformance)
    PrintElapseTime("generateGroupMarkers(): end addGroupOverlays for markers");


    
    //alert("done markers 1");  // this gets fired second ...

    	//document.getElementById("divLoading").innerHTML= "";



    }) // end GDownloadUrl function
    
    //alert("done markers 2");   // this gets fired first ...
    //alert("last line of gen markers now");
}


//*******************************************************************************
// Function:     generateGroupPolylines
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Function generates a line for each <polyLine> tag in the XML file provided
//
// Parameters:   XML data file
// Returns:
// Calls:        
// Called By:    InitGroupLayers()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function generateGroupPolylines( groupId, datafile, lineWidth, lineColor, lineOpacity, optParameter1  ) {

// Debug variable (set to 1 to debug)
var debug = 0;

    showLoading();
    window.setTimeout(hideLoading, 1500);
    
    //(1) determine if we are doing a bus route layer here
    //(2) if we are .. capture all the points in a global array
    //(3) determine first and last point, and do stuff
    
    var transitTestInt;
    var lTransitTest=0;
    var checkboxTransit;

    //check to see if this a public transit layer
    transitTestInt = groupId.indexOf('TRA_Public');   
    if (transitTestInt != -1){        
        //set the transit test switch = 1 for bus routes        
        lTransitTest=1;                       
    } else {
        lTransitTest=0;
    }
    
    // initialize download response array
	var data = [];


//bb new ajax lines, don't know if they work ...
//if (debugThreadAJAX)
//{
  //  countThreadAJAX++;
    
    //if (countThreadAJAX > 2)
      //  alert("countThreadAJAX: " + countThreadAJAX);
//} 
//end ofbb new ajax lines, don't know if they work ...


    // append timestamp so data returned are fresh
    datafile = timeStampUrl(datafile);

	// download markers data from xml
	GDownloadUrl( datafile, function( data, responseCode ) {


//bb new ajax lines, don't know if they work ...
//if (debugThreadAJAX)
//{
  //  countThreadAJAX--;
//}  
//end ofbb new ajax lines, don't know if they work ...

	
	//alert("Download successful: " + datafile);
	
	//**** View the contents of the XML file ****//
	//alert("data is: " + data);

if (debugPerformance)
    PrintElapseTime("generateGroupPolylines(): start parsing datafile for polylines: " + datafile);
    
if (debug)
    alert("Download successful: " + datafile);

        // Remove existing layer
        RemoveLayerIfLayerExists( groupId,optParameter1 );
        
        
        
		var xml = GXml.parse( data );
		var polylines = [];
		var markers = [];
		var polyColor = lineColor;
		var lineColors = [];
		var grpPolylines = [];  // group of polylines
		
		var busRecenterPoints = [];		

		
    //determine if we are doing congestion data here
    if (groupId == "layer_ROD_Cong"){

        //if we are doing congestion data, we need to assign a seperate line color per congestion node
        var congestionNodes = xml.documentElement.getElementsByTagName("congestion");
       		
			for( var c=0; c<congestionNodes.length; c++ ) {		
				
                //grab the congestion level
                var conLevel = getNodeValue(congestionNodes[c], "congestionLevel");
                
                //grab the appropriate congestion level color from the system parameters
                var conLevelColor = getSystemParameter(conLevel);
                
                if (conLevelColor == "SystemParamterMissing"){
                    //use the default blue color just in case the system paramter is not returned
                    conLevelColor="#0000ff";
                }                
				
				//grab the polyline nodes from inside the congestion node
				var polylineNodes = congestionNodes[c].getElementsByTagName("polyLine");

		        // loop through each "polyLine" node in the xml doc		
		        for( var j=0; j<polylineNodes.length; j++ ) {
        		
			        //reset the points array
			        var points = [];
        		
		            // Get all childNodes that are of element node type
		            var elementChildNodes = getElementChildNodes( polylineNodes[j] );

			        //loop through all child nodes		
			        for( var k=0; k<elementChildNodes.length; k++ ) {		
                
				        //loop through all point nodes within polyline			
				        var point = new GLatLng( parseFloat( elementChildNodes[k].getAttribute( "lat" ) ), parseFloat( elementChildNodes[k].getAttribute( "long" ) ) );
        				
				        //push the point to the points array
				        points.push( point );				
			        }

                    //add the new congestion polyline with the congestion color
        			var polyline;
                    polyline = new GPolyline( points, conLevelColor, 5, 1);
			        polyline.group = new String( groupId );
			        polyline.id = new String( groupId + '_' + i );

			        // Store polyline in array
			        grpPolylines.push( polyline );

		        }    
				
			}// end congestion for loop
			
    } else {

		//we are not doing congestion data, draw regular polylines
		var polylineNodes = xml.documentElement.getElementsByTagName("polyLine");
		
        //alert("polylineNodes.length: " + polylineNodes.length);		
		
        if (debug)
        alert("polylineNodes.length: " + polylineNodes.length);
        
        var lastPolyLine = polylineNodes.length-1;
                    
		// loop through each "polyLine" node in the xml doc		
		for( var j=0; j<polylineNodes.length; j++ ) {
		
		    //alert("total polylines are: " + polylineNodes.length);
		    //alert("lastPolyLine is: " + lastPolyLine);
		
			//reset the points array
			var points = [];
		
		    // Get all childNodes that are of element node type
		    var elementChildNodes = getElementChildNodes( polylineNodes[j] );
		    
		    //grab the count for the last child node
		    var childNodeCount = elementChildNodes.length -1;		     
		    
		    //alert("childNodeCount is:" + childNodeCount);
		    
			//loop through all child nodes		
			for( var k=0; k<elementChildNodes.length; k++ ) {
						    
                //alert("j is: " + j + " k is: " + k);

				//loop through all point nodes within polyline			
				var point = new GLatLng( parseFloat( elementChildNodes[k].getAttribute( "lat" ) ), parseFloat( elementChildNodes[k].getAttribute( "long" ) ) );
				
				//push the point to the points array
				points.push( point );
				
				 //put the first point into our bus center array
				 if (j == 0 && k == 0 ){
                        //alert("grabbing first point:" + point);
                        busRecenterPoints.push( point ); 
			            //alert("bus center points are: " + busRecenterPoints);                                                      
                 }			
                 
				 //put the first point into our bus center array
				 if (j == lastPolyLine ){

                        //alert(" we are in the last polyline, k is: " + k);                                
                        
                        if ( k == childNodeCount){
                            //alert(" grabbing last point:" + point);
                            busRecenterPoints.push( point );                       
			                //alert("bus center points are: " + busRecenterPoints);                                                      

                        }               
                 }		
			}

			// push the points in polylines array
			polylines.push( points );
		}        
    }	

if (debug)
    alert("polylines.length: " + polylines.length);
    			
        //create polylines for all non congestion polylines
        if (groupId == "layer_ROD_Cong"){
            //do nothing
            
        }else {

		        // Create a new polyline based on a group of points
		        for( var i=0; i<polylines.length; i++) {

			        var polyline;
                    polyline = new GPolyline( polylines[i], polyColor, lineWidth, lineOpacity);            

			        polyline.group = new String( groupId );
			        polyline.id = new String( groupId + '_' + i );

			        // Store polyline in array
			        grpPolylines.push( polyline );
			        
		        }
        }


if (debug)
    alert("Done grpPolylines.push");
    
    //alert("group polylines: " + grpPolylines);

		// Global variable to store number of groups
		groups++;

if (debugPerformance)
    PrintElapseTime("generateGroupPolylines(): end parsing datafile");
    
if (debugPerformance)
    PrintElapseTime("generateGroupPolylines(): start addGroupOverlays() for polylines");

    //alert("lets add the polyline overlay, group id is:" + groupId);

		// Finally add the polylines as a group of overlays to the map
		map.addGroupOverlays( "Polyline", grpPolylines, groupId, optParameter1 );
		
//alert("you yo yo done adding the bus overlay, tranist test is:" + lTransitTest);		

if (debugPerformance)
    PrintElapseTime("generateGroupPolylines(): end addGroupOverlays() for polylines");

if (debugPerformance)
    PrintElapseTime("generateGroupPolylines(): start recenterMapForBusRoute()");

//alert(" tranist test is:" + lTransitTest);		

        //if we are doing a bus route, re-center the map based on the staring/ending point for a bus route           
        if (lTransitTest == 1)
        {    
            if (isRecenterBusRouteOnMap == true)
                recenterMapForBusRoute( busRecenterPoints );
                //recenterMapForBusRoute( points );
        }

if (debugPerformance)
    PrintElapseTime("generateGroupPolylines(): end recenterMapForBusRoute()");

if (debug)
    alert("Done map.addGroupOverlays( Polyline, " + grpPolylines + ", " + groupId +");");
	}
    );
    
if (debug)
    alert("Done generateGroupPolylines for groupId: " + groupId);
    

}

//*******************************************************************************
// Function:     regenerateGroupPolyLines
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.1
// Date:         Aug 23 2006
//
// Description:  Function regenerates groups of polylines
//
// Parameters:   groupId - group ID
//               datafile - XML data file
//               lineWidth - polyline width
//               lineColor - polyline color
// Returns:
// Calls:        
// Called By:    togglePolyLineLayer()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function regenerateGroupPolyLines( groupId, datafile, lineWidth, lineColor, lineOpacity, optParameter1 ) {

// Debug variable (set to 1 to debug)
var debug = 0;

if (debug)
    alert('RegenerateGroupPolyLines: ' + groupId);
       
    
    //alert("draw line: '" + groupId + "' datafile is:" + datafile);
    
    // generate group polylines in the xml file
    generateGroupPolylines( groupId, datafile, lineWidth, lineColor, lineOpacity, optParameter1 );
    
    //alert("done draw line: '" + groupId + "'" + datafile);

if (debug)
{
    if (overlays != null)
        if (overlays['groups'] != null)
        {
            alert("After add: overlays['groups'].length: " + overlays['groups'].length);
            for( j=0; j<overlays['groups'].length; j++ ) 
                alert("overlays['groups'][" + j + "]: " + overlays['groups'][j]);
        }
}

}

//*******************************************************************************
// Function:     toggleCheckboxLayer
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.9
// Date:         Dec 04 2006
//
// Description:  Toggle layer on map to turn on/off based on the input checkbox.
//               This function calls toggleLayer(). The difference between these
//               two functions is that toggleMapLayer() is called directly due to
//               user interaction with a specific checkbox, where as 
//               toggleLayer() can also be called programmatically without 
//               direct user interaction. Hence, this will help differentiate 
//               whether it originates directly from user toggling the checkbox.
//
// Parameters:   control - Input checkbox control
//               optParameter1 - optional parameters used for filtering
//                               such as bus route id
//               optFilterLayerXMLPath - this will override default
//                                       path to XML content in cases
//                                       where filtering is needed
// Returns:
// Calls:        
// Called By:    Input checkbox clicked for a map layer
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function toggleCheckboxLayer( control, optParameter1, optFilterLayerXMLPath ){
    
    toggleLayer( control, optParameter1, optFilterLayerXMLPath, true );
}

//*******************************************************************************
// Function:     toggleLayer
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.7
// Date:         Nov 02 2006
//
// Description:  Toggle layer on map to turn on/off based on the input checkbox.
//
// Parameters:   control - Input checkbox control
//               optParameter1 - optional parameters used for filtering
//                               such as bus route id
//               optFilterLayerXMLPath - this will override default
//                                       path to XML content in cases
//                                       where filtering is needed
//               userToggle - indicates whether user directly toggles on/off checkbox
// Returns:
// Calls:        
// Called By:    Input checkbox clicked for a map layer
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function toggleLayer( control, optParameter1, optFilterLayerXMLPath, userToggle ){

    // Toggle associated Map Menu Checkboxes representing same layers
    toggleMapMenuCheckbox(control, optParameter1, userToggle);

    // check box name representing the map layer
    var checkBoxName = control.id;
    
    // Retrieve group id based on checkbox name    
    var groupIds = GetCheckBoxMapLayerName(checkBoxName, optParameter1);

    // Toggle each layer on or off based on marker or polyline layer.
    for (var i=0; i<groupIds.length; i++)
    {
        // Get the current group id
        var groupId = groupIds[i];
        
        //alert("group to be toggled is:" + groupId.LayerName);
        
        if (groupId.LayerType == "Marker")
            toggleMarkerLayer( control, groupId.LayerName, optParameter1, optFilterLayerXMLPath );
        else if (groupId.LayerType == "Polyline")
            togglePolyLineLayer( control, groupId.LayerName, optParameter1 ); 

            //window.setTimeout(hideLoading, 1000);
    }

}

//*******************************************************************************
// Function:     toggleMarkerLayer
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 20 2006
//
// Description:  Toggle layer on map to turn on/off based on the input checkbox.
//
// Parameters:   control - Input checkbox control
//               groupId - name of the map layer 
//               optFilterLayerXMLPath - this will override default
//                                       path to XML content in cases
//                                       where filtering is needed
// Returns:
// Calls:        
// Called By:    Input checkbox clicked for a map layer
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function toggleMarkerLayer( control, groupId, optParameter1, optFilterLayerXMLPath  ){
    
    var iconImage;      // icon file name
    var shadowIconImage; // shadow icon file name
    
    // icon properties
    var iconWidth;
    var iconHeight;
    var shadowW;
    var shadowH;
    var hasShadow=true;  // indicate if the marker should have a shadow or not
    var transitTestString;
    var transitTestInt=0;

    // check box name representing the map layer
    var checkBoxName = control.id;

    transitTestString = checkBoxName;

    //check to see if this a public transit layer
    transitTestInt = transitTestString.indexOf('TRA_Public');   
    if (transitTestInt != -1){
        //alert("yep tranist bus"); 
        checkBoxName="chk_TRA_Public_Marker";
    }

//alert("final .. checkbox name is: " + checkBoxName );

    // If control is checked, toggle map layer to turn on
    if( control.checked ) {
  
        switch( checkBoxName ) 
        {
        
            //set the icon properties for each type of layer
            case "chk_BusRouteTest" : { hasShadow=false; iconHeight=14; iconWidth=14; shadowH=0; shadowW=0;  break; }         
           
            
            // Event Layers
            case "chk_EV_CurInc" : {iconHeight=17; iconWidth=21; shadowH=17; shadowW=30;  break; }         
            case "chk_EV_CurCon" :  {iconHeight=23; iconWidth=21; shadowH=23; shadowW=35; break; } 	
            case "chk_EV_CurEv" : {iconHeight=19; iconWidth=19; shadowH=19; shadowW=34; break; }         
            case "chk_EV_FutCon" :  {iconHeight=23; iconWidth=21; shadowH=23; shadowW=35; break; } 	
            case "chk_EV_FutEv" :  {iconHeight=18; iconWidth=19; shadowH=19; shadowW=37; break; } 	
            case "chk_EV_FutSrvc" :  {iconHeight=17; iconWidth=20; shadowH=17; shadowW=30; break; } 	
            case "EventsReal": {iconHeight=19; iconWidth=19; shadowH=19; shadowW=34; break; }
            
            // Camera Layers
            case "chk_CAM_Border": 
		    case "chk_CAM_TrafficInt": 
		    case "chk_CAM_TrafficHigh":  
		    case "chk_CAM_Port": 
		    case "CamerasReal": {
		    
                iconWidth=25; iconHeight=11; shadowW=35; shadowH=11;  
                break; 
            }
            
            // Weather Layer
            // - no need to set image width and height
            case "chk_Weather": {
		    
                iconWidth=44; iconHeight=35; shadowW=0; shadowH=0;  
                break; 
            }
            
           
            // Road Layers
            
            case "chk_ROD_HwaySigns" : {iconHeight=22; iconWidth=22; shadowH=21; shadowW=32;  break; }                                             
            case "chk_ROD_Cong" :  {iconHeight=17; iconWidth=21; shadowH=17; shadowW=30;  break; }
            case "chk_ROD_CurInc" : {iconHeight=17; iconWidth=21; shadowH=17; shadowW=30;  break; }         
            case "chk_ROD_CurCon" :  {iconHeight=23; iconWidth=21; shadowH=23; shadowW=35; break; } 	
            case "chk_ROD_CurEvnt" : {iconHeight=19; iconWidth=19; shadowH=19; shadowW=34; break; }

//Brian change new US border layer
            case "chk_ROD_Border" : {iconWidth=18; iconHeight=9; shadowW=39; shadowH=9;  break; }
            case "chk_ROD_USBorder" : {iconWidth=18; iconHeight=9; shadowW=39; shadowH=9;  break; }


            case "chk_ROD_Parking" : {iconWidth=19; iconHeight=19; shadowW=34; shadowH=18;  break; }
            case "chk_ROD_Landmarks" : {iconWidth=19; iconHeight=18; shadowW=37; shadowH=19;  break; }            
            case "chk_ROD_NonKeyLandmarks" : {iconWidth=19; iconHeight=18; shadowW=37; shadowH=19;  break; }
            case "chk_ROD_FacStatus" : {iconWidth=19; iconHeight=18; shadowW=37; shadowH=19;  break; }            
            case "chk_ROD_Albion" : {iconWidth=28; iconHeight=16; shadowW=36; shadowH=16;  break; }                        
                        
            // Transit Layers
            // - all polylines: - no need to set image width and height
            case "chk_TRA_Public_Marker" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }         
            case "chk_TRA_BlueBus" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }         
            
//bus_test
            case "chk_Test_Route9Markers" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }         
            case "chk_Test_Route218Markers" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }         
            case "chk_Test_PerfTestMarkers" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }                     
            case "chk_Test_Route73PolyMarkers" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }                     

            case "chk_TRA_Exch" : {iconWidth=16; iconHeight=19; shadowW=34; shadowH=19;  break; }         
            case "chk_TRA_Parking" : {iconWidth=19; iconHeight=19; shadowW=34; shadowH=18;  break; }
            case "chk_TRA_Greyhound": {iconWidth=16; iconHeight=19; shadowW=34; shadowH=19;  break; }         
            case "chk_TRA_BCFerries" : {iconWidth=28; iconHeight=16; shadowW=36; shadowH=16;  break; }
            case "chk_TRA_IntAir" : {iconWidth=23; iconHeight=23; shadowW=44; shadowH=23;  break; }
            case "chk_TRA_RegAir" : {iconWidth=23; iconHeight=23; shadowW=44; shadowH=23;  break; }
            case "chk_TRA_SeaBus" : {iconWidth=35; iconHeight=16; shadowW=40; shadowH=15;  break; }       
            case "chk_TRA_ViaRail" : {iconWidth=16; iconHeight=24; shadowW=51; shadowH=38;  break; }
            case "chk_TRA_Amtrak" : {iconWidth=16; iconHeight=24; shadowW=51; shadowH=38;  break; }
            case "chk_TRA_WstCstExpr" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }         
            case "chk_TRA_Boundaries" : {iconWidth=19; iconHeight=19; shadowW=37; shadowH=19;  break; }            
            case "chk_TRA_ExpoLine" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }         
            case "chk_TRA_MilLine" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }         

       
            // Commercial Layers
            case "chk_COM_Weigh" : {iconWidth=19; iconHeight=18; shadowW=37; shadowH=19; break; }
            case "chk_COM_Border" : {iconWidth=18; iconHeight=19; shadowW=39; shadowH=19;  break; }
            case "chk_COM_BCFerries" : {iconWidth=28; iconHeight=16; shadowW=36; shadowH=16;  break; }
            case "chk_COM_IntAir" : {iconWidth=23; iconHeight=23; shadowW=44; shadowH=23;  break; }
            case "chk_COM_RegAir" : {iconWidth=23; iconHeight=23; shadowW=44; shadowH=23;  break; }
            case "chk_COM_Restrictions" : {iconWidth=19; iconHeight=18; shadowW=37; shadowH=19;  break; }
            // Truck Routes: polyline - no need to set image width and height
            // Dangerous Goods: polyline - no need to set image width and height
            // Emergency Response: polyline - no need to set image width and height
            
            // Marine Layers
            case "chk_MA_CruiseLines" : {iconWidth=23; iconHeight=24; shadowW=41; shadowH=26;  break; }
            case "chk_MA_Ports" : {iconWidth=20; iconHeight=20; shadowW=35; shadowH=20;  break; }
            case "chk_MA_CustomEntry" : {iconWidth=19; iconHeight=18; shadowW=34; shadowH=18;  break; }
            case "chk_MA_FalseCreek" : {iconWidth=28; iconHeight=16; shadowW=36; shadowH=16;  break; }
            case "chk_MA_MarineAccess" : {iconWidth=28; iconHeight=16; shadowW=36; shadowH=16;  break; }
            case "chk_MA_BCFerries" : {iconWidth=28; iconHeight=16; shadowW=36; shadowH=16;  break; }            
            case "chk_MA_SeaBus" : {iconWidth=35; iconHeight=16; shadowW=40; shadowH=15;  break; } 
            case "chk_MA_Albion" : {iconWidth=28; iconHeight=16; shadowW=36; shadowH=16;  break; }                                          
            
            // Air Layers
            case "chk_AIR_IntAir" : {iconWidth=23; iconHeight=23; shadowW=44; shadowH=23;  break; }
            case "chk_AIR_RegAir" : {iconWidth=23; iconHeight=23; shadowW=44; shadowH=23;  break; }
            case "chk_AIR_HrbrAir" : {iconWidth=23; iconHeight=23; shadowW=44; shadowH=23;  break; }
            case "chk_AIR_WestCoastAir" : {iconWidth=23; iconHeight=23; shadowW=44; shadowH=23;  break; }
            case "chk_AIR_Helijet" : {iconWidth=23; iconHeight=23; shadowW=44; shadowH=23;  break; }
            
            // Rail Layers        
            case "chk_RAIL_Railroads" : {iconWidth=16; iconHeight=24; shadowW=51; shadowH=38;  break; }
//            case "chk_RAIL_ExpoLine" : polyline
//            case "chk_RAIL_MilLine" : polyline
//            case "chk_RAIL_WstCstExpr" : polyline
            case "chk_RAIL_ViaRail" : {iconWidth=16; iconHeight=24; shadowW=51; shadowH=38;  break; }
            case "chk_RAIL_RockyMtn" : {iconWidth=16; iconHeight=24; shadowW=51; shadowH=38;  break; }
            case "chk_RAIL_Amtrak" : {iconWidth=16; iconHeight=24; shadowW=51; shadowH=38;  break; }
            case "chk_RAIL_RailAccess" : {iconWidth=16; iconHeight=24; shadowW=51; shadowH=38;  break; }
            case "chk_RAIL_WstCstExpr" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }         
            case "chk_RAIL_MilLine" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }         
            case "chk_RAIL_ExpoLine" : {hasShadow=false; iconWidth=14; iconHeight=14; shadowW=34; shadowH=19;  break; }         

            // Cycling Layer
            // - all polylines: - no need to set image width and height 
            
   		    default: break;

		}

        //get the icon file name
        iconImage=getLayerIconPath(checkBoxName);
     	
 	    // trim off extension, and add -s for the shadow image..
 	    shadowIconImage = iconImage.substr(0,iconImage.length-4) + "-s.png";
 	     	    
        // Use the optional filter path if it is input otherwise
        // get default path to XML content
        if (optFilterLayerXMLPath == null)
            optFilterLayerXMLPath = getLayerXMLPath(checkBoxName, optParameter1);

        // this will load the markers into memory, and will toggle them on, if the checkbox is checked	    
  	    regenerateGroupMarkers( groupId, optFilterLayerXMLPath, generateShadowIcon( hasShadow, iconImage,iconWidth,iconHeight,shadowIconImage,shadowW,shadowH), optParameter1 );
	    
    } 
    else 
    { // If control is unchecked, toggle map layer to turn off

        //toggle the group off the map
        toggleGroup(groupId, false);	   
        
    }   
}

//*******************************************************************************
// Function:     getLayerIconPath
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 20 2006
//
// Description:  Gets the file path of the icon for a specific map layer
//
// Parameters:   groupId - The checkbox name represents the group id of the layer
// Returns:      icon's file path
// Calls:        
// Called By:    toggleMarkerLayer()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function getLayerIconPath( groupId ){
	
	// default location for icon's file path
	var iconRootPath ="/ATIS/App_Themes/atis/images/"
	
	// stores the icon's file path
	var iconPath = "";
	
    // Special Case for Public Bus Routes Markers
    var specialGroupId = "";
    specialGroupId = groupId.substring(0,21);
    if (specialGroupId == "chk_TRA_Public_Marker")
        groupId = specialGroupId;

    // Special Case for West Van Blue Bus Routes
	specialGroupId = "";
	specialGroupId = groupId.substring(0,15);
	if (specialGroupId == "chk_TRA_BlueBus")
	    groupId = specialGroupId;

	switch( groupId ) {  
	
        //set the icon properties for each type of layer
        case "chk_BusRouteTest" : { iconPath = iconRootPath + "png/stop.png"; break; } 	        
        case "chk_TRA_BlueBus" : { iconPath = iconRootPath + "png/stop.png"; break; } 	                
        
//bus_test                        	   
        case "chk_Test_Route9Markers" : { iconPath = iconRootPath + "png/stop.png"; break; } 	
        case "chk_Test_Route218Markers" : { iconPath = iconRootPath + "png/stop.png"; break; } 	
        case "chk_Test_PerfTestMarkers" : { iconPath = iconRootPath + "png/stop.png"; break; } 	
        case "chk_Test_Route73PolyMarkers" : { iconPath = iconRootPath + "png/stop.png"; break; } 	
        
        //events layers
        case "chk_EV_CurInc" : { iconPath = iconRootPath + "png/cur-incidents.png"; break; } 	        
        case "chk_EV_CurCon" : { iconPath = iconRootPath + "png/cur-construction.png"; break; } 	        
        case "chk_EV_CurEv" : { iconPath = iconRootPath + "png/cur-events.png"; break; } 	        
        case "chk_EV_FutCon" : { iconPath = iconRootPath + "png/fut-construction.png"; break; } 	        
        case "chk_EV_FutEv" : { iconPath = iconRootPath + "png/fut-events.png"; break; } 	        
        case "chk_EV_FutSrvc" : { iconPath = iconRootPath + "png/fut-serv-disr.png"; break; } 	        
        //All Events: no need to set image
            
        // Camera Layers
        case "chk_CAM_Border": 
        case "chk_CAM_TrafficInt": 
        case "chk_CAM_TrafficHigh":  
        case "chk_CAM_Port":  { 
        
            iconPath = iconRootPath + "png/camera.png"; 
            break; 
        }
            
        // Weather Layer
        case "chk_Weather" : { 
            
            iconPath = iconRootPath + "weather_icons/a.gif"; 
            break; 
        } 
            
        // Road Layers
        case "chk_ROD_HwaySigns" : {iconPath = iconRootPath + "png/highwaySigns.png"; break;}
        case "chk_ROD_Cong" :  {iconPath = iconRootPath + "png/cur-incidents.png"; break;}
        case "chk_ROD_CurInc" : {iconPath = iconRootPath + "png/cur-incidents.png"; break;}    
        case "chk_ROD_CurCon" :  {iconPath = iconRootPath + "png/cur-construction.png"; break;}
        case "chk_ROD_CurEvnt" : {iconPath = iconRootPath + "png/cur-events.png"; break;}

//Brian fix: new US border layer
        case "chk_ROD_Border" : {iconPath = iconRootPath + "png/CANborder.png"; break;}
        case "chk_ROD_USBorder" : {iconPath = iconRootPath + "png/USborder.png"; break;}

        case "chk_ROD_Parking" : {iconPath = iconRootPath + "png/parking.png"; break;}
        case "chk_ROD_Landmarks" : { iconPath = iconRootPath + "png/landmarks.png"; break; }        
        case "chk_ROD_NonKeyLandmarks" : { iconPath = iconRootPath + "png/landmarks.png"; break; }
        case "chk_ROD_FacStatus" : { iconPath = iconRootPath + "png/landmarks.png"; break; }        
        case "chk_ROD_Albion" : { iconPath = iconRootPath + "png/ferry.png"; break; }
                
        // Transit Layers
        case "chk_TRA_Public_Marker" : {  iconPath = iconRootPath + "png/stop.png"; break; } 	        
        case "chk_TRA_BlueBus" : { iconPath = iconRootPath + "png/stop.png"; break; } 
        
        case "chk_TRA_MilLine" : { iconPath = iconRootPath + "png/stop.png"; break; } 	        
        case "chk_TRA_ExpoLine" : { iconPath = iconRootPath + "png/stop.png"; break; } 	                
        case "chk_TRA_Exch" : { iconPath = iconRootPath + "png/trans-bus.png"; break; } 	        
        case "chk_TRA_Parking" : { iconPath = iconRootPath + "png/parking.png"; break; } 
        case "chk_TRA_Greyhound": { iconPath = iconRootPath + "png/trans-bus.png"; break; } 	        
        case "chk_TRA_BCFerries" : {iconPath = iconRootPath + "png/ferry.png"; break;}
        case "chk_TRA_IntAir" : { iconPath = iconRootPath + "png/airport.png"; break; }
        case "chk_TRA_RegAir" : { iconPath = iconRootPath + "png/airport.png"; break; }
        case "chk_TRA_SeaBus" : { iconPath = iconRootPath + "png/seabus.png"; break; }
        case "chk_TRA_ViaRail" : { iconPath = iconRootPath + "png/train.png"; break; }
        case "chk_TRA_Amtrak" : { iconPath = iconRootPath + "png/train.png"; break; }
        case "chk_TRA_WstCstExpr" : { iconPath = iconRootPath + "png/stop.png"; break; } 	                        
        case "chk_TRA_Boundaries" : { iconPath = iconRootPath + "png/boundary.png"; break; }        
            
        // Commercial layers   
        case "chk_COM_Weigh" : { iconPath = iconRootPath + "png/weigh-scale.png"; break; }
        case "chk_COM_Border" : {iconPath = iconRootPath + "png/border.png"; break;}
        case "chk_COM_BCFerries" : { iconPath = iconRootPath + "png/ferry.png"; break; }
        case "chk_COM_IntAir" : { iconPath = iconRootPath + "png/airport.png"; break; }
        case "chk_COM_RegAir" : { iconPath = iconRootPath + "png/airport.png"; break; }
        case "chk_COM_Restrictions" : { iconPath = iconRootPath + "png/dangerousGoods.png"; break; }        
        // Truck Routes: polyline - no need to set image width and height
        // Dangerous Goods: polyline - no need to set image width and height
        // Emergency Response: polyline - no need to set image width and height
            
        // Marine Layers
        case "chk_MA_CruiseLines" : { iconPath = iconRootPath + "png/cruise-line.png"; break; }
        case "chk_MA_Ports" : { iconPath = iconRootPath + "png/port.png"; break; }
        case "chk_MA_CustomEntry" : { iconPath = iconRootPath + "png/customEntryPoints.png"; break; }
        case "chk_MA_FalseCreek" : { iconPath = iconRootPath + "png/ferry.png"; break; }
        case "chk_MA_MarineAccess" : { iconPath = iconRootPath + "png/ferry.png"; break; }
        case "chk_MA_BCFerries" : {iconPath = iconRootPath + "png/ferry.png"; break;}
        case "chk_MA_SeaBus" : { iconPath = iconRootPath + "png/seabus.png"; break; }        
        case "chk_MA_Albion" : { iconPath = iconRootPath + "png/ferry.png"; break; }        
        
        // Air Layers
        case "chk_AIR_IntAir" : { iconPath = iconRootPath + "png/airport.png"; break; }
        case "chk_AIR_RegAir" : { iconPath = iconRootPath + "png/airport.png"; break; }
        case "chk_AIR_HrbrAir" : { iconPath = iconRootPath + "png/airport.png"; break; }
        case "chk_AIR_WestCoastAir" : { iconPath = iconRootPath + "png/airport.png"; break; }
        case "chk_AIR_Helijet" : { iconPath = iconRootPath + "png/airport.png"; break; }     
        
        // Rail Layers        
        case "chk_RAIL_Railroads" : { iconPath = iconRootPath + "png/train.png"; break; }
//            case "chk_RAIL_ExpoLine" : polyline
//            case "chk_RAIL_MilLine" : polyline
//            case "chk_RAIL_WstCstExpr" : polyline
        case "chk_RAIL_ViaRail" : { iconPath = iconRootPath + "png/train.png"; break; }
        case "chk_RAIL_RockyMtn" : { iconPath = iconRootPath + "png/train.png"; break; }
        case "chk_RAIL_Amtrak" : { iconPath = iconRootPath + "png/train.png"; break; }
        case "chk_RAIL_RailAccess" : { iconPath = iconRootPath + "png/train.png"; break; }
        case "chk_RAIL_WstCstExpr" : { iconPath = iconRootPath + "png/stop.png"; break; } 	                                
        case "chk_RAIL_MilLine" : { iconPath = iconRootPath + "png/stop.png"; break; } 	        
        case "chk_RAIL_ExpoLine" : { iconPath = iconRootPath + "png/stop.png"; break; } 	                	                

        
        // Cycling Layer
        // - all polylines: - no need to set image width and height 
        

   		default: break;

		}
    return iconPath;
}


//*******************************************************************************
// Function:     getLayerXMLPath
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 20 2006
//
// Description:  Gets the URL of the service to return the XML data response
//               for the specific map layer
//
// Parameters:   groupId - The checkbox name represents the group id of the layer
//               optParameter1 - optional parameters used for filtering
//                               such as bus route id
// Returns:      URL path to return the XML data response
// Calls:        
// Called By:    toggleMarkerLayer()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function getLayerXMLPath ( groupId, optParameter1 ){

//alert("group is: " + groupId + " opt is:" + optParameter1);
    
    // default path for retrieving XML data for the grid or map
    // the global variable "xmlRootPathCommon" is defined at the top of this page

    // default service for retrieving XML data response for the grid or map
    // the global variable "xmlRootPathService" is definded at the top of this page
    
    // stores the URL path to return the XML data response
	var xmlPath = "";
	
	
    // Special Case for Public Bus Routes Markers
    var specialGroupId = "";
    specialGroupId = groupId.substring(0,21);
    if (specialGroupId == "chk_TRA_Public_Marker")
        groupId = specialGroupId;

    // Special Case for Public Bus Routes polylines
    specialGroupId = "";
    specialGroupId = groupId.substring(0,23);
    if (specialGroupId == "chk_TRA_Public_Polyline")
        groupId = specialGroupId;


    // Special Case for highlighting a public Bus Routes
	specialGroupId = "";
	specialGroupId = groupId.substring(0,24);
	if (specialGroupId == "chk_TRA_Highlight_Public")
	    groupId = specialGroupId;

	switch( groupId ) {

//        case "chk_BusRouteTest" : { xmlPath = xmlRootPathService + "Busroutes.aspx?routeid=1" + optParameter1; break; }
        case "chk_BusRouteTest" : { xmlPath = xmlRootPathService + "Busroutes.aspx?routeid=" + optParameter1; break; }
             
        //events layers
        case "chk_EV_CurInc" : { xmlPath = xmlRootPathService + "Events.aspx?type=Incident" + "&" + filterAdvisoriesQueryString( false ); break; }
        case "chk_EV_CurCon" : { xmlPath = xmlRootPathService + "Events.aspx?type=Construction" + "&" + filterAdvisoriesQueryString( false ); break; } 	        
        case "chk_EV_CurEv" : { xmlPath = xmlRootPathService + "Events.aspx?type=Event" + "&" + filterAdvisoriesQueryString( false ); break; } 	        
        case "chk_EV_FutCon" : { xmlPath = xmlRootPathService + "Events.aspx?type=Future%20Construction" + "&" + filterAdvisoriesQueryString( false ); break; } 	        
        case "chk_EV_FutEv" : { xmlPath = xmlRootPathService + "Events.aspx?type=Future%20Event" + "&" + filterAdvisoriesQueryString( false ); break; } 	        
        case "chk_EV_FutSrvc" : { xmlPath = xmlRootPathService + "Events.aspx?type=Future%20Service" + "&" + filterAdvisoriesQueryString( false ); break; } 	        
            
        // Camera Layers
        case "chk_CAM_Border" : { xmlPath = xmlRootPathService + "Cameras.aspx?type=Border" + "&" + filterCamerasQueryString( false ); break; } 
        case "chk_CAM_TrafficInt" : { xmlPath = xmlRootPathService + "Cameras.aspx?type=Intersection" + "&" + filterCamerasQueryString( false ); break; } 
        case "chk_CAM_TrafficHigh" : { xmlPath = xmlRootPathService + "Cameras.aspx?type=Highway" + "&" + filterCamerasQueryString( false ); break; } 
        case "chk_CAM_Port" : { xmlPath = xmlRootPathService + "Cameras.aspx?type=Port" + "&" + filterCamerasQueryString( false ); break; } 

        //Weather layers
        case "chk_Weather" : { xmlPath = xmlRootPathCommon + "Weather.xml" + getTimeStampQueryString(); break; } 

        // Road Layers
        case "chk_ROD_HwaySigns" : { xmlPath = xmlRootPathCommon + "highWaySigns.xml" + getTimeStampQueryString(); break; } 
        case "chk_ROD_Cong" : { xmlPath = xmlRootPathCommon + "congestion.xml" + getTimeStampQueryString(); break; } 
        case "chk_ROD_CurInc" : { xmlPath = xmlRootPathService + "Events.aspx?type=Incident" + "&" + filterAdvisoriesQueryString( false ); break; }
        case "chk_ROD_CurCon" : { xmlPath = xmlRootPathService + "Events.aspx?type=Construction" + "&" + filterAdvisoriesQueryString( false ); break; }
        case "chk_ROD_CurEvnt" : { xmlPath = xmlRootPathService + "Events.aspx?type=Event" + "&" + filterAdvisoriesQueryString( false ); break; }

//brian new US border layer
        case "chk_ROD_Border" : { xmlPath = xmlRootPathService + "BorderCrossings.aspx?type=Border"; break; }
        case "chk_ROD_USBorder" : { xmlPath = xmlRootPathService + "BorderCrossings.aspx?type=USBorder"; break; }

        case "chk_ROD_Parking" : { xmlPath = xmlRootPathCommon + "parkandrides.xml" + getTimeStampQueryString(); break; }
        case "chk_ROD_Landmarks" : { xmlPath = xmlRootPathService + "Landmarks.aspx?key=true"; break; }
        case "chk_ROD_NonKeyLandmarks" : { xmlPath = xmlRootPathService + "Landmarks.aspx?key=false"; break; }
        case "chk_ROD_FacStatus" : { xmlPath = xmlRootPathCommon + "facility.xml" + getTimeStampQueryString(); break; }
        case "chk_ROD_Albion" : { xmlPath = xmlRootPathService + "MarineServices.aspx?type=Albion"; break; } 	
        
        //Transit layers
        //case "chk_TRA_Public" : { xmlPath = xmlRootPathService + "Busroutes.aspx?routeid=" + optParameter1; break; }
        case "chk_TRA_Public_Marker" : { xmlPath = xmlRootPathCommon + "BusRoutes/BusRouteStops" + optParameter1 + ".xml"; break; }
        case "chk_TRA_Public_Polyline" : { xmlPath = xmlRootPathCommon + "BusRoutes/BusRoutePolyline" + optParameter1 + ".xml"; break; }
        
        //Old Bus Routes Path, this was failing every now and then in firefox
        //case "chk_TRA_Public_Marker" : { xmlPath = xmlRootPathBusRoutes + "BusRouteStops" + optParameter1 + ".xml"; break; }
        //case "chk_TRA_Public_Polyline" : { xmlPath = xmlRootPathBusRoutes + "BusRoutePolyline" + optParameter1 + ".xml"; break; }

        case "chk_TRA_BlueBus" : { xmlPath = xmlRootPathService + "Busroutes.aspx?routeid=" + optParameter1; break; }
//bus_test
        case "chk_Test_Route9Markers" : { xmlPath = xmlRootPathCommon + "route9markers.xml";  break; }
        case "chk_Test_Route9Poly" : { xmlPath = xmlRootPathCommon + "route9poly.xml"; break; }
        case "chk_Test_Route218Markers" : { xmlPath = xmlRootPathCommon + "route218markers.xml";  break; }
        case "chk_Test_Route218Poly" : { xmlPath = xmlRootPathCommon + "route218poly.xml"; break; }
        case "chk_Test_PerfTestMarkers" : { xmlPath = xmlRootPathCommon + "routePerfTestmarkers.xml";  break; }
        case "chk_Test_PerfTestPoly" : { xmlPath = xmlRootPathCommon + "routePerfTestpoly.xml"; break; }
        case "chk_Test_Route73PolyMarkers" : { xmlPath = xmlRootPathCommon + "route73.xml"; break; }    

        case "chk_TRA_Highlight_Public" : { xmlPath = xmlRootPathBusRoutes + "BusRoutePolyline" + optParameter1 + ".xml"; break; }
        //case "chk_TRA_Highlight_Public" : { xmlPath = xmlRootPathService + "Busroutes.aspx?routeid=" + optParameter1; break; }
         //case "chk_TRA_Highlight_BlueBus" : { xmlPath = xmlRootPathService + "Busroutes.aspx?routeid=" + optParameter1; break; }


        case "chk_TRA_Exch" : { xmlPath = xmlRootPathCommon + "transitExchange.xml" + getTimeStampQueryString(); break; } 	
        case "chk_TRA_Parking" : { xmlPath = xmlRootPathCommon + "parkandrides.xml" + getTimeStampQueryString(); break; } 	
        case "chk_TRA_ExpoLine" : { xmlPath = xmlRootPathService + "skyTrain.aspx?type=Expo"; break; }
        case "chk_TRA_MilLine" : { xmlPath = xmlRootPathService + "skyTrain.aspx?type=Millennium"; break; }
        case "chk_TRA_WstCstExpr" : { xmlPath = xmlRootPathCommon + "wstCostExp.xml" + getTimeStampQueryString(); break; } 
        case "chk_TRA_Boundaries" : { xmlPath = xmlRootPathCommon + "ATIS_Boundaries.xml" + getTimeStampQueryString(); break; } 	
        case "chk_TRA_SeaBus": { xmlPath = xmlRootPathCommon + "seaBus.xml" + getTimeStampQueryString(); break; } 	
        case "chk_TRA_WstCstExpr" : { xmlPath = xmlRootPathCommon + "wstCostExp.xml" + getTimeStampQueryString(); break; } 
        case "chk_TRA_Greyhound": { xmlPath = xmlRootPathService + "PrivateTransitServices.aspx?type=PrivateTransit"; break; } 	
        case "chk_TRA_BCFerries" : { xmlPath = xmlRootPathService + "MarineServices.aspx?type=BCFerries"; break; }
        case "chk_TRA_IntAir" : { xmlPath = xmlRootPathService + "AirPortServices.aspx?type=International"; break; }
        case "chk_TRA_RegAir" : { xmlPath = xmlRootPathService + "AirPortServices.aspx?type=Regional"; break; }
        case "chk_TRA_ViaRail" : { xmlPath = xmlRootPathService + "RailServices.aspx?type=VIARail"; break; }
        case "chk_TRA_Amtrak" : { xmlPath = xmlRootPathService + "RailServices.aspx?type=Amtrak"; break; }
        
        //Commercial layers
        case "chk_COM_Weigh" : { xmlPath = xmlRootPathCommon + "weighStations.xml" + getTimeStampQueryString(); break; }
        case "chk_COM_Border" : { xmlPath = xmlRootPathService + "BorderCrossings.aspx?type=Border"; break; }
        case "chk_COM_BCFerries" : { xmlPath = xmlRootPathService + "MarineServices.aspx?type=BCFerries"; break; } 	
        case "chk_COM_IntAir" : { xmlPath = xmlRootPathService + "AirPortServices.aspx?type=International"; break; } 	
        case "chk_COM_RegAir" : { xmlPath = xmlRootPathService + "AirPortServices.aspx?type=Regional"; break; } 	
        case "chk_COM_TruckRoute" : { xmlPath = xmlRootPathCommon + "truckingRoutes.xml" + getTimeStampQueryString(); break; } 	
        case "chk_COM_DangGoods" : { xmlPath = xmlRootPathCommon + "dangerGoodsRoutes.xml" + getTimeStampQueryString(); break; }
        case "chk_COM_EmerResp" : { xmlPath = xmlRootPathCommon + "emergencyResponseRoutes.xml" + getTimeStampQueryString(); break; }
        case "chk_COM_Restrictions" : { xmlPath = xmlRootPathCommon + "dangerousGoodsRestrictions.xml" + getTimeStampQueryString(); break; }
        
        // Marine Layers
        case "chk_MA_CruiseLines" : { xmlPath = xmlRootPathService + "MarineServices.aspx?type=CruiseLines"; break; }
        case "chk_MA_Ports" : { xmlPath = xmlRootPathService + "MarineServices.aspx?type=Ports"; break; }
        case "chk_MA_CustomEntry" : { xmlPath = xmlRootPathService + "MarineServices.aspx?type=CustomEntryPoints"; break; }
        case "chk_MA_FalseCreek" : { xmlPath = xmlRootPathService + "MarineServices.aspx?type=FalseCreekFerries"; break; }
        case "chk_MA_MarineAccess" : { xmlPath = xmlRootPathService + "MarineServices.aspx?type=MarineAccessPoints"; break; }
        case "chk_MA_SeaBus": { xmlPath = xmlRootPathCommon + "seaBus.xml" + getTimeStampQueryString(); break; } 	
        case "chk_MA_BCFerries" : { xmlPath = xmlRootPathService + "MarineServices.aspx?type=BCFerries"; break; }
        case "chk_MA_Albion" : { xmlPath = xmlRootPathService + "MarineServices.aspx?type=Albion"; break; } 	        
        
        // Air Layers
        case "chk_AIR_IntAir" : { xmlPath = xmlRootPathService + "AirPortServices.aspx?type=International"; break; }
        case "chk_AIR_RegAir" : { xmlPath = xmlRootPathService + "AirPortServices.aspx?type=Regional"; break; }
        case "chk_AIR_HrbrAir" : { xmlPath = xmlRootPathService + "AirPortServices.aspx?type=Harbour"; break; }
        case "chk_AIR_WestCoastAir" : { xmlPath = xmlRootPathService + "AirPortServices.aspx?type=WestCoastAir"; break; }
        case "chk_AIR_Helijet" : { xmlPath = xmlRootPathService + "AirPortServices.aspx?type=Helijet"; break; }
        
        // Rail Layers
        case "chk_RAIL_Railroads" : { xmlPath = xmlRootPathService + "RailServices.aspx?type=RailRoads"; break; }
        case "chk_RAIL_ExpoLine" : { xmlPath = xmlRootPathService + "skyTrain.aspx?type=Expo"; break; }
        case "chk_RAIL_MilLine" : { xmlPath = xmlRootPathService + "skyTrain.aspx?type=Millennium"; break; }
        case "chk_RAIL_WstCstExpr" : { xmlPath = xmlRootPathCommon + "wstCostExp.xml" + getTimeStampQueryString(); break; }
        case "chk_RAIL_ViaRail" : { xmlPath = xmlRootPathService + "RailServices.aspx?type=VIARail"; break; }
        case "chk_RAIL_RockyMtn" : { xmlPath = xmlRootPathService + "RailServices.aspx?type=Rocky"; break; }
        case "chk_RAIL_Amtrak" : { xmlPath = xmlRootPathService + "RailServices.aspx?type=Amtrak"; break; }
        case "chk_RAIL_RailAccess" : { xmlPath = xmlRootPathService + "RailServices.aspx?type=RailAccess"; break; }
        case "chk_RAIL_WstCstExpr" : { xmlPath = xmlRootPathCommon + "wstCostExp.xml" + getTimeStampQueryString(); break; }
            
        // Cycling Layer
        case "chk_CYC_DesOnStreet" : { xmlPath = xmlRootPathService + "cyclingPath.aspx?type=Designated-OnStreet"; break; }
        case "chk_CYC_DesOffStreet" : { xmlPath = xmlRootPathService + "cyclingPath.aspx?type=Designated-OffStreet"; break; }   
        case "chk_CYC_AltOnStreet" : { xmlPath = xmlRootPathService + "cyclingPath.aspx?type=Alternate-OnStreet"; break; }
        case "chk_CYC_AltOffStreet" : { xmlPath = xmlRootPathService + "cyclingPath.aspx?type=Alternate-OffStreet"; break; }           

        //TRUCK ROUTES
        case "chk_truckRouteAbbotsford" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteAbbotsford.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteAldergrove" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteAldergrove.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteBurnaby" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteBurnaby.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteCoquitlam" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteCoquitlam.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteDelta" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteDelta.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteFortLangley" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteFortLangley.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteMapleRidge" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteMapleRidge.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteMcMillanIslandIR" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteMcMillanIslandIR.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteMission" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteMission.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteNewWestminster" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteNewWestminster.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteNorthVancouver" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteNorthVancouver.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRoutePittMeadows" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRoutePittMeadows.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRoutePortCoquitlam" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRoutePortCoquitlam.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteRichmond" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteRichmond.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteSurrey" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteSurrey.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteUBC" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteUBC.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteVancouver" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteVancouver.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteWestVancouver" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteWestVancouver.xml" + getTimeStampQueryString(); break; }
        case "chk_truckRouteWhiteRock" : { xmlPath = xmlRootPathCommon + "/TruckRoutes/truckRouteWhiteRock.xml" + getTimeStampQueryString(); break; }


        //CYCLING ROUTES 
        case "chk_cycAbbotsford_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycAbbotsford_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycBelcarra_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycBelcarra_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycBelcarra_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycBelcarra_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycBurnaby_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycBurnaby_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycBurnaby_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycBurnaby_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycBurnaby_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycBurnaby_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycBurnaby_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycBurnaby_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycCoquitlam_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycCoquitlam_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycCoquitlam_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycCoquitlam_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycCoquitlam_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycCoquitlam_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycCoquitlam_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycCoquitlam_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycDelta_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycDelta_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycDelta_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycDelta_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycDelta_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycDelta_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycDelta_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycDelta_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycLangley_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycLangley_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycLangley_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycLangley_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycLangley_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycLangley_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycLangley_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycLangley_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycLionsBay_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycLionsBay_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycMapleRidge_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycMapleRidge_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycMapleRidge_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycMapleRidge_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycMapleRidge_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycMapleRidge_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycMapleRidge_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycMapleRidge_DesOn.xml" + getTimeStampQueryString(); break; }

        case "chk_cycNewWestminster_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycNewWestminster_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycNewWestminster_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycNewWestminster_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycNewWestminster_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycNewWestminster_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycNewWestminster_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycNewWestminster_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycNorthVancouver_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycNorthVancouver_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycNorthVancouver_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycNorthVancouver_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycNorthVancouver_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycNorthVancouver_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycNorthVancouver_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycNorthVancouver_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPittMeadows_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPittMeadows_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPittMeadows_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPittMeadows_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPittMeadows_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPittMeadows_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPittMeadows_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPittMeadows_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPortCoquitlam_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPortCoquitlam_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPortCoquitlam_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPortCoquitlam_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPortCoquitlam_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPortCoquitlam_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPortCoquitlam_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPortCoquitlam_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPortMoody_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPortMoody_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPortMoody_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPortMoody_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPortMoody_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPortMoody_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycPortMoody_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycPortMoody_DesOn.xml" + getTimeStampQueryString(); break; }

        case "chk_cycRichmond_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycRichmond_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycRichmond_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycRichmond_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycRichmond_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycRichmond_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycRichmond_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycRichmond_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycSurrey_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycSurrey_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycSurrey_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycSurrey_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycSurrey_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycSurrey_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycSurrey_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycSurrey_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycUBC_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycUBC_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycUBC_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycUBC_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycUBC_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycUBC_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycUBC_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycUBC_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycVancouver_AltOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycVancouver_AltOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycVancouver_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycVancouver_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycVancouver_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycVancouver_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycVancouver_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycVancouver_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycWestVancouver_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycWestVancouver_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycWestVancouver_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycWestVancouver_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycWestVancouver_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycWestVancouver_DesOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycWhiteRock_AltOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycWhiteRock_AltOn.xml" + getTimeStampQueryString(); break; }
        case "chk_cycWhiteRock_DesOff" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycWhiteRock_DesOff.xml" + getTimeStampQueryString(); break; }
        case "chk_cycWhiteRock_DesOn" : { xmlPath = xmlRootPathCommon + "/CyclingPaths/cycWhiteRock_DesOn.xml" + getTimeStampQueryString(); break; }
        

   
		default: break;

	}
    
    return xmlPath;
}

//*******************************************************************************
// Function:     togglePolyLineLayer
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 23 2006
//
// Description:  Toggle layer on map to turn on/off based on the input checkbox.
//               The layer contains polylines.
//
// Parameters:   control - Input checkbox control
//               groupId - name of the map layer 
//               optParameter1 - optional parameters used for filtering
//                               such as bus route id
// Returns:
// Calls:        
// Called By:    Input checkbox clicked for a map layer
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function togglePolyLineLayer( control, groupId, optParameter1 ){

    // check box name representing the map layer
    var checkBoxName = control.id;
    
    //polylines for highlighting bus routes
    var publicHighlightTest = "layer_TRA_Highlight_Public_Polyline_" + optParameter1;
    
    switch( groupId ) {
        
        //lineOpacity = 0.0 (clear) - 1 (dark)

        //Transit layers
        case publicHighlightTest: { lineWidth=13; lineColor="#03FD3E"; lineOpacity=0.6; break; }

        case "layer_WstCstExpr_Polyline" : { lineWidth=6; lineColor="#3B2884";lineOpacity=0.8; break; }
        case "layer_ExpoLine_Polyline" : { lineWidth=6; lineColor="#031D8C"; lineOpacity=0.8; break; }
        case "layer_MilLine_Polyline" : { lineWidth=6; lineColor="#031D8C"; lineOpacity=0.9; break; }
        case "layer_TRA_SeaBus_Polyline" : { lineWidth=6; lineColor="#09800B"; lineOpacity=0.6; break; }
        case "layer_TRA_Boundaries_Polyline" : { lineWidth=20; lineColor="#A0A0A0"; lineOpacity=0.5; break; }        
        
//bus_test        
        case "layer_Test_Route9Poly" : { lineWidth=5; lineColor="#FE04D2"; lineOpacity=0.9; break; }        
        case "layer_Test_Route218Poly" : { lineWidth=5; lineColor="#FE04D2"; lineOpacity=0.9; break; }        
        case "layer_Test_PerfTestPoly" : { lineWidth=5; lineColor="#FE04D2"; lineOpacity=0.9; break; }                
        case "layer_Test_Route73Polyline" : { lineWidth=5; lineColor="#FE04D2"; lineOpacity=0.9; break; }                        
                
        //Commerical layers
        case "layer_COM_TruckRoute" : { lineWidth=4; lineColor="#FE04D2"; lineOpacity=0.8; break; }
        case "layer_COM_DangGoods" : { lineWidth=7; lineColor="#FF0101"; lineOpacity=0.8; break; }
        case "layer_COM_EmerResp" : { lineWidth=4; lineColor="#FF0107"; lineOpacity=0.8; break; }
        case "layer_COM_Restrictions" : { lineWidth=7; lineColor="#FF0101"; break; }
        
        // Rail Layers
        case "layer_RAIL_ExpoLine" : { lineWidth=7; lineColor="#FE04D2"; lineOpacity=0.8; break; }
        case "layer_RAIL_MilLine" : { lineWidth=7; lineColor="#FE04D2"; lineOpacity=0.8; break; }
        //case "layer_RAIL_WstCstExpr" : { lineWidth=7; lineColor="#FE04D2"; break; }
        
        // Cycling Layers
        case "layer_CYC_DesOnStreet" : { lineWidth=6; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_CYC_DesOffStreet" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_CYC_AltOnStreet" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_CYC_AltOffStreet" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }                
    
        //Truck Routes
        case "layer_truckRouteAbbotsford" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteAldergrove" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteBurnaby" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteCoquitlam" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteDelta" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteFortLangley" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteMapleRidge" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteMcMillanIslandIR" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteMission" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteNewWestminster" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteNorthVancouver" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRoutePittMeadows" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRoutePortCoquitlam" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteRichmond" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteSurrey" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteUBC" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteVancouver" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteWestVancouver" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }
        case "layer_truckRouteWhiteRock" : { lineWidth=4; lineColor="#955B43"; lineOpacity=0.9; break; }

        //Cycling paths
        case "layer_cycAbbotsford_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycBelcarra_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycBelcarra_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycBurnaby_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycBurnaby_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycBurnaby_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycBurnaby_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycCoquitlam_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycCoquitlam_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycCoquitlam_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycCoquitlam_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycDelta_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycDelta_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycDelta_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycDelta_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycLangley_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycLangley_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycLangley_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycLangley_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycLionsBay_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycMapleRidge_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycMapleRidge_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycMapleRidge_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycMapleRidge_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }

        case "layer_cycNewWestminster_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycNewWestminster_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycNewWestminster_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycNewWestminster_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycNorthVancouver_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycNorthVancouver_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycNorthVancouver_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycNorthVancouver_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPittMeadows_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPittMeadows_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPittMeadows_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPittMeadows_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPortCoquitlam_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPortCoquitlam_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPortCoquitlam_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPortCoquitlam_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPortMoody_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPortMoody_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPortMoody_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycPortMoody_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }

        case "layer_cycRichmond_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycRichmond_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycRichmond_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycRichmond_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycSurrey_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycSurrey_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycSurrey_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycSurrey_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycUBC_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycUBC_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycUBC_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycUBC_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycVancouver_AltOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycVancouver_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycVancouver_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycVancouver_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycWestVancouver_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycWestVancouver_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycWestVancouver_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycWhiteRock_AltOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycWhiteRock_DesOff" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }
        case "layer_cycWhiteRock_DesOn" : { lineWidth=4; lineColor="#35962B"; lineOpacity=0.9; break; }

            
        
        default: { lineWidth=5; lineColor="#0000ff"; lineOpacity=0.6; break; }
        
    }

    // If control is checked, toggle map layer to turn on
    if( control.checked ) 
    {
        //alert("in polylines, gruop id is:" + groupId);

  	    //this will load the polylines into memory, and will toggle them on, if the checkbox is checked
	    regenerateGroupPolyLines( groupId, getLayerXMLPath(checkBoxName, optParameter1), lineWidth, lineColor, lineOpacity, optParameter1);
    } 
    else 
    {
        //toggle the group off the map
        toggleGroup(groupId, false);	   
    }  
}


//*******************************************************************************
// Function:     toggleMapMenuCheckbox
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 26 2006
//
// Description:  Toggle associated checkboxes on map menu
//               to turn on/off based on the checkbox being toggled.
//               (ie. multiple checkboxes representing same layer)
//
// Parameters:   control - Input checkbox control
//               optParameter1 - optional parameters used for filtering
//                               such as bus route id
//               userToggle - indicates whether user directly toggles on/off checkbox
// Returns:

// Calls:        
// Called By:    Input checkbox clicked for a map layer
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//  Michael Chu  Dec 01, 2006 Added abiltiy to toggle grid checkboxes and vice versa.
//*******************************************************************************
function toggleMapMenuCheckbox( control, optParameter1, userToggle ){

    // check box name 
    var checkBoxName = control.id;

	// Special Case for Bus Routes
	var specialChkBoxName = "";
	specialChkBoxName = checkBoxName.substring(0,25);
	if (specialChkBoxName == "chk_TRA_Public_Polyline_M")
	    checkBoxName = specialChkBoxName;


    // Toggle on or off the associated checkboxes representing the same layers
        
        switch( checkBoxName ) 
        {
                    
            // Event Menu Checkboxes
            case "chk_EV_CurInc" : {
            
                var cbx = document.getElementById( "chk_ROD_CurInc" );
                cbx.checked = control.checked;
                
                var cbx = document.getElementById( "chk_EV_CurInc_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                cbx = null;
                break; 
            }
            case "chk_EV_CurCon" :  {
            
                var cbx = document.getElementById( "chk_ROD_CurCon" );
                cbx.checked = control.checked;
                
                var cbx = document.getElementById( "chk_EV_CurCon_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                cbx = null;
                break; 
            }
            case "chk_EV_CurEv" : {
                
                var cbx = document.getElementById( "chk_ROD_CurEvnt" );
                cbx.checked = control.checked;
                
                var cbx = document.getElementById( "chk_EV_CurEv_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                 cbx = null;   
                break; 
            }
            case "chk_EV_FutCon" :  {
                
                var cbx = document.getElementById( "chk_EV_FutCon_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                cbx = null;
                break; 
            }
            case "chk_EV_FutEv" : {
                
                var cbx = document.getElementById( "chk_EV_FutEv_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                cbx = null;
                break; 
            }
            case "chk_EV_FutSrvc" : {
                
                var cbx = document.getElementById( "chk_EV_FutSrvc_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                 cbx = null;   
                break; 
            }

            // Camera Menu Checkboxes
            case "chk_CAM_Border" : {
            
                var cbx = document.getElementById( "chk_CAM_Border_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                cbx = null;
                break; 
            }
            case "chk_CAM_TrafficInt" :  {
                
                var cbx = document.getElementById( "chk_CAM_TrafficInt_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                cbx = null;
                break; 
            }
            case "chk_CAM_TrafficHigh" : {
                
                var cbx = document.getElementById( "chk_CAM_TrafficHigh_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                 cbx = null;   
                break; 
            }
            case "chk_CAM_Port" : {
                
                var cbx = document.getElementById( "chk_CAM_Port_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                cbx = null;
                break; 
            }
            
            // Weather Layer
            // - there are no associated checkboxes for cameras
            
            
            // Road Menu Checkboxes
            case "chk_ROD_CurInc" : {
            
                var cbx = document.getElementById( "chk_EV_CurInc" );
                cbx.checked = control.checked;
                
                var cbx = document.getElementById( "chk_EV_CurInc_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                cbx = null;
                break; 
            }
            case "chk_ROD_CurCon" :  {
            
                var cbx = document.getElementById( "chk_EV_CurCon" );
                cbx.checked = control.checked;
                
                var cbx = document.getElementById( "chk_EV_CurCon_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                cbx = null;
                break; 
            }
            case "chk_ROD_CurEvnt" : {
            
                var cbx = document.getElementById( "chk_EV_CurEv" );
                cbx.checked = control.checked;
                
                var cbx = document.getElementById( "chk_EV_CurEv_Grid" );
                if (cbx != null)
                {
                    cbx.checked = control.checked;
                    if (userToggle == true)
                        LoadGridData();    // reload grid results
                }
                cbx = null;
                break; 
            }

            case "chk_ROD_Border" : {
            
                var cbx = document.getElementById( "chk_COM_Border" );
                cbx.checked = control.checked;
                break; 
            }

            case "chk_ROD_Parking" : {
            
                var cbx = document.getElementById( "chk_TRA_Parking" );
                cbx.checked = control.checked;
                cbx = null;
                break; 
            }

            case "chk_ROD_Albion" : {
            
                var cbx = document.getElementById( "chk_MA_Albion" );
                cbx.checked = control.checked;
                cbx = null;break; 
            }

            
            // Transit Layers

            case "chk_TRA_Parking" : {
            
                var cbx = document.getElementById( "chk_ROD_Parking" );
                cbx.checked = control.checked;
                cbx = null;break; 
            }

            case "chk_TRA_ExpoLine" : {
            
                var cbx = document.getElementById( "chk_RAIL_ExpoLine" );
                cbx.checked = control.checked;
                cbx = null;break; 
            }
            case "chk_TRA_MilLine" :  {
            
                var cbx = document.getElementById( "chk_RAIL_MilLine" );
                cbx.checked = control.checked;
                cbx = null;break; 
            }
            case "chk_TRA_WstCstExpr" : {
                
                var cbx = document.getElementById( "chk_RAIL_WstCstExpr" );
                cbx.checked = control.checked;
                cbx = null;break; 
            }    
        

            case "chk_TRA_ViaRail" :  {
            
                var cbx = document.getElementById( "chk_RAIL_ViaRail" );
                cbx.checked = control.checked;
                cbx = null;break; 
            }
            case "chk_TRA_Amtrak" : {
                
                var cbx = document.getElementById( "chk_RAIL_Amtrak" );
                cbx.checked = control.checked;
                cbx = null;break; 
            }    

            case "chk_TRA_BCFerries" : {
                
                var cbx = document.getElementById( "chk_COM_BCFerries" );
                cbx.checked = control.checked;

                cbx = document.getElementById( "chk_MA_BCFerries" );
                cbx.checked = control.checked;
                cbx = null;break; 
                
            }    

            case "chk_TRA_IntAir" : {
                
                var cbx = document.getElementById( "chk_AIR_IntAir" );
                cbx.checked = control.checked;
cbx = null;
                break; 

            }    

            case "chk_TRA_RegAir" : {
                
                var cbx = document.getElementById( "chk_AIR_RegAir" );
                cbx.checked = control.checked;
cbx = null;
                var cbx2 = document.getElementById( "chk_COM_RegAir" );
                cbx2.checked = control.checked;
cbx2 = null;
                break; 

            }    


            case "chk_TRA_SeaBus" : {
                
                var cbx = document.getElementById( "chk_MA_SeaBus" );
                cbx.checked = control.checked;
cbx = null;
                break; 

            }    

            //Commercial layers
            case "chk_COM_Border" : {
                
                var cbx = document.getElementById( "chk_ROD_Border" );
                cbx.checked = control.checked;
                cbx = null;break; 
            }    

            case "chk_COM_BCFerries" : {
                
                var cbx = document.getElementById( "chk_TRA_BCFerries" );
                cbx.checked = control.checked;              
                cbx = null;
                var cbx2 = document.getElementById( "chk_MA_BCFerries" );
                cbx2.checked = control.checked;
                cbx2 = null;break; 

            }    

            case "chk_COM_IntAir" : {
                
                var cbx = document.getElementById( "chk_AIR_IntAir" );
                cbx.checked = control.checked;
                cbx = null;

                var cbx2 = document.getElementById( "chk_TRA_IntAir" );
                cbx2.checked = control.checked;

                cbx2 = null;
                break; 

            }    

            case "chk_COM_RegAir" : {
                
              var cbx = document.getElementById( "chk_AIR_RegAir" );
                cbx.checked = control.checked;
                cbx = null;

              var cbx2 = document.getElementById( "chk_TRA_RegAir" );
                cbx2.checked = control.checked;
            cbx2 = null;
                break; 

            }    

            // Rail Layers        
            case "chk_RAIL_ExpoLine" : {
            
                var cbx = document.getElementById( "chk_TRA_ExpoLine" );
                cbx.checked = control.checked;
                cbx = null;
                break; 
            }
            case "chk_RAIL_MilLine" :  {
            
                var cbx = document.getElementById( "chk_TRA_MilLine" );
                cbx.checked = control.checked;
                cbx = null;
                break; 
            }
            case "chk_RAIL_WstCstExpr" : {
                
                var cbx = document.getElementById( "chk_TRA_WstCstExpr" );
                cbx.checked = control.checked;
                cbx = null;
                break; 
            }            

            case "chk_RAIL_ViaRail" :  {
            
                var cbx = document.getElementById( "chk_TRA_ViaRail" );
                cbx.checked = control.checked;
               cbx = null;
             break; 
            }
            case "chk_RAIL_Amtrak" : { 
                
                var cbx = document.getElementById( "chk_TRA_Amtrak" );
                cbx.checked = control.checked;
               cbx = null;
                break; 
            }    


        // Air layers
        
                case "chk_AIR_IntAir" : {
                
                var cbx = document.getElementById( "chk_COM_IntAir" );
                cbx.checked = control.checked;
                cbx = null;


                var cbx2 = document.getElementById( "chk_TRA_IntAir" );
                cbx2.checked = control.checked;
                cbx2 = null;
                break; 

            }    

            case "chk_AIR_RegAir" : {
                
                var cbx = document.getElementById( "chk_COM_RegAir" );
                cbx.checked = control.checked;
                cbx = null;                
                
                var cbx2 = document.getElementById( "chk_TRA_RegAir" );
                cbx2.checked = control.checked;
                cbx2 = null;
                break;

            }    


            // Marine layers

            case "chk_MA_Albion" : {
            
                var cbx = document.getElementById( "chk_ROD_Albion" );
                cbx.checked = control.checked;
                cbx = null;   
                break; 
            }
            
            
            case "chk_MA_BCFerries" : {
                
                var cbx = document.getElementById( "chk_COM_BCFerries" );
                cbx.checked = control.checked;
               cbx = null;   
               
                var cbx2 = document.getElementById( "chk_TRA_BCFerries" );
                cbx2.checked = control.checked;
                cbx2 = null;   
                break; 
                
            }    

            case "chk_MA_SeaBus" : {
                
                var cbx = document.getElementById( "chk_TRA_SeaBus" );
                cbx.checked = control.checked;
                cbx = null;   
                break; 

            }                


		    // Bus Route grid checkboxes
            case "chk_TRA_Public_Polyline_M" : {
                var cbx = document.getElementById( "chk_TRA_Public_Polyline_" + optParameter1 );
                
                if (cbx != null) // make sure the checkbox exists
                    cbx.checked = control.checked; // this would always be unchecked in the bus routes grid 1 case scenario
            }

            /*****************************************************************/
            // The following action will originate from checkboxes on the grids.
            // The grid will be reloaded eventually, so there is no need to call
            // LoadGridData() function here.

            // Event Checkboxes on Grid
            case "chk_EV_CurInc_Grid" : {
            
                var cbx = document.getElementById( "chk_ROD_CurInc" );
                cbx.checked = control.checked;
                cbx = null; 
                
                var cbx = document.getElementById( "chk_EV_CurInc" );
                cbx.checked = control.checked;
                cbx = null; 
                break; 
            }
            case "chk_EV_CurCon_Grid" :  {
            
                var cbx = document.getElementById( "chk_ROD_CurCon" );
                cbx.checked = control.checked;
                cbx = null; 
                
                var cbx = document.getElementById( "chk_EV_CurCon" );
                cbx.checked = control.checked;
                
                cbx = null;                 
                break; 
            }
            case "chk_EV_CurEv_Grid" : {
                
                var cbx = document.getElementById( "chk_ROD_CurEvnt" );
                cbx.checked = control.checked;

                cbx = null;                 
                var cbx = document.getElementById( "chk_EV_CurEv" );
                cbx.checked = control.checked;
                cbx = null;                                     
                    
                break; 
            }
            case "chk_EV_FutCon_Grid" :  {
                
                var cbx = document.getElementById( "chk_EV_FutCon" );
                cbx.checked = control.checked;
                cbx = null;                                                     
                break; 
            }
            case "chk_EV_FutEv_Grid" : {
                
                var cbx = document.getElementById( "chk_EV_FutEv" );
                cbx.checked = control.checked;
                                cbx = null;                                     
                break; 
            }
            case "chk_EV_FutSrvc_Grid" : {
                
                var cbx = document.getElementById( "chk_EV_FutSrvc" );
                cbx.checked = control.checked;
                                   cbx = null;                                      
                break; 
            }

            // Camera Checkboxes on Grid
            case "chk_CAM_Border_Grid" : {
            
                var cbx = document.getElementById( "chk_CAM_Border" );
                cbx.checked = control.checked;
                cbx = null;                                     
                break; 
            }
            case "chk_CAM_TrafficInt_Grid" :  {
                
                var cbx = document.getElementById( "chk_CAM_TrafficInt" );
                cbx.checked = control.checked;
                                cbx = null;                                     
                break; 
            }
            case "chk_CAM_TrafficHigh_Grid" : {
                
                var cbx = document.getElementById( "chk_CAM_TrafficHigh" );
                cbx.checked = control.checked;
                                   cbx = null;                                      
                break; 
            }
            case "chk_CAM_Port_Grid" : {
                
                var cbx = document.getElementById( "chk_CAM_Port" );
                cbx.checked = control.checked;
                                cbx = null;                                     
                break; 
            }

   		    default: break;

		}

}



//*******************************************************************************
// Function:     GetMapLayerCheckBoxName
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.7
// Date:         Sep 06, 2006
//
// Description:  The following function returns the name of the check box
//               that toggles the group input as parameter.
//
// Parameters:   GroupId - Layer group name
// Returns:      Returns the name of the check box to toggle on/off the layer 
//               on the map
// Calls:        
// Called By:    map.addGroupOverlays(), map.removeGroupOverlays()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function GetMapLayerCheckBoxName( groupId, optParameter1 ){


//alert("*NEW* group id is: " + groupId);
//alert("*NEW* opt parameter is: " + optParameter1);


    var transitMarkersLayerName;
    var transitPolyLinesLayerName;

    var highlightPublicPolyLinesLayerName;
    var highlightBlueBusPolyLinesLayerName;        
    
    //build the Transit marker layer name dynamically, if optional parameter is passed
    if (optParameter1 != null ){
    
        var highlightPublicTest;
        var highlightBlueBusTest;        
        var highlightBoolean=false;
        
            // see if the layer name is for highlighting a public bus route
            highlightPublicTest = groupId.indexOf('TRA_Highlight_Public');   
            
            if (highlightPublicTest != -1){
                //we are highlighting a public bus route
                highlightPublicPolyLinesLayerName="layer_TRA_Highlight_Public_Polyline_" + optParameter1;
                highlightBoolean=true;
            }

            // see if the layer name is for highlighting a bluebus bus route
            highlightBlueBusTest = groupId.indexOf('TRA_Highlight_BlueBus');   
            
            if (highlightBlueBusTest != -1){
                //we are highlighting a bluebus route
                highlightBlueBusPolyLinesLayerName="layer_TRA_Highlight_BlueBus_Polyline_" + optParameter1;
                highlightBoolean=true;
            }

            //determine if we are drawing a regular bus route, or highlighting a route
            if (highlightBoolean == true){
                //do nothing, we already have the info 
            }  else{
                //we are not highlighting a route, draw the regular route
                transitMarkersLayerName = "layer_TRA_Public_Marker_" + optParameter1;
                transitPolyLinesLayerName = "layer_TRA_Public_Polyline_" + optParameter1;
            }
    }

	
	var checkboxName = "";
	switch( groupId ) {
	
	 //this is the dynamic transit markers layer
      case transitMarkersLayerName: { checkboxName="chk_TRA_Public_Marker_" + optParameter1; break;  } 
      case transitPolyLinesLayerName: { checkboxName="chk_TRA_Public_Polyline_" + optParameter1; break;  } 

	 //this is the dynamic transit markers layer
      case highlightPublicPolyLinesLayerName: { checkboxName="chk_TRA_Highlight_Public_" + optParameter1; break;  } 
      case highlightBlueBusPolyLinesLayerName: { checkboxName="chk_TRA_Highlight_BlueBus_" + optParameter1; break;  } 


        //Events layers
	    case "layer_CurInc" : { checkboxName =  "chk_EV_CurInc"; break; } 	
	    case "layer_CurCon" : { checkboxName =  "chk_EV_CurCon"; break; } 	
	    case "layer_CurEv" : { checkboxName =  "chk_EV_CurEv"; break; } 

        //Cameras layers       
	    
        //Weather layers
        
        //Roads layers
	    case "layer_Border" : { checkboxName =  "chk_ROD_Border"; break; } 	
	    
	    //brian US border testing ... do we need this ..
	    case "layer_USBorder" : { checkboxName =  "chk_ROD_USBorder"; break; } 	
	    
	    case "layer_Albion" : { checkboxName =  "chk_ROD_Albion"; break; } 		    
	    
        
        //Transit layers
	    case "layer_Parking" : { checkboxName =  "chk_TRA_Parking"; break; } 		    
	    case "layer_BCFerries" : { checkboxName =  "chk_TRA_BCFerries"; break; } 		    	    
        case "layer_TRA_SeaBus_Polyline" : { checkboxName =  "chk_TRA_SeaBus"; break; }
        case "layer_TRA_SeaBus_Marker" : { checkboxName =  "chk_TRA_SeaBus"; break; }

//bus_test
        case "layer_Test_Route73Polyline" : { checkboxName =  "chk_Test_Route73PolyMarkers"; break; }
        case "layer_Test_Route73Markers" : { checkboxName =  "chk_Test_Route73PolyMarkers"; break; }
        
                
        case "layer_TRA_Boundaries_Polyline" : { checkboxName =  "chk_TRA_Boundaries"; break; }
        case "layer_TRA_Boundaries_Marker" : { checkboxName =  "chk_TRA_Boundaries"; break; }

	    case "layer_ExpoLine_Polyline" : { checkboxName =  "chk_TRA_ExpoLine"; break; } 	
	    case "layer_ExpoLine_Marker" : { checkboxName =  "chk_TRA_ExpoLine"; break; } 	
        
        case "layer_MilLine_Polyline" : { checkboxName =  "chk_TRA_MilLine"; break; } 	
        case "layer_MilLine_Marker" : { checkboxName =  "chk_TRA_MilLine"; break; } 	


            //Public Bus Routes
	    
	    	    	    
        //West Van Blue Bus Routes
	            

        //All other transit layers
	    

        //Commercial layers
	    
        
        //Marine layers
	    

        //Air layers
	    
	    case "layer_IntAir" : { checkboxName =  "chk_AIR_IntAir"; break; } 		    	    	    
	    case "layer_RegAir" : { checkboxName =  "chk_AIR_RegAir"; break; } 		    	    	    	    
	    
        //Rail layers
//	    case "layer_ExpoLine_Polyline" : { checkboxName =  "chk_RAIL_ExpoLine"; break; } 	
//	    case "layer_ExpoLine_Marker" : { checkboxName =  "chk_RAIL_ExpoLine"; break; } 	
        
//        case "layer_MilLine_Polyline" : { checkboxName =  "chk_RAIL_MilLine"; break; } 	
  //      case "layer_MilLine_Marker" : { checkboxName =  "chk_RAIL_MilLine"; break; } 	

        case "layer_WstCstExpr_Polyline" : { checkboxName =  "chk_RAIL_WstCstExpr"; break; } 	
        case "layer_WstCstExpr_Marker" : { checkboxName =  "chk_RAIL_WstCstExpr"; break; } 	
	    
        case "layer_ViaRail" : { checkboxName =  "chk_RAIL_ViaRail"; break; } 	
        case "layer_Amtrak" : { checkboxName =  "chk_RAIL_Amtrak"; break; } 	

	    
       //Cycling layers
        case "layer_BusRouteTest_Marker" : { checkboxName =  "chk_BusRouteTest"; break; } 	        
        case "layer_BusRouteTest_Polyline" : { checkboxName =  "chk_BusRouteTest"; break; } 	                
        
   
	    // TODO: Might need to take out the following if the ALL layer is not needed
			case "layer_EventsReal": {
				checkboxName = "chkEvents";
				break;
			} 
			case "layer_CamerasReal": {
			    checkboxName = "chkRealCameras";
				break;
			} 
			
			
			// The default case is useful when the layer is controlled
			// by only one checkbox and the layer name starts with "layer_".
			default: {
			    
			    var index = groupId.indexOf("layer_");
                var len = groupId.length;
                
                // if it exists
                if (index > -1)
                {
                    checkboxName = "chk_" + groupId.substring(6, len);
                }
                else 
                    checkboxName = null;
			    
			    break;
            }
		}
    
    return checkboxName;    
}


//*******************************************************************************
// Function:     GetCheckBoxMapLayerName
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.2
// Date:         Sep 06, 2006
//
// Description:  The following function returns the name of the check box
//               that toggles the group input as parameter.
//
// Parameters:   GroupId - Layer group name
//               optParameter1 - optional parameters used for filtering
//               such as bus route id
// Returns:      Returns the name of the check box to toggle on/off the layer 
//               on the map
// Calls:        
// Called By:    map.addGroupOverlays(), map.removeGroupOverlays()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function GetCheckBoxMapLayerName(checkboxName, optParameter1){

    //alert("1 in get checkbox layer name here, checkbox name is:" + checkboxName );
    
    // All layers controlled by the checkbox
	var groupIds = [];
	
	// Special Case for Public Bus Routes Markers
	var specialGroupId = "";
	specialGroupId = checkboxName.substring(0,21);
	if (specialGroupId == "chk_TRA_Public_Marker")
	    checkboxName = specialGroupId;

    // Special Case for Public Bus Routes polylines
	specialGroupId = "";
	specialGroupId = checkboxName.substring(0,23);
	if (specialGroupId == "chk_TRA_Public_Polyline")
	    checkboxName = specialGroupId;
	
	// Special Case for highlighting a Public Bus Routes
	specialGroupId = "";	
	specialGroupId = checkboxName.substring(0,24);
	if (specialGroupId == "chk_TRA_Highlight_Public")
	    checkboxName = specialGroupId;
	
	
	switch( checkboxName ) {

        //Events layers
	    case "chk_EV_CurInc" : 
	    case "chk_ROD_CurInc" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CurInc";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        } 	
	    case "chk_EV_CurCon" : 
	    case "chk_ROD_CurCon" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CurCon";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        } 	
	    case "chk_EV_CurEv" : 
	    case "chk_ROD_CurEvnt" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CurEv";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        }
	    case "chk_EV_FutCon" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_EV_FutCon";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        }
        case "chk_EV_FutEv" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_EV_FutEv";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        }
        case "chk_EV_FutSrvc" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_EV_FutSrvc";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        }    
            
        // Camera Layers
        case "chk_CAM_Border" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CAM_Border";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        }
        case "chk_CAM_TrafficInt" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CAM_TrafficInt";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        }
        case "chk_CAM_TrafficHigh" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CAM_TrafficHigh";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        }
        case "chk_CAM_Port" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CAM_Port";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        }

        //Weather layers
        case "chk_Weather" : { 
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Weather";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
        }

        
        
        //Roads layers
	    case "chk_MA_Albion" : 
	    case "chk_ROD_Albion" : { 
	        
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Albion";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }


	    case "chk_ROD_HwaySigns" : { 
	        
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_ROD_HwaySigns";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
	    //TODO:Congestion layer 	
	    case "chk_ROD_Cong" : { 
	        
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_ROD_Cong";
	        groupIds[0]["LayerType"] = "Polyline";
	        
	        break; 
	    } 
	    case "chk_ROD_Border" : 
	    case "chk_COM_Border" : { 
	        
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Border";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    } 	
	    
	    case "chk_ROD_USBorder" : { 
	        
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_USBorder";
	        groupIds[0]["LayerType"] = "Marker";	        
	        break; 
	    } 	

	    case "chk_ROD_FacStatus" : { 
	        
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_ROD_FacStatus";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }     

	    case "chk_ROD_Parking" : 
	    case "chk_TRA_Parking" : {
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Parking";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }	    

	    case "chk_ROD_Landmarks" : {
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_ROD_Landmarks";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
	    case "chk_ROD_NonKeyLandmarks" : {
	        var groupId = []; 
	        groupId["LayerName"] = "layer_ROD_NonKeyLandmarks";
	        groupId["LayerType"] = "Marker";
	        groupIds[0] = groupId;
	        break; 
	    }	

	    case "chk_ROD_FacStatus" : {
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_ROD_FacStatus";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }


        //Transit layers

        case "chk_TRA_Public_Marker" : {
	        
	        var groupId = []; 
	        groupId["LayerName"] = "layer_TRA_Public_Marker_" + optParameter1;
	        groupId["LayerType"] = "Marker";
	        groupIds[0] = groupId;	        
	        break; 
	    }
        
        case "chk_TRA_Public_Polyline" : {

	        var groupId = []; 
	        groupId["LayerName"] = "layer_TRA_Public_Polyline_" + optParameter1;
	        groupId["LayerType"] = "Polyline";
	        groupIds[0] = groupId;
	        break;
	    }

        //Transit layers
        case "chk_TRA_Highlight_Public" : {

	        var groupId = []; 
	        groupId["LayerName"] = "layer_TRA_Highlight_Public_Polyline_" + optParameter1;
	        groupId["LayerType"] = "Polyline";
	        groupIds[0] = groupId;
	        
	        break; 
	    }
	    	 
        case "chk_TRA_Highlight_BlueBus" : {

	        var groupId = []; 
	        groupId["LayerName"] = "layer_TRA_Highlight_BlueBus_Polyline_" + optParameter1;
	        groupId["LayerType"] = "Polyline";
	        groupIds[0] = groupId;
	        
	        break; 
	    }

	    case "chk_TRA_BlueBus" : {
	    
	        var groupId = []; 
	        groupId["LayerName"] = "layer_TRA_BlueBus_Poly_" + optParameter1;
	        groupId["LayerType"] = "Polyline";
	        groupIds[0] = groupId;
	        
	        var groupId2 = []; 
	        groupId2["LayerName"] = "layer_TRA_BlueBus_Marker_" + optParameter1;
	        groupId2["LayerType"] = "Marker";
	        groupIds[1] = groupId2;

	        break; 
	    }
	    case "chk_TRA_Exch" : {
	    
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_TRA_Exch";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }	   
	    
	    // Parking - Please see above in section Roads layers
	    
	    case "chk_TRA_ExpoLine" : 
        case "chk_RAIL_ExpoLine" : { 
        
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_ExpoLine_Polyline";
	        groupIds[0]["LayerType"] = "Polyline";

            groupIds[1] = [];
	        groupIds[1]["LayerName"] = "layer_ExpoLine_Marker";
	        groupIds[1]["LayerType"] = "Marker";

	        
	        break; 
	    }	    
        case "chk_TRA_MilLine" : 
        case "chk_RAIL_MilLine" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_MilLine_Polyline";
	        groupIds[0]["LayerType"] = "Polyline";

            groupIds[1] = [];
	        groupIds[1]["LayerName"] = "layer_MilLine_Marker";
	        groupIds[1]["LayerType"] = "Marker";

	        
	        break; 
	    }	    
        case "chk_TRA_WstCstExpr" : 
        case "chk_RAIL_WstCstExpr" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_WstCstExpr_Polyline";
	        groupIds[0]["LayerType"] = "Polyline";
	        
            groupIds[1] = [];
	        groupIds[1]["LayerName"] = "layer_WstCstExpr_Marker";
	        groupIds[1]["LayerType"] = "Marker";

	        break; 
	    }	
	    
	    //Mockup layers
        case "chk_MA_SeaBus" :  
	    case "chk_TRA_SeaBus" : { 
	    
	        var groupId = []; 
	        groupId["LayerName"] = "layer_TRA_SeaBus_Polyline";
	        groupId["LayerType"] = "Polyline";
	        groupIds[0] = groupId;
	        
	        var groupId2 = []; 
	        groupId2["LayerName"] = "layer_TRA_SeaBus_Marker";
	        groupId2["LayerType"] = "Marker";
	        groupIds[1] = groupId2;
	        
	        break; 
        }

	    case "chk_TRA_Boundaries" : { 
	    
	        var groupId = []; 
	        groupId["LayerName"] = "layer_TRA_Boundaries_Polyline";
	        groupId["LayerType"] = "Polyline";
	        groupIds[0] = groupId;
	        
	        var groupId2 = []; 
	        groupId2["LayerName"] = "layer_TRA_Boundaries_Marker";
	        groupId2["LayerType"] = "Marker";
	        groupIds[1] = groupId2;

	        break; 
        }

        case "chk_TRA_Greyhound" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_TRA_Greyhound";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }	

	    case "chk_MA_BCFerries" : 
	    case "chk_TRA_BCFerries" : 
	    case "chk_COM_BCFerries" : {
	        
	        groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_BCFerries";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }	    	    	    
        case "chk_TRA_IntAir" :
        case "chk_COM_IntAir" : 
        case "chk_AIR_IntAir" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_IntAir";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }	   
        case "chk_TRA_RegAir" :
        case "chk_COM_RegAir" : 
        case "chk_AIR_RegAir" : { 
        
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_RegAir";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }    
        case "chk_TRA_ViaRail" : 
        case "chk_RAIL_ViaRail" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_ViaRail";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }	    
        case "chk_TRA_Amtrak" : 
        case "chk_RAIL_Amtrak" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Amtrak";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }	    
        	       
        
        //Commercial layers
        case "chk_COM_Weigh" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_COM_Weigh";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }	
	    // Border - Please see above in section Roads layers
	    // BCFerries - Please see above in section Transit layers
	    // IntAir - Please see above in section Transit layers
	    // RegAir - Please see above in section Transit layers
	    case "chk_COM_TruckRoute" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_COM_TruckRoute";
	        groupIds[0]["LayerType"] = "Polyline";
	        
	        break; 
	    }
	    case "chk_COM_DangGoods" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_COM_DangGoods";
	        groupIds[0]["LayerType"] = "Polyline";
	        
	        break; 
	    }
	    case "chk_COM_EmerResp" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_COM_EmerResp";
	        groupIds[0]["LayerType"] = "Polyline";
	        
	        break; 
	    }
	    case "chk_COM_Restrictions" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_COM_Restrictions";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
        
        // Marine Layers
        case "chk_MA_CruiseLines" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_MA_CruiseLines";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
	    case "chk_MA_Ports" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_MA_Ports";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
	    case "chk_MA_CustomEntry" : {             
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_MA_CustomEntry";
	        groupIds[0]["LayerType"] = "Marker";	        
	        break; 
	    }

	    case "chk_MA_FalseCreek" : {             
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_MA_FalseCreek";
	        groupIds[0]["LayerType"] = "Marker";	        
	        break; 
	    }

	    case "chk_MA_MarineAccess" : {             
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_MA_MarineAccess";
	        groupIds[0]["LayerType"] = "Marker";	        
	        break; 
	    }
        
        // Air Layers
        // IntAir - Please see above in section Transit layers
	    // RegAir - Please see above in section Transit layers
        case "chk_AIR_HrbrAir" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_AIR_HrbrAir";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
	    case "chk_AIR_WestCoastAir" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_AIR_WestCoastAir";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
	    case "chk_AIR_Helijet" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_AIR_Helijet";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
        
        // Rail Layers
        case "chk_RAIL_Railroads" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_RAIL_Railroads";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
        
        // chk_RAIL_ExpoLine - Please see above in section Transit layers
        // chk_RAIL_MilLine - Please see above in section Transit layers
        // chk_RAIL_WstCstExpr - Please see above in section Transit layers
        // chk_RAIL_ViaRail - Please see above in section Transit layers
        
        case "chk_RAIL_RockyMtn" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_RAIL_RockyMtn";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
        // chk_RAIL_Amtrak - Please see above in section Transit layers
        case "chk_RAIL_RailAccess" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_RAIL_RailAccess";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }
            
        // Cycling Layer
        case "chk_CYC_DesOnStreet" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CYC_DesOnStreet";
	        groupIds[0]["LayerType"] = "Polyline";
	        
	        break; 
	    }

        // Cycling Layer
        case "chk_CYC_DesOffStreet" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CYC_DesOffStreet";
	        groupIds[0]["LayerType"] = "Polyline";
	        
	        break; 
	    }

        // Cycling Layer
        case "chk_CYC_AltOnStreet" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CYC_AltOnStreet";
	        groupIds[0]["LayerType"] = "Polyline";
	        
	        break; 
	    }
	    
        // Cycling Layer
        case "chk_CYC_AltOffStreet" : { 
            
            groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CYC_AltOffStreet";
	        groupIds[0]["LayerType"] = "Polyline";
	        
	        break; 
	    }
	    	    
	    case "chk_BusRouteTest" : { 
	    
	        var groupId = []; 
	        groupId["LayerName"] = "layer_BusRouteTest_Polyline";
	        groupId["LayerType"] = "Polyline";
	        groupIds[0] = groupId;
	        
	        var groupId2 = []; 
	        groupId2["LayerName"] = "layer_BusRouteTest_Marker";
	        groupId2["LayerType"] = "Marker";
	        groupIds[1] = groupId2;
	        
	        break; 
        }

   
	    // TODO: Might need to take out the following if the ALL layer is not needed
	    case "chkEvents": {
			
			groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_EventsReal";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }	   
		case "chkRealCameras": {
			
			groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_CamerasReal";
	        groupIds[0]["LayerType"] = "Marker";
	        
	        break; 
	    }	   

// These are the test bus route layers
//bus_test
		case "chk_Test_Route9Poly": {
			groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Test_Route9Poly";
	        groupIds[0]["LayerType"] = "Polyline";
	        break; 
	    }

		case "chk_Test_Route9Markers": {
			groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Test_Route9Markers";
	        groupIds[0]["LayerType"] = "Marker";
	        break; 
	    }

		case "chk_Test_Route218Poly": {
			groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Test_Route218Poly";
	        groupIds[0]["LayerType"] = "Polyline";
	        break; 
	    }

		case "chk_Test_Route218Markers": {
			groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Test_Route218Markers";
	        groupIds[0]["LayerType"] = "Marker";
	        break; 
	    }

		case "chk_Test_PerfTestPoly": {
			groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Test_PerfTestPoly";
	        groupIds[0]["LayerType"] = "Polyline";
	        break; 
	    }

		case "chk_Test_PerfTestMarkers": {
			groupIds[0] = [];
	        groupIds[0]["LayerName"] = "layer_Test_PerfTestMarkers";
	        groupIds[0]["LayerType"] = "Marker";
	        break; 
	    }

	    case "chk_Test_Route73PolyMarkers" : { 
	    
	        var groupId = []; 
	        groupId["LayerName"] = "layer_Test_Route73Polyline";
	        groupId["LayerType"] = "Polyline";
	        groupIds[0] = groupId;
	        
	        var groupId2 = []; 
	        groupId2["LayerName"] = "layer_Test_Route73Markers";
	        groupId2["LayerType"] = "Marker";
	        groupIds[1] = groupId2;
	        
	        break; 
        }

        //Truck routes
		case "chk_truckRouteAbbotsford": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteAbbotsford";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteAldergrove": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteAldergrove";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteBurnaby": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteBurnaby";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteCoquitlam": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteCoquitlam";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteDelta": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteDelta";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteFortLangley": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteFortLangley";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteMapleRidge": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteMapleRidge";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteMcMillanIslandIR": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteMcMillanIslandIR";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteMission": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteMission";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteNewWestminster": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteNewWestminster";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteNorthVancouver": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteNorthVancouver";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRoutePittMeadows": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRoutePittMeadows";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRoutePortCoquitlam": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRoutePortCoquitlam";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteRichmond": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteRichmond";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteSurrey": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteSurrey";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteUBC": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteUBC";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteVancouver": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteVancouver";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteWestVancouver": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteWestVancouver";  groupIds[0]["LayerType"] = "Polyline";   break;    }
		case "chk_truckRouteWhiteRock": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_truckRouteWhiteRock";  groupIds[0]["LayerType"] = "Polyline";   break;    }
    
        //Cycling routes
        case "chk_cycAbbotsford_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycAbbotsford_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycBelcarra_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycBelcarra_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycBelcarra_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycBelcarra_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycBurnaby_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycBurnaby_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycBurnaby_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycBurnaby_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycBurnaby_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycBurnaby_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycBurnaby_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycBurnaby_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycCoquitlam_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycCoquitlam_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycCoquitlam_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycCoquitlam_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycCoquitlam_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycCoquitlam_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycCoquitlam_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycCoquitlam_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycDelta_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycDelta_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycDelta_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycDelta_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycDelta_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycDelta_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycDelta_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycDelta_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycLangley_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycLangley_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycLangley_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycLangley_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycLangley_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycLangley_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycLangley_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycLangley_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycLionsBay_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycLionsBay_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycMapleRidge_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycMapleRidge_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycMapleRidge_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycMapleRidge_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycMapleRidge_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycMapleRidge_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycMapleRidge_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycMapleRidge_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }

        case "chk_cycNewWestminster_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycNewWestminster_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycNewWestminster_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycNewWestminster_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycNewWestminster_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycNewWestminster_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycNewWestminster_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycNewWestminster_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycNorthVancouver_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycNorthVancouver_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycNorthVancouver_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycNorthVancouver_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycNorthVancouver_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycNorthVancouver_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycNorthVancouver_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycNorthVancouver_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPittMeadows_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPittMeadows_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPittMeadows_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPittMeadows_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPittMeadows_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPittMeadows_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPittMeadows_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPittMeadows_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPortCoquitlam_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPortCoquitlam_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPortCoquitlam_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPortCoquitlam_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPortCoquitlam_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPortCoquitlam_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPortCoquitlam_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPortCoquitlam_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPortMoody_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPortMoody_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPortMoody_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPortMoody_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPortMoody_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPortMoody_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycPortMoody_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycPortMoody_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }

        case "chk_cycRichmond_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycRichmond_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycRichmond_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycRichmond_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycRichmond_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycRichmond_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycRichmond_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycRichmond_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycSurrey_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycSurrey_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycSurrey_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycSurrey_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycSurrey_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycSurrey_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycSurrey_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycSurrey_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycUBC_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycUBC_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycUBC_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycUBC_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycUBC_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycUBC_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycUBC_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycUBC_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycVancouver_AltOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycVancouver_AltOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycVancouver_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycVancouver_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycVancouver_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycVancouver_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycVancouver_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycVancouver_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycWestVancouver_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycWestVancouver_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycWestVancouver_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycWestVancouver_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycWestVancouver_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycWestVancouver_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycWhiteRock_AltOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycWhiteRock_AltOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycWhiteRock_DesOff": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycWhiteRock_DesOff";  groupIds[0]["LayerType"] = "Polyline";   break;    }
        case "chk_cycWhiteRock_DesOn": {	groupIds[0] = []; groupIds[0]["LayerName"] = "layer_cycWhiteRock_DesOn";  groupIds[0]["LayerType"] = "Polyline";   break;    }
	    	   
		default: {
            break;
        }	
         
	}

//alert("returned group ids is: " + groupIds[0]["LayerName"]);
//alert("returned group ids is: " + groupIds[1]["LayerName"]);
        
    return groupIds;
}


//*******************************************************************************
// Function:     InitializeDefaultMapLayers
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 26 2006
//
// Description:  Initialize map layers based on default or saved state 
//               based on current tab (ie. Motorists,
//               Transit, Cycling, Gateways, Visitors, or Commercial).
//               Default state is defined in this function for each tab.
//               Saved state is defined in a cookie for each tab.   
//
// Parameters:   
// Returns:
// Calls:        InitializeSavedCustomizedMapView(),
// Called By:    Load()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function InitializeDefaultMapLayers()
{
// Debug variable (set to 1 to debug)
var debug = 0;

    // get the layers saved for the specific tab it is on
    var activeTabLayers = GetSavedCheckboxNames();
        
    // if there is something stored previously in the cookie, 
    // split the values up, and toggle on the checkboxes
    if (activeTabLayers != null && activeTabLayers != ""){        
                
        // Load the map to saved/customized view    
        InitializeSavedCustomizedMapView();
           
    }else {
        
      
        // reload the map to default view, and not based on saved customized view
        InitializeDefaultMapView();

        if ( moz || op ) {
            //Reset the grid to the advisories tab
            TurnOnTab(document.getElementById('AdvisoriesTab'));	            
         }   

    }
    
}

//*******************************************************************************
// Function:     InitializeSavedCustomizedMapView
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 2.3
// Date:         Jan 29 2007
//
// Description:  Load the map to saved/customized view
//               based on current tab (ie. Motorists,
//               Transit, Cycling, Gateways, Visitors, or Commercial).
//               Saved state is defined in a cookie for each tab.   
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    Load()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function InitializeSavedCustomizedMapView()
{
    // get the layers saved for the specific tab it is on
    var activeTabLayers = GetSavedCheckboxNames();
    
    // if there is something stored previously in the cookie, 
    // split the values up, and toggle on the checkboxes
    if (activeTabLayers != null && activeTabLayers != ""){        
                
        var partialCookieArr = activeTabLayers.split( "," );
            
        for( var i=0; i<partialCookieArr.length-1; i++ ) 
        {
            // Retrieve checkbox name    
            var checkboxName = partialCookieArr[i];
        
            //toggle the saved checkbox on
            var cbx = document.getElementById( checkboxName );
            cbx.checked = true;
            toggleLayer( cbx );
                        cbx = null;
        }        
    }
}

//*******************************************************************************
// Function:     InitializeDefaultMapView
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 2.3
// Date:         Jan 29 2007
//
// Description:  Initialize map layers based on default state and
//               based on current tab (ie. Motorists,
//               Transit, Cycling, Gateways, Visitors, or Commercial).
//               Default state is defined in this function for each tab.
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    Load()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function InitializeDefaultMapView()
{
// Debug variable (set to 1 to debug)
var debug = 0;
   
    // Retrieve active tab cookie
    var activeTab = Get_Cookie('activeTab');

    switch( activeTab )     
    {
                    
        case "Motorists" : {
        
            // turn on default Events checkboxes and layers on map
            TurnOnDefaultEventsCheckboxesAndLayers();

            // turn on road congestions            
            var cbx = document.getElementById( "chk_ROD_Cong" );
            cbx.checked = true;
            toggleLayer( cbx );
            cbx = null;
            break;
        }
        case "Transit" : {


            var cbx = document.getElementById( "chk_EV_CurEv" );
            cbx.checked = true;
            toggleLayer( cbx );
            cbx = null;

            //turn off all the bus route layers as well
            //TurnOffAllExistingBusRouteLayers();

             //delete all active bus route cookies, so they do not persist between sessions
             //eraseCookie( activeBusRoutesCookieName );
            
           // Delete_Cookie( activeBusRoutesCookieName, '/', '' );

            //ToggleDefaultBusRoutesOnMap();
            //TurnOnActiveBusRoutes();

          //if ( moz || op ) {

                // turn on specific checkboxes and layers
//                var cbx = document.getElementById( "chk_TRA_Public_Polyline_162" );
  //              cbx.checked = true;
    //            toggleLayer( cbx, '162' );
      //          AddOrRemovePartialCookieValue(activeBusRoutesCookieName, '162', true);


                // turn on specific checkboxes and layers
        //        var cbx = document.getElementById( "chk_TRA_Public_Polyline_165" );
          //      cbx.checked = true;
            //    toggleLayer( cbx, '165' );
              //  AddOrRemovePartialCookieValue(activeBusRoutesCookieName, '165', true);
        

                // turn on specific checkboxes and layers
//                var cbx = document.getElementById( "chk_TRA_Public_Polyline_194" );
  //              cbx.checked = true;
    //            toggleLayer( cbx, '194' );
      //          AddOrRemovePartialCookieValue(activeBusRoutesCookieName, '194', true);

        //        TurnOnActiveBusRoutes();
            
          //  } else {

              //  ToggleDefaultBusRoutesOnMap();
                //TurnOnActiveBusRoutes();
            
//            }

            // turn on specific checkboxes and layers
//            var cbx = document.getElementById( "chk_EV_CurEv" );
  //          cbx.checked = true;
    //        toggleLayer( cbx );

      //      cbx = document.getElementById( "chk_TRA_WstCstExpr" );
        //    cbx.checked = true;
          //  toggleLayer( cbx );

//            cbx = document.getElementById( "chk_TRA_ExpoLine" );
  //          cbx.checked = true;
    //        toggleLayer( cbx );

      //      cbx = document.getElementById( "chk_TRA_MilLine" );
        //    cbx.checked = true;
          //  toggleLayer( cbx );
                
            // bus routes are initialized later on in the function.

            break; 
        }
        case "Cycling" : {

//                // turn on Cycling checkbox and layer
//                cbx = document.getElementById( "chk_CYC_DesOnStreet" );
//	            cbx.checked = true;
//                toggleLayer( cbx );
//            	
//    	        cbx = document.getElementById( "chk_CYC_DesOffStreet" );
//	            cbx.checked = true;
//                toggleLayer( cbx );
//            	
//    	        cbx = document.getElementById( "chk_CYC_AltOnStreet" );
//	            cbx.checked = true;
//                toggleLayer( cbx );
//            	
//    	        cbx = document.getElementById( "chk_CYC_AltOffStreet" );
//	            cbx.checked = true;
//                toggleLayer( cbx );
                
            break;
                
        }
        case "Gateways" : {
                
            // turn on specific checkboxes and layers
            var cbx = document.getElementById( "chk_AIR_IntAir" );
            cbx.checked = true;
            toggleLayer( cbx );
                
            cbx = document.getElementById( "chk_AIR_RegAir" );
            cbx.checked = true;
            toggleLayer( cbx );

            cbx = document.getElementById( "chk_COM_BCFerries" );
            cbx.checked = true;
            toggleLayer( cbx );

            cbx = document.getElementById( "chk_TRA_ViaRail" );
            cbx.checked = true;
            toggleLayer( cbx );

            cbx = document.getElementById( "chk_TRA_Amtrak" );
            cbx.checked = true;
            toggleLayer( cbx );
            cbx = null;
            break; 

        }
        case "Visitors" : {
            
            // turn on specific checkboxes and layers
            var cbx = document.getElementById( "chk_AIR_IntAir" );
            cbx.checked = true;
            toggleLayer( cbx );
                
            cbx = document.getElementById( "chk_AIR_RegAir" );
            cbx.checked = true;
            toggleLayer( cbx );

            cbx = document.getElementById( "chk_COM_BCFerries" );
            cbx.checked = true;
            toggleLayer( cbx );

            cbx = document.getElementById( "chk_TRA_ViaRail" );
            cbx.checked = true;
            toggleLayer( cbx );

            cbx = document.getElementById( "chk_TRA_Amtrak" );
            cbx.checked = true;
            toggleLayer( cbx );
                
            cbx = document.getElementById( "chk_ROD_Landmarks" );
            cbx.checked = true;
            toggleLayer( cbx );
                                cbx = null;
            break; 
        }
        case "Commercial" : {

            // turn on default Events checkboxes and layers on map
            TurnOnDefaultEventsCheckboxesAndLayers();
            
            break;                 
        }
        default: {
        
            break;
        }
                    
    }
    
    //SPECIAL CASE: Always initialize default bus routes
    // even when it is not on the bus route tab
    switch( activeTab )     
    {
                       
        case "Transit" : {

                // toggle on three bus routes as default layers for the 
                // Transit tab, they are Route Numbers: 97, 98, and 99. 
                
                //ToggleDefaultBusRoutesOnMap();

                //TurnOnActiveBusRoutes();

                break; 
        }
        default: {
        
            break;
        }
    }
    
    
    // set default map center and zoom level
    SetDefaultMapCenterAndZoomLevel();
    
}

//*******************************************************************************
// Function:     TurnOnDefaultEventsCheckboxesAndLayers
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 26 2006
//
// Description:  Turn on default Events checkboxes and layers
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function TurnOnDefaultEventsCheckboxesAndLayers()
{

    // turn on current incidents checkbox and layer
    var cbx = document.getElementById( "chk_EV_CurInc" );
    cbx.checked = true;
    toggleLayer( cbx );
            
    // turn on current constructions checkbox and layer
    var cbx = document.getElementById( "chk_EV_CurCon" );
    cbx.checked = true;
    toggleLayer( cbx );
            
    // turn on current events checkbox and layer
    var cbx = document.getElementById( "chk_EV_CurEv" );
    cbx.checked = true;
    toggleLayer( cbx );
                        cbx = null;
    // turn on future constructions checkbox and layer
    var cbx = document.getElementById( "chk_EV_FutCon" );
    cbx.checked = true;
    toggleLayer( cbx );
            
    // turn on future events checkbox and layer
    var cbx = document.getElementById( "chk_EV_FutEv" );
    cbx.checked = true;
    toggleLayer( cbx );
            
    // turn on future service checkbox and layer
    var cbx = document.getElementById( "chk_EV_FutSrvc" );
    cbx.checked = true;
    toggleLayer( cbx );
}


//*******************************************************************************
// Function:     TurnOnAllCamerasCheckboxesAndLayers
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 26 2006
//
// Description:  Turn on all Cameras checkboxes and layers
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function TurnOnAllCamerasCheckboxesAndLayers()
{
            
    // turn on current border cameras checkbox and layer
    var cbx = document.getElementById( "chk_CAM_Border" );
    cbx.checked = true;
    toggleLayer( cbx );
            
    // turn on current traffic-intersection cameras checkbox and layer
    var cbx = document.getElementById( "chk_CAM_TrafficInt" );
    cbx.checked = true;
    toggleLayer( cbx );
            
    // turn on current traffic-highway cameras checkbox and layer
    var cbx = document.getElementById( "chk_CAM_TrafficHigh" );
    cbx.checked = true;
    toggleLayer( cbx );
            
    // turn on current port cameras checkbox and layer
    var cbx = document.getElementById( "chk_CAM_Port" );
    cbx.checked = true;
    toggleLayer( cbx );
    
                cbx = null;
            
}

//*******************************************************************************
// Function:     TurnOnDefaultEventsCheckboxesAndLayersOnGrid
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 26 2006
//
// Description:  Turn on default Events checkboxes and layers
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function TurnOnDefaultEventsCheckboxesAndLayersOnGrid()
{

    // turn on current incidents checkbox and layer
    var cbx = document.getElementById( "chk_EV_CurInc_Grid" );
    cbx.checked = true;
    toggleMapMenuCheckbox(cbx, null, null);
            
    // turn on current constructions checkbox and layer
    var cbx = document.getElementById( "chk_EV_CurCon_Grid" );
    cbx.checked = true;
    toggleMapMenuCheckbox(cbx, null, null);
            
    // turn on current events checkbox and layer
    var cbx = document.getElementById( "chk_EV_CurEv_Grid" );
    cbx.checked = true;
    toggleMapMenuCheckbox(cbx, null, null);
    
                cbx = null;
            
//    // turn on future constructions checkbox and layer
//    var cbx = document.getElementById( "chk_EV_FutCon_Grid" );
//    cbx.checked = true;
//    toggleMapMenuCheckbox(cbx, null, null);
//            
//    // turn on future events checkbox and layer
//    var cbx = document.getElementById( "chk_EV_FutEv_Grid" );
//    cbx.checked = true;
//    toggleMapMenuCheckbox(cbx, null, null);
//            
//    // turn on future service checkbox and layer
//    var cbx = document.getElementById( "chk_EV_FutSrvc_Grid" );
//    cbx.checked = true;
//    toggleMapMenuCheckbox(cbx, null, null);
}


//*******************************************************************************
// Function:     TurnOnAllCamerasCheckboxesAndLayersOnGrid
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 26 2006
//
// Description:  Turn on all Cameras checkboxes and layers
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function TurnOnAllCamerasCheckboxesAndLayersOnGrid()
{
            
    // turn on current border cameras checkbox and layer
    var cbx = document.getElementById( "chk_CAM_Border_Grid" );
    cbx.checked = true;
    toggleMapMenuCheckbox(cbx, null, null);
            
    // turn on current traffic-intersection cameras checkbox and layer
    var cbx = document.getElementById( "chk_CAM_TrafficInt_Grid" );
    cbx.checked = true;
    toggleMapMenuCheckbox(cbx, null, null);
            
    // turn on current traffic-highway cameras checkbox and layer
    var cbx = document.getElementById( "chk_CAM_TrafficHigh_Grid" );
    cbx.checked = true;
    toggleMapMenuCheckbox(cbx, null, null);
            
    // turn on current port cameras checkbox and layer
    var cbx = document.getElementById( "chk_CAM_Port_Grid" );
    cbx.checked = true;
    toggleMapMenuCheckbox(cbx, null, null);
                cbx = null;
            
}

//*******************************************************************************
// Function:     toggleBoundaries
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.6
// Date:         Nov 6 2006
//
// Description:  Toggling the boundaries layer will also toggle on/off the border crossings, and 
//               BC Ferries layers
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function toggleBoundaries( control){

    // check box name representing the map layer
    var checkBoxName = control.id;
    var isChecked;    

    var cbx = document.getElementById( "chk_TRA_Boundaries" );
    
    //determine if we are turning on/off the boundaries layer
    if (cbx.checked){
        isChecked=true;
    } else {
        isChecked=false;
    }
    
    cbx.checked = isChecked;
    toggleLayer( cbx );

    var cbx2 = document.getElementById( "chk_ROD_Border" );
    cbx2.checked = isChecked;
    toggleLayer( cbx2 );

    var cbx3 = document.getElementById( "chk_TRA_BCFerries" );
    cbx3.checked = isChecked;
    toggleLayer( cbx3 );   
    
    var cbx4 = document.getElementById( "chk_AIR_IntAir" );
    cbx4.checked = isChecked;
    toggleLayer( cbx4 );   
    
        cbx = null;
    cbx2 = null;
    cbx3 = null;
    cbx4 = null;

}


function ResetPage2(){

    alert("is fullscreen?: " + isFullScreenMap);

    var activeRoutes = Get_Cookie( activeBusRoutesCookieName );      
    alert("active routes are :'" + activeRoutes + "'");    
    
    var activeRoutes2 = Get_Cookie( FSactiveBusRoutesCookieName );      
    alert("FSactive routes are :'" + activeRoutes2 + "'");     

    var activeRoutes3 = Get_Cookie( activeBusRoutesStopsCookieName );      
    alert("active stops are :'" + activeRoutes3 + "'");    
    
    var activeRoutes4 = Get_Cookie( FSactiveBusRoutesStopsCookieName );      
    alert("FSactive stops are :'" + activeRoutes4 + "'");     

}

//*******************************************************************************
// Function:     ResetPage
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 26 2006
//
// Description:  Resets the default map layers based on current tab (ie. Motorists,
//               Transit, Cycling, Gateways, Visitors, or Commercial).
//               It will first clear all the map layers and then initialize 
//               to default map view.
//
// Parameters:   
// Returns:
// Calls:        RemoveAllMapLayers(), InitializeDefaultMapView()
// Called By:    Click of toolbar button
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function ResetPage(){

    //reset functionality for Regular map
    if ( isFullScreenMap == false ){

        /*Note:  This used to be the old clear functionalitiy*/
        
        //turn off all bus routes
        TurnOffAllExistingBusRouteLayers();

        //delete all active bus route cookies
        Delete_Cookie( activeBusRoutesCookieName, '/', '' );
        Delete_Cookie( activeBusRoutesStopsCookieName, '/', '' );
        Delete_Cookie( highlightBusRouteCookieName, '/', '' );

        //delete the testing cookie message
	 Delete_Cookie( iMoveTestingCookieName, '/', '' );

      
        // Uncheck off all checkboxes and remove all layers from map
        RemoveAllMapLayers();

        //alert("done bus stuff");
        //alert("done initalize bus routes");

        //Reset the grid to the advisories tab
        TurnOnTab(document.getElementById('AdvisoriesTab'));	
        LoadFilterBarContentBasedOnXMLData('Events');                    

        //alert("done turning on tabs");

        //this will reset the page, based on the saved settings or defaults if there are no saved settings
        InitializeDefaultMapLayers();

        //alert("start initilalize");
        
        //do not recenter map on bus routes (transit tab)
        isRecenterBusRouteOnMap = false;

        //turn on any bus routes
        InitializeBusRouteCookies();

        //alert("done initilalize bu sroutes");

        TurnOnActiveBusRoutes();

        //alert("done turn on active routes");
        //recenter the map based on the saved settings if there are any
        //SetDefaultMapCenterAndZoomLevel();

        // show loading message
        showLoading();	
        
        // hide the loading message after 5 seconds
        window.setTimeout(hideLoading, 5000);   
        
        /*Note: END OF This used to be the old clear functionalitiy*/


    } else {
    //user has pressed the Reset button on the fullscreen map

        // show loading message
        showLoading();	
        
        // hide the loading message after 5 seconds
        window.setTimeout(hideLoading, 5000);   


        RemoveAllMapLayers();


                    //turn off all bus routes
                    TurnOffAllExistingBusRouteLayers();

                    //delete the full screen map cookies if there are any
                    Delete_Cookie( FSactiveBusRoutesCookieName, '/', '' );
                    Delete_Cookie( FShighlightBusRouteCookieName, '/', '' ); 
                    Delete_Cookie( FSactiveBusRoutesStopsCookieName, '/', '' ); 

                //reload the fullscreen map load function
                LoadFullScreenMapInfo();


                    //store the active bus route stops into temporary cookie
              //      var tempActiveBusRoutesCooke = Get_Cookie( activeBusRoutesCookieName );            
            //        if (tempActiveBusRoutesCooke != null){                
          //              var partialCookieArr = tempActiveBusRoutesCooke.split( "," );                
        //                for( var i=0; i<partialCookieArr.length-1; i++ )                 {
      //                      var routeId = partialCookieArr[i];            	                            
    //                       AddOrRemovePartialCookieValue(FSactiveBusRoutesCookieName, routeId, true);
  //                      }
//                    } 

        
             //loop through full screen cookie    
//            var fullScreenLayersCookie = Get_Cookie( activeFullScreenLayersCookieName );
  //          if (fullScreenLayersCookie != null){
    //            // split the cookie into individual routes
      //          var partialCookieArr = fullScreenLayersCookie.split( "," );
                
                //loop through each Route Id
//                for( var i=0; i<partialCookieArr.length-1; i++ ) 
  //              {
    //                var checkboxName = partialCookieArr[i];            	        
    	            //check off the saved checkboxes
    //	            cbx = document.getElementById( checkboxName );
    //	            cbx.checked = true;
    //	            toggleLayer( cbx );
      //          }
        //    }


            //turn back on the default bus routes if there are any
            //TurnOnFullScreenActiveBusRoutes(); 
            
    }  // end of fullscreen map reset functionality

}


//*******************************************************************************
// Function:     ClearPage
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 3.0
// Date:         Mar 7 2007
//
// Description:  "Clear Current Map View" will reset map to your SAVED settings
//               (or the default if there are no saved settings)
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    Click of toolbar button
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function ClearPage(){    

        /*NOTE:  This used to be the old clear functionality ...*/
        
        var confirmReset = confirm ("Clearing the page will clear all saved map settings, would you like to continue ?");

        if (confirmReset){

            //figure out which tab we are working on
            var activeTab = Get_Cookie( 'activeTab' );    

            //only delete all the cookie settings while on the regular map
            if ( isFullScreenMap == false ){
                
                    //update the appropriate cookie
                    switch( activeTab ) 
                    
                    {
              
                        case "Motorists" : {                        
                            //delete the pan + zoom cookies for the tab
                            Delete_Cookie( activeMotoristsLayersCookieName, '/', '' );
                            Delete_Cookie( MotoristsMapCenterCookieName, '/', '' );
                            Delete_Cookie( MotoristsZoomLevelCookieName, '/', '' );                 
                            Delete_Cookie( savedMotoristsBusRoutesCookieName, '/', '' );
                            Delete_Cookie( savedMotoristsBusRoutesStopsCookieName, '/', '' );
                            break; 
                        }
                        case "Transit" : {
                            //delete the pan + zoom cookies for the tab
                            Delete_Cookie( activeTransitLayersCookieName, '/', '' );
                            Delete_Cookie( TransitMapCenterCookieName, '/', '' );
                            Delete_Cookie( TransitZoomLevelCookieName, '/', '' );   
                            Delete_Cookie( savedTransitBusRoutesCookieName, '/', '' );
                            Delete_Cookie( savedTransitBusRoutesStopsCookieName, '/', '' );
                            break; 
                        }
                        case "Cycling" : {
                            //delete the pan + zoom cookies for the tab
                            Delete_Cookie( activeCyclingLayersCookieName, '/', '' );
                            Delete_Cookie( CyclingMapCenterCookieName, '/', '' );
                            Delete_Cookie( CyclingZoomLevelCookieName, '/', '' );                                
                            Delete_Cookie( savedCyclingBusRoutesCookieName, '/', '' );
                            Delete_Cookie( savedCyclingBusRoutesStopsCookieName, '/', '' );

                            break; 
                        }
                        case "Gateways" : {
                            //delete the pan + zoom cookies for the tab
                            Delete_Cookie( activeGatewaysLayersCookieName, '/', '' );
                            Delete_Cookie( GatewaysMapCenterCookieName, '/', '' );
                            Delete_Cookie( GatewaysZoomLevelCookieName, '/', '' );                                
                            Delete_Cookie( savedGatewaysBusRoutesCookieName, '/', '' );
                            Delete_Cookie( savedGatewaysBusRoutesStopsCookieName, '/', '' );

                            break; 
                        }
                        case "Visitors" : {
                            //delete the pan + zoom cookies for the tab
                            Delete_Cookie( activeVisitorsLayersCookieName, '/', '' );
                            Delete_Cookie( VisitorsMapCenterCookieName, '/', '' );
                            Delete_Cookie( VisitorsZoomLevelCookieName, '/', '' );                
                            Delete_Cookie( savedVisitorsBusRoutesCookieName, '/', '' );
                            Delete_Cookie( savedVisitorsBusRoutesStopsCookieName, '/', '' );

                            break; 
                        }
                        case "Commercial" : {
                            //delete the pan + zoom cookies for the tab
                            Delete_Cookie( activeCommericalsLayersCookieName, '/', '' );
                            Delete_Cookie( CommercialMapCenterCookieName, '/', '' );
                            Delete_Cookie( CommercialZoomLevelCookieName, '/', '' );                                
                            Delete_Cookie( savedCommericalBusRoutesCookieName, '/', '' );
                            Delete_Cookie( savedCommercialBusRoutesStopsCookieName, '/', '' );

                            break; 
                        }
                        default: {
                        
                            break;
                        }    

                    }
                    
                    //turn off all the bus route layers as well
                    TurnOffAllExistingBusRouteLayers();

                    //delete all active bus route cookies
                    Delete_Cookie( activeBusRoutesCookieName, '/', '' );
                    Delete_Cookie( activeBusRoutesStopsCookieName, '/', '' );
                    Delete_Cookie( highlightBusRouteCookieName, '/', '' );

            } else {
            
                //turn off all the bus route layers as well
                TurnOffAllExistingBusRouteLayers();
            
                //delete all full screen active bus route cookies
                Delete_Cookie( FSactiveBusRoutesCookieName, '/', '' );
                Delete_Cookie( FSactiveBusRoutesStopsCookieName, '/', '' );
                Delete_Cookie( FShighlightBusRouteCookieName, '/', '' );
            
            }

            // Uncheck off all checkboxes and remove all layers from map
            RemoveAllMapLayers();

            //delete the testing cookie message
  	    Delete_Cookie( iMoveTestingCookieName, '/', '' );

            
            //turn off all the bus route layers as well
            //TurnOffAllExistingBusRouteLayers();

            //Reset the grid to the advisories tab
            TurnOnTab(document.getElementById('AdvisoriesTab'));	
            LoadFilterBarContentBasedOnXMLData('Events');                    
            
            //do not recenter map on bus routes (transit tab)
            isRecenterBusRouteOnMap = false;
            
            // reload the map to default view, and not based on saved customized view
            InitializeDefaultMapView();
            
            if ( activeTab == "Transit" ){        

                // turn on specific checkboxes and layers
                var cbx = document.getElementById( "chk_EV_CurEv" );
                cbx.checked = true;
                toggleLayer( cbx );

                cbx = document.getElementById( "chk_TRA_WstCstExpr" );
                cbx.checked = true;
                toggleLayer( cbx );

                cbx = document.getElementById( "chk_TRA_ExpoLine" );
                cbx.checked = true;
                toggleLayer( cbx );

                cbx = document.getElementById( "chk_TRA_MilLine" );
                cbx.checked = true;
                toggleLayer( cbx );
                
                cbx = null;
                
                ToggleDefaultBusRoutesOnMap();
                
                TurnOnActiveBusRoutes();
            }
           
            // show loading message
            showLoading();	
            
            // hide the loading message after 5 seconds
            window.setTimeout(hideLoading, 5000);

        } else {
        //user has pressed the cancel button on the Reset, do nothing
            //alert("do nothing");
        }

}


//*******************************************************************************
// Function:     RemoveAllMapLayers
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 26 2006
//
// Description:  Uncheck off all checkboxes and remove all layers from map
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    ResetPage()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function RemoveAllMapLayers()
{
   	//Events layers
   	
    cbx = document.getElementById( "chk_EV_CurInc" );
	cbx.checked = false;
    toggleLayer( cbx );
    
	cbx = document.getElementById( "chk_EV_CurCon" );
	cbx.checked = false;
    toggleLayer( cbx );
    	
	cbx = document.getElementById( "chk_EV_CurEv" );
	cbx.checked = false;
    toggleLayer( cbx );

	cbx = document.getElementById( "chk_EV_FutCon");
	cbx.checked = false;
    toggleLayer( cbx );
    
	cbx = document.getElementById( "chk_EV_FutEv" );
	cbx.checked = false;
    toggleLayer( cbx );
    
	cbx = document.getElementById( "chk_EV_FutSrvc" );
	cbx.checked = false;
    toggleLayer( cbx );
    
	//Camera layers
    
    cbx = document.getElementById( "chk_CAM_Border" );
	cbx.checked = false;
    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_CAM_TrafficInt" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_CAM_TrafficHigh");
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_CAM_Port" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    


	//Weather layers		
    
    cbx = document.getElementById( "chk_Weather" );
	cbx.checked = false;
    toggleLayer( cbx );

	//Road layers		
	
	cbx = document.getElementById( "chk_ROD_HwaySigns" );
	cbx.checked = false;
    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_ROD_Cong" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_ROD_CurInc" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_ROD_CurCon" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_ROD_CurEvnt" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_ROD_Border" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_ROD_Parking" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_ROD_Landmarks" );
	    cbx.checked = false;
    	    toggleLayer( cbx );

	    cbx = document.getElementById( "chk_ROD_FacStatus" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_ROD_Albion" );
	    cbx.checked = false;
    	    toggleLayer( cbx );


	//Transit layers		
	
	cbx = document.getElementById( "chk_TRA_Exch" );
	cbx.checked = false;
    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_Parking" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_ExpoLine" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_MilLine" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_WstCstExpr" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_Boundaries" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_SeaBus" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_Greyhound" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_BCFerries" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_IntAir" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_RegAir" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_ViaRail" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_TRA_Amtrak" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	//Commercial layers		
	
	cbx = document.getElementById( "chk_COM_Weigh" );
	cbx.checked = false;
    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_COM_Border" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_COM_BCFerries" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_COM_IntAir" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_COM_RegAir" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    //cbx = document.getElementById( "chk_COM_TruckRoute" );
	    //cbx.checked = false;
    	    //toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_COM_DangGoods" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_COM_EmerResp" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_COM_Restrictions" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    
       
	//Marine layers		
	
	cbx = document.getElementById( "chk_MA_CruiseLines" );
	cbx.checked = false;
    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_MA_Ports" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

        cbx = document.getElementById( "chk_MA_CustomEntry" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_MA_FalseCreek" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_MA_MarineAccess" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    	    
	    cbx = document.getElementById( "chk_MA_BCFerries" );
	    cbx.checked = false;
    	    toggleLayer( cbx );

	    cbx = document.getElementById( "chk_MA_SeaBus" );
	    cbx.checked = false;
    	    toggleLayer( cbx );

	    cbx = document.getElementById( "chk_MA_Albion" );
	    cbx.checked = false;
    	    toggleLayer( cbx );

    

	//Air layers			    
	
	cbx = document.getElementById( "chk_AIR_IntAir" );
	cbx.checked = false;
    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_AIR_RegAir" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_AIR_HrbrAir" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_AIR_WestCoastAir" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	cbx = document.getElementById( "chk_AIR_Helijet" );
	cbx.checked = false;
    toggleLayer( cbx );
    

	//Rail layers
	
	//cbx = document.getElementById( "chk_RAIL_Railroads" );
	//cbx.checked = false;
    //toggleLayer( cbx );


	    cbx = document.getElementById( "chk_RAIL_ExpoLine" );
	    cbx.checked = false;
    	    toggleLayer( cbx );


	    cbx = document.getElementById( "chk_RAIL_MilLine" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_RAIL_WstCstExpr" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_RAIL_ViaRail" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    

	    cbx = document.getElementById( "chk_RAIL_RockyMtn" );
	    cbx.checked = false;
    	    toggleLayer( cbx );
    
	cbx = document.getElementById( "chk_RAIL_Amtrak" );
	cbx.checked = false;
    toggleLayer( cbx );

	cbx = document.getElementById( "chk_RAIL_RailAccess" );
	cbx.checked = false;
    toggleLayer( cbx );

	//Cycling layers
	
	cbx = document.getElementById( "chk_CYC_DesOnStreet" );
    cbx.checked = false;
    toggleLayer( cbx );
            	
    cbx = document.getElementById( "chk_CYC_DesOffStreet" );
    cbx.checked = false;
    toggleLayer( cbx );
                    	
    cbx = document.getElementById( "chk_CYC_AltOnStreet" );
	cbx.checked = false;
    toggleLayer( cbx );
                    	
    cbx = document.getElementById( "chk_CYC_AltOffStreet" ); cbx.checked = false; toggleLayer( cbx );

    //Truck Routes
	cbx = document.getElementById( "chk_truckRouteAbbotsford" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteAldergrove" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteBurnaby" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteCoquitlam" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteDelta" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteFortLangley" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteMapleRidge" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteMcMillanIslandIR" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteMission" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteNewWestminster" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteNorthVancouver" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRoutePittMeadows" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRoutePortCoquitlam" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteRichmond" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteSurrey" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteUBC" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteVancouver" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteWestVancouver" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_truckRouteWhiteRock" ); cbx.checked = false; toggleLayer( cbx );

    //Cycling Routes
	cbx = document.getElementById( "chk_cycAbbotsford_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycBelcarra_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycBelcarra_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycBurnaby_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycBurnaby_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycBurnaby_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycBurnaby_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycCoquitlam_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycCoquitlam_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycCoquitlam_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycCoquitlam_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycDelta_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycDelta_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycDelta_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycDelta_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycLangley_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycLangley_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycLangley_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycLangley_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycLionsBay_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycMapleRidge_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycMapleRidge_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycMapleRidge_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycMapleRidge_DesOn" ); cbx.checked = false; toggleLayer( cbx );

	cbx = document.getElementById( "chk_cycNewWestminster_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycNewWestminster_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycNewWestminster_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycNewWestminster_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycNorthVancouver_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycNorthVancouver_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycNorthVancouver_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycNorthVancouver_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPittMeadows_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPittMeadows_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPittMeadows_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPittMeadows_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPortCoquitlam_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPortCoquitlam_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPortCoquitlam_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPortCoquitlam_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPortMoody_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPortMoody_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPortMoody_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycPortMoody_DesOn" ); cbx.checked = false; toggleLayer( cbx );

	cbx = document.getElementById( "chk_cycRichmond_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycRichmond_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycRichmond_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycRichmond_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycSurrey_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycSurrey_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycSurrey_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycSurrey_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycUBC_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycUBC_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycUBC_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycUBC_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycVancouver_AltOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycVancouver_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycVancouver_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycVancouver_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycWestVancouver_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycWestVancouver_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycWestVancouver_DesOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycWhiteRock_AltOn" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycWhiteRock_DesOff" ); cbx.checked = false; toggleLayer( cbx );
	cbx = document.getElementById( "chk_cycWhiteRock_DesOn" ); cbx.checked = false; toggleLayer( cbx );

    cbx = null;
}

//*******************************************************************************
// Function:     RemoveLayerIfLayerExists
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.7
// Date:         Nov 09 2006
//
// Description:  This function will remove the layer if the layer already exists.
//               It is called before adding (refreshing) the layer's overlays 
//               again.
//
// Parameters:   groupId - name of map layer
// Returns:
// Calls:        
// Called By:    generateGroupMarkers(), 
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function RemoveLayerIfLayerExists(groupId, optParameter1)
{

// Debug variable (set to 1 to debug)
var debug = 0;

    var groupExist = hasGroupLayer(groupId);
    if (groupExist > 0)
    {

if (debug)
    alert('hasGroupLayer: true');

if (debug)
{
    if (overlays != null)
        if (overlays['groups'] != null)
        {
            alert("Before removal: overlays['groups'].length: " + overlays['groups'].length);
            
            for( j=0; j<overlays['groups'].length; j++ ) 
                alert("overlays['groups'][" + j + "]: " + overlays['groups'][j]);
        }
}
            
        // remove exising group markers
        // remove these overlays
        map.removeGroupOverlays( "Marker", groupId, optParameter1 );
                
if (debug)
{
    if (overlays != null)
        if (overlays['groups'] != null)
        {
            alert("After removal: overlays['groups'].length: " + overlays['groups'].length);
            
            for( j=0; j<overlays['groups'].length; j++ ) 
                alert("overlays['groups'][" + j + "]: " + overlays['groups'][j]);
        }
}

    }
    else
    {
if (debug)
    alert('hasGroupLayer: false');
    }

if (debug)
{
    if (overlays != null)
        if (overlays['groups'] != null)
        {
            alert("Before add: overlays['groups'].length: " + overlays['groups'].length);
            
            for( j=0; j<overlays['groups'].length; j++ ) 
                alert("overlays['groups'][" + j + "]: " + overlays['groups'][j]);
        }
}
            
}

//*******************************************************************************
// Function:     Save Page
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.6
// Date:         Oct 26 2006
//
// Description:  Saves the map layers in a cookie based on the current tab. These layers will
//               overwrite the default layers for the tab. 
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function SavePage(){

    // save cookie information for current tab's cookie
    var activeTab = Get_Cookie( 'activeTab' );    
    
    //show the loading message
    showLoading();
    window.setTimeout(hideLoading,2000);               

    //update the appropriate cookie
    switch( activeTab ) 
    
    {
                    
        case "Motorists" : {            
            var activeTabLayers = activeMotoristsLayersCookieName;    

             //store the map zoom level for the fullscreen map
            var zoom = map.getZoom();
            AddOrRemovePartialCookieValue(MotoristsZoomLevelCookieName, zoom, true);  

            //store the map center for the fullscreen map
            var mapCenter = map.getCenter();
            AddOrRemovePartialCookieValue(MotoristsMapCenterCookieName, mapCenter, true);              

            //save bus route data for the tab
            saveBusRoutesInfoForTab( savedMotoristsBusRoutesCookieName, savedMotoristsBusRoutesStopsCookieName);                         
            
            break; 
        }
        case "Transit" : {
            var activeTabLayers =  activeTransitLayersCookieName;    

             //store the map zoom level for the fullscreen map
            var zoom = map.getZoom();            
            AddOrRemovePartialCookieValue(TransitZoomLevelCookieName, zoom, true);              

            //store the map center for the fullscreen map
            var mapCenter = map.getCenter();            
            AddOrRemovePartialCookieValue(TransitMapCenterCookieName, mapCenter, true);  

            //save bus route data for the tab
            saveBusRoutesInfoForTab( savedTransitBusRoutesCookieName, savedTransitBusRoutesStopsCookieName);                         

            break; 
        }
        case "Cycling" : {
            var activeTabLayers =  activeCyclingLayersCookieName;    

             //store the map zoom level for the fullscreen map
            var zoom = map.getZoom();            
            AddOrRemovePartialCookieValue(CyclingZoomLevelCookieName, zoom, true);  

            //store the map center for the fullscreen map
            var mapCenter = map.getCenter();            
            AddOrRemovePartialCookieValue(CyclingMapCenterCookieName, mapCenter, true);  

            //save bus route data for the tab
            saveBusRoutesInfoForTab( savedCyclingBusRoutesCookieName, savedCyclingBusRoutesStopsCookieName);                         

            break; 
        }
        case "Gateways" : {
            var activeTabLayers =  activeGatewaysLayersCookieName;    

             //store the map zoom level for the fullscreen map
            var zoom = map.getZoom();
            AddOrRemovePartialCookieValue(GatewaysZoomLevelCookieName, zoom, true);  

            //store the map center for the fullscreen map
            var mapCenter = map.getCenter();            
            AddOrRemovePartialCookieValue(GatewaysMapCenterCookieName, mapCenter, true);              

            //save bus route data for the tab
            saveBusRoutesInfoForTab( savedGatewaysBusRoutesCookieName, savedGatewaysBusRoutesStopsCookieName);                         

            break; 
        }
        case "Visitors" : {
            var activeTabLayers =  activeVisitorsLayersCookieName;    

             //store the map zoom level for the fullscreen map
            var zoom = map.getZoom();            
            AddOrRemovePartialCookieValue(VisitorsZoomLevelCookieName, zoom, true);                  

            //store the map center for the fullscreen map
            var mapCenter = map.getCenter();
            AddOrRemovePartialCookieValue(VisitorsMapCenterCookieName, mapCenter, true);              

            //save bus route data for the tab
            saveBusRoutesInfoForTab( savedVisitorsBusRoutesCookieName, savedVisitorsBusRoutesStopsCookieName);                         

            break; 
        }
        case "Commercial" : {
            var activeTabLayers =  activeCommericalsLayersCookieName;                

             //store the map zoom level for the fullscreen map
            var zoom = map.getZoom();
            AddOrRemovePartialCookieValue(CommercialZoomLevelCookieName, zoom, true);              

            //store the map center for the fullscreen map
            var mapCenter = map.getCenter();            
            AddOrRemovePartialCookieValue(CommercialMapCenterCookieName, mapCenter, true);                           

            //save bus route data for the tab
            saveBusRoutesInfoForTab( savedCommericalBusRoutesCookieName, savedCommercialBusRoutesStopsCookieName);                         

            break; 
        }
        default: {
        
            break;
        }    

    }
    
    //save the active tab layers into the cookie
    saveCheckboxCookieInfo( activeTabLayers );    

}



function saveBusRoutesInfoForTab( busRoutesTabCookieName, busRouteStopsTabCookieName ){

    //Save the active bus routes into the saved bus routes cookie
    var activeBusRoutesCookie = Get_Cookie( activeBusRoutesCookieName );
    if (activeBusRoutesCookie != null){
        //delete the old saved bus routes cookie            
        //Delete_Cookie( savedBusRoutesCookieName, '/', '' );
        Delete_Cookie( busRoutesTabCookieName, '/', '' );

        // split the cookie into individual routes
        var partialCookieArr = activeBusRoutesCookie.split( "," );
        
        //loop through each Route Id
        for( var i=0; i<partialCookieArr.length-1; i++ ) 
        {
            var activeBusRoute = partialCookieArr[i]; 
            //add these items to the saves bus routes cookie here
            //AddOrRemovePartialCookieValue(savedBusRoutesCookieName, activeBusRoute, true);
            AddOrRemovePartialCookieValue(busRoutesTabCookieName, activeBusRoute, true);
        }
    }	    

    //Save the active bus routes stops the saved bus routes stops cookie
    var activeBusStopsCookie = Get_Cookie( activeBusRoutesStopsCookieName );
    if (activeBusStopsCookie != null){
        //delete the old saved bus stops cookie            
        //Delete_Cookie( savedBusRoutesStopsCookieName, '/', '' );
        Delete_Cookie( busRouteStopsTabCookieName, '/', '' );

        // split the cookie into individual routes
        var partialCookieArr = activeBusStopsCookie.split( "," );
        
        //loop through each Route Id
        for( var i=0; i<partialCookieArr.length-1; i++ ) 
        {
            var routeId = partialCookieArr[i]; 
            //add these items to the saves bus routes cookie here
           // AddOrRemovePartialCookieValue(savedBusRoutesStopsCookieName, routeId, true);
            AddOrRemovePartialCookieValue(busRouteStopsTabCookieName, routeId, true);
        }
    }	    
}


//*******************************************************************************
// Function:     recenterMapForBusRoute
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.6
// Date:         Nov 24 2006
//
// Description:  This function recenters the map based on the points in a bus route.
//               The function takes an array of points for the bus route, and makes
//               the map boundaries being shown from the first point, and the last
//               point in the bus route, and centers the map accordingly.
//
// Parameters:   points [] from a bus route
// Returns:
// Calls:        
// Called By:    generateGroupPolylines()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function recenterMapForBusRoute( points ){


// Debug variable (set to 1 to debug)
var debug = 0;

if (debug)
    PrintElapseTime("recenterMapForBusRoute(): start calculating center point");

    //determine the last point from the array of points
    var lastPoint = points.length-1;

    //grab the first and last point from the array of points
    var firstPointStr = points[0].toString();
    //var lastPointStr = points[lastPoint].toString();
    var lastPointStr = points[1].toString();

    //find the comma position, as we have to split up the array into 2 strings
    var commaPosition = firstPointStr.indexOf(",");

    //trim off the first bracket
    var x1Point = firstPointStr.substr(1,commaPosition-1);
    var y1Point = firstPointStr.substr(commaPosition+1,firstPointStr.length);

    //trim off the last bracket
    y1Point = y1Point.substr(0,y1Point.length-1);

//alert("y1Point2"+y1Point);    
//alert("point 1's are: '" +  x1Point + "' - '" + y1Point + "'");  
//alert("str2 is '"+lastPointStr + "'");      

    commaPosition = lastPointStr.indexOf(",");

    //trim off the first bracket
    var x2Point = lastPointStr.substr(1,commaPosition-1);
    var y2Point = lastPointStr.substr(commaPosition+1,lastPointStr.length);

    //trim off the last bracket
    y2Point = y2Point.substr(0,y2Point.length-1);

    // Start with an empty GLatLngBounds object 
    var bounds = new GLatLngBounds();

    //create the starting point
    var startPoint = new GLatLng( x1Point,y1Point );

    //add the starting point to the bounds
    bounds.extend(startPoint);

    //create the ending point
    var endPoint = new GLatLng(x2Point , y2Point);

    // add the end point to the bounds
    bounds.extend(endPoint);
    
    // ===== determine the zoom level from the bounds =====
    var newZoomLevel = map.getBoundsZoomLevel(bounds);
    
    // move the map back one zoom level, so we aren't totally zoomed in
    newZoomLevel = newZoomLevel - 1;    

    // ===== determine the centre from the bounds ======
    var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
    var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;

if (debug)
    PrintElapseTime("recenterMapForBusRoute(): end calculating center point");

if (debug)
    PrintElapseTime("recenterMapForBusRoute(): start setCenter()");
    
    //set the map to the new center point
    map.setCenter(new GLatLng(clat,clng), newZoomLevel);

if (debug)
    PrintElapseTime("recenterMapForBusRoute(): end setCenter()");
   

}


function getQueryVariable(variable) { 
    var query = window.location.search.substring(1); 
    var vars = query.split("&"); 
    
    //alert("variable is: '" + variable + "' vars are:'" + vars + "'");
    
    for (var i=0;i<vars.length;i++) {         
        
        var pair = vars[i].split("=");     
    
        if (pair[0] == variable) { 
            return pair[1]; 
        } 
    }     
    
    //alert('Query Variable ' + variable + ' not found'); 
    
    //when the query variable is not found, return a null value
    return null;
    
} 


function isValidNumber(numval)
{
	if (numval==""){return false;}
	var myRegExp = new RegExp("^[/+|/-]?[0-9]*[/.]?[0-9]*$");
	return myRegExp.test(numval);
}



//Load the custom fullscreen map
function LoadFullScreenCustomMapInfo(){

    var lNumberCheck = false;


    RemoveAllMapLayers();

    //alert("yo yo");

    //delete the full screen map cookies if there are any
    Delete_Cookie( FSactiveBusRoutesCookieName, '/', '' );
    Delete_Cookie( FShighlightBusRouteCookieName, '/', '' ); 
    Delete_Cookie( FSactiveBusRoutesStopsCookieName, '/', '' ); 

    //Load the data grid with the advisories tab
    TurnOnTab(document.getElementById('AdvisoriesTab'));                
    LoadFilterBarContentBasedOnXMLData('Events');
    LoadGridData( true );  
                  
    
    //get map zoom level from map
    var mapZoom = getQueryVariable("Zoom");
    
    //alert("mapZoom is: '" + mapZoom + "'");
    
    
    if (mapZoom == null){
        //if map zoom level is not supplied, default it         
        mapZoom = 9;
    
    } else {    
    
        //make sure zoom level is a valid integer
        lNumberCheck = isValidNumber(mapZoom);
        
        if (lNumberCheck == true){
            //map zoom is ok, do nothing              
        } else {
            //map zoom is bad, set to default            
            mapZoom = 9;
        }
    }

    //reset the number check variable
    lNumberCheck = false;
    
    //get map Lat from query string
    var mapLat = getQueryVariable("Lat"); 

    if (mapLat == null){
        //if map zoom level is not supplied, default it 
        mapLat = 49.2274;
            
    } else {    
    
        //make sure zoom level is a valid integer
        lNumberCheck = isValidNumber(mapLat);
        
        if (lNumberCheck == true){
            //map zoom is ok, do nothing 
            //alert("lat ok");                           
        } else {
            //map zoom is bad, set to default            
            //alert("lat NOT ok");              
            mapLat = 49.2274;
        }
    }

    lNumberCheck = false;

    //get map Long from query string
    var mapLong = getQueryVariable("Long"); 

    if (mapLong == null){
        //if map long level is not supplied, default it 
        mapLong = -122.882;
    
    } else {    
    
        //make sure map long is a valid integer
        lNumberCheck = isValidNumber(mapLong);
        
        if (lNumberCheck == true){
            //map long is ok, do nothing
            //alert("long ok");              
        } else {
            //map long is bad, set to default            
            //alert("long NOT ok");
            mapLong = -122.882;
        }
    }

    
    //testing, set the map center to lions gate bridge
    //map.setCenter( new GLatLng( 49.304755,-123.137341),  parseInt( zoom ) );
    map.setCenter( new GLatLng( mapLat, mapLong),  parseInt( mapZoom ) );
    
    // http://www.i-move.ca/InteractiveMapFullScreen?v=C&Zoom=9&Lat=49.00252&Long=-122.757454&CheckBoxes=chk_CAM_Border;chk_ROD_HwaySigns;chk_ROD_Border;chk_EV_CurInc;&BusRoutes=1;2;3;4;    

// http://www.i-move.ca/InteractiveMapFullScreen?v=C&Zoom=12&Lat=49.314828&Long=-123.138885&CheckBoxes=chk_CAM_TrafficInt;chk_ROD_Parking;chk_ROD_FacStatus;chk_TRA_Exch;

//chk_CAM_TrafficInt;chk_ROD_Parking;chk_ROD_FacStatus;chk_TRA_Exch;
//49.00252,-122.757454
//chk_CAM_Border....
//chk_ROD_HwaySigns
//chk_ROD_Border


    //the checkbox
    var cbx;

    //get map Long from query string
    var mapCheckBoxes = getQueryVariable("CheckBoxes"); 

    if (mapCheckBoxes != null){
        
        //split up the checkboxes        
        var mapCheckBoxArray = mapCheckBoxes.split(";"); 
        
        for (var i=0;i<mapCheckBoxArray.length -1;i++) {         
            
            //grab checkbox name
            var checkBox = mapCheckBoxArray[i];
            
            //make sure checkbox is a valid name, then turn on
            cbx = document.getElementById( checkBox );
            
            if (cbx != null){
            	cbx.checked = true;
        	    toggleLayer( cbx );
        	    
        	    cbx = null;
            }
        }  
    }

// are we doing bus routes ...
    
        // don't recenter map
        isRecenterBusRouteOnMap = false;
            
            //ToggleBusRouteOnMap('25');
            //ToggleBusRouteOnMap('32');

        //get map Long from query string
        var mapBusRoutes = getQueryVariable("BusRoutes"); 

        if (mapBusRoutes != null){
            
            //split up the checkboxes        
            var mapBusRoutesArray = mapBusRoutes.split(";"); 
            
            for (var i=0;i<mapBusRoutesArray.length -1;i++) {         
                
                //grab checkbox name
                var busRouteID = mapBusRoutesArray[i];                
                ToggleBusRouteOnMap( busRouteID );

            }  
        }

}


//*******************************************************************************
// Function:     LoadFullScreenMapInfo
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.6
// Date:         Nov 24 2006
//
// Description:  This function opens the full screen layers cookie, and checks off
//               the saved checkboxes.                 
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    LoadPage, when the fullscreen page is requested.
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function LoadFullScreenMapInfo(){

    //switch the fullscreen map flag cookie, indicating we will need to overwrite active bus routes 
    //alert("lets set the fullscreen map flag");
    AddOrRemovePartialCookieValue(FullScreenBusRoutesFlagCookie, "yes", true); 
    
    //delete the full screen map cookies if there are any
    Delete_Cookie( FSactiveBusRoutesCookieName, '/', '' );
    Delete_Cookie( FShighlightBusRouteCookieName, '/', '' ); 
    Delete_Cookie( FSactiveBusRoutesStopsCookieName, '/', '' ); 

        //store the active bus route stops into temporary cookie
        var tempActiveBusRoutesCooke = Get_Cookie( activeBusRoutesCookieName );            
        if (tempActiveBusRoutesCooke != null){                
            var partialCookieArr = tempActiveBusRoutesCooke.split( "," );                
            for( var i=0; i<partialCookieArr.length-1; i++ )                 {
                var routeId = partialCookieArr[i];            	                            
               AddOrRemovePartialCookieValue(FSactiveBusRoutesCookieName, routeId, true);
            }
        } 
        
    var cbx;

    //alert("start checking off fullscreen checkboxes");       

    //loop through full screen cookie    
    var fullScreenLayersCookie = Get_Cookie( activeFullScreenLayersCookieName );
       
    if (fullScreenLayersCookie != null){
    
        // split the cookie into individual routes
        var partialCookieArr = fullScreenLayersCookie.split( "," );
        
        //loop through each Route Id
        for( var i=0; i<partialCookieArr.length-1; i++ ) 
        {
            var checkboxName = partialCookieArr[i];            	        
    	    
    	    //check off the saved checkboxes
    	    cbx = document.getElementById( checkboxName );
    	    cbx.checked = true;
    	    toggleLayer( cbx );
    	    cbx = null;
        }
    
    }

        //alert("done checking off fullscreen checkboxes");       

      //grab tab value from cookie
      var activeTab = Get_Cookie(DataGridTabCookieName );
        //TRIM OFF THE LAST COMMA
      var activeTabString = activeTab.substr(0,activeTab.length-1);
      
      switch( activeTabString )     
        {
            case "AdvisoriesTab" : {
            
                //alert("start advisories tab");
            
                LoadFilterBarContentBasedOnXMLData('Events');
            
                TurnOnTab(document.getElementById('AdvisoriesTab'));                
                //LoadFilterBarContentBasedOnXMLData('Events');  -- old position                
                
                //alert("done with filter bar");
                LoadGridDataWhenNotPanAndZoom();  //-- old one 
                
                //LoadGridData( true );      -- old one   
                
                //alert("done with fullscreen grid data");       
                break;
            }
            case "GroupTab" : {
                TurnOnTab(document.getElementById('GroupTab'));
                LoadFilterBarContentBasedOnXMLData('CameraGroups');
                LoadGridDataWhenNotPanAndZoom();
                break;
            }
            case "CameraTab" : {
                TurnOnTab(document.getElementById('CameraTab'));
                LoadFilterBarContentBasedOnXMLData('Cameras');
                LoadGridDataWhenNotPanAndZoom();
                break;
            }
            case "BusRoutesTab" : {

                TurnOnTab(document.getElementById('BusRoutesTab'));
                LoadFilterBarContentBasedOnXMLData('BusRoutes');                
                LoadGridDataWhenNotPanAndZoom();                
                break;
            }

            default: {
                //load advisories tab by default    
                TurnOnTab(document.getElementById('AdvisoriesTab'));
                LoadFilterBarContentBasedOnXMLData('Events');
                //LoadGridDataWhenNotPanAndZoom();
                LoadGridData( true );                
                break;                
            }                

    }
    
    //set the map zoom level for the fullscreen map from the cookie
    var fullScreenMapZoom = Get_Cookie(FullScreenZoomLevelCookieName); 
    var fullScreenMapCenter = Get_Cookie(FullScreenMapCenterCookieName);   

    var center_arr=fullScreenMapCenter.split( "," );
    map.setCenter( new GLatLng( center_arr[0].substr( 1, center_arr[0].length ), center_arr[1].substr( 0, center_arr[0].length-1 ) ), parseInt( fullScreenMapZoom ) );
    
    //testing, set the map center to lions gate bridge
    //map.setCenter( new GLatLng( 49.304755,-123.137341),  13 );

    
    //after the map has loaded, turn on active bus routes if there are any
    //TurnOnActiveBusRoutes();    
    TurnOnFullScreenActiveBusRoutes();    

}

//*******************************************************************************
// Function:     SaveFullScreenInfo
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.6
// Date:         Nov 28 2006
//
// Description:  Saves the checked off layers into the fullscreen layers cookie, 
//               to be loaded when the full screen map is loaded. 
//
// Parameters:   
// Returns:
// Calls:        
// Called By:   OnClick of the fullscreen button in the toolbar 
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function SaveFullScreenInfo(){
    
    //delete the old fullscreen layers cookie
    Delete_Cookie( activeFullScreenLayersCookieName, '/', '' ); 

    //save the active layers into the full screen cookie    
    saveCheckboxCookieInfo( activeFullScreenLayersCookieName );
    
    //store the map zoom level for the fullscreen map
    var zoom = map.getZoom();
    Set_Cookie(FullScreenZoomLevelCookieName, zoom);      

    //store the map center for the fullscreen map
    var mapCenter = map.getCenter();
    Set_Cookie(FullScreenMapCenterCookieName, mapCenter);     
    
    //alert("done saving full screen info");
    
}

//*******************************************************************************
// Function:     saveCheckboxCookieInfo
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.6
// Date:         Nov 28 2006
//
// Description:  Saves the checked off layers into the provided cookie name
//
// Parameters:   
// Returns:
// Calls:        
// Called By:   SaveFullScreenInfo(), SavePage()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************

function saveCheckboxCookieInfo( cookieName ){

    var cbx;    
    var checked;

        //save all checkboxes
 	   	cbx = document.getElementById( "chk_RAIL_Amtrak" );
	    checked = cbx.checked;
        AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_EV_CurInc" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_EV_CurCon" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_EV_CurEv" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_EV_FutCon");
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_EV_FutEv" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_EV_FutSrvc" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	   //Camera layers
	    cbx = document.getElementById( "chk_CAM_Border" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_CAM_TrafficInt" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_CAM_TrafficHigh");
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_CAM_Port" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	//Weather layers		
            cbx = document.getElementById( "chk_Weather" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	//Road layers		
	    cbx = document.getElementById( "chk_ROD_HwaySigns" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_ROD_Cong" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_ROD_CurInc" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_ROD_CurCon" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_ROD_CurEvnt" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_ROD_Border" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_ROD_Parking" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
        
	    cbx = document.getElementById( "chk_ROD_Landmarks" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_ROD_FacStatus" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_ROD_Albion" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);



	//Transit layers		
	    cbx = document.getElementById( "chk_TRA_Exch" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_Parking" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_ExpoLine" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_TRA_MilLine" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_WstCstExpr" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_Boundaries" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_SeaBus" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_Greyhound" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_BCFerries" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_IntAir" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_RegAir" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_ViaRail" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_TRA_Amtrak" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	//Commercial layers		
	    cbx = document.getElementById( "chk_COM_Weigh" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_COM_Border" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_COM_BCFerries" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_COM_IntAir" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_COM_RegAir" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_COM_TruckRoute" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_COM_DangGoods" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_COM_EmerResp" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_COM_Restrictions" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

       
	//Marine layers		
	    cbx = document.getElementById( "chk_MA_CruiseLines" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_MA_Ports" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

        cbx = document.getElementById( "chk_MA_CustomEntry" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_MA_FalseCreek" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_MA_MarineAccess" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_MA_BCFerries" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_MA_SeaBus" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_MA_Albion" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	//Air layers			    
	    cbx = document.getElementById( "chk_AIR_IntAir" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_AIR_RegAir" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_AIR_HrbrAir" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_AIR_WestCoastAir" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_AIR_Helijet" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
        

	//Rail layers
	    //cbx = document.getElementById( "chk_RAIL_Railroads" );
	    //checked = cbx.checked;
    	  //  AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_RAIL_ExpoLine" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_RAIL_MilLine" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_RAIL_WstCstExpr" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_RAIL_ViaRail" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_RAIL_RockyMtn" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_RAIL_Amtrak" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


	    cbx = document.getElementById( "chk_RAIL_RailAccess" );
	    checked = cbx.checked;
    	    AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);


        //Cycling layers
        cbx = document.getElementById( "chk_CYC_DesOnStreet" );
	    checked = cbx.checked;
    	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	
    	cbx = document.getElementById( "chk_CYC_DesOffStreet" );
	    checked = cbx.checked;
    	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	
    	cbx = document.getElementById( "chk_CYC_AltOnStreet" );
	    checked = cbx.checked;
    	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	
    	cbx = document.getElementById( "chk_CYC_AltOffStreet" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	

        //Truck Routes
    	cbx = document.getElementById( "chk_truckRouteAbbotsford" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteAldergrove" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteBurnaby" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteCoquitlam" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteDelta" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteFortLangley" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteMapleRidge" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteMcMillanIslandIR" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteMission" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteNewWestminster" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteNorthVancouver" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRoutePittMeadows" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRoutePortCoquitlam" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteRichmond" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteSurrey" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteUBC" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteVancouver" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteWestVancouver" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	cbx = document.getElementById( "chk_truckRouteWhiteRock" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
    	
        //Cycling Routes
	    cbx = document.getElementById( "chk_cycAbbotsford_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycBelcarra_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycBelcarra_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycBurnaby_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycBurnaby_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycBurnaby_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycBurnaby_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycCoquitlam_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycCoquitlam_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycCoquitlam_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycCoquitlam_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycDelta_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycDelta_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycDelta_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycDelta_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycLangley_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycLangley_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycLangley_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycLangley_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycLionsBay_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycMapleRidge_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycMapleRidge_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycMapleRidge_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycMapleRidge_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_cycNewWestminster_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycNewWestminster_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycNewWestminster_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycNewWestminster_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycNorthVancouver_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycNorthVancouver_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycNorthVancouver_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycNorthVancouver_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPittMeadows_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPittMeadows_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPittMeadows_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPittMeadows_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPortCoquitlam_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPortCoquitlam_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPortCoquitlam_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPortCoquitlam_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPortMoody_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPortMoody_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPortMoody_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycPortMoody_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);

	    cbx = document.getElementById( "chk_cycRichmond_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycRichmond_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycRichmond_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycRichmond_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycSurrey_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycSurrey_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycSurrey_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycSurrey_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycUBC_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycUBC_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycUBC_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycUBC_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycVancouver_AltOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycVancouver_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycVancouver_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycVancouver_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycWestVancouver_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycWestVancouver_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycWestVancouver_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycWhiteRock_AltOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycWhiteRock_DesOff" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
	    cbx = document.getElementById( "chk_cycWhiteRock_DesOn" ); checked = cbx.checked;	AddOrRemovePartialCookieValue(cookieName, cbx.id, checked);
cbx = null;

}


//*******************************************************************************
// Function:     GetSavedCheckboxNames
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.8
// Date:         Dec 01 2006
//
// Description:  Returns the value of the cookie for the saved checkbox names.
//               These checkbox names will represent different map layers
//               that will be shown on the map. Saved advisory and camera layers
//               will also be loaded on the grid initially.
//               Returns empty string if value of cookie is null.
//               Saved state is defined in a cookie for each tab.   
//
// Parameters:   
// Returns:
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function GetSavedCheckboxNames()
{

// Debug variable (set to 1 to debug)
var debug = 0;

    // Retrieve active tab cookie
    var activeTab = Get_Cookie( 'activeTab' );

    // Set default value for active tab
    if (activeTab == null)
        activeTab = 'Motorists';

if (debug)
{
        alert('active tab: ' + activeTab + '\n');
}
    
    // grab the appropriate cookie name from the tab

    var savedCheckboxNames = "";
    
    switch( activeTab )     
    {
        case "Motorists" : {            
            savedCheckboxNames = Get_Cookie( activeMotoristsLayersCookieName );    
            break; 
        }
        case "Transit" : {
            savedCheckboxNames = Get_Cookie( activeTransitLayersCookieName );    
            break; 
        }
        case "Cycling" : {
            savedCheckboxNames = Get_Cookie( activeCyclingLayersCookieName );    
            break; 
        }
        case "Gateways" : {
            savedCheckboxNames = Get_Cookie( activeGatewaysLayersCookieName );    
            break; 
        }
        case "Visitors" : {
            savedCheckboxNames = Get_Cookie( activeVisitorsLayersCookieName );    
            break; 
        }
        case "Commercial" : {
            savedCheckboxNames = Get_Cookie( activeCommericalsLayersCookieName );                
            break; 
        }
        default: {
        
            break;
        }
        
  }
  
  return savedCheckboxNames;
}

//*******************************************************************************
// Function:     filterRegion
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.1
// Date:         Sep 01, 2006
//
// Description:  The following function returns the filtered region path with
//               query string. 
//               This function depends on hardcoded region dropdownlist 
//               id to find selected value. 
//
// Parameters:   
// Returns:      Returns the filtered region path with query string in order 
//               to retrieve XML response data.
// Calls:        
// Called By:    LoadMapData(), LoadGridData()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************
function filterRegion() {

        // Find currently selected tab.
	    var tabSelectedId = GridTabSelected();
	
	    // This only happens on initial Load, set it to load advisories tab.
	    if (tabSelectedId == "")
	    {
	        tabSelectedId = AdvisoriesTabId;
	    }
    	
    	// Retrieve filter criteria selected region value
	    if (tabSelectedId == AdvisoriesTabId)
	    {
            ddlAdvisoriesRegion = document.getElementById(AdvisoryRegionSelectName);
            if (ddlAdvisoriesRegion != null)
                region = ddlAdvisoriesRegion.options[ddlAdvisoriesRegion.selectedIndex].text;
            else
                region = "All";
                            ddlAdvisoriesRegion = null;
        }
        else if (tabSelectedId == CameraGroupsTabId)
	    {
            ddlCameraGroupsRegion = document.getElementById(CameraGroupRegionSelectName);
            if (ddlCameraGroupsRegion != null)
                region = ddlCameraGroupsRegion.options[ddlCameraGroupsRegion.selectedIndex].text;
            else
                region = "All";
                
                ddlCameraGroupsRegion = null;
        }
        else if (tabSelectedId == CamerasTabId)
	    {
            ddlCamerasRegion = document.getElementById(CameraRegionSelectName);
            if (ddlCamerasRegion != null)
                region = ddlCamerasRegion.options[ddlCamerasRegion.selectedIndex].text;
            else
                region = "All";
                ddlCamerasRegion = null;
        }
        else if (tabSelectedId == BusRoutesTabId)
	    {
            ddlBusRoutesRegion = document.getElementById(BusRouteRegionSelectName);
            if (ddlBusRoutesRegion != null)
                region = ddlBusRoutesRegion.options[ddlBusRoutesRegion.selectedIndex].text;
            else
                region = "All";
                ddlBusRoutesRegion = null;
        }
                    
        // URL encode string
        region = URLEncode(region);
            
        // Build individual query string
        regionQS = "";
        if (region != "All")
            regionQS = "name=" + region;

        // Build query string
        queryString = "";

        if (regionQS != "")
        {
            if (queryString != "")
                queryString += "&" + regionQS;
            else
                queryString = regionQS;
        }
        
        // return the path including query string 
        // for retrieving the filtered response
        return RegionsXmlResponsePath + "?" + queryString;
}// end function

//*******************************************************************************
// Function:     filterAdvisories
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.2
// Date:         Sep 05, 2006
//
// Description:  The following function returns the filtered advisories path with
//               query string. 
//               This function depends on hardcoded dropdownlist ids to find
//               selected values.
//              
//               Only data within map boundaries and satisfaction of specified 
//               zoom level are shown.
//
// Parameters:   isFilterByType - indicates whether to filter by type.
// Returns:      Returns the filtered advisories path with query string in order 
//               to retrieve XML response data.
// Calls:        
// Called By:    LoadMapData(), LoadGridData()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
// Michael Chu  Dec 04, 2006 Moved to common.js file because it is being used on initial load.
//*******************************************************************************    
function filterAdvisories( isFilterByType ) {

// Debug variable (set to 1 to debug)
var debug = 0;

//alert("huh ? filterAdvisories()");

if (debug)
    alert("filterAdvisories()");
            
        // return the path including query string 
        // for retrieving the filtered response 
        
        //alert(EventsXmlResponsePath + "?"+ filterAdvisoriesQueryString( isFilterByType ));      
        
        return EventsXmlResponsePath + "?"+ filterAdvisoriesQueryString( isFilterByType );
}// end function

//*******************************************************************************
// Function:     filterAdvisoriesQueryString
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.8
// Date:         Nov 23, 2006
//
// Description:  The following function returns the filtered advisories 
//               query string without the URL path.
//               This function depends on hardcoded dropdownlist ids to find
//               selected values.
//              
//               Only data within map boundaries and satisfaction of specified 
//               zoom level are shown.
//
// Parameters:   isFilterByType - indicates whether to filter by type.
// Returns:      Returns the filtered advisories query string which can be
//               appended to URL path with a "?" or "&" in order to retrieve 
//               XML response data.
// Calls:        
// Called By:    filterAdvisories()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
// Michael Chu  Dec 04, 2006 Moved to common.js file because it is being used on initial load.
//*******************************************************************************    
function filterAdvisoriesQueryString( isFilterByType ) {

// Debug variable (set to 1 to debug)
var debug = 0;

if (debug)
    alert("filterAdvisoriesQueryString()");
    
        // Retrieve filter criteria selected text values
        ddlAdvisoriesRegion = document.getElementById(AdvisoryRegionSelectName);
        if (ddlAdvisoriesRegion != null)
            advisoryRegion = ddlAdvisoriesRegion.options[ddlAdvisoriesRegion.selectedIndex].text;
        else
            advisoryRegion = "All";
            ddlAdvisoriesRegion = null;    
        // The following has been commented out since
        // instead of using drop down selection, checkboxes are used for each
        // type instead.            
//        ddlAdvisoriesType = document.getElementById(AdvisoryTypeSelectName);
//        if (ddlAdvisoriesType != null)
//            advisoryType = ddlAdvisoriesType.options[ddlAdvisoriesType.selectedIndex].text;
//        else
//            advisoryType = "All";

        var advisoryType = "";
        if (isFilterByType == null || isFilterByType == true)
        {
            var cbx;
            cbx = document.getElementById( "chk_EV_CurInc_Grid" );
            if (cbx != null && cbx.checked == true)
                advisoryType = "Incident";
                
            cbx = document.getElementById( "chk_EV_CurCon_Grid" );
            if (cbx != null && cbx.checked == true)
            {
                if (advisoryType == "")
                    advisoryType = "Construction";
                else
                    advisoryType += "," + "Construction";
            }
            cbx = document.getElementById( "chk_EV_CurEv_Grid" );
            if (cbx != null && cbx.checked == true)
            {
                if (advisoryType == "")
                    advisoryType = "Event";
                else
                    advisoryType += "," + "Event";
            }
            cbx = document.getElementById( "chk_EV_FutCon_Grid" );
            if (cbx != null && cbx.checked == true)
            {
                if (advisoryType == "")
                    advisoryType = "Future Construction";
                else
                    advisoryType += "," + "Future Construction";
            }
            cbx = document.getElementById( "chk_EV_FutEv_Grid" );
            if (cbx != null && cbx.checked == true)
            {
                if (advisoryType == "")
                    advisoryType = "Future Event";
                else
                    advisoryType += "," + "Future Event";
            }
            cbx = document.getElementById( "chk_EV_FutSrvc_Grid" );
            if (cbx != null && cbx.checked == true)
            {
                if (advisoryType == "")
                    advisoryType = "Future Service";
                else
                    advisoryType += "," + "Future Service";
            }
            
            if (advisoryType == "")
                advisoryType = "-1"; // return nothing since no checkbox is checked.
                
                cbx = null;
        }
        
        // Severity
        ddlAdvisoriesSeverity = document.getElementById(AdvisorySeveritySelectName);
        if (ddlAdvisoriesSeverity != null)
            advisorySeverity = ddlAdvisoriesSeverity.options[ddlAdvisoriesSeverity.selectedIndex].text;
        else
            advisorySeverity = "All";
            
        // URL encode string
        advisoryRegion = URLEncode(advisoryRegion);
        advisoryType = URLEncode(advisoryType);
        advisorySeverity = URLEncode(advisorySeverity);
            
        // Build individual query string
        regionQS = "";
        if (advisoryRegion != "All")
            regionQS = "region=" + advisoryRegion;

        typeQS = "";
        if (advisoryType != "")
            typeQS = "type=" + advisoryType;

        severityQS = "";
        if (advisorySeverity != "All")
            severityQS = "priority=" + advisorySeverity;

        // Build query string
        queryString = "";

        if (regionQS != "")
        {
            if (queryString != "")
                queryString += "&" + regionQS;
            else
                queryString = regionQS;
        }
        
        if (typeQS != "")
        {
            if (queryString != "")
                queryString += "&" + typeQS;
            else
                queryString = typeQS;
        }
        if (severityQS != "")
        {
            if (queryString != "")
                queryString += "&" + severityQS;
            else
                queryString = severityQS;
        }

        // Include filter for map boundaries and zoom level
        if (queryString != null && queryString != "")
            queryString += "&" + filterMapBoundariesAndZoomLevel();
        else
            queryString += filterMapBoundariesAndZoomLevel();
            
        // Feature: Add number to the results
        if (queryString != null && queryString != "")
            queryString += "&" + "Numbered=true";
        else
            queryString += "Numbered=true";
            
        // return the query string for retrieving the filtered response
        return queryString;
}// end function



//*******************************************************************************
// Function:     filterCameras
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.2
// Date:         Sep 05, 2006
//
// Description:  The following function returns the filtered cameras path with
//               query string. 
//               This function depends on hardcoded dropdownlist ids to find
//               selected values. 
//               Only data within map boundaries and satisfaction of specified 
//               zoom level are shown.
//
// Parameters:   isFilterByType - indicates whether to filter by type.
// Returns:      Returns the filtered advisories path with query string in order 
//               to retrieve XML response data.
// Calls:        
// Called By:    LoadMapData(), LoadGridData()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
// Michael Chu  Dec 04, 2006 Moved to common.js file because it is being used on initial load.
//*******************************************************************************    
function filterCameras( isFilterByType ) {

// Debug variable (set to 1 to debug)
var debug = 0;

if (debug)
    alert("filterCameras()");
            
        // return the path including query string 
        // for retrieving the filtered response
        return CamerasXmlResponsePath + "?" + filterCamerasQueryString( isFilterByType );
}// end function

//*******************************************************************************
// Function:     filterCamerasQueryString
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.2
// Date:         Sep 05, 2006
//
// Description:  The following function returns the filtered cameras path with
//               query string. 
//               This function depends on hardcoded dropdownlist ids to find
//               selected values. 
//               Only data within map boundaries and satisfaction of specified 
//               zoom level are shown.
//
// Parameters:   isFilterByType - indicates whether to filter by type.
// Returns:      Returns the filtered advisories path with query string in order 
//               to retrieve XML response data.
// Calls:        
// Called By:    LoadMapData(), LoadGridData()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
// Michael Chu  Dec 04, 2006 Moved to common.js file because it is being used on initial load.
//*******************************************************************************    
function filterCamerasQueryString( isFilterByType ) {

// Debug variable (set to 1 to debug)
var debug = 0;

if (debug)
    alert("filterCameras()");
        
        // Retrieve filter criteria selected text values
        ddlCamerasRegion = document.getElementById(CameraRegionSelectName);
        if (ddlCamerasRegion != null)
            cameraRegion = ddlCamerasRegion.options[ddlCamerasRegion.selectedIndex].text;
        else
            cameraRegion = "All";
            ddlCamerasRegion = null;    
//        ddlCameraType = document.getElementById(CameraTypeSelectName);
//        if (ddlCameraType != null)
//            cameraType = ddlCameraType.options[ddlCameraType.selectedIndex].text;
//        else
//            cameraType = "All";
        
        var cameraType = "";
        if (isFilterByType == null || isFilterByType == true)
        {
            var cbx;
            cbx = document.getElementById( "chk_CAM_Border_Grid" );
            if (cbx != null && cbx.checked == true)
                cameraType = "Border";
                
            cbx = document.getElementById( "chk_CAM_TrafficInt_Grid" );
            if (cbx != null && cbx.checked == true)
            {
                if (cameraType == "")
                    cameraType = "Intersection";
                else
                    cameraType += "," + "Intersection";
            }
            cbx = document.getElementById( "chk_CAM_TrafficHigh_Grid" );
            if (cbx != null && cbx.checked == true)
            {
                if (cameraType == "")
                    cameraType = "Highway";
                else
                    cameraType += "," + "Highway";
            }
            cbx = document.getElementById( "chk_CAM_Port_Grid" );
            if (cbx != null && cbx.checked == true)
            {
                if (cameraType == "")
                    cameraType = "Port";
                else
                    cameraType += "," + "Port";
            }

            if (cameraType == "")
                cameraType = "-1"; // return nothing since no checkbox is checked.
        }
        
        ddlCameraStatus = document.getElementById(CameraStatusSelectName);
        if (ddlCameraStatus != null)
            cameraStatus = ddlCameraStatus.options[ddlCameraStatus.selectedIndex].text;
        else
            cameraStatus = "All";
            ddlCameraStatus = null;

if (debug)
{
    alert("cameraRegion: " + cameraRegion);
    alert("cameraType: " + cameraType);
    alert("cameraStatus: " + cameraStatus);
}
        // URL encode string
        cameraRegion = URLEncode(cameraRegion);
        cameraType = URLEncode(cameraType);
        cameraStatus = URLEncode(cameraStatus);
            
        // Build individual query string
        regionQS = "";
        if (cameraRegion != "All")
            regionQS = "region=" + cameraRegion;
        
        typeQS = "";
        if (cameraType != "")
            typeQS = "type=" + cameraType;

        statusQS = "";
        if (cameraStatus != "All")
            statusQS = "status=" + cameraStatus;

        // Build query string
        queryString = "";

        if (regionQS != "")
        {
            if (queryString != "")
                queryString += "&" + regionQS;
            else
                queryString = regionQS;
        }
        
        if (typeQS != "")
        {
            if (queryString != "")
                queryString += "&" + typeQS;
            else
                queryString = typeQS;
        }
        if (statusQS != "")
        {
            if (queryString != "")
                queryString += "&" + statusQS;
            else
                queryString = statusQS;
        }

        // Include filter for map boundaries and zoom level
        if (queryString != null && queryString != "")
            queryString += "&" + filterMapBoundariesAndZoomLevel();
        else
            queryString += filterMapBoundariesAndZoomLevel();
            
        // return the query string for retrieving the filtered response
        return queryString;
}// end function

function debugCouldNotReadMemoryError(datafile, generateFrom)
{
    var len = datafile.length;
    
}

// hide the loading message later based on the number of overlays
function HideLoadingMessage( numberOfOverlays )
{

    if (numberOfOverlays <= 5)
        hideLoading();
    else if (numberOfOverlays <= 20)
    {
        window.setTimeout(hideLoading, 1000);
    }
    else if (numberOfOverlays <= 50)
    {
        window.setTimeout(hideLoading, 2000);
    }
    else if (numberOfOverlays <= 100)
    {
        window.setTimeout(hideLoading, 3000);
    }
    else if (numberOfOverlays <= 200)
    {
        window.setTimeout(hideLoading, 4000);
    }
    else if (numberOfOverlays <= 500)
    {
        window.setTimeout(hideLoading, 5000);
    }
    else
    {
        window.setTimeout(hideLoading, 6000);
    }
  
}

//*******************************************************************************
// Function:     retrieveResourceLocation
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 0.9
// Date:         Dec 07, 2006
//
// Description:  Returns the resource value
//
// Parameters:   resource - name of the resource
// Returns:      Returns the resource value
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
// 
//*******************************************************************************    
function retrieveResourceLocation(resource)
{

    var atisResourcesServicesPath = xmlRootPathService + "AtisResources.aspx";

    // download data from xml
    GDownloadUrl( atisResourcesServicesPath , function( data, responseCode ) 
    {
	    var xml = GXml.parse( data );
	    var resources = [];
	    
	    // XML file related variables
    	var childElementName = "resource";  // the first child element of the root
    	
    	// Parse the resources from the file and store into array
    	resources = xml.documentElement.getElementsByTagName(childElementName);					    
        
	    // Find the resource value
	    for( var i=0; i<resources.length; i++ ) {
    		
    		var name = getNodeValue(resources[i], "name");
    		var value = getNodeValue(resources[i], "value");
    		
            if (name == resource)
            {
                xmlRootPathCommon = value;
                return;
            }
    		
        }
        
        xmlRootPathCommon = "";
        alert("ATIS Service for Resources is unavailable.");
    })
}

//*******************************************************************************
// Function:     retrieveResourceLocationBusRoutes
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 2.0
// Date:         Jan 22, 2007
//
// Description:  Returns the resource value
//
// Parameters:   resource - name of the resource
// Returns:      Returns the resource value
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
// 
//*******************************************************************************    
function retrieveResourceLocationBusRoutes(resource)
{

    var atisResourcesServicesPath = xmlRootPathService + "AtisResources.aspx";

    // download data from xml
    GDownloadUrl( atisResourcesServicesPath , function( data, responseCode ) 
    {
	    var xml = GXml.parse( data );
	    var resources = [];
	    
	    // XML file related variables
    	var childElementName = "resource";  // the first child element of the root
    	
    	// Parse the resources from the file and store into array
    	resources = xml.documentElement.getElementsByTagName(childElementName);					    
        
	    // Find the resource value
	    for( var i=0; i<resources.length; i++ ) {
    		
    		var name = getNodeValue(resources[i], "name");
    		var value = getNodeValue(resources[i], "value");
    		
            if (name == resource)
            {
                xmlRootPathBusRoutes = value;
                return;
            }
    		
        }
        
        xmlRootPathBusRoutes = "";
        alert("ATIS Service for Resources is unavailable.");
    })
}

//*******************************************************************************
// Function:     LoadSystemParams
// Author:       brian.boykochu@cgi.com
// Project:      iMove Build - 0.8
// Date:         Dec 18, 2006
//
// Description:  The function stores all of the system parameters used by ATIS into
//               a global array for later use.               
//
// Parameters:   
// Returns:      GlobalSystemParams multidimesional array
// Calls:        
// Called By:    Load()
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//*******************************************************************************    
function LoadSystemParams(){

    // initialize download response array
	var data = [];
	var datafile="/ATISServices/Services/SystemParams.aspx";

    // download markers data from xml
	GDownloadUrl( datafile, function( data, responseCode ) {
	
        var xml = GXml.parse( data );
        var xmlMarkers = [];        
        

        // Parse the markers from the file and store into array
        xmlMarkers = xml.documentElement.getElementsByTagName("systemParam");
        
        var paramName,paramValue;
       
	        for( var i=0; i<xmlMarkers.length; i++ ) {
	           			        
    		        paramName = new String( getNodeValue(xmlMarkers[i], "parameterName") );        				    		        
    		        paramValue = new String( getNodeValue(xmlMarkers[i], "parameterValue") ); 

                    //store the values in a defined multidimensional array
                    GlobalSystemParams[i] = new AtisSystemParameter( paramName,paramValue );                    
	        } 

     });  //end GDownloadUrl
}


function AtisSystemParameter( paramName, paramValue ) {
    this.paramName = paramName;
    this.paramValue = paramValue;
}


//*******************************************************************************
// Function:     getSystemParameter
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.8
// Date:         Dec 18, 2006
//
// Description:  The function returns a system parameter value, from the passed in
//               parameter name.               
//
// Parameters:   
// Returns:      System Parameter value
// Calls:        
// Called By:    GeneramteGroupMarkers() -- returns URL values for Bus Stop infoboxes
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//*******************************************************************************    

function getSystemParameter( systemParameterName ){

//alert("in get paramter:'" + systemParameterName + "'");

        var lReturnValue;
                
            //loop through the parameters to find a match
            for( var i=0; i<GlobalSystemParams.length; i++ ) {

                    var paramName, paramValue;	        	                
	                paramName = GlobalSystemParams[i].paramName
	                
                    // if the parameter name matches the one requested, return the value
                    if (paramName == systemParameterName){
                        lReturnValue = GlobalSystemParams[i].paramValue                        
                        return lReturnValue;                   
                    }                       
	     } 
	     
	     //if the parameter name is not found, return an error string
	     lReturnValue="SystemParamterMissing";
	     return lReturnValue;
}

//*******************************************************************************
// Function:     ToggleDefaultBusRoutesOnMap
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 1.6
// Date:         Jan 10, 2007
//
// Description:  The function toggles on default bus routes layers on the map.               
//
// Parameters:   
// Returns:      
// Calls:        
// Called By:    InitializeDefaultMapLayers
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//*******************************************************************************    
function ToggleDefaultBusRoutesOnMap()
{

//alert("start toggling defautl bus routes on ");

    // don't recenter map
    isRecenterBusRouteOnMap = false;

    // routeNumber: 97
    // routeName: COQUITLAM STN/LOUGHEED STN (B-LINE) - EAST
    //ToggleBusRouteOnMap('165');  
    ToggleBusRouteOnMap('168');  

    // routeNumber: 98
    // routeName: BURRARD STN/RICHMOND CTR (B-LINE) - SOUTH
    //ToggleBusRouteOnMap('162');  
    ToggleBusRouteOnMap('93');  

    // routeNumber: 99
    // routeName: BROADWAY STN/UBC (B-LINE) - EAST
    //ToggleBusRouteOnMap('194');  
    ToggleBusRouteOnMap('104');  


//alert("finish toggling defautl bus routes on ");

    
}

//*******************************************************************************
// Event:        ZoomLevelChecks
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.3
// Date:         Jan 10, 2007
//
// Description:  This function calls the functions below to hide/show markers.
//
// Parameters:   
// Returns:      
// Calls:        BusRouteZoomCheck(); SkyTrainMarkersZoomCheck(); LandmarksZoomCheck();
// Called By:    Zoom event on map
//
// Revision History:
//*******************************************************************************    
function ZoomLevelChecks(){

        //check to see if we are toggling on any bus route markers
        //BusRouteZoomCheck();
            
        //check to see if we are toggling on non key landmarks
        SkyTrainMarkersZoomCheck();
        
        //check to see if we are toggling on non key landmarks
        LandmarksZoomCheck();
}

//*******************************************************************************
// Function:     BusRouteZoomCheck
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.8
// Date:         Nov 20, 2006
//
// Description:  The following function tests whether to toggle off the 
//               bus route markers layers based on specified zoom level.
//
// Parameters:   
// Returns:      
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************    
function BusRouteZoomCheck(){

    //get the map zoom level
    var zoomLevel = map.getZoom();
    
    //GLog.write(" in BusRouteZoomTest, zoom level is" + zoomLevel);
    
    //get the bus routes cookie
    var busRouteCookie = Get_Cookie( activeBusRoutesCookieName );
       
    if (busRouteCookie != null){
    
        //GLog.write(" BusRouteZoomTest, cookie found" );
    
            if (zoomLevel < 14 ){            		    
                //toggle the bus route markers off 
                toggleBusRouteMarkers( false );    
                //GLog.write(" BusRouteZoomTest, toggled markers off 1 of 1" );            

            } else {        
		        //toggle all markers off, then toggle back on, so there is no duplicate layers
		        //toggle markers off
		        toggleBusRouteMarkers( false );		        
		        //GLog.write(" BusRouteZoomTest, toggled markers off 1 of 2" );            
		        
		        //toggle markers on
		        toggleBusRouteMarkers( true );	        
		        //GLog.write(" BusRouteZoomTest, toggled markers on 2 of 2" );            
	        }
    }

}

//*******************************************************************************
// Function:     toggleBusRouteMarkers
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.8
// Date:         Nov 20, 2006
//
// Description:  The following toggles bus route markers on or off
//               based on input parameter.
//
// Parameters:   visible - indicates whether to toggle on or off
// Returns:      
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************    
function toggleBusRouteMarkers( visible ){
   
    //get the bus routes cookie
    var busRouteCookie = Get_Cookie( activeBusRoutesStopsCookieName );
       
    if (busRouteCookie != null){
    
    //GLog.write(" inside toggle function here");      	
    
        // split the cookie into individual routes
        var partialCookieArr = busRouteCookie.split( "," );
        
        //loop through each Route Id
        for( var i=0; i<partialCookieArr.length-1; i++ ) 
        {
            var rId = partialCookieArr[i];            	        
	        //toggle the marker layer on/off
	        //GLog.write(" toggling visible:" + visible + " for route : " + rId);      	
	        toggleGroup("layer_TRA_Public_Marker_" + rId, visible);  
	        //GLog.write(" done toggling visible:" + visible + " for route : " + rId);      	
        }
    
    }

}

//*******************************************************************************
// Event:        SkyTrainMarkersZoomCheck
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.3
// Date:         Jan 10, 2007
//
// Description:  When the skytrain layers are checked off, this function turns on/off
//               the skytrain markers at zoom level 11
//
// Parameters:   
// Returns:      
// Calls:        
// Called By:    ZoomLevelChecks
//
// Revision History:
//*******************************************************************************    
function SkyTrainMarkersZoomCheck(){

    var cbxControl = document.getElementById("chk_TRA_ExpoLine");
    if (cbxControl.checked == true)
    {
            //get the map zoom level
            var zoomLevel = map.getZoom();
    
            if (zoomLevel > 10 ){     
                //need to toggle layer off first, then back on to avoid duplicate layers
                toggleGroup("layer_ExpoLine_Marker", false);                    
                toggleGroup("layer_ExpoLine_Marker", true);                    
            } else {        
		        toggleGroup("layer_ExpoLine_Marker", false);                    
	        }
    }
cbxControl = null;
    var cbxControl2 = document.getElementById("chk_TRA_MilLine");
    if (cbxControl2.checked == true)
    {
            //get the map zoom level
            var zoomLevel = map.getZoom();
    
            if (zoomLevel > 10 ){     
                //need to toggle layer off first, then back on to avoid duplicate layers
                toggleGroup("layer_MilLine_Marker", false);                    
                toggleGroup("layer_MilLine_Marker", true);                    
            } else {        
		        toggleGroup("layer_MilLine_Marker", false);                    
	        }
    }
    cbxControl2 = null;
}

//*******************************************************************************
// Event:        LandmarksZoomCheck
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.3
// Date:         Jan 10, 2007
//
// Description:  This function initially toggles on the key landmarks layer, and 
//               if the map is at zoom level 11 or greater, also toggles on the
//               non key landmark layer.
//
// Parameters:   
// Returns:      
// Calls:        
// Called By:    ZoomLevelChecks()
//
// Revision History:
//*******************************************************************************    
function LandmarksZoomCheck(){

    var cbxLandmarks = document.getElementById("chk_ROD_Landmarks");
    var cbxNonLandmarks = document.getElementById("chk_ROD_NonKeyLandmarks");
   
    //if the landmarks layer is turned on, then check to see if we need to turn on additional layer
    if (cbxLandmarks.checked == true)
    {
         //only turn on the additional landmarks at zoom level 11 or greater
         if (MapZoomLevelCheck( 11 ))
	     {  cbxNonLandmarks.checked = true;
                         showLoading();  //show the loading message when toggling on the landmarks
             window.setTimeout(hideLoading,3500);

            toggleCheckboxLayer( cbxNonLandmarks );      	                 
         }  else {
            cbxNonLandmarks.checked = false;
            toggleCheckboxLayer( cbxNonLandmarks );      	                 
         }      
    }
    cbxLandmarks = null;
    cbxNonLandmarks = null;

}

//*******************************************************************************
// Event:        toggleLandmarks
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.3
// Date:         Jan 10, 2007
//
// Description:  This function initially toggles on the key landmarks layer, and 
//               if the map is at zoom level 11 or greater, also toggles on the
//               non key landmark layer.
//
// Parameters:   
// Returns:      
// Calls:        
// Called By:    ZoomLevelChecks()
//
// Revision History:
//*******************************************************************************    
function toggleLandmarks(){

    var cbxLandmarks = document.getElementById("chk_ROD_Landmarks");
    var cbxNonLandmarks = document.getElementById("chk_ROD_NonKeyLandmarks");
   
    if (cbxLandmarks.checked == true)
    {
        //turn on the regular landmarks regardless of zoom level
        toggleCheckboxLayer( cbxLandmarks );  
        
         if (MapZoomLevelCheck( 11 ))
	     {
            cbxNonLandmarks.checked = true;
            toggleCheckboxLayer( cbxNonLandmarks );      	                 
         }        
    
    } else {

        //turn off both landmark layers regardless of zoom level
        toggleCheckboxLayer( cbxLandmarks );          
        cbxNonLandmarks.checked = false;
        toggleCheckboxLayer( cbxNonLandmarks );              
    }
    cbxLandmarks = null;
    cbxNonLandmarks = null;

}

//*******************************************************************************
// Event:        toggleBorderCrossingsROD
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.3
// Date:         Aug 15, 2007
//
// Description:  This function initially toggles both Canadian and US border crossing
//               layers on from the Border (Roads) checkbox
//
// Parameters:   
// Returns:      
// Calls:        
// Called By:    
//
// Revision History:
//*******************************************************************************   
function toggleBorderCrossingsROD(){

    var cbxRODBorders = document.getElementById("chk_ROD_Border");
    var cbxRODUSBorders = document.getElementById("chk_ROD_USBorder");
    var cbxCOMBorders = document.getElementById("chk_COM_Border");    
    
    //toggle on/off the ROD/COM border checkbox
    
    if (cbxRODBorders.checked == true )
    {   
        //toggle both border crossings on
        toggleCheckboxLayer( cbxRODBorders );                  
        
        cbxRODUSBorders.checked = true;                
        toggleCheckboxLayer( cbxRODUSBorders );      	                         
        
    } else {
        
        //toggle both border crossings off
        toggleCheckboxLayer( cbxRODBorders );                  
        
        cbxRODUSBorders.checked = false;
        toggleCheckboxLayer( cbxRODUSBorders );        
        
    }
}

//*******************************************************************************
// Event:        toggleBorderCrossingsCOM
// Author:       brian.boyko@cgi.com
// Project:      iMove Build - 0.3
// Date:         Aug 15, 2007
//
// Description:  This function initially toggles both Canadian and US border crossing
//               layers on from the Border (Commercial) checkbox
//
// Parameters:   
// Returns:      
// Calls:        
// Called By:    
//
// Revision History:
//*******************************************************************************   

function toggleBorderCrossingsCOM(){

    var cbxRODBorders = document.getElementById("chk_ROD_Border");
    var cbxRODUSBorders = document.getElementById("chk_ROD_USBorder");
    var cbxCOMBorders = document.getElementById("chk_COM_Border");    
    
    //toggle on/off the ROD/COM border checkbox
    
    if (cbxCOMBorders.checked == true )
    {   
        //toggle both border crossings on
        cbxRODBorders.checked = true;
        toggleCheckboxLayer( cbxRODBorders );                  

        cbxRODUSBorders.checked = true;
        toggleCheckboxLayer( cbxRODUSBorders );        

    } else {
                
        //toggle both border crossings off
        cbxRODBorders.checked = false;
        toggleCheckboxLayer( cbxRODBorders );                  
        
        cbxRODUSBorders.checked = false;
        toggleCheckboxLayer( cbxRODUSBorders );        

    }
}


//*******************************************************************************
// Function:     MapZoomLevelCheck
// Author:       michael.chu@cgi.com
// Project:      iMove Build - 1.6
// Date:         Jan 09, 2007
//
// Description:  The following function indicates whether the specified zoom level
//               satisfies the current map's zoom level. It is used to indicate
//               whether a layer should be shown on the map.
//
// Parameters:   
// Returns:      True to indicate layer should be shown.
// Calls:        
// Called By:    
//
// Revision History:
//
//   Name        Date        Description
//  ------       ------      ------------------------------------------------
//
//*******************************************************************************  
function MapZoomLevelCheck( minZoomLevel )
{
    //get the map zoom level
    var mapZoomLevel = map.getZoom();
    
    if (mapZoomLevel < minZoomLevel )
        return false;
    else
        return true;
    
}


function deleteOldBusCookies(){

            //turn off all the bus route layers as well
            //TurnOffAllExistingBusRouteLayers();

             //delete all active bus route cookies, so they do not persist between sessions
             //eraseCookie( activeBusRoutesCookieName );
            Delete_Cookie( activeBusRoutesCookieName, '/', '' );
            Delete_Cookie( activeBusRoutesStopsCookieName, '/', '' );
            Delete_Cookie( highlightBusRouteCookieName, '/', '' );
            
            Delete_Cookie( FSactiveBusRoutesCookieName, '/', '' );
            Delete_Cookie( FSactiveBusRoutesStopsCookieName, '/', '' );
            Delete_Cookie( FShighlightBusRouteCookieName, '/', '' );


}


function InitializeBusRouteCookies(){

     // Retrieve active tab cookie
    var activeTab = Get_Cookie( 'activeTab' );
    
    switch( activeTab )     
    {                
        case "Motorists" : {                        

            deleteOldBusCookies();
            TurnOnSavedBusRoutes( savedMotoristsBusRoutesCookieName, savedMotoristsBusRoutesStopsCookieName )
            break; 
            
            
        }
        case "Transit" : {

            //check to see if the user has any bus routes saved for the transit tab
            var transitCookie = Get_Cookie( savedTransitBusRoutesCookieName );
            
            //alert("transit cookie is: '" + transitCookie + "'");

            if (transitCookie == null){
            
                //alert("no saved transit bus lines, turn on defaults");
                  
                  //clear all of the old bus route data 
                  deleteOldBusCookies();

                  //toggle the default bus routes on
                  ToggleDefaultBusRoutesOnMap();

                    cbx = document.getElementById( "chk_TRA_WstCstExpr" );
                    cbx.checked = true;
                    toggleLayer( cbx );

                    cbx = document.getElementById( "chk_TRA_ExpoLine" );
                    cbx.checked = true;
                    toggleLayer( cbx );

                    cbx = document.getElementById( "chk_TRA_MilLine" );
                    cbx.checked = true;
                    toggleLayer( cbx );

                    
                    // turn on specific checkboxes and layers
                    //var cbx = document.getElementById( "chk_EV_CurEv" );
                    //cbx.checked = true;
                    //toggleLayer( cbx );
                cbx = null;
            
            } else {
            
                //alert("yes saved transit bus lines, turn them on");
                deleteOldBusCookies();
                TurnOnSavedBusRoutes( savedTransitBusRoutesCookieName, savedTransitBusRoutesStopsCookieName )            
            
            }
                

            //check to see if the user has any bus routes saved for the transit tab
  //          var transitCookie = Get_Cookie( savedTransitBusRoutesCookieName );

//                    if (transitCookie == null){
                        //user does not have any saved bus routes, load the defaults                
                        //eraseCookie( activeBusRoutesCookieName );
                        
                        //deleteOldBusCookies();
                        
                          //alert("toggle defaults on");
                        //ToggleDefaultBusRoutesOnMap();

                            // Create a checkbox control to simulate one on the UI
                          //  if ( moz || op ) {
                            

                        //     } else {                    
                             
                              
                                
                      //       }
                        
                    //} else {                
                        //alert("yes saved transits,do not turn on defaults");
                        //deleteOldBusCookies();
                        //TurnOnSavedBusRoutes( savedTransitBusRoutesCookieName, savedTransitBusRoutesStopsCookieName )            
                    //}


            
            break; 
        }
        case "Cycling" : {            
            deleteOldBusCookies();
            TurnOnSavedBusRoutes( savedCyclingBusRoutesCookieName, savedCyclingBusRoutesStopsCookieName )
            break; 
        }
        case "Gateways" : {
            deleteOldBusCookies();
            TurnOnSavedBusRoutes( savedGatewaysBusRoutesCookieName, savedGatewaysBusRoutesStopsCookieName )
            break; 
        }            
        case "Visitors" : {            
            deleteOldBusCookies();
            TurnOnSavedBusRoutes( savedVisitorsBusRoutesCookieName, savedVisitorsBusRoutesStopsCookieName )
            break; 
        }
        case "Commercial" : {
            deleteOldBusCookies();
            TurnOnSavedBusRoutes( savedCommericalBusRoutesCookieName, savedCommercialBusRoutesStopsCookieName )
            break; 
        }
        
        default: {
            break;
        }
     
    }   
}


function TurnOnSavedBusRoutes( busRoutesTabCookieName, busRouteStopsTabCookieName ){

           //loop through the saved bus routes cookie and turn on the lines as required  
        var savedBusRoutesCooke = Get_Cookie( busRoutesTabCookieName );
        //var savedBusRoutesCooke = Get_Cookie( savedBusRoutesCookieName );
        if (savedBusRoutesCooke != null){
            
            // split the cookie into individual routes
            var partialCookieArr = savedBusRoutesCooke.split( "," );
            //loop through each Route Id
            for( var i=0; i<partialCookieArr.length-1; i++ ) 
            {
                var routeId = partialCookieArr[i];            	        
    	        //add these items to the saves bus routes cookie here
    	       AddOrRemovePartialCookieValue(activeBusRoutesCookieName, routeId, true);

                // Create a checkbox control to simulate one on the UI
                if ( moz || op ) {
                    
                    //create the control in Firefox
                    var control = document.createElement('input');    
                    control.setAttribute('type', 'checkbox');
                    control.setAttribute('checked', 'checked');
                    control.setAttribute('id', 'chk_TRA_Public_Polyline_' + routeId);
                    
                   var d = document.getElementById('contentPrint2');
                   d.appendChild(control);         

                    // toggle on bus route layer on map
                    toggleLayer(control, routeId);      
                    d.removeChild(control); 
                    d = null;       	      
                    
                 } else {                    
                 
                   //create the control in IE
                    var control = document.createElement("<input type='checkbox' id='chk_TRA_Public_Polyline_" + routeId + "' checked='checked'>");
                    document.appendChild(control);         

                    // toggle on bus route layer on map
                    toggleLayer(control, routeId);   
                    document.removeChild(control);  
                }
                
            }
        } 

        //loop through the saved bus stops cookie, and turn on as required
        var savedBusStopsCooke = Get_Cookie( busRouteStopsTabCookieName );
        //var savedBusStopsCooke = Get_Cookie( savedBusRoutesStopsCookieName );
        if (savedBusStopsCooke != null){
            // split the cookie into individual routes
            var partialCookieArr = savedBusStopsCooke.split( "," );
            //loop through each Route Id
            for( var i=0; i<partialCookieArr.length-1; i++ ) 
            {
                var routeId = partialCookieArr[i];            	        
    	        //add these items to the saves bus routes cookie here
    	       AddOrRemovePartialCookieValue(activeBusRoutesStopsCookieName, routeId, true);
    	       
                // Create a checkbox control to simulate one on the UI
                if ( moz || op ) {
                    
                    //create the control in Firefox
                    var control = document.createElement('input');    
                    control.setAttribute('type', 'checkbox');
                    control.setAttribute('checked', 'checked');
                    control.setAttribute('id', 'chk_TRA_Public_Marker_' + routeId);
                    
                   var d = document.getElementById('contentPrint2');
                   d.appendChild(control);         

                    // toggle on bus route layer on map
                    toggleLayer(control, routeId);      
                    d.removeChild(control);  	
                    d = null;            
                    
                 } else {                    
                 
                   //create the control in IE
                    var control = document.createElement("<input type='checkbox' id='chk_TRA_Public_Marker_" + routeId + "' checked='checked'>");
                    document.appendChild(control);         

                    // toggle on bus route layer on map
                    toggleLayer(control, routeId);   
                    document.removeChild(control);
                    control = null;  
                }

            }
        } 

}




//these are turned on when the full screen map loads ...
function TurnOnActiveBusRoutes(){

        //check to see if we have any active bus routes
    
        //loop through full screen cookie    
        var activeBusRoutesCookie = Get_Cookie( activeBusRoutesCookieName );
        
        //alert("turn on these actives:" + activeBusRoutesCookie );
           
        if (activeBusRoutesCookie != null){
        
          //  alert("yes we have saved bus routes");
        
            // split the cookie into individual routes
            var partialCookieArr = activeBusRoutesCookie.split( "," );
            
            //loop through each Route Id
            for( var i=0; i<partialCookieArr.length-1; i++ ) 
            {
                var routeId = partialCookieArr[i];            	        

                        //alert("yes we have saved bus routes 11");

                        //var control = document.createElement("<input type='checkbox' id='chk_TRA_Public_Polyline_" + routeId + "' checked='checked'>");
                        //document.appendChild(control);         

                    // Create a checkbox control to simulate one on the UI
                    if ( moz || op ) {
                        //alert("firefox");
                        //create the control in Firefox
                        var control = document.createElement('input');    
                        control.setAttribute('type', 'checkbox');
                        control.setAttribute('checked', 'checked');
                        control.setAttribute('id', 'chk_TRA_Public_Polyline_' + routeId);
                        
                       var d = document.getElementById('contentPrint2');
                       d.appendChild(control);         

                        // toggle on bus route layer on map
                        toggleLayer(control, routeId);      
                        d.removeChild(control); 
                             d = null; 	      


                     } else {
                        //alert("IE");
                       //create the control in IE
                        var control = document.createElement("<input type='checkbox' id='chk_TRA_Public_Polyline_" + routeId + "' checked='checked'>");
                        document.appendChild(control);         

                        // toggle on bus route layer on map
                        toggleLayer(control, routeId);   
                        document.removeChild(control);
                        control = null;  
                    }

                    //alert("yes we have saved bus routes 22"); 

                    // toggle on bus route layer on map
                    //toggleLayer(control, routeId);      
                    
                    //var dd = document.getElementById('contentPrint2');            
                    //dd.removeChild(control);  	      
            
                    //alert("yes we have saved bus routes 33"); 
    	        
            }
        
    } 
}


//these are turned on when the full screen map loads ...
function TurnOnFullScreenActiveBusRoutes(){

        //check to see if we have any active bus routes
    
        //loop through full screen cookie    
        var FSactiveBusRoutesCookie = Get_Cookie( FSactiveBusRoutesCookieName );
        
        //alert("turn on these actives:" + activeBusRoutesCookie );
           
        if (FSactiveBusRoutesCookie != null){
        
          //  alert("yes we have saved bus routes");
        
            // split the cookie into individual routes
            var partialCookieArr = FSactiveBusRoutesCookie.split( "," );
            
            //loop through each Route Id
            for( var i=0; i<partialCookieArr.length-1; i++ ) 
            {
                var routeId = partialCookieArr[i];            	        

                        //alert("yes we have saved bus routes 11");

                        //var control = document.createElement("<input type='checkbox' id='chk_TRA_Public_Polyline_" + routeId + "' checked='checked'>");
                        //document.appendChild(control);         

                    // Create a checkbox control to simulate one on the UI
                    if ( moz || op ) {
                        //alert("firefox");
                        //create the control in Firefox
                        var control = document.createElement('input');    
                        control.setAttribute('type', 'checkbox');
                        control.setAttribute('checked', 'checked');
                        control.setAttribute('id', 'chk_TRA_Public_Polyline_' + routeId);
                        
                       var d = document.getElementById('contentPrint2');
                       d.appendChild(control);         

                        // toggle on bus route layer on map
                        toggleLayer(control, routeId);      
                        d.removeChild(control);  
                        d = null;	      


                     } else {
                        //alert("IE");
                       //create the control in IE
                        var control = document.createElement("<input type='checkbox' id='chk_TRA_Public_Polyline_" + routeId + "' checked='checked'>");
                        document.appendChild(control);         

                        // toggle on bus route layer on map
                        toggleLayer(control, routeId);   
                        document.removeChild(control);
                        control = null;  
                    }

                    //alert("yes we have saved bus routes 22"); 

                    // toggle on bus route layer on map
                    //toggleLayer(control, routeId);      
                    
                    //var dd = document.getElementById('contentPrint2');            
                    //dd.removeChild(control);  	      
            
                    //alert("yes we have saved bus routes 33"); 
    	        
            }
        
    } 
}
