
function dispXY(
    mouseEvent, 
    imageElement, 
    minX, 
    maxX, 
    minY, 
    maxY, 
    latitudeDisplayElement, 
    longitudeDisplayElement,
    eastingDisplayElement, 
    northingDisplayElement, 
    zoneDisplayElement, 
    mapSheetDisplayElement, 
    imgWidth, imgHeight)
{
  // get map properties
  var mapWidth;
  var mapHeight;

  mapWidth  = maxX - minX;
  mapHeight = maxY - minY;
  
  // image cursor location
  var mousePos = getMouseElementPosition(imageElement, mouseEvent);
    
  var imgLcnX = mousePos.x;
  var imgLcnY = imgHeight - mousePos.y;
  
  //map cursor location
  var mapLcnX = ((imgLcnX * mapWidth) / imgWidth) + minX;
  var mapLcnY = ((imgLcnY * mapHeight) / imgHeight) + minY;
    
  //map cursor '250k Map Sheet' - according to the decimal degrees location
  var mapSheet = getMapSheet(mapLcnX, mapLcnY);
  mapSheetDisplayElement.value = mapSheet;
    
  // convert decimal to degrees
  convertDecimal2Degree(mapLcnX, mapLcnY);
  
  latitudeDisplayElement.value = mouseLat;
  longitudeDisplayElement.value = mouseLong;
 
  // convert latlong to MGA rounding easting and northing to 0 decimal places
  convertLatLong2MGA(mapLcnX, mapLcnY);

  eastingDisplayElement.value = Math.round(mouseEast);
  northingDisplayElement.value = Math.round(mouseNorth);
  zoneDisplayElement.value = mouseZone;
  
  //set window status
  var statusTxt;
  statusTxt = insertPadding('Lat:' + mouseLat, 16);
  statusTxt += insertPadding('Long:' + mouseLong, 18);
  statusTxt += insertPadding('|   East:' + Math.round(mouseEast), 16);
  statusTxt += insertPadding('North:' + Math.round(mouseNorth), 16);
  statusTxt += insertPadding('Zone=' + mouseZone, 8);
  statusTxt += '  |  250k Map Sheet: ' + mapSheet;
  window.status = statusTxt;

  if (zooming) {
	x2=mouseX;
	y2=mouseY;
    setClip();
  }
 clearTimeout(mouseOutTimerID);

  return false;
}

function clearXY(latitudeDisplayElement, longitudeDisplayElement,
                 eastingDisplayElement, northingDisplayElement, zoneDisplayElement, mapSheetDisplayElement)
{

  var emptyText = ""

  // clear elements
  latitudeDisplayElement.value = emptyText;
  longitudeDisplayElement.value = emptyText;
  eastingDisplayElement.value = emptyText;
  northingDisplayElement.value = emptyText;
  zoneDisplayElement.value = emptyText;
  mapSheetDisplayElement.value = emptyText;
  
  //Status bar
  window.status = '';

}

function getPageCoords (element) {
  var coords = {x : 0, y : 0};
  while (element) {
    coords.x += element.offsetLeft;
    coords.y += element.offsetTop;
    element = element.offsetParent;
  }
  return coords;
}


function getOffsets (evt) {
  var target = evt.target;
  
  if (typeof target.offsetLeft == 'undefined') {
    target = target.parentNode;
  }
  var pageCoords = getPageCoords(target);
  var eventCoords = { 
    x: window.pageXOffset + evt.clientX,
    y: window.pageYOffset + evt.clientY
  };
  var offsets = {
    offsetX: eventCoords.x - pageCoords.x,
    offsetY: eventCoords.y - pageCoords.y
  }
  return offsets;
}


// get image cursor location
function getImageXY(e)
{

    try
    {
      //Attempt to get mouse coords using W3C method
      var offsetsConverted = getOffsets(e)      
      mouseX = parseInt(offsetsConverted.offsetX);
      mouseY = parseInt(offsetsConverted.offsetY);
    }
    catch (er)
    {
      //W3C method failed, use Microsoft/IE method.
      mouseX = parseInt(e.offsetX);
      mouseY = parseInt(e.offsetY);
    }
}

function insertPadding(txt, pos)
{
  var t = txt;
  var txtSize = txt.length;
  var i;
  if(txtSize < pos) {
    for (i=0; i<pos-txtSize; i++)
    {
      t += '  ';
    }
  }
  return t;
}

function formatNumber(num,precision)
{
  var strNum = num.toString();
  if(strNum.indexOf('.') != -1)
    return parseFloat(strNum.substring(1, strNum.lastIndexOf('.')+precision+1));
  else
    return num;
}

