var tempHtmlContent; 

function printDiv () 
{
   if (document.all && window.print) 
   { 
       window.onbeforeprint = beforeDivs; 
       window.onafterprint = afterDivs; 
       window.print(); 
   } 
} 

function beforeDivs () 
{ 
   if (document.all) { 
       var rng = document.body.createTextRange( ); 
       if (rng!=null) { 
           //alert(rng.htmlText); 
           tempHtmlContent = rng.htmlText; 
           rng.pasteHTML("<table border=0 align=center cellpadding=0 cellspacing=0><tr><td>"  
           + document.all("pDiv").innerHTML + "</td></tr></table>"); 
       } 
   } 
} 

function afterDivs () 
{ 
   if (document.all) 
   { 
        var rng = document.body.createTextRange( ); 
       if (rng!=null) 
       { 
            rng.pasteHTML(tempHtmlContent); 
       } 
   } 
} 