function addEvent(name,obj,f) {
  if(obj) {
    if (obj.attachEvent) {
      obj.attachEvent("on"+name,f);
    } else if (obj.addEventListener) {
      obj.addEventListener(name,f,false);
    }
  }
}

addEvent('load',window,function() {
  var cal=document.getElementById('calendar');
  var ctitle=document.getElementById('calendartitle');

  if ((cal) && (ctitle)) {
    var ctitlecopy=ctitle.cloneNode(true);
    var calcopy=cal.cloneNode(true);
    var a=calcopy.getElementsByTagName('a');
    for (var i=0;i<a.length;i++) {
      a[i].removeAttribute('href');
    }
    a=document.createElement('a');
    a.href='#';
    a.style.display='block';
    a.style.paddingLeft='8px';
    a.style.marginTop='-15px';
    var img=document.createElement('img');
    img.src='/images/demo/print.png';
    img.width='23';
    img.height='24';
    img.style.border='none';
    img.style.marginRight='4px';
    if (a.filters) {
      img.style.visibility='hidden';
      a.style.height=''+img.height+'px';
      a.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="crop",src="'+img.src+'")';
    }
    a.appendChild(img);
    a.appendChild(document.createTextNode('Click For Printable Version'));
    addEvent('click',a,openprintable);
    ctitle.appendChild(a);
  }

  function openprintable(e) {
    if (window.event) {
      window.event.cancelBubble=true;
      window.event.returnValue=false;
    } else {
      if (e.preventDefault) e.preventDefault();
      if (e.stopPropagation) e.stopPropagation();
    }
    var w=window.open('about:blank','','menubar=yes,scrollbars=yes,width=820,height=600');
    w.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\
<head>\
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />\
  <title>'+ctitlecopy.innerHTML+'</title>\
  <link rel="stylesheet" href="/includes/calendar.css" />\
  <link rel="shortcut icon" href="/favicon.ico" />\
</head>\
<body>\
<div class="hide">\
  <a href="#" onclick="var el=this;while(el=el.nextSibling) { if ((el.nodeType==1) && (el.nodeName.toLowerCase()==\'div\')) { el.style.display=((el.style.display==\'block\')?\'none\':\'block\'); break; } }; return false;"><img src="images/print.gif" border="0"></a>\
\
  <div>\
    This page must be printed in landscape view with background colors turned on.\
    <p><span class="aquo">&raquo;</span> To enable background color printing in Internet Explorer, use the menu at the top of the browser and select Tools&gt;&gt;Internet Options...</p>\
    <p><span class="aquo">&raquo;</span> In the Internet Options window click the &quot;Advanced&quot; tab. Scroll down to "Printing" and check the box for &quot;Print background colors and images.&quot; Click OK.</p>\
\
    <p><span class="aquo">&raquo;</span> To print in landscape view, use the "File" menu and click "Print..." Click the "Layout" or "Paper" tab and set "Orientation" to "Landscape."</p>\
    <p><span class="aquo">&raquo;</span> Click "Print" to start printing. <i>These instructions will not display on the printed calendar.</i></p>\
  </div>\
</div>');
    w.document.write('<table class="calendar" id="calendar" align="center" cellspacing="0">'+calcopy.innerHTML+'</table>');
    w.document.write('</body>\
</html>');
  w.document.close();

  }
});