// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function insert_fields(link, method, content) {
  var new_id = new Date().getTime();
  var regexp = new RegExp("new_" + method, "g")
  $(link).up(1).insert({
    before: content.replace(regexp, new_id)
  });
}
 
function remove_fields(link) {
  var hidden_field = $(link).previous("input[type=hidden]");
  if (hidden_field) {
    hidden_field.value = '1';
  }
  var to_remove = $(link).up(".fields");
  to_remove.hide();
  to_remove.next("tr").hide();
}


// HANDLE WINDOW RESIZING TO KEEP THE BOTTOM BAR IN THE RIGHT SPOT
function resizeOnLoad() {
  window.onresize = resizeContent;
  resizeContent();
}

function resizeContent() {
  document.getElementById('content').style.minHeight = 0;
  
  var clientHeight = document.body.offsetHeight;
  
  document.getElementById('content').style.minHeight = (clientHeight - 136) + 'px';
}

document.observe("dom:loaded", function() {
  
  // Wait 2 seconds, then close the flash's cause they are annoying
  setTimeout(function() {
    if (document.getElementById('flash-notice')) {
        Element.fade('flash-notice');
    }
    
    if (document.getElementById('flash-error')) {
        Element.fade('flash-error');
    }
  }, 2000);
  
});


