
function toggle_image(selected_image,unselected_image,clicked_image_element,form_name) {

   try {

     var clicked_image = clicked_image_element.src.substr(clicked_image_element.src.lastIndexOf('/') + 1,clicked_image_element.src.length);

     var image_path = clicked_image_element.src.substr(0,clicked_image_element.src.length - clicked_image.length);
     var clicked_image_name = clicked_image_element.src.substr(clicked_image_element.src.lastIndexOf('/') + 1,clicked_image_element.src.length-(clicked_image_element.src.lastIndexOf('_')-2) );
     var new_tool_name = clicked_image.substr(0,clicked_image.length-6) ;
     var clicked_ext = clicked_image_element.src.substr(clicked_image_element.src.lastIndexOf('.') + 1,clicked_image_element.src.length);

     // get hidden tool with tool the last tool value in it

     var tool = document.getElementById('tool') ;

     if(tool.value=='initialize'){tool.value='pan';}

     var last_tool = document.getElementById(tool.value);
     // get the value for the last tool from the tools file name

     var last_tool_name = last_tool.src;

     var last_tool_ext = '';

     last_tool_name = last_tool_name.substr(last_tool_name.lastIndexOf('/') + 1,last_tool_name.length);

     last_tool_ext = last_tool_name.substr(last_tool_name.lastIndexOf('.') + 1,last_tool_name.length);

     last_tool_name = last_tool_name.substr(0,last_tool_name.length-6) ;

     // switch the last tool to the off graphic
      if(last_tool){

                 last_tool.src =  image_path +last_tool_name+'_0.'+last_tool_ext;
      }

	   // set the hidden field value to the new tool value
      tool.value = new_tool_name;
      // check if the new tool and last tool are the same

	  if (clicked_image == selected_image && tool.value != clicked_image_element.name){
           clicked_image_element.src = image_path + unselected_image;
      } else {
           clicked_image_element.src = image_path + selected_image;
      }

	  //call setToolInit to handle startup stuff
      setToolInit(last_tool_name,tool.value);

	  //document.getElementById('map').onmousedown=setToolAction ;
      getMap().onmousedown=setToolAction ;

    }catch (err) {
         window.alert('toggle_image err='+err) ;
    }
  }