Merge new summary view branches changes into trunk
[citadel.git] / webcit / static / wclib.js
index 1d04a9e50fc516d8c5c5669c238253f62ed4e855..b2d62e1a73e20185c0dd6cc1e5825cbb4b888529 100644 (file)
@@ -9,24 +9,51 @@
 var browserType;
 var room_is_trash = 0;
 
-if (document.layers) {
-       browserType = "nn4";
-}
-if (document.all) {
-       browserType = "ie";
-}
+var currentlyExpandedFloor = null;
+var roomlist = null;
+
+var _switchToRoomList = "switch to room list";
+var _switchToMenu = "switch to menu";
+
+var currentDropTarget = null;
+
+var supportsAddEventListener = (!!document.addEventListener);
+var today = new Date();
+
+if (document.all) {browserType = "ie"}
 if (window.navigator.userAgent.toLowerCase().match("gecko")) {
        browserType= "gecko";
 }
-
 var ns6=document.getElementById&&!document.all;
 Event.observe(window, 'load', ToggleTaskDateOrNoDateActivate);
 Event.observe(window, 'load', taskViewActivate);
+//document.observe("dom:loaded", setupPrefEngine);
+document.observe("dom:loaded", setupIconBar);
 function CtdlRandomString()  {
        return((Math.random()+'').substr(3));
 }
 
-
+function emptyElement(element) {
+  childNodes = element.childNodes;
+  for(var i=0; i<childNodes.length; i++) {
+    element.removeChild(childNodes[i]);
+  }
+}
+/** Implements superior internet explorer 'extract all child text from element' feature'. Falls back on buggy, patent violating standardized method */
+function getTextContent(element) {
+  if (element.textContent == undefined) {
+    return element.innerText;
+  }
+  return element.textContent;
+}
+/** Same reasons as above */
+function setTextContent(element, textContent) {
+  if(element.textContent == undefined) {
+    element.innerText = textContent;
+  } else {
+  element.textContent = textContent;
+  }
+}
 
 // We love string tokenizers.
 function extract_token(source_string, token_num, delimiter) {
@@ -50,8 +77,32 @@ function extract_token(source_string, token_num, delimiter) {
        return extracted_string;
 }
 
-
-
+function CtdlSpawnContextMenu(event, source) {
+  // remove any existing menus
+  disintergrateContextMenus(null);
+  var x = event.clientX-10; // cut a few pixels out so our mouseout works right
+  var y = event.clientY-10;
+  var contextDIV = document.createElement("div");
+  contextDIV.setAttribute("id", "ctdlContextMenu");
+  document.body.appendChild(contextDIV);
+  var sourceChildren = source.childNodes;
+  for(var j=0; j<sourceChildren.length; j++) {
+    contextDIV.appendChild(sourceChildren[j].cloneNode(true));
+  }
+  var leftRule = "left: "+x+"px;";
+  contextDIV.setAttribute("style", leftRule);
+  contextDIV.setAttribute("actual", leftRule);
+  contextDIV.style.top = y+"px";
+  contextDIV.style.display = "block";
+  $(contextDIV).observe('mouseout',disintergrateContextMenus);
+}
+function disintergrateContextMenus(event) {
+  var contextMenu = document.getElementById("ctdlContextMenu");
+  if (contextMenu) {
+    contextMenu.parentNode.removeChild(contextMenu);
+  }
+  Event.stopObserving(document,'click',disintergrateContextMenus);
+}
 // This code handles the popups for important-messages.
 function hide_imsg_popup() {
        if (browserType == "gecko") {
@@ -75,362 +126,181 @@ function activate_entmsg_autocompleters() {
        new Ajax.Autocompleter('recp_id', 'recp_name_choices', 'recp_autocomplete', {} );
 }
 
-
-
-// Toggle the icon bar between menu/roomlist...
-var which_div_expanded = null;
-var num_drop_targets = 0;
-var drop_targets_elements = new Array();
-var drop_targets_roomnames = new Array();
-
-function switch_to_room_list() {
-       $('iconbar').innerHTML = $('iconbar').innerHTML.substr(0, $('iconbar').innerHTML.indexOf('switch'));
-       CtdlLoadScreen('iconbar');
-       new Ajax.Updater('iconbar', 'iconbar_ajax_rooms', { method: 'get' } );
+function setupIconBar() {
+  if (!document.getElementById("switch")) {
+      return;
+    }
+  var switchSpan = document.getElementById("switch").firstChild;
+  if (switchSpan != null) {
+    setTextContent(switchSpan, _switchToRoomList);
+    $(switchSpan).observe('click', changeIconBarEvent);
+    var currentView = ctdlLocalPrefs.readPref("iconbar_view");
+    if (currentView != null) {
+      switchSpan.ctdlSwitchIconBarTo = currentView;
+      changeIconBar(switchSpan);
+    } else {
+      switchSpan.ctdlSwitchIconBarTo = "rooms";
+    }
+  }
+  var online_users = document.getElementById("online_users");
+  var ou_displayAs = online_users.style.display;
+  if (ou_displayAs != "none") {
+    new Ajax.PeriodicalUpdater('online_users', 'do_template?template=wholist_section', {method: 'get', frequency: 30});
+  }
+}
+function changeIconBarEvent(event) {
+  changeIconBar(event.target);
+}
+function changeIconBar(target) {
+  var switchTo = target.ctdlSwitchIconBarTo;
+  if (!!window.console) {
+    console.log("Changing to: " + switchTo);
+  }
+  ctdlLocalPrefs.setPref("iconbar_view", target.ctdlSwitchIconBarTo);  
+  if (switchTo == "rooms") {
+    switch_to_room_list();
+    setTextContent(target, _switchToMenu);
+    target.ctdlSwitchIconBarTo = "menu";
+  } else {
+    switch_to_menu_buttons();
+    setTextContent(target, _switchToRoomList);
+    target.ctdlSwitchIconBarTo = "rooms";
+  }
 }
-
-function expand_floor(floor_div) {
-       if (which_div_expanded != null) {
-               if ($(which_div_expanded) != null) {
-                       $(which_div_expanded).style.display = 'none' ;
-               }
-       }
-
-       // clicking on the already-expanded floor causes the whole list to collapse
-       if (which_div_expanded == floor_div) {
-               which_div_expanded = null;
-
-               // notify the server that no floors are expanded
-               new Ajax.Request(
-                       'set_floordiv_expanded/-1', {
-                               method: 'post'
-                       }
-               );
-               return true;
-       }
-
-       // expand the requested floor
-       $(floor_div).style.display = 'block';
-       which_div_expanded = floor_div;
-
-       // notify the server of which floor is expanded
-       new Ajax.Request(
-               'set_floordiv_expanded/'+floor_div, {
-                       method: 'post'
-               }
-       );
+function switch_to_room_list() {
+  var roomlist = document.getElementById("roomlist");
+  var summary = document.getElementById("iconbar_menu");
+  if (!rooms || !floors || !roomlist) {
+    FillRooms(IconBarRoomList);
+  }
+  roomlist.className = roomlist.className.replace("hidden","");
+  summary.className += " hidden";
 }
 
 function switch_to_menu_buttons() {
-       which_div_expanded = null;
-       num_drop_targets = 0;
-       CtdlLoadScreen('iconbar');
-       new Ajax.Updater('iconbar', 'iconbar_ajax_menu', { method: 'get' } );
-}
-
-
-// Static variables for mailbox view...
-//
-var CtdlNumMsgsSelected = 0;
-var CtdlMsgsSelected = new Array();
-var CtdlLastMsgnumSelected = 0;
-
-// This gets called when you single click on a message in the mailbox view.
-// We know that the element id of the table row will be the letter 'm' plus the message number.
-//
-function CtdlSingleClickMsg(evt, msgnum) {
-
-       // Clear the preview pane until we load the new message
-       $('preview_pane').innerHTML = '';
-
-       // De-select any messages that were already selected, *unless* the Ctrl or
-       // Shift key is being pressed, in which case the user wants multi select
-       // or group select.
-       if ( (!evt.ctrlKey) && (!evt.shiftKey) ) {
-               if (CtdlNumMsgsSelected > 0) {
-                       for (i=0; i<CtdlNumMsgsSelected; ++i) {
-                               $('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
-                               $('m'+CtdlMsgsSelected[i]).style.color = '#000';
-                       }
-                       CtdlNumMsgsSelected = 0;
-               }
-       }
-
-       // For multi select ... is the message being clicked already selected?
-       already_selected = 0;
-       if ( (evt.ctrlKey) && (CtdlNumMsgsSelected > 0) ) {
-               for (i=0; i<CtdlNumMsgsSelected; ++i) {
-                       if (CtdlMsgsSelected[i] == msgnum) {
-                               already_selected = 1;
-                               already_selected_pos = i;
-                       }
-               }
-       }
-
-       // Now select (or de-select) the message
-       if ( (evt.ctrlKey) && (already_selected == 1) ) {
-
-               // Deselect: first un-highlight it...
-               $('m'+msgnum).style.backgroundColor = '#fff';
-               $('m'+msgnum).style.color = '#000';
-
-               // Then remove it from the selected messages list.
-               for (i=already_selected_pos; i<(CtdlNumMsgsSelected-1); ++i) {
-                       CtdlMsgsSelected[i] = CtdlMsgsSelected[i+1];
-               }
-               CtdlNumMsgsSelected = CtdlNumMsgsSelected - 1;
-               
-       }
-
-       else if (evt.shiftKey) {
-               
-               // Group select: first clear everything out...
-               if (CtdlNumMsgsSelected > 0) {
-                       for (i=0; i<CtdlNumMsgsSelected; ++i) {
-                               $('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
-                               $('m'+CtdlMsgsSelected[i]).style.color = '#000';
-                       }
-               }
-               CtdlNumMsgsSelected = 0;
-
-               // Then highlight and select the group.
-               // Traverse the table looking for a row whose ID contains the desired msgnum
-
-               var in_the_group = 0;
-               var is_edge = 0;
-               var table = $('summary_headers');
-               if (table) {
-                       for (var r = 0; r < table.rows.length; r++) {
-                               var thename = table.rows[r].id;
-                               if ( (thename.substr(1) == msgnum) || (thename.substr(1) == CtdlLastMsgnumSelected) ) {
-                                       in_the_group = 1 - in_the_group;
-                                       is_edge = 1;
-                               }
-                               else {
-                                       is_edge = 0;
-                               }
-                               if ( (in_the_group == 1) || (is_edge == 1) ) {
-                                       // Highlight it...
-                                       table.rows[r].style.backgroundColor='#69aaff';
-                                       table.rows[r].style.color='#fff';
-
-                                       // And add it to the selected messages list.
-                                       CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
-                                       CtdlMsgsSelected[CtdlNumMsgsSelected-1] = thename.substr(1);
-                               }
-                       }
-               }
-       }
-
-       else {
-               // Select: first highlight it...
-               $('m'+msgnum).style.backgroundColor='#69aaff';
-               $('m'+msgnum).style.color='#fff';
-
-               // Then add it to the selected messages list.
-               CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
-               CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
-
-               // Gradient
-               CtdlLoadScreen('preview_pane');
-               // Update the preview pane
-               new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
-       
-               // Mark the message as read
-               new Ajax.Request(
-                       'ajax_servcmd', {
-                               method: 'post',
-                               parameters: 'g_cmd=SEEN '+msgnum+'|1',
-                               onComplete: CtdlRemoveTheUnseenBold(msgnum)
-                       }
-               );
-       }
-       
-       // Save the selected position in case the user does a group select next time.
-       CtdlLastMsgnumSelected = msgnum;
-
-       return false;           // try to defeat the default click behavior
-}
-
-// Delete selected messages.
-function CtdlDeleteSelectedMessages(evt) {
-       
-       if (CtdlNumMsgsSelected < 1) {
-               // Nothing to delete, so exit silently.
-               return false;
-       }
-       for (i=0; i<CtdlNumMsgsSelected; ++i) {
-               if (parseInt(room_is_trash) > 0) {
-                       new Ajax.Request(
-                               'ajax_servcmd', {
-                                       method: 'post',
-                                       parameters: 'g_cmd=DELE ' + CtdlMsgsSelected[i],
-                                       onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
-                               }
-                       );
-               }
-               else {
-                       new Ajax.Request(
-                               'ajax_servcmd', {
-                                       method: 'post',
-                                       parameters: 'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|_TRASH_|0',
-                                       onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
-                               }
-                       );
-               }
-       }
-       CtdlNumMsgsSelected = 0;
-
-       // Clear the preview pane too.
-       $('preview_pane').innerHTML = '';
-}
-
-
-// Move selected messages.
-function CtdlMoveSelectedMessages(evt, target_roomname) {
-       
-       if (CtdlNumMsgsSelected < 1) {
-               // Nothing to delete, so exit silently.
-               return false;
-       }
-       for (i=0; i<CtdlNumMsgsSelected; ++i) {
-               new Ajax.Request(
-                       'ajax_servcmd', {
-                               method:'post',
-                               parameters:'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|' + target_roomname + '|0',
-                               onComplete:CtdlClearDeletedMsg(CtdlMsgsSelected[i])
-                       }
-               );
-       }
-       CtdlNumMsgsSelected = 0;
-
-       // Clear the preview pane too.
-       $('preview_pane').innerHTML = '';
-}
-
-
-
-// This gets called when the user touches the keyboard after selecting messages...
-function CtdlMsgListKeyPress(evt) {
-       if(document.all) {                              // aIEeee
-               var whichKey = window.event.keyCode;
-       }
-       else {                                          // non-sux0r browsers
-               var whichKey = evt.which;
-       }
-       if (whichKey == 46) {                           // DELETE key
-               CtdlDeleteSelectedMessages(evt);
-       }
-       return true;
-}
-
-// Take the boldface away from a message to indicate that it has been seen.
-function CtdlRemoveTheUnseenBold(msgnum) {
-       $('m'+msgnum).style.fontWeight='normal';
-}
-
-// A message has been deleted, so yank it from the list.
-function CtdlClearDeletedMsg(msgnum) {
-
-
-       // Traverse the table looking for a row whose ID contains the desired msgnum
-       var table = $('summary_headers');
-       if (table) {
-               for (var r = 0; r < table.rows.length; r++) {
-                       var thename = table.rows[r].id;
-                       if (thename.substr(1) == msgnum) {
-                               try {
-                                       table.deleteRow(r);
-                               }
-                               catch(e) {
-                                       alert('error: browser failed to clear row ' + r);
-                               }
-                       }
-               }
-       }
-       else {                                          // if we can't delete it,
-               new Effect.Squish('m'+msgnum);          // just hide it.
-       }
-
-
-}
-
-// These functions called when the user down-clicks on the message list resizer bar
-
-var saved_x = 0;
-var saved_y = 0;
-
-function CtdlResizeMsgListMouseUp(evt) {
-       document.onmouseup = null;
-       document.onmousemove = null;
-       if (document.layers) {
-               document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
-       }
-       return true;
-}
-
-function CtdlResizeMsgListMouseMove(evt) {
-       y = (ns6 ? evt.clientY : event.clientY);
-       increment = y - saved_y;
-
-       // First move the bottom of the message list...
-       d = $('message_list');
-       if (d.offsetHeight){
-               divHeight = d.offsetHeight;
-       }
-       else if (d.style.pixelHeight) {
-               divHeight = d.style.pixelHeight;
-       }
-       d.style.height = (divHeight + increment) + 'px';
-
-       // Then move the top of the preview pane...
-       d = $('preview_pane');
-       if (d.offsetTop){
-               divTop = d.offsetTop;
-       }
-       else if (d.style.pixelTop) {
-               divTop = d.style.pixelTop;
-       }
-       d.style.top = (divTop + increment) + 'px';
-
-       // Resize the bottom of the preview pane...
-       d = $('preview_pane');
-       if (d.offsetHeight){
-               divHeight = d.offsetHeight;
-       }
-       else if (d.style.pixelHeight) {
-               divHeight = d.style.pixelHeight;
-       }
-       d.style.height = (divHeight - increment) + 'px';
-
-       // Then move the top of the slider bar.
-       d = $('resize_msglist');
-       if (d.offsetTop){
-               divTop = d.offsetTop;
-       }
-       else if (d.style.pixelTop) {
-               divTop = d.style.pixelTop;
-       }
-       d.style.top = (divTop + increment) + 'px';
-
-       saved_y = y;
-       return true;
-}
-
-function CtdlResizeMsgListMouseDown(evt) {
-       saved_y = (ns6 ? evt.clientY : event.clientY);
-       document.onmouseup = CtdlResizeMsgListMouseUp;
-       document.onmousemove = CtdlResizeMsgListMouseMove;
-       if (document.layers) {
-               document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
-       }
-       return false;           // disable the default action
+  if (roomlist != null) {
+    roomlist.className += "hidden";
+  }
+  var iconbar = document.getElementById("iconbar_menu");
+  iconbar.className = iconbar.className.replace("hidden","");
+  var roomlist = document.getElementById("roomlist");
+  roomlist.className += " hidden";
+}
+function IconBarRoomList() {
+  var currentExpanded = ctdlLocalPrefs.readPref("rooms_expanded");
+  currentDropTargets = new Array();
+  var iconbar = document.getElementById("iconbar");
+  roomlist = document.getElementById("roomlist");
+  var ul = document.createElement("ul");
+  roomlist.appendChild(ul);
+  // Add mailbox, because they are special
+  var mailboxLI = document.createElement("li");
+  ul.appendChild(mailboxLI);
+  var mailboxSPAN = document.createElement("span");
+  mailboxSPAN.appendChild(document.createTextNode("Mailbox"));
+  $(mailboxSPAN).observe('click', expandFloorEvent);
+  mailboxLI.appendChild(mailboxSPAN);
+  mailboxLI.setAttribute("class", "floor");
+  var mailboxUL = document.createElement("ul");
+  mailboxLI.appendChild(mailboxUL);
+  var mailboxRooms = GetMailboxRooms();
+  for(var i=0; i<mailboxRooms.length; i++) {
+    var room = mailboxRooms[i];
+    currentDropTargets.push(addRoomToList(mailboxUL, room));
+  }
+  if (currentExpanded != null && currentExpanded == "Mailbox") {
+    expandFloor(mailboxSPAN);
+  }
+  for(var a=0; a<floors.length; a++) {
+    var floor = floors[a];
+    var floornum = floor[0];
+    var name = floor[1];
+    var floorLI = document.createElement("li");
+    ul.appendChild(floorLI);
+    var floorSPAN = document.createElement("span");
+    floorSPAN.appendChild(document.createTextNode(name));
+    $(floorSPAN).observe('click', expandFloorEvent);
+    floorLI.appendChild(floorSPAN);
+    floorLI.setAttribute("class", "floor");
+    var floorUL = document.createElement("ul");
+    floorLI.appendChild(floorUL);
+    var roomsForFloor = GetRoomsByFloorNum(floornum);
+    for(var b=0; b<roomsForFloor.length; b++) {
+      var room = roomsForFloor[b];
+      currentDropTargets.push(addRoomToList(floorUL, room));
+    }
+    if (currentExpanded != null && currentExpanded == name) {
+      expandFloor(floorSPAN);
+    }
+  }
+}
+
+function addRoomToList(floorUL,room) {
+  var roomName = room[RN_ROOM_NAME];
+  var flag = room[RN_ROOM_FLAG];
+  var curView = room[RN_CUR_VIEW];
+  var view = room[RN_DEF_VIEW];
+  var isMailBox = ((flag & QR_MAILBOX) == QR_MAILBOX);
+  var hasNewMsgs = ((curView & UA_HASNEWMSGS) == UA_HASNEWMSGS);
+  var roomLI = document.createElement("li");
+  var roomA = document.createElement("a");
+  roomA.setAttribute("href","dotgoto?room="+roomName);
+  roomA.appendChild(document.createTextNode(roomName));
+  roomLI.appendChild(roomA);
+  floorUL.appendChild(roomLI);
+  var className = "room ";
+  if (view == VIEW_MAILBOX) {
+    className += "room-private"
+  } else if (view == VIEW_ADDRESSBOOK) {
+    className += "room-addr";
+  } else if (view == VIEW_CALENDAR || view == VIEW_CALBRIEF) {
+    className += "room-cal";
+  } else if (view == VIEW_TASKS) {
+    className += "room-tasks";
+  } else if (view == VIEW_NOTES) {
+    className += "room-notes";
+  } else {
+    className += "room-chat";
+  }
+  if (hasNewMsgs) {
+    className += " room-newmsgs";
+  }
+  roomLI.setAttribute("class", className);
+  roomA.dropTarget = true;
+  roomA.dropHandler = roomListDropHandler;
+  return roomLI;
+}
+
+function roomListDropHandler(target, dropped) {
+  if (dropped.ctdlMsgId) {
+    var room = getTextContent(target);
+    var msgIds = "";
+    for(msgId in currentlyMarkedRows) { //defined in summaryview.js
+      msgIds += ","+msgId;
+    }
+    var mvCommand = "g_cmd=MOVE " + msgIds + "|"+room+"|0";
+    new Ajax.Request('ajax_servcmd', {
+      method: 'post',
+         parameters: mvCommand,
+         onComplete: deleteAllMarkedRows()});
+    } 
+}
+function expandFloorEvent(event) {
+  expandFloor(event.target);
+}
+function expandFloor(target) {
+  if (target.nodeName.toLowerCase() != "span") {
+    return; // ignore clicks on child UL
+  }
+  ctdlLocalPrefs.setPref("rooms_expanded", target.firstChild.nodeValue);
+  var parentUL = target.parentNode;
+  if (currentlyExpandedFloor != null) {
+    currentlyExpandedFloor.className = currentlyExpandedFloor.className.replace("floor-expanded","");
+  }
+  parentUL.className = parentUL.className + " floor-expanded";
+  currentlyExpandedFloor = parentUL;
 }
 
-
-
-
-
 // These functions handle moving sticky notes around the screen by dragging them
 
 var uid_of_note_being_dragged = 0;
@@ -654,128 +524,6 @@ function DeleteStickyNote(evt, uid, confirmation_prompt) {
        }
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// These functions handle drag and drop message moving
-
-var mm_div = null;
-
-function CtdlMoveMsgMouseDown(evt, msgnum) {
-
-       // do the highlight first
-       CtdlSingleClickMsg(evt, msgnum);
-
-       // Now handle the possibility of dragging
-       saved_x = (ns6 ? evt.clientX : event.clientX);
-       saved_y = (ns6 ? evt.clientY : event.clientY);
-       document.onmouseup = CtdlMoveMsgMouseUp;
-       document.onmousemove = CtdlMoveMsgMouseMove;
-       if (document.layers) {
-               document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
-       }
-
-       return false;
-}
-
-function CtdlMoveMsgMouseMove(evt) {
-       x = (ns6 ? evt.clientX : event.clientX);
-       y = (ns6 ? evt.clientY : event.clientY);
-
-       if ( (x == saved_x) && (y == saved_y) ) {
-               return true;
-       }
-
-       if (CtdlNumMsgsSelected < 1) { 
-               return true;
-       }
-
-       if (!mm_div) {
-
-
-               drag_o_text = "<div style=\"overflow:none; background-color:#fff; color:#000; border: 1px solid black; filter:alpha(opacity=75); -moz-opacity:.75; opacity:.75;\"><tr><td>";
-               for (i=0; i<CtdlNumMsgsSelected; ++i) {
-                       drag_o_text = drag_o_text + 
-                               ctdl_ts_getInnerText(
-                                       $('m'+CtdlMsgsSelected[i]).cells[0]
-                               ) + '<br>';
-               }
-               drag_o_text = drag_o_text + "<div>";
-
-               mm_div = document.createElement("DIV");
-               mm_div.style.position='absolute';
-               mm_div.style.top = y + 'px';
-               mm_div.style.left = x + 'px';
-               mm_div.style.pixelHeight = '300';
-               mm_div.style.pixelWidth = '300';
-               mm_div.innerHTML = drag_o_text;
-               document.body.appendChild(mm_div);
-       }
-       else {
-               mm_div.style.top = y + 'px';
-               mm_div.style.left = x + 'px';
-       }
-
-       return false;   // prevent the default mouse action from happening?
-}
-
-function CtdlMoveMsgMouseUp(evt) {
-       document.onmouseup = null;
-       document.onmousemove = null;
-       if (document.layers) {
-               document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
-       }
-
-       if (mm_div) {
-               document.body.removeChild(mm_div);      
-               mm_div = null;
-       }
-
-       if (num_drop_targets < 1) {     // nowhere to drop
-               return true;
-       }
-
-       // Did we release the mouse button while hovering over a drop target?
-       // NOTE: this only works cross-browser because the iconbar div is always
-       //      positioned at 0,0.  Browsers differ in whether the 'offset'
-       //      functions return pos relative to the document or parent.
-
-       for (i=0; i<num_drop_targets; ++i) {
-
-               x = (ns6 ? evt.clientX : event.clientX);
-               y = (ns6 ? evt.clientY : event.clientY);
-
-               l = parseInt(drop_targets_elements[i].offsetLeft);
-               t = parseInt(drop_targets_elements[i].offsetTop);
-               r = parseInt(drop_targets_elements[i].offsetLeft)
-                 + parseInt(drop_targets_elements[i].offsetWidth);
-               b = parseInt(drop_targets_elements[i].offsetTop)
-                 + parseInt(drop_targets_elements[i].offsetHeight);
-
-               /* alert('Offsets are: ' + l + ' ' + t + ' ' + r + ' ' + b + '.'); */
-       
-               if ( (x >= l) && (x <= r) && (y >= t) && (y <= b) ) {
-                       // Yes, we dropped it on a hotspot.
-                       CtdlMoveSelectedMessages(evt, drop_targets_roomnames[i]);
-                       return true;
-               }
-       }
-
-       return true;
-}
-
-
 function ctdl_ts_getInnerText(el) {
        if (typeof el == "string") return el;
        if (typeof el == "undefined") { return el };
@@ -798,67 +546,6 @@ function ctdl_ts_getInnerText(el) {
 }
 
 
-function CtdlShowRaw(msgnum) {
-var customnav = document.createElement("span");
-var mode_citadel = document.createElement("a");
-mode_citadel.appendChild(document.createTextNode("Citadel Source"));
-var mode_rfc822 = document.createElement("a");
-mode_rfc822.appendChild(document.createTextNode(" RFC822 Source"));
-mode_citadel.setAttribute("href","#");
-mode_rfc822.setAttribute("href","#");
-mode_rfc822.setAttribute("onclick","rawSwitch822('" + msgnum + "');");
-mode_citadel.setAttribute("onclick","rawSwitchCitadel('" + msgnum + "');");
-customnav.appendChild(mode_citadel);
-customnav.appendChild(mode_rfc822);
-customnav.setAttribute("class","floatcustomnav");
-floatwindow("headerscreen","pre",customnav);
-rawSwitch822(msgnum);
-}
-
-function rawSwitch822(msgnum) {
-CtdlLoadScreen("headerscreen");
-new Ajax.Updater("headerscreen", 
-'ajax_servcmd_esc',
- { method: 'post',parameters: 'g_cmd=MSG2 ' +msgnum  } );
-
-}
-
-function rawSwitchCitadel(msgnum) {
-CtdlLoadScreen("headerscreen");
-new Ajax.Updater("headerscreen", 
-'ajax_servcmd_esc',
- { method: 'post',parameters: 'g_cmd=MSG0 ' +msgnum  } );
-
-}
-
-function floatwindow(newdivid,contentelementtype,customnav) {
-var windiv = document.createElement("div");
-windiv.setAttribute("class","floatwindow");
-var winid = newdivid+"_window";
-windiv.setAttribute("id",winid);
-var nav = document.createElement("div");
-if (customnav != null) {
-nav.appendChild(customnav);
-}
-var minimizeA = document.createElement("a");
-var minimizeButton = document.createTextNode("Close");
-minimizeA.appendChild(minimizeButton);
-minimizeA.setAttribute("onclick","killFloatWindow(this);");
-minimizeA.setAttribute("href","#");
-nav.appendChild(minimizeA);
-nav.setAttribute("class","floatnav");
-windiv.appendChild(nav);
-var contentarea = document.createElement("pre");
-contentarea.setAttribute("class","floatcontent");
-contentarea.setAttribute("id",newdivid);
-windiv.appendChild(contentarea);
-document.body.appendChild(windiv);
-}
-function killFloatWindow(caller) {
-var span = caller.parentNode;
-var fwindow = span.parentNode;
-fwindow.parentNode.removeChild(fwindow);
-}
 // Place a gradient loadscreen on an element, e.g to use before Ajax.updater
 function CtdlLoadScreen(elementid) {
 var elem = document.getElementById(elementid);
@@ -924,9 +611,9 @@ function HandleRSVP(question_divname, title_divname, msgnum, cal_partnum, sc) {
        new Ajax.Updater(title_divname, 'handle_rsvp', { method: 'post', parameters: p } );
        Effect.Fade(question_divname, { duration: 0.5 });
 }
-var fakeMouse = document.createEvent("MouseEvents");
-fakeMouse.initMouseEvent("click", true, true, window, 
-       0,0,0,0,0, false, false, false, false, 0, null);
+/* var fakeMouse = document.createEvent("MouseEvents");
+ fakeMouse.initMouseEvent("click", true, true, window, 
+   0,0,0,0,0, false, false, false, false, 0, null); */
 // TODO: Collapse into one function
 function toggleTaskDtStart(event) {
        var checkBox = $('nodtstart');
@@ -986,3 +673,84 @@ function eventEditAllDay() {
                dtend.style.textDecoration = "";
        }
 }
+
+
+
+
+// Functions which handle show/hide of various elements in the recurrence editor
+
+function RecurrenceShowHide() {
+
+       if ($('is_recur').checked) {
+               $('rrule_div').style.display = 'block';
+       }
+       else {
+               $('rrule_div').style.display = 'none';
+       }
+
+       if ($('freq_selector').selectedIndex == 4) {
+               $('weekday_selector').style.display = 'block';
+       }
+       else {
+               $('weekday_selector').style.display = 'none';
+       }
+
+       if ($('freq_selector').selectedIndex == 5) {
+               $('monthday_selector').style.display = 'block';
+       }
+       else {
+               $('monthday_selector').style.display = 'none';
+       }
+
+       if ($('rrend_count').checked) {
+               $('rrcount').disabled = false;
+       }
+       else {
+               $('rrcount').disabled = true;
+       }
+
+       if ($('rrend_until').checked) {
+               $('rruntil').disabled = false;
+       }
+       else {
+               $('rruntil').disabled = true;
+       }
+
+       if ($('rrmonthtype_mday').checked) {
+               $('rrmday').disabled = false;
+       }
+       else {
+               $('rrmday').disabled = true;
+       }
+
+       if ($('rrmonthtype_wday').checked) {
+               $('rrmweek').disabled = false;
+               $('rrmweekday').disabled = false;
+       }
+       else {
+               $('rrmweek').disabled = true;
+               $('rrmweekday').disabled = true;
+       }
+
+       if ($('freq_selector').selectedIndex == 6) {
+               $('yearday_selector').style.display = 'block';
+       }
+       else {
+               $('yearday_selector').style.display = 'none';
+       }
+
+       $('ymday').innerHTML = 'XXXX-' + $('dtstart').value.substr(5);
+       $('rrmday').innerHTML = $('dtstart').value.substr(8);
+
+       if ($('rryeartype_ywday').checked) {
+               $('rrymweek').disabled = false;
+               $('rrymweekday').disabled = false;
+               $('rrymonth').disabled = false;
+       }
+       else {
+               $('rrymweek').disabled = true;
+               $('rrymweekday').disabled = true;
+               $('rrymonth').disabled = true;
+       }
+
+}