
<!--

// modified: 06/03/2003   (mm/dd/yyyy)

/*
step-by-step manual:


what does this js do:
  Print one or more parts of the content of a page.
  
what to do to get this working:
  1a. Create an html document that should be printed. This html document is the template for the print job. 
  In this document you could add the address of the company. You might also want to include a close button:
  <button onClick="window.close();">close this window</button>

  1b.   Link this js to the page:
  <script language="JavaScript" type="text/javascript" src="/javascript/print_functions.js"></script>
  In the onLoad of the body of this print document you envoke the function printDIVsFromOpener. 
  Your body's beginning tag
  might look like this:
  <body onLoad="printDIVsFromOpener();">
  Bare in mind that javascript is case sensitive!
  If you don't want to add an extra button to close the window but rather close the window automatically
  after printing was done or canceled then you should add the window.close(); to you body onLoad, for instance:
  <body onLoad="printDIVsFromOpener(); window.close();">
  
  2. Put the content of the original document that should be printed in div-tags. Every part of the document that you
  would like to be printed should be enclosed within <div> and </div>
  Give every div that must be printed an id and name (must be the same ofcourse).
  You might have a div like this:
  <div id="print_div_maincontent" name="print_div_maincontent">
    bla bla bla bla
    yadiyadiyadiyadi
    bla bla.
  </div>
  
  It does not matter how you name your div's but it will clearify things if you include a word like 'print' in the id/name. 
  It doesn't matter where the content originally came from. 
  You might have an Updater template that looks like that (please note that these all are merely examples):
  <div id="print_div_maincontent" name="print_div_maincontent">
    <$
      type=TEXT
      varname=text01
      question=First text of page
    $>
  </div>
  
  Make absolutely sure that the content within all (all!) your div's are complete pieces of html. The following is not allowed:
  <p>
    <div>
      <!-- this is not allowed because the html within this div is not a complete piece of html 
           but with proper indent this is very obvious! (in other words: indent you code properly!)
      -->
      hello world!! \
  </p>
    </div>
  
  or
  <table>
    <div>
      <!-- this is not allowed because the html within this div is not a complete piece of html: 
           inside this div is half a table...! Only whole tables are allowed (though Internet Explorer might accept this)!
      -->
      <tr><td>hello</td><td>world!!</td></tr>
    </div>
  </table>
  
  
  3. Put div's in your print template with the same id/name as the div's you want to be printed. These div's
  should be left empty. You MAY put some content in them but this content will be replaced by this script. 
  (Adding content to the div's allows you to show a message like 'printing' while the script is still running. It's not
  guaranteed that this text *will* be shown)
  
 
  4. Add a window.open to your original document. This function must open the print document.
  You can also just use a <a href="my_print_doc..." target="_blank">print</a> construction. 
  Let's say the print document you just created is /templates/js_print.htm
  then a basic window.open link might look like this:
  <a href="#" onClick="window.open('/templates/js_print.htm'); return false;">print</a>
  but you will probably want to add (a name and) features, for instance:
  <a href="#" onClick="window.open('/templates/js_print.htm', '', 'status=no,height=300'); return false;">print</a>
  

  (REMOVED: 5. To use css-files add all the css files to your print doc that your site uses. 
  All included css files in your print doc which have exactly the same
  href as one of the css files in the original document will be enabled. All others
  will be disabled!)

  6. In the original document make sure that all flash movies have an id and name. 
  
  7. That's it. If you now click on the print link the print document opens and copies the div's innerHTML's 
  to the div in it with the same id/name and then prints itself. 
  If you get an error like 'object not found' please check if you included 
  the js correctly (check the path) and check if the function is in the onLoad of the body and ofcourse 
  correctly spelled (it is case sensitive!).  


*/




  /*
  ' function  : printDIVsFromOpener
  ' overview  : This function copies the content (in div's with the same name) of the document
  '             that opened this document to itself and then prints itself.
  '             This function must be put into the onLoad of the body tag of the opened document. 
  ' arguments : 
  ' returns   : 
  ' example   : <body onLoad="copyDIVsFromOpener(); window.close();">
  */
  function printDIVsFromOpener()
  {
/*  
    // enable the correct css's
    for (var iStyleSheet = 0; iStyleSheet < document.styleSheets.length; iStyleSheet++)
    {
      document.styleSheets[iStyleSheet].disabled = true;
      for (var iStyleSheetInOpener = 0; iStyleSheetInOpener < opener.document.styleSheets.length; iStyleSheetInOpener++)
      {
        if (document.styleSheets[iStyleSheet].href == opener.document.styleSheets[iStyleSheetInOpener].href)
        {
          document.styleSheets[iStyleSheet].disabled = false;
          break; // break out of the for loop
        }
      }
    }
*/  

    // copy the content of the divs of the opener document into the divs in this document
    var allElements = window.opener.document.getElementsByTagName('div');
    for (var iElement = 0; iElement < allElements.length; iElement++)
    {
      var objElement = allElements[iElement];
    
      // if this window has an element with the same id as the element found in the opener then paste the HTML into it
      var sDivId = objElement.id;
      if (sDivId != '')
      {
        if (document.getElementById(sDivId))
        {
          document.getElementById(sDivId).innerHTML = window.opener.document.getElementById(sDivId).innerHTML;
        }
      }
    }
    
    
    // enable ALL flash movies
    allElements = window.opener.document.getElementsByTagName('object');
    for (iElement = 0; iElement < allElements.length; iElement++)
    {
      // Play the movie (cannot be done with objElement.Play(), note that the function is called Play() not play()!)
      // because objElement.Play() does not work this method is used and required that the flash movie has an ID.
      objElement = allElements[iElement];
      
/*      var sallprop = '';
      for (var prop in objElement)
      {
        sallprop += prop + ' = ' + objElement[prop] + '  |  ';
      }
      alert(sallprop);
*/      
  
      // play the flash movie (it might not be a flash movie, therefor 'try')    
      try 
      {
        document[objElement.id].Play();
      }
      catch(ex)
      {
        // if Play could not be envoked, just continue
      }
    }

    // print this window after one second so that the flash movies are running
    window.setTimeout('window.print();', 1000);
    
  } 

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

// ----------------------------------------------------------





  
  /*  
  ' function  : stringOrEmptyStringIfNull
  ' overview  : returns the given string or '' if the string is null
  ' arguments : [in] sString
  ' returns   : string
  ' example   :
  */ 
  function stringOrEmptyStringIfNull(sString)
  {
    if (sString)
    {
      return sString;
    }
    else
    {
      return '';
    }
  }



-->
