// This function is called in the onload event of each page. It looks for the menu frame
// by going up in the frameset hierarchy.
function showPrintButtonsInMenuFrame() {
  var p = window.parent;
  while (p.frames.length > 0) {
    if (p.frames.length > 1 && p.frames[0].name == 'frmMenu') {
      // Set the state of the print buttons in the menu frame
      var frmMenu = p.frames[0];
      if (frmMenu != null) {
        if (typeof(frmMenu.showPrintButtons) != 'undefined') {
          frmMenu.showPrintButtons();
        }
      }
      break;
    }
    else {
      // Start looking in the parent frame
      p = p.parent;
    }
  }
}

// Set the state of the print buttons.
// There are 2 situations:
// 1. The content frame contains only 1 page
// 2. The content frame contains 1 frameset containing a left page and a right page
function showPrintButtons() {
  if (typeof(SessionGuard_Reset) != 'undefined') {
    SessionGuard_Reset();
  }

  // There are 3 print buttons:
  // 1. aPrintWnd prints the current page when there is only one
  // 2. aPrintLeftWnd prints the left page
  // 3. aPrintRightWnd prints the right page
  document.all["aPrintWnd"].style.display = "none";
  document.all["aPrintLeftWnd"].style.display = "none";
  document.all["aPrintRightWnd"].style.display = "none";

  var frmContents = window.parent.frames[1];
  if (frmContents != null) {
    if (frmContents.frames.length == 0) {
      // Contents frame doesn't contain frames. It is filled with a normal page!
      document.all["aPrintWnd"].style.display = "inline";
    }
    else if (frmContents.frames.length == 2) {
      // Contents frame itself contains a frameset containing a left page and a right page!
      document.all["aPrintLeftWnd"].style.display = "inline";
      document.all["aPrintRightWnd"].style.display = "inline";
    }
  }
}

function printScreen(sWnd) {
  var frmContents = window.parent.frames[1];
  if (frmContents != null) {
    if (sWnd == 'wnd') {
      if (frmContents.frames.length == 0) {
        frmContents.window.focus();
        frmContents.window.print();
      }
    }
    else if (sWnd == 'wndLeft') {
      if (frmContents.frames.length > 0) {
        frmContents.frames[0].focus();
        frmContents.frames[0].print();
      }
    }
    if (sWnd == 'wndRight') {
      if (frmContents.frames.length > 1) {
        frmContents.frames[1].focus();
        frmContents.frames[1].print();
      }
    }
  }
}
