add:   if (!oldSelection || oldSelection < 0) { var defaultCalendar = composite.defaultCalendar; var item = defaultCalendar ? getListItem(defaultCalendar) : null; oldSelection = item ? calendarList.getIndexOfItem(item) : 0; } if (oldSelection >= calendars.length) { oldSelection = calendars.length-1; }  
context: function setCalendarManagerUI(){    var calendarList = document.getElementById("list-calendars-listbox");    var oldSelection = calendarList.selectedIndex;    if (!oldSelection || oldSelection < 0) {        oldSelection = 0;    }    var child;    while ((child = calendarList.lastChild) && (child.tagName == "listitem")) {        calendarList.removeChild(child);    }    var composite = getCompositeCalendar();    var calmgr = getCalendarManager();    var calendars = calmgr.getCalendars({});    if (oldSelection >= calendars.length) {        oldSelection = calendars.length-1;    }    var hasRefreshableCal = false;    for each (var calendar in calendars) {        if (calendar.canRefresh) {            hasRefreshableCal = true;        }        var listItem = document.createElement("listitem");        var checkCell = document.createElement("listcell");        checkCell.setAttribute("type", "checkbox");        checkCell.setAttribute("checked",                                composite.getCalendar(calendar.uri) ? true : false);        listItem.appendChild(checkCell);        listItem.addEventListener("click", onCalendarCheckboxClick, true);        var colorCell = document.createElement("listcell");        try {           var calColor = calmgr.getCalendarPref(calendar, 'color');           colorCell.style.background = calColor;        } catch(e) {}        listItem.appendChild(colorCell);        var nameCell = document.createElement("listcell");        nameCell.setAttribute("label", calendar.name);        listItem.appendChild(nameCell);        listItem.calendar = calendar;        calendarList.appendChild(listItem);    }    calendarList.selectedIndex = oldSelection;    var remoteCommand = document.getElementById("reload_remote_calendars");    if (!hasRefreshableCal) {        remoteCommand.setAttribute("disabled", true);    } else {        remoteCommand.removeAttribute("disabled");    }}
meta: 10234	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/10234/04a723ed6e15f5174c7e8978dcb49263d824a8c8/calendarManagement.js/buggy/calendar/resources/content/calendarManagement.js