var isCountdown = false;

Event.observe(window, 'load', init, false);

function init() {
  refresh_widget();
  //new Form.EventObserver('linking_form', refresh_widget);
}


function refresh_widget() {
  
  formName = 'linking_form';
  
  $('refresh_button').value='Generating..';
  
  new Ajax.Updater('widget','/bb/linking/who/' + $('LinkingUrl').value,
    {
      method:'post',
      parameters: Form.serialize(formName),
      onFailure: function(){ alert('Something went wrong...') },
      onSuccess: function(){ $('refresh_button').value='Preview Widget + Generate Code'; }
    });
  
  if ($('LinkingUrl').value.length > 0) {
    new Ajax.Updater('code','/bb/linking/who/' + $('LinkingUrl').value + '/1',
      {
        method:'post',
        parameters: Form.serialize(formName),
        onFailure: function(){ alert('Something went wrong...') }
      });
  }
  
}