home *** CD-ROM | disk | FTP | other *** search
/ Beweegwijzer / beweegwijzer.iso / setup / _SETUP.1 / profiel.js < prev    next >
Encoding:
Text File  |  2000-09-08  |  9.7 KB  |  255 lines

  1. var activeDd = -1;
  2. var cancelCount = 0;
  3. var ddOpen = false;
  4. var userName = '';
  5. var profielType = 0;
  6. var minMax = new Array(0,120,30,260,10,300);
  7. var qiMode = false;
  8.  
  9. var moduleData = new ActiveXObject("Microsoft.XMLDOM");
  10. moduleData.load("data/profiel.xml");
  11. var moduleRoot = moduleData.documentElement;
  12.  
  13. var xmlUserData = new ActiveXObject("Microsoft.XMLDOM");
  14. xmlUserData.load("data/gebruikers.xml");
  15. var userRoot = xmlUserData.documentElement;
  16.  
  17. function showPage() {
  18.   buildPage();
  19.   AppScreen.style.visibility = "visible";
  20.   NaamBox.style.visibility = "visible";
  21.   }
  22.  
  23. function buildPage() {
  24.   TextArea.innerHTML = moduleRoot.selectSingleNode("text").text;
  25.   
  26.   Geluid[parent.soundSettings].style.textDecoration = 'underline';
  27.   
  28.   if ((userRoot.selectNodes("gebruiker").length > 0) && (parent.userName == '')) {
  29.     // er zijn reeds gebruikers, maar er is nog niet aangelogd
  30.     ddWriteString = '<div id="ddItem" num="0" class="ddShown">...</div>';
  31.     for (var i=0; i<userRoot.selectNodes("gebruiker").length; i++) {
  32.       ddWriteString += '<div id="ddItem" num="' + (i+1) + '" class="ddHidden">' + userRoot.selectNodes("gebruiker")[i].getAttribute("naam") + '</div>';
  33.       }
  34.     dd[0].innerHTML = ddWriteString;
  35.     Indicator[1].style.visibility = 'inherit';
  36.     }
  37.   else if ((userRoot.selectNodes("gebruiker").length > 0) && (parent.userName != '')) {
  38.     // er zijn reeds gebruikers, en er is aangelogd
  39.     ddWriteString = '<div id="ddItem" num="0" class="ddHidden">...</div>';
  40.     for (var i=0; i<userRoot.selectNodes("gebruiker").length; i++) {
  41.       classType = (userRoot.selectNodes("gebruiker")[i].getAttribute("naam") == parent.userName)?'ddShown':'ddHidden';
  42.       ddWriteString += '<div id="ddItem" num="' + (i+1) + '" class="' + classType + '">' + userRoot.selectNodes("gebruiker")[i].getAttribute("naam") + '</div>';
  43.       }
  44.     dd[0].innerHTML = ddWriteString;
  45.     Indicator[1].style.visibility = 'inherit';
  46.     
  47.     Indicator[0].style.backgroundImage = "url('images/indcover.bmp')";
  48.     Indicator[1].style.backgroundImage = "url('images/indicator.bmp')";
  49.     profielType = 1;
  50.     
  51.     userName = parent.userName;
  52.     
  53.     buildSubPage();
  54.     }    
  55.   }
  56.   
  57. function document.onclick() {
  58.   var eSrc = window.event.srcElement;
  59.   if (ddOpen) {
  60.     if (eSrc != dd[activeDd]) {
  61.       cancelCount++;
  62.       if (cancelCount>1) {
  63.         for (var i=0; i<dd[activeDd].childNodes.length; i++) {
  64.           if (dd[activeDd].childNodes[i].innerText != userName) {
  65.             dd[activeDd].childNodes[i].className = 'ddHidden';
  66.             }
  67.           else dd[activeDd].childNodes[i].className = 'ddShown';
  68.           }
  69.         ddOpen = false;
  70.         cancelCount = 0;        
  71.         }
  72.       }
  73.     }
  74.   }
  75.  
  76. function profielTypeChange(n) {
  77.   if (profielType == n) return;
  78.   else profielType = n;
  79.   
  80.   Indicator[2].style.visibility = 'hidden';
  81.   Indicator[3].style.visibility = 'hidden';
  82.   Indicator[4].style.visibility = 'hidden';
  83.   Indicator[5].style.visibility = 'hidden';
  84.   CountBox[0].style.visibility = 'hidden';
  85.   CountBox[1].style.visibility = 'hidden';
  86.   CountBox[2].style.visibility = 'hidden';
  87.   ProfielBtn[0].style.visibility = 'hidden';
  88.   ProfielBtn[1].style.visibility = 'hidden';
  89.   ProfielBtn[2].style.visibility = 'hidden';  
  90.   
  91.   if (n == 0) {
  92.     Indicator[1].style.backgroundImage = "url('images/indcover.bmp')";
  93.     Indicator[0].style.backgroundImage = "url('images/indicator.bmp')";
  94.     for (var i=0; i<dd[0].childNodes.length; i++) {
  95.       dd[0].childNodes[i].className = (i==0)?'ddShown':'ddHidden';
  96.       }
  97.     }
  98.   else {
  99.     Indicator[0].style.backgroundImage = "url('images/indcover.bmp')";
  100.     Indicator[1].style.backgroundImage = "url('images/indicator.bmp')";
  101.     }
  102.   }
  103.  
  104. function NaamAction() {
  105.   if ((userName == '') || (userName == '...')) {
  106.     FbkArea.innerHTML = 'Om een gebruikersprofiel aan te maken dient u een geldige naam in te voeren.<br/><br/>Om een bestaand profiel op te halen dient u een naam te selecteren.';
  107.     return;
  108.     }
  109.   else FbkArea.innerText = '';
  110.   if (profielType == 0) { // nieuw
  111.     parent.emptyProfiel(userName);
  112.     parent.userName = userName;
  113.     buildSubPage();
  114.     }
  115.   else { // bestaand
  116.     parent.getProfiel(userName);
  117.     parent.userName = userName;
  118.     buildSubPage();
  119.     }
  120.   }
  121.   
  122. function CountAction(c) {
  123.   theNum = c;
  124.   theValue = parseInt(CountBox[c].value);
  125.   if ((theValue >= minMax[theNum*2]) && (theValue <= minMax[(theNum*2)+1])) {
  126.     CountBox[c].value = parseInt(CountBox[c].value);
  127.     }
  128.   else CountBox[c].value = minMax[theNum*2];
  129.   }
  130.  
  131. function buildSubPage() {
  132.   if (parent.userRoot.selectSingleNode("geslacht").text == 'm') {
  133.     Sex[0].style.textDecoration = 'underline';
  134.     Sex[1].style.textDecoration = 'none';    
  135.     }
  136.   else if (parent.userRoot.selectSingleNode("geslacht").text == 'v') {
  137.     Sex[0].style.textDecoration = 'none';
  138.     Sex[1].style.textDecoration = 'underline';    
  139.     }
  140.   
  141.   CountBox[0].innerText = parent.userRoot.selectSingleNode("leeftijd").text;
  142.   CountBox[1].innerText = parent.userRoot.selectSingleNode("lengte").text;
  143.   CountBox[2].innerText = parent.userRoot.selectSingleNode("gewicht").text;
  144.  
  145.   Indicator[2].style.visibility = 'inherit';
  146.   Indicator[3].style.visibility = 'inherit';
  147.   Indicator[4].style.visibility = 'inherit';
  148.   Indicator[5].style.visibility = 'inherit';
  149.   CountBox[0].style.visibility = 'inherit';
  150.   CountBox[1].style.visibility = 'inherit';
  151.   CountBox[2].style.visibility = 'inherit';
  152.   
  153.   if (profielType == 0) { // nieuw
  154.     ProfielBtn[0].style.visibility = 'hidden';
  155.     ProfielBtn[1].style.visibility = 'hidden';
  156.     ProfielBtn[2].style.visibility = 'inherit';        
  157.     }
  158.   else { // bestaand
  159.     ProfielBtn[0].style.visibility = 'inherit';
  160.     ProfielBtn[1].style.visibility = 'inherit';
  161.     ProfielBtn[2].style.visibility = 'inherit';
  162.     }  
  163.   }
  164.  
  165. function buildQi() {
  166.   geslacht = (Sex[1].style.textDecoration == 'underline')?'v':'m';
  167.   leeftijd = CountBox[0].value;
  168.   lengte = CountBox[1].value;
  169.   gewicht = CountBox[2].value;
  170.   
  171.   qi = Math.round(10 * (gewicht / Math.pow((lengte/100),2)))/10;
  172.   
  173.   styleRule = '<?xml version="1.0"?>';
  174.   styleRule += '<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">';
  175.   styleRule += '<xsl:template match="/">';
  176.   styleRule += '<xsl:apply-templates select="//inlog/qi">';
  177.   styleRule += '<xsl:template>';
  178.   styleRule += '<xsl:copy>';
  179.   styleRule += '<xsl:apply-templates select="@* | * | comment() | pi() | text()"/>';
  180.   styleRule += '</xsl:copy>';
  181.   styleRule += '</xsl:template>';
  182.   styleRule += '</xsl:apply-templates>';
  183.   styleRule += '</xsl:template>';
  184.   styleRule += '</xsl:stylesheet>';    
  185.  
  186.   style = new ActiveXObject("Microsoft.XMLDOM");
  187.   style.loadXML(styleRule);  
  188.   
  189.   QiArea.innerHTML = moduleData.transformNode(style);
  190.   QiArea.innerHTML += '<p><table width="220" cellpadding="0" cellspacing="0"><tr><td width="160" style="color:#000000">Uw quetelet index is: </td><td>' + qi + '</td></tr></table>';
  191.   
  192.   for (var i=0; i<moduleRoot.selectNodes("fbk").length; i++) {
  193.     minQI = parseFloat(moduleRoot.selectNodes("fbk")[i].getAttribute("min"));
  194.     maxQI = parseFloat(moduleRoot.selectNodes("fbk")[i].getAttribute("max"));
  195.     if ((qi >= minQI) && (qi < maxQI)) {
  196.       QiArea.innerHTML += moduleRoot.selectNodes("fbk")[i].selectNodes("text")[0].text;
  197.       if (moduleRoot.selectNodes("fbk")[i].getAttribute("displaymin") == "true") QiArea.innerHTML += '<p><table width="220" cellpadding="0" cellspacing="0"><tr><td width="160" style="color:#000000">Minimaal gewicht: </td><td>' + Math.round(185 * Math.pow((lengte/100),2))/10 + '</td></tr></table>';
  198.       if (moduleRoot.selectNodes("fbk")[i].getAttribute("displaymax") == "true")QiArea.innerHTML += '<p><table width="220" cellpadding="0" cellspacing="0"><tr><td width="160" style="color:#000000">Maximaal gewicht: </td><td>' + Math.round(249 * Math.pow((lengte/100),2))/10 + '</td></tr></table>';
  199.       if (moduleRoot.selectNodes("fbk")[i].selectNodes("text")[1]) QiArea.innerHTML += moduleRoot.selectNodes("fbk")[i].selectNodes("text")[1].text;
  200.       }
  201.     }
  202.   
  203.   QiArea.style.visibility = 'inherit';
  204.   }
  205.  
  206. function storeData() {
  207.   if (userName == "") return;
  208.   
  209.   if (!userRoot.selectSingleNode("gebruiker[@naam = '" + userName + "']")) { // gebruiker toevoegen
  210.     newUser = xmlUserData.createElement("gebruiker");
  211.     userRoot.appendChild(newUser);
  212.     userRoot.lastChild.setAttribute("naam",userName);
  213.     xmlUserData.save("data/gebruikers.xml");
  214.     }
  215.     
  216.   geslacht = (Sex[1].style.textDecoration == 'underline')?'v':'m';
  217.   leeftijd = CountBox[0].value;
  218.   lengte = CountBox[1].value;
  219.   gewicht = CountBox[2].value;
  220.   
  221.   parent.putProfiel(userName,geslacht,leeftijd,lengte,gewicht);
  222.   }
  223.  
  224. function eraseCurrentUser() {
  225.   for (var i=0; i<userRoot.childNodes.length; i++) {
  226.     if (userRoot.childNodes[i].getAttribute("naam") == userName) {
  227.       userRoot.removeChild(userRoot.childNodes(i));
  228.       }
  229.     }
  230.   xmlUserData.save("data/gebruikers.xml");
  231.   userName = "";
  232.   parent.userName = "";
  233.   }
  234.  
  235. var countTimer;
  236. var counting = false;
  237. var countObj;
  238.   
  239. function RealCount() {
  240.   clearTimeout(countTimer);
  241.   theNum = parseInt(countObj.num);
  242.   theFactor = (countObj.factor)?parseInt(countObj.factor):1;
  243.   theValue = parseInt(CountBox[theNum].value);
  244.   if (((countObj.innerText == '-') || (countObj.dirtype == '-')) && ((theValue-theFactor) >= minMax[theNum*2])) {
  245.     theValue -= theFactor;
  246.     }
  247.   else if (((countObj.innerText == '+') || (countObj.dirtype == '+')) && ((theValue-theFactor) <= minMax[(theNum*2)+1])) {
  248.     theValue += theFactor;
  249.     }
  250.   CountBox[theNum].value = theValue;
  251.   CountAction(theNum);
  252.       
  253.   if (counting) countTimer = window.setTimeout('RealCount()',200);
  254.   }
  255.