// todo: preload images (have to know path and iconset)

function setTool( toolName, zoomFactor )
{

	/* defaults */

	if ( zoomFactor == undefined ){
		zoomFactor = 2;

	}

	/* action */
	if (toolName != "update")
	{
		document.mapform.tool.value = toolName;
	}
	window.status = "";

	// Not all forms have all the buttons so check each one.
	if (toolName == "zoomin")
	{
		window.status="Current tool set to Zoom In";
		document.mapform.zoom.value = zoomFactor;
	}
	else if (toolName == "zoomout")
	{
		window.status="Current tool set to Zoom Out";
		document.mapform.zoom.value = - zoomFactor;
	}
	else if (toolName == "zoomfull")
	{
		window.status="Current tool set to Zoom to Default Extents";
		document.mapform.imgext.value = '';
		document.mapform.submit();
		return false;
	}
	else if (toolName == "pan")
	{
		window.status="Current tool set to Pan";
		document.mapform.zoom.value = 1;
	}
	else if (toolName == "drag")
	{
		window.status="Current tool set to Click and Drag";
		document.mapform.zoom.value = 1;
	}
	else if (toolName == "query")
	{
		document.mapform.zoom.value = 0;
		window.status="Current tool set to Query";
	}
	else if (toolName == "timequery")
	{
		document.mapform.zoom.value = 0;
		window.status="Current tool set to Time Query";
	}
	else if (toolName == "queryplot")
	{
		document.mapform.zoom.value = 0;
		window.status="Current tool set to Query Plot";
	}
	else if (toolName == "update")
	{
		document.mapform.submit();
		return false;
	}

	// Turn on current tool, turn off all others which may exist
	var LiteMe = eval("document." + toolName);

	/* /maptools/icons/default/tool-pan-on.png */
	var imgSrc = LiteMe.src;
	var imgPath = imgSrc.substring( 0, imgSrc.lastIndexOf('/') );
	var imgTool = imgSrc.substring( imgSrc.lastIndexOf('/'), imgSrc.lastIndexOf('-') );
	var imgExt = imgSrc.substring( imgSrc.lastIndexOf('.'), imgSrc.length );

	// First, turn off all tools
	var allTools = new Array("zoomin","zoomout","pan","drag","query","zoomfull","update");
	for (var n = 0; n < allTools.length; n++){
		var thisTool = eval("document." + allTools[n]);
		if ( thisTool != undefined ){
			thisTool.src = imgPath + "/tool-" + allTools[n] + '-off' + imgExt;
		}
	}
	/* Turn on the selected one */
	LiteMe.src = imgPath + imgTool + "-on" + imgExt;

}

// for hilighting the tool buttons. doesn't work yet.
function liteTool(toolName, MouseIsOver)
{
	if ( MouseIsOver == true )
	{ // TODO: lite up with, e.g. zoomout-over.gif IF not the current tool
		if (toolName == "zoomin")
		{
			document.zoomin.src = "/zoomout-on." + imgExt;
		}

			window.status="Current tool set to Zoom In";
	}
	else {
		// restore tool to proper state
		window.status="";
	}
}

