// Handles launch of separate browser

// The Windows tool bar is 24 pixels high
// I have also found that IE thinks the available width is 10 pixels less than
// it should be on 800x600 mode
var windowsHOffset = 24;
var windowsWOffset = 10;

function tearoff(url, name, width, height, left, top)
{
	if (width > (screen.availWidth - windowsWOffset) || height > (screen.availHeight - windowsHOffset)) {
		return tearoffWithScroll(url, name, width, height, left, top);
	}
	return tearoff_WindowOpen(url, name, width, height, left, top, 'no', 'no', 'yes');
}  

function tearoff_WindowOpen(url, name, width, height, left, top, scrollbars, menubar, resizable)
{
	if (isNaN(parseInt(width))) width = 640;
	if (isNaN(parseInt(height))) height = 480;
	
	if (width > (screen.availWidth - windowsWOffset)) {
		width = screen.availWidth - windowsWOffset;
	}
	
	if (height > (screen.availHeight - windowsHOffset)) {
		height = screen.availHeight - windowsHOffset;
	}
	
	// If either "left" or "top" are unspecified or invalid, center the window.
	left = parseInt(left);
	top = parseInt(top);
	if (isNaN(left) || isNaN(top)) {
		var arrCtrWinPos = getCenteredWindowPosition(width, height);
		left = arrCtrWinPos[0];
		top = arrCtrWinPos[1];
	}
	
	var tearWin = window.open(url, name, 'personalbar=no,toolbar=no,status=no,scrollbars='
	                                    + scrollbars + ',location=no,resizable=' + resizable
	                                    + ',menubar=' + menubar + ',width=' + width + ',height='
	                                    + height + ',left=' + left + ',top=' + top);
	if (window.focus) {
		tearWin.focus();
	} 
	return tearWin;
}  

function tearoffWithScroll(url, name, width, height, left, top)
{
	return tearoff_WindowOpen(url, name, width, height, left, top, 'yes', 'no', 'yes');
}

function tearoffWithScrollAndMenu(url, name, width, height, left, top)
{
	return tearoff_WindowOpen(url, name, width, height, left, top, 'yes', 'yes', 'yes');
}

function tearoffWithScrollNoresize(url, name, width, height, left, top)
{
	return tearoff_WindowOpen(url, name, width, height, left, top, 'yes', 'no', 'no');
}

function getCenteredWindowPosition(iWinWidth, iWinHeight)
{
	// This works with all the browsers we've ever supported, including NS 4.79.
	var iWinLeft = 0;
	var iWinTop  = 0;
	// Ensure that the current browser supports the necessary features.
	if (typeof window.screen != "undefined") {
		iWinLeft = (window.screen.availWidth - iWinWidth) / 2;
		if (iWinLeft < 0) iWinLeft = 0;
		iWinTop = (window.screen.availHeight - iWinHeight) / 2;
		if (iWinTop < 0) iWinTop = 0;
   	}
   	return new Array(iWinLeft, iWinTop);
}