var left_offset = 0;
var top_offset = 0;

function open_window(url, width, height) {
	woa = window.open(url, 'a_centered_window', 'left=' + center_x(width) + 
	',top=' + center_y(height) + 
	',width=' +
	width + ',height=' + height + ',menubar=no,toolbar=no,location=yes,resizable=yes,scrollbars=yes')
}

function open_window_offset(url, width, height) {
	window.open(url, '_blank', 'left=' + (center_x(width)+left_offset) + 
	',top=' + (center_y(height)+top_offset) + 
	',width=' +
	width + ',height=' + height + ',menubar=no,toolbar=no,location=yes,resizable=yes,scrollbars=yes');
	left_offset += 20;
	top_offset += 20;
	if (left_offset > 100) {
		left_offset = 0;
	}
	if (top_offset > 100) {
		top_offset = 0;
	}	
}

function open_window_options(url, width, height, options) {
	wob = window.open(url, 'b_centered_window', 'left=' + center_x(width) + 
	',top=' + center_y(height) + 
	',width=' +
	width + ',height=' + height + ',' + options)
}

/* Get the horizontal position a window needs to have to center this window horizontally on the screen. */
function center_x(window_width) {
	return (screen.width / 2) - (window_width / 2);
}

/* Get the vertical position a window needs to have to center this window vertically on the screen. */
function center_y(window_height) {
	height = (screen.height / 2) - (window_height / 2);
	if (height < 0) {
		// height cannot be a negative value
		height = 0;
	}
	else if (height > 50) {
		// move a little bit to the top so that a large screen doesn't appear above the task bar + it looks better
		height -= 40;
	}
	else if (height > 30) {
		// move a little bit to the top so that a large screen doesn't appear above the task bar + it looks better
		height -= 20;
	}
	return height;
}

function get_width(width) {
	return width;
}

function get_height(height) {
	if (height > screen.height) {
		height = screen.height - 60;
	}
	return height;
}

function show_help() {
	catalog_window = window.open('http://www.astrolab.be/html/acg_help.html',
    'help','toolbar=no,scrollbars,top=' + center_y(get_height()) +
    ',left=' + center_x(get_width()) +
    ',resizable=yes,width=' + get_width() +
    ',height=' + get_height());
}

