/* print-ctrlp.js: simple print page generated via CTRP-P key */
var newsection;

/* convert document into its printable form */
function chgtoprint() {
  /* 1: move contents of the right column to the page's bottom and make right column invisible */
  var contrgt = document.getElementById("rechts");
  var cpynode = contrgt.cloneNode(true);
  document.getElementById("spalterechts").style.display = "none";
  var conttabl = document.getElementById("contentarea");
  newsection = conttabl.parentNode.insertBefore(cpynode, conttabl.nextSibling);

  /* 2: convert anchor's target and content into plain text form */
  var allatags = newsection.getElementsByTagName("a");
  var ix = 0;
  while (allatags[ix]) {
    if (allatags[ix].firstChild) {
      var aconts = allatags[ix].innerHTML.replace(/\<img.*?\>/gi, '');
      aconts = aconts.replace(/&nbsp;|\<br\>/gi, ' ');
      var refline1 = document.createTextNode(aconts);
      allatags[ix].parentNode.insertBefore(refline1, allatags[ix]); /* link-title */
      var refline2 = document.createTextNode(': [' + allatags[ix].href + '] ');
      allatags[ix].parentNode.insertBefore(refline2, allatags[ix]); /* link-address */
      allatags[ix].style.display = "none";
    }
    ix++;
  }
  newsection.style.borderTop = "1px solid silver";
}

/* restore page design on return from print */
function retrnfrprnt() {
	newsection.parentNode.removeChild(newsection);
	document.getElementById("spalterechts").style.display = "block";
}

/* Test if CTRL-p (print key) is pressed and do the print-page modifications
   (this is needed as long as FF doesn't support 'onbeforeprint' and 'onafterprint')
*/
function isctrlp(e){
  var evtobj = window.event ? event : e;
  var kyCode = evtobj.charCode ? evtobj.charCode : evtobj.keyCode;
  var StdKey = String.fromCharCode(kyCode);
  var ShfKey = '';
  if (evtobj.altKey || evtobj.ctrlKey || evtobj.shiftKey) {
    ShfKey = (evtobj.shiftKey ? "SHIFT+": "");
    ShfKey += (evtobj.ctrlKey ? "CTRL+": "");
    ShfKey += (evtobj.altKey ? "ALT+": "");
  }
  if (ShfKey+StdKey == "CTRL+p") { /* accept CTRL-p only */
    chgtoprint();
    window.setTimeout("retrnfrprnt()", 300);
  }
}
if (!(window.onbeforeprint !== undefined)) {
  /* no 'onbeforeprint' and 'onafterprint', so we catch CTRL-p */
  document.onkeypress = isctrlp;
}
