// from http://www.sitepoint.com/article/perfect-pop-up/2
//
// This works great to open and close popups on the same page
// (as with multiple links to different external pages on Amazon,
// for example). I haven't tested to see what happens when your
// browser has set to block popups, however! 
//
// One glitch I noticed: open a popup from one page, then move
// to another page which has popups and open one from there - the 
// first click will close the original popup, but fail to open
// the new one. This happens only when switching between pages.  

var newWin = null;
function popUp(strURL, strType, strHeight, strWidth) {
 if (newWin != null && !newWin.closed)
   newWin.close();
 var strOptions="";
 if (strType=="console")
   strOptions="resizable,height="+
     strHeight+",width="+strWidth;
 if (strType=="fixed")
   strOptions="status,height="+
     strHeight+",width="+strWidth;
 if (strType=="elastic")
   strOptions="toolbar,menubar,scrollbars,"+
     "resizable,location,height="+
     strHeight+",width="+strWidth;
 newWin = window.open(strURL, 'newWin', strOptions);
 newWin.focus();
}

// Note that "console" means no toolbars etc. Looks like I'll
// generally want "elastic" mode for links to Amazon, etc., or to 
// allow user to save a .gif file etc. 

// USAGE IN A LINK: 
//
// <a href="my-pop-up-window.htm"
//  onclick="popUp(this.href,'console',400,200);return false;"
//  target="_blank">This is my link</a>


// INFERIOR POPUP SCRIPT BELOW
// The below has the problem of not closing popups that have already been
// opened, which in effect loses focus on the popup if you try to open 
// more than one popup link on the same page. 

// from http://www.boutell.com/newfaq/creating/windowsize.html'
// Altered to favor opening the new window WITH menubar,
// toolbar, scrollbars, and resizeable - I want all those. 
function wopen(url, name, w, h)
{
// Fudge factors for window decoration space.
 // In my tests these work well on all platforms & browsers.
w += 32;
h += 96;
 var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
  'location=yes, menubar=yes, ' +
  'status=yes, toolbar=yes, scrollbars=yes, resizable=yes');
 win.resizeTo(w, h);
 win.focus();
 window.onload = win.focus();
}
// these instructions for the above:
// When it comes time to actually open such a window, just 
// write a link like the following:
//
// <a href="page.html" target="popup"
//  onClick="wopen('page.html', 'popup', 640, 480); return false;"> Click here to open the page in a new window. 


