home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / messenger.jar / content / messenger / addressbook / abCardOverlay.js < prev    next >
Text File  |  2005-07-29  |  22KB  |  582 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  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.org 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.  *  Seth Spitzer <sspitzer@netscape.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the NPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the NPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. var editCard;
  40. var gOnSaveListeners = new Array;
  41. var gOkCallback = null;
  42. var gAddressBookBundle;
  43. var gHideABPicker = false;
  44.  
  45. function OnLoadNewCard()
  46. {
  47.   InitEditCard();
  48.  
  49.   var cardproperty;
  50.  
  51.   // if one is passed in, use it
  52.   try {
  53.     cardproperty = window.arguments[0].QueryInterface(Components.interfaces.nsIAbCard);
  54.   }
  55.   catch (ex) {
  56.     cardproperty = Components.classes["@mozilla.org/addressbook/cardproperty;1"].createInstance(Components.interfaces.nsIAbCard);
  57.   }
  58.  
  59.   editCard.card = cardproperty;
  60.   editCard.titleProperty = "newCardTitle";
  61.   editCard.selectedAB = "";
  62.  
  63.   if ("arguments" in window && window.arguments[0])
  64.   {
  65.     if ("selectedAB" in window.arguments[0]) {
  66.       // check if selected ab is a mailing list
  67.       var abURI = window.arguments[0].selectedAB;
  68.       
  69.       var directory = GetDirectoryFromURI(abURI);
  70.       if (directory.isMailList) {
  71.         var parentURI = GetParentDirectoryFromMailingListURI(abURI);
  72.         if (parentURI) {
  73.           editCard.selectedAB = parentURI;
  74.         }
  75.         else {
  76.           // it's a mailing list, but we failed to determine the parent directory
  77.           // use the personal addressbook
  78.           editCard.selectedAB = kPersonalAddressbookURI;
  79.         }
  80.       }
  81.       else if (!(directory.operations & directory.opWrite)) {
  82.         editCard.selectedAB = kPersonalAddressbookURI;
  83.       }
  84.       else {
  85.       editCard.selectedAB = window.arguments[0].selectedAB;
  86.       }
  87.     }
  88.     else {
  89.       editCard.selectedAB = kPersonalAddressbookURI;
  90.     }
  91.  
  92.     // we may have been given properties to pre-initialize the window with....
  93.     // we'll fill these in here...
  94.     if ("primaryEmail" in window.arguments[0])
  95.       editCard.card.primaryEmail = window.arguments[0].primaryEmail;
  96.     if ("displayName" in window.arguments[0]) {
  97.       editCard.card.displayName = window.arguments[0].displayName;
  98.       // if we've got a display name, don't generate
  99.       // a display name (and stomp on the existing display name)
  100.       // when the user types a first or last name
  101.       if (editCard.card.displayName.length)
  102.         editCard.generateDisplayName = false;
  103.     }
  104.     if ("aimScreenName" in window.arguments[0])
  105.       editCard.card.aimScreenName = window.arguments[0].aimScreenName;
  106.     
  107.     if ("okCallback" in window.arguments[0])
  108.       gOkCallback = window.arguments[0].okCallback;
  109.  
  110.     if ("escapedVCardStr" in window.arguments[0]) {
  111.       // hide non vcard values
  112.       HideNonVcardFields(); 
  113.       var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook);
  114.       editCard.card = addressbook.escapedVCardToAbCard(window.arguments[0].escapedVCardStr);
  115.     }
  116.  
  117.     if ("titleProperty" in window.arguments[0])
  118.       editCard.titleProperty = window.arguments[0].titleProperty;
  119.     
  120.     if ("hideABPicker" in window.arguments[0])
  121.       gHideABPicker = window.arguments[0].hideABPicker;
  122.   }
  123.  
  124.   // set popup with address book names
  125.   var abPopup = document.getElementById('abPopup');
  126.   if ( abPopup )
  127.   {
  128.     var menupopup = document.getElementById('abPopup-menupopup');
  129.  
  130.     if ( editCard.selectedAB && menupopup && menupopup.childNodes )
  131.     {
  132.       for ( var index = menupopup.childNodes.length - 1; index >= 0; index-- )
  133.       {
  134.         if ( menupopup.childNodes[index].getAttribute('value') == editCard.selectedAB )
  135.         {
  136.           abPopup.label = menupopup.childNodes[index].getAttribute('label');
  137.           abPopup.value = menupopup.childNodes[index].getAttribute('value');
  138.           break;
  139.         }
  140.       }
  141.     }
  142.     else {
  143.       // Default to the first valid addressbook when none is
  144.       // selected. (the 0th is an empty/invalid entry)
  145.       abPopup.label = menupopup.childNodes[1].getAttribute('label');
  146.       abPopup.value = menupopup.childNodes[1].getAttribute('value');
  147.     }
  148.   }
  149.  
  150.   if (gHideABPicker && abPopup) {
  151.     abPopup.hidden = true;
  152.     var abPopupLabel = document.getElementById("abPopupLabel");
  153.     abPopupLabel.hidden = true;
  154.   }
  155.  
  156.   SetCardDialogTitle(editCard.card.displayName);
  157.     
  158.   GetCardValues(editCard.card, document);
  159.  
  160.   // FIX ME - looks like we need to focus on both the text field and the tab widget
  161.   // probably need to do the same in the addressing widget
  162.  
  163.   // focus on first or last name based on the pref
  164.   var focus;
  165.   if (editCard.displayLastNameFirst)
  166.     focus = document.getElementById('LastName');
  167.   else
  168.     focus = document.getElementById('FirstName');
  169.   if ( focus ) {
  170.     // XXX Using the setTimeout hack until bug 103197 is fixed
  171.     setTimeout( function(firstTextBox) { firstTextBox.focus(); }, 0, focus );
  172.   }
  173.   moveToAlertPosition();
  174. }
  175.  
  176. // find the index in addressLists for the card that is being saved.
  177. function findCardIndex(directory)
  178. {
  179.   var index = -1;
  180.   var listCardsCount = directory.addressLists.Count();
  181.   for ( var i = 0;  i < listCardsCount; i++ ) {
  182.     var card = directory.addressLists.QueryElementAt(i, Components.interfaces.nsIAbCard);
  183.     if (editCard.card.equals(card)) {
  184.       index = i;
  185.       break;
  186.     }
  187.   }
  188.   return index;
  189. }
  190.  
  191. function EditCardOKButton()
  192. {
  193.  
  194.   // See if this card is in any mailing list
  195.   // if so then we need to update the addresslists of those mailing lists
  196.   var index = -1;
  197.   var directory = GetDirectoryFromURI(editCard.abURI);
  198.  
  199.   // if the directory is a mailing list we need to search all the mailing lists
  200.   // in the parent directory if the card exists.
  201.   if (directory.isMailList) {
  202.     var parentURI = GetParentDirectoryFromMailingListURI(editCard.abURI);
  203.     directory = GetDirectoryFromURI(parentURI);
  204.   }
  205.  
  206.   var listDirectoriesCount = directory.addressLists.Count();
  207.   var foundDirectories = new Array();
  208.   var foundDirectoriesCount = 0;
  209.   var i;
  210.   // create a list of mailing lists and the index where the card is at.
  211.   for ( i=0;  i < listDirectoriesCount; i++ ) {
  212.     var subdirectory = directory.addressLists.QueryElementAt(i, Components.interfaces.nsIAbDirectory);
  213.     index = findCardIndex(subdirectory);
  214.     if (index > -1)
  215.     {
  216.       foundDirectories[foundDirectoriesCount] = {directory:subdirectory, index:index};
  217.       foundDirectoriesCount++;
  218.     }
  219.   }
  220.   
  221.   SetCardValues(editCard.card, document);
  222.  
  223.   editCard.card.editCardToDatabase(editCard.abURI);
  224.   
  225.   for (i=0; i<foundDirectoriesCount; i++) {
  226.       // Update the addressLists item for this card
  227.       foundDirectories[i].directory.addressLists.
  228.               SetElementAt(foundDirectories[i].index, editCard.card);
  229.   }
  230.   NotifySaveListeners();
  231.  
  232.   // callback to allow caller to update
  233.   if (gOkCallback)
  234.     gOkCallback();
  235.  
  236.   return true;  // close the window
  237. }
  238.  
  239. function OnLoadEditCard()
  240. {
  241.   InitEditCard();
  242.  
  243.   editCard.titleProperty = "editCardTitle";
  244.  
  245.   if (window.arguments && window.arguments[0])
  246.   {
  247.     if ( window.arguments[0].card )
  248.       editCard.card = window.arguments[0].card;
  249.     if ( window.arguments[0].okCallback )
  250.       gOkCallback = window.arguments[0].okCallback;
  251.     if ( window.arguments[0].abURI )
  252.       editCard.abURI = window.arguments[0].abURI;
  253.   }
  254.  
  255.   // set global state variables
  256.   // if first or last name entered, disable generateDisplayName
  257.   if ( editCard.generateDisplayName && (editCard.card.firstName.length +
  258.                       editCard.card.lastName.length +
  259.                       editCard.card.displayName.length > 0) )
  260.   {
  261.     editCard.generateDisplayName = false;
  262.   }
  263.  
  264.   GetCardValues(editCard.card, document);
  265.  
  266.   SetCardDialogTitle(editCard.card.displayName);
  267.  
  268.   // check if selectedAB is a writeable
  269.   // if not disable all the fields
  270.   if ("arguments" in window && window.arguments[0])
  271.   {
  272.     if ("abURI" in window.arguments[0]) {
  273.       var abURI = window.arguments[0].abURI;
  274.       var directory = GetDirectoryFromURI(abURI);
  275.  
  276.       if (!(directory.operations & directory.opWrite)) 
  277.       {
  278.         var disableElements = document.getElementsByAttribute("disableforreadonly", "true");
  279.         for (var i=0; i<disableElements.length; i++)
  280.           disableElements[i].setAttribute('disabled', 'true');
  281.       }
  282.     }
  283.   }
  284.   
  285. }
  286.  
  287. // this is used by people who extend the ab card dialog
  288. // like Netscape does for screenname
  289. function RegisterSaveListener(func)
  290. {
  291.   var length = gOnSaveListeners.length;
  292.   gOnSaveListeners[length] = func;
  293. }
  294.  
  295. // this is used by people who extend the ab card dialog
  296. // like Netscape does for screenname
  297. function NotifySaveListeners()
  298. {
  299.   for ( var i = 0; i < gOnSaveListeners.length; i++ )
  300.     gOnSaveListeners[i]();
  301.  
  302.   if (gOnSaveListeners.length) {
  303.     // the save listeners might have tweaked the card
  304.     // in which case we need to commit it.
  305.     editCard.card.editCardToDatabase(editCard.abURI);
  306.   }
  307. }
  308.  
  309. function InitPhoneticFields()
  310. {
  311.   var showPhoneticFields =
  312.         gPrefs.getComplexValue("mail.addr_book.show_phonetic_fields", 
  313.                                Components.interfaces.nsIPrefLocalizedString).data;
  314.  
  315.   // hide phonetic fields if indicated by the pref
  316.   if (showPhoneticFields == "true")
  317.   {
  318.     var element = document.getElementById("PhoneticLastName");
  319.     element.setAttribute("hidden", "false");
  320.     element = document.getElementById("PhoneticLabel1");
  321.     element.setAttribute("hidden", "false");
  322.     element = document.getElementById("PhoneticSpacer1");
  323.     element.setAttribute("hidden", "false");
  324.  
  325.     element = document.getElementById("PhoneticFirstName");
  326.     element.setAttribute("hidden", "false");
  327.     element = document.getElementById("PhoneticLabel2");
  328.     element.setAttribute("hidden", "false");
  329.     element = document.getElementById("PhoneticSpacer2");
  330.     element.setAttribute("hidden", "false");
  331.   }
  332. }
  333.  
  334. function InitEditCard()
  335. {
  336.   InitPhoneticFields();
  337.  
  338.   gAddressBookBundle = document.getElementById("bundle_addressBook");
  339.   // create editCard object that contains global variables for editCard.js
  340.   editCard = new Object;
  341.  
  342.   editCard.prefs = gPrefs;
  343.  
  344.   // get specific prefs that editCard will need
  345.   try {
  346.     var displayLastNameFirst =
  347.         gPrefs.getComplexValue("mail.addr_book.displayName.lastnamefirst", 
  348.                                Components.interfaces.nsIPrefLocalizedString).data;
  349.     editCard.displayLastNameFirst = (displayLastNameFirst == "true");
  350.     editCard.generateDisplayName = gPrefs.getBoolPref("mail.addr_book.displayName.autoGeneration");
  351.   }
  352.   catch (ex) {
  353.     dump("ex: failed to get pref" + ex + "\n");
  354.   }
  355. }
  356.  
  357. function NewCardOKButton()
  358. {
  359.   if (gOkCallback)
  360.   {
  361.     SetCardValues(editCard.card, document);
  362.     var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook);
  363.     gOkCallback(addressbook.abCardToEscapedVCard(editCard.card));
  364.     return true;  // close the window
  365.   }
  366.  
  367.   var popup = document.getElementById('abPopup');
  368.   if ( popup )
  369.   {
  370.     var uri = popup.getAttribute('value');
  371.  
  372.     // FIX ME - hack to avoid crashing if no ab selected because of blank option bug from template
  373.     // should be able to just remove this if we are not seeing blank lines in the ab popup
  374.     if ( !uri )
  375.       return false;  // don't close window
  376.     // -----
  377.  
  378.     if ( editCard.card )
  379.     {
  380.       SetCardValues(editCard.card, document);
  381.  
  382.       var directory = GetDirectoryFromURI(uri);
  383.  
  384.       // replace editCard.card with the card we added
  385.       // so that save listeners can get / set attributes on
  386.       // the card that got created.
  387.       var addedCard = directory.addCard(editCard.card);
  388.       editCard.card = addedCard;
  389.       NotifySaveListeners();
  390.     }
  391.   }
  392.  
  393.   return true;  // close the window
  394. }
  395.  
  396. // Move the data from the cardproperty to the dialog
  397. function GetCardValues(cardproperty, doc)
  398. {
  399.   if ( cardproperty )
  400.   {
  401.     doc.getElementById('FirstName').value = cardproperty.firstName;
  402.     doc.getElementById('LastName').value = cardproperty.lastName;
  403.     doc.getElementById('DisplayName').value = cardproperty.displayName;
  404.     doc.getElementById('NickName').value = cardproperty.nickName;
  405.  
  406.     doc.getElementById('PrimaryEmail').value = cardproperty.primaryEmail;
  407.     doc.getElementById('SecondEmail').value = cardproperty.secondEmail;
  408.     doc.getElementById('ScreenName').value = cardproperty.aimScreenName;
  409.  
  410.     var popup = document.getElementById('PreferMailFormatPopup');
  411.     if ( popup )
  412.       popup.value = cardproperty.preferMailFormat;
  413.  
  414.     doc.getElementById('WorkPhone').value = cardproperty.workPhone;
  415.     doc.getElementById('HomePhone').value = cardproperty.homePhone;
  416.     doc.getElementById('FaxNumber').value = cardproperty.faxNumber;
  417.     doc.getElementById('PagerNumber').value = cardproperty.pagerNumber;
  418.     doc.getElementById('CellularNumber').value = cardproperty.cellularNumber;
  419.  
  420.     doc.getElementById('HomeAddress').value = cardproperty.homeAddress;
  421.     doc.getElementById('HomeAddress2').value = cardproperty.homeAddress2;
  422.     doc.getElementById('HomeCity').value = cardproperty.homeCity;
  423.     doc.getElementById('HomeState').value = cardproperty.homeState;
  424.     doc.getElementById('HomeZipCode').value = cardproperty.homeZipCode;
  425.     doc.getElementById('HomeCountry').value = cardproperty.homeCountry;
  426.     doc.getElementById('WebPage2').value = cardproperty.webPage2;
  427.  
  428.     doc.getElementById('JobTitle').value = cardproperty.jobTitle;
  429.     doc.getElementById('Department').value = cardproperty.department;
  430.     doc.getElementById('Company').value = cardproperty.company;
  431.     doc.getElementById('WorkAddress').value = cardproperty.workAddress;
  432.     doc.getElementById('WorkAddress2').value = cardproperty.workAddress2;
  433.     doc.getElementById('WorkCity').value = cardproperty.workCity;
  434.     doc.getElementById('WorkState').value = cardproperty.workState;
  435.     doc.getElementById('WorkZipCode').value = cardproperty.workZipCode;
  436.     doc.getElementById('WorkCountry').value = cardproperty.workCountry;
  437.     doc.getElementById('WebPage1').value = cardproperty.webPage1;
  438.  
  439.     doc.getElementById('Custom1').value = cardproperty.custom1;
  440.     doc.getElementById('Custom2').value = cardproperty.custom2;
  441.     doc.getElementById('Custom3').value = cardproperty.custom3;
  442.     doc.getElementById('Custom4').value = cardproperty.custom4;
  443.     doc.getElementById('Notes').value = cardproperty.notes;
  444.  
  445.     // get phonetic fields if exist
  446.     try {
  447.       doc.getElementById('PhoneticFirstName').value = cardproperty.phoneticFirstName;
  448.       doc.getElementById('PhoneticLastName').value = cardproperty.phoneticLastName;
  449.     }
  450.     catch (ex) {}
  451.   }
  452. }
  453.  
  454. // when the ab card dialog is being loaded to show a vCard, 
  455. // hide the fields which aren't supported
  456. // by vCard so the user does not try to edit them.
  457. function HideNonVcardFields()
  458. {
  459.   document.getElementById('nickNameContainer').collapsed = true;
  460.   document.getElementById('secondaryEmailContainer').collapsed = true;
  461.   document.getElementById('screenNameContainer').collapsed = true;
  462.   document.getElementById('homeAddressGroup').collapsed = true;
  463.   document.getElementById('customFields').collapsed = true;
  464.  
  465. }
  466.  
  467. // Move the data from the dialog to the cardproperty to be stored in the database
  468. function SetCardValues(cardproperty, doc)
  469. {
  470.   if (cardproperty)
  471.   {
  472.     cardproperty.firstName = doc.getElementById('FirstName').value;
  473.     cardproperty.lastName = doc.getElementById('LastName').value;
  474.     cardproperty.displayName = doc.getElementById('DisplayName').value;
  475.     cardproperty.nickName = doc.getElementById('NickName').value;
  476.  
  477.     cardproperty.primaryEmail = doc.getElementById('PrimaryEmail').value;
  478.     cardproperty.secondEmail = doc.getElementById('SecondEmail').value;
  479.     cardproperty.aimScreenName = doc.getElementById('ScreenName').value;
  480.  
  481.     var popup = document.getElementById('PreferMailFormatPopup');
  482.     if ( popup )
  483.       cardproperty.preferMailFormat = popup.value;
  484.  
  485.     cardproperty.workPhone = doc.getElementById('WorkPhone').value;
  486.     cardproperty.homePhone = doc.getElementById('HomePhone').value;
  487.     cardproperty.faxNumber = doc.getElementById('FaxNumber').value;
  488.     cardproperty.pagerNumber = doc.getElementById('PagerNumber').value;
  489.     cardproperty.cellularNumber = doc.getElementById('CellularNumber').value;
  490.  
  491.     cardproperty.homeAddress = doc.getElementById('HomeAddress').value;
  492.     cardproperty.homeAddress2 = doc.getElementById('HomeAddress2').value;
  493.     cardproperty.homeCity = doc.getElementById('HomeCity').value;
  494.     cardproperty.homeState = doc.getElementById('HomeState').value;
  495.     cardproperty.homeZipCode = doc.getElementById('HomeZipCode').value;
  496.     cardproperty.homeCountry = doc.getElementById('HomeCountry').value;
  497.     cardproperty.webPage2 = CleanUpWebPage(doc.getElementById('WebPage2').value);
  498.  
  499.     cardproperty.jobTitle = doc.getElementById('JobTitle').value;
  500.     cardproperty.department = doc.getElementById('Department').value;
  501.     cardproperty.company = doc.getElementById('Company').value;
  502.     cardproperty.workAddress = doc.getElementById('WorkAddress').value;
  503.     cardproperty.workAddress2 = doc.getElementById('WorkAddress2').value;
  504.     cardproperty.workCity = doc.getElementById('WorkCity').value;
  505.     cardproperty.workState = doc.getElementById('WorkState').value;
  506.     cardproperty.workZipCode = doc.getElementById('WorkZipCode').value;
  507.     cardproperty.workCountry = doc.getElementById('WorkCountry').value;
  508.     cardproperty.webPage1 = CleanUpWebPage(doc.getElementById('WebPage1').value);
  509.  
  510.     cardproperty.custom1 = doc.getElementById('Custom1').value;
  511.     cardproperty.custom2 = doc.getElementById('Custom2').value;
  512.     cardproperty.custom3 = doc.getElementById('Custom3').value;
  513.     cardproperty.custom4 = doc.getElementById('Custom4').value;
  514.     cardproperty.notes = doc.getElementById('Notes').value;
  515.  
  516.     // set phonetic fields if exist
  517.     try {
  518.       cardproperty.phoneticFirstName = doc.getElementById('PhoneticFirstName').value;
  519.       cardproperty.phoneticLastName = doc.getElementById('PhoneticLastName').value;
  520.     }
  521.     catch (ex) {}
  522.   }
  523. }
  524.  
  525. function CleanUpWebPage(webPage)
  526. {
  527.   // no :// yet so we should add something
  528.   if ( webPage.length && webPage.search("://") == -1 )
  529.   {
  530.     // check for missing / on http://
  531.     if ( webPage.substr(0, 6) == "http:/" )
  532.       return( "http://" + webPage.substr(6) );
  533.     else
  534.       return( "http://" + webPage );
  535.   }
  536.   else
  537.     return(webPage);
  538. }
  539.  
  540.  
  541. function GenerateDisplayName()
  542. {
  543.   if ( editCard.generateDisplayName )
  544.   {
  545.     var displayName;
  546.  
  547.     var firstNameField = document.getElementById('FirstName');
  548.     var lastNameField = document.getElementById('LastName');
  549.     var displayNameField = document.getElementById('DisplayName');
  550.  
  551.     if (lastNameField.value && firstNameField.value) {
  552.       if ( editCard.displayLastNameFirst )
  553.         displayName = gAddressBookBundle.getFormattedString("lastFirstFormat",[ lastNameField.value, firstNameField.value ]);
  554.       else
  555.         displayName = gAddressBookBundle.getFormattedString("firstLastFormat",[ firstNameField.value, lastNameField.value ]);
  556.     }
  557.     else {
  558.       // one (or both) of these is empty, so this works.
  559.       displayName = firstNameField.value + lastNameField.value;
  560.     }
  561.  
  562.     displayNameField.value = displayName;
  563.  
  564.     SetCardDialogTitle(displayName);
  565.   }
  566. }
  567.  
  568. function DisplayNameChanged()
  569. {
  570.   // turn off generateDisplayName if the user changes the display name
  571.   editCard.generateDisplayName = false;
  572.  
  573.     var displayName = document.getElementById('DisplayName').value;
  574.  
  575.   SetCardDialogTitle(displayName);
  576. }
  577.  
  578. function SetCardDialogTitle(displayName)
  579. {
  580.    top.window.title = displayName ? gAddressBookBundle.getFormattedString(editCard.titleProperty + "WithDisplayName", [displayName]) : gAddressBookBundle.getString(editCard.titleProperty);                                          
  581. }
  582.