var aWindow = null;
var aWindowName = '';

function openPopup(URLtoOpen, windowName, width, height, scrollbars, resizeable, toolbar) {        
  var newWindowName = windowName+'_'+width+'x'+height;
  var positionStr = '';
  
  if (aWindow != null) {
    if (!aWindow.closed) { 
      if (aWindowName != newWindowName) {
        if (aWindowName != '') {
          if (aWindow.screenX) {
            positionStr = ',screenX='+aWindow.screenX+',screenY='+aWindow.screenY+
                          ',left='+aWindow.screenX+',top='+aWindow.screenY;
          } else {
            positionStr = ',screenX='+aWindow.screenLeft+',screenY='+aWindow.screenTop+
                          ',left='+aWindow.screenLeft+',top='+aWindow.screenTop;
          }
        } else {
          positionStr = '';
        }
     	  aWindow.close();
      }
    }
  }
  
  var newWindow = null;  
	newWindow = window.open(URLtoOpen, newWindowName,
    'width='+width+',height='+height+',scrollbars='+scrollbars+',toolbar='+toolbar+',resizeable='+resizeable+
    ',dependent=yes'+positionStr);        
  aWindow = newWindow;
  
  if (URLtoOpen.match(/^[a-z]+:/)) {
    aWindowName = '';
  } else {
    aWindowName = newWindowName;
  }
}
