]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/Calendar/Cal.js
Release 6.4.0beta3
[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         
56         CAL.dom = YAHOO.util.Dom;
57         CAL.get = YAHOO.util.Dom.get;
58         CAL.query = YAHOO.util.Selector.query;
59         
60         CAL.arrange_slot = function (cell_id){
61                 if(!cell_id)
62                         return; 
63                 cellElm = document.getElementById(cell_id);
64                 if(cellElm){                            
65                         var total_height = 0;
66                         var prev_i = 0;
67                         var first = 1;
68                         var top = 0;
69                         var height = 0;
70                         var cnt = 0;
71                         var child_cnt = cellElm.childNodes.length;
72                         for(var i = 0; i < child_cnt; i++){
73                                         var width_p = (92 / child_cnt);
74                                         width = width_p.toString() + "%";
75                                         if(cellElm.childNodes[i].tagName == "DIV"){
76                                                 cellElm.childNodes[i].style.top = "-1px";
77                                                 cellElm.childNodes[i].style.left = "-"+(cnt+1)+"px"; 
78                                                 cellElm.childNodes[i].style.width = width                                                       
79                                                 cnt++;                                          
80                                                 prev_i = i;                                     
81                                         }
82                         }
83                 }
84         }
85         
86         CAL.add_item_to_grid = function (item){
87                         
88                         var suffix = "";
89                         var id_suffix = "";                     
90                         
91                         if( item.user_id != "" && CAL.view == 'shared'){
92                                 suffix = "_" + CAL.shared_users[item.user_id];  
93                                 id_suffix = '____' + CAL.shared_users[item.user_id];            
94                         }
95                         
96                         var e = CAL.get(item.record + id_suffix);
97                         if(e){
98                                 e.parentNode.removeChild(e);
99                         }
100                                 
101                         var duration_text = item.duration_hours + CAL.lbl_hours_abbrev;
102                         if(item.duration_minutes > 0)
103                                 duration_text += item.duration_minutes + CAL.lbl_mins_abbrev;
104                         var start_text = CAL.get_header_text(item.type,item.time_start,item.status,item.record);
105                                                 
106                         var time_cell = item.timestamp - item.timestamp % (CAL.t_step * 60);                    
107                         
108                         var duration_coef; 
109                         if(item.module_name == 'Tasks'){
110                                 duration_coef = 1;
111                                 duration_text = " ";
112                         }else{  
113                                 if((item.duration_minutes < CAL.t_step) && (item.duration_hours == 0))
114                                         duration_coef = 1;
115                                 else                                    
116                                         duration_coef = (parseInt(item.duration_hours) * 60 + parseInt(item.duration_minutes)) / CAL.t_step;
117                         }                       
118
119                         var item_text = "";
120                         if(CAL.item_text && (typeof item[CAL.item_text] != "undefined") )
121                                 item_text = item[CAL.item_text];
122                         
123                         var contain_style = "";
124                         if(duration_coef < 1.75)
125                                 contain_style = "style='display: none;'";                                                       
126                         
127                         var elm_id = item.record + id_suffix;                   
128                         
129                         var el = document.createElement("div");
130                         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>"; 
131                         el.className = "act_item" + " " + item.type+"_item";
132                         el.setAttribute("id",elm_id);
133                         el.setAttribute("module_name",item.module_name);
134                         el.setAttribute("record",item.record);
135                         el.setAttribute("dur",duration_text);
136                         el.setAttribute("subj",item.record_name);
137                         el.setAttribute("date_start",item.date_start);
138                         el.setAttribute("desc",item.description);
139                         el.setAttribute("parent_name",item.parent_name);
140                         el.setAttribute("parent_type",item.parent_type);
141                         el.setAttribute("parent_id",item.parent_id);
142                         el.setAttribute("status",item.status);
143                         el.setAttribute("detail",item.detail);
144                         el.setAttribute("edit",item.edit);
145                         el.setAttribute("duration_coef",duration_coef);
146                         el.style.backgroundColor = CAL.activity_colors[item.module_name]['body'];
147                         el.style.borderColor = CAL.activity_colors[item.module_name]['border']; 
148                         el.style.height = parseInt(15 * duration_coef - 1) + "px";
149                         YAHOO.util.Event.on(el,"click",function(){
150                                         if(this.getAttribute('detail') == "1")
151                                                 CAL.load_from(this.getAttribute('module_name'),this.getAttribute('record'),false);
152                         });
153                         YAHOO.util.Event.on(el,"mouseover",function(){
154                                 if(!CAL.records_openable)
155                                         return;
156                                 CAL.disable_creating = true;    
157                                 CAL.tp = setTimeout(
158                                         function(){
159                                                 var e;
160                                                 if(e = CAL.get(elm_id))
161                                                         e.style.zIndex = 2;
162                                         },
163                                         150
164                                 ); 
165                         });
166                         YAHOO.util.Event.on(el,"mouseout",function(){
167                                 if(!CAL.records_openable)
168                                         return;
169                                 clearTimeout(CAL.tp);
170                                 CAL.get(elm_id).style.zIndex = '';
171                                 CAL.disable_creating = false;                                           
172                         });
173                         
174                         var slot;
175                         if(slot = CAL.get("t_" + time_cell + suffix)){
176                                 slot.appendChild(el);                                           
177                                 
178                                 if(duration_coef < 1.75 && CAL.mouseover_expand){
179                                         YAHOO.util.Event.on(elm_id,"mouseover",function(){
180                                                 if(CAL.records_openable)
181                                                         CAL.expand_record(this.getAttribute("id"));                                             
182                                         });
183                                         YAHOO.util.Event.on(elm_id,"mouseout",function(){       
184                                                 CAL.unexpand_record(this.getAttribute("id"));                                           
185                                         });
186                                         YAHOO.util.Event.on(elm_id,"click",function(){
187                                                 CAL.unexpand_record(this.getAttribute("id"));
188                                         });
189                                 }                                                               
190                                 
191                                 if(CAL.items_draggable && item.module_name != "Tasks" && item.edit == 1){
192                                 
193                                         var border = 'cal-grid';
194                                         if(CAL.view != "shared" && CAL.view != "month")
195                                                 border = 'cal-scrollable';
196                                                 
197                                         var dd = new YAHOO.util.DDCAL(elm_id,"cal",{isTarget: false,cont: border});                                                                     
198                                                                                                         
199                                         dd.onInvalidDrop = function(e){ 
200                                                 this.el.style.left = "-1px";
201                                                 this.el.style.top = "-1px";
202                                                 if(CAL.dropped == 0){
203                                                         this.el.childNodes[0].innerHTML = CAL.old_caption;
204                                                 }                                
205                                         }                                       
206                                                                         
207                                         dd.onMouseDown = function(e){
208                                                 YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
209                                                 YAHOO.util.DDM.clickPixelThresh = 20;
210                                         }
211                                         
212                                         dd.onMouseUp = function(e){
213                                                 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
214                                                 YAHOO.util.DDM.clickPixelThresh = 3;
215                                         }
216                                         
217                                         dd.startDrag = function(x,y){                                   
218                                                 this.el = document.getElementById(this.id);
219                                                 this.el.style.zIndex = 5;
220                                                 CAL.dropped = 0;                                                
221                                                 CAL.records_openable = false;
222                                                 CAL.old_caption = this.el.childNodes[0].innerHTML;
223                                                 CAL.moved_from_cell = this.el.parentNode.id;                                                    
224                                                 
225                                                 this.setDelta(2,2);
226                                         }
227                                         
228                                         dd.endDrag  = function(x,y){            
229                                                 this.el = document.getElementById(this.id);
230                                                 this.el.style.zIndex = "";
231                                                 
232                                                 var nodes = CAL.query("#cal-grid .slot");
233                                                 CAL.each(nodes,function(i,v){
234                                                         YAHOO.util.Dom.removeClass(nodes[i],"slot_active");
235                                                 });                                             
236                                         }
237                                         
238                                         dd.onDragDrop = function(e,id){ 
239                                                         
240                                                 var slot = document.getElementById(id);
241                                                 YAHOO.util.Dom.removeClass(slot,"slot_active");
242                                                 if(CAL.dropped) // prevent dropping on two slots in same time
243                                                         return;
244                                                 CAL.dropped = 1;
245                                                                                                 
246                                                 this.el.style.position = "relative";
247                                                 this.el.style.cssFloat = "none";                                                
248                                                 
249                                                 if(CAL.view != 'shared'){
250                                                         var box_id = this.id;
251                                                         var slot_id = id;
252                                                         var ex_slot_id = CAL.moved_from_cell;                           
253                                                         CAL.move_activity(box_id,slot_id,ex_slot_id);
254                                                 }else{                                  
255                                                         var record = this.el.getAttribute("record");
256                                                         var tid = id;
257                                                         var tar = tid.split("_");                                       
258                                                         var timestamp = tar[1];
259                                                         var tid = CAL.moved_from_cell;
260                                                         var tar = tid.split("_");                                       
261                                                         var ex_timestamp = tar[1];
262
263                                                         for(i = 0; i < CAL.shared_users_count; i++){            
264                                                                 var box_id = ""+record+"____"+i;        
265                                                                 var slot_id = "t_"+timestamp+"_"+i;
266                                                                 var ex_slot_id = "t_"+ex_timestamp+"_"+i;                                               
267                                                                 CAL.move_activity(box_id,slot_id,ex_slot_id);
268                                                         }                               
269                                                 }
270                                                 
271                                                 var callback = {
272                                                         success: function(o){
273                                                                 CAL.records_openable = true;
274                                                                 CAL.update_vcal();
275                                                                 ajaxStatus.hideStatus();
276                                                         }                                                        
277                                                 };
278                                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));                                         
279                                                 var url = "index.php?module=Calendar&action=Reschedule&sugar_body_only=true";
280                                                 var data = {
281                                                                 "current_module" : this.el.getAttribute("module_name"),
282                                                                 "record" : this.el.getAttribute("record"),
283                                                                 "datetime" : slot.getAttribute("datetime")
284                                                 };                                              
285                                                 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));                                           
286                                                                                         
287                                         
288                                                 YAHOO.util.Dom.removeClass(slot,"slot_active"); 
289                                                 CAL.disable_creating = false;   
290                                                 CAL.records_openable = true;                                                    
291                                                                                 
292                                         }
293                                         
294                                         dd.onDragOver = function(e,id){
295                                                 var slot = document.getElementById(id);
296                                                 if(!YAHOO.util.Dom.hasClass(slot,"slot_active"))
297                                                         YAHOO.util.Dom.addClass(slot,"slot_active");                                            
298                                                 this.el.childNodes[0].childNodes[1].childNodes[0].innerHTML = slot.getAttribute('time');                                                                                        
299                                         }
300                                         
301                                         dd.onDragOut = function(e,id){
302                                                 var slot = document.getElementById(id);
303                                                 YAHOO.util.Dom.removeClass(slot,"slot_active");
304                                         }                                       
305                                 }
306
307                                 CAL.cut_record(item.record + id_suffix);                                
308                                 CAL.arrange_slot("t_" + time_cell + suffix);
309                         }
310                                 
311         }
312
313         CAL.expand_record = function (id){
314                                                         CAL.tp1 = setTimeout(
315                                                                 function(){
316                                                                         var el = CAL.get(id);
317                                                                         if(el){
318                                                                                 el.style.height = parseInt(15 * 2 - 1) + "px";
319                                                                                 el.childNodes[1].style.display = "block";
320                                                                         }                       
321                                                                 },
322                                                                 350
323                                                         );
324         }
325
326         CAL.unexpand_record = function (id){
327                                                         clearTimeout(CAL.tp1);
328                                                         var el = CAL.get(id);
329                                                         el.style.height = parseInt(15 * CAL.get(id).getAttribute("duration_coef") - 2) + "px";
330                                                         el.childNodes[1].style.display = "none"; //innerHTML = "";
331                                                         CAL.cut_record(id);
332         }
333
334         CAL.get_header_text = function (type,time_start,status,record){
335                         var start_text = "<span class='start_time'>" + time_start + "</span> " + SUGAR.language.languages.app_list_strings[type +'_status_dom'][status];
336                         return start_text;
337         }
338         
339         CAL.cut_record = function (id){
340         
341                         var el = CAL.get(id);                   
342                         if(!el)
343                                 return;
344                                 
345                         var duration_coef = el.getAttribute("duration_coef");                   
346                         var real_celcount = CAL.celcount;
347                         
348                         if(CAL.view == 'day' || CAL.view == 'week')                     
349                                 real_celcount = CAL.cells_per_day;      
350                         
351                         var celpos = 0;                 
352                         var s = el.parentNode;
353                         while(s.previousSibling){
354                                 celpos++;
355                                 s = s.previousSibling;
356                         }
357                         
358                         if(CAL.view == 'week')
359                                 celpos = celpos + 1;
360                         
361                         if(real_celcount - celpos - duration_coef < 0)
362                                 duration_coef = real_celcount - celpos + 1;                                                     
363                         el.style.height = parseInt(15 * duration_coef - 1) + "px";
364                         
365         }
366
367         CAL.init_edit_dialog = function (params){
368                 CAL.editDialog = false;
369                 
370                 var rd = CAL.get("cal-edit");
371                 var content = CAL.get("edit-dialog-content");
372                 
373                 if(CAL.dashlet && rd){
374                         document.getElementById("content").appendChild(rd);
375                 }
376                         
377                 rd.style.width = params.width+"px";                             
378                 content.style.height = params.height+"px";
379                 content.style.overflow = "auto";
380                 content.style.padding = "0";
381
382                 CAL.editDialog = new YAHOO.widget.Dialog("cal-edit",{ 
383                         fixedcenter : true,
384                         draggable : true,
385                         visible : false,
386                         modal : true,
387                         close : true,
388                         zIndex : 10
389                 });
390                 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.editDialog.cancel();} } );
391                 CAL.editDialog.cfg.queueProperty("keylisteners", listeners);
392                 
393                 
394                 
395                 CAL.editDialog.cancelEvent.subscribe(function(e, a, o){                                 
396                         CAL.close_edit_dialog();
397                 });
398                 
399                 rd.style.display = "block";
400                 CAL.editDialog.render();
401                 
402                 rd.style.overflow = "auto";
403                 rd.style.overflowX = "hidden";
404                 rd.style.outline = "0 none";
405                 rd.style.height = "auto";
406         
407         }
408         
409
410         CAL.open_edit_dialog = function (params){       
411                                                                                         
412                                                 CAL.editDialog.show();          
413                                                 
414                                                 var nodes = CAL.query("#cal-tabs li a");
415                                                 CAL.each(nodes,function(i,v){
416                                                         YAHOO.util.Event.on(nodes[i], 'click', function(){
417                                                                 var nodes_li = CAL.query("#cal-tabs li");
418                                                                 CAL.each(nodes_li,function(j,v){
419                                                                         CAL.dom.removeClass(nodes_li[j],"selected");
420                                                                 });
421                                                         
422                                                                 if(!CAL.dom.hasClass(this.parentNode,"selected"))
423                                                                         CAL.dom.addClass(this.parentNode,"selected");   
424                                                                 CAL.select_tab(this.getAttribute("tabname"));
425                                                         });
426                                                 });
427                                                 
428                                                 var nodes_li = CAL.query("#cal-tabs li");
429                                                 CAL.each(nodes_li,function(j,v){                                                                                                                                                
430                                                         CAL.dom.removeClass(nodes_li[j],"selected");
431                                                         if(j == 0)
432                                                                 CAL.dom.addClass(nodes_li[j],"selected");       
433                                                 });
434                                                 
435                                                 var nodes = CAL.query(".yui-nav");
436                                                 CAL.each(nodes,function(i,v){
437                                                         nodes[i].style.overflowX = "visible";
438                                                 });                                     
439
440         }
441
442         CAL.close_edit_dialog = function (){                                    
443                 CAL.reset_edit_dialog();
444         }
445         
446         CAL.remove_edit_dialog = function(){
447                 var rd_c = CAL.get("cal-edit_c");
448                 if(rd_c){
449                         rd_c.parentNode.removeChild(rd_c);
450                 }               
451         }       
452         
453         CAL.reset_edit_dialog = function (){
454                 var e;
455
456                 document.getElementById("form_content").innerHTML = ""; 
457                 document.forms["CalendarEditView"].elements["current_module"].value = "Meetings";
458         
459                 CAL.get("radio_call").removeAttribute("disabled");
460                 CAL.get("radio_meeting").removeAttribute("disabled");
461                 CAL.get("radio_call").checked = false;
462                 CAL.get("radio_meeting").checked = true;
463                 
464                 CAL.get("send_invites").value = "";
465         
466                 if(e = CAL.get("record"))
467                         e.value = "";
468                         
469                 if(e = CAL.get("list_div_win"))
470                         e.style.display = "none";
471                         
472                 /*if(e = CAL.get("edit_all_recurrences_btn"))
473                         e.style.display = "none";               
474                                                 
475                 var nodes = CAL.query("#repeat_type option[value='']");
476                 CAL.each(nodes,function(i,v){
477                         nodes[i].setAttribute("selected","selected");
478                 });*/
479                 
480                 //CAL.repeat_type_selected();           
481         
482                 CAL.GR_update_focus("Meetings",""); 
483                 CAL.select_tab("cal-tab-1");
484         }
485
486         CAL.select_tab = function (tid){
487                 var nodes = CAL.query("#cal-tabs .yui-content");
488                 CAL.each(nodes,function(i,v){
489                         nodes[i].style.display = "none";
490                 });
491                 var nodes = CAL.query("#cal-tabs #"+tid);
492                 CAL.each(nodes,function(i,v){
493                         nodes[i].style.display = "block";
494                 });
495         }
496
497         CAL.GR_update_user = function (user_id){        
498         
499                 var callback = {
500                         success: function(o){                           
501                                 res = eval(o.responseText);
502                                 GLOBAL_REGISTRY.focus.users_arr_hash = undefined;                                                                                       
503                                 //SugarWidgetScheduler.update_time();
504                         }
505                 };
506         
507                 var data = {
508                         "users": user_id
509                 };
510                 var url = "index.php?module=Calendar&action=GetGRUsers&sugar_body_only=true";   
511                 YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
512
513         }
514                 
515         CAL.GR_update_focus = function (module,record){
516                 if(record == ""){
517                         GLOBAL_REGISTRY["focus"] = {"module":module, users_arr:[],fields:{"id":"-1"}};
518                         SugarWidgetScheduler.update_time();                     
519                 }else{          
520                         var callback = {
521                                 success: function(o){
522                                         res = eval(o.responseText);
523                                         SugarWidgetScheduler.update_time();                                                                                     
524                                         if(CAL.record_editable){
525                                                 CAL.get("btn-save").removeAttribute("disabled");
526                                                 CAL.get("btn-delete").removeAttribute("disabled");
527                                                 CAL.get("btn-apply").removeAttribute("disabled");
528                                                 CAL.get("btn-send-invites").removeAttribute("disabled");
529                                         }
530                                 }
531                         };      
532
533                         var url = 'index.php?module=Calendar&action=GetGR&sugar_body_only=true&type=' + module + '&record=' + record;   
534                         YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
535                 }               
536         }
537
538         CAL.toggle_settings = function (){
539                 var sd = CAL.get("settings_dialog");            
540                         
541                         
542                 if(!CAL.settingsDialog){        
543                         CAL.settingsDialog = new YAHOO.widget.Dialog("settings_dialog",{ 
544                                         fixedcenter: true,
545                                         draggable: false,
546                                         visible : false, 
547                                         modal : true,
548                                         close: true
549                         });
550                         var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() { CAL.settingsDialog.cancel();} } );
551                         CAL.settingsDialog.cfg.queueProperty("keylisteners", listeners);
552                 }
553                 CAL.settingsDialog.cancelEvent.subscribe(function(e, a, o){
554                         CAL.get("form_settings").reset();
555                 });
556                 sd.style.display = "block";      
557                 CAL.settingsDialog.render();
558                 CAL.settingsDialog.show();
559         }
560
561         CAL.toggle_whole_day = function (){
562                 var wd = CAL.get("whole_day");
563                 if(!wd.value)
564                         wd.value = "1";
565                 else
566                         wd.value = "";
567                 setTimeout(
568                         function(){
569                                 if(wd.value){
570                                         var nodes = CAL.query("#cal-grid .owt");
571                                         CAL.each(nodes,function(i,v){                                           
572                                                 nodes[i].style.display = "block";
573                                         });
574                                 }else{
575                                         var nodes = CAL.query("#cal-grid .owt");
576                                         CAL.each(nodes,function(i,v){
577                                                 nodes[i].style.display = "none";
578                                         });
579                                 }
580                         },
581                         25);
582         
583         }
584                 
585         CAL.fill_invitees = function (){        
586                 
587                 CAL.get("user_invitees").value = "";
588                 CAL.get("contact_invitees").value = "";
589                 CAL.get("lead_invitees").value = "";    
590
591                 CAL.each( GLOBAL_REGISTRY['focus'].users_arr,   function(i,v){
592                                                                         var field_name = "";
593                                                                         if(v.module == "User")
594                                                                                 field_name = "user_invitees";
595                                                                         if(v.module == "Contact")
596                                                                                 field_name = "contact_invitees";
597                                                                         if(v.module == "Lead")
598                                                                                 field_name = "lead_invitees";
599                                                                         var str = CAL.get(field_name).value;
600                                                                         CAL.get(field_name).value = str + v.fields.id + ",";    
601                                                                 }
602                 );      
603         }       
604                                 
605         
606         CAL.repeat_type_selected = function (){
607                 var rt;
608                 if(rt = CAL.get("repeat_type")){
609                         if(rt.value == 'Weekly'){
610                                 var nodes = CAL.query(".weeks_checks_div");
611                                 CAL.each(nodes,function (i,v){
612                                         nodes[i].style.display = "block";                               
613                                 });
614                         }else{
615                                 var nodes = CAL.query(".weeks_checks_div");
616                                 CAL.each(nodes,function (i,v){
617                                         nodes[i].style.display = "none";                                
618                                 });
619                         }
620                 
621                         if(rt.value == ''){
622                                 CAL.get("repeat_interval").setAttribute("disabled","disabled");
623                                 CAL.get("repeat_end_date").setAttribute("disabled","disabled");
624                         }else{
625                                 CAL.get("repeat_interval").removeAttribute("disabled");
626                                 CAL.get("repeat_end_date").removeAttribute("disabled"); 
627                         }
628                 }
629         }
630                 
631         CAL.load_from = function (module_name,record,run_one_time){
632         
633                 var e;
634                 var to_open = true;
635                 if(module_name == "Tasks")
636                         to_open = false;
637
638                 if(to_open && CAL.records_openable){
639                         CAL.get("form_content").style.display = "none";
640                 
641                         CAL.get("btn-delete").setAttribute("disabled","disabled");
642                         CAL.get("btn-apply").setAttribute("disabled","disabled");
643                         CAL.get("btn-save").setAttribute("disabled","disabled");
644                         CAL.get("btn-send-invites").setAttribute("disabled","disabled");                
645         
646                         CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
647                         
648                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
649                         
650                         CAL.open_edit_dialog(); 
651                         CAL.get("record").value = "";   
652                                                 
653         
654                         var callback = {
655                                                                                                                                         
656                                         success: function(o){
657                                                 res = eval("("+o.responseText+")");                     
658                                                 if(res.success == 'yes'){                                               
659                                                         var fc = document.getElementById("form_content");
660                                                         CAL.script_evaled = false;
661                                                         fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html; 
662                                                         if(!CAL.script_evaled){                                                                                 
663                                                                 SUGAR.util.evalScript(res.html);
664                                                         }
665                                                         
666                                                         CAL.get("record").value = res.record;
667                                                         CAL.get("current_module").value = res.module_name;      
668                                                         
669                                                         var mod_name = res.module_name; 
670                                                         
671                                                         if(mod_name == "Meetings")
672                                                                 CAL.get("radio_meeting").checked = true;
673                                                         if(mod_name == "Calls")
674                                                                 CAL.get("radio_call").checked = true;
675                                                                 
676                                                         if(res.edit == 1){
677                                                                 CAL.record_editable = true;
678                                                         }else{
679                                                                 CAL.record_editable = false;
680                                                         }
681                                                         
682                                                         CAL.get("radio_call").setAttribute("disabled","disabled");
683                                                         CAL.get("radio_meeting").setAttribute("disabled","disabled");                                                                                                           
684                 
685                                                         eval(res.gr);                                                   
686                                                         SugarWidgetScheduler.update_time();                                                                                     
687                                                         if(CAL.record_editable){
688                                                                 CAL.get("btn-save").removeAttribute("disabled");
689                                                                 CAL.get("btn-delete").removeAttribute("disabled");
690                                                                 CAL.get("btn-apply").removeAttribute("disabled");
691                                                                 CAL.get("btn-send-invites").removeAttribute("disabled");
692                                                         }                                                       
693                                                         
694                                                         CAL.get("form_content").style.display = "";
695                                                         CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
696                                                         ajaxStatus.hideStatus();
697                                                         
698                                                         if(typeof changeParentQS != 'undefined')                                                        
699                                                                 changeParentQS("parent_name");
700                                                                 
701                                                         setTimeout(function(){
702                                                                 enableQS(false);
703                                                                 disableOnUnloadEditView();
704                                                         },500);
705                                                         
706                                                 }else
707                                                         alert(CAL.lbl_error_loading);
708                                                                                                                                                         
709                                         },
710                                         failure: function(){
711                                                 alert(CAL.lbl_error_loading);
712                                         }
713                         };
714                         var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
715                         var data = {
716                                 "current_module" : module_name,
717                                 "record" : record
718                         };
719                         YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
720                         
721                 }
722                 CAL.records_openable = true;                                                            
723         }
724                 
725         
726         CAL.remove_shared = function (record_id){
727                         var e;
728                         var cell_id;
729                         if(e = CAL.get(record_id + '____' + "0"))
730                                 cell_id = e.parentNode.id;
731                                 
732                         if(typeof cell_id != "undefined"){
733                                 var cell_id_arr = cell_id.split("_");
734                                 cell_id = "t_" + cell_id_arr[1];
735                         }                                                                                       
736                         CAL.each(CAL.shared_users,function(i,v){        
737                                 if(e = CAL.get(record_id + '____' + v)) 
738                                         e.parentNode.removeChild(e);                                                                                                            
739                                 CAL.arrange_slot(cell_id + '_' + v);
740                                 
741                         });
742         }
743                         
744         CAL.add_item = function (item){ 
745                                                 
746                         if(CAL.view != 'shared'){
747                                 CAL.add_item_to_grid(item);
748                         }else{
749                                 CAL.remove_shared(item.record);
750                                 record_id = item.record;
751                                 //var rec_id = item.rec_id;
752                                 var timestamp = item.timestamp;
753                                 CAL.each(
754                                         item.users,
755                                         function (i,v){                                         
756                                                 var rec = item;
757                                                 //rec.rec_id = rec_id;
758                                                 rec.timestamp = timestamp;                                              
759                                                 rec.user_id = v;
760                                                 rec.record = record_id;
761                                                 CAL.add_item_to_grid(rec);
762                                                 
763                                                 CAL.each(
764                                                         rec.arr_rec,
765                                                         function (j,r){
766                                                                 rec.record = r.record;
767                                                                 rec.timestamp = r.timestamp;
768                                                                 //rec.rec_id = record_id;
769                                                                 CAL.add_item_to_grid(rec);
770                                                         }                               
771                                                 );                                                                                                                                                                                      
772                                         }                                                                                                                               
773                                 );
774                         }                       
775                         
776         }
777                 
778         CAL.move_activity = function (box_id,slot_id,ex_slot_id){
779                                 var u,s;                                                
780                                 if(u = CAL.get(box_id)){
781                                         if(s = CAL.get(slot_id)){
782                                                 s.appendChild(u);
783                                                 CAL.arrange_slot(slot_id);
784                                                 CAL.arrange_slot(ex_slot_id);
785                                                 CAL.cut_record(box_id);                                 
786                                                 var start_text = CAL.get_header_text(CAL.act_types[u.getAttribute('module_name')],s.getAttribute('time'),u.getAttribute('status'),u.getAttribute('record'));
787                                                 u.setAttribute("date_start",s.getAttribute("datetime"));                                
788                                                 u.childNodes[0].childNodes[1].innerHTML = start_text;
789                                         }
790                                 }
791         }       
792         
793         CAL.change_activity_type = function (mod_name){
794                 if(typeof CAL.current_params.module_name != "undefined" )
795                         if(CAL.current_params.module_name == mod_name)
796                                 return;
797         
798                 var e,user_name,user_id,date_start;
799                 
800                 CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;
801                                 
802                 document.forms["CalendarEditView"].elements["current_module"].value = mod_name;         
803         
804                 CAL.current_params.module_name = mod_name;
805                 CAL.load_create_form(CAL.current_params);                               
806         }
807
808
809         
810         CAL.load_create_form = function (params){
811         
812                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
813                         
814                         var callback = {
815                                                                                                                                         
816                                         success: function(o){
817                                                 res = eval("("+o.responseText+")");                     
818                                                 if(res.success == 'yes'){                                               
819                                                         var fc = document.getElementById("form_content");
820                                                         CAL.script_evaled = false;
821                                                         fc.innerHTML = '<script type="text/javascript">CAL.script_evaled = true;</script>'+res.html; 
822                                                         
823                                                         if(!CAL.script_evaled){                                                                                 
824                                                                 SUGAR.util.evalScript(res.html);
825                                                         }
826                                                                                                                 
827                                                         CAL.get("record").value = "";
828                                                         CAL.get("current_module").value = res.module_name;                                                              
829                                                         var mod_name = res.module_name; 
830                                                                                                         
831                                                         if(res.edit == 1){
832                                                                 CAL.record_editable = true;
833                                                         }else{
834                                                                 CAL.record_editable = false;
835                                                         }
836                                                                                                                 
837                                                         CAL.get("title-cal-edit").innerHTML = CAL.lbl_create_new;
838                                                                                                                                                                         
839                                                         SugarWidgetScheduler.update_time();
840                                                                 
841                                                         setTimeout(function(){
842                                                                 enableQS(false);
843                                                                 disableOnUnloadEditView();
844                                                         },500);
845                                                         
846                                                         ajaxStatus.hideStatus();
847                                                         
848                                                 }else{
849                                                         alert(CAL.lbl_error_loading);
850                                                         ajaxStatus.hideStatus();
851                                                 }
852                                         },
853                                         failure: function() {
854                                                 alert(CAL.lbl_error_loading);
855                                                 ajaxStatus.hideStatus();
856                                         }       
857                         };                      
858                                                         
859                         var url = "index.php?module=Calendar&action=QuickEdit&sugar_body_only=true";
860                         var data = {
861                                 "current_module" : params.module_name,
862                                 "assigned_user_id" : params.user_id,
863                                 "assigned_user_name" : params.user_name,
864                                 "date_start" : params.date_start,
865                                 "duration_hours" : 1,
866                                 "duration_minutes" : 0
867                         };
868                         YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));   
869         }
870                 
871         
872         CAL.dialog_create = function (cell){
873         
874                         var e,user_id,user_name;
875                         CAL.get("title-cal-edit").innerHTML = CAL.lbl_loading;                                                                                                          
876                         CAL.open_edit_dialog();
877                         CAL.get("btn-delete").setAttribute("disabled","disabled");
878                         
879                         var module_name = CAL.get("current_module").value;
880                         
881                         if(CAL.view == 'shared'){
882                                 user_name = cell.parentNode.parentNode.parentNode.getAttribute("user_name");
883                                 user_id = cell.parentNode.parentNode.parentNode.getAttribute("user_id");
884                                 CAL.GR_update_user(user_id);
885                         }else{
886                                 user_id = CAL.current_user_id;
887                                 user_name = CAL.current_user_name;
888                                 CAL.GR_update_user(CAL.current_user_id);                                                                                                
889                         }                                               
890                         
891                         var params = {  
892                                 'module_name': module_name,
893                                 'user_id': user_id,     
894                                 'user_name': user_name,                 
895                                 'date_start': cell.getAttribute("datetime")                             
896                         };
897                         CAL.current_params = params;
898                         CAL.load_create_form(CAL.current_params);
899                                                         
900         }
901         
902         CAL.dialog_save = function(){                                           
903                                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
904                                                 
905                                                 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;                                                                                                                                                                   
906                                                 CAL.fill_invitees();                                                    
907                                                 //CAL.fill_recurrence();
908                                                                                                 
909                                                 var callback = {
910                                                                 success: function(o){
911                                                                         res = eval('('+o.responseText+')');     
912                                                                         if(res.success == 'yes'){
913                                                                                 CAL.add_item(res);
914                                                                                 CAL.editDialog.cancel();
915                                                                                 CAL.update_vcal();
916                                                                                 ajaxStatus.hideStatus();                                                                                                
917                                                                         }else{
918                                                                                 alert(CAL.lbl_error_saving);
919                                                                                 ajaxStatus.hideStatus();
920                                                                         }                                                                                                               
921                                                                 },
922                                                                 failure: function(){
923                                                                                 alert(CAL.lbl_error_saving);
924                                                                                 ajaxStatus.hideStatus();
925                                                                 }
926                                                 };                                              
927                                                 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true"; 
928                                                 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
929                                                 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);     
930         }
931         
932         CAL.dialog_apply = function(){
933                                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
934                                                 
935                                                 CAL.get("title-cal-edit").innerHTML = CAL.lbl_saving;                                                           
936                                                 CAL.fill_invitees();                                                    
937                                                 //CAL.fill_recurrence();        
938                                                 
939                                                 var e;
940                                                 if(e = CAL.get("radio_call"))
941                                                         e.setAttribute("disabled","disabled");
942                                                 if(e = CAL.get("radio_meeting"))
943                                                         e.setAttribute("disabled","disabled");                                                                                                  
944
945                                                 CAL.get("btn-apply").setAttribute("disabled","disabled");
946                                                 
947                                                 var callback = {
948                                                                 success: function(o){
949                                                                         res = eval('('+o.responseText+')');     
950                                                                         if(res.success == 'yes'){                                                                               
951                                                                                 var e;
952                                                                                 CAL.get("record").value = res.record;   
953                                                                                 //SugarWidgetScheduler.update_time();
954                                                                                 //CAL.GR_update_focus(CAL.get("current_module").value,res.record);
955                                                                                 CAL.add_item(res);
956                                                                                 CAL.update_vcal();                                                                                                                                                                                                              
957                                                                                 CAL.get("title-cal-edit").innerHTML = CAL.lbl_edit;
958                                                                                 if(e = CAL.get("send_invites"))
959                                                                                         e.removeAttribute("checked");
960                                                                                 ajaxStatus.hideStatus();                                                                                        
961                                                                         }else{
962                                                                                 alert(CAL.lbl_error_saving);
963                                                                                 ajaxStatus.hideStatus();
964                                                                         }                                                                                                               
965                                                                 },
966                                                                 failure: function(){
967                                                                                 alert(CAL.lbl_error_saving);
968                                                                                 ajaxStatus.hideStatus();
969                                                                 }
970                                                 };                                              
971                                                 var url = "index.php?module=Calendar&action=SaveActivity&sugar_body_only=true"; 
972                                                 YAHOO.util.Connect.setForm(CAL.get("CalendarEditView"));
973                                                 YAHOO.util.Connect.asyncRequest('POST',url,callback,false);
974         }
975         
976         CAL.dialog_remove = function(){
977                                                                         CAL.deleted_id = CAL.get("record").value;
978                                                                         CAL.deleted_module = CAL.get("current_module").value;                                                                   
979                                                                         var delete_recurring = false;                                                           
980                                                                                         
981                                                                         var callback = {
982                                                                                         success: function(o){
983                                                                                                 res = eval('('+o.responseText+')');
984                                                                                                         
985                                                                                                 var e,cell_id;
986                                                                                                 if(e = CAL.get(CAL.deleted_id))
987                                                                                                         cell_id = e.parentNode.id;
988                                                                                                 if(CAL.view == 'shared')        
989                                                                                                         CAL.remove_shared(CAL.deleted_id);      
990                                                                                                         
991                                                                                                 if(e = CAL.get(CAL.deleted_id))
992                                                                                                         e.parentNode.removeChild(e);                                                                    
993                                                                                                 
994                                                                                                 CAL.arrange_slot(cell_id);                                                                                              
995                                                         
996                                                                                                                                                                                                                 
997                                                                                         },
998                                                                                         failure: function(){
999                                                                                                         alert(CAL.lbl_error_saving);
1000                                                                                         }
1001                                                                         };                                                                      
1002                                                                         
1003                                                                         var data = {
1004                                                                                 "current_module" : CAL.deleted_module,
1005                                                                                 "record" : CAL.deleted_id,
1006                                                                                 "delete_recurring": delete_recurring
1007                                                                         };
1008                                                                         var url = "index.php?module=Calendar&action=Remove&sugar_body_only=true";                                                                       
1009                                                                         YAHOO.util.Connect.asyncRequest('POST',url,callback,CAL.toURI(data));
1010
1011                                                                         CAL.editDialog.cancel();        
1012         }
1013         
1014         CAL.show_additional_details = function (id){
1015                 var obj = CAL.get(id);
1016         
1017                 var record = obj.getAttribute("record");
1018                 mod = obj.getAttribute("module_name");
1019                 var atype = CAL.act_types[mod];
1020         
1021                 var subj = obj.getAttribute("subj");
1022                 var date_start = obj.getAttribute("date_start");
1023                 var duration = obj.getAttribute("dur"); 
1024                 var desc = obj.getAttribute("desc");    
1025                 var detail = parseInt(obj.getAttribute("detail"));
1026                 var edit = parseInt(obj.getAttribute("edit"));                          
1027                 
1028                 var related = "";
1029                 if(obj.getAttribute("parent_id") != '')
1030                         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>";
1031
1032                 if(desc != '')
1033                         desc = '<b>'+ CAL.lbl_desc + ':</b><br> ' + desc +'<br>';                       
1034                 if(subj == '')
1035                         return "";
1036
1037                 var date_lbl = CAL.lbl_start;           
1038                 if(duration != ""){
1039                         var duration_text = '<b>'+CAL.lbl_duration+':</b> ' + duration + '<br>';
1040                         if(mod == "Tasks"){
1041                                 date_lbl = CAL.lbl_due;
1042                                 duration_text = "";                     
1043                         }
1044                 }else
1045                         duration_text = "";
1046
1047                 var caption = "<div style='float: left;'>"+CAL.lbl_title+"</div><div style='float: right;'>";
1048                 if(edit){
1049                         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>";
1050                 }
1051                 if(detail){
1052                         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>";
1053                 }
1054                 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>";
1055
1056                 
1057                 var body = '<b>'+CAL.lbl_name+':</b> ' + subj + ' <br><b>'+date_lbl+':</b> ' + date_start + '<br>' + duration_text + related + desc;
1058                 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');
1059         }               
1060         
1061         CAL.toggle_shared_edit = function (id){
1062                 if(document.getElementById(id).style.display == 'none'){
1063                         document.getElementById(id).style.display = 'inline'
1064                         if(document.getElementById(id+"link") != undefined){
1065                                 document.getElementById(id+"link").style.display='none';
1066                         }
1067                 }else{
1068                         document.getElementById(id).style.display = 'none'
1069                         if(document.getElementById(id+"link") != undefined){
1070                                 document.getElementById(id+"link").style.display = 'inline';
1071                         }
1072                 }
1073         }
1074
1075         CAL.goto_date_call = function (){
1076                 var date_string = CAL.get("goto_date").value;
1077                 var date_arr = [];
1078                 date_arr = date_string.split("/");
1079                 
1080                 window.location.href = "index.php?module=Calendar&view="+CAL.view+"&day="+date_arr[1]+"&month="+date_arr[0]+"&year="+date_arr[2];       
1081         }
1082         
1083         CAL.toURI = function (a){
1084                         t=[];
1085                         for(x in a){                    
1086                                 if(!(a[x].constructor.toString().indexOf('Array') == -1)){
1087                                         for(i in a[x])
1088                                                 t.push(x+"[]="+encodeURIComponent(a[x][i]));
1089                                 }else                   
1090                                         t.push(x+"="+encodeURIComponent(a[x]));
1091                         }
1092                         return t.join("&");
1093         }       
1094         
1095         CAL.each = function (object, callback) {
1096                 
1097                 if(typeof object == "undefined")
1098                         return;
1099                 var name, i = 0,
1100                 length = object.length,
1101                 isObj = (length === undefined) || (typeof (object) === "function");
1102                 if(isObj){
1103                             for (name in object) {
1104                                 if (callback.call(object[name], name, object[name]) === false) {
1105                                     break;
1106                                 }
1107                             }
1108                 }else{
1109                             for (; i < length;) {
1110                                 if (callback.call(object[i], i, object[i++]) === false) {
1111                                     break;
1112                                 }
1113                             }
1114                 }
1115                 return object;
1116         }
1117         
1118         CAL.update_vcal = function(){
1119                                                                                                 
1120                                         var v = CAL.current_user_id;                                                                                            
1121                                         var callback = {
1122                                                 success: function(result){ 
1123                                                         if (typeof GLOBAL_REGISTRY.freebusy == 'undefined') {
1124                                                                 GLOBAL_REGISTRY.freebusy = new Object();
1125                                                         }
1126                                                         if (typeof GLOBAL_REGISTRY.freebusy_adjusted == 'undefined') {
1127                                                                         GLOBAL_REGISTRY.freebusy_adjusted = new Object();
1128                                                         }
1129                                                         // parse vCal and put it in the registry using the user_id as a key:
1130                                                         GLOBAL_REGISTRY.freebusy[v] = SugarVCalClient.parseResults(result.responseText, false);                  
1131                                                         // parse for current user adjusted vCal
1132                                                         GLOBAL_REGISTRY.freebusy_adjusted[v] = SugarVCalClient.parseResults(result.responseText, true);
1133                                                         SugarWidgetScheduler.update_time();
1134                                                 }                                                                                               
1135                                         };
1136                                                         
1137                                         var url = "vcal_server.php?type=vfb&source=outlook&user_id="+v;                                                                 
1138                                         YAHOO.util.Connect.asyncRequest('GET',url,callback,false);
1139         }
1140         
1141         CAL.fit_grid = function(){
1142                 var day_width;
1143                 var cal_width = document.getElementById("cal-grid").parentNode.parentNode.offsetWidth;
1144                 var left_width = 80;
1145                 
1146                 
1147                 if(CAL.view == "day")
1148                         day_width = parseInt((cal_width - left_width));
1149                 else                                                    
1150                         day_width = parseInt((cal_width - left_width) / 7 );
1151                         
1152                 var nodes = CAL.query("#cal-grid div.day_col");
1153                 CAL.each(nodes, function(i,v){          
1154                         nodes[i].style.width = day_width + "px";
1155                 });
1156                 
1157                 document.getElementById("cal-grid").style.visibility = "";
1158         }
1159         
1160         
1161         YAHOO.util.DDCAL = function(id, sGroup, config){ 
1162                 this.cont = config.cont; 
1163                 YAHOO.util.DDCAL.superclass.constructor.apply(this, arguments);
1164         }
1165         YAHOO.extend(YAHOO.util.DDCAL, YAHOO.util.DD, { 
1166                 cont: null,                             
1167                 init: function(){
1168                         YAHOO.util.DDCAL.superclass.init.apply(this, arguments);
1169                         this.initConstraints();
1170                         YAHOO.util.Event.on(window, 'resize', function() {
1171                                 this.initConstraints();
1172                         }, this, true); 
1173                 },
1174                 initConstraints: function() { 
1175                         var region = YAHOO.util.Dom.getRegion(this.cont);
1176                         var el = this.getEl();
1177                         var xy = YAHOO.util.Dom.getXY(el);
1178                         var width = parseInt(YAHOO.util.Dom.getStyle(el, 'width'), 10);
1179                         var height = parseInt(YAHOO.util.Dom.getStyle(el, 'height'), 10); 
1180                         var left = xy[0] - region.left;
1181                         var right = region.right - xy[0] - width;
1182                         var top = xy[1] - region.top;
1183                         var bottom = region.bottom - xy[1] - height;
1184                         this.setXConstraint(left, right);
1185                         this.setYConstraint(top, bottom);
1186                 }
1187         });
1188         
1189         CAL.remove_edit_dialog();
1190         
1191         var cal_loaded = true;