Replacing the PDF Engine with a slightly modified TCPDF
[fa-stable.git] / js / utils.js
index 5dbbcbf96c7cfc42b5494c32db685f313e84bf2a..0be2d4867dc1b7322e08500f8e83c2d35e631642 100644 (file)
 //
 //     User price formatting
 //
-function price_format(post, num, dec, label) {
+function price_format(post, num, dec, label, color) {
+       var el = label ? document.getElementById(post) : document.getElementsByName(post)[0];
        //num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num))
                num = "0";
@@ -149,9 +150,12 @@ function price_format(post, num, dec, label) {
         num = ((sign)?'':'-') + num;
         if(dec!=0) num = num + user.ds + cents;
        if(label)
-           document.getElementById(post).innerHTML = num;
+           el.innerHTML = num;
        else
-           document.getElementsByName(post)[0].value = num;
+           el.value = num;
+       if(color) {
+                       el.style.color = (sign) ? '' : '#FF0000';
+       }
 }
 
 function get_amount(doc, label) {
@@ -176,8 +180,8 @@ function setFocus(name, byId) {
   if(!name) {
        if (_focus)     
                name = _focus;  // last focus set in onfocus handlers
-       else {  // no current focus -  set it from from hidden var (first page display)
-         var cur = document.getElementsByName('_focus')[0];
+       else {  // no current focus (first page display) -  set it from from last form
+         var cur = document.getElementsByName('_focus')[document.forms.length-1];
          if(cur) name = cur.value;
        }
   }