﻿function OpenWindowCenter( filename, winname, width, height, style )
{
    
	x = (screen.Width - width)/2, y = (screen.Height - height)/2;

	if (screen)
	{
		y = (screen.Height - 50 - height)/2;
		x = (screen.Width - width)/2;
	}
	
	if ( x < 0 )
	{
		x = 0;
		width = screen.Width - 10;
		openWindowInMax = true;
	}
	
	if ( y < 0 )
	{
		y = 0;
		height = screen.Height - 55;
		openWindowInMax = true;
	}

	var winhandle=window.open( filename, winname,'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+','+style);
	
	if ( winhandle == null || typeof(winhandle)== "undefined" )
	{
		alert( "You must turn off browser popup blocker before you can use this system" );
	}
	return winhandle;
}

function OpenWindowCenterOld( filename, winname, width, height, style )
{
	x = (1280 - width)/2, y = (1024 - height)/2;

	if (screen)
	{
		y = (screen.availHeight - height)/2;
		x = (screen.availWidth - width)/2;
	}
	
	if ( x < 0 )
	{
		x = 0
		width = screen.availWidth;
	}
	
	if ( y < 0 )
	{
		y = 0
		height = screen.availHeight
	}

	var winhandle=window.open( filename, winname,'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+','+style);
	if ( winhandle == null || typeof(winhandle)== "undefined" )
	{
		alert( "You must turn off browser popup blocker before you can use this system" );
	}
	return winhandle;
}

function MoveWindowToCenter(windowWidth, windowHeight)
{
	x = (1280 - windowWidth)/2, y = (1024 - windowHeight)/2;

	if (screen)
	{
		y = (screen.availHeight - windowHeight)/2;
		x = (screen.availWidth - windowWidth)/2;
	}
	
	if ( x < 0 )
	{
		x = 0
		windowWidth = screen.availWidth;
	}
	
	if ( y < 0 )
	{
		y = 0
		windowHeight = screen.availHeight
	}

	window.moveTo( x, y );
}
