In the following code,
doPrintAir(); is a function used for printing.
Actually, I am passing this function window.htmlLoader so it print all html.
but, what it does. it doesn't print the HTML first time. it prints doc second time.

$('#main_window').html(msg); is used to get the html via ajax and pass to page html but first time, print function doesn't get that ..

why ?

Code JavaScript:
<html>
	<head>
        <title>Pizza Smart Order Prints</title>
        <link href="sample.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="lib/air/AIRAliases.js"></script>
		 <script type="text/javascript" src="lib/jquery/jquery-1.3.2.min.js"></script>
        <script type="text/javascript">
            function doPrintAir() 
			{
   				var pjob = new window.runtime.flash.printing.PrintJob;
			    if ( pjob.start() )
			    {
			        var poptions = new window.runtime.flash.printing.PrintJobOptions;
			        poptions.printAsBitmap = true;
			        try
			        {
 
			            pjob.addPage(window.htmlLoader, null, poptions);
			            pjob.send();
						//alert("PrintJob start");
						//$("#board").append(t.'3');
			        }
			        catch (err)
			        {
			            alert("exception: " + err);
			        }
			    }
			    else
			    {
			       // alert("PrintJob couldn't start");
			    }
			}
        </script>
		<script language=javascript>
clock();
var t=0;
var timer;
function clock()
  {
 					// goes and check for the orders posted
					if(timer)
					{
						clearTimeout(timer);
						//alert(timer);
						//t=0;
					}
					t++;
					$.ajax({
						   type: "POST",
						   url: "http://pizzasmart.gr/air/db.php",
						   data: "id=;908fHtiIl",
						   success: function(msg){
							 $('#main_window').html("");
							  $('#main_window').html("Loading..");
							 // alert( $('#main_window').html() );
							 if (msg == "nothing") {
							 	$('#main_window').html(msg);
							 }
							 else {
							 	$('#main_window').html(msg);
								//alert($('#main_window').html());
								doPrintAir(); 
							 }
						   }
						 });
						 $("#board").append(t);
						 timer=setTimeout(clock,1000);
  }
</script>
	</head>
    <body>
        <table width="200" border="1">
  <tr>
    <td><span class="style1">Pizza Smart</span></td>
  </tr>
  <tr>
    <td>
    	<div id="main_window">
    		"Loading.."
    	</div>
		<div id="board"></div>
	</td>
  </tr>
</table>
    </body>
</html>