// ----------------------------------------------------------------
//     				   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.
	
	//learnmorelink
	//var m_learnmorehref;
	
	
	//varriable for zooming when all zoom levels are omitted
	
	
	var m_ZoomToLevel;
	
	//var m_lblstatus;
    var m_radZoomIn;
    var m_radRecenter;
    var m_radBuffer;
    var m_ddradius;
    
    var m_bf_x;
    var m_bf_y;
    //new one
    var m_radestlatlong;
    
    var m_imgMapCanvas;
   
    var m_divZoomBox;
    
    var m_divSelectBox;
	var m_imgurl;
    
	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_txtfieldx;
	//var m_txtfieldy;
	var m_fieldinfo;
	
	
	
	//for features
	var m_features;
	var m_framefeatures;
	//var m_hvURL;
	
	//var m_trs;
	
	//var m_returnurl;
	
	//var m_imgidentify;
	
	var m_radidentify;
	
	var m_hvtxtfeatures;
	
	

	// 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_zbxSelect;      // Object of type select.  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
				        //				+ info = 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(0.005, 0.015, 0.035, 0.1, 0.3, 0.75, 2, 6, 10, 30, 110);

	var m_lTimerID = 1; // used only for hiding the "Wait" image for Netscape 6.x


//choose of time
    //var m_radArchiveMap;
    var m_hvArchive;
    var m_navArchive;
    var m_hvtype;
    var m_hvyear;
    
    var m_type;
	// 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.
	//learn href
	//alert(" Abu is working right now, please donot hit the site!!!!");
	
	//m_learnmorehref = document.getElementById("learnmorehref");
	//set up zoom level for the variable  m_ZoomToLevel
	
	//alert("This web site is in maintenance now.Please wait until further notice");
	m_ZoomToLevel = 10;
	
	m_radZoomIn = document.getElementById("radZoomIn");
	//m_lblstatus = document.getElementById("lblstatus");
	
	m_imgMapCanvas = document.getElementById("imgMapCanvas");
   
	m_divZoomBox = document.getElementById("divZoomBox");
	
	m_divSelectBox = document.getElementById("divSelectBox");
	m_imgurl = document.getElementById("imgurl");
	
	//m_buffer = document.getElementById("buffer");
	//m_ddradius = document.getElementById("ddradius");
	
	//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("divMapTools");
	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_fieldinfo = document.getElementById("fieldinfo");
	m_hvtxtfeatures = document.getElementById("hvtxtfeatures");
	
	
	//read features
	m_framefeatures = document.getElementById("framefeatures");
	m_features = document.getElementById("features");//for div item
	//alert(document.getElementById("imgidentify"));
	
	//m_imgidentify = document.getElementById("imgidentify");
	
	m_radidentify = document.getElementById("radidentify");
	
	
	m_hvArchive=document.getElementById("hvArchive");
	
	m_navArchive = document.getElementById("navArchive");
	
	m_type = document.getElementById("ddlType");
	m_hvtype = document.getElementById("hvtype");
	m_hvyear = document.getElementById("hvYear");
	//alert("element=" + m_hvtype.value);
	
	
	
	
	var obj=document.getElementById('imgMapCanvas');
	var x = m_imgMapCanvas.offsetLeft;
	var y = m_imgMapCanvas.offsetTop;
	while(obj.offsetParent)
	{
		if(obj==document.getElementsByTagName('body')[0]){break;}
		else{
				x=x+obj.offsetParent.offsetLeft;
				y=y+obj.offsetParent.offsetTop;
				obj=obj.offsetParent;
			}
	} 
	
	


		// Create a map coordinate manager.
	m_mapViewer = new map(x,
  						 y,
						  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);
       //create a select box
       
    m_zbxSelect = new selectBox(m_divSelectBox);
       
   
        //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());
	

		// Assign custom event handlers to mousedown, mousemove, 
		// and mouseup.
	if (m_sClientBrowserType == 'Netscape') {
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
	//alert('I am netscape');
	}
	document.onmousedown = handleMouseDown;
	document.onmousemove = handleMouseMove;
	document.onmouseup = handleMouseUp;
	
	// Assign an event handler to the m_imgMapCanvas onload event.
	m_imgMapCanvas.onload = hideWaitImage;
	
	
	submit();
}

function printmap()
{
var url='';
//alert(m_radBuffer.checked);
if (m_radBuffer.checked){
	url = 'print.aspx?CMD=INIT&XMIN='+m_mapViewer.getExtent().getLeft()+'&YMIN='+m_mapViewer.getExtent().getBottom()+'&XMAX='+m_mapViewer.getExtent().getRight()+'&YMAX='+m_mapViewer.getExtent().getTop()+'&HEIGHT='+m_mapViewer.getTagHeight()+'&WIDTH='+m_mapViewer.getTagWidth()+'&BFRADIUS='+m_ddradius.value +'&BFX=' + m_bf_x.value + '&BFY=' + m_bf_y.value ;
 //window.location.href= url;
   return url;
}
else
{
url = 'print.aspx?CMD=INIT&XMIN='+m_mapViewer.getExtent().getLeft()+'&YMIN='+m_mapViewer.getExtent().getBottom()+'&XMAX='+m_mapViewer.getExtent().getRight()+'&YMAX='+m_mapViewer.getExtent().getTop()+'&HEIGHT='+m_mapViewer.getTagHeight()+'&WIDTH='+m_mapViewer.getTagWidth();
 //window.location.href= url;
 return url;
}


}

// *******************************************************************
// *********************** EVENT HANDLERS  ***************************
// *******************************************************************

function handleMouseDown(e) {
// 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.  evt


	// Get event coordinates by browser-specific means.
	var eventX=0;
	var eventY=0;

	if (m_sClientBrowserType == 'Netscape') {
		//eventX = evt.clientX;
		//eventY = evt.clientY;
		eventX = e.pageX;
		eventY = e.pageY;
	} else {
			//alert("event y=" + event.clientX + "scrolltop=" + document.body.scrollTop);
		eventX = eval(event.clientX) + eval(document.body.scrollLeft);
		eventY = eval(event.clientY) + eval(document.body.scrollTop);
		
	}

	// Check to see if click is over map
	if (!(m_mapViewer.isEventOverMap(eventX, eventY))) {	
		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: //identify/select
		    
		    //m_fieldinfo.style.visibility='hidden';
			//m_features.style.visibility='visible';
		    //var getpoint = m_mapViewer.toMapPoint(eventX, eventY);
			//submitfeatures(getpoint);
			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(); 
			}
			//if (m_sClientBrowserType == 'Netscape') {
			
			//window.captureEvents (Eventc.mousemove); 
			
			//}
			//else
			//{
			//	window.captureEvents(Event.MOUSEMOVE);
			//}
			m_zbxSelect.showSelect();
			m_zbxSelect.startSelect(eventX, eventY);
		    //m_fieldinfo.style.visibility='hidden';
			//m_features.style.visibility='visible';		    
		  break;
		  
	}
}



function handleMouseMove(e) {
// Purpose:  Any time the mouse moves anywhere on the document, 
//           this function is given the opportunity to respond to 
//           the event. evt

	// Get event coordinates by browser-specific means.

	var eventX;
	var eventY;

	if (m_sClientBrowserType == 'Netscape') {
		//eventX = eval(evt.clientX);
		//eventY = eval(evt.clientY);
		eventX = e.pageX;
		eventY = e.pageY;
	} else {
		eventX = eval(event.clientX) + eval(document.body.scrollLeft);
		eventY = eval(event.clientY) + eval(document.body.scrollTop);
		//window.status ='Y:=' + eval(event.clientY) + 'Sc:'+ eval(document.body.scrollTop) + 'totalY:' +eventY ;
	}

    // 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) {
		if (m_zbxZoom.isInProgress) {
			m_zbxZoom.update(eventX, eventY);
		}
  }
  
  /******
  for select tool
  **************/
   if (m_iToolMode == 2){
		if (m_zbxSelect.isInProgressSelect) {
			m_zbxSelect.updateSelect(eventX, eventY);
		}
  }
}

function handleMouseUp(e) {
	// 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. evt
	
	
	/**
	for zoom box
	****/
	if (m_iToolMode == 1)
	{
	
			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();
			}
			//if (m_sClientBrowserType == 'Netscape') {
			
			//window.releaseEvents (Eventc.mousemove);
			
			//}
			
			//else
			//{
			//	window.releaseEvents(Event.MOUSEMOVE);
			//}

				// 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 one map level.
				// Otherwise, set the extent to the zoom box.
			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.
					m_mapViewer.zoom(0.5);
				} else {
					m_mapViewer.setLevel(m_mapViewer.getLevel() - 1);
			}
				m_mapViewer.recenter(ptUserClick);
		} else {
			if (m_mapViewer.getLevel() == 1) {
				var ptUserClick = m_mapViewer.toMapPoint(m_zbxZoom.getStartX(), m_zbxZoom.getStartY());
				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);
				m_mapViewer.setExtent(new rect(ptStart.x,ptStart.y,ptEnd.x,ptEnd.y));
			}
			}
			
			//update the global variable for dynamic zooming without the zoomlevel bars
			m_ZoomToLevel = m_ZoomToLevel -1;
			
			//Request a new map.
			
			submit();
	}
	
	/********************
	for Select box
	**************/
	if (m_iToolMode == 2)
	{
	//alert(" I am here ");
	//alert(m_zbxSelect.isInProgressSelect());
		if (!(m_zbxSelect.isInProgressSelect())) {
				return;
			}
		if ((m_sClientBrowserType == 'IE') && (m_sClientPlatform == 'Windows')) {
				document.releaseCapture();
			}
			//else
			//{
			//  document.releaseCapture();
			//}

				// Stop the current effect.
			m_zbxSelect.stopSelect();
			
			borderWidth = 0;
  				if (m_sClientBrowserType == 'Netscape') {
					borderWidth = 4; // 2 times border width
				}
				var ptStart = m_mapViewer.toMapPoint(m_zbxSelect.getStartXSelect()+borderWidth, m_zbxSelect.getStartYSelect()+borderWidth);
				var ptEnd   = m_mapViewer.toMapPoint(m_zbxSelect.getEndXSelect()+borderWidth, m_zbxSelect.getEndYSelect()+borderWidth);
				if ((ptStart.x==ptEnd.x)&&(ptStart.y==ptEnd.y))
				{
				//ptStart = m_mapViewer.toMapPoint(m_zbxSelect.getStartXSelect()-5, m_zbxSelect.getStartYSelect()-5);
				//ptEnd   = m_mapViewer.toMapPoint(m_zbxSelect.getEndXSelect()+5, m_zbxSelect.getEndYSelect()+5);
				//alert("Draw a box around points first");
				//return;
				ptStart.x = ptStart.x -1;
				ptStart.y = ptStart.y -1;
				ptEnd.x = ptEnd.x + 1;
				ptEnd.y = ptEnd.y + 1;
				}
				m_mapViewer.setExtentFeature(new rect(ptStart.x,ptStart.y,ptEnd.x,ptEnd.y));
	
	
			submitfeatures();
			//var ptUserClick = m_mapViewer.toMapPoint(m_zbxSelect.getStartXSelect()+borderWidth, m_zbxSelect.getStartYSelect()+borderWidth);
			m_mapViewer.recenterfeature();
			 m_imgMapCanvas.src = m_imgurl.value ;
 
 
 
	
	
	
	}
	
	
	
	
			

}

function handleToolClick(iToolMode) {
	switch(iToolMode) {
		case 1:
			// zoom in mode
			m_imgMapCanvas.style.cursor = "crosshair";
			//m_lblstatus.value = "zoom";
			//alert(m_lblstatus.value);
			break;
		case 2:
			//get  aphid info
			m_imgMapCanvas.style.cursor = "crosshair";
			//m_lblstatus.value = "info";
			//alert(m_lblstatus.value);
			break;
		
	}
	m_iToolMode = iToolMode;
}

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();
}

function DynamicZoomToLevel(param){

if (param=='in')
   {
	 
	 if (m_ZoomToLevel == 1)
	   {
		m_ZoomToLevel = m_ZoomToLevel;
	   }
	   else
	   {
		m_ZoomToLevel = m_ZoomToLevel - 1;
	   }
   }
   else  //zoom out
   {
	if (m_ZoomToLevel == 10)
	   {
		m_ZoomToLevel = m_ZoomToLevel;
	   }
	   else
	   {
		m_ZoomToLevel = m_ZoomToLevel + 1;
	   }
   }
 ZoomToLevel(m_ZoomToLevel);
}

// *******************************************************************
// ********************** HELPER FUNCTIONS  **************************
// *******************************************************************

function hideWaitImage() {
    m_zbxZoom.hide();
   // m_zbxSelect.hide();
    //m_imgLoading.style.visibility = 'hidden';
}

function hideWaitImageSelect() {
    m_zbxSelect.hideSelect();
   // m_zbxSelect.hide();
    //m_imgLoading.style.visibility = 'hidden';
}


function hideWaitImageForNetscape6() {
	if (m_imgMapCanvas.complete) {
		clearInterval(m_lTimerID);
		m_divZoomBox.style.visibility = 'hidden';
		//m_divSelectBox.style.visibility = 'hidden';
		//m_imgLoading.style.visibility = 'hidden';
	}
}

function hideWaitImageForNetscape6Select() {
	if (m_imgMapCanvas.complete) {
		clearInterval(m_lTimerID);
		m_divSelectBox.style.visibility = 'hidden';
		//m_divSelectBox.style.visibility = 'hidden';
		//m_imgLoading.style.visibility = 'hidden';
	}
}

function moveEast() {
    m_mapViewer.moveEast();
    submit();
}

function moveNorth() {
    m_mapViewer.moveNorth();
    submit();
}

function moveSouth() {
    m_mapViewer.moveSouth();
    submit();
}

function moveWest() {
    m_mapViewer.moveWest();
    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',''));
   // m_divMapTools.style.width = m_imgMapCanvas.width;
}

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_radZoomIn.checked) {
		return 1;
	} 
	else if(m_radidentify.checked){
	  return 2;
	  }
}

function showWaitImage() {
 
	//m_imgLoading.style.visibility = 'visible';
	//alert(m_imgLoading.style.visibility);
}

function createbuffer(point){
		//alert(" i am here in create buffer");
		var burl = "GetBufferPoint.aspx?ptx=" + point.x + "&pty=" + point.y + "&WIDTH="+m_mapViewer.getTagWidth()+
								"&HEIGHT="+m_mapViewer.getTagHeight()+ "&XMIN="+m_hvMinX.value+
									"&YMIN="+m_hvMinY.value+
									"&XMAX="+m_hvMaxX.value+
									"&YMAX="+m_hvMaxY.value +
									"&RADIUS="+m_ddradius.value;
		//alert(burl);
									
		//fill the values in the hidden boxes
		m_bf_x.value = point.x;
		m_bf_y.value = point.y;
		
		posLoadingImage();
		showWaitImage();
		m_imgMapCanvas.src = burl;

}

function keyvalue(key, initializevalue)
{
var qstring = window.location.href;
var varray = new Array();
var vkey = key + '=';
if (qstring.indexOf(vkey)>-1)
{
	varray = qstring.split(vkey);
	var rsvarray = varray[1];
	if (rsvarray.indexOf("&")>-1)
	{
	 var varray2 = new Array();
	  varray2 = rsvarray.split('&');
	  keyvalue = eval(varray2[0]);
	}
	else
	{
	 keyvalue = eval(varray[1]);
	}
}
else
{
 keyvalue = initializevalue;
}

return keyvalue;
}

function submit() {

//get the queery string ARCHIVE value

var archieve = "0";
 var varray = new Array();
 var qstring = window.location.href;
 if (qstring.indexOf("ARCHIVE=")>0)
 {
	varray = window.location.href.split('ARCHIVE=');
	archieve = eval(varray[1]);
	
 }



  //initialize
 //var archieve = '0';
  //archieve = keyvalue("ARCHIVE",0);
  //alert(" I am her e");
 //var bnbts = '';
 //bnbts = keyvalue('BnBts','');
 // alert (" i am here ");
  //learnmorehref.href = "http://www.syngentacropprotection-us.com/btsTrack/index.asp?BTS=" + bnbts;
 
 
//alert(m_hvyear.value);
  
	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()+
						 "&TYPE="+m_hvtype.value+
						 "&YEAR="+m_hvyear.value;
						 
						 
	//alert ("m_navArchive=" + m_navArchive.value); 
	
  updateZoomLevel(m_mapViewer.getLevel());
  //posLoadingImage();
	//showWaitImage();

	if (navigator.userAgent.indexOf('Netscape6/6') > -1) {
		m_lTimerID = setInterval("hideWaitImageForNetscape6();",100);
	}
 m_imgMapCanvas.src = sURL;
 
 //store the imageURL
 m_imgurl.value = sURL;
   	  //Persist extent in Hidden variables
    persistExtent();	
  //also store the url
  

}


function submitfeatures(){

//get the queery string ARCHIVE value
 var archieve = "0";
 var varray = new Array();
 var qstring = window.location.href;
 if (qstring.indexOf("ARCHIVE=")>0)
 {
	varray = window.location.href.split('ARCHIVE=');
	archieve = eval(varray[1]);
	
 }

	//m_imgMapCanvas.src = "";
	var xmin = m_mapViewer.getExtent().getLeft();
	var xmax = m_mapViewer.getExtent().getRight();
	var ymin = m_mapViewer.getExtent().getBottom();
	var ymax = m_mapViewer.getExtent().getTop();
	
	
	
	
	
	if (navigator.userAgent.indexOf('Netscape6/6') > -1) {
		m_lTimerID = setInterval("hideWaitImageForNetscape6();",100);
	}
	var surlfeatures = "GetFeatures.aspx?XMIN="+xmin+"&YMIN="+ymin+"&XMAX="+xmax+"&YMAX="+ymax + "&TYPE="+m_hvtype.value+ "&YEAR="+m_hvyear.value;
	window.open(surlfeatures, "NematodeWatchDetails", "left=250, top=225, menubar=1,resizable=1,width=360,height=250,scrollbars=1");
   
   
    hideWaitImageSelect();
}


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;
        
        //change from 1 to 2
		//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 archivenav(arcvalue)
{
var geturlp = "";
var geturl = window.location.href;
//alert( 'Abu is developing now ' );
//take out ARCHIVE staff
var locBt = geturl.indexOf('BnBts=');
if (locBt > -1){



	var loc = geturl.indexOf('&ARCHIVE=');
	if (loc > -1)
	{
	var geturlp = geturl.substring(0,loc);
	}
	else
	{
	geturlp = geturl;
	}
	location.href = geturlp +'&ARCHIVE=' + arcvalue;
}
else
{
	var loc = geturl.indexOf('ARCHIVE=');
	if (loc > -1)
	{
	var geturlp = geturl.substring(0,loc);
	}
	else
	{
	geturlp = geturl;
	}
	var locq = geturlp.indexOf('?');
	if (locq > -1)
	{
	location.href = geturlp +'ARCHIVE=' + arcvalue;
	}
	else
	{
	location.href = geturlp +'?ARCHIVE=' + arcvalue;
	}

}


}



