//vars voor activate layers (laatste script is in act_init
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}

 function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
} 
		/*
		***************************************************************************************
		
		DHTML layer functions - used to create and manipulate style sheets
			These functions are used by the ArcIMS HTML Viewer - found in aimsDHTML.js
		
		***************************************************************************************
		*/
		
		// 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 (isIE && 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
		    	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 if (isIE) {
				    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) {
				clipLayer("zoomBoxTop",theLeft,theTop,theRight,theTop+ovBoxSize);
				clipLayer("zoomBoxLeft",theLeft,theTop,theLeft+ovBoxSize,theBottom);
				clipLayer("zoomBoxRight",theRight-ovBoxSize,theTop,theRight,theBottom);
				clipLayer("zoomBoxBottom",theLeft,theBottom-ovBoxSize,theRight,theBottom);	
				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);
			getImageXY(e);	
			
			var MapForm = MM_findObj('MapForm');
			var SelTool = '';
			
			if (MapForm)
			{
				var SelTool = MapForm.tool.value;
			}
			// keep it within the MapImage

			if ((mouseX<iWidth) && (mouseY<iHeight) && (mouseX>0) && (mouseY>0)) {
				if (zooming) {
					stopZoomBox(e);
				} else {
					if (SelTool == 'select')
					{
						x1=mouseX;
						y1=mouseY;
						x2=x1+1;
						y2=y1+1;
						zleft=x1;
						ztop=y1;
						zbottom=y1;
						zright=x1
						boxIt(x1+hspc,y1+vspc,x2+hspc,y2+vspc);
						stopZoomBox(e);
					}
					else
					{
						x1=mouseX;
						y1=mouseY;
						x2=x1+1;
						y2=y1+1;
						zleft=x1;
						ztop=y1;
						zbottom=y1;
						zright=x1
						boxIt(x1+hspc,y1+vspc,x2+hspc,y2+vspc);
						zooming=true;
					}
				}
			} else {
				zooming=false;
			}
			return false;
		}
		
		// stop zoom box display... 
		function stopZoomBox(e) {
			zooming=false;
			hideLayer("zoomBoxTop");
			hideLayer("zoomBoxLeft");
			hideLayer("zoomBoxRight");
			hideLayer("zoomBoxBottom");
			window.scrollTo(0,0);
			var MapForm = MM_findObj('MapForm');
				MapForm.x1.value = zleft;
				MapForm.x2.value = zright;
				MapForm.y1.value = ztop;
				MapForm.y2.value = zbottom;
				MM_showHideLayers('catchClicks','','show');
				MapForm.submit();
			return true;
		}

		// get the coords at mouse position
		function getMouse(e) {
			window.status="";
			getImageXY(e);
			if ((mouseX>iWidth) || (mouseY>iHeight) || (mouseX<=0) ||(mouseY<=0)) {
				chkMouseUp(e);
			} else {
				if (zooming) {
					x2=mouseX;
					y2=mouseY;
					setClip();	
				}
				var mouseString = "";
				if (zooming) mouseString += "ZoomBox: [" + x1 + "," + y1 + " x " + x2 + "," + y2 + "]";
				mouseString += "Coords: " + mouseX + " , " + mouseY;
				window.status = mouseString;
			}
			// next line needed for Mac
			return false;
		}
		
		// clip zoom box layer to mouse coords
		function 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)) {
				boxIt(zleft+hspc,ztop+vspc,zright+hspc,zbottom+vspc);
			}
			//return false;
		}

		// check for mouseup
		function chkMouseUp(e) { 
			// we are only demo'ing the zoombox	. . . so only one thing to do
			//if ((toolMode == 1) && (zooming)) {
			if (zooming){	
				stopZoomBox(e);
				}
			//}
			//if ((toolMode == 3) && (panning)) {
			//	stopPan(e);
		
			//}
			// next line needed for Mac	
			return false;
			
		}
		
		// perform appropriate action with mapTool
		function mapTool (e) {
			// we are only demo'ing the zoombox. . . so only one thing to do
			/*var MapForm = MM_findObj('MapForm');
			var SelTool = '';
			
			if (MapForm)
			{
				var SelTool = MapForm.tool.value;
			}
			
			if (SelTool == 'select')
			{
				x1=mouseX;
				y1=mouseY;
				x2=x1+1;
				y2=y1+1;
				zleft=x1;
				ztop=y1;
				zbottom=y1;
				zright=x1
				boxIt(x1+hspc,y1+vspc,x2+hspc,y2+vspc);
				stopZoomBox(e);
			}
			else
			{*/
				startZoomBox(e);
			//}
			return false;
		}