blue_=new Image(10,10);blue_.src="./img/blue.png";green_=new Image(10,10);green_.src="./img/green.png";red_=new Image(10,10);red_.src="./img/red.png";white_=new Image(10,10);white_.src="./img/white.png";yellow_=new Image(10,10);yellow_.src="./img/yellow.png";clearing_allowed=false;fps_old=0;cnt=0;filter_fac=0.4;
function getFrameRate(){if(cnt==0){fps_new=filter_fac*fps_old+(1-filter_fac)*document.CC3D.getCurrentFrameRate();fps_old=fps_new;document.getElementById("current_frame_rate").innerHTML=Math.round(fps_new)+" fps";cnt=4}--cnt}function try_clearing_res(){if(clearing_allowed)keyboard_2_keys(67,82)}function try_clearing_tc(){if(clearing_allowed)keyboard_2_keys(67,84)}function keyboard_1_key(k1){document.CC3D.setNodeEventIn("SCR_KBD","fromPage",k1)}
function keyboard_2_keys(k1,k2){document.CC3D.setNodeEventIn("SCR_KBD","fromPage",k1);document.CC3D.setNodeEventIn("SCR_KBD","fromPage",k2)}function background(){document.CC3D.setNodeEventIn("_Background","frontUrl","./bkg/up.jpg");document.CC3D.setNodeEventIn("_Viewpoint","fieldOfView","1.57")}function loadURL(url){document.CC3D.loadURL(url,"")}function save_my_world(){document.CC3D.saveWorld("./koe.wrl")}
function setHeadlight(val){document.CC3D.setNodeEventIn("NAV_INFO","headlight",val?"TRUE":"FALSE")}function setCollission(s){res=document.CC3D.setOption("collisionDetection",s?"TRUE":"FALSE")}function onPageLoad(){count()}function count(){timer=1;clearTimeout(timer);timer=setTimeout("count() ",250);if(!count_vp_done)count_vp()}vp_cnt=0;vp_cur=1;count_vp_done=false;
function count_vp(){n=1;if(!document.CC3D.setNodeEventIn("VP_1","set_bind","TRUE"))return;while(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=true}function bind_vp(n){document.CC3D.setNodeEventIn("VP_"+n,"set_bind","TRUE")}function lock_vp(n){document.CC3D.setNodeEventIn("SCR_VP_LOCKER","Selection",n)}function bind_selected_vp(t){bind_vp(t.selectedIndex+1)}
function lock_the_vp(t){lock_vp(t.selectedIndex)}function add_vp_to_select(n){var S=document.getElementById("selCombo");S.options[S.options.length]=new Option(document.CC3D.getNodeEventOut("VP_"+n,"description"),n)}
function OnEvent(par1,par2,time){if(par1=="crank1")document.crank1.src=par2==1?"./img/green.png":"./img/white.png";if(par1=="crank2")document.crank2.src=par2==1?"./img/green.png":"./img/white.png";if(par1=="crank3")document.crank3.src=par2==1?"./img/green.png":"./img/white.png";if(par1=="crank4")document.crank4.src=par2==1?"./img/green.png":"./img/white.png";if(par1=="adder_mode"){document.adder_mode_add.src=par2==0?"./img/green.png":"./img/white.png";document.adder_mode_sub.src=par2==1?"./img/green.png":
"./img/white.png"}if(par1=="tc_mode"){document.tc_mode_inc.src=par2==0?"./img/green.png":"./img/white.png";document.tc_mode_dec.src=par2==1?"./img/green.png":"./img/white.png"}if(par1=="col_set_mode"){document.col_set_show.src=par2==1?"./img/green.png":"./img/white.png";document.col_set_hide.src=par2==0?"./img/green.png":"./img/white.png"}if(par1=="cover_mode"){document.cover_auto.src=par2==0?"./img/green.png":"./img/white.png";document.cover_show.src=par2==1?"./img/green.png":"./img/white.png";document.cover_hide.src=
par2==2?"./img/green.png":"./img/white.png"}if(par1=="stripParts"){document.skel_on.src=par2==1?"./img/green.png":"./img/white.png";document.skel_off.src=par2==0?"./img/green.png":"./img/white.png"}if(par1=="exploded_view_mode"){document.exploded_on.src=par2==1?"./img/green.png":"./img/white.png";document.exploded_off.src=par2==0?"./img/green.png":"./img/white.png"}if(par1=="leverMode"){document.clearing_lever_fold.src=par2==0?"./img/green.png":"./img/white.png";document.clearing_lever_expand.src=
par2==1?"./img/green.png":"./img/white.png";clearing_allowed=par2==1;if(clearing_allowed){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]"}else{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(par1=="ClearingAD_ActiveOut")document.clearing_action_results.src=par2==1?"./img/green.png":"./img/white.png";if(par1=="ClearingTC_ActiveOut")document.clearing_action_tc.src=par2==1?"./img/green.png":"./img/white.png";if(par1=="Clearing_Set_Active")document.clearing_action_set.src=par2==1?"./img/green.png":"./img/white.png";if(par1=="offsetCur_changed"){document.car_pos_1.src=par2==0?"./img/green.png":"./img/white.png";
document.car_pos_2.src=par2==1?"./img/green.png":"./img/white.png";document.car_pos_3.src=par2==2?"./img/green.png":"./img/white.png";document.car_pos_4.src=par2==3?"./img/green.png":"./img/white.png";document.car_pos_5.src=par2==4?"./img/green.png":"./img/white.png";document.car_pos_6.src=par2==5?"./img/green.png":"./img/white.png"}if(par1=="machineReadyBusy"){document.machine_ready.src=par2==1?"./img/green.png":"./img/white.png";if(state!=0)if(par2==1){state=2;update_keyboard(key_ena_state_2);show_on_7_segm("busy   ")}else{state=
3;update_keyboard(key_ena_state_3);s="0";show_on_7_segm(s,state)}}if(par1=="setReq_done")if(state==6){state=7;s="0";show_on_7_segm(s,state);update_keyboard(key_ena_state_7)}if(par1=="time_mul_done")state=11;if(par1=="time_crank_done")if(state==10)display_tmp_result(par2);if(par1=="skyColor_changed_final");if(par1=="skyColor_changed_int"){i=parseInt(par2);str=i.toString(16);while(str.length<6)str="0"+str;str="#"+str;set_web_page_color(str)}if(par1=="fog_On")document.fog_toggle.src=par2==0?"./img/white.png":
"./img/green.png";if(par1=="fog_Type"){document.fog_linear.src=par2=="LINEAR"?"./img/green.png":"./img/white.png";document.fog_exponential.src=par2=="EXPONENTIAL"?"./img/green.png":"./img/white.png"}if(par1=="fog_VisRng")document.getElementById("fog_vis_rng").innerHTML="visibility range: "+par2+" [mm]"}
function show_on_7_segm(s,sts){while(s.length<11)s=" "+s;for(i=0;i<11;++i){var ind="0123456789bceprsuy ".indexOf(s.charAt(i));if(ind!=-1)document.getElementById("7segm_"+i).style.left=ind*-18}document.getElementById("status_ind").style.left=-350-state*10}var s="0";var state=0;var key_ena_state_0=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0];var key_ena_state_1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1];var key_ena_state_2=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];var key_ena_state_3=[0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1];
var key_ena_state_4=[1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1];var key_ena_state_5=[0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1];var key_ena_state_6=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];var key_ena_state_7=[0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1];var key_ena_state_8=[1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,1];var key_ena_state_9=[0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1];var key_ena_state_10=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];var key_ena=key_ena_state_0;
function update_keyboard(ar){key_ena=ar;for(k=0;k<ar.length;++k)document.getElementById("k"+k).style.top=key_ena[k]?-36:-100}function key_dn(k){if(key_ena[k])document.getElementById("k"+k).style.top=-68}
function key_up(k){if(key_ena[k])document.getElementById("k"+k).style.top=-36;else return;if(k==15&&state==0){s="press c  ";state=1;update_keyboard(key_ena_state_1);show_on_7_segm(s,state)}if(k==16){s="";state=0;update_keyboard(key_ena_state_0);show_on_7_segm(s,state)}if(k>=0&&k<=9&&state==4){s+=""+k;if(s.length==8){update_keyboard(key_ena_state_5);state=5}show_on_7_segm(s,state)}if(k>=1&&k<=9&&state==3){s=""+k;update_keyboard(key_ena_state_4);show_on_7_segm(s,state);state=4}if(k==11&&(state==4||
state==5)){s="0";show_on_7_segm(s,state);update_keyboard(key_ena_state_3);state=3}if(k==12&&state==4){if(s.length>1)s=s.substring(0,s.length-1);else{s="0";update_keyboard(key_ena_state_3);state=3}show_on_7_segm(s,state)}if(k==12&&state==5){s=s.substring(0,s.length-1);update_keyboard(key_ena_state_4);state=4;show_on_7_segm(s,state)}if(k==10&&(state==4||state==5)){document.CC3D.setNodeEventIn("SEC_SET_AD","setting_from_html",s);document.CC3D.setNodeEventIn("PROG_MUL","m1",s);s="0";state=6;update_keyboard(key_ena_state_6);
show_on_7_segm(s,state)}if(k>=0&&k<=9&&state==8){s+=""+k;if(s.length==6){update_keyboard(key_ena_state_9);state=9}show_on_7_segm(s,state)}if(k>=1&&k<=9&&state==7){s=""+k;update_keyboard(key_ena_state_8);show_on_7_segm(s,state);state=8}if(k==11&&(state==8||state==9)){s="0";show_on_7_segm(s,state);update_keyboard(key_ena_state_7);state=7}if(k==12&&state==8){if(s.length>1)s=s.substring(0,s.length-1);else{s="0";update_keyboard(key_ena_state_7);state=7}show_on_7_segm(s,state)}if(k==12&&state==9){s=s.substring(0,
s.length-1);update_keyboard(key_ena_state_8);state=8;show_on_7_segm(s,state)}if(k==13&&(state==8||state==9)){document.CC3D.setNodeEventIn("PROG_MUL","m2",s);state=10;update_keyboard(key_ena_state_10);show_on_7_segm("0",state)}if(k==14&&state==1)keyboard_2_keys(77,82)}function display_tmp_result(s){s=s.substring(5,16);ix=0;while(s.charAt(ix)=="0"&&ix<10)++ix;s=s.substring(ix,s.length);show_on_7_segm(s,state)}
function createCookie(name,value,days){if(days){var date=new Date;date.setTime(date.getTime()+days*24*60*60*1E3);var expires="; expires="+date.toGMTString()}else var expires="";document.cookie=name+"="+value+expires+"; path=/"}function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(";");for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==" ")c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length)}return null}
function eraseCookie(name){createCookie(name,"",-1)}function restoreFactoryBackground(){eraseCookie("bkg_rgb");eraseCookie("visits");document.CC3D.setNodeEventIn("SCR_INIT_BKG","sky_rgb","0.2 0.3 0.4")}var bkg_rgb;function readCookies(){var visits=readCookie("visits");bkg_rgb=readCookie("bkg_rgb");if(visits){visits=parseInt(visits)+1;text="welcome back<br>visit: "+visits}else{visits=1;text="welcome on your<br>first visit"}document.getElementById("id_visits").innerHTML=text}var bkg_col_sync=false;
var last_str="";function toggle_sync_mode(){document.col_sync.src=(bkg_col_sync=!bkg_col_sync)?"./img/green.png":"./img/white.png";if(bkg_col_sync)set_colors(last_str)}function set_colors(str){for(cell=0;cell<3;++cell)document.all.tags("table")[0].rows[0].cells[cell].style.backgroundColor=str}function set_web_page_color(str){last_str=str;if(bkg_col_sync)set_colors(str)};
