function GetMeterFactor(){
  var lyrName=document.ECWView1.GetLayerName(0);
  var units = document.ECWView1.GetLayerCellUnits(lyrName);
  switch (units) {
    case 1:
      dMeterFactor = 1.0;	  //"Meters"
    break;
    case 2:
      dMeterFactor = 1.0;	  //"DEGREES";
    break;
    case 3:
      dMeterFactor = 0.3048;	  // "FEET";
    break;
    default:
      dMeterFactor = 1.0; // "UNKNOWN";
    break;
  }
}
/**
 * ECWUpdateOverview - update the ECWView with the extents from the overview window, draw the overview rectangle.
 */
function ECWUpdateOverview(dScreenX, dScreenY, dWorldX, dWorldY, bUpdateSlave) {
  var view = (document.ECWView2 == null ? document.ToolPanelForm.ECWView2 : document.ECWView2);

  dWorldTLX = view.GetTopLeftWorldCoordinateX();
  dWorldTLY = view.GetTopLeftWorldCoordinateY();
  dWorldBRX = view.GetBottomRightWorldCoordinateX();
  dWorldBRY = view.GetBottomRightWorldCoordinateY();

  currentExtent=dWorldTLX+","+dWorldBRY+","+dWorldBRX+","+dWorldTLY;

  // Move the current overview rectangle to center around this point.
  OverlayRect.Move(dWorldX, dWorldY, bUpdateSlave);
}

/**
 * ECWUpdateOverviewSlave : The slave updates the overlay rect when it roams or zooms (pass false for update slave since the
 *                          slave is initiating the update, we dont want to recursively call back into ourselves).
 */
function ECWUpdateOverviewSlave(worldTLX, worldTLY, worldBRX, worldBRY) {
	if (OverlayRect != null) {
		OverlayRect.SetRect(worldTLX, worldTLY, worldBRX, worldBRY, false);
	}
  currentExtent=worldTLX+","+worldBRY+","+worldBRX+","+worldTLY;
  //Maßstab
  GetMeterFactor();
  if (theStatus)
    theStatus.showScale(parseInt(9600 * (worldBRX - worldTLX) * dMeterFactor/ (document.ECWView1.GetViewWidth() * 2.54) + 0.5));
}

/**
 * ECWOverviewMouseDown : This is the mouse callback for the plugin on the right tools panel in the overview example.
 */
function ECWOverviewMouseDown(buttonMask, screenx, screeny, worldx, worldy) {
	ECWUpdateOverview(screenx, screeny, worldx, worldy, bUseJavaPlugin ? false : true);
}

/**
 * ECWOverviewMouseMove : This is the mouse callback for the plugin on the right tools panel in the overview example.
 */
function ECWOverviewMouseMove(buttonMask, screenx, screeny, worldx, worldy) {
  ECWUpdateOverview(screenx, screeny, worldx, worldy, bUseJavaPlugin ? false : true);
}

/**
 * ECWOverviewMouseUp : This is the mouse callback for the plugin on the right tools panel in the overview example.
 */
function ECWOverviewMouseUp(buttonMask, screenx, screeny, worldx, worldy) {
	ECWUpdateOverview(screenx, screeny, worldx, worldy, true);
}

function ECWOverviewInitTimer() {
	// On some browsers, calling back into the control on the onload event makes it freeze, so we set of a timer to do it.
	tOverviewLoadTimer = setTimeout('ECWInitOverview()',700);
}

/**
 * ECWInitOverview : Initialize the overlay rectangle class for the overview example.
 */
function ECWInitOverview() {
	var dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY;
      //if (OverlayRect == null) {
		OverlayRect = new NCSOverlayRect();

		var view2 = (document.ECWView2 == null ? document.ToolPanelForm.ECWView2 : document.ECWView2);
		setViewExtentsAll(view2);
		view2.SetPointerMode(2);// Set it to pointer, we dont want it to roam and zoom.
		window.document.ECWView1.SetPointerMode(2); // Set the main view to pointer mode
		OverlayRect.Init(view2, window.document.ECWView1);
		//OverlayRect.Create(-1, -1, -1, -1);
		var view1=(document.ECWView1 == null ? document.ToolPanelForm.ECWView1 : document.ECWView1);
      	dWorldTLX = view1.GetTopLeftWorldCoordinateX();
	      dWorldTLY = view1.GetTopLeftWorldCoordinateY();
      	dWorldBRX = view1.GetBottomRightWorldCoordinateX();
	      dWorldBRY = view1.GetBottomRightWorldCoordinateY();
		OverlayRect.Create(dWorldTLX , dWorldTLY, dWorldBRX, dWorldBRY);
	//}

}

/**
 * ECWLoadOverview : Initialize the overlay rectangle class for the overview example.
 */
function ECWLoadOverview(imgURL) {
      //var dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY;
	var view2 = (document.ECWView2 == null ? document.ToolPanelForm.ECWView2 : document.ECWView2);
      view2.DeleteAllLayers();
	if (view2.AddLayer("ECW", imgURL, "", "") < 0) {
		alert(view2.GetLastErrorText());
	}
	else {
		setTimeout("ECWInitOverview()",500);
	}
}
