Index: uc_multiprice.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_multiprice/uc_multiprice.install,v
retrieving revision 1.5
diff -u -r1.5 uc_multiprice.install
--- uc_multiprice.install	13 Aug 2009 14:38:47 -0000	1.5
+++ uc_multiprice.install	24 Sep 2009 12:13:14 -0000
@@ -47,6 +47,12 @@
         'not null' => TRUE,
         'default' => 0.0,
       ),
+			'data' => array(
+        'description' => 'Extra data.',
+        'type' => 'text',
+        'not null' => TRUE,
+        'size' => 'big',
+      ),
     ),
   );
 
@@ -116,6 +122,7 @@
 function uc_multiprice_uninstall() {
   drupal_uninstall_schema('uc_multiprice');
 }
+
 function uc_multiprice_update_6001() {
   $ret = array();
 
@@ -173,4 +180,15 @@
   $ret[] = update_sql("INSERT INTO {uc_multiprice_currencies} (country_id, currency_code) VALUES (840, 'USD')");
 
   return $ret;
+}
+
+function uc_multiprice_update_6002() {
+  $ret = array();
+  db_add_field($ret, 'uc_multiprice', 'data', array(
+        'description' => 'Extra data.',
+        'type' => 'text',
+        'not null' => TRUE,
+        'size' => 'big',
+      ));
+  return $ret;
 }
\ No newline at end of file
Index: uc_multiprice.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_multiprice/uc_multiprice.module,v
retrieving revision 1.13
diff -u -r1.13 uc_multiprice.module
--- uc_multiprice.module	2 Sep 2009 12:20:30 -0000	1.13
+++ uc_multiprice.module	28 Sep 2009 11:38:40 -0000
@@ -47,24 +47,24 @@
         '#title' => t('Pricing'),
         //'#description' => t('You can override the global pricing by country.'),
         '#tree' => TRUE,
-        '#weight' => 6,
+        //'#weight' => 6,
         '#collapsible' => TRUE,
         '#collapsed' => FALSE,
     );
     $form['multiprice']['countries'] = array(
         '#type' => 'fieldset',
         '#tree' => TRUE,
-        '#weight' => 3,
+        '#weight' => 0,
         '#collapsible' => FALSE,
         '#collapsed' => FALSE,
         '#prefix' => '<div id="multiprice-countries">',
         '#suffix' => '</div>',
-        '#theme' => 'uc_multiprice_form',
+        '#theme' => (module_exists('uc_multiprice_calc')) ? 'uc_multiprice_calc_form' : 'uc_multiprice_form',
     );
 
     // Get all multiprices
     $result = db_query("SELECT 
-                           c.country_id, c.country_name, m.nid, m.sell_price, m.cost, m.list_price 
+                           c.country_id, c.country_name, m.nid, m.sell_price, m.cost, m.list_price, m.data 
                         FROM 
                           {uc_countries} c 
                         LEFT JOIN 
@@ -89,23 +89,31 @@
 		
 		$exist = array();
     while ($country = db_fetch_object($result)) {
-      $form['multiprice']['countries'] += uc_multiprice_field_element($country);
-      $exist[] = $country->country_id;
+			if(module_exists('uc_multiprice_calc')) {
+				$form['multiprice']['countries'][$country->country_id] =  uc_multiprice_calc_field_element($country);
+				$form['multiprice']['countries'][$country->country_id]['calc']['list_price'] = uc_multiprice_calc_element($country, 'list_price');
+				$form['multiprice']['countries'][$country->country_id]['calc']['cost'] = uc_multiprice_calc_element($country, 'cost');
+				$form['multiprice']['countries'][$country->country_id]['calc']['sell_price'] = uc_multiprice_calc_element($country, 'sell_price');
+			}else{
+				$form['multiprice']['countries'][$country->country_id] = uc_multiprice_field_element($country);
+			}
+			$exist[] = $country->country_id;
     }
       
     $result = db_query("SELECT country_id, country_name FROM {uc_countries} WHERE version > 0 ORDER BY country_name ASC");
     
+		// build country dropdown
 		$countries[0] = 'Select country';
 		while ($country = db_fetch_object($result)) {
       if (!in_array($country->country_id, $exist))
-        $countries[$country->country_id] = $country->country_name;  
+        $countries[$country->country_id] = $country->country_name; 
     }
       
     $form['multiprice']['more'] = array(
 			'#type' => 'fieldset',
 			'#title' => t('Add a price override for a country'),
 			'#tree' => TRUE,
-			'#weight' => 6,
+			'#weight' => 1,
 			'#collapsible' => TRUE,
 			'#collapsed' => FALSE,
     );
@@ -113,7 +121,7 @@
       '#type' => 'select',
       '#description' => t("Select the country/region to add a price overide."),
       '#options' => $countries,
-      '#weight' => 1,
+      //'#weight' => 1,
       '#ahah' => array(
         'path' => 'uc_multiprice/js',
         'wrapper' => 'multiprice-countries',
@@ -122,6 +130,8 @@
         ),
     );
     $form['#validate'][] = 'uc_multiprice_form_validate';
+		drupal_add_js(array('uc_multiprice' => array('countries' => $exist)), 'setting');
+		
   }
   
   // Checkout form
@@ -257,17 +267,21 @@
 			break;
       case 'insert':
       case 'update':
-        db_query("DELETE FROM {uc_multiprice} WHERE nid = %d", $node->nid);
+			 db_query("DELETE FROM {uc_multiprice} WHERE nid = %d", $node->nid);
+			 unset($node->multiprice['countries'][0]);
        
        if (count($node->multiprice['countries'])==0)
           break;
         
-        foreach ($node->multiprice['countries'] as $country_id => $country) {
-            if (empty($country->delete) || $country->country_id!=0) {
-              db_query("INSERT INTO {uc_multiprice} (nid, country_id, list_price, cost, sell_price) VALUES (%d, %d, %f, %f, %f)",
-                $node->nid, $country_id, $country['list_price'], $country['cost'], $country['sell_price']);
+       foreach ($node->multiprice['countries'] as $country_id => $country) {
+        //    			print_r($country);
+			//exit;
+						if (empty($country->delete)) {
+              db_query("INSERT INTO {uc_multiprice} (nid, country_id, list_price, cost, sell_price, data) VALUES (%d, %d, %f, %f, %f, '%s')",
+                $node->nid, $country_id, $country['list_price'], $country['cost'], $country['sell_price'], serialize($country['calc']));
             }
         }
+
       break;
     }
   }
@@ -470,25 +484,28 @@
 
   $form_state = array('submitted' => FALSE);
   $form_build_id = $_POST['form_build_id'];
-
-  // Add the new element to the stored form. Without adding the element to the
-  // form, Drupal is not aware of this new elements existence and will not
-  // process it. We retreive the cached form, add the element, and resave.
   $form = form_get_cache($form_build_id, $form_state);
-  
 	$country_id = check_plain($_POST['multiprice']['more']['list']);
-	if ($country_id != 0) {
-		// new field
-		$country = db_fetch_object(db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country_id));
-		$field = uc_multiprice_field_element($country);
-		$form['multiprice']['countries'] += $field;
-	}
 	
+	// new field
+	$country = db_fetch_object(db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country_id));
+	if(module_exists('uc_multiprice_calc')) {
+		$form['multiprice']['countries'][$country->country_id] = uc_multiprice_calc_field_element($country);
+		$form['multiprice']['countries'][$country->country_id]['calc']['list_price'] = uc_multiprice_calc_element($country, 'list_price');
+		$form['multiprice']['countries'][$country->country_id]['calc']['cost'] = uc_multiprice_calc_element($country, 'cost');
+		$form['multiprice']['countries'][$country->country_id]['calc']['sell_price'] = uc_multiprice_calc_element($country, 'sell_price');
+	}else{
+		$form['multiprice']['countries'][$country->country_id] = uc_multiprice_field_element($country);
+	}
+	//print_r($form['multiprice']['countries'][$country->country_id]);
+
   form_set_cache($form_build_id, $form, $form_state);
-  $form += array(
+  /*
+	$form += array(
     '#post' => $_POST,
     '#programmed' => FALSE,
   );
+	*/
   // Rebuild the form. 
   $form = form_builder($_POST['form_id'], $form, $form_state);
   
@@ -496,6 +513,7 @@
   unset($form['multiprice']['countries']['prefix']);
   unset($form['multiprice']['countries']['suffix']);
   $output = drupal_render($form['multiprice']['countries']);
+	$output .= '<script type="text/javascript">Drupal.settings.uc_multiprice.countries.push('.$country_id.');</script>'; // bad programming?
   
   print drupal_to_js(array('status' => TRUE, 'data' => $output));
   exit;
--- css/popup.css
+++ css/popup.css
@@ -0,0 +1,33 @@
+#uc_multiprice_table input.disabled {
+	background-color:#ccc;
+	color:white;
+}
+.calc {
+	border:0;
+	height:20px;
+	width:20px;
+	cursor:pointer;
+	margin:0;
+}
+.calc_on {
+	background:url(../images/calculator.png) 0 0 no-repeat;
+}
+.calc_off {
+	background:url(../images/calculator_off.png) 0 0 no-repeat;
+}
+.popup {
+	display:none;
+	background-color:#999;
+	width:100%;	
+}
+.popup td{
+	background-color:#999;
+}
+.popup fieldset {
+	width:25%;
+	padding:4px;
+	margin:0;
+	border:0;
+	float:left;
+	display:inline;
+}

--- js/uc_multiprice_calc.js
+++ js/uc_multiprice_calc.js
@@ -0,0 +1,125 @@
+function uc_multiprice_calc(country_id, field) {
+	field = field.replace('_', '-');
+	var _return = $("#edit-multiprice-countries-"+country_id+"-"+field+"");
+	var _default = $("#edit-multiprice-countries-0-"+field);
+	var calc_button = $("#edit-multiprice-countries-"+country_id+"-edit-"+field);
+	var enabled = $("#edit-multiprice-countries-"+country_id+"-calc-"+field+"-enabled");
+	
+	//check if enabled otherwise quit
+	if(enabled.attr("checked")) {
+		$(calc_button).removeClass('calc_off').addClass('calc_on');
+		_return.attr("disabled", "disabled");
+		$(_return).addClass('disabled');
+	}else{
+		$(calc_button).removeClass('calc_on').addClass('calc_off');
+		_return.attr("disabled");
+		$(_return).removeClass('disabled');
+		return;
+	}
+
+	// get operators and values
+	var operator 		= $("#edit-multiprice-countries-"+country_id+"-calc-"+field+"-operator-value");
+	var operator_1 	= $("#edit-multiprice-countries-"+country_id+"-calc-"+field+"-1-operator");
+	var value_1			= $("#edit-multiprice-countries-"+country_id+"-calc-"+field+"-1-value");
+	var operator_2	= $("#edit-multiprice-countries-"+country_id+"-calc-"+field+"-2-operator");
+	var value_2 		= $("#edit-multiprice-countries-"+country_id+"-calc-"+field+"-2-value");
+
+	// do some changing
+	if(operator_1.val() == 'default') {
+		value_1.val(_default.val());
+		value_1.attr("disabled", "disabled");
+		$(value_1).addClass('disabled');
+	}else{
+		value_1.attr("disabled");
+		$(value_1).removeClass('disabled');
+	}
+	
+	if(operator_2.val() == 'default') {
+		value_2.val(_default.val());
+		value_2.attr("disabled", "disabled");
+		$(value_2).addClass('disabled');
+	}else{
+		value_2.attr("disabled");
+		$(value_2).removeClass('disabled');
+	}
+	
+	if(operator_1.val() == 'custom') {
+		value_1.attr("disabled", '');
+	}
+	if(operator_2.val() == 'custom') {
+		value_2.attr("disabled", '');
+	}
+	
+	// calculations
+	if(operator.val() == 'x') {
+		result = parseFloat(value_1.val()) * parseFloat(value_2.val());
+	}
+	if(operator.val() == '-') {
+		result = parseFloat(value_1.val()) - parseFloat(value_2.val());
+	}
+	if(operator.val() == '+') {
+		result = parseFloat(value_1.val()) + parseFloat(value_2.val());
+	}
+	
+	// return
+	_return.val(result);	
+}
+
+function uc_multiprice_recalculate(field) {
+	jQuery.each(Drupal.settings.uc_multiprice.countries, function() {
+			uc_multiprice_calc(this, field);																																
+	})
+}
+
+function uc_multiprice_calc_close() {
+	//$('.calc').parents("td").css('background', 'none');
+	//popup_tr.hide();
+}
+
+function uc_multiprice_calc_open() {
+	//popup_tr.show();
+}
+
+Drupal.behaviors.uc_multiprice = function (context) {
+	$('.popup').hide();
+	
+	uc_multiprice_recalculate('list-price');
+	uc_multiprice_recalculate('sell-price');
+	uc_multiprice_recalculate('cost')
+	//popup_tr = $('#popup').parents("tr");
+/*
+	$('.calc').mousedown(function(){
+		//$('.calc').parents("td").css('background', 'none');
+		//$(this).parents("td").css('background', '#999');
+		//$(this).parents("tr").after(popup_tr);
+		
+		uc_multiprice_recalculate('list-price');
+		uc_multiprice_recalculate('sell-price');
+		uc_multiprice_recalculate('cost');
+		
+		//uc_multiprice_calc_open();
+	});
+	*/
+
+	$('.calc').click(function(){
+		$('.popup').hide();
+		$('.calc').parents("td").css('background', 'none');
+		
+		var id = $(this).attr('id');
+		$('#'+ id +'-calc').show();
+		$(this).parents("td").css('background', '#999');
+		
+		return false;
+	});
+
+	// add listeners to default
+	$("#edit-multiprice-countries-0-list-price").change(function(){
+			uc_multiprice_recalculate('list-price');
+	});
+	$("#edit-multiprice-countries-0-sell-price").change(function(){
+			uc_multiprice_recalculate('sell-price');
+	});
+	$("#edit-multiprice-countries-0-cost").change(function(){
+			uc_multiprice_recalculate('cost');
+	});
+};

--- uc_multiprice_calc.info
+++ uc_multiprice_calc.info
@@ -0,0 +1,5 @@
+name = Multiprice Dynamic price
+description = Allows dynamic calculation of the price
+package = "Ubercart - extra"
+dependencies[] = uc_multiprice
+core = 6.x

--- uc_multiprice_calc.module
+++ uc_multiprice_calc.module
@@ -0,0 +1,330 @@
+<?php
+
+/**
+ * @file Provides Multiprice dynamic options
+ */
+
+/*******************************************************************************
+ * Hook Functions (Drupal)
+ ******************************************************************************/
+
+/**
+ * Implementation of hook_menu().
+ */
+function uc_multiprice_calc_menu() {
+  $items['uc_multiprice_calc/js/edit/%/%'] = array(
+    'page callback' => 'uc_multiprice_calc_js',
+		'page arguments' => array(3, 4),
+    'access arguments' => array('administer nodes'),
+    'type' => MENU_CALLBACK,
+  );
+	
+	$items['uc_multiprice_calc/js/save/%'] = array(
+    'page callback' => 'uc_multiprice_calc_js_save',
+		'page arguments' => array(3),
+    'access arguments' => array('administer nodes'),
+    'type' => MENU_CALLBACK,
+  );
+
+  return $items;
+}
+
+function uc_multiprice_calc_theme() {
+  return array(
+    'uc_multiprice_calc_form' => array(
+      'arguments' => array('form' => NULL),
+    ),
+		'uc_multiprice_calc_element_form' => array(
+      'arguments' => array('form' => NULL),
+    ),
+  );
+}
+function theme_uc_multiprice_calc_element_form($form) {
+	$output = '';
+	$output .= drupal_render($form);
+	return $output;
+}
+
+function theme_uc_multiprice_calc_form($form) {
+	$path = drupal_get_path('module', 'uc_multiprice_calc');
+	drupal_add_js($path .'/js/uc_multiprice_calc.js', 'module', 'header');	
+	drupal_add_css($path .'/css/popup.css', 'module', 'all', FALSE);
+	
+  $header = array(array('data' => t('Country'), 'width' => '125px'), '', t('List price'), '', t('Cost'), '', t('Sell price'), t('Delete'));
+	//  $header = array(array('data' => t('Country'), 'colspan' => '2'), array('data' => t('List price'), 'colspan' => '2'), array('data' => t('Cost'), 'colspan' => '2'),array('data' => t('Sell price'), 'colspan' => '2'), t('Delete'));
+  $row = array();
+  foreach (element_children($form) as $country_id) {
+		$row = array();
+		if ($country_id != '0' || $country_id != 'calc') {
+			$row[] = check_plain($form[$country_id]['country']['#value']);
+			//$row[] = drupal_render($form[$country_id]['edit']['list_price']);
+			$row[] = drupal_render($form[$country_id]['edit']['list_price']);
+			$row[] = drupal_render($form[$country_id]['list_price']);
+			$row[] = drupal_render($form[$country_id]['edit']['cost']);
+			$row[] = drupal_render($form[$country_id]['cost']);
+			$row[] = drupal_render($form[$country_id]['edit']['sell_price']);
+			$row[] = drupal_render($form[$country_id]['sell_price']);
+			$row[] = drupal_render($form[$country_id]['delete']);
+		}elseif($country_id == '0'){
+			//print $country_id;
+			$row[] = check_plain($form[$country_id]['country']['#value']);
+			$row[] = '';
+			$row[] = drupal_render($form[$country_id]['list_price']);
+			$row[] = '';
+			$row[] = drupal_render($form[$country_id]['cost']);
+			$row[] = '';
+			$row[] = drupal_render($form[$country_id]['sell_price']);
+			$row[] = '';
+		}	
+    $rows[] = $row;
+		
+		$row = array();
+	  $row[] = array('data' => drupal_render($form[$country_id]['calc']['list_price']), 'colspan' => '8');
+	  $rows[] = array('data' => $row, 'id' => 'edit-multiprice-countries-'.$country_id.'-edit-list-price-calc', 'class' => 'popup');
+		
+		$row = array();
+	  $row[] = array('data' => drupal_render($form[$country_id]['calc']['cost']), 'colspan' => '8');
+	  $rows[] = array('data' => $row, 'id' => 'edit-multiprice-countries-'.$country_id.'-edit-cost-calc', 'class' => 'popup');
+		
+		$row = array();
+	  $row[] = array('data' => drupal_render($form[$country_id]['calc']['sell_price']), 'colspan' => '8');
+	  $rows[] = array('data' => $row, 'id' => 'edit-multiprice-countries-'.$country_id.'-edit-sell-price-calc', 'class' => 'popup');
+  }
+	//print_r($form);
+	// add wrapper
+	//$row = array();
+	//$row[] = array('data' => drupal_render($form['multiprice']['countries']['calc']), 'colspan' => '8', 'id' => 'popup');
+	//$rows[] = array('data' => $row, 'style' => 'display:none');
+	
+	$output .= theme('table', $header, $rows, array('id' => 'uc_multiprice_table'));
+	
+	//$output .= uc_multiprice_popup()."<input type='button' name='basic' value='Demo' class='basic demo'/> or <a href='#' class='basic'>Demo</a>";
+	
+	return $output;
+}
+
+function uc_multiprice_calc_element($country, $type) {
+	$data = unserialize($country->data);
+	//print_r($data);
+	//$type2 = 
+	//print_r($data);
+	$field['#theme'] = 'uc_multiprice_calc_element_form';
+	$field['enabled'] = array(
+			'#type' => 'checkbox',
+			'#title' => t('Enabled'),
+			'#default_value' => isset($data[$type]['enabled']) ? $data[$type]['enabled'] : 0,
+			'#attributes' => array('onchange' => 'uc_multiprice_calc("'. $country->country_id .'", "'.$type.'");'),
+	);
+	$field['country_id'] = array(
+    '#type' => 'hidden',
+    '#value' => $country->country_id,
+  );
+	$field['type'] = array(
+    '#type' => 'hidden',
+    '#value' => $type,
+  );
+	$field['operator'] = array(
+			'#type' => 'fieldset',
+			'#tree' => TRUE,
+			'#weight' => 1,
+			'#collapsible' => FALSE,
+			'#collapsed' => FALSE,
+	);
+	$field['operator']['value'] = array(
+    '#type' => 'select',
+    '#required' => FALSE,
+		'#options' => array('x' => 'x', '-' => '-', '+' => '+'),
+		'#attributes' => array('onchange' => 'uc_multiprice_calc("'. $country->country_id .'", "'.$type.'");'),
+    '#default_value' => isset($data[$type]) ? check_plain($data[$type]['value']) : 'x',
+  );
+	$field['1'] = array(
+			'#type' => 'fieldset',
+			'#tree' => TRUE,
+			'#weight' => 0,
+			'#collapsible' => FALSE,
+			'#collapsed' => FALSE,
+	);
+	$field['1']['operator'] = array(
+    '#type' => 'select',
+    '#required' => FALSE,
+		'#options' => array('default' => 'Default', 'custom' => 'Custom'),
+    '#default_value' => isset($data[$type]['1']) ? check_plain($data[$type]['1']['operator']) : 'default',
+		'#attributes' => array('onchange' => 'uc_multiprice_calc("'. $country->country_id .'", "'.$type.'");'),
+  );
+	//print $data[$type]['1']['value'];
+	$field['1']['value'] = array(
+    '#type' => 'textfield',
+    '#default_value' => isset($data[$type]['1']['value']) ? check_plain($data[$type]['1']['value']) : 0.00,
+		'#size' => 5,
+		'#attributes' => array('onchange' => 'uc_multiprice_calc("'. $country->country_id .'", "'.$type.'");'),
+		'#disabled' => ($data[$type]['1']['operator']=='default')? TRUE : FALSE,
+  );
+	$field['2'] = array(
+			'#type' => 'fieldset',
+			'#tree' => TRUE,
+			'#weight' => 2,
+			'#collapsible' => FALSE,
+			'#collapsed' => FALSE,
+	);
+	$field['2']['operator'] = array(
+    '#type' => 'select',
+		'#options' => array('default' => 'Default', 'custom' => 'Custom'),
+    '#default_value' => isset($data[$type]['2']) ? check_plain($data[$type]['2']['operator']) : 'default',
+		'#attributes' => array('onchange' => 'uc_multiprice_calc("'. $country->country_id .'", "'.$type.'");'),
+  );
+	$field['2']['value'] = array(
+    '#type' => 'textfield',
+    '#default_value' => isset($data[$type]['2']) ? check_plain($data[$type]['2']['value']) : 0.00,
+		'#size' => 5,
+		'#attributes' => array('onchange' => 'uc_multiprice_calc("'. $country->country_id .'", "'.$type.'");'),
+		'#disabled' => ($data[$type]['2']['operator']=='default')? TRUE : FALSE,
+  );
+	/*
+	$field['opslaan'] = array(
+		'#type' => 'button',
+		'#default_value' => t('Save'),
+		'#weight' => 1,
+		'#ahah' => array(
+			'path' => 'uc_multiprice_calc/js/save/'. $country->nid,
+			'wrapper' => 'popup',
+			'method' => 'replace',
+			'effect' => 'slide',
+			),
+	);
+	$field['cancel'] = array(
+		'#type' => 'button',
+		'#default_value' => t('Cancel'),
+		'#attributes' => array('onclick' => "uc_multiprice_calc_close(); return false;"),
+	);
+	*/
+
+  return $field;
+}
+
+function uc_multiprice_calc_field_element($country) {
+	$data = unserialize($country->data);
+	
+  $field['country'] = array(
+    '#type' => 'textfield',
+    '#default_value' => $country->country_name,
+  );
+	$field['edit']['list_price'] = array(
+		'#type' => 'button',
+		'#weight' => 1,
+		'#attributes' => array('class' => ($data['list_price']['enabled']==1) ? 'calc calc_on' : 'calc calc_off'),
+	);
+  $field['list_price'] = array(
+    '#type' => 'textfield',
+    '#required' => FALSE,
+    '#default_value' => isset($country->list_price) ? check_plain($country->list_price) : 0.00,
+    '#weight' => 0,
+    '#size' => 10,
+    '#maxlength' => 35,
+  );
+	$field['edit']['cost'] = array(
+		'#type' => 'button',
+		'#weight' => 1,
+		'#attributes' => array('class' => ($data['cost']['enabled']==1) ? 'calc calc_on' : 'calc calc_off'),
+	);
+  $field['cost'] = array(
+    '#type' => 'textfield',
+    '#required' => FALSE,
+    '#default_value' => isset($country->cost) ? check_plain($country->cost) : 0.00,
+    '#weight' => 1,
+    '#size' => 20,
+    '#maxlength' => 35,
+  );
+	$field['edit']['sell_price'] = array(
+		'#type' => 'button',
+		'#weight' => 1,
+		'#attributes' => array('class' => ($data['sell_price']['enabled']==1) ? 'calc calc_on' : 'calc calc_off'),
+	);
+  $field['sell_price'] = array(
+    '#type' => 'textfield',
+    '#required' => FALSE,
+    '#weight' => 2,
+    '#default_value' => isset($country->sell_price) ? check_plain($country->sell_price) : 0.00,
+    '#size' => 20,
+    '#maxlength' => 35,
+  );
+  $field['delete'] = array(
+    '#type' => 'checkbox',
+    '#required' => FALSE,
+  );
+  return $field;
+}
+
+/*
+function uc_multiprice_calc_js($country_id = NULL, $type = NULL) {
+  if (!$_POST || !$country_id) {
+    exit;
+  }
+	//print_r($_POST);
+	//print $country_id;
+	//exit;
+	$form_state = array('submitted' => FALSE);
+  $form_build_id = $_POST['form_build_id'];
+
+  // Add the new element to the stored form. Without adding the element to the
+  // form, Drupal is not aware of this new elements existence and will not
+  // process it. We retreive the cached form, add the element, and resave.
+  $form = form_get_cache($form_build_id, $form_state);
+  
+
+		// new field
+		$country = db_fetch_object(db_query("SELECT * FROM {uc_multiprice} WHERE country_id = %d", $country_id));
+
+		$field = uc_multiprice_calc_element($country, $type);
+
+		$form['multiprice']['countries']['calc'] = $field;
+
+  // Rebuild the form. 
+  $form = form_builder($_POST['form_id'], $form, $form_state);
+	
+  
+	// return correct part
+ // unset($form['multiprice']['calc']['#attributes']);
+  $output = drupal_render($form['multiprice']['countries']['calc']);
+	//print_r($form['multiprice']['countries']['calc']);
+	//exit;
+	
+	$output .= "<script>
+		//alert(Drupal.settings.uc_multiprice_country.data.list_price.enabled);
+		//uc_multiprice_calc_refill();
+		//$('#popup').show();
+		</script>";
+
+  print drupal_to_js(array('status' => TRUE, 'data' => $output));
+  exit;
+}
+
+function uc_multiprice_calc_js_save($nid) {
+  if (!$_POST) {
+    exit;
+  }
+
+	$element = $_POST['multiprice']['countries']['calc'];
+
+		//print_r($element);
+	//exit;
+	// get current data
+	$country = db_fetch_object(db_query("SELECT * FROM {uc_multiprice} WHERE nid = %d AND country_id = %d", 
+																			$nid, $element['country_id']));
+	$data = unserialize($country->data);
+	
+	// create new data and merge
+	$data_new = $element;
+	unset($data_new['type']);
+	unset($data_new['country_id']);
+	$data[$element['type']] = $data_new;
+	
+		//print_r($data);
+	//exit;
+	db_query("UPDATE {uc_multiprice} SET data = '%s' WHERE nid = %d AND country_id = %d", serialize($data), $nid, $element['country_id']);
+
+	$output = "<script>uc_multiprice_calc_close();</script>";
+		
+  print drupal_to_js(array('status' => TRUE, 'data' => $output));
+  exit;
+}
+*/


