| 1 |
// $Id$
|
| 2 |
|
| 3 |
var copy_box_checked = false;
|
| 4 |
|
| 5 |
/**
|
| 6 |
* Scan the DOM and display the cancel and continue buttons.
|
| 7 |
*/
|
| 8 |
$(document).ready(
|
| 9 |
function() {
|
| 10 |
$('.show-onload').show();
|
| 11 |
}
|
| 12 |
);
|
| 13 |
|
| 14 |
/**
|
| 15 |
* When a customer clicks a Next button, expand the next pane, remove the
|
| 16 |
* button, and don't let it collapse again.
|
| 17 |
*/
|
| 18 |
function uc_cart_next_button_click(button, pane_id, current) {
|
| 19 |
if (current !== 'false') {
|
| 20 |
$('#' + current + '-pane legend a').click();
|
| 21 |
}
|
| 22 |
else {
|
| 23 |
button.disabled = true;
|
| 24 |
}
|
| 25 |
|
| 26 |
if ($('#' + pane_id + '-pane').attr('class').indexOf('collapsed') > -1 && $('#' + pane_id + '-pane').html() !== null) {
|
| 27 |
$('#' + pane_id + '-pane legend a').click();
|
| 28 |
}
|
| 29 |
|
| 30 |
return false;
|
| 31 |
}
|
| 32 |
|
| 33 |
/**
|
| 34 |
* Copy the delivery information to the payment information on the checkout
|
| 35 |
* screen if corresponding fields exist.
|
| 36 |
*/
|
| 37 |
function uc_cart_copy_address(checked, source, target) {
|
| 38 |
if (!checked) {
|
| 39 |
$('#' + target + '-pane div.address-pane-table').slideDown();
|
| 40 |
copy_box_checked = false;
|
| 41 |
return false;
|
| 42 |
}
|
| 43 |
|
| 44 |
if (target == 'billing') {
|
| 45 |
var x = 28;
|
| 46 |
}
|
| 47 |
else {
|
| 48 |
var x = 26;
|
| 49 |
}
|
| 50 |
|
| 51 |
// Hide the target information fields.
|
| 52 |
$('#' + target + '-pane div.address-pane-table').slideUp();
|
| 53 |
copy_box_checked = true;
|
| 54 |
|
| 55 |
// Copy over the zone options manually.
|
| 56 |
if ($('#edit-panes-' + target + '-' + target + '-zone').html() != $('#edit-panes-' + source + '-' + source + '-zone').html()) {
|
| 57 |
$('#edit-panes-' + target + '-' + target + '-zone').empty().append($('#edit-panes-' + source + '-' + source + '-zone').children().clone());
|
| 58 |
$('#edit-panes-' + target + '-' + target + '-zone').attr('disabled', $('#edit-panes-' + source + '-' + source + '-zone').attr('disabled'));
|
| 59 |
}
|
| 60 |
|
| 61 |
// Copy over the information and set it to update if delivery info changes.
|
| 62 |
$('#' + source + '-pane input, select, textarea').each(
|
| 63 |
function() {
|
| 64 |
if (this.id.substring(0, x) == 'edit-panes-' + source + '-' + source) {
|
| 65 |
$('#edit-panes-' + target + '-' + target + this.id.substring(x)).val($(this).val());
|
| 66 |
if (target == 'billing') {
|
| 67 |
$(this).change(function () { update_billing_field(this); });
|
| 68 |
}
|
| 69 |
else {
|
| 70 |
$(this).change(function () { update_delivery_field(this); });
|
| 71 |
}
|
| 72 |
}
|
| 73 |
}
|
| 74 |
);
|
| 75 |
|
| 76 |
return false;
|
| 77 |
}
|
| 78 |
|
| 79 |
function update_billing_field(field) {
|
| 80 |
if (copy_box_checked) {
|
| 81 |
$('#edit-panes-billing-billing' + field.id.substring(28)).val($(field).val());
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
function update_delivery_field(field) {
|
| 86 |
if (copy_box_checked) {
|
| 87 |
$('#edit-panes-delivery-delivery' + field.id.substring(26)).val($(field).val());
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
| 91 |
/**
|
| 92 |
* Apply the selected address to the appropriate fields in the cart form.
|
| 93 |
*/
|
| 94 |
function apply_address(type, address_str) {
|
| 95 |
if (address_str == '0') {
|
| 96 |
return;
|
| 97 |
}
|
| 98 |
|
| 99 |
eval('var address = ' + address_str + ';');
|
| 100 |
var temp = type + '-' + type;
|
| 101 |
|
| 102 |
$('#edit-panes-' + temp + '-first-name').val(address.first_name).trigger('change');
|
| 103 |
$('#edit-panes-' + temp + '-last-name').val(address.last_name).trigger('change');
|
| 104 |
$('#edit-panes-' + temp + '-phone').val(address.phone).trigger('change');
|
| 105 |
$('#edit-panes-' + temp + '-company').val(address.company).trigger('change');
|
| 106 |
$('#edit-panes-' + temp + '-street1').val(address.street1).trigger('change');
|
| 107 |
$('#edit-panes-' + temp + '-street2').val(address.street2).trigger('change');
|
| 108 |
$('#edit-panes-' + temp + '-city').val(address.city).trigger('change');
|
| 109 |
$('#edit-panes-' + temp + '-postal-code').val(address.postal_code).trigger('change');
|
| 110 |
|
| 111 |
if ($('#edit-panes-' + temp + '-country').val() != address.country) {
|
| 112 |
$('#edit-panes-' + temp + '-country').val(address.country);
|
| 113 |
try {
|
| 114 |
uc_update_zone_select('edit-panes-' + temp + '-country', address.zone);
|
| 115 |
}
|
| 116 |
catch (err) { }
|
| 117 |
}
|
| 118 |
|
| 119 |
$('#edit-panes-' + temp + '-zone').val(address.zone).trigger('change');
|
| 120 |
}
|