Fixed edition of purchase order (bug #0000001)
[fa-stable.git] / js / utils.js
index a2dc4ba1783f2744cf49e2bfd5ede4ed05f07ff3..0bb87d949fc05b8b0d05121061394e96fe095cdf 100644 (file)
@@ -26,7 +26,6 @@
                        values[trigger] = 1;
                // this is to avoid caching problems
                values['_random'] = Math.random()*1234567;
-
         JsHttpRequest.query(
             'POST '+url, // backend
                values,
@@ -45,7 +44,7 @@
                        // seek element by id if there is no elemnt with given name
                          objElement = document.getElementsByName(id)[0] || document.getElementById(id);
                  if(cmd=='as') {
-                                 eval("objElement."+property+"=data;");
+                                 eval("objElement.setAttribute('"+property+"',"+data+");");
                          } else if(cmd=='up') {
 //                             if(!objElement) debug('No element "'+id+'"');
                            if (objElement.tagName == 'INPUT' || objElement.tagName == 'TEXTAREA')
 //
 //     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";
@@ -150,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) {