
// -----------------------------------------------------------------
//						Redland Shire Council 
// -----------------------------------------------------------------
// Class    : ResizeMapWindow 
// Purpose  : Handles resizing the map window.
// -----------------------------------------------------------------
// Calls    :
// Called by: the onresize event of the body tag within default.aspx
// -----------------------------------------------------------------
// Arguments:
// Globals  :
// Returns  :
// -----------------------------------------------------------------
// Notes    : No events will fire until the window has been released
//			  and 1 second has elapsed. This is so that the resize
//			  event does not fire as the window is being resized.
// -----------------------------------------------------------------
// History  :
// =================================================================

//Reloading timer
var reloadTimer = 0;
var reloadTimer2 = 0;

//Function to call the adjustment code after the window has been resized,
//AND STAYS resized for at least 1 second.
function reloadApp()
{
	//Clear the timer
	window.clearTimeout(reloadTimer);
	
	//Call the adjustMapSize function if 1000 milliseconds have elapsed
	reloadTimer = window.setTimeout("checkMapSize();",1000);
}

// check that the map is sized correctly within the window
function checkMapSize()
{
	// if the map size doesn't match the window size adjust the map size
	// only force the resize if a resize isn't already pending!
	if (document.getElementById('txtCurrentTool').value != 'ResizeMapWindow' && Math.abs(document.getElementById("imgMap").width - document.body.clientWidth) > 5) {
		// there has been a communication problem with IMS and the map hasn't loaded correctly. don't refresh!
		if (document.getElementById('txtCurrentTool').value=='ZoomIn' && document.getElementById("imgMap").width==1)
		{
			//alert('There has been a communication problem with the Map Server.\n\nPlease try again in 5 minutes.\n\nIf you continue to receive this message contact the IT Help Desk.');
			alert(imsComError);
		}
		else
		{
			adjustMapSize();
		}
	}
}

//Calculate new min/max x/y values, and send them back to the server
function adjustMapSize()
{

	//MaxX and MaxY should be the width and height of the client window
	document.forms["frmMapPage"].txtX1.value = document.body.clientWidth;
	document.forms["frmMapPage"].txtY1.value = document.body.clientHeight;
	
	//MinX and MinY should be the values of the left and top from the CSS of the divImgMap
	document.forms["frmMapPage"].txtX2.value = document.getElementById('divImgMap').style.left;
	document.forms["frmMapPage"].txtY2.value = document.getElementById('divImgMap').style.top;
	
	//Set the current tool to resize the window on postback
	document.forms["frmMapPage"].txtCurrentTool.value = "ResizeMapWindow";
	
	//Resize the transparent toolbar to the new width of the window
	document.getElementById('toolbar').style.width = document.body.clientWidth;
	document.getElementById('toolbar2').style.width = document.body.clientWidth;
	
	//Show the loading splash in the centre of the new screen dimensions
	updateLoadingSplashPos();
	LoadNextImage();
	
	//Submit the page to the server for processing
	document.getElementById('frmMapPage').submit();
	
}