
function f71(xIn,yIn) { //getMapXY
		mouseX = xIn;
		pixelX = xDistance / iWidth;
		mapX = pixelX * mouseX + left;
		mouseY = iHeight - yIn;
		pixelY = yDistance / iHeight;
		mapY = pixelY * mouseY + bottom;
}

function f72(e) { //getImageXY
	if (isNav) {
		mouseX=e.pageX;
		mouseY=e.pageY;
	} else {
		mouseX=event.clientX + document.body.scrollLeft;
		mouseY=event.clientY + document.body.scrollTop;
	}
	mouseX = mouseX-hspc;
	mouseY = mouseY-vspc;

}	


function f73(e) { //zoomin
	f71(mouseX,mouseY);
	var tempLeft;
	var tempRight;
	var tempTop;
	var tempBottom;
	addLegendToMap();

	tempLeft = mapX - (xHalf/zoomFactor);
	tempRight = mapX + (xHalf/zoomFactor);
	tempTop = mapY + (yHalf/zoomFactor);
	tempBottom = mapY - (yHalf/zoomFactor);

	if(parent.ScaleFrame.validateScale(f66(tempLeft,tempRight))){
		left = tempLeft;
		right = tempRight;
		top = tempTop;
		bottom = tempBottom;
	}

	sendMapXML();
}

function checkLimits(){
	//ppunter September 2005 fixed top and bottom code.......
    if (limitLeft>left){
		//alert("in left");
		left=limitLeft;
    }
    if (limitRight<right){
		right=limitRight;
		//alert("in right");
    }
    if (limitTop<top){
		//alert("in top");
		top=limitTop;
    }
    if (limitBottom>bottom){
		//alert("in bottom");
		bottom=limitBottom;
    }
}

function f74(e) { //zoomout
	f71(mouseX,mouseY);
	var tempLeft=lastLeft;
	var tempRight=lastRight;
	var tempTop=lastTop;
	var tempBottom=lastBottom;
	addLegendToMap();

	left = mapX - (xDistance*zoomFactor/2);
	right = mapX + (xDistance*zoomFactor/2);
	top = mapY + (yDistance*zoomFactor/2);
	bottom = mapY - (yDistance*zoomFactor/2);
	
	sendMapXML();
}	

function f75(e) { //getMouse
	if (hasf1)
	{
		return;
	}

	window.status="";
	f72(e);

	
	if ((mouseX>iWidth) || (mouseY>iHeight) || (mouseX<=0) ||(mouseY<=0) ) {
		f11(e);
		
	} else {
	
		if ((f73g) || (selectBox)) {
			x2=mouseX;
			y2=mouseY;
			setClip();
		} else if (panning) {
			x2=mouseX;
			y2=mouseY;
			panMouse();	
		}
		pixelX = xDistance / iWidth;
		mapX = pixelX * mouseX + left;
		var theY = iHeight - mouseY;
		pixelY = yDistance / iHeight;
		mapY = pixelY * theY + bottom;
		
		if (toolMode==20) {
			f63(mapX,mapY);	
		} 
		else if (showXYs) {
			var u = Math.pow(10,numDecimals);
			var uX = parseInt(mapX * u + 0.5) / u
			var uY= parseInt(mapY * u + 0.5) / u
			var mouseString = "Map: " + uX + " , " + uY + " -- Image: " + mouseX + " , " + mouseY;	
			if (showScalePercent) mouseString = mouseString + " -- ScaleFactor: " + mapScaleFactor;
			window.status = mouseString;
		}
		//if (navigator.appVersion.indexOf("MSIE 6")!=-1)	f102();
        if(toolMode==13){
			var nn=measureString+" l"+mouseX+","+mouseY+" l"+firstpoint+" e";
			v3(nn);

		//Mackay for markup
		}else if (toolMode==1200) {
		  if(currentshape=="shape"){
			 var nn=draw_Str+" l "+mouseX+","+mouseY+" l "+firstpoint+" e";

			 //window.status =nn;
		  }else{
			var nn=draw_Str+" l "+mouseX+","+mouseY+" e";
		  }
		  showtempDraw(nn);

		}else{
			f102();
        }



	  
	}

		return false;

}

function f76(e) { //startZoomBox
	f35("theMap",hspc,vspc);
	f72(e);	
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
		if (f73g) {
			f77(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			zleft=x1;
			ztop=y1;
			zbottom=y1;
			zright=x1
			f41(x1,y1,x2,y2);
			f73g=true;
			showLayer("zoomBoxTop");
			showLayer("zoomBoxLeft");
			showLayer("zoomBoxRight");
			showLayer("zoomBoxBottom");
			
		}
	}
	return false;
	
}

function f77(e) { //stopZoomBox
	f73g=false;
	if ((zright <zleft+2) && (zbottom < ztop+2)) {
		f73(e);
	} else {
		var tempLeft;
		var tempRight;
		var tempTop;
		var tempBottom;


		pixelX = xDistance / iWidth;
		var theY = iHeight - ztop;
		pixelY = yDistance / iHeight;
		tempTop = pixelY * theY + bottom;
		tempRight = pixelX * zright + left;
		tempLeft = pixelX * zleft + left;
		theY = iHeight - zbottom;
		pixelY = yDistance / iHeight;
		tempBottom = pixelY * theY + bottom;

		if(parent.ScaleFrame.validateScale(f66(tempLeft,tempRight))){
			left = tempLeft;
			right = tempRight;
			top = tempTop;
			bottom = tempBottom;
		}
		window.scrollTo(0,0);

		sendMapXML();
		hideLayer("zoomBoxTop");
		hideLayer("zoomBoxLeft");
		hideLayer("zoomBoxRight");
		hideLayer("zoomBoxBottom");
	}
	return true;

}

function f78(e) { //startzoomoutbox
	f35("theMap",hspc,vspc);
	f72(e);
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
		
		if (f73g) {
			f79(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			zleft=x1;
			ztop=y1;
			zbottom=y1;
			zright=x1
			f41(x1,y1,x2,y2);
			f73g=true;
			showLayer("zoomBoxTop");
			showLayer("zoomBoxLeft");
			showLayer("zoomBoxRight");
			showLayer("zoomBoxBottom");
		}

	}
	return false;
	
}

function f79(e) { //stopzoomoutbox
	f73g=false;
	if ((zright <zleft+2) && (zbottom < ztop+2)) {
		f74(e);
	} else {	
		var tempLeft=lastLeft;
		var tempRight=lastRight;
		var tempTop=lastTop;
		var tempBottom=lastBottom;
		addLegendToMap();
		var zWidth = Math.abs(zright-zleft);
		var zHeight = Math.abs(ztop-zbottom);
		var xRatio = iWidth / zWidth;
		var yRatio = iHeight / zHeight;
		var xAdd = xRatio * xDistance / 2;
		var yAdd = yRatio * yDistance / 2;
		left = left - xAdd;
		right = right + xAdd;
		top = top + yAdd;
		bottom = bottom - yAdd;
		window.scrollTo(0,0);

		sendMapXML();
		hideLayer("zoomBoxTop");
		hideLayer("zoomBoxLeft");
		hideLayer("zoomBoxRight");
		hideLayer("zoomBoxBottom");
	}
	return true;
}

function setClip() { //setClip	
	var tempX=x1;
	var tempY=y1;
	if (x1>x2) {
		zright=x1;
		zleft=x2;
	} else {
		zleft=x1;
		zright=x2;
	}
	if (y1>y2) {
		zbottom=y1;
		ztop=y2;
	} else {
		ztop=y1;
		zbottom=y2;
	}
	
	if ((x1 != x2) && (y1 != y2)) {
		f41(zleft,ztop,zright,zbottom);

	}
	//return false;
}

function f81(e) { //startPan

	f35("theMap",hspc,vspc);

	f72(e);
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
		if (panning) {
			f82(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			panning=true;
		}
	}

	return false;

}

function f82(e) { //stopPan

	window.scrollTo(0,0);
	panning=false;
	var tempLeft=lastLeft;
	var tempRight=lastRight;
	var tempTop=lastTop;
	var tempBottom=lastBottom;
	addLegendToMap();
	var ixOffset = x2-x1;
	var iyOffset = y1-y2;
	pixelX = xDistance / iWidth;
	var theY = iHeight - ztop;
	pixelY = yDistance / iHeight;
	var xOffset = pixelX * ixOffset;
	var yOffset = pixelY * iyOffset;
	top = top - yOffset;
	right = right - xOffset;
	left = left - xOffset;
	bottom = bottom - yOffset;
	
	f68();
	
	hideLayer("theMap");
	if (hasLayer("theMapClicks")) {
		document.theClickImage.src = blankImage;

	}
	sendMapXML();

	return true;
	
}

function panMouse() { //panMouse
	var xMove = x2-x1;
	var yMove = y2-y1;
	var cLeft = -xMove;
	var cTop = -yMove;
	var cRight = iWidth;
	var cBottom = iHeight;
	if (xMove>0) {
		cLeft = 0;
		cRight = iWidth - xMove;
	}
	if (yMove>0) {
		cTop = 0;
		cBottom = iHeight - yMove;
	}
	f39("theMap",cLeft,cTop,cRight,cBottom);
	f35("theMap",xMove+hspc,yMove+vspc);
	if (hasLayer("theMapClicks")) {
		f39("theMapClicks",cLeft,cTop,cRight,cBottom);
		f35("theMapClicks",xMove+hspc,yMove+vspc);

	}
}

function pan(e) {
	f71(mouseX,mouseY);
	var tempLeft=lastLeft;
	var tempRight=lastRight;
	var tempTop=lastTop;
	var tempBottom=lastBottom;
	addLegendToMap();

	left = mapX - xHalf;
	right = mapX + xHalf;
	top = mapY + yHalf;
	bottom = mapY - yHalf;
	sendMapXML();
}	