home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / messenger.jar / content / messenger / aw-identity.js < prev    next >
Text File  |  2001-02-14  |  4KB  |  133 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  * Alec Flett <alecf@netscape.com>
  22.  * Seth Spitzer <sspitzer@netscape.com>
  23.  */
  24.  
  25. var currentDomain;
  26. var Bundle = srGetStrBundle("chrome://messenger/locale/prefs.properties");
  27.  
  28. function validate(data)
  29. {
  30.   var name = document.getElementById("fullName").value;
  31.  
  32.   if (! name || name=="") {
  33.     var alertText = Bundle.GetStringFromName("enterName");
  34.     window.alert(alertText);
  35.     return false;
  36.   }
  37.   if (!validateEmail()) return false;
  38.  
  39.   parent.UpdateWizardMap();
  40.   
  41.   return true;
  42. }
  43.  
  44. // this is kind of wacky.. basically it validates the email entered in
  45. // the text field to make sure it's in the form "user@host"..
  46. //
  47. // However, if there is a current domain (retrieved during onInit)
  48. // then we have to do some special tricks:
  49. // - if the user ALSO entered an @domain, then we just chop it off
  50. // - at some point it would be useful to keep the @domain, in case they
  51. //   wish to override the domain.
  52. function validateEmail() {
  53.   var emailElement = document.getElementById("email");
  54.   var email = emailElement.value;
  55.  
  56.   
  57.   var emailArray = email.split('@');
  58.  
  59.   if (currentDomain) {
  60.     // check if user entered and @ sign even though we have a domain
  61.     if (emailArray.length >= 2) {
  62.       email = emailArray[0];
  63.       emailElement.value = email;
  64.     }
  65.     
  66.     if (email.length =="") {
  67.       var alertText = Bundle.GetStringFromName("enterValidEmailPrefix");
  68.       window.alert(alertText);
  69.       return false;
  70.     }
  71.   }
  72.  
  73.   else {
  74.     if (emailArray.length != 2 ||
  75.         emailArray[0] == "" ||
  76.         emailArray[1] == "") {
  77.       alertText = Bundle.GetStringFromName("enterValidEmail");
  78.       window.alert(alertText);
  79.       return false;
  80.     }
  81.   }
  82.     
  83.   return true;
  84. }
  85.  
  86. function onInit()
  87. {
  88.   checkForDomain();
  89.   checkForFullName(); 
  90.   checkForEmail(); 
  91. }
  92.  
  93. // retrieve the current domain from the parent wizard window,
  94. // and update the UI to add the @domain static text
  95. function checkForDomain()
  96. {
  97.   var accountData = parent.gCurrentAccountData;
  98.   if (!accountData) return;
  99.   if (!accountData.domain) return;
  100.  
  101.   // save in global variable
  102.   currentDomain = accountData.domain;
  103.   
  104.   var postEmailText = document.getElementById("postEmailText");
  105.   postEmailText.setAttribute("value", "@" + currentDomain);
  106. }
  107.  
  108. function checkForFullName() {
  109.     var name = document.getElementById("fullName");
  110.     if (name.value=="") {
  111.         try {
  112.             var userInfo = Components.classes["@mozilla.org/userinfo;1"].getService(Components.interfaces.nsIUserInfo);
  113.             name.value = userInfo.fullname;
  114.         }
  115.         catch (ex) {
  116.             // dump ("checkForFullName failed: " + ex + "\n");
  117.         }
  118.     }
  119. }
  120.  
  121. function checkForEmail() {
  122.     var email = document.getElementById("email");
  123.     if (email.value=="") {
  124.         try {
  125.             var userInfo = Components.classes["@mozilla.org/userinfo;1"].getService(Components.interfaces.nsIUserInfo);
  126.             email.value = userInfo.emailAddress;
  127.         }
  128.         catch (ex) {
  129.             // dump ("checkForEmail failed: " + ex + "\n"); 
  130.         }
  131.     }
  132. }
  133.