

// hide the common floating div window (if the X button is clicked)
function hideCommonDiv()
{
	try
	{
		document.getElementById('divCommon').style.visibility = 'hidden';

		// also need to clear the source to prevent issues with the link to proclaim window.
		document.getElementById('divCommon').removeChild(document.getElementById('iframeCommon'));
	}
	
	catch (err)
	{
		// what should we do if there is an error?
	}
	
}

// common function that is used for displaying the common floating div window.
// inputs are:
//		title -		the title of the div window
//		w -			the width of the div window
//		h -			the height of the div window
//		l -			the number of pixels from the left of the main window
//		t -			the number of pixels from the top of the main window
//		page -		the URL to the page that is to be displayed
//		show -		if the div window should be made visible by default, true - the window is made visible by default
//					false - the page loaded controls the visibility, this prevents the window from displaying if
//					the conditions required are not met.
//		scroll -	should the iframe within the div window display scroll bars or not.
//		close -		should the close button be displayed or not.
function showCommonDiv(title,w,h,l,t,page,show,scroll,close)
{

	if (document.getElementById('txtCurrentTool').value=='Measure'||document.getElementById('txtCurrentTool').value=='AddText'||document.getElementById('txtCurrentTool').value=='Coord')
	{
		// reset the current tool to prevent errors from attempting to access a tool that is no longer available.
		document.getElementById('txtCurrentTool').value='ZoomIn';
		restoreCurrentTool();
	}
	
	// get the div object so we can set its properties
	var dv = document.getElementById('divCommon');
	
	// always start off with the div hidden
	dv.style.visibility = 'hidden';
	
	// only reset the div size and position if this is a different tool
	if (document.getElementById('divCommonHead').innerHTML != title)
	{
		dv.style.width = w;
		dv.style.height = h;
		dv.style.left = l;
		dv.style.top = t;
		
		// make sure that the width doesn't exceed the width of the map area
		if (eval(parseInt(dv.style.width.replace("px",""))+l) > document.getElementById("imgMap").width && parseInt(document.getElementById("imgMap").width) > 1) {
			dv.style.width = document.getElementById("imgMap").width-l;
		}
		
		// make sure that the height doesn't exceed the height of the map area
		if (eval(parseInt(dv.style.height.replace("px",""))+t) > eval(document.getElementById("imgMap").height+63)) {
			dv.style.height = document.getElementById("imgMap").height-t+63;
			// reset the height so the internal iFrame (set below) is relative to the updated height of the div
			h=parseInt(dv.style.height.replace("px",""));
		}
	
		// set the title of the floating div window
		document.getElementById('divCommonHead').innerHTML = title;
	}

	// should the close button be displayed
	if (close)
	{
		// only add the close button if it doesn't already exist.
		if (!document.getElementById('imgClose')) {
			dv.innerHTML+="<img src=\"images/closecrossdark.gif\" id=\"imgClose\" width=\"21\" height=\"15\" style=\"RIGHT:0px;POSITION:absolute;TOP:2px\" onclick=\"hideCommonDiv();\" onmouseover=\"this.src='images/closecrossbright.gif'\" onmouseout=\"this.src='images/closecrossdark.gif'\">";
		}
	}
	else
	{
		// if the close button is displayed and it shouldn't be, remove it.
		if (document.getElementById('imgClose')) {
			dv.removeChild(document.getElementById('imgClose'));
		}
	}
	
	// show the scrollbars within the iframe?
	if (scroll)
	{
		// the iframe is added programmatically, otherwise we can reset the scrollbars. 
		//(turning them off after they have been on leaves a blank space where the scrollbars were.
		if (document.getElementById('iframeCommon')) {
			// only remove the iframe if it had previously been generated.
			dv.removeChild(document.getElementById('iframeCommon'));
		}
		// add the iframe with scrolling.
		dv.innerHTML+="<iframe id=\"iframeCommon\" src='"+page+"' frameborder=\"0\" scrolling=\"yes\" width=\"100%\" height=\""+(h-18)+"\" style=\"FILTER:alpha(opacity=100)\"></iframe>";
	}
	else
	{
		//remove the previous iframe object if it exists
		if (document.getElementById('iframeCommon')) {
			dv.removeChild(document.getElementById('iframeCommon'));
		}
		// add the iframe without scrollbars.
		dv.innerHTML+="<iframe id=\"iframeCommon\" src='"+page+"' frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\""+(h-18)+"\" style=\"FILTER:alpha(opacity=100)\"></iframe>";
	}
	
	// make the floating div window visible
	if (show)
	{
		dv.style.visibility = 'visible';
	}
}

//Variable to store the start x/y click when moving the divCommon window
var beginDivCommonXClick = 0;
var beginDivCommonYClick = 0;

//Variable to determine if the window is currently moving (1) or not (0)
var divCommonMoving = 0;

//MouseDown event handler for dragging the divCommon window
function divCommonMouseDown(event)
{
	//Set the legend as moving only if the left button was clicked
	if (event.button == 1)
	{
		divCommonMoving = 1;
	}
		
	//Set variables to be used in DivCommonMouseMove
	beginDivCommonXClick = event.clientX;
	beginDivCommonYClick = event.clientY;
	
	//Get and set the current x and y coords of the div window
	currentDivCommonX = document.getElementById('divCommon').style.left;
	currentDivCommonY = document.getElementById('divCommon').style.top;
	
	//Start a capture over the image so that IE does not try and drag'n'drop it
	document.getElementById('divCommon').setCapture();
}


//MouseMove event handler for dragging the divCommon window
function divCommonMouseMove(event)
{
	//If the window is currently moving... (being dragged)
	if (divCommonMoving == 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('divCommon').style.left = parseInt(currentDivCommonX) + event.clientX - beginDivCommonXClick;
			document.getElementById('divCommon').style.top = parseInt(currentDivCommonY) + event.clientY - beginDivCommonYClick;
		}
	}
}

//MouseUp event handler for dragging the divCommon window
function divCommonMouseUp(event)
{
	//Stop the legend from moving
	divCommonMoving = 0;
	
	//Release mouse capture as no more dragging necessary
	document.getElementById('divCommon').releaseCapture();
}
