﻿function printpreview()
{
    var OLECMDID = 7;
    /* OLECMDID values:
    * 6 - print
    * 7 - print preview
    * 1 - open window
    * 4 - Save As
    */
    var PROMPT = 1; // 2 DONTPROMPTUSER 
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
    document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
    WebBrowser1.ExecWB(OLECMDID, PROMPT);
    WebBrowser1.outerHTML = "";
}


function subInDivs(tagName, typeName) 
{   
   var collTextAreas = document.getElementsByTagName(tagName);
   var oNewDiv;
   var sTemp;
   var i;

   for (i = 0; i < collTextAreas.length; i++) 
   {
      
      //if this is an input, we must ensure we have the correct type
      if (tagName != "INPUT" || (tagName == "INPUT" && collTextAreas[i].type != null && collTextAreas[i].type.toUpperCase()  == typeName.toUpperCase()))
      {
      
          oNewDiv = document.createElement("SPAN");
          oNewDiv.style.width = collTextAreas[i].clientWidth;
          oNewDiv.style.height = collTextAreas[i].clientHeight;
          oNewDiv.className = 'printDiv' + ' ' + collTextAreas[i].className;
          oNewDiv.id = collTextAreas[i].uniqueID + "_printspan";

          // replace all line breaks with HTML line breaks
          sTemp = collTextAreas[i].value.replace(/\n/gi,"<BR>"); 

          // match 2 spaces with to non-breaking spaces
          sTemp = sTemp.replace(/\s\s/gi,"&nbsp;&nbsp;"); 

          oNewDiv.innerHTML = sTemp;      
          collTextAreas[i].parentNode.insertBefore(oNewDiv, collTextAreas[i]);
          collTextAreas[i].style.display = "none";
          oNewDiv = null;
      
      } //end check for inputs vs other elements
   } //end for loop through found controls
}

function putBackTextAreas(tagName, typeName)
{
   var collTextAreas = document.getElementsByTagName(tagName);
   var oDivToRemove;
   var i;

   for (i = 0; i < collTextAreas.length; i++) 
   {
      
      //if this is an input, we must ensure we have the correct type
      if (tagName != "INPUT" || (tagName == "INPUT" && collTextAreas[i].type != null && collTextAreas[i].type.toUpperCase()  == typeName.toUpperCase()))
      {
      
          oDivToRemove = document.getElementById(collTextAreas[i].uniqueID + "_printspan");
          if (oDivToRemove != null)
          {
             oDivToRemove.parentNode.removeChild(oDivToRemove);
          }
          collTextAreas[i].style.display = "";
      } //end check for inputs vs other elements
   } //end for loop through found controls

}

