// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function inventory() {
  if ($('difference').value == '') {
    alert("Adjust Units cannot be blank");
    return false;
  }else if ($('reason').value == '') {
    alert("Reason cannot be blank.");
    return false;
  }
    
}

function total_cost(field) {
  attr_id = field.split('_');  
  //var total = parseFloat($('order_total_cost').value);
  //var qty = parseFloat($('order_line_items_attributes_' + attr_id[4] + '_quantity').value);
  //var pri = parseFloat($('order_line_items_attributes_' + attr_id[4] + '_price').value);
  //$('order_total_cost').value = (qty*pri);
  
  total = 0.0;
  i = 0;
  while( qty = $('order_line_items_attributes_'+ i +'_quantity'))
  {
    total += parseFloat($('order_line_items_attributes_' + i + '_quantity').value)*parseFloat($('order_line_items_attributes_' + i + '_price').value);
    i++;
  }
  total += parseFloat($('order_shipping').value);
  $('order_total_cost').value = total;
}

function shipping(field) {
    var total = parseFloat($('order_total_cost').value);
    var shi = parseFloat($('order_shipping').value);
    $('order_total_cost').value = (total+shi);
}
