--- uc_aac.orig	2007-12-18 15:59:45.000000000 -0600
+++ uc_aac.module	2007-12-18 16:28:06.000000000 -0600
@@ -51,8 +51,10 @@ function _uc_aac_alter_form($field_id, $
   $correct_token = drupal_get_token($field_id);
   $result = db_query('select sell_price from {uc_products} where nid=%d', $nid);
   $price = 0;
+  $cost = 0;
   if ($product = db_fetch_object($result)) {
     $price = $product->sell_price;
+    $cost = $product->cost;
   }
 
 
@@ -66,6 +68,8 @@ function _uc_aac_alter_form($field_id, $
   $content .= '
 <script>
   var replacePrice_'.$field_id.' = "'.uc_currency_format($price).'";
+  var replaceCost_'.$field_id.' = "'.uc_currency_format($cost).'";
+  var replaceDisplay_'.$field_id.' = "'.uc_currency_format($price+$cost).'";
   function initializeFields_'.$field_id.'() {
     $("#node-'.$nid.' select").each(function () {
       var element = this;
@@ -111,15 +115,25 @@ function _uc_aac_alter_form($field_id, $
   $content .= '
     $(fakeForm).ajaxSubmit( {
       success: function(html_result) {
+        var results = html_result.split("|");
+        var res_price = results[0];
+        var res_cost = results[1];
+        var res_display = results[2];
         var currentsellHTML= $("#node-'.$nid.' .sell_price").html();
+        var currentcostHTML= $("#node-'.$nid.' .cost").html();
         var currentdisplayHTML = $("#node-'.$nid.' .display_price").html();
         if (currentdisplayHTML) {
-          $("#node-'.$nid.' .display_price").html(currentdisplayHTML.replace(replacePrice_'.$field_id.', html_result));
+          $("#node-'.$nid.' .display_price").html(currentdisplayHTML.replace(replaceDisplay_'.$field_id.', res_display));
+        }
+        if (currentcostHTML) {
+          $("#node-'.$nid.' .cost").html(currentcostHTML.replace(replaceCost_'.$field_id.', res_cost));
         }
         if (currentsellHTML) {
-          $("#node-'.$nid.' .sell_price").html(currentsellHTML.replace(replacePrice_'.$field_id.', html_result));
+          $("#node-'.$nid.' .sell_price").html(currentsellHTML.replace(replacePrice_'.$field_id.', res_price));
         }
-        replacePrice_'.$field_id.' = html_result;
+        replacePrice_'.$field_id.' = res_price;
+        replaceCost_'.$field_id.' = res_cost;
+        replaceDisplay_'.$field_id.' = res_display;
       },
       error: function() {
         //alert("Failed to update this result.");
@@ -142,20 +156,24 @@ function _calculate_price() {
   $field_values = $_POST;
   $correct_token = drupal_get_token($field_values['uccp']['field_id']);
   if ($correct_token == $field_values['uccp']['form_token']) {
-    $result = db_query('select sell_price from {uc_products} where nid=%d', $field_values['uccp']['nid']);
+    $result = db_query('select sell_price, cost from {uc_products} where nid=%d', $field_values['uccp']['nid']);
     if ($product = db_fetch_object($result)) {
       $price = $product->sell_price;
+      $cost = $product->cost;
     }
     $attributes = $field_values['attributes'];
     if ($attributes) {
       foreach ($attributes as $attr) {
-        $result = db_query('select price from {uc_product_options} WHERE nid = %d AND oid = %d', $field_values['uccp']['nid'], $attr);
+        $result = db_query('select price, cost from {uc_product_options} WHERE nid = %d AND oid = %d', $field_values['uccp']['nid'], $attr);
         if ($adjustment = db_fetch_object($result)) {
           $price += $adjustment->price;
+          $cost += $adjustment->cost;
         }
       }
     }
-    $ret = uc_currency_format($price);
-    print( $ret );
+    $ret_price = uc_currency_format($price);
+    $ret_cost = uc_currency_format($cost);
+    $ret_display = uc_currency_format($price+$cost);
+    print( $ret_price . "|" . $ret_cost . "|" . $ret_display );
   }
 }

