home *** CD-ROM | disk | FTP | other *** search
/ Chip 2009 November / Chip_2009.11_CD.iso / Chip_WPI / WPIScripts / check.js < prev    next >
Encoding:
JavaScript  |  2006-11-20  |  9.8 KB  |  624 lines

  1. //
  2. // Date Last Modified: August 27, 2006
  3. //
  4. // Modified By: Mark Ritter (mritter)
  5. //
  6.  
  7.  
  8. function isChecked(i)
  9. {
  10.     position="check.js";
  11.     whatfunc="isChecked()";
  12.  
  13.     var elem;
  14.     
  15.     if (isCategory(i))
  16.         elem = document.getElementById("Cat"+i);
  17.     else
  18.         elem = document.getElementById("chkbox"+i);
  19.  
  20.     if (elem==null) 
  21.         return false;
  22.  
  23.     if (elem.checked) 
  24.         return true;
  25.     else 
  26.         return false;
  27. }
  28.  
  29.  
  30. function isCategory(i) 
  31. {
  32.     position="check.js";
  33.     whatfunc="isCategory()";
  34.  
  35.     var numbers = " 0123456789.";
  36.     var isString = false;
  37.     var j, char;
  38.  
  39.     if (typeof(i) == "number")
  40.         return false;
  41.  
  42.     for (j=0; j<i.length && !isString; j++) 
  43.     { 
  44.         char = i.charAt(j); 
  45.         if (numbers.indexOf(char) == -1)
  46.             isString = true;
  47.     }
  48.  
  49.     return isString;
  50. }
  51.  
  52.     
  53. function setEnabled(i)
  54. {
  55.     position="check.js";
  56.     whatfunc="setEnabled()";
  57.  
  58.     var elem = document.getElementById("chkbox"+i);
  59.  
  60.     if (elem==null) 
  61.         return;
  62.     if (deps[i] && DisableOnDepsNotMet && !parentsAreChecked(i)) 
  63.         return;
  64.     if (excludorIsChecked(i)) 
  65.         return;
  66.     elem.disabled=false;
  67.     tabs++; 
  68.     enableChildren(i); 
  69.     tabs--;
  70. }
  71.  
  72.  
  73. function setDisabled(i)
  74. {
  75.     position="check.js";
  76.     whatfunc="setDisabled()";
  77.  
  78.     var elem = document.getElementById("chkbox"+i);
  79.  
  80.     if (elem==null) 
  81.         return;
  82.     elem.disabled=true;
  83.     tabs++;    
  84.     disableChildren(i);
  85.     tabs--;
  86. }
  87.  
  88.  
  89. function setChecked(i)
  90. {
  91.     position="check.js";
  92.     whatfunc="setChecked()";
  93.  
  94.     var elem;
  95.  
  96.     if (isCategory(i))
  97.     {
  98.         elem = document.getElementById("Cat"+i);
  99.  
  100.         if (elem==null) 
  101.             return;
  102.         if (elem.disabled) 
  103.             return;
  104.         elem.checked=true;
  105.     }
  106.     else 
  107.     {
  108.         var chkbox = document.getElementById("chkbox"+i);
  109.         var lbl = document.getElementById('lbl'+i);
  110.  
  111.         if (chkbox==null) 
  112.             return;
  113.         if (chkbox.disabled)
  114.             return;
  115.         chkbox.checked=true;
  116.         if (lbl.value != "IsGray")
  117.             lbl.className='chktxt';
  118.         else
  119.             lbl.className='gtxt';
  120.         tabs++;
  121.         checkParent(i);
  122.         if (DisableOnDepsNotMet) 
  123.             enableChildren(i); 
  124.         if (useExclusions) 
  125.             checkExclusions(i);
  126.         tabs--;
  127.     }
  128. }
  129.  
  130.  
  131. function setUnchecked(i)
  132. {
  133.     position="check.js";
  134.     whatfunc="setUnchecked()";
  135.  
  136.     var elem;
  137.     
  138.     if (isCategory(i))
  139.     {
  140.         elem = document.getElementById("Cat"+i);
  141.  
  142.         if (elem==null) 
  143.             return;
  144.         elem.checked=false;
  145.     }
  146.     else 
  147.     {
  148.         var chkbox = document.getElementById("chkbox"+i);
  149.         var lbl = document.getElementById('lbl'+i);
  150.  
  151.         if (chkbox==null) 
  152.             return;
  153.         if (forc[i]!=null && forc[i]=='yes')
  154.             return;
  155.         chkbox.checked=false;
  156.         if (lbl.value != "IsGray")
  157.             lbl.className='txt';
  158.         else
  159.             lbl.className='gtxt';
  160.         tabs++;
  161.         uncheckChildren(i);
  162.         if (DisableOnDepsNotMet) 
  163.             disableChildren(i);
  164.         if (useExclusions) 
  165.             checkExclusions(i);
  166.         tabs--;
  167.     }
  168. }
  169.  
  170.  
  171. function toggleChecked(i)
  172. {
  173.     position="check.js";
  174.     whatfunc="toggleChecked()";
  175.  
  176.     var elem;
  177.     
  178.     if (isCategory(i))
  179.         elem = document.getElementById("Cat"+i);
  180.     else
  181.         elem = document.getElementById("chkbox"+i);
  182.  
  183.     if (elem==null) 
  184.         return;
  185.     if (elem.disabled) 
  186.         return;
  187.  
  188.     if (elem.checked) 
  189.         setUnchecked(i);
  190.     else 
  191.         setChecked(i);
  192. }
  193.  
  194.  
  195. function check(se)
  196. {
  197.     position="check.js";
  198.     whatfunc="check()";
  199.  
  200.     var elem, i, DoGray;
  201.  
  202.     tabs=0;
  203.     tabs++;
  204.     for (i=1; prog[i] != null; i++)
  205.     {
  206.         elem = document.getElementById("chkbox"+i);
  207.         if (elem==null) 
  208.             continue;
  209.         if (elem.disabled) 
  210.             continue;
  211.  
  212.         tabs++;
  213.         if (se != "none")
  214.         {
  215.             if (configs[i][0].indexOf(se) != -1)
  216.             {
  217.                 setChecked(i);    
  218.                 checkDeps(i);
  219.             }
  220.             else 
  221.                 setUnchecked(i);
  222.             if (forc[i] != null && forc[i] == "yes")
  223.             {
  224.                 setChecked(i); 
  225.                 checkDeps(i);
  226.             }
  227.         }
  228.             
  229.         if (se=="all") 
  230.         {
  231.             setChecked(i); 
  232.             checkDeps(i); 
  233.         }
  234.         if (se=="none") 
  235.             setUnchecked(i);
  236.         if (se=="default") 
  237.         {
  238.             if (dflt[i] && dflt[i][0]=='yes') 
  239.             {
  240.                 DoGray=0;
  241.                 if (gcond[i] && gcond[i][0]) 
  242.                 {
  243.                     var d = unescape(ReplacePath(gcond[i][0]).replace(/\\/g, "\\\\"));
  244.  
  245.                     DoGray = eval(d) ? 1 : 0;
  246.                     if (DoGray)
  247.                         setUnchecked(i);
  248.                     else 
  249.                     {
  250.                         setChecked(i); 
  251.                         checkDeps(i);
  252.                     }
  253.                 } 
  254.                 else 
  255.                 {
  256.                     setChecked(i); 
  257.                     checkDeps(i);
  258.                 }
  259.             } 
  260.             else 
  261.                 setUnchecked(i);
  262.         }
  263.         tabs--;
  264.     }    
  265.     tabs--;
  266.     initialization = false;
  267.  
  268.     CheckCatIfAllChecked();
  269. }
  270.  
  271.  
  272. function remChecks()
  273. {
  274.     position="check.js";
  275.     whatfunc="remChecks()";
  276.  
  277.     var i, elem;
  278.  
  279.     for (i=1; prog[i] != null; i++)
  280.     {
  281.         elem=document.getElementById("chkbox"+i);
  282.         if (elem==null || forc[i]=="yes") 
  283.             continue;
  284.  
  285.         elem.checked=false;
  286.     }
  287. }
  288.  
  289.  
  290. function checkDeps(i)
  291. {
  292.     position="check.js";
  293.     whatfunc="checkDeps()";
  294.  
  295.     var elem;
  296.     
  297.     tabs++;
  298.  
  299.     elem=document.getElementById("chkbox"+i);
  300.  
  301.     if (elem==null) 
  302.         return;
  303.     if (elem.disabled)
  304.     {
  305.         if (forc[i] != null && forc[i]=='yes')
  306.             return; 
  307.         elem.checked=false; 
  308.         return 0; 
  309.     }
  310.     
  311.     rekArray = [];
  312.     if (elem.checked) 
  313.         setChecked(i,rekArray);
  314.     else 
  315.         setUnchecked(i,rekArray);
  316.     rekArray = [];
  317.     tabs--;
  318. }
  319.  
  320.  
  321. function checkParent(i)
  322. {
  323.     position="check.js";
  324.     whatfunc="checkParent()";
  325.  
  326.     var j, k, DoGray;
  327.  
  328.     if (!uid[i]) 
  329.         return;
  330.  
  331.     tabs++;    
  332.     if (deps[i] != null)
  333.     {
  334.         for (j=0; deps[i][j] != null; j++)
  335.         {
  336.             k = 1;    
  337.             while (prog[k] != null && (uid[k]==null || uid[k] != deps[i][j])) 
  338.                 k++;
  339.             
  340.             if (prog[k] != null) 
  341.             {
  342.                 DoGray=0;
  343.                 if (gcond[k] && gcond[k][0]) 
  344.                 {
  345.                     var d = unescape(ReplacePath(gcond[k][0]).replace(/\\/g, "\\\\"));
  346.  
  347.                     DoGray = eval(d) ? 1 : 0;
  348.                     if (DoGray) 
  349.                         continue; // do nothing... dependency is already installed
  350.                     else 
  351.                         setChecked(k);
  352.               } 
  353.               else 
  354.                   setChecked(k);
  355.             }
  356.         }
  357.     }
  358.     tabs--;
  359. }
  360.  
  361.  
  362. function uncheckChildren(i)
  363. {
  364.     position="check.js";
  365.     whatfunc="uncheckChildren()";
  366.  
  367.     var j, k;    
  368.  
  369.     if (!uid[i]) 
  370.         return;
  371.  
  372.     tabs++;
  373.     for (j=1; prog[j] != null; j++) //run through all progs
  374.     {
  375.         for (k=0; deps[j] != null && deps[j][k] != null; k++) //run through 'parent' defines
  376.         {
  377.             if (deps[j][k]==uid[i])
  378.                 setUnchecked(j);
  379.         }
  380.     }
  381.     tabs--;
  382. }
  383.  
  384.  
  385. function enableChildren(i)
  386. {
  387.     position="check.js";
  388.     whatfunc="enableChildren()";
  389.  
  390.     var j, k;    
  391.  
  392.     if (!uid[i]) 
  393.         return;
  394.  
  395.     tabs++;
  396.     for (j=1; prog[j] != null; j++) //run through all progs
  397.     {
  398.         for (k=0; deps[j] != null && deps[j][k] != null; k++) //run through 'parent' defines
  399.         {
  400.             if (deps[j][k]==uid[i] && parentsAreChecked(j))
  401.                 setEnabled(j);
  402.         }
  403.     }
  404.     tabs--;
  405. }
  406.  
  407.  
  408. function parentsAreChecked(i) 
  409. {
  410.     position="check.js";
  411.     whatfunc="parseAreChecked()";
  412.  
  413.     var j, k;
  414.     
  415.     for (j=0; deps[i] && j<deps[i].length; j++) //run through all dependencies of prog[i]
  416.     {
  417.         //find parent's checkbox
  418.         var elem = eval("document.all." +deps[i][j]);
  419.  
  420.         if (!elem.checked || elem.disabled) 
  421.             return false;
  422.     }
  423.  
  424.     return true;
  425. }
  426.  
  427.  
  428. function parentsAreEnabled(i) 
  429. {
  430.     position="check.js";
  431.     whatfunc="parentsAreEnabled()";
  432.  
  433.     var j, k;
  434.     
  435.     for (j=0; deps[i] && j<deps[i].length; j++) //run through all dependencies of prog[i]
  436.     {
  437.         //find parent's checkbox
  438.         var elem = eval("document.all." +deps[i][j]);
  439.  
  440.         if (elem.disabled) 
  441.             return false;
  442.     }
  443.  
  444.     return true;
  445. }
  446.  
  447.  
  448. function excludorIsChecked(i) 
  449. {
  450.     position="check.js";
  451.     whatfunc="excludorIsChecked()";
  452.  
  453.     var j, k;
  454.     
  455.     for (j=1; prog[j]; j++) //run through all progs
  456.     {
  457.         for (k=0; excl[j] && k<excl[j].length; k++) //run through all exclusions of prog[j]
  458.         {
  459.             if (uid[i] && uid[i]==excl[j][k])
  460.             {
  461.                 //find parent's checkbox
  462.                 var elem = document.getElementById("chkbox"+j);
  463.  
  464.                 if (elem.checked) 
  465.                     return true;
  466.             }
  467.         }
  468.     }
  469.  
  470.     return false;
  471. }
  472.  
  473.  
  474. function disableChildren(i)
  475. {
  476.     position="check.js";
  477.     whatfunc="disableChildren()";
  478.  
  479.     var j, k;
  480.  
  481.     if (!uid[i]) 
  482.         return;
  483.  
  484.     tabs++;
  485.     for (j=1; prog[j]; j++) //run through all progs
  486.     {
  487.         for (k=0; deps[j] && deps[j][k]; k++) //run through 'parent' defines
  488.         {
  489.             if (deps[j][k]==uid[i])
  490.                 setDisabled(j);
  491.         }
  492.     }
  493.     tabs--;
  494. }
  495.  
  496.  
  497. function checkExclusions(i)
  498. {
  499.     position="check.js";
  500.     whatfunc="checkExclusions()";
  501.  
  502.     var n, k;
  503.     var nArray = new Array();
  504.     var elem = document.getElementById("chkbox"+i);
  505.  
  506.     if (elem==null) 
  507.         return;  
  508.     if (!excl[i]) 
  509.         return;
  510.     tabs++;  
  511.  
  512.     for (k=0; k<rekArray.length; k++)
  513.     {
  514.         if (rekArray[k]==i) 
  515.             return;
  516.     }
  517.     
  518.     rekArray.push(i);
  519.  
  520.     if (elem.checked) // ... disable excluded programs
  521.     {                           
  522.         for (n=0; excl[i][n]; n++)
  523.         {     
  524.             tabs++;
  525.             k = findProgByUID(excl[i][n]);
  526.             if (k<=0) 
  527.                 continue;
  528.             setUnchecked(k);  
  529.             setDisabled(k); 
  530.             tabs--;
  531.         }    
  532.     }
  533.     else              // ... enable excluded programs, if possible
  534.     {
  535.         for (n=0; excl[i][n] != null; n++)
  536.         {     
  537.             tabs++;
  538.             k = findProgByUID(excl[i][n]);
  539.             if (k<=0) 
  540.                 continue;   
  541.             setEnabled(k); 
  542.             tabs--;
  543.         }    
  544.         
  545.     }
  546.     tabs--;
  547. }
  548.  
  549.  
  550. function checkCategory(thisChk)
  551. {
  552.     position="check.js";
  553.     whatfunc="checkCategory()";
  554.  
  555.     var allChked = true;
  556.     var state = isChecked(thisChk);    
  557.     var i, thisCat;
  558.     
  559.     if (isCategory(thisChk)) //If category checkbox was checked
  560.     {
  561.         thisCat = thisChk;
  562.         
  563.         for (i=1; cat[i] != null; i++)
  564.         {
  565.             if (cat[i] == thisCat)
  566.             {
  567.                 if (state)
  568.                 {
  569.                     setChecked(i);
  570.                     checkDeps(i);
  571.                 }
  572.                 else 
  573.                 {
  574.                     setUnchecked(i);
  575.                     checkDeps(i);
  576.                 }
  577.             }
  578.         }
  579.     }
  580.     else //If program checkbox was checked
  581.     {
  582.         if (!prog[thisChk]) 
  583.             return; //Ensure checkbox exists
  584.         thisCat = cat[thisChk].toString();
  585.     }
  586.     
  587.     if (state)
  588.     {
  589.         for (i=1; cat[i] != null; i++)
  590.         {
  591.             if (cat[i] == thisCat)
  592.             {
  593.                 if (!isChecked(i))
  594.                 {
  595.                     allChked = false;
  596.                     break;
  597.                 }
  598.             }
  599.         }
  600.     }
  601.  
  602.     if (state && allChked)
  603.         setChecked(thisCat);
  604.     else
  605.         setUnchecked(thisCat);
  606. }
  607.  
  608.  
  609. function findProgByUID(s_uid)
  610. {
  611.     position="check.js";
  612.     whatfunc="findProgByUID()";
  613.  
  614.     var i;
  615.  
  616.     for (i=1; prog[i] != null; i++)
  617.     {
  618.         if (uid[i] && uid[i]==s_uid)
  619.             return i;
  620.     }
  621.  
  622.     return 0;
  623. }
  624.