/*

@license
dhtmlxScheduler.Net v.4.0.3 Professional Evaluation

This software is covered by DHTMLX Evaluation License. Contact sales@dhtmlx.com to get Commercial or Enterprise license. Usage without proper license is prohibited.

(c) XB Software Ltd.

*/
Scheduler.plugin(function(e){e.attachEvent("onTemplatesReady",function(){this.layers.sort(function(e,t){return e.zIndex-t.zIndex}),e._dp_init=function(t){t._methods=["_set_event_text_style","","changeEventId","deleteEvent"],this.attachEvent("onEventAdded",function(e){!this._loading&&this.validId(e)&&this.getEvent(e)&&this.getEvent(e).layer==t.layer&&t.setUpdated(e,!0,"inserted")}),this.attachEvent("onBeforeEventDelete",function(e){if(this.getEvent(e)&&this.getEvent(e).layer==t.layer){
if(!this.validId(e))return;var a=t.getState(e);return"inserted"==a||this._new_event?(t.setUpdated(e,!1),!0):"deleted"!=a&&("true_deleted"==a||(t.setUpdated(e,!0,"deleted"),!1))}return!0}),this.attachEvent("onEventChanged",function(e){!this._loading&&this.validId(e)&&this.getEvent(e)&&this.getEvent(e).layer==t.layer&&t.setUpdated(e,!0,"updated")}),t._getRowData=function(e,t){var a=this.obj.getEvent(e),n={}
;for(var i in a)0!==i.indexOf("_")&&(a[i]&&a[i].getUTCFullYear?n[i]=this.obj._helpers.formatDate(a[i]):n[i]=a[i]);return n},t._clearUpdateFlag=function(){},t.attachEvent("insertCallback",e._update_callback),t.attachEvent("updateCallback",e._update_callback),t.attachEvent("deleteCallback",function(e,t){this.obj.setUserData(t,this.action_param,"true_deleted"),this.obj.deleteEvent(t)})},function(){var t=function(e){if(null===e||"object"!=typeof e)return e;var a=new e.constructor
;for(var n in e)a[n]=t(e[n]);return a};e._dataprocessors=[],e._layers_zindex={};for(var a=0;a<e.layers.length;a++){if(e.config["lightbox_"+e.layers[a].name]={},e.config["lightbox_"+e.layers[a].name].sections=t(e.config.lightbox.sections),e._layers_zindex[e.layers[a].name]=e.config.inital_layer_zindex||5+3*a,e.layers[a].url){var n=new dataProcessor(e.layers[a].url);n.layer=e.layers[a].name,e._dataprocessors.push(n),e._dataprocessors[a].init(e)}
e.layers[a].isDefault&&(e.defaultLayer=e.layers[a].name)}}(),e.showLayer=function(e){this.toggleLayer(e,!0)},e.hideLayer=function(e){this.toggleLayer(e,!1)},e.toggleLayer=function(e,t){var a=this.getLayer(e);a.visible=void 0!==t?!!t:!a.visible,this.setCurrentView(this._date,this._mode)},e.getLayer=function(t){var a,n;"string"==typeof t&&(n=t),"object"==typeof t&&(n=t.layer);for(var i=0;i<e.layers.length;i++)e.layers[i].name==n&&(a=e.layers[i]);return a},
e.attachEvent("onBeforeLightbox",function(t){var a=this.getEvent(t);return this.config.lightbox.sections=this.config["lightbox_"+a.layer].sections,e.resetLightbox(),!0}),e.attachEvent("onClick",function(t,a){var n=e.getEvent(t);return!e.getLayer(n.layer).noMenu}),e.attachEvent("onEventCollision",function(t,a){var n=this.getLayer(t);if(!n.checkCollision)return!1;for(var i=0,r=0;r<a.length;r++)a[r].layer==n.name&&a[r].id!=t.id&&i++;return i>=e.config.collision_limit}),
e.addEvent=function(t,a,n,i,r){var o=t;1!=arguments.length&&(o=r||{},o.start_date=t,o.end_date=a,o.text=n,o.id=i,o.layer=this.defaultLayer),o.id=o.id||e.uid(),o.text=o.text||"","string"==typeof o.start_date&&(o.start_date=this.templates.api_date(o.start_date)),"string"==typeof o.end_date&&(o.end_date=this.templates.api_date(o.end_date)),o._timed=this.isOneDayEvent(o);var d=!this._events[o.id];this._events[o.id]=o,this.event_updated(o),
this._loading||this.callEvent(d?"onEventAdded":"onEventChanged",[o.id,o])},this._evs_layer={};for(var t=0;t<this.layers.length;t++)this._evs_layer[this.layers[t].name]=[];e.addEventNow=function(t,a,n){var i={};"object"==typeof t&&(i=t,t=null);var r=6e4*(this.config.event_duration||this.config.time_step);t||(t=Math.round(e._currentDate().valueOf()/r)*r);var o=new Date(t);if(!a){var d=this.config.first_hour;d>o.getHours()&&(o.setHours(d),t=o.valueOf()),a=t+r}i.start_date=i.start_date||o,
i.end_date=i.end_date||new Date(a),i.text=i.text||this.locale.labels.new_event,i.id=this._drag_id=this.uid(),i.layer=this.defaultLayer,this._drag_mode="new-size",this._loading=!0,this.addEvent(i),this.callEvent("onEventCreated",[this._drag_id,n]),this._loading=!1,this._drag_event={},this._on_mouse_up(n)},e._t_render_view_data=function(e){if(this.config.multi_day&&!this._table_view){for(var t=[],a=[],n=0;n<e.length;n++)e[n]._timed?t.push(e[n]):a.push(e[n]);this._table_view=!0,this.render_data(a),
this._table_view=!1,this.render_data(t)}else this.render_data(e)},e.render_view_data=function(){if(this._not_render)return void(this._render_wait=!0);this._render_wait=!1,this.clear_view(),this._evs_layer={};for(var e=0;e<this.layers.length;e++)this._evs_layer[this.layers[e].name]=[];for(var t=this.get_visible_events(),e=0;e<t.length;e++)this._evs_layer[t[e].layer]&&this._evs_layer[t[e].layer].push(t[e]);if("month"==this._mode){
for(var a=[],e=0;e<this.layers.length;e++)this.layers[e].visible&&(a=a.concat(this._evs_layer[this.layers[e].name]));this._t_render_view_data(a)}else for(var e=0;e<this.layers.length;e++)if(this.layers[e].visible){var n=this._evs_layer[this.layers[e].name];this._t_render_view_data(n)}},e._render_v_bar=function(t,a,n,i,r,o,d,l,s){var _=t.id;-1==d.indexOf("<div class=")&&(d=e.templates["event_header_"+t.layer]?e.templates["event_header_"+t.layer](t.start_date,t.end_date,t):d),
-1==l.indexOf("<div class=")&&(l=e.templates["event_text_"+t.layer]?e.templates["event_text_"+t.layer](t.start_date,t.end_date,t):l);var c=document.createElement("div"),u="dhx_cal_event",h=e.templates["event_class_"+t.layer]?e.templates["event_class_"+t.layer](t.start_date,t.end_date,t):e.templates.event_class(t.start_date,t.end_date,t);h&&(u=u+" "+h)
;var p=e._border_box_events(),v=i-2,g=p?v:i-4,m=p?v:i-6,f=p?v:i-(this._quirks?4:14),b=p?v-2:i-8,y=p?r-this.xy.event_header_height:r-(this._quirks?20:30)+1,x='<div event_id="'+_+'" class="'+u+'" style="position:absolute; top:'+n+"px; left:"+a+"px; width:"+g+"px; height:"+r+"px;"+(o||"")+'">';return x+='<div class="dhx_header" style=" width:'+m+'px;" >&nbsp;</div>',x+='<div class="dhx_title">'+d+"</div>",x+='<div class="dhx_body" style=" width:'+f+"px; height:"+y+'px;">'+l+"</div>",
x+='<div class="dhx_footer" style=" width:'+b+"px;"+(s?" margin-top:-1px;":"")+'" ></div></div>',c.innerHTML=x,c.style.zIndex=100,c.firstChild},e.render_event_bar=function(t){var a=this._els.dhx_cal_data[0],n=this._colsS[t._sday],i=this._colsS[t._eday];i==n&&(i=this._colsS[t._eday+1])
;var r=this.xy.bar_height,o=this._colsS.heights[t._sweek]+(this._colsS.height?this.xy.month_scale_height+2:2)+t._sorder*r,d=document.createElement("div"),l=t._timed?"dhx_cal_event_clear":"dhx_cal_event_line",s=e.templates["event_class_"+t.layer]?e.templates["event_class_"+t.layer](t.start_date,t.end_date,t):e.templates.event_class(t.start_date,t.end_date,t);s&&(l=l+" "+s)
;var _='<div event_id="'+t.id+'" class="'+l+'" style="position:absolute; top:'+o+"px; left:"+n+"px; width:"+(i-n-15)+"px;"+(t._text_style||"")+'">';t._timed&&(_+=e.templates["event_bar_date_"+t.layer]?e.templates["event_bar_date_"+t.layer](t.start_date,t.end_date,t):e.templates.event_bar_date(t.start_date,t.end_date,t)),_+=e.templates["event_bar_text_"+t.layer]?e.templates["event_bar_text_"+t.layer](t.start_date,t.end_date,t):e.templates.event_bar_text(t.start_date,t.end_date,t)+"</div>)",
_+="</div>",d.innerHTML=_,this._rendered.push(d.firstChild),a.appendChild(d.firstChild)},e.render_event=function(t){var a=e.xy.menu_width;if(e.getLayer(t.layer).noMenu&&(a=0),!(t._sday<0)){var n=e.locate_holder(t._sday);if(n){
var i=60*t.start_date.getHours()+t.start_date.getMinutes(),r=60*t.end_date.getHours()+t.end_date.getMinutes()||60*e.config.last_hour,o=Math.round((60*i*1e3-60*this.config.first_hour*60*1e3)*this.config.hour_size_px/36e5)%(24*this.config.hour_size_px)+1,d=Math.max(e.xy.min_event_height,(r-i)*this.config.hour_size_px/60)+1,l=Math.floor((n.clientWidth-a)/t._count),s=t._sorder*l+1;t._inner||(l*=t._count-t._sorder)
;var _=this._render_v_bar(t.id,a+s,o,l,d,t._text_style,e.templates.event_header(t.start_date,t.end_date,t),e.templates.event_text(t.start_date,t.end_date,t));if(this._rendered.push(_),n.appendChild(_),s=s+parseInt(n.style.left,10)+a,o+=this._dy_shift,_.style.zIndex=this._layers_zindex[t.layer],this._edit_id==t.id){_.style.zIndex=parseInt(_.style.zIndex)+1;var c=_.style.zIndex;l=Math.max(l-4,e.xy.editor_width);var _=document.createElement("div");_.setAttribute("event_id",t.id),
this.set_xy(_,l,d-20,s,o+14),_.className="dhx_cal_editor",_.style.zIndex=c;var u=document.createElement("div");this.set_xy(u,l-6,d-26),u.style.cssText+=";margin:2px 2px 2px 2px;overflow:hidden;",u.style.zIndex=c,_.appendChild(u),this._els.dhx_cal_data[0].appendChild(_),this._rendered.push(_),u.innerHTML="<textarea class='dhx_cal_editor'>"+t.text+"</textarea>",this._quirks7&&(u.firstChild.style.height=d-12+"px"),this._editor=u.firstChild,this._editor.onkeypress=function(t){
if((t||event).shiftKey)return!0;var a=(t||event).keyCode;a==e.keys.edit_save&&e.editStop(!0),a==e.keys.edit_cancel&&e.editStop(!1)},this._editor.onselectstart=function(e){return(e||event).cancelBubble=!0,!0},u.firstChild.focus(),this._els.dhx_cal_data[0].scrollLeft=0,u.firstChild.select()}if(this._select_id==t.id){_.style.zIndex=parseInt(_.style.zIndex)+1
;for(var h=this.config["icons_"+(this._edit_id==t.id?"edit":"select")],p="",v=0;v<h.length;v++)p+="<div class='dhx_menu_icon "+h[v]+"' title='"+this.locale.labels[h[v]]+"'></div>";var g=this._render_v_bar(t.id,s-a+1,o,a,20*h.length+26,"","<div class='dhx_menu_head'></div>",p,!0);g.style.left=s-a+1,g.style.zIndex=_.style.zIndex,this._els.dhx_cal_data[0].appendChild(g),this._rendered.push(g)}}}},e.filter_agenda=function(t,a){var n=e.getLayer(a.layer);return n&&n.visible}})});