Popup = {
   defaults:{
      toolbar:0,
      location:0,
      directories:0,
      status:0,
      scrollbars:'yes',
      menubar:0,
      resizable:'no'
   },
   
   windows:{},
   
   open:function ( url, windowName, width, height, override ) {
      var args = [];
      if ( !windowName ) {
         windowName='_blank';
      }
      args.push ( 'width=' + width );
      args.push ( 'height=' + height );
      args.push ( 'left=' + ( screen.width / 2 - width / 2 ) );
      args.push ( 'top=' + ( screen.height / 2 - height / 2 ) );
      
      for ( i in Popup.defaults ) {
         if ( i in override ) {
            args.push ( i + '=' + override[i] );
         } else {
            args.push ( i + '=' + Popup.defaults[i] );
         }
      }
      
      Popup.windows[windowName] = window.open (
         url,
         windowName,
         args.join ( ',' )
      )
      
      return Popup.windows[windowName];
   },
   
   close:function ( windowName ) {
      if ( 
         windowName in Popup.windows 
         && typeof (Popup.windows[windowName]) == 'object' 
         && typeof (Popup.windows[windowName].close) == 'function' 
      ) {
         Popup.windows[windowName].close();
         return true;
      }
      return false;
   }
}
if ( window.onload ) {
   f = window.onload;
} else {
   f = function(){}
}
window.onload = function () {
   f ();
   
   for ( var i in document.links ) {
      if ( document.links [ i ].href && document.links[i].target ){
         var m;
         if ( m = document.links[i].target.match ( /popup([0-9]+)x([0-9]+)/ ) ) {
            document.links[i].onclick = new Function ( "Popup.open(this.href,null, " + m[1] + ", " + m[2] + ", {}); return false;" );
         }
      }
   }
}
