//  ProtoTypes:
// requires inclusion of
// cgiBasePath.js
// utilsString.js
// utilsTracker.js


function openCenteredWindow (width, height, windowName, scroll, url, htmlText, focus)
{
  var winName = "" + windowName;
  var winprops = "";
  var scrollbars = scroll;


  var doc_width  = width;
  var doc_height = height;
  var screenHeight = screen.height;

  if (doc_height > (screen.height-100) )
  {
   screenHeight = screenHeight - 100;
   doc_height = screenHeight;
   doc_width  = doc_width + 17;
   scrollbars = 'yes';
  }
  if (doc_width > screen.width)
  {
   doc_width = screen.width - 20;

   if (IsEmpty (scrollbars) || scrollbars == 'no' || scrollbars == 'false' || scrollbars == 'FALSE' || scrollbars == '0')
   {
     doc_height = doc_height + 17;
     scrollbars = 'no';
   }
   else
   {
     scrollbars = 'yes';
   }
  }

  var winl = (screen.width - doc_width) / 2;
  var wint = (screenHeight - doc_height) / 2;

  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;

  winprops = 'height='+doc_height+',width='+doc_width+',top='+wint+',left='+winl+',scrollbars='+scrollbars+',status=1,toolbar=0,resizable';

  msgWindow=window.open(url,winName,winprops);

  if (focus == 1)
    msgWindow.focus();
  else
    msgWindow.blur();

  if (!IsEmpty (htmlText))
  {
    msgWindow.document.write (htmlText);
    msgWindow.document.close ();
  }
}

function openImageWindow (x, y, dx, dy, windowName, fileName, trackName, trackOwner, trackEmail )
{
  var startX, startY, winWidth, winHeight, allowScroll;

  var screenOffsetX = 0;
  var screenOffsetY = 30;

  allowScroll = 0;
  startX = x;
  startY = y;

  winWidth = dx;
  winHeight= dy;

  if (x < 0  || y < 0 )      // set for centered
  {
    if (winWidth < screen.width)
    {
      startX = (screen.width - winWidth) / 2;
    }
    else
    {
      startX = 0;
      winWidth = screen.width - 15; //account for scroll bar
      allowScroll = 1;
    }


    if (winHeight < (screen.height-80) )
    {
      startY = (screen.height-80 - winHeight) / 2;
    }
    else
    {
      startY = 0;
      winHeight = screen.height-80;
      allowScroll = 1;
    }
  }
  else  // check if winWidth and winHeight exceed screen dims. and resize
  {
     if ( (x + winWidth) > screen.width )
     {
        winWidth = screen.width - x;
        allowScroll = 1;

     }
     if ( (y + winHeight) > screen.height )
     {
        winHeight = screen.height - y;
        allowScroll = 1;
   }
  }

  var winprops = 'height=' + winHeight + ',width=' + winWidth + ',top=' + startY + ',left=' + startX +
                 ',scrollbars=' + allowScroll +', status=0, toolbar=0, resizable';

  msgWindow=window.open("",windowName,winprops);

  msgWindow.document.write ('<HTML>\n');
  msgWindow.document.write ('<BODY topmargin=0 leftmargin=0 marginwidth=0 marginheight=0 onload="window.focus()" bgcolor="#000000">');
  msgWindow.document.write ('<table width="100%" height="100%" cellspacing=0 cellpadding=0 ><tr><td align=center><a href="javascript:window.close()"><IMG src="' + fileName + '" border=0 hspace=0 vspace=0 alt="Click to close" ></a></td></tr></table>');

  // if (!IsEmpty (trackName) )
  //  track (msgWindow.document, trackOwner, trackName, trackEmail);

  msgWindow.document.write ('</BODY>\n');
  msgWindow.document.write ('</HTML>');
  msgWindow.document.close ();

  msgWindow.focus();

}
//----------------------------------------------------------------------------------
