
var applicationWindow;

/////////////////////check if Agree is ticked///////////////
function checkAgree()
{
if (!document.AgreeForm.Agree.checked)
	{ alert("You must agree to the Terms of Use before you can start IntraMaps");

	}
else
	{ startIntraMaps('Armadale');
	}
}

/////////////          startIntraMaps()     To open IntraMaps in a custom browser///////////

function startIntraMaps( Project ) {

	var availHeight = window.screen.availHeight;
	var	availWidth	= window.screen.availWidth;

	var tooSmall = ( document.bandwidthSelector.bandwidth[1].checked && (availWidth <= 800 && availHeight <= 600) );

	if( tooSmall ) {
		alert( "Your resolution must be greater than 800x600 pixels to display high bandwidth maps." );
	}

	var width, height, top, left, highBandwidth;

	if( tooSmall || document.bandwidthSelector.bandwidth[0].checked ) {

		// Low bandwidth
		highBandwidth = "false";

		width	= 1024;
		height	= 768;

		// Calculate top and left so that the window is centred
		top		= Math.round( (availHeight/2) - (height/2) );
		left	= Math.round( (availWidth/2) - (width/2) );

		// Just position at 0 if the Application top is small, as it's probably a small screen
		// and the toolbar height will cause the window to be partly offscreen
		if( top < 50 ) top = 2;

	} else {

		// High bandwidth
		highBandwidth = "true";

		width	= availWidth;
		height	= availHeight;

		top		= 0;
		left	= 0;
	}

	var dimensionParameters = "highBandwidth=" + highBandwidth + "&width=" + width + "&height=" + height;
	var url;

		// Parameters - send user straight to application (such as http://server/intramaps/Application.aspx?project=Demo&module=Swimming Pools)
		url = "redirect.php?project=" + Project + "&" + dimensionParameters;

	// If the application window already exists close it to avoid session unloading deadlocks
	try{
		if( typeof applicationWindow != 'undefined' ) applicationWindow.close();
	} catch(e){}

	applicationWindow = window.open( url, "IntraMapsPublic", 'resizable=yes,location=no,status=yes,menubar=no', false );

	// Position and size window, and bring to the front
	try{	applicationWindow.moveTo( left, top );			}catch(e){}
	try{	applicationWindow.resizeTo( width, height );	}catch(e){}
	try{	applicationWindow.focus();						}catch(e){}
}

function CompatibleBrowser( userAgent ) {
	return true; // Because it's now awesome enough to work in every browser...
	/*
	if( userAgent.match( /Firefox/ ) )		return true;		// Firefox
	if( userAgent.match( /Chrome/ ) )		return true;		// Firefox
	if( userAgent.match( /Opera|Safari/ ) )	return false;		// Opera / Safari

	// IE 6+
	if( matches = userAgent.match( /^Mozilla.+MSIE (\d+)\./ ) ) {
		return ( ( matches[1] >= 6 ) );
	} else {
		// Not IE, none of the above
		return false;
	}*/
}
