var aWin;

function openPopup(page, title, parms, width, height, top, left )
{
   op_page=page;
   if(parms != null)
      if(parms != '')         
         op_page = page + '?' + parms;
         
   if(width == null)
   	width=350;
   if(height == null)
   	height=450;
   if(top == null)
	top = (screen.height - height) / 2;
   if(left == null)
   	left = (screen.width - width) / 2;
    
   attrib = 'scrollbars=yes, status=yes, left='+left+', top='+top+', width='+width+', height='+height;
   return window.open(op_page, title, attrib);
}

function closePopup(win)
{
  if(win != null)
    if(!win.closed)
    {
     	win.close();
     	win=null;
    }
}

function openModal(page, title, parms, width, height, top, left )
{
   // se il browser non gestisce le windows modali, si comporta come
   // per una usuale popup
   if(!window.showModalDialog)
      return openPopup(page, title, parms, width, height, top, left );
      
   op_page=page;
   if(parms != null)
      if(parms != '')         
         op_page = page + '?' + parms;
         
   if(width == null)
   	width=350;
   if(height == null)
   	height=450;
   if(top == null)
	top = (screen.height - height) / 2;
   if(left == null)
   	left = (screen.width - width) / 2;
   	
   attrib='dialogWidth:'+width+'px'+',dialogHeight:'+height+'px'+',dialogTop:'+top+'px'+',dialogLeft:'+left+'px';
   return showModalDialog(op_page,window,attrib);
}

function openWindow(page, title, parms, width, height, top, left, modal)
{
	if(modal == null) modal=false;
	
	/***
	if(isOpen(aWin))
	{
		aWin.focus()
		return;	
	}
	***/
	
	if(modal)
		aWin = openModal(page, title, parms, width, height, top, left);
	else
		aWin = openPopup(page, title, parms, width, height, top, left);
}

function closeWindow()
{
	closePopup(aWin);
}

function isOpen(win)
{
	if(win == null) return false;
	if(win.closed) return false;
	
	return true;	
}
