var defaultLeft = 0.0;
var defaultBottom = 0.0;
var defaultRight = 0.0;
var defaultTop = 0.0;

var zoomBoxColor = '#FF0000'; //controls colour of zoom box 
var ovZoomBoxColor = "#DEDE9C"
var cornerOffset = 8; //I think this is only used by Netscape 5.x users 
var ovBoxSize = 1; //controls width of zoom box 
var mouseX = 0; //current mouse X position 
var mouseY = 0; //current mouse Y position 
var startX = 0; //X position of mouse when user presses button 
var startY = 0; //Y position of mouse when user presses button 
var zooming = false; //the getMouse function is called every time the mouse moves. 
var panning = false;
var movegraphic = false;
//prevents the zoom box from being displayed unless the user has pressed a button 
//var currentTool = "ZoomIn" //name this variable to whatever you want, but the engage function needs to know 
//which map tool you want to use 
var vspc = 0;
var hspc = 0;

var currentTool = 'zoomin'
var toolMode = 1;

// setup test for Nav 4.0
var isIE = false;
var isNav = (navigator.appName.indexOf("Netscape")>=0);
var isNav4 = false;
var isNav5 = false;
var isNav6 = false;
var isIE4 = false;
var isIE5 = false;
var is5up = false;

if (document.getElementById&&!document.all){
	isNav6 = true;
}

//alert(navigator.appVersion+','+navigator.appName);
if (isNav) 
{
	if (parseFloat(navigator.appVersion)<5) 
	{
		isNav4=true;
		//alert("Netscape 4.x or older");
	} 
	else 
	{
		is5up = true;
		isNav5 = true;
		isNav6 = true;
	}
} 
else 
{
	isIE4=true;
	isIE=true;
	if ((navigator.appVersion.indexOf("MSIE 5")>0)||(navigator.appVersion.indexOf("MSIE 6")>0)) 
	{
		isIE4 = false;
		is5up = true;
		isIE5 = true;
	}
}
/*
***************************************************************************************

DHTML layer functions

***************************************************************************************
*/

function createLayer(name, inleft, intop, width, height, visible, content){
	var layer;
	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>');

}

// move layer to x,y
function moveLayer(name, x, y){	
  	var layer = getLayer(name, 'document.all');		
	layer.left = x + "px";
	layer.top  = y + "px";
}

// set layer background color
function setLayerBackgroundColor(name, color){		
  	var layer = getLayer(name, 'document.all');		
   	layer.backgroundColor = color;
}

// clip layer display to clipleft, cliptip, clipright, clipbottom
function clipLayer2(name, clipleft, cliptop, clipright, clipbottom){
	var layer = getLayer(name, 'document.all');		
    layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
}

function clipLayer(name, clipleft, cliptop, clipright, clipbottom){
	var layer = getLayer(name, 'document.all');
	var newWidth = clipright - clipleft;
	var newHeight = clipbottom - cliptop;
	window.status = newWidth + ',' + newHeight;
	layer.height = newHeight;
	layer.width	= newWidth;
	layer.top	= cliptop  + "px";
	layer.left	= clipleft + "px";
}



//constrains the OV map box to the size of the OV map
function constrain(inner, outer, a)
{
	var b = a;
	
	if(a<inner)
		b=inner;
	if(a>outer)
		b=outer;
		
	return b;
}


//draws a box on the map
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");
}


// next set of functions are DHTML utility functions
function isVisible(name){
	var layer = getLayer(name, 'document.all');
    if (isNav && layer.visibility == "show")
	    return(true);
	if (isIE && layer.visibility == "visible")
		return(true);
	return(false);
}


// toggle layer to invisible
function hideLayer(name){
  	var layer = getLayer(name, 'document.all');		
	layer.visibility = "hidden";
}

// toggle layer to visible
function showLayer(name){	
  	var layer = getLayer(name, 'document.all');		
	layer.visibility = "visible";
}

// get the layer object called "name"
function getLayer(name){
	var ret, path = "document.",postpath = ".style";
	if (isIE4){
		ret = eval(path + 'all.' + name + postpath);
	}else if (isIE5){
		ret = eval(path + 'getElementById("' + name + '")' + postpath);
	}else if (isNav) {
		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
	}
	return ret;
}




// get the layer object called "name".
// Used for finding the map picture element for changing the cursor type.
function getLayerElement(name){
	var ret, path = "document.";
	if (isIE4){
		ret = eval(path + 'all.' + name);
	}else if(isIE5){
		ret = eval(path + 'getElementById("' + name + '")');
	} else
		ret = eval(path + 'getElementById("' + name + '")');
		
	return ret;
}

// replaces map/ovmap images when new map requested
/*function replaceContent(name, content){
	var ret, path = "document."; 
	if (isNav) {
		    var layer = getLayer(name);
		    //alert(layer)
		    layer.document.open();
		    layer.document.writeln(content);
		    layer.document.close();
	  }  else 
	if(isIE){
	//alert(eval(path + "all." + name))
   		if(eval(path + "all." + name) != null){
   	  		eval(path + "all." + name + ".innerHTML = '" + content + "'");
   		}
	}
   return;
}*/


function replaceContent(name, content) {
	var theObj = document.getElementById(name);
	if (theObj!=null) {	  
	
		theObj.innerHTML = content;	
		//alert(theObj.innerHTML)
	} else alert('theObj is null')
}

function hasLayer(name) {
	var result = false;
	if (isNav4) {
		if (document.layers[name]!=null) result=true;
	}  else if (isIE) {
		if (eval('document.all.' + name)!=null) result=true;
	} else if (isNav) {
		var theElements = document.getElementsByTagName("DIV");
		var theObj;
		var j = -1;
		for (i=0;i<theElements.length;i++) {
			if (theElements[i].id==name) result=true;
		}
    }
	return result;
}




