$(document).ready(function() {
 $("#Promo").keyup(function() {
  var code = $("#Promo").val().toUpperCase();
  if (code == "RAVE-LDE" || code == "RAVE_LDE") {
   $("#unit-price").html('720.00');
   $("#remote-price").html('140.00');
   //alert('There will be a $115 freight charge added to the cost of your order.');
   //alert('match!');
  } else {
   $("#unit-price").html('1199.00');
   $("#remote-price").html('160.00');
  }
  calculate();
 });
 
 $("#Unit_Order_Quantity").keyup(function() {
  this.value = this.value.replace(/\D/g,'');
  calculate();
 });
 $("#Remote_Order_Quantity").keyup(function() {
  this.value = this.value.replace(/\D/g,'');
  calculate();
 });
 
 function calculate() {
  var qtyunit = $("#Unit_Order_Quantity").val();
  var qtyremote = $("#Remote_Order_Quantity").val();
  var unitprice = $("#unit-price").html();
  var remoteprice = $("#remote-price").html();
  var freight = 0;
  var total = 0;

  $("#Freight_cost").val(0);
  $("#Total_cost").val(0);

  // calculate freight
  freight = qtyunit * 115;
  $("#Freight_cost").val("$" + freight + ".00");
  
  // calculate the total
  total = (qtyunit * unitprice) + (qtyremote * remoteprice) + freight;
  $("#Total_cost").val("$" + total + ".00");
 }
 
 $("#form1").submit(function(){
  calculate();
 });
});
