// aimsDHTML.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js,
*		aimsLayers.js
*/

var aimsDHTMLPresent=true;

var cornerOffset = 8;

/*
***************************************************************************************

DHTML layer functions

***************************************************************************************
*/

		// Create a DHTML layer
		function createLayer(name, left, top, width, height, visible, content) {
			  var layer;
			  if (isNav4) {
			    document.writeln('<layer name="' + name + '" left=' + left + ' top=' + top + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') +  '>');
			    document.writeln(content);
			    document.writeln('</layer>');
			    //layer = getLayer(name);
			   // layer.width = width;
			   // layer.height = height;
			  //}
			  } else {
			 // if (isNav) {
			    document.writeln('<div id="' + name + '" style="position:absolute; overflow:hidden; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
			    document.writeln(content);
			    document.writeln('</div>');
			  }
			  //clipLayer(name, 0, 0, width, height);
		}
		
		// get the layer object called "name"
		function getLayer(name) {
			  if (isNav4)
			    return(document.layers[name]);
			  else if (isIE) {
			    layer = eval('document.all.' + name + '.style');
			    return(layer);
			  } else if (isNav) {
			  	// layer = eval('document.' + name + '.css.style');
				var theElements = document.getElementsByTagName("DIV");
				var theObj;
				var j = -1;
				for (i=0;i<theElements.length;i++) {
					if (theElements[i].id==name) theObj = theElements[i].style;
				}
				return theObj
			  }
			  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;
		   		 layer.top  = y;
		  	}
		}
		
		// 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";
		}
		
		// toggle layer to visible
		function showLayer(name) {		
		  	var layer = getLayer(name);		
		  	if (isNav4)
		    	layer.visibility = "show";
		  	//if (document.all)
			else
		   	 layer.visibility = "visible";
		}
		
		// clip layer display to clipleft, cliptip, clipright, clipbottom
			// Not working with Mozilla Milestone 12 (Nav5)
		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;
			  }
			  //if (document.all)
			  else
				    layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
		}
		
		// replace layer's content with new content
			// not working with Mozilla Milestone 12 (Nav5)
		function replaceLayerContent(name, content) {
			  if (isNav4) {
				    var layer = getLayer(name);
				    layer.document.open();
				    layer.document.writeln(content);
				    layer.document.close();
			  }  else if (isIE) {
				    var str = "document.all." + name + ".innerHTML = '" + content + "'";
				    eval(str);
			  }
		}

		// get window width		
		function getWinWidth() {
			  if (isNav)
			    	return(window.innerWidth);
			  else if (isIE)
			    	return(document.body.clientWidth);
			  else
			    	return(null);
		}
		
		// get window height
		function getWinHeight() {
		  	if (isNav)
			    return(window.innerHeight);
			else if (isIE)
			    return(document.body.clientHeight);
			else
			    return(null);
		}
		
		// toggle Overview Map display
		function toggleOVMap() {
			if (imsURL!="") {
				ovIsVisible = !ovIsVisible;
				if (ovIsVisible) {
					//showRetrieveMap();
					//var theString = writeOVXML();
					putExtentOnOVMap();
					showLayer("ovLayer");
					showLayer("ovShadow");
					
					showLayer("zoomOVBoxTop");
					showLayer("zoomOVBoxLeft");
					showLayer("zoomOVBoxRight");
					showLayer("zoomOVBoxBottom");
					//sendToServer(imsOVURL,theString,2);
					
				} else {
					hideLayer("ovLayer");
					hideLayer("ovShadow");
					hideLayer("zoomOVBoxTop");
					hideLayer("zoomOVBoxLeft");
					hideLayer("zoomOVBoxRight");
					hideLayer("zoomOVBoxBottom");
					//hideLayer("ovBox");
				}
				if (isIE) {
					document.all.theTop.style.cursor = theCursor;
				}
			} else {
				alert("A MapService must be loaded");
			}
			
		}
		
		// plot extent box on overview map
		function putExtentOnOVMap() {
			var ovXincre = fullOVWidth / i2Width;
			var ovYincre = fullOVHeight / i2Height;
			var vleft = (left - fullOVLeft) / ovXincre + ovBorderWidth;
			var vright = (right - fullOVLeft) / ovXincre + ovBorderWidth;
			var vtop = (fullOVTop - top) / ovYincre + ovBorderWidth;
			var vbottom = (fullOVTop - bottom) / ovYincre + ovBorderWidth;
			if (isNav5up) {
				// /*
				moveLayer("zoomOVBoxTop",vleft,vtop);
				moveLayer("zoomOVBoxBottom",vright-cornerOffset,vbottom-cornerOffset);
				moveLayer("zoomOVBoxLeft",vleft,vbottom-cornerOffset);
				moveLayer("zoomOVBoxRight",vright-cornerOffset,vtop);
				// */
				 /*
				moveLayer("zoomOVBoxTop",ovBorderWidth,vtop);
				moveLayer("zoomOVBoxBottom",ovBorderWidth,vbottom);
				moveLayer("zoomOVBoxLeft",vleft,ovBorderWidth);
				moveLayer("zoomOVBoxRight",vright,ovBorderWidth);
				 */
			} else {		
				clipLayer("zoomOVBoxTop",vleft,vtop-ovExtentBoxSize,vright,vtop);
				clipLayer("zoomOVBoxLeft",vleft-ovExtentBoxSize,vtop-ovExtentBoxSize,vleft,vbottom);
				clipLayer("zoomOVBoxRight",vright,vtop-ovExtentBoxSize,vright+ovExtentBoxSize,vbottom);
				clipLayer("zoomOVBoxBottom",vleft,vbottom-ovExtentBoxSize,vright,vbottom);
			}
			
		}

		function boxIt(theLeft,theTop,theRight,theBottom) {
			if (isNav5up) {
				// /*
				moveLayer("zoomBoxTop",theLeft,theTop);
				moveLayer("zoomBoxBottom",theRight-cornerOffset,theBottom-cornerOffset);
				moveLayer("zoomBoxLeft",theLeft,theBottom-cornerOffset);
				moveLayer("zoomBoxRight",theRight-cornerOffset,theTop);
				// */
				 /*
				moveLayer("zoomBoxTop",0,theTop-ovBoxSize+1);
				moveLayer("zoomBoxBottom",0,theBottom);
				moveLayer("zoomBoxLeft",theLeft-ovBoxSize+1,0);
				moveLayer("zoomBoxRight",theRight,0);
				 */
			
			} else {
				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);
			
			}
		
		}
