// -----------------------------------------------------------------
//						Redland Shire Council 
// -----------------------------------------------------------------
// Class    : Error 
// Purpose  : Handlers for the Error Div Tag, hide, move etc.
// -----------------------------------------------------------------
// Calls    :
// Called by: divError's mouse events within default.aspx
// -----------------------------------------------------------------
// Arguments:
// Globals  :
// Returns  :
// -----------------------------------------------------------------
// Notes    : This JavaScript file contains client side code to
//			  allow the Error div tag to be dragged anywhere
//			  within the main map window and released.
// -----------------------------------------------------------------
// History  :
// =================================================================

//Variable to store the start x/y click when moving the error window
var beginErrorFeatureXClick = 0;
var beginErrorFeatureYClick = 0;

//Variable to determine if the window is currently moving (1) or not (0)
var errorMoving = 0;

function HideErrorPanel()
{
	//Hide the Error window as the close button (X) has been clicked.
	document.getElementById('divError').style.visibility = 'hidden';
}

//MouseDown event handler for dragging the error window
function ErrorMouseDown(event)
{
	//Set the legend as moving only if the left button was clicked
	if (event.button == 1)
	{
		errorMoving = 1;
	}
		
	//Set variables to be used in ErrorMouseMove
	beginErrorFeatureXClick = event.clientX;
	beginErrorFeatureYClick = event.clientY;
	
	//Get and set the current x and y coords of the div window
	currentErrorFeatureX = document.getElementById('divError').style.left;
	currentErrorFeatureY = document.getElementById('divError').style.top;
	
	//Start a capture over the image so that IE does not try and drag'n'drop it
	document.getElementById('divError').setCapture();
}


//MouseMove event handler for dragging the error window
function ErrorMouseMove(event)
{
	//If the window is currently moving... (being dragged)
	if (errorMoving == 1)
	{	
		//Only adjust the position of the div tag if it's within the main map window
		//ie, don't allow it to go off the sides or top/bottom of the screen
		if (event.clientX < (parseInt(document.body.clientWidth) -50) && event.clientY < (parseInt(document.body.clientHeight)) - 30 && event.clientX > 50 && event.clientY > 70)
		{		
			//Update the left and top properties of the div tag as the mouse moves and drags		
			document.getElementById('divError').style.left = parseInt(currentErrorFeatureX) + event.clientX - beginErrorFeatureXClick;
			document.getElementById('divError').style.top = parseInt(currentErrorFeatureY) + event.clientY - beginErrorFeatureYClick;
		}
	}
}

//MouseUp event handler for dragging the error window
function ErrorMouseUp(event)
{
	//Stop the legend from moving
	errorMoving = 0;
	
	//Release mouse capture as no more dragging necessary
	document.getElementById('divError').releaseCapture();
}
