]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/Calendar/Cal.js
Release 6.4.0
[Github/sugarcrm.git] / jssource / src_files / modules / Calendar / Cal.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36         
37         var CAL = {};
38
39         CAL.dropped = 0;
40         CAL.records_openable = true;
41         CAL.moved_from_cell = "";
42         CAL.deleted_id = "";
43         CAL.deleted_module = "";
44         CAL.old_caption = "";
45         CAL.disable_creating = false;
46         CAL.record_editable = false;            
47         CAL.tp = false;
48         CAL.tp1 = false;
49         CAL.shared_users = {};
50         CAL.shared_users_count = 0;
51         CAL.script_evaled = false;
52         CAL.editDialog = false;
53         CAL.settingsDialog = false;     
54         CAL.scroll_slot = 0;
55         CAL.update_dd = new YAHOO.util.CustomEvent("update_dd");
56         
57         CAL.dom = YAHOO.util.Dom;
58         CAL.get = YAHOO.util.Dom.get;
59         CAL.query = YAHOO.util.Selector.query;
60         
61         CAL.arrange_slot = function (cell_id){
62                 if(!cell_id)
63                         return; 
64                 cellElm = document.getElementById(cell_id);
65                 if(cellElm){                            
66                         var total_height = 0;
67                         var prev_i = 0;
68                         var first = 1;
69                         var top = 0;
70                         var height = 0;
71                         var cnt = 0;
72                         var child_cnt = cellElm.childNodes.length;
73                         for(var i = 0; i < child_cnt; i++){
74                                         var width_p = (92 / child_cnt);
75                                         width = width_p.toString() + "%";
76                                         if(cellElm.childNodes[i].tagName == "DIV"){
77                                                 cellElm.childNodes[i].style.top = "-1px";
78                                                 cellElm.childNodes[i].style.left = "-"+(cnt+1)+"px"; 
79                                                 cellElm.childNodes[i].style.width = width                                                       
80                                                 cnt++;                                          
81                                                 prev_i = i;                                     
82                                         }
83                         }
84                 }
85         }
86         
87         // prevent item overlapping
88         CAL.arrange_column = function(column){
89                 
90                 for(var i = 0; i < column.childNodes.length; i++){
91                         for(var j = 0; j < column.childNodes[i].childNodes.length; j++){
92                                 var el = column.childNodes[i].childNodes[j];
93                                 if(YAHOO.util.Dom.hasClass(el,"empty")){
94                                         el.parentNode.removeChild(el);
95                                         j--;
96                                 }
97                         }
98                 }
99         
100                 var slots = column.childNodes;
101                 
102                 var start = 0;
103                 var end = slots.length; 
104                 var slot_count = end;
105                 var level = 0;
106                 
107                 var affected_slots = new Array();
108                 var affected_items = Array();           
109                 var ol = new Array();           
110                 
111                 // fill ol array with groups of overlapping items to fit them bit later
112                 find_overlapping(null,start,end,level,null);
113                 
114                 // add transparent empty blocks to the left
115                 for(var i = 0; i < ol.length; i++){
116                         var ol_group = ol[i];
117                         var depth = ol_group.depth;
118                         for(var j = 0; j < ol_group.items.length; j++){
119                                 var el_id = ol_group.items[j]['id'];
120                                 var level = ol_group.items[j]['level'];                         
121                                 var el = CAL.get(el_id);                                        
122                                 var node = el;                  
123                                 var pos = 0;
124                                 while(node.previousSibling){
125                                         pos++;
126                                         node = node.previousSibling;
127                                 }                               
128                                 insert_empty_items(el,level - 1 - pos,false);
129                         }                               
130                 }
131                 
132                 // add transparent empty blocks to the right
133                 for(var i = 0; i < ol.length; i++){
134                         var ol_group = ol[i];
135                         var depth = ol_group.depth;
136                         for(var j = 0; j < ol_group.items.length; j++){
137                                 var el_id = ol_group.items[j]['id'];
138                                 
139                                 var el = CAL.get(el_id);
140                                 var cnt = el.parentNode.childNodes.length;
141                                 insert_empty_items(el,depth - cnt,true);
142                         }                               
143                 }
144                 
145                 CAL.each(affected_slots,function(i,v){                  
146                         CAL.arrange_slot(affected_slots[i]);
147                 });             
148         
149
150                 function find_overlapping(el,start,end,level,ol_group){
151                 
152                         if(level > 20)
153                                 return;
154                 
155                         var depth = level;
156
157                         if(el != null){
158                                 if(level == 1){
159                                         ol_group = {};
160                                         ol_group.items = new Array();   
161                                 }
162                                 ol_group.items.push({
163                                         id: el.id,
164                                         level: level
165                                 });                             
166                                 affected_items.push(el.id);                     
167                         }                       
168                                                 
169                         for(var i = start; i < end; i++){
170                                 if(i >= slot_count)
171                                         break;
172                                         
173                                 if(typeof slots[i].childNodes != 'undefined' && typeof slots[i].childNodes[0] != 'undefined'){
174                                 
175                                         var pos = 0;                                    
176                                         if(i == start){                                         
177                                                 var node = slots[i].childNodes[0];
178                                                 while(node.nextSibling && contains(affected_items,node.id)){                                                                                                                            
179                                                         node = node.nextSibling;
180                                                         pos ++;
181                                                 }                                                                                               
182                                         }
183                                                 
184                                         var current = slots[i].childNodes[pos];                                                                                                         
185                                         var slots_takes = parseInt(current.getAttribute('duration_coef'));
186                                         
187                                         if(contains(affected_items,current.id))
188                                                 continue;
189                                         
190                                         if(pos == 0){
191                                                 var slot_id = current.parentNode.id;    
192                                                 if(!contains(affected_slots,slot_id))
193                                                         affected_slots.push(slot_id);
194                                         }
195                                                                                                                                                         
196                                         if(slots_takes > 0){
197                                                 var k = find_overlapping(current, i, i + slots_takes, level + 1,ol_group);
198                                                 if(k > depth)
199                                                         depth = k;                                                      
200                                         }
201                                 }
202                         }                                               
203                         
204                         if(level == 1){
205                                 ol_group.depth = depth;
206                                 ol.push(ol_group);
207                         }
208                                                 
209                         return depth;
210                 }
211                 
212                 function insert_empty_items(el,count,to_end){
213                         var slot = el.parentNode;
214                         for(var i = 0; i < count; i++){
215                                 var empty = document.createElement("div");
216                                 empty.className = "act_item empty";
217                                 empty.style.zIndex = "-1";
218                                 empty.style.width = "1px";                              
219                                 if(to_end == true){
220                                         slot.appendChild(empty);
221                                 }else{  
222                                         slot.insertBefore(empty,slot.firstChild);
223                                 }                                               
224                         }
225                 }
226                 
227                 function contains(a, obj){
228                         var i = a.length;
229                         while(i--)
230                                 if (a[i] === obj)
231                                         return true;
232                         return false;
233                 }       
234         }
235         
236         CAL.arrange_advanced = function (){
237                 var nodes = CAL.query("#cal-grid .day_col");
238                 for(var i = 0; i < nodes.length; i++){
239                         CAL.arrange_column(nodes[i]);   
240                 }
241                 CAL.update_dd.fire();
242         }
243         
244         CAL.add_item_to_grid = function (item){
245                         
246                         var suffix = "";
247                         var id_suffix = "";                     
248                         
249                         if( item.user_id != "" && CAL.view == 'shared'){
250                                 suffix = "_" + CAL.shared_users[item.user_id];  
251                                 id_suffix = '____' + CAL.shared_users[item.user_id];            
252                         }
253                         
254                         var e = CAL.get(item.record + id_suffix);
255                         if(e){
256                                 e.parentNode.removeChild(e);
257                         }
258                                 
259                         var duration_text = item.duration_hours + CAL.lbl_hours_abbrev;
260                         if(item.duration_minutes > 0)
261                                 duration_text += item.duration_minutes + CAL.lbl_mins_abbrev;
262                         var start_text = CAL.get_header_text(item.type,item.time_start,item.status,item.record);
263                                                 
264                         var time_cell = item.timestamp - item.timestamp % (CAL.t_step * 60);                    
265                         
266                         var duration_coef; 
267                         if(item.module_name == 'Tasks'){
268                                 duration_coef = 1;
269                                 duration_text = " ";
270                         }else{  
271                                 if((item.duration_minutes < CAL.t_step) && (item.duration_hours == 0))
272                                         duration_coef = 1;
273                                 else                                    
274                                         duration_coef = (parseInt(item.duration_hours) * 60 + parseInt(item.duration_minutes)) / CAL.t_step;
275                         }                       
276
277                         var item_text = "";
278                         if(CAL.item_text && (typeof item[CAL.item_text] != "undefined") )
279                                 item_text = item[CAL.item_text];
280                         
281                         var contain_style = "";
282                         if(duration_coef < 1.75)
283                                 contain_style = "style='display: none;'";                                                       
284                         
285                         var elm_id = item.record + id_suffix;                   
286                         
287                         var el = document.createElement("div");
288                         el.innerHTML = "<div class='head'><div class='adicon' onmouseover='return CAL.show_additional_details(" + '"' + item.record  + id_suffix + '"'  +  ");' onmouseout='return nd(400);' >&nbsp;&nbsp;</div><div>" + start_text + "</div>" + "" + "</div><div class='contain' "+contain_style+">" + item_text + "</div>"; 
289                         el.className = "act_item" + " " + item.type+"_item";
290                         el.setAttribute("id",elm_id);
291                         el.setAttribute("module_name",item.module_name);
292                         el.setAttribute("record",item.record);
293                         el.setAttribute("dur",duration_text);
294                         el.setAttribute("subj",item.record_name);
295                         el.setAttribute("date_start",item.date_start);
296                         el.setAttribute("desc",item.description);
297                         el.setAttribute("parent_name",item.parent_name);
298                         el.setAttribute("parent_type",item.parent_type);
299                         el.setAttribute("parent_id",item.parent_id);
300                         el.setAttribute("status",item.status);
301                         el.setAttribute("detail",item.detail);
302                         el.setAttribute("edit",item.edit);
303                         el.setAttribute("duration_coef",duration_coef);
304                         el.style.backgroundColor = CAL.activity_colors[item.module_name]['body'];
305                         el.style.borderColor = CAL.activity_colors[item.module_name]['border']; 
306                         el.style.height = parseInt(15 * duration_coef - 1) + "px";                                              
307                         if(item.module_name == "Tasks")
308                                 el.setAttribute("date_due",item.date_due);                              
309                         
310                         YAHOO.util.Event.on(el,"click",function(){
311                                         if(this.getAttribute('detail') == "1")
312                                                 CAL.load_form(this.getAttribute('module_name'),this.getAttribute('record'),false);
313                         });
314                         YAHOO.util.Event.on(el,"mouseover",function(){
315                                 if(!CAL.records_openable)
316                                         return;
317                                 CAL.disable_creating = true;    
318                                 CAL.tp = setTimeout(
319                                         function(){
320                                                 var e;
321                                                 if(e = CAL.get(elm_id))
322                                                         e.style.zIndex = 2;
323                                         },
324                                         150
325                                 ); 
326                         });
327                         YAHOO.util.Event.on(el,"mouseout",function(){
328                                 if(!CAL.records_openable)
329                                         return;
330                                 clearTimeout(CAL.tp);
331                                 CAL.get(elm_id).style.zIndex = '';
332                                 CAL.disable_creating = false;                                           
333                         });
334                         
335                         var slot;
336                         if(slot = CAL.get("t_" + time_cell + suffix)){
337                                 slot.appendChild(el);   
338                                 
339                                 CAL.cut_record(item.record + id_suffix);                                        
340                                 
341                                 if(duration_coef < 1.75 && CAL.mouseover_expand){
342                                         YAHOO.util.Event.on(elm_id,"mouseover",function(){
343                                                 if(CAL.records_openable)
344                                                         CAL.expand_record(this.getAttribute("id"));                                             
345                                         });
346                                         YAHOO.util.Event.on(elm_id,"mouseout",function(){       
347                                                 CAL.unexpand_record(this.getAttribute("id"));                                           
348                                         });
349                                         YAHOO.util.Event.on(elm_id,"click",function(){
350                                                 CAL.unexpand_record(this.getAttribute("id"));
351                                         });
352                                 }                                                               
353                                 
354                                 if(CAL.items_draggable && item.edit == 1){
355                                 
356                                         var border = 'cal-grid';
357                                         if(CAL.view != "shared" && CAL.view != "month")
358                                                 border = 'cal-scrollable';
359                                                 
360                                         var dd = new YAHOO.util.DDCAL(elm_id,"cal",{isTarget: false,cont: border});                                                                     
361                                                                                                         
362                                         dd.onInvalidDrop = function(e){
363                                                 CAL.arrange_slot(this.el.parentNode.getAttribute("id"));
364                                                 if(CAL.dropped == 0){
365                                                         this.el.childNodes[0].innerHTML = CAL.old_caption;
366                                                 }
367                                                 CAL.records_openable = true;
368                                                 CAL.disable_creating = false;                            
369                                         }                                       
370                                                                         
371                                         dd.onMouseDown = function(e){
372                                                 YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
373                                                 YAHOO.util.DDM.clickPixelThresh = 20;
374                                         }
375                                         
376                                         dd.onMouseUp = function(e){
377                                                 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
378                                                 YAHOO.util.DDM.clickPixelThresh = 3;
379                                         }
380                                         
381                                         dd.startDrag = function(x,y){                                   
382                                                 this.el = document.getElementById(this.id);
383                                                 this.el.style.zIndex = 5;
384                                                 CAL.dropped = 0;                                                
385                                                 CAL.records_openable = false;
386                                                 CAL.disable_creating = true;
387                                                 CAL.old_caption = this.el.childNodes[0].innerHTML;
388                                                 CAL.moved_from_cell = this.el.parentNode.id;                                                    
389                                                 
390                                                 this.setDelta(2,2);
391                                         }
392                                         
393                                         dd.endDrag  = function(x,y){            
394                                                 this.el = document.getElementById(this.id);
395                                                 this.el.style.zIndex = "";
396                                                 
397                                                 var nodes = CAL.query("#cal-grid .slot");
398                                                 CAL.each(nodes,function(i,v){
399                                                         YAHOO.util.Dom.removeClass(nodes[i],"slot_active");
400                                                 });                                             
401                                         }
402                                         
403                                         dd.onDragDrop = function(e,id){ 
404                                                         
405                                                 var slot = document.getElementById(id);
406                                                 YAHOO.util.Dom.removeClass(slot,"slot_active");
407                                                 if(CAL.dropped) // prevent dropping on two slots in same time
408                                                         return;
409                                                 CAL.dropped = 1;
410                                                                                                 
411                                                 this.el.style.position = "relative";
412                                                 this.el.style.cssFloat = "none";                                                
413                                                 
414                                                 if(CAL.view != 'shared'){
415                                                         var box_id = this.id;
416                                                         var slot_id = id;
417                                                         var ex_slot_id = CAL.moved_from_cell;                           
418                                                         CAL.move_activity(box_id,slot_id,ex_slot_id);
419                                                 }else{                                  
420                                                         var record = this.el.getAttribute("record");
421                                                         var tid = id;
422                                                         var tar = tid.split("_");                                       
423                                                         var timestamp = tar[1];
424                                                         var tid = CAL.moved_from_cell;
425                                                         var tar = tid.split("_");                                       
426                                                         var ex_timestamp = tar[1];
427
428                                                         for(i = 0; i < CAL.shared_users_count; i++){            
429                                                                 var box_id = ""+record+"____"+i;        
430                                                                 var slot_id = "t_"+timestamp+"_"+i;
431                                                                 var ex_slot_id = "t_"+ex_timestamp+"_"+i;                                               
432                                                                 CAL.move_activity(box_id,slot_id,ex_slot_id);
433                                                         }                               
434                                                 }
435                                                 
436                                                 var callback = {
437                                                         success: function(o){
438                                                                 try{
439                                                                         res = eval("("+o.responseText+")");
440                                                                 }catch(err){
441                                                                         alert(CAL.lbl_error_saving);                                                    
442                                                                         ajaxStatus.hideStatus();
443                                                                         return; 
444                                                                 }
445                                                                 CAL.records_openable = true;
446                                                                 CAL.disable_creating = false;
447                                                                 CAL.update_vcal();
448                                                                 ajaxStatus.hideStatus();
449                                                         }                                                        
450                                                 };
451                                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));                                         
452                                                 var url = "index.php?module=Calendar&action=Reschedule&sugar_body_only=true";
453                                                 var data = {
454                                                                 "current_module" : this.el.getAttribute("module_name"),
455                                                                 "record" : this.el.getAttribute("record"),
456                                                                 "datetime" : slot.getAttribute("datetime")
457                                                 };                                              
458                                                 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
459                                         
460                                                 YAHOO.util.Dom.removeClass(slot,"slot_active");
461                                         }
462                                         
463                                         dd.onDragOver = function(e,id){
464                                                 var slot = document.getElementById(id);
465                                                 if(!YAHOO.util.Dom.hasClass(slot,"slot_active"))
466                                                         YAHOO.util.Dom.addClass(slot,"slot_active");                                            
467                                                 this.el.childNodes[0].childNodes[1].childNodes[0].innerHTML = slot.getAttribute('time');                                                                                        
468                                         }
469                                         
470                                         dd.onDragOut = function(e,id){
471                                                 var slot = document.getElementById(id);
472                                                 YAHOO.util.Dom.removeClass(slot,"slot_active");
473                                         }                                       
474                                 }
475                                                                 
476                                 CAL.arrange_slot("t_" + time_cell + suffix);
477                         }
478                                 
479         }
480
481         CAL.expand_record = function (id){
482                                                         CAL.tp1 = setTimeout(
483                                                                 function(){
484                                                                         var el = CAL.get(id);
485                                                                         if(el){
486                                                                                 el.style.height = parseInt(15 * 2 - 1) + "px";
487                                                                                 el.childNodes[1].style.display = "block";
488                                                                         }                       
489                                                                 },
490                                                                 350
491                                                         );
492         }
493
494         CAL.unexpand_record = function (id){
495                                                         clearTimeout(CAL.tp1);
496                                                         var el = CAL.get(id);
497                                                         el.style.height = parseInt(15 * CAL.get(id).getAttribute("duration_coef") - 2) + "px";
498                                                         el.childNodes[1].style.display = "none"; //innerHTML = "";
499                                                         CAL.cut_record(id);
500         }
501
502         CAL.get_header_text = function (type,time_start,status,record){
503                         var start_text = "<span class='start_time'>" + time_start + "</span> " + SUGAR.language.languages.app_list_strings[type +'_status_dom'][status];
504                         return start_text;
505         }
506         
507         CAL.cut_record = function (id){
508         
509                         var el = CAL.get(id);                   
510                         if(!el)
511                                 return;
512                                 
513                         var duration_coef = el.getAttribute("duration_coef");                   
514                         var real_celcount = CAL.celcount;
515                         
516                         if(CAL.view == 'day' || CAL.view == 'week')                     
517                                 real_celcount = CAL.cells_per_day;      
518                         
519                         var celpos = 0;                 
520                         var s = el.parentNode;
521                         while(s.previousSibling){
522                                 celpos++;
523                                 s = s.previousSibling;
524                         }
525                         
526                         if(CAL.view == 'week')
527                                 celpos = celpos + 1;
528                         
529                         if(real_celcount - celpos - duration_coef < 0)
530                                 duration_coef = real_celcount - celpos + 1;                                                     
531                         el.style.height = parseInt(15 * duration_coef - 1) + "px";
532                         
533         }
534
535         CAL.init_edit_dialog = function (params){
536                 CAL.editDialog = false;
537                 
538                 var rd = CAL.get("cal-edit");
539                 var content = CAL.get("edit-dialog-content");
540                 
541                 if(CAL.dashlet && rd){
542                         document.getElementById("content").appendChild(rd);
543                 }
544                         
545                 rd.style.width = params.width+"px";                             
546                 content.style.height = params.height+"px";
547                 content.style.overflow = "auto";
548                 content.style.padding = "0";
549
550                 CAL.editDialog = new YAHOO.widget.Dialog("cal-edit",{ 
551                         draggable : true,
552                         visible : false,
553                         modal : true,
554                         close : true,
555                         zIndex : 10
556                 });
557                 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.editDialog.cancel();} } );
558                 CAL.editDialog.cfg.queueProperty("keylisteners", listeners);
559                 
560                 
561                 
562                 CAL.editDialog.cancelEvent.subscribe(function(e, a, o){                                 
563                         CAL.close_edit_dialog();
564                 });
565                 
566                 rd.style.display = "block";
567                 CAL.editDialog.render();
568                 
569                 rd.style.overflow = "auto";
570                 rd.style.overflowX = "hidden";
571                 rd.style.outline = "0 none";
572                 rd.style.height = "auto";
573         
574         }
575         
576
577         CAL.open_edit_dialog = function (params){
578                                                 // Reset display parameter, if the delete button was hidden 
579                                                 CAL.get("btn-delete").style.display = "";
580                                                 
581                                                 CAL.editDialog.center();
582                                                 CAL.editDialog.show();          
583                                                 
584                                                 var nodes = CAL.query("#cal-tabs li a");
585                                                 CAL.each(nodes,function(i,v){
586                                                         YAHOO.util.Event.on(nodes[i], 'click', function(){
587                                                                 CAL.select_tab(this.getAttribute("tabname"));
588                                                         });
589                                                 });
590                                                 
591                                                 var nodes_li = CAL.query("#cal-tabs li");
592                                                 CAL.each(nodes_li,function(j,v){                                                                                                                                                
593                                                         CAL.dom.removeClass(nodes_li[j],"selected");
594                                                         if(j == 0)
595                                                                 CAL.dom.addClass(nodes_li[j],"selected");       
596                                                 });
597                                                 
598                                                 var nodes = CAL.query(".yui-nav");
599                                                 CAL.each(nodes,function(i,v){
600                                                         nodes[i].style.overflowX = "visible";
601                                                 });                                     
602
603         }
604
605         CAL.close_edit_dialog = function (){                                    
606                 CAL.reset_edit_dialog();
607         }
608         
609         CAL.remove_edit_dialog = function(){
610                 var rd_c = CAL.get("cal-edit_c");
611                 if(rd_c){
612                         rd_c.parentNode.removeChild(rd_c);
613                 }               
614         }       
615         
616         CAL.reset_edit_dialog = function (){
617                 var e;
618
619                 document.getElementById("form_content").innerHTML = ""; 
620                 document.forms["CalendarEditView"].elements["current_module"].value = "Meetings";
621         
622                 CAL.get("radio_call").removeAttribute("disabled");
623                 CAL.get("radio_meeting").removeAttribute("disabled");
624                 CAL.get("radio_call").checked = false;
625                 CAL.get("radio_meeting").checked = true;
626                 
627                 CAL.get("send_invites").value = "";
628         
629                 if(e = CAL.get("record"))
630                         e.value = "";
631                         
632                 if(e = CAL.get("list_div_win"))
633                         e.style.display = "none";                       
634
635                 CAL.GR_update_focus("Meetings",""); 
636                 CAL.select_tab("cal-tab-1");            
637                 
638                 QSFieldsArray = new Array();
639                 QSProcessedFieldsArray = new Array();
640         }
641
642         CAL.select_tab = function (tid){
643         
644                 var nodes_li = CAL.query("#cal-tabs li");
645                 CAL.each(nodes_li,function(j,v){
646                         CAL.dom.removeClass(nodes_li[j],"selected");
647                 });                                                     
648                 
649                 CAL.dom.addClass(CAL.get(tid + "-link").parentNode,"selected");
650                 
651                                                                         
652                 var nodes = CAL.query("#cal-tabs .yui-content");
653                 CAL.each(nodes,function(i,v){
654                         nodes[i].style.display = "none";
655                 });
656                 var nodes = CAL.query("#cal-tabs #"+tid);
657                 CAL.each(nodes,function(i,v){
658                         nodes[i].style.display = "block";
659                 });
660         }
661
662         CAL.GR_update_user = function (user_id){        
663         
664                 var callback = {
665                         success: function(o){                           
666                                 res = eval(o.responseText);
667                                 GLOBAL_REGISTRY.focus.users_arr_hash = undefined;                                                                                       
668                                 //SugarWidgetScheduler.update_time();
669                         }
670                 };
671         
672                 var data = {
673                         "users": user_id
674                 };
675                 var url = "index.php?module=Calendar&action=GetGRUsers&sugar_body_only=true";   
676                 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
677
678         }
679                 
680         CAL.GR_update_focus = function (module,record){
681                 if(record == ""){
682                         GLOBAL_REGISTRY["focus"] = {"module":module, users_arr:[],fields:{"id":"-1"}};
683                         SugarWidgetScheduler.update_time();                     
684                 }else{          
685                         var callback = {
686                                 success: function(o){
687                                         res = eval(o.responseText);
688                                         SugarWidgetScheduler.update_time();                                                                                     
689                                         if(CAL.record_editable){
690                                                 CAL.get("btn-save").removeAttribute("disabled");
691                                                 CAL.get("btn-delete").removeAttribute("disabled");
692                                                 CAL.get("btn-apply").removeAttribute("disabled");
693                                                 CAL.get("btn-send-invites").removeAttribute("disabled");
694                                         }
695                                 }
696                         };      
697
698                         var url = 'index.php?module=Calendar&action=GetGR&sugar_body_only=true&type=' + module + '&record=' + record;   
699                         YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
700                 }               
701         }
702
703         CAL.toggle_settings = function (){
704                 var sd = CAL.get("settings_dialog");            
705                         
706                         
707                 if(!CAL.settingsDialog){        
708                         CAL.settingsDialog = new YAHOO.widget.Dialog("settings_dialog",{ 
709                                         fixedcenter: true,
710                                         draggable: false,
711                                         visible : false, 
712                                         modal : true,
713                                         close: true
714                         });
715                         var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.settingsDialog.cancel();} } );
716                         CAL.settingsDialog.cfg.queueProperty("keylisteners", listeners);
717                 }
718                 CAL.settingsDialog.cancelEvent.subscribe(function(e, a, o){
719                         CAL.get("form_settings").reset();
720                 });
721                 sd.style.display = "block";      
722                 CAL.settingsDialog.render();
723                 CAL.settingsDialog.show();
724         }
725
726         CAL.toggle_whole_day = function (){
727                 var wd = CAL.get("whole_day");
728                 if(!wd.value)
729                         wd.value = "1";
730                 else
731                         wd.value = "";
732                 setTimeout(
733                         function(){
734                                 if(wd.value){
735                                         var nodes = CAL.query("#cal-grid .owt");
736                                         CAL.each(nodes,function(i,v){                                           
737                                                 nodes[i].style.display = "block";
738                                         });
739                                 }else{
740                                         var nodes = CAL.query("#cal-grid .owt");
741                                         CAL.each(nodes,function(i,v){
742                                                 nodes[i].style.display = "none";
743                                         });
744                                 }
745                         },
746                         25);
747         
748         }
749                 
750         CAL.fill_invitees = function (){        
751                 
752                 CAL.get("user_invitees").value = "";
753                 CAL.get("contact_invitees").value = "";
754                 CAL.get("lead_invitees").value = "";    
755
756                 CAL.each( GLOBAL_REGISTRY['focus'].users_arr,   function(i,v){
757                                                                         var field_name = "";
758                                                                         if(v.module == "User")
759                                                                                 field_name = "user_invitees";
760                                                                         if(v.module == "Contact")
761                                                                                 field_name = "contact_invitees";
762                                                                         if(v.module == "Lead")
763                                                                                 field_name = "lead_invitees";
764                                                                         var str = CAL.get(field_name).value;
765                                                                         CAL.get(field_name).value = str + v.fields.id + ",";    
766                                                                 }
767                 );      
768         }       
769                                 
770         
771         CAL.load_form = function (module_name,record,run_one_time){
772         
773                 var e;
774                 var to_open = true;
775                 if(module_name == "Tasks")
776                         to_open = false;
777
778                 if(to_open && CAL.records_openable){
779                         CAL.get("form_content").style.display = "none";
780                 
781                         CAL.get("btn-delete").setAttribute("disabled","disabled");
782                         CAL.get("btn-apply").setAttribute("disabled","disabled");
783                         CAL.get("btn-save").setAttribute("disabled","disabled");
784                         CAL.get("btn-send-invites").setAttribute("disabled","disabled");                
785         
786                         CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
787                         
788                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
789                         
790                         CAL.open_edit_dialog(); 
791                         CAL.get("record").value = "";   
792                                                 
793         
794                         var callback = {
795                                                                                                                                         
796                                         success: function(o){
797                                                 try{
798                                                         res = eval("("+o.responseText+")");
799                                                 }catch(err){
800                                                         alert(CAL.lbl_error_loading);
801                                                         CAL.editDialog.cancel();                                                        
802                                                         ajaxStatus.hideStatus();
803                                                         return; 
804                                                 }                                                                       
805                                                 if(res.success == 'yes'){                                               
806                                                         var fc = document.getElementById("form_content");
807                                                         CAL.script_evaled = false;
808                                                         fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html; 
809                                                         if(!CAL.script_evaled){                                                                                 
810                                                                 SUGAR.util.evalScript(res.html);
811                                                         }
812                                                         
813                                                         CAL.get("record").value = res.record;
814                                                         CAL.get("current_module").value = res.module_name;      
815                                                         
816                                                         var mod_name = res.module_name; 
817                                                         
818                                                         if(mod_name == "Meetings")
819                                                                 CAL.get("radio_meeting").checked = true;
820                                                         if(mod_name == "Calls")
821                                                                 CAL.get("radio_call").checked = true;
822                                                                 
823                                                         if(res.edit == 1){
824                                                                 CAL.record_editable = true;
825                                                         }else{
826                                                                 CAL.record_editable = false;
827                                                         }
828                                                         
829                                                         CAL.get("radio_call").setAttribute("disabled","disabled");
830                                                         CAL.get("radio_meeting").setAttribute("disabled","disabled");
831                                                         
832                                                         eval(res.gr);                                                   
833                                                         SugarWidgetScheduler.update_time();
834                                                                                                                                 
835                                                         if(CAL.record_editable){
836                                                                 CAL.get("btn-save").removeAttribute("disabled");
837                                                                 CAL.get("btn-delete").removeAttribute("disabled");
838                                                                 CAL.get("btn-apply").removeAttribute("disabled");
839                                                                 CAL.get("btn-send-invites").removeAttribute("disabled");
840                                                         }                                                       
841                                                         
842                                                         CAL.get("form_content").style.display = "";
843                                                         CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
844                                                         ajaxStatus.hideStatus();
845                                                                 
846                                                         setTimeout(function(){
847                                                                 enableQS(false);
848                                                                 disableOnUnloadEditView();
849                                                         },500);
850                                                         
851                                                 }else
852                                                         alert(CAL.lbl_error_loading);
853                                                                                                                                                         
854                                         },
855                                         failure: function(){
856                                                 alert(CAL.lbl_error_loading);
857                                         }
858                         };
859                         var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
860                         var data = {
861                                 "current_module" : module_name,
862                                 "record" : record
863                         };
864                         YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
865                         
866                 }
867                 CAL.records_openable = true;                                                            
868         }
869                 
870         
871         CAL.remove_shared = function (record_id){
872                         var e;
873                         var cell_id;
874                         if(e = CAL.get(record_id + '____' + "0"))
875                                 cell_id = e.parentNode.id;
876                                 
877                         if(typeof cell_id != "undefined"){
878                                 var cell_id_arr = cell_id.split("_");
879                                 cell_id = "t_" + cell_id_arr[1];
880                         }                                                                                       
881                         CAL.each(CAL.shared_users,function(i,v){        
882                                 if(e = CAL.get(record_id + '____' + v)) 
883                                         e.parentNode.removeChild(e);                                                                                                            
884                                 CAL.arrange_slot(cell_id + '_' + v);
885                                 
886                         });
887         }
888                         
889         CAL.add_item = function (item){ 
890                                                 
891                         if(CAL.view != 'shared'){
892                                 CAL.add_item_to_grid(item);
893                         }else{
894                                 CAL.remove_shared(item.record);
895                                 record_id = item.record;
896                                 //var rec_id = item.rec_id;
897                                 var timestamp = item.timestamp;
898                                 CAL.each(
899                                         item.users,
900                                         function (i,v){                                         
901                                                 var rec = item;
902                                                 //rec.rec_id = rec_id;
903                                                 rec.timestamp = timestamp;                                              
904                                                 rec.user_id = v;
905                                                 rec.record = record_id;
906                                                 CAL.add_item_to_grid(rec);
907                                                 
908                                                 CAL.each(
909                                                         rec.arr_rec,
910                                                         function (j,r){
911                                                                 rec.record = r.record;
912                                                                 rec.timestamp = r.timestamp;
913                                                                 //rec.rec_id = record_id;
914                                                                 CAL.add_item_to_grid(rec);
915                                                         }                               
916                                                 );                                                                                                                                                                                      
917                                         }                                                                                                                               
918                                 );
919                         }
920                         
921                         CAL.arrange_advanced();
922         }
923                 
924         CAL.move_activity = function (box_id,slot_id,ex_slot_id){
925                                 var u,s;                                                
926                                 if(u = CAL.get(box_id)){
927                                         if(s = CAL.get(slot_id)){
928                                                 s.appendChild(u);
929                                                 
930                                                 CAL.arrange_column(document.getElementById(slot_id).parentNode);
931                                                 CAL.arrange_column(document.getElementById(ex_slot_id).parentNode);
932                                                 CAL.update_dd.fire();
933
934                                                 CAL.cut_record(box_id);                                 
935                                                 var start_text = CAL.get_header_text(CAL.act_types[u.getAttribute('module_name')],s.getAttribute('time'),u.getAttribute('status'),u.getAttribute('record'));
936                                                 var date_field = "date_start";
937                                                 if(u.getAttribute('module_name') == "Tasks")
938                                                         date_field = "date_due";                                                        
939                                                 u.setAttribute(date_field,s.getAttribute("datetime"));                          
940                                                 u.childNodes[0].childNodes[1].innerHTML = start_text;
941                                         }
942                                 }
943         }       
944         
945         CAL.change_activity_type = function (mod_name){
946                 if(typeof CAL.current_params.module_name != "undefined" )
947                         if(CAL.current_params.module_name == mod_name)
948                                 return;
949         
950                 var e,user_name,user_id,date_start;
951                 
952                 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
953                                 
954                 document.forms["CalendarEditView"].elements["current_module"].value = mod_name;         
955         
956                 CAL.current_params.module_name = mod_name;
957                 
958                 QSFieldsArray = new Array();
959                 QSProcessedFieldsArray = new Array();
960                 
961                 CAL.load_create_form(CAL.current_params);                               
962         }
963
964
965         
966         CAL.load_create_form = function (params){
967         
968                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
969                         
970                         var callback = {
971                                                                                                                                         
972                                         success: function(o){                                           
973                                                 try{
974                                                         res = eval("("+o.responseText+")");
975                                                 }catch(err){
976                                                         alert(CAL.lbl_error_loading);
977                                                         CAL.editDialog.cancel();                                                        
978                                                         ajaxStatus.hideStatus();
979                                                         return; 
980                                                 }                                                                       
981                                                 if(res.success == 'yes'){                                               
982                                                         var fc = document.getElementById("form_content");
983                                                         CAL.script_evaled = false;
984                                                         fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html; 
985                                                         
986                                                         if(!CAL.script_evaled){                                                                                 
987                                                                 SUGAR.util.evalScript(res.html);
988                                                         }
989                                                                                                                 
990                                                         CAL.get("record").value = "";
991                                                         CAL.get("current_module").value = res.module_name;                                                              
992                                                         var mod_name = res.module_name; 
993                                                                                                         
994                                                         if(res.edit == 1){
995                                                                 CAL.record_editable = true;
996                                                         }else{
997                                                                 CAL.record_editable = false;
998                                                         }
999                                                                                                                 
1000                                                         CAL.get("title-cal-edit").innerHTML = CAL.lbl_create_new;
1001
1002                                                         setTimeout(function(){
1003                                                                 SugarWidgetScheduler.update_time();
1004                                                                 enableQS(false);
1005                                                                 disableOnUnloadEditView();
1006                                                         },500);
1007                                                         
1008                                                         ajaxStatus.hideStatus();
1009                                                         
1010                                                 }else{
1011                                                         alert(CAL.lbl_error_loading);
1012                                                         ajaxStatus.hideStatus();
1013                                                 }
1014                                         },
1015                                         failure: function() {
1016                                                 alert(CAL.lbl_error_loading);
1017                                                 ajaxStatus.hideStatus();
1018                                         }       
1019                         };                      
1020                                                         
1021                         var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
1022                         var data = {
1023                                 "current_module" : params.module_name,
1024                                 "assigned_user_id" : params.user_id,
1025                                 "assigned_user_name" : params.user_name,
1026                                 "date_start" : params.date_start
1027                         };
1028                         YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));   
1029         }
1030                 
1031         
1032         CAL.dialog_create = function (cell){
1033         
1034                         var e,user_id,user_name;
1035                         CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;                                                                                                          
1036                         CAL.open_edit_dialog();
1037
1038                         // Hide and disable delete button when creating a new record 
1039                         CAL.get("btn-delete").setAttribute("disabled","disabled");
1040                         CAL.get("btn-delete").style.display = "none";
1041
1042                         
1043                         var module_name = CAL.get("current_module").value;
1044                         
1045                         if(CAL.view == 'shared'){
1046                                 user_name = cell.parentNode.parentNode.parentNode.getAttribute("user_name");
1047                                 user_id = cell.parentNode.parentNode.parentNode.getAttribute("user_id");
1048                                 CAL.GR_update_user(user_id);
1049                         }else{
1050                                 user_id = CAL.current_user_id;
1051                                 user_name = CAL.current_user_name;
1052                                 CAL.GR_update_user(CAL.current_user_id);                                                                                                
1053                         }                                               
1054                         
1055                         var params = {  
1056                                 'module_name': module_name,
1057                                 'user_id': user_id,     
1058                                 'user_name': user_name,                 
1059                                 'date_start': cell.getAttribute("datetime")                             
1060                         };
1061                         CAL.current_params = params;
1062                         CAL.load_create_form(CAL.current_params);
1063                                                         
1064         }
1065         
1066         CAL.dialog_save = function(){                                           
1067                                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
1068                                                 
1069                                                 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;                                                                                                                                                                   
1070                                                 CAL.fill_invitees();                                                    
1071                                                 //CAL.fill_recurrence();
1072                                                                                                 
1073                                                 var callback = {
1074                                                                 success: function(o){
1075                                                                         try{
1076                                                                                 res = eval("("+o.responseText+")");
1077                                                                         }catch(err){
1078                                                                                 alert(CAL.lbl_error_saving);
1079                                                                                 CAL.editDialog.cancel();                                                        
1080                                                                                 ajaxStatus.hideStatus();
1081                                                                                 return; 
1082                                                                         }
1083                                                                         if(res.success == 'yes'){
1084                                                                                 CAL.add_item(res);
1085                                                                                 CAL.editDialog.cancel();
1086                                                                                 CAL.update_vcal();
1087                                                                                 ajaxStatus.hideStatus();                                                                                                
1088                                                                         }else{
1089                                                                                 alert(CAL.lbl_error_saving);
1090                                                                                 ajaxStatus.hideStatus();
1091                                                                         }                                                                                                               
1092                                                                 },
1093                                                                 failure: function(){
1094                                                                                 alert(CAL.lbl_error_saving);
1095                                                                                 ajaxStatus.hideStatus();
1096                                                                 }
1097                                                 };                                              
1098                                                 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true"; 
1099                                                 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
1100                                                 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);     
1101         }
1102         
1103         CAL.dialog_apply = function(){
1104                                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
1105                                                 
1106                                                 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;                                                           
1107                                                 CAL.fill_invitees();                                                    
1108                                                 //CAL.fill_recurrence();        
1109                                                 
1110                                                 var e;
1111                                                 if(e = CAL.get("radio_call"))
1112                                                         e.setAttribute("disabled","disabled");
1113                                                 if(e = CAL.get("radio_meeting"))
1114                                                         e.setAttribute("disabled","disabled");                                                                                                  
1115                                                 
1116
1117
1118                                                 var callback = {
1119                                                                 success: function(o){
1120                                                                         try{
1121                                                                                 res = eval("("+o.responseText+")");
1122                                                                         }catch(err){
1123                                                                                 alert(CAL.lbl_error_saving);
1124                                                                                 CAL.editDialog.cancel();                                                        
1125                                                                                 ajaxStatus.hideStatus();
1126                                                                                 return; 
1127                                                                         }
1128                                                                         if(res.success == 'yes'){                                                                               
1129                                                                                 var e;
1130                                                                                 CAL.get("record").value = res.record;   
1131                                                                                 //SugarWidgetScheduler.update_time();
1132                                                                                 //CAL.GR_update_focus(CAL.get("current_module").value,res.record);
1133                                                                                 CAL.add_item(res);
1134                                                                                 CAL.update_vcal();                                                                                                                                                                                                              
1135                                                                                 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
1136                                                                                 if(e = CAL.get("send_invites"))
1137                                                                                         e.removeAttribute("checked");
1138
1139                                                                                 ajaxStatus.hideStatus();                
1140                                                                                 
1141                                                                                 // If new data is added with Apply, show the Delete button
1142                                                                                 CAL.get("btn-delete").removeAttribute("disabled");
1143                                                                                 CAL.get("btn-delete").style.display = "";
1144                                                                         }else{
1145                                                                                 alert(CAL.lbl_error_saving);
1146                                                                                 ajaxStatus.hideStatus();
1147                                                                         }                                                                                                               
1148                                                                 },
1149                                                                 failure: function(){
1150                                                                                 alert(CAL.lbl_error_saving);
1151                                                                                 ajaxStatus.hideStatus();
1152                                                                 }
1153                                                 };                                              
1154                                                 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true"; 
1155                                                 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
1156                                                 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
1157         }
1158         
1159         CAL.dialog_remove = function(){
1160                                                                         CAL.deleted_id = CAL.get("record").value;
1161                                                                         CAL.deleted_module = CAL.get("current_module").value;                                                                   
1162                                                                         var delete_recurring = false;                                                           
1163                                                                                         
1164                                                                         var callback = {
1165                                                                                         success: function(o){
1166                                                                                                 try{
1167                                                                                                         res = eval("("+o.responseText+")");
1168                                                                                                 }catch(err){
1169                                                                                                         alert(CAL.lbl_error_saving);
1170                                                                                                         CAL.editDialog.cancel();                                                        
1171                                                                                                         ajaxStatus.hideStatus();
1172                                                                                                         return; 
1173                                                                                                 }
1174                                                                                                         
1175                                                                                                 var e,cell_id;
1176                                                                                                 if(e = CAL.get(CAL.deleted_id))
1177                                                                                                         cell_id = e.parentNode.id;
1178                                                                                                 if(CAL.view == 'shared')        
1179                                                                                                         CAL.remove_shared(CAL.deleted_id);      
1180                                                                                                         
1181                                                                                                 if(e = CAL.get(CAL.deleted_id))
1182                                                                                                         e.parentNode.removeChild(e);                                                                    
1183                                                                                                 
1184                                                                                                 
1185                                                                                                 CAL.arrange_advanced();
1186                                                                                                                                                                                                                 
1187                                                                                         },
1188                                                                                         failure: function(){
1189                                                                                                         alert(CAL.lbl_error_saving);
1190                                                                                         }
1191                                                                         };                                                                      
1192                                                                         
1193                                                                         var data = {
1194                                                                                 "current_module" : CAL.deleted_module,
1195                                                                                 "record" : CAL.deleted_id,
1196                                                                                 "delete_recurring": delete_recurring
1197                                                                         };
1198                                                                         var url = "index.php?module=Calendar&action=Remove&sugar_body_only=true";                                                                       
1199                                                                         YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1200
1201                                                                         CAL.editDialog.cancel();        
1202         }
1203         
1204         CAL.show_additional_details = function (id){
1205                 var obj = CAL.get(id);
1206         
1207                 var record = obj.getAttribute("record");
1208                 mod = obj.getAttribute("module_name");
1209                 var atype = CAL.act_types[mod];
1210         
1211                 var subj = obj.getAttribute("subj");
1212                 var date_start = obj.getAttribute("date_start");
1213                 var duration = obj.getAttribute("dur"); 
1214                 var desc = obj.getAttribute("desc");    
1215                 var detail = parseInt(obj.getAttribute("detail"));
1216                 var edit = parseInt(obj.getAttribute("edit"));
1217                 
1218                 var date_str = "";
1219                 if(date_start != "")
1220                         date_str += '<b>'+CAL.lbl_start+':</b> ' +  date_start;                 
1221                 if(mod == "Tasks"){
1222                         var date_due = obj.getAttribute("date_due");
1223                         if(date_due != ""){
1224                                 if(date_str != "")
1225                                         date_str += "<br>";
1226                                 date_str += '<b>'+CAL.lbl_due+':</b> ' +  date_due;
1227                         }               
1228                 }                               
1229                 
1230                 var related = "";
1231                 if(obj.getAttribute("parent_id") != '' && obj.getAttribute("parent_name") != '')
1232                         related = "<b>" + CAL.lbl_related + ":</b> <a href='index.php?module="+obj.getAttribute("parent_type")+"&action=DetailView&record="+obj.getAttribute("parent_id")+"'>"+obj.getAttribute("parent_name")+"</a>" + "<br>";
1233
1234                 if(desc != '')
1235                         desc = '<b>'+ CAL.lbl_desc + ':</b><br> ' + desc +'<br>';                       
1236                 if(subj == '')
1237                         return "";
1238
1239                 var date_lbl = CAL.lbl_start;           
1240                 if(duration != ""){
1241                         var duration_text = '<b>'+CAL.lbl_duration+':</b> ' + duration + '<br>';
1242                         if(mod == "Tasks"){
1243                                 date_lbl = CAL.lbl_due;
1244                                 duration_text = "";                     
1245                         }
1246                 }else
1247                         duration_text = "";
1248
1249                 var caption = "<div style='float: left;'>"+CAL.lbl_title+"</div><div style='float: right;'>";
1250                 if(edit){
1251                         caption += "<a title=\'"+SUGAR.language.get('app_strings', 'LBL_EDIT_BUTTON')+"\' href=\'index.php?module="+mod+"&action=EditView&record="+record+"\'><img border=0  src=\'"+CAL.img_edit_inline+"\'></a>";
1252                 }
1253                 if(detail){
1254                         caption += "<a title=\'"+SUGAR.language.get('app_strings', 'LBL_VIEW_BUTTON')+"\' href=\'index.php?module="+mod+"&action=DetailView&record="+record+"\'><img border=0  style=\'margin-left:2px;\' src=\'"+CAL.img_view_inline+"\'></a>";
1255                 }
1256                 caption += "<a title=\'"+SUGAR.language.get('app_strings', 'LBL_ADDITIONAL_DETAILS_CLOSE_TITLE')+"\' href=\'javascript:return cClick();\' onclick=\'javascript:return cClick();\'><img border=0  style=\'margin-left:2px;margin-right:2px;\' src=\'"+CAL.img_close+"\'></a></div>";
1257
1258                 
1259                 var body = '<b>'+CAL.lbl_name+':</b> ' + subj + '<br>' + date_str + '<br>' + duration_text + related + desc;
1260                 return overlib(body, CAPTION, caption, DELAY, 200, STICKY, MOUSEOFF, 200, WIDTH, 300, CLOSETEXT, '', CLOSETITLE, SUGAR.language.get('app_strings','LBL_ADDITIONAL_DETAILS_CLOSE_TITLE'), CLOSECLICK, FGCLASS, 'olFgClass', CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass ecCapFontClass', CLOSEFONTCLASS, 'olCloseFontClass');
1261         }               
1262         
1263         CAL.toggle_shared_edit = function (id){
1264                 if(document.getElementById(id).style.display == 'none'){
1265                         document.getElementById(id).style.display = 'inline'
1266                         if(document.getElementById(id+"link") != undefined){
1267                                 document.getElementById(id+"link").style.display='none';
1268                         }
1269                 }else{
1270                         document.getElementById(id).style.display = 'none'
1271                         if(document.getElementById(id+"link") != undefined){
1272                                 document.getElementById(id+"link").style.display = 'inline';
1273                         }
1274                 }
1275         }
1276
1277         CAL.goto_date_call = function (){
1278                 var date_string = CAL.get("goto_date").value;
1279                 var date_arr = [];
1280                 date_arr = date_string.split("/");
1281                 
1282                 window.location.href = "index.php?module=Calendar&view="+CAL.view+"&day="+date_arr[1]+"&month="+date_arr[0]+"&year="+date_arr[2];       
1283         }
1284         
1285         CAL.toURI = function (a){
1286                         t=[];
1287                         for(x in a){                    
1288                                 if(!(a[x].constructor.toString().indexOf('Array') == -1)){
1289                                         for(i in a[x])
1290                                                 t.push(x+"[]="+encodeURIComponent(a[x][i]));
1291                                 }else                   
1292                                         t.push(x+"="+encodeURIComponent(a[x]));
1293                         }
1294                         return t.join("&");
1295         }       
1296         
1297         CAL.each = function (object, callback) {
1298                 
1299                 if(typeof object == "undefined")
1300                         return;
1301                 var name, i = 0,
1302                 length = object.length,
1303                 isObj = (length === undefined) || (typeof (object) === "function");
1304                 if(isObj){
1305                             for (name in object) {
1306                                 if (callback.call(object[name], name, object[name]) === false) {
1307                                     break;
1308                                 }
1309                             }
1310                 }else{
1311                             for (; i < length;) {
1312                                 if (callback.call(object[i], i, object[i++]) === false) {
1313                                     break;
1314                                 }
1315                             }
1316                 }
1317                 return object;
1318         }
1319         
1320         CAL.update_vcal = function(){
1321                                                                                                 
1322                                         var v = CAL.current_user_id;                                                                                            
1323                                         var callback = {
1324                                                 success: function(result){ 
1325                                                         if (typeof GLOBAL_REGISTRY.freebusy == 'undefined') {
1326                                                                 GLOBAL_REGISTRY.freebusy = new Object();
1327                                                         }
1328                                                         if (typeof GLOBAL_REGISTRY.freebusy_adjusted == 'undefined') {
1329                                                                         GLOBAL_REGISTRY.freebusy_adjusted = new Object();
1330                                                         }
1331                                                         // parse vCal and put it in the registry using the user_id as a key:
1332                                                         GLOBAL_REGISTRY.freebusy[v] = SugarVCalClient.parseResults(result.responseText, false);                  
1333                                                         // parse for current user adjusted vCal
1334                                                         GLOBAL_REGISTRY.freebusy_adjusted[v] = SugarVCalClient.parseResults(result.responseText, true);
1335                                                         SugarWidgetScheduler.update_time();
1336                                                 }                                                                                               
1337                                         };
1338                                                         
1339                                         var url = "vcal_server.php?type=vfb&source=outlook&user_id="+v;                                                                 
1340                                         YAHOO.util.Connect.asyncRequest('GET',url,callback,false);
1341         }
1342         
1343         CAL.fit_grid = function(){
1344                 var day_width;
1345                 var cal_width = document.getElementById("cal-grid").parentNode.parentNode.offsetWidth;
1346                 var left_width = 80;
1347                 
1348                 
1349                 if(CAL.view == "day")
1350                         day_width = parseInt((cal_width - left_width));
1351                 else                                                    
1352                         day_width = parseInt((cal_width - left_width) / 7 );
1353                         
1354                 var nodes = CAL.query("#cal-grid div.day_col");
1355                 CAL.each(nodes, function(i,v){          
1356                         nodes[i].style.width = day_width + "px";
1357                 });
1358                 
1359                 document.getElementById("cal-grid").style.visibility = "";
1360         }
1361         
1362         
1363         YAHOO.util.DDCAL = function(id, sGroup, config){ 
1364                 this.cont = config.cont; 
1365                 YAHOO.util.DDCAL.superclass.constructor.apply(this, arguments);
1366         }
1367         YAHOO.extend(YAHOO.util.DDCAL, YAHOO.util.DD, { 
1368                 cont: null,                             
1369                 init: function(){
1370                         YAHOO.util.DDCAL.superclass.init.apply(this, arguments);
1371                         this.initConstraints();
1372                         CAL.update_dd.subscribe(function(type, args, dd){
1373                                 dd.resetConstraints();                                  
1374                                 dd.initConstraints();
1375                         },this);
1376                 },
1377                 initConstraints: function() { 
1378                         var region = YAHOO.util.Dom.getRegion(this.cont);
1379                         var el = this.getEl();
1380                         var xy = YAHOO.util.Dom.getXY(el);
1381                         var width = parseInt(YAHOO.util.Dom.getStyle(el, 'width'), 10);
1382                         var height = parseInt(YAHOO.util.Dom.getStyle(el, 'height'), 10); 
1383                         var left = xy[0] - region.left;
1384                         var right = region.right - xy[0] - width;
1385                         var top = xy[1] - region.top;
1386                         var bottom = region.bottom - xy[1] - height;
1387                         this.setXConstraint(left, right);
1388                         this.setYConstraint(top, bottom);
1389                 }
1390         });
1391         
1392         CAL.remove_edit_dialog();
1393         
1394         var cal_loaded = true;