﻿// ToolBar JScript File
// This client side script maintains the toolbar, current Tool, and Selected Action.
//-------------------------------------------------------------------------------------------------
// *** Global Variables
// *** Global Variables
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
// *** Global Classes ***

function ToolBarClass()
{
	//-------------------------------------------------------------------------------------------------
	// *** Internal class module Objects ***
	//.................................................................................................
	var m_CurrentTool = null;
	var m_SelectedAction = null;
	//.................................................................................................
	// *** Internal class module Objects ***
	//-------------------------------------------------------------------------------------------------
	// *** Public Properties ***
	//.................................................................................................
	// Current Tool is the last TOOL selected.
	// Use this to determine the Mouse functionality needed.
	this.CurrentToolName = function()
	{
		if (m_CurrentTool)
		{
			return m_CurrentTool.alt;
		}
		return "";
	}
	//.................................................................................................
	// Selected Action is the command the last selected BUTTON or TOOL represents.
	// Use this to determine what functions must be performed.
	this.SelectedAction = function()
	{
		return m_SelectedAction;
	}
	//.................................................................................................
	// *** Public Properties ***
	//-------------------------------------------------------------------------------------------------
	// *** Public Methods *** 
	//.................................................................................................
	// ToolBar Initialize is called from a startup JavaScript created by the ToolBar control's code behind.
	// EXAMPLE:
//			Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),
//																		"InitializeToolBar",
//																		"<script type=\"text/javascript\" > "
//																		+ " var InitialToolClientID = \""
//																		+ Elements.Find(m_e_ElementMatchesElement).ClientID
//																		+ "\"; </script> ",
//																		false
//																		);
	this.Initialize = function()
	{
		if (CurrentToolClientID)
		{
			m_CurrentTool = document.getElementById(document.getElementById(CurrentToolClientID).value);
		}
		else
		{
			alert("TOOL BAR INITIALIZATION: CurrentToolClientID is null or empty!");
		}
		
		if (m_CurrentTool) 
		{ 
			this.SetTool(m_CurrentTool); 
		}
		else
		{
			alert("TOOL BAR INITIALIZATION: CurrentTool is null!");
		}

		return false;
	}
	//.................................................................................................
	// SetTool is Called from the initialize function (above) 
	// and the Toolbar elements (OnClientClick event) on the ToolBar control's page.
	// EXAMPLE:
	//		OnClientClick="jsobjToolBar.SetTool(this); return false;"
	this.SetTool = function(ToolBarElement)
	{
		var ImageSource;
		var ImageSourceLength;

		if ( ToolBarElement )
		{	// Process if tool was passed to SetTool.
			if (ToolBarElement.tagName != "INPUT")	
			{
				return false;	
			}
		}
		else
		{	// ToolBarElement will be null for a reset.
			if ( m_CurrentTool )	
			{	// Resetting back to actual last selected Tool (not a button);
				ToolBarElement = m_CurrentTool;	
			}
			else	
			{	// Didn't get an element and don't have a selected tool.
				return false;	
			}	
		}
		// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
		// Process the given TOOL element by changing the image of the current TOOL to 'not selected' 
		// and the given TOOL element by changing the image of the current tool to 'not selected' 
		m_SelectedAction = ToolBarElement.alt;

		if ( m_CurrentTool )	
		{
			// Change the selected tool image to the 'selected' image if it is a tool, NOT an ACTION Button.
			if ( ToolBarElement.className == "TOOL" )
			{		// A new tool was selected.  Change the images of the previously selected tool to the unselected image.
				with ( m_CurrentTool )
				{
					ImageSource = src;
					ImageSourceLength = ImageSource.length;
					if (ImageSource.substr(ImageSourceLength-12,8) == "selected")
						src = ImageSource.substr(0,ImageSourceLength-13) + ".GIF";
				}
			}
		}
		
		if ( ToolBarElement.className == "TOOL" )
		{
			with ( ToolBarElement )
			{
				ImageSource = src;
				ImageSourceLength = ImageSource.length;
				if (ImageSource.substr(ImageSourceLength-12,8) != "selected")
					src = ImageSource.substr(0,ImageSourceLength-4) + "_selected.GIF";
			}
			m_CurrentTool = ToolBarElement;
			document.getElementById(CurrentToolClientID).value = m_CurrentTool.ID;
		}
		return false;
	}
	//.................................................................................................
	// *** Public Methods *** 
	//-------------------------------------------------------------------------------------------------
}
// *** Global Classes ***
//-------------------------------------------------------------------------------------------------
