+//
+// Javascript conversions to/from user numeric format.
+//
+function get_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) {
+ //num = num.toString().replace(/\\$|\\,/g,'');
+ if(isNaN(num))
+ num = \"0\";
+ sign = (num == (num = Math.abs(num)));
+ num = Math.floor(num*100+0.50000000001);
+ cents = num%100;
+ num = Math.floor(num/100).toString();
+ if(cents<10)
+ 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));
+ document.getElementsByName(post)[0].value = (((sign)?'':'-') + num + '".$ds."' + cents);
+ }
+ 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>";
+
+ return $js;
+}
+
+function get_js_allocate() {
+ return get_js_user_num() .
+ "<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){
+ alloc-=unallocated-amount;
+ amount=unallocated;
+ }else{
+ amount=amount+alloc;
+ alloc=0;
+ }
+ price_format('amount'+doc, amount);
+ price_format('left_to_allocate', alloc);
+ }
+ function allocate_none(doc) {
+ amount = get_amount('amount'+doc);
+ left = get_amount('left_to_allocate');
+ price_format('left_to_allocate',amount+left);
+ price_format('amount'+doc, 0);
+ }
+ </script>";
+}
+