[% PROCESS _header.tt %]
[% PROCESS _message.tt %]

    <table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td align="left" valign="top" width="33%">
        [% PROCESS _infobox.tt %]
        </td>
        <td align="center" valign="middle" width="33%"></td>
        <td align="right" valign="bottom" width="33%">
          [% PROCESS _help.tt topic = "waiting" %]
        </td>
      </tr>
    </table>

    <br><br>

    <div align="center">
    [% IF job_id %]
    <!-- thruk: waiting for job [% job_id %] -->
    [% IF job_message %][% job_message %][% ELSE %]please stand by while your job is being processed...[% END %]<br>
    <div id="progressbar" style="width: 400px; color: inherit;"><div align="center" id="job_time" style="z-index: 100;  line-height: 24px; position: absolute; width: 400px; color: inherit;">[% job_time %]s</div></div>
    <script type="text/javascript">
    <!--
        jQuery(function() {
            jQuery( "#progressbar" ).progressbar({
                value: [% job_percent %]
            });
        });
        var last_time = 0;

        function update_job_progressbar() {
            var datestr = Math.round((new Date()).getTime()/1000);
            var val = jQuery( "#progressbar" ).progressbar( "value" );
            // update every 2 seconds
            if(last_time != 0 && datestr%2 != 0 && val < 100) {
                last_time = last_time + 1;
                jQuery( "#progressbar" ).progressbar( "value", val + 1 );
                jQuery( "#job_time" ).html(last_time + "s");
                return;
            }
            jQuery.ajax({
                url: "job.cgi?job=[% job_id %]&json=1&_"+datestr,
                type: 'POST',
                dataType: 'json',
                success: function(data, status, jqXHR) {
                    if(data.percent != 0) {
                        jQuery( "#progressbar" ).progressbar( "value", data.percent );
                    }
                    if(data.percent != 100) {
                      last_time = data.time;
                      jQuery( "#job_time" ).html(data.time + "s");
                    }
                }
            });

            var val = jQuery( "#progressbar" ).progressbar( "value" );
            if(val >= 100) {
                clearInterval(job_wait_timer);
                reloadPage();
                return;
            } else {
                jQuery( "#progressbar" ).progressbar( "value", val + 1 );
            }
        }
        [% IF job_percent != 100 %]
        var job_wait_timer;
        jQuery(function() {
            job_wait_timer = window.setInterval(update_job_progressbar, 1000);
        });
        [% END +%]
    -->
    </script>
    [% END %]

    <br>
    <a href="#" onclick="window.history.go(-1); return false;">go back</a>
    </div>

[% PROCESS _footer.tt %]
