//-------- LAYER SUPPORT FUNCTIONS --------------

    var isIE = false;
	var isNav = (navigator.appName.indexOf("Netscape")>=0);
	var isNav4 = false;
	var isIE4 = false;
	var is5up = false;
	
if (isNav) {
	if (parseFloat(navigator.appVersion)<5) {
		isNav4=true;
	} else {
		is5up = true;
	}
} else {
	isIE4=true;
	isIE=true;
	if (navigator.appVersion.indexOf("MSIE 5")>0) {
		isIE4 = false;
		is5up = true;
	}
}	

// clip layer display to clipleft, cliptip, clipright, clipbottom


function clipTTLayer(name, clipleft, cliptop, clipright, clipbottom) {		
	  var layer = getTTLayer(name);
	 
	  if (isNav4) {
		    layer.clip.left   = clipleft;
		    layer.clip.top    = cliptop;
		    layer.clip.right  = clipright;
		    layer.clip.bottom = clipbottom;
	  }	  else {
		    //layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
			var newWidth = clipright - clipleft;
			var newHeight = clipbottom - cliptop;
			layer.height = newHeight;
			layer.width	= newWidth;
			//var theTop = parseInt((parseFloat(cliptop) * 10 + 0.5)/10);
			//var theLeft = parseInt((parseFloat(clipleft) * 10 + 0.5)/10);
			//alert(cliptop + " " + clipleft);
			layer.top	= cliptop  + "px";
			layer.left	= clipleft + "px";
			//layer.display= "none";
		}

}


// Create a DHTML layer
function createTTLayer(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>');
	  }
}

// get the layer object called "name"
function getTTLayer(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);
}

// toggle layer to invisible
function hideLayer(name) {		
  	var layer = getTTLayer(name);		
	
	if (layer != null) {
	
	 	if (isNav4){
    		layer.visibility = "hide";
		} else {
   			 layer.visibility = "hidden";
		}
	}
}

// move layer to x,y
function moveTTLayer(name, x, y) {	
  	var layer = getTTLayer(name);	
	if (layer != null) {
	  	if (isNav4)
    		layer.moveTo(x, y);
	 	else if (isIE) {
    		layer.left = x + "px";
   			layer.top  = y + "px";
		} else {
			layer.height = 20;
			layer.width	= 20;
    		layer.left = x + "px";
   			layer.top  = y + "px";
	  	}
	}
}

// replace layer's content with new content
function replaceTTLayerContent(name, content, uLeft,uTop,rgt,btm) {
	/* var idx = content.indexOf('<BR>',0);
	var newBWidth;
	if (content.length - idx - 4 > idx)
		newBWidth = (content.length - idx - 4) * 7;
	else
		newBWidth = idx * 7;
	*/
	content = '<img src="' + content + '">';
	  if (isNav4) {
		    var layer = getTTLayer(name);
			if (layer != null) {
			    layer.document.open();
			    layer.document.writeln(content);
			    layer.document.close();
			}
	  }  else if (isIE) {
			if (eval("document.all." + name) != null) {
		  		content = content.replace(/\'/g,"\\'");
			    var str = "document.all." + name + ".innerHTML = '" + content + "'";
			    eval(str);
	  		} 
	  } else if (isNav) {
		content += "\n";
		if (document.getElementById){
			rng = document.createRange();
			el = document.getElementById(name);
			rng.setStartBefore(el);
			htmlFrag = rng.createContextualFragment(content);
			while (el.hasChildNodes()){
				el.removeChild(el.lastChild);
			}
			el.appendChild(htmlFrag);
		}
	  }
clipTTLayer(name,uLeft,uTop,rgt,btm);
}

// set layer background color
function setTTLayerBackgroundColor(name, color) {		
  	var layer = getTTLayer(name);		
	if (layer != null) {
	    if (isNav) 
    		layer.bgColor = color;
		else 
    		layer.backgroundColor = color;
	}
}

// toggle layer to visible
function showLayer(name) {		
  	var layer = getTTLayer(name);		
	if (layer != null) {
	  	if (isNav4)
    		layer.visibility = "show";
		else
   		 	layer.visibility = "visible";
	}
}


function createToolTips(toolName, xVal) {
	var fWidth = 0;
	var ttMsg;

	var docWidth = getDocumentWidth();
	var xValMax = docWidth-1;
	switch (toolName) {
	/*	replaceTTLayerContent('TTMSGBox', ttMsg, xVal,2);
	'TTMSGBox' is the text msg box created in top5.htm as a layer
	ttMsg is the msg based on the Case to display in TTMSGBOX
	xVal is the horizontal position value above the button calculated by getLeft
	in toolbar5.js 
	15 is the height (y position).  To make the box smaller, increase 15
	 
	 replaceTTLayerContent('TTMSGBox', 'ovtip.gif', xVal,2,xVal+102,67)
	       xVal is left, 15 is top ,xVal+102 is right (left + width of button = right),  and 67 is bottom (15 + height = bottom)
	 */
	    case 'HOME':
			window.status='Click here for the Home page';
			replaceTTLayerContent('TTMSGBox', 'images/logotip.gif', xVal+260,0,xVal+415,50);
			break;
		case 'AG':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/agtip.gif', xVal + 12,1,xVal+335,59);
			break;
		case 'BIO':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/biotip.gif', xVal - 20,1,xVal+320,59);
			break;
		case 'BND':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/bndtip.gif', xVal - 30,1,xVal+320,59);
			break;
		case 'CLI':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/clitip.gif', xVal - 40,1,xVal+320,59);
			break;
		case 'ENV':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/envtip.gif', xVal - 40,1,xVal+320,59);
			break;	
		case 'GEO':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/geotip.gif', xVal - 90,1,xVal+320,59);
			break;
		case 'GOV':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/govtip.gif', xVal - 110,1,xVal+320,59);
			break;
		case 'HST':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/hsttip.gif', xVal - 150,1,xVal+320,59);
			break;
		case 'MAP':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/maptip.gif', xVal - 175,1,xVal+320,59);
			break;
		case 'PPL':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/ppltip.gif', xVal - 200,1,xVal+320,59);
			break;
		case 'TRS':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/trstip.gif', xVal - 225,1,xVal+320,59);
			break;
		case 'WTR':
			//window.status='Show or hide the overview map';
			replaceTTLayerContent('TTMSGBox', '../../images/lib/wtrtip.gif', xVal - 275,1,xVal+320,59);
			break;
			
		}	
	
	showLayer('TTMSGBox');
	}
	
function getRealLeft(elem)
{
   xPos = eval(elem).offsetLeft;
   tempEl = eval(elem).offsetParent;
     while (tempEl != null) {
          xPos += tempEl.offsetLeft;
          tempEl = tempEl.offsetParent;
     }
   return xPos;
}

function getRealTop(elem)
{
   yPos = eval(elem).offsetTop;
   tempEl = eval(elem).offsetParent;
     while (tempEl != null) {
          yPos += tempEl.offsetTop;
          tempEl = tempEl.offsetParent;
     }
   return yPos;
}
function getDocumentWidth(){
	//opera Netscape 6 Netscape 4x Mozilla 
	if (window.innerWidth){ 
		docwidth = window.innerWidth; 
	} 
	//IE Mozilla 
	if (document.body.clientWidth){ 
		docwidth = document.body.clientWidth; 
	} 
	return docwidth;
}
function getDocumentHeight(){
	//opera Netscape 6 Netscape 4x Mozilla 
	if (window.innerHeight){ 
		docheight = window.innerHeight; 
	} 
	//IE Mozilla 
	if (document.body.clientHeight){ 
		docheight = document.body.clientHeight; 
	} 
	return docheight;
}
function getMouseX(e)
{
// e gives access to the event in all browsers
	if (!e) var e = window.event;
		//if (document.layers) {
	if (isNav) {
		mouseX=e.pageX;
	} else {
		mouseX=event.clientX + document.body.scrollLeft;
	}

	return mouseX;
}	
function getMouseY(e)
{
// e gives access to the event in all browsers
	if (!e) var e = window.event;
		//if (document.layers) {
	if (isNav) {
		mouseY=e.pageY;
	} else {
		mouseY=event.clientY + document.body.scrollTop;
	}

	return mouseY;
}
function getFrameWidth(obj){
	//opera Netscape 6 Netscape 4x Mozilla 
	if (obj.window.innerWidth){ 
		docwidth = obj.window.innerWidth; 
	} 
	//IE Mozilla 
	if (obj.document.body.clientWidth){ 
		docwidth = obj.document.body.clientWidth; 
	} 
	return docwidth;
}

