// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var MS_IN_MIN = 1000 * 60;
var MIN_IN_HR = 60;

function getField(id, default_) {
  if (!default_) {
    default_ = null;
  }
  
  try {
    return parseInt($F(id));
  }
  catch (e) {
    return default_;
  }
}
function getDateTime(id) {
  var year = getField(id + "_3i", 0);
  var month = getField(id + "_2i", 0);
  var day = getField(id + "_1i", 0);
  var hour = getField(id + "_4i", 0);
  var minute = getField(id+ "_5i", 0);

  var date = new Date();
  date.setFullYear(year, month, day);
  date.setHours(hour);
  date.setMinutes(minute);
  return date;
}

function appendNoPrintForEmptyHeader() {
  $$('th').select(function (o) {
    return o.cleanWhitespace().empty();
  }).each(function (o) {
    o.addClassName("noprint");
  });
}

function thWidthFix() {
  $$('th[width=1%]').each(function (th) {
    th.removeAttribute("width");
  });
}

function fixIconAlignment() {
  $$('.icon').each(function (e) {
     var parent = e.up();
     if (parent.tagName.toLowerCase() == 'td') {
       parent.writeAttribute("align", "center");
     }
  });
}
document.observe('dom:loaded', function() {
  appendNoPrintForEmptyHeader();
  thWidthFix();
  fixIconAlignment();
});


function populate_rate(select, rate) {
  var option = select.options[select.selectedIndex];
  $(rate).value = $(option).readAttribute('rate') || 0
}