/* popup_window.js Pops up a new window maybe with email
   New window is slightly narrower that caller, has a "Close" button
   Copyright (C) 2009 - 2011  Jeffrey Hennick, o l r e g @ j e f f - h . c o m
   Part of Registration / Administation System. GLP License in ../copyleft.php.
*/
// 05/25/09
// 12/31/09 Use <object> so can add close-button. JH
//  1/ 4/10 More documentation; shortened lines per Ed. JH
//  4/17/11 Som += to +. JH


 function mailto(n) {  // Special shortcut for VictorHikingTrails.Org
  openPopup('vht_mail_form.php?to=' + n);
 }

 function openPopup(page,text,force_new,width,height) {  // make a window!
   var id = (force_new) ? Math.floor(Math.random()*9999999) : '';
   var WindowObjectReference;  // Going to be our new window
   var w = (width>0) ? width : window.outerWidth * .9;
   var h = (height>0) ? height : window.outerHeight;
   if(id != '' || WindowObjectReference == null || WindowObjectReference.closed) {
   /* if the pointer to the window object in memory does not exist
      or if such pointer exists but the window was closed */

     var wname = "WinName" + id;

     WindowObjectReference = window.open(page,wname,
       "resizable=yes,scrollbars=yes,status=yes,width=" + w + ",height=" + h);
     /* then create it. The new window will be created and
        will be brought on top of any other window. */
   }

   if (window.focus) WindowObjectReference.focus();
     /* the window reference must now exist and the window
        is not closed; therefore, we can bring it back on top of any other
        window with the focus() method.  */

/* This is not working. Reverting. Added page to window.open.
   IE8 is not scrolling to id, IE7 is non-standard

     // Add a "close"-button

   if (page != '') {
     var o = "<html><body><div style='position:fixed;top:" + (h-150) + "px;";
           + "left:20px;z-index:999'> <button onclick='window.close()'>"
           + "Close Window</button></div><object data='" + page
           + "' type='text/html' WIDTH='100%' height='100%'>"
           + "<script type='text/javascript'>"
           + "document.location = '" + page + "';"
           + "</object></body></html>";

     // Add it to the page
   }
   else {
     var o = "<html><body><div style='position:fixed;top:" + (h-150) + "px;";
           + "left:20px;z-index:999'> <button onclick='window.close()'>"
           + "Close Window</button></div>"
           + text;
           + "</body></html>";
   }

   WindowObjectReference.document.write(o);
   WindowObjectReference.document.close();
*/
 }

