//-------------------------------------------------------------------------
// getMainWindow - returns the top most window of the main frame
//-------------------------------------------------------------------------
function getMainWindow() {
	var win = self.top;
	while (win.opener) win = win.opener.top;
	return win;
}


var process_window = null;

//-------------------------------------------------------------------------
// beginProcessing - open up the processing window
//-------------------------------------------------------------------------
function beginProcessing(p_win, p_target_win) {
	if (p_target_win == null) return;
	p_target_win.process_window = p_win.open('Processing.html', 'winProcessing', 'width=350,height=120,left=' + ((screen.width-300)/2) + ',top=' + ((screen.height-200)/2));
	p_target_win.setInterval('continueProcessing()', 1000);
}

function continueProcessing() {
	if (process_window == null || process_window.closed) return;
	if (process_window.active_flag == null) return;
	process_window.active_flag = true;
}


//-------------------------------------------------------------------------
// openWindow - opens an url in p_target, returning the resulting window
//-------------------------------------------------------------------------
function openWindow(p_form, p_url, p_target, p_wait, p_width, p_height, p_other_features) {
	var features;
	var new_window = null;
	// var win = getMainWindow();
	var win = window;
	if (p_target == null) p_target = win.name;

	// build all the features into an array
	features = new Array();
	if (p_width) features[features.length] = 'left=' + ((screen.width-p_width)/2) + ',width=' + p_width;
	if (p_height) features[features.length] = 'top=' + ((screen.height-p_height)/2) + ',height=' + p_height;
	if (p_other_features) features[features.length] = p_other_features;

	// submit data
	if (p_form == null) new_window = open(p_url, p_target, features.join(','));
	else {
		if (p_form.onsubmit != null) {
			if (!p_form.onsubmit()) return null;
		}
		if (features.length > 0) new_window = open('BlankPage.html', p_target, features.join(','));
		else new_window = open('BlankPage.html', p_target);
		// else new_window = open('javascript:;', p_target);
		if (p_wait != null && p_wait == true) beginProcessing(win, new_window);
		p_form.action = p_url;
		p_form.method = 'post';
		p_form.target = p_target;
		p_form.submit();
	}
	return new_window;
}


