

// hide the common floating div window (if the X button is clicked)
function hideCommonDiv()
{
	try
	{
		document.getElementById('divCommon').style.visibility = 'hidden';
	}
	
	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.
//		urlPage - 	does the window show a HTML page or text only
function showCommonDiv(title,w,h,l,t,page,show,scroll,close,urlPage)
{
	
	// 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';
	
	dv.innerHTML="<div id=\"divCommonHead\" style=\"PADDING-LEFT:10px;FONT-WEIGHT:bold;FONT-SIZE:x-small;COLOR:#ffffff;FONT-FAMILY:Verdana;HEIGHT:15px;BACKGROUND-COLOR:#003366\"></div>";
	
	// 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;
	
		// 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'));
		}
	}
	
	if (urlPage)
	{
		// 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>";
		}
	} 
	else
	{
		dv.innerHTML+="<br>"+page;
		dv.innerHTML+="<br><br><a onclick=\"hideCommonDiv();\" class=\"link\">CLOSE <img alt=\"\" src=\"images_css/orange-minor-link-arrow-right.gif\"></a>";
	}
	
	// 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 > 10)
		{
			//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();
}

