//Set Parameters
var zoomBoxColor = "#990000";	// color of zoombox


var hspc = 0; 		// horizontal image offset
var vspc = 0; 		// vertical image offset
var ovBoxSize = 2; 	// Zoombox line width;

var zooming = false;
var panning = false;

// 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;

//for panning
var zminx=0;
var zmaxx=0;
var zmaxy=0;
var zminy=0;

//Map Parameters
var theServerName
var theServerPort
var theService
var minx
var miny
var maxx
var maxy
var iwd
var iht
var aspMapParms



// Global vars for browser type and version
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;
	theapp = navigator.appVersion
	theBrowser = "Microsoft Internet Explorer"
	theBrowID = "MSIE"
	theVersion = 5
	cont = false
	themsie = theapp.indexOf(theBrowID)
	if (themsie>0) {
		themsiever = theapp.substring(themsie, themsie + 10)
		thesc = themsiever.indexOf(";")
		if (thesc > 0 ) {
			thever = themsiever.substring(5,thesc)
			if (thever >= theVersion) {
				is5up = true
				isIE4 = false
			}
		}
	}

}

function getBrowser() {
   var theapp = navigator.appName
   var thever = navigator.appVersion
   var isNav = (theapp.indexOf("Netscape")>=0);
   var isIE = (theapp.indexOf("Microsoft Internet Explorer")>=0);
   var theBrowser
   cont = false

   if (isIE) {
   	theBrowID = "MSIE"
   	themsie = thever.indexOf(theBrowID)
   	themsiever = thever.substring(themsie, themsie + 10)
   	thesc = themsiever.indexOf(";")
   	theVersion = 5
   	if (thesc > 0 ) {
   		thever = themsiever.substring(5,thesc)
   		if (thever >= theVersion) {
   			theBrowser = "IE5"
   		}
   	}
   } else if (isNav) {
   	if (parseFloat(thever)<5) {
   		theBrowser = "NN4"
   	} else {
   		theBrowser = "NN6"
   	}
   } else {
   	theBrowser = ""
   }
   return theBrowser;
}

function startUp() {

	if (isNav) {
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
	}

	document.onmousedown = mapTool;
	document.onmouseup = chkMouseUp;
	document.onmousemove = getMouse;

}

function getMapWidth () {
	var mapFrameWidth = thePageWin.innerWidth;

	if (mapFrameWidth == null) {
		mapFrameWidth = thePageDoc.body.clientWidth;
	}
	return mapFrameWidth;
}

 //get the Map Image height
function getMapHeight () {
	var mapFrameHeight = thePageWin.innerHeight;

	if (mapFrameHeight == null) {
		mapFrameHeight = thePageDoc.body.clientHeight;
	}
	return mapFrameHeight;
}

function getMapParams(t) {
	theServerName = t.theServerName.value;
	theServerPort = t.theServerPort.value;
	theService = t.theService.value;
	xmin = t.xmin.value;
	ymin = t.ymin.value;
	xmax = t.xmax.value;	
	ymax = t.ymax.value;
	iwd = t.iwd.value;
	iht = t.iht.value;
}

function passMapParams(theForm) {
	getMapParams()
	theForm.theServerName.value = theServerName
	theForm.theServerPort.value = theServerPort
	theForm.theService.value = theService
	theForm.xmin.value = xmin
	theForm.ymin.value = ymin
	theForm.xmax.value = xmax
	theForm.ymax.value = ymax
	theForm.iwd.value = iwd
	theForm.iht.value = iht
}

function createAspMapString(theSource, theTarget) {
	getMapParams(theSource)
	theTarget = theTarget + "?theServerName=" + theServerName + "&theServerPort=" + theServerPort + "&theService=" + theService + "&xmin=" + xmin + "&ymin=" + ymin + "&xmax=" + xmax + "&ymax=" + ymax + "&iwd=" + iwd + "&iht=" + iht
	return theTarget
}

function replaceChars(thestring,theold,thenew) {
	temp = "" + thestring; // temporary holder
	while (temp.indexOf(theold)>-1) {
		pos= temp.indexOf(theold);
		temp = "" + (temp.substring(0, pos) + thenew + 
		temp.substring((pos + theold.length), temp.length));
	}
	return temp;
}


/*
***************************************************************************************

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>');
	  }
}

// get the layer object called "name"
function getLayer_old(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 getLayer(name) {
	var lyr = null;
	if (document.getElementById) {
		lyr = document.getElementById(name);
	}
	else if (document.all) {
		lyr = document.all[name];
	}
	else if (document.layers) {
		lyr = document.layers[name];
	}
	if (lyr && lyr.style) { lyr = lyr.style; }
	return lyr;
}

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 (layer != null) {
	  	if (isNav4)
    		layer.moveTo(x, y);
	 	else if (isIE4) {
    			layer.left = x + "px";
   			layer.top  = y + "px";
		} else {
			layer.height = mHeight - y;
			layer.width	= mWidth - x;
    			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
    		layer.backgroundColor = color;
}

// toggle layer to invisible
function hideLayer(name) {
  	var layer = getLayer(name);
  	if (isNav4)
    		layer.visibility = "hide";
	else
	 	layer.visibility = "hidden";
}

// toggle layer to visible
function showLayer(name) {
  	var layer = getLayer(name);
  	if (isNav4)
    		layer.visibility = "show";
	else
   	 	layer.visibility = "visible";
}

// 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;
	  } 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-1;
	mouseY = mouseY-vspc-1;
}

// start zoom in.... box displayed
function startZoomBox(e) {
	moveLayer("theMap",hspc,vspc);
	getImageXY(e);
	// keep it within the MapImage
	if ((mouseX<mWidth) && (mouseY<mHeight)) {
		if (zooming) {
			stopZoomBox(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			zleft=x1;
			ztop=y1;
			zbottom=y1;
			zright=x1

			boxIt(x1,y1,x2,y2);
			zooming=true;
		}
	}
	return false;

}

// stop zoom box display...
function stopZoomBox(e) {
	zooming=false;
	showLayer("loadMap")
	hideLayer("zoomBoxTop");
	hideLayer("zoomBoxLeft");
	hideLayer("zoomBoxRight");
	hideLayer("zoomBoxBottom");
	window.scrollTo(0,0);
	var m
	m = parent.MapFrame.document.forms.MapForm
    	m.mapxmin.value = x1;
	m.mapymin.value = y1;
	m.mapxmax.value = x2;
	m.mapymax.value = y2;
	refreshMap();
	return true;
	
	
}

// start Select .... box displayed
function startSelect(e) {
	moveLayer("theMap",hspc,vspc);
	getImageXY(e);
	// keep it within the MapImage
	if ((mouseX<mWidth) && (mouseY<mHeight)) {
		if (zooming) {
			stopSelect(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			zleft=x1;
			ztop=y1;
			zbottom=y1;
			zright=x1

			boxIt(x1,y1,x2,y2);
			zooming=true;
		}
	}
	return false;

}
// stop Select display...
function stopSelect(e) {
	zooming=false;
	showLayer("loadMap")
	hideLayer("zoomBoxTop");
	hideLayer("zoomBoxLeft");
	hideLayer("zoomBoxRight");
	hideLayer("zoomBoxBottom");
	window.scrollTo(0,0);
	
	// Get boolean value of Shift Key
	// e should be the EVENT, but in IE it's empty
	// IE forces us to get the event info from the window object
	//  This is needed for checking of the SHIFT or CONTROL keys
	//  when selecting features.
	if (!e) { e = window.event; }
	keyShift = e.shiftKey;
	
	//var projdir = parent.Defaults.document.forms.Defaults.appFolderName.value
	var activeLyr = d.activeLyr.value
	var afName = d.appFolderName.value;
	var axlFile = d.axlFile.value;
	var theURL = "select_spatial.asp"
	theURL = createAspMapString(parent.MapFrame.document.forms.MapForm,theURL)
	theURL = theURL + "&activeLyr=" + activeLyr
	theURL = theURL + "&axlFile=" + axlFile;
	theURL = theURL + "&afName=" + afName
	theURL = theURL + "&x1=" + x1 + "&y1=" + y1 + "&x2=" + x2 + "&y2=" + y2  ;
	theURL = theURL + "&keyShift=" + keyShift
	parent.BottomFrame.document.location = theURL
	//parent.MapFrame.document.loadData.src = "images/loaddata.gif"
	showLayer("loadData")

	//Win1=window.open(theURL,"Select");
	//Win1.focus();
	return true;
	
	
}

// get the coords at mouse position
function getMouse(e) {

	//window.status="";
	getImageXY(e);

	if ((mouseX>mWidth) || (mouseY>mHeight) || (mouseX<=0) ||(mouseY<=0)) {

	} else {

		if (zooming) {
			x2=mouseX;
			y2=mouseY;
			setClip();
		} else if (panning) {
			x2=mouseX;
			y2=mouseY;
			panMouse();
		}

		var mouseString = "";
		if (zooming) mouseString += "ZoomBox: [" + x1 + "," + y1 + " x " + x2 + "," + y2 + "]    ";

	}
	// 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,ztop,zright,zbottom);
	}

	
	//return false;
}

// start pan.... image will move
function startPan(e) {
	moveLayer("theMap",hspc,vspc);

	getImageXY(e);
	// keep it within the MapImage
	if ((mouseX<mWidth) && (mouseY<mHeight)) {
		if (panning) {
			stopPan(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			panning=true;
		}
	}
	return false;

}

// stop moving image.... pan 
function stopPan(e) {
	var m
	m = parent.MapFrame.document.forms.MapForm


	if ((Math.abs(x2-x1) < 2) && (Math.abs(y2-y1) < 2)) {
		//the move is too small
	} else  {
		window.scrollTo(0,0);
		panning=false;
    		minx = m.mapxmin.value
	    	miny = m.mapymin.value
    		maxx = m.mapxmax.value	
    		maxy = m.mapymax.value
		
		var width = Math.abs(maxx - minx);
		var height = Math.abs(maxy - miny);
		var tempLeft=minx;
		var tempRight=maxx;
		var tempTop=maxy;
		var tempBottom=miny;
		var ixOffset = x2-x1;
		var iyOffset = y1-y2;
		newMaxy = iyOffset;
		newMaxx = ixOffset;
		newMinx = ixOffset;
		newMiny = iyOffset;
		
    		m.mapxmin.value = newMinx
	    	m.mapymin.value = newMiny	
    		m.mapxmax.value = newMaxx	
    		m.mapymax.value = newMaxy		
		m.toolAction.value = "pan"

		refreshMap();
	}
		
	return true;
	
}

// move map image with mouse
function panMouse() {
	var xMove = x2-x1;
	var yMove = y2-y1;
	var cLeft = -xMove;
	var cTop = -yMove;
	var cRight = mWidth;
	var cBottom = mHeight;
	if (xMove>0) {
		cLeft = 0;
		cRight = mWidth - xMove;
	}
	if (yMove>0) {
		cTop = 0;
		cBottom = mHeight - yMove;
	}
	clipLayer("theMap",cLeft,cTop,cRight,cBottom);
	moveLayer("theMap",xMove+hspc,yMove+vspc);
	clipLayer("theAcMap",cLeft,cTop,cRight,cBottom);
	moveLayer("theAcMap",xMove+hspc,yMove+vspc);

	return false;
}


function refreshMap() {
    showLayer("loadMap") 
    d = parent.Defaults.document.forms.Defaults
    t = parent.LeftFrame.document.forms.LeftForm
    m = parent.MapFrame.document.forms.MapForm
    d.VisLayers.value = t.VisLayers.value
    m.VisLayers.value = t.VisLayers.value
    m.submit()
}

function createlabels(mx,my) {
	var theURL = "Labelform.asp?x=" + mouseX + "&y=" + mouseY ;
	wd = 450
	ht = 130
	createPopup(theURL,wd,ht)
	return false; 
}

function createPopup(nam,wd,ht) {
	lx = (screen.height/2) - (ht/2)
	ly = (screen.width/2) - (wd/2)
	parm = "width="+ wd + ",height=" + ht + ",scrollbars=no,resizable=yes,left=" + ly + ",top=" + lx + ",screenx=" + ly + ",screeny=" + lx
	Win1=window.open(nam,"Popup",parm);
	Win1.focus();
}

function checkresize() {
	var m
	m = parent.MapFrame.document.forms.MapForm

	formht = m.iht.value
	formwd = m.iwd.value
	trueht = parent.MapFrame.document.body.clientHeight
	truewd =  parent.MapFrame.document.body.clientWidth
	alert(formht + "-" + trueht)
	alert(formwd + "-" + truewd)
	resize = false
	if (formht != trueht) {
		formht = trueht
		resize = true
	}
	if (formwd != truewd) {
		formwd = truewd
		resize = true
	}
	
	if (resize == true) {
		refreshMap()
	}
	

}



/*
***************************************************************************************

Click/Mouse functions - used to catch mouse button events
	Extended versions of these functions are used by the ArcIMS HTML Viewer - found in aimsClick.js

***************************************************************************************
*/

// check for mouseup
function chkMouseUp(e) {
	var m
	m = parent.MapFrame.document.forms.MapForm

	if (m.toolAction.value == 'zoomin') {
	 	stopZoomBox(e)
	 }
	
	if (m.toolAction.value == 'zoomout') {
	 	stopZoomBox(e)
	 }

	if (m.toolAction.value == 'select') {
	 	stopSelect(e)
	}

	if (m.toolAction.value == 'pan') {
		stopPan(e);

	}
	// next line needed for Mac
	return false;

}

// check to see if there is an Active Layer selected
function CheckActiveLayer() {
	var d = parent.Defaults.document.forms.Defaults;
	if (d.activeLyr.value == "") { 
		alert("This tool requires an Active Layer.  Please select one by clicking on a layer name in the Layer list on the left.");
		return false; 
	} else { return true; };
}

// perform appropriate action with mapTool
function mapTool (e) {
	var d = parent.Defaults.document.forms.Defaults
	var m = parent.MapFrame.document.forms.MapForm

	var theaction = m.toolAction.value
	
	getImageXY(e);
	//zzz need to fix the resize to work with netscape
	//checkresize()
		  	
		  	
	if ((theaction == "identify") && 
	    (mouseX >= 0) && (mouseX <= mWidth) && 
	    (mouseY >= 0) && (mouseY <= mHeight)){
		var activeLyr = d.activeLyr.value;
		var activeLyrName = escape(d.activeLyrName.value);
		var afName = d.appFolderName.value;
		var axlFile = d.axlFile.value;
		var theURL = 'fullresults.asp';
		theURL = createAspMapString(m,theURL);
		theURL = theURL + "&activeLyr=" + activeLyr;
		theURL = theURL + "&activeLyrName=" + activeLyrName;
		theURL = theURL + "&mapX=" + mouseX + "&mapY=" + mouseY ;
		theURL = theURL + "&afName=" + afName + "&axlFile=" + axlFile;
		theURL = theURL + "&callPage=Identify";
		theURL = theURL + "&idX=-999999999";
		theURL = theURL + "&reportParcel=Disable";				
		parent.BottomFrame.document.location = theURL;
		showLayer("loadData");

	}
	// Parisa G.
	// When the action is reportParcel it enables the reportParcel variable in order to copy the parcel into park layer. The latter is being done in fullresults.asp . For this purspose, users should activate in advance the LA County Parcels layer in left menu.
    else if ((theaction == "reportParcel") && 
	    (mouseX >= 0) && (mouseX <= mWidth) && 
	    (mouseY >= 0) && (mouseY <= mHeight)){
		var activeLyr = d.activeLyr.value;
		var activeLyrName = escape(d.activeLyrName.value);
//		alert(activeLyrName);
		if(activeLyrName ==  "LA%20County%20Parcels"){
    		var afName = d.appFolderName.value;
		 	var axlFile = d.axlFile.value;
			var theURL = 'fullresults.asp';
			theURL = createAspMapString(m,theURL);
			theURL = theURL + "&activeLyr=" + activeLyr;
			theURL = theURL + "&activeLyrName=" + activeLyrName;
			theURL = theURL + "&mapX=" + mouseX + "&mapY=" + mouseY ;
			theURL = theURL + "&afName=" + afName + "&axlFile=" + axlFile;
			theURL = theURL + "&callPage=Identify";
			theURL = theURL + "&idX=-999999999";
			theURL = theURL + "&reportParcel=Enable";		
			parent.BottomFrame.document.location = theURL;
			showLayer("loadData");
    	    var url = "WebToolMessages.asp?ID=2";
			var height = 285;
			var width = 360;	
	
			createPopup(url, width, height, true, "Web Tool Development Message",200,300);	
			
		}
		else
		{
    	    var url = "WebToolMessages.asp?ID=1";
			var height = 285;
			var width = 360;	
	
			createPopup(url, width, height, true, "Web Tool Development Message",200,300);	
		}

	}
	
	
	
	else if ((theaction == "report") && 
	    (mouseX >= 0) && (mouseX <= mWidth) && 
	    (mouseY >= 0) && (mouseY <= mHeight)){
	    	var appFolder = parent.Defaults.document.forms.Defaults.appFolderName.value;
		var theURL = appFolder + '/report.asp';
		theURL = createAspMapString(m,theURL);
		theURL = theURL + "&x=" + mouseX + "&y=" + mouseY ;
		parent.BottomFrame.document.location = theURL;
		showLayer("loadData");

	} else if ((theaction == "location") && 
	    (mouseX >= 0) && (mouseX <= mWidth) && 
	    (mouseY >= 0) && (mouseY <= mHeight)){
		var theURL = 'LocationInfo.asp';
		theURL = createAspMapString(m,theURL);
		theURL = theURL + "&x=" + mouseX + "&y=" + mouseY ;
		parent.BottomFrame.document.location = theURL;
		showLayer("loadData")

	} else if ((theaction == "redflag") && 
	    (mouseX >= 0) && (mouseX <= mWidth) && 
	    (mouseY >= 0) && (mouseY <= mHeight)){
	    	theDataDB = parent.Defaults.document.forms.Defaults.theDataDB.value;
		var theURL = 'EnQuery/redflag.asp';
		theURL = createAspMapString(parent.MapFrame.document.forms.MapForm,theURL);
		theURL = theURL + "&theDataDB=" + theDataDB + "&x=" + mouseX + "&y=" + mouseY ;
		parent.BottomFrame.document.location = theURL;
		showLayer("loadData");

	} else if ((theaction == "obs") && 
	    (mouseX >= 0) && (mouseX <= mWidth) && 
	    (mouseY >= 0) && (mouseY <= mHeight)){
	    	var appFolder = parent.Defaults.document.forms.Defaults.appFolderName.value;
		var theURL = 'EntryForm.asp';
		theURL = createAspMapString(m,theURL);
		theURL = theURL + "&x=" + mouseX + "&y=" + mouseY ;
		var theURL = appFolder + "/" + theURL;
		Win1=window.open(theURL,"Popup","width=550,height=350,scrollbars=no,resizable=yes,left = 200,top = 200");
		Win1.resizeTo(550,375);
		Win1.focus();

	} else if (theaction == 'label') {
		createlabels(mouseX,mouseY);
	
	} else if (theaction == 'pan') {
		startPan(e);
	} else if (theaction == 'measure') {
		var b = parent.BottomFrame.document.forms.measForm;
		if (!b) {
			var toolBar = top.TopFrame.GetToolBar();
			var tool = toolBar.FindTool("Measure");
			tool.Activate();
			tool.Execute();
			b = parent.BottomFrame.document.forms.measForm;
		}
		//else {
		if (b) {
			b.imagex.value = mouseX;
			b.imagey.value = mouseY;
			b.submit();
		}
	} else if (theaction == 'zoomin') {
		startZoomBox(e);
		
	} else if (theaction == 'zoomout') {
		startZoomBox(e);
		
	} else if (theaction == 'select') {
		startSelect(e);
	}
	
	return false;
}

/* ------------------------------------------------------------------------- *
 * FakeButton - Class encapsulates some simple behaviors for button-like
 * elements
 * ------------------------------------------------------------------------- */
function FakeButton(elem) {

   this.elem = elem;
   var self = this;

   function MouseIn(e) {
       self.elem.style.borderColor = "#AAAA90";
   }

   function MouseDown(e) {
       self.elem.style.borderStyle = "inset";    
   }

   function MouseUp(e) {
       self.elem.style.borderStyle = "outset";
   }

   function MouseOut(e) {
       self.elem.style.borderStyle = "outset";
       self.elem.style.borderColor = "#FFFFF0";
   }

   var style = this.elem.style;
   style.border = "2px outset #FFFFF0";
   style.lineHeight = "2";
   style.margin = "1px";
   style.padding = "2px";
   style.cursor = "pointer";
   this.elem.onmouseover = MouseIn;
   this.elem.onmousedown = MouseDown;
   this.elem.onmouseup = MouseUp;
   this.elem.onmouseout = MouseOut;

}

// Call this during the page onload event to make all elements having the
// "fakebutton" class into FakeButtons.
function InitializeFakeButtons() {

    function _check_elem(elem) {
		if (!elem) return;
		_check_elem(elem.firstChild);
		var className = elem.className;
		if (className) {
			var names = className.split(/\s+/);
			for (var i = 0; i < names.length; i++) {
				if (names[i] == "fakebutton") {
					elem.fakeButton = new FakeButton(elem);
				}
         }
		}
		_check_elem(elem.nextSibling);
	}

	_check_elem(document.body);
}
