* add missing banner on preferences template
[citadel.git] / webcit / static / wclib.js
1 //
2 // $Id$
3 //
4 // JavaScript function library for WebCit.
5 //
6 //
7
8
9 var browserType;
10 var room_is_trash = 0;
11
12 var currentlyExpandedFloor = null;
13 var roomlist = null;
14
15 var _switchToRoomList = "switch to room list";
16 var _switchToMenu = "switch to menu";
17
18 var currentDropTarget = null;
19
20 var supportsAddEventListener = (!!document.addEventListener);
21 var today = new Date();
22
23 if (document.all) {browserType = "ie"}
24 if (window.navigator.userAgent.toLowerCase().match("gecko")) {
25         browserType= "gecko";
26 }
27 var ns6=document.getElementById&&!document.all;
28 Event.observe(window, 'load', ToggleTaskDateOrNoDateActivate);
29 Event.observe(window, 'load', taskViewActivate);
30 Event.observe(window, 'load', fixbanner);
31 //document.observe("dom:loaded", setupPrefEngine);
32 document.observe("dom:loaded", setupIconBar);
33 document.observe('dom:loaded', function() { if (!!document.getElementById("ib_chat_launch")) { $('ib_chat_launch').observe('click', launchChat); } });
34 function CtdlRandomString()  {
35         return((Math.random()+'').substr(3));
36 }
37
38 function emptyElement(element) {
39   childNodes = element.childNodes;
40   for(var i=0; i<childNodes.length; i++) {
41     element.removeChild(childNodes[i]);
42   }
43 }
44 /** Implements superior internet explorer 'extract all child text from element' feature'. Falls back on buggy, patent violating standardized method */
45 function getTextContent(element) {
46   if (element.textContent == undefined) {
47     return element.innerText;
48   }
49   return element.textContent;
50 }
51 /** Same reasons as above */
52 function setTextContent(element, textContent) {
53   if(element.textContent == undefined) {
54     element.innerText = textContent;
55   } else {
56   element.textContent = textContent;
57   }
58 }
59
60 // We love string tokenizers.
61 function extract_token(source_string, token_num, delimiter) {
62         var i = 0;
63         var extracted_string = source_string;
64
65         if (token_num > 0) {
66                 for (i=0; i<token_num; ++i) {
67                         var j = extracted_string.indexOf(delimiter);
68                         if (j >= 0) {
69                                 extracted_string = extracted_string.substr(j+1);
70                         }
71                 }
72         }
73
74         j = extracted_string.indexOf(delimiter);
75         if (j >= 0) {
76                 extracted_string = extracted_string.substr(0, j);
77         }
78
79         return extracted_string;
80 }
81
82 function CtdlSpawnContextMenu(event, source) {
83   // remove any existing menus
84   disintergrateContextMenus(null);
85   var x = event.clientX-10; // cut a few pixels out so our mouseout works right
86   var y = event.clientY-10;
87   var contextDIV = document.createElement("div");
88   contextDIV.setAttribute("id", "ctdlContextMenu");
89   document.body.appendChild(contextDIV);
90   var sourceChildren = source.childNodes;
91   for(var j=0; j<sourceChildren.length; j++) {
92     contextDIV.appendChild(sourceChildren[j].cloneNode(true));
93   }
94   var leftRule = "left: "+x+"px;";
95   contextDIV.setAttribute("style", leftRule);
96   contextDIV.setAttribute("actual", leftRule);
97   contextDIV.style.top = y+"px";
98   contextDIV.style.display = "block";
99   $(contextDIV).observe('mouseout',disintergrateContextMenus);
100 }
101 function disintergrateContextMenus(event) {
102   var contextMenu = document.getElementById("ctdlContextMenu");
103   if (contextMenu) {
104     contextMenu.parentNode.removeChild(contextMenu);
105   }
106   Event.stopObserving(document,'click',disintergrateContextMenus);
107 }
108 // This code handles the popups for important-messages.
109 function hide_imsg_popup() {
110         if (browserType == "gecko") {
111                 document.poppedLayer = eval('document.getElementById(\'important_message\')');
112         }
113         else if (browserType == "ie") {
114                 document.poppedLayer = eval('document.all[\'important_message\']');
115         }
116         else {
117                 document.poppedLayer = eval('document.layers[\'`important_message\']');
118         }
119
120         document.poppedLayer.style.visibility = "hidden";
121 }
122
123
124 // This function activates the ajax-powered recipient autocompleters on the message entry screen.
125 function activate_entmsg_autocompleters() {
126         new Ajax.Autocompleter('cc_id', 'cc_name_choices', 'cc_autocomplete', {} );
127         new Ajax.Autocompleter('bcc_id', 'bcc_name_choices', 'bcc_autocomplete', {} );
128         new Ajax.Autocompleter('recp_id', 'recp_name_choices', 'recp_autocomplete', {} );
129 }
130
131 function setupIconBar() {
132   if (!document.getElementById("switch")) {
133       return;
134     }
135   _switchToRoomList = getTextContent(document.getElementById("rmlist_template"));
136   _switchToMenu = getTextContent(document.getElementById("mnlist_template"));
137   var switchSpan = document.getElementById("switch").firstChild;
138   if (switchSpan != null) {
139     setTextContent(switchSpan, _switchToRoomList);
140     $(switchSpan).observe('click', changeIconBarEvent);
141     var currentView = ctdlLocalPrefs.readPref("iconbar_view");
142     if (currentView != null) {
143       switchSpan.ctdlSwitchIconBarTo = currentView;
144       changeIconBar(switchSpan);
145     } else {
146       switchSpan.ctdlSwitchIconBarTo = "rooms";
147     }
148   }
149   var online_users = document.getElementById("online_users");
150   if (online_users.offsetParent != null) {
151     new Ajax.PeriodicalUpdater('online_users', 'do_template?template=wholist_section', {method: 'get', frequency: 30});
152   }
153 }
154 function changeIconBarEvent(event) {
155   changeIconBar(event.target);
156 }
157 function changeIconBar(target) {
158   var switchTo = target.ctdlSwitchIconBarTo;
159   WCLog("Changing to: " + switchTo);
160   ctdlLocalPrefs.setPref("iconbar_view", target.ctdlSwitchIconBarTo);  
161   if (switchTo == "rooms") {
162     switch_to_room_list();
163     setTextContent(target, _switchToMenu);
164     target.ctdlSwitchIconBarTo = "menu";
165   } else {
166     switch_to_menu_buttons();
167     setTextContent(target, _switchToRoomList);
168     target.ctdlSwitchIconBarTo = "rooms";
169   }
170 }
171 function switch_to_room_list() {
172   var roomlist = document.getElementById("roomlist");
173   var summary = document.getElementById("iconbar_menu");
174   if (!rooms || !floors || !roomlist) {
175     FillRooms(IconBarRoomList);
176   }
177   roomlist.className = roomlist.className.replace("hidden","");
178   summary.className += " hidden";
179 }
180
181 function switch_to_menu_buttons() {
182   if (roomlist != null) {
183     roomlist.className += "hidden";
184   }
185   var iconbar = document.getElementById("iconbar_menu");
186   iconbar.className = iconbar.className.replace("hidden","");
187   var roomlist = document.getElementById("roomlist");
188   roomlist.className += " hidden";
189 }
190 function IconBarRoomList() {
191   var currentExpanded = ctdlLocalPrefs.readPref("rooms_expanded");
192   currentDropTargets = new Array();
193   var iconbar = document.getElementById("iconbar");
194   roomlist = document.getElementById("roomlist");
195   var ul = document.createElement("ul");
196   roomlist.appendChild(ul);
197   // Add mailbox, because they are special
198   var mailboxLI = document.createElement("li");
199   ul.appendChild(mailboxLI);
200   var mailboxSPAN = document.createElement("span");
201   var _mailbox = getTextContent(document.getElementById("mbox_template"));
202   mailboxSPAN.appendChild(document.createTextNode(_mailbox));
203   $(mailboxSPAN).observe('click', expandFloorEvent);
204   mailboxLI.appendChild(mailboxSPAN);
205   mailboxLI.setAttribute("class", "floor");
206   var mailboxUL = document.createElement("ul");
207   mailboxLI.appendChild(mailboxUL);
208   var mailboxRooms = GetMailboxRooms();
209   for(var i=0; i<mailboxRooms.length; i++) {
210     var room = mailboxRooms[i];
211     currentDropTargets.push(addRoomToList(mailboxUL, room));
212   }
213   if (currentExpanded != null && currentExpanded == "Mailbox") {
214     expandFloor(mailboxSPAN);
215   }
216   for(var a=0; a<floors.length; a++) {
217     var floor = floors[a];
218     var floornum = floor[0];
219     var name = floor[1];
220     var floorLI = document.createElement("li");
221     ul.appendChild(floorLI);
222     var floorSPAN = document.createElement("span");
223     floorSPAN.appendChild(document.createTextNode(name));
224     $(floorSPAN).observe('click', expandFloorEvent);
225     floorLI.appendChild(floorSPAN);
226     floorLI.setAttribute("class", "floor");
227     var floorUL = document.createElement("ul");
228     floorLI.appendChild(floorUL);
229     var roomsForFloor = GetRoomsByFloorNum(floornum);
230     for(var b=0; b<roomsForFloor.length; b++) {
231       var room = roomsForFloor[b];
232       currentDropTargets.push(addRoomToList(floorUL, room));
233     }
234     if (currentExpanded != null && currentExpanded == name) {
235       expandFloor(floorSPAN);
236     }
237   }
238 }
239
240 function addRoomToList(floorUL,room) {
241   var roomName = room[RN_ROOM_NAME];
242   var flag = room[RN_ROOM_FLAG];
243   var curView = room[RN_CUR_VIEW];
244   var view = room[RN_DEF_VIEW];
245   var isMailBox = ((flag & QR_MAILBOX) == QR_MAILBOX);
246   var hasNewMsgs = ((curView & UA_HASNEWMSGS) == UA_HASNEWMSGS);
247   var roomLI = document.createElement("li");
248   var roomA = document.createElement("a");
249   roomA.setAttribute("href","dotgoto?room="+roomName);
250   roomA.appendChild(document.createTextNode(roomName));
251   roomLI.appendChild(roomA);
252   floorUL.appendChild(roomLI);
253   var className = "room ";
254   if (view == VIEW_MAILBOX) {
255     className += "room-private"
256   } else if (view == VIEW_ADDRESSBOOK) {
257     className += "room-addr";
258   } else if (view == VIEW_CALENDAR || view == VIEW_CALBRIEF) {
259     className += "room-cal";
260   } else if (view == VIEW_TASKS) {
261     className += "room-tasks";
262   } else if (view == VIEW_NOTES) {
263     className += "room-notes";
264   } else {
265     className += "room-chat";
266   }
267   if (hasNewMsgs) {
268     className += " room-newmsgs";
269   }
270   roomLI.setAttribute("class", className);
271   roomA.dropTarget = true;
272   roomA.dropHandler = roomListDropHandler;
273   return roomLI;
274 }
275
276 function roomListDropHandler(target, dropped) {
277   if (dropped.ctdlMsgId) {
278     var room = getTextContent(target);
279     var msgIds = "";
280     for(msgId in currentlyMarkedRows) { //defined in summaryview.js
281       msgIds += ","+msgId;
282     }
283     var mvCommand = "g_cmd=MOVE " + msgIds + "|"+room+"|0";
284     new Ajax.Request('ajax_servcmd', {
285       method: 'post',
286           parameters: mvCommand,
287           onComplete: deleteAllMarkedRows()});
288     } 
289 }
290 function expandFloorEvent(event) {
291   expandFloor(event.target);
292 }
293 function expandFloor(target) {
294   if (target.nodeName.toLowerCase() != "span") {
295     return; // ignore clicks on child UL
296   }
297   ctdlLocalPrefs.setPref("rooms_expanded", target.firstChild.nodeValue);
298   var parentUL = target.parentNode;
299   if (currentlyExpandedFloor != null) {
300     currentlyExpandedFloor.className = currentlyExpandedFloor.className.replace("floor-expanded","");
301   }
302   parentUL.className = parentUL.className + " floor-expanded";
303   currentlyExpandedFloor = parentUL;
304 }
305
306 // These functions handle moving sticky notes around the screen by dragging them
307
308 var uid_of_note_being_dragged = 0;
309 var saved_cursor_style = 'default';
310 var note_was_dragged = 0;
311
312 function NotesDragMouseUp(evt) {
313         document.onmouseup = null;
314         document.onmousemove = null;
315         if (document.layers) {
316                 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
317         }
318
319         d = $('note-' + uid_of_note_being_dragged);
320         d.style.cursor = saved_cursor_style;
321
322         // If any motion actually occurred, submit an ajax http call to record it to the server
323         if (note_was_dragged > 0) {
324                 p = 'note_uid=' + uid_of_note_being_dragged
325                         + '&left=' + d.style.left
326                         + '&top=' + d.style.top
327                         + '&r=' + CtdlRandomString();
328                 new Ajax.Request(
329                         'ajax_update_note',
330                         {
331                                 method: 'post',
332                                 parameters: p
333                         }
334                 );
335         }
336
337         uid_of_note_being_dragged = '';
338         return true;
339 }
340
341 function NotesDragMouseMove(evt) {
342         x = (ns6 ? evt.clientX : event.clientX);
343         x_increment = x - saved_x;
344         y = (ns6 ? evt.clientY : event.clientY);
345         y_increment = y - saved_y;
346
347         // Move the div
348         d = $('note-' + uid_of_note_being_dragged);
349
350         divTop = parseInt(d.style.top);
351         divLeft = parseInt(d.style.left);
352
353         d.style.top = (divTop + y_increment) + 'px';
354         d.style.left = (divLeft + x_increment) + 'px';
355
356         saved_x = x;
357         saved_y = y;
358         note_was_dragged = 1;
359         return true;
360 }
361
362
363 function NotesDragMouseDown(evt, uid) {
364         saved_x = (ns6 ? evt.clientX : event.clientX);
365         saved_y = (ns6 ? evt.clientY : event.clientY);
366         document.onmouseup = NotesDragMouseUp;
367         document.onmousemove = NotesDragMouseMove;
368         if (document.layers) {
369                 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
370         }
371         uid_of_note_being_dragged = uid;
372         d = $('note-' + uid_of_note_being_dragged);
373         saved_cursor_style = d.style.cursor;
374         d.style.cursor = 'move';
375         return false;           // disable the default action
376 }
377
378
379 // Called when the user clicks on the palette icon of a sticky note to change its color.
380 // It toggles the color selector visible or invisible.
381
382 function NotesClickPalette(evt, uid) {
383         uid_of_note_being_colored = uid;
384         d = $('palette-' + uid_of_note_being_colored);
385
386         if (d.style.display) {
387                 if (d.style.display == 'none') {
388                         d.style.display = 'block';
389                 }
390                 else {
391                         d.style.display = 'none';
392                 }
393         }
394         else {
395                 d.style.display = 'block';
396         }
397
398         return true;
399 }
400
401
402 // Called when the user clicks on one of the colors in an open color selector.
403 // Sets the desired color and then closes the color selector.
404
405 function NotesClickColor(evt, uid, red, green, blue, notecolor, titlecolor) {
406         uid_of_note_being_colored = uid;
407         palette_button = $('palette-' + uid_of_note_being_colored);
408         note_div = $('note-' + uid_of_note_being_colored);
409         titlebar_div = $('titlebar-' + uid_of_note_being_colored);
410
411         // alert('FIXME red=' + red + ' green=' + green + ' blue=' + blue);
412
413         note_div.style.backgroundColor = notecolor;
414         titlebar_div.style.backgroundColor = titlecolor;
415         palette_button.style.display = 'none';
416
417         // submit an ajax http call to record it to the server
418         p = 'note_uid=' + uid_of_note_being_colored
419                 + '&red=' + red
420                 + '&green=' + green
421                 + '&blue=' + blue
422                 + '&r=' + CtdlRandomString();
423         new Ajax.Request(
424                 'ajax_update_note',
425                 {
426                         method: 'post',
427                         parameters: p
428                 }
429         );
430 }
431
432
433
434
435 // These functions handle resizing sticky notes by dragging the resize handle
436
437 var uid_of_note_being_resized = 0;
438 var saved_cursor_style = 'default';
439 var note_was_resized = 0;
440
441 function NotesResizeMouseUp(evt) {
442         document.onmouseup = null;
443         document.onmousemove = null;
444         if (document.layers) {
445                 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
446         }
447
448         d = $('note-' + uid_of_note_being_resized);
449         d.style.cursor = saved_cursor_style;
450
451         // If any motion actually occurred, submit an ajax http call to record it to the server
452         if (note_was_resized > 0) {
453                 p = 'note_uid=' + uid_of_note_being_resized
454                         + '&width=' + d.style.width
455                         + '&height=' + d.style.height
456                         + '&r=' + CtdlRandomString();
457                 new Ajax.Request(
458                         'ajax_update_note',
459                         {
460                                 method: 'post',
461                                 parameters: p
462                         }
463                 );
464         }
465
466         uid_of_note_being_resized = '';
467         return false;           // disable the default action
468 }
469
470 function NotesResizeMouseMove(evt) {
471         x = (ns6 ? evt.clientX : event.clientX);
472         x_increment = x - saved_x;
473         y = (ns6 ? evt.clientY : event.clientY);
474         y_increment = y - saved_y;
475
476         // Move the div
477         d = $('note-' + uid_of_note_being_resized);
478
479         divTop = parseInt(d.style.height);
480         divLeft = parseInt(d.style.width);
481
482         d.style.height = (divTop + y_increment) + 'px';
483         d.style.width = (divLeft + x_increment) + 'px';
484
485         saved_x = x;
486         saved_y = y;
487         note_was_resized = 1;
488         return false;           // disable the default action
489 }
490
491
492 function NotesResizeMouseDown(evt, uid) {
493         saved_x = (ns6 ? evt.clientX : event.clientX);
494         saved_y = (ns6 ? evt.clientY : event.clientY);
495         document.onmouseup = NotesResizeMouseUp;
496         document.onmousemove = NotesResizeMouseMove;
497         if (document.layers) {
498                 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
499         }
500         uid_of_note_being_resized = uid;
501         d = $('note-' + uid_of_note_being_resized);
502         saved_cursor_style = d.style.cursor;
503         d.style.cursor = 'move';
504         return false;           // disable the default action
505 }
506
507
508 function DeleteStickyNote(evt, uid, confirmation_prompt) {
509         uid_of_note_being_deleted = uid;
510         d = $('note-' + uid_of_note_being_deleted);
511
512         if (confirm(confirmation_prompt)) {
513                 new Effect.Puff(d);
514
515                 // submit an ajax http call to delete it on the server
516                 p = 'note_uid=' + uid_of_note_being_deleted
517                         + '&deletenote=yes'
518                         + '&r=' + CtdlRandomString();
519                 new Ajax.Request(
520                         'ajax_update_note',
521                         {
522                                 method: 'post',
523                                 parameters: p
524                         }
525                 );
526         }
527 }
528
529 function ctdl_ts_getInnerText(el) {
530         if (typeof el == "string") return el;
531         if (typeof el == "undefined") { return el };
532         if (el.innerText) return el.innerText;  //Not needed but it is faster
533         var str = "";
534         
535         var cs = el.childNodes;
536         var l = cs.length;
537         for (var i = 0; i < l; i++) {
538                 switch (cs[i].nodeType) {
539                         case 1: //ELEMENT_NODE
540                                 str += ts_getInnerText(cs[i]);
541                                 break;
542                         case 3: //TEXT_NODE
543                                 str += cs[i].nodeValue;
544                                 break;
545                 }
546         }
547         return str;
548 }
549
550
551 // Place a gradient loadscreen on an element, e.g to use before Ajax.updater
552 function CtdlLoadScreen(elementid) {
553 var elem = document.getElementById(elementid);
554 elem.innerHTML = "<div align=center><br><table border=0 cellpadding=10 bgcolor=\"#ffffff\"><tr><td><img src=\"static/throbber.gif\" /><font color=\"#AAAAAA\">&nbsp;&nbsp;Loading....</font></td></tr></table><br /></div>";
555 }
556
557
558
559 // Pop open the address book (target_input is the INPUT field to populate)
560
561 function PopOpenAddressBook(target_input) {
562         $('address_book_popup').style.display = 'block';
563         p = 'target_input=' + target_input + '&r=' + CtdlRandomString();
564         new Ajax.Updater(
565                 'address_book_popup_middle_div',
566                 'display_address_book_middle_div',
567                 {
568                         method: 'get',
569                         parameters: p,
570                         evalScripts: true
571                 }
572         );
573 }
574
575 function PopulateAddressBookInnerDiv(which_addr_book, target_input) {
576         $('address_book_inner_div').innerHTML = "<div align=center><br><table border=0 cellpadding=10 bgcolor=\"#ffffff\"><tr><td><img src=\"static/throbber.gif\" /><font color=\"#AAAAAA\">&nbsp;&nbsp;Loading....</font></td></tr></table><br /></div>";
577         p = 'which_addr_book=' + which_addr_book
578           + '&target_input=' + target_input
579           + '&r=' + CtdlRandomString();
580         new Ajax.Updater(
581                 'address_book_inner_div',
582                 'display_address_book_inner_div',
583                 {
584                         method: 'get',
585                         parameters: p
586                 }
587         );
588 }
589
590 // What happens when a contact is selected from the address book popup
591 // (populate the specified target)
592
593 function AddContactsToTarget(target, whichaddr) {
594         while (whichaddr.selectedIndex != -1) {
595                 if (target.value.length > 0) {
596                         target.value = target.value + ', ';
597                 }
598                 target.value = target.value + whichaddr.value;
599                 whichaddr.options[whichaddr.selectedIndex].selected = false;
600         }
601 }
602
603 // Respond to a meeting invitation
604 function RespondToInvitation(question_divname, title_divname, msgnum, cal_partnum, sc) {
605         p = 'msgnum=' + msgnum + '&cal_partnum=' + cal_partnum + '&sc=' + sc ;
606         new Ajax.Updater(title_divname, 'respond_to_request', { method: 'post', parameters: p } );
607         Effect.Fade(question_divname, { duration: 0.5 });
608 }
609
610 // Handle a received RSVP
611 function HandleRSVP(question_divname, title_divname, msgnum, cal_partnum, sc) {
612         p = 'msgnum=' + msgnum + '&cal_partnum=' + cal_partnum + '&sc=' + sc ;
613         new Ajax.Updater(title_divname, 'handle_rsvp', { method: 'post', parameters: p } );
614         Effect.Fade(question_divname, { duration: 0.5 });
615 }
616 /* var fakeMouse = document.createEvent("MouseEvents");
617  fakeMouse.initMouseEvent("click", true, true, window, 
618    0,0,0,0,0, false, false, false, false, 0, null); */
619 // TODO: Collapse into one function
620 function toggleTaskDtStart(event) {
621         var checkBox = $('nodtstart');
622         dtStart = document.getElementById("dtstart");
623         if (checkBox.checked) {
624                 dtStart.disabled = true;
625                 dtStart.style.textDecoration = "line-through";
626         } else {
627                 dtStart.disabled = false;
628                 dtStart.style.textDecoration = "";
629                 if (dtStart.value.length == 0)
630                         dtStart.dpck._initCurrentDate();
631         }
632 }
633 function toggleTaskDue(event) {
634         var checkBox = $('nodue');
635         dueField = document.getElementById("due");
636         if (checkBox.checked) {
637                 dueField.disabled = true;
638                 dueField.style.textDecoration = "line-through";
639         } else {
640                 dueField.disabled = false;
641                 dueField.style.textDecoration = "";
642                 if (dueField.value.length == 0)
643                         dueField.dpck._initCurrentDate();
644         }
645 }
646 function ToggleTaskDateOrNoDateActivate(event) {
647         var dtstart = document.getElementById("nodtstart");
648         if (dtstart != null) {
649                 toggleTaskDtStart(null);
650                 toggleTaskDue(null);
651                 $('nodtstart').observe('click', toggleTaskDtStart);
652                 $('nodue').observe('click', toggleTaskDue);
653         } 
654 }
655 function TaskViewGatherCategoriesFromTable() {
656         var table = $('taskview');
657         
658 }
659 function attachDatePicker(relative) {
660         var dpck = new DatePicker({
661         relative: relative,
662               language: 'en', //wclang.substr(0,2),
663               disableFutureDate: false,
664               dateFormat: [ ["yyyy", "mm", "dd"], "-"],
665               showDuration: 0.2
666         });
667         document.getElementById(relative).dpck = dpck; // attach a ref to it
668 }
669 function eventEditAllDay() {
670         var allDayCheck = document.getElementById("alldayevent");
671         var dtend= document.getElementById("dtendcell");
672         if(allDayCheck.checked) {
673                 //dtend.disabled = true;
674                 dtend.style.textDecoration = "line-through";
675         } else {
676                 //dtend_day.disabled = false;
677                 dtend.style.textDecoration = "";
678         }
679 }
680
681 // Functions which handle show/hide of various elements in the recurrence editor
682
683 function RecurrenceShowHide() {
684
685         if ($('is_recur').checked) {
686                 $('rrule_div').style.display = 'block';
687         }
688         else {
689                 $('rrule_div').style.display = 'none';
690         }
691
692         if ($('freq_selector').selectedIndex == 4) {
693                 $('weekday_selector').style.display = 'block';
694         }
695         else {
696                 $('weekday_selector').style.display = 'none';
697         }
698
699         if ($('freq_selector').selectedIndex == 5) {
700                 $('monthday_selector').style.display = 'block';
701         }
702         else {
703                 $('monthday_selector').style.display = 'none';
704         }
705
706         if ($('rrend_count').checked) {
707                 $('rrcount').disabled = false;
708         }
709         else {
710                 $('rrcount').disabled = true;
711         }
712
713         if ($('rrend_until').checked) {
714                 $('rruntil').disabled = false;
715         }
716         else {
717                 $('rruntil').disabled = true;
718         }
719
720         if ($('rrmonthtype_mday').checked) {
721                 $('rrmday').disabled = false;
722         }
723         else {
724                 $('rrmday').disabled = true;
725         }
726
727         if ($('rrmonthtype_wday').checked) {
728                 $('rrmweek').disabled = false;
729                 $('rrmweekday').disabled = false;
730         }
731         else {
732                 $('rrmweek').disabled = true;
733                 $('rrmweekday').disabled = true;
734         }
735
736         if ($('freq_selector').selectedIndex == 6) {
737                 $('yearday_selector').style.display = 'block';
738         }
739         else {
740                 $('yearday_selector').style.display = 'none';
741         }
742
743         $('ymday').innerHTML = 'XXXX-' + $('dtstart').value.substr(5);
744         $('rrmday').innerHTML = $('dtstart').value.substr(8);
745
746         if ($('rryeartype_ywday').checked) {
747                 $('rrymweek').disabled = false;
748                 $('rrymweekday').disabled = false;
749                 $('rrymonth').disabled = false;
750         }
751         else {
752                 $('rrymweek').disabled = true;
753                 $('rrymweekday').disabled = true;
754                 $('rrymonth').disabled = true;
755         }
756
757 }
758 function launchChat(event) {
759 window.open('chat', 'ctdl_chat_window', 'toolbar=no,location=no,directories=no,copyhistory=no,status=no,scrollbars=yes,resizable=yes');
760 }
761 // logger
762 function WCLog(msg) {
763   if (!!window.console && !!console.log) {
764     console.log(msg);
765   } else if (!!window.opera && !!opera.postError) {
766     opera.postError(msg);
767   }
768 }
769
770 function fixMissingCSSTable(elems) {
771  if (elems[0] == null || elems[1] == null) {
772     return;
773   }
774   if (elems[0].getStyle("display") != "table-cell") {
775     var parentNode = elems[0].parentNode;
776     var table = document.createElement("table");
777     table.style.width = "100%";
778     var tbody = document.createElement("tbody");
779     table.appendChild(tbody);
780     var tr = document.createElement("tr");
781     tbody.appendChild(tr);
782     parentNode.appendChild(table);
783     for(var i=0; i<elems.length; i++) {
784       parentNode.removeChild(elems[i]);
785       var td = document.createElement("td");
786       td.appendChild(elems[i]);
787       tr.appendChild(td);
788     }
789   }
790 }
791 function fixbanner() {
792   var elems = [$('room_banner'),$('actiondiv')];
793   fixMissingCSSTable(elems);
794 }