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