/* print */

var daysArray = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var monthsArray = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

function writeDate()
{
  var returnValue = '';
  var now = new Date();
  returnValue += daysArray[now.getDay()] + ', ' + monthsArray[now.getMonth()] + ' ' + now.getDate() + ', ' + ((now.getFullYear) ? now.getFullYear() : now.getYear()) + ' at ' + ((now.getHours() > 12) ? now.getHours() - 12 : now.getHours()) + ':' + ((now.getMinutes() < 10) ? '0' + now.getMinutes() : now.getMinutes()) + ' ' + ((now.getHours() > 12) ? 'PM' : 'AM');
  return returnValue;
}

function setBeforePrint()
{
  oMain = document.getElementById('content');
  oMainLinks = oMain.getElementsByTagName('A');
  if(oMain && oMainLinks.length)
  {
    var aLinks = new Array();
        aLinks[0] = '';
    
    for(var i = 0; i < oMainLinks.length; i++)
    {
      sHref = oMainLinks[i].href;
      sName = oMainLinks[i].name;
      sClass = oMainLinks[i].className;
      sText = oMainLinks[i].innerText;
      sHTML = oMainLinks[i].innerHTML;
      
      parentPath = oMainLinks[i];

      while(!parentPath.style.display && parentPath.tagName.toUpperCase() != 'BODY')
        parentPath = parentPath.parentNode;
      if(parentPath.style.display == 'none')
        sHref = null;
      if(sHref && sClass.indexOf('noprint') != -1)
        sHref = null;
      if(sHref && sHref.toLowerCase().indexOf('javascript:') == 0)
        sHref = null;
      if(sHref && sHref.toLowerCase().indexOf('ymsgr:') == 0)
        sHref = null;
      if(sHref && sHref.toLowerCase().indexOf('aim:') == 0)
        sHref = null;
      if(sHref && sHref == sText)
        sHref = null;
      if(sHref && sHref.replace('mailto:', '') == sText)
        sHref = null;
  
//      if(sHref && sHref.indexOf('http:\/\/' + location.host) == 0)
//        sHref = sHref.replace('http:\/\/' + location.host, '');
//      if(sHref && sHref.indexOf('https:\/\/' + location.host) == 0)
//        sHref = sHref.replace('https:\/\/' + location.host, '');
  
      if(sHref && sHref.indexOf(location.pathname) == 0)
      {
        sHref = sHref.replace(location.pathname, '');
        if(sHref.indexOf('?') == 0 || sHref.indexOf('#') == 0)
          sHref = null;
        else
          sHref = location.pathname + sHref;
      }

      if(sHref)
      {
        iLinks = aLinks.length;
        aLinks[iLinks] = sHref;
        oMainLinks[i].oldInnerHTML = oMainLinks[i].innerHTML;
        oMainLinks[i].innerHTML += ' [' + iLinks + ']';
      }
    }
    if(aLinks != '' && aLinks.length != 0)
    {
      oFootnote = document.createElement('DIV');
      oFootnote.id = 'footnote';
      oFootnoteH6 = document.createElement('H6');
      oFootnoteH6.innerHTML = 'Footnotes &#8212; Numbers correspond to items with numbered brackets in the document above.';
      oFootnote.appendChild(oFootnoteH6);
      oFootnoteOL = document.createElement('OL');
      for(i = 1; i < aLinks.length; i++)
      {
        oFootnoteLI = document.createElement('LI');
        oFootnoteLI.innerText = aLinks[i];
        oFootnoteOL.appendChild(oFootnoteLI);
      }
      oFootnote.appendChild(oFootnoteOL);
      oMain.appendChild(oFootnote);
    }
    else
      oFootnote = null;
  }
  oFooter = document.getElementById('footer');
  if(oFooter)
  {
    oFooter.oldInnerHTML = oFooter.innerHTML;
    oFooter.innerHTML = 'Printed from: ' + location.href + '<br />Date: ' + writeDate() + '<br />' + oFooter.innerHTML;
  }
}

function setAfterPrint()
{
  oMain = document.getElementById('content');
  oMainLinks = oMain.getElementsByTagName('A');
  if(oMain && oMainLinks.length)
  {
    for(var i = 0; i < oMainLinks.length; i++)
      if(oMainLinks[i].oldInnerHTML)
        oMainLinks[i].innerHTML = oMainLinks[i].oldInnerHTML;
    if(oFootnote)
      oMain.removeChild(oFootnote);
  }
  oFooter = document.getElementById('footer');
  if(oFooter)
    oFooter.innerHTML = oFooter.oldInnerHTML;
}

if(window.attachEvent)
{
  window.attachEvent('onbeforeprint', setBeforePrint);
  window.attachEvent('onafterprint', setAfterPrint);
}

