// Redirects to Nexradmap.aspx
function ClearForm(url)
{
	var ClearForm = parent.navigate(url);
}

//these functions handle the tracking of the mouse on the image map
//credits go to a Mike who posted some of the code on google groups
var IE = document.all?true:false;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

function getLatitude(y)
{
	var latitude = 0;
	/* low 36.97 high 25.45
	* diff = 11.52
	* for 451 pixels */
	var yScaleFactor = 0.025543237250554323725055432372506;
	latitude = 36.97 - y * yScaleFactor;
	return latitude;
}

function getLongitude(x)
{
	var longitude = 0;
	/* low is -108.36 high is -91.76
	* 16.6
	* 641*/
	var xScaleFactor = 0.025897035881435257410296411856474;
	longitude = -108.36	+ x * xScaleFactor;
	return longitude;
}

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) 
{
	if (IE) 
	{ // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.offsetLeft;
		tempY = event.clientY + document.body.offsetTop;
	} else 
	{  // grab the x-y pos.s if browser is NS</FONT>
		tempX = e.pageX;
		tempY = e.pageY;
	}
	// catch possible negative values in NS4
	if (tempX < 0)
		tempX = 0;
	if (tempY < 0)
		tempY = 0;

	displayLatLong(tempX, tempY);
	return true;
}

function displayLatLong(x, y)
{
	var target = document.getElementById('texasMap');
	if(target == null)
		return false;

	var imgX = 0;
	var imgY = 0;
	//var width = target.scrollWidth;
	var height = 0;
	var imageWidth = target.width;
	var imageHeight = target.height;

	for(target; target!= null; target = target.offsetParent)
	{
		imgX += target.offsetLeft;
		imgY += target.scrollTop;
		height += target.offsetTop;
	}

	imgY = height - imgY;

	//the 2 is some random correction factor (probly for a border
	//that's missing)
	var xCoord = x - imgX;
	var yCoord = y - imgY;
	if(xCoord < 0 || xCoord > imageWidth + 1 || yCoord < 0 || yCoord > imageHeight + 1){
		document.getElementById('lblMapLat').innerHTML = '-------';
		document.getElementById('lblMapLong').innerHTML = '--------';
		return false;
	}
	else 
	{
		var lat = getLatitude(y - imgY);
		var longt = getLongitude(x - imgX);

		document.getElementById('lblMapLat').innerHTML = Math.round(lat * 1000) / 1000;
		document.getElementById('lblMapLong').innerHTML = Math.round(longt * 1000) / 1000;
		//document.getElementById('lblDescriptor').innerText = 'X:' + x + ' Y:' + y + ' imgX:'
		//	+ imgX + ' imgY:' + imgY + ' for long:' + (x - imgX) +
		//	' for lat:' + (y - imgY);
		return true;
	}

	//lblMapLat.Text = lat;
	//lblMapLong.Text = longt;
	//alert('lat and long are: ' + lat + ' ' + longt);
}
