/* print */

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;
        for(var j = aLinks.length; j > 0; j--)
        {
          if(aLinks[j] == sHref)
          {
            iLinks = j;
            break;
          }
        }
        aLinks[iLinks] = sHref;
        oMainLinks[i].oldInnerHTML = oMainLinks[i].innerHTML;
        oMainLinks[i].innerHTML += ' [' + iLinks + ']';
      }
    }
    if(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);
    }
  }
  oFooter = document.getElementById('footer');
  if(oFooter)
  {
    oFooter.oldInnerHTML = oFooter.innerHTML;
    oFooter.innerHTML = 'Printed from: ' + location.href + '<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;
    oMain.removeChild(oFootnote);
  }
  oFooter = document.getElementById('footer');
  if(oFooter)
    oFooter.innerHTML = oFooter.oldInnerHTML;
}

if(window.attachEvent)
{
  window.attachEvent('onbeforeprint', setBeforePrint);
  window.attachEvent('onafterprint', setAfterPrint);
}

