home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2002 December / PCpro_2002_12.ISO / browser / netscape7 / nim.xpi / bin / chrome / aim.jar / content / aim / App.js < prev    next >
Encoding:
JavaScript  |  2002-07-03  |  44.1 KB  |  1,396 lines

  1.  
  2.  
  3. // XXX Global to determine if our onload handler has been called yet.
  4. // For some reason, our onunload handler is getting called before onload
  5. // on the first time we create App.xul. This is a workaround.
  6. var gFirstTime = 1;
  7. var timercatch = false;
  8.  
  9. function GoAway( target )
  10. {
  11.     var name = target.getAttribute('MsgText');
  12.     if(name=='')
  13.     {
  14.         try 
  15.         {
  16.           name= document.getElementById('tbAway').getElementsByTagName("menuitem")[1].getAttribute('MsgText')
  17.         }
  18.         catch (e)
  19.         {
  20.             //Some error finding tbAway message-Setting default backup message
  21.             name=aimString("away.DefaultMessage");
  22.         }
  23.     }
  24.  
  25.     locateManager = aimLocateManager();
  26.   if (locateManager)
  27.         locateManager.SetUserInfoAwayMessage(name);
  28. }
  29.  
  30. var targetElement = null;
  31.  
  32. function GoAwayWait(target,wait)
  33. {
  34.     targetElement = target;
  35.     setTimeout('GoAway( targetElement )',wait)
  36. }
  37.  
  38. /*
  39.  * Function: AimAppOnWndLoad()
  40.  *
  41.  * Arguments: None
  42.  * 
  43.  * Return: None
  44.  *
  45.  * Description: Called once app.xul has finished loading.Initializes the
  46.  *        sidebar.
  47. */
  48.  
  49. function AimAppOnWndLoad()
  50. {
  51.   // XXX See note at the top of the file
  52.     gFirstTime = 0;
  53.  
  54.     setTimeout("CheckBuddyPanel()",500);
  55.     
  56.   setAdTimer();
  57.  
  58.   updateCurrentAppWindow();
  59.  
  60.   addAppSessionListener();
  61.  
  62.   setTimeout("aimSession().SetAppIcon()", 1000);
  63.  
  64.  
  65. }
  66.  
  67. /*
  68.  * Function: AimAppOnWndUnload()
  69.  *
  70.  * Arguments: None
  71.  * 
  72.  * Return: None
  73.  *
  74.  * Description: Called once app.xul has been unloaded. 
  75. */
  76.  
  77. function AimAppOnWndUnload()
  78. {
  79.     // XXX See note at the top of the file
  80.  
  81.   if(gFirstTime == 1)
  82.         return;
  83.   removeAppSessionListener();
  84. }
  85.  
  86. //************  Command Handling ****************
  87.  
  88. /*
  89.  * Function: cmdNewBrowser()
  90.  *
  91.  * Arguments: None
  92.  * 
  93.  * Return: None
  94.  *
  95.  * Description: Function invoked from menu or toolbar to create a new 
  96.  *         browser window. 
  97.  * 
  98.  * Bugs: URL is hardcoded. Needs to open a user-specified preference.
  99. */
  100.  
  101. function cmdNewBrowser()
  102. {
  103.     aimCmdNewBrowser("http://home.netscape.com");
  104. }
  105.  
  106. /*
  107.  * Function: cmdNewEmail()
  108.  *
  109.  * Arguments: None
  110.  * 
  111.  * Return: None
  112.  *
  113.  * Description: Function invoked from menu or toolbar to create a new
  114.  *        messenger window. 
  115. */
  116.  
  117. function cmdNewEmail()
  118. {
  119.     aimCmdNewEmail();
  120. }
  121.  
  122.  
  123.  
  124. function cmdNewChat(invScreenName,invProposal,invScreenNames,toExistingWindow,invMode)
  125. {
  126.   if (isIcq() != true )
  127.   {
  128.     //App is aim - in this case shift-ctrl-C which invokes cmdNewchat should bring up chat window
  129.   inviteArgsObj = {
  130.     inviteProposalScreenName: invScreenName, 
  131.     inviteProposalObj: invProposal,
  132.     invitedScreenNames: invScreenNames,
  133.     inviteToExistingWindow: toExistingWindow,
  134.     inviteMode: invMode
  135.   }
  136.   window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  137.   }
  138.   else
  139.   {
  140.    //App is aim - in this case shift-ctrl-C which invokes cmdNewchat should bring up add Contact window.
  141.       cmdAddBuddy();
  142.   }
  143. }
  144.  
  145. /*
  146.  * Function: cmdNewIM()
  147.  *
  148.  * Arguments: None
  149.  * 
  150.  * Return: None
  151.  *
  152.  * Description: Function invoked from menu or toolbar to create a new IM 
  153.  *        window. Loads the window into a pre-connect state, e.g., the 
  154.  *        dialog consists of screen name field and an editor. This
  155.  *        function determines which buddy is selected in the list. 
  156.  *        If a buddy is selected (the first one found) and is online,
  157.  *        the screenname field in the IM window is initialized to that
  158.  *        buddy. Otherwise, the screen name field is set to "".
  159. */
  160.  
  161. function cmdNewIM()
  162. {
  163.   var screenName = getSelectedScreenName();
  164.   if (AimOnlineAway())
  165.     ComeBack();
  166.   if (!aimBuddyIsOnline(screenName))
  167.     screenName = null;
  168.     
  169.   if (screenName != null) {
  170.     var pIAimIM = aimIMObject();
  171.     if (pIAimIM)
  172.       var pWindow = pIAimIM.GetExistingIM(screenName);
  173.     if (pWindow) {
  174.       pWindow.focus();
  175.       return;
  176.     }
  177.   }
  178.   aimIMInvokeIMForm(screenName);
  179. }
  180.  
  181. /*
  182.  * Function: getSelectedBuddiesFromList()
  183.  *
  184.  * Arguments: None
  185.  * 
  186.  * Return: array of strings of buddies
  187.  *     that are currently selected (expands Groups to all buddies in group).
  188.  *
  189.  * Description: Function invoked via cmdNewChatSidebar to poll the
  190.  *        Buddy list to find out which buddies (and expanded groups are selected).
  191.  *        This function will always return an Array.
  192.  *    
  193. */
  194.  
  195. function getSelectedBuddiesFromList()
  196. {
  197.   var tree = getSelectedTreeName();
  198.   var col = getSelectedTabName();
  199.   var selectedBuddies = new Array();
  200.   var selectedGroups = new Array();
  201.   var groupCount = 0;
  202.   var buddyCount = 0;
  203.   if (!tree || !col) return;
  204.   var rangeCount = tree.treeBoxObject.selection.getRangeCount();
  205.   if (rangeCount == 0)
  206.     return null;
  207.   var view = tree.treeBoxObject.view;
  208.   var totalRowCount = view.rowCount;
  209.   for(var i = 0; i < rangeCount; i++) {
  210.     var startIndex = {};
  211.     var endIndex = {};
  212.     tree.treeBoxObject.selection.getRangeAt(i, startIndex, endIndex);
  213.     for (var j = startIndex.value; j <= endIndex.value; j++) {
  214.       var inOffline = IsIndexinSpecialGroup(tree, col, j);
  215.       if (inOffline)
  216.         break;
  217.  
  218.       var level = view.getLevel(j);
  219.       if (level == 0) {
  220.         //ok..a group (not in offline gp) is selected.
  221.         var groupResource = GetBuddyResource(tree, j);
  222.         var groupName = GetBuddyAttribute(tree, groupResource, "Name");
  223.         if (!CheckForDuplicateInArray(selectedGroups, groupName)) {
  224.           // we really don't need this check...but just in case ;-)
  225.           selectedGroups[groupCount++] = groupName;
  226.         }
  227.       }
  228.       else {
  229.         // ok..a buddy is selected. Make sure the group associated with this buddy is not in the selectedGroups list.
  230.         var parentIndex = view.getParentIndex(j);
  231.         var parentResource = GetBuddyResource(tree, parentIndex);
  232.         var parentName = GetBuddyAttribute(tree, parentResource, "Name");
  233.         if (!CheckForDuplicateInArray(selectedGroups, parentName)) {
  234.           var buddyResource = GetBuddyResource(tree, j);
  235.           var buddyName = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  236.           if (!CheckForDuplicateInArray(selectedBuddies, buddyName)) {
  237.             selectedBuddies[buddyCount++] = buddyName;
  238.           }
  239.         }
  240.  
  241.  
  242.       }
  243.     }
  244.   }
  245.  
  246.   //till now we have all the information about the selected buddies and the groups (NOT the buddies underneath
  247.   //the selected groups.
  248.   for (var m=0; m < selectedGroups.length; m++) {
  249.     var viewIndex = GetGroupIndex(tree, col, selectedGroups[m]);
  250.     if (viewIndex < 0) {
  251.       dump("Unable to find the group index for group: " + selectedGroups[m] + "\n");
  252.       return;
  253.     }
  254.  
  255.     //open the group
  256.     if(!view.isContainerOpen(viewIndex))
  257.       view.toggleOpenState(viewIndex);
  258.  
  259.     //get the buddies
  260.     var groupIndex = viewIndex;
  261.     totalRowCount = view.rowCount;
  262.     while ((groupIndex < totalRowCount-1) && (viewIndex == view.getParentIndex(++groupIndex))) {
  263.       var buddyResource1 = GetBuddyResource(tree, groupIndex);
  264.       var buddyName1 = GetBuddyAttribute(tree, buddyResource1, "ScreenName");
  265.       if (!CheckForDuplicateInArray(selectedBuddies, buddyName1))
  266.         selectedBuddies[buddyCount++] = buddyName1;
  267.     } //while
  268.  
  269.   } //for
  270.  
  271.   return selectedBuddies;
  272. }
  273.  
  274. /* For the given parameter, this fn returns the index of the groupName */
  275. function GetGroupIndex(tree, col, groupName)
  276. {
  277.   var view = tree.treeBoxObject.view;
  278.   var totalRowCount = view.rowCount;
  279.   for (var k=0; k<totalRowCount; k++) {
  280.     var level = view.getLevel(k);
  281.     //groups are always at index 0
  282.     if (level == 0) {
  283.       var parentResource = GetBuddyResource(tree, k);
  284.       var cellText = GetBuddyAttribute(tree, parentResource, "Name");
  285.       if (cellText == groupName)
  286.         return k;
  287.     }
  288.   }
  289.   return -1;
  290. }
  291.  
  292. /* Just checks for any duplication in the array */
  293. function CheckForDuplicateInArray(aarray, element)
  294. {
  295.   for (var i=0; i<aarray.length; i++) {
  296.     if (aarray[i] == element)
  297.       return true;
  298.   }
  299.   return false;
  300. }
  301.  
  302. /*Checks for any duplicatation in the name property in an array */
  303. function CheckForDuplicateNameInArray(aarray, element)
  304. {
  305.   for (var i=0; i<aarray.length; i++) {
  306.     if (aarray[i].name == element)
  307.       return true;
  308.   }
  309.   return false;
  310. }
  311.  
  312. /* Checks whether the index is in Special group
  313.    Right now only Special group: Awaiting Authorization
  314.    Maybe later on Offline and Collected buddies will fall under this category ;-)
  315. */
  316.  
  317. function IsIndexinSpecialGroup(tree, col, index)
  318. {
  319.   var offlineIndex = -1;
  320.   var view = tree.treeBoxObject.view;
  321.   var totalRowCount = view.rowCount;
  322.   for (var k=0; k<totalRowCount; k++) {
  323.     var level = view.getLevel(k);
  324.     if (level == 0) {
  325.       var cellText = view.getCellText(k, col);
  326.       if (cellText == aimString("msg.AuthGroup")) {
  327.       
  328.         offlineIndex = k;
  329.         break;
  330.       }
  331.     }
  332.   }
  333.  
  334.   if ((index >= offlineIndex) && (offlineIndex != -1))
  335.     return true;
  336.   else
  337.     return false;
  338.  
  339. }
  340.  
  341.  
  342. /*
  343.  * Function: cmdSignOn()
  344.  *
  345.  * Arguments: None
  346.  * 
  347.  * Return: None
  348.  *
  349.  * Description: Called from menu item or toolbar. Passes control to sidebar
  350.  *        panel cmdSignOn() (see SidebarPanel/SidebarPanel.js)
  351. */
  352.  
  353. function cmdSignOn()
  354. {
  355.     //var sidebarframe = top.frames["AppPanel"];
  356.     //var sidebarframe=top.AIMDocumentPath;
  357.     var sidebarframe=getsidebarframe();
  358.  
  359.   if(sidebarframe) {
  360.       sidebarframe.cmdPanelSignOn();
  361.   }
  362.   
  363. }
  364.  
  365. /*
  366.  * Function: cmdSignOff()
  367.  *
  368.  * Arguments: None
  369.  * 
  370.  * Return: None
  371.  *
  372.  * Description: Calls aimSessionLogoff to close current IM session. 
  373.  *     
  374.  *
  375. */
  376.  
  377. function cmdSignOff()
  378. {
  379.   /* Set pref to be false so that auto login doesnt get fired for every launch */
  380.   aimPrefsManager().SetBoolPref("aim.session.appfirstlogin", false, null,true);
  381.   aimSessionLogoff();
  382.  
  383. }
  384.  
  385. /*
  386.  * Function: cmdCancelSignOn()
  387.  *
  388.  * Arguments: None
  389.  * 
  390.  * Return: None
  391.  *
  392.  * Description: Called during connection startup if cancel button is pressed.
  393.  *         Cancels the IM session by calling cmdSignOff().
  394.  *        
  395. */
  396.  
  397. function cmdCancelSignOn()
  398. {
  399.     aimPrefsManager().SetBoolPref("aim.session.firsttry", false, null, true);
  400.     cmdSignOff();
  401. }
  402.  
  403. /*
  404.  * Function: cmdClose()
  405.  *
  406.  * Arguments: None
  407.  * 
  408.  * Return: None
  409.  *
  410.  * Description: Invoked from close menu item, or from cmdSignOffAndClose(),
  411.  *        below. Causes the app window to be closed.
  412.  *
  413. */
  414.  
  415. function cmdClose()
  416. {
  417.    //aimCmdClose();
  418.    top.close();
  419. }
  420.  
  421. /*
  422.  * Function: cmdSignOffAndClose()
  423.  *
  424.  * Arguments: None
  425.  * 
  426.  * Return: None
  427.  *
  428.  * Description: Called in response to user selecting signoff and close menu
  429.  *        item. Signs off the current IM session and closes the 
  430.  *        standalone window.
  431. */
  432.  
  433. function createInstance( contractid, iidName )
  434. {
  435.     var iid = eval( "Components.interfaces." + iidName );
  436.         return Components.classes[ contractid ].createInstance( iid );
  437. }
  438.  
  439. function cmdExportBuddyList()
  440. {
  441.         nsIFilePicker = Components.interfaces.nsIFilePicker;
  442.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  443.  
  444.     fp.init(window, aimString("title.exportbudlist"), nsIFilePicker.modeSave);
  445.     fp.appendFilter(aimString("budlist.title"), aimString("budlist.filter"));
  446.     fp.appendFilters(nsIFilePicker.filterAll);
  447.  
  448.     try {
  449.         var ret = fp.show();
  450.         if ( ret == nsIFilePicker.returnOK || ret == nsIFilePicker.returnReplace) {
  451.             var status;
  452.             status = aimBuddyExportBuddyList(fp.file);
  453. /*
  454.             if ( status == false )
  455.                 aimErrorBox(aimString("msg.exporttryagain"));
  456.             else
  457.                 aimErrorBox(aimString("msg.exportsuccess"));
  458. */
  459.         }
  460.     } 
  461.     catch (ex) {
  462.         aimErrorBox(aimString("msg.exportfailure"));
  463.     }
  464.     return;
  465. }
  466.  
  467.  
  468. function cmdImportBuddyList()
  469. {
  470.  
  471.     nsIFilePicker = Components.interfaces.nsIFilePicker;
  472.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  473.  
  474.     fp.init(window, aimString("title.importbudlist"), nsIFilePicker.modeOpen);
  475.     fp.appendFilter(aimString("budlist.title"), aimString("budlist.filter"));
  476.     fp.appendFilters(nsIFilePicker.filterAll);
  477.  
  478.     try {
  479.         var ret = fp.show();
  480.         if ( ret == nsIFilePicker.returnOK ) {
  481.             var status;
  482.             aimBuddyImportBuddyList(fp.file);
  483.         }
  484.     }
  485.     catch (ex) {
  486.         aimErrorBox(aimString("msg.importfailure"));
  487.     }
  488.     return;
  489. }
  490.  
  491. function cmdSignOffAndClose()
  492. {
  493.     cmdSignOff();
  494.     cmdClose();
  495. }
  496.  
  497. /*
  498.  * Function: cmdAddBuddy()
  499.  *
  500.  * Arguments: None
  501.  * 
  502.  * Return: None
  503.  *
  504.  * Description: Called in response to menu item of toolbar button in standalone
  505.  *        for adding a buddy to a buddy group. Opens BuddyAddBuddy.xul to
  506.  *        place a dialog that can be used to add a buddy.
  507.  *
  508.  * Bugs:    Needs to support inline editing.
  509.  * 
  510. */
  511.  
  512. function cmdAddBuddy()
  513. {
  514.   var sidebarframe=getsidebarframe();
  515.     var foundOne = false;
  516.     var selectedGroup = "";
  517.   var elt = sidebarframe;
  518.   if (!sidebarframe)
  519.     elt = window;
  520.   var tree = elt.document.getElementById("ListSetup");
  521.    if (!tree )
  522.       return;
  523.  
  524.   var isGroupPresent = aimCheckForGroupCount();
  525.   if (!isGroupPresent) {
  526.     (aimString("msg.NoGroups"));
  527.       return;
  528.   }
  529.  
  530.   var groups = aimGetSelectedBuddyGroups();
  531.     openDialog("chrome://aim/content/BuddyAddBuddy.xul", "", 
  532.         "modal=yes,titlebar,chrome", groups, tree, null);
  533. }
  534.  
  535. /*
  536.  * Function: cmdAddGroup()
  537.  *
  538.  * Arguments: None
  539.  * 
  540.  * Return: None
  541.  *
  542.  * Description: Called in response to menu item of toolbar button in standalone
  543.  *        for adding a buddy group. Opens BuddyAddGroup.xul to place a 
  544.  *        dialog that can be used to add a buddy group.
  545.  *
  546.  * Bugs:    Needs to support inline editing.
  547.  * 
  548. */
  549.  
  550. function cmdAddGroup()
  551. {
  552.     openDialog("chrome://aim/content/BuddyAddGroup.xul", "", "modal=yes,titlebar,chrome");
  553. }
  554.  
  555. /*
  556.  * Function: SelectedGroup()
  557.  *
  558.  * Arguments: None
  559.  * 
  560.  * Return: None
  561.  *
  562.  * Description: Constructor function for SelectedGroup objects
  563.  *         
  564.  *        
  565. */
  566.  
  567. function SelectedGroup()
  568. {
  569.   var index = 0;
  570.     var selected = "false";
  571.     var name = null;
  572. }
  573.  
  574. /*
  575.  * Function: SelectedBuddy()
  576.  *
  577.  * Arguments: None
  578.  * 
  579.  * Return: None
  580.  *
  581.  * Description: Constructor function for SelectedBuddy objects
  582.  *         
  583. */
  584.  
  585. function SelectedBuddy()
  586. {
  587.     var parentname = null;
  588.     var name = null;
  589. }
  590.  
  591. /*
  592.  * Function: cmdDelete()
  593.  *
  594.  * Arguments: None
  595.  * 
  596.  * Return: None
  597.  *
  598.  * Description: Called in response to user clicking delete toolbar button or
  599.  *        selecting delete menu item. Deletes all selected groups (and
  600.  *        the buddies they contain) and all selected buddies.
  601. */
  602.  
  603. function cmdDelete()
  604. {
  605.   var tree = getSelectedTreeName();
  606.   var col = getSelectedTabName();
  607.   var selectedBuddies = new Array();
  608.   var selectedGroups = new Array();
  609.   var groupCount = 0;
  610.   var buddyCount = 0;
  611.   var lastSelectedIndex;
  612.   if (!tree || !col) return;
  613.   var groupCount = 0;
  614.   var buddyCount = 0;
  615.   var rangeCount = tree.treeBoxObject.selection.getRangeCount();
  616.   if (rangeCount == 0) {
  617.     // nothing is selected
  618.     aimErrorBox(aimString("msg.NothingToDelete"));
  619.     return;
  620.   }
  621.   var view = tree.treeBoxObject.view;
  622.   for(var i = 0; i < rangeCount; i++) {
  623.     var startIndex = {};
  624.     var endIndex = {};
  625.     tree.treeBoxObject.selection.getRangeAt(i, startIndex, endIndex);
  626.     lastSelectedIndex = endIndex.value;
  627.     for (var j = startIndex.value; j <= endIndex.value; j++) {
  628.       var level = view.getLevel(j);
  629.       if (level == 0) {
  630.         var groupResource = GetBuddyResource(tree, j);
  631.         var groupName = GetBuddyAttribute(tree, groupResource, "Name");
  632.         // Special groups like Offline have no resources. So the value will be null.
  633.         if (groupName == aimString("msg.AuthGroup")|| groupName == null) {
  634.           aimErrorBox(aimString("msg.CannotDeleteAuthGroup"));
  635.           continue;
  636.         }
  637.         
  638.         selectedGroups[groupCount] = new SelectedGroup;
  639.         selectedGroups[groupCount].name = groupName;
  640.         selectedGroups[groupCount].index = j;
  641.         groupCount++;
  642.  
  643.  
  644.  
  645.       } //if level ==0
  646.       else {
  647.         if (level == 1) {
  648.           var parentIndex = view.getParentIndex(j);
  649.           var parentResource = GetBuddyResource(tree, parentIndex);
  650.           var parentName = GetBuddyAttribute(tree, parentResource, "Name");
  651.           if (parentName == aimString("msg.AuthGroup") || parentName == null) {
  652.              // A contact from the special group Authorization awaiting has been selected.
  653.              var buddyResource = GetBuddyResource(tree, j);
  654.              var buddyName = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  655.              selectedBuddies[buddyCount] = new SelectedBuddy;
  656.              selectedBuddies[buddyCount].name = buddyName;
  657.              selectedBuddies[buddyCount].parentname = aimString("msg.AuthGroup");
  658.             // a group under Offline is selected.
  659.           /*  var offlineGroupResource = GetBuddyResource(tree, j);
  660.             var offlineGroupName = GetBuddyAttribute(tree, offlineGroupResource, "Name");
  661.             if (!CheckForDuplicateNameInArray(selectedGroups, offlineGroupName)) {
  662.               selectedGroups[groupCount] = new SelectedGroup;
  663.               selectedGroups[groupCount].name = offlineGroupName;
  664.               selectedGroups[groupCount].index = j;
  665.               groupCount++;
  666.  
  667.             }
  668.            */
  669.  
  670.  
  671.           } //if offline
  672.           else {
  673.             // a Online buddy is selected
  674.             if (!tree.treeBoxObject.selection.isSelected(parentIndex)) {
  675.               //If the parent is already selected, ignore the selection. Else get the parent name
  676.               var buddyResource = GetBuddyResource(tree, j);
  677.               var buddyName = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  678.               selectedBuddies[buddyCount] = new SelectedBuddy;
  679.               selectedBuddies[buddyCount].name = buddyName;
  680.               selectedBuddies[buddyCount].parentname = parentName;
  681.               buddyCount++;
  682.             } //if
  683.  
  684.  
  685.           } //else
  686.  
  687.         } //if level 1
  688.         else {
  689.           if (level == 2) {
  690.             //Offline buddy is selected..
  691.             var offlineParentIndex = view.getParentIndex(j);
  692.             if (!tree.treeBoxObject.selection.isSelected(offlineParentIndex)) {
  693.               //If the parent is already selected, ignore the selection. Else get the parent name
  694.               //get the offline parent name
  695.               var offlineParentResource = GetBuddyResource(tree, offlineParentIndex);
  696.               var offlineParentName = GetBuddyAttribute(tree, offlineParentResource, "Name");
  697.               
  698.               // if the group is already selected in the Online, ignore it.
  699.               if (!CheckForDuplicateNameInArray(selectedGroups, offlineParentName)) {
  700.                 var buddyResource = GetBuddyResource(tree, j);
  701.                 var buddyName = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  702.                 selectedBuddies[buddyCount] = new SelectedBuddy;
  703.                 selectedBuddies[buddyCount].name = buddyName;
  704.                 selectedBuddies[buddyCount].parentname = offlineParentName;
  705.                 buddyCount++;
  706.               }
  707.             } //if
  708.           } //if 
  709.         } //else
  710.       } //else
  711.     } //for
  712.   } //for
  713.  
  714.  
  715.  
  716.   var answer;
  717.   var hasCancelled = 0;
  718.   for (var g=0; g<selectedGroups.length; g++) {
  719.     if (selectedGroups[g].name != null && selectedGroups[g].name != "" ) {
  720.       if (isIcq() != true ) {
  721.         answer = top.confirm(aimString("confirm.DeleteGroup").replace(/%GroupName%/, selectedGroups[g].name));
  722.         }
  723.       else {
  724.         answer = top.confirm(aimString("confirm.DeleteGroup_ICQ").replace(/%GroupName%/, selectedGroups[g].name));
  725.         }
  726.       if (answer == true)
  727.         aimBuddyRemoveBuddyGroup(selectedGroups[g].name);
  728.       else
  729.         if (!hasCancelled)
  730.           hasCancelled = 1;
  731.     }
  732.   }
  733.  
  734.   for (var b=0; b<selectedBuddies.length; b++) {
  735.     if (selectedBuddies[b].name != null && selectedBuddies[b].name != "" ) {
  736.       if (isIcq() != true ) {
  737.         answer  = top.confirm(aimString("confirm.DeleteBuddy").replace(/%BuddyName%/, selectedBuddies[b].name).replace(/%GroupName%/, selectedBuddies[b].parentname));
  738.         }
  739.       else {
  740.         answer  = top.confirm(aimString("confirm.DeleteBuddy_ICQ").replace(/%BuddyName%/, selectedBuddies[b].name).replace(/%GroupName%/, selectedBuddies[b].parentname));
  741.         }
  742.       if (answer == true) {
  743.         if (selectedBuddies[b].parentname == aimString("msg.AuthGroup")) {
  744.            // If this is the Awaiting authorization special group remove from feedbag and datasource
  745.            aimBuddyManager().RemoveBuddyAll(selectedBuddies[b].name);
  746.            aimFeedbagManager().ClearAuthorization(selectedBuddies[b].name);
  747.            continue;
  748.         }
  749.  
  750.         aimBuddyRemoveBuddy(selectedBuddies[b].parentname, selectedBuddies[b].name);
  751.      }
  752.       else
  753.         if (!hasCancelled)
  754.           hasCancelled = 1;
  755.     }
  756.   }
  757.  
  758.   var totalRowCount = view.rowCount;
  759.   if (!hasCancelled) {
  760.     // The view maintains the selection if the user has cancelled the deletion. So don't worry about selecting the
  761.     // next index in this case
  762.     if ((lastSelectedIndex + 1) > totalRowCount)
  763.       //if there is nothing after the last selected one, select the last one.
  764.       SelectIndex(totalRowCount-1);
  765.     else
  766.       SelectIndex(lastSelectedIndex);
  767.   }
  768.  
  769. }
  770.  
  771.  
  772.  
  773. function cmdAbEditCard()
  774. {
  775.   var sidebarframe=getsidebarframe();
  776.   var selectedGroup = "";
  777.   var wasSelected = false;
  778.   var tree = sidebarframe.document.getElementById("ListSetup");
  779.     var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");   
  780.     // in the online tab and the user hit delete
  781.   if ( tab.selectedIndex == 0 )
  782.     return;
  783.   var groups = aimBuddyTreeFindGroups( tree );
  784.   top.selectedGroups = new Array();
  785.   for (var i = 0; i != groups.length; i++) {
  786.   // make a record for this group
  787.     top.selectedGroups[i] = new SelectedGroup;
  788.     top.selectedGroups[i].selectedBuddies = new Array();
  789.     top.selectedGroups[i].name = groups[i].getAttribute("Name");
  790.     if (groups[i].getAttribute("selected") == "true") {
  791.       wasSelected = "true";
  792.       top.selectedGroups[i].selected = "true";
  793.     }
  794.     else
  795.       top.selectedGroups[i].selected = "false";                                                   // find the buddy nodes for this group.
  796.  
  797.     var buddies = null;
  798.     for (var j = 0; j != groups[i].childNodes.length; j++)
  799.     {
  800.       if (groups[i].childNodes[j].nodeName == "treechildren")
  801.       {
  802.         // found it.
  803.         buddies = groups[i].childNodes[j].childNodes;
  804.         break;
  805.       }
  806.     }
  807.  
  808.     if (buddies)
  809.     {
  810.       for (var j = 0; j != buddies.length; j++)
  811.       {
  812.         top.selectedGroups[i].selectedBuddies[j] = new SelectedBuddy;
  813.         if (buddies[j].getAttribute("selected") == "true") {
  814.           // buddy is selected. Save the name
  815.           // and set the selected flag to true
  816.           wasSelected = "true";
  817.           top.selectedGroups[i].selectedBuddies[j].name = buddies[j].getAttribute("ScreenName");
  818.           top.selectedGroups[i].selectedBuddies[j].selected = "true";
  819.         }
  820.         else
  821.           top.selectedGroups[i].selectedBuddies[j].selected = "false";
  822.       }
  823.     }                     
  824.     }
  825.  
  826.   for ( var i = 0; i != top.selectedGroups.length; i++ ) {
  827.     selectedGroup = top.selectedGroups[i].name;
  828.     if ( top.selectedGroups[i].selected == "true" ) {
  829.          aimErrorBox(aimString("msg.SelectBuddy")); 
  830.         }
  831.     else {
  832.       for ( var j = 0; j != top.selectedGroups[i].selectedBuddies.length; j++ ) {
  833.         if ( top.selectedGroups[i].selectedBuddies[j].selected == "true" ) {
  834.           selectedBuddy = top.selectedGroups[i].selectedBuddies[j].name;
  835.           if ( selectedBuddy && selectedBuddy != "" ) {
  836.             // XXX DOES THIS STILL WORK, IS IT STILL NEEDED?
  837.                   var card = aimABInfo().getPersonalAbCardFromAttribute("_AimScreenName", selectedBuddy, false);
  838.               goEditCardDialog("moz-abmdbdirectory://abook.mab",card,null);
  839.           }
  840.         }                  
  841.         }
  842.     }
  843.   }
  844.  
  845. }       
  846.  
  847.  
  848. function cmdCustom()
  849. {
  850.   url = aimString("app.custom.url");
  851.   aimCmdNewBrowser(url);
  852. }
  853.  
  854. function cmdAdClick()
  855. {
  856.      aimCmdNewBrowser(aimRegionString("app.ad.link"));
  857.   }
  858.  
  859. var ad_access=1;
  860.  
  861. function setAdTimer()
  862. {
  863.  
  864.   var adButton = top.document.getElementById("adButton");
  865.     var adImage = aimRegionString("app.ad.image")+"?access=" + ad_access;
  866.  
  867.   ad_access++;
  868.   var adTimer = aimString("app.ad.timer");
  869.  
  870.   if(adButton)
  871.         adButton.setAttribute("src", adImage);
  872.  
  873.   if(window)
  874.     window.setTimeout('setAdTimer()', adTimer);
  875. }
  876.  
  877. function getSidebarDs()
  878. {
  879. var PANELS_RDF_FILE = "UPnls";
  880. try {
  881.      var locator_service = Components.classes["@mozilla.org/file/directory_service;1"].getService();
  882.       if (locator_service)
  883.         locator_service = locator_service.QueryInterface(Components.interfaces.nsIProperties);
  884.       var sidebar_file = locator_service.get(PANELS_RDF_FILE, Components.interfaces.nsIFile);
  885.       if (!sidebar_file.exists()) {
  886.         //Sidebar panels file does not exist?
  887.         return;
  888.       }
  889.         var file_url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
  890.         file_url.file = sidebar_file;
  891.         return file_url.spec;
  892.     } catch (ex) {
  893.        throw(ex);
  894.     }
  895.  }
  896.  
  897. function CheckBuddyPanel()
  898. {
  899.   var RDF = aimRDF();
  900.   this.nc = "http://home.netscape.com/NC-rdf#";
  901.   this.resource = 'urn:sidebar:current-panel-list';
  902.     var panel_list =RDF.GetDataSource(getSidebarDs()).GetTarget(RDF.GetResource("urn:sidebar:current-panel-list"),RDF.GetResource("http://home.netscape.com/NC-rdf#"+"panel-list"),  true);
  903.     if (panel_list) {
  904.         panel_list.QueryInterface(Components.interfaces.nsIRDFResource);
  905.     }
  906.   var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  907.     try { 
  908.     container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  909.     container.Init(RDF.GetDataSource(getSidebarDs()), panel_list);
  910.     const RDF_CONTRACTID = "@mozilla.org/rdf/rdf-service;1";
  911.     const nsIRDFService = Components.interfaces.nsIRDFService;
  912.     this.datasource = RDF.GetDataSource(getSidebarDs());
  913.     this.rdf = Components.classes[RDF_CONTRACTID].getService(nsIRDFService);
  914.   } catch (ex)
  915.   {
  916.     if (timercatch == false)
  917.     {
  918.       timercatch = true;
  919.       setTimeout("CheckBuddyPanel()",5000);
  920.     }
  921.     
  922. //    throw(ex);
  923.   }
  924.     var panel_resource = RDF.GetResource("urn:sidebar:panel:im-panel");
  925.     var im_resource=RDF.GetResource("urn:sidebar:3rdparty-panel:chrome://aim/content/SidebarPanel.xul");
  926.     var panel_index = container.IndexOf(panel_resource);
  927.     var panel_index2 = container.IndexOf(im_resource);
  928.     if ((panel_index == -1) && (panel_index2==-1))
  929.     {
  930.       if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) 
  931.     { 
  932. //  This line was broken by mstoltz's security fix to disallow chrome urls passed to addPanel
  933. //  Eventually when the security fix is done properly (i.e. checking the caller rather than blindly disallowing chrome)
  934. //  We should use this addPanel call and back out all the changes I made to this file in this checkin.
  935. //         window.sidebar.addPanel ("Buddy List","chrome://aim/content/SidebarPanel.xul",""); 
  936.  
  937.       var aTitle = "Buddy List";
  938.       var aContentURL = "chrome://aim/content/SidebarPanel.xul";
  939.  
  940.       this.datasource.Assert(panel_resource,
  941.                              this.rdf.GetResource(this.nc + "title"),
  942.                              this.rdf.GetLiteral(aTitle),
  943.                              true);
  944.       this.datasource.Assert(panel_resource,
  945.                             this.rdf.GetResource(this.nc + "content"),
  946.                             this.rdf.GetLiteral(aContentURL),
  947.                             true);
  948.       container.AppendElement(panel_resource);
  949.       // Use an assertion to pass a "refresh" event to all the sidebars.
  950.       // They use observers to watch for this assertion (in sidebarOverlay.js).
  951.       this.datasource.Assert(this.rdf.GetResource(this.resource),
  952.                              this.rdf.GetResource(this.nc + "refresh"),
  953.                              this.rdf.GetLiteral("true"),
  954.                              true);
  955.       this.datasource.Unassert(this.rdf.GetResource(this.resource),
  956.                                this.rdf.GetResource(this.nc + "refresh"),
  957.                                this.rdf.GetLiteral("true"));
  958.  
  959.       /* Write the modified panels out. */
  960.       const nsIRDFRemoteDataSource = Components.interfaces.nsIRDFRemoteDataSource;
  961.       this.datasource.QueryInterface(nsIRDFRemoteDataSource).Flush();
  962.       }
  963.     } 
  964.   SidebarSelectPanel(document.getElementById("urn:sidebar:panel:im-panel"), false, false);
  965. }
  966.  
  967.  
  968.  /******
  969.   * Request info about a user and display it in a tooltip (after callback).
  970.   ******/
  971.  
  972. function fillInfoTooltip(aEvent, aTooltipNode)
  973. {
  974.   var tree = document.getElementById("OnlineBuddies");
  975.   var bx = tree.treeBoxObject;
  976.   var row = {}; var col = {}; var obj = {};
  977.   bx.getCellAt(aEvent.clientX, aEvent.clientY, row, col, obj);
  978.   var rowValue = row.value;
  979.   var tooltip = document.getElementById("infoTooltip");
  980.   if (rowValue < 0) {
  981.     tooltip.setAttribute("collapsed", "true");
  982.     return;
  983.   }
  984.   var buddyResource = GetBuddyResource(tree, rowValue);
  985.   var name = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  986.   var view = tree.treeBoxObject.view;
  987.   var level = view.getLevel(rowValue);
  988.   var inOffline = IsIndexinSpecialGroup(tree, col.value, rowValue);
  989.   if (level != 1 || inOffline) {
  990.     // if this is a mac do this bad hack to hide the tooltip
  991.     if (navigator.appVersion.indexOf("Macintosh") != -1)
  992.       document.getElementById("hideload").setAttribute("collapsed", "true");
  993.     else
  994.       tooltip.setAttribute("collapsed", "true");
  995.     return;
  996.   }
  997.   
  998.    // this check is required to prevent redundant 
  999.    // re-requests while waiting for the callback
  1000.    if (!rowValue._RequestingInfo) {
  1001.      //var name = getScreenNameFromNode(aTreecell);
  1002.      //var tooltip = document.getElementById("infoTooltip");
  1003.  
  1004.      if (name && name != "" && tooltip) {
  1005.        var elOnline = document.getElementById("infoTooltipOnlineTime");
  1006.        elOnline.setAttribute("value", "");
  1007.        var elStatusTime = document.getElementById("infoTooltipStatusTime");
  1008.        elStatusTime.setAttribute("value", "");
  1009.        // if this is a mac do this bad hack to hide the tooltip
  1010.        if (navigator.appVersion.indexOf("Macintosh") != -1)
  1011.          document.getElementById("hideload").setAttribute("collapsed", "true");
  1012.        else
  1013.          tooltip.setAttribute("collapsed", "true");
  1014.        rowValue._RequestingInfo = true;
  1015.  
  1016.        // send the request and wait for callback
  1017.        var listenerCap = new TooltipCapListener(rowValue, tooltip);
  1018.        try {
  1019.         aimLocateManager().RequestUserInfoCapabilities(listenerCap, name);
  1020.        } catch (ex) {
  1021.          //ERROR: unable to retrieve AIM user info for name
  1022.          return;
  1023.        }
  1024.      }
  1025.    }
  1026.  }
  1027.  
  1028.  /******
  1029.   * Search up the tree for first treeitem node.
  1030.   ******/
  1031.  
  1032.  function getScreenNameFromNode(aNode)
  1033.  {
  1034.    var node = aNode;
  1035.    while (node.localName != "treeitem") {
  1036.      node = node.parentNode;
  1037.    }
  1038.    return node ? node.getAttribute("ScreenName") : null;
  1039.  }
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  /******
  1045.   * Event listener used for RequestUserInfoCapabilities
  1046.   ******/
  1047.  
  1048.  function TooltipCapListener(aTreecell, aTooltip)
  1049.  {
  1050.    this.mTreecell = aTreecell;
  1051.    this.mTooltip = aTooltip;
  1052.  }
  1053.  
  1054.  TooltipCapListener.prototype = {
  1055.     OnRequestUserInfoCapabilitiesComplete: function(aScreenName, aUserObj)
  1056.      {
  1057.      var now = new Date().getTime()/1000;
  1058.      // TODO: search within mTooltip for text elements instead of id search
  1059.      
  1060.      // fill the screen name
  1061.      var elName = document.getElementById("infoTooltipName");
  1062.   
  1063.      aimABInfo = aimManager().QueryInterface(Components.interfaces.nsIAimABInfo);
  1064.      if (aimABInfo) {
  1065.         var card = aimABInfo.getPersonalAbCardFromAttribute("_AimScreenName", aScreenName, false);
  1066.         if (card) {
  1067.           if (card.nickName)
  1068.             elName.setAttribute("value", card.nickName);
  1069.           else if (card.displayName)
  1070.             elName.setAttribute("value", card.displayName);
  1071.                else
  1072.             elName.setAttribute("value", aScreenName);
  1073.           }
  1074.           else
  1075.           elName.setAttribute("value", aScreenName);
  1076.      }
  1077.      else
  1078.        elName.setAttribute("value", aScreenName);
  1079.  
  1080.      
  1081.    // fill the online line
  1082.    var elOnline = document.getElementById("infoTooltipOnlineTime");
  1083.    var since = aUserObj.GetOnlineSinceTime();
  1084.    elOnline.setAttribute("value", getPrettyDateDiff(now, since));
  1085.      var elOnlineId = document.getElementById("infoTooltipOnlineTimeId");
  1086.    elOnlineId.setAttribute("value", aimString("tooltip.online") + ":");
  1087.    
  1088.    // fill the status line
  1089.    var elStatus = document.getElementById("infoTooltipStatus");
  1090.      var elStatusTime = document.getElementById("infoTooltipStatusTime");
  1091.    if (aUserObj.IsIdle()) {
  1092.      elStatus.setAttribute("value", aimString("tooltip.idle") + ":");
  1093.      var statusDate = aUserObj.GetIdleSinceTime();
  1094.      elStatusTime.setAttribute("value", getPrettyDateDiff(now, statusDate));
  1095.    } else if (aUserObj.IsAway()) {
  1096.        elStatus.setAttribute("value", aimString("tooltip.status") + ":");
  1097.      elStatusTime.setAttribute("value", aimString("tooltip.away"));
  1098.    } else {
  1099.       elStatus.setAttribute("value", aimString("tooltip.status") + ": ");
  1100.     elStatusTime.setAttribute("value", aimString("tooltip.active"));
  1101.    }
  1102.    
  1103.    if (isIcq() != true ) 
  1104.    {  
  1105.      // fill the warnings line
  1106.      var warnings = document.getElementById("infoTooltipWarnings");
  1107.      warnings.setAttribute("value", aUserObj.GetWarningPercent() + "%");
  1108.        var warningsId = document.getElementById("infoTooltipWarningsId");
  1109.      warningsId.setAttribute("value", aimString("tooltip.warnings") + ":");
  1110.      warningsId.setAttribute("hidden", "false");
  1111.      warnings.setAttribute("hidden", "false");
  1112.  
  1113.      
  1114.   // fill in the Service Type (AOL, Internet, Administrator...)     
  1115.      var elFlagService = document.getElementById("infoTooltipFlagValue");
  1116.      var flagServiceValue = aUserObj.GetFlags();
  1117.      var serviceString = "";
  1118.      var serviceEnums = Components.interfaces.nsAimServiceTypes;
  1119.      if (flagServiceValue & serviceEnums.Transient)
  1120.         serviceString = aimString("IdsflagTrial.label") + " ";
  1121.      if (flagServiceValue & serviceEnums.Aol)
  1122.         serviceString = serviceString + aimString("IdsflagAol.label") + " ";
  1123.      if (flagServiceValue & serviceEnums.Free)
  1124.         serviceString = serviceString + aimString("IdsflagInternet.label") + " ";
  1125.      if (flagServiceValue & serviceEnums.Administrator)
  1126.         serviceString = serviceString + aimString("IdsflagAdministrator.label") + " ";
  1127.      
  1128.    elFlagService.setAttribute("value", serviceString);
  1129.      var elFlagServiceId = document.getElementById("infoTooltipFlag");
  1130.    elFlagServiceId.setAttribute("value", aimString("tooltip.service") + ":");
  1131.    elFlagService.setAttribute("hidden", "false");
  1132.    elFlagServiceId.setAttribute("hidden", "false");
  1133.  
  1134.      
  1135.   // fill in the Capabilities
  1136.     var elCapabilities = document.getElementById("capabilitiesValue");
  1137.   var elCapabilitiesId = document.getElementById("capabilities");
  1138.   elCapabilitiesId.setAttribute("hidden", "false");
  1139.   elCapabilities.setAttribute("hidden", "false");
  1140.     try {
  1141.         var capMask = aUserObj.GetCapabilities();
  1142.     if (capMask == 0) {
  1143.       elCapabilitiesId.setAttribute("hidden", "true");
  1144.       elCapabilities.setAttribute("hidden", "true");
  1145.     } else {
  1146.       var capEnums = Components.interfaces.nsAimCapabilitesMask;
  1147.       var capString = "";
  1148.         if (capEnums.buddyIcon & capMask) {
  1149.           if (capString == "")
  1150.             // if it is the first capability, just add it
  1151.             capString += aimString("tooltip.buddyicon");
  1152.           else
  1153.             // if some capability already present just add a comma and the capability
  1154.             capString += ", " + aimString("tooltip.buddyicon");
  1155.         }
  1156.         if (capEnums.chat & capMask) {
  1157.           if (capString == "")
  1158.             capString += aimString("tooltip.chat");
  1159.           else
  1160.             capString += ", " + aimString("tooltip.chat");
  1161.         }
  1162.         if (capEnums.filexfer & capMask) {
  1163.           if (capString == "")
  1164.             capString += aimString("tooltip.filexfer");
  1165.           else
  1166.             capString += ", " + aimString("tooltip.filexfer");
  1167.         }
  1168.       
  1169.       elCapabilities.setAttribute("value", capString);
  1170.     }
  1171.     } catch (e) {}
  1172.      
  1173.      elCapabilitiesId.setAttribute("value", aimString("tooltip.capabilities") + ":");
  1174.  
  1175.   } //end if icq
  1176.   else
  1177.   {
  1178.     //Hide warning capabilities etc in Icq     
  1179.     document.getElementById("infoTooltipWarningsId").setAttribute("hidden", "true");
  1180.     document.getElementById("infoTooltipWarnings").setAttribute("hidden", "true");
  1181.     document.getElementById("infoTooltipFlag").setAttribute("hidden", "true");
  1182.     document.getElementById("infoTooltipFlagValue").setAttribute("hidden", "true");
  1183.     document.getElementById("capabilitiesValue").setAttribute("hidden", "true");
  1184.     document.getElementById("capabilities").setAttribute("hidden", "true");
  1185.     
  1186.   }
  1187.  
  1188.      // show the tooltip
  1189.      // if this is a mac do this bad hack to hide the tooltip
  1190.      if (navigator.appVersion.indexOf("Macintosh") != -1)
  1191.          document.getElementById("hideload").removeAttribute("collapsed");
  1192.      else
  1193.          this.mTooltip.removeAttribute("collapsed");
  1194.      this.mTreecell._RequestingInfo = false;
  1195.      },
  1196.  
  1197.     OnRequestUserInfoCapabilitiesError: function(aScreenName, aError)
  1198.      {
  1199.      this.mTreecell._RequestingInfo = false;
  1200.      }
  1201.  };
  1202.  
  1203.  
  1204. function cmdChangePassword() {
  1205.     window.openDialog('chrome://aim/content/AimChangePassword.xul','','modal=no,titlebar,chrome,centerscreen',null);
  1206. }
  1207.  
  1208. function cmdConfirmAccount() {
  1209.     window.openDialog('chrome://aim/content/AimConfirmAccount.xul','','modal=yes,titlebar,chrome,centerscreen',null);
  1210. }
  1211.  
  1212. function cmdChangeEmail() {
  1213.     window.openDialog('chrome://aim/content/AimChangeEmail.xul','','modal=no,titlebar,chrome,centerscreen',null);
  1214. }
  1215.  
  1216. function cmdGetMemberInfo() {
  1217.   var screenName = getSelectedScreenName();
  1218.   window.openDialog('chrome://aim/content/GetMemberInfo.xul','_blank','chrome,all,dialog=no', screenName);
  1219. }
  1220.  
  1221.  
  1222. /*
  1223. * Name: cmdBuddyAlert
  1224. * Arguments: none. 
  1225. * Description: This function is called by command handler of cmd_buddyAlert. It chooses the appropriate tree where
  1226. * the event is triggered from and checks to see if there is a screenName attribute on the selected node. Then it opens
  1227. * the BuddyAlert dialog by passign the screenname as an argument.
  1228. * Return Value: none
  1229. * Author: Prassanna<prass@netscape.com> 
  1230. */
  1231.  
  1232. function cmdBuddyAlert(isedit) {
  1233.   var screenName = getSelectedScreenName();
  1234.   if (screenName && (screenName != null)) 
  1235.   {
  1236.     if (isedit == 1)
  1237.       window.openDialog('chrome://aim/content/AimBuddyAlert.xul','_blank','chrome,all,dialog=no', screenName, 1);
  1238.     else  
  1239.       window.openDialog('chrome://aim/content/AimBuddyAlert.xul','_blank','chrome,all,dialog=no', screenName, null);
  1240.   }
  1241. }
  1242.  
  1243. /*
  1244. * Name: cmdDelBuddyAlert
  1245. * Arguments: none. 
  1246. * Description: This function is called by command handler of cmd_delbuddyAlert. It chooses the appropriate tree where
  1247. * the event is triggered from and checks to see if there is a screenName attribute on the selected node. Then it removes 
  1248. * the screen name from the buddy alert list.
  1249. * Return Value: none
  1250. * Author: Prassanna<prass@netscape.com> 
  1251. */
  1252.  
  1253. function cmdDelBuddyAlert() {
  1254.   var screenName = getSelectedScreenName();
  1255.   if (screenName && (screenName != null))
  1256.     aimBuddyManager().DeleteBuddyFromAlertList(screenName); 
  1257. }
  1258.  
  1259. function cmdNewAway()
  1260. {
  1261.   if (isIcq() == true )
  1262.     window.openDialog("chrome://aim/content/AddIcqAwayMessage.xul","_blank", "chrome,close,titlebar,modal", "", "", "");
  1263.   else
  1264.     window.openDialog("chrome://aim/content/AddAwayMessage.xul","_blank", "chrome,close,titlebar,modal", "", "", "");
  1265. }
  1266.  
  1267. function sendFile()
  1268. {
  1269.   window.openDialog("chrome://aim/content/sendfile.xul","_blank", "chrome,close,titlebar", "", "", "");
  1270. }
  1271.  
  1272. function addAppSessionListener() {
  1273.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  1274.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  1275.   if (observerService) {
  1276.     observerService.addObserver(sessionAppObserver, "sessionMode-changed", false);
  1277.   } else {
  1278.     dump("failed to get observer service\n");
  1279.   }
  1280. }
  1281.  
  1282. function removeAppSessionListener() {
  1283.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  1284.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  1285.   if (observerService)
  1286.   {
  1287.   observerService.removeObserver(sessionAppObserver, "sessionMode-changed");
  1288.   }
  1289. }
  1290.  
  1291.  
  1292. var sessionAppObserver = {
  1293.   observe: function(subject, message, data) {
  1294.   if (message == 'sessionMode-changed') {
  1295.      // Update sessionMode attribut which updates all images thru css
  1296.      window.document.getElementById("sessionAppWatcher").setAttribute("sessionMode", data);
  1297.      UpdateAppMenus(data);
  1298.      }
  1299.   }
  1300. }
  1301.  
  1302.  
  1303. function cmdRegistUser()
  1304. {
  1305.  // Open regist user url;
  1306.   regLink = aimString("icq.register.url");
  1307.   dump("SURESH: regLink = " + regLink + "\n");
  1308.   openTopWin(regLink);  
  1309.   return;
  1310. }
  1311.  
  1312. function updateCurrentAppWindow()
  1313. {
  1314.   var connectionName;
  1315.   connectionName = aimPrefsManager().GetCharPref("aim.session.userconnectionname", null, true);       
  1316.   if (connectionName == "ICQ")
  1317.   {
  1318.     // Change the sessionMode to Icq. Originally in xul it was initialized to Aim by default.
  1319.     window.document.getElementById("sessionAppWatcher").setAttribute("sessionMode", "Icq");
  1320.     UpdateAppMenus("Icq");
  1321.   }
  1322. }
  1323.  
  1324. function UpdateAppMenus(sessionName)
  1325. {
  1326.   switch (sessionName) {
  1327.         case "Icq": document.getElementById('menu_File_Icq').removeAttribute("hidden");
  1328.                     document.getElementById('menu_File').setAttribute("hidden", "true");
  1329.                     document.getElementById('editOptionsid_Icq').removeAttribute("hidden");
  1330.                     document.getElementById('editOptionsid').setAttribute("hidden", "true");
  1331.                     break;
  1332.         case "Aim": document.getElementById('menu_File_Icq').setAttribute("hidden", "true");
  1333.                     document.getElementById('menu_File').removeAttribute("hidden");
  1334.                     document.getElementById('editOptionsid_Icq').setAttribute("hidden", "true");
  1335.                     document.getElementById('editOptionsid').removeAttribute("hidden");
  1336.                     break;   
  1337.   }
  1338.   
  1339. }
  1340.  
  1341. /*
  1342.  * Name: cmdRename
  1343.  * Arguments: none. 
  1344.  * Description: This function is called by command handler of cmd_rename. It opens the add buddy dialog from which user can remane
  1345.  * Return Value: none
  1346.  * Author: Prassanna<prass@netscape.com> 
  1347.  */
  1348.  
  1349. function cmdRename()
  1350. {
  1351.    var user=getSelectedScreenName();
  1352.    var tree = getSelectedTreeName();
  1353.    var currentIndex = tree.currentIndex;
  1354.    var rangeCount = tree.treeBoxObject.selection.getRangeCount();
  1355.    if (rangeCount > 1 || rangeCount < 1) { 
  1356.      // We dont support multiple selectetion for rename :-(
  1357.      aimErrorBox(aimString("msg.SelectContact"));
  1358.      return;
  1359.      }
  1360.    var view = tree.treeBoxObject.view;
  1361.    var parentIndex = view.getParentIndex(currentIndex);
  1362.    if (currentIndex > 0) {
  1363.        var groupResource = GetBuddyResource(tree, parentIndex);
  1364.        var groupName = GetBuddyAttribute(tree, groupResource, "Name");
  1365.    }
  1366.    if (user) {
  1367.      openDialog("chrome://aim/content/RenameBuddy.xul", "", "modal=yes,titlebar,chrome,centerscreen", groupName, user);
  1368.    }
  1369.    else
  1370.      aimErrorBox(aimString("msg.SelectContact"));
  1371. }
  1372.  
  1373.  
  1374. /*
  1375. * Name: cmdRequestAuth
  1376. * Arguments: none. 
  1377. * Description: This function is called by command handler of cmd_rerequest auth. It chooses the appropriate tree where
  1378. * the event is triggered from and checks to see if there is a screenName attribute on the selected node. Then it opens
  1379. * the authorization request window with the screenname.
  1380. * Return Value: none
  1381. * Author: Prassanna<prass@netscape.com> 
  1382. */
  1383.  
  1384. function cmdRequestAuth()
  1385. {
  1386.   var auth_msg=aimString("icq.rerequestauth");
  1387.   var user=getSelectedScreenName();
  1388.   var isinlist = new Object();
  1389.   aimFeedbagManager().IsInAuthList(user, isinlist);
  1390.    // Ifin auth await group open rerequest auth window
  1391.   if (isinlist.value == true) {
  1392.     window.openDialog('chrome://aim/content/icqAuthOutgoing.xul','_blank','chrome,all,dialog=no',user, auth_msg);
  1393.     }
  1394.   else
  1395.     aimErrorBox(aimString("msg.authtryagain"));  
  1396. }