noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
calc.js
Go to the documentation of this file.
1/*
2 * This file is part of NOALYSS.
3 *
4 * NOALYSS is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * NOALYSS is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with NOALYSS; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18/* $Revision$ */
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/**
23 * @file
24 * This file show a little online calculator, in the caller the span id result,
25 * listing, the id form calc_line and the
26 *
27 *
28 */
29var p_history="";
30var p_variable="";
31/**
32 * Compute and update the box
33 * @see show_calc()
34 * @returns nothing
35 */
36// add input
37function cal()
38{
39 p_variable=this.document.getElementById('inp').value;
40 if (p_variable.search(/^\s*$/) !=-1)
41 {
42 return;
43 }
44 try
45 {
46 Compute();
47 p_variable=p_variable.replace(/[a-z]/,'');
48 p_variable=p_variable.replace(/[A-Z]/,'');
49 p_variable=p_variable.replace(/</,'');
50 p_variable=p_variable.replace(/%/,'');
51 p_variable=p_variable.replace(/;/,'');
52 p_variable=p_variable.replace(/>/,'');
53 p_variable=p_variable.replace(/ /g,"");
54 p_variable=p_variable.replace(/\+/g,"+ ");
55 p_variable=p_variable.replace(/-/g,"- ");
56 p_variable=p_variable.replace(/\//g,"/ ");
57 p_variable=p_variable.replace(/,/g,".");
58
59 sub=eval(p_variable);
60 var result=parseFloat(sub);
61 result=Math.round(result*10000)/10000;
62 }
63 catch(exception)
64 {
65 alert_box(content[48]+p_variable);
66 return false;
67 }
68 p_history=p_variable+"="+result.toString()+'<br>'+p_history;
69 var str_sub='<p class="highlight"> '+p_variable+" = "+result.toString()+'</p>';
70 this.document.getElementById("sub_total").innerHTML=str_sub;
71 this.document.getElementById("listing").innerHTML=p_history;
72 this.document.getElementById('inp').value=result;
73}
74// Clean
75//
76function CleanHistory()
77{
78 this.document.getElementById('listing').innerHTML="";
79 this.document.getElementById('sub_total').innerHTML="";
80 this.document.getElementById('inp').value="";
81 this.document.getElementById('inp').focus();
82
83}
84function Clean()
85{
86 this.document.getElementById('inp').value="";
87 this.document.getElementById('inp').focus();
88}
89function Compute()
90{
91 var tot=0;
92 var ret="";
93
94 this.document.getElementById('inp').value="";
95 this.document.getElementById('inp').focus();
96}