//------------------------------------------------------------------------------------
// Opens a side window to a specified URL and then resizes this window to fit
// the rest of the screen
//------------------------------------------------------------------------------------
var objHelpWindowHandle = null;
function MW_window_help(strURL, objMainWindowHandle, strHelpPage) {
	var numWindowWidth_Side = 300;
	var numWindowWidth_Main = screen.width - numWindowWidth_Side;
	
	objHelpWindowHandle = newWindow(strURL + '?pg=' + strHelpPage, 'MARS_side_window', true, screen.height, numWindowWidth_Side, false, true);
	if (objHelpWindowHandle) {
		// position the help window to the right side of the screen
		objHelpWindowHandle.moveTo(screen.width - numWindowWidth_Side, 0);
		
		// now try and resize the main window if it needs it
		objMainWindowHandle.resizeTo(numWindowWidth_Main - 10, screen.height);
		objMainWindowHandle.moveTo(0,0);
		
		// set the focus if this window is already open
		objHelpWindowHandle.focus();
		
		return false; // cancel the hyperlink
	}
}

//------------------------------------------------------------------------------------
// Function to open a new window with various properties
//------------------------------------------------------------------------------------
function MW_window_new(URL, windowName, menuFlag, pHeight, pWidth, centerWindow, resizable, returnHandle) {
	if (parseInt(navigator.appVersion) >= 4) {
		isDyn = true;
	}
	else {
		isDyn = false;
	}

	if (pHeight != null && pWidth != null) {
		wWidth = pWidth;
		wHeight = pHeight;
	}
	else {
		// set absolute defaults in case not a 4.0 or greater
		wWidth = 450;
		wHeight = 500;
	
		// ok...figure out the screen size
	
		if (isDyn) {
			wWidth = parseInt(screen.width * .75);
			wHeight = parseInt(screen.height * .75);
		}
	}
	
	if (windowName == null)
		windowName = "popupWindow";
	
	if (menuFlag) menuFlag = 'yes'; else menuFlag = 'no';
	
	if (resizable) resizable = 'yes'; else resizable = 'no';
	
	var windowFeatures = "height=" + wHeight + ",width=" + wWidth;
	windowFeatures += ",resizable=" + resizable + ",toolbar=no,scrollbars=yes,menubar=";
	windowFeatures += menuFlag;

	if (centerWindow) {	
		if (isDyn) {
			var sWidth = screen.width;
			var sHeight = screen.height;
			windowFeatures += ",left=" + (sWidth / 2 - wWidth / 2) + ",top=" + (sHeight / 2 - wHeight / 2 - 35);
		}
	}
	var windowHandle = window.open(URL, windowName, windowFeatures);
	
	if (windowHandle) {
		if (centerWindow) windowHandle.focus();
			if (returnHandle)
				return windowHandle;
			else
				return false;
	}
	else {
		return false;
	}
}

//------------------------------------------------------------------------------------
// Function to open a form submission in a new window...
// must have a page called "blank.html" in the root directory
//------------------------------------------------------------------------------------
function MW_window_form(form, windowName, menuFlag, 
						pHeight, pWidth, centerWindow) {
	// open a blank window, wait, then run the form
	if (!MW_window_new('/blank.html', windowName, menuFlag, pHeight, pWidth, centerWindow, resizable, false)) {
		form.target = windowName;
		form.submit();
	}	
}