/**
 * Opens a new browser window with extra user interface paraphenalia.
 *
 * useful overrides: left, top
 *
 * @param name window name, "_blank", "_media", "_parent", "_search", "_self", "_top"
 *
 * @see http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/open_0.asp
 */
function popupWindow(url, windowName, w, h, overridesHash) {
	var defaultSettings = {
		channelmode : "no",
		directories : "no",
		fullscreen  : "no",
		location    : "no",
		menubar		: "no",
		resizable   : "yes",
		scrollbars  : "yes",
		status      : "no",
		titlebar    : "no", // Ignored except for HTML Applications (.hta) and trusted dialog boxes
		toolbar     : "no"
	};

	return _newWindowDriver(url, windowName, w, h, overridesHash, defaultSettings);
}

/**
 * Opens a new browser window, complete with default UI controls.
 */
function newWindow(url, windowName, w, h, overridesHash) {
	var defaultSettings = {
		channelmode : "no",
		directories : "yes",
		fullscreen  : "no",
		location    : "yes",
		menubar		: "yes",
		resizable   : "yes",
		scrollbars  : "yes",
		status      : "yes",
		titlebar    : "yes", // Ignored except for HTML Applications (.hta) and trusted dialog boxes
		toolbar     : "yes"
	};

	return _newWindowDriver(url, windowName, w, h, overridesHash, defaultSettings);
}

function _newWindowDriver(url, windowName, w, h, overridesHash, defaultSettings) {
	if (overridesHash) {
		for (var key in overridesHash) {
			defaultSettings[key] = overridesHash[key];
		}
	}

	if (!windowName)
		windowName = "_blank";

	if (w) defaultSettings.width  = w;
	if (h) defaultSettings.height = h;

	var settingsArray = new Array();
	for (var key in defaultSettings) {
		settingsArray.push(key + "=" + defaultSettings[key]);
	}

	window.open(url, windowName, settingsArray.join(","), true);
	return false;
}
