/*
@license
dhtmlxScheduler v.4.4.9 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) Dinamenta, UAB.
*/
Scheduler.plugin(function(e){e._props={},e.createUnitsView=function(t,a,i,n,r,s,o){"object"==typeof t&&(i=t.list,a=t.property,n=t.size||0,r=t.step||1,s=t.skip_incorrect,o=t.days||1,t=t.name),e._props[t]={map_to:a,options:i,step:r,position:0,days:o},n>e._props[t].options.length&&(e._props[t]._original_size=n,n=0),e._props[t].size=n,e._props[t].skip_incorrect=s||!1,e.date[t+"_start"]=e.date.day_start,e.templates[t+"_date"]=function(a,i){var n=e._props[t];return n.days>1?e.templates.week_date(a,i):e.templates.day_date(a);
},e._get_unit_index=function(t,a){var i=t.position||0,n=Math.round((e._correct_shift(+a,1)-+e._min_date)/864e5),r=t.options.length;return n>=r&&(n%=r),i+n},e.templates[t+"_scale_text"]=function(e,t,a){return a.css?"<span class='"+a.css+"'>"+t+"</span>":t},e.templates[t+"_scale_date"]=function(a){var i=e._props[t],n=i.options;if(!n.length)return"";var r=e._get_unit_index(i,a),s=n[r];return e.templates[t+"_scale_text"](s.key,s.label,s)},e.templates[t+"_second_scale_date"]=function(t){return e.templates.week_scale_date(t);
},e.date["add_"+t]=function(a,i){return e.date.add(a,i*e._props[t].days,"day")},e.date["get_"+t+"_end"]=function(a){return e.date.add(a,(e._props[t].size||e._props[t].options.length)*e._props[t].days,"day")},e.attachEvent("onOptionsLoad",function(){for(var a=e._props[t],i=a.order={},n=a.options,r=0;r<n.length;r++)i[n[r].key]=r;a._original_size&&0===a.size&&(a.size=a._original_size,delete a.original_size),a.size>n.length?(a._original_size=a.size,a.size=0):a.size=a._original_size||a.size,e._date&&e._mode==t&&e.setCurrentView(e._date,e._mode);
}),e["mouse_"+t]=function(t){var a=e._props[this._mode];if(a){if(t=this._week_indexes_from_pos(t),this._drag_event||(this._drag_event={}),this._drag_id&&this._drag_mode&&(this._drag_event._dhx_changed=!0),this._drag_mode&&"new-size"==this._drag_mode){var i=e._get_event_sday(e._events[e._drag_id]);Math.floor(t.x/a.options.length)!=Math.floor(i/a.options.length)&&(t.x=i)}var n=t.x%a.options.length,r=Math.min(n+a.position,a.options.length-1);t.section=(a.options[r]||{}).key,t.x=Math.floor(t.x/a.options.length);
var s=this.getEvent(this._drag_id);this._update_unit_section({view:a,event:s,pos:t})}return t.force_redraw=!0,t},e.callEvent("onOptionsLoad",[])},e._update_unit_section=function(e){var t=e.view,a=e.event,i=e.pos;a&&(a[t.map_to]=i.section)},e.scrollUnit=function(t){var a=e._props[this._mode];a&&(a.position=Math.min(Math.max(0,a.position+t),a.options.length-a.size),this.setCurrentView())},function(){var t=function(t){var a=e._props[e._mode];if(a&&a.order&&a.skip_incorrect){for(var i=[],n=0;n<t.length;n++)"undefined"!=typeof a.order[t[n][a.map_to]]&&i.push(t[n]);
t.splice(0,t.length),t.push.apply(t,i)}return t},a=e._pre_render_events_table;e._pre_render_events_table=function(e,i){return e=t(e),a.apply(this,[e,i])};var i=e._pre_render_events_line;e._pre_render_events_line=function(e,a){return e=t(e),i.apply(this,[e,a])};var n=function(t,a){if(t&&"undefined"==typeof t.order[a[t.map_to]]){var i=e,n=864e5,r=Math.floor((a.end_date-i._min_date)/n);return t.options.length&&(a[t.map_to]=t.options[Math.min(r+t.position,t.options.length-1)].key),!0}},r=e.is_visible_events;
e.is_visible_events=function(t){var a=r.apply(this,arguments);if(a){var i=e._props[this._mode];if(i&&i.size){var n=i.order[t[i.map_to]];if(n<i.position||n>=i.size+i.position)return!1}}return a};var s=e._process_ignores;e._process_ignores=function(t,a,i,n,r){if(!e._props[this._mode])return void s.call(this,t,a,i,n,r);this._ignores={},this._ignores_detected=0;var o=e["ignore_"+this._mode];if(o){var d=e._props&&e._props[this._mode]?e._props[this._mode].size||e._props[this._mode].options.length:1;a/=d;
for(var _=new Date(t),l=0;a>l;l++){if(o(_))for(var c=l*d,h=(l+1)*d,u=c;h>u;u++)this._ignores_detected+=1,this._ignores[u]=!0,r&&a++;_=e.date.add(_,n,i),e.date[i+"_start"]&&(_=e.date[i+"_start"](_))}}};var o=e._reset_scale;e._reset_scale=function(){var t=e._props[this._mode],a=o.apply(this,arguments);if(t){this._max_date=this.date.add(this._min_date,t.days,"day");for(var i=this._els.dhx_cal_data[0].childNodes,n=0;n<i.length;n++)i[n].className=i[n].className.replace("_now","");var r=this._currentDate();
if(r.valueOf()>=this._min_date&&r.valueOf()<this._max_date){var s=864e5,d=Math.floor((r-e._min_date)/s),_=t.options.length,l=d*_,c=l+_;for(n=l;c>n;n++)i[n]&&(i[n].className=i[n].className.replace("dhx_scale_holder","dhx_scale_holder_now"))}if(t.size&&t.size<t.options.length){var h=this._els.dhx_cal_header[0],u=document.createElement("DIV");t.position&&(this._waiAria.headerButtonsAttributes(u,""),u.className="dhx_cal_prev_button",u.style.cssText="left:1px;top:2px;position:absolute;",u.innerHTML="&nbsp;",
h.firstChild.appendChild(u),u.onclick=function(){e.scrollUnit(-1*t.step)}),t.position+t.size<t.options.length&&(this._waiAria.headerButtonsAttributes(u,""),u=document.createElement("DIV"),u.className="dhx_cal_next_button",u.style.cssText="left:auto; right:0px;top:2px;position:absolute;",u.innerHTML="&nbsp;",h.lastChild.appendChild(u),u.onclick=function(){e.scrollUnit(t.step)})}}return a};var d=e._reset_scale;e._reset_scale=function(){var t=e._props[this._mode],a=e.xy.scale_height;t&&t.days>1?this._header_resized||(this._header_resized=e.xy.scale_height,
e.xy.scale_height=2*a):this._header_resized&&(e.xy.scale_height/=2,this._header_resized=!1),d.apply(this,arguments)};var _=e._get_view_end;e._get_view_end=function(){var t=e._props[this._mode];if(t&&t.days>1){var a=this._get_timeunit_start();return e.date.add(a,t.days,"day")}return _.apply(this,arguments)};var l=e._render_x_header;e._render_x_header=function(t,a,i,n){var r=e._props[this._mode];if(!r||r.days<=1)return l.apply(this,arguments);if(r.days>1){var s=e.xy.scale_height;e.xy.scale_height=Math.ceil(s/2),
l.call(this,t,a,i,n,Math.ceil(e.xy.scale_height));var o=r.options.length;if((t+1)%o===0){var d=document.createElement("DIV");d.className="dhx_scale_bar dhx_second_scale_bar";var _=this.date.add(this._min_date,Math.floor(t/o),"day");this.templates[this._mode+"_second_scalex_class"]&&(d.className+=" "+this.templates[this._mode+"_second_scalex_class"](new Date(_)));var c,h=this._cols[t]*o-1;c=o>1?this._colsS[t-(o-1)]-this.xy.scale_width-2:a,this.set_xy(d,h,this.xy.scale_height-2,c,0),d.innerHTML=this.templates[this._mode+"_second_scale_date"](new Date(_),this._mode),
n.appendChild(d)}e.xy.scale_height=s}};var c=e._get_event_sday;e._get_event_sday=function(t){var a=e._props[this._mode];if(a){if(a.days<=1)return n(a,t),this._get_section_sday(t[a.map_to]);var i=864e5,r=Math.floor((t.end_date.valueOf()-1-60*t.end_date.getTimezoneOffset()*1e3-(e._min_date.valueOf()-60*e._min_date.getTimezoneOffset()*1e3))/i),s=a.options.length,o=a.order[t[a.map_to]];return r*s+o-a.position}return c.call(this,t)},e._get_section_sday=function(t){var a=e._props[this._mode];return a.order[t]-a.position;
};var h=e.locate_holder_day;e.locate_holder_day=function(t,a,i){var r=e._props[this._mode];if(!r)return h.apply(this,arguments);var s;if(i?n(r,i):(i={start_date:t,end_date:t},s=0),r.days<=1)return 1*(void 0===s?r.order[i[r.map_to]]:s)+(a?1:0)-r.position;var o=864e5,d=Math.floor((i.start_date.valueOf()-e._min_date.valueOf())/o),_=r.options.length,l=void 0===s?r.order[i[r.map_to]]:s;return d*_+1*l+(a?1:0)-r.position};var u=e._time_order;e._time_order=function(t){var a=e._props[this._mode];a?t.sort(function(e,t){
return a.order[e[a.map_to]]>a.order[t[a.map_to]]?1:-1}):u.apply(this,arguments)};var v=e._pre_render_events_table;e._pre_render_events_table=function(t,a){function i(t){var a=e.date.add(t,1,"day");return a=e.date.date_part(a)}var n=e._props[this._mode];if(n&&n.days>1&&!this.config.all_timed){for(var r={},s=0;s<t.length;s++){var o=t[s];if(this.isOneDayEvent(t[s])){var d=+e.date.date_part(new Date(o.start_date));r[d]||(r[d]=[]),r[d].push(o)}else{var _=new Date(Math.min(+o.end_date,+this._max_date)),l=new Date(Math.max(+o.start_date,+this._min_date));
for(t.splice(s,1);+_>+l;){var c=this._copy_event(o);c.start_date=l,c.end_date=i(c.start_date),l=e.date.add(l,1,"day");var d=+e.date.date_part(new Date(l));r[d]||(r[d]=[]),r[d].push(c),t.splice(s,0,c),s++}s--}}var h=[];for(var s in r)h.splice.apply(h,[h.length-1,0].concat(v.apply(this,[r[s],a])));for(var s=0;s<h.length;s++)this._ignores[h[s]._sday]?(h.splice(s,1),s--):h[s]._first_chunk=h[s]._last_chunk=!1;h.sort(function(e,t){return e.start_date.valueOf()==t.start_date.valueOf()?e.id>t.id?1:-1:e.start_date>t.start_date?1:-1;
}),t=h}else t=v.apply(this,[t,a]);return t},e.attachEvent("onEventAdded",function(t,a){if(this._loading)return!0;for(var i in e._props){var n=e._props[i];"undefined"==typeof a[n.map_to]&&(a[n.map_to]=n.options[0].key)}return!0}),e.attachEvent("onEventCreated",function(t,a){var i=e._props[this._mode];if(i&&a){var r=this.getEvent(t);n(i,r);var s=this._mouse_coords(a);this._update_unit_section({view:i,event:r,pos:s}),this.event_updated(r)}return!0})}()});