home *** CD-ROM | disk | FTP | other *** search
/ PC User 2004 November / PCU1104CD1.iso / software / security / files / norton.exe / Setup / ISCommon / APP / fwUI.dll / HTML / RULESUMMARY.JS < prev    next >
Encoding:
JavaScript  |  2003-09-06  |  20.2 KB  |  848 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // PRODUCT: Norton Internet Security/Symantec Desktop Firewall
  4. //
  5. // NAME:    RuleSummary.js (Javascript file for RuleSummary.HTM)
  6. //
  7. // Copyright (c) 2001 by Symantec Corporation. All rights reserved.
  8. //
  9. ////////////////////////////////////////////////////////////////////////////////////////////
  10.  
  11. // Global Variables    
  12.  
  13.     var szRuleType = StrID("UnknownB");
  14.     var g_nNumAdminRules = 0;
  15.     var g_IEVer = GetIEVersion();
  16.     var g_htmlappFullPath = null;
  17.     var g_RuleList = null; // List of rules
  18.     var g_NumRules = 0;
  19.     var g_nRulesProcessed = 0;
  20.     var g_bInitialized = false;
  21.     var g_sLocation = "";
  22.  
  23.     var MB_OK = 0;
  24.     var MB_OKCANCEL = 1;
  25.     var IDCANCEL = 2;
  26.     
  27.  
  28. function init()
  29. {
  30.     g_RuleList = window.dialogArguments;
  31.     
  32.     UserManager.WatchForFREIntegStart();
  33.     
  34.     //
  35.     // Setup the list control
  36.     //
  37.     ruleList.SetTableFont("MS Sans Serif", "75%", "", "");
  38.     ruleList.OnClick = ruleList_OnClick;
  39.     ruleList.OnDblClick = ruleList_OnDblClick;
  40.     ruleList.OnSpace = ruleList_OnSpace;
  41.  
  42.     var RLevelStatus = new ActiveXObject("RLevel.NISStatusInfo");    
  43.     var bLAIsOn = RLevelStatus.LocationAwarenessEnabled;
  44.     if(bLAIsOn)
  45.     {
  46.         LocationAwarenessIsOffText.innerText = " ";
  47.         RuleSummary_SELECT_LocationDropDown.style.width = "400px";
  48.     }
  49.  
  50.     //
  51.     // Insert app name if the list comes from an application. Otherwise, show straight text
  52.     //
  53.  
  54.     if(g_RuleList.ApplicationDescription != "")
  55.     {
  56.         g_htmlappFullPath = g_RuleList.ApplicationPath; 
  57.  
  58.         htmlappPath.innerText = Ellipse_Path(30, g_htmlappFullPath);
  59.         htmlappName.innerText = g_RuleList.ApplicationDescription; 
  60.  
  61.         szRuleType = "Application";
  62.         htmlapplistline.style.display = "";
  63.         htmlrulelistline.style.display = "none"; 
  64.  
  65.         htmlHeading.innerText = StrID("AppRuleListTitle");
  66.         document.title = StrID("AppRuleListTitle");
  67.     }
  68.     else
  69.     {
  70.         htmlapplistline.style.display = "none";
  71.         htmlrulelistline.style.display = ""; 
  72.  
  73.         if (g_RuleList.Type == 1)
  74.         {
  75.             htmlHeading.innerText = StrID("TrojanRuleListTitle");
  76.             document.title = StrID("TrojanRuleListTitle");
  77.         }
  78.         else
  79.         {
  80.             htmlHeading.innerText = StrID("SysRuleListTitle");
  81.             document.title = StrID("RuleListMenuTitle");
  82.         }
  83.         
  84.         CancelB.style.display = "none";
  85.     }
  86.  
  87.     // add all locations to the dropdown 
  88.     Location_PopulateDropDown(RuleSummary_SELECT_LocationDropDown);
  89.     
  90.     //select the FilterByLocation
  91.     if (g_RuleList.FilterByLocation != "")
  92.     {
  93.         for (var i=RuleSummary_SELECT_LocationDropDown.length-1; i>=0; i--)
  94.         {
  95.             var oOption = RuleSummary_SELECT_LocationDropDown.options[i];
  96.             var sOption = Location_GetDropDownSelectedItemText(oOption);
  97.             if (sOption == g_RuleList.FilterByLocation)
  98.             {
  99.                 RuleSummary_SELECT_LocationDropDown.selectedIndex = i;
  100.                 break;
  101.             }        
  102.         }
  103.     }
  104.         
  105.     OnLocationDropListChange(RuleSummary_SELECT_LocationDropDown.options[RuleSummary_SELECT_LocationDropDown.selectedIndex]);
  106. }
  107.  
  108. function UserManager_OnFREIntegratorStart()
  109. {
  110.      window.navigate('res://closeme.xyz');
  111. }
  112.  
  113. function OnLocationDropListChange(oSelectedOption)
  114. {
  115.     if(g_bInitialized)
  116.     {
  117.         updateRules();
  118.     }
  119.      
  120.     g_sLocation = Location_GetDropDownSelectedItemText(oSelectedOption);
  121.     g_RuleList.FilterByLocation = g_sLocation;
  122.     g_NumRules = g_RuleList.ItemCount;
  123.  
  124.     // Initialize the list
  125.     g_nRulesProcessed = 0;
  126.     g_nNumAdminRules = 0;
  127.     processRulesForDisplay();
  128.     g_bInitialized = true;
  129. }
  130.  
  131.  
  132.  
  133. function RefreshRules()
  134. {     
  135.     g_RuleList.FilterByLocation = g_sLocation;
  136.  
  137.     // Initialize the list
  138.     g_nRulesProcessed = 0;
  139.     g_nNumAdminRules = 0;
  140.     processRulesForDisplay();
  141.     g_bInitialized = true;
  142. }
  143.  
  144. function Ellipse_Path(nMaxLen, szPath)
  145. {
  146.     var szItems = szPath.split("\\");
  147.     var nItem = 0;
  148.     var nLastStart = 1;
  149.     var szOutput = szPath;
  150.     while(szOutput.length > nMaxLen)
  151.     {
  152.         szOutput = szItems[0];
  153.         szOutput = szOutput + "\\" + "...";
  154.         
  155.         for(nItem = nLastStart; nItem < szItems.length; nItem++)
  156.         {
  157.             szOutput = szOutput + "\\" + szItems[nItem];            
  158.         }
  159.         
  160.         nLastStart++;
  161.     }
  162.     
  163.     return szOutput;
  164. }
  165.  
  166.  
  167. function updateRules()
  168. {
  169.     // Since the user clicked OK, this app is now "CUSTOM",
  170.     // even if the user made NO changes!
  171.     //
  172.     // App rules only!    
  173.     if(g_RuleList.ApplicationDescription != "")
  174.     {        
  175.         g_RuleList.AppAccess = 3; // Set app access to custom
  176.     }
  177.     
  178.     UpdateRulesInUseStatus();
  179.  
  180.     return length;
  181. }
  182.  
  183. function ruleList_OnClick()
  184. {
  185.     //
  186.     // Enable or Disable the Modify, Delete, Up, and Down buttons
  187.     //
  188.     var ncurrSel = ruleList.GetCurSel();
  189.     var bEnable = false;
  190.  
  191.     if (0 > ncurrSel)
  192.         return;    
  193.  
  194.     var rule = g_RuleList.GetItem(ncurrSel);
  195.  
  196.     if(null == rule)
  197.         return;
  198.  
  199.     if(UserManager.CurrentUserType == "UT_SUPERVISOR")
  200.         bEnable = true;
  201.     else if( usingClientRules() && (UserManager.CurrentUserType == "UT_NORMAL") && (rule.Priority == 1) )
  202.         bEnable = true;
  203.  
  204.     EnableButton(Modify, bEnable);
  205.     EnableButton(Remove, bEnable);
  206.     EnableButton(MoveUp, bEnable);
  207.     EnableButton(MoveDown, bEnable);
  208. }
  209.  
  210. function ruleList_OnDblClick()
  211. {
  212.     var ncurrSel = ruleList.GetCurSel();
  213.     var bEnable = false;
  214.  
  215.     if (0 > ncurrSel)
  216.         return;    
  217.  
  218.     var rule = g_RuleList.GetItem(ncurrSel);
  219.  
  220.     if(null == rule)
  221.         return;
  222.  
  223.     if(UserManager.CurrentUserType == "UT_SUPERVISOR")
  224.         bEnable = true;
  225.     else if( usingClientRules() && (UserManager.CurrentUserType == "UT_NORMAL") && (rule.Priority == 1) )
  226.         bEnable = true;
  227.     //
  228.     // Emulate a click on the modify button
  229.     //
  230.     if(bEnable)
  231.     {
  232.         if(!Modify.disabled)
  233.             Modify.click();
  234.     }
  235. }
  236.  
  237. function ruleList_OnSpace(nRow)
  238. {
  239.     var ncurrSel = ruleList.GetCurSel();
  240.     var bEnable = false;
  241.  
  242.     if (0 > ncurrSel)
  243.         return;    
  244.  
  245.     var rule = g_RuleList.GetItem(ncurrSel);
  246.  
  247.     if(null == rule)
  248.         return;
  249.  
  250.     if(UserManager.CurrentUserType == "UT_SUPERVISOR")
  251.         bEnable = true;
  252.     else if( usingClientRules() && (UserManager.CurrentUserType == "UT_NORMAL") && (rule.Priority == 1) )
  253.         bEnable = true;
  254.  
  255.     //
  256.     // Swap the state of the check box for this item
  257.     //
  258.     if(bEnable)
  259.     {
  260.         var CheckBox = ruleList.GetCellPtr(nRow, 0).children[0];
  261.         CheckBox.checked = !CheckBox.checked;
  262.     }
  263. }
  264.  
  265. function LoadingList(bLoading)
  266. {
  267.     RuleSummary_SELECT_LocationDropDown.disabled = bLoading;
  268.  
  269.     if(bLoading)
  270.     {
  271.         ruleListLoading.style.display = "";
  272.         ruleListDIV.style.display = "none";    
  273.         docBody.style.cursor = "wait";
  274.     }
  275.     else
  276.     {
  277.         ruleListLoading.style.display = "none";
  278.         ruleListDIV.style.display = "";        
  279.         docBody.style.cursor = "";
  280.     }
  281. }
  282.  
  283. function processRulesForDisplay(nStep)
  284. {
  285.     if(nStep == null)
  286.         nStep = 0;
  287.  
  288.     switch(nStep)
  289.     {
  290.         case 0:
  291.         {
  292.             OKB.focus();
  293.             LoadingList(true);
  294.  
  295.             //
  296.             // Reset the list control
  297.             //
  298.             ruleList.DeleteAllRows();
  299.             ruleList.SetColumnCount(4);
  300.             ruleList.SetColumnWidth(0, "15px");
  301.  
  302.             if(usingClientRules())
  303.                 ruleList.SetColumnWidth(1, "40px");
  304.             else
  305.                 ruleList.SetColumnWidth(1, "0px");
  306.  
  307.             ruleList.SetColumnWidth(2, "72px");
  308.             ruleList.SetColumnWidth(3, "400px");    // needed for IE4x
  309.  
  310.             //
  311.             // Disable the Modify, Delete, Up, and Down buttons
  312.             //
  313.             EnableButton(Modify, false);
  314.             EnableButton(Remove, false);
  315.             EnableButton(MoveUp, false);
  316.             EnableButton(MoveDown, false);
  317.  
  318.             // Disable these buttons during the load
  319.             EnableButton(Add, false);
  320.             EnableButton(OKB, false);
  321.             EnableButton(CancelB, false);
  322.  
  323.             // DWong 01/15/01 Defect 351342 - Add button text missing // ejp 2003june05 we require ie 5.x now so this is a non-issue
  324.             // innterHTML -> innerHTML
  325.             // Add.innerHTML = szAdd;
  326.             // Modify.innerHTML = szModify;
  327.             // Remove.innerHTML = szRemove;
  328.             // MoveUp.innerHTML = szMoveUp;
  329.             // MoveDown.innerHTML = szMoveDown;
  330.  
  331.             // Set a timer for step 1 (so the screen will redraw)
  332.             g_nTimerID = window.setInterval("processRulesForDisplay(1)", 0);
  333.             break;
  334.         }
  335.         case 1:
  336.         {
  337.             clearInterval(g_nTimerID);
  338.  
  339.             // DWong 01/12/01 Defect 351101 UI locks up on IE4
  340.             // The slowness comes from the table (ruleList) when we insert rows and columns
  341.             // (inserting column for some reason is extremely slow on IE4)
  342.             //
  343.             // The workaround now is to create a timer to display the rules continuously
  344.             // until all is read. In this case the HTML page will display right away
  345.             // with maybe 5 or 10 rules at first, while the timer still adding rules
  346.             // to the list box
  347.             //
  348.             g_nTimerID = window.setInterval("TimerProcessRule()", 1);
  349.             break;
  350.         }
  351.         case 2:
  352.         {
  353.             clearInterval(g_nTimerID);
  354.             LoadingList(false);
  355.             // DWong 01/19/01 Defect 351342 - On IE4 machines repainting the list box
  356.             // (in LoadingList) causes the button text disappear
  357.             // Reset the text explicitly for the buttons (except Add button, which will be
  358.             // set in EnableButton function) but for IE4 case only
  359.             if (g_IEVer < 5)
  360.             {
  361.                 Modify.innerHTML = szModify;
  362.                 Remove.innerHTML = szRemove;
  363.                 MoveUp.innerHTML = szMoveUp;
  364.                 MoveDown.innerHTML = szMoveDown;
  365.             }
  366.             EnableButton(Add, true);
  367.             EnableButton(OKB, true);
  368.             EnableButton(CancelB, true);
  369.             
  370.             OKB.focus();
  371.             break;
  372.         }
  373.     }
  374. }
  375.  
  376. function TimerProcessRule()
  377. {
  378.     // If we are not done processing Admin Rules, continue
  379.     if(g_nRulesProcessed < g_NumRules)
  380.     {
  381.         // display rules 5 at a time, when we are done clear the timer
  382.         for(var nCount = 0; nCount < 5; nCount++)
  383.         {
  384.             var rule;
  385.             if (g_nRulesProcessed == 0) rule = g_RuleList.GetFirst();
  386.             else rule = g_RuleList.GetNext();
  387.  
  388.             if(null != rule)
  389.             {
  390.                 processRuleForDisplay(rule);
  391.                 g_nRulesProcessed++;
  392.  
  393.                 if(rule.Priority == 0)
  394.                     g_nNumAdminRules++;
  395.             }
  396.             else
  397.                 break;
  398.         }
  399.     }
  400.     // Else we're done processing rules, continue initialization of rules list
  401.     else
  402.     {    
  403.         window.clearInterval(g_nTimerID);
  404.  
  405.         // Set a timer for processRulesForDisplay(step 2) (so the screen will redraw)
  406.         g_nTimerID = window.setInterval("processRulesForDisplay(2)", 0);
  407.     }
  408. }
  409.  
  410.  
  411. function processRuleForDisplay(rule, pRow, nRow)
  412. {
  413.     var TextString;
  414.     var direction;
  415.     var action = "";
  416.     var Enabled;
  417.     var checkboxString = "";
  418.  
  419.     if (rule.IsInUseForLocation(g_sLocation))
  420.         Enabled = "checked=yes";
  421.     else
  422.         Enabled = "";
  423.  
  424.  
  425.     TextString = rule.Description;
  426.  
  427.     TextString =  "<B>" + TextString + "<br></B>" + developRuleString(rule);
  428.  
  429.     switch (rule.Direction)
  430.     {
  431.         case 2: // IN
  432.             direction= "FROM"
  433.              break;
  434.         case 1: // OUT
  435.             direction= "TO"
  436.              break;
  437.         case 3: // IN-OUT
  438.             direction= "BETWEEN"
  439.             break;
  440.      }
  441.  
  442.     switch (rule.Action)
  443.     {
  444.         case 2: // Permit
  445.             action = "ALLOW";
  446.             break;
  447.         case 1: // Block
  448.             action = "BLOCK";
  449.             break;
  450.         case 4: // Monitor
  451.             action = "MONITOR";
  452.             break;
  453.     }
  454.  
  455.     if((pRow == null) && (nRow == null))
  456.         pRow = ruleList.InsertRow(-1);
  457.     else if((pRow == null) && (nRow != null))
  458.         pRow = ruleList.InsertRow(nRow);
  459.  
  460.     checkboxString = "<input type=checkbox " + Enabled + " ";
  461.     
  462.     if( usingClientRules() && (rule.Priority == 0) && (UserManager.CurrentUserType != "UT_SUPERVISOR") )
  463.         checkboxString += "disabled";
  464.     
  465.     checkboxString += ">";
  466.  
  467.     ruleList.SetCellTextPtr(pRow, 0, checkboxString);
  468.  
  469.     if(usingClientRules())
  470.     {
  471.         if(rule.Priority == 0)
  472.             ruleList.SetCellTextPtr(pRow, 1, "<font type=bold color=red>Admin</font>");
  473.         else
  474.             ruleList.SetCellTextPtr(pRow, 1, "<font type=bold color=blue>User</font>");
  475.     }
  476.  
  477.     TextToAdd = "<img src=res://fwui.dll//" + action + "_" + direction + "_256" + ".GIF>";
  478.     ruleList.SetCellTextPtr(pRow, 2, TextToAdd);
  479.     TextToAdd = "<div style='margin-top:6;margin-bottom:6'>" + TextString + "</div>";
  480.     ruleList.SetCellTextPtr(pRow, 3, TextToAdd);
  481. }
  482.  
  483.  
  484. function AddB_OnClick()
  485. {
  486.     var newRule = null;
  487.     var rule = new ActiveXObject("ccFWSettg.Rule");    
  488.  
  489.     rule.ApplicationDescription = g_RuleList.ApplicationDescription;
  490.     rule.ApplicationPath = g_RuleList.ApplicationPath;
  491.     rule.Type = g_RuleList.Type;
  492.  
  493.     webWnd.SetIcon2("res://NisRes.dll/105");
  494.     newRule = webWnd.showModalDialog("res://fwui.dll/addRuleWiz.htm", 550, 415, rule);
  495.         
  496.     if (null != newRule)
  497.     {        
  498.         var index = null;
  499.  
  500.         g_RuleList.LastError = 0;
  501.         g_RuleList.AppendItem(newRule);
  502.         
  503.         if(HandleListError(g_RuleList.LastError, 1008, 116))
  504.             return;
  505.             
  506.         if (newRule.IsInUseForLocation(g_sLocation))
  507.         {
  508.             //Update the number of rules. Do not increment, because the new rule might have been merged.    
  509.             g_NumRules = g_RuleList.ItemCount;
  510.             RefreshRules();
  511.         }
  512.     }
  513. }
  514.  
  515. function ModifyB_OnClick()
  516. {
  517.     var ncurrSel = ruleList.GetCurSel();
  518.     if (0 > ncurrSel)
  519.         return;
  520.  
  521.     var rule = g_RuleList.GetItem(ncurrSel);
  522.  
  523.     if(null != rule)
  524.     {
  525.         var oldPriority = rule.Priority;
  526.     
  527.         var ruleCopy = new ActiveXObject("ccFWSettg.Rule");
  528.         ruleCopy.CopyFrom(rule);
  529.  
  530.         ruleCopy.ApplicationDescription = g_RuleList.ApplicationDescription;
  531.  
  532.         webWnd.SetIcon2("res://NisRes.dll/105");
  533.         ruleCopy = webWnd.showModalDialog("res://fwui.dll/modifyRule.htm", 550, 468, ruleCopy);
  534.  
  535.         if (null != ruleCopy)
  536.         {    
  537.             ruleCopy.ClearLocations();
  538.             ruleCopy.AddToLocation( g_sLocation );  
  539.         
  540.             if(ruleCopy.Priority == oldPriority)
  541.             {
  542.                 ruleList.DeleteRow(ncurrSel);
  543.             
  544.                 g_RuleList.LastError = 0;
  545.                 
  546.                 g_RuleList.InsertItem(rule, ruleCopy);
  547.                 
  548.                 if(HandleListError(g_RuleList.LastError, 1008, 116))
  549.                     return;         
  550.  
  551.                 g_RuleList.DeleteItem(rule);    
  552.  
  553.                 processRuleForDisplay(ruleCopy, null, ncurrSel);
  554.             }
  555.             else
  556.             {
  557.                 ruleList.DeleteRow(ncurrSel);
  558.  
  559.                 var index = null;
  560.  
  561.                 if(ruleCopy.Priority == 0)
  562.                 {
  563.                     index = g_nNumAdminRules;
  564.                     g_nNumAdminRules++;
  565.                 }
  566.                 else
  567.                 {
  568.                     g_nNumAdminRules--;
  569.                 }                                
  570.  
  571.                 g_RuleList.LastError = 0;
  572.                 g_RuleList.AppendItem(ruleCopy);
  573.                 if(HandleListError(g_RuleList.LastError, 1008, 117))
  574.                     return;
  575.                 g_RuleList.DeleteItem(rule);    
  576.  
  577.                 processRuleForDisplay(ruleCopy, null, index);                                
  578.             }
  579.  
  580.             ruleList.SetCurSel(ncurrSel);
  581.         }
  582.     }
  583. }
  584.  
  585.  
  586. function RemoveB_OnClick()
  587. {
  588.     var ncurrSel = ruleList.GetCurSel();
  589.  
  590.     if (0 > ncurrSel)
  591.         return;
  592.  
  593.     //
  594.     // Ensure any updates to rules in UI are made to data before move.
  595.     //
  596.     updateRules();
  597.  
  598.     // Delete the rule from the rule list object
  599.     var rule = g_RuleList.GetItem(ncurrSel);
  600.  
  601.     if(null != rule)
  602.     {
  603.         webWnd.SetIcon2("res://NisRes.dll/105");
  604.     
  605.         if(webWnd.MsgBox(StrID("DeleteRulePrompt"), UserManager.ProductName, MB_OKCANCEL) == IDOK)
  606.         {
  607.             if(rule.Priority == 0)
  608.                 g_nNumAdminRules--;
  609.  
  610.             var nLocations = rule.NumLocations;
  611.             if (nLocations == 1 ||
  612.                     webWnd.MsgBox(StrID("RemoveRuleFromAllLocations?"), UserManager.ProductName, MB_YESNO) == IDNO)
  613.             {
  614.                 g_RuleList.DeleteItem(rule);
  615.             }
  616.             else 
  617.                 g_RuleList.DeleteItemFromAllLocations(rule);
  618.     
  619.             ruleList.DeleteRow(ncurrSel);
  620.             g_NumRules--;
  621.             
  622.             if (ruleList.GetRowCount() <= ncurrSel)
  623.                 ncurrSel = ruleList.GetRowCount()-1;
  624.  
  625.             ruleList.SetCurSel(ncurrSel);
  626.         }
  627.     }
  628. }
  629.  
  630.  
  631. function MoveUpB_OnClick()
  632. {
  633.     var ncurrSel = ruleList.GetCurSel();
  634.  
  635.     if(ncurrSel == 0)
  636.         return;    
  637.  
  638.     //
  639.     // Ensure any updates to rules in UI are made to data before move.
  640.     //
  641.     updateRules();
  642.  
  643.     var rule = g_RuleList.GetItem(ncurrSel);
  644.     var ruleBefore = g_RuleList.GetItem(ncurrSel - 1);
  645.     
  646.     var newRule = new ActiveXObject("CcFWSettg.Rule");
  647.     newRule.CopyFrom(rule);
  648.     newRule.ClearLocations();
  649.     newRule.AddToLocation(g_sLocation);
  650.     
  651.     // Swap the rules in the RuleList Object
  652.     if(rule.Priority == 0)
  653.     {
  654.         g_RuleList.LastError = 0;
  655.         g_RuleList.InsertItem(ruleBefore, newRule);
  656.         if(HandleListError(g_RuleList.LastError, 1008, 121))
  657.             return;
  658.         g_RuleList.DeleteItem(rule);
  659.     }
  660.     else
  661.     {
  662.         if(ruleBefore.Priority == 0)
  663.             return;
  664.         else
  665.         {
  666.             g_RuleList.LastError = 0;
  667.             g_RuleList.InsertItem(ruleBefore, newRule);
  668.             if(HandleListError(g_RuleList.LastError, 1008, 122))
  669.                 return;
  670.             g_RuleList.DeleteItem(rule);
  671.         }
  672.     }
  673.     
  674.     ruleList.SwapRow(ncurrSel, false);
  675.     
  676.     ruleList.SetCurSel(ncurrSel-1);
  677.     var row = ruleList.GetCurSelPtr();
  678.  
  679.     var oElement = row.offsetParent;
  680.     var iOffsetTop = row.offsetTop;
  681.     var iListTop = oElement.parentElement.scrollTop;
  682.  
  683.     if (iOffsetTop < iListTop)
  684.         row.scrollIntoView(true);
  685. }
  686.  
  687. function MoveDownB_OnClick()
  688. {
  689.     var ncurrSel = ruleList.GetCurSel();
  690.  
  691.     // If it's the last rule then do nothing
  692.     if(ncurrSel == (g_NumRules - 1))
  693.         return;    
  694.  
  695.     //
  696.     // Ensure any updates to rules in UI are made to data before move.
  697.     //
  698.     updateRules();
  699.  
  700.     var rule = g_RuleList.GetItem(ncurrSel);
  701.     var ruleNext = g_RuleList.GetItem(ncurrSel + 1);
  702.     var ruleBefore = null;
  703.     
  704.     if((ncurrSel+2) < g_NumRules)
  705.         ruleBefore = g_RuleList.GetItem(ncurrSel + 2);
  706.         
  707.     var newRule = new ActiveXObject("CcFWSettg.Rule");
  708.     newRule.CopyFrom(rule);
  709.     newRule.ClearLocations();
  710.     newRule.AddToLocation(g_sLocation);
  711.     
  712.     // Swap the rules in the RuleList Object
  713.     if(rule.Priority == 0)
  714.     {
  715.         if((null != ruleNext) && (ruleNext.Priority == 1))
  716.             return;
  717.  
  718.         g_RuleList.LastError = 0;
  719.         if(null != ruleBefore)
  720.             g_RuleList.InsertItem(ruleBefore, newRule);
  721.         else
  722.             g_RuleList.AppendItem(newRule);
  723.  
  724.         if(HandleListError(g_RuleList.LastError, 1008, 124))
  725.             return;
  726.  
  727.         g_RuleList.DeleteItem(rule);
  728.     }
  729.     else
  730.     {    
  731.         g_RuleList.LastError = 0;
  732.         if(null != ruleBefore)
  733.             g_RuleList.InsertItem(ruleBefore, newRule);
  734.         else
  735.             g_RuleList.AppendItem(newRule);
  736.             
  737.         if(HandleListError(g_RuleList.LastError, 1008, 125))
  738.             return;
  739.     
  740.         g_RuleList.DeleteItem(rule);
  741.     }
  742.  
  743.     ruleList.SwapRow(ncurrSel, true);
  744.     
  745.     ruleList.SetCurSel(ncurrSel+1);
  746.     var row = ruleList.GetCurSelPtr();
  747.  
  748.     var oElement = row.offsetParent;
  749.     var iOffsetTop = row.offsetTop + row.offsetHeight;
  750.     var iListTop = oElement.parentElement.scrollTop;
  751.     var iBottom  = oElement.parentElement.offsetHeight + iListTop;
  752.  
  753.     // if bottom of row is below window, scroll.
  754.     if (iOffsetTop >= iBottom)
  755.         row.scrollIntoView(false);
  756.  
  757. }
  758.  
  759. // confirm that the rule list is empty and the user wants to
  760. // erase this application
  761.  
  762. function confirm_empty()
  763. {
  764.     return (webWnd.MsgBox(StrID("RuleSumNoRules"), StrID("RuleSumNoRulesTitle"), 1) == 1);
  765. }
  766.  
  767. function OKB_OnClick()
  768. {
  769.     //
  770.     // Before we leave, determine if there are no rules left (for application rules only).
  771.     // If so, we prompt the user to be sure this is what they meant and to let them know
  772.     // that the application entry will go away.
  773.     //
  774.     var n = updateRules();
  775.  
  776.     //
  777.     // Only if the user agreed (or there's no problem), do we save and exit.
  778.     //
  779.     if (("" == g_RuleList.ApplicationDescription) || (n != 0) || confirm_empty())
  780.     {
  781.         window.returnValue = g_RuleList;
  782.         window.navigate('res://closeme.xyz');
  783.     }
  784. }
  785.  
  786. function CancelB_OnClickOrReset()
  787. {
  788.     window.navigate('res://closeme.xyz');
  789. }
  790.  
  791.  
  792. function UpdateRulesInUseStatus()
  793. {
  794.     g_RuleList.FilterByLocation = g_sLocation;
  795.     var nElem = -1;
  796.     
  797.     for (var rule = g_RuleList.GetFirst(); rule != null; rule = g_RuleList.GetNext())
  798.     {
  799.         nElem++;
  800.         var bChanged = false;
  801.         //
  802.         // If the user checked this rule (via the nested child INPUT tag), enable it.
  803.         // Otherwise, disable it.
  804.         //
  805.         var newRule = new ActiveXObject("ccFWSettg.Rule");
  806.         
  807.         newRule.CopyFrom(rule);
  808.         newRule.ClearLocations();
  809.         newRule.AddToLocation(g_sLocation);        
  810.         
  811.         if (null == rule)
  812.             continue;
  813.  
  814.         if (ruleList.GetCellPtr(nElem, 0).children[0].checked)
  815.         {
  816.             if(rule.IsInUseForLocation(g_sLocation) == false)
  817.             {
  818.                 bChanged    = true;                
  819.             }
  820.             newRule.ClearInUseLocations();
  821.             newRule.AddInUseLocation(g_sLocation);
  822.         }
  823.         else
  824.         {
  825.             if(rule.IsInUseForLocation(g_sLocation) == true)
  826.             {
  827.                 bChanged    = true;
  828.             }
  829.             
  830.             newRule.ClearInUseLocations();
  831.             newRule.RemoveInUseLocation(g_sLocation);
  832.         }
  833.  
  834. // Fix for defect# 394925
  835. // This is how you write the settings back to the driver
  836.         if(bChanged==true)
  837.         {
  838.             g_RuleList.LastError = 0;
  839.             g_RuleList.InsertItem(rule, newRule);
  840.             if(HandleListError(g_RuleList.LastError, 1008, 128))
  841.                 break;      
  842.  
  843.             g_RuleList.DeleteItem(rule);    
  844.         }
  845.     }
  846. }
  847.  
  848.