var fromBookPage = false;

function showPreview()
{
   var WebBrowser = '<OBJECT ID="oWebBrowser" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';

   document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
   oWebBrowser.ExecWB( 7, 1 );
   oWebBrowser.outerHTML = "";

   // This won't close the temporary preview window is the Preview is closed
   // by clicking on the right X button
   close();
}

function printMemoryBook(sessionId)
{
   return openPrintPDFWindow('stageReviewBookReviewMemoryBookPDF.do', sessionId);
}

function reviewCurrentMemoryBook(sessionId)
{
   if(top.workArea.bookArea.updateMemorybookHiddenForm)
      top.workArea.bookArea.updateMemorybookHiddenForm();
   else
      top.workArea.bookArea.updateStageForm();

   return printMemoryBook(sessionId);
}

function openPrintPDFWindow(action, sessionId)
{
   var windowName = 'printPdf';
   return openPrintWindow(action, windowName, sessionId);
}

//
// (YS) for SP2, we only popup the window. Session expiration check must be performed in a
// seperate thread
//
// todo: unite this code with trackmyorder.jsp openPrintWindow() and orderReceipt.jsp openMyPrintWindow()
function openPrintWindow(action, windowName, sessionId)
{
   var url=action;
   var urlParam="url="+escape(url);
   var sessionIdParam="&sessionId="+escape(sessionId);
   var newWin = window.open(getContextPath()+"/common/checkSessionAndRedirect.do?"+urlParam+sessionIdParam, windowName, 'top=50,width=700,height=500,status=no,resizable=yes,scrollbars=yes');
   //window.open(getContextPath() + "/" + url, windowName, 'top=50,width=700,height=500,status=no,resizable=yes,scrollbars=yes') ;
   if(newWin)
   {
      try
      {
         newWin.focus();
      }
      catch(e)
      {
         // focus failed - no need to handle this error         
      }
      return true;
   }
   else
   {
      return false;
   }
}


// the following function does the same as 'reviewMemoryBook(mbId)' in print.js, but since the main-frameset is not our 'top'
// we couldn't reuse that code.
function reviewMemoryBookPDF(mbId, sessionId)
{
   var printCommand = 'showMemoryBookPreview.do?'+top.memoryBookConstants.MB_ID_PARAM_NAME+'='+mbId;
   openPrintPDFWindow(printCommand, sessionId);
}
