How would one do the following in Javascript:
Somebody clicks on a link, and Javascript checks if the window called "popup" has already been opened, if it hasn't it opens it. If the user is clicking the link a second time it brings the popup to focus rather than re-opening it.

I've tried something like:
PHP Code:
<script language="javascript" type="text/javascript"><!--
 var 
winref null;
function 
addWindow(add_window_url) {

if (
winref==null || winref.closed) {
         
winref window.open(add_window_url,'popup');
} else {
winref.focus();
}
return 
false;
}
//--></script> 
But that didn't work.