// this is implemented as a function in order to
// avoid variable collisions with other scripts
function writePrintControl(showSend, showPrint) {
  var element = document.getElementById('page-controls');
  if(element && print && document.createElement
     && document.createTextNode && element.appendChild) {
    if(showSend && (encodeURIComponent || escape)) {
      var liSend = document.createElement('li');
      liSend.id = 'page-controls-send';
      var aSend = document.createElement('a');
      aSend.href = '/send/?url=';
      if(encodeURIComponent)
        aSend.href += encodeURIComponent(window.location);
      else
        aSend.href += escape(window.location);
      aSend.onclick = function() {
        window.open(this.href, '_blank',
                    'width=400,height=400,resizable=yes,scrollbars=yes');
        return false;
      };
      aSend.appendChild(document.createTextNode('Send to a friend'));
      liSend.appendChild(aSend);
      element.appendChild(liSend);
    }

    if(showPrint && window.print) {
      var liPrint = document.createElement('li');
      liPrint.id = 'page-controls-print';
      var aPrint = document.createElement('a');
      aPrint.href = '#';
      aPrint.onclick = function() { window.print(); return false; };
      aPrint.appendChild(document.createTextNode('Print this page'));
      liPrint.appendChild(aPrint);
      element.appendChild(liPrint);
    }
  }
}

if(typeof(printControlShowSend)=='undefined')
  var printControlShowSend = true;
if(typeof(printControlShowPrint)=='undefined')
  var printControlShowPrint = true;
writePrintControl(printControlShowSend, printControlShowPrint);
