home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / aim.jar / content / aim / networkTransactions.js < prev    next >
Encoding:
JavaScript  |  2005-07-29  |  51.1 KB  |  1,258 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Netscape Public License
  6.  * Version 1.1 (the "License"); you may not use this file except in
  7.  * compliance with the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/NPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Mozilla Communicator client code.
  16.  *
  17.  * The Initial Developer of the Original Code is 
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *      Martijn Pieters <mj@digicool.com> 
  24.  *      for toBase64() copied from 
  25.  *      mozilla\extensions\xml-rpc\src\nsXmlRpcClient.js
  26.  *
  27.  * Alternatively, the contents of this file may be used under the terms of
  28.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  29.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30.  * in which case the provisions of the GPL or the LGPL are applicable instead
  31.  * of those above. If you wish to allow use of your version of this file only
  32.  * under the terms of either the GPL or the LGPL, and not to allow others to
  33.  * use your version of this file under the terms of the NPL, indicate your
  34.  * decision by deleting the provisions above and replace them with the notice
  35.  * and other provisions required by the GPL or the LGPL. If you do not delete
  36.  * the provisions above, a recipient may use your version of this file under
  37.  * the terms of any one of the NPL, the GPL or the LGPL.
  38.  *
  39.  * ***** END LICENSE BLOCK ***** */
  40.  
  41. var gIOService;
  42. var gDataReceived = null;
  43. var gImageData = [];
  44. var gAuthenticationUrl;
  45. var gNewAccountUrl;
  46. var gSuggestSnUrl;
  47. var gReadUrl;
  48. var gWriteUrl;
  49. var gForgottenPwdUrl;
  50. var gSetUserBrandUrl;
  51. var gAgeSuspendUrl;
  52. var gCreditCardValidationUrl;
  53. var gGetRegImageUrl;
  54. var gCurrentPageDefined;
  55. var gStartInPage;
  56. var gCategory;
  57. var gCloseProgressMeter = false;
  58. var gEntryPoint;
  59. var gCurrentErrorMsg;
  60. var gAuthToken;
  61. var gSnToken;
  62. var gCcToken;
  63. var gWroteInfo = false;
  64. var gReadInfo = false;
  65. var gUserBrandIsSet = false;
  66. var gFailedToCreateWebMailAccount = false;
  67. var gCollectDataFromExistingMember = false;
  68. var gSNSEntryCreated = false;
  69. var gPingedForExistingInfo = false;
  70. var gMigratedUserScreenName;
  71. var gFirstName;
  72. var gLastName;
  73. var gSiteIdPerActivationSchema;
  74. var gFinalSideBarPanel;
  75. var gNetscapeNetworkFlag;
  76. var gPayingMember = false;
  77. var gAgeSuspended = false;
  78. var gAgeSuspendedPlus = false;
  79. var gAgeSuspendedSet = false;
  80. var gNumOfCredits = 0;
  81. var gValidate;
  82. var gNetscapeNetworkSite;
  83. var gSetAgeSuspend = false;
  84. var gWroteAgeData = false;
  85. var gScreenName;
  86. var gCreditPageCancelled = false;
  87. var gExistingAccountDOBYear;
  88. var gExistingAccountDOBMonth;
  89. var gExistingAccountDOBDay; 
  90. var gExistingAccountZip;
  91. var gExistingAccountCountry;
  92. var gExistingAccountGender;
  93.  
  94.  
  95. const kPostMethod = "POST";
  96. const kGetMethod = "GET";
  97. const kScreennameNamespace = "0-9a-zA-Z";
  98. const kNetscapeNetworkBrand = "NETSCAPE-NETWORK";
  99.  
  100. var strBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(); 
  101. strBundleService = strBundleService.QueryInterface(Components.interfaces.nsIStringBundleService);
  102.  
  103. var activationStrBundle = strBundleService.createBundle("chrome://communicator/locale/profile/activation.properties");
  104.  
  105. function PostData(destinationDirectoryLocation, data)
  106. {
  107.   gActivationListener(destinationDirectoryLocation, data, kPostMethod);
  108. }
  109.  
  110. function getIOService()
  111. {
  112.   if (gIOService)
  113.     return gIOService;
  114.  
  115.   gIOService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  116.   return gIOService;
  117. }
  118.  
  119. function get_uri(url)
  120. {
  121.   var nsiuri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI);
  122.   nsiuri.spec = url;
  123.   return nsiuri;
  124. }
  125.  
  126. function post_data_to_server(newLocation, data, pingMethod)
  127. {
  128.   try
  129.   {
  130.     // Set up channel.
  131.     var ioService = getIOService();
  132.  
  133.     dump ("---) ioService is " + ioService + "\n");
  134.     var uri = get_uri(newLocation);
  135.  
  136.     dump ("---) uri is " + uri + "\n");
  137.     
  138.     var chann = ioService.newChannelFromURI(uri)
  139.         .QueryInterface(Components.interfaces.nsIHttpChannel);
  140.  
  141.     dump ("---) chann is " + chann + "\n");
  142.     
  143.     if (pingMethod == kPostMethod) {
  144.       // Create a stream out of the request and attach it to the channel
  145.       var upload = chann.QueryInterface(Components.interfaces.nsIUploadChannel);
  146.       
  147.       dump ("---) upload is " + upload + "\n");
  148.       
  149.       var postStream = createInstance('@mozilla.org/io/string-input-stream;1',
  150.           'nsIStringInputStream');
  151.  
  152.       dump ("---) postStream is " + postStream + "\n");
  153.       
  154.       if (!gSiteIdPerActivationSchema)
  155.         gSiteIdPerActivationSchema = activationStrBundle.GetStringFromName("defaultSiteId");
  156.  
  157.       dump ("---) gSiteIdPerActivationSchema is " + gSiteIdPerActivationSchema + "\n");
  158.       
  159.       chann.setRequestHeader("SNS-SITEID", gSiteIdPerActivationSchema, true); // was false SL
  160.  
  161.       // get the charset
  162.       var charset = activationStrBundle.GetStringFromName("charset");
  163.  
  164.       if (!data) {
  165.         data = "siteId=" + escape(gSiteIdPerActivationSchema) + "&charset=" + escape(charset);
  166.         chann.setRequestHeader("HTTP-COOKIE", document.cookie, true);
  167.       }
  168.       else {
  169.         // Add charset to the data we are posting
  170.         data += "&siteId=" + escape(gSiteIdPerActivationSchema) + "&charset=" + escape(charset);
  171.       }
  172.       dump("---) in networkTransactions.js, post data to server\n");
  173.       dump("XXX " + newLocation + " " + data + "\n");
  174.       postStream.setData(data, data.length);
  175.       var cookieString = document.cookie;
  176.  
  177.       upload.setUploadStream(postStream, 'application/x-www-form-urlencoded', -1);
  178.     }
  179.  
  180.     chann.requestMethod = pingMethod;
  181.  
  182.     chann.notificationCallbacks = gProgressNotifications;
  183.  
  184.     chann.asyncOpen(gActivationListener, null);
  185.   }
  186.   catch (e)
  187.   {
  188.   }
  189. }
  190.  
  191. var gActivationListener =
  192. {
  193.   QueryInterface: function(aIId, instance)
  194.   {
  195.     if (aIId.equals(Components.interfaces.nsIStreamListener))
  196.       return this;
  197.     if (aIId.equals(Components.interfaces.nsISupports))
  198.       return this;
  199.     
  200.     throw Components.results.NS_NOINTERFACE;
  201.   },
  202.  
  203.   onStartRequest: function(request, ctxt)
  204.   {
  205.     gImageData = [];
  206.     gDataReceived = "";
  207.     gCloseProgressMeter = false;
  208.   },
  209.  
  210.   onStopRequest: function(request, ctxt, status, errorMsg)
  211.   {
  212.     var currPage;
  213.     var screenNames;
  214.     var statusArray;
  215.     var isExistingAccount = false;
  216.     var isValidAccount = false;
  217.     var errorCode;
  218.     var cookieCheckInvalid = false;
  219.     var coppaViolation = false;
  220.     var invalidCreditCard = false;
  221.     gMismatchedImageWord = false;
  222.  
  223.     try {
  224.       if (gCurrentPageDefined)
  225.         currPage = gCurrentPageDefined;
  226.       else
  227.         currPage = document.documentElement.currentPage.id;
  228.     }
  229.     catch (ex) {
  230.     }
  231.     
  232.     // if there was no data (gImageData.length == 0)
  233.     // we should send the user to the "Try Again Later" page
  234.     if (currPage == "ispPage17" && gImageData.length)
  235.     {
  236.       // if the image data is really an error code
  237.       // like "rc=304", we need to handle it differently
  238.       if (gImageData[0] == 114 &&
  239.           gImageData[1] == 99 &&
  240.           gImageData[2] == 61)
  241.       {
  242.         // convert the bytes into a string
  243.         gDataReceived = "";
  244.         for (i=0;i<gImageData.length;i++)
  245.         {
  246.           gDataReceived += String.fromCharCode(gImageData[i]);
  247.         }
  248.       }
  249.       else  
  250.       {
  251.         var imageWordImg = document.getElementById("imageWordImg");
  252.         imageWordImg.setAttribute("src", "data:image/gif;base64," + toBase64(gImageData));
  253.         // fake the "rc=0"
  254.         gDataReceived = "rc=0";
  255.       }
  256.     }
  257.  
  258.     // Network transaction is over. Time to close the progress dialog
  259.     //gCloseProgressMeter = true;
  260.     if (gDataReceived && currPage) {
  261.       // There are 2 cases when we come here.
  262.       // 1. MainStream Activation beginning
  263.       // 2. DownStream Activation beginning
  264.       //    a. From Mailnews
  265.       //    b. From IM
  266.       //    c. From other points in Navigator
  267.       if (currPage == "activationStartWindow" || 
  268.           currPage == "ispPage1" || 
  269.           gEntryPoint == "downstreamActivation") {
  270.         gEntryPoint = null;
  271.         var value = extractReturnValue("rc", true);
  272.         if (value == 0) {
  273.           gAuthenticationUrl = extractReturnValue("authUrl", true);
  274.           gNewAccountUrl = extractReturnValue("newSnUrl", true);
  275.           gReadUrl = extractReturnValue("readUrl", true);
  276.           gWriteUrl = extractReturnValue("writeUrl", true);
  277.           gForgottenPwdUrl = extractReturnValue("forgottenPwdUrl", true);
  278.           gSuggestSnUrl = extractReturnValue("suggestSnUrl", true);
  279.           gSetUserBrandUrl = extractReturnValue("setUserBrandUrl", true);
  280.           gAgeSuspendUrl = extractReturnValue("ageSuspendUrl", true);
  281.           gCreditCardValidationUrl = extractReturnValue("creditCardValidationUrl", true);
  282.           gGetRegImageUrl = extractReturnValue("getRegImageUrl", true);
  283.         }
  284.         else { 
  285.           if (currPage == "activationStartWindow" && !gPingedForExistingInfo && !gReadInfo) {
  286.             var progressWindow = getProgressDialog(currPage);
  287.             if (progressWindow) 
  288.               progressWindow.close();
  289.           }
  290.           else if (currPage != "activationStartWindow") {
  291.             gCloseProgressMeter = true;
  292.             setAllHandlersForPageAdvance();
  293.             try {
  294.             gCurrentErrorMsg = activationStrBundle.GetStringFromID(value);
  295.             }
  296.             catch (ex) {
  297.               // possbily hit an undefined error case
  298.               gCurrentErrorMsg = activationStrBundle.GetStringFromName("unknownError");
  299.             }
  300.  
  301.             document.documentElement.advance("ispPage10");
  302.           }
  303.         }
  304.  
  305.         // Set the next pages from here
  306.         switch (currPage) {
  307.           case "activationStartWindow" :
  308.             // based on what you find here, 
  309.             // you have to jump to the right page in the wizard sequence
  310.             // We always start with an existing account scenario in the process
  311.             // of mainstream registration. For downstream registration, coming from
  312.             // menuitem which has no wizard base, we need to start in new account page.
  313.             if (gStartInPage && gStartInPage == "ispPage4") {
  314.               if (gCategory) {
  315.                 switch (gCategory) {
  316.                   case "globalHelp:registerNetscape" :
  317.               setNewAccountGlobals();
  318.               window.openDialog("chrome://communicator/content/profile/newactivation.xul",
  319.                                 "Activation", "chrome,titlebar,resizable=no,centerscreen,dialog=no", 
  320.                                 {page:gStartInPage, origin:currPage, newaccturl:gNewAccountUrl,
  321.                                  authurl:gAuthenticationUrl, readurl:gReadUrl, writeurl:gWriteUrl, 
  322.                                  forgotpwdurl:gForgottenPwdUrl,suggestsnurl:gSuggestSnUrl,
  323.                                  setbrandurl:gSetUserBrandUrl,agesuspendurl:gAgeSuspendUrl,
  324.                                  creditvalidurl:gCreditCardValidationUrl,gFinalSideBarPanel:"search",
  325.                                  getregimageurl:gGetRegImageUrl}, this);
  326.                     break;
  327.                   case "messenger:getFreeAccount" :
  328.                     setNewAccountGlobals();
  329.                     window.openDialog("chrome://messenger/content/AccountWizard.xul",
  330.                                       "AccountWizard", "chrome,titlebar,resizable,centerscreen", 
  331.                                       {page:gStartInPage, origin:currPage, newaccturl:gNewAccountUrl,
  332.                                        authurl:gAuthenticationUrl, readurl:gReadUrl, writeurl:gWriteUrl, 
  333.                                        forgotpwdurl:gForgottenPwdUrl,suggestsnurl:gSuggestSnUrl,setbrandurl:gSetUserBrandUrl,
  334.                                        agesuspendurl:gAgeSuspendUrl,creditvalidurl:gCreditCardValidationUrl,
  335.                                        getregimageurl:gGetRegImageUrl}, this);
  336.                     break;
  337.                   default :
  338.                     break;
  339.                 }
  340.               }
  341.             }
  342.             else {
  343.             if ("setExistingAccountGlobals" in this) 
  344.               setExistingAccountGlobals();
  345.             if("gPingedForExistingInfo" in this  && !gPingedForExistingInfo)  {
  346.               gPingedForExistingInfo = true;
  347.               var charset = activationStrBundle.GetStringFromName("charset");
  348.               post_data_to_server(gAuthenticationUrl, null, kPostMethod, charset);
  349.             }
  350.             else if ("gReadInfo" in this && !gReadInfo) {
  351.               gReadInfo = true;
  352.               var charset = activationStrBundle.GetStringFromName("charset");
  353.               post_data_to_server(gReadUrl, ("authToken="+ gAuthToken + 
  354.                                              "&user_name_first&user_name_last&user_gender" + 
  355.                                              "&user_home_postal_postalcode&user_home_postal_countrycode" + 
  356.                                              "&user_bdate_ymd_year&user_bdate_ymd_month&user_bdate_ymd_day" +
  357.                                              "&user_nscp_network_member"), kPostMethod, charset);
  358.             }
  359.             else {
  360.               if ("extractReturnValue" in this) {
  361.                 gMigratedUserScreenName = extractReturnValue("user_screenname", true);
  362.                 gFirstName = extractReturnValue("user_name_first", true);
  363.                 gLastName = extractReturnValue("user_name_last", true);
  364.               }
  365.  
  366.               var startPage = "ispPage3";
  367.               if (gCategory == "messenger:setupExistingAccount") {
  368.                 window.openDialog("chrome://messenger/content/AccountWizard.xul",
  369.                                   "Activation", "chrome,titlebar,resizable=no,centerscreen,dialog=no", null, 
  370.                                 {page:gStartInPage, origin:currPage, newaccturl:gNewAccountUrl,
  371.                                  authurl:gAuthenticationUrl, readurl:gReadUrl, writeurl:gWriteUrl, 
  372.                                  forgotpwdurl:gForgottenPwdUrl,suggestsnurl:gSuggestSnUrl,
  373.                                  setbrandurl:gSetUserBrandUrl,agesuspendurl:gAgeSuspendUrl,
  374.                                  creditvalidurl:gCreditCardValidationUrl,gFinalSideBarPanel:"search",
  375.                                  getregimageurl:gGetRegImageUrl}, this);
  376.               }
  377.               else
  378.               window.openDialog("chrome://communicator/content/profile/newactivation.xul",
  379.                                 "Activation", "chrome,titlebar,resizable=no,centerscreen,dialog=no", 
  380.                                 {page:startPage, origin:currPage, newaccturl:gNewAccountUrl,
  381.                                  authurl:gAuthenticationUrl, readurl:gReadUrl, writeurl:gWriteUrl, 
  382.                                  forgotpwdurl:gForgottenPwdUrl,suggestsnurl:gSuggestSnUrl,setbrandurl:gSetUserBrandUrl,
  383.                                  agesuspendurl:gAgeSuspendUrl,creditvalidurl:gCreditCardValidationUrl,
  384.                                  collectedScreenName:gMigratedUserScreenName, collectedFirstName:gFirstName,
  385.                                  collectedLastName:gLastName, getregimageurl:gGetRegImageUrl}, this);
  386.             }
  387.             }
  388.             return;
  389.           case "ispPage1" :
  390.             // based on what you find here, 
  391.             // you have to jump to the right page in the wizard sequence
  392.             // For now, let's go to the standard start page.
  393.             gAcctTypeOnPageHandlerKicked = true;
  394.             gCloseProgressMeter = true;
  395.             if (gExistingAccount)
  396.               document.documentElement.advance("ispPage3");
  397.             else
  398.               document.documentElement.advance("ispPage4");
  399.             return;
  400.           default :
  401.             gCloseProgressMeter = true;
  402.             gAcctTypeOnPageHandlerKicked = true;
  403.             if (gExistingAccount)
  404.               document.documentElement.advance("ispPage3");
  405.             else
  406.               document.documentElement.advance("ispPage4");
  407.             break;
  408.         }
  409.       }
  410.       else {
  411.         if (gDataReceived) {
  412.           // Get status of the transaction
  413.           var value = extractReturnValue("rc", true);
  414.             switch (parseInt(value)) { 
  415.               // SNS APIs returned a successful tranasaction code (rc=0) for a 
  416.               // requested operation on a given account. Examples include, 
  417.               // API authenticated the existing user's Screen Name and password, 
  418.               // user's information could be read from/written to SNS database.
  419.               case 0 : 
  420.                 isValidAccount = true;
  421.                 break;
  422.  
  423.               // SNS APIs returned a code (rc=216) that indicates that user has tried
  424.               // to create a new Screen Name and that Screen Name is already 
  425.               // taken. Client need to serve a page with alternative Screen Names.
  426.               case 216 : 
  427.                 isExistingAccount = true;
  428.                 break;
  429.  
  430.               // SNS APIs checked existing user cookies and got back saying that existing
  431.               // SNS cookies are invalid or expired. So, we need to ask users for Screen Name
  432.               // and password and do the authentication.
  433.               case 210 : 
  434.               case 215 : 
  435.                 cookieCheckInvalid = true;
  436.                 break;
  437.  
  438.               // SNS APIs returned an error trying to process user's request.
  439.               // For list of error codes, please refer to 
  440.               // http://lxr/commercial/source/profile/resources/locale/en-US/activation.properties
  441.  
  442.                // we get this error when en-us user is under 13.
  443.                case 214 :
  444.                  coppaViolation = true;
  445.                  errorCode = value;
  446.                  break;
  447.  
  448.                // User is under 13 years(age suspended) and 30 days has not passed 
  449.                // since he was age suspended.
  450.                case 231:
  451.                  gAgeSuspended = true;
  452.                  break;
  453.  
  454.               // User is under 13 years(age suspended) and 30 days have passed 
  455.               // since he was age suspended.
  456.               case 232:
  457.                 gAgeSuspendedPlus = true;
  458.                 break;
  459.  
  460.               // the credit card information entered is not valid
  461.               case 233:
  462.                 invalidCreditCard = true;
  463.                 break;
  464.  
  465.               // the word the user typed did not match the image
  466.               case 303:
  467.                 gMismatchedImageWord = true;
  468.                 errorCode = value;
  469.                 break;
  470.                 
  471.               default :
  472.                 errorCode = value;
  473.                 break;
  474.             }
  475.  
  476.           // Check for additional data
  477.           // Get AuthToken
  478.           var authToken = extractReturnValue("authToken", false);
  479.           if (authToken) {
  480.             // Be careful. Strip of that new line character.
  481.             realToken = authToken.split("\n");
  482.             gAuthToken = escape(realToken[0]);
  483.           }
  484.  
  485.           // Get screennames, if any
  486.           var screenNameData = extractReturnValue("screennames", true);
  487.           if (screenNameData) {
  488.             gAlternateNamesReceived = true;
  489.             isExistingAccount = true;
  490.             screenNames = screenNameData.split(" ");
  491.           }
  492.  
  493.           // Get user first name
  494.           if (!gFirstName) {
  495.             gFirstName = extractReturnValue("user_name_first", true);
  496.           }
  497.  
  498.           // Get user last name
  499.           if (!gLastName) {
  500.             gLastName = extractReturnValue("user_name_last", true);
  501.           }
  502.  
  503.           // Get user gender
  504.           if (!gExistingAccountGender) {
  505.             gExistingAccountGender = extractReturnValue("user_gender", true);
  506.           }
  507.  
  508.           // Get user's zipcode
  509.           if (!gExistingAccountZip) {
  510.             gExistingAccountZip = extractReturnValue("user_home_postal_postalcode", true);
  511.           } 
  512.           
  513.           // Get user's countrycode
  514.           if (!gExistingAccountCountry) {
  515.             gExistingAccountCountry = extractReturnValue("user_home_postal_countrycode", true);
  516.           }
  517.  
  518.           // Get user's dob year
  519.           if (!gExistingAccountDOBYear) {
  520.             gExistingAccountDOBYear = extractReturnValue("user_bdate_ymd_year", true);
  521.           }
  522.  
  523.           // Get user's dob month
  524.           if (!gExistingAccountDOBMonth) {
  525.             gExistingAccountDOBMonth = extractReturnValue("user_bdate_ymd_month", true);
  526.           }
  527.  
  528.           // Get user's dob day
  529.           if (!gExistingAccountDOBDay) {
  530.             gExistingAccountDOBDay = extractReturnValue("user_bdate_ymd_day", true);
  531.           }
  532.  
  533.           // Get the netscape network flag
  534.           if (!gNetscapeNetworkFlag) {
  535.             gNetscapeNetworkFlag = extractReturnValue("user_nscp_network_member", true);
  536.           }
  537.           
  538.           // if this a AOL/CS paying member
  539.           if (!gPayingMember) {
  540.             gPayingMember = extractReturnValue("payingMember", true);
  541.           }
  542.  
  543.           if (gAgeSuspended || gAgeSuspendedPlus)
  544.           {
  545.             if (!gSnToken) {
  546.               var snToken = extractReturnValue("snToken", false);
  547.               if (snToken) {
  548.                 // Be careful. Strip of that new line character.
  549.                 gSnToken = escape(snToken.split("\n")[0]);
  550.               }
  551.             }
  552.           }
  553.  
  554.           // Get ccToken
  555.           var ccToken = extractReturnValue("ccToken", false);
  556.           if (ccToken) {
  557.             // Be careful. Strip of that new line character.
  558.             gCcToken = escape(ccToken.split("\n")[0]);
  559.           }
  560.  
  561.           if ((currPage == "ispPage5") && coppaViolation)
  562.             gSetAgeSuspend = true;
  563.         }
  564.  
  565.         if (isValidAccount || isExistingAccount || gSNSEntryCreated ||
  566.             gAgeSuspended || gAgeSuspendedPlus || gSetAgeSuspend || invalidCreditCard) {
  567.           
  568.           switch (currPage) {
  569.             case "ispPage17" :
  570.               gCloseProgressMeter = true;
  571.               break;
  572.             case "ispPage2"  :
  573.               if (gNewAccount) {
  574.                 // Assuming that user has valid record in the database, 
  575.                 // let's move onto the next page
  576.                 gNewAcctHandlerKicked = true;
  577.  
  578.                 if (isExistingAccount) {
  579.                   if (gAlternateNamesReceived) {
  580.                     setAltScreenNameAsLabels(screenNames);
  581.                     setNextPage("ispPage6", gEndPageId);
  582.                     gCloseProgressMeter = true;
  583.                     document.documentElement.advance("ispPage6");
  584.                   }
  585.                   else {
  586.                     gCloseProgressMeter = false;
  587.                     var hints = gNewAccountScreenName + " " + ReduceToNamespace(gNewAccountUserFullName, kScreennameNamespace);
  588.                     post_data_to_server(gSuggestSnUrl, "hints="+hints, kPostMethod);
  589.                   }
  590.                 }
  591.                 else if (isValidAccount || gSNSEntryCreated) {
  592.                   // all is good, proceed with new screen name
  593.                   gAlternateNamesReceived = false;
  594.                   gUserFullName = gNewAccountUserFullName;
  595.                   gScreenName = gNewAccountScreenName;
  596.                   gPassword = gNewAccountPassword;
  597.                   gEmailAddress = gScreenName + '@' + kWebMailDomain;
  598.                   gSNSEntryCreated = true;
  599.  
  600.                   // Time to set the Netscape Network flag for this new member. If this API 
  601.                   // is not supported for a given siteId, the registration process continues 
  602.                   // with the next step i.e., writing the data collected to the database.
  603.                   if (!gUserBrandIsSet) {
  604.                     gCloseProgressMeter = false;
  605.                     gUserBrandIsSet = true;
  606.                     post_data_to_server(gSetUserBrandUrl, ("authToken="+ gAuthToken + 
  607.                                                            "&brand="+kNetscapeNetworkBrand), kPostMethod);
  608.                   }
  609.  
  610.                  // Get back to writeUrl after figuring out the 
  611.                   // token problem
  612.                   if (!gWroteInfo) {
  613.                     gCloseProgressMeter = false;
  614.                     gWroteInfo = true;
  615.                     post_data_to_server(gWriteUrl, ("authToken="+ gAuthToken + 
  616.                                                   "&user_gender="+gNewAccountGender+ 
  617.                                                   "&user_home_postal_postalcode="+gNewAccountZip+ 
  618.                                                   "&user_home_postal_countrycode="+gNewAccountCountry), kPostMethod);
  619.                   }
  620.                   else
  621.                     pingWebMailServer("hiddenWindow1");
  622.                 }
  623.               }
  624.               else if (gExistingAccount) {
  625.                 // Assuming that user has valid record in the database, 
  626.                 // let's move onto the next page
  627.                 gUserFullName = existingAccountUserName;
  628.                 gScreenName = existingAccountScreenName;
  629.                 gPassword = existingAccountPassword;
  630.                 gEmailAddress = gScreenName + '@' + kWebMailDomain;
  631.  
  632.                 // Time to set the Netscape Network flag for this existing member who is not a 
  633.                 // member of Netscape Netwrok yet. If this API is not supported for a given siteId, 
  634.                 // the registration process continues with the next step i.e., getting user name
  635.                 // OR getting Webmail account.
  636.                 if (!gUserBrandIsSet) {
  637.                   gCloseProgressMeter = false;
  638.                   gUserBrandIsSet = true;
  639.                   post_data_to_server(gSetUserBrandUrl, ("authToken="+ gAuthToken + 
  640.                                                          "&brand="+kNetscapeNetworkBrand+
  641.                                                          "&hand=1"), kPostMethod);
  642.                 }
  643.                 
  644.                 if (document.documentElement.id == "migWiz") {
  645.                   gCloseProgressMeter = true;
  646.                   gExistingAccountOnPageHandlerKicked = true;
  647.                   setNextPage("ispPage2", gEndPageId);
  648.                   document.documentElement.advance(gEndPageId);
  649.                 }
  650.                 else {
  651.                   if (!(gFirstName || gLastName)) {
  652.                     gCloseProgressMeter = true;
  653.                     gExistingAccountOnPageHandlerKicked = true;
  654.                     setNextPage("ispPage2", "ispPage7");
  655.                     setNextPage("ispPage7", gEndPageId);
  656.                     document.documentElement.advance("ispPage7");
  657.                   }
  658.                   else {
  659.                     setUpUserFullName();
  660.                     pingWebMailServer("hiddenWindow1");
  661.                   }
  662.                 }
  663.               }
  664.               break;
  665.             case "ispPage3"  :
  666.               // Time to check if the user has Netscape Network flag
  667.               // and send them to appropriate wizard page
  668.               gScreenName = existingAccountScreenName;
  669.               gPassword = existingAccountPassword;
  670.               gEmailAddress = gScreenName + '@' + kWebMailDomain;
  671.               gSNSEntryCreated = true;
  672.  
  673.               if (gAgeSuspendedPlus || gAgeSuspended) {
  674.                 if (gAgeSuspendedPlus) {
  675.                   gCloseProgressMeter = true;
  676.                   gExistingAccountOnPageHandlerKicked = true;
  677.                   if (gValidate == "true")
  678.                     document.documentElement.advance("ispPage14");
  679.                   else
  680.                     document.documentElement.advance("ispPage16");
  681.                 }
  682.                 else {
  683.                   if (gValidate == "true")
  684.                   {
  685.                     gCloseProgressMeter = true;
  686.                     gExistingAccountOnPageHandlerKicked = true;
  687.                     setNextPage("ispPage3", "ispPage12");
  688.                     setNextPage("ispPage12", "ispPage2");
  689.                     document.documentElement.advance("ispPage12");
  690.                   }
  691.                   else {
  692.                     gCloseProgressMeter = true;
  693.                     gExistingAccountOnPageHandlerKicked = true;
  694.                     setNextPage("ispPage3", "ispPage16");
  695.                     document.documentElement.advance("ispPage16");
  696.                   }
  697.                 }
  698.               }
  699.               else {
  700.                 if (!gReadInfo) {
  701.                   gCloseProgressMeter = false;
  702.                   gReadInfo = true;
  703.                   post_data_to_server(gReadUrl, ( "authToken="+ gAuthToken + 
  704.                                                "&user_name_first&user_name_last&user_gender" + 
  705.                                                "&user_home_postal_postalcode&user_home_postal_countrycode" + 
  706.                                                "&user_bdate_ymd_year&user_bdate_ymd_month&user_bdate_ymd_day" +
  707.                                                "&user_nscp_network_member"), kPostMethod);
  708.                 }
  709.                 else {
  710.                   // If the user is AOL/CS paying member, go to the end page.
  711.                   // If the user has ever registered with Netscape Network,
  712.                   // his/her record in UMP will have Netscape Network bit
  713.                   // set to 'y'. So, check if the user has already registered.
  714.                   // If so, skip terms page. Otherwise, start with collecting 
  715.                   // user information and move on.
  716.                   // For sites that are not part of the netscape network check if
  717.                   // we have all the data. If all the info exists we do not have to
  718.                   // collect the information.
  719.                   if (gPayingMember=="1" || gNetscapeNetworkFlag == "y" || 
  720.                      ((gNetscapeNetworkSite == "false") && (gExistingAccountDOBYear && gExistingAccountDOBMonth && 
  721.                       gExistingAccountDOBDay && gExistingAccountZip && gExistingAccountCountry && gExistingAccountGender))) 
  722.                   {
  723.                     if (document.documentElement.id == "migWiz") {
  724.                       gCloseProgressMeter = true;
  725.                       gExistingAccountOnPageHandlerKicked = true;
  726.                       setNextPage("ispPage3", gEndPageId);
  727.                       document.documentElement.advance(gEndPageId);
  728.                     }
  729.                     else {
  730.                     if (!(gFirstName || gLastName)) {
  731.                       gCloseProgressMeter = true;
  732.                       gExistingAccountOnPageHandlerKicked = true;
  733.                       if (document.documentElement.id == "migWiz") {
  734.                         setNextPage("ispPage3", gEndPageId);
  735.                         document.documentElement.advance(gEndPageId);
  736.                       }
  737.                       else {
  738.                         setNextPage("ispPage3", "ispPage7");
  739.                         setNextPage("ispPage7", gEndPageId);
  740.                         document.documentElement.advance("ispPage7");
  741.                       }
  742.                     }
  743.                     else {
  744.                       setUpUserFullName();
  745.                       pingWebMailServer("hiddenWindow4");
  746.                     }
  747.                   }
  748.                   }
  749.                   else {
  750.                     // If the user has not registered, get user details
  751.                     // again and follow the regular path of an existing
  752.                     // member.
  753.                      gCloseProgressMeter = true;
  754.                      gExistingAccountOnPageHandlerKicked = true;
  755.                      gCollectDataFromExistingMember = true;
  756.                      setNextPage("ispPage3", "ispPage5");
  757.                      setNextPage("ispPage5", "ispPage17");
  758.                      setNextPage("ispPage17", "ispPage2");
  759.                      if (document.documentElement.id == "migWiz")
  760.                        setNextPage("ispPage2", gEndPageId);
  761.                      else {
  762.                        setNextPage("ispPage2", "ispPage7");
  763.                        setNextPage("ispPage7", gEndPageId);
  764.                      }
  765.                      document.documentElement.advance("ispPage5");
  766.                    }
  767.                 }
  768.               }
  769.               break;
  770.             case "ispPage5"  :
  771.              if (gExistingAccount)
  772.              {
  773.                // if user is under age the we need to set the agesuspend bit to 1
  774.                // if gValidate = false we dont have to set the bit
  775.                if (gValidate == "true" && gSuspendAge && gSetAgeSuspend) {
  776.                  gSetAgeSuspend = false;
  777.                  gCloseProgressMeter = false;
  778.                  post_data_to_server(gAgeSuspendUrl, ("authToken=" + gAuthToken + 
  779.                                                       "&agesuspend=1"), kPostMethod);
  780.                 }
  781.                 else {
  782.                   gSetAgeSuspend = false;
  783.                   if (!gWroteAgeData) {
  784.                     if (gSuspendAge) { //user age < age limit
  785.                       gWroteAgeData = true;
  786.                       gCloseProgressMeter = true;
  787.                       if (gValidate == "true") { 
  788.                         setNextPage("ispPage5", "ispPage12");
  789.                         document.documentElement.advance("ispPage12");
  790.                       }
  791.                       else { // do not validate. just block
  792.                         setNextPage("ispPage5", "ispPage16");
  793.                         document.documentElement.advance("ispPage16");
  794.                       }
  795.                     }
  796.                   }
  797.                 }
  798.               }
  799.               break;
  800.             case "ispPage6"  :
  801.               // Assuming that user has valid record in the database, 
  802.               // let's move onto the next page
  803.  
  804.               if (isExistingAccount) {
  805.                 if (gAlternateNamesReceived) {
  806.                   gAlternateNamesReceived = false;
  807.                   gCloseProgressMeter = true;
  808.                   setAltScreenNameAsLabels(screenNames);
  809.                   gScreenNamesOnPageHandlerKicked = false;
  810.                 }
  811.                 else {
  812.                   gAlternateNamesReceived = false;
  813.                   isExistingAccount = false;
  814.                   gCloseProgressMeter = false;
  815.                   var hints = gNewAccountScreenName + " " + ReduceToNamespace(gNewAccountUserFullName, kScreennameNamespace);
  816.                   post_data_to_server(gSuggestSnUrl, "hints="+hints, kPostMethod);
  817.                 }
  818.               }
  819.               else if (isValidAccount || gSNSEntryCreated) {
  820.                 // all is good, proceed with new screen name
  821.                 gAlternateNamesReceived = false;
  822.                 gUserFullName = gNewAccountUserFullName;
  823.                 gScreenName = gNewAccountScreenName;
  824.                 gPassword = gNewAccountPassword;
  825.                 gEmailAddress = gScreenName + '@' + kWebMailDomain;
  826.                 gScreenNamesOnPageHandlerKicked = true;
  827.                 gSNSEntryCreated = true;
  828.  
  829.                 // Time to set the Netscape Network flag for this new member. If this API 
  830.                 // is not supported for a given siteId, the registration process continues 
  831.                 // with the next step i.e., writing the data collected to the database.
  832.                 if (!gUserBrandIsSet) {
  833.                   gCloseProgressMeter = false;
  834.                   gUserBrandIsSet = true;
  835.                   post_data_to_server(gSetUserBrandUrl, ("authToken="+ gAuthToken + 
  836.                                                          "&brand="+kNetscapeNetworkBrand), kPostMethod);
  837.                 }
  838.  
  839.                 // Get back to writeUrl after figuring out the 
  840.                 // token problem
  841.                 if (!gWroteInfo) {
  842.                   gCloseProgressMeter = false;
  843.                   gWroteInfo = true;
  844.                   post_data_to_server(gWriteUrl, ("authToken="+ gAuthToken + 
  845.                                                   "&user_gender="+gNewAccountGender+ 
  846.                                                   "&user_home_postal_postalcode="+gNewAccountZip+ 
  847.                                                   "&user_home_postal_countrycode="+gNewAccountCountry+
  848.                                                   "&user_bdate_ymd_year="+gNewAccountDOBYear+
  849.                                                   "&user_bdate_ymd_month="+gNewAccountDOBMonth+
  850.                                                   "&user_bdate_ymd_day="+gNewAccountDOBDay), kPostMethod);
  851.                 }
  852.                   else {
  853.                   pingWebMailServer("hiddenWindow2");
  854.               }
  855.               }
  856.               break;
  857.             case "ispPage8"  :
  858.               setNextPage("ispPage8", "ispPage9");
  859.               gCloseProgressMeter = true;
  860.               gForgotPwdHandlerKicked = true;
  861.               document.documentElement.advance("ispPage9");
  862.               break;
  863.             case "ispPage12" :
  864.               // only allow the user to try 5 times in a session
  865.               if (invalidCreditCard) {
  866.                 gNumOfCredits++;
  867.                 if (gNumOfCredits >= 5) {
  868.                   gCloseProgressMeter = true;
  869.                   gCreditLimitPassed = true;
  870.                   document.documentElement.advance("ispPage15");
  871.                 }
  872.                 else {
  873.                   // if we do not close the progressdialog like this
  874.                   // showErrorMsg is getting called before we close progressdialog
  875.                   // and when we close errormsg dialog, the focus is not on the wizard.
  876.                   var progressWindow = getProgressDialog("progressWindow");
  877.                   if (progressWindow)
  878.                     progressWindow.close();
  879.                   showErrorMsg("invalidCredit");
  880.                 }
  881.               }
  882.               else {
  883.                 // if the credit card information is valid set the Netscape network flag.
  884.                 if (!gNNFlagSet) {
  885.                   gCloseProgressMeter = false;
  886.                   gNNFlagSet = true;
  887.                   if (gSnToken)
  888.                     post_data_to_server(gAgeSuspendUrl, ("snToken=" + gSnToken +
  889.                                                        "&ccToken=" + gCcToken + 
  890.                                                        "&agesuspend=0" +
  891.                                                        "&sns_bit=1"), kPostMethod);
  892.                   else {
  893.                     post_data_to_server(gAgeSuspendUrl, ("authToken=" + gAuthToken +
  894.                                                        "&ccToken=" + gCcToken + 
  895.                                                        "&agesuspend=0" +
  896.                                                        "&sns_bit=1"), kPostMethod);
  897.                   }
  898.                 }
  899.                 else {
  900.                   // we may not have the authtoken since we got error 231 the first time we called
  901.                   // gAuthenticationUrl
  902.                   if (!gAuthToken) {
  903.                     gCloseProgressMeter = false;
  904.                     post_data_to_server(gAuthenticationUrl, ("screenname="+escape(gScreenName)+
  905.                                                              "&password="+escape(gPassword)), kPostMethod);
  906.                   }
  907.                   else {
  908.                     if (!gReadInfo) {
  909.                       gCloseProgressMeter = false;
  910.                       gReadInfo = true;
  911.                       post_data_to_server(gReadUrl, ( "authToken="+ gAuthToken + 
  912.                                              "&user_name_first&user_name_last&user_gender" + 
  913.                                              "&user_home_postal_postalcode&user_home_postal_countrycode" + 
  914.                                              "&user_bdate_ymd_year&user_bdate_ymd_month&user_bdate_ymd_day" +
  915.                                              "&user_nscp_network_member"), kPostMethod);
  916.                     }
  917.                     else {
  918.                       gExistingAccountOnPageHandlerKicked = true;
  919.                       if (document.documentElement.id == "migWiz")
  920.                       {
  921.                         gCloseProgressMeter = true;
  922.                         gCreditLimitPassed = true;
  923.                         setNextPage("ispPage2", gEndPageId);
  924.                         document.documentElement.advance("ispPage2");
  925.                       }
  926.                       else {
  927.                       if (!(gFirstName || gLastName)) {
  928.                         gCloseProgressMeter = true;
  929.                         gCreditLimitPassed = true;
  930.                         setNextPage("ispPage2", "ispPage7");
  931.                         setNextPage("ispPage7", gEndPageId);
  932.                         document.documentElement.advance("ispPage2");
  933.                       }
  934.                       else {
  935.                         setUpUserFullName();
  936.                         pingWebMailServer("hiddenWindow6");
  937.                       }
  938.                       }
  939.                     }
  940.                   }
  941.                 }
  942.               }
  943.               break;
  944.             case "ispPage14" :
  945.               if (!gNotAvailableWritten) {
  946.                 gNotAvailableWritten = true;
  947.                 gCloseProgressMeter = true;
  948.               } 
  949.               break;
  950.             default :
  951.               // go to error page
  952.               break;
  953.           }
  954.         }
  955.         else {
  956.           // go to error page
  957.           if (currPage == "activationStartWindow") {
  958.             var progressWindow = getProgressDialog(currPage);
  959.             if (progressWindow) 
  960.               progressWindow.close();
  961.           }
  962.           else {
  963.             gCloseProgressMeter = true;
  964.             setAllHandlersForPageAdvance();
  965.             try {
  966.               gCurrentErrorMsg = activationStrBundle.GetStringFromID(errorCode);
  967.             }
  968.             catch (ex) {
  969.               // possbily hit an undefined error case
  970.               gCurrentErrorMsg = activationStrBundle.GetStringFromName("unknownError");
  971.             }
  972.             document.documentElement.advance("ispPage10");
  973.           }
  974.         }
  975.       }
  976.     }
  977.     else {
  978.       // go to error page
  979.       if (currPage == "activationStartWindow") {
  980.         var progressWindow = getProgressDialog(currPage);
  981.         if (progressWindow) 
  982.           progressWindow.close();
  983.       }
  984.       else {
  985.         gCloseProgressMeter = true;
  986.         setAllHandlersForPageAdvance();
  987.         gCurrentErrorMsg = activationStrBundle.GetStringFromName("couldNotConnectToServer");
  988.         document.documentElement.advance("ispPage10");
  989.       }
  990.     }
  991.   },
  992.  
  993.   onDataAvailable: function(request, ctxt, inStream, sourceOffset, count)
  994.   {
  995.     var currPage;
  996.     try {
  997.       if (gCurrentPageDefined)
  998.         currPage = gCurrentPageDefined;
  999.       else
  1000.         currPage = document.documentElement.currentPage.id;
  1001.     }
  1002.     catch (ex) {
  1003.     }
  1004.     
  1005.     if (currPage == "ispPage17")
  1006.     {
  1007.       var sstream = Components.classes["@mozilla.org/binaryinputstream;1"];
  1008.       sstream = sstream.createInstance(Components.interfaces.nsIBinaryInputStream);
  1009.       sstream.setInputStream(inStream);
  1010.       gImageData = gImageData.concat(sstream.readByteArray(count));
  1011.     }
  1012.     else
  1013.     {
  1014.       var SIStream = Components.Constructor(
  1015.       '@mozilla.org/scriptableinputstream;1',
  1016.       'nsIScriptableInputStream', 'init');
  1017.       var scriptableStream = new SIStream(inStream);
  1018.       gDataReceived += scriptableStream.read(count);
  1019.     }
  1020.   }
  1021. }
  1022.  
  1023. /* XXX copied from mozilla\extensions\xml-rpc\src\nsXmlRpcClient.js, is this an issue? */
  1024. /* Convert data (an array of integers) to a Base64 string. */
  1025. const toBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' +
  1026.     '0123456789+/';
  1027. const base64Pad = '=';
  1028. function toBase64(data) {
  1029.     var result = '';
  1030.     var length = data.length;
  1031.     var i;
  1032.     // Convert every three bytes to 4 ascii characters.
  1033.     for (i = 0; i < (length - 2); i += 3) {
  1034.         result += toBase64Table[data[i] >> 2];
  1035.         result += toBase64Table[((data[i] & 0x03) << 4) + (data[i+1] >> 4)];
  1036.         result += toBase64Table[((data[i+1] & 0x0f) << 2) + (data[i+2] >> 6)];
  1037.         result += toBase64Table[data[i+2] & 0x3f];
  1038.     }
  1039.  
  1040.     // Convert the remaining 1 or 2 bytes, pad out to 4 characters.
  1041.     if (length%3) {
  1042.         i = length - (length%3);
  1043.         result += toBase64Table[data[i] >> 2];
  1044.         if ((length%3) == 2) {
  1045.             result += toBase64Table[((data[i] & 0x03) << 4) + (data[i+1] >> 4)];
  1046.             result += toBase64Table[(data[i+1] & 0x0f) << 2];
  1047.             result += base64Pad;
  1048.         } else {
  1049.             result += toBase64Table[(data[i] & 0x03) << 4];
  1050.             result += base64Pad + base64Pad;
  1051.         }
  1052.     }
  1053.  
  1054.     return result;
  1055. }
  1056.  
  1057. var gProgressNotifications =
  1058. {
  1059.   getInterface: function(aIId, instance)
  1060.   {
  1061.     dump ("---) gProgressNotifications - aIId " + aIId + "\n");
  1062.     
  1063.     if (aIId.equals(Components.interfaces.nsIProgressEventSink))
  1064.       return this;
  1065.     if (aIId.equals(Components.interfaces.nsISupports))
  1066.       return this;
  1067.  
  1068.     if (aIId.equals(Components.interfaces.nsIHttpEventSink))
  1069.     {  
  1070.       dump("is this exception expected?\n")
  1071.       dump("see http://lxr.mozilla.org/mozilla/source/netwerk/protocol/http/public/nsIHttpEventSink.idl#49\n");
  1072.     }  
  1073.     
  1074.     throw Components.results.NS_ERROR_NO_INTERFACE;
  1075.   },
  1076.  
  1077.   onStatus: function(request, ctxt, status, statusText)
  1078.   {
  1079.     // DecToHex gets last 2 digits of hex.
  1080.     // Applying HexToDec on that will give us the code we are looking for.
  1081.     var decodedStatus = HexToDec(DecToHex(status));
  1082.  
  1083.     var currPage;
  1084.     try {
  1085.       if (gCurrentPageDefined)
  1086.         currPage = gCurrentPageDefined;
  1087.       else
  1088.         currPage = document.documentElement.currentPage.id;
  1089.     }
  1090.     catch (ex) {
  1091.     }
  1092.  
  1093.     var progressWindow;
  1094.     if (currPage == "activationStartWindow") {
  1095.       progressWindow = getActivationStartDialog();
  1096.     }
  1097.     else {
  1098.       progressWindow = getProgressDialog("progressWindow");
  1099.     }
  1100.     var statusMsg;
  1101.     dump ("---> in networkTransactions.js gProgressNotifications\n");
  1102.     
  1103.     switch (decodedStatus) {
  1104.       case 3 :
  1105.         if (progressWindow) {
  1106.             statusMsg = activationStrBundle.GetStringFromName("connectingToServer");
  1107.             progressWindow.setStatus(statusMsg);
  1108.         }
  1109.         break;
  1110.       case 4 :
  1111.         if (progressWindow) {
  1112.             statusMsg = activationStrBundle.GetStringFromName("connectedToServer");
  1113.             progressWindow.setStatus(statusMsg);
  1114.         }
  1115.         break;
  1116.       case 5 :
  1117.         if (progressWindow) {
  1118.             statusMsg = activationStrBundle.GetStringFromName("connectedToServer");
  1119.             progressWindow.setStatus(statusMsg);
  1120.         }
  1121.         break;
  1122.       case 6 :
  1123.         if (progressWindow) {
  1124.             statusMsg = activationStrBundle.GetStringFromName("connectedToServer");
  1125.             progressWindow.setStatus(statusMsg);
  1126.         }
  1127.         break;
  1128.       case 7 :
  1129.         if (progressWindow) {
  1130.             statusMsg = activationStrBundle.GetStringFromName("connectingToServer");
  1131.             progressWindow.setStatus(statusMsg);
  1132.         }
  1133.         break;
  1134.       default:
  1135.         break;
  1136.     }
  1137.   },
  1138.  
  1139.   onProgress: function(request, ctxt, progress, progressMax)
  1140.   {
  1141.   }
  1142. }
  1143.  
  1144. /* Create an instance of the given ContractID, with given interface */
  1145. function createInstance(contractId, intf) {
  1146.     return Components.classes[contractId]
  1147.         .createInstance(Components.interfaces[intf]);
  1148. }
  1149.  
  1150. var hexbase="0123456789ABCDEF";
  1151. function DecToHex(number) {
  1152.   // take a decimal integer, return 2-digit hex string
  1153.   return hexbase.charAt((number>> 4)& 0xf)+ hexbase.charAt(number& 0xf);
  1154. }
  1155.  
  1156. function HexToDec(number) {
  1157.   // take a hex string, return decimal integer
  1158.   return parseInt(number.toUpperCase(), 16);
  1159. }
  1160.  
  1161. function pingForTransactionUrls()
  1162. {
  1163.   var versionNumber = activationStrBundle.GetStringFromName("SNS_API_Version");
  1164.   var data = "version=" + versionNumber;
  1165.  
  1166.   dump ("in pingForTransactionUrls() in aim\\AimProfile\\resources\\content\\networkTransactions.js\n");
  1167.   dump (gPrefs + "\n");
  1168.   var initialUrl = gPrefs.getComplexValue("browser.new_registration.sns_production_url",
  1169.                                    Components.interfaces.nsIPrefLocalizedString).data;
  1170.   dump ("------\n");
  1171.   dump ("------ initialUrl is " + initialUrl + "\n");
  1172.   dump ("------ data is " + data + "\n");
  1173.   dump ("------ kPostMethod is " + kPostMethod + "\n");
  1174.   
  1175.   post_data_to_server(initialUrl, data, kPostMethod);
  1176.  
  1177.   window.openDialog("chrome://communicator/content/profile/progressMeter.xul", "progressWindow", "chrome,modal,titlebar,resizable,centerscreen", this);
  1178. }
  1179.  
  1180. function getActivationStartDialog()
  1181. {
  1182.   var progressWindow;
  1183.   var windowManagerInterface = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  1184.   progressWindow = windowManagerInterface.getMostRecentWindow('activationStartWindow');
  1185.   return progressWindow;
  1186. }
  1187.  
  1188. function getProgressDialog(windowType)
  1189. {
  1190.   var progressWindow;
  1191.   var windowManagerInterface = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  1192.   progressWindow = windowManagerInterface.getMostRecentWindow(windowType);
  1193.   return progressWindow;
  1194. }
  1195.  
  1196. function setEntryPoint(name)
  1197. {
  1198.   gEntryPoint = name;
  1199.   
  1200.   // Set siteId at this time
  1201.   if (gEntryPoint == "mainstreamActivation")
  1202.     gSiteIdPerActivationSchema = activationStrBundle.GetStringFromName("mainstreamSiteId");
  1203.   else  if (gEntryPoint == "downstreamActivation")
  1204.     gSiteIdPerActivationSchema = activationStrBundle.GetStringFromName("downstreamSiteId");
  1205. }
  1206.  
  1207. function setAllHandlersForPageAdvance()
  1208. {
  1209.   gAcctTypeOnPageHandlerKicked = true;
  1210.   gNewAcctHandlerKicked = true;
  1211.   gExistingAccountOnPageHandlerKicked = true;
  1212.   gScreenNamesOnPageHandlerKicked = true;
  1213.   gForgotPwdHandlerKicked = true;
  1214. }
  1215.  
  1216. function extractReturnValue(key, unesacpeResult)
  1217. {
  1218.   value = null;
  1219.   if (gDataReceived) {
  1220.     var dataArray = gDataReceived.split("&");
  1221.   
  1222.     var dataSubArray;
  1223.     for (var i=0; i < dataArray.length; i++) {
  1224.       dataSubArray = dataArray[i].split("=");
  1225.       if (dataSubArray[0] == key) {
  1226.         value = dataSubArray[1];
  1227.         if (unesacpeResult)
  1228.           value = unescape(value);
  1229.         break;
  1230.       }
  1231.     }
  1232.   }
  1233.   return value;
  1234. }
  1235.  
  1236. function ReduceToNamespace(name, namespace)
  1237. {
  1238.     var regex = /[^ + namespace + ]/g;
  1239.  
  1240.     return name.replace(regex, "");
  1241. }
  1242.  
  1243. // get the format string from the properties file
  1244. // and set the full name accordingly
  1245. function setUpUserFullName() {
  1246.   if (gFirstName && gLastName)
  1247.     gUserFullName = activationStrBundle.formatStringFromName("nameFormat", 
  1248.                                                            [gFirstName, gLastName], 2);
  1249.   else {
  1250.     if (gFirstName)
  1251.       gUserFullName = gFirstName;
  1252.     else {
  1253.       if (gLastName)
  1254.         gUserFullName = gLastName;
  1255.     }
  1256.   }
  1257. }
  1258.