var dialogueWindows = new Object();

onunload = closeAllDialogues;

function openDialogue( windowName, windowUrl, windowWidth, windowHeight ) 
{	
	var dialogue = dialogueWindows[ windowName ];
	var windowTop = ( screen.height / 2 ) - ( windowHeight / 2 );
	var windowLeft = ( screen.width / 2 ) - ( windowWidth / 2 );
	var features = 'height=' + windowHeight + ',width=' + windowWidth + ',top=' + windowTop + ',left=' + windowLeft + ',scrollbars=no,resizable=yes,status=no';
	
	if( dialogue && ! dialogue.closed )
		dialogue.close();
	
	dialogueWindows[ windowName ] = window.open( windowUrl, windowName, features );
}

function closeDialogue()
{
	if( window.opener && ! window.opener.closed ) 
	{
		window.opener.focus();
	}
	window.close();
}

function closeAllDialogues()
{
	for( windowName in dialogueWindows )
	{	
		var dialogue = dialogueWindows[ windowName ];
		
		if( dialogue && ! dialogue.closed )
		{
			dialogue.close();
		}
	}
}

function completeDialogue() 
{	
	if( window.opener && ! window.opener.closed ) 
	{
		window.opener.location.reload();
	}
	closeDialogue();
}

function parseGetVars() 
{
    var args = new Array();
    var query = window.location.search.substring( 1 );
    if( query ) 
    {
        var strList = query.split( '&' );
        for( str in strList ) 
        {
            var parts = strList[ str ].split( '=' );
            args[ unescape( parts[ 0 ] ) ] = unescape( parts[ 1 ] );
        }
    }
    return args;
}


function fitImage() 
{
	var offsetWidth = 12;
	var offsetHeight =  30;

	var windowWidth = document.images[0].width + offsetWidth;
	var windowHeight = document.images[0].height + offsetHeight;

	var windowTop = ( screen.height / 2 ) - ( windowHeight / 2 );
	var windowLeft = ( screen.width / 2 ) - ( windowWidth / 2 );

	window.moveTo( windowLeft, windowTop );
	window.resizeTo( windowWidth, windowHeight ); 

	self.focus(); 
}
