(function() {
  var $, copyForm;
  $ = this.$;
  copyForm = function(from, to) {
    var input, _i, _len, _ref, _results;
    _ref = from.form.find(':input');
    _results = [];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      input = _ref[_i];
      _results.push((function() {
        try {
          return to.form.find("[name=" + input.name.replace(from.prefix, to.prefix) + "]")[0].value = input.value;
        } catch (err) {
          /*
          No such input field in other form
          */
        }
      })());
    }
    return _results;
  };
  this.$(function() {
    var deliveryUpdate;
    $('.copy-details').click(function() {
      copyForm({
        form: $('.billing-info'),
        prefix: 'billing-Billing'
      }, {
        form: $('.delivery-info'),
        prefix: 'delivery-Delivery'
      });
      deliveryUpdate();
      return false;
    });
    $('#id_delivery-DeliveryCountry').live('change', function() {
      return deliveryUpdate();
    });
    deliveryUpdate = function() {
      var elem, error, updatePrice;
      elem = $('#id_delivery-DeliveryCountry');
      updatePrice = function(data) {
        return $('#checkout-summary').fadeOut(function() {
          $('#checkout-summary').replaceWith($(data).find('#checkout-summary'));
          return $('#checkout-summary').fadeIn();
        });
      };
      error = function() {
        $('.pay-now').hide();
        return alert('We\'ve encountered an error.');
      };
      return $.ajax({
        url: "./",
        type: "GET",
        data: {
          delivery: elem.val()
        },
        dataType: "html",
        async: true,
        success: updatePrice,
        error: error
      });
    };
    return false;
  });
}).call(this);

