noalyss Version-9
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/*! \file
23 * \brief This file show a little online calculator, in the caller
24 * the span id result, listing, the id form calc_line and the
25 *
26 *
27 */
28var p_history="";
29var p_variable="";
30/**
31 * Compute and update the box
32 * @see show_calc()
33 * @returns nothing
34 */
35// add input
36function cal()
37{
38 p_variable=this.document.getElementById('inp').value;
39 if (p_variable.search(/^\s*$/) !=-1)
40 {
41 return;
42 }
43 try
44 {
45 Compute();
46 p_variable=p_variable.replace(/[a-z]/,'');
47 p_variable=p_variable.replace(/[A-Z]/,'');
48 p_variable=p_variable.replace(/</,'');
49 p_variable=p_variable.replace(/%/,'');
50 p_variable=p_variable.replace(/;/,'');
51 p_variable=p_variable.replace(/>/,'');
52 p_variable=p_variable.replace(/ /g,"");
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
58 sub=eval(p_variable);
59 var result=parseFloat(sub);
60 result=Math.round(result*10000)/10000;
61 }
62 catch(exception)
63 {
64 alert_box(content[48]+p_variable);
65 return false;
66 }
67 p_history=p_variable+"="+result.toString()+'<br>'+p_history;
68 var str_sub='<p class="highlight"> '+p_variable+" = "+result.toString()+'</p>';
69 this.document.getElementById("sub_total").innerHTML=str_sub;
70 this.document.getElementById("listing").innerHTML=p_history;
71 this.document.getElementById('inp').value=result;
72}
73// Clean
74//
75function CleanHistory()
76{
77 this.document.getElementById('listing').innerHTML="";
78 this.document.getElementById('sub_total').innerHTML="";
79 this.document.getElementById('inp').value="";
80 this.document.getElementById('inp').focus();
81
82}
83function Clean()
84{
85 this.document.getElementById('inp').value="";
86 this.document.getElementById('inp').focus();
87}
88function Compute()
89{
90 var tot=0;
91 var ret="";
92
93 this.document.getElementById('inp').value="";
94 this.document.getElementById('inp').focus();
95}