home *** CD-ROM | disk | FTP | other *** search
/ Beweegwijzer / beweegwijzer.iso / setup / _SETUP.1 / beweegtugenoeg.js < prev    next >
Encoding:
Text File  |  2001-10-18  |  15.3 KB  |  309 lines

  1. var moduleData = new ActiveXObject("Microsoft.XMLDOM");
  2. moduleData.load("data/beweegtugenoeg.xml");
  3. var moduleRoot = moduleData.documentElement;
  4.  
  5. var styleData = new ActiveXObject("Microsoft.XMLDOM");
  6.  
  7. var chosenDag = '';
  8. var chosenDagNum = -1;
  9. var weekNum = 1;
  10. var minMax = new Array(1,52,0,1440,0,1440,0,1440);
  11. var chosenTab = -1;
  12. var stepDotStep = 0;
  13. var stepTexts = new Array('Blader naar de gewenste week. Kies vervolgens een dag.',
  14. 'Kies een bewegingsvorm door ΘΘn van tabbladen aan te klikken. Wilt u de gegevens overnemen van een reeds ingevulde dag, gebruik dan de knoppen <img src="images/btn_copy_0.bmp" width="29" height="10" alt="" border="0" style="position:relative; top:2px"/> en <img src="images/btn_paste_0.bmp" width="29" height="10" alt="" border="0" style="position:relative; top:2px"/> .',
  15. 'Vul het aantal minuten in dat u met een bepaalde intensiteit bewogen heeft. Voor voorbeelden kiest u <img src="images/help_help.gif" width="14" height="14" alt="" border="0" style="position:relative; top:3px"/>. Bent u klaar, kies dan de volgende dag.',
  16. 'U heeft alle dagen van de week ingevuld, kies rechts voor <img src="images/help_ok.gif" width="16" height="16" alt="" border="0" style="position:relative; top:3px"/> om uw weekresultaat te berekenen.');
  17. var stepDotTimer;
  18. var gewicht = parseFloat(parent.userRoot.selectSingleNode("gewicht").text);
  19. var factor1 = 3;
  20. var factor2 = 5.25;
  21. var factor3 = 8;
  22. var cpweek = -1;
  23. var cpdag = '';
  24. var weekResult = false;
  25. var groeneWeken = false; // blijft altijd false
  26.  
  27. function showPage() {
  28.   buildPage();
  29.   parent.goPage = 'beweegtugenoeg.html';
  30.   AppScreen.style.visibility = "visible";
  31.   for (var i=0; i<CountBox.length; i++) {
  32.     CountBox[i].style.visibility = "inherit";
  33.     }
  34.   }
  35.  
  36. function buildPage() {
  37.   stepIt();
  38.   getWeek();
  39.   }
  40.   
  41. function stepIt() {
  42.   for (var i=0; i<StepDot.length; i++) {
  43.     StepDot[i].src = "images/dot_0.gif";
  44.     }
  45.   StepDot[stepDotStep].src = "images/dot_1.gif";
  46.   StepArea.innerHTML = stepTexts[stepDotStep];
  47.   stepDotTimer = window.setTimeout("stopStep()",10000);
  48.   }
  49.  
  50. function stopStep() {
  51.   clearTimeout(stepDotTimer)
  52.   for (var i=0; i<StepDot.length; i++) {
  53.     StepDot[i].src = "images/dot_0.gif";
  54.     }
  55.   }
  56.   
  57. function CountAction(c) {
  58.   theNum = c;
  59.   theValue = parseInt(CountBox[c].value);
  60.   if ((theValue >= minMax[theNum*2]) && (theValue <= minMax[(theNum*2)+1])) {
  61.     CountBox[c].value = parseInt(CountBox[c].value);
  62.     }
  63.   else CountBox[c].value = minMax[theNum*2];
  64.   
  65.   if (theNum == 0) { // week
  66.     weekNum = parseInt(CountBox[0].value);
  67.     
  68.     chosenDag = '';
  69.     chosenDagNum = -1;
  70.     for (var i=0; i<DagBtn.length; i++) {
  71.       DagBtn[i].style.backgroundImage = "url('images/bt_dag_"+DagBtn[i].dag+((DagBtn[i].dag == chosenDag)?"_2":"_0")+".gif')";
  72.       }
  73.     TabArea.style.backgroundImage = "url('images/tab_default.bmp')";
  74.     TabImg.filters.blendTrans.Apply();
  75.     TabImg.src = "images/bck_meettab_default.bmp";
  76.     TabImg.filters.blendTrans.Play();
  77.     chosenTab = -1;
  78.     
  79.     CopyPaste.style.visibility = 'hidden';
  80.     
  81.     getWeek();
  82.     
  83.     stepDotStep = 0;
  84.     stepIt();
  85.     }
  86.   else calculateDag();
  87.   }
  88.  
  89. function calculateDag() {
  90.   if (chosenTab == -1) {
  91.     CountBox[1].value = 0;
  92.     CountBox[2].value = 0;
  93.     CountBox[3].value = 0;  
  94.     return;
  95.     }
  96.  
  97.   gewicht = parseInt(parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']").getAttribute("gewicht"));
  98.     
  99.   r1 = Math.round(parseInt(CountBox[1].value)/60*factor1*gewicht); // laag
  100.   r2 = Math.round(parseInt(CountBox[2].value)/60*factor2*gewicht); // matig
  101.   r3 = Math.round(parseInt(CountBox[3].value)/60*factor3*gewicht); // zwaar
  102.   subtot = r1 + r2 + r3; // totaal van activiteit
  103.   norm = Math.round(30/60*factor2*gewicht);
  104.  
  105.   ResultBox[chosenTab].innerText = subtot;
  106.   ResultBox[chosenTab].subtot = subtot;
  107.   ResultBox[chosenTab].teltot = r2 + r3;
  108.  
  109.   t = parseInt(ResultBox[0].subtot)+parseInt(ResultBox[1].subtot)+parseInt(ResultBox[2].subtot)+parseInt(ResultBox[3].subtot)+parseInt(ResultBox[4].subtot);
  110.   teltot = parseInt(ResultBox[0].teltot)+parseInt(ResultBox[1].teltot)+parseInt(ResultBox[2].teltot)+parseInt(ResultBox[3].teltot)+parseInt(ResultBox[4].teltot);  
  111.  
  112.   DagBox[chosenDagNum].innerText = t;
  113.   if (teltot<norm) {
  114.     DagBox[chosenDagNum].className = 'dagBoxRed';
  115.     result = 'r';
  116.     }
  117.   else if (teltot>=norm) {
  118.     DagBox[chosenDagNum].className = 'dagBoxGreen';
  119.     result = 'g';
  120.     }
  121.  
  122.   if (DagBox[chosenDagNum].innerText != '0') {
  123.     CopyPasteBtn[0].style.visibility = 'inherit';
  124.     CopyPaste.style.visibility = 'inherit';
  125.     }
  126.   else CopyPaste.style.visibility = 'hidden';
  127.   
  128.   if (cpweek != -1) {
  129.     CopyPasteBtn[1].style.visibility = 'inherit';
  130.     CopyPaste.style.visibility = 'inherit';  
  131.     }    
  132.     
  133.   checkWeekComplete();
  134.  
  135.   putResultInDag(CountBox[1].value,CountBox[2].value,CountBox[3].value,t,result,subtot,ResultBox[chosenTab].teltot);  
  136.   }
  137.   
  138. function checkWeekComplete() {
  139.   complete = true;
  140.   for (var i=0; i<7; i++) {
  141.     if (!parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+DagBtn[i].dag+"']")) {
  142.       complete = false;
  143.       break;
  144.       }
  145.     }
  146.   if (complete) {
  147.     WeekBtn.style.visibility = 'inherit';
  148.     stepDotStep = 3;
  149.     stepIt();    
  150.     }
  151.   else WeekBtn.style.visibility = 'hidden';
  152.   }
  153.   
  154. function getWeek() {
  155.   CountBox[1].value = 0;
  156.   CountBox[2].value = 0;
  157.   CountBox[3].value = 0;
  158.   
  159.   ResultBox[0].innerText = '0';
  160.   ResultBox[1].innerText = '0';
  161.   ResultBox[2].innerText = '0';
  162.   ResultBox[3].innerText = '0';
  163.   ResultBox[4].innerText = '0';
  164.   
  165.   for (var i=0; i<7; i++) {
  166.     if (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+DagBox[i].parentElement.dag+"']")) {
  167.       DagBox[i].innerText = parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+DagBox[i].parentElement.dag+"']").getAttribute("totaal");
  168.       DagBox[i].className = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+DagBox[i].parentElement.dag+"']").getAttribute("result")=='g')?'dagBoxGreen':'dagBoxRed';
  169.       }
  170.     else {
  171.       DagBox[i].innerText = '0';
  172.       DagBox[i].className = 'dagBoxNeutral';
  173.       }
  174.     }
  175.   VoorbeeldButtons('hide');
  176.  
  177.   WeekArea.style.visibility = 'hidden';
  178.   WeekResultImg.src = "images/weekresult_oranje.bmp";
  179.   weekResult = false;   
  180.  
  181.   checkWeekComplete();
  182.   }
  183.  
  184. function getDag() {
  185.   if (!parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']")) { // week?
  186.     newWeek = parent.xmlUserData.createElement("week");
  187.     newWeek.setAttribute("num",weekNum);
  188.     parent.userRoot.selectSingleNode("data").appendChild(newWeek);
  189.     }
  190.   if (!parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']")) { // dag?
  191.     newDag = parent.xmlUserData.createElement("dag");
  192.     newDag.setAttribute("naam",chosenDag);
  193.     newDag.setAttribute("totaal","0");
  194.     newDag.setAttribute("result","");
  195.     newDag.setAttribute("gewicht",gewicht);
  196.     parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']").appendChild(newDag);    
  197.     }
  198.     
  199.   CountBox[1].value = 0;
  200.   CountBox[2].value = 0;
  201.   CountBox[3].value = 0;    
  202.   
  203.   ResultBox[0].teltot = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '0']"))?parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '0']").getAttribute("teltot"):'0';  
  204.   ResultBox[0].subtot = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '0']"))?parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '0']").getAttribute("subtot"):'0';
  205.   ResultBox[0].innerText = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '0']"))?Math.round(parseFloat(ResultBox[0].subtot)):'0';
  206.   ResultBox[1].teltot = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '1']"))?parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '1']").getAttribute("teltot"):'0';  
  207.   ResultBox[1].subtot = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '1']"))?parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '1']").getAttribute("subtot"):'0';
  208.   ResultBox[1].innerText = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '1']"))?Math.round(parseFloat(ResultBox[1].subtot)):'0';
  209.   ResultBox[2].teltot = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '2']"))?parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '2']").getAttribute("teltot"):'0';  
  210.   ResultBox[2].subtot = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '2']"))?parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '2']").getAttribute("subtot"):'0';
  211.   ResultBox[2].innerText = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '2']"))?Math.round(parseFloat(ResultBox[2].subtot)):'0';
  212.   ResultBox[3].teltot = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '3']"))?parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '3']").getAttribute("teltot"):'0';  
  213.   ResultBox[3].subtot = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '3']"))?parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '3']").getAttribute("subtot"):'0';
  214.   ResultBox[3].innerText = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '3']"))?Math.round(parseFloat(ResultBox[3].subtot)):'0';
  215.   ResultBox[4].teltot = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '4']"))?parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '4']").getAttribute("teltot"):'0';  
  216.   ResultBox[4].subtot = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '4']"))?parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '4']").getAttribute("subtot"):'0';
  217.   ResultBox[4].innerText = (parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '4']"))?Math.round(parseFloat(ResultBox[4].subtot)):'0';
  218.  
  219.   parent.xmlUserData.save(parent.userDataFileName);
  220.   }
  221.   
  222. function putResultInDag(r1,r2,r3,t,result,subtot,teltot) {
  223.   if (!parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '"+chosenTab+"']")) {
  224.     newAct = parent.xmlUserData.createElement("act");
  225.     newAct.setAttribute("num",chosenTab);
  226.     parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']").appendChild(newAct);
  227.     }
  228.   parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '"+chosenTab+"']").setAttribute("r1",r1);
  229.   parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '"+chosenTab+"']").setAttribute("r2",r2);
  230.   parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '"+chosenTab+"']").setAttribute("r3",r3);
  231.   parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '"+chosenTab+"']").setAttribute("subtot",subtot);
  232.   parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '"+chosenTab+"']").setAttribute("teltot",teltot);  
  233.   parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']").setAttribute("totaal",t);
  234.   parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']").setAttribute("result",result);
  235.   
  236.   parent.xmlUserData.save(parent.userDataFileName);    
  237.   }
  238.   
  239. function getTab() {
  240.   if (!parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '"+chosenTab+"']")) {
  241.     CountBox[1].value = 0;
  242.     CountBox[2].value = 0;
  243.     CountBox[3].value = 0;
  244.     }
  245.   else {
  246.     CountBox[1].value = parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '"+chosenTab+"']").getAttribute("r1");
  247.     CountBox[2].value = parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '"+chosenTab+"']").getAttribute("r2");
  248.     CountBox[3].value = parent.userRoot.selectSingleNode("data/week[@num = '"+weekNum+"']/dag[@naam = '"+chosenDag+"']/act[@num = '"+chosenTab+"']").getAttribute("r3");
  249.     }
  250.   VoorbeeldButtons('show');
  251.   }
  252.   
  253. function VoorbeeldButtons(t) {
  254.   VoorbeeldBtn[0].style.visibility = (t=='hide')?"hidden":"visible";
  255.   VoorbeeldBtn[1].style.visibility = (t=='hide')?"hidden":"visible";
  256.   VoorbeeldBtn[2].style.visibility = (t=='hide')?"hidden":"visible";
  257.   }
  258.   
  259. function buildWeek(t) {
  260.   WeekArea.style.visibility = 'inherit';
  261.   WeekResultImg.filters.blendTrans.Apply();
  262.   if (t<3) theSrc = "images/weekresult_groen.bmp";
  263.   else if (t>3) theSrc = "images/weekresult_rood.bmp";
  264.   else theSrc = "images/weekresult_oranje.bmp";
  265.   WeekResultImg.src = theSrc;
  266.   WeekResultImg.filters.blendTrans.Play();
  267.   
  268.   WeekTitle.innerText = moduleRoot.selectNodes("//result")[t].selectSingleNode("titel").text;
  269.   
  270.   styleRule = '<?xml version="1.0"?>';
  271.   styleRule += '<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">';
  272.   styleRule += '<xsl:template match="/">';
  273.   styleRule += '<xsl:apply-templates select="//result['+t+']/tekst">';
  274.   styleRule += '<xsl:template>';
  275.   styleRule += '<xsl:copy>';
  276.   styleRule += '<xsl:apply-templates select="@* | * | comment() | pi() | text()"/>';
  277.   styleRule += '</xsl:copy>';
  278.   styleRule += '</xsl:template>';
  279.   styleRule += '</xsl:apply-templates>';
  280.   styleRule += '</xsl:template>';
  281.   styleRule += '</xsl:stylesheet>';    
  282.  
  283.   style = new ActiveXObject("Microsoft.XMLDOM");
  284.   style.loadXML(styleRule);  
  285.   
  286.   WeekTekst.innerHTML = moduleData.transformNode(style);  
  287.   }
  288.  
  289. var countTimer;
  290. var counting = false;
  291. var countObj;
  292.   
  293. function RealCount() {
  294.   clearTimeout(countTimer);
  295.   
  296.   theNum = parseInt(countObj.num);
  297.   theFactor = (countObj.factor)?parseInt(countObj.factor):1;
  298.   theValue = parseInt(CountBox[theNum].value);
  299.   if (((countObj.innerText == '-') || (countObj.dirtype == '-')) && ((theValue-theFactor) >= minMax[theNum*2])) {
  300.     theValue -= theFactor;
  301.     }
  302.   else if (((countObj.innerText == '+') || (countObj.dirtype == '+')) && ((theValue-theFactor) <= minMax[(theNum*2)+1])) {
  303.     theValue += theFactor;
  304.     }
  305.   CountBox[theNum].value = theValue;
  306.   CountAction(theNum);
  307.     
  308.   if (counting) countTimer = window.setTimeout('RealCount()',100);
  309.   }