document.observe("dom:loaded", function() {
	var count = 0;
	new Ajax.PeriodicalUpdater('', 'include_ajax.php', {
		method: 'get',
		frequency: 30,
		onFailure: function() { return; },
		onSuccess: function(transport, json) {
			if (!json) { return false; }
			var html = '';
			var template = new Template('<tr style="background:#{color}"><td width="50">#{status}</td><td width="100">#{time}</td><td width="160" class="b">#{aircraft}</td><td width="190">#{type}</td><td width="524"><table width="524" cellpadding="0" cellspacing="0"><tr><td>#{destination}</td><td align="right">#{lastinfo}</td></table></td></tr>\n');
			json.each( function(record){
				record.status = (record.status==2||record.status==3||record.status==6||record.status==7) ? '<img src="blink.gif" width="45" height="34">' : '';
				html += template.evaluate(record);
			});


var table_top = ' \
<tr style="background:#666;"> \
    <th width="50" height="37">&nbsp;</th> \
    <th width="100" height="37">TIME</th> \
    <th width="160" height="37">AIRCRAFT</th> \
    <th width="190" height="37">TYPE</th> \
    <th width="524" height="37">DESTINATION</th> \
</tr>';
		   ++count;
		   debug = false;
		   debug_msg = (debug) ? '<h2 style="text-align:center;">RequestCounter: '+count+'</h2>' : '';




        var dobj = new Date();
        var hh = dobj.getHours();
        var mm = dobj.getMinutes();
        var ss = dobj.getSeconds();

        var time = "" + hh;
        time += ((mm < 10) ? ":0" : ":") + mm;
        time += ((ss < 10) ? ":0" : ":") + ss;

        var D = dobj.getDate();
        var M = dobj.getMonth()+1;
        var Y = dobj.getYear();
        if ((Y > 99) && (Y < 1900)) Y += 1900;

        var date = "" + D;
        date += ((M<10) ? ".0" : ".") + M;
        date += "." + Y;

			Element.update('time', date+'<br />'+time); 

			Element.update('timetable', debug_msg+'<table width="1024" border="0" align="center" cellpadding="0" cellspacing="2">'+table_top+html+'</table>');
		}
	});
});