// Display JScript File
// This client side script handles the mouse reactions based on the currently selected tool.
//=================================================================================================
function DisplayClass()
{
	//=================================================================================================
	// *** Internal class module variables ***
	//-------------------------------------------------------------------------------------------------
	var m_aPoint;
	var m_aRectangle;
	var m_aCircle;
	var m_CurrentShape;
	var m_MouseEntered = false;
	var m_MouseDown = false;
	var m_Action = null;
	
	var jsobjController			= new ControllerClass();
	//-------------------------------------------------------------------------------------------------
	// *** Internal class module variables ***
	//=================================================================================================
	// *** Public Properties ***
	this.Action = function(action)
	{
		if (!action)
		{
			if (hfDisplayActionClientID)
			{ 
				action =  document.getElementById(hfDisplayActionClientID).value;
			}
			else
			{
				alert("DISPLAY Action: hfDisplayActionClientID is null or empty!");
			}
		}
		m_Action = action.toUpperCase();
		m_MouseEntered = false;	
		m_MouseDown = false;

		document.getElementById(hfDisplayActionClientID).value = action;
		
		return m_Action
	}
	//-------------------------------------------------------------------------------------------------
	// *** Public Properties ***
	//=================================================================================================
	// *** Public Methods *** 
	//-------------------------------------------------------------------------------------------------
	this.Initialize = function()
	{
		action = this.Action();
		if (action)
		{
			return false;
		}
		else
		{
			alert("DISPLAY INITIALIZATION: Action could not be assigned!");
		}
		return false;
	}
	//-------------------------------------------------------------------------------------------------
	this.UpdateMap = function()
	{
	    //jsobjController.ShowMapProgress();
		document.getElementById(ibMapClientID).click();
		return true;
	}
	//-------------------------------------------------------------------------------------------------
	this.setCoordinates = function(MinX, MinY, MaxX, MaxY)
	{
		document.getElementById(hfMinPointXClientID).value = MinX;
		document.getElementById(hfMinPointYClientID).value = MinY;
		document.getElementById(hfMaxPointXClientID).value = MaxX;
		document.getElementById(hfMaxPointYClientID).value = MaxY;
		return true;
	}
	//-------------------------------------------------------------------------------------------------
	this.setRadius = function(Radius)
	{	    
	    document.getElementById(hfCircleRadiusClientID).value = Radius;
		return true;
	}
	//-------------------------------------------------------------------------------------------------
	this.MouseEnterMap = function(Sender) 
	{
		m_MouseEntered = true;
		if (!m_Action) 
		{
			m_Action = document.getElementById(hfDisplayActionClientID).value.toUpperCase();
		}
		switch (m_Action)
		{
			case "IDENTIFY" :
			case "CIRCLEQUERY" :
				Sender.style.cursor="default";
				//Sender.style.cursor="url(../Map/Images/ToolBar/Identify.gif)"
				break;
			case "ZOOMIN" :
			case "ZOOMOUT" :
				Sender.style.cursor="Crosshair";
				break;
			case "PAN" :
				Sender.style.cursor="Move";
				break;
			default :
				break;
		}
		return false; // Mouse Entered
	}
	//-------------------------------------------------------------------------------------------------
	this.MouseLeaveMap = function(Sender) 
	{
		m_MouseEntered = false;
		Sender.style.cursor = "Default";
		return false; // Mouse Exited
	}
	//-------------------------------------------------------------------------------------------------
	this.MouseDownOnMap = function(Sender, Event)
	{
		if (!m_MouseEntered)
		{
			this.MouseEnterMap(Sender);
		}
		m_MouseDown = true;
		
		this.ClearGraphics();
		
		switch (m_Action)
		{
			case "IDENTIFY" :
			case "ZOOMOUT" :
			case "PAN" :
				if (m_aPoint == null) {
				    m_aPoint = new ShapeClass(Sender);  }
				else {
				    delete m_aPoint;
				    m_aPoint = null;
				    m_aPoint = new ShapeClass(Sender);
				}
				    
				m_aPoint.SetType(Point);
				m_CurrentShape = Point;
				m_aPoint.Draw(Event);
				break;
			case "CIRCLEQUERY" :
				if (m_aCircle == null) { 
				    m_aCircle = new ShapeClass(Sender); }
				else {
				    delete m_aCircle;
				    m_aCircle = null;
				    m_aCircle = new ShapeClass(Sender);
				}
				m_aCircle.SetType(Circle);
				m_CurrentShape = Circle;
				m_aCircle.Draw(Event);
				break;
			case "ZOOMIN" :
				if (m_aRectangle == null)	
				{
				    m_aRectangle = new ShapeClass(Sender);
				}
				else
				{
				    delete m_aRectangle;
				    m_aRectangle = null;
				    m_aRectangle = new ShapeClass(Sender);
				}
				m_aRectangle.SetType(Rectangle);
				m_CurrentShape = Rectangle;
				m_aRectangle.Draw(Event);		
				break;
			default :
				break;
		}
		return false;  // Mouse Down
	}
	//-------------------------------------------------------------------------------------------------
	this.MouseMoveOnMap = function(Sender, Event)
	{
		if (!m_MouseDown) return false;
		
		if (!m_MouseEntered)	this.MouseEnterMap(Sender);

		switch (m_Action)
		{
			case "IDENTIFY" :
			case "ZOOMOUT" :
			case "PAN" :
				m_aPoint.Draw(Event);
				break;
			case "CIRCLEQUERY" :
				m_aCircle.Draw(Event);
				break;
			case "ZOOMIN" :
				m_aRectangle.Draw(Event);		
				break;
			default :
				break;
		}
		return false; // Mouse move
	}
	//-------------------------------------------------------------------------------------------------
	this.MouseUpOnMap = function(Sender, Event)
	{
		if (!m_MouseDown) 
		{
		    return false;
        }
		
		m_MouseDown = false;
		
		if (!m_MouseEntered)
		{
			this.MouseEnterMap(Sender);
		}
		m_MouseEntered = false;

		switch (m_Action)
		{
			case "IDENTIFY" :
			      m_aPoint.Draw(Event);
				this.setCoordinates(m_aPoint.Left,m_aPoint.Top,m_aPoint.Left,m_aPoint.Top);
				jsobjController.SetDivVisibility("hfIdentifyResultsClientID");
				break;
			case "ZOOMOUT" :
			case "PAN" :
				m_aPoint.Draw(Event);
				this.setCoordinates(m_aPoint.Left,m_aPoint.Top,m_aPoint.Left,m_aPoint.Top);
				break;
			case "CIRCLEQUERY" :
				m_aCircle.Draw(Event);
				this.setCoordinates(m_aCircle.Left,m_aCircle.Top,m_aCircle.Right,m_aCircle.Bottom);
				this.setRadius(m_aCircle.Radius);
				jsobjController.SetDivVisibility("hfCircleQueryResultsID");
				break;
			case "ZOOMIN" :
				m_aRectangle.Draw(Event);
				this.setCoordinates(m_aRectangle.Left,m_aRectangle.Top,m_aRectangle.Right,m_aRectangle.Bottom);
				this.ClearGraphics();
				break;
			case "ZOOMFULL" :
			default :
				break;
		}
		document.getElementById(hfDisplayActionClientID).value = m_Action;
		this.UpdateMap();
		
		return true; //Mouse Up
	}
	//-------------------------------------------------------------------------------------------------
	this.ClearGraphics = function()
	{
		if (!(m_aPoint == null)) m_aPoint.Clear();
		if (!(m_aCircle == null)) m_aCircle.Clear();	
		if (!(m_aRectangle == null)) m_aRectangle.Clear();
	}
	// *** Public Methods *** 
	//=================================================================================================
}