// Window defaults
var windowDefaults = {
	toolbar: 'no',
	location: 'no',
	directories: 'no',
	status: 'no',
	menubar: 'no',
	scrollbars: 'no',
	resizable: 'no',
	width: '800',
	height: '600'
};
	
// Save window references for focus and stop duplicates from popping up
var windowRefs = new Array();

// Window Opener function
function windowPopup(uri, overrides) {
	// Set our local scope paramenters to defaults
	var windowParams = windowDefaults;
		
	// Get all of the passed overrides and fill an array with the properties
	var overrideMembers = new Array();
	for (member in eval(overrides)) {
		overrideMembers[overrideMembers.length] = member;
	}
	
	// Turn the uri into a valid propertie name
	var id = uri;
	var slashes = new RegExp("\/", "g");
	var spaces = new RegExp(" ", "g");
	var collon = new RegExp(":", "g");
	var period = new RegExp(".", "g");
//	var backslash = new RegExp("\\", "g");
	
	id = id.replace(spaces, "_");
//	id = id.replace(backslash, "_");
	id = id.replace(slashes, "_");
	id = id.replace(period, "_");
	id = id.replace(".", "_");
	id = id.replace(collon, "_");

	// Don't open a new window, just give it focus if the URI requested already exhists
	if (eval("windowRefs." + id) != undefined) {
		eval("windowRefs['" + id + "'].close();");
	}
	
	// Process all of the override parameters and replace any defaults with them
	for (index = 0; index < overrideMembers.length; index++) {
		eval("windowParams." + overrideMembers[index] + " = overrides." + overrideMembers[index]);
	}
	
	// Build a string from the array
	var paramString = "";
	for (member in eval(windowParams)) {
		paramString = paramString + member + "=" + eval("windowParams." + member) + ", ";
	}
	// Strip the last comma from the parameter string
	paramString = paramString.substr(0, paramString.length - 2);

	// Open the window! Huzza!
	windowRefs[id] = window.open(uri, id, paramString);
	windowRefs[id].focus();
	return false;
}

// Window Closer function
function windowClose(uri) {
	
}