function logBlockHash(leblock)
{
  console.log('Last Block detected : '+leblock.hash);
}

var last_block = null;
var last_block_hooks = [logBlockHash];
var last_block_refresh_flag = true;

function getLastBlockInfo()
{
  $.get( "data/getBlockInfo.php", function( data ) {
    if ((last_block == null)||(last_block.hash != data.hash))
    {      
      if (last_block_refresh_flag && (last_block != null)) 
        last_block_refresh_flag = window.confirm('New block detected, apply change ?');
      
      last_block = data;

      if (last_block_refresh_flag)
      {
        last_block_hooks.forEach(function(element) {
          element(last_block);
        });
      }
    } 
  }, "json" );

  setTimeout(getLastBlockInfo, 30000);
}

$(document).ready(function() {
  getLastBlockInfo();
});
