/*

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