// Global variables
var intHeight;
var intWidth;
//var objSession;
//var objRedirect;

// Set a string for use in browsers requiring "px" if necessary.
var strPx = document.childNodes ? 'px' : 0;

// Events to look out for
window.onload = initialise;
window.onresize = initialise;
window.onbeforeprint = beforePrint;
window.ononafterprint = afterPrint;

// Initialise takes care of processes that must run during page loading and/or resizing.
function initialise()
{
	// Only carry out the processes within initialise where browsers support getElementById,
	// otherwise the results can not be predicted.
	if (document.getElementById)
	{
		getWindowSize();
		reposition();
		// Set up auto redirect to home page when session approaches time out
		if (document.getElementById("warning"))
		{
		    //objSession = window.setTimeout("document.getElementById('Warning').style.display='inline';", 1680000);
		    //objRedirect = window.setTimeout("document.location='../default.aspx';", 1770000);
		}
    }
}

// GetWindowSize simply tests to see how large the viewing area is
function getWindowSize()
{
	if(typeof(window.innerWidth) == "number" )
	{
		//Non-IE
		intWidth = window.innerWidth;
		intHeight = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		intWidth = document.documentElement.clientWidth;
		intHeight = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		intWidth = document.body.clientWidth;
		intHeight = document.body.clientHeight;
	}
}

// Reposition moves and/or resizes screen elements to fill the user's viewport.
function reposition()
{
	if (document.getElementById("Container"))
	{
		if (parseInt(document.getElementById("Container").offsetHeight) <= parseInt(intHeight))
		{
			document.getElementById("Container").style.top = (parseInt(intHeight) - parseInt(document.getElementById("Container").offsetHeight)) / 2 + strPx;
		}
		document.getElementById("Container").style.left = (parseInt(intWidth) - parseInt(document.getElementById("Container").offsetWidth)) / 2 + strPx;
	    document.getElementById("Container").style.visibility = "visible";
	}
}

// openWindow opens a windows of the specified size with the options as specified
function openWindow(windowURL, windowName, windowFeatures, originalWindowName)
{
	var remote = open(windowURL, windowName, windowFeatures);
	if (remote.opener == null) // if something went wrong
		remote.opener = window;
	remote.opener.name = originalWindowName;
	return remote;
}

function beforePrint()
{
    if (document.getElementById("Container"))
    {
        document.getElementById("Container").style.top = 0 + strPx;
        document.getElementById("Container").style.left = 0 + strPx;
        document.getElementById("Container").style.visibility = "visible";
    }
}

function afterPrint()
{
    reposition();
}