/**********************************************************************************************************************/
/* tinyJStools version 1.1                                                                                            */
/* March 2004                                                                                                         */
/*                                                                                                                    */
/* (c) SCalc 2004                                                                                                     */
/* You can be used freely for personal purposes or installed on personal or commercial websites provided it is        */
/* installed without any modifications (apart from the settings which can be modified according to the install.txt    */
/* file).                                                                                                             */
/* It is not allowed:                                                                                                 */
/* - to modify the code, in particular - but not only - to remove the link(s) to tinyJStools                          */
/* - to redistribute the code without a prior agreement with tinyJStools                                              */
/**********************************************************************************************************************/

if(_mode >= _modes.length) _mode = _modes.length-1;if(_mode == -1) _mode = Math.floor(Math.random()*_modes.length);var time_out; var _tjst_site = 'http://tjst.scalc.org';var _isNS = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4);function tinyjstools(){if(document.getElementById) {var _output = '<div style="width:120px;"><table width="120" height="120" border="0" cellpadding="0" cellspacing="0">';_output += '<tr height="6">';_output += '   <td width="6" class="bordertable"><img src="'+_tjst_path+'/style/topleft.gif"></td>';_output += '   <td width="108" class="bordertable"><img src="'+_tjst_path+'/style/top.gif"></td>';_output += '   <td width="6" class="bordertable"><img src="'+_tjst_path+'/style/topright.gif"></td>';_output += '</tr>';_output += '<tr height="100" valign="middle">';_output += '   <td width="6" class="bordertable"><img src="'+_tjst_path+'/style/left.gif"></td>';_output += '   <td width="108" class="outputpanel"><div align="center" id="display" style="overflow: hidden; height: 98px; width: 106px;"></div></td>';_output += '   <td width="6" class="bordertable"><img src="'+_tjst_path+'/style/right.gif"></td>';_output += '</tr>';_output += '<tr height="14">';_output += '   <td width="6" class="bordertable"><img src="'+_tjst_path+'/style/botleft.gif"></td>';_output += '   <td width="108" class="bordertable">';_output += '   <table width="100%" border="0" cellpadding="0" cellspacing="0">';_output += '	<tr>';_output += '		<td class="bordertable"><img src="'+_tjst_path+'/style/bot_4.gif"></td>';_output += '		<td class="bordertable"><a class="link" href="javascript:" onclick="decrease_mode(); return(false);"><img src="'+_tjst_path+'/style/button_left.gif" border="0"></a></td>';_output += '		<td class="bordertable"><a class="link" href="'+_tjst_site+'/index.php?pid='+_tjst_pid+'" target="_blank"><img src="'+_tjst_path+'/style/bot_78_tjst.gif" border="0"></a></td>';_output += '		<td class="bordertable"><a class="link" href="javascript:" onclick="increase_mode(); return(false);"><img src="'+_tjst_path+'/style/button_right.gif" border="0"></a></td>';_output += '		<td class="bordertable"><img src="'+_tjst_path+'/style/bot_4.gif"></td>';_output += '	</tr>';_output += '   </table>';_output += '   </td>';_output += '   <td width="6" class="bordertable"><img src="'+_tjst_path+'/style/botright.gif"></td>';_output += '</tr>';_output += '</table></div>';document.write(_output);_display();}else{_output = '<a class="link" href="' + _tjst_site +'/index.php?pid='+_tjst_pid+'"><img src="'+_tjst_path+'/style/logo_default.gif border="0"></a>';document.write(_output);}}function _display(){clearTimeout(time_out);if(_modes[_mode] == 'clock') {disp_clock(); return;}else if(_modes[_mode] == 'puzzle') { _puzzle_drawtable(); _puzzle_init(); _puzzle_draw();}else if(_modes[_mode] == 'calendar') {var jour=new Date(); disp_calendar(jour.getMonth()+1,jour.getYear()); return;}else if(_modes[_mode] == 'calculator') {disp_calculator(); return;}else if(_modes[_mode] == 'info') {disp_info(); return;}}function _write_display(id, text){if(document.getElementById(id)){document.getElementById(id).innerHTML = text;}else document.all[id].innerHTML = text;}function _write_calcinput(text){if(document.getElementById('calcinput')){if(document.getElementById('calcinput').S1) document.getElementById('calcinput').S1.value = text;}else{calcinput.S1.value = text;}}function _get_calcinput(){if(document.getElementById('calcinput') && document.getElementById('calcinput').S1) return(document.getElementById('calcinput').S1.value);return('');}function _focus_calcinput(){if(document.getElementById('calcinput')){if(document.getElementById('calcinput').S1) document.getElementById('calcinput').S1.focus();}else{calcinput.S1.focus();}}function disp_info(){var _output = '<iframe  id="subframe" src="'+_tjst_site+'/info.php?aid='+_tjst_aid+'" frameborder="0" width="106" height="98" marginheight="0" marginwidth="0" scrolling="auto"></iframe>';_write_display('display',_output);}function decrease_mode(){_mode--; if(_mode < 0) _mode = _modes.length-1; _display();}function increase_mode(){_mode++; if(_mode >= _modes.length) _mode = 0; _display();}function disp_clock(){var date_day = new Date();var year = date_day.getYear(); if(year<1000) year+=1900;var month = date_day.getMonth();var date = date_day.getDate();var day = date_day.getDay();var hours = date_day.getHours();var min = date_day.getMinutes();var sec = date_day.getSeconds();if (hours < 10) hours = "0" + hours;if (min < 10) min = "0" + min;if (sec < 10) sec = "0" + sec;var _output = "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td align='center' height='48'><font class='normal'>" + _clock_days[day] + "<br> " + date + " " + _clock_months[month] + " " + year + "</font></td></tr>";_output += "<tr><td align='center' valign='Middle' height='50'><font class='bold'>" + hours + ":" + min + ":" + sec + "</font></td></tr></table>";_write_display('display',_output);time_out = setTimeout("disp_clock()",1000);}function help_puzzle(){clearTimeout(time_out);var _output = "";_output = "<table width='100%' cellspacing='0' cellpadding='1' border='0'>";_output += "<tr><td align='center' height='15'><font class='small'><b>" + _tjstmessage[38] + "</b></font></td></tr>";_output += "<tr><td align='left'><font class='tiny'>" + _tjstmessage[39] + "</font></td></tr>";_output += "<tr><td align='center' height='17' valign='middle'><font class='tiny'><a class='link' href='javascript:' onclick='_display(); return(false);'>" + _tjstmessage[40] + "</a></font></td></tr></table>";_write_display('display',_output);}var _puzzle_size = 4;var _nrandom = 100;var _puzzle = new Array(6);var _i, _ie, _je, _nr, _ik, _jk;for(_i=0; _i<7; _i++) _puzzle[_i] = new Array(6);function _puzzle_init(){var _i, _j;for(_i=0; _i<_puzzle_size+2; _i++){_puzzle[_i][0] = -1;_puzzle[_i][_puzzle_size+1] = -1;_puzzle[_puzzle_size+1][_i] = -1;_puzzle[0][_i] = -1;}for(_i=1; _i <= _puzzle_size; _i++){for(_j=1; _j <= _puzzle_size; _j++){_puzzle[_i][_j] = (_i - 1) * _puzzle_size + _j;}}_puzzle[_puzzle_size][_puzzle_size] = 0;_ie = _puzzle_size;_je = _puzzle_size;_nr = 0;_ik = 0;_jk = 0;}function _puzzle_checkgain(){var _i, _j, _n;var _output = '';for(_i=1; _i<=_puzzle_size; _i++){for(_j=1; _j<=_puzzle_size; _j++){_n = (_i - 1) * _puzzle_size + _j;if(_i == _puzzle_size && _j == _puzzle_size) _n = 0;if(_puzzle[_i][_j] != _n) return;}}_output = '&nbsp;<br><font class="tiny"><b>' + _tjstmessage[25] + '</b></font><br>&nbsp;<br>';_output += '<font class="small"><a class="link" href="javascript:" onClick="_puzzle_drawtable(); _puzzle_init(); _puzzle_draw(); Randomize();  return(false);">'+_tjstmessage[35]+'</a></font>';_write_display('display',_output);}function _puzzle_randomize(){var _i, _nij, _njk;do {_nik = Math.floor(3*Math.random())-1; _njk = 0; if(_nik == 0) _njk = Math.floor(3*Math.random())-1;}while(_nik == -_ik && _njk == -_jk);_ik = _nik; _jk = _njk;if(_puzzle[_ie+_ik][_je+_jk] != -1) {_nr ++; _puzzle_move(_ie+_ik, _je+_jk); _ie = _ie+_ik; _je = _je+_jk;}if(_nr < _nrandom) setTimeout("_puzzle_randomize()",1);}function _puzzle_draw(){var _i, _j, _k;_write_display('p1','<a class="link" href="javascript:" onclick="_puzzle_move(1,1); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[1][1]+'.gif" border="0"></a>');_write_display('p2','<a class="link" href="javascript:" onclick="_puzzle_move(1,2); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[1][2]+'.gif" border="0"></a>');_write_display('p3','<a class="link" href="javascript:" onclick="_puzzle_move(1,3); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[1][3]+'.gif" border="0"></a>');_write_display('p4','<a class="link" href="javascript:" onclick="_puzzle_move(1,4); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[1][4]+'.gif" border="0"></a>');_write_display('p5','<a class="link" href="javascript:" onclick="_puzzle_move(2,1); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[2][1]+'.gif" border="0"></a>');_write_display('p6','<a class="link" href="javascript:" onclick="_puzzle_move(2,2); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[2][2]+'.gif" border="0"></a>');_write_display('p7','<a class="link" href="javascript:" onclick="_puzzle_move(2,3); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[2][3]+'.gif" border="0"></a>');_write_display('p8','<a class="link" href="javascript:" onclick="_puzzle_move(2,4); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[2][4]+'.gif" border="0"></a>');_write_display('p9','<a class="link" href="javascript:" onclick="_puzzle_move(3,1); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[3][1]+'.gif" border="0"></a>');_write_display('p10','<a class="link" href="javascript:" onclick="_puzzle_move(3,2); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[3][2]+'.gif" border="0"></a>');_write_display('p11','<a class="link" href="javascript:" onclick="_puzzle_move(3,3); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[3][3]+'.gif" border="0"></a>');_write_display('p12','<a class="link" href="javascript:" onclick="_puzzle_move(3,4); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[3][4]+'.gif" border="0"></a>');_write_display('p13','<a class="link" href="javascript:" onclick="_puzzle_move(4,1); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[4][1]+'.gif" border="0"></a>');_write_display('p14','<a class="link" href="javascript:" onclick="_puzzle_move(4,2); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[4][2]+'.gif" border="0"></a>');_write_display('p15','<a class="link" href="javascript:" onclick="_puzzle_move(4,3); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[4][3]+'.gif" border="0"></a>');_write_display('p16','<a class="link" href="javascript:" onclick="_puzzle_move(4,4); _puzzle_checkgain();"><img src="'+_tjst_path+'/style/puzzle/pu'+_puzzle[4][4]+'.gif" border="0"></a>');}function _puzzle_move(_i, _j){if(_puzzle[_i-1][_j] == 0) {_puzzle[_i-1][_j] = _puzzle[_i][_j]; _puzzle[_i][_j] = 0; _puzzle_draw(); return; }if(_puzzle[_i+1][_j] == 0) {_puzzle[_i+1][_j] = _puzzle[_i][_j]; _puzzle[_i][_j] = 0; _puzzle_draw(); return; }if(_puzzle[_i][_j-1] == 0) {_puzzle[_i][_j-1] = _puzzle[_i][_j]; _puzzle[_i][_j] = 0; _puzzle_draw(); return; }if(_puzzle[_i][_j+1] == 0) {_puzzle[_i][_j+1] = _puzzle[_i][_j]; _puzzle[_i][_j] = 0; _puzzle_draw(); return; }}function _puzzle_drawtable(){var _hsize = 18*4+2;var _i, _j, _n;var _output = '';_output = '<table width="106" border="0" cellpadding="0" cellspacing="0"><tr>';_output += '<td width="53" height="20" align="center" valign="middle"><font class="tiny"><a class="link" href="javascript:" onclick="window.open(\''+_tjst_path+'/help/taquin_'+_language+'.html\',\'\',\'toolbar=0,location=0,directories=0,status=1,scrollbars=yes,resizable=yes,copyhistory=0,menuBar=0,width=550,height=575\'); return(false);">'+_tjstmessage[36]+'</a></font></td><td align="center" width="53" valign="middle"><font class="tiny"><a class="link" href="javascript:" onclick="Randomize(); return(false);">'+_tjstmessage[37]+'</a></font></td></tr>';_output += '<tr><td colspan="2" valign="middle" align="center">';_output += '<div style="width:'+_hsize+'px;"><table width="'+_hsize+'" cellpadding="0" cellspacing="0" style="border: 1px solid #ccc;" align="center">';for(_i=0; _i<4; _i++){_output += '<tr height="18">';for(_j=0; _j<4; _j++){_n = 4 * _i + _j + 1;_output += '<td id="p'+_n+'" width="18"></td>';}_output += '</tr>';}_output += '</table></div></td></tr></table>';_write_display('display',_output);}function ChangeSize(){var _value = parseInt(document.size.input.value);_puzzle_size = _value;_puzzle_drawtable();_puzzle_init();_puzzle_draw();}function ChangeRandom(){var _value = parseInt(document.random.input.value);if(_value == 0) _nrandom = 3;else if(_value == 1) _nrandom = 10;else if(_value == 2) _nrandom = 30;else if(_value == 3) _nrandom = 100;else if(_value == 4) _nrandom = 300;}function Randomize(){_nr = 0;_puzzle_init();_puzzle_randomize();_puzzle_draw();}function disp_calendar(month, year){if(year<1000) year+=1900;var _output = '';var d_jour=new Date();var a=year;var m=month;var d=new Date(a,m-1,1);var dfin=new Date(a,m-1,1);var nb_jour=31;var aff_j="";for(var k=32;k>27;k--){dfin.setMonth(m-1);dfin.setDate(k);if (dfin.getMonth()!=m-1) {nb_jour=k-1;}}var prevmonth = month-1;var prevyear = year;if(prevmonth < 1) {prevmonth=12; prevyear=prevyear-1}var nextmonth = month+1;var nextyear = year;if(nextmonth > 12) {nextmonth=1; nextyear=nextyear+1}var j1=d.getDay(); if (j1==0) j1=7;var jour=0;_output += "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";_output += "<tr height='16' class='calhead'><td align='center'><font class='tiny'><b><a class='link' href='javascript:' onclick='disp_calendar("+prevmonth+","+prevyear+"); return(false);'>&lt;</a></b></font></td>";_output += "<td colspan='5' align='center'><font class='tiny'><b>"+_calendar_months[m-1]+" "+a+"</b></font></td>";_output += "<td align='center'><font class='tiny'><b><a class='link' href='javascript:' onclick='disp_calendar("+nextmonth+","+nextyear+"); return(false);'>&gt;</a></b></font></td></tr>";_output += "<tr align='center'>";for(var j=0; j<7; j++){_output += "<td width='15' align='center'><font class='tiny' style='color:  blue;'>" + _cal_days[j] + "</font></TD>";}_output += "</TR>";for(var i=0;i<6;i++){_output += "<TR height='10'>";for (j=0;j<7;j++){jour=7*i+j-j1+2;aff_j=jour;if ((jour==d_jour.getDate())&&(m==d_jour.getMonth()+1)) {aff_j="<FONT class='tinycal' style='color: red; background-color: #ff8;'>"+jour+"</FONT>";}if ((7*i+j>=j1-1)&&(jour<=nb_jour)) {if (j==6) _output += "<TD align='center'><FONT class='tinycal'>"+aff_j+"</FONT></TD>";else _output += "<TD align='center'><FONT class='tinycal' >"+aff_j+"</FONT></TD>";}else _output += "<TD align='center'><FONT class='tinycal'>&nbsp; </TD>";}_output += "</TR>";}_output += '</font></table>';_write_display('display',_output);}function calc_keyboard(chr){if(document.getElementById('calcinput') && document.getElementById('calcinput').S1){if(_clear == 1) document.getElementById('calcinput').S1.value = '';document.getElementById('calcinput').S1.value += chr;_clear = 0;_focus_calcinput();}}function disp_calculator(){var _output = '';_output += '<form class="tjstform" id="calcinput" name="calcinput" action="javascript:void(0)"><table width="100%" style="width: 106px;" cellpadding="0" cellspacing="0" align="center" valign="top">';_output += '<tr><td width="100%" id="calchead" align="right" height="12" valign="middle">';_output += '<table width="100%" cellpadding="0" cellspacing="0">';_output += '<tr>';_output += '<td width="33%" class="tiny" align="center"><div id="angle"></div></td>';_output += '<td width="33%" id="fixfield" class="tiny" align="center"></td>';_output += '<td width="34%" align="center"><font class="tiny"><a class="link" href="javascript:" onclick="window.open(\''+_tjst_path+'/help/calc_'+_language+'.html\',\'\',\'toolbar=0,location=0,directories=0,status=1,scrollbars=yes,resizable=yes,copyhistory=0,menuBar=0,width=550,height=575\'); return(false);">'+_tjstmessage[36]+'</a></font></td>';_output += '</tr></table></td></tr>';_output += '<tr><td width="100%" height="18" valign="middle">';_output += '<input class="calcinput" type="text" style="width: 106px; height: 18px; border: 1px solid black; font-size: 10px;" rows="1" name="S1" onkeypress="_keypressed(event);" onkeyup="_keyup(event);">';_output += '</td></tr>';_output += '<tr class="keyboard"><td height="68">';_output += '<table width="100%" cellpadding="1" cellspacing="0">';_output += '<tr>';_output += '<td width="16" height="16"><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="+" onClick="calc_keyboard(\'+\');" onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16"><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="-" onClick="calc_keyboard(\'-\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16"><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="0" onClick="calc_keyboard(\'0\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16" ><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="1" onClick="calc_keyboard(\'1\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16" ><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="2" onClick="calc_keyboard(\'2\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16" ><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="3" onClick="calc_keyboard(\'3\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '</tr>';_output += '<tr>';_output += '<td width="16" height="16"><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="*" onClick="calc_keyboard(\'*\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16"><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="/" onClick="calc_keyboard(\'/\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16"><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="." onClick="calc_keyboard(\'.\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16" ><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="4" onClick="calc_keyboard(\'4\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16" ><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="5" onClick="calc_keyboard(\'5\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16" ><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="6" onClick="calc_keyboard(\'6\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '</tr>';_output += '<tr>';_output += '<td width="32" colspan="2" height="16"><input type="button" class="CalculatorButtonDefault" style="width:32; text-align:center; font-weight: bold;" name="enter" value="ent." onClick="_docalc(false);calcinput.S1.focus();"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16"><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="C" onClick="_clearmem();calcinput.S1.focus();"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16" ><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="7" onClick="calc_keyboard(\'7\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16" ><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="8" onClick="calc_keyboard(\'8\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '<td width="16" ><input type="button" class="CalculatorButtonDefault" style="width:15; text-align:center;" name="one" value="9" onClick="calc_keyboard(\'9\');"onmouseover="this.className=\'CalculatorButtonHighlight\';" onmouseout="this.className=\'CalculatorButtonDefault\';"></td>';_output += '</tr>';_output += '</table></td></tr></table></form>';_write_display('display',_output);disp_calc_head();disp_calcoutput();}function disp_calc_head(){var _angle_text = (Math.deg)?"<font class='tiny'><a class='link' href='javascript:' onclick='Math.deg = 0; disp_calc_head(); return(false);'>deg</a></font>":"<font class='tiny'><a class='link' href='javascript:' onclick='Math.deg = 1; disp_calc_head(); return(false);'>rad</a></font>";_write_display('angle', _angle_text);if(_fix > -1){_write_display('fixfield', "fix " + _fix);}else{_write_display('fixfield', "");}_clear = 1;}function disp_calcoutput(){_write_calcinput(_calcoutput);_focus_calcinput();_clear = 1;}



var _fN = new Array();
var _lines = new Array();
var _units = new Array();
var _params = new Array();
var _right=1;
var _left=0;
var _myexception = new Error("my error");
var _tmpmessage = _tjstmessage[6];
var _mywindow;
var _ret = _isNS?"\n":"\r\n";
var _fix = -1;
var _calcoutput = '';
var _clear = 0;

var _maxhistory = 50;
var _historyIndex = 0;
var _history = new Array(_maxhistory);

//_text=document.input.S1.value
//_answer=document.input.T1
e= 2.7182818284590452353602;

_fN[0] = ["asin",["x"],"Math.asin(x)*((Math.deg)?180/pi:1)",0];
_fN[1] = ["acos",["x"],"Math.acos(x)*((Math.deg)?180/pi:1)",0];
_fN[2] = ["atan",["x"],"Math.atan(x)*((Math.deg)?180/pi:1)",0];
_fN[3] = ["log",["x"],"Math.log(x)/Math.log(10)",0];
_fN[4] = ["ln",["x"],"Math.log(x)",0];
_fN[5] = ["sin",["x"],"Math.sin(x*((Math.deg)?pi/180:1))",0];
_fN[6] = ["cos",["x"],"Math.cos(x*((Math.deg)?pi/180:1))",0];
_fN[7] = ["tan",["x"],"Math.tan(x*((Math.deg)?pi/180:1))",0];
_fN[8] = ["pi",[],"Math.PI",0];
_fN[9] = ["log",["x","y"],"Math.log(x)/Math.log(y)",0];
_fN[10] = ["sqrt",["x"],"Math.sqrt(x)",0];
_fN[11] = ["exp",["x"],"Math.exp(x)",0];
_fN[12] = ["pow",["x","y"],"Math.pow(x,y)",0];
_fN[13] = ["cosh",["x"],"0.5*(Math.exp(x)+Math.exp(-x))",0];
_fN[14] = ["sinh",["x"],"0.5*(Math.exp(x)-Math.exp(-x))",0];
_fN[15] = ["tanh",["x"],"(Math.exp(x)-Math.exp(-x))/(Math.exp(x)+Math.exp(-x))",0];
_fN[16] = ["atanh",["x"],"0.5*Math.log((1+x)/(1-x))",0];
_fN[17] = ["acosh",["x"],"Math.log(x+Math.sqrt(x*x-1))",0];
_fN[18] = ["asinh",["x"],"Math.log(x+Math.sqrt(x*x+1))",0];

_defaultfunctions=19;

_nameslength=26;
_recursions=40;

function StdDev(_ar)
{
var _x=0;
var _temp=0;
for(_i=0;_i<_ar.length;++_i)
  _x=_x+_ar[_i];
_x=_x/_ar.length  ;
for(_i=0;_i<_ar.length;++_i)
     _temp=_temp+Math.pow(_ar[_i]-_x,2) ;
_temp=Math.pow(_temp/(_ar.length-1),1/2);
return (_temp);
}

function fitpoly(e,b)
{
var c=new Array();
var a=new Array();
var d=new Array();

n = 1+b;
e=[[0,0]].concat(e);
ns=e.length-1;
for(i=0;i<=n+1;i++)
{
 a[i]=new Array();
 d[i]=new Array();
 c[i]=0;
 for(j=0;j<=n+1;++j)
 {
  a[i][j]=0;
  d[i][j]=0;
 }
 }
for(m=1;m <= n;m++)
        for(i=1;i<= m;i++) 
             {
                j = m - i + 1; 
                for(ii=1;ii <= ns;ii++) a[i][j] = a[i][j] + Math.pow(e[ii][0], m-1);
              }         
for(i=1;i<= n;++i)
        for(ii=1;ii<=ns;++ii) a[i][n+1] = a[i][n+1]  +e[ii][1]*Math.pow(e[ii][0],i-1) ;
for(m = n+2 ; m <=  2*n ; ++m)
        for(i = m-n; i<= n;++i)
           {
                j= m -i  ;
                for(ii=1; ii<=ns;++ii) a[i][j] = a[i][j] + Math.pow(e[ii][0],m-2);
            }

for(m=2; m<=n ; ++m)
{
        for(i=m;i<=n;++i)
                for(j=m-1;j<=n+1;++j)
                {   
					if(a[i][m-1]==0) d[i][j]=0 ;
                    else d[i][j] = a[i][j] * a[m-1][m-1] / a[i][m-1];                  
                 }   
        for(i=m;i<=n;++i)
                for(j=m-1;j<=n+1;++j)
                {
                     a[i][j] = -a[m-1][j] + d[i][j];
                     if(Math.abs(a[i][j])<1.E-20) a[i][j]=0;
                }        
}        
for(i=n;i>=1;--i)
{
        c[i-1] = a[i][n+1];
        if (i!=n)
         for(j=n; j>=i+1;--j) c[i-1] = c[i-1] -a[i][j] * c[j-1];

        if(a[i][i]!=0) c[i-1]=c[i-1] / a[i][i];
        else c[i-1]=0;
        if(Math.abs(c[i-1])<Math.pow(10,-ns)) c[i-1]=0;
}

c.length=n;
return c;
}


function factorial(_a)
{
	if (_a==0) return 1;
	else return _a*factorial(_a-1);
}

function replabs(_line)
{
	_reg=/[a-zA-Z0-9\)\!\.][ ]{0,1}[|]/;
	_count=0;
	while ((_pos=_line.indexOf(_what=_line.match(_reg)))!=-1)
	{
	_count++;
	_w=String(_what).length-1;
	_line=_line.substring(0,_pos)+String(_what).substring(0,_w)+")"+_line.substring(_pos+1+_w);
	}

	while (_line.indexOf("|")!=-1)
	{
	_count--;
	_line=_line.replace("|","Math.abs(");
	}
	if (_count) 
	 {
	 _tmpmessage = _tjstmessage[7];
	  throw _myexception;
	 }
	return _line;
}

function _keypressed(_evnt)
{

_ch=(_isNS?_evnt.which:_evnt.keyCode);
//alert(_ch);
if (_ch==13)
{
	_docalc(false);
//	alert('docalc');
//	_focus_calcinput();
}
else if(_clear == 1)
	{
	_write_calcinput('');
	_focus_calcinput();
//	calcinput.S1.value = '';
//	calcinput.S1.focus();
	_clear = 0;
	}
	
}

function _keyup(_evnt)
{
	_ch = (_isNS?_evnt.which:_evnt.keyCode);

//	alert(_ch);
	if(_ch == 38 || _ch == 40)
	{
		if(_ch == 38) _historyIndex++;
		if(_ch == 40) _historyIndex--;
		if(_historyIndex < 0) _historyIndex = 0;
		if(_historyIndex > _maxhistory) _historyIndex = _maxhistory;
		
		_val = _history[_historyIndex-1];
		if(_val == null) _val = '';
		_write_calcinput(_val);
	}
	return;
}

function _clearmem()
{
	if ((_fN.length==_defaultfunctions)&&(_get_calcinput()==""))
	{
		 _calcoutput = _tjstmessage[8];
		 disp_calcoutput();
	}
	else
	{
		_write_calcinput('');
		_fN.length=_defaultfunctions;
		_calcoutput = _tjstmessage[9];
		disp_calcoutput();
	}
}


function _findfirstname(_aline,_frompos)
{
	_reader="";
	_first=true;
	_ch="";
	_oldch="";
	_pos=-1;
	for(_i=_frompos;_i<_aline.length;++_i)
	{
	 _ch=_aline.charAt(_i);

	 if (_first)
	 {
	   if (((_ch>="a")&&(_ch<="z"))||((_ch>="A")&&(_ch<="Z")))
	   {
			if (!(((_oldch>="0")&&(_oldch<="9"))||(_oldch==".")))
			{
			   _first=false;
			   _reader=_reader+_ch;
			   _pos=_i;
			}
	   }
	   else _oldch=_ch;
	  }
	 else if ((((_ch>="a")&&(_ch<="z"))||((_ch>="A")&&(_ch<="Z"))) || ((_ch>="0")&&(_ch<="9"))) _reader=_reader+_ch;
	 else if(_ch=="(") return [_reader,_pos,true];
     else if(_ch==".")
	 {
		  _reader="";
		  _oldch=_ch;
		  _first=true;
	 }
	 else return [_reader,_pos,false];
	}
	if(_reader.length>0) return [_reader,_pos,false];
	else return ["",-1,false];
}


function _priority(_ch)
{
	_symb= ".!^*/%+-=#><@$\\,?:";
	_prior="654333221111111000";
	if (_symb.indexOf(_ch)==-1) return 7;
	else return(_prior.charAt(_symb.indexOf(_ch)));
}

function _readentity(_tmp,_pos,_dir)
{
_level=0;
_entity="";
_ch="";
_checkCh=_tmp.charAt(_pos);

for(_i=_pos+(_dir?+1:-1);;(_dir?++_i:--_i))
{ 
  _ch=_tmp.charAt(_i);
  if (
        ((_priority(_ch)<=_priority(_checkCh))&&(_level==0))
        ||
        (_ch=="")
        )
    return _entity;
  if (  ((_ch=="(") && (_dir?(++_level,0):_level--==0))
        ||
        ((_ch==")") && (_dir?(_level--==0):(++_level,0)))
     ) 
    return _entity;
   else _entity=(_dir?"":_ch)+_entity+(_dir?_ch:"");
}
}

function _replacepower(_tmp)
{
	var _pos=0;

	while (_tmp.indexOf("!")!=-1)
	{  
		_pos=_tmp.indexOf("!");
		_leftentity=_readentity(_tmp,_pos,_left);
		_tmp=_tmp.substr(0,_pos-_leftentity.length)+"factorial("+_leftentity+")"+_tmp.substr(_pos+1);
	}  
	while (_tmp.indexOf("^")!=-1)
	{
	  _pos=_tmp.indexOf("^");
	  _leftentity=_readentity(_tmp,_pos,_left);
	  _rightentity=_readentity(_tmp,_pos,_right);
	  _tmp=_tmp.substr(0,_pos-_leftentity.length)+"Math.pow("+_leftentity+","+_rightentity+")"+_tmp.substr(_pos+1+_rightentity.length,_tmp.length);
	}  
	return _tmp;
}

function _SaveFunction(_str,_f)
{
	 var _i;
	 var _j;
	 if (_f)
	 {
		 _nameOf =_str.substring(0,_str.indexOf("("));
		 _paramOf =_str.substring(_str.indexOf("(")+1,_str.indexOf(")")).split(",");
		 for(_i=0;_i<_paramOf.length;++_i)
		  for(_j=_i+1;_j<_paramOf.length;++_j)
		   if(_paramOf[_i]==_paramOf[_j])
				 {
				  _tmpmessage = _tjstmessage[10];
				  throw _myexception;
				 }    
	 }         
	 else
	 {
		 _nameOf =_str.substring(0,_str.indexOf("="));
		 _paramOf=[];
	  }
	 _bodyOf =_str.substring(_str.indexOf("=")+1,_str.length)  ;
	  _exist = false;
	  for(_i=0;_i<_fN.length;++_i)
	  if (_fN[_i][0]==_nameOf)
		   if (
				  ((_f) && (_fN[_i][1].length==_paramOf.length)) ||
				  ((!_f) && (_fN[_i][1].length==0))
			  )
		   {
		  _exist=true;
		   if(_i>=_defaultfunctions)
			 {  
			 _fN[_i]=[_nameOf,_paramOf,_bodyOf,0];
			 _calcoutput += _tjstmessage[11];
			 disp_calcoutput();
			 }
		   else
			 {
			  _tmpmessage = _tjstmessage[12];
			  throw _myexception;
			 }  
		   }
	  if (!_exist) 
	  {
		 _fN[_fN.length]=[_nameOf,_paramOf,_bodyOf,0];
		 _calcoutput += _str;
		 disp_calcoutput();
		 }
}


function _makequal(_line)
{
var _j=0;
var _startline = "";
var _endline = "";
var _qual = [];
var _q = "";
var _token;

_re = /[a-z|A-Z|0-9|!|.|\)][ ][a-z|A-Z|0-9|\(]/;
_token = _re.exec(_line);
_startline = _line;
if(_token != null)
  {
  _startline = _line.substring(0,_token.index+1) ;
  _q = _line.substring(_token.index+2);
   _qual[_j] = _q;
  while((_token = _re.exec(_q)) != null)
      {
        ++_j;
        _qual[_j-1]=_q.substring(0,_token.index+1);
        _qual[_j]=_q.substring(_token.index+2);
        _q=_qual[_j]   ;
      } 
  }
return [_startline,_qual];
}


function _MakeLines(_tmp)
{
var _check=[];
var _testline= "";
var _unit=[];
var _j=0;
var _i=0;
var _count=0;
while (
          ((_i=_tmp.indexOf(_isNS?"\n":"\r\n"))!=-1)
          ||
          ((_i=_tmp.length)!=0)
      )
{
     ++_count;
    _testline= _tmp.substr(0,_i);
    _check=_checkpar(_testline);
     if (!(_check[4]==0))
     {
       _tmpmessage = _tjstmessage[13] + _j;
        throw _myexception;
     }
     if (_testline.length>0)
     {
        _reg=new RegExp("[a-zA-Z][a-zA-Z0-9]{0,"+_nameslength+"}\\(","");
          if (
               (_testline.indexOf(_testline.match(_reg))==0)
               &&
               (_testline.indexOf(")=")!=-1)
             ) 
          {
            if((_check[0]==1)&&(_check[1]==0))
            {
            _unit=_makequal(_testline);
            _SaveFunction(_unit[0],true);
            _tmp=_tmp.replace(_testline,"");
            }
            else
            {
             _tmpmessage = _tjstmessage[14] + _j;
              throw _myexception;
            }
           }
           else
           {
            _reg = new RegExp("[a-zA-Z][a-z0-9]{0,"+_nameslength+"}=","");
            _token= _reg.exec(_testline);
             if (
               (_token!=null)&&(_token.index==0)
                )
             {
              if((_check[0]==1)&&(_check[1]==0))
              { 
               _unit=_makequal(_testline);
               _SaveFunction(_unit[0],false);
              _lines[_j]=[_testline.substring(0,_testline.indexOf("=")),true];
              _units[_j]=_unit[1];
               ++_j;
              } 
            else
            {
             _tmpmessage = _tjstmessage[14] + _j;
              throw _myexception;
             }
             _tmp = _tmp.replace(_testline,"");
           }
           else
           {
             _unit=_makequal(_testline);
             _lines[_j]= [_unit[0],false];
             _units[_j]=_unit[1];
             _tmp=_tmp.replace(_testline,"");
             ++_j;
            }
         }
       }
     else
       _tmp=_tmp.replace(_isNS?"\n":"\r\n","")  ;
} //while
}


function _getrealparams(_expr,_pos)
{
var _ch;
var _par=[];
var _level=0;
_ch=_expr.charAt(_pos);
_p1=_pos;
var _param="";
 while(!(_ch==(_level?"|":")")))
{
if ((_ch==",") && (_level==0))
 {
 _par[_par.length]=_param;
 _param="";
 }
else 
  _param=_param + _ch;
  
 if (_ch=="(") ++_level;
 if (_ch==")") --_level;
++_pos;
_ch=_expr.charAt(_pos);
}   
_par[_par.length]=_param;
return [_par,_pos-_p1];
}

function _replaceparams(_par,_realpar,_str)
{
var _leftstr="";
var _rightstr=_str;
var _re=new RegExp("\\b"+_par+"\\b");
var _token=_re.exec(_rightstr);
while (_token!=null)
{
if(_rightstr.charAt(_token.index+_par.length)!="(")
  {
  _leftstr=_leftstr+_rightstr.substring(0,_token.index);
  _rightstr=_rightstr.substring(_token.index+_par.length);
   _leftstr=_leftstr+"("+_realpar+")";
  }
  else
  {  
   _leftstr=_leftstr+_rightstr.substring(0,_token.index+_par.length+1);
   _rightstr=_rightstr.substring(_token.index+_par.length+1);
  } 
  _token=_re.exec(_rightstr);
}
return _leftstr+_rightstr;
}


function _replacefunctions(_line)
{
var _callcounter=0;
var _f;
_position=0;
var _redoit;
var _ii=0  ;
_paramandlength=[];
_realparams=[];
_counter=0;
_x=[];
for(_ii==0;_ii<_fN.length;++_ii)
  _fN[_ii][3]=0;
while ((_x=_findfirstname(_line,_position))[1]!=-1)
 {
   _counter=0;
   _redoit=false;
   for(_ii=0;_ii<_fN.length;++_ii)
    {
     if(_x[0]==_fN[_ii][0])
       {
        if ((_x[2])&&(_fN[_ii][1].length>0))
            {
             _paramandlength= _getrealparams(_line,_x[1]+_x[0].length+1);
             _realparams=_paramandlength[0];
             _paramsFN=_fN[_ii][1];
              if(_realparams.length==_paramsFN.length)
                 {
                   ++_counter;
                    _callcounter=++_fN[_ii][3]  ;                    
                   _leftstr=_line.substr(0,_x[1]);
                   _rightstr=_line.substr(_x[1]+_x[0].length+_paramandlength[1]+2);
                   _expression=_fN[_ii][2];
                   for(_j=0;_j<_paramsFN.length;++_j)
                         _expression=_replaceparams(_paramsFN[_j],_realparams[_j],_expression);
                  }
              }
         else if ((!_x[2])&&(_fN[_ii][1].length==0))
              {
                ++_counter;
                 _callcounter=++_fN[_ii][3];
                _leftstr=_line.substr(0,_x[1]);
                _rightstr=_line.substr(_x[1]+_x[0].length);
                _expression=_fN[_ii][2]  ;
              }
         }     
    if(_counter>0)
      {
       _line=_leftstr+"("+_expression+")"+_rightstr;
       _redoit=true;
        break  ;       
        }
    }//for
  
    if (_counter==0) 
            _tmpmessage = _tjstmessage[15] + _x[0];
     if(_callcounter > _recursions)    
        {
          _tmpmessage = _tjstmessage[16] + _x[0] + _tjstmessage[17] + _fN[_ii][3]  + _tjstmessage[18];
          throw _myexception;
        }
if (_redoit)
  _position=0;
  else
  _position=_x[1]+_x[0].length+1;
  }  //while 

return _line;
}

function _checkpar(_str)
{
var _leftlevel=-1;
var _rightlevel=0;
var _countequal=0;
var _equallevel=-1;
var _level=0;
var _oldch="";
var _ch="";
var _maxlevel=0;

for(_i=0;_i<_str.length;++_i)
 {
  _ch=_str.charAt(_i);
  switch (_ch)
   {
    case "(":
       ++_level;
       _maxlevel=_level;
       if (_oldch==")") 
           return [_countequal,0,0,0,-1] ;  
       _oldch=_ch;
       break;

    case ")":
        if (_oldch=="(") return [_countequal,0,0,0,-1];   
        --_level;
        _oldch=_ch;
        break;

    case "=": 
         if(_level==0)   
            {
              ++_countequal;
              _equallevel=_level ; 
               _leftlevel=_maxlevel;
               _maxlevel=0;
            }  
        _oldch=_ch;
         break;
    default: _oldch=_ch;    
   } //switch      
  if(_level<0) return [_countequal,0,0,0,-1] ;  
 }
return [_countequal,_equallevel,_leftlevel,_maxlevel,_level]; 
}




function _printfunctions()
{ 

 _mywindow=window.open("","newwin");
 _mywindow.document.write("----- user defined functions and variables----------","<p>");
 
 if (_fN.length==_defaultfunctions) _mywindow.document.write("---  NONE ------","<p>"); 
  for(_ii=_defaultfunctions;_ii<_fN.length;++_ii)
       _mywindow.document.write(_fN[_ii][0],((_fN[_ii][1].length==0)?"":"("),_fN[_ii][1],((_fN[_ii][1].length==0)?"=":")="),_restall(_fN[_ii][2],0),"<p>");
  _mywindow.document.write("---  results ( angles in "+(Math.deg?"degrees":"radians")+ ")------","<p>") ;
}

// symbols and values for units taken from http://physics.nist.gov/cuu/Units/rules.html"

_L1=[
  ["m","cm","mm","km","mi","yd","in","ft","acre","knot","mach"],
  ["L","gal","bu","bbl"],
  ["J","cal","Btu","erg"],
  ["s","min","h","yr","d","Hz"],
  ["gr","kg","lb","t","oz"],
  ["A","C"],
  ["N","dyn","kgf","lbf","W","V","hp","kp","kip","ozf"],
  ["frf","eur","dem","bef","itl","esp","iep","nlg","ats","pte","fim","grd"],
  ["Pa","Torr","bar","atm","at","inHg","psi","mmHg"]
  ];
_L2=[
    ["LL","m/100","1E-3*m","1000*m","5280*ft","m/1.0936","2.54*cm","yd/3","4046.8564*m^2","0.514444*m/s","m/s/0.0030154814819282195"],
    ["1E03*cm^3","3.785412*L","35.23907*L","42*gal"],
    ["N*m","4.19002*J","1.05587E3*J","1E-07*J"],
    ["TT","s*60","60*min","365*24*h","24*h","1/s"],
    ["MM","1000*gr","kg/2.2046","1000*kg","2.834952E-2*kg"],
    ["AA","A*s"],
    ["gr*m/s^2","N/1000000","9.80665*N","4.448222*N","J/s","W/A","550*ft*lbf/s","kgf","1000*lbf","2.780139E-1*N"],
    ["DD","6.55957*frf","1/1.95583*eur","1/40.3399*eur","1/1936.27*eur","1/166.386*eur","1/.787564*eur","1/2.20371*eur","1/13.7603*eur","1/200.482*eur","1/5.94573*eur","1/340.750*eur"],
    ["N/m^2","Pa/0.007501","Pa/0.00001","10132.5*Pa","9806.65*Pa","3386.389*Pa","lbf/in^2","133.3224*Pa"]
   ] ;
   
function _convert(_src)
{
var _i;
var _j;
var _coef="1";
var _position=0;
var _leftstr="";
var _rightstr="";
var _counter=0;
while ((_x=_findfirstname(_src,_position))[1]!=-1)
{
_leftstr=_src.substring(0,_x[1]);
_rightstr=_src.substring(_x[1]+_x[0].length);
 for(_i = 0; _i < _L1.length; ++_i)
 for(_j=0;_j<_L1[_i].length;++_j)
 {
   if(_x[0] == _L1[_i][_j])
   {
     _coef = _coef + "*" + _L2[_i][_j];
     _src = _leftstr + "(" + _coef + ")" +_rightstr;
     break;
   }
 }
 
 if((_x[0]=="LL")||(_x[0]=="TT")||(_x[0]=="MM")||(_x[0]=="DD")||(_x[0]=="AA") || (_x[0]=="CC"))
 _position=_x[1]+_x[0].length;
 _coef="1";
 if(++_counter>30) 
 {
 _tmpmessage = _tjstmessage[19] + _x[0];
  throw _myexception;
 }
}
_src=_replacepower(_src);
return _src;
}

var LL;
var TT;
var MM;
var DD;
var AA;
function _fortest(_LL)
{
LL=++_LL;
TT=++_LL;
MM=++_LL;
DD=++_LL;
AA=++_LL;
}
function _testdim(_src)
{
if(Math.abs((_fortest(1),eval(_src))-(_fortest(3),eval(_src)))<1E-8)
 {
  _tmpmessage = _tjstmessage[20];
  throw _myexception;
 }
}
function _replall(_str)
{
while (_str.indexOf("  ")!=-1)
   _str=_str.replace("  "," ");
while (_str.indexOf("<>")!=-1)
   _str=_str.replace("<>","#");
while (_str.indexOf("==")!=-1)
   _str=_str.replace("==","\\");

while (_str.indexOf(">=")!=-1)
   _str=_str.replace(">=","@");
while (_str.indexOf("<=")!=-1)
   _str=_str.replace("<=","$");
return _str;
}

function _restall(_str,_sw)
{
while (_str.indexOf("\\")!=-1)
   _str=_str.replace("\\","==");

while (_str.indexOf("#")!=-1)
 if (_sw)
   _str=_str.replace("#","!=");
   else
    _str=_str.replace("#","<>");

while (_str.indexOf("@")!=-1)
   _str=_str.replace("@",">=");
while (_str.indexOf("$")!=-1)
   _str=_str.replace("$","<=");
return _str;
}


function _docalc(_todoc)
{
_fortest(1);
var _line="";
var _unit=[];
var _result="";
_calcoutput = '';
_lines=[];
_units=[];
_temp=document.calcinput.S1.value;
_tmpmessage = _tjstmessage[20];

_addhistory(_temp);

if(_temp.indexOf("fix") == 0)
	{
	eval(_temp);
	disp_calc_head();
	return;
	}

if(_temp.indexOf("h2d") == 0)
	{
	_beg = strpos(_temp,'(')+1;
	_end = strpos(_temp,')');
	_inp = _temp.substr(_beg,_end-_beg);
	_calcoutput = _hex2dec(_inp); 
	disp_calcoutput();
	return;
	}

if(_temp.indexOf("d2h") == 0)
	{
	_beg = strpos(_temp,'(')+1;
	_end = strpos(_temp,')');
	_inp = _temp.substr(_beg,_end-_beg);
	_calcoutput = tohex(_inp); 
	disp_calcoutput();
	return;
	}

_calcoutput = _calc(_todoc, _temp);
disp_calcoutput();
return;
}

function _calc(_todoc, _temp)
{
_fortest(1);

var _calcoutput = '';
var _line="";
var _unit=[];
var _result="";
_lines=[];
_units=[];
//_temp=document.input.S1.value;
_tmpmessage = _tjstmessage[20];

try
 {
_temp=_replall(_temp);

_MakeLines(_temp);


if (_todoc)
  _printfunctions();
  
   for(_ii=0;_ii<_lines.length;++_ii) 
    {
     _line=_lines[_ii][0];
     _lines[_ii][0]=_restall(_lines[_ii][0]);
     _line= _replacefunctions(_line);
     _line=replabs(_line);
     _line=_replacepower(_line);
     _line=_restall(_line,true) ;    
           try {
             _firstunit="";
             _lastunit="";
             _result=eval(_line);
             if (_units[_ii].length>0)
             {
              _firstunit=_units[_ii][0];
              _testdim(_convert(_firstunit));
              _lastunit=_firstunit;
              _test1=_convert(_units[_ii][0]);
              for(_iii=1;_iii<_units[_ii].length;++_iii)
              {_lastunit=_units[_ii][_iii];
                _testdim(_convert(_lastunit));
               eval("var _test="+"   \"(\"+ _convert(_units[_ii][_iii-1])+\")/(\"+_convert(_units[_ii][_iii])+\")\" ") ;              
               if (
                  !(
                     (Math.abs((eval(_test))-(_fortest(2),eval(_test)))<1E-7) &&
                     (Math.abs((_fortest(3),eval(_test))-(_fortest(4),eval(_test)))<1E-7)
                   )
                   )
                     {
                     _tmpmessage = _tjstmessage[22];
                      throw _myexception;
                     }
             
               _result=eval(_result+"*"+ _test);
              }
              }
              
              if (_todoc)
                _mywindow.document.write(_lines[_ii][0]," ",_firstunit," => ",_result," ",_lastunit,"<p>");
//				  alert('result');
			  if(_fix > -1) _result = Math.round(_result*Math.pow(10,_fix))/Math.pow(10,_fix);
			  if(_lastunit != "") _calcoutput += _result + " " + _lastunit;
			  else _calcoutput += _result;
//			 disp_calcoutput();
                }
               catch(_er)
                {    if  (_lines[_ii][1])
                    {
                     if (_tmpmessage.indexOf(_tjstmessage[15])!=-1)
					 {
                        _calcoutput += _tjstmessage[11];
//						disp_calcoutput();
						}
                     } 
                     else
					 {
                     _calcoutput+=_tmpmessage;
//					 disp_calcoutput();
					 }
                 }
   }
 }
 catch(_myexception)
 {
    _calcoutput += _tmpmessage;
//	disp_calcoutput();
 }
 return(_calcoutput);
}

function _getLastLine()
{
	var s = _calcoutput.split('<br>');
	var n = s.length;
	return s[n-2];
}

function _switchAngles()
{
	Math.deg = (Math.deg)?0:1;
	disp_calc_head();
}

function fix(newfix)
{
	if(newfix == null) {_fix = -1; return; }
	_fix = newfix;
}

function _addhistory(_temp)
{
	for(_i = _maxhistory; _i > 0; _i--)
	{
		_history[_i] = _history[_i-1];
	}
	_history[0] = _temp;
	_historyIndex = 0;
}

function _hex2dec(_hexval){return(parseInt(_hexval,16));}

function strpos(str, ch) { for (var i = 0; i < str.length; i++) if (str.substring(i, i+1) == ch) return i; return -1; }

   function tohex(i) {
      a2 = '';
      ihex = hexQuot(i);
      idiff = eval(i + '-(' + ihex + '*16)');
      a2 = itohex(idiff) + a2;
      while( ihex >= 16) {
         itmp = hexQuot(ihex);
         idiff = eval(ihex + '-(' + itmp + '*16)');
         a2 = itohex(idiff) + a2;
         ihex = itmp;
      } 
      a1 = itohex(ihex);
      return a1 + a2 ;
   }
   function hexQuot(i) {
      return Math.floor(eval(i +'/16'));
   }
   function itohex(i) {
      if( i == 0) {
         aa = '0'; }
      else { if( i== 1) {
                aa = '1';}
         else {if( i== 2) {
                  aa = '2';}
            else {if( i == 3) {
                     aa = '3'; }
               else {if( i== 4) {
                        aa = '4';}
                  else {if( i == 5) {
                           aa = '5'; }
                     else {if( i== 6) {
                              aa = '6';}
                        else {if( i == 7) {
                                 aa = '7'; }
                           else {if( i== 8) {
                                    aa = '8';}
                              else {if( i == 9) {
                                        aa = '9';}
                                 else {if( i==10) {
                                          aa = 'A';}
                                    else {if( i==11) {
                                             aa = 'B';}
                                       else {if( i==12) {
                                                aa = 'C';}
                                          else {if( i==13) {
                                                   aa = 'D';}
                                             else {if( i==14) {
                                                      aa = 'E';}
                                                else {if( i==15) {
                                                         aa = 'F';}

                                                }
                                             }
                                          }
                                       }
                                    }
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
         }
      }
      return aa;
   }
 
