clearing_allowed=!1;function handle_skeleton_mode(){res=document.CC3D.getNodeEventOut("SCR_KBD","stripParts");document.skel_on.src=res==1?"./img/green.png":"./img/white.png";document.skel_off.src=res==0?"./img/green.png":"./img/white.png"}
function handle_cover_mode(){res=document.CC3D.getNodeEventOut("SCR_COVER","cover_mode");document.cover_auto.src=res==0?"./img/green.png":"./img/white.png";document.cover_show.src=res==1?"./img/green.png":"./img/white.png";document.cover_hide.src=res==2?"./img/green.png":"./img/white.png"}
function handle_col_set_mode(){res=document.CC3D.getNodeEventOut("SEC_SET_COL","col_set_mode");document.col_set_show.src=res==1?"./img/green.png":"./img/white.png";document.col_set_hide.src=res==0?"./img/green.png":"./img/white.png"}function handle_exploded_view_mode(){res=document.CC3D.getNodeEventOut("EXP_IMP_HANDLER","exploded_view_mode");document.exploded_on.src=res==1?"./img/green.png":"./img/white.png";document.exploded_off.src=res==0?"./img/green.png":"./img/white.png"}cnt=fps_old=0;
filter_fac=0.4;function getFrameRate(){cnt==0&&(fps_old=fps_new=filter_fac*fps_old+(1-filter_fac)*document.CC3D.getCurrentFrameRate(),fps=Math.round(fps_new),(d9=fps>=512)&&(fps-=512),(d8=fps>=256)&&(fps-=256),(d7=fps>=128)&&(fps-=128),(d6=fps>=64)&&(fps-=64),(d5=fps>=32)&&(fps-=32),(d4=fps>=16)&&(fps-=16),(d3=fps>=8)&&(fps-=8),(d2=fps>=4)&&(fps-=4),(d1=fps>=2)&&(fps-=2),d0=fps>=1,cnt=4);--cnt}
function handle_clearing_lever_pos(){res=document.CC3D.getNodeEventOut("SEC_CARRIAGE","leverMode");clearing_allowed=res==1;document.clearing_lever_fold.src=res==0?"./img/green.png":"./img/white.png";document.clearing_lever_expand.src=res==1?"./img/green.png":"./img/white.png"}
function handle_clearing_actions(){clearing_allowed?(document.clearing_action_results.src=document.CC3D.getNodeEventOut("SEC_CARRIAGE","ClearingAD_ActiveOut")=="TRUE"?"./img/green.png":"./img/white.png",document.clearing_action_results.title="click to clear the results [CR]"):(document.clearing_action_results.src="./img/red.png",document.clearing_action_results.title="first expand the clearing lever");clearing_allowed?(document.clearing_action_tc.src=document.CC3D.getNodeEventOut("SEC_CARRIAGE","ClearingTC_ActiveOut")==
"TRUE"?"./img/green.png":"./img/white.png",document.clearing_action_tc.title="click to clear the turns counter [CT]"):(document.clearing_action_tc.src="./img/red.png",document.clearing_action_tc.title="first expand the clearing lever");document.clearing_action_set.src=document.CC3D.getNodeEventOut("SEC_SET_AD","Clearing_Set_Active")=="TRUE"?"./img/green.png":"./img/white.png"}function try_clearing_res(){clearing_allowed&&keyboard_2_keys(67,82)}
function try_clearing_tc(){clearing_allowed&&keyboard_2_keys(67,84)}
function handle_car_pos(){res=document.CC3D.getNodeEventOut("SEC_CARRIAGE","offsetCur_changed");document.car_pos_1.src=res==0?"./img/green.png":"./img/white.png";document.car_pos_2.src=res==1?"./img/green.png":"./img/white.png";document.car_pos_3.src=res==2?"./img/green.png":"./img/white.png";document.car_pos_4.src=res==3?"./img/green.png":"./img/white.png";document.car_pos_5.src=res==4?"./img/green.png":"./img/white.png";document.car_pos_6.src=res==5?"./img/green.png":"./img/white.png"}
function handle_adder_mode(){res=document.CC3D.getNodeEventOut("SEC_ROTOR","isSubtractMode");document.adder_mode_add.src=res=="FALSE"?"./img/green.png":"./img/white.png";document.adder_mode_sub.src=res=="TRUE"?"./img/green.png":"./img/white.png"}function handle_tc_mode(){res=document.CC3D.getNodeEventOut("SEC_SET_TC","tc_mode");document.tc_mode_inc.src=res==0?"./img/green.png":"./img/white.png";document.tc_mode_dec.src=res==1?"./img/green.png":"./img/white.png"}
function handle_cranking(){res=document.CC3D.getNodeEventOut("SEC_ROTOR","isCranking");document.crank.src=res=="TRUE"?"./img/green.png":"./img/white.png";return res=="TRUE"}function keyboard_1_key(a){document.CC3D.setNodeEventIn("SCR_KBD","fromPage",a)}function keyboard_2_keys(a,b){document.CC3D.setNodeEventIn("SCR_KBD","fromPage",a);document.CC3D.setNodeEventIn("SCR_KBD","fromPage",b)}
function background(){document.CC3D.setNodeEventIn("_Background","frontUrl","./bkg/up.jpg");document.CC3D.setNodeEventIn("_Viewpoint","fieldOfView","1.57")}function loadURL(a){document.CC3D.loadURL(a,"")}function save_my_world(){document.CC3D.saveWorld("./koe.wrl")}function setHeadlight(a){document.CC3D.setNodeEventIn("NAV_INFO","headlight",a?"TRUE":"FALSE")}function setCollission(a){res=document.CC3D.setOption("collisionDetection",a?"TRUE":"FALSE")}
function count(){getFrameRate();timer=1;clearTimeout(timer);timer=setTimeout("count() ",250);count_vp_done||count_vp()}vp_cnt=0;vp_cur=1;count_vp_done=!1;function count_vp(){n=1;if(document.CC3D.setNodeEventIn("VP_1","set_bind","TRUE")){for(;document.CC3D.setNodeEventIn("VP_"+n,"set_bind","TRUE");)add_vp_to_select(n),++n;vp_cnt=--n;document.CC3D.setNodeEventIn("VP_1","set_bind","TRUE");count_vp_done=!0}}function bind_vp(a){document.CC3D.setNodeEventIn("VP_"+a,"set_bind","TRUE")}
function lock_vp(a){document.CC3D.setNodeEventIn("SCR_VP_LOCKER","Selection",a)}function bind_selected_vp(a){bind_vp(a.selectedIndex+1)}function lock_the_vp(a){lock_vp(a.selectedIndex)}function add_vp_to_select(a){var b=document.getElementById("selCombo");b.options[b.options.length]=new Option(document.CC3D.getNodeEventOut("VP_"+a,"description"),a)}var s="0",s="0",state=0;
function OnEvent(a,b){if(a=="crank1")document.crank1.src=b==1?"./img/green.png":"./img/white.png";if(a=="crank2")document.crank2.src=b==1?"./img/green.png":"./img/white.png";if(a=="crank3")document.crank3.src=b==1?"./img/green.png":"./img/white.png";if(a=="crank4")document.crank4.src=b==1?"./img/green.png":"./img/white.png";if(a=="adder_mode")document.adder_mode_add.src=b==0?"./img/green.png":"./img/white.png",document.adder_mode_sub.src=b==1?"./img/green.png":"./img/white.png";if(a=="tc_mode")document.tc_mode_inc.src=
b==0?"./img/green.png":"./img/white.png",document.tc_mode_dec.src=b==1?"./img/green.png":"./img/white.png";if(a=="col_set_mode")document.col_set_show.src=b==1?"./img/green.png":"./img/white.png",document.col_set_hide.src=b==0?"./img/green.png":"./img/white.png";if(a=="cover_mode")document.cover_auto.src=b==0?"./img/green.png":"./img/white.png",document.cover_show.src=b==1?"./img/green.png":"./img/white.png",document.cover_hide.src=b==2?"./img/green.png":"./img/white.png";if(a=="stripParts")document.skel_on.src=
b==1?"./img/green.png":"./img/white.png",document.skel_off.src=b==0?"./img/green.png":"./img/white.png";if(a=="exploded_view_mode")document.exploded_on.src=b==1?"./img/green.png":"./img/white.png",document.exploded_off.src=b==0?"./img/green.png":"./img/white.png";if(a=="leverMode")document.clearing_lever_fold.src=b==0?"./img/green.png":"./img/white.png",document.clearing_lever_expand.src=b==1?"./img/green.png":"./img/white.png",(clearing_allowed=b==1)?(document.clearing_action_results.src="./img/white.png",
document.clearing_action_results.title="click to clear the results [CR]",document.clearing_action_tc.src="./img/white.png",document.clearing_action_tc.title="click to clear the turns counter [CT]"):(document.clearing_action_results.src="./img/red.png",document.clearing_action_results.title="first expand the clearing lever [CX]",document.clearing_action_tc.src="./img/red.png",document.clearing_action_tc.title="first expand the clearing lever [CX]");if(a=="ClearingAD_ActiveOut")document.clearing_action_results.src=
b==1?"./img/green.png":"./img/white.png";if(a=="ClearingTC_ActiveOut")document.clearing_action_tc.src=b==1?"./img/green.png":"./img/white.png";if(a=="Clearing_Set_Active")document.clearing_action_set.src=b==1?"./img/green.png":"./img/white.png";if(a=="offsetCur_changed")document.car_pos_1.src=b==0?"./img/green.png":"./img/white.png",document.car_pos_2.src=b==1?"./img/green.png":"./img/white.png",document.car_pos_3.src=b==2?"./img/green.png":"./img/white.png",document.car_pos_4.src=b==3?"./img/green.png":
"./img/white.png",document.car_pos_5.src=b==4?"./img/green.png":"./img/white.png",document.car_pos_6.src=b==5?"./img/green.png":"./img/white.png";a=="machineReadyBusy"&&(b==1?(state=4,update_keyboard(key_ena_state_mr),show_on_7_segm("busyzzz")):(state=1,s="0",show_on_7_segm(s,state,2),update_keyboard(key_ena_state_1a)));a=="setReq_done"&&state==2&&(state=3,s="0",show_on_7_segm(s,state,3),update_keyboard(key_ena_state_3a));a=="time_mul_done"&&(state=4);a=="time_crank_done"&&state==4&&display_tmp_result(b);
if(a=="fog_On")document.fog_toggle.src=b==0?"./img/white.png":"./img/green.png";if(a=="fog_Type")document.fog_linear.src=b=="LINEAR"?"./img/green.png":"./img/white.png",document.fog_exponential.src=b=="EXPONENTIAL"?"./img/green.png":"./img/white.png";if(a=="fog_VisRng")document.getElementById("fog_vis_rng").innerHTML="visibility range: "+b+" [mm]"}
function dec_2_8bin(a){dec=parseInt(a);(d7=dec>=128)&&(dec-=128);(d6=dec>=64)&&(dec-=64);(d5=dec>=32)&&(dec-=32);(d4=dec>=16)&&(dec-=16);(d3=dec>=8)&&(dec-=8);(d2=dec>=4)&&(dec-=4);(d1=dec>=2)&&(dec-=2);d0=dec>=1;s="";s+=d7?"1":"0";s+=d6?"1":"0";s+=d5?"1":"0";s+=d4?"1":"0";s+=d3?"1":"0";s+=d2?"1":"0";s+=d1?"1":"0";s+=d0?"1":"0";return s}function dec_2_6bin(a){s=dec_2_8bin(a);return s=s.substring(2,8)}
function show_on_7_segm(a,b,c){for(;a.length<11;)a="z"+a;document.d00.src="./7_segm/"+a.charAt(0)+".png";document.d01.src="./7_segm/"+a.charAt(1)+".png";document.d02.src="./7_segm/"+a.charAt(2)+".png";document.d03.src="./7_segm/"+a.charAt(3)+".png";document.d04.src="./7_segm/"+a.charAt(4)+".png";document.d05.src="./7_segm/"+a.charAt(5)+".png";document.d06.src="./7_segm/"+a.charAt(6)+".png";document.d07.src="./7_segm/"+a.charAt(7)+".png";document.d08.src="./7_segm/"+a.charAt(8)+".png";document.d09.src=
"./7_segm/"+a.charAt(9)+".png";document.d10.src="./7_segm/"+a.charAt(10)+".png";if(c==1)document.d00.src="./7_segm/d.png",document.d01.src="./7_segm/e.png",document.d02.src="./7_segm/c.png";if(c==2)document.d00.src="./7_segm/1.png",document.d01.src="./7_segm/dash.png",document.d02.src="./7_segm/2.png",document.d03.src="./7_segm/5.png",document.d04.src="./7_segm/5.png";if(c==3)document.d00.src="./7_segm/1.png",document.d01.src="./7_segm/dash.png",document.d02.src="./7_segm/6.png",document.d03.src=
"./7_segm/3.png";if(b==0)document.sts.src="./7_segm/ind_state_0.png";if(b==1)document.sts.src="./7_segm/ind_state_1.png";if(b==3)document.sts.src="./7_segm/ind_state_3.png";if(b==4)document.sts.src="./7_segm/ind_state_4.png"}
var key_ena_state_off=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0],key_ena_state_0=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1],key_ena_state_1a=[0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1],key_ena_state_1b=[1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1],key_ena_state_1c=[0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,0,1],key_ena_state_2=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],key_ena_state_3a=[0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1],key_ena_state_3b=[1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1],key_ena_state_3c=[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1],key_ena_state_4=[0,0,
0,0,0,0,0,0,0,0,0,0,0,0,1,0,1],key_ena_state_mr=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],key_ena=key_ena_state_off;function update_keyboard(a){key_ena=a;for(k=0;k<a.length;++k)document.getElementById("k"+k).src=key_ena[k]?"./calc_buttons/"+k+"_up.png":"./calc_buttons/"+k+"_no.png"}function key_dn(a){if(key_ena[a])document.getElementById("k"+a).src="./calc_buttons/"+a+"_dn.png"}
function key_up(a){if(key_ena[a]){document.getElementById("k"+a).src="./calc_buttons/"+a+"_up.png";a>=15&&state==0&&(s="presszczz",state=0,update_keyboard(key_ena_state_0),show_on_7_segm(s,state));a>=16&&(s="",state=0,update_keyboard(key_ena_state_off),show_on_7_segm(s,state));if(a>=0&&a<=9&&state==1){var b;s=="0"?(s=""+a,update_keyboard(key_ena_state_1b)):(s.length<3&&(tmp=""+s+a,b=parseInt(tmp),b<=255&&(s=tmp)),s.length==3&&update_keyboard(key_ena_state_1c));show_on_7_segm(s,state,2)}a>=0&&a<=9&&
state==3&&(s=="0"?(s=""+a,update_keyboard(key_ena_state_3b)):(s.length<2&&(tmp=""+s+a,b=parseInt(tmp),b<=63&&(s=tmp)),s.length==2&&update_keyboard(key_ena_state_3c)),show_on_7_segm(s,state,3));a==10&&state==1&&(s_bin=dec_2_8bin(s),document.CC3D.setNodeEventIn("SEC_SET_AD","setting_from_html",s_bin),document.CC3D.setNodeEventIn("PROG_MUL","m1",s_bin),s="0",state=2,update_keyboard(key_ena_state_2),show_on_7_segm(s,state,3));a==11&&state==1&&(s="0",show_on_7_segm(s,state,2),update_keyboard(key_ena_state_1a));
a==11&&state==3&&(s="0",show_on_7_segm(s,state,3),update_keyboard(key_ena_state_3a));a==12&&state==1&&(s.length>1?(s=s.substring(0,s.length-1),update_keyboard(key_ena_state_1b)):(s="0",update_keyboard(key_ena_state_1a)),show_on_7_segm(s,state,2));a==12&&state==3&&(s.length>1?(s=s.substring(0,s.length-1),update_keyboard(key_ena_state_3b)):(s="0",update_keyboard(key_ena_state_3a)),show_on_7_segm(s,state,3));a==13&&state==3&&(s_bin=dec_2_6bin(s),document.CC3D.setNodeEventIn("PROG_MUL","m2",s_bin),state=
4,update_keyboard(key_ena_state_4),show_on_7_segm("0",state));a==14&&keyboard_2_keys(77,82)}}function show_result(a){a=a.substring(5,16);for(ix=0;a.charAt(ix)=="0"&&ix<10;)++ix;a=a.substring(ix,a.length);show_on_7_segm(a,state)}function display_tmp_result(a){show_result(a)};
