
function mapDrawLocatorExtent() {
  // il locator potrebbe non essere valido, allora ignora
	if (document.processa.locator_minx.value == 0 && document.processa.locator_maxx.value == 0) {
		return;
	}
	if (document.processa.locator_miny.value == 0 && document.processa.locator_maxy.value == 0) {
		return;
	}
	var locatorBoxOffsetX = 12; // questo è l'offset della cella che contiene l'immagine, devo farlo a occhio
	var locatorBoxOffsetY = 14;
	var spessore = 2; // deve essere > 1
  // leggi l'extent della mappa
	var mapext = mapGetExtent(); // minx, maxx, miny, maxy
  // leggi l'extent del locator
	var locator_minx = document.processa.locator_minx.value;
	var locator_maxx = document.processa.locator_maxx.value;
	var locator_miny = document.processa.locator_miny.value;
	var locator_maxy = document.processa.locator_maxy.value;
  //alert(locator_minx+","+locator_maxx+","+locator_miny+","+locator_maxy);
  // e la sua larghezza
	var locator_width = document.processa.locator_width.value;
	var locator_height = document.processa.locator_height.value;

  // calcola l'offset
  // su monitor top = 0 bottom = 800, le distanze sono dal top = maxy
	var theLeft = (mapext[0] - locator_minx) * locator_width / (locator_maxx - locator_minx); // pixels
	var theRight = (mapext[1] - locator_minx) * locator_width / (locator_maxx - locator_minx); // pixels
	var theBottom = (locator_maxy - mapext[2]) * locator_height / (locator_maxy - locator_miny); // pixels
	var theTop = (locator_maxy - mapext[3]) * locator_height / (locator_maxy - locator_miny); // pixels

  // comincia a mostrare i layers
	layerShow("locatorBoxTop");
	layerShow("locatorBoxLeft");
	layerShow("locatorBoxRight");
	layerShow("locatorBoxBottom");

	// resetta i limiti dentro le dimensioni e nascondi i limiti esterni
	if (theLeft < 0) {
		theLeft = 0;
		layerHide("locatorBoxLeft");
	}
	if (theRight > locator_width) {
		theRight = locator_width;
		layerHide("locatorBoxRight");
	}
	if (theTop < 0) {
		theTop = 0;
		layerHide("locatorBoxTop");
	}
	if (theBottom > locator_height) {
		theBottom = locator_height;
		layerHide("locatorBoxBottom");
	}

	// ma se sei completamente fuori nascondi tutto
	if (theLeft > locator_width || theRight < 0 || theTop > locator_height || theBottom < 0) {
		layerHide("locatorBoxLeft");
		layerHide("locatorBoxRight");
		layerHide("locatorBoxTop");
		layerHide("locatorBoxBottom");
	}
	theRight = eval(theRight) + locatorBoxOffsetX;
	theLeft = eval(theLeft) + locatorBoxOffsetX;
	theBottom = eval(theBottom) + locatorBoxOffsetY;
	theTop = eval(theTop) + locatorBoxOffsetY;

  // ora aggiusta le dimensioni
  // guarda se le dimensioni sono + piccole di 5 pixels
	if (theRight - theLeft < 5 || theBottom - theTop < 5) {
		var crosshalflen = 5;
		var x = theLeft + (theRight - theLeft) / 2;
		var y = theTop + (theBottom - theTop) / 2;
		layerClip("locatorBoxTop", x - crosshalflen, y - spessore / 2, x + crosshalflen, y + spessore / 2);
		layerClip("locatorBoxBottom", x - crosshalflen, y - spessore / 2, x + crosshalflen, y + spessore / 2);
		layerClip("locatorBoxLeft", x - spessore / 2, y - crosshalflen, x + spessore / 2, y + crosshalflen);
		layerClip("locatorBoxRight", x - spessore / 2, y - crosshalflen, x + spessore / 2, y + crosshalflen);
	} else {
		layerClip("locatorBoxTop", theLeft, theTop, theRight, theTop + spessore);
		layerClip("locatorBoxBottom", theLeft, theBottom - spessore, theRight, theBottom);
		layerClip("locatorBoxLeft", theLeft, theTop, theLeft + spessore, theBottom);
		layerClip("locatorBoxRight", theRight - spessore, theTop, theRight, theBottom);
	}
}

