// ======================================================================
// PUP.JS
//     defines routines for creating javascript pop up windows
// ======================================================================

// routines for assembling pop up window options

function optPop( r, s, m, b, i, t, x, y )
{
   var o =  'resizable='   + r
         + ',scrollbars='  + s
         + ',menubar='     + m
         + ',toolbar='     + b
         + ',location='    + i
         + ',status='      + t

   if (x >= 0) o = o  + ",left=" + x
   if (y >= 0) o = o  + ",top="  + y

   return( o );
}

function optNul()                { return( optPop( 0, 0, 0, 0, 0, 0, -1, -1 ) ); }
function optAll()                { return( optPop( 1, 1, 1, 1, 1, 1, -1, -1 ) ); }

function optAdd(o1,o2)
{
   if (o1.length < 1) return(o2);
   if (o2.length < 1) return(o1);
   return( o1 + ',' + o2 );
}

function optNum(i,s)             { return( (i<0) ? '' : s + '=' + i ); }
function optSiz(w,h)             { return( optAdd( optNum(w,'width'), optNum(h,'height') ) ); }
function optPos(l,t)             { return( optAdd( optNum(l,'left' ), optNum(t,'top'   ) ) ); }
function optCen(w,h)
{
   if (self.screen)
   {
      var l = ((screen.width)  ? (screen.width-w)/2  : 0);
      var t = ((screen.height) ? (screen.height-h)/2 : 0);
      return( optPos(l,t) );
   }
   return('');
}
function optLocCen(w,h)          { return( optAdd( optSiz(w,h), optCen(w,h) ) ); }
function optLocPos(w,h,l,t)      { return( optAdd( optSiz(w,h), optPos(l,t) ) ); }

// various flavors of pop up windows

function popUpOpt(r,n,w,h,o)     { window.open( r, n, optAdd( optSiz(w,h)        , o        ) ); }
function popUpDef(r,n,w,h)       { window.open( r, n, optAdd( optSiz(w,h)        , optNul() ) ); }
function popUpCen(r,n,w,h)       { window.open( r, n, optAdd( optLocCen(w,h)     , optNul() ) ); }
function popUpPos(r,n,w,h,l,t)   { window.open( r, n, optAdd( optLocPos(w,h,l,t) , optNul() ) ); }
function winUpOpt(r,n,o)         { window.open( r, n,                              o          ); }
function winUpDup(r,n)           { window.open( r, n,                              optAll()   ); }
function winUpCen(r,n,w,h)       { window.open( r, n, optAdd( optLocCen(w,h)     , optAll() ) ); }
function winUpPos(r,n,w,h,l,t)   { window.open( r, n, optAdd( optLocPos(w,h,l,t) , optAll() ) ); }
function cusUpCen(r,n,w,h,o)     { window.open( r, n, optAdd( optLocCen(w,h)     , o        ) ); }
function cusUpPos(r,n,w,h,o,l,t) { window.open( r, n, optAdd( optLocPos(w,h,l,t) , o        ) ); }

