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 / aimHelpers.js < prev    next >
Encoding:
JavaScript  |  2002-06-24  |  50.5 KB  |  1,585 lines

  1. // Various IDL interfaces 
  2. var CachedAimServiceClass = null;
  3. var CachedAimManager = null;
  4. var CachedAimSession = null;
  5. var CachedAimLocateManager = null;
  6. var CachedAimBuddyManager = null;
  7. var CachedAimOdirManager = null;
  8. var CachedAimUserLookupManager = null;
  9. var CachedAimChatManager = null;
  10. var CachedAimTalkAgent = null;
  11. var CachedAimFileXfer = null;
  12. var CachedAimInviteManager = null;
  13. var CachedAimPrivacy = null;
  14. var CachedAimIM = null;
  15. var CachedAimPIM = null;
  16. var CachedAimAdminManager = null;
  17. var CachedAimABInfo = null;
  18. var CachedAimFeedbagManager = null;
  19. var CachedAimWarnings = null;
  20. var CachedAimPrefsManager = null;
  21. var CachedAimStringBundle = null;
  22. var CachedAimSoundManager = null;
  23. var CachedAimDataSource = null;
  24. var CachedAimRDFServiceClass  = null;
  25. var CachedAimRDFService = null;
  26. var CachedAimRDF  = null;
  27. var CachedSessionType= null;
  28. var CachedUserConnection = null;
  29.  
  30.  
  31. /* Various IDL that represent enumerated types */
  32. var CachedAimAuthorizerState = null;
  33. var CachedAimInsertionStyles = null;
  34. var CachedAimPrivacyModes = null;
  35. var CachedAimTalkAudioMode = null;
  36.  
  37.  
  38. /*
  39.  * Function: aimRDFServiceClass()
  40.  * Arguments: None
  41.  * Return: the cached RDF service class
  42.  * Description: This function checks to see is there is already an existing CachedAimRDFServiceClass.
  43.  * If so, then the cached service class is returned. If not, then the rdf-service object is got from Components.classes
  44.  * and stored as CachedAimRDFSeriveClass.
  45. */
  46.  
  47. function aimRDFServiceClass() 
  48. {
  49.      try {
  50.       if (CachedAimRDFServiceClass == null)
  51.         CachedAimRDFServiceClass = Components.classes["@mozilla.org/rdf/rdf-service;1"];
  52.   } catch (e) {};
  53.   return CachedAimRDFServiceClass;
  54. }
  55.  
  56. /*
  57.  * Function: aimRDF()
  58.  * Arguments: None
  59.  * Return: the cached RDF service
  60.  * Description: This function checks to see is there is already an existing CachedAimRDFService.
  61.  * If so, then the cached service is returned. If not, then a getService function is called 
  62.  * on aimRDFServiceClass (See Above) and stored as CachedAimRDFSerive.
  63. */
  64.  
  65. function aimRDF()
  66. {
  67.   try {
  68.       if (CachedAimRDFService == null)
  69.         CachedAimRDFService = aimRDFServiceClass().getService(Components.interfaces.nsIRDFService);
  70.   } catch (e) {};
  71.   return CachedAimRDFService;
  72. }
  73.  
  74. /*
  75.  * Function: aimRDFDataSource()
  76.  * Arguments: None
  77.  * Return: the cached Aim DataSource
  78.  * Description: This function is called whenever the Aim DataSource is needed.
  79.  * This function checks to see is there is already an existing CachedAimDataSource.
  80.  * If so, then the cahced datasource is returned. If not, then an RDFservice is accessed through
  81.  * the RDFclass object from Components.classes array by using getservice. From the RDF service,
  82.  * the aimDataSource is obtained by using getdataSource function. This gets stored in the global 
  83.  * variable CachedAimDataSource and this gets returned.
  84. */
  85.  
  86. function aimRDFDataSource()
  87. {
  88.     try {
  89.         if (CachedAimDataSource == null) {
  90.             var RDFClass = Components.classes["@mozilla.org/rdf/rdf-service;1"];
  91.             var RDF = RDFClass.getService(Components.interfaces.nsIRDFService);
  92.             CachedAimDataSource = RDF.GetDataSource("rdf:AIM");
  93.         }
  94.     } catch (e) {};
  95.  
  96.     return CachedAimDataSource;
  97. }
  98.  
  99. /*
  100.  * Function: aimServiceClass()
  101.  * Arguments: None
  102.  * Return: the cached Aim Service class
  103.  * Description: This function returns the IMService class object.
  104.  * IMService class is one of the classes in the Components.classes array which can be
  105.  * uniquely identified by the ProgID of "@netscape.com/aim/IMManager;1". 
  106. */
  107.  
  108. function aimServiceClass() 
  109. {
  110.   try {
  111.       if (CachedAimServiceClass == null)
  112.         CachedAimServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  113.   } catch (e) {};
  114.   return CachedAimServiceClass;
  115. }
  116.  
  117. /*
  118.  * Function: aimManager()
  119.  * Arguments: None
  120.  * Return: the IMManager service
  121.  * Description: This function is called whenever the Aim Manager service is needed.
  122.  * It checks to see if there is an existing instance of CachedAimManager available. If it does, that is returned.
  123.  * If not, then the AimManager service is obtained from the aimServiceClass() (See Above) 
  124.  * and stored in the CachedAimManager which is returned.
  125. */
  126.  
  127. function aimManager()
  128. {
  129.   try {
  130.       if (CachedAimManager == null)
  131.         CachedAimManager = aimServiceClass().getService(Components.interfaces.nsIIMManager);
  132.   } catch (e) {};
  133.   return CachedAimManager;
  134. }
  135.  
  136. /*
  137.  * Function: aimSession()
  138.  * Arguments: None
  139.  * Return: the AimSession interface
  140.  * Description: This function is either returns(if it already exists) or queries for it and
  141.  * holds the nsIAimSession interface in the CachedAimSession global variable.
  142. */
  143.  
  144. function aimSession()
  145. {
  146.   try {
  147.       if(CachedAimSession == null)
  148.         CachedAimSession = aimManager().QueryInterface(Components.interfaces.nsIAimSession);
  149.   } catch (e) {}; 
  150.   return CachedAimSession;
  151. }
  152.  
  153. /*
  154.  * Function: aimPrivacy()
  155.  * Arguments: None
  156.  * Return: the AimPrivacy interface
  157.  * Description: This function either returns(if it already exists) or queries for it and
  158.  * holds the nsIAimPrivacy interface in the CachedAimPrivacy global variable.
  159. */
  160.  
  161. function aimPrivacy()
  162. {
  163.   try {
  164.       if(CachedAimPrivacy == null)
  165.         CachedAimPrivacy = aimManager().QueryInterface(Components.interfaces.nsIAimPrivacy);
  166.   } catch (e) {}; 
  167.   return CachedAimPrivacy;
  168. }
  169.  
  170. /*
  171.  * Function: aimBuddyManager()
  172.  * Arguments: None
  173.  * Return: the AimBuddy interface
  174.  * Description: This function either returns(if it already exists) or queries for it and
  175.  * holds the nsIAimBuddy interface in the CachedAimBuddyManager global variable.
  176. */
  177.  
  178. function aimBuddyManager()
  179. {
  180.   try {
  181.       if(CachedAimBuddyManager == null)
  182.         CachedAimBuddyManager = aimManager().QueryInterface(Components.interfaces.nsIAimBuddy);
  183.   } catch (e) {}; 
  184.   return CachedAimBuddyManager;
  185. }
  186.  
  187. /*
  188.  * Function: aimLocateManager()
  189.  * Arguments: None
  190.  * Return: the AimLocateManager interface
  191.  * Description: This function either returns(if it already exists) or queries for it and
  192.  * holds the nsIAimLocateManager interface in the CachedAimLocateManager global variable.
  193. */
  194.  
  195. function aimLocateManager()
  196. {
  197.   try {
  198.       if(CachedAimLocateManager == null)
  199.         CachedAimLocateManager = aimManager().QueryInterface(Components.interfaces.nsIAimLocateManager);
  200.   } catch (e) {}; 
  201.   return CachedAimLocateManager;
  202. }
  203.  
  204.  
  205. /*
  206.  * Function: aimOdirManager()
  207.  * Arguments: None
  208.  * Return: the AimOdirManager interface
  209.  * Description: This function either returns(if it already exists) or queries for it and
  210.  * holds the nsIAimOdirManager interface in the CachedAimOdirManager global variable.
  211. */
  212.  
  213. function aimOdirManager()
  214. {
  215.   try {
  216.       if(CachedAimOdirManager == null)
  217.         CachedAimOdirManager = aimManager().QueryInterface(Components.interfaces.nsIAimOdirManager);
  218.   } catch (e) {}; 
  219.   return CachedAimOdirManager;
  220. }
  221.  
  222. /*
  223.  * Function: aimUserLookupManager()
  224.  * Arguments: None
  225.  * Return: the AimUserLookupManager interface
  226.  * Description: This function either returns(if it already exists) or queries for it and
  227.  * holds the nsIAimUserLookupManager interface in the CachedAimUserLookupManager global variable.
  228. */
  229.  
  230. function aimUserLookupManager()
  231. {
  232.   try {
  233.       if(CachedAimUserLookupManager == null)
  234.         CachedAimUserLookupManager = aimManager().QueryInterface(Components.interfaces.nsIAimUserLookupManager);
  235.   } catch (e) {}; 
  236.   return CachedAimUserLookupManager;
  237. }
  238.  
  239. /*
  240.  * Function: aimChatManager()
  241.  * Arguments: None
  242.  * Return: the AimChatManager interface
  243.  * Description: This function either returns(if it already exists) or queries for it and
  244.  * holds the nsIAimChatManager interface in the CachedAimChatManager global variable.
  245. */
  246.  
  247. function aimChatManager()
  248. {
  249.   try {
  250.       if(CachedAimChatManager == null)
  251.         CachedAimChatManager = aimManager().QueryInterface(Components.interfaces.nsIAimChatManager);
  252.   } catch (e) {}; 
  253.   return CachedAimChatManager;
  254. }
  255.  
  256. /*
  257.  * Function: aimLocateManager()
  258.  * Arguments: None
  259.  * Return: the AimTalkAgent interface
  260.  * Description: This function either returns(if it already exists) or queries for it and
  261.  * holds the nsIAimTalkAgent interface in the CachedAimTalkAgent global variable.
  262. */
  263.  
  264. function aimTalkAgent()
  265. {
  266.   try {
  267.       if(CachedAimTalkAgent == null)
  268.         CachedAimTalkAgent = aimManager().QueryInterface(Components.interfaces.nsIAimTalkAgent);
  269.   } catch (e) {}; 
  270.   return CachedAimTalkAgent;
  271. }
  272.  
  273.  
  274.  
  275. function fileXfer()
  276. {
  277.   try {
  278.           if(CachedAimFileXfer == null)
  279.             CachedAimFileXfer = aimManager().QueryInterface(Components.interfaces.nsIAimFileXfer);
  280.   } catch (e) {};
  281.   return CachedAimFileXfer;
  282. }
  283.  
  284.  
  285. /*
  286.  * Function: aimInviteManager()
  287.  * Arguments: None
  288.  * Return: the AimInviteManager interface
  289.  * Description: This function either returns(if it already exists) or queries for it and
  290.  * holds the nsIAimInviteManager interface in the CachedAimInviteManager global variable.
  291. */
  292.  
  293. function aimInviteManager()
  294. {
  295.   try {
  296.       if(CachedAimInviteManager == null)
  297.         CachedAimInviteManager = aimManager().QueryInterface(Components.interfaces.nsIAimInviteManager);
  298.   } catch (e) {}; 
  299.   return CachedAimInviteManager;
  300. }
  301.  
  302. /*
  303.  * Function: aimSoundManager()
  304.  * Arguments: None
  305.  * Return: the AimSoundManager interface
  306.  * Description: This function either returns(if it already exists) or queries for it and
  307.  * holds the nsIAimSoundManager interface in the CachedAimSoundManager global variable.
  308. */
  309.  
  310. function aimSoundManager()
  311. {
  312.   try {
  313.       if(CachedAimSoundManager == null)
  314.         CachedAimSoundManager = aimManager().QueryInterface(Components.interfaces.nsIAimSoundManager);
  315.   } catch (e) {}; 
  316.   return CachedAimSoundManager;
  317. }
  318.  
  319. /*
  320.  * Function: aimIM()
  321.  * Arguments: None
  322.  * Return: the AimIM interface
  323.  * Description: This function either returns(if it already exists) or queries for it and
  324.  * holds the nsIAimIM interface in the CachedAimIM global variable.
  325. */
  326.  
  327. function aimIM()
  328. {
  329.   try {
  330.       if(CachedAimIM == null)
  331.         CachedAimIM = aimManager().QueryInterface(Components.interfaces.nsIAimIM);
  332.   } catch (e) {}; 
  333.   return CachedAimIM;
  334. }
  335.  
  336. /*
  337.  * Function: aimAdminManager()
  338.  * Arguments: None
  339.  * Return: the AimAdminManager interface
  340.  * Description: This function either returns(if it already exists) or queries for it and
  341.  * holds the nsIAimAdminManager interface in the CachedAimAdminManager global variable.
  342. */
  343.  
  344. function aimAdminManager()
  345. {
  346.   try {
  347.       if(CachedAimAdminManager == null)
  348.         CachedAimAdminManager = aimManager().QueryInterface(Components.interfaces.nsIAimAdminManager);
  349.   } catch (e) {}; 
  350.   return CachedAimAdminManager;
  351. }
  352.  
  353. /*
  354.  * Function: aimABInfo()
  355.  * Arguments: None
  356.  * Return: the AimABInfo interface
  357.  * Description: This function either returns(if it already exists) or queries for it and
  358.  * holds the nsIAimABInfo interface in the CachedAimABInfo global variable.
  359. */
  360.  
  361. function aimABInfo()
  362. {
  363.   try {
  364.       if(CachedAimABInfo == null)
  365.         CachedAimABInfo = aimManager().QueryInterface(Components.interfaces.nsIAimABInfo);
  366.   } catch (e) {}; 
  367.   return CachedAimABInfo;
  368. }
  369.  
  370. /*
  371.  * Function: aimFeedbagManager()
  372.  * Arguments: None
  373.  * Return: the AimFeedbagManager interface
  374.  * Description: This function either returns(if it already exists) or queries for it and
  375.  * holds the nsIAimFeedbagManager interface in the CachedAimFeedbagManager global variable.
  376. */
  377.  
  378. function aimFeedbagManager()
  379. {
  380.   try {
  381.       if(CachedAimFeedbagManager == null)
  382.         CachedAimFeedbagManager = aimManager().QueryInterface(Components.interfaces.nsIAimFeedbagManager);
  383.   } catch (e) {}; 
  384.   return CachedAimFeedbagManager;
  385. }
  386.  
  387. /*
  388.  * Function: aimWarnings()
  389.  * Arguments: None
  390.  * Return: the AimWarnings interface
  391.  * Description: This function either returns(if it already exists) or queries for it and
  392.  * holds the nsIAimWarnings interface in the CachedAimWarnings global variable.
  393. */
  394.  
  395. function aimWarnings()
  396. {
  397.   try {
  398.       if(CachedAimWarnings == null)
  399.         CachedAimWarnings = aimManager().QueryInterface(Components.interfaces.nsIAimWarnings);
  400.   } catch (e) {}; 
  401.   return CachedAimWarnings;
  402. }
  403.  
  404. /*
  405.  * Function: aimPrefsManager()
  406.  * Arguments: None
  407.  * Return: the AimPrefsManager interface
  408.  * Description: This function either returns(if it already exists) or queries for it and
  409.  * holds the nsIAimPrefsManager interface in the CachedAimPrefsManager global variable.
  410. */
  411.  
  412. function aimPrefsManager()
  413. {
  414.   try {
  415.       if(CachedAimPrefsManager == null)
  416.         CachedAimPrefsManager = aimManager().QueryInterface(Components.interfaces.nsIPrefsManager);
  417.   } catch (e) {}; 
  418.   return CachedAimPrefsManager;
  419. }
  420.  
  421. /*
  422.  * Function: aimStringBundle()
  423.  * Arguments: None
  424.  * Return: the AimLocateManager interface
  425.  * Description: This function either returns(if it already exists) or queries for it and
  426.  * holds the nsIStringBundle interface in the CachedAimStringBundle global variable.
  427. */
  428.  
  429. function aimStringBundle()
  430. {
  431.   try {
  432.       if(CachedAimStringBundle == null)
  433.         CachedAimStringBundle = aimManager().QueryInterface(Components.interfaces.nsIStringBundle);
  434.   } catch (e) {}; 
  435.   return CachedAimStringBundle;
  436. }
  437.  
  438.  
  439. // The various enumerated types/interfaces
  440. /*
  441.  * Function: aimInsertionStyles()
  442.  * Arguments: None
  443.  * Return: the AimInsertionStyles  
  444.  * Description: This function either returns(if it already exists) or queries for it and
  445.  * holds the nsIAimInsertionStyles enumerated type in the CachedAimInsertionStyles global variable.
  446. */
  447.  
  448. function aimInsertionStyles()
  449. {
  450.   try {
  451.       if(CachedAimInsertionStyles == null)
  452.         CachedAimInsertionStyles = Components.interfaces.nsAimInsertionStyles;
  453.   } catch (e) {}; 
  454.   return CachedAimInsertionStyles;
  455. }
  456.  
  457. /*
  458.  * Function: aimPrivacyModes()
  459.  * Arguments: None
  460.  * Return: the AimPrivacyModes  
  461.  * Description: This function either returns(if it already exists) or queries for it and
  462.  * holds the nsIAimPrivacyModes enumerated type in the CachedAimPrivacyModes global variable.
  463. */
  464.  
  465. function aimPrivacyModes()
  466. {
  467.   try {
  468.       if(CachedAimPrivacyModes == null)
  469.         CachedAimPrivacyModes = Components.interfaces.nsAimPrivacyModes;
  470.   } catch (e) {}; 
  471.   return CachedAimPrivacyModes;
  472. }
  473.  
  474. /*
  475.  * Function: aimNormalizeScreenName()
  476.  * Arguments: 
  477.  *    oldSN -- The original screen name
  478.  * Return: the normalised formatted screenname  
  479.  * Description: This function takes a screen name and formats all the white space charaters with 
  480.  * empty string and converts the screen name into lowercase word.
  481. */
  482.  
  483. function aimNormalizeScreenName(oldSN)
  484. {
  485.     return (oldSN.replace(/\s/gi,"")).toLowerCase();
  486. }
  487.  
  488. /*
  489.  * Function: aimIsSameScreenName()
  490.  * Arguments: 
  491.  *  sN1 -- Screen name one
  492.  *  sN2 --  Screen name two
  493.  * Return: true if both screen names are same, false if not  
  494.  * Description: It is is used to know if two formatted screen names are the same.
  495.  * The aimNormalizeScreenName (See Above) function is used to get the formatted screen names.
  496. */
  497.  
  498. function aimIsSameScreenName(sN1, sN2)
  499. {
  500.      return (aimNormalizeScreenName(sN1) == aimNormalizeScreenName(sN2))
  501. }
  502.  
  503. /* 
  504.  * Function: aimMigrateBuddyList( who )
  505.  * Arguments: 
  506.  *    who --  screen name whose buddy list needs to be migrated.
  507.  * Return: None
  508.  * Description: This function is used to migrate the buddylist of the screen name with
  509.  * which the user has signed on to the aim session. This used thr AimMigratorMigrateBuddyList 
  510.  * function of the AimMigrator service which does the actual migration.
  511.  *
  512. */
  513.  
  514. function aimMigrateBuddyList( who )
  515. {
  516.     var whoMigrate = aimPrefsManager().GetCharPref("aim.session.migrateBuddyList",null, true);
  517.     if ( !whoMigrate || whoMigrate == null || whoMigrate == undefined || whoMigrate != who ) {
  518.         return;
  519.     }
  520.     var IMServiceClass;
  521.     var pAimMigrator;
  522.     try { 
  523.         IMServiceClass = Components.classes['@netscape.com/aim/AimMigrator;1'];
  524.         if ( IMServiceClass != null ) {
  525.             try {
  526.                 pAimMigrator = IMServiceClass.getService(Components.interfaces.nsIAimMigrator);
  527.                 if ( pAimMigrator != null ) {
  528.                     pAimMigrator.AimMigratorMigrateBuddyList( who );
  529.                     aimPrefsManager().SetCharPref("aim.session.migrateBuddyList", "nobody", null, true);
  530.                 }
  531.             }
  532.             catch ( exception ) {
  533.                 // nothing
  534.             }
  535.         }
  536.     }
  537.     catch ( exception ) {
  538.         // nothing
  539.     }
  540. }
  541.  
  542. /*
  543.  * Function: html( node )
  544.  * Arguments: 
  545.  *    node  --  the parent node
  546.  * Return: the entire text content of the document tree
  547.  * Description: This function recursively walks through the entire conversation window doucment
  548.  * and stores all the values in the variable answer.
  549.  *
  550. */
  551.  
  552. function html(node)
  553. {
  554.     var answer = "";
  555.     var type = node.nodeType;
  556.     if (type == Node.ELEMENT_NODE) {
  557.       answer += "<" + node.tagName;
  558.         attributes = node.attributes;
  559.         if (null != attributes) {
  560.             var countAttrs = attributes.length;
  561.             var index = 0;
  562.             while(index < countAttrs) {
  563.                 att = attributes[index];
  564.                 if (null != att) {
  565.                     answer += " " + att.name + "=\"" + att.value + "\"";
  566.                 }
  567.                 index++
  568.             }
  569.         }
  570.  
  571.         // close tag
  572.         answer += ">";
  573.  
  574.         // recursively dump the children
  575.         if (node.hasChildNodes()) {
  576.             // get the children
  577.             var children = node.childNodes;
  578.             var length = children.length;
  579.             var count = 0;
  580.             while(count < length) {
  581.                 child = children[count]
  582.                 answer += html(child)
  583.                 count++
  584.             }
  585.             answer += "</" + node.tagName + ">";
  586.         }
  587.  
  588.  
  589.     }
  590.     // if it's a piece of text just dump the text
  591.     else if (type == Node.TEXT_NODE) {
  592.         answer += node.data;
  593.     }
  594.     return answer;
  595. }
  596.  
  597. /*
  598.  * Function: createInstance( contractid, iidName  )
  599.  * Arguments: 
  600.  *    contractid  --  'ProgID' of the component class.
  601.  *    iidName -- Interface id for the object
  602.  * Return: the XPConnect wrapper for the object with the given iid
  603.  * Description: This function is used to create an instance of class. According to the progID
  604.  * and interface ID, the instance gets created and returned.
  605.  *
  606. */
  607.  
  608. function createInstance( contractid, iidName ) {
  609.   var iid = eval( "Components.interfaces." + iidName );
  610.   return Components.classes[ contractid ].createInstance( iid );
  611. }
  612.  
  613. /*
  614.  * Function: cmdFileSave()
  615.  * Arguments: None
  616.  * Return: None;
  617.  * Description: This function is called from File_>Save menu option in the IM window.
  618.  * It takes the converstaion window document and recursively walk through each documentElement
  619.  * and stores them in a variable called answer. After traversing the entire document,
  620.  * it displays the file picker dialog. Once the user chooses a filename, the SaveConversation
  621.  * function is used to write the contents of variable into the chosen file.
  622. */
  623.  
  624. function cmdFileSave()
  625. {
  626.   var answer;
  627.   var wind = top.frames["LogWnd"];
  628.   if ( wind ) {
  629.       myhead = wind.document.getElementsByTagName("HEAD").item(0);
  630.         if (myhead == null) {
  631.             myhead = wind.document.createElement("HEAD");
  632.             myhtml = wind.document.getElementsByTagName("HTML").item(0);
  633.             myhtml.appendChild(myhead);
  634.         }
  635.         mymeta = wind.document.createElement("META");
  636.         mymeta.setAttribute("HTTP-EQUIV", "Content-Type");
  637.         mymeta.setAttribute("CONTENT", "text/html; charset=UTF-8");
  638.         myhead.appendChild(mymeta);
  639.     answer = html(wind.document.documentElement);
  640.     answer += "\n";
  641.   }
  642.   else {
  643.     return;
  644.   }
  645.   try {
  646.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  647.     // XXX i18n
  648.     fp.init(window, aimString( "title.saveconversation" ),  nsIFilePicker.modeSave);
  649.     fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterAll );
  650.         var returnCode = fp.show();
  651.     if (returnCode == nsIFilePicker.returnOK || returnCode == nsIFilePicker.returnReplace) {
  652.           var pPAimIM = aimPIMObject();
  653.             if (pPAimIM) {
  654.         pPAimIM.SaveConversation(fp.file.path, answer);
  655.             }
  656.     }
  657.   } catch (ex) {
  658.                    }
  659. }
  660.  
  661. /*
  662.  * Function: cmdFileClose()
  663.  * Arguments: None
  664.  * Return: None
  665.  * Description: This function is called from File_>Close menu item.
  666.  * It closes the current window( does not exit app).
  667. */
  668.  
  669. function cmdFileClose()
  670. {
  671.   top.close();
  672. }
  673.  
  674. /*
  675.  * Function: cmdFilePrint()
  676.  * Arguments: None 
  677.  * Return: None
  678.  * Description: This function is used to print the IM conversation window. 
  679.  * It accesses the Log window and calls the print function to print the contents.
  680. */
  681.  
  682. function cmdFilePrint(window)
  683. {
  684.   switch(window) {
  685.   case "im":
  686.           if (top.frames["LogWnd"].document.documentElement.lastChild.firstChild != null) {
  687.             // print the contents of log window
  688.             top.frames["LogWnd"].print();
  689.             return;
  690.           }
  691.           // No log window yet - print the compose window
  692.           top.editorShell.Print();
  693.           break;
  694.   case "chat":
  695.           top.frames["LogWnd"].print();
  696.           break;
  697.   }
  698. }
  699.  
  700. /*
  701.  * Function: getEnums( myInterface )
  702.  * Arguments: 
  703.  *    myInterface --  Interface whose enums needs to be obtained 
  704.  * Return: all the enumerated types in the interface
  705.  * Description: This function is used to get all the enumerated types defined in the interface.
  706.  * It loops through all the variables and checks to see if it is of type number. If it is then,
  707.  * it stores all the enums os that variable in a array called enums which is returned.
  708. */
  709.  
  710. function getEnums( myInterface )
  711. {
  712.   var enums = {};
  713.   for ( var i in myInterface ) {
  714.     if ( typeof myInterface[i] == "number" ) {
  715.       enums[i] = myInterface[i];
  716.     }
  717.   }
  718.   return enums;
  719. }
  720.  
  721. /*
  722.  * Function: MigrateDiscover()
  723.  * Arguments: None
  724.  * Return: Boolean
  725.  * Description: This function uses the Aim migrator serice to see what instant messenger 
  726.  * has been used ( to migrate from). Once that version  has been determined, it then checks
  727.  * to see if there is any defaultscreen name and password stored.
  728.  * Return true, if present. Return false if not and set screen name and password to be empty.
  729. */
  730.  
  731. function MigrateDiscover()
  732. {
  733.   var IMServiceClass;
  734.   var pAimMigrator;
  735.     try { 
  736.       IMServiceClass = Components.classes['@netscape.com/aim/AimMigrator;1'];
  737.         if ( IMServiceClass != null ) {
  738.             try {
  739.                 pAimMigrator = IMServiceClass.getService(Components.interfaces.nsIAimMigrator);
  740.                 if ( pAimMigrator != null ) {
  741.                     version = pAimMigrator.AimMigratorDiscover();
  742.                     parent.migrationSource = version;
  743.                     if ( version == null || version == "" ) {
  744.                         return false;
  745.                     }
  746.  
  747.                     var stringPref = {};
  748.                     var stringPref2 = {};
  749.                     var enums = getEnums( Components.interfaces.nsIAimMigrator );
  750.                     // get the default screen name
  751.  
  752.                     var ret = pAimMigrator.AimMigratorGetStringPref2( enums.DefaultScreenName, stringPref, stringPref2 );
  753.  
  754.                     if ( ret == true ) {
  755.                         parent.migrationScreenName = stringPref.value;
  756.                         parent.migrationPassword = stringPref2.value;
  757.                     }
  758.                     else {
  759.                         parent.migrationScreenName = "";
  760.                         parent.migrationPassword = "";
  761.                     }
  762.  
  763.                     // get the remaining screen names, if any
  764.                     var stringPrefVec = {}; 
  765.                     var vecSize = {};
  766.                     stringPrefVec = pAimMigrator.AimMigratorGetStringVectorPref( enums.ScreenName, vecSize );
  767.  
  768.                     var i;
  769.                     parent.migrationScreenNameVecSize = vecSize;
  770.                     parent.migrationScreenNameVec = stringPrefVec;
  771.  
  772.                     return ret;        // all we care about is did we get a default screenname
  773.                 }
  774.             }
  775.             catch(exception) {
  776.                 return false;
  777.             }
  778.         }    
  779.     }
  780.   catch(exception) {
  781.         return false;
  782.     }
  783. }
  784.  
  785. /*
  786.  * Function: AimOnlineAway()
  787.  * Arguments: None 
  788.  * Return: Boolean
  789.  * Description: This function is used to check whether user is in away state. 
  790.  * This function uses the RDF service to access Aim Session from the Aimdatasource.
  791.  * From the aimSession, the value of the Sessionstate is retrieved and checked to see if it
  792.  * is "OnlineAway". If it is return true, otherwise return false.
  793. */
  794.  
  795. function AimOnlineAway()
  796. {
  797.     var SessionState = aimRDF().GetResource("http://home.netscape.com/NC-rdf#OnlineState");
  798.     var dataSource = aimRDFDataSource();
  799.     var AimSession = aimRDF().GetResource("NC:AIM/Session");
  800.     var target = dataSource.GetTarget(AimSession, SessionState, true);
  801.     var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  802.     if ("OnlineAway" == state)
  803.         return true;
  804.     return false;
  805. }
  806.  
  807. /*
  808.  * Function: ComeBack()
  809.  * Arguments: None 
  810.  * Return: None
  811.  * Description: This function is used when the I'mBack button is clicked or 
  812.  * whenever the user needs to get out of the "Away" state. It sets a null away message
  813.  * using the SetUserInfoAwayMessage function. 
  814. */
  815.  
  816. function ComeBack()
  817. {
  818.     locateManager = aimLocateManager();
  819.     if ( locateManager ) 
  820.         locateManager.SetUserInfoAwayMessage(null);
  821. }
  822.  
  823. /*
  824.  * Function: AimtoOpenWindowByType( inType, uri )
  825.  * Arguments:  
  826.  *    inType  --  name of the window type
  827.  *    uri   --  uri of the window to be opened
  828.  * Return: None
  829.  * Description: This function uses the windows mediator service to get the most recent window
  830.  * of the given type. If there is a window with the same type, then that window is brought to 
  831.  * focus. If no window exists, then a new window get opened.
  832. */
  833.  
  834. function AimtoOpenWindowByType( inType, uri )
  835. {
  836.   var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  837.   var     windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  838.   var topWindow = windowManagerInterface.getMostRecentWindow( inType );
  839.   if ( topWindow ) {
  840.     topWindow.focus();
  841.   } 
  842.   else
  843.     window.openDialog(uri, "_blank", "chrome,all,dialog=no", "Setup");
  844. }                     
  845.  
  846. /*
  847.  * Function: aimGlobalCmdHelp()
  848.  * Arguments: None 
  849.  * Return: None
  850.  * Description: For netbusiness instant messenger client, this will call the AimtoOpenWindwoByType 
  851.  * (See Above) function with help_nim.xul. For NIM, it is called with help.xul?im. 
  852.  * These files in turn contain the help contents for the respective products.
  853. */
  854.  
  855. function aimGlobalCmdHelp()
  856. {
  857.    if (isIcq()) {
  858.        AimtoOpenWindowByType("help:icq","chrome://help/content/help.xul?icq"); 
  859.    }
  860.    else {
  861.           AimtoOpenWindowByType("help:im","chrome://help/content/help.xul?im"); 
  862.    }
  863. }
  864.     
  865.  
  866. /*
  867.  * Function: AimgoClickThrobber(urlPref)
  868.  * Arguments: 
  869.  *  urlPref --  input url which should be loaded
  870.  * Return: None
  871.  * Description: For netbusiness instant messenger client, this will get the localised url.
  872.  * This url is then loaded in the default browser.
  873.  * for NIM, this just loads the given url in the browser.
  874. */
  875.  
  876. function AimgoClickThrobber(urlPref)
  877. {
  878.         goClickThrobber( urlPref );
  879. }
  880.  
  881. /*
  882.  * Function: GetRdfFileUrl(def_name, chg_name)
  883.  * Arguments: 
  884.  *    def_name  --  default file that needs to be copied in the case of new profile  
  885.  *    chg_name  --  the name of the file which will be appended to screen name and stores the data.
  886.  * Return: the url of the file
  887.  * Description: This function is used to get the rdf file for away messages/sign on a friend invites 
  888.  * for a given screen name. Using the directory service, the default profile and the user profile is
  889.  * obtained.  A default file is created by making a copy of the default profile file.
  890.  * This will be named after the def_name (first input parameter). e.g. in the case of away messages 
  891.  * it will be called default-messages.rdf.  A new file which is a copy of the user's profile is created.
  892.  * It will be named after the screen name for the current session. According to the second input 
  893.  * parameter it will be further identified. So e.g. in case of away message, the file will be named 
  894.  * as <screenname><chg_name>.rdf. If this file cannot be created from the user's profile, then default 
  895.  * profile file is copied over and this will now be called after the session's screen name and chg_name param. 
  896.  * The exact identity and location of this file is then obtained  by using nsIFileURL and 
  897.  * the unique url gets returned.
  898. */
  899. function GetRdfFileUrl(def_name, chg_name)
  900. {                                                                               
  901.     var directoryService  =  Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
  902.     var userProfile = directoryService.get("ProfD", Components.interfaces.nsIFile);
  903.     var defaultProfile = directoryService.get("profDef", Components.interfaces.nsIFile); // profile defaults
  904.     if (!defaultProfile.exists())                                   
  905.         defaultProfile = directoryService.get("ProfDefNoLoc", Components.interfaces.nsIFile); // profile defaults
  906.     var defaultInviteFile = defaultProfile.clone();                         
  907.     defaultInviteFile.append(def_name);                                     
  908.   var screenName = "";                                                
  909.   myPref = aimPrefsManager();                                         
  910.   if ( myPref ) {                                                         
  911.       try {                                                           
  912.             screenName = myPref.GetCharPref( "aim.session.screenname" , null, false);
  913.           }
  914.       catch(e) {                                                      
  915.              screenName = "";                                        
  916.                }
  917.     }   
  918.     if ( screenName != "" ) {                                               
  919.         screenName = screenName + ".";                                  
  920.   }
  921.     else                                                            
  922.   {
  923.       return;                                         
  924.   }
  925.     var InviteListFile = userProfile.clone();
  926.     InviteListFile.append(screenName+chg_name);                             
  927.     if (!InviteListFile.exists()) {                                         
  928.           try {
  929.               defaultInviteFile.copyTo(userProfile,screenName+chg_name);     
  930.         }
  931.             catch (e) {
  932.                       }
  933.             InviteListFile = userProfile.clone();                           
  934.       InviteListFile.append(screenName+chg_name);                     
  935.       if (!InviteListFile.exists())    {
  936.         // Something is wrong - This should never happen
  937.         return;
  938.       }                               
  939.     }                                                                       
  940.   var InviteFileURL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
  941.     InviteFileURL.file = InviteListFile;
  942.     return( InviteFileURL.spec );                                           
  943. }  
  944.  
  945. /*
  946.  * Function: getsidebarframe()
  947.  * Arguments: None
  948.  * Return: the frame which contains the sidebarbarpanel.xul
  949.  * Description: This function walks through the list of frames. If there is only one frame, then that frame is
  950.  * returned. Otherwise from the list, the frame which contains SidebarPanel.xul is returned.
  951. */
  952.  
  953. function getsidebarframe()
  954. {
  955.   var frame_list=window.frames;
  956.      if (frame_list.length==0)
  957.        return window;
  958.   for (var i=0; i<frame_list.length; i++) {
  959.        if (frame_list[i].location =="chrome://aim/content/SidebarPanel.xul")
  960.              return frame_list[i];
  961.      }
  962.     return window;    
  963.                                                                              
  964. function aimString(name)
  965. {
  966.  
  967.     var myAimSession = aimSession();
  968.     if ( myAimSession ) {
  969.         var pIStringBundle = aimSession().QueryInterface(Components.interfaces.nsIStringBundle);
  970.         if (pIStringBundle)
  971.             return pIStringBundle.GetStringFromName(name);
  972.     }
  973.     return "";
  974. }
  975.  
  976. function aimErrorBox(errorText)
  977. {
  978.     top.alert(errorText);
  979. }
  980.  
  981.  
  982. /*
  983.  * Function: processAwayMsg(msg)
  984.  *
  985.  * Arguments: msg
  986.  * 
  987.  * Return: msg with real away msgs.
  988.  *
  989.  * Description: This fn takes a msg (like "Hi %n, howdy?") and converts to real away msgs (like "Hi screenname, howdy?").
  990.  *
  991.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  992.  *              
  993. */
  994.  
  995. function processAwayMsg(msg)
  996. {
  997.   var sn;
  998.   var pIAimSession = aimSession();
  999.   if(pIAimSession)
  1000.     sn = pIAimSession.CurrentScreenName;
  1001.   else
  1002.     sn = "";
  1003.   var date = new Date();
  1004.   var dateService = Components.classes["@mozilla.org/intl/scriptabledateformat;1"].getService(Components.interfaces.nsIScriptableDateFormat);
  1005.   var time =  dateService.FormatTime(
  1006.                               "",
  1007.                               dateService.timeFormatNoSeconds,
  1008.                               date.getHours(),
  1009.                               date.getMinutes(),
  1010.                               date.getSeconds());
  1011.  
  1012.   var day =  dateService.FormatDate(
  1013.                               "",
  1014.                               dateService.dateFormatShort,
  1015.                               date.getFullYear(),
  1016.                               date.getMonth()+1,
  1017.                               date.getDate());
  1018.  
  1019.   msg = msg.replace(/%t/gi, time);
  1020.   msg = msg.replace(/%d/gi, day);
  1021.   msg = msg.replace(/%n/gi, sn);
  1022.   return msg;
  1023. }
  1024.  
  1025.  
  1026.  /******
  1027.   * Returns a string with the difference between two dates looking like: "x days, x hours, x minutes."
  1028.   * Both parameters are dates in seconds since 1/1/1970 00:00:00.
  1029.   ******/
  1030.  
  1031. function getPrettyDateDiff(aDate2, aDate1)
  1032. {
  1033.   var diff = aDate2-aDate1;
  1034.   var pretty = "";
  1035.    
  1036.   var dayDiff = Math.floor(diff / 86400);
  1037.   diff %= 86400;
  1038.   if (dayDiff > 0) {
  1039.     pretty += dayDiff + " day" + (dayDiff == 1 ? "" : "s");
  1040.   }
  1041.    
  1042.   var hourDiff = Math.floor(diff / 3600);
  1043.   diff %= 3600;
  1044.   if (hourDiff > 0) {
  1045.     pretty += (pretty.length > 0 ? ", " : "") + hourDiff + " " + aimString("tooltip.hour") + (hourDiff == 1 ? "" : "s");
  1046.   }
  1047.    
  1048.   var minDiff = Math.floor(diff / 60);
  1049.   if (minDiff > 0) {
  1050.     pretty += (pretty.length > 0 ? ", " : "") + minDiff + " " + aimString("tooltip.minute") + (minDiff == 1 ? "" : "s");
  1051.   }
  1052.    
  1053.   return pretty;
  1054. }
  1055.  
  1056.  
  1057. /*
  1058.  * Function: validateEmailAddress()
  1059.  *
  1060.  * Arguments: email address
  1061.  * 
  1062.  * Return: boolean true if the email address is valid
  1063.  *         boolean false if the email address is invalid
  1064.  *
  1065.  * Description: Called from the above function to validate the email address. Length and special characters are validated.
  1066.  *
  1067.  * Author: Suresh Kasinathan<suresh@netscape.com> 11/15/01
  1068.  *        
  1069. */
  1070.  
  1071. function validateEmailAddress(emailElement)
  1072. {
  1073.   // var email = emailElement.value;
  1074.   var emailArray = emailElement.split('@');
  1075.  
  1076.   if (emailArray.length != 2 ||
  1077.       !emailArray[0].length ||
  1078.       !emailArray[1].length || 
  1079.       containsIllegalCharacter(emailArray[0]) ||
  1080.       containsIllegalCharacter(emailArray[1]) ) {
  1081.         aimErrorBox(aimString("msg.enterValidEmail"));
  1082.         return false;
  1083.   }
  1084.     
  1085.   return true;
  1086. }
  1087.  
  1088. /*
  1089.  * Function: containsIllegalCharacter()
  1090.  *
  1091.  * Arguments: string
  1092.  * 
  1093.  * Return: boolean true if the string doesnot contain illegal characters.
  1094.  *         boolean false if the string contain illegal characters.
  1095.  *
  1096.  * Description: This function checks for common illegal characters. 
  1097.  *
  1098.  * Author: Suresh Kasinathan<suresh@netscape.com> 11/15/01
  1099.  *        
  1100. */
  1101.  
  1102. function containsIllegalCharacter(aString)
  1103. {
  1104.   for (var i=0; i < aString.length; i++) {
  1105.     var code = aString.charCodeAt(i);
  1106.     if (code > 127)
  1107.       return true; // non-ASCII
  1108.     else if (code == 9 || code == 10 || code == 11 || code == 32)
  1109.       return true; // white space
  1110.     else if (code == 64)
  1111.       return true; // '@'
  1112.   }
  1113.   return false;
  1114.  
  1115.  
  1116. /* Returns the selected tree/tree name based on the selected tab (online or listsetup) */
  1117. function getSelectedTreeName()
  1118. {
  1119.   var sidebarframe=getsidebarframe();
  1120.   var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  1121.   var tree;
  1122.   if (tab.selectedIndex == 0)
  1123.     tree = sidebarframe.document.getElementById("OnlineBuddies");
  1124.   else
  1125.     tree = sidebarframe.document.getElementById("ListSetup");
  1126.  
  1127.   return tree;
  1128. }
  1129.  
  1130. /* Returns the column name for the selected tab*/
  1131. function getSelectedTabName()
  1132. {
  1133.   var sidebarframe=getsidebarframe();
  1134.   var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  1135.   if (tab.selectedIndex == 0)
  1136.     return "BuddiesCol"
  1137.   else
  1138.     return "ListSetupCol"
  1139. }
  1140.  
  1141. /*this returns the target for the given source, attribute(property) in the tree*/
  1142. function GetBuddyAttribute(tree, source, attribute)
  1143. {
  1144.   var RDF = aimRDF();
  1145.   var property = RDF.GetResource("http://home.netscape.com/NC-rdf#" + attribute);
  1146.   var target = tree.database.GetTarget(source, property, true);
  1147.   if (target)
  1148.     target = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  1149.   return target;
  1150. }
  1151.  
  1152. /* returns the resource at the given index */
  1153. function GetBuddyResource(tree, index)
  1154. {
  1155.   var RDF = aimRDF();
  1156.   var item = tree.contentView.getItemAtIndex(index);
  1157.   return RDF.GetUnicodeResource(item.id);
  1158. }
  1159.  
  1160. /*
  1161. * Name: getSelectedScreenName
  1162. * Arguments: tree 
  1163. * Description:
  1164. *  This function returns the selected item's screenname value if selected item has this attribute. 
  1165. * Return Value: screenName
  1166. * Author: Prassanna<prass@netscape.com>, Joseph Elwell<jelwell@netscape.com>
  1167. */
  1168.  
  1169. function getSelectedScreenName()
  1170. {
  1171.   var tree = getSelectedTreeName();
  1172.   var col = getSelectedTabName();
  1173.   if (!tree || !col) return;
  1174.   var screenName = null;
  1175.   var currentIndex = tree.currentIndex;
  1176.   if (currentIndex > 0) {
  1177.     var isContainer = tree.treeBoxObject.view.isContainer(currentIndex);
  1178.     //if it is a container (groups or Offline group) return null
  1179.     if (!isContainer) {
  1180.       var buddyResource = GetBuddyResource(tree, currentIndex);
  1181.       var screenName = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  1182.     }
  1183.   }
  1184.   return screenName;
  1185. }
  1186.  
  1187. /*
  1188. * Name: checkInputEmail
  1189. * Arguments: input email value 
  1190. * Description:
  1191. *  This function returns a boolean value based on whether the input is a valid email-address
  1192. * Return Value: boolean
  1193. * Author: Prassanna<prass@netscape.com> 
  1194. */
  1195.  
  1196.  
  1197. function checkInputEmail( email)
  1198. {
  1199.   var emailArray=email.split('@');
  1200.   var emailArray2=email.split('.');
  1201.   var alertText;
  1202.   if (email.length =="") {
  1203.     aimErrorBox(aimString("msg.Invalidemail"));
  1204.     return false;
  1205.   }
  1206.   if (emailArray.length != 2 || emailArray[0] == "" || emailArray[1] == "") {
  1207.     aimErrorBox(aimString("msg.Invalidemail"));
  1208.     return false;
  1209.   }
  1210.   if (emailArray2.length < 2) { 
  1211.     aimErrorBox(aimString("msg.Invalidemail"));
  1212.     return false;
  1213.   }
  1214.   for (i=0; i<emailArray2.length; i++)
  1215.   {
  1216.     if (emailArray2[i] == "") {
  1217.       aimErrorBox(aimString("msg.Invalidemail"));
  1218.       return false;
  1219.     }
  1220.   }
  1221.   return true;
  1222. }
  1223.  
  1224. /*
  1225. * Name: setConnectionInfo
  1226. * Arguments: connectionName, aClient, screenName
  1227. * Description:
  1228. *  This function sets current connection
  1229. * Return Value: true
  1230. * Author: A Averbukh<anatoliya@netscape.com> 
  1231. */
  1232. function setConnectionInfo (connectionName, aClient, screenName)
  1233. {
  1234.     var curSession;
  1235.     if (connectionName =="AIM")
  1236.         curSession = 0;
  1237.     else // ICQ
  1238.         curSession = 2;
  1239. dump("SURESH: curSession=" + curSession + "\n");
  1240.        
  1241.  
  1242.  
  1243.     manPref = aimPrefsManager();
  1244.  
  1245.     var Host           = manPref.GetCharPrefEdit ("aim.session.host",           null, 2, "", curSession);
  1246.     var Port           = manPref.GetIntPrefEdit  ("aim.session.port",           null, 2, "", curSession);
  1247.     var ProxyHost      = manPref.GetCharPrefEdit ("aim.session.proxyhost",      null, 2, "", curSession);
  1248.     var ProxyPort      = manPref.GetIntPrefEdit  ("aim.session.proxyport",      null, 2, "", curSession);
  1249.     var ProxyUser      = manPref.GetWCharPrefEdit("aim.session.proxyuser",      null, 2, "", curSession);
  1250.     var ProxyPassword  = manPref.GetWCharPrefEdit("aim.session.proxypassword",  null, 2, "", curSession);
  1251.     var ProxyProtocol  = manPref.GetIntPrefEdit  ("aim.session.proxyprotocol",  null, 2, "", curSession);
  1252.     var useProxy       = manPref.GetBoolPrefEdit ("aim.session.isproxy",        null, 2, "", curSession);
  1253.     var ConnectionType = manPref.GetIntPrefEdit  ("aim.session.connectiontype", null, 2, "", curSession);                                                
  1254.  
  1255. dump("Host=" + Host + " Port=" + Port + " ProxyHost=" + ProxyHost + " ProxyPort=" + ProxyPort + "\n");
  1256. dump("ProxyUser=" + ProxyUser + " ProxyPassword=" + ProxyPassword + " ProxyProtocol=" + ProxyProtocol + "\n");
  1257. dump("useProxy=" + useProxy + " ConnectionType=" + ConnectionType + "\n");
  1258.  
  1259.  
  1260.     if (aClient == "im") { // internal session
  1261.  
  1262.         manPref.SetIntPrefEdit  ("aim.internal.intsessiontype",  curSession,    
  1263.                                  null, 1, "", -1);
  1264.         manPref.SetWCharPrefEdit("aim.internal.intname",         connectionName, 
  1265.                                  null, 1, "", -1);
  1266.         manPref.SetCharPrefEdit("aim.internal.inthost",             Host,           
  1267.                                  null, 1, "", -1);                  
  1268.         manPref.SetIntPrefEdit  ("aim.internal.intport",            Port,           
  1269.                                  null, 1, "", -1);                  
  1270.         manPref.SetCharPrefEdit("aim.internal.intproxyhost",        ProxyHost,      
  1271.                                  null, 1, "", -1);                  
  1272.         manPref.SetIntPrefEdit  ("aim.internal.intproxyport",       ProxyPort,      
  1273.                                  null, 1, "", -1);                  
  1274.         manPref.SetWCharPrefEdit("aim.internal.intproxyuser",       ProxyUser,      
  1275.                                  null, 1, "", -1);                  
  1276.         manPref.SetWCharPrefEdit("aim.internal.intproxypassword",   ProxyPassword,  
  1277.                                  null, 1, "", -1);                  
  1278.         manPref.SetIntPrefEdit  ("aim.internal.intproxyprotocol",   ProxyProtocol,  
  1279.                                  null, 1, "", -1);
  1280.         manPref.SetBoolPrefEdit ("aim.internal.intisproxy",         useProxy,                 
  1281.                                  null, 1, "", -1);
  1282.         manPref.SetIntPrefEdit  ("aim.internal.intconnectiontype",  ConnectionType,                 
  1283.                                  null, 1, "", -1);                                           
  1284.     }
  1285.     else { //external session
  1286.  
  1287.         manPref.SetIntPrefEdit  ("aim.internal.extsessiontype",  curSession,    
  1288.                                  null, 1, "", -1);
  1289.         manPref.SetWCharPrefEdit("aim.internal.extname",         connectionName, 
  1290.                                  null, 1, "", -1);
  1291.         manPref.SetCharPrefEdit("aim.internal.exthost",           Host,           
  1292.                                  null, 1, "", -1);
  1293.         manPref.SetIntPrefEdit  ("aim.internal.extport",          Port,           
  1294.                                  null, 1, "", -1);
  1295.         manPref.SetCharPrefEdit("aim.internal.extproxyhost",      ProxyHost,      
  1296.                                  null, 1, "", -1);
  1297.         manPref.SetIntPrefEdit  ("aim.internal.extproxyport",     ProxyPort,      
  1298.                                  null, 1, "", -1);
  1299.         manPref.SetWCharPrefEdit("aim.internal.extproxyuser",     ProxyUser,      
  1300.                                  null, 1, "", -1);
  1301.         manPref.SetWCharPrefEdit("aim.internal.extproxypassword", ProxyPassword,  
  1302.                                  null, 1, "", -1);
  1303.         manPref.SetIntPrefEdit  ("aim.internal.extproxyprotocol", ProxyProtocol,  
  1304.                                  null, 1, "", -1);
  1305.         manPref.SetBoolPrefEdit ("aim.internal.extisproxy",       useProxy,   
  1306.                                  null, 1, "", -1);  
  1307.         manPref.SetIntPrefEdit  ("aim.internal.extconnectiontype", ConnectionType,   
  1308.                                  null, 1, "", -1);  
  1309.     }
  1310.  
  1311.     return true;
  1312.     
  1313. }
  1314.  
  1315.  
  1316. /*
  1317.  * Function: GetPanelSessionType 
  1318.  * Arguments: 
  1319.  * Return: the url of the file
  1320.  * Description: returns current pref panel type
  1321.  * The function is used for preferences
  1322.  * Author: A Averbukh<anatoliya@netscape.com> 
  1323. */
  1324.  
  1325. function GetPanelSessionType()
  1326. {
  1327.  
  1328.     if (document.documentElement.getAttribute("isIcqPanel") == "true")
  1329.         return 2;
  1330.     else//AIM
  1331.         return 0;
  1332.  
  1333. }
  1334.  
  1335. /*
  1336.  * Function: CopynGetUrl (def_name, chg_name)
  1337.  * Arguments: 
  1338.  *    def_name  --  default file that needs to be copied in the case of new profile  
  1339.  *    chg_name  --  the name of the file which will be appended to screen name and stores the data.
  1340.  * Return: the url of the file
  1341.  * Description: The same one as GetRdfFileUrl, except: it copies file to user's profile without adding SN to the file name
  1342.  * The function is used for connection settings
  1343. */
  1344. function CopynGetUrl (def_name, chg_name) 
  1345. {
  1346.     var directoryService  =  Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
  1347.     
  1348.     var userProfile = directoryService.get("ProfD", Components.interfaces.nsIFile);
  1349.     var defaultProfile = directoryService.get("profDef", Components.interfaces.nsIFile);
  1350.     if (!defaultProfile.exists())                                   
  1351.         defaultProfile = directoryService.get("ProfDefNoLoc", Components.interfaces.nsIFile); 
  1352.  
  1353.  
  1354.     var defaultConnections = defaultProfile.clone();                         
  1355.     defaultConnections.append(def_name);                                 
  1356.  
  1357.     var UserConnections = userProfile.clone();
  1358.     UserConnections.append(chg_name); 
  1359.     
  1360.     if (!UserConnections.exists()) 
  1361.     { 
  1362.       try 
  1363.       {
  1364.         defaultConnections.copyTo(userProfile, chg_name);     
  1365.       }
  1366.       catch (e) 
  1367.       {
  1368.  
  1369.         return null;
  1370.       }
  1371.                       
  1372.       UserConnections = userProfile.clone();                           
  1373.       UserConnections.append(chg_name);   
  1374.  
  1375.     }  
  1376.     
  1377.     var UserConnectionsURL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
  1378.     UserConnectionsURL.file = UserConnections;
  1379.  
  1380.     return( UserConnectionsURL.spec );
  1381.  
  1382. }
  1383.  
  1384. /*
  1385.  * Function: isIcq
  1386.  * Arguments: 
  1387.  * Return: boolean
  1388.  * Description: returns true is it is icq session, false if not
  1389.   * Author: Prassanna<prass@netscape.com> 
  1390. */
  1391. function isIcq()
  1392. {
  1393.   var SessionType=getCurrentSessionType();
  1394.   if (SessionType == "ICQ")
  1395.   {
  1396.     return true;
  1397.    }
  1398.    return false;
  1399. }
  1400.  
  1401. /*
  1402.  * Function: getCurrentSessionType
  1403.  * Arguments: 
  1404.  * Return: Value of sessionType
  1405.  * Description: If cached sessionType value exists, return that value, else obtain sessionType from prefs.
  1406.  * This will be used in most windows where the user is logged in and is attached to one session and is safe to 
  1407.  * look at cached value.
  1408.  * Author: Prassanna<prass@netscape.com> 
  1409. */
  1410. function getCurrentSessionType()
  1411. {
  1412.  try {
  1413.       // if(CachedSessionType == null)
  1414.             CachedSessionType = aimPrefsManager().GetCharPref("aim.session.userconnectionname", null, true);
  1415.   } catch (e) {}; 
  1416.   return CachedSessionType;
  1417.  }
  1418.  
  1419. function setCurrentSessionType(conval)
  1420. {
  1421.    CachedSessionType=conval;
  1422.    aimPrefsManager().SetCharPref("aim.session.userconnectionname", conval, null, true);
  1423. }
  1424.  
  1425. /*
  1426.  * Function: getSessionType
  1427.  * Arguments: 
  1428.  * Return: Value of sessionType
  1429.  * Description: Obtain the sessionType from prefs everytime. Differnt from the above where a cahced value is used.
  1430.  * This will be used in sidebarpanel and app windows where user could change it before loggin in.
  1431.  * Author: Prassanna<prass@netscape.com> 
  1432. */
  1433.  
  1434. function getSessionType() {
  1435.   return(aimPrefsManager().GetSessionType());
  1436. }
  1437.  
  1438. /*
  1439.  * Function: IsServiceCorrect (curSN, curConnName)
  1440.  * Arguments: 
  1441.  *    curSN        --  cureent SN
  1442.  *    curConnName  --  cureent connection name
  1443.  * Return: true/false 
  1444.  * Description: Check, if curSN can be used to sign on to service curConnName
  1445.  * Author: Anatoliy Averbukh<anatoliya@netscape.com> 
  1446. */
  1447. function IsServiceCorrect (curSN, curConnName)
  1448. {
  1449.    var curTypeperSN = aimPrefsManager().GetSessionTypeEdit (curSN);
  1450.  
  1451.    var nCurConn;
  1452.  
  1453.    if (curConnName =="AIM") {
  1454.       nCurConn = 0;
  1455.    }
  1456.    else if (curConnName =="ICQ"){
  1457.       nCurConn = 2;
  1458.    }
  1459.    else {
  1460.       return false;
  1461.    }
  1462.  
  1463.    if (nCurConn == curTypeperSN) {
  1464.        return true;
  1465.    }
  1466.    else {
  1467.        if (curConnName =="AIM")
  1468.         aimErrorBox(aimString("msg.wrongsrv").replace(/%ScreenName%/, '"' + curSN + '"'));
  1469.        else
  1470.         aimErrorBox(aimString("msgICQ.wrongsrv").replace(/%ScreenName%/, '"' + curSN + '"'));
  1471.  
  1472.        return false;
  1473.    }
  1474.  
  1475.       
  1476.  
  1477. }
  1478.  
  1479.  
  1480.  
  1481. /*
  1482.  * Function:  openRegisterLink(sessionID)
  1483.  *
  1484.  * Arguments: sessionID
  1485.  * Possible values: sessionWatcher (inside sidebar), sessionAppWatcher (from menu)
  1486.  *
  1487.  * Return: None
  1488.  *
  1489.  * Description: This function is called when the register link in sigon overlay is invoked. It opens 
  1490.  * registration url for icq if session is icq. If session is Aim, it opens the regitration wizard.
  1491.  * Note: this is a clone of the function openRegisterLink() in SidebarPanel.js except this getting a  
  1492.  * app-level session element
  1493.  *
  1494.  * Author: Prassanna 4/06/2002
  1495.  */
  1496.  
  1497. function openRegisterLink(sessionID)
  1498. {
  1499.  if(sessionID != null  && sessionID  !=""){
  1500.  
  1501.   var checkSession=window.document.getElementById(sessionID).getAttribute('sessionMode'); 
  1502.   if (checkSession == "Aim")
  1503.     {
  1504.       aimGlobalCmdStartupWizard();
  1505.       return;
  1506.     }
  1507.   else
  1508.     {
  1509.       regLink = aimString("icq.register.url");
  1510.       openTopWin(regLink);  
  1511.       return;
  1512.     }
  1513.  } 
  1514. }
  1515.  
  1516. /*
  1517.  * Function:  cmdIcqSearch()
  1518.  *
  1519.  * Arguments: None
  1520.  * Return: None
  1521.  *
  1522.  * Description: This function is used as a workaround to go to a web page and do user search since we do not support
  1523.  * server side search for Machv.
  1524.  *
  1525.  * Author: Prassanna 4/29/2002
  1526. */
  1527.   
  1528.  
  1529. function cmdIcqSearch()
  1530. {
  1531.    var url=aimString("icq.search.url");
  1532.    if (window.opener) {
  1533.        // From add buddy modal dialog
  1534.        window.opener.openDialog("chrome://navigator/content/navigator.xul", "_blank","modal=no,chrome,chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar", url);
  1535.        return;
  1536.        //Since we have a modal window opening some other window (yuk!), this opener stuff is there
  1537.       // Clean this up post-Machv when real icq search is supported
  1538.    }
  1539.    openDialog("chrome://navigator/content/navigator.xul", "_blank","modal=no,chrome,chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar", url);
  1540. }
  1541.  
  1542.  
  1543. /*
  1544.  * Function: openPrefWindow
  1545.  * Arguments: none
  1546.  * Return: none
  1547.  * Description: opens the pref window based on session type.
  1548.  * Author: Suresh <suresh@netscape.com> 
  1549. */
  1550. function openPrefWindow()
  1551. {
  1552.   if (isIcq())
  1553.     goPreferences('icq', 'chrome://aim/content/pref-Icq_icq.xul','icq');
  1554.   else
  1555.     goPreferences('instantmessenger', 'chrome://aim/content/pref-IM_instantmessage.xul','instantmessenger');
  1556. }
  1557.  
  1558. /* Selects the given index in the buddy list */
  1559. function SelectIndex(index)
  1560. {
  1561.   var tree = getSelectedTreeName();
  1562.   var treeselection = tree.treeBoxObject.selection;
  1563.   treeselection.select(index);
  1564. }
  1565.  
  1566.  
  1567. /*
  1568.  * Function: cachedUserConnection
  1569.  * Arguments: None
  1570.  * Return: connection name
  1571.  * Description: returns AIM or ICQ
  1572.   * Author: Prassanna<prass@netscape.com> 
  1573. */
  1574. function cachedUserConnection()
  1575. {
  1576.   try {
  1577.       if(CachedUserConnection== null)
  1578.             CachedUserConnection= aimPrefsManager().GetCharPref("aim.session.userconnectionname", null, true);
  1579.   } catch (e) {}; 
  1580.   return CachedUserConnection;
  1581. }
  1582.  
  1583.