function getNewImage()
{
	// Get a new map image using the currently set variables
	//setWaitCursor();
	//alert(layers + ' | ' + drawingSpaceWidth + ' | ' + drawingSpaceHeight + ' | ' + zoomBoxLeft + ' | ' + zoomBoxTop + ' | ' + zoomBoxWidth + ' | ' + zoomBoxHeight);
	//Tracker.NHTMap.GetNewImage(layers, drawingSpaceWidth, drawingSpaceHeight, zoomBoxLeft, zoomBoxTop, zoomBoxWidth, zoomBoxHeight, pv_callback);
	clearReportTree();
	setWaitCursor();
	// Hide the newScale popup
	hideDiv('newScale');

	//setTimeout("Tracker.NHTMap.UpdateSizeAndEnvelope('" + drawingSpaceWidth + "', '" + drawingSpaceHeight + "', '" + zoomBoxLeft + "', '" + zoomBoxTop + "', '" + zoomBoxWidth + "', '" + zoomBoxHeight + "', callback_UpdateWhereString);", 100);
	AjaxTimeStampMap = new Date().getTime();
	setTimeout("Tracker.NHTMap.GetNewImage('" + layers + "', '" + drawingSpaceWidth + "', '" + drawingSpaceHeight + "', '" + zoomBoxLeft + "', '" + zoomBoxTop + "', '" + zoomBoxWidth + "', zoomBoxHeight, pv_callback, '" + AjaxTimeStampMap + "');", 100);
}



function updateNewScale()
{
	// position the popup
	$('newScale').style.left = mouseX + drawingSpaceLeft - 35;
	$('newScale').style.top = mouseY + 10 + drawingSpaceTop;
	
	// Calculate the new scale, roughly based on the width of the zoom box, compared to the original map size, and then multiplied against the current metersperpixel
	
	// First of all, see if the zoombox needs to be artifically extended wider
	// to try to keep the upper/left of the zoom box to be the upper/left of the returned image.  
	var myZW = zoomBoxWidth;
	
	var widthAspectCanvas = drawingSpaceWidth / drawingSpaceHeight;
	var widthAspectZoom = zoomBoxWidth / zoomBoxHeight;
	var widthAspect = widthAspectCanvas / widthAspectZoom;
	if (widthAspect > 1)
	{
		myZW *= widthAspect;
	}
	var pctChange = myZW / drawingSpaceWidth;
	$('newScaleInner').innerHTML = 'Scale 1:' + addCommas(Math.round(pv.metersPerPixel  * pctChange / .000265));

	if ($('newScale').style.display == 'none') { showDiv('newScale'); }
}


function waitForResize()
{
	// I used this timeout routine to keep from calling the resize function too quickly/often.
	//   Say that the user is slowly dragging the size of their browser window, 
	//   I don't want to generate 20 arcims requests for new maps.
	//   Rather with this timeout, I will keep resetting the clock as they drag the screen, 
	//   and ### miliseconds after they finish resizing, it will send the map request.
	clearTimeout(myTimeOut);  myTimeOut = null;
	myTimeOut = setTimeout('executeResize();',550);
}


function executeResize(b)
{
	// Call this routine with executeResize(false) to only resize the windows and global variables without requesting a new map
	var blockMapRequest = (b == false) ? true : false;

	// This first section will calculate the size of the browser window (taking into account the scrollbar h/w) 
	// and resize the drawing space and legend appropriately
	if (IE)
	{
		winW = document.documentElement.offsetWidth-2;
		winH = document.documentElement.offsetHeight-2;
	}
	else
	{
		winW = window.innerWidth-2;
		winH = window.innerHeight-2;
	}
	// Adjust the padding on the Mapcontainer in case the toolbar wrapped to the next line
	$('MapContainer').style.paddingTop = $('titlebardiv').offsetHeight;
	
	// Get the location of the drawing space and status bar and if the Admin Div is showing
	drawingSpaceTop = document.getElementById("DrawingSpace").offsetTop;
	statusbarHeight = document.getElementById("StatusBar").offsetHeight;
	if (document.getElementById("mapResults"))
	{
		adminHeight = document.getElementById("mapResults").offsetHeight;
	}
	else
	{
		adminHeight = 0;
	}
	adminHeight = 0;


	// Make Legend stretch to bottom of window
	document.getElementById("divDataTools").style.height = winH - drawingSpaceTop - 2 - 19;	// 18 is for the Exp/ColAll.  If it did let me calculate the top and bottom borders then I could make this a dynamic number of pixels to subtract.
	// Make DrawingSpace stretch to bottom (minus height of Tabular Report base)
	document.getElementById("DrawingSpace").style.height = winH - drawingSpaceTop - 0 - 22;
	
	// update the global vars for the new drawingSpace size
	var ds = document.getElementById("DrawingSpace");
	drawingSpaceTop = ds.offsetTop;
	drawingSpaceLeft = ds.offsetLeft;
	drawingSpaceHeight = ds.offsetHeight;
	drawingSpaceWidth = ds.offsetWidth;
	
	// Recenter the indicator boxes and images
	$('WaitDiv').style.top = winH / 2 - ($('WaitDiv').offsetHeight / 2);
	$('WaitDiv').style.left = (drawingSpaceWidth / 2) - ($('WaitDiv').offsetWidth / 2) + drawingSpaceLeft;
	$('MapError').style.top = drawingSpaceTop;
	$('MapError').style.left = drawingSpaceLeft;
	$('FilterError').style.top = drawingSpaceTop +20;
	$('FilterError').style.left = drawingSpaceLeft +50;

	// make sure the draggable reportslider can scroll to the correct extent and reset the onDrag function
	ReportSlider.style.left = drawingSpaceLeft;
	ReportSlider.style.width = drawingSpaceWidth + 2; //+1;
	ReportSlider.style.top = TabularReport.offsetTop - ReportSlider.offsetHeight;
	
	TabularReport.style.left = drawingSpaceLeft;
	TabularReport.style.width = drawingSpaceWidth+2;
	
	// Set up the draggable Detailed info box
	var dragCountOutsideOfBounds;	// I use this to help with the start and end drag if the mouse is at the top/bottom of the slide area
	Drag.init(ReportSlider, null, drawingSpaceLeft, drawingSpaceLeft, drawingSpaceTop, winH - (ReportSlider.offsetHeight+2));

	ReportSlider.onDrag = function(x,y) {
		if (y >= winH-(ReportSlider.offsetHeight+2) || y <= drawingSpaceTop) 
		{ 
			// increment the counter, we need to move the mouse outside of the bounds at least 3 times before the drag ends.
			// This is so we can actually 'start' a drag.  If the slider is already at the start/end limits when the drag starts, this y= true and the drag ends
			// By putting a counter on it, I give the user a few mouse moves before I start checking for out of bounds
			dragCountOutsideOfBounds += 1;
			if (dragCountOutsideOfBounds > 2)
			{
				document.onmousemove = falsefunc; 
				document.onmouseup = falsefunc; 
				glassSheetLayer.onselectstart = falsefunc;
				document.onselectstart = falsefunc;
				window.onselectstart = falsefunc;
			}
		}
		var h = winH - y - (ReportSlider.offsetHeight+1);
		//window.status = h + ' ' + drawingSpaceTop + ' ' + (winH - (ReportSlider.offsetHeight+3)) + ' ' + y;
		if (h<1) { h=1; }
		TabularReport.style.height=h;
	}
	
	ReportSlider.onDragStart = function(x,y) {
		// reset the drag counter
		dragCountOutsideOfBounds = 0;
	}

	ReportSlider.onDragEnd = function(x,y) {
		//resizeSummaryDetailTables();
	}

	hideDiv("divIdentify");
	Drag.init($("divIdentify"));


	// Now make sure the Legend and Location divs are visible and not in the upper left corner (0,0)
	// If they resize the screen so the divs are outside the visible range, just reset them to their starting position
	var loc = document.getElementById("Location");
	var locT = loc.style.top.replace("px", "");
	var locL = loc.style.left.replace("px", "");
	
	if ( (locT > winH-10) || (locL > winW-10) || (locT == 0 && locL == 0) )
	{
		loc.style.top = drawingSpaceTop + drawingSpaceHeight - loc.offsetHeight - 4;
		loc.style.left = winW - loc.offsetWidth - 26;
	}

	// make sure the tabular report draggable div isn't above the top of the drawing space
	fixTabularIfTooBig();

	if (blockMapRequest==false)
	{
		// Call the Ajax function to get a new map image
		// (use the panzoom function with the zoom box equal to the canvas size)
		zoomBoxLeft = 0;
		zoomBoxTop = 0;
		zoomBoxWidth = drawingSpaceWidth;
		zoomBoxHeight = drawingSpaceHeight;
		getNewImage();
	}
}


function resetImageLocation()
{
	// I put these here so the img.src has time to load before I move the image so we don't get the flicker/jump
	actualMapImage.style.height = "100%";
	actualMapImage.style.width = "100%";
	actualMapImage.style.left = "0px";
	actualMapImage.style.top = "0px";
	actualMapImage.style.visibility = "visible";
	new Rico.Effect.FadeTo( 'actualMapImage', 1.0, 800, 5, {complete:function() {resetTempImage();}});

	// And set focus on the glass sheet layer
	glassSheetLayer.style.zIndex = 1000;

	setNormalCursor();
}

function resetTempImage()
{
	// Reset the temp image for the next pan/zoom
	//tempPanMapImage.style.zIndex = -1;
	tempPanMapImage.style.left = "0px";
	tempPanMapImage.style.top = "0px";
	tempPanMapImage.style.height = "100%";
	tempPanMapImage.style.width = "100%";
	tempPanMapImage.src = imgDotClear.src;
}


function showHideLayer(layers)
{
//	setWaitCursor();
	// Call the Ajax function to get a new map image with the layer(s) turned on/off
//	NHTMap.PanZoomMap(drawingSpaceWidth, drawingSpaceHeight, 0, 0, drawingSpaceWidth, drawingSpaceHeight, pv_callback);
	AjaxTimeStampMap = new Date().getTime();
	Tracker.NHTMap.ChangeVisibleLayer(layers, drawingSpaceWidth, drawingSpaceHeight, 0, 0, drawingSpaceWidth, drawingSpaceHeight, pv_callback, AjaxTimeStampMap);
}

function popupVisibleSightings()
{
	winVisibleSightings = window.open('VisibleSightings.aspx?minx='+envMinX+'&maxx='+envMaxX+'&miny='+envMinY+'&maxy='+envMaxY+'&w='+drawingSpaceWidth, 'VisibleSightings', 'width=540, height=300, status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1, scrollbars=1');
	if (winVisibleSightings == null)
	{
		alert("Unable to open window. Please be sure to adjust your popup blockers to allow popups from this site.");
	}
	else
	{
		winVisibleSightings.focus();
	}
}

function closeVisibleSightings()
{
	if (winVisibleSightings != null)
	{
		winVisibleSightings.close();
	}
}








