//
// File : bioprojects-rtwgmap-core.js
//
// Description : Javascript functions for core components on the Bioenergy Projects Map
//               implementation. Overrides several functions found in the 
//               RTWGMap's javascript lib
//

 		var mapImage ;
        var markerListing = "";
        var maxPrintableMarkers = 10;
        
	//
	// get all the gmarkers for the specified region
	//
	function getMarkersForRegion(regionId){
    	currentRegionId = regionId;
    	
	    map.closeInfoWindow();    
    	directions.clear();
    	//unapplyFilter();
    	
    	if(directions != null)
           directions.clear();
  
    	// set the map to the center of the region
	    for(var i = 0; i < regions.length; i++)
    	{
        	if(regions[i].id == regionId) {
	            globalRegion = regions[i];
    	        map.setCenter(new GLatLng(regions[i].latitude, regions[i].longitude), regions[i].zoomLevel);
        	    break;
	        }
    	}
    	
        // show all the markers in the current view in the side listings        
        //returnFilteredMarkers( getMarkersInCurrentView() );
	}
	
	
   //
    // print the current listings
    // see printableMarkers, returnFilteredMarkers
    //
    var printCurrentListings = function(title) {
    
   		setCookie("printableMapUrl", getPrintableMapUrl());
   
    
	    top.consoleRef=window.open('/app68/listings/bioprojects/print.jsp','myconsole',
									  'width=600,height=400'
									 +',menubar=0'
									 +',toolbar=1'
									 +',status=0'
								     +',scrollbars=1'
									 +',resizable=1');   	

		//
		//
		//
		markerListing = "<table border='0'>";
		var count = 0;
		for(var i=0;i<printableMarkers.length && count < maxPrintableMarkers; i++) {
				
		    var gmarker = gmarkers[printableMarkers[i].id];           
            if( !gmarker.isHidden() && map.getBounds().contains( gmarker.getPoint() ) ) {                          
    			var character = count + 97; // 'a'

	    		var lat = printableMarkers[i].latitude;
    			var lng = printableMarkers[i].longitude;
    			
    			if(count%2 == 0)
	    			markerListing += "<tr>";
    			
    			markerListing += "<td valign='top'>";
    			markerListing += "<br/><img align='left' alt='A' src='/app21/rtw/icons/maps/red" + unescape("%" + character.toString(16)) + ".png'>";    			
    		    markerListing += "<br/>" + printableMarkers[i].infoHtml;
    		    markerListing += "</td>";
    		    
    			if(count%2 != 0)
	    		    markerListing += "</tr>";
	    		    
    			count ++;
    		}
		}
		markerListing += "</table>";
	
		setTimeout('update()',1000);
    }
 	
 	
 	var update = function() {
		var listings = top.consoleRef.document.getElementById("listings");
		if(listings) {
			listings.innerHTML = markerListing;
			top.consoleRef.focus();
			top.consoleRef.print();
		} else {
			setTimeout('update()',1000);
		}
 	}
 	
 	
 	//
 	//
 	// 	
    var getPrintableMapUrl = function() {    
	     var c = map.getCenter();
	     var xcoord = c.lng();
    	 var ycoord = c.lat();
        var center = ycoord + "," + xcoord;
	   	var mapImgUrl = "";
		mapImgUrl += "http://maps.google.com/staticmap?center=" + center ;
		mapImgUrl += "&zoom=" + map.getZoom();
		mapImgUrl += "&size=500x480";
		mapImgUrl += "&markers=";
		var count = 0;
		for(var i=0;i<printableMarkers.length && count < maxPrintableMarkers; i++) {
				
		    var gmarker = gmarkers[printableMarkers[i].id];           
            if( !gmarker.isHidden() && map.getBounds().contains( gmarker.getPoint() ) ) {                          
    			var character = count + 97; // 'a'

	    		var lat = printableMarkers[i].latitude;
    			var lng = printableMarkers[i].longitude;
    			
    			mapImgUrl += lat + "," + lng;
    			mapImgUrl += ",red" + unescape("%" + character.toString(16));
    			mapImgUrl += "%7C";
    			count ++;
    		}
		}
              
	 	return mapImgUrl;
 	}
 	
 	
 	