3  <form name="CalcQtyForm" id="calc_qty_form_id">
 
   5   <input type="hidden" name="input_name" value="[% HTML.escape(input_name) %]">
 
   6   <input type="hidden" name="input_id"   value="[% HTML.escape(input_id) %]">
 
   9    <tr><td>[% 'Please insert object dimensions below.' | $T8 %]</td></tr>
 
  15       <tr class="listheading">
 
  16        [% FOREACH col = HEADER %]
 
  17         <th nowrap class="listheading">[% col.column_title %]</a></th>
 
  21       [% FOREACH row = VARIABLES %]
 
  22        <tr class="listrow[% loop.count % 2 %]">
 
  23         <td>[% HTML.escape(row.description) %]:</td><td><input id="[% row.name %]" name="[% row.name %]" value=""></td>
 
  24         <td>[% HTML.escape(row.unit) %]</td>
 
  32  <button type="button" onclick="calculate_qty()">[% 'Calculate' | $T8 %]</button>
 
  35  <script type="text/javascript">
 
  36    function calculate_qty() {
 
  37 [%- FOREACH row = VARIABLES %]
 
  38      var [% row.name %] = parse_amount('[% MYCONFIG.numberformat %]', $('#calc_qty_form_id #[% row.name %]').val());
 
  40      var result = [% formel %];
 
  41      result = number_format(result, 2, '[% MYCONFIG.numberformat %]');
 
  42      if (document.CalcQtyForm.input_id.value) {
 
  43        document.getElementById(document.CalcQtyForm.input_id.value).value = result;
 
  45        document.getElementsByName(document.CalcQtyForm.input_name.value)[0].value = result;
 
  47      $('#calc_qty_dialog').dialog('close');
 
  50    function parse_amount(numberformat, amount) {
 
  51      if (numberformat == '1.000,00' || numberformat == '1000,00')
 
  52        amount = amount.replace(/\./g, "").replace(/,/, ".");
 
  53      if (numberformat == "1'000.00")
 
  54        amount = amount.replace(/\'/g, '');
 
  55      return amount.replace(/,/g, '');
 
  58    function number_format(number, precision, numberformat) {
 
  59      number = Math.round( number * Math.pow(10, precision) ) / Math.pow(10, precision);
 
  60      var nf     = numberformat.replace(/\d/g, '').split('').reverse();
 
  64      str_number = number+"";
 
  65      arr_int = str_number.split(".");
 
  66      if(!arr_int[0]) arr_int[0] = "0";
 
  67      if(!arr_int[1]) arr_int[1] = "";
 
  68      if(arr_int[1].length < precision) {
 
  69        nachkomma = arr_int[1];
 
  70        for(i=arr_int[1].length+1; i <= precision; i++) {
 
  73        arr_int[1] = nachkomma;
 
  75      if(th_sep != "" && arr_int[0].length > 3) {
 
  76        raw_arr_int = arr_int[0];
 
  78        for(j = 3; j < raw_arr_int.length ; j+=3) {
 
  79          arr_int[0] = th_sep + raw_arr_int.slice(raw_arr_int.length - j, raw_arr_int.length - j + 3) +  arr_int[0] + "";
 
  81        str_first = raw_arr_int.substr(0, (raw_arr_int.length % 3 == 0) ? 3 : (raw_arr_int.length % 3));
 
  82        arr_int[0] = str_first + arr_int[0];
 
  84      return arr_int[0] + sep + arr_int[1];