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-server.js < prev    next >
Text File  |  2001-02-14  |  4KB  |  112 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 Bundle = srGetStrBundle("chrome://messenger/locale/prefs.properties");
  26.  
  27. function validate() {
  28.   var servername = document.getElementById("hostname");
  29.   var smtpserver = document.getElementById("smtphostname");
  30.  
  31.   if ((servername && servername.value =="") ||
  32.       (smtpserver && smtpserver.value == "")) {
  33.     var alertText = Bundle.GetStringFromName("enterValidHostname");
  34.     window.alert(alertText);
  35.     return false;
  36.   }
  37.  
  38.   /* if this is for a server that doesn't require a username, 
  39.    * check if the account exists. 
  40.    * for other types, we check after the user provides the username (see aw-login.js)
  41.    */
  42.   var pageData = parent.GetPageData();
  43.   var serverType = parent.getCurrentServerType(pageData);
  44.   var protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + serverType].getService(Components.interfaces.nsIMsgProtocolInfo);
  45.   if (!protocolinfo.requiresUsername) {
  46.     var userName = parent.getCurrentUserName(pageData);
  47.     var hostName = servername.value;
  48.  
  49.     if (parent.AccountExists(userName,hostName,serverType)) {
  50.       alertText = Bundle.GetStringFromName("accountExists");
  51.       window.alert(alertText);
  52.       return false;
  53.     }
  54.   }
  55.  
  56.   return true;
  57. }
  58.  
  59. function onInit() {
  60.   
  61.   var smtpTextField = document.getElementById("smtphostname");
  62.  
  63.   var smtpServer = parent.smtpService.defaultServer;
  64.   if (smtpTextField && smtpTextField.value == "" &&
  65.       smtpServer.hostname)
  66.     smtpTextField.value = smtpServer.hostname;
  67.  
  68.   // modify the value in the smtp display if we already have a 
  69.   // smtp server so that the single string displays the 
  70.   // name of the smtp server.
  71.   var smtpStatic = document.getElementById("smtpStaticText");
  72.   if (smtpServer && smtpServer.hostname && 
  73.       smtpStatic.hasChildNodes()) {
  74.     var staticText = smtpStatic.firstChild.nodeValue;
  75.     staticText = staticText.replace(/@server_name@/, smtpServer.hostname);
  76.     while (smtpStatic.hasChildNodes())
  77.       smtpStatic.removeChild(smtpStatic.firstChild);
  78.     var staticTextNode = document.createTextNode(staticText);
  79.     smtpStatic.appendChild(staticTextNode);
  80.   }
  81.   
  82.   hideShowSmtpSettings(smtpServer);
  83. }
  84.  
  85. function hideShowSmtpSettings(smtpServer) {
  86.  
  87.   var noSmtpBox = document.getElementById("noSmtp");
  88.   var haveSmtpBox = document.getElementById("haveSmtp");
  89.  
  90.   var boxToHide;
  91.   var boxToShow;
  92.   
  93.   if (smtpServer && smtpServer.hostname &&
  94.       smtpServer.hostname != "") {
  95.     // we have a hostname, so show the static text
  96.     boxToShow = haveSmtpBox;
  97.     boxToHide = noSmtpBox;
  98.   } else {
  99.     // no default hostname yet
  100.     boxToShow = noSmtpBox;
  101.     boxToHide = haveSmtpBox;
  102.   }
  103.  
  104.   if (boxToHide)
  105.     boxToHide.setAttribute("hidden", "true");
  106.  
  107.   if (boxToShow)
  108.     boxToShow.removeAttribute("hidden");
  109.  
  110.  
  111. }
  112.