if (!reservation_printing_js_included) { var reservation_printing_js_included = true;

includeJavaScript('common/misc_utility.js');

var Printing_hideNoPrintItemsFn;

function Printing_setup(hideNoPrintItemsFn)
{
  Printing_hideNoPrintItemsFn = hideNoPrintItemsFn;

  if(document.location.href.match("[?&]printnow=(?:1|true|printnow)"))
  {
    execOnLoad(Printing_onloadprint);
  }
}

function Printing_initiate(urlOrForm)
{
  if(!urlOrForm)
    urlOrForm = window.location.href;

  var useForm = useForm = urlOrForm.tagName;

  if(document.getElementById("Printing_Frame"))
  {
    document.body.removeChild(document.getElementById("Printing_Frame"));
  }

  var printingFrame = document.createElement("iframe");
  printingFrame.id = "Printing_Frame";
  printingFrame.name = "Printing_Frame";

  if(!useForm)
  {
    printingFrame.src =
        urlOrForm
        + (-1 == urlOrForm.indexOf("?") ? "?" : "&") + "printnow=1";
  }
  else
  {
    if(/MSIE/i.test(navigator.userAgent))
      printingFrame.src = "dummy";
      // Somewhat ugly workaround to prevent IE from showing the irrelevant
      // "this page contains both secure and insecure objects" warning.
  }

  printingFrame.style.height = 0;
  printingFrame.style.position = "absolute";
  printingFrame.style.top = "-1000px";

  document.body.appendChild(printingFrame);

  if(useForm)
  {
    var origFormTarget = urlOrForm.target;
    var origFormAction = urlOrForm.action;

    if(! /opera/i.test(navigator.userAgent))
      printingFrame.contentWindow.name = printingFrame.name;
          // This is needed for IE to work (it doesn't infer frame name
          // from the <iframe> tag name).
          // On the other hand, in Opera this statement causes JS errors...

    urlOrForm.target = printingFrame.name;
    urlOrForm.action =
        window.location.href
        + (-1 == window.location.href.indexOf("?") ? "?" : "&") + "printnow=1";
    urlOrForm.submit();

    urlOrForm.target = origFormTarget;
    urlOrForm.action = origFormAction;
  }
}

function Printing_onloadprint()
{
  if (Printing_hideNoPrintItemsFn) Printing_hideNoPrintItemsFn();

  window.focus();
  window.print();
}

}

