// ----------------------------------------------------------------
//     				   ArcWeb Services Site Starter Client
// ----------------------------------------------------------------
// Purpose:  Manages "active" navigation functionality.  
//           + Manages map coordinate logic.
//           + Uses DHTML to produce rubber-banding effect 
//             when user zooms in or out.  This is handled
//             by the zoomBox class.
// ----------------------------------------------------------------
// Notes:		
// -------------------------------------------------------------------

// The following variables are global to the page.
	// These vars reference HTML tags in the page whose
	// values may be read or set dynamically.
	var PixelBuffer=120;
	var m_hvsURL;
	var menuFlag;
	var i;
    var m_radZoomIn;
    var m_radZoomOut;
    var m_radRecenter;
    var m_txtXCoord;
    var m_txtYCoord;
    var m_imgLoading;
    var m_imgMapCanvas;
    //var m_treeForm;
    var m_divMapBorder;
    var m_divZoomBox;
	var m_divMapTools;
	//var m_divNorth;
	//var m_divSouth;
	//var m_divEast;
	//var m_divWest;
    var	m_hvMinX;
    var	m_hvMinY;
    var	m_hvMaxX;
    var	m_hvMaxY;
	var m_hvMapPage;
	var m_hvMaxLayers;
	var m_checkbox;
	//4.22.05 - stores layer data in binary 0,1
	var m_layerArray;
	//3.7.07 - added pan flag
	var m_panFlag = 0;

	// These vars represent javascript classes that will
	// handle logic.
    var m_mapViewer;  // Object of type map.  Handles map coordinate management.

    var m_zbxZoom;      // Object of type zoombox.  Handles drawing the zoombox.  
				        // Operates entirely within page coordinates and has no 
				        // awareness of the map space or even the image that 
				        // represents the map on the page.

    var m_iToolMode;    // Indicates the currently selected tool, where
				        //				+ zoom in  = 1
				        //				+ recenter = 2	

	var m_sClientBrowserType;	// Possible values: "IE", "Netscape"
	var m_sClientPlatform;		// Possible values: "Windows","Mac"
    
    		           // The array that stores the level extent widths				  
	var m_ExtentWidths = new Array(500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 128000, 256000, 512000, 1000000, 2000000, 4000000);
	//var m_ExtentWidths = new Array(0.00025, 0.0005, 0.001, 0.002, 0.005, 0.75, 2, 6, 10, 30, 110);

	var m_lTimerID = 1; // used only for hiding the "Wait" image for Netscape 6.x

	// Determine browser type and platform.

	if (navigator.appName.indexOf("Netscape")>=0) {
		m_sClientBrowserType = 'Netscape';
	} else if (navigator.appName.indexOf('Microsoft') >=0) {
		m_sClientBrowserType = 'IE';
	} else {
		window.location = "unsupported.htm";
	}

	if (navigator.userAgent.indexOf("Win") >= 0) {
		m_sClientPlatform = 'Windows';
	} else if (navigator.platform.indexOf("Mac") >= 0) {
		m_sClientPlatform = 'Mac';
	} else {
		window.location = "unsupported.htm";
	}
    

// *******************************************************************
// *********************** STARTUP FUNCTION **************************
// *******************************************************************


function startUp() {

// Purpose: Fires when the page first loads.  


		// Find the HTML tags that will be used throughout the
		// page.
	m_hvsURL = document.getElementById("hvsURL");
	m_currTool = document.getElementById("currTool");
	m_radZoomIn = document.getElementById("radZoomIn");
	m_radZoomOut = document.getElementById("radZoomOut");
	m_radRecenter = document.getElementById("radRecenter");
	m_radIdentify = document.getElementById("radIdentify");
	m_txtXCoord = document.getElementById("txtXCoord");
	m_txtYCoord = document.getElementById("txtYCoord");
	m_imgMapCanvas = document.getElementById("imgMapCanvas");
	// hack to reduce map height by margin to add header graphics to MHTD
	// must set margin-top in smallmap in viewer.css
	// 5.11.05
	i = 0;
	i = m_imgMapCanvas.height;
	i = i - 181;
	m_imgMapCanvas.style.height = i;
	//m_treeForm = document.getElementById("treediv");
    m_imgLoading = document.getElementById("imgLoading");
	m_divZoomBox = document.getElementById("divZoomBox");
	m_divMapBorder = document.getElementById("divMapBorder");
  	//m_divNorth = document.getElementById("divNorth");
  	//m_divSouth = document.getElementById("divSouth");
  	//m_divEast = document.getElementById("divEast");
  	//m_divWest = document.getElementById("divWest");
  	m_divMapTools = document.getElementById("attributediv");
	m_hvMinX = document.getElementById("hvMinX");
	m_hvMinY = document.getElementById("hvMinY");
	m_hvMaxX = document.getElementById("hvMaxX");
	m_hvMaxY = document.getElementById("hvMaxY");
	m_hvMapPage = document.getElementById("hvMapPage");
	m_hvMaxLayers = document.getElementById("hvMaxLayers");
	menuFlag = 0;

		// Create a map coordinate manager.
	m_mapViewer = new map(m_imgMapCanvas.offsetLeft,
  						  m_imgMapCanvas.offsetTop,
						  m_imgMapCanvas.width,	
						  m_imgMapCanvas.height,
						  m_ExtentWidths,
						  new rect(m_hvMinX.value, m_hvMinY.value, m_hvMaxX.value, m_hvMaxY.value)
						  );

		// Create a zoom box.
    m_zbxZoom = new zoomBox(m_divZoomBox);
   
        //Orient other page elements - Map Border, Map Tools, Loading Image, Border Navigation.
    posLoadingImage();
    posBorder();
    posBorderNavigation(); //must be called BEFORE posTools()
    posTools();  //must be called AFTER posBorderNavigation()  

		// Initialize the tool mode. 
	handleToolClick(returnActiveTool());
		
	    // Initialize the X,Y coordinate display.
	m_txtXCoord.value = "X:"
	m_txtYCoord.value = "Y:"

		// Assign custom event handlers to mousedown, mousemove, 
		// and mouseup.
	if (m_sClientBrowserType == 'Netscape') {
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
	}
	document.onmousedown = handleMouseDown;
	document.onmousemove = handleMouseMove;
	document.onmouseup = handleMouseUp;
	
	// Assign an event handler to the m_imgMapCanvas onload event.
	m_imgMapCanvas.onload = hideWaitImage;
	
	var LayerCount = m_hvMaxLayers.value
	
	//alert("There are "+LayerCount+" Layers!");
	
	// Create layer Array
	m_layerArray = new Array(LayerCount)
	
	for (var i = 0; i <= LayerCount - 1; i++) { 
		m_layerArray[i] = 1;
	}
	
	//Request a map.
	submit();
}

// *******************************************************************
// *********************** EVENT HANDLERS  ***************************
// *******************************************************************

function handleMouseDown(evt) {
// Purpose:  Any time a mouse button is depressed, this function
//           is given the opportunity to respond to the event.
//
//           For the purposes of the map, we are only interested
//           in the click if it happened within the map area, so 
//           an initial check kicks us out of the function if the
//           click has not occurred in the map area.
//
//           If the click is over the map, then -- depending on
//           the tool mode -- either the zoombox must be started
//           or a recenter must be performed.


	// Get event coordinates by browser-specific means.
	var eventX;
	var eventY;

	if (m_sClientBrowserType == 'Netscape') {
		eventX = evt.clientX;
		eventY = evt.clientY;
	} else {
		eventX = event.clientX;
		eventY = event.clientY;
	}
	// Check to see if click is over map
	if (!(m_mapViewer.isEventOverMap(eventX, eventY))) {	
		return;
	}
	
	// Check to see if menu is open
	if (!(menuFlag == 0)) {
		//alert("nope!");
		//alert(menuFlag);	
		return;
	} 
	switch(m_iToolMode) {
		case 1: // zoom in mode
			if ((m_sClientBrowserType == 'IE') && (m_sClientPlatform == 'Windows')) {
	  		// For IE, a call to "setCapture" is made to ensure that
				// new IE dragging events do not interfere with capturing 
				// the mousemove events -- effectively, this turns off 
				// drag and drop events temporarily.
				m_imgMapCanvas.setCapture(); 
			}
			m_zbxZoom.show();
			m_zbxZoom.start(eventX, eventY);
			break;
		case 2: // recenter mode
  			var ptUserClick = m_mapViewer.toMapPoint(eventX, eventY);
			m_mapViewer.recenter(ptUserClick);
			//Request a new map.
			submit();
			break;
		case 3: // zoom out mode
			if ((m_sClientBrowserType == 'IE') && (m_sClientPlatform == 'Windows')) {
	  		// For IE, a call to "setCapture" is made to ensure that
				// new IE dragging events do not interfere with capturing 
				// the mousemove events -- effectively, this turns off 
				// drag and drop events temporarily.
				m_imgMapCanvas.setCapture(); 
			}
			m_zbxZoom.show();
			m_zbxZoom.start(eventX, eventY);
			break;
		case 7: // Identify
  			var theBox=GetBuffer(eventX, eventY,PixelBuffer);
  			if (theBox != null)

  			  {  				

			    IdPop(theBox);

			  }
			break;	
	}
}

function IdPop(BOX){

	var BoxArray=BOX.split(",");

	var xmin=BoxArray[0];

	var ymax=BoxArray[1];

	var xmax=BoxArray[2];

	var ymin=BoxArray[3];

	//alert(BOX);

	var sel = document.getElementById("selCoords");

	if (sel != null)

	{

		sel.value = xmin + "," + ymin + "," + xmax + "," + ymax;

		document.frmViewer.submit();

	}

}

function handleMouseMove(evt) {
// Purpose:  Any time the mouse moves anywhere on the document, 
//           this function is given the opportunity to respond to 
//           the event.

	// Get event coordinates by browser-specific means.

	var eventX;
	var eventY;

	if (m_sClientBrowserType == 'Netscape') {
		eventX = evt.clientX;
		eventY = evt.clientY;
	} else {
		eventX = event.clientX;
		eventY = event.clientY;
	}

    // If the mouse isn't currently over the map, we
    // have nothing to do.
	if (!(m_mapViewer.isEventOverMap(eventX, eventY))) {	
		return;
	} 		
	reportCoords(m_mapViewer.toMapPoint(eventX, eventY)); // update the textbox to reflect
																																												 // the current coordinates.
    // If the current tool is zoom in and a zoombox is in progress, update
    // the zoom box.
  if (m_iToolMode == 1 || m_iToolMode == 3) {
		if (m_zbxZoom.isInProgress) {
			m_zbxZoom.update(eventX, eventY);
		}
  }
}

function handleMouseUp(evt) {
	// Purpose:  Any time a mouse button is released, this function is 
	//					 given the opportunity to respond to the event.

		// If a ZoomBox is not in progress, we've got nothing
		// to do.
	if (!(m_iToolMode == 1 || m_iToolMode == 3)) {
		return;
	}
	if (!(m_zbxZoom.isInProgress())) {
		return;
	}
		// Release the capture that was set in the mousedown
		// handler (again, this is something that we have to do because
		// of drag events in IE).
	if ((m_sClientBrowserType == 'IE') && (m_sClientPlatform == 'Windows')) {
		document.releaseCapture();
	}

		// Stop the current effect.
	m_zbxZoom.stop();

		// If the width of the zoom box is less than five pixels,
		// treat is as a single click and zoom in/out one map level.
		// Otherwise, set the extent to the zoom box.
		
	//sb 3.1.07 - moved out of loop
	var nLevels = m_ExtentWidths.length;
	if ((Math.abs(m_zbxZoom.getStartX() - m_zbxZoom.getEndX()) < 5) && (Math.abs(m_zbxZoom.getStartY() - m_zbxZoom.getEndY()) < 5))  {	
		var ptUserClick = m_mapViewer.toMapPoint(m_zbxZoom.getStartX(), m_zbxZoom.getStartY());
		if (m_mapViewer.getLevel() == 1) {   //if we reach the minimum zoom level, zoom a fixed amount.
		  // if zoom in, zoom in fixed
		  if (m_iToolMode == 1) {
		  m_mapViewer.zoom(100);
		  }
		  // if zoom out, zoom out to next level
		  else if (m_iToolMode == 3) {
		  //m_mapViewer.zoom(-100);
		  m_mapViewer.setLevel(m_mapViewer.getLevel() + 1);
		  }
		} else {
		    // if zoom in, zoom in fixed
		  if (m_iToolMode == 1) {
		  m_mapViewer.setLevel(m_mapViewer.getLevel() - 1);
		  }
		  // if zoom out, zoom out to next level
		  else if (m_iToolMode == 3) {
		  	
		  	//check to see if array is at limits, if so, stay at current level
		  	//sb 3.1.07 - fixed state level point zoom issue
		  	if (m_mapViewer.getLevel() == nLevels) {
					m_mapViewer.setLevel(m_mapViewer.getLevel());
				}
				else {
				m_mapViewer.setLevel(m_mapViewer.getLevel() + 1);
				}
		  }		
     }
		m_mapViewer.recenter(ptUserClick);
  } else {
  		borderWidth = 0;
  		if (m_sClientBrowserType == 'Netscape') {
			borderWidth = 4; // 2 times border width
		}
		var ptStart = m_mapViewer.toMapPoint(m_zbxZoom.getStartX()+borderWidth, m_zbxZoom.getStartY()+borderWidth);
		var ptEnd   = m_mapViewer.toMapPoint(m_zbxZoom.getEndX()+borderWidth, m_zbxZoom.getEndY()+borderWidth);
		if (m_iToolMode == 1) {
			m_mapViewer.setExtent(new rect(ptStart.x,ptStart.y,ptEnd.x,ptEnd.y));
		}
		if (m_iToolMode == 3) {
			//eventually implement full zoom box, but for now fake it.
			//alert("Zooming Out");
			var ptUserClick = m_mapViewer.toMapPoint(m_zbxZoom.getStartX(), m_zbxZoom.getStartY());
			
			//check to see if array is at limits, if so, stay at current level
			if (m_mapViewer.getLevel() == nLevels) {
			//alert(nLevels);
			m_mapViewer.setLevel(m_mapViewer.getLevel());
			}
			else {
			m_mapViewer.setLevel(m_mapViewer.getLevel() + 1);
			}
			m_mapViewer.recenter(ptUserClick);
		}
	}
	//Request a new map.
	submit();

}


function handleLayerSelect(layer) {
	//alert(layer);
}

function handleToolClick(iToolMode) {

    //alert(iToolMode);
    // turn on/off appropriate images
    imageOnOff(iToolMode);
	switch(iToolMode) {
		case 1:
			// zoom in mode
			m_imgMapCanvas.style.cursor = "crosshair";
			break;
		case 2:
			// pan mode
			m_imgMapCanvas.style.cursor = "hand";
			break;
		case 3:
			// zoom out mode
			m_imgMapCanvas.style.cursor = "crosshair";
			break;
		case 7:
		    // identify mode
		    m_imgMapCanvas.style.cursor = "hand";
		    break;
	}
	m_iToolMode = iToolMode;
}
function imageOnOff(iToolMode)
{
	var imgZoom = document.getElementById("imgZoomInTool");
	var imgRecenter = document.getElementById("imgRecenterTool");
	var imgZoomOut = document.getElementById("imgZoomOutTool");
	var imgIdentify = document.getElementById("imgIdentifyTool");
	switch(iToolMode) 
	{
		case 1:
			// zoom in mode			
			if (imgZoom != null)
			{				
				imgZoom.src = "images/1_on.gif";
			}
			if (imgRecenter != null)
			{
				imgRecenter.src = "images/2_off.gif";
			}
			if (imgIdentify != null)
			{
				imgZoomOut.src = "images/3_off.gif";
			}
			if (imgIdentify != null)
			{
				imgIdentify.src = "images/7_off.gif";
			}
			break;
		case 2:
			// recenter in mode			
			if (imgZoom != null)
			{
				imgZoom.src = "images/1_off.gif";
			}
			if (imgRecenter != null)
			{
				imgRecenter.src = "images/2_on.gif";
			}
			if (imgIdentify != null)
			{
				imgZoomOut.src = "images/3_off.gif";
			}
			if (imgIdentify != null)
			{
				imgIdentify.src = "images/7_off.gif";
			}
			break;
		case 3:
			//alert("turn image on for identify");
			// identify		
			if (imgZoom != null)
			{
				imgZoom.src = "images/1_off.gif";
			}
			if (imgRecenter != null)
			{
				imgRecenter.src = "images/2_off.gif";
			}
			if (imgIdentify != null)
			{
				imgZoomOut.src = "images/3_on.gif";
			}
			if (imgIdentify != null)
			{
				imgIdentify.src = "images/7_off.gif";
			}
			break;
		case 7:
			//alert("turn image on for identify");
			// identify		
			if (imgZoom != null)
			{
				imgZoom.src = "images/1_off.gif";
			}
			if (imgRecenter != null)
			{
				imgRecenter.src = "images/2_off.gif";
			}
			if (imgIdentify != null)
			{
				imgZoomOut.src = "images/3_off.gif";
			}
			if (imgIdentify != null)
			{
				imgIdentify.src = "images/7_on.gif";
			}
			break;

		default:
			//all off
			if (imgZoom != null)
			{
				imgZoom.src = "images/1_off.gif";
			}
			if (imgRecenter != null)
			{
				imgRecenter.src = "images/2_off.gif";
			}
			if (imgIdentify != null)
			{
				imgZoomOut.src = "images/3_off.gif";
			}
			if (imgIdentify != null)
			{
				imgIdentify.src = "images/7_off.gif";
			}
			break;
		}
}
function ResizeMap(sSize) {

    if (((sSize == 'SMALL') && (m_imgMapCanvas.className == 'SmallMap')) || 
        ((sSize == 'LARGE') && (m_imgMapCanvas.className == 'LargeMap'))) {
        return;
    }
    
    switch(sSize) { 
        case 'SMALL':
        m_imgMapCanvas.className = 'SmallMap';
        break;
        case 'LARGE':
        m_imgMapCanvas.className = 'LargeMap';
        break;
        default: 
        return; // invalid sSize value
    }

        // Create a new map coordinate manager.
    m_mapViewer = new map(m_imgMapCanvas.offsetLeft,
  				    m_imgMapCanvas.offsetTop,
				    m_imgMapCanvas.width,	
				    m_imgMapCanvas.height,
					m_ExtentWidths,
				    m_mapViewer.getExtent()
				    );


        //Orient other page elements - MapSizeImage, Map Border, Map Tools, Loading Image.
    switch(sSize) { 
        case 'SMALL':
        updateImgMapSize('LARGE');
        break;
        case 'LARGE':
        updateImgMapSize('SMALL');
        break;
    }
    
    posLoadingImage();
    posBorder();
    posBorderNavigation(); //must be called BEFORE posTools()
    posTools();  //must be called AFTER posBorderNavigation()

    submit();
}

function ZoomToLevel(iLevel) {           
	m_mapViewer.setLevel(iLevel);
    //Request a new map.
    submit();
}

// *******************************************************************
// ********************** HELPER FUNCTIONS  **************************
// *******************************************************************

function hideWaitImage() {
    m_zbxZoom.hide();
    m_imgLoading.style.visibility = 'hidden';
}

function hideWaitImageForNetscape6() {
	if (m_imgMapCanvas.complete) {
		clearInterval(m_lTimerID);
		m_divZoomBox.style.visibility = 'hidden';
		m_imgLoading.style.visibility = 'hidden';
	}
}

function moveEast() {
    m_mapViewer.moveEast();
     m_panFlag = 1;
    submit();
}

function moveNorth() {
    m_mapViewer.moveNorth();
     m_panFlag = 1;
    submit();
}

function moveSouth() {
    m_mapViewer.moveSouth();
     m_panFlag = 1;
    submit();
}

function moveWest() {
    m_mapViewer.moveWest();
     m_panFlag = 1;
    submit();
}

function persistExtent() {
	m_hvMinX.value = m_mapViewer.getExtent().getLeft();
	m_hvMinY.value = m_mapViewer.getExtent().getBottom();
	m_hvMaxX.value = m_mapViewer.getExtent().getRight();
	m_hvMaxY.value = m_mapViewer.getExtent().getTop();
}

function posBorder() {

    if (m_sClientBrowserType == 'Netscape') { 
		m_divMapBorder.style.left = m_imgMapCanvas.offsetLeft - parseInt(m_divMapBorder.style.borderWidth.replace('px',''));
		m_divMapBorder.style.top = m_imgMapCanvas.offsetTop - parseInt(m_divMapBorder.style.borderWidth.replace('px',''));
	} else { // browser must be IE
		m_divMapBorder.style.left = m_imgMapCanvas.offsetLeft;
		m_divMapBorder.style.top = m_imgMapCanvas.offsetTop;
	}
		
    m_divMapBorder.style.width = m_imgMapCanvas.width;
    m_divMapBorder.style.height = m_imgMapCanvas.height;
    m_divMapBorder.style.visibility = "visible";

}

function posBorderNavigation() {

    var borderOffset = 0;    
    if (m_sClientBrowserType == 'Netscape') {
		borderOffset = parseInt(m_divMapBorder.style.borderWidth.replace('px','')) 
	}
   
          //align the NORTH DIV       
    //m_divNorth.style.top = m_imgMapCanvas.offsetTop - (parseInt(m_divNorth.style.height.replace('px',''))) - borderOffset;
    //m_divNorth.style.left = m_imgMapCanvas.offsetLeft + (m_imgMapCanvas.width / 2)- (parseInt(m_divNorth.style.width.replace('px','')) / 2);    

         //align the SOUTH DIV
    //m_divSouth.style.top = m_imgMapCanvas.offsetTop + m_imgMapCanvas.height + borderOffset;
    //m_divSouth.style.left = m_imgMapCanvas.offsetLeft + (m_imgMapCanvas.width / 2)- (parseInt(m_divSouth.style.width.replace('px','')) / 2);   
  
         //align the EAST DIV       
    //m_divEast.style.top = m_imgMapCanvas.offsetTop + ((m_imgMapCanvas.height / 2) - (parseInt(m_divEast.style.height.replace('px','')) / 2));
    //m_divEast.style.left = m_imgMapCanvas.offsetLeft + m_imgMapCanvas.width + borderOffset;    

         //align the WEST DIV       
    //m_divWest.style.top = m_imgMapCanvas.offsetTop + ((m_imgMapCanvas.height / 2) - (parseInt(m_divWest.style.height.replace('px','')) / 2));
    //m_divWest.style.left = m_imgMapCanvas.offsetLeft - (parseInt(m_divWest.style.width.replace('px',''))) - borderOffset;   
}

function posLoadingImage() {
    m_imgLoading.style.top = (parseInt(m_imgMapCanvas.style.top.replace('px','')) + (m_imgMapCanvas.height / 2) - (m_imgLoading.height / 2) );
    m_imgLoading.style.left = (parseInt(m_imgMapCanvas.style.left.replace('px','')) + (m_imgMapCanvas.width / 2) - (m_imgLoading.width / 2) );
}

function posTools() {
    //m_divMapTools.style.top = parseInt(m_divSouth.style.top.replace('px','')) + parseInt(m_divSouth.style.height.replace('px',''));
    //alert(m_imgMapCanvas.width);
    m_divMapTools.style.left = m_imgMapCanvas.width;
    m_divMapTools.style.height = m_imgMapCanvas.height;
}

function reportCoords(ptReport) {
	// Note: Use round() instead of toFixed(), since the latter isn't supported
  //       in IE Mac.
	m_txtXCoord.value = "X: "+(Math.round(ptReport.x*10000.0)/10000.0).toString();
	m_txtYCoord.value = "Y: "+(Math.round(ptReport.y*10000.0)/10000.0).toString();
}

function returnActiveTool() {
    if (m_currTool.value == 7) {
        return 7;
    } else if (m_radZoomIn.checked) {
		return 1;
	} else if(m_radRecenter.checked) {
		return 2;
	}
}

function showWaitImage() {
	m_imgLoading.style.visibility = 'visible';
}

function submit() {
	var onLayers = ""
	var offLayers = ""	
	// Create string to hold layer #'s - 4.22.05
	for (var i = 0; i <= m_layerArray.length - 1; i++) {
		 switch (m_layerArray[i])	{
		 case 0:
			//alert("Layer off")
			offLayers = offLayers+i+"."
			break
		 case 1:
			//alert("Layer on")
			onLayers = onLayers+i+"."
			break
		 }
	}
	//Trim last period off of string - 4.22.05
	offLayers = offLayers.substring(0, offLayers.length - 1);
	onLayers = onLayers.substring(0,onLayers.length - 1);
	
	var sURL = m_hvMapPage.value+
		         "?XMIN="+m_mapViewer.getExtent().getLeft()+
				     "&YMIN="+m_mapViewer.getExtent().getBottom()+
						 "&XMAX="+m_mapViewer.getExtent().getRight()+
						 "&YMAX="+m_mapViewer.getExtent().getTop()+
						 "&WIDTH="+m_mapViewer.getTagWidth()+
						 "&HEIGHT="+m_mapViewer.getTagHeight()+
						 "&OFFLAYERS="+offLayers+
						 "&ONLAYERS="+onLayers;
						 
  //alert(sURL);
  updateZoomLevel(m_mapViewer.getLevel());
	showWaitImage();

	if (navigator.userAgent.indexOf('Netscape6/6') > -1) {
		m_lTimerID = setInterval("hideWaitImageForNetscape6();",100);
	}
  if(m_iToolMode == 7 && m_hvsURL.value != '' && m_panFlag != 1) {
    m_imgMapCanvas.src = m_hvsURL.value;
  }
  else {
    m_imgMapCanvas.src = sURL;
  }
  //3.13.05
  //ob_t2c('a0');
  
  //5.10.05
  //m_treeForm.src = "treeform.aspx"
  
  //Persist extent in Hidden variables

  persistExtent();	

}

function zoomSegment(minx, miny, maxx, maxy) {
	
	var sURL = m_hvMapPage.value+
		         "?XMIN="+minx+
				     "&YMIN="+miny+
						 "&XMAX="+maxx+
						 "&YMAX="+maxy+
						 "&WIDTH="+m_mapViewer.getTagWidth()+
						 "&HEIGHT="+m_mapViewer.getTagHeight();
  m_mapViewer.setExtent(new rect(minx,miny,maxx,maxy));
  updateZoomLevel(m_mapViewer.getLevel());
	showWaitImage();

	if (navigator.userAgent.indexOf('Netscape6/6') > -1) {
		m_lTimerID = setInterval("hideWaitImageForNetscape6();",100);
	}

  m_imgMapCanvas.src = sURL;

   	
 	  //Persist extent in Hidden variables

  persistExtent();	


}

function updateImgMapSize(sSize) {
    m_imgMapSize = document.getElementById("imgMapSize");
    switch(sSize) { 
        case 'SMALL':
            m_imgMapSize.name = 'SMALL';
            m_imgMapSize.src= 'images/smallmap.gif';
        break;
        case 'LARGE':
            m_imgMapSize.name = 'LARGE';
            m_imgMapSize.src= 'images/largemap.gif';
        break;
    }
}

function updateZoomLevel(inLevel) {
        var nLevels = m_ExtentWidths.length;
		for (i=1;i<nLevels+1;i++) {
			//document.getElementById('imgZoomLevel' + i).src = 'images/tick.gif';
			//if (i==inLevel) {
			//    document.getElementById('imgZoomLevel' + i).src = 'images/tick_selected.gif';
			//}
		}
}

function updateLayers(z) {
		//alert("Updating layers!");
		switch (m_layerArray[z])	{
		 case 0:
			//alert("Layer turned on")
			m_layerArray[z] = 1
			document.getElementById('a' + z).checked = true;
			break
		 case 1:
			//alert("Layer turned off")
			m_layerArray[z] = 0
			document.getElementById('a' + z).checked = false;
			break
		 }
		
				
		submit();
}
