=== modified file 'ca/ca.module'
--- ca/ca.module	2010-04-09 14:18:53 +0000
+++ ca/ca.module	2010-05-24 20:44:27 +0000
@@ -349,7 +349,7 @@
  */
 function ca_evaluate_conditions($predicate, $arguments) {
   // Automatically pass if there are no conditions.
-  if (count($predicate['#conditions']) == 0) {
+  if (empty($predicate['#conditions'])) {
     return TRUE;
   }
 

=== modified file 'payment/uc_2checkout/uc_2checkout.module'
--- payment/uc_2checkout/uc_2checkout.module	2010-05-18 20:14:02 +0000
+++ payment/uc_2checkout/uc_2checkout.module	2010-06-03 15:57:46 +0000
@@ -106,7 +106,7 @@
  *
  * @see uc_2checkout_uc_payment_method()
  */
-function uc_payment_method_2checkout($op, &$arg1) {
+function uc_payment_method_2checkout($op, &$order, $form = NULL, &$form_state = NULL) {
   switch ($op) {
     case 'cart-details':
       if (variable_get('uc_2checkout_check', FALSE)) {
@@ -135,7 +135,7 @@
       return $build;
 
     case 'cart-process':
-      $_SESSION['pay_method'] = $_POST['pay_method'];
+      $_SESSION['pay_method'] = $form_state['values']['panes']['payment']['details']['pay_method'];
       return;
 
     case 'settings':

=== modified file 'payment/uc_credit/uc_credit.module'
--- payment/uc_credit/uc_credit.module	2010-04-06 15:51:15 +0000
+++ payment/uc_credit/uc_credit.module	2010-06-03 15:57:46 +0000
@@ -118,11 +118,6 @@
       break;
 
     case 'uc_cart_checkout_form':
-      if (isset($_POST['cc_number'])) {
-        $order = new stdClass();
-        uc_payment_method_credit('cart-process', $order, TRUE);
-      }
-
       // Cache the CC details for use in other functions.
       if (isset($_SESSION['sescrd'])) {
         uc_credit_cache('save', $_SESSION['sescrd']);
@@ -301,9 +296,9 @@
 /**
  * Implement hook_uc_order().
  */
-function uc_credit_uc_order($op, &$arg1, $arg2) {
+function uc_credit_uc_order($op, &$order, $arg2) {
   // Set up the encryption key and object for saving and loading.
-  if (isset($arg1->payment_method) && $arg1->payment_method == 'credit' && ($op == 'save' || $op == 'load')) {
+  if (isset($order->payment_method) && $order->payment_method == 'credit' && ($op == 'save' || $op == 'load')) {
     // Log an error if encryption isn't configured properly.
     if (!uc_credit_encryption_key()) {
       watchdog('uc_credit', 'Credit card encryption must be set up to process credit cards.');
@@ -312,7 +307,7 @@
 
   switch ($op) {
     case 'submit':
-      if (isset($arg1->payment_method) && $arg1->payment_method == 'credit') {
+      if (isset($order->payment_method) && $order->payment_method == 'credit') {
         // Clear out that session variable denoting this as a CC paid order.
         unset($_SESSION['cc_pay']);
 
@@ -325,7 +320,7 @@
           );
 
           // Attempt to process the CC payment.
-          $pass = uc_payment_process_payment('credit', $arg1->order_id, $arg1->order_total, $data, TRUE, NULL, FALSE);
+          $pass = uc_payment_process_payment('credit', $order->order_id, $order->order_total, $data, TRUE, NULL, FALSE);
 
           // If the payment failed, store the data back in the session and
           // halt the checkout process.
@@ -338,45 +333,45 @@
           // If we aren't set to process transactions immediately and we're in
           // debug mode, store the CC data in the order so it can be viewed
           // later for test processing.
-          $cc_data = $arg1->payment_details;
+          $cc_data = $order->payment_details;
 
-          _uc_credit_save_cc_data_to_order($cc_data, $arg1->order_id);
+          _uc_credit_save_cc_data_to_order($cc_data, $order->order_id);
         }
       }
       break;
 
     case 'save':
-      if (isset($arg1->payment_method) && $arg1->payment_method == 'credit') {
+      if (isset($order->payment_method) && $order->payment_method == 'credit') {
         // Build an array of CC data to store with the order.
-        if (!empty($arg1->payment_details)) {
+        if (!empty($order->payment_details)) {
           // Check for debug mode.
           if (variable_get('uc_credit_debug', FALSE) && arg(1) != 'checkout') {
             // If enabled, store the full payment details.
-            $cc_data = $arg1->payment_details;
+            $cc_data = $order->payment_details;
           }
           else {
             // Otherwise, save only some limited, PCI compliant data.
             $cc_data = array(
-              'cc_number' => substr($arg1->payment_details['cc_number'], -4),
-              'cc_exp_month' => $arg1->payment_details['cc_exp_month'],
-              'cc_exp_year' => $arg1->payment_details['cc_exp_year'],
-              'cc_type' => $arg1->payment_details['cc_type'],
+              'cc_number' => substr($order->payment_details['cc_number'], -4),
+              'cc_exp_month' => $order->payment_details['cc_exp_month'],
+              'cc_exp_year' => $order->payment_details['cc_exp_year'],
+              'cc_type' => $order->payment_details['cc_type'],
             );
           }
 
-          _uc_credit_save_cc_data_to_order($cc_data, $arg1->order_id);
+          _uc_credit_save_cc_data_to_order($cc_data, $order->order_id);
         }
       }
       break;
 
     case 'load':
-      if (isset($arg1->payment_method) && $arg1->payment_method == 'credit') {
+      if (isset($order->payment_method) && $order->payment_method == 'credit') {
         // Load the CC details from the credit cache if available.
-        $arg1->payment_details = uc_credit_cache('load');
+        $order->payment_details = uc_credit_cache('load');
 
         // Otherwise load any details that might be stored in the data array.
-        if (empty($arg1->payment_details) && isset($arg1->data['cc_data'])) {
-          $arg1->payment_details = uc_credit_cache('save', $arg1->data['cc_data']);
+        if (empty($order->payment_details) && isset($order->data['cc_data'])) {
+          $order->payment_details = uc_credit_cache('save', $order->data['cc_data']);
         }
       }
       break;
@@ -418,35 +413,28 @@
  ******************************************************************************/
 
 // Callback function for the Credit Card payment method.
-function uc_payment_method_credit($op, &$arg1, $silent = FALSE) {
+function uc_payment_method_credit($op, &$order, $form = NULL, &$form_state = NULL) {
   switch ($op) {
     case 'cart-details':
-      $details = drupal_get_form('uc_payment_method_credit_form', $arg1);
-      return uc_strip_form($details);
+      $details = uc_payment_method_credit_form(array(), $form_state, $order);
+      return $details;
 
     case 'cart-process':
       // Fetch the CC details from the $_POST directly.
-      $cc_data = array(
-        'cc_type' => check_plain($_POST['cc_type']),
-        'cc_owner' => check_plain($_POST['cc_owner']),
-        'cc_number' => check_plain(str_replace(' ', '',  $_POST['cc_number'])),
-        'cc_start_month' => check_plain($_POST['cc_start_month']),
-        'cc_start_year' => check_plain($_POST['cc_start_year']),
-        'cc_exp_month' => check_plain($_POST['cc_exp_month']),
-        'cc_exp_year' => check_plain($_POST['cc_exp_year']),
-        'cc_issue' => check_plain($_POST['cc_issue']),
-        'cc_cvv' => check_plain($_POST['cc_cvv']),
-        'cc_bank' => check_plain($_POST['cc_bank']),
-      );
-
-      // Recover cached CC data in $_POST if it exists.
-      if (isset($_POST['payment_details_data'])) {
-        $cache = uc_credit_cache('save', $_POST['payment_details_data']);
+      $cc_data = $form_state['values']['panes']['payment']['details'];
+
+      $cc_data['cc_number'] = str_replace(' ', '', $cc_data['cc_number']);
+
+      array_walk($cc_data, 'check_plain');
+
+      // Recover cached CC data in $form_state['values']['panes']['payment']['details'] if it exists.
+      if (isset($form_state['values']['panes']['payment']['details']['payment_details_data'])) {
+        $cache = uc_credit_cache('save', $form_state['values']['panes']['payment']['details']['payment_details_data']);
       }
 
       // Account for partial CC numbers when masked by the system.
       if (substr($cc_data['cc_number'], 0, strlen(t('(Last4)'))) == t('(Last4)')) {
-        // Recover the number from the encrypted data in $_POST if truncated.
+        // Recover the number from the encrypted data in the form if truncated.
         if (isset($cache['cc_number'])) {
           $cc_data['cc_number'] = $cache['cc_number'];
         }
@@ -467,66 +455,54 @@
       }
 
       // Go ahead and put the CC data in the payment details array.
-      $arg1->payment_details = $cc_data;
+      $order->payment_details = $cc_data;
 
       // Default our value for validation.
       $return = TRUE;
 
       // Make sure an owner value was entered.
       if (variable_get('uc_credit_owner_enabled', FALSE) && empty($cc_data['cc_owner'])) {
-        if (!$silent) {
-          drupal_set_message(t('Enter the owner name as it appears on the card.'), 'error');
-        }
+        form_set_error('panes][payment][details][cc_owner', t('Enter the owner name as it appears on the card.'));
         $return = FALSE;
       }
 
       // Validate the CC number if that's turned on/check for non-digits.
       if ((variable_get('uc_credit_validate_numbers', TRUE) && !_uc_credit_valid_card_number($cc_data['cc_number']))
         || !ctype_digit($cc_data['cc_number'])) {
-        if (!$silent) {
-          drupal_set_message(t('You have entered an invalid credit card number.'), 'error');
-        }
+        form_set_error('panes][payment][details][cc_number', t('You have entered an invalid credit card number.'));
         $return = FALSE;
       }
 
       // Validate the start date (if entered).
       if (variable_get('uc_credit_start_enabled', FALSE) && !_uc_credit_valid_card_start($cc_data['cc_start_month'], $cc_data['cc_start_year'])) {
-        if (!$silent) {
-          drupal_set_message(t('The start date you entered is invalid.'), 'error');
-        }
+        form_set_error('panes][payment][details][cc_start_month', t('The start date you entered is invalid.'));
+        form_set_error('panes][payment][details][cc_start_year');
         $return = FALSE;
       }
 
       // Validate the card expiration date.
       if (!_uc_credit_valid_card_expiration($cc_data['cc_exp_month'], $cc_data['cc_exp_year'])) {
-        if (!$silent) {
-          drupal_set_message(t('The credit card you entered has expired.'), 'error');
-        }
+        form_set_error('panes][payment][details][cc_exp_month', t('The credit card you entered has expired.'));
+        form_set_error('panes][payment][details][cc_exp_year');
         $return = FALSE;
       }
 
       // Validate the issue number (if entered).  With issue numbers, '01' is
       // different from '1', but is_numeric() is still appropriate.
       if (variable_get('uc_credit_issue_enabled', FALSE) && !_uc_credit_valid_card_issue($cc_data['cc_issue'])) {
-        if (!$silent) {
-          drupal_set_message(t('The issue number you entered is invalid.'), 'error');
-        }
+        form_set_error('panes][payment][details][cc_issue', t('The issue number you entered is invalid.'));
         $return = FALSE;
       }
 
       // Validate the CVV number if enabled.
       if (variable_get('uc_credit_cvv_enabled', TRUE) && !_uc_credit_valid_cvv($cc_data['cc_cvv'])) {
-        if (!$silent) {
-          drupal_set_message(t('You have entered an invalid CVV number.'), 'error');
-        }
+        form_set_error('panes][payment][details][cc_ccv', t('You have entered an invalid CVV number.'));
         $return = FALSE;
       }
 
       // Validate the bank name if enabled.
       if (variable_get('uc_credit_bank_enabled', FALSE) && empty($cc_data['cc_bank'])) {
-        if (!$silent) {
-          drupal_set_message(t('You must enter the issuing bank for that card.'), 'error');
-        }
+        form_set_error('panes][payment][details][cc_bank', t('You must enter the issuing bank for that card.'));
         $return = FALSE;
       }
 
@@ -535,7 +511,7 @@
       $crypt = new uc_encryption_class;
 
       // Store the encrypted details in the session for the next pageload.
-      $_SESSION['sescrd'] = $crypt->encrypt($key, serialize($arg1->payment_details));
+      $_SESSION['sescrd'] = $crypt->encrypt($key, serialize($order->payment_details));
 
       // Log any errors to the watchdog.
       uc_store_encryption_errors($crypt, 'uc_credit');
@@ -550,25 +526,25 @@
 
     case 'cart-review':
       if (variable_get('uc_credit_type_enabled', FALSE)) {
-        $review[] = array('title' => t('Card Type'), 'data' => check_plain($arg1->payment_details['cc_type']));
+        $review[] = array('title' => t('Card Type'), 'data' => check_plain($order->payment_details['cc_type']));
       }
       if (variable_get('uc_credit_owner_enabled', FALSE)) {
-        $review[] = array('title' => t('Card Owner'), 'data' => check_plain($arg1->payment_details['cc_owner']));
+        $review[] = array('title' => t('Card Owner'), 'data' => check_plain($order->payment_details['cc_owner']));
       }
-      $review[] = array('title' => t('Card Number'), 'data' => uc_credit_display_number($arg1->payment_details['cc_number']));
+      $review[] = array('title' => t('Card Number'), 'data' => uc_credit_display_number($order->payment_details['cc_number']));
       if (variable_get('uc_credit_start_enabled', FALSE)) {
-        $start = $arg1->payment_details['cc_start_month'] . '/' . $arg1->payment_details['cc_start_year'];
+        $start = $order->payment_details['cc_start_month'] . '/' . $order->payment_details['cc_start_year'];
         $review[] = array('title' => t('Start Date'), 'data' => strlen($start) > 1 ? $start : '');
       }
-      $review[] = array('title' => t('Expiration'), 'data' => $arg1->payment_details['cc_exp_month'] . '/' . $arg1->payment_details['cc_exp_year']);
+      $review[] = array('title' => t('Expiration'), 'data' => $order->payment_details['cc_exp_month'] . '/' . $order->payment_details['cc_exp_year']);
       if (variable_get('uc_credit_issue_enabled', FALSE)) {
-        $review[] = array('title' => t('Issue Number'), 'data' => user_access('view cc numbers') ? $arg1->payment_details['cc_issue'] : str_repeat('-', strlen($arg1->payment_details['cc_issue'])));
+        $review[] = array('title' => t('Issue Number'), 'data' => user_access('view cc numbers') ? $order->payment_details['cc_issue'] : str_repeat('-', strlen($order->payment_details['cc_issue'])));
       }
       if (variable_get('uc_credit_cvv_enabled', TRUE)) {
-        $review[] = array('title' => t('CVV'), 'data' => user_access('view cc numbers') ? $arg1->payment_details['cc_cvv'] : str_repeat('-', strlen($arg1->payment_details['cc_cvv'])));
+        $review[] = array('title' => t('CVV'), 'data' => user_access('view cc numbers') ? $order->payment_details['cc_cvv'] : str_repeat('-', strlen($order->payment_details['cc_cvv'])));
       }
       if (variable_get('uc_credit_bank_enabled', FALSE)) {
-        $review[] = array('title' => t('Issuing Bank'), 'data' => check_plain($arg1->payment_details['cc_bank']));
+        $review[] = array('title' => t('Issuing Bank'), 'data' => check_plain($order->payment_details['cc_bank']));
       }
       return $review;
 
@@ -582,50 +558,50 @@
         $rows = array();
 
         if (variable_get('uc_credit_type_enabled', TRUE)) {
-          $type = check_plain($arg1->payment_details['cc_type']);
+          $type = check_plain($order->payment_details['cc_type']);
           if (strlen($type) > 0) {
             $rows[] = array(t('Card Type:'), $type);
           }
         }
 
         if (variable_get('uc_credit_owner_enabled', FALSE)) {
-          $owner = check_plain($arg1->payment_details['cc_owner']);
+          $owner = check_plain($order->payment_details['cc_owner']);
           if (strlen($owner) > 0) {
             $rows[] = array(t('Card Owner:'), $owner);
           }
         }
 
-        $rows[] = array(t('Card Number:'), uc_credit_display_number($arg1->payment_details['cc_number']));
+        $rows[] = array(t('Card Number:'), uc_credit_display_number($order->payment_details['cc_number']));
 
-        $exp = $arg1->payment_details['cc_exp_month'] . '/' . $arg1->payment_details['cc_exp_year'];
+        $exp = $order->payment_details['cc_exp_month'] . '/' . $order->payment_details['cc_exp_year'];
         if (strlen($exp) > 1) {
           $rows[] = array(t('Expiration:'), $exp);
         }
 
         if (variable_get('uc_credit_debug', FALSE)) {
           if (variable_get('uc_credit_start_enabled', FALSE)) {
-            $start = $arg1->payment_details['cc_start_month'] . '/' . $arg1->payment_details['cc_start_year'];
+            $start = $order->payment_details['cc_start_month'] . '/' . $order->payment_details['cc_start_year'];
             if (strlen($start) > 1) {
               $rows[] = array(t('Start Date:'), $start);
             }
           }
 
           if (variable_get('uc_credit_issue_enabled', FALSE)) {
-            $issue = $arg1->payment_details['cc_issue'];
+            $issue = $order->payment_details['cc_issue'];
             if (strlen($issue) > 0) {
               $rows[] = array(t('Issue Number:'), $issue);
             }
           }
 
           if (variable_get('uc_credit_cvv_enabled', TRUE)) {
-            $cvv = user_access('view cc numbers') ? $arg1->payment_details['cc_cvv'] : str_repeat('-', strlen($arg1->payment_details['cc_cvv']));
+            $cvv = user_access('view cc numbers') ? $order->payment_details['cc_cvv'] : str_repeat('-', strlen($order->payment_details['cc_cvv']));
             if (strlen($cvv) > 0) {
               $rows[] = array(t('CVV:'), $cvv);
             }
           }
 
           if (variable_get('uc_credit_bank_enabled', TRUE)) {
-            $bank = check_plain($arg1->payment_details['cc_bank']);
+            $bank = check_plain($order->payment_details['cc_bank']);
             if (strlen($bank) > 0) {
               $rows[] = array(t('Issuing Bank:'), $bank);
             }
@@ -644,7 +620,7 @@
 
         // Add the form to process the card if applicable.
         if (user_access('process credit cards')) {
-          $build['terminal'] = drupal_get_form('uc_credit_order_view_form', $arg1->order_id);
+          $build['terminal'] = drupal_get_form('uc_credit_order_view_form', $order->order_id);
         }
       }
 
@@ -652,13 +628,13 @@
 
     case 'customer-view':
       $build['#markup'] = t('Card Number:') . '<br />'
-        . uc_credit_display_number($arg1->payment_details['cc_number'], TRUE);
+        . uc_credit_display_number($order->payment_details['cc_number'], TRUE);
 
       return $build;
 
     case 'order-details':
       if (variable_get('uc_credit_debug', FALSE)) {
-        $details = drupal_get_form('uc_payment_method_credit_form', $arg1);
+        $details = drupal_get_form('uc_payment_method_credit_form', $order);
         return uc_strip_form($details);
       }
       else {
@@ -946,8 +922,8 @@
 // Displays the credit card details form on the checkout screen.
 function uc_payment_method_credit_form($form, &$form_state, $order) {
   // Normally the CC data is posted in via AJAX.
-  if (!empty($_POST['payment-details-data']) && arg(0) == 'cart') {
-    $order->payment_details = uc_credit_cache('save', $_POST['payment-details-data']);
+  if (!empty($form_state['values']['payment_details_data']) && arg(0) == 'cart') {
+    $order->payment_details = uc_credit_cache('save', $form_state['values']['payment_details_data']);
   }
 
   // But we have to accommodate failed checkout form validation here.
@@ -956,6 +932,22 @@
     unset($_SESSION['sescrd']);
   }
 
+  if (!isset($order->payment_details)) {
+    // Fetch the CC details from the $_POST directly.
+    $order->payment_details = array(
+      'cc_type' => check_plain($form_state['values']['panes']['payment']['details']['cc_type']),
+      'cc_owner' => check_plain($form_state['values']['panes']['payment']['details']['cc_owner']),
+      'cc_number' => check_plain(str_replace(' ', '', $form_state['values']['panes']['payment']['details']['cc_number'])),
+      'cc_start_month' => check_plain($form_state['values']['panes']['payment']['details']['cc_start_month']),
+      'cc_start_year' => check_plain($form_state['values']['panes']['payment']['details']['cc_start_year']),
+      'cc_exp_month' => check_plain($form_state['values']['panes']['payment']['details']['cc_exp_month']),
+      'cc_exp_year' => check_plain($form_state['values']['panes']['payment']['details']['cc_exp_year']),
+      'cc_issue' => check_plain($form_state['values']['panes']['payment']['details']['cc_issue']),
+      'cc_cvv' => check_plain($form_state['values']['panes']['payment']['details']['cc_cvv']),
+      'cc_bank' => check_plain($form_state['values']['panes']['payment']['details']['cc_bank']),
+    );
+  }
+
   $form['cc_policy'] = array('#markup' => variable_get('uc_credit_policy', t('Your billing information must match the billing address for the credit card entered below or we will be unable to process your payment.')));
 
   if (variable_get('uc_credit_type_enabled', FALSE)) {
@@ -976,6 +968,9 @@
       '#default_value' => $order->payment_details['cc_type'] ? $order->payment_details['cc_type'] : array_shift(array_keys($options)),
     );
   }
+  else {
+    $form['cc_type'] = array('#type' => 'value', '#value' => NULL);
+  }
 
   if (variable_get('uc_credit_owner_enabled', FALSE)) {
     $form['cc_owner'] = array(
@@ -987,6 +982,9 @@
       '#maxlength' => 64,
     );
   }
+  else {
+    $form['cc_owner'] = array('#type' => 'value', '#value' => NULL);
+  }
 
   // Set up the default CC number on the credit card form.
   if (variable_get('uc_credit_validate_numbers', TRUE) && (strlen($order->payment_details['cc_number']) > 4 && !_uc_credit_valid_card_number($order->payment_details['cc_number']))) {
@@ -1003,10 +1001,13 @@
       $default_num = t('(Last 4) ') . substr($order->payment_details['cc_number'], -4);
     }
   }
+
+  $clear_cc = isset($_SESSION['clear_cc']) && $_SESSION['clear_cc'];
+
   $form['cc_number'] = array(
     '#type' => 'textfield',
     '#title' => t('Card number'),
-    '#default_value' => $_SESSION['clear_cc'] ? '' : $default_num,
+    '#default_value' => $clear_cc ? '' : $default_num,
     '#attributes' => array('autocomplete' => 'off'),
     '#size' => 20,
     '#maxlength' => 19,
@@ -1016,6 +1017,10 @@
     $form['cc_start_month'] = uc_select_month(t('Start Month'), $order->payment_details['cc_start_month'], TRUE);
     $form['cc_start_year'] = uc_select_year(t('Start Year'), $order->payment_details['cc_start_year'], date('Y') - 10, date('Y'), TRUE);
   }
+  else {
+    $form['cc_start_month'] = array('#type' => 'value', '#value' => NULL);
+    $form['cc_start_year'] = array('#type' => 'value', '#value' => NULL);
+  }
 
   $form['cc_exp_month'] = uc_select_month(t('Expiration Month'), $order->payment_details['cc_exp_month']);
   $form['cc_exp_year'] = uc_select_year(t('Expiration Year'), $order->payment_details['cc_exp_year']);
@@ -1045,6 +1050,9 @@
       '#maxlength' => 2,
     );
   }
+  else {
+    $form['cc_issue'] = array('#type' => 'value', '#value' => NULL);
+  }
 
   if (variable_get('uc_credit_cvv_enabled', TRUE)) {
     // Set up the default CVV  on the credit card form.
@@ -1065,12 +1073,15 @@
     $form['cc_cvv'] = array(
       '#type' => 'textfield',
       '#title' => t('CVV'),
-      '#default_value' => $_SESSION['clear_cc'] ? '' : $default_cvv,
+      '#default_value' => $clear_cc ? '' : $default_cvv,
       '#attributes' => array('autocomplete' => 'off'),
       '#size' => variable_get('uc_credit_amex', TRUE) ? 4 : 3,
       '#maxlength' => variable_get('uc_credit_amex', TRUE) ? 4 : 3,
     );
   }
+  else {
+    $form['cc_cvv'] = array('#type' => 'value', '#value' => NULL);
+  }
 
   if (variable_get('uc_credit_bank_enabled', FALSE)) {
     $form['cc_bank'] = array(
@@ -1082,6 +1093,11 @@
       '#maxlength' => 64,
     );
   }
+  else {
+    $form['cc_bank'] = array('#type' => 'value', '#value' => NULL);
+  }
+
+  $form['#theme'] = 'uc_payment_method_credit_form';
 
   unset($_SESSION['clear_cc']);
 
@@ -1314,6 +1330,7 @@
     return FALSE;
   }
 
+  $total = 0;
   for ($i = 0; $i < strlen($number); $i++) {
     $digit = substr($number, $i, 1);
     if ((strlen($number) - $i - 1) % 2) {

=== modified file 'payment/uc_google_checkout/uc_google_checkout.admin.inc'
--- payment/uc_google_checkout/uc_google_checkout.admin.inc	2010-04-07 21:26:09 +0000
+++ payment/uc_google_checkout/uc_google_checkout.admin.inc	2010-06-03 15:57:46 +0000
@@ -90,13 +90,6 @@
     '#options' => array('right' => t('Right'), 'left' => t('Left')),
   );
 
-  /* $form['options'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Merchant options'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  ); */
-
   return system_settings_form($form);
 }
 
@@ -262,7 +255,6 @@
     else {
       $row[] = $form['taxes'][$zone]['zone']['#value'];
     }
-    //$form['taxes'][$zone]['zone']['#printed'] = TRUE;
     $row[] = drupal_render($form['taxes'][$zone]['rate']);
     $row[] = drupal_render($form['taxes'][$zone]['tax_shipping']);
     $rows[] = $row;

=== modified file 'payment/uc_google_checkout/uc_google_checkout.module'
--- payment/uc_google_checkout/uc_google_checkout.module	2010-05-20 19:31:35 +0000
+++ payment/uc_google_checkout/uc_google_checkout.module	2010-06-03 15:57:46 +0000
@@ -275,24 +275,24 @@
   return $items;
 }
 
-function uc_google_checkout_uc_order($op, &$arg1, $arg2) {
+function uc_google_checkout_uc_order($op, &$order, $arg2) {
   switch ($op) {
     case 'load':
-      $result = db_query("SELECT * FROM {uc_gc_orders} WHERE order_id = :id", array(':id' => $arg1->order_id));
+      $result = db_query("SELECT * FROM {uc_gc_orders} WHERE order_id = :id", array(':id' => $order->order_id));
       if ($gc = $result->fetchObject()) {
-        $arg1->google_order_number = $gc->gc_order_number;
-        $arg1->financial_state = $gc->financial_state;
-        $arg1->fulfillment_state = $gc->fulfillment_state;
-        $arg1->gc_total = $gc->gc_total;
+        $order->google_order_number = $gc->gc_order_number;
+        $order->financial_state = $gc->financial_state;
+        $order->fulfillment_state = $gc->fulfillment_state;
+        $order->gc_total = $gc->gc_total;
       }
     break;
     case 'can_update':
-      if (!isset($arg1->google_order_number) || isset($_SESSION['google_updates']) && $_SESSION['google_updates']) {
+      if (!isset($order->google_order_number) || isset($_SESSION['google_updates']) && $_SESSION['google_updates']) {
         return TRUE;
       }
       switch ($arg2) {
         case 'canceled':
-          if (uc_google_checkout_cancel_order($arg1)) {
+          if (uc_google_checkout_cancel_order($order)) {
             drupal_set_message(t('Cancel order request sent to Google Checkout. The order will be updated momentarily.'));
           }
           else {
@@ -714,11 +714,11 @@
   return $response;
 }
 
-function uc_google_checkout_pane_email_allowed($op, $arg1) {
+function uc_google_checkout_pane_email_allowed($op, $order) {
   switch ($op) {
     case 'customer':
     case 'view':
-      if ($arg1->data['email_allowed']) {
+      if ($order->data['email_allowed']) {
         $build = array('#markup' => t('Customer will accept marketing emails.'));
       }
       else {
@@ -733,10 +733,10 @@
  * Add setting callbacks to the payment settings section
  *  The fulfillment sections need coded still. JS.
  */
-function uc_payment_method_google_checkout($op, &$arg1) {
+function uc_payment_method_google_checkout($op, &$order) {
   switch ($op) {
     case 'order-view':
-      $build['#markup'] = l(t('Google Checkout terminal'), 'admin/store/orders/' . $arg1->order_id . '/google_checkout');
+      $build['#markup'] = l(t('Google Checkout terminal'), 'admin/store/orders/' . $order->order_id . '/google_checkout');
 
       return $build;
     case 'settings':

=== modified file 'payment/uc_payment/uc_payment.admin.inc'
--- payment/uc_payment/uc_payment.admin.inc	2010-03-24 13:18:45 +0000
+++ payment/uc_payment/uc_payment.admin.inc	2010-04-30 20:00:16 +0000
@@ -124,7 +124,7 @@
       }
 
       $null = NULL;
-      $method_settings = $method['callback']('settings', $null);
+      $method_settings = $method['callback']('settings', $null, array(), $form_state);
       if (is_array($method_settings)) {
         $form['method_' . $method['id']] = array(
           '#type' => 'fieldset',

=== modified file 'payment/uc_payment/uc_payment.ca.inc'
--- payment/uc_payment/uc_payment.ca.inc	2010-03-24 13:11:48 +0000
+++ payment/uc_payment/uc_payment.ca.inc	2010-06-03 15:57:46 +0000
@@ -173,11 +173,11 @@
     case 'less':
       return $balance < 0;
     case 'less_equal':
-      return $balance <= .01;
+      return $balance <= 0.01;
     case 'equal':
-      return $balance < .01 && $balance > -.01;
+      return $balance < 0.01 && $balance > -0.01;
     case 'greater':
-      return $balance >= .01;
+      return $balance >= 0.01;
   }
 }
 

=== modified file 'payment/uc_payment/uc_payment.js'
--- payment/uc_payment/uc_payment.js	2010-03-23 20:10:29 +0000
+++ payment/uc_payment/uc_payment.js	2010-06-03 19:32:27 +0000
@@ -1,36 +1,12 @@
 // $Id$
 
-/**
- * Calculate the number of bytes of a Unicode string.
- *
- * Gratefully stolen from http://dt.in.th/2008-09-16.string-length-in-bytes.html.
- * Javascript String.length returns the number of characters, but PHP strlen()
- * returns the number of bytes. When building serialize()d strings in JS,
- * use this function to get the correct string length.
- */
-String.prototype.bytes = function() {
-  // Drupal.encodePath() gets around some weirdness in
-  // encodeURIComponent(), but encodes some characters twice. The first
-  // replace takes care of those while the second lets String.length count
-  // the multi-byte characters.
-  return Drupal.encodePath(this).replace(/%252[36F]/g, 'x').replace(/%../g, 'x').length;
-};
-
-// Arrays for order total preview data.
-var li_titles = {};
-var li_values = {};
-var li_weight = {};
-var li_summed = {};
-
 // Timestamps for last time line items or payment details were updated.
-var line_update = 0;
 var payment_update = 0;
 
 var do_payment_details = true;
 
 jQuery.extend(Drupal.settings, {
   ucShowProgressBar: false,
-  ucDefaultPayment: '',
   ucOrderInitiate: false
 });
 
@@ -42,11 +18,6 @@
       show_progressBar('#line-items-div');
     }
 
-    // initialize payment details
-    if (Drupal.settings.ucDefaultPayment != '') {
-      init_payment_details(Drupal.settings.ucDefaultPayment);
-    }
-
     // disable the submission buttons and get payment details
     if (Drupal.settings.ucOrderInitiate) {
       add_order_save_hold();
@@ -61,147 +32,6 @@
   jQuery(id).empty().append(progress.element);
 }
 
-function serializeOrder() {
-  var products = jQuery("[name=cart_contents]").val();
-  if (!products) {
-    return false;
-  }
-
-  var p_email = jQuery("input[name*=primary_email]").val() || '';
-  var s_f_name = jQuery("input[name*=delivery_first_name]").val() || '';
-  var s_l_name = jQuery("input[name*=delivery_last_name]").val() || '';
-  var s_street1 = jQuery("input[name*=delivery_street1]").val() || '';
-  var s_street2 = jQuery("input[name*=delivery_street2]").val() || '';
-  var s_city = jQuery("input[name*=delivery_city]").val() || '';
-  var s_zone = jQuery("select[name*=delivery_zone]").val() || '0';
-  var s_code = jQuery("input[name*=delivery_postal_code]").val() || '';
-  var s_country = jQuery("select[name*=delivery_country]").val() || '0';
-
-  var b_f_name = jQuery("input[name*=billing_first_name]").val() || '';
-  var b_l_name = jQuery("input[name*=billing_last_name]").val() || '';
-  var b_street1 = jQuery("input[name*=billing_street1]").val() || '';
-  var b_street2 = jQuery("input[name*=billing_street2]").val() || '';
-  var b_city = jQuery("input[name*=billing_city]").val() || '';
-  var b_zone = jQuery("select[name*=billing_zone]").val() || '0';
-  var b_code = jQuery("input[name*=billing_postal_code]").val() || '';
-  var b_country = jQuery("select[name*=billing_country]").val() || '0';
-
-  var line_item = '';
-  var key;
-  var type;
-  var i = 0;
-  for (key in li_titles) {
-    temp = key.split('_', 2);
-    if (temp[1] != undefined && temp[1].match(/^\d+$/)) {
-      type = temp[0];
-    }
-    else {
-      type = key;
-    }
-    line_item = line_item + 'i:' + i + ';a:5:{s:5:"title";s:' + li_titles[key].bytes() + ':"' + li_titles[key] + '";s:4:"type";s:'+ type.bytes() + ':"'+ type + '";s:6:"amount";d:' + li_values[key] + ';s:6:"weight";d:' + li_weight[key] + ';s:6:"summed";i:' + li_summed[key] + ';}';
-    i++;
-  }
-  line_item = 's:10:"line_items";a:' + i + ':{' + line_item + '}';
-
-  var order_size = 21;
-  var order = 'O:8:"stdClass":' + order_size + ':{s:8:"products";' + products
-    + 's:8:"order_id";i:0;'
-    + 's:3:"uid";i:0;'
-    + 's:13:"primary_email";s:' + p_email.bytes() + ':"' + p_email
-    + '";s:19:"delivery_first_name";s:' + s_f_name.bytes() + ':"' + s_f_name
-    + '";s:18:"delivery_last_name";s:' + s_l_name.bytes() + ':"' + s_l_name
-    + '";s:16:"delivery_street1";s:' + s_street1.bytes() + ':"' + s_street1
-    + '";s:16:"delivery_street2";s:' + s_street2.bytes() + ':"' + s_street2
-    + '";s:13:"delivery_city";s:' + s_city.bytes() + ':"' + s_city
-    + '";s:13:"delivery_zone";i:' + s_zone
-    + ';s:20:"delivery_postal_code";s:' + s_code.bytes() +':"' + s_code
-    + '";s:16:"delivery_country";i:' + s_country + ';'
-    + 's:18:"billing_first_name";s:' + b_f_name.bytes() + ':"' + b_f_name
-    + '";s:17:"billing_last_name";s:' + b_l_name.bytes() + ':"' + b_l_name
-    + '";s:15:"billing_street1";s:' + b_street1.bytes() + ':"' + b_street1
-    + '";s:15:"billing_street2";s:' + b_street2.bytes() + ':"' + b_street2
-    + '";s:12:"billing_city";s:' + b_city.bytes() + ':"' + b_city
-    + '";s:12:"billing_zone";i:' + b_zone
-    + ';s:19:"billing_postal_code";s:' + b_code.bytes() +':"' + b_code
-    + '";s:15:"billing_country";i:' + b_country + ';'
-    + line_item + '}';
-
-  return order;
-}
-
-/**
- * Sets a line item in the order total preview.
- */
-function set_line_item(key, title, value, weight, summed, render) {
-  var do_update = false;
-
-  if (summed === undefined) {
-    summed = 1;
-  }
-  // Check to see if we're actually changing anything and need to update.
-  if (window.li_values[key] === undefined) {
-    do_update = true;
-  }
-  else {
-    if (li_titles[key] != title || li_values[key] != value || li_weight[key] != weight || li_summed[key] != summed) {
-      do_update = true;
-    }
-  }
-
-  if (do_update) {
-    // Set the values passed in, overriding previous values for that key.
-    if (key != "") {
-      li_titles[key] = title;
-      li_values[key] = value;
-      li_weight[key] = weight;
-      li_summed[key] = summed;
-    }
-    if (render == null || render) {
-      render_line_items();
-    }
-  }
-}
-
-function render_line_items() {
-  // Set the timestamp for this update.
-  var this_update = new Date();
-
-  // Set the global timestamp for the update.
-  line_update = this_update.getTime();
-
-  // Put all the existing line item data into a single array.
-  var cur_total = 0;
-  jQuery.each(li_titles,
-    function(a, b) {
-      // Tally up the current order total for storage in a hidden item.
-      if (li_titles[a] != '' && li_summed[a] == 1) {
-        cur_total += li_values[a];
-      }
-    }
-  );
-  jQuery('#edit-panes-payment-current-total').val(cur_total).click();
-
-  jQuery('#order-total-throbber').addClass('ubercart-throbber').html('&nbsp;&nbsp;&nbsp;&nbsp;');
-
-  // Post the line item data to a URL and get it back formatted for display.
-  jQuery.post(Drupal.settings.ucURL.checkoutLineItems, {order: serializeOrder()},
-    function(contents) {
-      // Only display the changes if this was the last requested update.
-      if (this_update.getTime() == line_update) {
-        jQuery('#line-items-div').empty().append(contents);
-      }
-    }
-  );
-}
-
-function remove_line_item(key) {
-  delete li_titles[key];
-  delete li_values[key];
-  delete li_weight[key];
-  delete li_summed[key];
-  render_line_items();
-}
-
 /**
  * Doesn't refresh the payment details if they've already been loaded.
  */

=== modified file 'payment/uc_payment/uc_payment.module'
--- payment/uc_payment/uc_payment.module	2010-04-05 19:25:15 +0000
+++ payment/uc_payment/uc_payment.module	2010-06-03 15:57:46 +0000
@@ -167,6 +167,9 @@
  */
 function uc_payment_theme() {
   return array(
+    'uc_payment_totals' => array(
+      'variables' => array('order' => NULL),
+    ),
     'uc_payment_method_table' => array(
       'render element' => 'form',
       'file' => 'uc_payment.admin.inc',
@@ -189,17 +192,6 @@
   $conf['i18n_variables'][] = 'uc_default_payment_msg';
 }
 
-/**
- * Implement hook_form_alter().
- */
-function uc_payment_form_alter(&$form, &$form_state, $form_id) {
-  if ($form_id == 'uc_cart_checkout_form') {
-    drupal_add_js('misc/progress.js');
-    drupal_add_js(drupal_get_path('module', 'uc_payment') . '/uc_payment.js');
-  }
-}
-
-
 /*******************************************************************************
  * Hook Functions (Ubercart)
  ******************************************************************************/
@@ -207,42 +199,42 @@
 /**
  * Implement hook_uc_order().
  */
-function uc_payment_uc_order($op, &$arg1) {
-  if (!isset($arg1->payment_method)) {
-    $arg1->payment_method = '';
+function uc_payment_uc_order($op, &$order) {
+  if (!isset($order->payment_method)) {
+    $order->payment_method = '';
   }
 
   switch ($op) {
     case 'submit':
-      $func = _uc_payment_method_data($arg1->payment_method, 'callback');
+      $func = _uc_payment_method_data($order->payment_method, 'callback');
       if (function_exists($func)) {
-        return $func('order-submit', $arg1);
+        return $func('order-submit', $order);
       }
       break;
 
     case 'load':
-      $func = _uc_payment_method_data($arg1->payment_method, 'callback');
+      $func = _uc_payment_method_data($order->payment_method, 'callback');
       if (function_exists($func)) {
-        $func('order-load', $arg1);
+        $func('order-load', $order);
       }
       break;
 
     case 'save':
-      $func = _uc_payment_method_data($arg1->payment_method, 'callback');
+      $func = _uc_payment_method_data($order->payment_method, 'callback');
       if (function_exists($func)) {
-        $func('order-save', $arg1);
+        $func('order-save', $order);
       }
       break;
 
     case 'can_delete':
-      if (uc_payment_load_payments($arg1->order_id) !== FALSE) {
+      if (uc_payment_load_payments($order->order_id) !== FALSE) {
         return FALSE;
       }
       break;
 
     case 'delete':
       db_delete('uc_payment_receipts')
-        ->condition('order_id', $arg1->order_id)
+        ->condition('order_id', $order->order_id)
         ->execute();
 
       // Call each payment method to delete method specific data from the database.
@@ -250,7 +242,7 @@
       foreach ($methods as $method) {
         $func = $method['callback'];
         if (function_exists($func)) {
-          $func('order-delete', $arg1);
+          $func('order-delete', $order);
         }
       }
       break;
@@ -283,7 +275,7 @@
     'desc' => t('Specify and collect payment for an order.'),
     'class' => 'pos-left',
     'weight' => 4,
-    'show' => array('view', 'edit', 'customer'), //, 'invoice', 'customer'),
+    'show' => array('view', 'edit', 'customer'),
   );
 
   return $panes;
@@ -320,55 +312,41 @@
  * @return
  *   The formatted HTML of the order total preview if $return is set to TRUE.
  */
-function uc_payment_get_totals($return = FALSE, $order = NULL) {
-  $output = '';
-
-  if (empty($order) && is_array($_POST) && isset($_POST['order'])) {
-    $order = unserialize($_POST['order']);
-  }
-
-  if ($order) {
-    usort($order->line_items, 'uc_weight_sort');
-
-    $output = t('Order total preview:')
-             . ' <span id="order-total-throbber"></span><table>';
-    $grand_total = 0;
-
-    $context = array(
-      'type' => 'line_item',
-      'subject' => array(
-        'order' => $order,
-      ),
-    );
-
-    foreach ($order->line_items as $line) {
-      if (!empty($line['title'])) {
-        $context['revision'] = 'themed';
-        $context['subject']['line_item'] = $line;
-
-        $output .= '<tr><td align="right"><b>' . filter_xss($line['title']) . ':</b></td>'
-                  . '<td align="right">' . uc_price($line['amount'], $context) . '</td></tr>';
-
-        if ($line['summed']) {
-          $context['revision'] = 'altered';
-        }
-      }
+function uc_payment_get_totals($form, $form_state) {
+  return $form['panes']['payment']['line_items'];
+}
+
+function theme_uc_payment_totals($variables) {
+  $order = $variables['order'];
+
+  $output = t('Order total preview:') . '<table>';
+  $grand_total = 0;
+
+  $context = array(
+    'type' => 'line_item',
+    'subject' => array(
+      'order' => $order,
+    ),
+  );
+
+  foreach ($order->line_items as $line) {
+    if (!empty($line['title'])) {
+      $context['revision'] = 'themed';
+      $context['subject']['line_item'] = $line;
+
+      $output .= '<tr><td align="right"><b>' . filter_xss($line['title']) . ':</b></td>'
+        . '<td align="right">' . uc_price($line['amount'], $context) . '</td></tr>';
     }
-
-    $context['revision'] = 'themed';
-    $context['type'] = 'amount';
-    unset($context['subject']);
-    $output .= '<tr><td align="right"><b>' . t('Order total:') . '</b></td>'
-              . '<td align="right">' . uc_price(uc_order_get_total($order), $context)
-              . '</td></tr></table>';
-  }
-
-  if ($return) {
-    return $output;
-  }
-
-  print $output;
-  exit();
+  }
+
+  $context['revision'] = 'themed';
+  $context['type'] = 'amount';
+  unset($context['subject']);
+  $output .= '<tr><td align="right"><b>' . t('Order total:') . '</b></td>'
+    . '<td align="right">' . uc_price(uc_order_get_total($order), $context)
+    . '</td></tr></table>';
+
+  return $output;
 }
 
 function uc_payment_get_details($method_id, $view = 'cart', $order = NULL) {
@@ -552,8 +530,8 @@
   // If the payment processed successfully...
   if ($result['success'] === TRUE) {
     // Log the payment to the order if not disabled.
-    if ($result['log_payment'] !== FALSE) {
-      uc_payment_enter($order_id, $method, $amount, empty($result['uid']) ? 0 : $result['uid'], $result['data'], $result['comment']);
+    if (!isset($result['log_payment']) || $result['log_payment'] !== FALSE) {
+      uc_payment_enter($order_id, $method, $amount, empty($result['uid']) ? 0 : $result['uid'], empty($result['data']) ? '' : $result['data'], empty($result['comment']) ? '' : $result['comment']);
     }
   }
   else {

=== modified file 'payment/uc_payment/uc_payment_checkout_pane.inc'
--- payment/uc_payment/uc_payment_checkout_pane.inc	2010-03-24 13:11:48 +0000
+++ payment/uc_payment/uc_payment_checkout_pane.inc	2010-06-03 19:32:27 +0000
@@ -9,35 +9,25 @@
  * preview of the line items and order total.
  */
 
-function uc_checkout_pane_payment($op, &$arg1, $arg2) {
+function uc_checkout_pane_payment($op, &$order, $form = NULL, &$form_state = NULL) {
   switch ($op) {
     case 'view':
-      // Add the default payment message as a JS variable.
-      // Add URL paths as JS variables (be nice to i18n, allow URL rewrite).
-      drupal_add_js(array(
-        'defPaymentMsg' => addslashes(variable_get('uc_default_payment_msg', t('Continue with checkout to complete payment.'))),
-        'ucURL' => array(
-          'adminOrders' => url('admin/store/orders/'),
-          'checkoutPaymentDetails' => url('cart/checkout/payment_details/'),
-          'checkoutLineItems' => url('cart/checkout/line_items'),
-          'creditCardCVVInfo' => url('cart/checkout/credit/cvv_info'),
-        ),
-      ), 'setting');
+      if (empty($order->line_items)) {
+        $order->line_items = uc_order_load_line_items($order, FALSE);
+      }
 
       if (variable_get('uc_payment_show_order_total_preview', TRUE)) {
-        drupal_add_js('misc/progress.js');
-
         $contents['current_total'] = array(
           '#type' => 'hidden',
-          '#value' => isset($arg1->order_total) && $arg1->order_total > 0 ? $arg1->order_total : NULL,
+          '#value' => isset($order->order_total) && $order->order_total > 0 ? $order->order_total : NULL,
         );
-        $contents['shown_total'] = array(
-          '#markup' => '<div style="padding: .5em 1em; margin-bottom: 1em; border: dashed 1px #bbb;" id="line-items-div"><em>' . t('Javascript must be enabled to view the order total preview.') . '</em></div>',
+        $contents['line_items'] = array(
+          '#theme' => 'uc_payment_totals',
+          '#order' => $order,
+          '#prefix' => '<div style="padding: .5em 1em; margin-bottom: 1em; border: dashed 1px #bbb;" id="line-items-div">',
+          '#suffix' => '</div>',
           '#weight' => -20,
         );
-
-        // let the script know we need to show a progressbar
-        drupal_add_js(array('ucShowProgressBar' => TRUE), 'setting');
       }
 
       $methods = _uc_payment_method_list();
@@ -51,11 +41,11 @@
       }
 
       if (count($options)) {
-        if (isset($_POST['panes']) && in_array($_POST['panes']['payment']['payment_method'], array_keys($options))) {
-          $default = $_POST['panes']['payment']['payment_method'];
+        if (isset($form_state['values']) && in_array($form_state['values']['panes']['payment']['payment_method'], array_keys($options))) {
+          $default = $form_state['values']['panes']['payment']['payment_method'];
         }
         else {
-          $default = (count($options) == 1 || !isset($arg1->payment_method)) ? key($options) : $arg1->payment_method;
+          $default = (count($options) == 1 || empty($order->payment_method)) ? key($options) : $order->payment_method;
         }
       }
 
@@ -73,20 +63,33 @@
         '#default_value' => $default,
         '#disabled' => count($options) == 1 ? TRUE : FALSE,
         '#required' => TRUE,
-        '#attributes' => array('onclick' => "get_payment_details(Drupal.settings.ucURL.checkoutPaymentDetails + this.value);"),
         '#theme' => 'uc_payment_method_select',
+        '#ajax' => array(
+          'callback' => 'uc_payment_checkout_payment_details',
+          'wrapper' => 'payment_details',
+        ),
       );
+
       $contents['details'] = array(
-        '#markup' => '<div id="payment_details" class="solid-border display-none"></div>',
+        '#prefix' => '<div id="payment_details" class="solid-border">',
+        '#suffix' => '</div>',
       );
 
+      $func = _uc_payment_method_data($default, 'callback');
+      if (function_exists($func)) {
+        $details = $func('cart-details', $order, $form, $form_state);
+        if (is_array($details) && !empty($details)) {
+          $contents['details'] += $details;
+        }
+      }
+
       return array('description' => $description, 'contents' => $contents);
 
     case 'process':
-      $arg1->payment_method = $arg2['payment_method'];
-      $func = _uc_payment_method_data($arg1->payment_method, 'callback');
+      $order->payment_method = $form_state['values']['panes']['payment']['payment_method'];
+      $func = _uc_payment_method_data($order->payment_method, 'callback');
       if (function_exists($func)) {
-        $result = $func('cart-process', $arg1);
+        $result = $func('cart-process', $order, $form, $form_state);
         if ($result === FALSE) {
           return FALSE;
         }
@@ -94,11 +97,11 @@
       return TRUE;
 
     case 'review':
-      $line_items = $arg1->line_items;
+      $line_items = $order->line_items;
       $items = _uc_line_item_list();
       foreach ($items as $item) {
         if (isset($item['display_only']) && $item['display_only'] == TRUE) {
-          $result = $item['callback']('display', $arg1);
+          $result = $item['callback']('display', $order);
           if (is_array($result)) {
             foreach ($result as $line) {
               $line_items[] = array(
@@ -116,21 +119,21 @@
         'revision' => 'themed',
         'type' => 'line_item',
         'subject' => array(
-          'order' => $arg1,
+          'order' => $order,
         ),
       );
       foreach ($line_items as $line_item) {
         $context['subject']['line_item'] = $line_item;
         $review[] = array('title' => $line_item['title'], 'data' => uc_price($line_item['amount'], $context));
       }
-      $review_data = _uc_payment_method_data($arg1->payment_method, 'review');
+      $review_data = _uc_payment_method_data($order->payment_method, 'review');
       if (empty($review_data)) {
-        $review_data = _uc_payment_method_data($arg1->payment_method, 'name');
+        $review_data = _uc_payment_method_data($order->payment_method, 'name');
       }
       $review[] = array('border' => 'top', 'title' => t('Paying by'), 'data' => $review_data);
-      $func = _uc_payment_method_data($arg1->payment_method, 'callback');
+      $func = _uc_payment_method_data($order->payment_method, 'callback');
       if (function_exists($func)) {
-        $result = $func('cart-review', $arg1);
+        $result = $func('cart-review', $order);
         if (is_array($result)) {
           $review = array_merge($review, $result);
         }
@@ -148,6 +151,13 @@
 }
 
 /**
+ * AJAX callback for payment method details on the checkout form.
+ */
+function uc_payment_checkout_payment_details($form, $form_state) {
+  return $form['panes']['payment']['details'];
+}
+
+/**
  * We need a theme function for the radios element in case another module alters
  * the default or available payment methods... we need the JS to grab the right
  * default payment details.
@@ -160,9 +170,5 @@
     return;
   }
 
-  // Perhaps instead this should be a normal JS function and we just print the
-  // default payment method to a JS variable or use a selector.  -RS
-  drupal_add_js(array('ucDefaultPayment' => $form['#default_value']), 'setting');
-
   return drupal_render_children($form);
 }

=== modified file 'payment/uc_payment/uc_payment_order_pane.inc'
--- payment/uc_payment/uc_payment_order_pane.inc	2010-05-18 20:14:02 +0000
+++ payment/uc_payment/uc_payment_order_pane.inc	2010-06-03 15:57:46 +0000
@@ -15,7 +15,7 @@
 /**
  * Handle the Payment order pane.
  */
-function uc_order_pane_payment($op, $arg1) {
+function uc_order_pane_payment($op, $order) {
   switch ($op) {
     case 'view':
       if (variable_get('uc_payment_tracking', TRUE)) {
@@ -23,20 +23,20 @@
           'revision' => 'formatted-original',
           'type' => 'amount',
         );
-        $build['balance'] = array('#markup' => t('Balance: @balance', array('@balance' => uc_price(uc_payment_balance($arg1), $context))));
+        $build['balance'] = array('#markup' => t('Balance: @balance', array('@balance' => uc_price(uc_payment_balance($order), $context))));
         $build['view_payments'] = array(
-          '#markup' => ' (' . l(t('View'), 'admin/store/orders/' . $arg1->order_id . '/payments') . ')',
+          '#markup' => ' (' . l(t('View'), 'admin/store/orders/' . $order->order_id . '/payments') . ')',
           '#suffix' => '<br />',
         );
       }
-      $method_name = _uc_payment_method_data($arg1->payment_method, 'review');
+      $method_name = _uc_payment_method_data($order->payment_method, 'review');
       if (empty($method_name)) {
-        $method_name = _uc_payment_method_data($arg1->payment_method, 'name');
+        $method_name = _uc_payment_method_data($order->payment_method, 'name');
       }
       $build['method'] = array('#markup' => t('Method: @payment_method', array('@payment_method' => $method_name)));
-      $func = _uc_payment_method_data($arg1->payment_method, 'callback');
+      $func = _uc_payment_method_data($order->payment_method, 'callback');
       if (function_exists($func)) {
-        $method_output = $func('order-view', $arg1);
+        $method_output = $func('order-view', $order);
         if (!empty($method_output)) {
           $build['output'] = $method_output + array(
             '#prefix' => '<br />',
@@ -47,14 +47,14 @@
       return $build;
 
     case 'customer':
-      $method_name = _uc_payment_method_data($arg1->payment_method, 'review');
+      $method_name = _uc_payment_method_data($order->payment_method, 'review');
       if (empty($method_name)) {
-        $method_name = _uc_payment_method_data($arg1->payment_method, 'name');
+        $method_name = _uc_payment_method_data($order->payment_method, 'name');
       }
       $build['method'] = array('#markup' => t('Method: @payment_method', array('@payment_method' => $method_name)));
-      $func = _uc_payment_method_data($arg1->payment_method, 'callback');
+      $func = _uc_payment_method_data($order->payment_method, 'callback');
       if (function_exists($func)) {
-        $method_output = $func('customer-view', $arg1);
+        $method_output = $func('customer-view', $order);
         if (!empty($method_output)) {
           $build['output'] = $method_output + array(
             '#prefix' => '<br />',
@@ -81,9 +81,9 @@
       $form['payment']['payment_method'] = array(
         '#type' => 'select',
         '#title' => t('Payment method'),
-        '#default_value' => $arg1->payment_method,
+        '#default_value' => $order->payment_method,
         '#options' => (is_array($options)) ? $options : array(t('None available')),
-        '#attributes' => array('onchange' => "add_order_save_hold(); get_payment_details(Drupal.settings.ucURL.adminOrders + '" . $arg1->order_id . "/payment_details/' + this.value);"),
+        '#attributes' => array('onchange' => "add_order_save_hold(); get_payment_details(Drupal.settings.ucURL.adminOrders + '" . $order->order_id . "/payment_details/' + this.value);"),
         '#disabled' => (is_array($options)) ? FALSE : TRUE,
       );
       return $form;
@@ -103,19 +103,19 @@
       drupal_add_js(array('ucOrderInitiate' => TRUE), 'setting');
 
       $output = '<table class="order-edit-table">';
-      foreach (element_children($arg1['payment']) as $field) {
-        $title = $arg1['payment'][$field]['#title'];
-        $arg1['payment'][$field]['#title'] = NULL;
+      foreach (element_children($order['payment']) as $field) {
+        $title = $order['payment'][$field]['#title'];
+        $order['payment'][$field]['#title'] = NULL;
         $output .= '<tr><td class="oet-label">' . $title . ':</td><td>'
-                 . drupal_render($arg1['payment'][$field]) . '</td></tr>';
+                 . drupal_render($order['payment'][$field]) . '</td></tr>';
       }
       $output .= '</table><div id="payment_details"></div>';
       return $output;
 
     case 'edit-process':
-      $changes['payment_method'] = $arg1['payment_method'];
-      $func = _uc_payment_method_data($arg1['payment_method'], 'callback');
-      if (function_exists($func) && ($return = $func('edit-process', $arg1)) != NULL && is_array($return)) {
+      $changes['payment_method'] = $order['payment_method'];
+      $func = _uc_payment_method_data($order['payment_method'], 'callback');
+      if (function_exists($func) && ($return = $func('edit-process', $order)) != NULL && is_array($return)) {
         $changes = array_merge($changes, $return);
       }
       return $changes;

=== modified file 'payment/uc_payment_pack/uc_payment_pack.module'
--- payment/uc_payment_pack/uc_payment_pack.module	2010-04-07 16:15:47 +0000
+++ payment/uc_payment_pack/uc_payment_pack.module	2010-06-03 15:57:46 +0000
@@ -87,18 +87,18 @@
 /**
  * Handle the generic payment method "Other."
  */
-function uc_payment_method_other($op, &$arg1) {
+function uc_payment_method_other($op, &$order) {
   switch ($op) {
     case 'order-view':
     case 'customer-view':
       // Fetch the description for the payment entered by the administrator.
-      if ($description = db_query("SELECT description FROM {uc_payment_other} WHERE order_id = :id", array(':id' => $arg1->order_id))->fetchField()) {
+      if ($description = db_query("SELECT description FROM {uc_payment_other} WHERE order_id = :id", array(':id' => $order->order_id))->fetchField()) {
         return array('#markup' => t('Description: @desc', array('@desc' => $description)));
       }
       break;
 
     case 'order-details':
-      $details = drupal_get_form('uc_payment_method_other_form', $arg1);
+      $details = drupal_get_form('uc_payment_method_other_form', $order);
       return uc_strip_form($details);
 
     case 'edit-process':
@@ -106,24 +106,24 @@
       return $changes;
 
     case 'order-load':
-      if ($description = db_query("SELECT description FROM {uc_payment_other} WHERE order_id = :id", array(':id' => $arg1->order_id))->fetchField()) {
-        $arg1->payment_details['description'] = $description;
+      if ($description = db_query("SELECT description FROM {uc_payment_other} WHERE order_id = :id", array(':id' => $order->order_id))->fetchField()) {
+        $order->payment_details['description'] = $description;
       }
       break;
 
     case 'order-save':
-      if (empty($arg1->payment_details['pm_other_description'])) {
+      if (empty($order->payment_details['pm_other_description'])) {
         db_delete('uc_payment_other')
-          ->condition('order_id', $arg1->order_id)
+          ->condition('order_id', $order->order_id)
           ->execute();
       }
       else {
         db_merge('uc_payment_other')
           ->key(array(
-            'order_id' => $arg1->order_id,
+            'order_id' => $order->order_id,
           ))
           ->fields(array(
-            'description' => $arg1->payment_details['pm_other_description'],
+            'description' => $order->payment_details['pm_other_description'],
           ))
           ->execute();
       }
@@ -156,7 +156,7 @@
 /**
  * Handle the Cash on Delivery payment method.
  */
-function uc_payment_method_cod($op, &$arg1) {
+function uc_payment_method_cod($op, &$order) {
   switch ($op) {
     case 'cart-details':
       $build['policy'] = array('#markup' => variable_get('uc_cod_policy', t('Full payment is expected upon delivery or prior to pick-up.')));
@@ -170,24 +170,24 @@
       }
 
       if (variable_get('uc_cod_delivery_date', FALSE)) {
-        $build['form'] = uc_strip_form(drupal_get_form('uc_payment_method_cod_form', $arg1));
+        $build['form'] = uc_strip_form(drupal_get_form('uc_payment_method_cod_form', $order));
       }
 
       return $build;
 
     case 'cart-process':
       if (variable_get('uc_cod_delivery_date', FALSE)) {
-        $arg1->payment_details['delivery_month'] = intval($_POST['cod_delivery_month']);
-        $arg1->payment_details['delivery_day'] = intval($_POST['cod_delivery_day']);
-        $arg1->payment_details['delivery_year'] = intval($_POST['cod_delivery_year']);
+        $order->payment_details['delivery_month'] = intval($_POST['cod_delivery_month']);
+        $order->payment_details['delivery_day'] = intval($_POST['cod_delivery_day']);
+        $order->payment_details['delivery_year'] = intval($_POST['cod_delivery_year']);
       }
       return TRUE;
 
     case 'cart-review':
       if (variable_get('uc_cod_delivery_date', FALSE)) {
-        $date = uc_date_format($arg1->payment_details['delivery_month'],
-                               $arg1->payment_details['delivery_day'],
-                               $arg1->payment_details['delivery_year']);
+        $date = uc_date_format($order->payment_details['delivery_month'],
+                               $order->payment_details['delivery_day'],
+                               $order->payment_details['delivery_year']);
         $review[] = array('title' => t('Delivery Date'), 'data' => $date);
       }
       return $review;
@@ -198,9 +198,9 @@
 
       if (variable_get('uc_cod_delivery_date', FALSE)) {
         $build['#markup'] = t('Desired delivery date:') . '<br />' .
-          uc_date_format($arg1->payment_details['delivery_month'],
-            $arg1->payment_details['delivery_day'],
-            $arg1->payment_details['delivery_year']);
+          uc_date_format($order->payment_details['delivery_month'],
+            $order->payment_details['delivery_day'],
+            $order->payment_details['delivery_year']);
       }
 
       return $build;
@@ -209,7 +209,7 @@
       $build = array();
 
       if (variable_get('uc_cod_delivery_date', FALSE)) {
-        $build = uc_strip_form(drupal_get_form('uc_payment_method_cod_form', $arg1));
+        $build = uc_strip_form(drupal_get_form('uc_payment_method_cod_form', $order));
       }
 
       return $build;
@@ -227,19 +227,19 @@
       return;
 
     case 'order-load':
-      $result = db_query("SELECT * FROM {uc_payment_cod} WHERE order_id = :id", array(':id' => $arg1->order_id));
+      $result = db_query("SELECT * FROM {uc_payment_cod} WHERE order_id = :id", array(':id' => $order->order_id));
       if ($row = $result->fetchObject()) {
-        $arg1->payment_details['delivery_month'] = $row->delivery_month;
-        $arg1->payment_details['delivery_day'] = $row->delivery_day;
-        $arg1->payment_details['delivery_year'] = $row->delivery_year;
+        $order->payment_details['delivery_month'] = $row->delivery_month;
+        $order->payment_details['delivery_day'] = $row->delivery_day;
+        $order->payment_details['delivery_year'] = $row->delivery_year;
       }
       break;
 
     case 'order-submit':
-      if ($arg1->payment_method == 'cod' &&
+      if ($order->payment_method == 'cod' &&
           ($max = variable_get('uc_cod_max_order', 0)) > 0 &&
           is_numeric($max) &&
-          $arg1->order_total > $max) {
+          $order->order_total > $max) {
           $result[] = array(
             'pass' => FALSE,
             'message' => t('Your final order total exceeds the maximum for COD payment.  Please go back and select a different method of payment.')
@@ -249,18 +249,18 @@
       }
     case 'order-save':
       db_merge('uc_payment_cod')
-        ->key(array('order_id' => $arg1->order_id))
+        ->key(array('order_id' => $order->order_id))
         ->fields(array(
-          'delivery_month' => $arg1->payment_details['delivery_month'],
-          'delivery_day' => $arg1->payment_details['delivery_day'],
-          'delivery_year' => $arg1->payment_details['delivery_year'],
+          'delivery_month' => $order->payment_details['delivery_month'],
+          'delivery_day' => $order->payment_details['delivery_day'],
+          'delivery_year' => $order->payment_details['delivery_year'],
         ))
         ->execute();
       break;
 
     case 'order-delete':
       db_delete('uc_payment_cod')
-        ->condition('order_id', $arg1->order_id)
+        ->condition('order_id', $order->order_id)
         ->execute();
       break;
 
@@ -320,7 +320,7 @@
 /**
  * Handle the Check payment method.
  */
-function uc_payment_method_check($op, &$arg1) {
+function uc_payment_method_check($op, &$order, $form = NULL, &$form_state = NULL) {
   switch ($op) {
     case 'cart-details':
       $build['instructions'] = array('#markup' => t('Checks should be made out to:'));
@@ -395,12 +395,12 @@
 
       $build = array('#suffix' => '<br />');
 
-      $result = db_query("SELECT clear_date FROM {uc_payment_check} WHERE order_id = :id ", array(':id' => $arg1->order_id));
+      $result = db_query("SELECT clear_date FROM {uc_payment_check} WHERE order_id = :id ", array(':id' => $order->order_id));
       if ($clear_date = $result->fetchField()) {
         $build['#markup'] = t('Clear Date:') . ' ' . format_date($clear_date, 'custom', variable_get('uc_date_format_default', 'm/d/Y'));
       }
       else {
-        $build['#markup'] = l(t('Receive Check'), 'admin/store/orders/' . $arg1->order_id . '/receive_check');
+        $build['#markup'] = l(t('Receive Check'), 'admin/store/orders/' . $order->order_id . '/receive_check');
       }
 
       return $build;
@@ -412,7 +412,7 @@
 
       $build = array();
 
-      $result = db_query("SELECT clear_date FROM {uc_payment_check} WHERE order_id = :id ", array(':id' => $arg1->order_id));
+      $result = db_query("SELECT clear_date FROM {uc_payment_check} WHERE order_id = :id ", array(':id' => $order->order_id));
       if ($clear_date = $result->fetchField()) {
         $build['#markup'] = t('Check received') . '<br />' .
           t('Expected clear date:') . '<br />' . format_date($clear_date, 'custom', variable_get('uc_date_format_default', 'm/d/Y'));

=== modified file 'payment/uc_paypal/uc_paypal.module'
--- payment/uc_paypal/uc_paypal.module	2010-05-17 14:07:01 +0000
+++ payment/uc_paypal/uc_paypal.module	2010-06-03 15:57:46 +0000
@@ -510,10 +510,10 @@
 }
 
 // Handles the Website Payments Standard payment method.
-function uc_payment_method_paypal_wps($op, &$arg1) {
+function uc_payment_method_paypal_wps($op, &$order) {
   switch ($op) {
     case 'order-view':
-      $txn_id = db_query("SELECT txn_id FROM {uc_payment_paypal_ipn} WHERE order_id = :id ORDER BY received ASC", array(':id' => $arg1->order_id))->fetchField();
+      $txn_id = db_query("SELECT txn_id FROM {uc_payment_paypal_ipn} WHERE order_id = :id ORDER BY received ASC", array(':id' => $order->order_id))->fetchField();
       if (empty($txn_id)) {
         $txn_id = t('Unknown');
       }
@@ -620,10 +620,10 @@
 }
 
 // Handles the Express Checkout payment method.
-function uc_payment_method_paypal_ec($op, &$arg1) {
+function uc_payment_method_paypal_ec($op, &$order) {
   switch ($op) {
     case 'order-view':
-      $txn_id = db_query("SELECT txn_id FROM {uc_payment_paypal_ipn} WHERE order_id = :id ORDER BY received ASC", array(':id' => $arg1->order_id))->fetchField();
+      $txn_id = db_query("SELECT txn_id FROM {uc_payment_paypal_ipn} WHERE order_id = :id ORDER BY received ASC", array(':id' => $order->order_id))->fetchField();
       if (empty($txn_id)) {
         $txn_id = t('Unknown');
       }

=== modified file 'payment/uc_paypal/uc_paypal.pages.inc'
--- payment/uc_paypal/uc_paypal.pages.inc	2010-03-24 13:11:48 +0000
+++ payment/uc_paypal/uc_paypal.pages.inc	2010-05-14 19:58:57 +0000
@@ -258,9 +258,6 @@
       '#markup' => '<div id="quote"></div>',
     );
 
-    // small hack; automatically looks for shipping quotes on page load
-    drupal_add_js("jQuery(document).ready(function() { jQuery('#edit-quote-button').click(); });", 'inline');
-
     // Fake the checkout form delivery information.
     $form['delivery_first_name'] = array('#type' => 'hidden', '#value' => $order->delivery_first_name);
     $form['delivery_last_name'] = array('#type' => 'hidden', '#value' => $order->delivery_last_name);

=== modified file 'shipping/uc_quote/uc_quote.install'
--- shipping/uc_quote/uc_quote.install	2010-04-01 18:42:54 +0000
+++ shipping/uc_quote/uc_quote.install	2010-06-03 19:32:27 +0000
@@ -159,10 +159,6 @@
         'not null' => TRUE,
         'default' => 0,
       ),
-      'quote_form' => array(
-        'description' => 'HTML form used to choose the shipping quote.',
-        'type' => 'text',
-      ),
     ),
     'unique keys' => array(
       'order_id_quote_method' => array('order_id', 'method'),
@@ -186,3 +182,9 @@
   variable_del('uc_store_shipping_type');
 }
 
+/**
+ * Drop {uc_order_quotes}.quote_form.
+ */
+function uc_quote_update_7001() {
+  db_drop_field('uc_order_quotes', 'quote_form');
+}

=== removed file 'shipping/uc_quote/uc_quote.js'
--- shipping/uc_quote/uc_quote.js	2010-03-23 20:10:29 +0000
+++ shipping/uc_quote/uc_quote.js	1970-01-01 00:00:00 +0000
@@ -1,209 +0,0 @@
-// $Id$
-
-/**
- * @file
- * Handle asynchronous calls on checkout page to retrieve shipping quotes.
- */
-
-var page;
-var details;
-var methods;
-
-/**
- * Set event handlers on address fields.
- */
-function setQuoteCallbacks(products, context) {
-  triggerQuoteCallback = function() {
-    quoteCallback(products);
-  };
-  jQuery("input[name*=delivery_postal_code]:not(.getQuotes-processed)", context).addClass('getQuotes-processed').change(triggerQuoteCallback);
-  jQuery("input[id*=quote-button]:not(.getQuotes-processed)", context).addClass('getQuotes-processed').click(function() {
-    // returns false to prevent default actions and propogation
-    return quoteCallback(products);
-  });
-  jQuery("input[name*=quote_method]:not(.getQuotes-processed)", context).addClass('getQuotes-processed').change(function() {
-    // returns false to prevent default actions and propogation
-    return quoteCallback(products);
-  });
-  jQuery("select[name*=delivery_address_select]:not(.getQuotes-processed)", context).addClass('getQuotes-processed').change(function() {
-    jQuery("input[name*=delivery_postal_code]").trigger('change');
-  });
-  jQuery("input[name*=copy_address]:not(.getQuotes-processed)", context).addClass('getQuotes-processed').click(function() {
-    if (copy_box_checked == true) {
-      jQuery("input[name*=billing_postal_code]:not(.getQuotes-processed)", context).addClass('getQuotes-processed').bind('change', triggerQuoteCallback);
-      jQuery("select[name*=billing_address_select]:not(.getQuotes-processed)", context).addClass('getQuotes-processed').bind('change', triggerQuoteCallback);
-      triggerQuoteCallback();
-    }
-    else {
-      jQuery("input[name*=billing_postal_code].getQuotes-processed").removeClass('getQuotes-processed').unbind('change', triggerQuoteCallback);
-      jQuery("select[name*=billing_address_select].getQuotes-processed").removeClass('getQuotes-processed').unbind('change', triggerQuoteCallback);
-    }
-  });
-}
-
-/**
- * Refresh line item list when a shipping method is selected.
- */
-function setTaxCallbacks() {
-  // Choosing to use click because of IE's bloody stupid bug not to
-  // trigger onChange until focus is lost. Click is better than doing
-  // set_line_item() and getTax() twice, I believe.
-  jQuery("#quote").find("input:radio").click(function() {
-    var i = jQuery(this).val();
-    if (window.set_line_item) {
-      var label = jQuery(this).parent().text();
-      set_line_item("shipping", label.substr(0, label.indexOf(":")), jQuery(this).parent().prev().val(), 1, 1);
-    }
-  });
-}
-
-/**
- * Retrieve a list of available shipping quotes.
- *
- * @param products
- *   Pipe- and carat-delimited values string representing the current contents
- *   of the shopping cart. Products are separated by | and product data by ^.
- */
-function quoteCallback(products) {
-  var updateCallback = function (progress, status, pb) {
-    if (progress == 100) {
-      pb.stopMonitoring();
-    }
-  };
-
-  page = jQuery("input:hidden[name*=page]").val();
-  details = new Object();
-  details["uid"] = jQuery("input[name*=uid]").val();
-  //details["details[zone]"] = jQuery("select[name*=delivery_zone] option:selected").val();
-  //details["details[country]"] = jQuery("select[name*=delivery_country] option:selected").val();
-
-  jQuery("select[name*=delivery_]").each(function(i) {
-    details["details[delivery][" + jQuery(this).attr("name").split("delivery_")[1].replace(/]/, "") + "]"] = jQuery(this).val();
-  });
-  jQuery("input[name*=delivery_]").each(function(i) {
-    details["details[delivery][" + jQuery(this).attr("name").split("delivery_")[1].replace(/]/, "") + "]"] = jQuery(this).val();
-  });
-  jQuery("select[name*=billing_]").each(function(i) {
-    details["details[billing][" + jQuery(this).attr("name").split("billing_")[1].replace(/]/, "") + "]"] = jQuery(this).val();
-  });
-  jQuery("input[name*=billing_]").each(function(i) {
-    details["details[billing][" + jQuery(this).attr("name").split("billing_")[1].replace(/]/, "") + "]"] = jQuery(this).val();
-  });
-
-  if (!!products) {
-    details["products"] = products;
-  }
-  else {
-    products = "";
-    var i = 0;
-    while (jQuery("input[name^='products[" + i + "]']").length) {
-      products += "|" + jQuery("input[name^='products[" + i + "]']").filter("[name$='[nid]']").val();
-      products += "^" + jQuery("input[name^='products[" + i + "]']").filter("[name$='[title]']").val();
-      products += "^" + jQuery("input[name^='products[" + i + "]']").filter("[name$='[model]']").val();
-      products += "^" + jQuery("input[name^='products[" + i + "]']").filter("[name$='[qty]']").val();
-      products += "^" + jQuery("input[name^='products[" + i + "]']").filter("[name$='[cost]']").val();
-      products += "^" + jQuery("input[name^='products[" + i + "]']").filter("[name$='[price]']").val();
-      products += "^" + jQuery("input[name^='products[" + i + "]']").filter("[name$='[weight]']").val();
-      products += "^" + jQuery("input[name^='products[" + i + "]']").filter("[name$='[data]']").val();
-      i++;
-    }
-    details["products"] = products.substr(1);
-  }
-  var progress = new Drupal.progressBar("quoteProgress");
-  progress.setProgress(-1, Drupal.settings.uc_quote.progress_msg);
-  jQuery("#quote").empty().append(progress.element);
-  jQuery("#quote").addClass("solid-border");
-  // progress.startMonitoring(Drupal.settings.basePath + "?q=shipping/quote", 0);
-  jQuery.ajax({
-    type: "POST",
-    url: Drupal.settings.ucURL.shippingQuotes,
-    data: details,
-    dataType: "json",
-    success: displayQuote
-  });
-
-  return false;
-}
-
-/**
- * Parse and render the returned shipping quotes.
- */
-function displayQuote(data) {
-  var quoteDiv = jQuery("#quote").empty()/* .append("<input type=\"hidden\" name=\"method-quoted\" value=\"" + details["method"] + "\" />") */;
-  var numQuotes = 0;
-  var errorFlag = true;
-  var i;
-  for (i in data) {
-    if (data[i].rate != undefined || data[i].error || data[i].notes) {
-      numQuotes++;
-    }
-  }
-  for (i in data) {
-    var item = '';
-    var label = data[i].option_label;
-    if (data[i].rate != undefined || data[i].error || data[i].notes) {
-
-      if (data[i].rate != undefined) {
-        if (numQuotes > 1 && page != 'cart') {
-          item = "<input type=\"hidden\" name=\"rate[" + i + "]\" value=\"" + data[i].rate + "\" />"
-            + "<label class=\"option\">"
-            + "<input type=\"radio\" class=\"form-radio\" name=\"quote-option\" value=\"" + i + "\" />"
-            + label + ": " + data[i].format + "</label>";
-        }
-        else {
-          item = "<input type=\"hidden\" name=\"quote-option\" value=\"" + i + "\" />"
-            + "<input type=\"hidden\" name=\"rate[" + i + "]\" value=\"" + data[i].rate + "\" />"
-            + "<label class=\"option\">" + label + ": " + data[i].format + "</label>";
-          if (page == "checkout") {
-            if (label != "" && window.set_line_item) {
-              set_line_item("shipping", label, data[i].rate, 1);
-            }
-          }
-        }
-      }
-      if (data[i].error) {
-        item += '<div class="quote-error">' + data[i].error + "</div>";
-      }
-      if (data[i].notes) {
-        item += '<div class="quote-notes">' + data[i].notes + "</div>";
-      }
-      if (data[i].rate == undefined && item.length) {
-        item = label + ': ' + item;
-      }
-      quoteDiv.append('<div class="form-item">' + item + "</div>\n");
-      Drupal.attachBehaviors(quoteDiv);
-      if (page == "checkout") {
-        // Choosing to use click because of IE's bloody stupid bug not to
-        // trigger onChange until focus is lost. Click is better than doing
-        // set_line_item() and getTax() twice, I believe.
-        quoteDiv.find("input:radio[value=" + i +"]").click(function() {
-          var i = jQuery(this).val();
-          if (window.set_line_item) {
-            set_line_item("shipping", data[i].option_label, data[i].rate, 1, 1);
-          }
-        });
-      }
-    }
-    if (data[i].debug != undefined) {
-      quoteDiv.append("<pre>" + data[i].debug + "</pre>");
-    }
-  }
-  if (quoteDiv.find("input").length == 0) {
-    quoteDiv.append(Drupal.settings.uc_quote.err_msg);
-  }
-  else {
-    quoteDiv.find("input:radio").eq(0).click().attr("checked", "checked");
-    var quoteForm = quoteDiv.html();
-    quoteDiv.append("<input type=\"hidden\" name=\"quote-form\" value=\"" + Drupal.encodePath(quoteForm) + "\" />");
-  }
-
-  /* if (page == "checkout") {
-    if (window.getTax) {
-      getTax();
-    }
-    else if (window.render_line_items) {
-      render_line_items();
-    }
-  } */
-}
-

=== modified file 'shipping/uc_quote/uc_quote.module'
--- shipping/uc_quote/uc_quote.module	2010-05-20 19:31:35 +0000
+++ shipping/uc_quote/uc_quote.module	2010-06-03 15:57:46 +0000
@@ -102,6 +102,9 @@
     'uc_cart_pane_quotes' => array(
       'render element' => 'form',
     ),
+    'uc_quote_returned_rates' => array(
+      'render element' => 'form',
+    ),
   );
 }
 
@@ -268,10 +271,31 @@
     $form['shipping']['default_address']['postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $address->postal_code, FALSE, NULL, 10, 10);
     $form['shipping']['default_address']['country'] = uc_country_select(uc_get_field_name('country'), $address->country);
   }
-  // Add quote selection form handlers to the checkout form.
-  if ($form_id == 'uc_cart_checkout_form' && isset($form['panes']['quotes'])) {
-    $form['#validate'][] = 'uc_quote_save_choice';
-    $form['#pre_render'][] = 'uc_quote_cache_quotes';
+}
+
+function uc_quote_form_uc_cart_checkout_form_alter(&$form, &$form_state) {
+  $ajax = array(
+    'callback' => 'uc_quote_returned_rates',
+    'effect' => 'slide',
+    'progress' => array(
+      'type' => 'throbber',
+      'message' => t('Receiving shipping quotes...'),
+    ),
+  );
+
+  if (isset($form['panes']['delivery']['delivery_postal_code'])) {
+    $form['panes']['delivery']['delivery_postal_code']['#ajax'] = $ajax;
+  }
+  if (isset($form['panes']['delivery']['delivery_address_select'])) {
+    $form['panes']['delivery']['delivery_address_select']['#ajax'] = $ajax;
+  }
+  // @todo: Figure out what needs to be done when the copy-address box is checked.
+
+  if (isset($form['panes']['payment']['line_items'])) {
+    $form['panes']['quotes']['quotes']['quote_option']['#ajax'] = array(
+      'callback' => 'uc_payment_get_totals',
+      'wrapper' => 'line-items-div',
+    );
   }
 }
 
@@ -495,7 +519,7 @@
   }
   $messages = ob_get_contents();
   ob_end_clean();
-  //drupal_set_message('<pre>' . print_r($quote_data, TRUE) . '</pre>');
+
   if ($messages && variable_get('uc_quote_log_errors', FALSE)) {
     watchdog('quote', '!messages', array('!messages' => $messages), WATCHDOG_WARNING);
     watchdog('quote', '<pre>@data</pre>', array('@data' => print_r($quote_data, TRUE)), WATCHDOG_WARNING);
@@ -515,12 +539,18 @@
     if (!variable_get('uc_cap_quotes_enabled', FALSE) || (variable_get('uc_cart_delivery_not_shippable', TRUE) && !uc_cart_is_shippable())) {
       return array();
     }
-  }
+
+    $body = drupal_get_form('uc_cart_pane_quotes', $items);
+  }
+  else {
+    $body = '';
+  }
+
   $panes[] = array('id' => 'quotes',
     'title' => t('Shipping quotes'),
     'enabled' => FALSE,
     'weight' => 5,
-    'body' => drupal_get_form('uc_cart_pane_quotes', $items),
+    'body' => $body,
   );
 
   return $panes;
@@ -530,7 +560,8 @@
  * Define the shipping quote checkout pane.
  */
 function uc_quote_uc_checkout_pane() {
-  $panes[] = array('id' => 'quotes',
+  $panes[] = array(
+    'id' => 'quotes',
     'callback' => 'uc_checkout_pane_quotes',
     'title' => t('Calculate shipping cost'),
     'desc' => t('Extra information necessary to ship.'),
@@ -560,48 +591,31 @@
 }
 
 /**
- * Implement hook_uc_add_to_cart().
- */
-function uc_quote_uc_add_to_cart() {
-  unset($_SESSION['quote']);
-}
-
-/**
- * Implement hook_uc_update_cart_item().
- */
-function uc_quote_uc_update_cart_item() {
-  unset($_SESSION['quote']);
-}
-
-/**
  * Implement hook_uc_order().
  */
-function uc_quote_uc_order($op, &$arg1, $arg2) {
+function uc_quote_uc_order($op, &$order, $arg2) {
   switch ($op) {
-    case 'submit':
-      unset($_SESSION['quote']);
-    break;
     case 'save':
-      if (isset($arg1->quote['method'])) {
+      if (isset($order->quote['method'])) {
         db_merge('uc_order_quotes')
-          ->key(array('order_id' => $arg1->order_id))
+          ->key(array('order_id' => $order->order_id))
           ->fields(array(
-            'method' => $arg1->quote['method'],
-            'accessorials' => $arg1->quote['accessorials'],
-            'rate' => $arg1->quote['rate'],
-            'quote_form' => $arg1->quote['quote_form'],
+            'method' => $order->quote['method'],
+            'accessorials' => $order->quote['accessorials'],
+            'rate' => $order->quote['rate'],
+            'quote_form' => $order->quote['quote_form'],
           ))
           ->execute();
       }
     break;
     case 'load':
-      $quote = db_query("SELECT method, accessorials, rate, quote_form FROM {uc_order_quotes} WHERE order_id = :id", array(':id' => $arg1->order_id))->fetchAssoc();
-      $arg1->quote = $quote;
-      $arg1->quote['accessorials'] = strval($quote['accessorials']);
+      $quote = db_query("SELECT method, accessorials, rate, quote_form FROM {uc_order_quotes} WHERE order_id = :id", array(':id' => $order->order_id))->fetchAssoc();
+      $order->quote = $quote;
+      $order->quote['accessorials'] = strval($quote['accessorials']);
     break;
     case 'delete':
       db_delete('uc_order_quotes')
-        ->condition('order_id', $arg1->order_id)
+        ->condition('order_id', $order->order_id)
         ->execute();
     break;
   }
@@ -738,87 +752,53 @@
  */
 function uc_cart_pane_quotes($form, &$form_state, $items) {
   global $user;
-  // Get all quote types neccessary to fulfill order.
-  $shipping_types = array();
-  foreach ($items as $product) {
-    $shipping_types[] =  uc_product_get_shipping_type($product);
-  }
-  $shipping_types = array_unique($shipping_types);
-  $all_types = uc_quote_get_shipping_types();
-  $shipping_type = '';
-  $type_weight = 1000; // arbitrary large number
-  foreach ($shipping_types as $type) {
-    if ($all_types[$type]['weight'] < $type_weight) {
-      $shipping_type = $all_types[$type]['id'];
-      $type_weight = $all_types[$type]['weight'];
-    }
-  }
-  $methods = array_filter(module_invoke_all('uc_shipping_method'), '_uc_quote_method_enabled');
-  uasort($methods, '_uc_quote_type_sort');
-  $method_choices = array();
-  foreach ($methods as $method) {
-    if ($method['quote']['type'] == 'order' || $method['quote']['type'] == $shipping_type) {
-      $method_choices[$method['id']] = $method['title'];
-    }
-  }
-  $form['delivery_country'] = uc_country_select(uc_get_field_name('country'), uc_store_default_country(), NULL, 'name', TRUE);
+
+  $form['delivery_country'] = uc_country_select(uc_get_field_name('country'), isset($form_state['values']['delivery_country']) ? $form_state['values']['delivery_country'] : uc_store_default_country(), NULL, 'name', TRUE);
   $country_id = isset($_POST['delivery_country']) ? intval($_POST['delivery_country']) : uc_store_default_country();
-  $form['delivery_zone'] = uc_zone_select(uc_get_field_name('zone'), NULL, NULL, $country_id, 'name', TRUE);
-  $form['delivery_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), '', TRUE, NULL, 10, 10);
-  $form['quote_method'] = array(
-    '#type' => 'hidden',
-    '#value' => key($method_choices),
-  );
+  $form['delivery_zone'] = uc_zone_select(uc_get_field_name('zone'), isset($form_state['values']['delivery_zone']) ? $form_state['values']['delivery_zone'] : NULL, NULL, $country_id, 'name', TRUE);
+  $form['delivery_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), isset($form_state['values']['delivery_postal_code']) ? $form_state['values']['delivery_postal_code'] : '', TRUE, NULL, 10, 10);
   $form['get_quote'] = array(
     '#type' => 'button',
     '#value' => t('Calculate'),
+    '#ajax' => array(
+      'callback' => 'uc_quote_cart_returned_rates',
+      'wrapper' => 'quote',
+    ),
   );
   $form['page'] = array(
     '#type' => 'hidden',
     '#value' => 'cart',
   );
-  $form['uid'] = array(
-    '#type' => 'hidden',
-    '#value' => $user->uid,
-  );
+
+  $order = new UcOrder();
+  $order->uid = $user->uid;
+  $order->delivery_country = $form['delivery_country']['#default_value'];
+  $order->delivery_zone = $form['delivery_zone']['#default_value'];
+  $order->delivery_postal_code = $form['delivery_postal_code']['#default_value'];
+  $order->products = $items;
+
+  module_load_include('inc', 'uc_quote', 'uc_quote.pages');
+  $quotes = uc_quote_assemble_quotes($order);
+
+  if (!empty($quotes)) {
+    foreach ($quotes as $method => $data) {
+      foreach ($data as $accessorial => $quote) {
+        $key = $method . '---' . $accessorial;
+
+        if (isset($quote['rate'])) {
+          $quote_options[$key] = t('!label: !price', array('!label' => $quote['option_label'], '!price' => $quote['format']));
+        }
+      }
+    }
+  }
+
   $form['quote'] = array(
-    '#markup' => '<div id="quote"></div>',
+    '#theme' => 'item_list',
+    '#items' => $quote_options,
+    '#prefix' => '<div id="quote"><div class="solid-border">',
+    '#suffix' => '</div></div>',
   );
 
-  drupal_add_js(array(
-    'uc_quote' => array(
-      'progress_msg' => t('Receiving quotes:'),
-      'err_msg' => check_markup(variable_get('uc_quote_err_msg', t("There were problems getting a shipping quote. Please verify the delivery and product information and try again.\nIf this does not resolve the issue, please call in to complete your order.")), variable_get('uc_quote_msg_format', filter_default_format())),
-    ),
-    'ucURL' => array(
-      'shippingQuotes' => url('cart/checkout/shipping/quote'),
-    ),
-  ), 'setting');
-  drupal_add_js('misc/progress.js');
-  drupal_add_js(drupal_get_path('module', 'uc_quote') . '/uc_quote.js');
-  $prod_string = '';
-  foreach (uc_cart_get_contents() as $item) {
-    $prod_string .= '|' . $item->nid;
-    $prod_string .= '^' . $item->title;
-    $prod_string .= '^' . $item->model;
-    $prod_string .= '^' . $item->manufacturer;
-    $prod_string .= '^' . $item->qty;
-    $prod_string .= '^' . $item->cost;
-    $prod_string .= '^' . $item->price;
-    $prod_string .= '^' . $item->weight;
-    $prod_string .= '^' . serialize($item->data);
-  }
-  $prod_string = substr($prod_string, 1);
-  // If a previous quote gets loaded, make sure it gets saved again.
-  // Also, make sure the previously checked option is checked by default.
-  drupal_add_js('jQuery(function() {
-    setQuoteCallbacks("' . drupal_encode_path($prod_string) . '");
-    jQuery("#uc-cart-pane-quotes").submit(function() {
-      quoteCallback("' . drupal_encode_path($prod_string) . '");
-      return false;
-    });
-  })', 'inline');
-
   return $form;
 }
 
@@ -851,8 +831,9 @@
  *
  * Adds a line item to the order that records the chosen shipping quote.
  */
-function uc_checkout_pane_quotes($op, &$arg1, $arg2) {
+function uc_checkout_pane_quotes($op, &$order, $form = NULL, &$form_state = NULL) {
   global $user;
+
   switch ($op) {
     case 'view':
       $description = check_markup(variable_get('uc_quote_pane_description', t('Shipping quotes are generated automatically when you enter your address and may be updated manually with the button below.')), variable_get('uc_quote_desc_format', filter_default_format()));
@@ -870,70 +851,50 @@
         '#type' => 'button',
         '#value' => t('Click to calculate shipping'),
         '#weight' => 0,
-      );
-
-      drupal_add_js(array(
-        'uc_quote' => array(
-          'progress_msg' => t('Receiving quotes...'),
-          'err_msg' => check_markup(variable_get('uc_quote_err_msg', t("There were problems getting a shipping quote. Please verify the delivery address and product information and try again.\nIf this does not resolve the issue, please call @phone to complete your order.", array('@phone' => variable_get('uc_store_phone', NULL)))), variable_get('uc_quote_msg_format', filter_default_format())),
-        ),
-        'ucURL' => array(
-          'shippingQuotes' => url('cart/checkout/shipping/quote'),
-        ),
-      ), 'setting');
-      drupal_add_js('misc/progress.js');
-      drupal_add_js(drupal_get_path('module', 'uc_quote') . '/uc_quote.js');
-
-      if (!empty($arg1->quote)) {
-        $default = $arg1->quote['method'] . '---' . ($arg1->quote['accessorials'] ? $arg1->quote['accessorials'] : 0);
-      }
-      else {
-        $default = '---';
-      }
-
-      $prod_string = '';
-      foreach (uc_cart_get_contents() as $item) {
-        $prod_string .= '|' . $item->nid;
-        $prod_string .= '^' . $item->title;
-        $prod_string .= '^' . $item->model;
-        $prod_string .= '^' . $item->qty;
-        $prod_string .= '^' . $item->cost;
-        $prod_string .= '^' . $item->price;
-        $prod_string .= '^' . $item->weight;
-        $prod_string .= '^' . serialize($item->data);
-      }
-      $prod_string = substr($prod_string, 1);
-      // If a previous quote gets loaded, make sure it gets saved again.
-      // Also, make sure the previously checked option is checked by default.
-      drupal_add_js('
-        Drupal.behaviors.getQuotes = {
-          attach: function (context) {
-            setQuoteCallbacks("' . drupal_encode_path($prod_string) . '", context);
-          }
-        };
-        jQuery(function() {
-        var quoteButton = jQuery("input:radio[name=quote-option]").click(function() {
-          var quoteButton = jQuery(this);
-          var label = quoteButton.parent("label").text().split(":", 2)[0];
-          var rate = jQuery("input:hidden[name=\'rate[" + quoteButton.val() + "]\']").val();
-          set_line_item("shipping", label, rate, 1, 1, false);
-          if (window.getTax) {
-            getTax();
-          }
-          else if (window.render_line_items) {
-            render_line_items();
-          }
-        }).filter("[value=' . $default . ']").click();
-        var quoteDiv = jQuery("#quote");
-        if (quoteDiv.length && jQuery("#quote input[name=quote-form]").length == 0) {
-          quoteDiv.append("<input type=\"hidden\" name=\"quote-form\" value=\"" + Drupal.encodePath(quoteDiv.html()) + "\" />");
-        }
-      });', 'inline');
+        '#ajax' => array(
+          'callback' => 'uc_quote_checkout_returned_rates',
+          'effect' => 'slide',
+          'progress' => array(
+            'type' => 'bar',
+            'message' => t('Receiving quotes...'),
+          ),
+        ),
+      );
+      $contents['quotes'] = array(
+        '#tree' => TRUE,
+        '#prefix' => '<div id="quote">',
+        '#suffix' => '</div>',
+        '#weight' => 1,
+      );
+
+      $contents['quotes'] += uc_quote_build_quote_form($order);
 
       return array('description' => $description, 'contents' => $contents);
 
     case 'process':
-      if (!isset($_POST['quote-option'])) {
+      if (!isset($form_state['values']['panes']['quotes']['quotes']['quote_option'])) {
+        // Get first returned quote as a default value.
+        module_load_include('inc', 'uc_quote', 'uc_quote.pages');
+
+        $quotes = uc_quote_assemble_quotes($order);
+
+        $quote_options = array();
+        if ($quotes) {
+          foreach ($quotes as $method => $data) {
+            foreach ($data as $accessorial => $quote) {
+              $key = $method . '---' . $accessorial;
+              if (isset($quote['rate'])) {
+                $form_state['values']['panes']['quotes']['quotes']['quote_option'] = $key;
+                $form_state['values']['panes']['quotes']['quotes'][$key]['rate'] = $quote['rate'];
+
+                break 2;
+              }
+            }
+          }
+        }
+      }
+
+      if (!isset($form_state['values']['panes']['quotes']['quotes']['quote_option'])) {
         if (variable_get('uc_quote_require_quote', TRUE)) {
           drupal_set_message(t('You must select a shipping option before continuing.'), 'error');
           return FALSE;
@@ -942,84 +903,46 @@
           return TRUE;
         }
       }
-      $details = array();
-      foreach ($arg1 as $key => $value) {
-        if (strpos($key, 'delivery_') !== FALSE) {
-          $details[substr($key, 9)] = $value;
-        }
-      }
-      $products = array();
-      foreach ($arg1->products as $id => $product) {
-        $node = (array)node_load($product->nid);
-        foreach ($node as $key => $value) {
-          if (!isset($product->$key)) {
-            $product->$key = $value;
-          }
-        }
-        $arg1->products[$id] = $product;
-      }
-      $quote_option = explode('---', $_POST['quote-option']);
-      $arg1->quote['method'] = $quote_option[0];
-      $arg1->quote['accessorials'] = $quote_option[1];
-      $_SESSION['quote']['quote_form'] = rawurldecode($_POST['quote-form']);
+
+      $quote_option = explode('---', $form_state['values']['panes']['quotes']['quotes']['quote_option']);
+      $order->quote['method'] = $quote_option[0];
+      $order->quote['accessorials'] = $quote_option[1];
       $methods = array_filter(module_invoke_all('uc_shipping_method'), '_uc_quote_method_enabled');
       $method = $methods[$quote_option[0]];
-      $quote_data = array();
-
-      $arguments = array(
-        'order' => array(
-          '#entity' => 'uc_order',
-          '#title' => t('Order'),
-          '#data' => $arg1,
-        ),
-        'method' => array(
-          '#entity' => 'quote_method',
-          '#title' => t('Quote method'),
-          '#data' => $method,
-        ),
-        'account' => array(
-          '#entity' => 'user',
-          '#title' => t('User'),
-          '#data' => $user,
-        ),
-      );
-
-      $predicates = ca_load_trigger_predicates('get_quote_from_' . $method['id']);
-      $predicate = array_shift($predicates);
-      if ($predicate && ca_evaluate_conditions($predicate, $arguments)) {
-        $quote_data = uc_quote_action_get_quote($arg1, $method, $user);
-      }
-
-      if (!isset($quote_data[$quote_option[1]])) {
-        drupal_set_message(t('Invalid option selected. Recalculate shipping quotes to continue.'), 'error');
-        return FALSE;
-      }
 
       $label = $method['quote']['accessorials'][$quote_option[1]];
-      $arg1->quote['rate'] = $quote_data[$quote_option[1]]['rate'];
-
-      $result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", array(':id' => $arg1->order_id, ':type' => 'shipping'));
+
+      $quote_option = $form_state['values']['panes']['quotes']['quotes']['quote_option'];
+      $order->quote['rate'] = $form_state['values']['panes']['quotes']['quotes'][$quote_option]['rate'];
+
+      $result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", array(':id' => $order->order_id, ':type' => 'shipping'));
       if ($lid = $result->fetchField()) {
         uc_order_update_line_item($lid,
           $label,
-          $arg1->quote['rate']
+          $order->quote['rate']
         );
       }
       else {
-        uc_order_line_item_add($arg1->order_id, 'shipping',
+        uc_order_line_item_add($order->order_id, 'shipping',
           $label,
-          $arg1->quote['rate']
+          $order->quote['rate']
         );
       }
 
+      // Update line items.
+      $order->line_items = uc_order_load_line_items($order, TRUE);
+      // Update calculated line items.
+      $order->line_items = array_merge($order->line_items, uc_order_load_line_items($order, FALSE));
+      usort($order->line_items, 'uc_weight_sort');
+
       return TRUE;
     case 'review':
       $context = array(
         'revision' => 'themed',
         'type' => 'line_item',
-        'subject' => array('order' => $arg1),
+        'subject' => array('order' => $order),
       );
-      $result = db_query("SELECT * FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", array(':id' => $arg1->order_id, ':type' => 'shipping'));
+      $result = db_query("SELECT * FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", array(':id' => $order->order_id, ':type' => 'shipping'));
       if ($line_item = $result->fetchAssoc()) {
         $context['subject']['line_item'] = $line_item;
         $review[] = array('title' => $line_item['title'], 'data' => uc_price($line_item['amount'], $context));
@@ -1032,7 +955,7 @@
 /**
  * Shipping quote order pane callback.
  */
-function uc_order_pane_quotes($op, $arg1) {
+function uc_order_pane_quotes($op, $order, $form = NULL, &$form_state = NULL) {
   switch ($op) {
     case 'edit-form':
       // Let Javascript know where we are.
@@ -1043,183 +966,220 @@
       $form['quotes']['quote_button'] = array(
         '#type' => 'submit',
         '#value' => t('Get shipping quotes'),
+        '#submit' => array('uc_quote_order_pane_quotes_submit'),
+        '#ajax' => array(
+          'callback' => 'uc_quote_order_returned_rates',
+          'effect' => 'slide',
+          'progress' => array(
+            'type' => 'bar',
+            'message' => t('Receiving quotes...'),
+          ),
+        ),
       );
       $form['quotes']['add_quote'] = array(
         '#type' => 'submit',
         '#value' => t('Apply to order'),
         '#attributes' => array('class' => array('save-button')),
         '#disabled' => TRUE,
-      );
-
-      $form['quotes']['quote'] = array(
-        '#markup' => '<div id="quote"></div>',
-      );
-
-      drupal_add_js(array(
-        'uc_quote' => array(
-          'progress_msg' => t('Receiving quotes...'),
-          'err_msg' => check_markup(variable_get('uc_quote_err_msg', t("There were problems getting a shipping quote. Please verify the delivery and product information and try again.\nIf this does not resolve the issue, please call in to complete your order.")), variable_get('uc_quote_msg_format', filter_default_format())),
-        ),
-        'ucURL' => array(
-          'shippingQuotes' => url('cart/checkout/shipping/quote'),
-        ),
-      ), 'setting');
-
-      drupal_add_js('misc/progress.js');
-      drupal_add_js(drupal_get_path('module', 'uc_quote') . '/uc_quote.js');
-
-      $default = $arg1->quote['accessorials'] ? $arg1->quote['accessorials'] : 0;
-      // If a previous quote gets loaded, make sure it gets saved again.
-      // Also, make sure the previously checked option is checked by default.
-      drupal_add_js('jQuery(function() {
-        setQuoteCallbacks();
-        jQuery("input:radio[name=quote-option]").filter("[value=' . $default . ']").attr("checked", "checked");
-        var quoteDiv = jQuery("#quote");
-        if (quoteDiv.length && jQuery("#quote input[name=quote-form]").length == 0) {
-          quoteDiv.append("<input type=\"hidden\" name=\"quote-form\" value=\"" + Drupal.encodePath(quoteDiv.html()) + "\" />");
-        }
-      })', 'inline');
+        '#submit' => array('uc_quote_apply_quote_to_order'),
+      );
+
+      $form['quotes']['quotes'] = array(
+        '#tree' => TRUE,
+        '#prefix' => '<div id="quote">',
+        '#suffix' => '</div>',
+      );
+
+      if (isset($form_state['quote_requested']) && $form_state['quote_requested'] == TRUE) {
+        $form['quotes']['quotes'] += uc_quote_build_quote_form($order);
+      }
+
       return $form;
+
     case 'edit-theme':
-      return drupal_render($arg1['quotes']);
-    case 'edit-process':
-      //drupal_set_message('<pre>' . print_r($_POST, TRUE) . '</pre>');
-      if (isset($_POST['quote-option'])) {
-        list($changes['quote']['method'], $changes['quote']['accessorials']) = explode('---', $_POST['quote-option']);
-      }
-      $changes['quote']['rate'] = $_POST['rate'][$_POST['quote-option']];
-      $changes['quote']['quote_form'] = rawurldecode($_POST['quote-form']);
-      return $changes;
-    case 'edit-ops':
-      return array(t('Apply to order'));
-    case t('Apply to order'):
-      if (isset($_POST['quote-option'])) {
-        if ($order = uc_order_load($arg1['order_id'])) {
-          $user = user_load($order->uid);
-          $products = array();
-          foreach ($order->products as $product) {
-            if ($product->nid) {
-              $node = (array)node_load($product->nid);
-              foreach ($node as $key => $value) {
-                if (!isset($product->$key)) {
-                  $product->$key = $value;
-                }
-              }
-            }
-            $products[] = $product;
-          }
-
-          //drupal_set_message('<pre>' . print_r($order, TRUE) . '</pre>');
-          $quote_option = explode('---', $_POST['quote-option']);
-          $order->quote['method'] = $quote_option[0];
-          $order->quote['accessorials'] = $quote_option[1];
-          $order->quote['quote_form'] = rawurldecode($_POST['quote-form']);
-          $methods = array_filter(module_invoke_all('uc_shipping_method'), '_uc_quote_method_enabled');
-          $method = $methods[$quote_option[0]];
-          $quote_data = array();
-
-          $predicate = ca_load_trigger_predicates('get_quote_from_' . $method['id']);
-          $arguments = array(
-            'order' => array(
-              '#entity' => 'uc_order',
-              '#title' => t('Order'),
-              '#data' => $arg1,
-            ),
-            'method' => array(
-              '#entity' => 'quote_method',
-              '#title' => t('Quote method'),
-              '#data' => $method,
-            ),
-            'account' => array(
-              '#entity' => 'user',
-              '#title' => t('User'),
-              '#data' => $user,
-            ),
-          );
-          if (ca_evaluate_conditions($predicate, $arguments)) {
-            $quote_data = uc_quote_action_get_quote($order, $method, $user);
-          }
-
-          //drupal_set_message('Chosen quote method:<pre>' . print_r($method, TRUE) . '</pre>');
-          //drupal_set_message('Chosen quote data:<pre>' . print_r($quote_data, TRUE) . '</pre>');
-          if (!isset($quote_data[$quote_option[1]])) {
-            drupal_set_message(t('Invalid option selected. Recalculate shipping quotes to continue.'), 'error');
-            break;
-          }
-          $label = $method['quote']['accessorials'][$quote_option[1]];
-          $order->quote['rate'] = $quote_data[$quote_option[1]]['rate'];
-          $result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", array(':id' => $arg1['order_id'], ':type' => 'shipping'));
-          if ($lid = $result->fetchField()) {
-            uc_order_update_line_item($lid,
-              $label,
-              $order->quote['rate']
-            );
-          }
-          else {
-            uc_order_line_item_add($order->order_id, 'shipping',
-              $label,
-              $order->quote['rate']
-            );
-          }
-        }
-      }
-    break;
-  }
-}
-
-/**
- * Validate handler added to uc_cart_checkout_form().
- *
- * Save the choice of shipping method in the customer's session.
- */
-function uc_quote_save_choice($form, &$form_state) {
-  $quote_option = explode('---', $_POST['quote-option']);
-  $_SESSION['quote'] = array('method' => $quote_option[0],
-    'accessorials' => $quote_option[1],
-    'rate' => $_POST['rate'][$_POST['quote-option']],
-    'quote_form' => $_POST['quote-form'],
-  );
-}
-
-/**
- * Pre-render callback added to uc_cart_checkout_form().
- *
- * Render the shipping quotes without an asynchronous call to create them if a
- * choice had been cached in the session.
- */
-function uc_quote_cache_quotes($form) {
-  if ($form['#id'] == 'uc-cart-checkout-form') {
-    if (isset($_SESSION['quote']) && isset($_SESSION['quote']['rate'])) {
-      $quote = $_SESSION['quote'];
-        $form['panes']['quotes']['quote'] = array(
-          '#markup' => '<div id="quote" class="solid-border">' . rawurldecode($_SESSION['quote']['quote_form']) . '</div>',
-          '#weight' => 1,
-        );
-        $methods = module_invoke_all('uc_shipping_method');
-        $method = $methods[$quote['method']];
-
-        drupal_add_js('jQuery(document).ready(function() {
-          jQuery("#quote").find("input:radio[value=' . $quote['method'] . '---' . $quote['accessorials'] . ']").eq(0).change().attr("checked", "checked");
-          if (window.set_line_item) {
-            set_line_item("shipping", "' . $method['quote']['accessorials'][$quote['accessorials']] . '", ' . $quote['rate'] . ', 1, 1, false);
-          }
-          if (window.getTax) {
-            getTax();
-            setTaxCallbacks();
-          }
-          else if (window.render_line_items) {
-            render_line_items();
-          }
-        });', 'inline');
-    }
-    else {
-      $form['panes']['quotes']['quote'] = array(
-        '#markup' => '<div id="quote"></div>',
-        '#weight' => 1,
-      );
-    }
-  }
-  return $form;
+      return drupal_render($order['quotes']);
+  }
+}
+
+function uc_quote_order_pane_quotes_submit($form, &$form_state) {
+  $form_state['quote_requested'] = ($form_state['triggering_element']['#value'] == $form['quotes']['quote_button']['#value']);
+}
+
+function uc_quote_apply_quote_to_order($form, &$form_state) {
+  if (isset($form_state['values']['quotes']['quote_option'])) {
+    if ($order = $form_state['build_info']['args'][0]) {
+      $user = user_load($order->uid);
+
+      $quote_option = explode('---', $form_state['values']['quotes']['quote_option']);
+      $order->quote['method'] = $quote_option[0];
+      $order->quote['accessorials'] = $quote_option[1];
+      $methods = array_filter(module_invoke_all('uc_shipping_method'), '_uc_quote_method_enabled');
+      $method = $methods[$quote_option[0]];
+
+      $label = $method['quote']['accessorials'][$quote_option[1]];
+
+      $quote_option = $form_state['values']['quotes']['quote_option'];
+      $order->quote['rate'] = $form_state['values']['quotes'][$quote_option]['rate'];
+
+      $result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", array(':id' => $order->order_id, ':type' => 'shipping'));
+      if ($lid = $result->fetchField()) {
+        uc_order_update_line_item($lid,
+          $label,
+          $order->quote['rate']
+        );
+      }
+      else {
+        uc_order_line_item_add($order->order_id, 'shipping',
+          $label,
+          $order->quote['rate']
+        );
+      }
+
+      // Update line items.
+      $order->line_items = uc_order_load_line_items($order, TRUE);
+      // Update calculated line items.
+      $order->line_items = array_merge($order->line_items, uc_order_load_line_items($order, FALSE));
+      usort($order->line_items, 'uc_weight_sort');
+    }
+  }
+}
+
+function uc_quote_build_quote_form($order) {
+  $return = array();
+
+  module_load_include('inc', 'uc_quote', 'uc_quote.pages');
+  $quotes = uc_quote_assemble_quotes($order);
+
+  if (!empty($quotes)) {
+    foreach ($quotes as $method => $data) {
+      foreach ($data as $accessorial => $quote) {
+        $key = $method . '---' . $accessorial;
+
+        if (isset($quote['rate'])) {
+          $quote_options[$key] = t('!label: !price', array('!label' => $quote['option_label'], '!price' => $quote['format']));
+          $return[$key]['rate'] = array(
+            '#type' => 'hidden',
+            '#value' => $quote['rate'],
+          );
+        }
+
+        if (!empty($quote['error'])) {
+          $return[$key]['error'] = array(
+            '#markup' => '<div class="quote-error">' . $quote['error'] . '</div>',
+          );
+        }
+
+        if (!empty($quote['notes'])) {
+          $return[$key]['notes'] = array(
+            '#markup' => '<div class="quote-notes">' . $quote['notes'] . '</div>',
+          );
+        }
+
+        if (!empty($quote['debug'])) {
+          $return[$key]['debug'] = array(
+            '#markup' => '<pre>' . $quote['debug'] . '</pre>',
+          );
+        }
+
+        if (!isset($quote['rate']) && count($return[$key])) {
+          $return[$key]['#prefix'] = $quote['label'] . ': ';
+        }
+      }
+    }
+  }
+
+  $num_quotes = count($quote_options);
+  $default = key($quote_options);
+  if ($num_quotes > 1) {
+    if (isset($order->quote['method']) && isset($order->quote['accessorials'])) {
+      $default = $order->quote['method'] . '---' . $order->quote['accessorials'];
+    }
+
+    $return['quote_option'] = array(
+      '#type' => 'radios',
+      '#options' => $quote_options,
+      '#default_value' => $default,
+    );
+  }
+  elseif ($num_quotes == 1) {
+    $return['quote_option'] = array(
+      '#type' => 'hidden',
+      '#value' => $default,
+      '#suffix' => $quote_options[$default],
+    );
+  }
+  else {
+    $return['error'] = array(
+      '#markup' => check_markup(variable_get('uc_quote_err_msg', t("There were problems getting a shipping quote. Please verify the delivery address and product information and try again.\nIf this does not resolve the issue, please call @phone to complete your order.", array('@phone' => variable_get('uc_store_phone', NULL)))), variable_get('uc_quote_msg_format', filter_default_format())),
+    );
+  }
+
+  $return['#theme'] = 'uc_quote_returned_rates';
+
+  return $return;
+}
+
+function uc_quote_cart_returned_rates($form, $form_state) {
+  $commands[] = ajax_command_replace('#quote', drupal_render($form['quote']));
+  $commands[] = ajax_command_prepend('#quote', theme('status_messages'));
+
+  return array('#type' => 'ajax', '#commands' => $commands);
+}
+
+/**
+ * AJAX callback for calculated shipping rates.
+ */
+function uc_quote_checkout_returned_rates($form, $form_state) {
+  $commands[] = ajax_command_replace('#quote', drupal_render($form['panes']['quotes']['quotes']));
+  $commands[] = ajax_command_prepend('#quote', theme('status_messages'));
+
+  // Show default shipping rate as a line item.
+  if (isset($form['panes']['payment']['line_items'])) {
+    $commands[] = ajax_command_replace('#line-items-div', drupal_render($form['panes']['payment']['line_items']));
+    $commands[] = ajax_command_prepend('#line-items-div', theme('status_messages'));
+  }
+
+  return array('#type' => 'ajax', '#commands' => $commands);
+}
+
+/**
+ * AJAX callback for calculated shipping rates.
+ */
+function uc_quote_order_returned_rates($form, $form_state) {
+  $commands[] = ajax_command_replace('#quote', drupal_render($form['quotes']['quotes']));
+  $commands[] = ajax_command_prepend('#quote', theme('status_messages'));
+
+  return array('#type' => 'ajax', '#commands' => $commands);
+}
+
+/**
+ * Display the returned shipping rates.
+ *
+ * @ingroup themeable
+ */
+function theme_uc_quote_returned_rates($variables) {
+  $form = $variables['form'];
+  $output = '';
+
+  $keys = element_children($form);
+
+  // Render notes and error messages after each radio button.
+  if (count($keys) > 1) {
+    foreach ($keys as $key) {
+      if ($key == 'quote_option') {
+        continue;
+      }
+
+      if (isset($form['quote_option'][$key])) {
+        $output .= drupal_render($form['quote_option'][$key]);
+      }
+      $output .= drupal_render($form[$key]);
+    }
+  }
+
+  $output .= drupal_render_children($form);
+
+  return '<div class="solid-border">' . $output . '</div>';
 }
 
 /**

=== modified file 'shipping/uc_quote/uc_quote.pages.inc'
--- shipping/uc_quote/uc_quote.pages.inc	2010-03-23 20:16:16 +0000
+++ shipping/uc_quote/uc_quote.pages.inc	2010-06-03 15:57:46 +0000
@@ -6,15 +6,34 @@
  * Menu callbacks for shipping quotes requested through AJAX.
  */
 
+function uc_quote_checkout_request_quotes($form, &$form_state) {
+  global $user;
+
+  $order = $form_state['storage']['order'];
+
+  // Build address info from form values.
+  $matches = array();
+  foreach ($form_state['values'] as $key => $value) {
+    if (preg_match('/^(delivery|billing)_/', $key, $matches)) {
+      // Set $order->delivery['first_name'], etc.
+      $order->{$matches[1]}[substr($key, strlen($matches[0]))] = $value;
+    }
+  }
+
+  // Consider the total to be from products only, because line items are
+  // mostly non-existent at this point.
+  // @todo: Get line item information from $form_state.
+  $order->order_total = uc_order_get_total($order, TRUE);
+  // Get all quote types neccessary to fulfill order.
+  $quote_data = _uc_quote_assemble_quotes($order);
+
+  $form_state['storage']['quotes'] = $quote_data;
+}
+
 /**
  * Callback to return the shipping quote(s) of the appropriate quoting method(s).
  */
-function uc_quote_request_quotes() {
-
-  /* print '<pre>';
-  print_r($_POST);
-  print '</pre>'; */
-
+function uc_quote_request_quotes($form, &$form_state) {
   $products = array();
   foreach (explode('|', urldecode($_POST['products'])) as $item) {
     $props = explode('^', $item);
@@ -59,8 +78,6 @@
   $fake_order->order_total = uc_order_get_total($fake_order, TRUE);
   // Get all quote types neccessary to fulfill order.
   $quote_data = _uc_quote_assemble_quotes($fake_order);
-  //drupal_set_message('<pre>' . print_r($methods, TRUE) . '</pre>');
-  //drupal_set_message('<pre>' . print_r($quote_data, TRUE) . '</pre>');
   $return_quotes = array();
   foreach ($quote_data as $method_id => $options) {
     foreach ($options as $accsrl => $data) {
@@ -73,10 +90,10 @@
 /**
  * Pull the get_quote_from_* triggers and assemble their returned data.
  */
-function _uc_quote_assemble_quotes($order) {
+function uc_quote_assemble_quotes($order) {
   global $user;
-  $account = user_load($order->uid);
-  if (!$account) {
+
+  if (!$order->uid || !($account = user_load($order->uid))) {
     $account = $user;
   }
 
@@ -115,7 +132,6 @@
     ),
   );
 
-  //drupal_set_message('<pre>' . print_r($products, TRUE) . '</pre>');
   $quote_data = array();
   $arguments = array(
     'order' => array(

=== modified file 'shipping/uc_shipping/uc_shipping.admin.inc'
--- shipping/uc_shipping/uc_shipping.admin.inc	2010-04-07 21:11:20 +0000
+++ shipping/uc_shipping/uc_shipping.admin.inc	2010-06-03 15:57:46 +0000
@@ -290,7 +290,7 @@
 
   $result = db_query("SELECT order_product_id, SUM(qty) AS quantity FROM {uc_packaged_products} AS pp LEFT JOIN {uc_packages} AS p ON pp.package_id = p.package_id WHERE p.order_id = :id GROUP BY order_product_id", array(':id' => $order->order_id));
   foreach ($result as $packaged_product) {
-    //Make already packaged products unavailable, except those in this package.
+    // Make already packaged products unavailable, except those in this package.
     $products[$packaged_product->order_product_id]->qty = $products[$packaged_product->order_product_id]->qty - $packaged_product->quantity + $package->products[$packaged_product->order_product_id]->qty;
   }
 
@@ -579,7 +579,6 @@
       '#value' => t('Ship packages'),
     );
   }
-  //drupal_set_message('<pre>' . print_r($form, TRUE) . '</pre>');
   return $form;
 }
 
@@ -610,7 +609,6 @@
         '#rows' => $rows,
       );
     }
-    //$output .= drupal_render($form[$shipping_type]['methods']);
   }
 
   $output .= drupal_render_children($form);
@@ -1005,9 +1003,6 @@
     }
   }
 
-  //$output .= dpr($order, TRUE, 'order');
-  //$output .= dpr($shipment, TRUE, 'shipment');
-
   $output .= '</body></html>';
 
   print $output;

=== modified file 'shipping/uc_shipping/uc_shipping.module'
--- shipping/uc_shipping/uc_shipping.module	2010-05-20 19:31:35 +0000
+++ shipping/uc_shipping/uc_shipping.module	2010-06-03 15:57:46 +0000
@@ -664,12 +664,12 @@
  *
  * @see uc_shipping_uc_order_pane()
  */
-function uc_shipping_order_pane_packages($op, $arg1) {
+function uc_shipping_order_pane_packages($op, $order) {
   switch ($op) {
     case 'view':
     case 'customer':
       $tracking = array();
-      $result = db_query("SELECT sid FROM {uc_shipments} WHERE order_id = :id", array(':id' => $arg1->order_id));
+      $result = db_query("SELECT sid FROM {uc_shipments} WHERE order_id = :id", array(':id' => $order->order_id));
       foreach ($result as $shipment) {
         $shipment = uc_shipping_shipment_load($shipment->sid);
         if ($shipment->tracking_number) {

=== modified file 'shipping/uc_ups/uc_ups.admin.inc'
--- shipping/uc_ups/uc_ups.admin.inc	2010-05-18 20:14:02 +0000
+++ shipping/uc_ups/uc_ups.admin.inc	2010-06-03 15:57:46 +0000
@@ -340,7 +340,6 @@
   <ShipmentDigest>" . $digest . "</ShipmentDigest>
 </ShipmentAcceptRequest>";
 
-  //drupal_set_message('<pre>' . htmlentities($schema) . '</pre>');
   return $schema;
 }
 

=== modified file 'shipping/uc_ups/uc_ups.module'
--- shipping/uc_ups/uc_ups.module	2010-05-20 19:31:35 +0000
+++ shipping/uc_ups/uc_ups.module	2010-06-03 15:57:46 +0000
@@ -408,7 +408,6 @@
       $package_schema .= "<Package>";
         $package_schema .= "<PackagingType>";
           $package_schema .= "<Code>" . $package_type['code'] . "</Code>";
-          //$package_schema .= "<Description>" . $package_type['description'] . "</Description>";
         $package_schema .= "</PackagingType>";
         if ($package->pkg_type == '02' && $package->length && $package->width && $package->height) {
           if ($package->length < $package->width) {
@@ -867,7 +866,7 @@
         'data' => $request,
       ));
       if (user_access('configure quotes') && variable_get('uc_quote_display_debug', FALSE)) {
-        $quotes[$ups_service]['debug'] .= /* '<pre>' . print_r($ship_packages, TRUE) . '</pre>' . */ htmlentities($request) . ' <br /><br /> ' . htmlentities($resp->data);
+        $quotes[$ups_service]['debug'] .= htmlentities($request) . ' <br /><br /> ' . htmlentities($resp->data);
       }
       $response = new SimpleXMLElement($resp->data);
       if (isset($response->Response->Error)) {
@@ -1139,17 +1138,14 @@
   $_SESSION['ups']['order_id'] = $form_state['values']['order_id'];
 
   $request = uc_ups_shipment_request($_SESSION['ups']['packages'], $origin, $destination, $form_state['values']['service']);
-  //print htmlentities($request);
   $response_obj = drupal_http_request(variable_get('uc_ups_connection_address', 'https://wwwcie.ups.com/ups.app/xml/') . 'ShipConfirm', array(
     'method' => 'POST',
     'data' => $request,
   ));
   $response = new SimpleXMLElement($response_obj->data);
-  //drupal_set_message('<pre>' . htmlentities($response->asXML()) . '</pre>');
   if (isset($response->Response->Error)) {
     $error = $response->Response->Error;
     $error_msg = (string)$error->ErrorSeverity . ' Error ' . (string)$error->ErrorCode . ': ' . (string)$error->ErrorDescription;
-    //drupal_set_message('<pre>' . print_r($_SESSION['ups']['packages'], TRUE) . '</pre>' . htmlentities($request) . ' <br /><br /> ' . htmlentities($response->data));
     if (strpos((string)$error->ErrorSeverity, 'Hard') !== FALSE) {
       form_set_error('', $error_msg);
       return FALSE;

=== modified file 'shipping/uc_usps/uc_usps.module'
--- shipping/uc_usps/uc_usps.module	2010-05-20 19:31:35 +0000
+++ shipping/uc_usps/uc_usps.module	2010-06-03 15:57:46 +0000
@@ -400,8 +400,6 @@
  *   JSON object containing rate, error, and debugging information.
  */
 function uc_usps_quote($products, $details, $method) {
-  //drupal_set_message('<pre>' . print_r($products, TRUE) . '</pre>');
-  //drupal_set_message('<pre>' . print_r($details, TRUE) . '</pre>');
   $services = array();
   $addresses = array(variable_get('uc_quote_store_default_address', new UcAddress()));
   $packages = _uc_usps_package_products($products, $addresses);

=== modified file 'uc_attribute/uc_attribute.admin.inc'
--- uc_attribute/uc_attribute.admin.inc	2010-04-12 14:55:54 +0000
+++ uc_attribute/uc_attribute.admin.inc	2010-06-03 15:57:46 +0000
@@ -972,8 +972,7 @@
       $form['attributes'][$aid]['default'] = array(
         '#type' => 'radios',
         '#options' => $options,
-        '#default_value' => /* $attribute->required ? NULL : */ $attribute->default_option,
-        //'#disabled' => $attribute->required,
+        '#default_value' => $attribute->default_option,
       );
     }
     else {
@@ -1200,7 +1199,7 @@
   drupal_set_title($node->title);
   $nid = $node->nid;
 
-  //Populate table and such.
+  // Populate table and such.
   $model = $node->model;
   $query_select = "SELECT DISTINCT";
   $query_from = " FROM";
@@ -1236,7 +1235,7 @@
   $num_prod_attr = count($attribute_ids);
 
   if ($num_prod_attr) {
-    //Get previous values
+    // Get previous values
     $old_vals = db_query("SELECT * FROM {uc_product_adjustments} WHERE nid = :nid", array(':nid' => $nid))->fetchAll();
 
     $result = $query->execute();

=== modified file 'uc_cart/uc_cart.admin.inc'
--- uc_cart/uc_cart.admin.inc	2010-04-05 20:37:23 +0000
+++ uc_cart/uc_cart.admin.inc	2010-04-29 17:43:59 +0000
@@ -443,7 +443,7 @@
     );
 
     $null = NULL;
-    $pane_settings = $pane['callback']('settings', $null, NULL);
+    $pane_settings = $pane['callback']('settings', $null, array());
     if (is_array($pane_settings)) {
       $form['pane_' . $pane['id']] = array(
         '#type' => 'fieldset',

=== modified file 'uc_cart/uc_cart.api.php'
--- uc_cart/uc_cart.api.php	2010-03-29 17:42:00 +0000
+++ uc_cart/uc_cart.api.php	2010-06-03 15:57:46 +0000
@@ -185,7 +185,7 @@
   switch ($op) {
     case 'load':
       $term = array_shift(taxonomy_node_get_terms_by_vocabulary($item->nid, variable_get('uc_manufacturer_vid', 0)));
-      $arg1->manufacturer = $term->name;
+      $item->manufacturer = $term->name;
       break;
   }
 }

=== modified file 'uc_cart/uc_cart.module'
--- uc_cart/uc_cart.module	2010-05-18 20:25:31 +0000
+++ uc_cart/uc_cart.module	2010-06-03 15:57:46 +0000
@@ -1308,11 +1308,16 @@
   }
 
   $messages['uc_msg_order_submit_format'] = variable_get('uc_msg_order_submit', uc_get_message('completion_message'));
-  $message = variable_get('uc_msg_order_'.$message_type, uc_get_message('completion_'.$message_type));
+  $message = variable_get('uc_msg_order_' . $message_type, uc_get_message('completion_' . $message_type));
   if ($message != '') {
-    $variables['!new_username'] = check_plain($_SESSION['new_user']['name']);
-    $variables['!new_password'] = check_plain($_SESSION['new_user']['pass']);
-    $messages['uc_msg_order_'.$message_type.'_format'] = strtr($message, $variables);
+    if (isset($_SESSION['new_user'])) {
+      $variables['!new_username'] = check_plain($_SESSION['new_user']['name']);
+      $variables['!new_password'] = check_plain($_SESSION['new_user']['pass']);
+      $messages['uc_msg_order_' . $message_type . '_format'] = strtr($message, $variables);
+    }
+    else {
+      $messages['uc_msg_order_' . $message_type . '_format'] = $message;
+    }
   }
   $messages['uc_msg_continue_shopping_format'] = variable_get('uc_msg_continue_shopping', uc_get_message('continue_shopping'));
 

=== modified file 'uc_cart/uc_cart.pages.inc'
--- uc_cart/uc_cart.pages.inc	2010-05-18 20:25:31 +0000
+++ uc_cart/uc_cart.pages.inc	2010-06-03 15:57:46 +0000
@@ -129,20 +129,16 @@
 function uc_cart_checkout_form($form, &$form_state) {
   global $user;
 
-  // Cancel an order when a customer clicks the 'Cancel' button.
-  if (isset($_POST['op']) && $_POST['op'] == t('Cancel')) {
-    if (intval($_SESSION['cart_order']) > 0) {
-      uc_order_comment_save($_SESSION['cart_order'], 0, t('Customer cancelled this order from the checkout form.'));
-      unset($_SESSION['cart_order']);
-    }
-    drupal_goto('cart');
-  }
-
-  if (isset($_SESSION['cart_order']) && is_numeric($_SESSION['cart_order'])) {
-    $order = uc_order_load($_SESSION['cart_order']);
+  if (isset($form_state['storage']['order'])) {
+    $order = $form_state['storage']['order'];
   }
   else {
-    $order = NULL;
+    if (isset($_SESSION['cart_order'])) {
+      $order = uc_order_load($_SESSION['cart_order']);
+    }
+    else {
+      $order = NULL;
+    }
   }
 
   // Check the referer URI to clear order details and prevent identity theft.
@@ -160,6 +156,10 @@
     $order = NULL;
   }
 
+  if (is_null($order)) {
+    $order = new UcOrder();
+  }
+
   $form['panes'] = array('#tree' => TRUE);
   $panes = _uc_checkout_pane_list();
 
@@ -176,14 +176,14 @@
       if (!isset($pane['collapsed'])) {
         $collapsed = ($pane['prev'] === FALSE || empty($displayed[$pane['prev']])) ? FALSE : TRUE;
       }
-      if (isset($_SESSION['expanded_panes'])) {
-        if (is_array($_SESSION['expanded_panes']) &&
-            in_array($pane['id'], $_SESSION['expanded_panes'])) {
+      if (isset($form_state['expanded_panes'])) {
+        if (is_array($form_state['expanded_panes']) &&
+            in_array($pane['id'], $form_state['expanded_panes'])) {
           $collapsed = FALSE;
         }
       }
 
-      $return = $pane['callback']('view', $order, NULL);
+      $return = $pane['callback']('view', $order, $form, $form_state);
 
       // Add the pane if any display data is returned from the callback.
       if (is_array($return) && (!empty($return['description']) || !empty($return['contents']))) {
@@ -222,7 +222,7 @@
       }
     }
   }
-  unset($_SESSION['expanded_panes']);
+  unset($form_state['expanded_panes']);
 
   $contents = uc_cart_get_contents();
 
@@ -234,7 +234,9 @@
   $form['cancel'] = array(
     '#type' => 'submit',
     '#value' => t('Cancel'),
-    '#submit' => FALSE,
+    '#validate' => array(), // Disable validation to prevent a new order from being created.
+    '#limit_validation_errors' => array(),
+    '#submit' => array('uc_cart_checkout_form_cancel'),
   );
   $form['continue'] = array(
     '#type' => 'submit',
@@ -284,16 +286,14 @@
 function uc_cart_checkout_form_validate($form, &$form_state) {
   global $user;
 
-  if (empty($_SESSION['cart_order'])) {
+  if (empty($form_state['storage']['order'])) {
     $order = uc_order_new($user->uid);
-    $_SESSION['cart_order'] = $order->order_id;
+    $form_state['storage']['order'] = $order;
   }
   else {
-    $order = new stdClass();
-    $order->uid = $user->uid;
-    $order->order_id = $_SESSION['cart_order'];
-    $order->order_status = uc_order_state_default('in_checkout');
+    $order = $form_state['storage']['order'];
   }
+  $_SESSION['cart_order'] = $order->order_id;
 
   db_delete('uc_order_products')
     ->condition('order_id', $order->order_id)
@@ -327,26 +327,30 @@
   $order->order_total = uc_order_get_total($order, TRUE);
 
   // Validate/process the cart panes.  A FALSE value results in failed checkout.
-  $_SESSION['checkout_valid'] = TRUE;
+  $form_state['checkout_valid'] = TRUE;
   foreach (element_children($form_state['values']['panes']) as $pane_id) {
     $func = _uc_checkout_pane_data($pane_id, 'callback');
-    $isvalid = $func('process', $order, $form_state['values']['panes'][$pane_id]);
+    $isvalid = $func('process', $order, $form, $form_state);
     if ($isvalid === FALSE) {
-      $_SESSION['expanded_panes'][] = $pane_id;
-      $_SESSION['checkout_valid'] = FALSE;
+      $form_state['expanded_panes'][] = $pane_id;
+      $form_state['checkout_valid'] = FALSE;
     }
   }
 
   $order->line_items = uc_order_load_line_items($order, TRUE);
+  $order->line_items = array_merge($order->line_items, uc_order_load_line_items($order, FALSE));
+  usort($order->line_items, 'uc_weight_sort');
 
   uc_order_save($order);
+
+  $form_state['storage']['order'] = uc_order_load($order->order_id);
 }
 
 /**
  * @see uc_cart_checkout_form()
  */
 function uc_cart_checkout_form_submit($form, &$form_state) {
-  if ($_SESSION['checkout_valid'] === FALSE) {
+  if ($form_state['checkout_valid'] === FALSE) {
     $url = 'cart/checkout';
   }
   else {
@@ -354,12 +358,24 @@
     $_SESSION['do_review'] = TRUE;
   }
 
-  unset($_SESSION['checkout_valid']);
+  unset($form_state['checkout_valid']);
 
   $form_state['redirect'] = $url;
 }
 
 /**
+ * @see uc_checkout_form()
+ */
+function uc_cart_checkout_form_cancel($form, &$form_state) {
+  if (intval($_SESSION['cart_order']) > 0) {
+    uc_order_comment_save($_SESSION['cart_order'], 0, t('Customer cancelled this order from the checkout form.'));
+    unset($_SESSION['cart_order']);
+  }
+
+  $form_state['redirect'] = 'cart';
+}
+
+/**
  * Allow a customer to review their order before finally submitting it.
  *
  * @see uc_cart_checkout_form()

=== modified file 'uc_cart/uc_cart.test'
--- uc_cart/uc_cart.test	2010-04-05 20:37:23 +0000
+++ uc_cart/uc_cart.test	2010-06-03 15:57:46 +0000
@@ -13,7 +13,8 @@
 class UbercartTestCase extends DrupalWebTestCase {
   // Perform the initial setup.
   function setUp() {
-    // Enable the core Ubercart modules and dependencies, along with any other modules passed as arguments.
+    // Enable the core Ubercart modules and dependencies, along with any other
+    // modules passed as arguments.
     $args = array_merge(func_get_args(), array('uc_store', 'uc_cart', 'ca', 'uc_order', 'uc_product'));
     call_user_func_array(array('parent', 'setUp'), $args);
 
@@ -96,7 +97,7 @@
   function checkout($edit = array()) {
     $this->drupalPost('cart', array(), 'Checkout');
     $this->assertText('Enter your billing address and information here.', t('Viewed cart page: Billing pane has been displayed.'));
-    //build the panes
+    // Build the panes.
     $edit += array(
       'panes[delivery][delivery_first_name]' => $this->randomName(10, 'Firstname_'),
       'panes[delivery][delivery_last_name]' => $this->randomName(10, 'Lastname_'),
@@ -113,14 +114,14 @@
       'panes[billing][billing_postal_code]' => $this->randomName(4, 'Zip_')
       );
 
-    //If the email address has not been set, and the user has not logged in,
-    //Add a primary email address.
+    // If the email address has not been set, and the user has not logged in,
+    // add a primary email address.
     if (!isset($edit['panes[customer][primary_email]']) && !$this->loggedInUser) {
       $edit['panes[customer][primary_email]'] = $this->randomName(8, 'Email_') . '@example.com';
     }
     $this->drupalPost('cart/checkout', $edit, t('Review order'));
     $this->assertRaw('Your order is almost complete.', t('Review order page: Found text "Your order is almost complete."'));
-    //Complete the review page
+    // Complete the review page.
     $this->drupalPost(NULL, array(), t('Submit order'));
     if ($order_id = db_query("SELECT order_id FROM {uc_orders} WHERE delivery_first_name = :name", array(':name' => $edit['panes[delivery][delivery_first_name]']))->fetchField()) {
       $this->pass(t('Order %order_id has been created', array('%order_id' => $order_id)));
@@ -194,7 +195,7 @@
     $this->assertField('uc_cart_breadcrumb_text', t('Custom cart breadcrumb text field exists'));
     $this->assertField('uc_cart_breadcrumb_url', t('Custom cart breadcrumb URL'));
 
-    //Test the empty cart text
+    // Test the empty cart text.
     $this->drupalGet('cart');
     $this->assertText('There are no products in your shopping cart.', t('Cart View: An empty cart displays the empty cart text'));
 
@@ -202,11 +203,11 @@
     $this->drupalPost('node/' . $product->nid, array(), t('Add to cart'));
     $this->assertTrue(($this->getUrl() == url('cart', array('absolute' => TRUE))), t('Redirected to the cart page after adding a product to the cart'));
 
-    //Ensure one item was added to the cart
+    // Ensure one item was added to the cart.
     $this->drupalGet('cart');
     $this->assertFieldByName('items[0][qty]', 1, t('One product was added to the cart'));
 
-    //Continue shopping link should take you back to the product page
+    // Continue shopping link should take you back to the product page.
     $shopping_url = url('node/' . $product->nid, array('absolute' => TRUE ));
     $shopping_link = $this->xpath("a[@href='$shopping_url'][@text()='Continue shopping']");
     $this->assertTrue(isset($shopping_link), t('Continue shopping link directs you back to the node page'));
@@ -215,9 +216,10 @@
     $this->assertText('Your cart has been updated.', t('Update cart button redirects to the view cart page'));
     $this->assertText('There are no products in your shopping cart.', t('The product was successfully removed from the shopping cart'));
 
-    //Modify the default settings
-        $settings = array(
-      'uc_minimum_subtotal' => rand(2, 9999), //greater than 2 dollars to test the above/below limit
+    // Modify the default settings.
+    $settings = array(
+      // Greater than 2 dollars to test the above/below limit
+      'uc_minimum_subtotal' => rand(2, 9999),
       'uc_continue_shopping_type' => 'button',
       'uc_continue_shopping_use_last_url' => FALSE,
       'uc_continue_shopping_url' => $this->randomName(8),
@@ -229,33 +231,36 @@
     $this->drupalPost('admin/store/settings/cart/edit', $settings, t('Save configuration'));
     $this->assertText('The configuration options have been saved.', t('Saved Cart settings. Found text "The configuration options have been saved."'));
 
-    //Create two products, one below the minimum price, and one above the minimum price
+    // Create two products, one below the minimum price, and one above the
+    // minimum price.
     $sell_price_below_limit = $settings['uc_minimum_subtotal'] - 1;
     $sell_price_above_limit = $settings['uc_minimum_subtotal'] + 1;
     $product_price_below_limit = $this->createProduct(array('sell_price' => $sell_price_below_limit));
     $product_price_above_limit = $this->createProduct(array('sell_price' => $sell_price_above_limit));
     $this->DrupalLogout();
 
-    // Check to see if the lower priced product triggers the minimum price logic
+    // Check to see if the lower priced product triggers the minimum price
+    // logic.
     $this->drupalPost('node/' . $product_price_below_limit->nid, array(), t('Add to cart'));
     $this->drupalPost('cart', array(), t('Checkout'));
     $this->assertRaw('The minimum order subtotal for checkout is', t('Minimum checkout check: Ubercart prevented checkout below the minimum order'));
 
-    // Check the custom breadcrumb text
+    // Check the custom breadcrumb text.
     $breadcrumb = $this->xpath("div[@class='" . $settings['uc_cart_breadcrumb_url'] . "']/a[@href='/ubertest/asdf'][@text()='" . $settings['uc_cart_breadcrumb_text'] . "']");
     $this->assertTrue(isset($breadcrumb), t('The breadcrumb text and url are properly displayed on the view cart page'));
 
-    // Check the back button to ensure it goes to the proper page
+    // Check the back button to ensure it goes to the proper page.
     $this->drupalPost('cart', array(), $settings['uc_continue_shopping_text']);
     $url_pass = ($this->getUrl() == url($settings['uc_continue_shopping_url'], array('absolute' => TRUE)));
     $this->assertTrue($url_pass, t('View cart back button is properly labled, and takes the user to the proper url.'));
 
-    // Add another product to the cart, and verify that we land on the checkout page
+    // Add another product to the cart, and verify that we land on the checkout
+    // page.
     $this->drupalPost('node/' . $product_price_above_limit->nid, array(), t('Add to cart'));
     $this->drupalPost('cart', array(), t('Checkout'));
     $this->assertText('Enter your billing address and information here.', t('Viewed cart page: Billing pane has been displayed.'));
 
-    // Check the redirect path
+    // Check the redirect path.
     $this->drupalLogin($this->user_store_admin);
     $uc_add_item_redirect = $this->randomName(8);
     $this->drupalPost('admin/store/settings/cart/edit', array('uc_add_item_redirect' => $uc_add_item_redirect), t('Save configuration'));

=== modified file 'uc_cart/uc_cart_checkout_pane.inc'
--- uc_cart/uc_cart_checkout_pane.inc	2010-05-18 20:14:02 +0000
+++ uc_cart/uc_cart_checkout_pane.inc	2010-06-03 15:57:46 +0000
@@ -15,9 +15,11 @@
 /**
  * Display the cart contents for review during checkout.
  */
-function uc_checkout_pane_cart($op) {
+function uc_checkout_pane_cart($op, &$order, $form = NULL, &$form_state = NULL) {
   switch ($op) {
     case 'view':
+      $order->products = uc_cart_get_contents();
+
       $contents['cart_review_table'] = array(
         '#theme' => 'uc_cart_review_table',
         '#weight' => variable_get('uc_pane_cart_field_cart_weight', 2),
@@ -56,12 +58,12 @@
 /**
  * Get the user's email address for login.
  */
-function uc_checkout_pane_customer($op, &$arg1, $arg2) {
+function uc_checkout_pane_customer($op, &$order, $form = NULL, &$form_state = NULL) {
   global $user;
 
   switch ($op) {
     case 'view':
-      $email = (is_null($arg1) || empty($arg1->primary_email)) ? $user->mail : $arg1->primary_email;
+      $email = empty($order->primary_email) ? $user->mail : $order->primary_email;
 
       if ($user->uid) {
         $description = t('Order information will be sent to your account e-mail listed below.');// . '<br />'
@@ -90,7 +92,7 @@
           $contents['new_account']['name'] = array(
             '#type' => 'textfield',
             '#title' => t('Username'),
-            '#default_value' => $arg1->data['new_user']['name'],
+            '#default_value' => $order->data['new_user']['name'],
             '#maxlength' => 60,
             '#size' => 32,
           );
@@ -135,15 +137,17 @@
       return array('description' => $description, 'contents' => $contents);
 
     case 'process':
-      if (!empty($arg2['primary_email']) && !valid_email_address($arg2['primary_email'])) {
+      $pane = $form_state['values']['panes']['customer'];
+
+      if (!empty($pane['primary_email']) && !valid_email_address($pane['primary_email'])) {
         drupal_set_message(t('You must enter a valid e-mail address.'), 'error');
         return FALSE;
       }
 
-      $arg1->primary_email = $arg2['primary_email'];
+      $order->primary_email = $pane['primary_email'];
 
       if (variable_get('uc_cart_email_validation', FALSE) && !$user->uid &&
-          $arg2['primary_email'] !== $arg2['primary_email_confirm']) {
+          $pane['primary_email'] !== $pane['primary_email_confirm']) {
         drupal_set_message(t('The e-mail address did not match.'), 'error');
         $_SESSION['email_match'] = FALSE;
         return FALSE;
@@ -155,41 +159,41 @@
           variable_get('uc_cart_new_account_password', FALSE)) &&
           $user->uid == 0) {
         // Skip if an account already exists for this e-mail address.
-        if (db_query("SELECT uid FROM {users} WHERE mail LIKE :email", array(':email' => $arg2['primary_email']))->fetchField()) {
+        if (db_query("SELECT uid FROM {users} WHERE mail LIKE :email", array(':email' => $pane['primary_email']))->fetchField()) {
           drupal_set_message(t('An account already exists for your e-mail address. The new account details you entered will be disregarded.'));
         }
         else {
           // Validate the username.
-          if (variable_get('uc_cart_new_account_name', FALSE) && !empty($arg2['new_account']['name'])) {
-            $message = user_validate_name($arg2['new_account']['name']);
+          if (variable_get('uc_cart_new_account_name', FALSE) && !empty($pane['new_account']['name'])) {
+            $message = user_validate_name($pane['new_account']['name']);
             if (!empty($message)) {
               drupal_set_message($message, 'error');
               return FALSE;
             }
-            if (db_query("SELECT uid FROM {users} WHERE name LIKE :name", array(':name' => $arg2['new_account']['name']))->fetchField()) {
-              drupal_set_message(t('The username %name is already taken. Please enter a different name or leave the field blank for your username to be your e-mail address.', array('%name' => $arg2['new_account']['name'])), 'error');
+            if (db_query("SELECT uid FROM {users} WHERE name LIKE :name", array(':name' => $pane['new_account']['name']))->fetchField()) {
+              drupal_set_message(t('The username %name is already taken. Please enter a different name or leave the field blank for your username to be your e-mail address.', array('%name' => $pane['new_account']['name'])), 'error');
               return FALSE;
             }
-            $arg1->data['new_user']['name'] = $arg2['new_account']['name'];
+            $order->data['new_user']['name'] = $pane['new_account']['name'];
           }
           // Validate the password.
           if (variable_get('uc_cart_new_account_password', FALSE)) {
-            if (strcmp($arg2['new_account']['pass'], $arg2['new_account']['pass_confirm'])) {
+            if (strcmp($pane['new_account']['pass'], $pane['new_account']['pass_confirm'])) {
               drupal_set_message(t('The passwords you entered did not match. Please try again.'), 'error');
               return FALSE;
             }
-            $arg1->data['new_user']['pass'] = $arg2['new_account']['pass'];
+            $order->data['new_user']['pass'] = $pane['new_account']['pass'];
           }
         }
       }
 
       if ($user->uid) {
-        $arg1->uid = $user->uid;
+        $order->uid = $user->uid;
       }
       return TRUE;
 
     case 'review':
-      $review[] = array('title' => t('E-mail'), 'data' => check_plain($arg1->primary_email));
+      $review[] = array('title' => t('E-mail'), 'data' => check_plain($order->primary_email));
       return $review;
 
     case 'settings':
@@ -222,7 +226,7 @@
 /**
  * Get the delivery information.
  */
-function uc_checkout_pane_delivery($op, &$arg1, $arg2) {
+function uc_checkout_pane_delivery($op, &$order, $form = NULL, &$form_state = NULL) {
   global $user;
 
   switch ($op) {
@@ -247,31 +251,31 @@
       }
 
       if (uc_address_field_enabled('first_name')) {
-        $delivery_first_name = $arg1 ? $arg1->delivery_first_name : '';
+        $delivery_first_name = $order ? $order->delivery_first_name : '';
         $contents['delivery_first_name'] = uc_textfield(uc_get_field_name('first_name'), $delivery_first_name, uc_address_field_required('first_name'));
       }
       if (uc_address_field_enabled('last_name')) {
-        $delivery_last_name = $arg1 ? $arg1->delivery_last_name : '';
+        $delivery_last_name = $order ? $order->delivery_last_name : '';
         $contents['delivery_last_name'] = uc_textfield(uc_get_field_name('last_name'), $delivery_last_name, uc_address_field_required('last_name'));
       }
       if (uc_address_field_enabled('company')) {
-        $delivery_company = $arg1 ? $arg1->delivery_company : '';
+        $delivery_company = $order ? $order->delivery_company : '';
         $contents['delivery_company'] = uc_textfield(uc_get_field_name('company'), $delivery_company, uc_address_field_required('company'), NULL, 64);
       }
       if (uc_address_field_enabled('street1')) {
-        $delivery_street1 = $arg1 ? $arg1->delivery_street1 : '';
+        $delivery_street1 = $order ? $order->delivery_street1 : '';
         $contents['delivery_street1'] = uc_textfield(uc_get_field_name('street1'), $delivery_street1, uc_address_field_required('street1'), NULL, 64);
       }
       if (uc_address_field_enabled('street2')) {
-        $delivery_street2 = $arg1 ? $arg1->delivery_street2 : '';
+        $delivery_street2 = $order ? $order->delivery_street2 : '';
         $contents['delivery_street2'] = uc_textfield(uc_get_field_name('street2'), $delivery_street2, uc_address_field_required('street2'), NULL, 64);
       }
       if (uc_address_field_enabled('city')) {
-        $delivery_city = $arg1 ? $arg1->delivery_city : '';
+        $delivery_city = $order ? $order->delivery_city : '';
         $contents['delivery_city'] = uc_textfield(uc_get_field_name('city'), $delivery_city, uc_address_field_required('city'));
       }
       if (uc_address_field_enabled('country')) {
-        $delivery_country = $arg1 ? $arg1->delivery_country : NULL;
+        $delivery_country = $order ? $order->delivery_country : NULL;
         $contents['delivery_country'] = uc_country_select(uc_get_field_name('country'), $delivery_country, NULL, 'name', uc_address_field_required('country'));
       }
       if (uc_address_field_enabled('zone')) {
@@ -281,40 +285,42 @@
         else {
           $country_id = $delivery_country;
         }
-        $delivery_zone = $arg1 ? $arg1->delivery_zone : NULL;
+        $delivery_zone = $order ? $order->delivery_zone : NULL;
         $contents['delivery_zone'] = uc_zone_select(uc_get_field_name('zone'), $delivery_zone, NULL, $country_id, 'name', uc_address_field_required('zone'));
         if (isset($_POST['panes']) && count($contents['delivery_zone']['#options']) == 1) {
           $contents['delivery_zone']['#required'] = FALSE;
         }
       }
       if (uc_address_field_enabled('postal_code')) {
-        $delivery_postal_code = $arg1 ? $arg1->delivery_postal_code : '';
+        $delivery_postal_code = $order ? $order->delivery_postal_code : '';
         $contents['delivery_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $delivery_postal_code, uc_address_field_required('postal_code'), NULL, 10, 10);
       }
       if (uc_address_field_enabled('phone')) {
-        $delivery_phone = $arg1 ? $arg1->delivery_phone : '';
+        $delivery_phone = $order ? $order->delivery_phone : '';
         $contents['delivery_phone'] = uc_textfield(uc_get_field_name('phone'), $delivery_phone, uc_address_field_required('phone'), NULL, 32, 16);
       }
 
       return array('description' => $description, 'contents' => $contents, 'theme' => 'uc_address_pane');
 
     case 'process':
-      $arg1->delivery_first_name = $arg2['delivery_first_name'];
-      $arg1->delivery_last_name = $arg2['delivery_last_name'];
-      $arg1->delivery_company = $arg2['delivery_company'];
-      $arg1->delivery_street1 = $arg2['delivery_street1'];
-      $arg1->delivery_street2 = $arg2['delivery_street2'];
-      $arg1->delivery_city = $arg2['delivery_city'];
-      $arg1->delivery_zone = $arg2['delivery_zone'];
-      $arg1->delivery_postal_code = $arg2['delivery_postal_code'];
-      $arg1->delivery_country = $arg2['delivery_country'];
-      $arg1->delivery_phone = $arg2['delivery_phone'];
+      $pane = $form_state['values']['panes']['delivery'];
+
+      $order->delivery_first_name = $pane['delivery_first_name'];
+      $order->delivery_last_name = $pane['delivery_last_name'];
+      $order->delivery_company = $pane['delivery_company'];
+      $order->delivery_street1 = $pane['delivery_street1'];
+      $order->delivery_street2 = $pane['delivery_street2'];
+      $order->delivery_city = $pane['delivery_city'];
+      $order->delivery_zone = $pane['delivery_zone'];
+      $order->delivery_postal_code = $pane['delivery_postal_code'];
+      $order->delivery_country = $pane['delivery_country'];
+      $order->delivery_phone = $pane['delivery_phone'];
       return TRUE;
 
     case 'review':
-      $review[] = array('title' => t('Address'), 'data' => uc_order_address($arg1, 'delivery', FALSE));
-      if (uc_address_field_enabled('phone') && !empty($arg1->delivery_phone)) {
-        $review[] = array('title' => t('Phone'), 'data' => check_plain($arg1->delivery_phone));
+      $review[] = array('title' => t('Address'), 'data' => uc_order_address($order, 'delivery', FALSE));
+      if (uc_address_field_enabled('phone') && !empty($order->delivery_phone)) {
+        $review[] = array('title' => t('Phone'), 'data' => check_plain($order->delivery_phone));
       }
       return $review;
   }
@@ -323,7 +329,7 @@
 /**
  * Get the billing information.
  */
-function uc_checkout_pane_billing($op, &$arg1, $arg2) {
+function uc_checkout_pane_billing($op, &$order, $form = NULL, &$form_state = NULL) {
   global $user;
 
   switch ($op) {
@@ -347,31 +353,31 @@
         }
       }
       if (uc_address_field_enabled('first_name')) {
-        $billing_first_name = $arg1 ? $arg1->billing_first_name : '';
+        $billing_first_name = $order ? $order->billing_first_name : '';
         $contents['billing_first_name'] = uc_textfield(uc_get_field_name('first_name'), $billing_first_name, uc_address_field_required('first_name'));
       }
       if (uc_address_field_enabled('last_name')) {
-        $billing_last_name = $arg1 ? $arg1->billing_last_name : '';
+        $billing_last_name = $order ? $order->billing_last_name : '';
         $contents['billing_last_name'] = uc_textfield(uc_get_field_name('last_name'), $billing_last_name, uc_address_field_required('last_name'));
       }
       if (uc_address_field_enabled('company')) {
-        $billing_company = $arg1 ? $arg1->billing_company : '';
+        $billing_company = $order ? $order->billing_company : '';
         $contents['billing_company'] = uc_textfield(uc_get_field_name('company'), $billing_company, uc_address_field_required('company'), NULL, 64);
       }
       if (uc_address_field_enabled('street1')) {
-        $billing_street1 = $arg1 ? $arg1->billing_street1 : '';
+        $billing_street1 = $order ? $order->billing_street1 : '';
         $contents['billing_street1'] = uc_textfield(uc_get_field_name('street1'), $billing_street1, uc_address_field_required('street1'), NULL, 64);
       }
       if (uc_address_field_enabled('street2')) {
-        $billing_street2 = $arg1 ? $arg1->billing_street2 : '';
+        $billing_street2 = $order ? $order->billing_street2 : '';
         $contents['billing_street2'] = uc_textfield(uc_get_field_name('street2'), $billing_street2, uc_address_field_required('street2'), NULL, 64);
       }
       if (uc_address_field_enabled('city')) {
-        $billing_city = $arg1 ? $arg1->billing_city : '';
+        $billing_city = $order ? $order->billing_city : '';
         $contents['billing_city'] = uc_textfield(uc_get_field_name('city'), $billing_city, uc_address_field_required('city'));
       }
       if (uc_address_field_enabled('country')) {
-        $billing_country = $arg1 ? $arg1->billing_country : NULL;
+        $billing_country = $order ? $order->billing_country : NULL;
         $contents['billing_country'] = uc_country_select(uc_get_field_name('country'), $billing_country, NULL, 'name', uc_address_field_required('country'));
       }
       if (uc_address_field_enabled('zone')) {
@@ -381,40 +387,42 @@
         else {
           $country_id = $billing_country;
         }
-        $billing_zone = $arg1 ? $arg1->billing_zone : NULL;
+        $billing_zone = $order ? $order->billing_zone : NULL;
         $contents['billing_zone'] = uc_zone_select(uc_get_field_name('zone'), $billing_zone, NULL, $country_id, 'name', uc_address_field_required('zone'));
         if (isset($_POST['panes']) && count($contents['billing_zone']['#options']) == 1) {
           $contents['billing_zone']['#required'] = FALSE;
         }
       }
       if (uc_address_field_enabled('postal_code')) {
-        $billing_postal_code = $arg1 ? $arg1->billing_postal_code : '';
+        $billing_postal_code = $order ? $order->billing_postal_code : '';
         $contents['billing_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $billing_postal_code, uc_address_field_required('postal_code'), NULL, 10, 10);
       }
       if (uc_address_field_enabled('phone')) {
-        $billing_phone = $arg1 ? $arg1->billing_phone : '';
+        $billing_phone = $order ? $order->billing_phone : '';
         $contents['billing_phone'] = uc_textfield(uc_get_field_name('phone'), $billing_phone, uc_address_field_required('phone'), NULL, 32, 16);
       }
 
       return array('description' => $description, 'contents' => $contents, 'theme' => 'uc_address_pane');
 
     case 'process':
-      $arg1->billing_first_name = $arg2['billing_first_name'];
-      $arg1->billing_last_name = $arg2['billing_last_name'];
-      $arg1->billing_company = $arg2['billing_company'];
-      $arg1->billing_street1 = $arg2['billing_street1'];
-      $arg1->billing_street2 = $arg2['billing_street2'];
-      $arg1->billing_city = $arg2['billing_city'];
-      $arg1->billing_zone = $arg2['billing_zone'];
-      $arg1->billing_postal_code = $arg2['billing_postal_code'];
-      $arg1->billing_country = $arg2['billing_country'];
-      $arg1->billing_phone = $arg2['billing_phone'];
+      $pane = $form_state['values']['panes']['billing'];
+
+      $order->billing_first_name = $pane['billing_first_name'];
+      $order->billing_last_name = $pane['billing_last_name'];
+      $order->billing_company = $pane['billing_company'];
+      $order->billing_street1 = $pane['billing_street1'];
+      $order->billing_street2 = $pane['billing_street2'];
+      $order->billing_city = $pane['billing_city'];
+      $order->billing_zone = $pane['billing_zone'];
+      $order->billing_postal_code = $pane['billing_postal_code'];
+      $order->billing_country = $pane['billing_country'];
+      $order->billing_phone = $pane['billing_phone'];
       return TRUE;
 
     case 'review':
-      $review[] = array('title' => t('Address'), 'data' => uc_order_address($arg1, 'billing', FALSE));
-      if (uc_address_field_enabled('phone') && !empty($arg1->billing_phone)) {
-        $review[] = array('title' => t('Phone'), 'data' => check_plain($arg1->billing_phone));
+      $review[] = array('title' => t('Address'), 'data' => uc_order_address($order, 'billing', FALSE));
+      if (uc_address_field_enabled('phone') && !empty($order->billing_phone)) {
+        $review[] = array('title' => t('Phone'), 'data' => check_plain($order->billing_phone));
       }
       return $review;
   }
@@ -423,13 +431,13 @@
 /**
  * Allow a customer to make comments on the order.
  */
-function uc_checkout_pane_comments($op, &$arg1, $arg2) {
+function uc_checkout_pane_comments($op, &$order, $form = NULL, &$form_state = NULL) {
   switch ($op) {
     case 'view':
       $description = t('Use this area for special instructions or questions regarding your order.');
 
-      if (!empty($arg1->order_id)) {
-        $default = db_query("SELECT message FROM {uc_order_comments} WHERE order_id = :id", array(':id' => $arg1->order_id))->fetchField();
+      if (!empty($order->order_id)) {
+        $default = db_query("SELECT message FROM {uc_order_comments} WHERE order_id = :id", array(':id' => $order->order_id))->fetchField();
       }
       else {
         $default = NULL;
@@ -443,17 +451,17 @@
       return array('description' => $description, 'contents' => $contents);
 
     case 'process':
-      if (strlen($arg2['comments']) > 0) {
+      if (strlen($form_state['values']['panes']['comments']['comments']) > 0) {
         db_delete('uc_order_comments')
-          ->condition('order_id', $arg1->order_id)
+          ->condition('order_id', $order->order_id)
           ->execute();
-        uc_order_comment_save($arg1->order_id, 0, $arg2['comments'], 'order', uc_order_state_default('post_checkout'), TRUE);
+        uc_order_comment_save($order->order_id, 0, $form_state['values']['panes']['comments']['comments'], 'order', uc_order_state_default('post_checkout'), TRUE);
       }
       return TRUE;
 
     case 'review':
       $review = NULL;
-      $result = db_query("SELECT message FROM {uc_order_comments} WHERE order_id = :id", array(':id' => $arg1->order_id));
+      $result = db_query("SELECT message FROM {uc_order_comments} WHERE order_id = :id", array(':id' => $order->order_id));
       if ($comment = $result->fetchObject()) {
         $review[] = array('title' => t('Comment'), 'data' => check_plain($comment->message));
       }

=== modified file 'uc_cart_links/uc_cart_links.pages.inc'
--- uc_cart_links/uc_cart_links.pages.inc	2010-03-16 15:26:04 +0000
+++ uc_cart_links/uc_cart_links.pages.inc	2010-06-03 15:57:46 +0000
@@ -9,17 +9,17 @@
 /**
  * Process a cart link to fiddle with the cart and redirect the user.
  *
- * @param $arg1
+ * @param $cart_action
  *   An action.
  */
-function uc_cart_links_process($arg1) {
+function uc_cart_links_process($cart_action) {
   $messages = array();
 
   // Fail if the link is restricted.
   $data = variable_get('uc_cart_links_restrictions', '');
   if (!empty($data)) {
     $restrictions = explode("\n", variable_get('uc_cart_links_restrictions', ''));
-    if (!empty($restrictions) && !in_array($arg1, $restrictions)) {
+    if (!empty($restrictions) && !in_array($cart_action, $restrictions)) {
       $url = variable_get('uc_cart_links_invalid_page', '');
       if (empty($url)) {
         $url = '<front>';
@@ -30,7 +30,7 @@
   }
 
   // Split apart the cart link on the -.
-  $actions = explode('-', urldecode($arg1));
+  $actions = explode('-', urldecode($cart_action));
   $rebuild_cart = FALSE;
 
   foreach ($actions as $action) {

=== modified file 'uc_catalog/uc_catalog.install'
--- uc_catalog/uc_catalog.install	2010-04-01 18:42:54 +0000
+++ uc_catalog/uc_catalog.install	2010-06-03 15:57:46 +0000
@@ -13,7 +13,7 @@
  */
 function uc_catalog_install() {
   $t = get_t();
-  //Find possible Product Catalog vocabulary.
+  // Find possible Product Catalog vocabulary.
   $vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE name = :name", array(':name' => $t('Catalog')))->fetchField();
 
   // If none, create one.

=== modified file 'uc_catalog/uc_catalog.module'
--- uc_catalog/uc_catalog.module	2010-04-14 13:36:28 +0000
+++ uc_catalog/uc_catalog.module	2010-06-03 15:57:46 +0000
@@ -771,7 +771,7 @@
         $terms[] = $current->tid;
       }
     }
-    //print '<pre>' . print_r($breadcrumbs, TRUE) . '</pre>';
+
     return $breadcrumbs;
   }
   else {

=== modified file 'uc_catalog/uc_catalog.pages.inc'
--- uc_catalog/uc_catalog.pages.inc	2010-04-05 13:53:11 +0000
+++ uc_catalog/uc_catalog.pages.inc	2010-06-03 15:57:46 +0000
@@ -73,7 +73,7 @@
         $j++;
       }
     }
-    //$grandchildren = array_slice($grandchildren, 0, intval(count($grandchildren) / 2) + 1, TRUE);
+
     if ($j > $max_gc_display) {
       array_push($grandchildren, l(t('More...'), uc_catalog_path($child), array('class' => array('subcategory'))));
     }

=== modified file 'uc_file/uc_file.admin.inc'
--- uc_file/uc_file.admin.inc	2010-04-26 18:08:32 +0000
+++ uc_file/uc_file.admin.inc	2010-06-03 15:57:46 +0000
@@ -314,7 +314,7 @@
 
       break;
 
-    case 'uc_file_upload': //Upload file
+    case 'uc_file_upload':
 
       // Calculate the max size of uploaded files, in bytes.
       $max_bytes = trim(ini_get('post_max_size'));

=== modified file 'uc_file/uc_file.api.php'
--- uc_file/uc_file.api.php	2010-03-29 17:42:00 +0000
+++ uc_file/uc_file.api.php	2010-06-03 15:57:46 +0000
@@ -121,7 +121,8 @@
     case 'info':
       return array('uc_image_watermark_add_mark' => 'Add Watermark');
     case 'insert':
-      //automatically adds watermarks to any new files that are uploaded to the file download directory
+      // Automatically adds watermarks to any new files that are uploaded to
+      // the file download directory.
       _add_watermark($args['file_object']->filepath);
     break;
     case 'form':
@@ -140,7 +141,7 @@
       _add_watermark($args['file_object']->filepath);
       break;
     case 'upload_validate':
-      //Given a file path, function checks if file is valid JPEG
+      // Given a file path, function checks if file is valid JPEG.
       if(!_check_image($args['file_object']->filepath)) {
         form_set_error('upload',t('Uploaded file is not a valid JPEG'));
       }
@@ -156,7 +157,7 @@
       if ($args['form_values']['action'] == 'uc_image_watermark_add_mark') {
         foreach ($args['form_values']['file_ids'] as $file_id) {
           $filename = db_query("SELECT filename FROM {uc_files} WHERE fid = :fid", array(':fid' => $file_id))->fetchField();
-          //Function adds watermark to image
+          // Function adds watermark to image.
           _add_watermark($filename);
         }
       }
@@ -187,7 +188,8 @@
  *   The path of the new file to transfer to customer.
  */
 function hook_uc_file_transfer_alter($file_user, $ip, $fid, $file) {
-  $file_data = file_get_contents($file)." [insert personalized data]"; //for large files this might be too memory intensive
+  // For large files this might be too memory intensive.
+  $file_data = file_get_contents($file)." [insert personalized data]";
   $new_file = tempnam(file_directory_temp(),'tmp');
   file_put_contents($new_file,$file_data);
   return $new_file;

=== modified file 'uc_file/uc_file.pages.inc'
--- uc_file/uc_file.pages.inc	2010-04-09 12:46:03 +0000
+++ uc_file/uc_file.pages.inc	2010-06-03 15:57:46 +0000
@@ -330,7 +330,8 @@
 
   ob_end_clean();
 
-  //Only send partial content header if downloading a piece of the file (IE workaround)
+  // Only send partial content header if downloading a piece of the file (IE
+  // workaround).
   if ($seek_start > 0 || $seek_end < ($size - 1)) {
     drupal_set_header('206 Partial Content');
   }

=== modified file 'uc_googleanalytics/uc_googleanalytics.module'
--- uc_googleanalytics/uc_googleanalytics.module	2010-05-18 20:14:02 +0000
+++ uc_googleanalytics/uc_googleanalytics.module	2010-06-03 15:57:46 +0000
@@ -49,11 +49,11 @@
 /**
  * Implement hook_uc_order().
  */
-function uc_googleanalytics_uc_order($op, &$arg1, $arg2) {
+function uc_googleanalytics_uc_order($op, &$order, $arg2) {
   // If a new order is created during the checkout process...
   if ($op == 'new' && arg(0) == 'cart') {
     // Store the order ID for later use.
-    $_SESSION['ucga_order_id'] = $arg1->order_id;
+    $_SESSION['ucga_order_id'] = $order->order_id;
   }
 }
 

=== modified file 'uc_order/uc_order.admin.inc'
--- uc_order/uc_order.admin.inc	2010-05-18 20:14:02 +0000
+++ uc_order/uc_order.admin.inc	2010-05-25 19:44:03 +0000
@@ -484,21 +484,16 @@
 
     if (arg(3) == 'sort' && !is_null(arg(4))) {
       $_SESSION['sort_status'] = arg(4);
-      $query->condition($o_order_status, arg(4));
     }
-    else {
-      if (isset($_SESSION['sort_status']) && !is_null($_SESSION['sort_status'])) {
+
+    if (!isset($_SESSION['sort_status']) || $_SESSION['sort_status'] != 'all') {
+      if (!empty($_SESSION['sort_status']) && is_string($_SESSION['sort_status'])) {
         $query->condition($o_order_status, $_SESSION['sort_status']);
       }
       else {
         $query->condition($o_order_status, uc_order_status_list('general', TRUE), 'IN');
       }
     }
-
-    if (isset($_SESSION['sort_status']) && $_SESSION['sort_status'] == 'all') {
-      $conditions =& $query->conditions();
-      $conditions = array();
-    }
   }
 
   $context = array(
@@ -1250,15 +1245,14 @@
   $form['order_id'] = array('#type' => 'hidden', '#value' => $order->order_id);
   $form['order_uid'] = array('#type' => 'hidden', '#value' => $order->uid);
 
-  $modified = isset($form_state['post']['order_modified']) ? $form_state['post']['order_modified'] : REQUEST_TIME;
+  $modified = isset($form_state['values']['order_modified']) ? $form_state['values']['order_modified'] : REQUEST_TIME;
   $form['order_modified'] = array('#type' => 'hidden', '#value' => $modified);
 
   $panes = _uc_order_pane_list('edit');
   foreach ($panes as $pane) {
-    if (in_array('edit', $pane['show']) &&
-        variable_get('uc_order_pane_' . $pane['id'] . '_show_edit', $pane['enabled'])) {
+    if (in_array('edit', $pane['show']) && variable_get('uc_order_pane_' . $pane['id'] . '_show_edit', $pane['enabled'])) {
       $func = $pane['callback'];
-      if (function_exists($func) && ($contents = $func('edit-form', $order)) != NULL) {
+      if (function_exists($func) && ($contents = $func('edit-form', $order, array(), $form_state)) != NULL) {
         $form = array_merge($form, $contents);
       }
     }
@@ -1275,6 +1269,7 @@
     $form['delete'] = array(
       '#type' => 'submit',
       '#value' => t('Delete'),
+      '#submit' => array('uc_order_edit_form_delete'),
     );
   }
 
@@ -1311,9 +1306,10 @@
   }
 
   $output .= '<div class="order-pane abs-left">' . drupal_render($form['order_id']) . drupal_render($form['order_modified'])
-           . drupal_render($form['form_id']) . drupal_render($form['form_token'])
-           . drupal_render($form['submit-changes']) . drupal_render($form['delete'])
-            . '</div>';
+    . drupal_render($form['form_id']) . drupal_render($form['form_token'])
+    . drupal_render($form['form_build_id'])
+    . drupal_render($form['submit-changes']) . drupal_render($form['delete'])
+    . '</div>';
 
   return $output;
 }
@@ -1334,20 +1330,15 @@
  * @see uc_order_edit_form()
  */
 function uc_order_edit_form_submit($form, &$form_state) {
-  if ($form_state['values']['op'] == t('Delete')) {
-    drupal_goto('admin/store/orders/' . $form_state['values']['order_id'] . '/delete');
-  }
-
   $order = uc_order_load($form_state['values']['order_id']);
   $log = array();
 
   $panes = _uc_order_pane_list();
   foreach ($panes as $pane) {
-    if (in_array('edit', $pane['show']) &&
-        variable_get('uc_order_pane_' . $pane['id'] . '_show_edit', TRUE)) {
+    if (in_array('edit', $pane['show']) && variable_get('uc_order_pane_' . $pane['id'] . '_show_edit', TRUE)) {
       $func = $pane['callback'];
       if (function_exists($func)) {
-        if (($changes = $func('edit-process', $form_state['values'])) != NULL) {
+        if (($changes = $func('edit-process', $form_state['values'], $form, $form_state)) != NULL) {
           foreach ($changes as $key => $value) {
             if ($order->$key != $value) {
               if (!is_array($value)) {
@@ -1372,8 +1363,8 @@
   }
 
   unset($order->products);
-  if (is_array($_POST['products'])) {
-    foreach ($_POST['products'] as $product) {
+  if (is_array($form_state['values']['products'])) {
+    foreach ($form_state['values']['products'] as $product) {
       if (!isset($product['remove']) && intval($product['qty']) > 0) {
         $product['data'] = unserialize($product['data']);
         $product = (object)$product;
@@ -1417,205 +1408,10 @@
 }
 
 /**
- * Populate the product add/edit div on the order edit screen.
- */
-function uc_order_edit_products($order) {
-  if (is_array($_POST['products'])) {
-    foreach ($_POST['products'] as $key => $product) {
-      $product['data'] = unserialize($product['data']);
-      uc_order_product_save($order->order_id, (object) $product);
-    }
-  }
-
-  switch ($_POST['action']) {
-    case 'add_blank':
-      db_insert('uc_order_products')
-        ->fields(array(
-          'order_id' => $order->order_id,
-          'qty' => 1,
-        ))
-        ->execute();
-      if (variable_get('uc_order_logging', TRUE)) {
-        uc_order_log_changes($order->order_id, array('add' => 'Added new product line to order.'));
-      }
-      break;
-    case 'add':
-      $form_state['values'] = $_POST;
-      $product = node_load(intval($_POST['nid']));
-      $product->qty = intval($_POST['qty']);
-      $product->price = $product->sell_price;
-      $product->data = module_invoke_all('uc_add_to_cart_data', $form_state['values']);
-
-      foreach (module_implements('uc_cart_item') as $module) {
-        $function = $module . '_uc_cart_item';
-        if (function_exists($function)) {
-          // $product must be passed by reference.
-          $function('load', $product);
-        }
-      }
-
-      $price_info = array(
-        'price' => $product->price,
-        'qty' => 1,
-      );
-      $context = array(
-        'revision' => 'original',
-        'type' => 'order_product',
-        'subject' => array(
-          'order' => $order,
-          'product' => $product,
-          'node' => clone $product,
-        ),
-      );
-      $product->price = uc_price($price_info, $context);
-
-      drupal_alter('uc_order_product', $product, $order);
-      uc_order_product_save($order->order_id, $product);
-
-      if (variable_get('uc_order_logging', TRUE)) {
-        uc_order_log_changes($order->order_id, array('add' => 'Added (' . $product->qty . ') ' . $product->title . ' to order.'));
-      }
-
-      // Decrement stock?
-      if (module_exists('uc_stock')) {
-        uc_stock_adjust_product_stock($product, 0, $order);
-      }
-      break;
-    case 'remove':
-      $order_product_id = intval($_POST['opid']);
-      // Put back the stock?
-      if (module_exists('uc_stock')) {
-        $product = db_query("SELECT model, qty FROM {uc_order_products} WHERE order_product_id = :id", array(':id' => $order_product_id))->fetchObject();
-        uc_stock_adjust($product->model, $product->qty);
-      }
-      db_delete('uc_order_products')
-        ->condition('order_product_id', $order_product_id)
-        ->execute();
-      break;
-  }
-
-  $products = db_query("SELECT * FROM {uc_order_products} WHERE order_id = :id ORDER BY order_product_id", array(':id' => $order->order_id))->fetchAll();
-
-  print drupal_render(uc_strip_form(drupal_get_form('uc_order_edit_products_form', $products)));
-  exit();
-}
-
-/**
- * Form to allow ordered products' data to be changed.
- *
- * @see
- *   uc_op_products_edit_table()
- *   theme_uc_order_edit_products_form()
- *   theme_uc_order_remove_product()
- */
-function uc_order_edit_products_form($form, &$form_state, $products) {
-  if (($product_count = count($products)) > 0) {
-    $form['products'] = tapir_get_table('uc_op_products_edit_table');
-    for ($i = 0; $i < $product_count; $i++) {
-      $form['products'][$i]['remove'] = array(
-        '#type' => 'checkbox',
-        '#name' => "products[$i][remove]",
-        '#theme' => 'uc_order_remove_product',
-        '#parents' => array(),
-        '#img_id' => $products[$i]->order_product_id,
-      );
-      $form['products'][$i]['order_product_id'] = array(
-        '#type' => 'hidden',
-        '#value' => $products[$i]->order_product_id,
-        '#name' => "products[$i][order_product_id]",
-        '#parents' => array(),
-      );
-      $form['products'][$i]['nid'] = array(
-        '#type' => 'hidden',
-        '#value' => $products[$i]->nid,
-        '#name' => "products[$i][nid]",
-        '#parents' => array(),
-      );
-      $form['products'][$i]['qty'] = array(
-        '#type' => 'textfield',
-        '#value' => $products[$i]->qty,
-        '#name' => "products[$i][qty]",
-        '#parents' => array(),
-        '#size' => 2,
-        '#maxlength' => 6,
-      );
-      $form['products'][$i]['title'] = array(
-        '#type' => 'textfield',
-        '#value' => $products[$i]->title,
-        '#name' => "products[$i][title]",
-        '#parents' => array(),
-        '#size' => 30,
-      );
-      $form['products'][$i]['model'] = array(
-        '#type' => 'textfield',
-        '#value' => $products[$i]->model,
-        '#name' => "products[$i][model]",
-        '#parents' => array(),
-        '#size' => 6,
-      );
-      $form['products'][$i]['weight'] = array(
-        '#type' => 'textfield',
-        '#value' => $products[$i]->weight,
-        '#name' => "products[$i][weight]",
-        '#parents' => array(),
-        '#size' => 3,
-      );
-      $form['products'][$i]['cost'] = array(
-        '#type' => 'textfield',
-        '#value' => uc_store_format_price_field_value($products[$i]->cost),
-        '#name' => "products[$i][cost]",
-        '#parents' => array(),
-        '#size' => 5,
-      );
-      $form['products'][$i]['price'] = array(
-        '#type' => 'textfield',
-        '#value' => uc_store_format_price_field_value($products[$i]->price),
-        '#name' => "products[$i][price]",
-        '#parents' => array(),
-        '#size' => 5,
-      );
-      $form['products'][$i]['data'] = array(
-        '#type' => 'hidden',
-        '#value' => $products[$i]->data,
-        '#name' => "products[$i][data]",
-        '#parents' => array(),
-      );
-    }
-  }
-  else {
-    $form['products'][]['remove'] = array(
-      '#value' => t('This order contains no products.'),
-      '#cell_attributes' => array('colspan' => 'full'),
-    );
-  }
-
-  return $form;
-}
-
-/**
- * @ingroup themeable
- * @see uc_order_edit_products_form()
- */
-function theme_uc_order_edit_products_form($variables) {
-  return drupal_render_children($variables['form']);
-}
-
-/**
- * Format the button to remove products from an order.
- *
- * @ingroup themeable
- * @see uc_op_products_edit_table()
- */
-function theme_uc_order_remove_product($variables) {
-  $form = $variables['form'];
-
-  return '<img id="' . $form['#img_id'] . '" src="'
-    . base_path() . drupal_get_path('module', 'uc_store')
-    . '/images/error.gif" style="padding-top: 1px; padding-left: .8em; '
-    . 'padding-right: 2px; float: left; cursor: pointer;" '
-    . 'alt="' . t('Remove this product.') . '" onclick="'
-    . 'remove_product_button(\'' . t('Remove product from order?') . '\', this.id);" />'
-    . drupal_render_children($form);
+ * @see uc_order_edit_form()
+ */
+function uc_order_edit_form_delete($form, &$form_state) {
+  $form_state['redirect'] = 'admin/store/orders/' . $form_state['values']['order_id'] . '/delete';
 }
 
 /**
@@ -1698,132 +1494,6 @@
 }
 
 /**
- * Select a product to add to the order.
- *
- * @see uc_order_load_product_select_form()
- */
-function uc_order_load_product_select($order) {
-  $types = uc_product_types();
-
-  if (!empty($_POST['search'])) {
-    $search = strtolower(str_replace('*', '%', check_plain($_POST['search'])));
-    $search_args = array(
-      ':types' => $types,
-      ':title' => $search,
-      ':model' => $search,
-    );
-
-    $result = db_query("SELECT n.nid, n.title FROM {node} AS n LEFT JOIN "
-                      . "{uc_products} AS p ON n.nid = p.nid WHERE n.type IN "
-                      . "(:types) AND (n.title LIKE :title OR p.model LIKE :model)"
-                      . " ORDER BY n.title", $search_args);
-  }
-  else {
-    $result = db_query("SELECT nid, title FROM {node} WHERE type IN (:types) ORDER BY title", array(':types' => $types));
-  }
-  foreach ($result as $row) {
-    $options[$row->nid] = $row->title;
-  }
-
-  $output = drupal_get_form('uc_order_product_select_form', $order->order_id, $options);
-
-  print drupal_render($output);
-  exit();
-}
-
-/**
- * Form to choose a product to add to the order.
- */
-function uc_order_product_select_form($form, &$form_state, $order_id, $options = array()) {
-  if (count($options) == 0) {
-    $options[0] = t('No products found.');
-  }
-
-  $form['unid'] = array(
-    '#type' => 'select',
-    '#title' => t('Select a product'),
-    '#options' => $options,
-    '#size' => 7,
-    '#attributes' => array('ondblclick' => 'return select_product();'),
-  );
-  $form['product_search'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Search by name or model/SKU (* is the wildcard)'),
-  );
-
-  $form['select'] = array(
-    '#type' => 'button',
-    '#value' => t('Select'),
-    '#attributes' => array('onclick' => 'return select_product();'),
-  );
-  $form['search'] = array(
-    '#type' => 'button',
-    '#value' => t('Search'),
-    '#attributes' => array('onclick' => 'return load_product_select(' . $order_id . ', true);'),
-  );
-  $form['close'] = array(
-    '#type' => 'button',
-    '#value' => t('Close'),
-    '#attributes' => array('onclick' => 'return close_product_select();'),
-  );
-
-  return $form;
-}
-
-/**
- * Intermediate div that lets you set the qty and attributes for a product.
- *
- * @see uc_order_add_product_form()
- */
-function uc_order_add_product($order, $product) {
-  $build = array();
-  $build['form'] = drupal_get_form('uc_order_add_product_form', $order, $product) + array(
-    '#prefix' => '<div style="margin: 1em;"><strong>Add ' . check_plain($product->title) . '</strong>',
-    '#suffix' => '</div>',
-  );
-
-  print drupal_render($build);
-  exit();
-}
-
-/**
- * Set the quantity and attributes of a product added to the order.
- *
- * @see uc_order_add_product_form()
- */
-function uc_order_add_product_form($form, &$form_state, $order, $node) {
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid,
-  );
-  $form['add-qty'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Qty'),
-    '#default_value' => '1',
-    '#size' => 2,
-    '#maxlength' => 5,
-  );
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Add to order'),
-    '#attributes' => array('onclick' => 'return add_product_to_order(' . $order->order_id . ', ' . $node->nid . ');')
-  );
-  $form['cancel'] = array(
-    '#type' => 'submit',
-    '#value' => t('Cancel'),
-    '#attributes' => array('onclick' => "\$('#add-product-button').click(); return false;"),
-  );
-  $form['node'] = array(
-    '#type' => 'value',
-    '#value' => $node,
-  );
-
-  uc_form_alter($form, $form_state, __FUNCTION__);
-
-  return $form;
-}
-
-/**
  * Display an invoice in the browser, convert it to PDF, or e-mail it as HTML.
  */
 function uc_order_invoice($order, $op = 'view') {

=== modified file 'uc_order/uc_order.api.php'
--- uc_order/uc_order.api.php	2010-03-29 17:42:00 +0000
+++ uc_order/uc_order.api.php	2010-06-03 15:57:46 +0000
@@ -129,17 +129,17 @@
  *
  * @param $op
  *   The action being performed.
- * @param &$arg1
+ * @param &$order
  *   This is the order object or a reference to it as noted below.
  * @param $arg2
  *   This is variable and is based on the value of $op:
- *   - new: Called when an order is created. $arg1 is a reference to the new
+ *   - new: Called when an order is created. $order is a reference to the new
  *       order object, so modules may add to or modify the order at creation.
  *   - save: When an order object is being saved, the hook gets invoked with this
- *       op to let other modules do any necessary saving. $arg1 is a reference to
+ *       op to let other modules do any necessary saving. $order is a reference to
  *       the order object.
  *   - load: Called when an order is loaded after the order and product data has
- *       been loaded from the database. Passes $arg1 as the reference to the
+ *       been loaded from the database. Passes $order as the reference to the
  *       order object, so modules may add to or modify the order object when it's
  *       loaded.
  *   - submit: When a sale is being completed and the customer has clicked the
@@ -155,25 +155,25 @@
  *         return array(array('pass' => FALSE, 'message' => t('We were unable to process your credit card.')));
  *       @endcode
  *   - can_update: Called before an order's status is changed to make sure the
- *       order can be updated. $arg1 is the order object with the old order
- *       status ID ($arg1->order_status), and $arg2 is simply the new order
+ *       order can be updated. $order is the order object with the old order
+ *       status ID ($order->order_status), and $arg2 is simply the new order
  *       status ID. Return FALSE to stop the update for some reason.
- *   - update: Called when an order's status is changed. $arg1 is the order
- *       object with the old order status ID ($arg1->order_status), and $arg2 is
+ *   - update: Called when an order's status is changed. $order is the order
+ *       object with the old order status ID ($order->order_status), and $arg2 is
  *       the new order status ID.
  *   - can_delete: Called before an order is deleted to verify that the order may
  *       be deleted. Returning FALSE will prevent a delete from happening. (For
  *       example, the payment module returns FALSE by default when an order has
  *       already received payments.)
  *   - delete: Called when an order is deleted and before the rest of the order
- *       information is removed from the database. Passes $arg1 as the order
+ *       information is removed from the database. Passes $order as the order
  *       object to let your module clean up it's tables.
  *   - total: Called when the total for an order is being calculated after the
- *       total of the products has been added. Passes $arg1 as the order object.
+ *       total of the products has been added. Passes $order as the order object.
  *       Expects in return a value (positive or negative) by which to modify the
  *       order total.
  */
-function hook_uc_order($op, &$arg1, $arg2) {
+function hook_uc_order($op, &$order, $arg2) {
   switch ($op) {
     case 'save':
       // Do something to save payment info!

=== modified file 'uc_order/uc_order.js'
--- uc_order/uc_order.js	2010-04-07 16:15:47 +0000
+++ uc_order/uc_order.js	2010-06-03 19:32:27 +0000
@@ -262,180 +262,6 @@
 }
 
 /**
- * Load the products div on the order edit screen.
- */
-function uc_order_load_product_edit_div(order_id) {
-  jQuery(document).ready(
-    function() {
-      add_order_save_hold();
-
-      show_product_throbber();
-
-      jQuery.post(Drupal.settings.ucURL.adminOrders + order_id + '/products',
-        { action: 'view' },
-        function(contents) {
-        if (contents != '') {
-           jQuery('#products-container').empty().append(contents);
-        }
-        remove_order_save_hold();
-        hide_product_throbber();
-      });
-    }
-  );
-}
-
-/**
- * Load the product selection form.
- */
-function load_product_select(order_id, search) {
-  if (search == true) {
-    options = {'search' : jQuery('#edit-product-search').val()};
-  }
-  else {
-    options = { };
-  }
-
-  show_product_throbber();
-
-  jQuery.post(Drupal.settings.ucURL.adminOrders + order_id + '/product_select', options,
-    function (contents) {
-      jQuery('#products-selector').empty().addClass('product-select-box2').append(contents);
-      hide_product_throbber();
-    }
-  );
-
-  return false;
-}
-
-/**
- * Deprecated?
- */
-function select_product() {
-  add_product_form();
-  return false;
-}
-
-/**
- * Hide product selection form.
- */
-function close_product_select() {
-  jQuery('#products-selector').empty().removeClass('product-select-box2');
-  return false;
-}
-
-/**
- * Load the quantity and other extra product fields.
- */
-function add_product_form() {
-  add_product_browser = jQuery('#products-selector').html();
-
-  show_product_throbber();
-
-  if (parseInt(jQuery('#edit-unid').val()) > 0) {
-    jQuery.post(Drupal.settings.ucURL.adminOrders + jQuery('#edit-order-id').val() + '/add_product/' + jQuery('#edit-unid').val(), { },
-      function(contents) {
-        jQuery('#products-selector').empty().append(contents);
-        hide_product_throbber();
-      }
-    );
-  }
-}
-
-/**
- * Add the selected product to the order.
- */
-function add_product_to_order(order_id, node_id) {
-  var post_vars = fetch_product_data();
-  post_vars['action'] = 'add';
-  post_vars['nid'] = node_id;
-  post_vars['qty'] = jQuery('#edit-add-qty').val();
-
-  jQuery('#uc-order-add-product-form :input').not(':radio:not(:checked), :checkbox:not(:checked)').each(
-    function() {
-      post_vars[jQuery(this).attr('name')] = jQuery(this).val();
-    }
-  );
-
-  show_product_throbber();
-
-  jQuery.post(Drupal.settings.ucURL.adminOrders + order_id + '/products', post_vars,
-    function(contents) {
-      if (contents != '') {
-        jQuery('#products-container').empty().append(contents);
-      }
-      hide_product_throbber();
-    }
-  );
-
-  jQuery('#add-product-button').click();
-
-  return false;
-}
-
-/**
- * Gather all of the products' data fields into one array.
- */
-function fetch_product_data() {
-  var pdata = { };
-
-  jQuery('.order-pane-table :input').each(
-    function() {
-      pdata[jQuery(this).attr('name')] = jQuery(this).val();
-    }
-  );
-  jQuery('.order-pane-table ~ :input').each(
-    function() {
-      pdata[jQuery(this).attr('name')] = jQuery(this).val();
-    }
-  );
-
-  return pdata;
-}
-
-/**
- * Button to create a new row of empty data fields.
- */
-function add_blank_line_button(order_id) {
-  var post_vars = fetch_product_data();
-  post_vars['action'] = 'add_blank';
-
-  show_product_throbber();
-
-  jQuery.post(Drupal.settings.ucURL.adminOrders + order_id + '/products',
-    post_vars,
-    function(contents) {
-      if (contents != '') {
-        jQuery('#products-container').empty().append(contents);
-      }
-      hide_product_throbber();
-    }
-  );
-}
-
-/**
- * Button to remove product from the order.
- */
-function remove_product_button(message, opid) {
-  if (confirm(message)) {
-    var post_vars = fetch_product_data();
-    post_vars['action'] = 'remove';
-    post_vars['opid'] = opid;
-
-    show_product_throbber();
-
-    jQuery.post(Drupal.settings.ucURL.adminOrders + jQuery('#edit-order-id').val() + '/products',
-      post_vars,
-      function(contents) {
-        if (contents != '') {
-          jQuery('#products-container').empty().append(contents);
-        }
-        hide_product_throbber();
-      }
-    );
-  }
-}
-
-/**
  * Prevent mistakes by confirming deletion.
  */
 function confirm_line_item_delete(message, img_id) {
@@ -472,17 +298,3 @@
   jQuery('#uc-order-edit-form input.save-button').removeAttr('disabled');
 }
 
-/**
- * User feedback that something is happening.
- */
-function show_product_throbber() {
-  jQuery('#product-div-throbber').attr('style', 'background-image: url(' + Drupal.settings.basePath + 'misc/throbber.gif); background-repeat: no-repeat; background-position: 100% -20px;').html('&nbsp;&nbsp;&nbsp;&nbsp;');
-}
-
-/**
- * Done loading forms.
- */
-function hide_product_throbber() {
-  jQuery('#product-div-throbber').removeAttr('style').empty();
-}
-

=== modified file 'uc_order/uc_order.line_item.inc'
--- uc_order/uc_order.line_item.inc	2010-05-18 20:14:02 +0000
+++ uc_order/uc_order.line_item.inc	2010-06-03 15:57:46 +0000
@@ -15,70 +15,28 @@
 /**
  * Handle the subtotal line item.
  */
-function uc_line_item_subtotal($op, $arg1) {
+function uc_line_item_subtotal($op, $order) {
   switch ($op) {
     case 'load':
       $lines[] = array(
         'id' => 'subtotal',
         'title' => t('Subtotal'),
-        'amount' => uc_order_get_total($arg1, TRUE),
+        'amount' => uc_order_get_total($order, TRUE),
       );
       return $lines;
-    case 'cart-preview':
-      if (module_exists('uc_payment') && variable_get('uc_pane_payment_enabled', TRUE)) {
-        $context = array(
-          'revision' => 'altered',
-          'type' => 'cart_item',
-        );
-        $subtotal = 0;
-        foreach ($arg1 as $item) {
-          $price_info = array(
-            'price' => $item->price,
-            'qty' => ($item->qty) ? $item->qty : 1,
-          );
-          $context['subject'] = array(
-            'cart_item' => $item,
-            'node' => node_load($item->nid),
-          );
-          $total = uc_price($price_info, $context);
-          $subtotal += $total;
-        }
-
-        $line_item = array(
-          'type' => 'subtotal',
-          'name' => t('Subtotal'),
-          'amount' => $subtotal,
-          'weight' => -10,
-        );
-
-        $order = new stdClass();
-        $order->products = $arg1;
-
-        $context = array(
-          'revision' => 'altered',
-          'type' => 'line_item',
-          'subject' => array(
-            'order' => $order,
-            'line_item' => $line_item,
-          ),
-        );
-
-        drupal_add_js("jQuery(document).ready( function() { set_line_item('subtotal', '" . $line_item['name'] . "', " . uc_price($line_item['amount'], $context) . ", " . $line_item['weight'] . "); } );", 'inline');
-      }
-      break;
   }
 }
 
 /**
  * Handle the total line item.
  */
-function uc_line_item_total($op, $arg1) {
+function uc_line_item_total($op, $order) {
   switch ($op) {
     case 'display':
       $lines[] = array(
         'id' => 'total',
         'title' => t('Total'),
-        'amount' => uc_order_get_total($arg1),
+        'amount' => uc_order_get_total($order),
       );
       return $lines;
   }

=== modified file 'uc_order/uc_order.module'
--- uc_order/uc_order.module	2010-05-18 20:14:02 +0000
+++ uc_order/uc_order.module	2010-05-24 20:44:27 +0000
@@ -15,6 +15,50 @@
 require_once('uc_order.line_item.inc');
 require_once('uc_order.ca.inc');
 
+class UcOrder {
+
+  public $order_id = 0;
+  public $uid = 0;
+  public $order_status = '';
+  public $order_total = 0;
+  public $primary_email = '';
+
+  public $delivery_first_name = '';
+  public $delivery_last_name = '';
+  public $delivery_phone = '';
+  public $delivery_company = '';
+  public $delivery_street1 = '';
+  public $delivery_street2 = '';
+  public $delivery_city = '';
+  public $delivery_zone = 0;
+  public $delivery_postal_code = '';
+  public $delivery_country = 0;
+
+  public $billing_first_name = '';
+  public $billing_last_name = '';
+  public $billing_phone = '';
+  public $billing_company = '';
+  public $billing_street1 = '';
+  public $billing_street2 = '';
+  public $billing_city = '';
+  public $billing_zone = 0;
+  public $billing_postal_code = '';
+  public $billing_country = 0;
+
+  public $products = array();
+  public $line_items = array();
+
+  public $payment_method = '';
+  public $data = '';
+  public $created = 0;
+  public $modified = 0;
+
+  function __construct() {
+    $this->order_status = uc_order_state_default('in_checkout');
+  }
+
+}
+
 /*******************************************************************************
  * Hook Functions (Drupal)
  ******************************************************************************/
@@ -332,11 +376,15 @@
     ),
     'uc_order_edit_products_form' => array(
       'render element' => 'form',
-      'file' => 'uc_order.admin.inc',
+      'file' => 'uc_order.order_pane.inc',
     ),
     'uc_order_remove_product' => array(
       'render element' => 'form',
-      'file' => 'uc_order.admin.inc',
+      'file' => 'uc_order.order_pane.inc',
+    ),
+    'uc_order_pane_line_items' => array(
+      'render element' => 'form',
+      'file' => 'uc_order.order_pane.inc',
     ),
     'uc_order_view_update_controls' => array(
       'render element' => 'form',
@@ -871,51 +919,6 @@
   drupal_goto('admin/store/orders/search/results/' . implode('/', $args));
 }
 
-/**
- * TAPIr table for products pane on the order edit page.
- *
- * @see uc_order_edit_products_form()
- */
-function uc_op_products_edit_table() {
-  $table = array(
-    '#type' => 'tapir_table',
-    '#tree' => TRUE,
-    '#attributes' => array('class' => array('order-pane-table')),
-  );
-
-  $table['#columns']['remove'] = array(
-    'cell' => t('Remove'),
-    'weight' => 0,
-  );
-  $table['#columns']['qty'] = array(
-    'cell' => t('Qty'),
-    'weight' => 1,
-  );
-  $table['#columns']['title'] = array(
-    'cell' => t('Name'),
-    'weight' => 2,
-  );
-  $table['#columns']['model'] = array(
-    'cell' => t('SKU'),
-    'weight' => 4,
-  );
-  $table['#columns']['weight'] = array(
-    'cell' => t('Weight'),
-    'weight' => 5,
-  );
-  $table['#columns']['cost'] = array(
-    'cell' => t('Cost'),
-    'weight' => 6,
-  );
-  $table['#columns']['price'] = array(
-    'cell' => t('Price'),
-    'weight' => 7,
-  );
-
-  return $table;
-}
-
-
 /*******************************************************************************
  * Module and Helper Functions
  ******************************************************************************/

=== modified file 'uc_order/uc_order.order_pane.inc'
--- uc_order/uc_order.order_pane.inc	2010-05-18 20:25:31 +0000
+++ uc_order/uc_order.order_pane.inc	2010-06-03 19:32:27 +0000
@@ -14,14 +14,14 @@
 /**
  * Handle the "Ship to" order pane.
  */
-function uc_order_pane_ship_to($op, $arg1) {
+function uc_order_pane_ship_to($op, $order) {
   switch ($op) {
     case 'customer':
-      if (!uc_order_is_shippable($arg1)) {
+      if (!uc_order_is_shippable($order)) {
         return;
       }
     case 'view':
-      $build = array('#markup' => uc_order_address($arg1, 'delivery') . '<br />' . check_plain($arg1->delivery_phone));
+      $build = array('#markup' => uc_order_address($order, 'delivery') . '<br />' . check_plain($order->delivery_phone));
       return $build;
 
     case 'edit-form':
@@ -32,63 +32,63 @@
         '#collapsed' => FALSE,
       );
       if (uc_address_field_enabled('first_name')) {
-        $form['ship_to']['delivery_first_name'] = uc_textfield(uc_get_field_name('first_name'), $arg1->delivery_first_name, FALSE);
+        $form['ship_to']['delivery_first_name'] = uc_textfield(uc_get_field_name('first_name'), $order->delivery_first_name, FALSE);
       }
       if (uc_address_field_enabled('last_name')) {
-        $form['ship_to']['delivery_last_name'] = uc_textfield(uc_get_field_name('last_name'), $arg1->delivery_last_name, FALSE);
+        $form['ship_to']['delivery_last_name'] = uc_textfield(uc_get_field_name('last_name'), $order->delivery_last_name, FALSE);
       }
       if (uc_address_field_enabled('phone')) {
-        $form['ship_to']['delivery_phone'] = uc_textfield(uc_get_field_name('phone'), $arg1->delivery_phone, FALSE, NULL, 32, 16);
+        $form['ship_to']['delivery_phone'] = uc_textfield(uc_get_field_name('phone'), $order->delivery_phone, FALSE, NULL, 32, 16);
       }
       if (uc_address_field_enabled('company')) {
-        $form['ship_to']['delivery_company'] = uc_textfield(uc_get_field_name('company'), $arg1->delivery_company, FALSE, NULL, 64);
+        $form['ship_to']['delivery_company'] = uc_textfield(uc_get_field_name('company'), $order->delivery_company, FALSE, NULL, 64);
       }
       if (uc_address_field_enabled('street1')) {
-        $form['ship_to']['delivery_street1'] = uc_textfield(uc_get_field_name('street1'), $arg1->delivery_street1, FALSE, NULL, 64);
+        $form['ship_to']['delivery_street1'] = uc_textfield(uc_get_field_name('street1'), $order->delivery_street1, FALSE, NULL, 64);
       }
       if (uc_address_field_enabled('street2')) {
-        $form['ship_to']['delivery_street2'] = uc_textfield(uc_get_field_name('street2'), $arg1->delivery_street2, FALSE, NULL, 64);
+        $form['ship_to']['delivery_street2'] = uc_textfield(uc_get_field_name('street2'), $order->delivery_street2, FALSE, NULL, 64);
       }
       if (uc_address_field_enabled('city')) {
-        $form['ship_to']['delivery_city'] = uc_textfield(uc_get_field_name('city'), $arg1->delivery_city, FALSE);
+        $form['ship_to']['delivery_city'] = uc_textfield(uc_get_field_name('city'), $order->delivery_city, FALSE);
       }
       if (uc_address_field_enabled('country')) {
-        $form['ship_to']['delivery_country'] = uc_country_select(uc_get_field_name('country'), $arg1->delivery_country);
+        $form['ship_to']['delivery_country'] = uc_country_select(uc_get_field_name('country'), $order->delivery_country);
       }
       if (uc_address_field_enabled('zone')) {
         if (isset($_POST['delivery_country'])) {
           $country_id = intval($_POST['delivery_country']);
         }
         else {
-          $country_id = $arg1->delivery_country;
+          $country_id = $order->delivery_country;
         }
-        $form['ship_to']['delivery_zone'] = uc_zone_select(uc_get_field_name('zone'), $arg1->delivery_zone, NULL, $country_id);
+        $form['ship_to']['delivery_zone'] = uc_zone_select(uc_get_field_name('zone'), $order->delivery_zone, NULL, $country_id);
       }
       if (uc_address_field_enabled('postal_code')) {
-        $form['ship_to']['delivery_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $arg1->delivery_postal_code, FALSE, NULL, 10, 10);
+        $form['ship_to']['delivery_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $order->delivery_postal_code, FALSE, NULL, 10, 10);
       }
       return $form;
 
     case 'edit-title':
       $output = ' <img src="' . base_path() . drupal_get_path('module', 'uc_store')
                 . '/images/address_book.gif" alt="' . t('Select from address book.') . '" '
-                . 'title="' . t('Select from address book.') . '" onclick="load_address_select(' . $arg1['order_uid']['#value'] . ', \'#delivery_address_select\', \'delivery\');" '
+                . 'title="' . t('Select from address book.') . '" onclick="load_address_select(' . $order['order_uid']['#value'] . ', \'#delivery_address_select\', \'delivery\');" '
                 . 'style="position: relative; top: 2px; cursor: pointer;" />';
       return $output;
 
     case 'edit-theme':
       $output = '<div id="delivery_address_select"></div><table class="order-edit-table">';
-      foreach (element_children($arg1['ship_to']) as $field) {
-        $title = $arg1['ship_to'][$field]['#title'];
-        $arg1['ship_to'][$field]['#title'] = NULL;
+      foreach (element_children($order['ship_to']) as $field) {
+        $title = $order['ship_to'][$field]['#title'];
+        $order['ship_to'][$field]['#title'] = NULL;
         $output .= '<tr><td class="oet-label">' . $title . ':</td><td>'
-                 . drupal_render($arg1['ship_to'][$field]) . '</td></tr>';
+                 . drupal_render($order['ship_to'][$field]) . '</td></tr>';
       }
       $output .= '</table>';
       return $output;
 
     case 'edit-process':
-      foreach ($arg1 as $key => $value) {
+      foreach ($order as $key => $value) {
         if (substr($key, 0, 9) == 'delivery_') {
           if (uc_address_field_enabled(substr($key, 9))) {
             $changes[$key] = $value;
@@ -102,11 +102,11 @@
 /**
  * Handle the "Bill to" order pane.
  */
-function uc_order_pane_bill_to($op, $arg1) {
+function uc_order_pane_bill_to($op, $order) {
   switch ($op) {
     case 'view':
     case 'customer':
-      $build = array('#markup' => uc_order_address($arg1, 'billing') . '<br />' . check_plain($arg1->billing_phone));
+      $build = array('#markup' => uc_order_address($order, 'billing') . '<br />' . check_plain($order->billing_phone));
       return $build;
 
     case 'edit-form':
@@ -117,47 +117,47 @@
         '#collapsed' => FALSE,
       );
       if (uc_address_field_enabled('first_name')) {
-        $form['bill_to']['billing_first_name'] = uc_textfield(uc_get_field_name('first_name'), $arg1->billing_first_name, FALSE);
+        $form['bill_to']['billing_first_name'] = uc_textfield(uc_get_field_name('first_name'), $order->billing_first_name, FALSE);
       }
       if (uc_address_field_enabled('last_name')) {
-        $form['bill_to']['billing_last_name'] = uc_textfield(uc_get_field_name('last_name'), $arg1->billing_last_name, FALSE);
+        $form['bill_to']['billing_last_name'] = uc_textfield(uc_get_field_name('last_name'), $order->billing_last_name, FALSE);
       }
       if (uc_address_field_enabled('phone')) {
-        $form['bill_to']['billing_phone'] = uc_textfield(uc_get_field_name('phone'), $arg1->billing_phone, FALSE, NULL, 32, 16);
+        $form['bill_to']['billing_phone'] = uc_textfield(uc_get_field_name('phone'), $order->billing_phone, FALSE, NULL, 32, 16);
       }
       if (uc_address_field_enabled('company')) {
-        $form['bill_to']['billing_company'] = uc_textfield(uc_get_field_name('company'), $arg1->billing_company, FALSE, NULL, 64);
+        $form['bill_to']['billing_company'] = uc_textfield(uc_get_field_name('company'), $order->billing_company, FALSE, NULL, 64);
       }
       if (uc_address_field_enabled('street1')) {
-        $form['bill_to']['billing_street1'] = uc_textfield(uc_get_field_name('street1'), $arg1->billing_street1, FALSE, NULL, 64);
+        $form['bill_to']['billing_street1'] = uc_textfield(uc_get_field_name('street1'), $order->billing_street1, FALSE, NULL, 64);
       }
       if (uc_address_field_enabled('street2')) {
-        $form['bill_to']['billing_street2'] = uc_textfield(uc_get_field_name('street2'), $arg1->billing_street2, FALSE, NULL, 64);
+        $form['bill_to']['billing_street2'] = uc_textfield(uc_get_field_name('street2'), $order->billing_street2, FALSE, NULL, 64);
       }
       if (uc_address_field_enabled('city')) {
-        $form['bill_to']['billing_city'] = uc_textfield(uc_get_field_name('city'), $arg1->billing_city, FALSE);
+        $form['bill_to']['billing_city'] = uc_textfield(uc_get_field_name('city'), $order->billing_city, FALSE);
       }
       if (uc_address_field_enabled('country')) {
-        $form['bill_to']['billing_country'] = uc_country_select(uc_get_field_name('country'), $arg1->billing_country);
+        $form['bill_to']['billing_country'] = uc_country_select(uc_get_field_name('country'), $order->billing_country);
       }
       if (uc_address_field_enabled('zone')) {
         if (isset($_POST['billing_country'])) {
           $country_id = intval($_POST['billing_country']);
         }
         else {
-          $country_id = $arg1->billing_country;
+          $country_id = $order->billing_country;
         }
-        $form['bill_to']['billing_zone'] = uc_zone_select(uc_get_field_name('zone'), $arg1->billing_zone, NULL, $country_id);
+        $form['bill_to']['billing_zone'] = uc_zone_select(uc_get_field_name('zone'), $order->billing_zone, NULL, $country_id);
       }
       if (uc_address_field_enabled('postal_code')) {
-        $form['bill_to']['billing_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $arg1->billing_postal_code, FALSE, NULL, 10, 10);
+        $form['bill_to']['billing_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $order->billing_postal_code, FALSE, NULL, 10, 10);
       }
       return $form;
 
     case 'edit-title':
       $output = ' <img src="' . base_path() . drupal_get_path('module', 'uc_store')
                 . '/images/address_book.gif" alt="' . t('Select from address book.') . '" '
-                . 'title="' . t('Select from address book.') . '" onclick="load_address_select(' . $arg1['order_uid']['#value'] . ', \'#billing_address_select\', \'billing\');" '
+                . 'title="' . t('Select from address book.') . '" onclick="load_address_select(' . $order['order_uid']['#value'] . ', \'#billing_address_select\', \'billing\');" '
                 . 'style="position: relative; top: 2px; cursor: pointer;" />';
       $output .= ' <img src="' . base_path() . drupal_get_path('module', 'uc_store')
                . '/images/copy.gif" alt="' . t('Copy shipping information.') . '" title="'
@@ -167,17 +167,17 @@
 
     case 'edit-theme':
       $output = '<div id="billing_address_select"></div><table class="order-edit-table">';
-      foreach (element_children($arg1['bill_to']) as $field) {
-        $title = $arg1['bill_to'][$field]['#title'];
-        $arg1['bill_to'][$field]['#title'] = NULL;
+      foreach (element_children($order['bill_to']) as $field) {
+        $title = $order['bill_to'][$field]['#title'];
+        $order['bill_to'][$field]['#title'] = NULL;
         $output .= '<tr><td class="oet-label">' . $title . ':</td><td>'
-                 . drupal_render($arg1['bill_to'][$field]) . '</td></tr>';
+                 . drupal_render($order['bill_to'][$field]) . '</td></tr>';
       }
       $output .= '</table>';
       return $output;
 
     case 'edit-process':
-      foreach ($arg1 as $key => $value) {
+      foreach ($order as $key => $value) {
         if (substr($key, 0, 8) == 'billing_') {
           if (uc_address_field_enabled(substr($key, 8))) {
             $changes[$key] = $value;
@@ -191,11 +191,11 @@
 /**
  * Handle the "Customer Info" order pane.
  */
-function uc_order_pane_customer($op, $arg1) {
+function uc_order_pane_customer($op, $order) {
   switch ($op) {
     case 'view':
-      $build['uid'] = array('#markup' => t('Customer number: !user_link', array('!user_link' => $arg1->uid ? l($arg1->uid, 'user/' . $arg1->uid) : '0')));
-      $build['primary_email'] = array('#markup' => '<br />' . t('Primary e-mail:') . '<br />' . check_plain($arg1->primary_email));
+      $build['uid'] = array('#markup' => t('Customer number: !user_link', array('!user_link' => $order->uid ? l($order->uid, 'user/' . $order->uid) : '0')));
+      $build['primary_email'] = array('#markup' => '<br />' . t('Primary e-mail:') . '<br />' . check_plain($order->primary_email));
 
       return $build;
 
@@ -208,24 +208,24 @@
       );
       $form['customer']['uid'] = array(
         '#type' => 'hidden',
-        '#default_value' => $arg1->uid,
+        '#default_value' => $order->uid,
       );
       $form['customer']['text']['uid_text'] = array(
         '#type' => 'textfield',
         '#title' => t('Customer number'),
-        '#default_value' => $arg1->uid,
+        '#default_value' => $order->uid,
         '#maxlength' => 10,
         '#size' => 10,
         '#disabled' => TRUE,
       );
       $form['customer']['primary_email'] = array(
         '#type' => 'hidden',
-        '#default_value' => $arg1->primary_email,
+        '#default_value' => $order->primary_email,
       );
       $form['customer']['text']['primary_email_text'] = array(
         '#type' => 'textfield',
         '#title' => t('Primary e-mail'),
-        '#default_value' => $arg1->primary_email,
+        '#default_value' => $order->primary_email,
         '#maxlength' => 64,
         '#size' => 32,
         '#disabled' => TRUE,
@@ -245,19 +245,19 @@
 
     case 'edit-theme':
       $output = '<div id="customer-select"></div><table class="order-edit-table">';
-      foreach (element_children($arg1['customer']['text']) as $field) {
-        $title = $arg1['customer']['text'][$field]['#title'];
-        $arg1['customer']['text'][$field]['#title'] = NULL;
+      foreach (element_children($order['customer']['text']) as $field) {
+        $title = $order['customer']['text'][$field]['#title'];
+        $order['customer']['text'][$field]['#title'] = NULL;
         $output .= '<tr><td class="oet-label">' . $title . ':</td><td>'
-                 . drupal_render($arg1['customer']['text'][$field]) . '</td></tr>';
+                 . drupal_render($order['customer']['text'][$field]) . '</td></tr>';
       }
-      $output .= '</table>' . drupal_render($arg1['customer']['primary_email'])
-               . drupal_render($arg1['customer']['uid']);
+      $output .= '</table>' . drupal_render($order['customer']['primary_email'])
+               . drupal_render($order['customer']['uid']);
       return $output;
 
     case 'edit-process':
-      $changes['uid'] = $arg1['uid'];
-      $changes['primary_email'] = $arg1['primary_email'];
+      $changes['uid'] = $order['uid'];
+      $changes['primary_email'] = $order['primary_email'];
       return $changes;
   }
 }
@@ -265,59 +265,465 @@
 /**
  * Handle the "Products" order pane.
  */
-function uc_order_pane_products($op, $arg1) {
+function uc_order_pane_products($op, $order, $form = NULL, &$form_state = NULL) {
   switch ($op) {
     case 'view':
-      return tapir_get_table('uc_op_products_view_table', $arg1);
+      return tapir_get_table('uc_op_products_view_table', $order);
 
     case 'customer':
-      return tapir_get_table('uc_op_products_customer_table', $arg1);
+      return tapir_get_table('uc_op_products_customer_table', $order);
+
+    case 'edit-form':
+      $form['add_product_button'] = array(
+        '#type' => 'submit',
+        '#value' => t('Add product'),
+        '#submit' => array('uc_order_pane_products_select'),
+        '#ajax' => array(
+          'callback' => 'uc_order_pane_products_ajax_callback',
+          'wrapper' => 'product-controls',
+        ),
+      );
+      $form['add_blank_line_button'] = array(
+        '#type' => 'submit',
+        '#value' => t('Add blank line'),
+        '#submit' => array('uc_order_edit_products_add_blank'),
+        '#ajax' => array(
+          'callback' => 'uc_order_pane_products_ajax_callback',
+          'wrapper' => 'product-controls',
+        ),
+      );
+
+      $form['product_controls'] = array(
+        '#tree' => TRUE,
+        '#prefix' => '<div id="product-controls">',
+        '#suffix' => '</div>',
+      );
+
+      $controls = array();
+
+      if (isset($form_state['products_action'])) {
+        switch ($form_state['products_action']) {
+          case 'select':
+            $controls = uc_order_product_select_form($form['product_controls'], $form_state, $order);
+            break;
+          case 'add_product':
+            $controls = uc_order_add_product_form($form['product_controls'], $form_state, $order, $form_state['node']);
+            break;
+        }
+      }
+
+      $form['product_controls'] += $controls;
+
+      $form += uc_order_edit_products_form($form, $form_state, $order->products);
+
+      return $form;
 
     case 'edit-theme':
-      drupal_add_js('uc_order_load_product_edit_div(' . $arg1['order_id']['#value'] . ');', 'inline');
-
-      $output = '<div id="products-selector"></div>'
-               . '<div id="products-container">' . t('Loading product information... (<em>If nothing happens, make sure you have Javascript enabled.</em>)') . '</div>';
-      return $output;
-
-    case 'edit-title':
-      $settings = array(
-        'div' => '#products-selector',
-        'class' => 'product-select-box',
-        'vid' => variable_get('uc_catalog_vid', 0),
-        'filter' => implode(',', uc_product_types()),
-        'search' => 'true',
-        'nids' => 'true',
-        'close' => 'true',
-        'nodesg' => 'product',
-        'nodepl' => 'products',
-        'select' => 'add_product_form();',
-      );
-
-      $output = '<input type="button" value="' . t('Add product')
-               . '" onclick="load_product_select(' . $arg1['order_id']['#value']
-               . ', false);" id="add-product-button" />';
-
-      $output .= '<input type="button" value="' . t('Add blank line')
-                . '" onclick="add_blank_line_button(' . $arg1['order_id']['#value']
-                . ');" />';
-      $output .= ' <span id="product-div-throbber"></span>';
-      return $output;
-  }
+      $output = drupal_render($order['add_product_button']);
+      $output .= drupal_render($order['add_blank_line_button']);
+      $output .= drupal_render($order['product_controls']);
+      $output .= drupal_render($order['products']);
+
+      return $output;
+
+    case 'edit-process':
+      if (isset($form_state['values']['products'])) {
+        foreach ($form_state['values']['products'] as $key => $product) {
+          $product['data'] = unserialize($product['data']);
+          uc_order_product_save($order->order_id, (object) $product);
+        }
+      }
+
+      break;
+  }
+}
+
+/**
+ * Form to choose a product to add to the order.
+ */
+function uc_order_product_select_form($form, &$form_state, $order) {
+  $options = $form_state['product_select_options'];
+  $ajax = array(
+    'callback' => 'uc_order_pane_products_ajax_callback',
+    'wrapper' => 'product-controls',
+  );
+
+  $form['nid'] = array(
+    '#type' => 'select',
+    '#title' => t('Select a product'),
+    '#options' => $options,
+    '#size' => 7,
+    '#ajax' => $ajax + array(
+      'event' => 'dblclick',
+      'trigger_as' => array(
+        'name' => 'op',
+        'value' => t('Select'),
+      ),
+    ),
+  );
+  $form['product_search'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Search by name or model/SKU (* is the wildcard)'),
+  );
+
+  $form['buttons']['select'] = array(
+    '#type' => 'submit',
+    '#value' => t('Select'),
+    '#submit' => array('uc_order_pane_products_add'),
+    '#ajax' => $ajax,
+    '#weight' => 0,
+  );
+  $form['buttons']['search'] = array(
+    '#type' => 'submit',
+    '#value' => t('Search'),
+    '#submit' => array('uc_order_pane_products_select'),
+    '#ajax' => $ajax,
+    '#weight' => 1,
+  );
+  $form['buttons']['close'] = array(
+    '#type' => 'submit',
+    '#value' => t('Close'),
+    '#submit' => array('uc_order_pane_products_close'),
+    '#ajax' => $ajax,
+    '#weight' => 2,
+  );
+
+  return $form;
+}
+
+/**
+ * Intermediate div that lets you set the qty and attributes for a product.
+ *
+ * @see uc_order_add_product_form()
+ */
+function uc_order_add_product($order, $product) {
+  $build = array();
+  $build['form'] = drupal_get_form('uc_order_add_product_form', $order, $product) + array(
+    '#prefix' => '<div style="margin: 1em;"><strong>Add ' . check_plain($product->title) . '</strong>',
+    '#suffix' => '</div>',
+  );
+
+  print drupal_render($build);
+  exit();
+}
+
+/**
+ * Set the quantity and attributes of a product added to the order.
+ *
+ * @see uc_order_add_product_form()
+ */
+function uc_order_add_product_form($form, &$form_state, $order, $node) {
+  $form['nid'] = array(
+    '#type' => 'hidden',
+    '#value' => $node->nid,
+  );
+  $form['qty'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Qty'),
+    '#default_value' => '1',
+    '#size' => 2,
+    '#maxlength' => 5,
+  );
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Add to order'),
+    '#submit' => array('uc_order_edit_products_add', 'uc_order_edit_form_submit'),
+  );
+  $form['cancel'] = array(
+    '#type' => 'submit',
+    '#value' => t('Cancel'),
+    '#submit' => array('uc_order_pane_products_select'),
+    '#ajax' =>  array(
+      'callback' => 'uc_order_pane_products_ajax_callback',
+      'wrapper' => 'product-controls',
+    ),
+  );
+  $form['node'] = array(
+    '#type' => 'value',
+    '#value' => $node,
+  );
+
+  uc_form_alter($form, $form_state, __FUNCTION__);
+
+  return $form;
+}
+
+/**
+ * Form to allow ordered products' data to be changed.
+ *
+ * @see
+ *   uc_op_products_edit_table()
+ *   theme_uc_order_edit_products_form()
+ *   theme_uc_order_remove_product()
+ */
+function uc_order_edit_products_form($form, &$form_state, $products) {
+  if (($product_count = count($products)) > 0) {
+    $form['products'] = tapir_get_table('uc_op_products_edit_table');
+    for ($i = 0; $i < $product_count; $i++) {
+      $form['products'][$i]['remove'] = array(
+        '#type' => 'image_button',
+        '#title' => t('Remove this product.'),
+        '#src' => drupal_get_path('module', 'uc_store') . '/images/error.gif',
+        '#attributes' => array(
+          'style' => 'padding-top: 1px; padding-left: .8em; padding-right: 2px; float: left; cursor: pointer;',
+        ),
+        '#submit' => array('uc_order_edit_products_remove', 'uc_order_edit_form_submit'),
+        '#return_value' => $products[$i]->order_product_id,
+      );
+      $form['products'][$i]['order_product_id'] = array(
+        '#type' => 'hidden',
+        '#value' => $products[$i]->order_product_id,
+      );
+      $form['products'][$i]['nid'] = array(
+        '#type' => 'hidden',
+        '#value' => $products[$i]->nid,
+      );
+      $form['products'][$i]['qty'] = array(
+        '#type' => 'textfield',
+        '#default_value' => $products[$i]->qty,
+        '#size' => 2,
+        '#maxlength' => 6,
+      );
+      $form['products'][$i]['title'] = array(
+        '#type' => 'textfield',
+        '#default_value' => $products[$i]->title,
+        '#size' => 30,
+      );
+      $form['products'][$i]['model'] = array(
+        '#type' => 'textfield',
+        '#default_value' => $products[$i]->model,
+        '#size' => 6,
+      );
+      $form['products'][$i]['weight'] = array(
+        '#type' => 'textfield',
+        '#default_value' => $products[$i]->weight,
+        '#size' => 3,
+      );
+      $form['products'][$i]['cost'] = array(
+        '#type' => 'textfield',
+        '#default_value' => uc_store_format_price_field_value($products[$i]->cost),
+        '#size' => 5,
+      );
+      $form['products'][$i]['price'] = array(
+        '#type' => 'textfield',
+        '#default_value' => uc_store_format_price_field_value($products[$i]->price),
+        '#size' => 5,
+      );
+      $form['products'][$i]['data'] = array(
+        '#type' => 'hidden',
+        '#value' => serialize($products[$i]->data),
+      );
+    }
+  }
+  else {
+    $form['products'][]['remove'] = array(
+      '#value' => t('This order contains no products.'),
+      '#cell_attributes' => array('colspan' => 'full'),
+    );
+  }
+
+  return $form;
+}
+
+/**
+ * @ingroup themeable
+ * @see uc_order_edit_products_form()
+ */
+function theme_uc_order_edit_products_form($variables) {
+  return drupal_render_children($variables['form']);
+}
+
+/**
+ * Format the button to remove products from an order.
+ *
+ * @ingroup themeable
+ * @see uc_op_products_edit_table()
+ */
+function theme_uc_order_remove_product($variables) {
+  $form = $variables['form'];
+
+  return '<img id="' . $form['#return_value'] . '" src="'
+    . $form['#src'] . '" style="padding-top: 1px; padding-left: .8em; '
+    . 'padding-right: 2px; float: left; cursor: pointer;" '
+    . 'alt="' . t('Remove this product.') . '" />'
+    . drupal_render_children($form);
+}
+
+/**
+ * Set the order pane to show the product selection form.
+ */
+function uc_order_pane_products_select($form, &$form_state) {
+  $types = uc_product_types();
+  $options = array();
+
+  if (!empty($form_state['values']['product_controls']['product_search'])) {
+    $search = strtolower(str_replace('*', '%', $form_state['values']['product_controls']['product_search']));
+    $search_args = array(
+      ':types' => $types,
+      ':title' => $search,
+      ':model' => $search,
+    );
+
+    $result = db_query("SELECT n.nid, n.title FROM {node} AS n LEFT JOIN "
+      . "{uc_products} AS p ON n.nid = p.nid WHERE n.type IN "
+      . "(:types) AND (n.title LIKE :title OR p.model LIKE :model)"
+      . " ORDER BY n.title", $search_args);
+  }
+  else {
+    $result = db_query("SELECT nid, title FROM {node} WHERE type IN (:types) ORDER BY title", array(':types' => $types));
+  }
+  foreach ($result as $row) {
+    $options[$row->nid] = $row->title;
+  }
+
+  if (count($options) == 0) {
+    $options[0] = t('No products found.');
+  }
+
+  $form_state['products_action'] = 'select';
+  $form_state['product_select_options'] = $options;
+  unset($form_state['refresh_products']);
+}
+
+/**
+ * Set the order pane to show the add product to order form.
+ */
+function uc_order_pane_products_add($form, &$form_state) {
+  $form_state['products_action'] = 'add_product';
+  $form_state['node'] = node_load($form_state['values']['product_controls']['nid']);
+  unset($form_state['refresh_products']);
+}
+
+/**
+ * Hide the form to add another product to the order.
+ */
+function uc_order_pane_products_close($form, &$form_state) {
+  unset($form_state['products_action']);
+  unset($form_state['refresh_products']);
+  unset($form_state['product_seelct_options']);
+}
+
+/**
+ * Populate the product add/edit div on the order edit screen.
+ */
+function uc_order_edit_products_add_blank($form, &$form_state) {
+  $form_state['refresh_products'] = TRUE;
+
+  $order = $form_state['build_info']['args'][0];
+
+  $product = new stdClass();
+  $product->qty = 1;
+  $product->order_id = $order->order_id;
+  drupal_write_record('uc_order_products', $product);
+
+  $order->products[] = $product;
+
+  if (variable_get('uc_order_logging', TRUE)) {
+    uc_order_log_changes($order->order_id, array('add' => t('Added new product line to order.')));
+  }
+}
+
+function uc_order_edit_products_add($form, &$form_state) {
+  $form_state['products_action'] = 'products_select';
+  $form_state['refresh_products'] = TRUE;
+  $order = $form_state['build_info']['args'][0];
+
+  $product = node_load(intval($form_state['values']['product_controls']['nid']));
+  $product->qty = isset($form_state['values']['product_controls']['qty']) ? $form_state['values']['product_controls']['qty'] : $product->default_qty;
+  $product->price = $product->sell_price;
+  $product->data = module_invoke_all('uc_add_to_cart_data', $form_state['values']['product_controls']);
+
+  foreach (module_implements('uc_cart_item') as $module) {
+    $function = $module . '_uc_cart_item';
+    if (function_exists($function)) {
+      // $product must be passed by reference.
+      $function('load', $product);
+    }
+  }
+
+  $price_info = array(
+    'price' => $product->price,
+    'qty' => 1,
+  );
+  $context = array(
+    'revision' => 'original',
+    'type' => 'order_product',
+    'subject' => array(
+      'order' => $order,
+      'product' => $product,
+      'node' => clone $product,
+    ),
+  );
+  $product->price = uc_price($price_info, $context);
+
+  drupal_alter('uc_order_product', $product, $order);
+  uc_order_product_save($order->order_id, $product);
+  $order->products[] = $product;
+
+  if (variable_get('uc_order_logging', TRUE)) {
+    uc_order_log_changes($order->order_id, array('add' => t('Added (@qty) @title to order.', array('@qty' => $product->qty, '@title' => $product->title))));
+  }
+
+  // Decrement stock.
+  if (module_exists('uc_stock')) {
+    uc_stock_adjust_product_stock($product, 0, $order);
+  }
+
+  // Add this product to the form values for accurate tax calculations.
+  $form_state['values']['products'][] = (array) $product;
+}
+
+function uc_order_edit_products_remove($form, &$form_state) {
+  $form_state['refresh_products'] = TRUE;
+
+  $order_product_id = intval($form_state['triggering_element']['#return_value']);
+
+  // Put back the stock.
+  if (module_exists('uc_stock')) {
+    $product = db_query("SELECT model, qty FROM {uc_order_products} WHERE order_product_id = :id", array(':id' => $order_product_id))->fetchObject();
+    uc_stock_adjust($product->model, $product->qty);
+  }
+  db_delete('uc_order_products')
+    ->condition('order_product_id', $order_product_id)
+    ->execute();
+
+  $order = $form_state['build_info']['args'][0];
+  $matches = array();
+  preg_match('/products\[(\d+)\]/', $form_state['triggering_element']['#name'], $matches);
+  $key = $matches[1];
+
+  unset($order->products[$key]);
+  $order->products = array_values($order->products);
+}
+
+/**
+ * AJAX callback to render the order product controls.
+ */
+function uc_order_pane_products_ajax_callback($form, &$form_state) {
+  $commands[] = ajax_command_replace('#product-controls', drupal_render($form['product_controls']));
+  $commands[] = ajax_command_prepend('#product-controls', theme('status_messages'));
+
+  if (isset($form_state['refresh_products']) && $form_state['refresh_products']) {
+    $commands[] = ajax_command_replace('#order-edit-products', drupal_render($form['products']));
+    $commands[] = ajax_command_replace('#order-line-items', drupal_render($form['line_items']));
+    $commands[] = ajax_command_prepend('#order-edit-products', theme('status_messages'));
+  }
+
+  return array('#type' => 'ajax', '#commands' => $commands);
 }
 
 /**
  * Handle the "Line Items" order pane.
  */
-function uc_order_pane_line_items($op, $arg1) {
+function uc_order_pane_line_items($op, $order) {
   switch ($op) {
     case 'view':
     case 'customer':
-      $line_items = $arg1->line_items;
+      $line_items = $order->line_items;
       $items = _uc_line_item_list();
       foreach ($items as $item) {
         if (isset($item['display_only']) && $item['display_only'] == TRUE) {
-          $result = $item['callback']('display', $arg1);
+          $result = $item['callback']('display', $order);
           if (is_array($result)) {
             foreach ($result as $line) {
               $line_items[] = array(
@@ -335,7 +741,7 @@
         'revision' => 'themed',
         'type' => 'line_item',
         'subject' => array(
-          'order' => $arg1,
+          'order' => $order,
         ),
       );
 
@@ -373,13 +779,13 @@
     case 'edit-form':
       $options = array();
       $items = _uc_line_item_list();
-      $line_items = $arg1->line_items;
+      $line_items = $order->line_items;
       foreach ($items as $item) {
         if (isset($item['add_list']) && $item['add_list'] === TRUE) {
           $options[$item['id']] = check_plain($item['title']);
         }
         if (isset($item['display_only']) && $item['display_only'] == TRUE) {
-          $result = $item['callback']('display', $arg1);
+          $result = $item['callback']('display', $order);
           if (is_array($result)) {
             foreach ($result as $line) {
               $line_items[] = array(
@@ -415,18 +821,17 @@
         '#type' => 'hidden',
       );
       $form['line_items'] = array(
-        '#type' => 'fieldset',
-        '#title' => t("Modify 'line items'"),
-        '#collapsible' => TRUE,
-        '#collapsed' => FALSE,
         '#tree' => TRUE,
+        '#theme' => 'uc_order_pane_line_items',
+        '#prefix' => '<div id="order-line-items">',
+        '#suffix' => '</div>',
       );
 
       $context = array(
         'revision' => 'themed',
         'type' => 'line_item',
         'subject' => array(
-          'order' => $arg1,
+          'order' => $order,
         ),
       );
       foreach ($line_items as $item) {
@@ -472,64 +877,89 @@
       return $form;
 
     case 'edit-theme':
-      $arg1['add_line_item']['li_type_select']['#title'] = '';
+      $order['add_line_item']['li_type_select']['#title'] = '';
       $output = '<table class="full-width"><tr><td>';
       $output .= '<table><tr><td colspan="2"><b>' . t('Add a line item')
-                . ': </b></td></tr><tr><td>' . drupal_render($arg1['add_line_item']['li_type_select'])
-                . ' </td><td>' . drupal_render($arg1['add_line_item']['submit'])
+                . ': </b></td></tr><tr><td>' . drupal_render($order['add_line_item']['li_type_select'])
+                . ' </td><td>' . drupal_render($order['add_line_item']['submit'])
                 . '</td></tr></table>';
-      $output .= '</td><td>' . drupal_render($arg1['li_delete_id'])
-                . '<table class="line-item-table">';
-      foreach (element_children($arg1['line_items']) as $field) {
-        $arg1['line_items'][$field]['title']['#title'] = '';
-        $arg1['line_items'][$field]['amount']['#title'] = '';
-        $output .= '<tr><td class="li-title">'
-                 . drupal_render($arg1['line_items'][$field]['li_id'])
-                 . drupal_render($arg1['line_items'][$field]['title'])
-                  . ':</td><td class="li-amount" nowrap>'
-                 . drupal_render($arg1['line_items'][$field]['amount'])
-                  . '</td></tr>';
-      }
-      $output .= '</table></td></tr></table>';
+      $output .= '</td><td>' . drupal_render($order['li_delete_id'])
+                . drupal_render($order['line_items']) . '</td></tr></table>';
       return $output;
 
     case 'edit-process':
-      if (is_array($arg1['line_items'])) {
-        foreach ($arg1['line_items'] as $line) {
-          if (is_numeric($line['li_id']) && intval($line['li_id']) > 0) {
-            uc_order_update_line_item($line['li_id'], $line['title'], $line['amount']);
-          }
-        }
-      }
-      if (intval($arg1['li_delete_id']) > 0) {
-        uc_order_delete_line_item($arg1['li_delete_id']);
-        drupal_set_message(t('Line item removed.'));
-      }
+      uc_order_pane_line_items_submit($form, $form_state);
       return;
 
     case 'edit-ops':
       return array(t('Add line'));
 
     case t('Add line'):
-      drupal_goto('admin/store/orders/' . $arg1['order_id']
-                 . '/add_line_item/' . $arg1['li_type_select']);
-  }
+      drupal_goto('admin/store/orders/' . $order['order_id']
+                 . '/add_line_item/' . $order['li_type_select']);
+  }
+}
+
+function theme_uc_order_pane_line_items($variables) {
+  $form = $variables['form'];
+
+  $output = '<table class="line-item-table">';
+  foreach (element_children($form) as $field) {
+    $form[$field]['title']['#title'] = '';
+    $form[$field]['amount']['#title'] = '';
+    $output .= '<tr><td class="li-title">'
+      . drupal_render($form[$field]['li_id'])
+      . drupal_render($form[$field]['title'])
+      . ':</td><td class="li-amount" nowrap>'
+      . drupal_render($form[$field]['amount'])
+      . '</td></tr>';
+  }
+  $output .= '</table>' . drupal_render_children($form);
+
+  return $output;
+}
+
+function uc_order_pane_line_items_submit($form, &$form_state) {
+  $values = $form_state['values'];
+
+  if (is_array($values['line_items'])) {
+    foreach ($values['line_items'] as $line) {
+      if (is_numeric($line['li_id']) && intval($line['li_id']) > 0) {
+        uc_order_update_line_item($line['li_id'], $line['title'], $line['amount']);
+      }
+    }
+  }
+  if (intval($values['li_delete_id']) > 0) {
+    uc_order_delete_line_item($values['li_delete_id']);
+    drupal_set_message(t('Line item removed.'));
+  }
+}
+
+function uc_order_edit_line_items_recalculate($form, &$form_state) {
+  $order = $form_state['build_info']['args'][0];
+
+  // Load line items again, since some may have been updated by the form.
+  $order->line_items = uc_order_load_line_items($order, TRUE);
+
+  // Merge it with the defaultish line items.
+  $order->line_items = array_merge($order->line_items, uc_order_load_line_items($order, FALSE));
+  usort($order->line_items, 'uc_weight_sort');
 }
 
 /**
  * Handle the "Order Comments" order pane.
  */
-function uc_order_pane_order_comments($op, $arg1) {
+function uc_order_pane_order_comments($op, $order) {
   switch ($op) {
     case 'view':
-      $comments = uc_order_comments_load($arg1->order_id);
+      $comments = uc_order_comments_load($order->order_id);
       return tapir_get_table('uc_op_order_comments_view_table', $comments);
 
     case 'customer':
-      $comments = uc_order_comments_load($arg1->order_id);
+      $comments = uc_order_comments_load($order->order_id);
       $header = array(t('Date'), t('Status'), array('data' => t('Message'), 'width' => '100%'));
       $rows[] = array(
-        format_date($arg1->created, 'custom', variable_get('uc_date_format_default', 'm/d/Y')),
+        format_date($order->created, 'custom', variable_get('uc_date_format_default', 'm/d/Y')),
         array('data' => '-', 'align' => 'center'),
         t('Order created.')
       );
@@ -558,10 +988,10 @@
 /**
  * Handle the "Admin Comments" order pane.
  */
-function uc_order_pane_admin_comments($op, $arg1) {
+function uc_order_pane_admin_comments($op, $order) {
   switch ($op) {
     case 'view':
-      $comments = uc_order_comments_load($arg1->order_id, TRUE);
+      $comments = uc_order_comments_load($order->order_id, TRUE);
       return tapir_get_table('uc_op_admin_comments_view_table', $comments);
 
     case 'edit-form':
@@ -578,7 +1008,7 @@
       return $form;
 
     case 'edit-theme':
-      $comments = uc_order_comments_load($arg1['order_id']['#value'], TRUE);
+      $comments = uc_order_comments_load($order['order_id']['#value'], TRUE);
       if (is_array($comments) && count($comments) > 0) {
         foreach ($comments as $comment) {
           $items[] = '[' . uc_get_initials($comment->uid) . '] ' . filter_xss_admin($comment->message);
@@ -587,13 +1017,13 @@
       else {
         $items = array(t('No admin comments have been entered for this order.'));
       }
-      $output = theme('item_list', array('items' => $items)) . drupal_render($arg1['admin_comment_field']);
+      $output = theme('item_list', array('items' => $items)) . drupal_render($order['admin_comment_field']);
       return $output;
 
     case 'edit-process':
-      if (!is_null($arg1['admin_comment']) && strlen(trim($arg1['admin_comment'])) > 0) {
+      if (!is_null($order['admin_comment']) && strlen(trim($order['admin_comment'])) > 0) {
         global $user;
-        uc_order_comment_save($arg1['order_id'], $user->uid, $arg1['admin_comment']);
+        uc_order_comment_save($order['order_id'], $user->uid, $order['admin_comment']);
       }
       return;
   }
@@ -602,10 +1032,10 @@
 /**
  * Handle the "Update" order pane.
  */
-function uc_order_pane_update($op, $arg1) {
+function uc_order_pane_update($op, $order) {
   switch ($op) {
     case 'view':
-      return drupal_get_form('uc_order_view_update_form', $arg1);
+      return drupal_get_form('uc_order_view_update_form', $order);
   }
 }
 
@@ -956,6 +1386,50 @@
 }
 
 /**
+ * TAPIr table for products pane on the order edit page.
+ *
+ * @see uc_order_edit_products_form()
+ */
+function uc_op_products_edit_table() {
+  $table = array(
+    '#type' => 'tapir_table',
+    '#tree' => TRUE,
+    '#attributes' => array('id' => 'order-edit-products', 'class' => array('order-pane-table')),
+  );
+
+  $table['#columns']['remove'] = array(
+    'cell' => t('Remove'),
+    'weight' => 0,
+  );
+  $table['#columns']['qty'] = array(
+    'cell' => t('Qty'),
+    'weight' => 1,
+  );
+  $table['#columns']['title'] = array(
+    'cell' => t('Name'),
+    'weight' => 2,
+  );
+  $table['#columns']['model'] = array(
+    'cell' => t('SKU'),
+    'weight' => 4,
+  );
+  $table['#columns']['weight'] = array(
+    'cell' => t('Weight'),
+    'weight' => 5,
+  );
+  $table['#columns']['cost'] = array(
+    'cell' => t('Cost'),
+    'weight' => 6,
+  );
+  $table['#columns']['price'] = array(
+    'cell' => t('Price'),
+    'weight' => 7,
+  );
+
+  return $table;
+}
+
+/**
  * Build the order comments table.
  */
 function uc_op_order_comments_view_table($comments) {

=== modified file 'uc_product/uc_product.module'
--- uc_product/uc_product.module	2010-05-18 20:14:02 +0000
+++ uc_product/uc_product.module	2010-06-03 15:57:46 +0000
@@ -692,7 +692,6 @@
     drupal_write_record('uc_products', $node);
   }
   else {
-    //drupal_set_message('<pre>' . print_r($node, TRUE) . '</pre>');
     drupal_write_record('uc_products', $node, 'vid');
   }
 }
@@ -785,7 +784,6 @@
       '#access' => $enabled['model'],
       '#weight' => $weight['model'],
     );
-    //$node->content['body']['#markup'] = theme('uc_product_body', array('body' => $node->body, 'teaser' => $teaser, 'page' => $page));
     $node->content['body']['#weight'] = 1;
 
     $context['class'][1] = 'list';
@@ -809,7 +807,6 @@
     );
   }
   else {
-    //$node->content['body']['#markup'] = theme('uc_product_body', array('body' => $node->teaser, 'teaser' => $teaser, 'page' => $page));
     $node->content['#attributes'] = array('style' => 'display: inline');
   }
 

=== modified file 'uc_product_kit/uc_product_kit.module'
--- uc_product_kit/uc_product_kit.module	2010-05-18 20:14:02 +0000
+++ uc_product_kit/uc_product_kit.module	2010-06-03 15:57:46 +0000
@@ -380,9 +380,6 @@
     $nodes[$prod->nid]->products[$product->nid] = $product;
   }
 
-  // I hope this is unnecessary since the query should pre-sort them.
-  //uasort($products, '_uc_product_kit_sort_products');
-
   // Add product data to kits.
   uc_product_load($nodes);
 }
@@ -524,7 +521,6 @@
     foreach ($node->products as $i => $product) {
       $form['base']['items'][$i] = array(
         '#type' => 'fieldset',
-        //'#title' => $product->title,
       );
       $form['base']['items'][$i]['link'] = array(
         '#type' => 'item',
@@ -777,7 +773,7 @@
   $form['nid'] = array('#type' => 'value', '#value' => $node->nid, );
   $form['products'] = array('#tree' => TRUE);
   foreach ($node->products as $i => $product) {
-    $form['products'][$i] = array(/* '#type' => 'fieldset',  */'#title' => $product->title);
+    $form['products'][$i] = array('#title' => $product->title);
     $form['products'][$i]['nid'] = array('#type' => 'hidden', '#value' => $product->nid);
     $form['products'][$i]['qty'] = array('#type' => 'hidden', '#value' => $product->qty);
   }
@@ -841,7 +837,7 @@
   if ($node->type == 'product_kit') {
     $form['products'] = array('#tree' => TRUE);
     foreach ($node->products as $i => $product) {
-      $form['products'][$i] = array(/* '#type' => 'fieldset',  */'#title' => $product->title);
+      $form['products'][$i] = array('#title' => $product->title);
       $form['products'][$i]['nid'] = array('#type' => 'hidden', '#value' => $product->nid);
       $form['products'][$i]['qty'] = array('#type' => 'hidden', '#value' => $product->qty);
     }
@@ -1086,7 +1082,6 @@
   static $products;
   $unique_id = $item->data['unique_id'];
   $kit = node_load($item->data['kit_id']);
-  //print '<pre>' . print_r($kit, TRUE) . '</pre>';
   if ($kit->mutable == UC_PRODUCT_KIT_MUTABLE) {
     return uc_product_uc_cart_display($item);
   }

=== modified file 'uc_stock/uc_stock.admin.inc'
--- uc_stock/uc_stock.admin.inc	2010-04-05 20:37:23 +0000
+++ uc_stock/uc_stock.admin.inc	2010-06-03 15:57:46 +0000
@@ -258,7 +258,7 @@
   $form = $variables['form'];
 
   $header = array(
-    array('data' => '&nbsp;&nbsp;'. t('Active')) + theme('table_select_header_cell'),
+    array('data' => '&nbsp;&nbsp;' . t('Active')) + theme('table_select_header_cell'),
     array('data' => t('SKU')),
     array('data' => t('Stock')),
     array('data' => t('Threshold')),

=== modified file 'uc_store/includes/tapir.inc'
--- uc_store/includes/tapir.inc	2010-04-07 15:02:53 +0000
+++ uc_store/includes/tapir.inc	2010-06-03 15:57:46 +0000
@@ -89,17 +89,6 @@
     $attributes = array();
     $row = array();
 
-    /* // If the row combines cell data with attributes...
-    if (isset($data['data'])) {
-      // Set the attributes array to be everything in the row array except the
-      // data array.
-      $attributes = $data;
-      unset($attributes['data']);
-
-      // Filter the data array down to just the cell data.
-      $data = $data['data'];
-    } */
-
     // Loop through each column in the header.
     foreach ($element['#columns'] as $col_id => $col_data) {
       // If this row defines cell data for the current column...

=== removed file 'uc_taxes/uc_taxes.js'
--- uc_taxes/uc_taxes.js	2010-03-23 20:10:29 +0000
+++ uc_taxes/uc_taxes.js	1970-01-01 00:00:00 +0000
@@ -1,91 +0,0 @@
-// $Id$
-
-/**
- * @file
- * Handle asynchronous requests to calculate taxes.
- */
-
-var pane = '';
-if (jQuery("input[name*=delivery_]").length) {
-  pane = 'delivery'
-}
-else if (jQuery("input[name*=billing_]").length) {
-  pane = 'billing'
-}
-
-jQuery(document).ready(function() {
-  getTax();
-  jQuery("select[name*=delivery_country], "
-    + "select[name*=delivery_zone], "
-    + "input[name*=delivery_city], "
-    + "input[name*=delivery_postal_code], "
-    + "select[name*=billing_country], "
-    + "select[name*=billing_zone], "
-    + "input[name*=billing_city], "
-    + "input[name*=billing_postal_code]").change(getTax);
-  jQuery("input[name*=copy_address]").click(getTax);
-  jQuery('#edit-panes-payment-current-total').click(getTax);
-});
-
-/**
- * Get tax calculations for the current cart and line items.
- */
-function getTax() {
-  var order = serializeOrder();
-
-  if (!!order) {
-    jQuery.ajax({
-      type: "POST",
-      url: Drupal.settings.ucURL.calculateTax,
-      data: 'order=' + Drupal.encodePath(order),
-      dataType: "json",
-      success: function(taxes) {
-        var key;
-        var render = false;
-        var i;
-        var j;
-        for (j in taxes) {
-          key = 'tax_' + taxes[j].id;
-          // Check that this tax is a new line item, or updates its amount.
-          if (li_values[key] == undefined || li_values[key] != taxes[j].amount) {
-            set_line_item(key, taxes[j].name, taxes[j].amount, Drupal.settings.ucTaxWeight + taxes[j].weight / 10, taxes[j].summed, false);
-
-            // Set flag to render all line items at once.
-            render = true;
-          }
-        }
-        var found;
-        // Search the existing tax line items and match them to a returned tax.
-        for (key in li_titles) {
-          // The tax id is the second part of the line item id if the first
-          // part is "tax".
-          keytype = key.substring(0, key.indexOf('_'));
-          if (keytype == 'tax') {
-            found = false;
-            li_id = key.substring(key.indexOf('_') + 1);
-            for (j in taxes) {
-              if (taxes[j].id == li_id) {
-                found = true;
-                break;
-              }
-            }
-            // No tax was matched this time, so remove the line item.
-            if (!found) {
-              delete li_titles[key];
-              delete li_values[key];
-              delete li_weight[key];
-              delete li_summed[key];
-              // Even if no taxes were added earlier, the display must be
-              // updated.
-              render = true;
-            }
-          }
-        }
-        if (render) {
-          render_line_items();
-        }
-      }
-    });
-  }
-}
-

=== modified file 'uc_taxes/uc_taxes.module'
--- uc_taxes/uc_taxes.module	2010-04-05 16:53:39 +0000
+++ uc_taxes/uc_taxes.module	2010-06-03 19:32:27 +0000
@@ -90,42 +90,10 @@
     'type' => MENU_CALLBACK,
     'file' => 'uc_taxes.admin.inc',
   );
-  $items['taxes/calculate'] = array(
-    'page callback' => 'uc_taxes_javascript',
-    'access arguments' => array('access content'),
-    'type' => MENU_CALLBACK,
-  );
 
   return $items;
 }
 
-/**
- * Implement hook_form_alter().
- */
-function uc_taxes_form_alter(&$form, &$form_state, $form_id) {
-  if ($form_id == 'uc_cart_checkout_form') {
-    if (isset($form['panes']['payment'])) {
-      drupal_add_js(array(
-        'ucTaxWeight' => variable_get('uc_li_tax_weight', 9),
-        'ucURL' => array(
-          'calculateTax' => url('taxes/calculate'),
-        ),
-      ), 'setting');
-      drupal_add_js(drupal_get_path('module', 'uc_taxes') . '/uc_taxes.js');
-    }
-  }
-  elseif ($form_id == 'uc_order_edit_form') {
-    if (isset($form['quotes'])) {
-      drupal_add_js(array(
-        'ucURL' => array(
-          'calculateTax' => url('taxes/calculate'),
-        ),
-      ), 'setting');
-      drupal_add_js(drupal_get_path('module', 'uc_taxes') . '/uc_taxes.js');
-    }
-  }
-}
-
 /*******************************************************************************
  * Ubercart Hooks
  ******************************************************************************/
@@ -161,22 +129,20 @@
  *
  * Update and save tax line items to the order.
  */
-function uc_taxes_uc_order($op, $arg1, $arg2) {
+function uc_taxes_uc_order($op, $order, $arg2) {
   switch ($op) {
     case 'save':
       $changes = array();
-      $line_items = uc_line_item_tax('load', $arg1);
-      //$arg1->line_items = uc_order_load_line_items($arg1, TRUE);
+      $line_items = uc_line_item_tax('load', $order);
       $context = array(
         'revision' => 'formatted',
         'type' => 'line_item',
         'subject' => array(
-          'order' => $arg1,
+          'order' => $order,
         ),
       );
-      if (is_array($arg1->line_items)) {
-        //drupal_set_message('<pre>' . var_export($arg1->line_items, TRUE) . '</pre>');
-        foreach ($arg1->line_items as $i => $line) {
+      if (is_array($order->line_items)) {
+        foreach ($order->line_items as $i => $line) {
           if ($line['type'] == 'tax') {
             $delete = TRUE;
             foreach ($line_items as $id => $new_line) {
@@ -184,7 +150,7 @@
                 if ($new_line['amount'] != $line['amount']) {
                   $context['subject']['line_item'] = $new_line;
                   uc_order_update_line_item($line['line_item_id'], $new_line['title'], $new_line['amount'], $new_line['data']);
-                  $arg1->line_items[$i]['amount'] = $new_line['amount'];
+                  $order->line_items[$i]['amount'] = $new_line['amount'];
                   $changes[] = t('Changed %title to %amount.', array('%amount' => uc_price($new_line['amount'], $context), '%title' => $new_line['title']));
                 }
                 unset($line_items[$id]);
@@ -194,7 +160,7 @@
             }
             if ($delete) {
               uc_order_delete_line_item($line['line_item_id']);
-              unset($arg1->line_items[$i]);
+              unset($order->line_items[$i]);
               $changes[] = t('Removed %title.', array('%title' => $line['title']));
             }
           }
@@ -202,15 +168,15 @@
       }
       if (is_array($line_items)) {
         foreach ($line_items as $line) {
-          uc_order_line_item_add($arg1->order_id, $line['id'], $line['title'], $line['amount'], $line['weight'], $line['data']);
+          uc_order_line_item_add($order->order_id, $line['id'], $line['title'], $line['amount'], $line['weight'], $line['data']);
           $line['type'] = 'tax';
-          $arg1->line_items[] = $line;
+          $order->line_items[] = $line;
           $context['subject']['line_item'] = $line;
           $changes[] = t('Added %amount for %title.', array('%amount' => uc_price($line['amount'], $context), '%title' => $line['title']));
         }
       }
       if (count($changes)) {
-        uc_order_log_changes($arg1->order_id, $changes);
+        uc_order_log_changes($order->order_id, $changes);
       }
     break;
   }
@@ -246,46 +212,45 @@
  */
 function uc_line_item_tax_subtotal($op, $order) {
   $amount = 0;
-//  if ($different && $has_taxes) {
-    switch ($op) {
-      case 'cart-preview':
-        drupal_add_js("jQuery(document).ready(function() {
-          if (window.set_line_item) {
-            set_line_item('tax_subtotal', '" . t('Subtotal excluding taxes') . "', " . $amount . ", " . variable_get('uc_li_tax_subtotal_weight', 8) . ");
-          }
-        });", 'inline');
-      break;
-      case 'load':
-  if (is_array($order->products)) {
-    foreach ($order->products as $item) {
-      $amount += $item->price * $item->qty;
-    }
-  }
-  if (is_array($order->line_items)) {
-    foreach ($order->line_items as $key => $line_item) {
-      if ($line_item['type'] == 'subtotal') {
-        continue;
-      }
-      if (substr($line_item['type'], 0, 3) != 'tax') {
-        $amount += $line_item['amount'];
-        $different = TRUE;
-      }
-      else {
+  switch ($op) {
+    case 'load':
+      $has_taxes = FALSE;
+      $different = FALSE;
+
+      if (is_array($order->products)) {
+        foreach ($order->products as $item) {
+          $amount += $item->price * $item->qty;
+        }
+      }
+      if (is_array($order->line_items)) {
+        foreach ($order->line_items as $key => $line_item) {
+          if ($line_item['type'] == 'subtotal') {
+            continue;
+          }
+          if (substr($line_item['type'], 0, 3) != 'tax') {
+            $amount += $line_item['amount'];
+            $different = TRUE;
+          }
+          else {
+            $has_taxes = TRUE;
+          }
+        }
+      }
+
+      if (isset($order->taxes) && is_array($order->taxes)) {
         $has_taxes = TRUE;
       }
-    }
-  }
-  if (isset($order->taxes) && is_array($order->taxes)) {
-    $has_taxes = TRUE;
-  }
+
+      if ($different && $has_taxes) {
         return array(array(
           'id' => 'tax_subtotal',
           'title' => t('Subtotal excluding taxes'),
           'amount' => $amount,
           'weight' => variable_get('uc_li_tax_subtotal_weight', 7),
         ));
-    }
-//  }
+      }
+      break;
+  }
 }
 
 
@@ -461,31 +426,6 @@
   return $order->taxes;
 }
 
-/**
- * AJAX callback for order preview.
- *
- * Calculate tax amounts for an order in the payment checkout pane.
- */
-function uc_taxes_javascript() {
-  $order = $_POST['order'];
-  if ($order = unserialize(rawurldecode($order))) {
-    $taxes = module_invoke_all('uc_calculate_tax', $order);
-    $callback = _uc_line_item_data('tax_subtotal', 'callback');
-    if (function_exists($callback)) {
-      $subtotal = $callback('load', $order);
-      if (is_array($subtotal) && !empty($taxes)) {
-        $taxes['subtotal'] = (object)array(
-          'id' => 'subtotal',
-          'name' => $subtotal[0]['title'],
-          'amount' => $subtotal[0]['amount'],
-          'weight' => -10,
-          'summed' => 0,
-        );
-      }
-    }
-  }
-  drupal_json_output((array) $taxes);
-}
 
 /**
  * Calculate tax for a single product.

