/****************md5.js***************************/ /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * Distributed under the BSD License * See http://pajhome.org.uk/crypt/md5 for more info. */ /* * Configurable variables. You may need to tweak these to be compatible with * the server-side, but the defaults work in most cases. */ var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ /* * These are the functions you'll usually want to call * They take string arguments and return either hex or base-64 encoded strings */ function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));} function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));} function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));} function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); } function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); } function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); } /* * Perform a simple self-test to see if the VM is working */ function md5_vm_test() { return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72"; } /* * Calculate the MD5 of an array of little-endian words, and a bit length */ function core_md5(x, len) { /* append padding */ x[len >> 5] |= 0x80 << ((len) % 32); x[(((len + 64) >>> 9) << 4) + 14] = len; var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; for(var i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); c = md5_ff(c, d, a, b, x[i+10], 17, -42063); b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); a = safe_add(a, olda); b = safe_add(b, oldb); c = safe_add(c, oldc); d = safe_add(d, oldd); } return Array(a, b, c, d); } /* * These functions implement the four basic operations the algorithm uses. */ function md5_cmn(q, a, b, x, s, t) { return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); } function md5_ff(a, b, c, d, x, s, t) { return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); } function md5_gg(a, b, c, d, x, s, t) { return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); } function md5_hh(a, b, c, d, x, s, t) { return md5_cmn(b ^ c ^ d, a, b, x, s, t); } function md5_ii(a, b, c, d, x, s, t) { return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); } /* * Calculate the HMAC-MD5, of a key and some data */ function core_hmac_md5(key, data) { var bkey = str2binl(key); if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz); var ipad = Array(16), opad = Array(16); for(var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C; } var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz); return core_md5(opad.concat(hash), 512 + 128); } /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ function safe_add(x, y) { var lsw = (x & 0xFFFF) + (y & 0xFFFF); var msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); } /* * Bitwise rotate a 32-bit number to the left. */ function bit_rol(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); } /* * Convert a string to an array of little-endian words * If chrsz is ASCII, characters >255 have their hi-byte silently ignored. */ function str2binl(str) { var bin = Array(); var mask = (1 << chrsz) - 1; for(var i = 0; i < str.length * chrsz; i += chrsz) bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32); return bin; } /* * Convert an array of little-endian words to a string */ function binl2str(bin) { var str = ""; var mask = (1 << chrsz) - 1; for(var i = 0; i < bin.length * 32; i += chrsz) str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask); return str; } /* * Convert an array of little-endian words to a hex string. */ function binl2hex(binarray) { var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; var str = ""; for(var i = 0; i < binarray.length * 4; i++) { str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) + hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF); } return str; } /* * Convert an array of little-endian words to a base-64 string */ function binl2b64(binarray) { var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var str = ""; for(var i = 0; i < binarray.length * 4; i += 3) { var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16) | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 ) | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF); for(var j = 0; j < 4; j++) { if(i * 8 + j * 6 > binarray.length * 32) str += b64pad; else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); } } return str; } /****************graphics.js***************************/ /*Copyright 2006 www.cashmain.com. All Rights Reserved*/ /* This notice must be untouched at all times. wz_jsgraphics.js v. 2.33 The latest version is available at http://www.walterzorn.com or http://www.devira.com or http://www.walterzorn.de Copyright (c) 2002-2004 Walter Zorn. All rights reserved. Created 3. 11. 2002 by Walter Zorn (Web: http://www.walterzorn.com ) Last modified: 24. 10. 2005 Performance optimizations for Internet Explorer by Thomas Frank and John Holdsworth. fillPolygon method implemented by Matthieu Haller. High Performance JavaScript Graphics Library. Provides methods - to draw lines, rectangles, ellipses, polygons with specifiable line thickness, - to fill rectangles and ellipses - to draw text. NOTE: Operations, functions and branching have rather been optimized to efficiency and speed than to shortness of source code. LICENSE: LGPL This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA, or see http://www.gnu.org/copyleft/lesser.html */ var jg_ihtm, jg_ie, jg_fast, jg_dom, jg_moz, jg_n4 = (document.layers && typeof document.classes != "undefined"); function chkDHTM(x, i) { x = document.body || null; jg_ie = x && typeof x.insertAdjacentHTML != "undefined"; jg_dom = (x && !jg_ie && typeof x.appendChild != "undefined" && typeof document.createRange != "undefined" && typeof (i = document.createRange()).setStartBefore != "undefined" && typeof i.createContextualFragment != "undefined"); jg_ihtm = !jg_ie && !jg_dom && x && typeof x.innerHTML != "undefined"; jg_fast = jg_ie && document.all && !window.opera; jg_moz = jg_dom && typeof x.style.MozOpacity != "undefined"; } function pntDoc() { this.wnd.document.write(jg_fast? this.htmRpc() : this.htm); this.htm = ''; } function pntCnvDom() { var x = document.createRange(); x.setStartBefore(this.cnv); x = x.createContextualFragment(jg_fast? this.htmRpc() : this.htm); this.cnv.appendChild(x); this.htm = ''; } function pntCnvIe() { this.cnv.insertAdjacentHTML("BeforeEnd", jg_fast? this.htmRpc() : this.htm); this.htm = ''; } function pntCnvIhtm() { this.cnv.innerHTML += this.htm; this.htm = ''; } function pntCnv() { this.htm = ''; } function mkDiv(x, y, w, h) { this.htm += '
<\/div>'; } function mkDivIe(x, y, w, h) { this.htm += '%%'+this.color+';'+x+';'+y+';'+w+';'+h+';'; } function mkDivPrt(x, y, w, h) { this.htm += '
<\/div>'; } function mkLyr(x, y, w, h) { this.htm += '<\/layer>\n'; } var regex = /%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);/g; function htmRpc() { return this.htm.replace( regex, '
\n'); } function htmPrtRpc() { return this.htm.replace( regex, '
\n'); } function mkLin(x1, y1, x2, y2) { if (x1 > x2) { var _x2 = x2; var _y2 = y2; x2 = x1; y2 = y1; x1 = _x2; y1 = _y2; } var dx = x2-x1, dy = Math.abs(y2-y1), x = x1, y = y1, yIncr = (y1 > y2)? -1 : 1; if (dx >= dy) { var pr = dy<<1, pru = pr - (dx<<1), p = pr-dx, ox = x; while ((dx--) > 0) { ++x; if (p > 0) { this.mkDiv(ox, y, x-ox, 1); y += yIncr; p += pru; ox = x; } else p += pr; } this.mkDiv(ox, y, x2-ox+1, 1); } else { var pr = dx<<1, pru = pr - (dy<<1), p = pr-dy, oy = y; if (y2 <= y1) { while ((dy--) > 0) { if (p > 0) { this.mkDiv(x++, y, 1, oy-y+1); y += yIncr; p += pru; oy = y; } else { y += yIncr; p += pr; } } this.mkDiv(x2, y2, 1, oy-y2+1); } else { while ((dy--) > 0) { y += yIncr; if (p > 0) { this.mkDiv(x++, oy, 1, y-oy); p += pru; oy = y; } else p += pr; } this.mkDiv(x2, oy, 1, y2-oy+1); } } } function mkLin2D(x1, y1, x2, y2) { if (x1 > x2) { var _x2 = x2; var _y2 = y2; x2 = x1; y2 = y1; x1 = _x2; y1 = _y2; } var dx = x2-x1, dy = Math.abs(y2-y1), x = x1, y = y1, yIncr = (y1 > y2)? -1 : 1; var s = this.stroke; if (dx >= dy) { if (dx > 0 && s-3 > 0) { var _s = (s*dx*Math.sqrt(1+dy*dy/(dx*dx))-dx-(s>>1)*dy) / dx; _s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1; } else var _s = s; var ad = Math.ceil(s/2); var pr = dy<<1, pru = pr - (dx<<1), p = pr-dx, ox = x; while ((dx--) > 0) { ++x; if (p > 0) { this.mkDiv(ox, y, x-ox+ad, _s); y += yIncr; p += pru; ox = x; } else p += pr; } this.mkDiv(ox, y, x2-ox+ad+1, _s); } else { if (s-3 > 0) { var _s = (s*dy*Math.sqrt(1+dx*dx/(dy*dy))-(s>>1)*dx-dy) / dy; _s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1; } else var _s = s; var ad = Math.round(s/2); var pr = dx<<1, pru = pr - (dy<<1), p = pr-dy, oy = y; if (y2 <= y1) { ++ad; while ((dy--) > 0) { if (p > 0) { this.mkDiv(x++, y, _s, oy-y+ad); y += yIncr; p += pru; oy = y; } else { y += yIncr; p += pr; } } this.mkDiv(x2, y2, _s, oy-y2+ad); } else { while ((dy--) > 0) { y += yIncr; if (p > 0) { this.mkDiv(x++, oy, _s, y-oy+ad); p += pru; oy = y; } else p += pr; } this.mkDiv(x2, oy, _s, y2-oy+ad+1); } } } function mkLinDott(x1, y1, x2, y2) { if (x1 > x2) { var _x2 = x2; var _y2 = y2; x2 = x1; y2 = y1; x1 = _x2; y1 = _y2; } var dx = x2-x1, dy = Math.abs(y2-y1), x = x1, y = y1, yIncr = (y1 > y2)? -1 : 1, drw = true; if (dx >= dy) { var pr = dy<<1, pru = pr - (dx<<1), p = pr-dx; while ((dx--) > 0) { if (drw) this.mkDiv(x, y, 1, 1); drw = !drw; if (p > 0) { y += yIncr; p += pru; } else p += pr; ++x; } if (drw) this.mkDiv(x, y, 1, 1); } else { var pr = dx<<1, pru = pr - (dy<<1), p = pr-dy; while ((dy--) > 0) { if (drw) this.mkDiv(x, y, 1, 1); drw = !drw; y += yIncr; if (p > 0) { ++x; p += pru; } else p += pr; } if (drw) this.mkDiv(x, y, 1, 1); } } function mkOv(left, top, width, height) { var a = width>>1, b = height>>1, wod = width&1, hod = (height&1)+1, cx = left+a, cy = top+b, x = 0, y = b, ox = 0, oy = b, aa = (a*a)<<1, bb = (b*b)<<1, st = (aa>>1)*(1-(b<<1)) + bb, tt = (bb>>1) - aa*((b<<1)-1), w, h; while (y > 0) { if (st < 0) { st += bb*((x<<1)+3); tt += (bb<<1)*(++x); } else if (tt < 0) { st += bb*((x<<1)+3) - (aa<<1)*(y-1); tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3); w = x-ox; h = oy-y; if (w&2 && h&2) { this.mkOvQds(cx, cy, -x+2, ox+wod, -oy, oy-1+hod, 1, 1); this.mkOvQds(cx, cy, -x+1, x-1+wod, -y-1, y+hod, 1, 1); } else this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, oy-h+hod, w, h); ox = x; oy = y; } else { tt -= aa*((y<<1)-3); st -= (aa<<1)*(--y); } } this.mkDiv(cx-a, cy-oy, a-ox+1, (oy<<1)+hod); this.mkDiv(cx+ox+wod, cy-oy, a-ox+1, (oy<<1)+hod); } function mkOv2D(left, top, width, height) { var s = this.stroke; width += s-1; height += s-1; var a = width>>1, b = height>>1, wod = width&1, hod = (height&1)+1, cx = left+a, cy = top+b, x = 0, y = b, aa = (a*a)<<1, bb = (b*b)<<1, st = (aa>>1)*(1-(b<<1)) + bb, tt = (bb>>1) - aa*((b<<1)-1); if (s-4 < 0 && (!(s-2) || width-51 > 0 && height-51 > 0)) { var ox = 0, oy = b, w, h, pxl, pxr, pxt, pxb, pxw; while (y > 0) { if (st < 0) { st += bb*((x<<1)+3); tt += (bb<<1)*(++x); } else if (tt < 0) { st += bb*((x<<1)+3) - (aa<<1)*(y-1); tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3); w = x-ox; h = oy-y; if (w-1) { pxw = w+1+(s&1); h = s; } else if (h-1) { pxw = s; h += 1+(s&1); } else pxw = h = s; this.mkOvQds(cx, cy, -x+1, ox-pxw+w+wod, -oy, -h+oy+hod, pxw, h); ox = x; oy = y; } else { tt -= aa*((y<<1)-3); st -= (aa<<1)*(--y); } } this.mkDiv(cx-a, cy-oy, s, (oy<<1)+hod); this.mkDiv(cx+a+wod-s+1, cy-oy, s, (oy<<1)+hod); } else { var _a = (width-((s-1)<<1))>>1, _b = (height-((s-1)<<1))>>1, _x = 0, _y = _b, _aa = (_a*_a)<<1, _bb = (_b*_b)<<1, _st = (_aa>>1)*(1-(_b<<1)) + _bb, _tt = (_bb>>1) - _aa*((_b<<1)-1), pxl = new Array(), pxt = new Array(), _pxb = new Array(); pxl[0] = 0; pxt[0] = b; _pxb[0] = _b-1; while (y > 0) { if (st < 0) { st += bb*((x<<1)+3); tt += (bb<<1)*(++x); pxl[pxl.length] = x; pxt[pxt.length] = y; } else if (tt < 0) { st += bb*((x<<1)+3) - (aa<<1)*(y-1); tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3); pxl[pxl.length] = x; pxt[pxt.length] = y; } else { tt -= aa*((y<<1)-3); st -= (aa<<1)*(--y); } if (_y > 0) { if (_st < 0) { _st += _bb*((_x<<1)+3); _tt += (_bb<<1)*(++_x); _pxb[_pxb.length] = _y-1; } else if (_tt < 0) { _st += _bb*((_x<<1)+3) - (_aa<<1)*(_y-1); _tt += (_bb<<1)*(++_x) - _aa*(((_y--)<<1)-3); _pxb[_pxb.length] = _y-1; } else { _tt -= _aa*((_y<<1)-3); _st -= (_aa<<1)*(--_y); _pxb[_pxb.length-1]--; } } } var ox = 0, oy = b, _oy = _pxb[0], l = pxl.length, w, h; for (var i = 0; i < l; i++) { if (typeof _pxb[i] != "undefined") { if (_pxb[i] < _oy || pxt[i] < oy) { x = pxl[i]; this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, _oy+hod, x-ox, oy-_oy); ox = x; oy = pxt[i]; _oy = _pxb[i]; } } else { x = pxl[i]; this.mkDiv(cx-x+1, cy-oy, 1, (oy<<1)+hod); this.mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod); ox = x; oy = pxt[i]; } } this.mkDiv(cx-a, cy-oy, 1, (oy<<1)+hod); this.mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod); } } function mkOvDott(left, top, width, height) { var a = width>>1, b = height>>1, wod = width&1, hod = height&1, cx = left+a, cy = top+b, x = 0, y = b, aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1, st = (aa2>>1)*(1-(b<<1)) + bb, tt = (bb>>1) - aa2*((b<<1)-1), drw = true; while (y > 0) { if (st < 0) { st += bb*((x<<1)+3); tt += (bb<<1)*(++x); } else if (tt < 0) { st += bb*((x<<1)+3) - aa4*(y-1); tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-3); } else { tt -= aa2*((y<<1)-3); st -= aa4*(--y); } if (drw) this.mkOvQds(cx, cy, -x, x+wod, -y, y+hod, 1, 1); drw = !drw; } } function mkRect(x, y, w, h) { var s = this.stroke; this.mkDiv(x, y, w, s); this.mkDiv(x+w, y, s, h); this.mkDiv(x, y+h, w+s, s); this.mkDiv(x, y+s, s, h-s); } function mkRectDott(x, y, w, h) { this.drawLine(x, y, x+w, y); this.drawLine(x+w, y, x+w, y+h); this.drawLine(x, y+h, x+w, y+h); this.drawLine(x, y, x, y+h); } function jsgFont() { this.PLAIN = 'font-weight:normal;'; this.BOLD = 'font-weight:bold;'; this.ITALIC = 'font-style:italic;'; this.ITALIC_BOLD = this.ITALIC + this.BOLD; this.BOLD_ITALIC = this.ITALIC_BOLD; } var Font = new jsgFont(); function jsgStroke() { this.DOTTED = -1; } var Stroke = new jsgStroke(); function jsGraphics(id, wnd) { this.setColor = new Function('arg', 'this.color = arg.toLowerCase();'); this.setStroke = function(x) { this.stroke = x; if (!(x+1)) { this.drawLine = mkLinDott; this.mkOv = mkOvDott; this.drawRect = mkRectDott; } else if (x-1 > 0) { this.drawLine = mkLin2D; this.mkOv = mkOv2D; this.drawRect = mkRect; } else { this.drawLine = mkLin; this.mkOv = mkOv; this.drawRect = mkRect; } }; this.setPrintable = function(arg) { this.printable = arg; if (jg_fast) { this.mkDiv = mkDivIe; this.htmRpc = arg? htmPrtRpc : htmRpc; } else this.mkDiv = jg_n4? mkLyr : arg? mkDivPrt : mkDiv; }; this.setFont = function(fam, sz, sty) { this.ftFam = fam; this.ftSz = sz; this.ftSty = sty || Font.PLAIN; }; this.drawPolyline = this.drawPolyLine = function(x, y, s) { for (var i=0 ; i>1, b = (h -= 1)>>1, wod = (w&1)+1, hod = (h&1)+1, cx = left+a, cy = top+b, x = 0, y = b, ox = 0, oy = b, aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1, st = (aa2>>1)*(1-(b<<1)) + bb, tt = (bb>>1) - aa2*((b<<1)-1), pxl, dw, dh; if (w+1) while (y > 0) { if (st < 0) { st += bb*((x<<1)+3); tt += (bb<<1)*(++x); } else if (tt < 0) { st += bb*((x<<1)+3) - aa4*(y-1); pxl = cx-x; dw = (x<<1)+wod; tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-3); dh = oy-y; this.mkDiv(pxl, cy-oy, dw, dh); this.mkDiv(pxl, cy+y+hod, dw, dh); ox = x; oy = y; } else { tt -= aa2*((y<<1)-3); st -= aa4*(--y); } } this.mkDiv(cx-a, cy-oy, w+1, (oy<<1)+hod); }; /* fillPolygon method, implemented by Matthieu Haller. This javascript function is an adaptation of the gdImageFilledPolygon for Walter Zorn lib. C source of GD 1.8.4 found at http://www.boutell.com/gd/ THANKS to Kirsten Schulz for the polygon fixes! The intersection finding technique of this code could be improved by remembering the previous intertersection, and by using the slope. That could help to adjust intersections to produce a nice interior_extrema. */ this.fillPolygon = function(array_x, array_y) { var i; var y; var miny, maxy; var x1, y1; var x2, y2; var ind1, ind2; var ints; var n = array_x.length; if (!n) return; miny = array_y[0]; maxy = array_y[0]; for (i = 1; i < n; i++) { if (array_y[i] < miny) miny = array_y[i]; if (array_y[i] > maxy) maxy = array_y[i]; } for (y = miny; y <= maxy; y++) { var polyInts = new Array(); ints = 0; for (i = 0; i < n; i++) { if (!i) { ind1 = n-1; ind2 = 0; } else { ind1 = i-1; ind2 = i; } y1 = array_y[ind1]; y2 = array_y[ind2]; if (y1 < y2) { x1 = array_x[ind1]; x2 = array_x[ind2]; } else if (y1 > y2) { y2 = array_y[ind1]; y1 = array_y[ind2]; x2 = array_x[ind1]; x1 = array_x[ind2]; } else continue; // modified 11. 2. 2004 Walter Zorn if ((y >= y1) && (y < y2)) polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1); else if ((y == maxy) && (y > y1) && (y <= y2)) polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1); } polyInts.sort(integer_compare); for (i = 0; i < ints; i+=2) this.mkDiv(polyInts[i], y, polyInts[i+1]-polyInts[i]+1, 1); } }; this.drawString = function(txt, x, y) { this.htm += '
'+ txt + '<\/div>'; }; /* drawStringRect() added by Rick Blommers. Allows to specify the size of the text rectangle and to align the text both horizontally (e.g. right) and vertically within that rectangle */ this.drawStringRect = function(txt, x, y, width, halign) { this.htm += '
'+ txt + '<\/div>'; }; this.drawImage = function(imgSrc, x, y, w, h, a) { this.htm += '
'+ ''+ '<\/div>'; }; this.clear = function() { this.htm = ""; if (this.cnv) this.cnv.innerHTML = this.defhtm; }; this.mkOvQds = function(cx, cy, xl, xr, yt, yb, w, h) { this.mkDiv(xr+cx, yt+cy, w, h); this.mkDiv(xr+cx, yb+cy, w, h); this.mkDiv(xl+cx, yb+cy, w, h); this.mkDiv(xl+cx, yt+cy, w, h); }; this.setStroke(1); this.setFont('verdana,geneva,helvetica,sans-serif', String.fromCharCode(0x31, 0x32, 0x70, 0x78), Font.PLAIN); this.color = '#000000'; this.htm = ''; this.wnd = wnd || window; if (!(jg_ie || jg_dom || jg_ihtm)) chkDHTM(); if (typeof id != 'string' || !id) this.paint = pntDoc; else { this.cnv = document.all? (this.wnd.document.all[id] || null) : document.getElementById? (this.wnd.document.getElementById(id) || null) : null; this.defhtm = (this.cnv && this.cnv.innerHTML)? this.cnv.innerHTML : ''; this.paint = jg_dom? pntCnvDom : jg_ie? pntCnvIe : jg_ihtm? pntCnvIhtm : pntCnv; } this.setPrintable(false); this.id = id; } function integer_compare(x,y) { return (x < y) ? -1 : ((x > y)*1); } //2628==================== iecanvas.js =============================== /*----------------------------------------------------------------------------\ | IE Canvas 1.0 | | Emulation Initialization Script | |-----------------------------------------------------------------------------| | Created by Emil A Eklund | | (http://eae.net/contact/emil) | |-----------------------------------------------------------------------------| | Implementation of the canvas API for Internet Explorer. Uses VML. | |-----------------------------------------------------------------------------| | Copyright (c) 2005 Emil A Eklund | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -| | This program is free software; you can redistribute it and/or modify it | | under the terms of the MIT License. | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -| | Permission is hereby granted, free of charge, to any person obtaining a | | copy of this software and associated documentation files (the "Software"), | | to deal in the Software without restriction, including without limitation | | the rights to use, copy, modify, merge, publish, distribute, sublicense, | | and/or sell copies of the Software, and to permit persons to whom the | | Software is furnished to do so, subject to the following conditions: | | The above copyright notice and this permission notice shall be included in | | all copies or substantial portions of the Software. | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -| | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | | DEALINGS IN THE SOFTWARE. | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -| | http://eae.net/license/mit | |-----------------------------------------------------------------------------| | Dependencies: canvas.htc - Actual implementation | |-----------------------------------------------------------------------------| | 2005-12-27 | Work started. | | 2005-12-29 | First version posted. | | 2006-01-03 | Added htcFile argument to ieCanvasInit method. | |-----------------------------------------------------------------------------| | Created 2005-12-27 | All changes are in the log above. | Updated 2006-01-03 | \----------------------------------------------------------------------------*/ function ieCanvasInit(htcFile) { var ie, opera, a, nodes, i, oVml, oStyle, newNode; /* * Only proceed if browser is IE 6 or later (as all other major browsers * support canvas out of the box there is no need to try to emulate for * them, and besides only IE supports VML anyway. */ ie = navigator.appVersion.match(/MSIE (\d\.\d)/); opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1); if ((!ie) || (ie[1] < 6) || (opera)) { return; } /* * Recreate elements, as there is no canvas tag in HTML * The canvas tag is replaced by a new one created using createElement, * even though the same tag name is given the generated tag is slightly * different, it's created prefixed with a XML namespace declaration * */ nodes = document.getElementsByTagName('canvas'); for (i = 0; i < nodes.length; i++) { node = nodes[i]; if (node.getContext) { return; } // Other implementation, abort newNode = document.createElement('canvas'); newNode.id = node.id; newNode.style.width = node.width; newNode.style.height = node.height; node.parentNode.replaceChild(newNode, node); } /* Add VML includes and namespace */ document.namespaces.add("v"); oVml = document.createElement('object'); oVml.id = 'VMLRender'; oVml.codebase = 'vgx.dll'; oVml.classid = 'CLSID:10072CEC-8CC1-11D1-986E-00A0C955B42E'; document.body.appendChild(oVml); /* Add required css rules */ if ((!htcFile) || (htcFile == '')) { htcFile = 'iecanvas.htc';} oStyle = document.createStyleSheet(); oStyle.addRule('canvas', "behavior: url('" + htcFile + "');"); oStyle.addRule('v\\:*', "behavior: url(#VMLRender);"); } /****************piechart.js***************************/ //2628==================== piechart_canvas.js =============================== var g_graphics_map = new Array(); var g_piechart_colors = new Array("#9ACD32", "#F5DEB3", "#D8BFD8", "#D2B48C", "#8CB4D2", "#C0C0C0", "#FA8072", "#FFC0CB", "#708090", "#B0E0E6"); function PieChart(id) { this.id = id; this.labels = null; this.values = null; this.colors = null; this.radius = 0; } PieChart.prototype.setLabels = function(labels) { this.labels = labels; } PieChart.prototype.getLabels = function() { return this.labels; } PieChart.prototype.setValues = function(values) { this.values = values; } PieChart.prototype.getValues = function() { return this.values; } PieChart.prototype.setColors = function(colors) { this.colors = colors; } PieChart.prototype.getColors = function() { return this.colors; } PieChart.prototype.setRadius = function(radius) { this.radius = radius; } PieChart.prototype.getRadius = function() { return this.radius; } PieChart.prototype.render = function() { var element = document.getElementById(this.id); //var width = parseInt(element.style.width.replace("px","")); //var height = parseInt(element.style.height.replace("px","")); var width = parseInt(element.getAttribute("width")); var height = parseInt(element.getAttribute("height")); if(!width) width = parseInt(element.style.width.replace("px","")); if(!height) height = parseInt(element.style.height.replace("px","")); var radius = 0; if(this.radius <= 0 || this.radius * 2 > height || this.radius * 2 > width) radius = Math.round((height < width) ? (height / 2) : (width / 2)); else radius = this.radius; var colors = null; if(this.colors == null) colors = g_piechart_colors; else colors = this.colors; drawpie_with_color(this.id, radius, this.values, this.labels, width, height, colors); } function get_graphics(canvasid) { for(var i = 0 ; i < g_graphics_map.length; i++){ if(g_graphics_map[i].id == "i_" + canvasid) return g_graphics_map[i]; } g_graphics_map[g_graphics_map.length] = new jsGraphics("i_" + canvasid); return g_graphics_map[g_graphics_map.length - 1]; } function drawpie_with_color(canvasid, radius, values, labels, width, height, colors) { var cum_angle = 0; var total_value = 0; var canvas = document.getElementById(canvasid); var ctx; ctx = canvas.getContext('2d'); for(var i = 0 ; i < values.length && i< colors.length; i++) total_value += values[i]; ctx.strokeStyle = '#ffffff'; ctx.fillStyle = '#FEDA61'; ctx.beginPath(); ctx.arc(radius, radius, radius, 0, Math.PI * 2, true); ctx.closePath(); ctx.fill(); for(var i = 0; i < values.length && i< colors.length; i++){ var angle = (Math.PI * 2 * values[i]) / total_value; if(angle <= (Math.PI * 2 / 360)) continue; if(i < colors.length) ctx.fillStyle = colors[i]; else ctx.fillStyle = '#dddddd'; ctx.beginPath(); ctx.arc(radius, radius, radius - 5, cum_angle + angle, cum_angle, true); ctx.lineTo(radius,radius); ctx.closePath(); ctx.fill(); ctx.stroke(); cum_angle += angle; } ctx.save(); var graphics = get_graphics(canvasid); if(graphics == null){ alert("Graphics is null"); return true; } graphics.clear(); graphics.setPrintable(true); graphics.setColor('black'); graphics.setFont("verdana","12px",Font.NORMAL); for(var i = 0 ; i < labels.length && i< colors.length; i++){ var max_length = ((labels.length > colors.length) ? colors.length: labels.length); graphics.setColor(colors[max_length - i - 1]); graphics.fillRect(radius * 2 + 5, height-i*15 - 15, 13, 13); graphics.setColor('black'); if(labels.length > colors.length && i == 0){ var others_value = 0; for(var k = max_length - 1 ; k < labels.length; k++) others_value += values[k]; var percentage = others_value * 100 / total_value; percentage = Math.round(percentage * 100) / 100; graphics.drawStringRect("Other" + "(" + percentage + "%)", radius * 2 + 20 , height - i * 15 - 15 , width - (radius * 2), 15 ,"left"); }else{ var percentage = values[max_length - i - 1] * 100 / total_value; percentage = Math.round(percentage * 100) / 100; graphics.drawStringRect(labels[max_length - i - 1] + "(" + percentage + "%)", radius * 2 + 20 , height - i * 15 - 15 , width - (radius * 2), 15 ,"left"); } } ctx.save(); graphics.paint(); return true; } function drawpie(canvasid, radius, values, labels, width, height) { return drawpie_with_color(canvasid, radius, values, labels, width, height, g_piechart_colors); } /****************tx_entries.js***************************/ var TRANSACTION_PREFIX_DEFINE = "T"; var TRANSFER_PREFIX_DEFINE = "F"; var ACCOUNT_PREFIX_DEFINE = "A"; var GROUP_PREFIX_DEFINE = "G"; var g_tx_manager = new TxEntriesManager(); //////////////////////////////////////////////////////////////////////////////////// function date2Str(date) { return date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear(); } function str2Date(string) { var temp = string.split("-"); return new Date(parseInt(temp[2]), parseInt(temp[1]) - 1, parseInt(temp[0])); } //////////////////////////////////////////////////////////////////////////////////// function is_numeric(sText) { var ValidChars = "0123456789."; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++){ Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } //////////////////////////////////////////////////////////////////////////////////// var dtCh= "-"; var minYear=1900; var maxYear=2100; function isInteger(s){ var i; for (i = 0; i < s.length; i++){ // Check that current character is number. var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } // All characters are numbers. return true; } function stripCharsInBag(s, bag){ var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++){ var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function daysInFebruary (year){ // February has 29 days in any year evenly divisible by four, // EXCEPT for centurial years which are not also divisible by 400. return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); } function DaysArray(n) { for (var i = 1; i <= n; i++) { this[i] = 31 if (i==4 || i==6 || i==9 || i==11) {this[i] = 30} if (i==2) {this[i] = 29} } return this } function isDate(dtStr){ var daysInMonth = DaysArray(12) var pos1=dtStr.indexOf(dtCh) var pos2=dtStr.indexOf(dtCh,pos1+1) var strDay=dtStr.substring(0,pos1) var strMonth=dtStr.substring(pos1+1,pos2) var strYear=dtStr.substring(pos2+1) strYr=strYear if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1) if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1) for (var i = 1; i <= 3; i++) { if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1) } month=parseInt(strMonth) day=parseInt(strDay) year=parseInt(strYr) if (pos1==-1 || pos2==-1){ //alert("The date format should be : dd-mm-yyyy") return false } if (strMonth.length<1 || month<1 || month>12){ //alert("Please enter a valid month") return false } if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){ //alert("Please enter a valid day") return false } if (strYear.length != 4 || year==0 || yearmaxYear){ //alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear) return false } if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){ //alert("Please enter a valid date") return false } return true } ////////////////////////////////////////////////////////////////////////////////////// function TxEntriesManager() { this.entries = new Array(); } TxEntriesManager.prototype.get_transfer_from_balance = function(account, from_account) { if(!account || !from_account) return null; var balance = 0; for(var i = 0; i < this.entries.length; i++){ if(this.entries[i]){ if(this.entries[i] instanceof Transfer){ var transfer = this.entries[i]; if(transfer.to_account != account || transfer.from_account != from_account) continue; balance += transfer.amount; } } } return balance; } TxEntriesManager.prototype.get_transfer_to_balance = function(account, to_account) { if(!account || !to_account) return null; var balance = 0; for(var i = 0; i < this.entries.length; i++){ if(this.entries[i]){ if(this.entries[i] instanceof Transfer){ var transfer = this.entries[i]; if(transfer.from_account != account || transfer.to_account != to_account) continue; balance += transfer.amount; } } } return balance; } TxEntriesManager.prototype.get_group_balance_in_period = function(group, starttime, endtime) { var balance = 0; if(starttime.valueOf() > endtime.valueOf()) return 0; for(var i = 0; i < this.entries.length; i++){ if(this.entries[i]){ if(this.entries[i] instanceof Transaction){ var transaction = this.entries[i]; if(transaction.date.valueOf() < starttime || transaction.date.valueOf() >= endtime) continue; if(transaction.group == group){ balance += transaction.deposit; balance -= transaction.expense; } } } } return balance; } TxEntriesManager.prototype.get_group_balance = function(group, account) { var balance = 0; for(var i = 0; i < this.entries.length; i++){ if(this.entries[i]){ if(this.entries[i] instanceof Transaction){ var transaction = this.entries[i]; if(account && transaction.account != account) continue; if(transaction.group == group){ balance += transaction.deposit; balance -= transaction.expense; } } } } return balance; } TxEntriesManager.prototype.get_account_balance = function(account) { var balance = 0; for(var i = 0; i < this.entries.length; i++){ if(this.entries[i]){ if(this.entries[i] instanceof Transaction){ var transaction = this.entries[i]; if(transaction.account == account){ balance += transaction.deposit; balance -= transaction.expense; } }else if(this.entries[i] instanceof Transfer){ var transfer = this.entries[i]; if(transfer.to_account == account) balance += transfer.amount; else if(transfer.from_account == account) balance -= transfer.amount; } } } return balance; } TxEntriesManager.prototype.create_transaction = function(date, group, description, expense, deposit, account) { var transaction = new Transaction(); transaction.id = this.entries.length; transaction.date = date; transaction.group = group; transaction.description = description; transaction.expense = expense; transaction.deposit = deposit; transaction.account = account; this.entries[this.entries.length] = transaction; return transaction; } //T:[id]:[date]:[group]:[description]:[expense]:[deposit]:[account]; TxEntriesManager.prototype.convert_to_transaction = function(message) { var items = message.split(":"); if(items.length != 8 || items[0] != TRANSACTION_PREFIX_DEFINE) return null; var transaction = new Transaction(); transaction.id = parseInt(unescape(items[1])); transaction.date = str2Date(unescape(items[2])); transaction.group = this.search_group(unescape(items[3])); if(transaction.group == null) transaction.group = this.create_group(unescape(items[3]), ""); transaction.description = unescape(items[4]); transaction.expense = parseFloat(unescape(items[5])); transaction.deposit = parseFloat(unescape(items[6])); transaction.account = this.search_account(unescape(items[7])); if(transaction.account == null) transaction.account = this.create_account(unescape(items[7]), ""); if(this.entries.length < transaction.id && this.entries[transaction.id] == null) this.entries[transaction.id] = transaction; else{ transaction.id = this.entries.length; this.entries[this.entries.length] = transaction; } return transaction; } TxEntriesManager.prototype.remove_transaction = function(transaction) { if(transaction.id < this.entries.length && this.entries[transaction.id] != null && this.entries[transaction.id] instanceof Transaction && this.entries[transaction.id] == transaction){ this.entries[transaction.id] = null; return; } for(var i = 0 ; i < this.entries.length; i++) if(this.entries[i] instanceof Transaction && this.entries[i] == transaction) this.entries[i] = null; } TxEntriesManager.prototype.create_transfer = function (date, from_account, to_account, description, amount) { var transfer = new Transfer(); transfer.id = this.entries.length; transfer.date = date; transfer.from_account = from_account; transfer.to_account = to_account; transfer.description = description; transfer.amount = amount; this.entries[this.entries.length] = transfer; return transfer; } //F:[id]:[date]:[from_account]:[to_account]:[description]:[amount]; TxEntriesManager.prototype.convert_to_transfer = function(message) { var items = message.split(":"); if(items.length != 7 || items[0] != TRANSFER_PREFIX_DEFINE) return null; var transfer = new Transfer(); transfer.id = parseInt(unescape(items[1])); transfer.date = str2Date(unescape(items[2])); transfer.from_account = this.search_account(unescape(items[3])); if(transfer.from_account == null) transfer.from_account = this.create_account(unescape(items[3]), ""); transfer.to_account = this.search_account(unescape(items[4])); if(transfer.to_account == null) transfer.to_account = this.create_account(unescape(items[4]), ""); transfer.description = unescape(items[5]); transfer.amount = parseFloat(unescape(items[6])); if(this.entries.length < transfer.id && this.entries[transfer.id] == null) this.entries[transfer.id] = transfer; else{ transfer.id = this.entries.length; this.entries[this.entries.length] = transfer; } return transfer; } TxEntriesManager.prototype.remove_transfer = function(transfer) { if(transfer.id < this.entries.length && this.entries[transfer.id] != null && this.entries[transfer.id] instanceof Transfer && this.entries[transfer.id] == transfer){ this.entries[transfer.id] = null; return; } for(var i = 0 ; i < this.entries.length; i++) if(this.entries[i] instanceof Transfer && this.entries[i] == transfer) this.entries[i] = null; } TxEntriesManager.prototype.is_account_empty = function(account) { var isEmptyAccount = true; for(var i = 0; i < this.entries.length; i++){ if(this.entries[i] && this.entries[i] instanceof Transaction && this.entries[i].account == account){ isEmptyAccount = false; break; }else if(this.entries[i] && this.entries[i] instanceof Transfer && (this.entries[i].to_account == account || this.entries[i].from_account == account)){ isEmptyAccount = false; break; } } return isEmptyAccount; } TxEntriesManager.prototype.create_account = function(strAccountName, strDescription) { var account = new Account(); account.id = this.entries.length; account.name = strAccountName; account.description = strDescription; account.order = this.entries.length; this.entries[this.entries.length] = account; return account; } TxEntriesManager.prototype.search_account = function(strAccountName) { for(var i = 0 ; i < this.entries.length; i++) if(this.entries[i] && this.entries[i] instanceof Account && this.entries[i].name == strAccountName) return this.entries[i]; return null; } TxEntriesManager.prototype.remove_account = function(account) { if(account.id < this.entries.length && this.entries[account.id] != null && this.entries[account.id] instanceof Account && this.entries[account.id] == account){ this.entries[account.id] = null; return; } for(var i = 0 ; i < this.entries.length; i++) if(this.entries[i] instanceof Account && this.entries[i] == account) this.entries[i] = null; } TxEntriesManager.prototype.combine_accounts = function(from_strAccount, to_strAccount) { var from_account = this.search_account(from_strAccount); var to_account = this.search_account(to_strAccount); if(from_account && to_account){ for(var i = 0 ; i < this.entries.length; i++){ if(!this.entries[i]) continue; if(this.entries[i] instanceof Transfer){ var transfer = this.entries[i]; if(transfer.to_account == from_account) transfer.to_account = to_account; if(transfer.from_account == from_account) transfer.from_account = to_account; }else if(this.entries[i] instanceof Transaction){ var transaction = this.entries[i]; if(transaction.account == from_account) transaction.account = to_account; } } } } //A:[id]:[name]:[description]:[order]; TxEntriesManager.prototype.convert_to_account = function(message) { var items = message.split(":"); if(items.length != 5 || items[0] != ACCOUNT_PREFIX_DEFINE) return null; var account = new Account(); account.id = parseInt(unescape(items[1])); account.name = unescape(items[2]); account.description = unescape(items[3]); account.order = parseInt(unescape(items[4])); if(this.entries.length < account.id && this.entries[account.id] == null) this.entries[account.id] = account; else{ account.id = this.entries.length; this.entries[this.entries.length] = account; } return account; } TxEntriesManager.prototype.search_group = function (strGroupName) { for(var i = 0 ; i < this.entries.length; i++) if(this.entries[i] && this.entries[i] instanceof Group && this.entries[i].name == strGroupName) return this.entries[i]; return null; } TxEntriesManager.prototype.remove_group = function(group) { if(group.id < this.entries.length && this.entries[group.id] != null && this.entries[group.id] instanceof Group && this.entries[group.id] == group){ this.entries[group.id] = null; }else{ for(var i = 0 ; i < this.entries.length; i++) if(this.entries[i] instanceof Group && this.entries[i] == group) this.entries[i] = null; } /*var null_group = this.entries[i].search_group("---"); if(!null_group) this.entries[i].create_group("---"); for(var i = 0 ; i < this.entries.length; i++) if(this.entries[i] instanceof Transaction && this.entries[i].group == group) this.entries[i].group = null_group; */ } TxEntriesManager.prototype.is_group_empty = function(group) { var isEmpty = true; for(var i = 0; i < this.entries.length; i++){ if(this.entries[i] && this.entries[i] instanceof Transaction && this.entries[i].group == group){ isEmpty = false; break; } } return isEmpty; } TxEntriesManager.prototype.create_group = function(strGroupName, strDescription) { var group = new Group(); group.id = this.entries.length; group.name = strGroupName; group.description = strDescription; group.order = this.entries.length; this.entries[this.entries.length] = group; return group; } TxEntriesManager.prototype.convert_to_group = function(message) { var items = message.split(":"); if(items.length != 5 || items[0] != GROUP_PREFIX_DEFINE) return null; var group = new Group(); group.id = parseInt(unescape(items[1])); group.name = unescape(items[2]); group.description = unescape(items[3]); group.order = parseInt(unescape(items[4])); if(this.entries.length < group.id && this.entries[group.id] == null) this.entries[group.id] = group; else{ group.id = this.entries.length; this.entries[this.entries.length] = group; } return group; } TxEntriesManager.prototype.toString = function() { var res = ""; for(var i = 0 ; i < this.entries.length; i++){ if(this.entries[i]) res += this.entries[i].toString() + ";"; } return res; } TxEntriesManager.prototype.import_save = function(message) { var items = message.split(";"); for(var i = 0 ; i < items.length; i++){ if(items[i].length != 0){ if(items[i].charAt(0) == TRANSACTION_PREFIX_DEFINE) this.convert_to_transaction(items[i]); else if(items[i].charAt(0) == TRANSFER_PREFIX_DEFINE) this.convert_to_transfer(items[i]); else if(items[i].charAt(0) == ACCOUNT_PREFIX_DEFINE) this.convert_to_account(items[i]); else if(items[i].charAt(0) == GROUP_PREFIX_DEFINE) this.convert_to_group(items[i]); } } } TxEntriesManager.prototype.reload_save = function(message) { delete g_tx_manager; g_tx_manager = new TxEntriesManager(); g_tx_manager.import_save(message); } ////////////////////////////////////////////////////////////////////////////////////// function Transaction() { this.id = -1; this.date = null; this.group = null; this.description= ""; this.expense = 0; this.deposit = 0; this.account = null; } Transaction.prototype.toString = function() { return TRANSACTION_PREFIX_DEFINE + ":" + escape(this.id) + ":" + escape(date2Str(this.date)) + ":" + escape(this.group.name) + ":" + escape(this.description) + ":" + escape(this.expense) + ":" + escape(this.deposit) + ":" + escape(this.account.name); } ////////////////////////////////////////////////////////////////////////////////////// function Transfer() { this.id = -1; this.date= null; this.from_account = null; this.to_account = null; this.description= ""; this.amount = 0; } Transfer.prototype.toString = function() { return TRANSFER_PREFIX_DEFINE + ":" + escape(this.id) + ":" + escape(date2Str(this.date)) + ":" + escape(this.from_account.name) + ":" + escape(this.to_account.name) + ":" + escape(this.description) + ":" + escape(this.amount); } ////////////////////////////////////////////////////////////////////////////////////// function Account() { this.id = -1; this.name = ""; this.description = ""; this.order = -1; } Account.prototype.toString = function(){ return ACCOUNT_PREFIX_DEFINE + ":" + escape(this.id) + ":" + escape(this.name) + ":" + escape(this.description) + ":" + escape(this.order); } ////////////////////////////////////////////////////////////////////////////////////// function Group() { this.id = -1; this.name = ""; this.description = ""; this.order = -1; } Group.prototype.toString = function(){ return GROUP_PREFIX_DEFINE + ":" + escape(this.id) + ":" + escape(this.name) + ":" + escape(this.description) + ":" + escape(this.order); } /****************ui_handle.js***************************/ /*Copyright 2006 www.cashmain.com. All Rights Reserved*/ var g_current_account = null; var g_account_menu_element = null; var g_transaction_menu_element = null; var g_transfer_menu_element = null; var g_overall_piechart_positive_colors = new Array("#9ACD32", "#7B68EE", "#94F48E", "#D2B48C", "#8CB4D2", "#C0C0C0", "#FA8072", "#FFC0CB", "#708090", "#B0E0E6"); var g_overall_piechart_negative_colors = new Array("#9ACD32", "#7B68EE", "#94F48E", "#D2B48C", "#8CB4D2", "#C0C0C0", "#FA8072", "#FFC0CB", "#708090", "#B0E0E6"); //=================================================================== var g_is_ns6 = document.getElementById&&!document.all var g_is_showing_menu = false ; var g_menu_selected_object = null ; var g_is_over_popup_menu = false; //document.onclick=eventHandler_onHideMenu; function groupOnPicked(id, value) { set_input_value(id, value); } function dateOnChanged(e){} function eventHandler_onHideMenu() { if( g_is_showing_menu ){ if( g_is_over_popup_menu == false ){ g_is_showing_menu = false ; g_is_over_popup_menu = false; var menudiv = document.getElementById(CASHMAIN_MENU_ID); menudiv.style.display = "none" ; } } } function eventHandler_saveToEmailKeyPress(e) { if (!e) e = window.event; if(e){ if (e.keyCode) code = e.keyCode; else if (e.which) code = e.which; if(code == 13) return eventHandler_saveToEmail(); } } function eventHandler_saveToEmail() { set_input_value(CASHMAIN_SAVE_TO_EMAIL_ID,g_tx_manager.toString()); return true; } function eventHandler_saveToCashmain() { set_input_value(CASHMAIN_SAVE_TO_CASHMAIN_DATA_ID,g_tx_manager.toString()); set_input_value(CASHMAIN_SAVE_TO_CASHMAIN_TOKEN_ID, document.getElementById(CASHMAIN_USERNAME_ID).value + "/" + hex_md5(document.getElementById(CASHMAIN_PASSWORD_ID).value)); document.getElementById(CASHMAIN_SAVE_TO_CASHMAIN_FORM_ID).submit(); } function eventHandler_loadFromCashmain() { set_input_value(CASHMAIN_LOAD_FROM_CASHMAIN_TOKEN_ID, document.getElementById(CASHMAIN_USERNAME_ID).value + "/" + hex_md5(document.getElementById(CASHMAIN_PASSWORD_ID).value)); document.getElementById(CASHMAIN_LOAD_FROM_CASHMAIN_FORM_ID).submit(); } function eventHandler_generateReport() { set_input_value("report_data",g_tx_manager.toString()); document.report.submit(); } function eventHandler_newAccountKeyPress(e) { if (!e) e = window.event; if(e){ if (e.keyCode) code = e.keyCode; else if (e.which) code = e.which; if(code == 13) eventHandler_newAccount(); } } function eventHandler_newAccount() { var newbook_input = document.getElementById(CASHMAIN_NEW_BOOK_INPUT_ID); if(!newbook_input) return; var account_name = newbook_input.value; if(account_name.length == 0) return; if(g_tx_manager.search_account(account_name)) alert("[" + account_name + "] " + CASHMAIN_MENU_BOOK_EXIST_STRING); else{ var account = g_tx_manager.create_account(account_name, ""); userInterface_addBookToTable(account); newbook_input.value=""; } } function eventHandler_onMenuRemove() { var index = parseInt(g_menu_selected_object.id); if(g_tx_manager.entries[index] && g_tx_manager.entries[index] instanceof Account){ var account = g_tx_manager.entries[index]; if(!g_tx_manager.is_account_empty(account)){ alert("[" + account.name+ "] " + CASHMAIN_MENU_REMOVE_NON_EMPTY_ACCOUNT_STRING); }else{ if (!confirm(CASHMAIN_REMOVE_ACCOUNT_CONFIRM_STRING)) return; g_tx_manager.remove_account(account); userInterface_removeItemFromTable(CASHMAIN_BOOKS_TABLE_ID, index); eventHandler_onHideMenu(); if(g_current_account == account){ set_element_value(CASHMAIN_BOOK_NAME_VALUE_ID, ""); set_element_value(CASHMAIN_BOOK_DESCRIPTION_VALUE_ID, ""); g_current_account = null; } } }else if(g_tx_manager.entries[index] && g_tx_manager.entries[index] instanceof Transaction){ if (!confirm(CASHMAIN_REMOVE_TRANSACTION_CONFIRM_STRING)) return; var transaction = g_tx_manager.entries[index]; g_tx_manager.remove_transaction(transaction); eventHandler_onHideMenu(); userInterface_removeItemFromTable(CASHMAIN_TRANSACTIONS_TABLE_ID, index); if(transaction.account == g_current_account) userInterface_fillBalance(transaction.account); userInterface_setAccountBalance(transaction.account); userInterface_setTotalBalance(); }else if(g_tx_manager.entries[index] && g_tx_manager.entries[index] instanceof Transfer){ if (!confirm(CASHMAIN_REMOVE_TRANSFER_CONFIRM_STRING)) return; var transfer = g_tx_manager.entries[index]; g_tx_manager.remove_transfer(transfer); eventHandler_onHideMenu(); userInterface_removeItemFromTable(CASHMAIN_TRANSACTIONS_TABLE_ID, index); userInterface_fillBalance(g_current_account); userInterface_setAccountBalance(transfer.to_account); userInterface_setAccountBalance(transfer.from_account); userInterface_setTotalBalance(); } } function eventHandler_onCombine() { var index = parseInt(g_menu_selected_object.id); if(g_tx_manager.entries[index] && g_tx_manager.entries[index] instanceof Account){ var account = g_tx_manager.entries[index]; var combine_with = getInput_string(CASHMAIN_ACCOUNT_COMBINE_SELECT_ID); if(!combine_with) return; var combine_account = g_tx_manager.search_account(combine_with); if(!combine_account) return; if (!confirm("You are going to move all entries from \n" + "[" + account.name + "]" + "\n to\n" + "[" + combine_account.name + "]\n" + "\n Are you sure?")) return; g_tx_manager.combine_accounts(account.name, combine_account.name); userInterface_setAccountBalance(combine_account); userInterface_setAccountBalance(account); userInterface_setTotalBalance(); load_transactions_table(account); alert("Combine completed!"); } } function eventHandler_onTransfer() { var index = parseInt(g_menu_selected_object.id); if(g_tx_manager.entries[index] && g_tx_manager.entries[index] instanceof Account){ var account = g_tx_manager.entries[index]; var transfer_to = getInput_string(CASHMAIN_ADD_TRANSFER_SELECT_ID); if(!transfer_to) return; var account_to = g_tx_manager.search_account(transfer_to); if(!account_to) return; var date = getInput_date(CASHMAIN_ADD_TRANSFER_DATE_INPUT_ID); if(!date){ alert(CASHMAIN_INVALID_DATE_STRING); return; } var amount = getInput_float(CASHMAIN_ADD_TRANSFER_AMOUNT_INPUT_ID); if(!amount){ alert(CASHMAIN_INVALID_AMOUNT_STRING); return; } var description = getInput_string(CASHMAIN_ADD_TRANSFER_DESCRIPTION_INPUT_ID); if(!description) description=""; var transfer = g_tx_manager.create_transfer (date, account, account_to, description, amount); userInterface_addEntryToTable(g_current_account, transfer); userInterface_fillBalance(account); userInterface_setAccountBalance(account); userInterface_setAccountBalance(account_to); userInterface_setTotalBalance(); alert(CASHMAIN_TRANSFER_SUCCESS_STRING); } } function userInterface_setTotalBalance() { var balance = 0; for(var i = 0; i < g_tx_manager.entries.length; i++){ if( g_tx_manager.entries[i] && g_tx_manager.entries[i] instanceof Account) balance += g_tx_manager.get_account_balance(g_tx_manager.entries[i]); } set_element_value(CASHMAIN_TOTAL_BALANCE_ID, format_as_money(balance)); window.setTimeout("userInterface_drawOverallPie()", 1 * 1000); } function userInterface_setAccountBalance(account) { var accountBalance = format_as_money(g_tx_manager.get_account_balance(account)); set_element_value("balance" + account.id, accountBalance); } function eventHandler_onMenuConfirm() { if(!is_numeric(g_menu_selected_object.id)){ if(g_menu_selected_object.id == CASHMAIN_ADD_TRANSACTION_PARENT_ID){ eventHandler_addTransaction(); eventHandler_onHideMenu(); } }else{ var index = parseInt(g_menu_selected_object.id); if(g_tx_manager.entries[index] && g_tx_manager.entries[index] instanceof Account){ var account = g_tx_manager.entries[index]; var name = ""; var description = ""; if(getInput_string(CASHMAIN_MENU_ACCOUNT_NAME_INPUT_ID) && getInput_string(CASHMAIN_MENU_ACCOUNT_NAME_INPUT_ID).length) name = getInput_string(CASHMAIN_MENU_ACCOUNT_NAME_INPUT_ID); if(getInput_string(CASHMAIN_MENU_ACCOUNT_DESCRIPTION_INPUT_ID) && getInput_string(CASHMAIN_MENU_ACCOUNT_DESCRIPTION_INPUT_ID).length) description = getInput_string(CASHMAIN_MENU_ACCOUNT_DESCRIPTION_INPUT_ID); if(name != account.name && g_tx_manager.search_account(name)){ alert("[" + name + "]" + CASHMAIN_MENU_BOOK_EXIST_STRING); set_input_value(CASHMAIN_MENU_ACCOUNT_NAME_INPUT_ID, account.name); return; }else{ account.name = name; account.description = description; } set_element_value("name" + account.id, account.name); if(g_current_account == account){ set_element_value(CASHMAIN_BOOK_NAME_VALUE_ID, account.name); set_element_value(CASHMAIN_BOOK_DESCRIPTION_VALUE_ID, account.description); } }else if(g_tx_manager.entries[index] && g_tx_manager.entries[index] instanceof Transaction){ var transaction = g_tx_manager.entries[index]; var date = getInput_date(CASHMAIN_TRANSACTION_DATE_INPUT_ID); if(!date){ alert(CASHMAIN_INVALID_DATE_STRING); return; } var group = getInput_group(); if(!group) return; var description = getInput_string(CASHMAIN_TRANSACTION_DESCRIPTION_INPUT_ID); if(!description) description = ""; var expense = getInput_float(CASHMAIN_TRANSACTION_EXPENSE_INPUT_ID); if(expense == null){ alert(CASHMAIN_INVALID_EXPENSE_STRING); return false; } var deposit = getInput_float(CASHMAIN_TRANSACTION_DEPOSIT_INPUT_ID); if(deposit == null){ alert(CASHMAIN_INVALID_DEPOSIT_STRING); return false; } set_element_value("date" + transaction.id, date2Str(date)); set_element_value("group" + transaction.id, group.name); set_element_value("description" + transaction.id, description); set_element_value("expense" + transaction.id, format_as_money(expense)); set_element_value("deposit" + transaction.id, format_as_money(deposit)); transaction.date = date; transaction.group = group; transaction.description = description; transaction.expense = expense; transaction.deposit = deposit; userInterface_fillBalance(transaction.account); userInterface_setAccountBalance(transaction.account); userInterface_setTotalBalance(); }else if(g_tx_manager.entries[index] && g_tx_manager.entries[index] instanceof Transfer){ var transfer = g_tx_manager.entries[index]; var date = getInput_date(CASHMAIN_TRANSFER_DATE_INPUT_ID); if(!date){ alert(CASHMAIN_INVALID_DATE_STRING); return; } var description = getInput_string(CASHMAIN_TRANSFER_DESCRIPTION_INPUT_ID); if(!description) return; var amount = getInput_float(CASHMAIN_TRANSFER_AMOUNT_INPUT_ID); if(amount == null){ alert(CASHMAIN_INVALID_AMOUNT_STRING); return false; } set_element_value("date" + transfer.id, date2Str(date)); set_element_value("description" + transfer.id, description); set_element_value("amount" + transfer.id, format_as_money(amount)); transfer.date = date; transfer.description = description; transfer.amount = amount; userInterface_fillBalance(g_current_account); userInterface_setAccountBalance(transfer.to_account); userInterface_setAccountBalance(transfer.from_account); userInterface_setTotalBalance(); } eventHandler_onHideMenu(); } } function eventHandler_onMenuCancel() { eventHandler_onHideMenu(); } // POP UP MENU function show_popup_menu(e) { var obj = g_is_ns6 ? e.target.parentNode : event.srcElement.parentElement; g_menu_selected_object = obj ; var menudiv = document.getElementById(CASHMAIN_MENU_ID); if (g_is_ns6){ menudiv.style.left = e.clientX+document.body.scrollLeft; menudiv.style.top = e.clientY+document.body.scrollTop; }else{ menudiv.style.pixelLeft = event.clientX+document.body.scrollLeft; menudiv.style.pixelTop = event.clientY+document.body.scrollTop - 100; } menudiv.style.display = ""; g_is_showing_menu = true; return false ; } //=================================================================== function format_as_money(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))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + num + '.' + cents); } function money_to_float(str) { var pos = str.indexOf(","); var str1 = str.substring(0, pos); var str2 = str.substring(pos + 1); str = str1 + str2; if(str.indexOf(",") == -1 && is_numeric(str)) return parseFloat(str); else if(str.indexOf(",") >= 0) return money_to_float(str); else return 0.0; } function set_element_value(id, value) { var element = document.getElementById(id); if(element && element.firstChild) element.firstChild.nodeValue = value; else if(element && !element.firstChild) element.appendChild(document.createTextNode(value)); } function set_input_value(id, value) { var element = document.getElementById(id); if(element) element.value=value; } function get_input_value(id, value) { var element = document.getElementById(id); if(element) return element.value; else return null; } function create_transfer_row(transfer, account) { var tr = document.createElement("tr"); tr.id = transfer.id; tr.className = "content_body"; tr.onmouseover = function(){this.className='content_onmouseover';} tr.onmouseout = function(){this.className='content_body';} var td = document.createElement("td"); td.id = "date" + transfer.id; td.appendChild(document.createTextNode(date2Str(transfer.date))) tr.appendChild(td); td = document.createElement("td"); if(transfer.to_account == account) td.appendChild(document.createTextNode(CASHMAIN_TRANSFER_FROM_STRING + " " + transfer.from_account.name)); else if(transfer.from_account == account) td.appendChild(document.createTextNode(CASHMAIN_TRANSFER_TO_STRING + " " + transfer.to_account.name)); tr.appendChild(td); td = document.createElement("td"); td.id = "description" + transfer.id; td.appendChild(document.createTextNode(transfer.description)); tr.appendChild(td); td = document.createElement("td"); td.style.textAlign = "right"; if(transfer.from_account == account){ td.id = "amount" + transfer.id; var strAmount = format_as_money(transfer.amount); td.appendChild(document.createTextNode(strAmount)); }else td.appendChild(document.createTextNode("0.00")); tr.appendChild(td); td = document.createElement("td"); td.style.textAlign = "right"; if(transfer.to_account == account){ td.id = "amount" + transfer.id; var strAmount = format_as_money(transfer.amount); td.appendChild(document.createTextNode(strAmount)); }else td.appendChild(document.createTextNode("0.00")); tr.appendChild(td); td = document.createElement("td"); td.style.textAlign = "right"; td.id = "balance" + transfer.id; tr.appendChild(td); return tr; } function create_group_summary_row(name, balance, percentage) { var tr = document.createElement("tr"); tr.className = "content_body"; tr.onmouseover = function(){this.className='content_onmouseover';} tr.onmouseout = function(){this.className='content_body';} var td = document.createElement("td"); td.appendChild(document.createTextNode(name)); tr.appendChild(td); td = document.createElement("td"); td.style.textAlign = "right"; td.appendChild(document.createTextNode(format_as_money(balance))); tr.appendChild(td); td = document.createElement("td"); td.style.textAlign = "right"; td.appendChild(document.createTextNode(format_as_money(percentage) + "%")); tr.appendChild(td); return tr; } function create_transaction_row(transaction) { var tr = document.createElement("tr"); tr.id = transaction.id; tr.className = "content_body"; tr.onmouseover = function(){this.className='content_onmouseover';} tr.onmouseout = function(){this.className='content_body';} var td = document.createElement("td"); td.id = "date" + transaction.id; td.appendChild(document.createTextNode(date2Str(transaction.date))); tr.appendChild(td); td = document.createElement("td"); td.id = "group" + transaction.id; td.appendChild(document.createTextNode(transaction.group.name)); tr.appendChild(td); td = document.createElement("td"); td.id = "description" + transaction.id; td.appendChild(document.createTextNode(transaction.description)); tr.appendChild(td); td = document.createElement("td"); td.id = "expense" + transaction.id; td.style.textAlign = "right"; var strExpense = format_as_money(transaction.expense); td.appendChild(document.createTextNode(strExpense)); tr.appendChild(td); td = document.createElement("td"); td.id = "deposit" + transaction.id; td.style.textAlign = "right"; var strDeposit = format_as_money(transaction.deposit); td.appendChild(document.createTextNode(strDeposit)); tr.appendChild(td); td = document.createElement("td"); td.style.textAlign = "right"; td.id = "balance" + transaction.id; tr.appendChild(td); return tr; } function get_reference_row(tx) { var table = document.getElementById(CASHMAIN_TRANSACTIONS_TABLE_ID); if(!table) return null; var ref_tr = null; for(var i = 0 ; i < table.childNodes.length; i++){ if(table.childNodes[i].nodeName.toLowerCase() == "tr"){ var index = parseInt(table.childNodes[i].id); if(index >= g_tx_manager.entries.length) continue; if(!g_tx_manager.entries[index]) continue; if(!(g_tx_manager.entries[index] instanceof Transaction) && !(g_tx_manager.entries[index] instanceof Transfer)) continue; if(tx.date.valueOf() > g_tx_manager.entries[index].date.valueOf()){ ref_tr = table.childNodes[i]; break; } if(tx.date.valueOf() == g_tx_manager.entries[index].date.valueOf() && tx.id > index){ ref_tr = table.childNodes[i]; break; } } } return ref_tr; } function load_transactions_table(account) { userInterface_clearTable(CASHMAIN_TRANSACTIONS_TABLE_ID); for(var i = 0 ; i < g_tx_manager.entries.length; i++) userInterface_addEntryToTable(account, g_tx_manager.entries[i]); userInterface_fillBalance(account); } function userInterface_fillSummary() { try{ var positive_input = document.getElementById (CASHMAIN_SUMMARY_PIECHART_POSITIVE_INPUT_ID); var negative_input = document.getElementById (CASHMAIN_SUMMARY_PIECHART_NEGATIVE_INPUT_ID); if(positive_input.checked){ userInterface_drawGroupPie(CASHMAIN_SUMMARY_PIECHART_ID, g_current_account, true); }else{ userInterface_drawGroupPie(CASHMAIN_SUMMARY_PIECHART_ID, g_current_account, false); } }catch(e){ window.setTimeout("userInterface_fillSummary()", 1 * 1000); } } function userInterface_fillBalance(account) { var balance = 0; var table = document.getElementById(CASHMAIN_TRANSACTIONS_TABLE_ID); if(!table) return; for(var i = table.childNodes.length - 1 ; i >= 0 ; i--){ if(table.childNodes[i].nodeName.toLowerCase() == "tr"){ var index = parseInt(table.childNodes[i].id); if(index >= g_tx_manager.entries.length) continue; if(!g_tx_manager.entries[index]) continue; if(g_tx_manager.entries[index] instanceof Transaction){ var transaction = g_tx_manager.entries[index]; balance += transaction.deposit; balance -= transaction.expense; }else if(g_tx_manager.entries[index] instanceof Transfer){ var transfer = g_tx_manager.entries[index]; if(transfer.to_account == account) balance += transfer.amount; else if(transfer.from_account == account) balance -= transfer.amount; } set_element_value("balance" + index, format_as_money(balance)); } } window.setTimeout("userInterface_fillSummary()", 1 * 1000); } function userInterface_loadBooksTable() { userInterface_clearTable(CASHMAIN_BOOKS_TABLE_ID); for(var i = 0 ; i < g_tx_manager.entries.length; i++) if(g_tx_manager.entries[i] && g_tx_manager.entries[i] instanceof Account) userInterface_addBookToTable(g_tx_manager.entries[i]); userInterface_setTotalBalance(); load_first_account(); } function userInterface_clearTable(table_id) { var table = document.getElementById(table_id); if(!table) return; while(table.childNodes.length != 0){ var dummy = table.firstChild; table.removeChild(dummy); delete dummy; } } function userInterface_removeItemFromTable(table_id, item_id) { var table = document.getElementById(table_id); if(!table) return; var item = document.getElementById(item_id); if(!item) return; table.removeChild(item); } function userInterface_showAddTransaction(e) { if(g_current_account){ show_popup_menu(e); userInterface_showElementToMenu(g_transaction_menu_element); set_element_value(CASHMAIN_MENU_TRANSACTION_LABEL_ID, CASHMAIN_MENU_ADD_NEW_TRANSACTION_LABEL + g_current_account.name); enableInput(CASHMAIN_REMOVE_TRANSACTION_BUTTON_ID, false); } return false; } function userInterface_clearSelect(id) { var select = document.getElementById(id); while(select.childNodes.length > 0){ var temp = select.firstChild; select.removeChild(select.firstChild); delete temp; } } function userInterface_fillSelect(id, value) { var select = document.getElementById(id); var option = document.createElement("option"); option.setAttribute("value", value); select.appendChild(option); option.appendChild(document.createTextNode(value)); } function userInterface_addBookToTable(account) { if(account && account instanceof Account){ var table = document.getElementById(CASHMAIN_BOOKS_TABLE_ID); if(!table) return; var tr = document.createElement("tr"); tr.id = "" + account.id; tr.className = "book_select"; tr.onmouseover = function(){this.className='book_onmouseover';} tr.onmouseout = function(){this.className='book_select';} tr.onclick = eventHandler_selectBook; tr.oncontextmenu = function(e){ eventHandler_onHideMenu(); var res = show_popup_menu(e); if(g_is_showing_menu){ userInterface_showElementToMenu(g_account_menu_element); set_element_value(CASHMAIN_MENU_ACCOUNT_LABEL_ID, CASHMAIN_SETTING_PREFIX + " " + account.name); set_input_value(CASHMAIN_MENU_ACCOUNT_NAME_INPUT_ID, account.name); set_input_value(CASHMAIN_MENU_ACCOUNT_DESCRIPTION_INPUT_ID, account.description); set_input_value(CASHMAIN_ADD_TRANSFER_DATE_INPUT_ID, ""); set_input_value(CASHMAIN_ADD_TRANSFER_AMOUNT_INPUT_ID, ""); set_input_value(CASHMAIN_ADD_TRANSFER_DESCRIPTION_INPUT_ID, ""); userInterface_clearSelect(CASHMAIN_ADD_TRANSFER_SELECT_ID); for(var i = 0 ; i < g_tx_manager.entries.length; i++) if(g_tx_manager.entries[i] && g_tx_manager.entries[i] instanceof Account && g_tx_manager.entries[i] != account) userInterface_fillSelect(CASHMAIN_ADD_TRANSFER_SELECT_ID, g_tx_manager.entries[i].name); userInterface_clearSelect(CASHMAIN_ACCOUNT_COMBINE_SELECT_ID); for(var i = 0 ; i < g_tx_manager.entries.length; i++) if(g_tx_manager.entries[i] && g_tx_manager.entries[i] instanceof Account && g_tx_manager.entries[i] != account) userInterface_fillSelect(CASHMAIN_ACCOUNT_COMBINE_SELECT_ID, g_tx_manager.entries[i].name); } return res; } var td1 = document.createElement("th"); td1.id = "name" + account.id; td1.appendChild(document.createTextNode(account.name)) var td2 = document.createElement("td"); td2.id = "balance" + account.id; var strBalance = format_as_money(g_tx_manager.get_account_balance(account)); td2.appendChild(document.createTextNode(strBalance)) tr.appendChild(td1);tr.appendChild(td2); table.appendChild(tr); } } function userInterface_addEntryToTable(account, entry) { var table = document.getElementById(CASHMAIN_TRANSACTIONS_TABLE_ID); if(!table) return; if(entry && entry instanceof Transaction){ var transaction = entry; if(transaction.account == account){ var ref_tr = get_reference_row(transaction); var tr = create_transaction_row(transaction); tr.oncontextmenu = function(e){ if(g_current_account){ eventHandler_onHideMenu(); show_popup_menu(e); userInterface_showElementToMenu(g_transaction_menu_element); //set_element_value(CASHMAIN_MENU_TRANSACTION_LABEL_ID, transaction.toString()); set_element_value(CASHMAIN_MENU_TRANSACTION_LABEL_ID, CASHMAIN_SETTING_PREFIX); set_input_value(CASHMAIN_TRANSACTION_DATE_INPUT_ID, date2Str(transaction.date)); set_input_value(CASHMAIN_TRANSACTION_GROUP_INPUT_ID, transaction.group.name); set_input_value(CASHMAIN_TRANSACTION_DESCRIPTION_INPUT_ID, transaction.description); set_input_value(CASHMAIN_TRANSACTION_EXPENSE_INPUT_ID, transaction.expense); set_input_value(CASHMAIN_TRANSACTION_DEPOSIT_INPUT_ID, transaction.deposit); enableInput(CASHMAIN_REMOVE_TRANSACTION_BUTTON_ID, true); } return false; }; //tr.oncontextmenu = tr.onclick; if(!ref_tr) table.appendChild(tr); else table.insertBefore(tr, ref_tr); } }else if(entry && entry instanceof Transfer){ var transfer = entry; if(transfer.to_account == account || transfer.from_account == account){ var ref_tr = get_reference_row(transfer); var tr = create_transfer_row(transfer, account); tr.oncontextmenu = function(e){ if(g_current_account){ eventHandler_onHideMenu(); show_popup_menu(e); userInterface_showElementToMenu(g_transfer_menu_element); //set_element_value(CASHMAIN_MENU_TRANSFER_LABEL_ID, transfer.toString()); set_element_value(CASHMAIN_MENU_TRANSFER_LABEL_ID, CASHMAIN_SETTING_PREFIX); set_input_value(CASHMAIN_TRANSFER_DATE_INPUT_ID, date2Str(transfer.date)); set_input_value(CASHMAIN_TRANSFER_DESCRIPTION_INPUT_ID, transfer.description); set_input_value(CASHMAIN_TRANSFER_AMOUNT_INPUT_ID, transfer.amount); if(transfer.to_account == g_current_account){ set_element_value(CASHMAIN_TRANSFER_ACCOUNT_LABEL_ID, CASHMAIN_TRANSFER_FROM_STRING + ":"); set_element_value(CASHMAIN_TRANSFER_ACCOUNT_VALUE_ID, transfer.from_account.name); } else if(transfer.from_account == g_current_account){ set_element_value(CASHMAIN_TRANSFER_ACCOUNT_LABEL_ID, CASHMAIN_TRANSFER_TO_STRING + ":"); set_element_value(CASHMAIN_TRANSFER_ACCOUNT_VALUE_ID, transfer.to_account.name); }else eventHandler_onHideMenu(); } return false; } //tr.oncontextmenu = tr.onclick; if(!ref_tr) table.appendChild(tr); else table.insertBefore(tr, ref_tr); } } } function add_transaction(date, group, description, expense, deposit, account) { var transaction = g_tx_manager.create_transaction(date, group, description, expense, deposit, account); if(transaction && g_current_account == account){ userInterface_addEntryToTable(account, transaction); userInterface_fillBalance(account); userInterface_setAccountBalance(account); userInterface_setTotalBalance(); return true; } return false; } function enableInput(id, enable) { var input = document.getElementById(id); if(!input) return; input.disabled = !enable; } function getInput_date(id) { var date_input = document.getElementById(id); var date = null; if(date_input){ if(!isDate(date_input.value)){ return null; } date = str2Date(date_input.value); } return date; } function getInput_group() { var group_input = document.getElementById(CASHMAIN_TRANSACTION_GROUP_INPUT_ID); var strGroup = null; if(group_input) strGroup = group_input.value; if(!strGroup) strGroup = ""; else strGroup = strGroup.replace("'","").replace("\"",""); var group = g_tx_manager.search_group(strGroup); if(group == null) group = g_tx_manager.create_group(strGroup, ""); return group; } function getInput_description() { var description_input = document.getElementById(CASHMAIN_TRANSACTION_DESCRIPTION_INPUT_ID); var strDescription = null; if(description_input) strDescription = description_input.value; if(!strDescription) strDescription = ""; return strDescription; } function getInput_float(id) { var input = document.getElementById(id); var str = null; if(input) str = input.value; else return null; if(!str || !str.length) str = "0"; if(!is_numeric(str)) return null; var f = money_to_float(str); return f; } function getInput_string(id) { var input = document.getElementById(id); if(!input) return null; else return input.value.replace("'", "").replace("\"", ""); } function eventHandler_addTransaction() { if(!g_current_account) return; var date = getInput_date(CASHMAIN_TRANSACTION_DATE_INPUT_ID); if(!date){ alert(CASHMAIN_INVALID_DATE_STRING); return false; } var group = getInput_group(); if(!group) return false; var description = getInput_string(CASHMAIN_TRANSACTION_DESCRIPTION_INPUT_ID); if(!description) description = ""; var expense = getInput_float(CASHMAIN_TRANSACTION_EXPENSE_INPUT_ID); if(expense == null){ alert(CASHMAIN_INVALID_EXPENSE_STRING); return false; } var deposit = getInput_float(CASHMAIN_TRANSACTION_DEPOSIT_INPUT_ID); if(deposit == null){ alert(CASHMAIN_INVALID_DEPOSIT_STRING); return false; } return add_transaction(date, group, description, expense, deposit, g_current_account); } function eventHandler_selectBookById(id) { var account = g_tx_manager.entries[id]; if(account && account instanceof Account){ g_current_account = account; load_transactions_table(account); set_element_value(CASHMAIN_BOOK_NAME_VALUE_ID, account.name); set_element_value(CASHMAIN_BOOK_DESCRIPTION_VALUE_ID, account.description); } } function eventHandler_selectBook() { eventHandler_onHideMenu(); var id = parseInt(this.id); eventHandler_selectBookById(id); } function userInterface_showElementToMenu(element) { var placeHolder = document.getElementById(CASHMAIN_MENU_PLACEHOLDER_ID); while(placeHolder.childNodes.length) placeHolder.removeChild(placeHolder.firstChild); placeHolder.appendChild(element); } function userInterface_hideMenuContents() { g_account_menu_element = document.getElementById(CASHMAIN_MENU_ACCOUNT_ID); if(g_account_menu_element) document.body.removeChild(g_account_menu_element); g_transaction_menu_element = document.getElementById(CASHMAIN_MENU_TRANSACTION_ID); if(g_transaction_menu_element) document.body.removeChild(g_transaction_menu_element); g_transfer_menu_element = document.getElementById(CASHMAIN_MENU_TRANSFER_ID); if(g_transfer_menu_element) document.body.removeChild(g_transfer_menu_element); } function sorting_pairs(pairs) { for(var i = 0 ; i < pairs[0].length; i++){ for(var j = i + 1 ; j < pairs[0].length; j++){ if(pairs[1][j] > pairs[1][i]){ var temp = pairs[1][i]; pairs[1][i] = pairs[1][j]; pairs[1][j] = temp; temp = pairs[0][i]; pairs[0][i] = pairs[0][j]; pairs[0][j] = temp; } } } return pairs; } function userInterface_drawAccountPie(id, draw_positive) { var pairs = new Array(2); pairs[0] = new Array();//name pairs[1] = new Array();//balance var index = 0; var colors = null; for(var i = 0; i < g_tx_manager.entries.length; i++){ if(g_tx_manager.entries[i] && g_tx_manager.entries[i] instanceof Account){ var balance = g_tx_manager.get_account_balance(g_tx_manager.entries[i]); if(draw_positive && balance > 0){ pairs[0][index] = g_tx_manager.entries[i].name; pairs[1][index] = balance; index++; colors = g_overall_piechart_positive_colors; }else if(!draw_positive && balance < 0){ pairs[0][index] = g_tx_manager.entries[i].name; pairs[1][index] = -balance; index++; colors = g_overall_piechart_negative_colors; } } } sorting_pairs(pairs); drawpie_with_color(id, 80, pairs[1], pairs[0], 350, 160, colors); } function userInterface_fillGroupTable(pairs, total_balance) { userInterface_clearTable(CASHMAIN_SUMMARY_GROUP_TABLE); var table = document.getElementById(CASHMAIN_SUMMARY_GROUP_TABLE); if(!table) return; for(var i =0; i < pairs[0].length; i++){ var tr = create_group_summary_row(pairs[0][i], pairs[1][i], pairs[1][i] * 100/total_balance); table.appendChild(tr); } } function userInterface_drawGroupPie(id, account, draw_positive) { var pairs = new Array(2); pairs[0] = new Array();//name pairs[1] = new Array();//balance var index = 0; var colors = null; for(var i = 0; i < g_tx_manager.entries.length; i++){ if(g_tx_manager.entries[i] && g_tx_manager.entries[i] instanceof Group){ var balance = g_tx_manager.get_group_balance(g_tx_manager.entries[i], account); if(draw_positive && balance > 0){ pairs[0][index] = g_tx_manager.entries[i].name.substring(0,14); pairs[1][index] = balance; index++; }else if(!draw_positive && balance < 0){ pairs[0][index] = g_tx_manager.entries[i].name.substring(0,14); pairs[1][index] = -balance; index++; } } } if(account){ for(var i = 0; i < g_tx_manager.entries.length; i++){ if(g_tx_manager.entries[i] && g_tx_manager.entries[i] instanceof Account && g_tx_manager.entries[i] != account){ var balance = g_tx_manager.get_transfer_from_balance (account, g_tx_manager.entries[i]); balance -= g_tx_manager.get_transfer_to_balance (account, g_tx_manager.entries[i]); if(draw_positive && balance > 0){ pairs[0][index] = "*" + g_tx_manager.entries[i].name; pairs[1][index] = balance; index++; }else if(!draw_positive && balance < 0){ pairs[0][index] = "*" + g_tx_manager.entries[i].name; pairs[1][index] = -balance; index++; } } } } if(draw_positive) colors = g_overall_piechart_positive_colors; else colors = g_overall_piechart_negative_colors; sorting_pairs(pairs); drawpie_with_color(id, 80, pairs[1], pairs[0], 350, 160, colors); if(account){ var total_balance = 0; for(var i = 0 ; i < pairs[0].length; i++) total_balance += pairs[1][i]; userInterface_fillGroupTable(pairs, total_balance); } } function userInterface_drawOverallPie() { try{ var positive_input = document.getElementById (CASHMAIN_OVERALL_PIECHART_POSITIVE_INPUT_ID); var negative_input = document.getElementById (CASHMAIN_OVERALL_PIECHART_NEGATIVE_INPUT_ID); var piechart_type_select = document.getElementById (CASHMAIN_OVERALL_PIECHART_TYPE_SELECT); if(positive_input.checked){ if(piechart_type_select.value == "Groups") userInterface_drawGroupPie(CASHMAIN_OVERALL_PIECHART_ID, null, true); else if(piechart_type_select.value == "Accounts") userInterface_drawAccountPie(CASHMAIN_OVERALL_PIECHART_ID, true); }else if(negative_input.checked){ if(piechart_type_select.value == "Groups") userInterface_drawGroupPie(CASHMAIN_OVERALL_PIECHART_ID, null, false); else if(piechart_type_select.value == "Accounts") userInterface_drawAccountPie(CASHMAIN_OVERALL_PIECHART_ID, false); } }catch(e){ window.setTimeout("userInterface_drawOverallPie()", 1 * 1000); } } function userInterface_showSaveString() { //alert(g_tx_manager.toString()); set_element_value(CASHMAIN_SAVE_STRING_ID, g_tx_manager.toString()); } function userInterface_loadSaveString() { var save = getInput_string(CASHMAIN_LOAD_SAVE_STRING_INPUT_ID); if(!save || save.length == 0) return; g_tx_manager.reload_save(save); userInterface_loadBooksTable(); userInterface_clearTable(CASHMAIN_TRANSACTIONS_TABLE_ID); set_element_value(CASHMAIN_BOOK_NAME_VALUE_ID, ""); set_element_value(CASHMAIN_BOOK_DESCRIPTION_VALUE_ID, ""); } function load_first_account() { for(var i = 0; i < g_tx_manager.entries.length; i++){ if(g_tx_manager.entries[i] && g_tx_manager.entries[i] instanceof Account){ eventHandler_selectBookById(i); break; } } } function date_sort_decreasing(date_array) { if(!date_array) return null; for(var i = 0; i < date_array.length; i++){ for(var j = i + 1; j < date_array.length; j++){ if(date_array[i].valueOf() < date_array[j].valueOf()){ var temp = date_array[i]; date_array[i] = date_array[j]; date_array[j] = temp; } } } return date_array; } function is_same_month(dateA, dateB) { if(dateA.getFullYear() != dateB.getFullYear()) return false; if(dateA.getMonth() != dateB.getMonth()) return false; return true; } /****************ui_datetimepicker.js***************************/ //Javascript name: My Date Time Picker //Date created: 16-Nov-2003 23:19 //Scripter: TengYong Ng //Website: http://www.rainforestnet.com //Copyright (c) 2003 TengYong Ng //FileName: DateTimePicker.js //Version: 0.8 //Contact: contact@rainforestnet.com // Note: Permission given to use this script in ANY kind of applications if // header lines are left unchanged. //Global variables var winCal; var dtToday=new Date(); var Cal; var docCal; var MonthName=["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"]; var WeekDayName=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; var exDateTime;//Existing Date and Time //Configurable parameters var cnTop="200";//top coordinate of calendar window. var cnLeft="300";//left coordinate of calendar window var WindowTitle ="DateTime Picker";//Date Time Picker title. var WeekChar=3;//number of character for week day. if 2 then Mo,Tu,We. if 3 then Mon,Tue,Wed. var CellWidth=20;//Width of day cell. var DateSeparator="-";//Date Separator, you can change it to "/" if you want. var TimeMode=24;//default TimeMode value. 12 or 24 var ShowLongMonth=true;//Show long month name in Calendar header. example: "January". var ShowMonthYear=true;//Show Month and Year in Calendar header. var MonthYearColor="#000000";//Font Color of Month and Year in Calendar header. var WeekHeadBgColor="#7999C2";//Background Color in Week header. var WeekHeadFontColor="#FFFFFF";//Font Color in Week header. var SundayColor="#FFCCFF";//Background color of Sunday. var SaturdayColor="#eeeef0";//Background color of Saturday. var WeekDayColor="#D9E9F2";//Background color of weekdays. var FontColor="blue";//color of font in Calendar day cell. var TodayColor="#ffffff";//Background color of today. var SelDateColor="#395982";//Backgrond color of selected date in textbox. var YrSelColor="#blue";//color of font of Year selector. var ThemeBg="#D9E9F2";//Background image of Calendar window. //end Configurable parameters //end Global variable function NewCal(pCtrl,pFormat,pShowTime,pTimeMode) { Cal=new Calendar(dtToday); if ((pShowTime!=null) && (pShowTime)) { Cal.ShowTime=true; if ((pTimeMode!=null) &&((pTimeMode=='12')||(pTimeMode=='24'))) { TimeMode=pTimeMode; } } if (pCtrl!=null) Cal.Ctrl=pCtrl; if (pFormat!=null) Cal.Format=pFormat.toUpperCase(); exDateTime=document.getElementById(pCtrl).value; //exDateTime=document.getElementById(pCtrl).firstChild.nodeValue; if (exDateTime!="")//Parse Date String { var Sp1;//Index of Date Separator 1 var Sp2;//Index of Date Separator 2 var tSp1;//Index of Time Separator 1 var tSp1;//Index of Time Separator 2 var strMonth; var strDate; var strYear; var intMonth; var YearPattern; var strHour; var strMinute; var strSecond; //parse month Sp1=exDateTime.indexOf(DateSeparator,0) Sp2=exDateTime.indexOf(DateSeparator,(parseInt(Sp1)+1)); if ((Cal.Format.toUpperCase()=="DDMMYYYY") || (Cal.Format.toUpperCase()=="DDMMMYYYY")) { strMonth=exDateTime.substring(Sp1+1,Sp2); strDate=exDateTime.substring(0,Sp1); } else if ((Cal.Format.toUpperCase()=="MMDDYYYY") || (Cal.Format.toUpperCase()=="MMMDDYYYY")) { strMonth=exDateTime.substring(0,Sp1); strDate=exDateTime.substring(Sp1+1,Sp2); } if (isNaN(strMonth)) intMonth=Cal.GetMonthIndex(strMonth); else intMonth=parseInt(strMonth,10)-1; if ((parseInt(intMonth,10)>=0) && (parseInt(intMonth,10)<12)) Cal.Month=intMonth; //end parse month //parse Date if ((parseInt(strDate,10)<=Cal.GetMonDays()) && (parseInt(strDate,10)>=1)) Cal.Date=strDate; //end parse Date //parse year strYear=exDateTime.substring(Sp2+1,Sp2+5); YearPattern=/^\d{4}$/; if (YearPattern.test(strYear)) Cal.Year=parseInt(strYear,10); //end parse year //parse time if (Cal.ShowTime==true) { tSp1=exDateTime.indexOf(":",0) tSp2=exDateTime.indexOf(":",(parseInt(tSp1)+1)); strHour=exDateTime.substring(tSp1,(tSp1)-2); Cal.SetHour(strHour); strMinute=exDateTime.substring(tSp1+1,tSp2); Cal.SetMinute(strMinute); strSecond=exDateTime.substring(tSp2+1,tSp2+3); Cal.SetSecond(strSecond); } } winCal=window.open("","DateTimePicker","modal=1,toolbar=0,status=0,menubar=0,fullscreen=no,width=220,height=260,resizable=0,top="+cnTop+",left="+cnLeft); docCal=winCal.document; RenderCal(); } function RenderCal() { var vCalHeader; var vCalData; var vCalTime; var i; var j; var SelectStr; var vDayCount=0; var vFirstDay; docCal.open(); docCal.writeln(""+WindowTitle+""); docCal.writeln(""); docCal.writeln("
"); vCalHeader="\n"; //Month Selector vCalHeader+="\n\n"; vCalHeader+=""; //Calendar header shows Month and Year if (ShowMonthYear) vCalHeader+="\n"; //Week day header vCalHeader+=""; for (i=0;i<7;i++){ vCalHeader+=""; } vCalHeader+=""; docCal.write(vCalHeader); //Calendar detail CalDate=new Date(Cal.Year,Cal.Month); CalDate.setDate(1); vFirstDay=CalDate.getDay(); vCalData=""; for (i=0;i\n"; } } docCal.writeln(vCalData); //Time picker if (Cal.ShowTime) { var showHour; showHour=Cal.getShowHour(); vCalTime="\n\n"; docCal.write(vCalTime); } //end time picker docCal.writeln("\n
"; //Year selector vCalHeader+="\n
\n"; vCalHeader+="< "+Cal.Year+" >
"+Cal.GetMonthName(ShowLongMonth)+" "+Cal.Year+"
" vCalHeader+="" +WeekDayName[i].substr(0,WeekChar)+"
"; vCalTime+=""; vCalTime+=" : "; vCalTime+=""; vCalTime+=" : "; vCalTime+=""; if (TimeMode==12) { var SelectAm =(parseInt(Cal.Hours,10)<12)? "Selected":""; var SelectPm =(parseInt(Cal.Hours,10)>=12)? "Selected":""; vCalTime+=""; } vCalTime+="\n
"); docCal.writeln("
©Copyright 2006 www.cashmain.com.
"); docCal.writeln("
"); docCal.writeln("
"); docCal.close(); } function GenCell(pValue,pHighLight,pColor)//Generate table cell with value { var PValue; var PCellStr; var vColor; var vHLstr1;//HighLight string var vHlstr2; var vTimeStr; if (pValue==null) PValue=""; else PValue=pValue; if (pColor!=null) vColor="bgcolor=\""+pColor+"\""; else vColor=""; if ((pHighLight!=null)&&(pHighLight)) {vHLstr1="color='red'>";vHLstr2="";} else {vHLstr1=">";vHLstr2="";} if (Cal.ShowTime) { vTimeStr="winMain.document.getElementById('"+Cal.Ctrl+"').value+=' '+"+"winMain.Cal.getShowHour()"+"+':'+"+"winMain.Cal.Minutes"+"+':'+"+"winMain.Cal.Seconds"; if (TimeMode==12) vTimeStr+="+' '+winMain.Cal.AMorPM"; } else vTimeStr=""; PCellStr=""+PValue+""+vHLstr2+""; return PCellStr; } function Calendar(pDate,pCtrl) { //Properties this.Date=pDate.getDate();//selected date this.Month=pDate.getMonth();//selected month number this.Year=pDate.getFullYear();//selected year in 4 digits this.Hours=pDate.getHours(); if (pDate.getMinutes()<10) this.Minutes="0"+pDate.getMinutes(); else this.Minutes=pDate.getMinutes(); if (pDate.getSeconds()<10) this.Seconds="0"+pDate.getSeconds(); else this.Seconds=pDate.getSeconds(); this.MyWindow=winCal; this.Ctrl=pCtrl; this.Format="ddMMyyyy"; this.Separator=DateSeparator; this.ShowTime=false; if (pDate.getHours()<12) this.AMorPM="AM"; else this.AMorPM="PM"; } function GetMonthIndex(shortMonthName) { for (i=0;i<12;i++) { if (MonthName[i].substring(0,3).toUpperCase()==shortMonthName.toUpperCase()) { return i;} } } Calendar.prototype.GetMonthIndex=GetMonthIndex; function IncYear() { Cal.Year++;} Calendar.prototype.IncYear=IncYear; function DecYear() { Cal.Year--;} Calendar.prototype.DecYear=DecYear; function SwitchMth(intMth) { Cal.Month=intMth;} Calendar.prototype.SwitchMth=SwitchMth; function SetHour(intHour) { var MaxHour; var MinHour; if (TimeMode==24) { MaxHour=23;MinHour=0} else if (TimeMode==12) { MaxHour=12;MinHour=1} else alert("TimeMode can only be 12 or 24"); var HourExp=new RegExp("^\\d\\d$"); if (HourExp.test(intHour) && (parseInt(intHour,10)<=MaxHour) && (parseInt(intHour,10)>=MinHour)) { if ((TimeMode==12) && (Cal.AMorPM=="PM")) { if (parseInt(intHour,10)==12) Cal.Hours=12; else Cal.Hours=parseInt(intHour,10)+12; } else if ((TimeMode==12) && (Cal.AMorPM=="AM")) { if (intHour==12) intHour-=12; Cal.Hours=parseInt(intHour,10); } else if (TimeMode==24) Cal.Hours=parseInt(intHour,10); } } Calendar.prototype.SetHour=SetHour; function SetMinute(intMin) { var MinExp=new RegExp("^\\d\\d$"); if (MinExp.test(intMin) && (intMin<60)) Cal.Minutes=intMin; } Calendar.prototype.SetMinute=SetMinute; function SetSecond(intSec) { var SecExp=new RegExp("^\\d\\d$"); if (SecExp.test(intSec) && (intSec<60)) Cal.Seconds=intSec; } Calendar.prototype.SetSecond=SetSecond; function SetAmPm(pvalue) { this.AMorPM=pvalue; if (pvalue=="PM") { this.Hours=(parseInt(this.Hours,10))+12; if (this.Hours==24) this.Hours=12; } else if (pvalue=="AM") this.Hours-=12; } Calendar.prototype.SetAmPm=SetAmPm; function getShowHour() { var finalHour; if (TimeMode==12) { if (parseInt(this.Hours,10)==0) { this.AMorPM="AM"; finalHour=parseInt(this.Hours,10)+12; } else if (parseInt(this.Hours,10)==12) { this.AMorPM="PM"; finalHour=12; } else if (this.Hours>12) { this.AMorPM="PM"; if ((this.Hours-12)<10) finalHour="0"+((parseInt(this.Hours,10))-12); else finalHour=parseInt(this.Hours,10)-12; } else { this.AMorPM="AM"; if (this.Hours<10) finalHour="0"+parseInt(this.Hours,10); else finalHour=this.Hours; } } else if (TimeMode==24) { if (this.Hours<10) finalHour="0"+parseInt(this.Hours,10); else finalHour=this.Hours; } return finalHour; } Calendar.prototype.getShowHour=getShowHour; function GetMonthName(IsLong) { var Month=MonthName[this.Month]; if (IsLong) return Month; else return Month.substr(0,3); } Calendar.prototype.GetMonthName=GetMonthName; function GetMonDays()//Get number of days in a month { var DaysInMonth=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; if (this.IsLeapYear()) { DaysInMonth[1]=29; } return DaysInMonth[this.Month]; } Calendar.prototype.GetMonDays=GetMonDays; function IsLeapYear() { if ((this.Year%4)==0) { if ((this.Year%100==0) && (this.Year%400)!=0) { return false; } else { return true; } } else { return false; } } Calendar.prototype.IsLeapYear=IsLeapYear; function FormatDate(pDate) { if (this.Format.toUpperCase()=="DDMMYYYY") return (pDate+DateSeparator+(this.Month+1)+DateSeparator+this.Year); else if (this.Format.toUpperCase()=="DDMMMYYYY") return (pDate+DateSeparator+this.GetMonthName(false)+DateSeparator+this.Year); else if (this.Format.toUpperCase()=="MMDDYYYY") return ((this.Month+1)+DateSeparator+pDate+DateSeparator+this.Year); else if (this.Format.toUpperCase()=="MMMDDYYYY") return (this.GetMonthName(false)+DateSeparator+pDate+DateSeparator+this.Year); } Calendar.prototype.FormatDate=FormatDate; /****************ui_grouppicker.js***************************/ /*Copyright 2006 by www.cashmain.com.*/ var GROUP_PICKER_BGCOLOR = "#D9E9F2"; var g_group_picker_document = null; var g_group_picker_groupid = null; function show_grouppicker(groupid) { g_group_picker_groupid = groupid; var windowcontrol = window.open("", "grouppicker", "modal=1"+ ",toolbar=0"+ ",status=0"+ ",menubar=0"+ ",fullscreen=no"+ ",width=500"+ ",height=400"+ ",resizable=0"+ ",top=200"+ ",left=200" + ",scrollbars=1"); g_group_picker_document = windowcontrol.document; render_grouppicker(); } function render_grouppicker() { g_group_picker_document.open(); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln("" + CASHMAIN_GROUP_PICKER_TITLE + ""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln("
"+CASHMAIN_GROUP_PICKER_TITLE+"
"); g_group_picker_document.writeln("
"); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln("
"+CASHMAIN_GROUP_PICKER_ADD_NEW+""); g_group_picker_document.writeln(""); g_group_picker_document.writeln("
"+CASHMAIN_GROUP_PICKER_NAME_HEADER+":"); g_group_picker_document.writeln("
"+CASHMAIN_GROUP_PICKER_DESC_HEADER+":"); g_group_picker_document.writeln(""); g_group_picker_document.writeln("
"); g_group_picker_document.writeln("
"); //var nodes = g_group_picker_groupsnode.getChildNodes(); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); for(var i = 0 ; i < g_tx_manager.entries.length; i++){ if(g_tx_manager.entries[i] && g_tx_manager.entries[i] instanceof Group){ render_grouppicker_row(g_tx_manager.entries[i]); } } g_group_picker_document.writeln("
"+CASHMAIN_GROUP_PICKER_NAME_HEADER+""+CASHMAIN_GROUP_PICKER_DESC_HEADER+"
"); g_group_picker_document.writeln("
"); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln("
"+CASHMAIN_COPYRIGHT+"
"); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.close(); } function handle_remove_group(name) { var group = g_tx_manager.search_group(name); if(group == null) return false; if(!g_tx_manager.is_group_empty(group)){ alert(CASHMAIN_GROUP_REMOVE_NON_EMPTY_GROUP_STRING); return false; } g_tx_manager.remove_group(group); render_grouppicker(); return true; } function handle_add_group(name, description) { if(name.length == 0) return true; if(g_tx_manager.search_group(name) != null){ alert("[" + name + "]" + CASHMAIN_GROUP_ALREADY_EXIST); return false; } g_tx_manager.create_group(name, description); render_grouppicker(); return true; } function render_grouppicker_row(group) { var group_name = group.name.replace("'","").replace("\"",""); var group_desc = group.description.replace("'","").replace("\"","");; //alert(group_name); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln(""); g_group_picker_document.writeln("" + group_name + ""); g_group_picker_document.writeln("" + group_desc + ""); g_group_picker_document.writeln(""); } /****************config.js***************************/ var CASHMAIN_OVERALL_PIECHART_ID = "OverallPieChart"; var CASHMAIN_OVERALL_PIECHART_TYPE_SELECT = "overallpie_type"; var CASHMAIN_OVERALL_PIECHART_POSITIVE_INPUT_ID = "overallpie_positive"; var CASHMAIN_OVERALL_PIECHART_NEGATIVE_INPUT_ID = "overallpie_negative"; var CASHMAIN_SUMMARY_PIECHART_ID = "SummaryPieChart"; var CASHMAIN_SUMMARY_PIECHART_POSITIVE_INPUT_ID = "summary_positive"; var CASHMAIN_SUMMARY_PIECHART_NEGATIVE_INPUT_ID = "summary_negative"; var CASHMAIN_SUMMARY_GROUP_TABLE = "group_summary_table"; var CASHMAIN_TOTAL_BALANCE_ID = "total_balance_value"; var CASHMAIN_BOOK_NAME_VALUE_ID = "book_name_value"; var CASHMAIN_BOOK_DESCRIPTION_VALUE_ID = "book_description_value"; var CASHMAIN_BOOKS_TABLE_ID = "books_table"; var CASHMAIN_TRANSACTIONS_TABLE_ID = "transactions_table"; var CASHMAIN_TRANSACTION_DATE_INPUT_ID = "transaction_date_input"; var CASHMAIN_TRANSACTION_GROUP_INPUT_ID = "transaction_group_input"; var CASHMAIN_TRANSACTION_DESCRIPTION_INPUT_ID = "transaction_description_input"; var CASHMAIN_TRANSACTION_EXPENSE_INPUT_ID = "transaction_expense_input"; var CASHMAIN_TRANSACTION_DEPOSIT_INPUT_ID = "transaction_deposit_input"; var CASHMAIN_ADD_TRANSFER_SELECT_ID = "add_transfer_account_select"; var CASHMAIN_ACCOUNT_COMBINE_SELECT_ID = "add_account_combine_select"; var CASHMAIN_ADD_TRANSFER_DATE_INPUT_ID = "add_transfer_date_input"; var CASHMAIN_ADD_TRANSFER_AMOUNT_INPUT_ID = "add_transfer_amount_input"; var CASHMAIN_ADD_TRANSFER_DESCRIPTION_INPUT_ID = "add_transfer_description_input"; var CASHMAIN_NEW_BOOK_INPUT_ID = "new_book_input"; var CASHMAIN_MENU_ACCOUNT_ID = "menu_account"; var CASHMAIN_MENU_ACCOUNT_LABEL_ID = "menu_account_label"; //var CASHMAIN_SETTING_PREFIX = "Settings: "; var CASHMAIN_MENU_ACCOUNT_NAME_INPUT_ID = "menu_account_name_input"; var CASHMAIN_MENU_ACCOUNT_DESCRIPTION_INPUT_ID = "menu_account_description_input"; var CASHMAIN_MENU_ID = "menudiv"; var CASHMAIN_MENU_PLACEHOLDER_ID = "menu_placeholder"; var CASHMAIN_MENU_TRANSACTION_ID = "menu_transaction"; var CASHMAIN_MENU_TRANSACTION_LABEL_ID = "menu_transaction_label"; var CASHMAIN_ADD_TRANSACTION_PARENT_ID = "ADD_TRANSACTION"; var CASHMAIN_MENU_TRANSFER_ID = "menu_transfer"; var CASHMAIN_MENU_TRANSFER_LABEL_ID = "menu_transfer_label"; var CASHMAIN_TRANSFER_DATE_INPUT_ID = "transfer_date_input"; var CASHMAIN_TRANSFER_AMOUNT_INPUT_ID = "transfer_amount_input"; var CASHMAIN_TRANSFER_DESCRIPTION_INPUT_ID = "transfer_description_input"; var CASHMAIN_TRANSFER_SELECT_ID = "transfer_account_select"; var CASHMAIN_TRANSFER_ACCOUNT_LABEL_ID = "menu_transfer_account_label"; var CASHMAIN_TRANSFER_ACCOUNT_VALUE_ID = "menu_transfer_account_value"; var CASHMAIN_REMOVE_TRANSACTION_BUTTON_ID = "menu_transaction_remove_button"; var CASHMAIN_SAVE_STRING_ID = "save_string"; var CASHMAIN_LOAD_SAVE_STRING_INPUT_ID = "load_save_input_id"; var CASHMAIN_SAVE_TO_EMAIL_ID = "save_to_email_data"; var CASHMAIN_SAVE_TO_CASHMAIN_DATA_ID = "save_to_cashmain_data"; var CASHMAIN_SAVE_TO_CASHMAIN_TOKEN_ID = "save_to_cashmain_token"; var CASHMAIN_SAVE_TO_CASHMAIN_FORM_ID = "save_to_cashmain_form"; var CASHMAIN_USERNAME_ID = "cashmain_username"; var CASHMAIN_PASSWORD_ID = "cashmain_password"; var CASHMAIN_LOAD_FROM_CASHMAIN_FORM_ID = "load_from_cashmain_form"; var CASHMAIN_LOAD_FROM_CASHMAIN_TOKEN_ID = "load_from_cashmain_token"; var CASHMAIN_LOAD_FROM_CASHMAIN_LANG_ID = "load_from_cashmain_lang";