

if (typeof onerror != 'undefined') reportErrors = onerror;


window_link = '';
window_name = '';
window_width = '';
window_height = '';

function retry_window_open(errorMessage, url, line) {
	new_window = window.open('',window_name);
	new_window.close();
	openWindow(window_link,window_name,window_width,window_width);
	onerror = reportErrors;
	return true;
}

function openWindow( link, name, width, height ) {
	if (name==undefined) name='';
	name = name.replace(/[^a-z0-9]/gi,'_');
	if (width==undefined) width=800;
	if (height==undefined) height=500;
	// if we have been assed in the link object rather than the url string
	// then extract then read the url from the link
	if ( link.href!=undefined ) link = link.href;

	// if we have previously opened this window and then they have
	// navigated to another site trying to re-open a window with the
	// same name causes errors. So... we remember what we were doing
	// and when opening the window set the error handler to a function
	// which closes the old window before retrying the window open operation.
	window_link = link;
	window_name = name;
	window_width = width;
	window_height= height;

	onerror = retry_window_open;
	new_window = window.open('',name,'width='+width+',height='+height+',resizable=yes,directories=no,location=yes,scrollbars=1,status=yes,toolbar=yes');
	new_window.name = name; //for safari

	new_window.document.write('<HTML>Loading. Please wait...</HTML>');

	if (link) new_window.location.href=link;
	//if (link) window.open(link,name);

	new_window.focus();
	return new_window;
}

function debug_alert( thing, print_values ) {
        output = '';
        for( property in thing ) {
                output += property;
                if (print_values && eval('thing.'+property) ) output += '="'+eval('thing.'+property+'.toString()')+'"';
                output += ', ';
        }
        window.alert( output );
}



