var	winRight	 = 0;
var 	winBottom	 = 0;

function popwin(url,name,width,height,options) {
	win_size();

	var x = ( width < winRight ? (winRight - width)/2 : 50 );
	var y = ( height < winBottom ? (winBottom-height)/2 : 50 );

	//
	// default options:
	//
	if ( ! options || options == '' ) options = 'scrollbars=yes,resizable=yes';

	var opts = 'width='+width+',height='+height+',screenx='+x+',screeny='+y+',left='+x+',top='+y+','+options;
	popup = window.open(url,name,opts);
	popup.focus();
}

function popup_window(url,name,width,height,options) {
	win_size();

	var x = ( width < winRight ? (winRight - width)/2 : 50 );
	var y = ( height < winBottom ? (winBottom-height)/2 : 50 );

	//
	// to initiate correct sub-nesting of templates, we add a parameter
	//
	var rg = new RegExp(/\/$/);
	var tp = ( rg.test(url) ? 'pop.htm' : '' );

	//
	// non-path_info version
	//
//	var rg = new RegExp(/\?\w+=.+/);
//	var tp = ( rg.test(url) ? '&type=pop' : '?type=pop' );


	//
	// default options:
	//
	if ( ! options || options == '' ) options = 'scrollbars=yes,resizable=yes';

	popup = window.open(url+tp,name,'width='+width+',height='+height+',screenx='+x+',screeny='+y+',left='+x+',top='+y+','+options);
	popup.focus();
}

function close_popup() {
	if ( confirm('Any changes that you have not yet saved will be lost') ) window.close();
}

function win_size() {
	if ( window.innerWidth ) winRight = window.innerWidth;
	if ( window.innerHeight ) winBottom = window.innerHeight;
	if ( winRight == 0 ) winRight = document.body.clientWidth;
	if ( winBottom == 0 ) winBottom = document.body.clientHeight;
	if ( winBottom > 800 ) winBottom = 800;
}

function href_parent(url) {
	if ( opener ) opener.document.location.href=url;
}