// Launches the main window for the URL at the specified size
// Also centers on screen, a little toward the top
// Requires browsercheck.js
//
// ** POSSIBLE PARAMETERS **
// 1: URL (REQUIRED)
// 2: width
// 3: height
// 4: x pos
// 5: y pos
// 6: window name
// 7: window options (resizable, location, etc.)
function popUp(url) {
	// If there's no URL, then die
	if (url == null || url.length < 1)
		return false;
	
	// Get screen size
	var screenWidth = screen.availWidth;
	var screenHeight = screen.availHeight;
	
	// Set the size -- either arguments 1 and 2 or basically
	// the max screen size
	if (arguments[1] != null) width = arguments[1];
	else width = screenWidth * 0.9;
	if (arguments[2] != null) height = arguments[2];
	else height = screenHeight * 0.9;
	
	var targetWidth = width;
	var targetHeight = height;
	var width = adjustXDimensionForPop(targetWidth);
	var height = adjustYDimensionForPop(targetHeight);
	
	// Set the position -- either the coordinates passed
	// to the function, or centered horizontally and 1/3
	// of the way down vertically (default)
	if (arguments[3] != null && arguments[4] != null) {
		xPos = arguments[3];
		yPos = arguments[4];
	} else {
		// Set proper position according to screen size
		var xPos = Math.round((screenWidth - width) / 2);
		var yPos = Math.round((screenHeight - height) / 3);
	}
	
	// Set proper position phrase
	var xPosPhrase = "left=" + xPos + ",screenX=" + xPos + ",";
	var yPosPhrase = "top=" + yPos + ",screenY=" + yPos + ",";
	
	// WINDOW NAME
	// Can be passed as a 5th parameter, or set 
	if (arguments[5] != null) myWin = arguments[5];
	else myWin = "window" + Math.floor(Math.random () * 11);
	
	// OPTIONS
	// If option name matches in 7th argument, that option is turned on
	// Else all options are by default off
	var scrollbars = 0;
	var toolbar = 0;
	var resizable = 0;
	var location = 0;
	var status = 0;
	var menu = 0;
	if (arguments[6] != null) {
		var options = arguments[6];
		if (options.indexOf("scroll") > -1) var scrollbars = 1;
		if (options.indexOf("tool") > -1) var toolbar = 1;
		if (options.indexOf("resiz") > -1) var resizable = 1;
		if (options.indexOf("location") > -1) var location = 1;
		if (options.indexOf("status") > -1) var status = 1;
		if (options.indexOf("menu") > -1) var menu = 1;
	}
	
	// Generate window.open statement
	eval (myWin + " = window.open('" + url + "', '" + myWin + "',\"" + xPosPhrase + yPosPhrase + "width=" + width + ",height=" + height + ",resizable=" + resizable + ",toolbar=" + toolbar + ",menu=" + menu + ",location=" + location + ",status=" + status + ",scrollbars=" + scrollbars + "\")");
	eval ("thisWindow = " + myWin);
	
	// If Mac IE 4.5, the window got positioned in the upper left corner.  Move it
	// If Safari, the window got positioned correctly with X but at Y=0.  Move it, too
	if (isMacIE4 || isSafari) {
		thisWindow.moveTo(xPos, yPos);
	}
}
