var Table = {
  restripe: function( table ){
    $(table).getElementsBySelector('tbody tr').each(function(row, index){
      row.removeClassName('alt0');
      row.removeClassName('alt1');
      row.addClassName('alt' + (index % 2 ? '0' : '1'));
    });
  }
};

var SelectBox = {
  submit: function( select ){
    select = $(select);
    var submit_to = select.getAttribute('submit_to');
    if ( submit_to && select.value != '') window.location.href = submit_to.replace( escape('%id%'), select.value );
  }
};

var Totals = {
  update: function( attributes ){
    var sum = 0;
    $$('#hours_for_day_' + attributes.day + ' td.hours input').each(function(input){
      sum += parseFloat( Totals._valueAsTime( input.value ) );
    });
    $('daily_total_for_' + attributes.day).update( Math.round( sum * 100 ) / 100 );
    
    sum = 0;
    $$('tbody td.hours.project_' + attributes.project + ' input').each(function(input){
      sum += parseFloat( Totals._valueAsTime( input.value ) );
    });
    $('project_total_for_' + attributes.project).update( Math.round( sum * 100 ) / 100 );
  },
  _valueAsTime: function( input_value ){
    var hours = input_value;
    if (hours == '' || isNaN(hours)) hours = 0;
    return parseFloat( hours );
  }
};