// Copyright(c) 2004-2007, Second Phase, LLC, All rights reserved worldwide. www.secondphase.net
// JavaScript Document
// Display current page in 'printable' format in new window

// requires a div with id='printready' surrounding code to be displayed in print ready window
var autoPrint = false; // print page automatically
function disableLinks() {
    var elems = document.getElementsByTagName('a'); 
    for (var i=2; i<elems.length; i++) // skip over print page and close window links
        elems[i].removeAttribute('href');
    elems = document.getElementsByTagName('form');
    for (var i=0; i<elems.length; i++) { // disable forms
        elems[i].setAttribute('action', 'javascript:;');
        elems[i].setAttribute('onsubmit', 'return false;');
    }
}
function printablePage() {
  if (document.getElementById != null) var html = "<html>\n<head>\n";
  if (document.getElementsByTagName != null) var headTags = document.getElementsByTagName("head");
  if (headTags.length > 0) html += headTags[0].innerHTML;
  html += "\n</head>\n<body onload='disableLinks();' style='background-color:white;'>\n<div style='position:absolute; width:620px; left:30px;'>\n";
  var printReadyElem = document.getElementById("printready");
  if (printReadyElem != null) {
        html += "<div style='postion:absolute; left:0px; text-align:right;'><a href='javascript:window.print()'>print page</a>&nbsp;|&nbsp;<a href='javascript:window.close()'>close window</a></div>";
        html += "<div align='left'><img src='images/site/logo_printready.gif'></div><br>";
        html += printReadyElem.innerHTML;
  } else {
    alert("Could not find the printReady function");
    return;
  }
  html += "<br><br>";
  html += "\n</div>\n</body>\n</html>";

  var printWin = window.open("","","width=730,toolbar=no,location=no,directories=no,menubar=yes,status=no,scrollbars=yes");
  printWin.document.open();
  printWin.document.write(html);
  printWin.document.close();
  if (autoPrint) printWin.print();
}
