// -----------------------------------------------------------------
//						Redland Shire Council 
// -----------------------------------------------------------------
// Class    : Coordinate Display 
// Purpose  : Handlers for the events associated with Displaying the 
//			  cursor coordinates.
// -----------------------------------------------------------------
// Calls    :
// Called by: mouseDown within the imgMap object of the default.aspx
// -----------------------------------------------------------------
// Arguments:
// Globals  :
// Returns  :
// -----------------------------------------------------------------
// Notes    : This JavaScript file contains client side code to
//			  display the cursor position in real world coordinates.
// -----------------------------------------------------------------
// History  :
// =================================================================


var Datum="";

function setDatum(sDatum) {
	Datum=sDatum;
	
	var iFrameDoc = getIframeDoc();
	
	if (iFrameDoc) {
		// reset the distance/area display fields
		iFrameDoc.getElementById('tdDatum').innerHTML = "Datum: "+sDatum;
	}
}

function ieMouseDownCoord(event) {
	//Calculate where the map window actually is, and store this in the offset variables
	var imgMapXOffset = parseInt(document.getElementById('divImgMap').style.left) + 2;
	var imgMapYOffset = parseInt(document.getElementById('divImgMap').style.top) + 2;

	//Remember the image coordinates
	var imageX=event.clientX - imgMapXOffset;
	var imageY=event.clientY - imgMapYOffset;
	
	//Calculate the map scale factor
	var scaleFactor = document.getElementById('txtScale').value / (96.000 * 39.3701);
	
	//Now transfer these into map coordinates.
	var mapX=Math.round(parseFloat(document.getElementById("txtMapX").value)+imageX*scaleFactor);
	var mapY=Math.round(parseFloat(document.getElementById("txtMapY").value)-(imageY*scaleFactor));
	
	//Display the corrdinates to the client
	var iFrameDoc = getIframeDoc();
	
	if (iFrameDoc) {
		// reset the distance/area display fields
		iFrameDoc.getElementById('txtEasting2').value = mapX;
		iFrameDoc.getElementById('txtNorthing2').value = mapY;
	}
}

function ieMouseMoveCoord(event) {
	//Calculate where the map window actually is, and store this in the offset variables
	var imgMapXOffset = parseInt(document.getElementById('divImgMap').style.left) + 2;
	var imgMapYOffset = parseInt(document.getElementById('divImgMap').style.top) + 2;

	//Remember the image coordinates
	var imageX=event.clientX - imgMapXOffset;
	var imageY=event.clientY - imgMapYOffset;
	
	//Calculate the map scale factor
	var scaleFactor = document.getElementById('txtScale').value / (96.000 * 39.3701);
	
	//Now transfer these into map coordinates.
	var mapX=Math.round(parseFloat(document.getElementById("txtMapX").value)+imageX*scaleFactor);
	var mapY=Math.round(parseFloat(document.getElementById("txtMapY").value)-(imageY*scaleFactor));
	
	//Display the corrdinates to the client
	//Display the corrdinates to the client
	var iFrameDoc = getIframeDoc();
	
	if (iFrameDoc) {
		// reset the distance/area display fields
		iFrameDoc.getElementById('txtEasting1').value = mapX;
		iFrameDoc.getElementById('txtNorthing1').value = mapY;
		// if the Datum hasn't yet been set, display it now.
		if (iFrameDoc.getElementById('tdDatum').innerHTML=="") {
			iFrameDoc.getElementById('tdDatum').innerHTML = "Datum: "+Datum;
		}
	}
}