Four minor bug fixes
[fa-stable.git] / includes / ui / ui_view.inc
index f34a443b47a45205922ffd9aa7d4acbba3fec8bf..9f0e445092c0f99f8ad9eb1965788eed1fb705f3 100644 (file)
@@ -1066,29 +1066,73 @@ document.write(\"<div id='CC'></div>\");
 ";
        return $js;
 }
+//
+//     Javascript conversions to/from user numeric format.
+//
+function add_js_user_num() {
+       global $thoseps, $decseps;
+       $ts = $thoseps[user_tho_sep()];
+       $ds = $decseps[user_dec_sep()];
+
+       $js =
+       "<script language=\"javascript\">
+function price_format(post, num, dec) {
+       //num = num.toString().replace(/\\$|\\,/g,'');
+       if(isNaN(num))
+               num = \"0\";
+       sign = (num == (num = Math.abs(num)));
+       if(dec<0) dec = 2;
+       decsize = Math.pow(10, dec);
+       num = Math.floor(num*decsize+0.50000000001);
+       cents = num%decsize;
+       num = Math.floor(num/decsize).toString();
+       for( i=cents.toString().length; i<dec; i++){
+               cents = \"0\" + cents;
+       }
+       for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
+               num = num.substring(0,num.length-(4*i+3))+'".$ts."'+
+                       num.substring(num.length-(4*i+3));
+        num = ((sign)?'':'-') + num;
+        if(dec!=0) num = num + '".$ds."' + cents;
+       document.getElementsByName(post)[0].value = num;
+       }
+       function get_amount(doc) {
+               var val = document.getElementsByName(doc)[0].value;
+               val = val.replace(/\\".$ts."/g,'');
+               val = val.replace(/\\".$ds."/g,'.');
+               return 1*val;
+       }
+       </script>";
+  add_js_source($js);
+}
 
-function get_js_allocate() {
-       return "<script>function allocate_all(doc) {
-       var alloc = 1*document.getElementsByName('left_to_allocate')[0].value;
-       var amount = 1*document.getElementsByName('amount'+doc)[0].value;
-       var unallocated = 1*document.getElementsByName('un_allocated'+doc)[0].value;
+function add_js_allocate() {
+       $source =
+       "<script>
+       function allocate_all(doc) {
+       var alloc = get_amount('left_to_allocate');
+       var amount = get_amount('amount'+doc);
+       var unallocated = get_amount('un_allocated'+doc);
        if(unallocated<amount) amount = unallocated;
-       if( (unallocated-amount)<=alloc){
+       if((unallocated-amount)<=alloc){
                alloc-=unallocated-amount;
        amount=unallocated;
        }else{
        amount=amount+alloc;
        alloc=0;
        }
-       document.getElementsByName('amount'+doc)[0].value = amount;
-       document.getElementsByName('left_to_allocate')[0].value = alloc;
+       price_format('amount'+doc, amount, ".user_price_dec().");
+       price_format('left_to_allocate', alloc, ".user_price_dec().");
        }
        function allocate_none(doc) {
-               amount = document.getElementsByName('amount'+doc)[0];
-       document.getElementsByName('left_to_allocate')[0].value +=
-                       amount.value;
-       amount.value=0;  }
+       amount = get_amount('amount'+doc);
+       left = get_amount('left_to_allocate');
+       price_format('left_to_allocate',amount+left, ".user_price_dec().");
+       price_format('amount'+doc, 0, ".user_price_dec().");
+       }
        </script>";
+       add_js_user_num();
+       add_js_source($source);
 }
 
 function alert($msg)
@@ -1113,17 +1157,4 @@ if (!function_exists('_vd'))
        }
 }
 
-/* ************************************** Backward compatible */
-function do_clone($object)
-{
-       if (version_compare(phpversion(), '5.0') < 0)
-       {
-               return $object;
-       }
-       else
-       {
-               return @clone($object);
-       }
-}
-
 ?>
\ No newline at end of file