		var zoomBoxColor = "#FF0000";	// color of zoombox
		var penColor = "#FF0000";	// color of the zoombox
		var penWidth = 2; 	// Zoombox line width;
		
		var iWidth = 402; 	// image width
		var iHeight = 294;	// image height
		var hspc = 0; 		// horizontal image offset
		var vspc = 0; 		// vertical image offset
		var ovBoxSize = 2; 	// Zoombox line width;
		
		/*===================================
		mouse-values
		===================================*/
		var mouseTool = 1; //0== nix, 1==zoomin, 2==zoomout, 3==pan, 4==point, 5==geopkt, 6==rect, 7==polygon, 8==circle, 9==distance
		
		var extentL = 0; // X1-Coordinate of the map in the targetsys (left)
		var extentT = 0; // Y1-Coordinate of the map in the targetsys (top)
		var extentR = 0; // X2-Coordinate of the map in the targetsys (right)
		var extentB = 0; // Y2-Coordinate of the map in the targetsys (bottom)
		
		var leftTopX = 0; 
		var leftTopY = 0; 
		var rightTopX = 0; 
		var rightTopY = 0; 
		var rightBottomX = 0; 
		var rightBottomY = 0; 
		var leftBottomX = 0; 
		var leftBottomY = 0; 		
		
	
		/*===================================
		Global vars for the mouse position
		===================================*/
		var mouseX=0; //global for the mouseposition (X)
		var mouseY=0; //global for the mouseposition (X)

		/*===================================
		Global vars for the Zoombox 
		===================================*/
		var rectLeft=0; //global zoomboxval X1
		var rectTop=0; //global zoomboxval Y1
		var rectRight=0; //global zoomboxval X2
		var rectBottom=0; //global zoomboxval Y2

		/*===================================
		Global vars for moving the map
		===================================*/
		var MapX = -7777; //acutal Map-LEFT position of the map if it is moved
		var MapY = -7777; //acutal Map-TOP position of the map if it is moved
		var aktOffsetX = 0; //acutal Mouse-X position while the map is moved
		var aktOffsetY = 0; //acutal Mouse-Y position of the map if it is moved
		
		
		var zooming = false; // is the map being zoomed
		var moving_it=false; // is the map being moved
		
		// Global vars to save mouse position
		var mouseX=0;
		var mouseY=0;
		var x1=0;
		var y1=0;
		var x2=0;
		var y2=0;
		var zleft=0;
		var zright=0;
		var ztop=0;
		var zbottom=0;
		
		// Global vars for browser type and version
		var isNav = (navigator.appName.indexOf("Netscape")>=0);
		var isNav4 = false;
		var isIE4 = false;
		var is5up = false;
		
		/*===================================
		Global var for saving all Logolayers
		===================================*/
		var logoLayers = new Array();

		/*===================================
		values for points (set in map)
		===================================*/
		var allPoints = new Array(); //--> array: [0]==X, [1] == Y
		var pointDivs = new Array(); // a different DIV for each point
		var pointIndex = 0;
		var pointCounter = 0;
		var symbolPath = "images/geopkt.gif"; //path to a symbol which is displayed when the user sets a point
		var symbolWidth = 32; //width of the symbol
		var symbolHeight = 32; //height of the symbol
		var userSymbol = "";

		/*===================================
		values for polylines and polygons
		===================================*/
		var LastMouseX = -7777; //last MouseXposition when drawing polyline
		var LastMouseY = -7777; //last MouseYposition when drawing polyline
		var lineIndex = 0; //index of array (entries may be empty)
		var closingLineIndex = 0;
		var lineCounter = 0; //actual amount of lines
		var allLinePnts = new Array(); // --> array [0]==LinePointX, [1]==LinePointY, 
		var linesCanvs = new Array(); // a different canvas for each line
		var aCanvas;
		var lastCanv = null;
		var activeLines = 0;
		
		//var degSymbol = "°";
		var degSymbol=String.fromCharCode(176);
		var line_ended = 0;		
		
		var strAP = null;
		

		/*===================================
		symbols for marking position in map
		===================================*/
		var symbolImages = new Array();
		symbolImages[0] = "pfeil.gif"; 
		symbolImages[1] = "autobus.gif"; 
		symbolImages[2] = "gaststaette.gif"; 
		symbolImages[3] = "tennis.gif"; 
		symbolImages[4] = "standort.gif"; 
		symbolImages[5] = "telefon.gif"; 
		symbolImages[6] = "tankstelle.gif"; 
		symbolImages[7] = "beherbergung.gif"; 
		symbolImages[8] = "minigolf.gif"; 
		symbolImages[9] = "start.gif"; 
		symbolImages[10] = "toilette.gif"; 
		symbolImages[11] = "eisenbahn.gif"; 
		symbolImages[12] = "zelten.gif"; 
		symbolImages[13] = "kegeln.gif"; 
		symbolImages[14] = "treffpunkt.gif"; 
		symbolImages[15] = "information.gif"; 
		symbolImages[16] = "parken.gif"; 
		symbolImages[17] = "kinderspielplatz.gif"; 
		symbolImages[18] = "schwimmen.gif"; 
		symbolImages[19] = "ziel.gif"; 
		
		var symbolOffsetsX = [-35,17,17,17,12,17,17,17,17,12,17,17,17,17,12,17,17,17,17,12];
		var symbolOffsetsY = [10,-16,-16,-16,8,-16,-16,-16,-16,8,-16,-16,-16,-16,8,-16,-16,-16,-16,8];

		
		


		if (isNav) {
			
			if (parseFloat(navigator.appVersion)<5) {
				isNav4=true;
			} else {
				is5up = true;
			}
		} else {
			isIE4=true;
			if (navigator.appVersion.indexOf("MSIE 5")>0) {
				isIE4 = false;
				is5up = true;
			}
		}
		
		function startUp() {		
			if (isNav) {
				document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP | Event.DBLCLICK);
			} 
			document.onmousedown = doMouseDown;
			document.onmouseup = doMouseUp;
			document.onmousemove = doMouseMove;
			document.ondblclick = doDblClick;
		}
		
		function doDblClick(e){
			if (mouseTool == 5){
				getImageXY(e);				
				
				
				if ((mouseX >= 0 && mouseX <= mapWidth) && (mouseY >= 0 && mouseY <= mapHeight)) {										
			
					offX = mouseX + mapLeft;
					offY = mouseY + mapTop;								
					setPoint(offX,offY,false);
					f = document.forms['mapForm'];
					aP = f.allLines;
					skn = f.SKN.value;					
					linesVal = aP.value;
					lineVals = linesVal.split('@');	
					//alert(xy.length);
					
					activeLines = 0;					
					
					url = "detailWin.php?lines=" + linesVal + "&task=1&SKN=" + skn;
					//aP.value = "";
					LastMouseX = -7777; 
					LastMouseY = -7777; 
					
					if (lineVals.length < 20)
						newwin = window.open(url,'detailWin','width=600,height=407,toolbar=0,location=no,directories=no,scrollBars=no,resizable=no');
					else{						
						newwin = window.open(url,'detailWin','width=600,height=407,toolbar=0,location=no,directories=no,scrollbars=no,resizable=no');
						newwin.close();
						newwin = window.open(url,'detailWin','width=600,height=407,toolbar=0,location=no,directories=no,scrollBars=yes,resizable=no');
						
					}
					newwin.focus();			
					aP.value = "ENDED" + aP.value;
					line_ended = 1;
				}
			}
			return false;
		}
		
		// Allgemeine Einstellungen
		function generalSettings(iw,ih,hs,vs,coordL,coordT,coordR,coordB) {
			mapWidth = iw;
			mapHeight = ih;
			mapLeft = hs;
			mapTop = vs;	
			mapLeftInit = hs;
			mapTopInit = vs;
			
			extentL = parseFloat(coordL);
			extentT = parseFloat(coordT); 
			extentR = parseFloat(coordR); 
			extentB = parseFloat(coordB); 			
			
			
			//window.status = extentL + " / " + extentT + " / " + extentR + " / " + extentB
			//window.status = Math.round(leftTopX*100000) + " / " + Math.round(leftTopY*100000) + " / " + Math.round(rightTopX*100000) + " / " + Math.round(rightTopY*100000) + " / " + Math.round(rightBottomX*100000) + " / " + Math.round(rightBottomY*100000) + " / " + Math.round(leftBottomX*100000) + " / " + Math.round(leftBottomY*100000);
			//window.status = leftTopX + " / " + leftTopY + " / " + rightBottomX + " / " + rightBottomY; // + " / " rightBottomX + " / " rightBottomY + " / " leftBottomX + " / " leftBottomY;
			//window.status = leftTopY - leftTopX;
			
		
		   iWidth = iw;
		   iHeight = ih;
		   hspc = hs;
		   vspc = vs;	   
		}		
		
		//GEO_WGS84 Koordinaten setzen
		function setGEOWGS(ltX,ltY,rtX,rtY,rbX,rbY,lbX,lbY){
			leftTopX = parseFloat(ltX); 
			leftTopY = parseFloat(ltY); 
			rightTopX = parseFloat(rtX); 
			rightTopY = parseFloat(rtY); 
			rightBottomX = parseFloat(rbX); 
			rightBottomY = parseFloat(rbY); 
			leftBottomX = parseFloat(lbX); 
			leftBottomY = parseFloat(lbY); 			
		}
		
		//UTM Koordinaten setzen
		function setUTMCoords(ltX,ltY,rtX,rtY,rbX,rbY,lbX,lbY,zone){
			leftTopX_utm = Math.round(parseFloat(ltX)); 
			leftTopY_utm = Math.round(parseFloat(ltY)); 
			rightTopX_utm = Math.round(parseFloat(rtX)); 
			rightTopY_utm = Math.round(parseFloat(rtY)); 
			rightBottomX_utm = Math.round(parseFloat(rbX)); 
			rightBottomY_utm = Math.round(parseFloat(rbY)); 
			leftBottomX_utm = Math.round(parseFloat(lbX)); 
			leftBottomY_utm = Math.round(parseFloat(lbY)); 
			zone_utm = zone;						
		}
		
			
		/*
		***************************************************************************************
		
		DHTML layer functions - used to create and manipulate style sheets
			These functions are used by the ArcIMS HTML Viewer - found in aimsDHTML.js
		
		***************************************************************************************
		*/
		
		// Create a DHTML layer
		function createLayer(name, inleft, intop, width, height, visible, content) {
			  var layer;			  
			  if (isNav4) {
			    document.writeln('<layer name="' + name + '" left=' + inleft + ' top=' + intop + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') +  '>');
			    document.writeln(content);
			    document.writeln('</layer>');
			  } else {
			    document.writeln('<div id="' + name + '" style="position:absolute; overflow:hidden; left:' + inleft + 'px; top:' + intop + 'px; width:' + width + 'px; height:' + height + 'px;' + '; z-index:1; visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
			    document.writeln(content);
			    document.writeln('</div>');
			  }
		}
		
		// Create a DHTML layer
		function createLayer2(name, inleft, intop, width, height, visible, content, zindex) {
			  var layer;			  
			  if (isNav4) {
			    document.writeln('<layer name="' + name + '" left=' + inleft + ' top=' + intop + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') +  '>');
			    document.writeln(content);
			    document.writeln('</layer>');
			  } else {
			    document.writeln('<div id="' + name + '" style="position:absolute; overflow:hidden; left:' + inleft + 'px; top:' + intop + 'px; width:' + width + 'px; height:' + height + 'px;' + '; z-index:' + zindex + '; visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
			    document.writeln(content);
			    document.writeln('</div>');
			  }
		}
		
		// get the layer object called "name"
		function getLayer(name) {
			  if (isNav4)
			    return(document.layers[name]);
			  else if (isIE4) {
			    layer = eval('document.all.' + name + '.style');
			    return(layer);
			  } else if (is5up) {
					var theObj = document.getElementById(name);
					return theObj.style
			  }
			  else
			    return(null);
		}
				
		function isVisible(name) {
			  var layer = getLayer(name);
			  if (isNav && layer.visibility == "show")
			    return(true);
			  if (isIE4 && layer.visibility == "visible")
			    return(true);
			  return(false);
		}
		
		
		// move layer to x,y
		function moveLayer(name, x, y) {		
		  	var layer = getLayer(name);		
		  	if (isNav4)
		    	layer.moveTo(x, y);
		  	//if (document.all) {
			 else {
		    	layer.left = x + "px";
		   		 layer.top  = y + "px";
		  	}
		}
		
		// set layer background color
		function setLayerBackgroundColor(name, color) {		
		  	var layer = getLayer(name);		
		 	 if (isNav4)
		    	layer.bgColor = color;
		  	//else if (document.all)
			else {
					if (layer != null)
		    		layer.backgroundColor = color;
		  }
		}
		
		// toggle layer to invisible
		function hideLayer(name) {		
		  	var layer = getLayer(name);		
		  	if (isNav4)
		    	layer.visibility = "hide";
		  	//if (document.all)
			else
		   		 layer.visibility = "hidden";
				 //layer.display="none";
		}
		
		// toggle layer to visible
		function showLayer(name) {		
		  	var layer = getLayer(name);		
		  	if (isNav4)
		    	layer.visibility = "show";
		  	//if (document.all)
			else
		   	 layer.visibility = "visible";
			 //layer.display="block";
		}
		
		// clip layer display to clipleft, cliptip, clipright, clipbottom
			// Not working with Mozilla Milestone 12 (Nav5)
		function clipLayer2(name, clipleft, cliptop, clipright, clipbottom) {		
			  var layer = getLayer(name);		
			  if (isNav4) {
				    layer.clip.left   = clipleft;
				    layer.clip.top    = cliptop;
				    layer.clip.right  = clipright;
				    layer.clip.bottom = clipbottom;
			  }
			  //if (document.all)
			  else {
				    layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
			  }
		}
		
		function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {		
			  var layer = getLayer(name);		
			  if (isNav4) {
				    layer.clip.left   = clipleft;
				    layer.clip.top    = cliptop;
				    layer.clip.right  = clipright;
				    layer.clip.bottom = clipbottom;
			  }	  else {
					var newWidth = clipright - clipleft;
					var newHeight = clipbottom - cliptop;
					layer.height = newHeight;
					layer.width	= newWidth;
					layer.top	= cliptop + "px";
					layer.left	= clipleft + "px";
				}
		
		}

		function boxIt(theLeft,theTop,theRight,theBottom) {				
			  if (isNav4){
					clipLayer("zoomBoxTop",theLeft,theTop,theRight,theTop+ovBoxSize);
					clipLayer("zoomBoxLeft",theLeft,theTop,theLeft+ovBoxSize,theBottom); //clipLayer("zoomBoxLeft",theLeft,theTop,theLeft+ovBoxSize,theBottom);
					clipLayer("zoomBoxRight",theRight-ovBoxSize,theTop,theRight,theBottom);
					clipLayer("zoomBoxBottom",theLeft,theBottom-ovBoxSize,theRight,theBottom);	
			  } else {
					clipLayer("zoomBoxTop",theLeft+hspc,theTop+vspc,theRight+hspc,theTop+ovBoxSize+vspc);
					clipLayer("zoomBoxLeft",theLeft+hspc,theTop+vspc,theLeft+ovBoxSize+hspc,theBottom+vspc); //clipLayer("zoomBoxLeft",theLeft,theTop,theLeft+ovBoxSize,theBottom);
					clipLayer("zoomBoxRight",theRight-ovBoxSize+hspc,theTop+vspc,theRight+hspc,theBottom+vspc);
					clipLayer("zoomBoxBottom",theLeft+hspc,theBottom-ovBoxSize+vspc,theRight+hspc,theBottom+vspc);	
				}
				showLayer("zoomBoxTop");
				showLayer("zoomBoxLeft");
				showLayer("zoomBoxRight");
				showLayer("zoomBoxBottom");
		}
		
		//draw the zoombox
		function drawZoombox(theLeft,theTop,theRight,theBottom) {	
			clipLayer("zoomBoxTop",theLeft+mapLeft,theTop+mapTop,theRight+mapLeft,theTop+penWidth+mapTop);
			clipLayer("zoomBoxLeft",theLeft+mapLeft,theTop+mapTop,theLeft+penWidth+mapLeft,theBottom+mapTop); 
			clipLayer("zoomBoxRight",theRight-penWidth+mapLeft,theTop+mapTop,theRight+mapLeft,theBottom+mapTop);
			clipLayer("zoomBoxBottom",theLeft+mapLeft,theBottom-penWidth+mapTop,theRight+mapLeft,theBottom+mapTop);	
			showLayer("zoomBoxTop");
			showLayer("zoomBoxLeft");
			showLayer("zoomBoxRight");
			showLayer("zoomBoxBottom");
		}
		
		
	
		/*
		***************************************************************************************
		
		Navigation functions - used to resize zoom box
			Extended versions of these functions are used by the ArcIMS HTML Viewer - found in aimsNavigation.js
		
		***************************************************************************************
		*/
		
		// get cursor location
		function getImageXY(e) {
			if (isNav) {
				mouseX=e.pageX;
				mouseY=e.pageY;
			} else {
				mouseX=event.clientX + document.body.scrollLeft;
				mouseY=event.clientY + document.body.scrollTop;
			}
			// subtract offsets from page left and top
			mouseX = mouseX-hspc;
			mouseY = mouseY-vspc;		
		}	

		// start zoom in.... box displayed
		function startZoomBox(e) {
			moveLayer("theMap",hspc,vspc);
			//moveLayer("theTransparentMapLayer",hspc,vspc); //bg: man weiss nicht, ob mans braucht
			getImageXY(e);	
			// keep it within the MapImage
			if ((mouseX<iWidth) && (mouseY<iHeight)) {
				if (zooming) {
					stopZoomBox(e);
				} else {
					rectLeft=mouseX;
					rectTop=mouseY
					rectRight=rectLeft+1;
					rectBottom=rectTop+1;
					drawZoombox(rectLeft,rectTop,rectRight,rectBottom);					
					zooming=true;					
				}
			}
			return false;
			
		}
		
		// stop zoom box display... 
		function stopZoomBox(e) {
			
			zooming=false;
			/*
			hideLayer("zoomBoxTop");
			hideLayer("zoomBoxLeft");
			hideLayer("zoomBoxRight");
			hideLayer("zoomBoxBottom");
			*/
			
			//save the Extent			
			if (rectLeft>rectRight) {
				zright=rectLeft;
				zleft=rectRight;
			} else {
				zleft=rectLeft;
				zright=rectRight;
			}
			if (rectTop>rectBottom) {
				zbottom=rectTop;
				ztop=rectBottom;
			} else {
				ztop=rectTop;
				zbottom=rectBottom;
			}
			rectLeft = zleft;
			rectTop = ztop;
			rectRight = zright;
			rectBottom = zbottom;
			
			window.scrollTo(0,0);			

			refreshMap(true);				
			
			return true;
		
		}


		/*
		***************************************************************************************
		
		MOUSEDOWN
		
		***************************************************************************************
		*/
		function doMouseDown (e) {			
	        getImageXY(e);	        
	        if (mouseTool == 1 || mouseTool == 2){
		      	if ((!zooming) && (mouseX>=0) && (mouseX<iWidth) && (mouseY>=0) && (mouseY<iHeight)) {        							      				      			
		                startZoomBox(e);		                
		                return false;
		
		    	} else if (zooming) {  		    						
		                doMouseMove(e);		                
		                stopZoomBox(e);
		        }
	       	}
	       	
	  		if (mouseTool == 3){	  				  			
	  			if ((mouseX>=0) && (mouseX<iWidth) && (mouseY>=0) && (mouseY<iHeight)) {        				
		  			hideLogos();
					if (pointCounter > 0){
						undoPoint();
					}
					if (lineCounter > 0){						
						undoLine();	
					}
		   			inBox = checkInMap(mouseX,mouseY);		   		
		      		if (inBox){		      		
						startMoving(e);
						return false;
		      		}	      		
	      		}
			}	
		    
			return true;
			
			
		}

		/*
		***************************************************************************************
		
		MOUSEMOVE
		
		***************************************************************************************
		*/
		function doMouseMove(e) {
			getImageXY(e);
			inBox = checkInMap(mouseX,mouseY);
			if (inBox){
				leftTop = new Array(mouseX,mouseY);				
				resCoords1 = img2MapGEO(leftTop);	
				//resCoords2 = img2Map(leftTop);	
				//window.status = resCoords2[0] + " <-> " + resCoords2[1];

				var coordsF = document.forms['coordsForm'];
				if (coordsF != null){
					inX = document.forms['coordsForm'].xco;
					inY = document.forms['coordsForm'].yco;
					if (inX != null && inY != null){
						//inX.value = Math.round(resCoords1[0]);
						//inY.value = Math.round(resCoords1[1]);
						//alert(resCoords1[0]);
						strX = calcGradMinSec(resCoords1[0]);						
						strY= calcGradMinSec(resCoords1[1]);
						inX.value = strX;
						inY.value = strY;
					}
				}


			}
			
			if (mouseX>iWidth) mouseX = iWidth;
			if (mouseY>iHeight) mouseY = iHeight;
			if (mouseX < 0) mouseX = 0;
			if (mouseY < 0) mouseY = 0;

			//if (!isNav){				
	      		if (inBox){	
	      			if (mouseTool == 1 || mouseTool == 2 || mouseTool == 4 || mouseTool == 5){
	      				theImage.style.cursor = "crosshair";
	      			} else if (mouseTool == 3){ //PAN      			
		      			theImage.style.cursor = "pointer";
		      		} else {
		      			theImage.style.cursor = "default";
		      		}
	      		}			
      	//	}
				
				
			if (zooming) {
				rectRight=mouseX;
				rectBottom=mouseY;	
				
                
				setClip();				
				return false;
				
			} else if (moving_it) {
		        //hideLayer('theTransparentMapLayer');
		        MapX = mouseX-aktOffsetX;
		        MapY = mouseY-aktOffsetY;		
		        
				newX = mouseX-aktOffsetX;
				newY = mouseY-aktOffsetY;		    
		        //Bewegen des Layers ausgeschaltet 
		        moveLayer("theMap",newX,newY);		       
		        
		        rectLeft = mapLeft - MapX;
		        rectTop = mapTop - MapY;
		        rectRight = rectLeft + mapWidth;
		        rectBottom = rectTop + mapHeight;
		        
		      	//Bewegen des Layers ausgeschaltet  
		      	clipLayer2("theMap",rectLeft,rectTop,rectRight,rectBottom);
		      	
		      	//ext = getPanExtent();
		      	//window.status = ext[0] + " / " + ext[1] + " / " + ext[2] + " / " + ext[3];
		        
		        return false;		    
		    } else
				return true;
			

			
			var mouseString = "";
			//if (zooming) mouseString += "ZoomBox: [" + x1 + "," + y1 + " x " + x2 + "," + y2 + "]    ";
			return true;
		
		}


		/*
		***************************************************************************************
		
		MOUSEUP
		
		***************************************************************************************
		*/
		function doMouseUp(e) { 
	        if (zooming) {  				   
	               if (mouseX<0)
	                       mouseX = 0;
	               if (mouseX>iWidth)
	                       mouseX = iWidth;
	               if (mouseY<0)
	                       mouseY = 0;
	               if (mouseY>iHeight)
	                       mouseY = iHeight;               
	               doMouseDown(e);	
	        } 
			if (moving_it){		
  			  	stopMoving(e);
				refreshMap(false);
				//showLogos();
			  //writePanExtent();
			}
			if (mouseTool == 4){ // 4=point, 																
				getImageXY(e);				
				if ((mouseX >= 0 && mouseX <= mapWidth) && (mouseY >= 0 && mouseY <= mapHeight)) {										

					if (pointIndex > 0){
						undoPoint();
					}

					offX = mouseX + mapLeft;
					offY = mouseY + mapTop;					
					setPoint(offX,offY,true);
				}
			}
			if (mouseTool == 5 || mouseTool == 7){ //5=line, 7=polygon, 
				getImageXY(e);
				if ((mouseX >= 0 && mouseX <= mapWidth) && (mouseY >= 0 && mouseY <= mapHeight)) {
					
					if (activeLines == 0 && lineCounter > 0 && line_ended == 1){
						undoPointLine();
					}else{
						//alert("al: " + activeLines + " lC " + lineCounter + "le: " + line_ended);
					}
					
					
					activeLines++;
					drawLine(LastMouseX,LastMouseY,mouseX,mouseY);
					f = document.forms['mapForm'];
					aP = f.allLines;
					//alert(aP.value);
					
	
					// keep it within the MapImage
					if ((mouseX >= 0 && mouseX <= mapWidth) && (mouseY >= 0 && mouseY <= mapHeight)) {
						LastMouseX=mouseX;
						LastMouseY=mouseY;
					}
				}

				return false;
			} 							//if (mouseTool == 5 || mouseTool == 7){ //5=line, 7=polygon, 
			
			
			
	        
		}
		
		// clip zoom box layer to mouse coords
		function setClip() {	
			if (rectLeft>rectRight) {
				zright=rectLeft;
				zleft=rectRight;
			} else {
				zleft=rectLeft;
				zright=rectRight;
			}
			if (rectTop>rectBottom) {
				zbottom=rectTop;
				ztop=rectBottom;
			} else {
				ztop=rectTop;
				zbottom=rectBottom;
			}
			if ((rectLeft != rectRight) && (rectTop != rectBottom)) {
				drawZoombox(zleft,ztop,zright,zbottom);
			}
		}




	//reload the Map
	function refreshMap(zooming) {								
		//s = document.forms[0].elements['STDREQUEST'].value;
		//s +=  "mouseTool=" + mouseTool + "&";
		//toggleLayer('loadMap',1);
		showLayer('loadMap');
		
		if (mouseTool==1){
			
			ext = getZoomExtent();
			if(ext[0]==ext[2]&&ext[1]==ext[3])
			{
				tempW=((extentR-extentL)/2);
				tempH=((extentT-extentB)/2);
				ext[0]=ext[0]-(tempW/2);
				ext[1]=ext[1]-(tempH/2);
				ext[2]=ext[2]+(tempW/2);
				ext[3]=ext[3]+(tempH/2);
			}
			//s = s + "EXL=" + ext[0] + "&EXT=" + ext[1] + "&EXR=" + ext[2] + "&EXB=" + ext[3] + "&mouseTool=" + mouseTool;
		} else if (mouseTool == 2){

			ext = getZoomOutExtent();
			if(ext[0]==ext[2]&&ext[1]==ext[3])
			{
				tempW=((extentR-extentL));
				tempH=((extentT-extentB));
				ext[0]=ext[0]-(tempW);
				ext[1]=ext[1]+(tempH);
				ext[2]=ext[2]+(tempW);
				ext[3]=ext[3]-(tempH);
			}		
			//s = s + "&X1=" + ext[0] + "&Y1=" + ext[1] + "&X2=" + ext[2] + "&Y2=" + ext[3] + "&mouseTool=" + mouseTool;
			//s = s + "&SAK=ZOOM";
		}
		
		
		if (mouseTool == 3) { //PAN
			ext = getPanExtent();
		}
		

		//setTimeout('gotoUrl(s)' ,500);
		var fo = document.forms['mapForm'];
		fo.EXL.value = ext[0];
		fo.EXT.value = ext[1];
		fo.EXR.value = ext[2];
		fo.EXB.value = ext[3];
		fo.zoomto.value = "false";			
		if (mouseTool != 3) { //PAN
			fo.searchId.value = "";
			fo.allPoints.value = "";
			fo.allLines.value = "";	
			fo.mustZoom.value = "1";					
		}
		
		fo.submit();
		
	}

  	function gotoUrl(URL){        
			//window.location = '<%=thecall%>';
			window.location = URL;
 	}
 	
	//check if mouse is inside the Map
	function checkInMap(testX,testY){
			mapR = mapWidth; //mapR = mapLeft + mapWidth;
			mapB = mapHeight; //mapB = mapTop + mapHeight;
			
			if (testX >= 0 && testX <= mapR && testY >= 0 && testY <= mapB){    //if (mouseX >= 0 && mouseX <= mapR && mouseY >= 0 && mouseY <= mapB){ //			if (mouseX >= mapLeft && mouseX <= mapR && mouseY >= mapTop && mouseY <= mapB){
				return true;
			} else {				
				return false;
			}
	}
	
	// Start Pan action
	function startMoving(e) {		
		var w,h;			
        getImageXY(e);
        if (MapX == -7777){
        		MapX = mapLeft;
        		MapY = mapTop;         		
        }

        w = MapX+mapWidth;
        h = MapY+mapHeight;
        
        moving_it = true;        		        	

        if (mouseX >= 0 && mouseX <= (w) && mouseY >= 0 && mouseY <= (h)){
	        aktOffsetX = mouseX - MapX;
	        aktOffsetY = mouseY - MapY;
	        if (!moving_it){	        	
	        	moving_it = true;        		        	
	        }
        }
        return false;	    
	}
	
	// Stop PAN action
	function stopMoving(e) {			
	        moving_it=false;        
	        getImageXY(e);		        	        
	        return true;
	}
	
	//get the Extent of a "moved"-Map
	function getPanExtent(){		
		distX = MapX-mapLeft;
		distY = MapY-mapTop;		
		resCoords = img2Map(new Array(-distX,-distY));				
		w = Math.abs(extentR - extentL);
		h = Math.abs(extentT - extentB);				
		result = new Array(Math.round(resCoords[0]),Math.round(resCoords[1]),Math.round(resCoords[0]+w),Math.round(resCoords[1]-h));
		return result;
	}
	
 
	//convert image coordinates to map coordinates
	function img2Map(imgPnt){
		x = imgPnt[0];
		y = imgPnt[1];
		extentW = extentR - extentL;
		extentH = extentT - extentB;
		if (mapWidth==0) mapWidth = 1;
		if (mapHeight==0)mapHeight=1;
		xco = (extentL + x * (extentW / mapWidth));
		yco = extentT - y * (extentH / mapHeight);
		return new Array(xco,yco);
	}
 
	
	//convert image coordinates to map coordinates in GEOWGS84
	function img2MapGEO(imgPnt){
		x = imgPnt[0];
		y = imgPnt[1];	
		mpLeft = 0;
		mpRight = 0;
		mpTop = 0;
		mpBott = 0;
		
		if (mapWidth==0) mapWidth = 1;
		if (mapHeight==0)mapHeight=1;

		if (leftTopX>leftBottomX)
			bigL = leftTopX;
		else
			bigL = leftBottomX;
		if (rightTopX < rightBottomX)
			smallR = rightTopX;
		else
			smallR = rightBottomX;
		if (leftBottomY > rightBottomY)
			bigB = leftBottomY;
		else
			bigB = rightBottomY;
		if (leftTopY < rightTopY)
			smallT = leftTopY;
		else
			smallT = rightTopY;
			
		leftW = Math.abs(leftTopX-leftBottomX);
		mL = (leftW * y) / mapHeight;
		mpLeft = bigL - mL;
		
		rightW = Math.abs(rightTopX - rightBottomX);
		mR = (rightW * y) / mapHeight;
		mpRight = smallR + mR;
		
		topH = Math.abs(leftTopY - rightTopY);
		mT = (topH * x) / mapWidth;
		mpTop = smallT + mT;
		
		bottomH = Math.abs(leftBottomY - rightBottomY);
		mB = (bottomH * x) / mapWidth;
		mpBott = bigB - mB;
		
		width = Math.abs(mpRight - mpLeft);
		height = Math.abs(mpTop - mpBott);
		
		xco = mpLeft + (x * (width / mapWidth));
		yco = mpTop - (y * (height / mapHeight));
		return new Array(xco,yco);
		
		//return new Array(x,y);
	}

		//convert image coordinates to map coordinates in UTM	
	function img2MapUTM(imgPnt){
		x = imgPnt[0];
		y = imgPnt[1];	
		mpLeft = 0;
		mpRight = 0;
		mpTop = 0;
		mpBott = 0;
		
		if (mapWidth==0) mapWidth = 1;
		if (mapHeight==0)mapHeight=1;
		
		
		if (leftTopX_utm>leftBottomX_utm)
			bigL = leftTopX_utm;
		else
			bigL = leftBottomX_utm;
		if (rightTopX_utm < rightBottomX_utm)
			smallR = rightTopX_utm;
		else
			smallR = rightBottomX_utm;
		if (leftBottomY_utm > rightBottomY_utm)
			bigB = leftBottomY_utm;
		else
			bigB = rightBottomY_utm;
		if (leftTopY_utm < rightTopY_utm)
			smallT = leftTopY_utm;
		else
			smallT = rightTopY_utm;
		
		leftW = Math.abs(leftTopX_utm-leftBottomX_utm);
		mL = (leftW * y) / mapHeight;
		mpLeft = bigL - mL;
		
		rightW = Math.abs(rightTopX_utm - rightBottomX_utm);
		mR = (rightW * y) / mapHeight;
		mpRight = smallR + mR;
		
		topH = Math.abs(leftTopY_utm - rightTopY_utm);
		mT = (topH * x) / mapWidth;
		mpTop = smallT + mT;
		
		bottomH = Math.abs(leftBottomY_utm - rightBottomY_utm);
		mB = (bottomH * x) / mapWidth;
		mpBott = bigB - mB;
		
		width = Math.abs(mpRight - mpLeft);
		height = Math.abs(mpTop - mpBott);
		
		xco = mpLeft + (x * (width / mapWidth));
		yco = mpTop - (y * (height / mapHeight));
		return new Array(xco,yco);
		
		//return new Array(x,y);
	}
	



	function calcGradMinSec(val){
		intGrad = Math.floor(val);
		intMinSrc = val - intGrad;
		intMin = Math.floor(60*intMinSrc);				
		intSecSrc = (60 * intMinSrc) - intMin;
		intSec = Math.floor(60 * intSecSrc);
		if (intMin < 10) intMin = "0" + intMin;
		if (intSec < 10) intSec = "0" + intSec;
			
		result = intGrad + degSymbol + intMin + "'" + intSec + "''";		
		//result = "c";
		return result;
	}
	
 
	//get the Extent of a "rubberband"-rect
	function getZoomExtent(){
		if (rectLeft == 0 && rectRight == 0){
			leftTop = new Array(extentL,extentT);
			rightBot = new Array(extentR,extentB);
		} else {						
			y1 = (mapHeight-rectTop);
			y2 = (mapHeight-rectBottom);
			leftTop = new Array(rectLeft,rectTop);
			rightBot = new Array(rectRight,rectBottom);
		}		
		resCoords1 = img2Map(leftTop);		
		resCoords2 = img2Map(rightBot);
		result = new Array(Math.round(resCoords1[0]),Math.round(resCoords1[1]),Math.round(resCoords2[0]),Math.round(resCoords2[1]));
		return result;
	}

	//get the Extent of a "rubberband"-rect
	function getZoomOutExtent(){
		if (rectLeft == 0 && rectRight == 0){
			leftTop = new Array(extentL,extentT);
			rightBot = new Array(extentR,extentB);
		}
		else 
		{									
			//wenn kein Rechteck aufgezogen wird, werden koordinaten des Punkts zurückgeliefert
			if(Math.abs(rectLeft-rectRight)<=5)
			{	
				leftTop = new Array(rectLeft,rectTop);
				rightBot = new Array(rectLeft,rectTop);
			}
			else
			{
					distX = rectRight-rectLeft;		
					distY = rectBottom-rectTop;
					if(distX==0)
					{
					factX=2;
					}
					else
					{
					factX = 1/(distX/mapWidth);
					}
					if(distY==0)
					{
					factY=2;
					}
					else
					{
					factY = 1/(distY/mapHeight);
					}
								
					mWidth = mapWidth * factX;
					mHeight = mapHeight * factY;
		
					deltaY = rectTop * factY; //(mapHeight-rectTop);
					y2 = rectBottom; //(mapHeight-rectBottom);
					rectLeft = - (rectLeft * factX);			
					rectRight = rectLeft + mWidth; //(mapLeft+mapWidth) + (((mapLeft+mapWidth)-rectRight) * factX);
					rectTop = -(rectTop * factY);
					rectBottom = rectTop + mHeight;
					
					
					y1 = rectTop;
					y2 = rectBottom;
					leftTop = new Array(rectLeft,y1);
					rightBot = new Array(rectRight,y2);
				}
		}	
		resCoords1 = img2Map(leftTop);		
		resCoords2 = img2Map(rightBot);
	
		result = new Array(resCoords1[0],resCoords1[1],resCoords2[0],resCoords2[1]);		
		return result;
	}
	
		
	var normalMap = null;
	var transparentMap = null;
	
	function setMap(name) {
		if(name==null) return null;
		name = String(name);
		var obj = document.getElementsByName(name)[0];
		return obj;
	}
	
	function setNormalMap(name) {
		var obj = setMap(name);
		if(obj==null) return;
		normalMap = obj;
	}
	
	function hideLogos(){
		/*
		for (i = 0;i< logoLayers.length;i++){
			if (logoLayers[i] != null)
				hideLayer(logoLayers[i]);
		}
		*/
	}
	
	function showLogos(){
		for (i = 0;i< logoLayers.length;i++){
			showLayer(logoLayers[i]);
		}
	}	

	//clear last point	
	function undoPoint(){					
		for (i=pointIndex-1;i>=0;i--){	
			dNam = pointDivs[i];				
			if (dNam != ""){
				hideLayer(dNam);
				allPoints[i][0] = -1;
				pointDivs[i] = "";
				pointCounter--;
				break;
			}
		}
	}
	
	function setPoint(offX,offY,showWin){
		var content = '';
		showLinkWin = false;
		if (userSymbol != '' && userSymbol != 'undefined'){
			content = '<img src="' + userSymbol	+ '">';				
			if (showWin){
				showLinkWin = true;
			}
			showWin = false;			
		} else {
			content = '<img src="' + symbolPath	+ '">';	
		}
		
		
		var symb = 0;
		for (i=0;i<symbolImages.length;i++){
			if (userSymbol.indexOf(symbolImages[i])>=0){
				symb = i;
				offX += symbolOffsetsX[i];
				offY += symbolOffsetsY[i];
				break;
			}
		}
		
		
		allPoints[pointIndex] = new Array(offX,offY);					
		divname = "pointDIV" + pointIndex;
		posX = offX - (symbolWidth/2);
		posY = offY - (symbolHeight/2) - 7;
		//theDiv = '<div id="' + divname + '" style="position:absolute; overflow:hidden; left:' + posX + 'px; top:' + posY + 'px; width:' + symbolWidth + 'px; height:' + symbolHeight + 'px; z-index:1; visibility:visible;">' + content + '</div>';					
		theDiv = '<div id="' + divname + '" style="position:absolute; overflow:hidden; left:' + posX + 'px; top:' + posY + 'px; width:' + 150 + 'px; height:' + 100 + 'px; z-index:1; visibility:visible;">' + content + '</div>';					
		pointDivs[pointIndex] = divname;					
		
		
		
		var x = getLayer('theMap');					
		inBox = checkInMap(posX,posY-mapTop);
		if (inBox){

			document.body.insertAdjacentHTML('beforeEnd',theDiv);
		
			//into an inputfield of the mapForm
			//worldP = img2Map(allPoints[pointIndex]);
			worldP = img2Map(new Array(mouseX,mouseY));
			worldPGeo = img2MapGEO(new Array(mouseX,mouseY));
			strX = calcGradMinSec(worldPGeo[0]);						
			strY= calcGradMinSec(worldPGeo[1]);
			
			worldPUTM = img2MapUTM(new Array(mouseX,mouseY));
			strAPUTM = "@" + Math.round(worldPUTM[0]) + "|" + Math.round(worldPUTM[1]) + "|" + zone_utm;
			
			f = document.forms['mapForm'];
			aP = f.allPoints;
			skn = f.SKN.value;
			//strAP = aP.value;
			strAP = "@" + Math.round(worldP[0]) + "|" + Math.round(worldP[1]);
			strAPGEO = "@" + strX + "|" + strY;
	
			
			if (showWin){
				aP.value = strAP;
			} else if (!showLinkWin && userSymbol != ""){
				aP.value = "";
			}
			
			projid = f.projid.value;
	
			pointIndex++;
			pointCounter++;		
			
			if (showWin){		
				url = "detailWin.php?point=" + strAPGEO + "&task=2&projid=" + projid + "&utmPoint=" + strAPUTM + "&SKN=" + skn;			
				newwin = window.open(url,'detailWin','width=600,height=407,toolbar=0,location=no,directories=no,scrollBars=no,resizable=no');
				newwin.focus();
			}
			if (showLinkWin){
				var param = "";				
				param += f.SKN.value + "~" + f.EXL.value + "~" + f.EXT.value + "~" + f.EXR.value + "~" + f.EXB.value + "~" + strAP + "~" + symb + "~" + f.projid.value + "~" + f.XPX.value + "~" + f.YPX.value;
				url = "linkWin.php?setTo=" + escape(param);
				newwin = window.open(url,'linkWin','width=600,height=150,toolbar=0,location=no,directories=no,scrollBars=no,resizable=yes');
				newwin.focus();
			}
		}
	}
	
	function drawLine(LastMouseX,LastMouseY,mouseX,mouseY){
		
		//if (LastMouseX != -7777 && LastMouseY != -7777 && ((mouseX >= 0 && mouseX <= mapWidth) && (mouseY >= 0 && mouseY <= mapHeight))){
		if (LastMouseX != -7777 && LastMouseY != -7777){
			
			divname = "lineDIV" + lineIndex;
			divtext = '<div id="' + divname + '" style="position:absolute; overflow:hidden; left:' + mapLeft + 'px; top:' + mapTop + 'px; width:' + mapWidth + 'px; height:' + mapHeight + 'px;' + '; z-index:1; visibility:visible;"></div>';
			document.body.insertAdjacentHTML('beforeEnd',divtext);

			actMouseX1 = LastMouseX;
			actMouseY1 = LastMouseY;
			actMouseX2 = mouseX;
			actMouseY2 = mouseY;
			
			aCanvas = new jsGraphics(divname);
			aCanvas.setColor(penColor);
			aCanvas.setStroke(penWidth);
			aCanvas.drawLine(actMouseX1, actMouseY1, actMouseX2, actMouseY2); // Koordinaten auf Zeichenfläche bezogen					
			aCanvas.paint();
			linesCanvs[lineIndex] = aCanvas;					
			allLinePnts[lineIndex] = new Array(actMouseX2,actMouseY2);

			worldP = img2Map(allLinePnts[lineIndex]);
			f = document.forms['mapForm'];
			aP = f.allLines;
			strAP = aP.value;
			strAP += "@" + Math.round(worldP[0]) + "|" + Math.round(worldP[1]);
			aP.value = strAP;
		
			lineIndex++;
			lineCounter++;					
			//window.status = "LineCounter: " + lineCounter;
		//} else if (LastMouseX == -7777 && LastMouseY == -7777 && ((mouseX >= 0 && mouseX <= mapWidth) && (mouseY >= 0 && mouseY <= mapHeight))){					
		} else if (LastMouseX == -7777 && LastMouseY == -7777 ){					
			allLinePnts[lineIndex] = new Array(mouseX,mouseY);

			offX = mouseX + mapLeft;
			offY = mouseY + mapTop;								
			setPoint(offX,offY,false);

			worldP = img2Map(allLinePnts[lineIndex]);
			f = document.forms['mapForm'];
			aP = f.allLines;
			strAP = aP.value;
			strAP += "@" + Math.round(worldP[0]) + "|" + Math.round(worldP[1]);
			aP.value = strAP;
			

			lineIndex++;
		}							//if (LastMouseX != -7777 && LastMouseY != -7777 ... else ...
	
	}

	//clear the latest line (polyline or polygon)
	function undoLine(){		
		for (i=lineIndex-1;i>=0;i--){				
			aCanv = linesCanvs[i];
			if (aCanv != null)
				aCanv.clear();
		}					
	}

	//clear the latest line (polyline or polygon)
	function undoPointLine(){		
		for (i=lineIndex-1;i>=0;i--){				
			aCanv = linesCanvs[i];
			if (aCanv != null)
				aCanv.clear();
		}			
		f = document.forms['mapForm'];
		aP = f.allLines;	
		aP.value = "";
		undoPoint();
		undoPoint();
	}



