var gAutoPrint = true; // Flag for whether or not to automatically call the print function

var today = new Date();
var Year = takeYear(today);
var Month = leadingZero(today.getMonth()+1);
var Day = leadingZero(today.getDate());


function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

function leadingZero(nr)
{
	if (nr < 10) nr = "0" + nr;
	return nr;
}


function printSpecial()
{

        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</HE>\n<BODY>\n';
                
                html += '<table width="561" border="0" align="center" cellpadding="0" cellspacing="0">'+
                        '<tr><td>&nbsp;</td></tr><tr><td bgcolor="#B4B7B9"><img src="../img/dot.gif" width="561" height="1"></td>'+
                        '</tr><tr><td background="../img/c_back2.gif"';
                        
                var printReadyElem = document.getElementById("printready");

                if (printReadyElem != null)
                {
                                html += printReadyElem.innerHTML;
                }
                else
                {
                        alert("Could not find the printReady section in the HTML");
                        return;
                }

                html += '</td></tr><tr><td background="../img/c_bas.gif"><table width="561"  border="0" cellspacing="0" cellpadding="0">'+
                '<tr><td rowspan="2" background="../img/c_coin.gif"><img src="../img/dot.gif" width="10" height="40"></td>'+
                '<td><img src="../img/dot.gif" width="279" height="1"></td><td><img src="../img/dot.gif" width="262" height="1"></td>'+
              '<td><img src="../img/dot.gif" width="9" height="1"></td><td rowspan="2" bgcolor="#B4B7B9"><img src="../img/dot.gif" width="1" height="1"></td>'+
              '</tr><tr><td class="copyright">Donn&eacute;es arr&ecirc;t&eacute;es au '+Day+'/'+Month+'/'+Year+' </td>'+
              '<td align="right" class="copyright">&copy; 2008 CNIEL - Tous droits r&eacute;serv&eacute;s</td><td>&nbsp;</td></tr></table></td>'+
              '</tr><tr><td background="../img/bas_ombre.gif"><table width="10"  border="0" cellspacing="0" cellpadding="0"><tr>'+
              '<td background="../img/bas_ombreg.gif"><img src="../img/dot.gif" width="10" height="15"></td></tr></table></td></tr></table>';
                
                html += '\n</BO>\n</HT>';

                var printWin = window.open("","printSpecial");
                printWin.document.open();
                printWin.document.write(html);
                printWin.document.close();
                if (window.print) {
                  if (gAutoPrint) {

                    printWin.print();

//                    printWin.setTimeout("printclose()",7000);
                    printWin.setTimeout("if (confirm('Vous pouvez maintenant fermer cette fenêtre.')) {self.close();}",7000);
                  }
                } else {
                  alert('Veuillez utiliser le bouton \"Imprimer\" dans la barre d\'outils ci-dessus.');
                }
                        
        }
        else
        {
                alert('Veuillez utiliser le bouton \"Imprimer\" dans la barre d\'outils ci-dessus.');
        }
}
