/*
This software is allowed to use under GPL or you need to obtain Commercial or Enterise License
to use it in not GPL project. Please contact sales@dhtmlx.com for details
*/
scheduler._wa={};scheduler.xy.week_agenda_scale_height=20;scheduler.templates.week_agenda_event_text=function(c,e,f){return scheduler.templates.event_date(c)+" "+f.text};scheduler.date.week_agenda_start=scheduler.date.week_start;scheduler.date.week_agenda_end=function(c){return scheduler.date.add(c,7,"day")};scheduler.date.add_week_agenda=function(c,e){return scheduler.date.add(c,e*7,"day")};
scheduler.attachEvent("onSchedulerReady",function(){var c=scheduler.templates;if(!c.week_agenda_date)c.week_agenda_date=c.week_date});(function(){var c=scheduler.date.date_to_str("%l, %F %d");scheduler.templates.week_agenda_scale_date=function(e){return c(e)}})();
scheduler.attachEvent("onTemplatesReady",function(){scheduler.attachEvent("onSchedulerResize",function(){return this._mode=="week_agenda"?(this.week_agenda_view(!0),!1):!0});var c=scheduler.render_data;scheduler.render_data=function(b){if(this._mode=="week_agenda")f();else return c.apply(this,arguments)};var e=function(){scheduler._cols=[];var b=parseInt(scheduler._els.dhx_cal_data[0].style.width);scheduler._cols.push(Math.floor(b/2));scheduler._cols.push(b-scheduler._cols[0]-1);scheduler._colsS=
{0:[],1:[]};for(var a=parseInt(scheduler._els.dhx_cal_data[0].style.height),m=0;m<3;m++)scheduler._colsS[0].push(Math.floor(a/(3-scheduler._colsS[0].length))),a-=scheduler._colsS[0][m];scheduler._colsS[1].push(scheduler._colsS[0][0]);scheduler._colsS[1].push(scheduler._colsS[0][1]);a=scheduler._colsS[0][scheduler._colsS[0].length-1];scheduler._colsS[1].push(Math.floor(a/2));scheduler._colsS[1].push(a-scheduler._colsS[1][scheduler._colsS[1].length-1])},f=function(){for(var b=scheduler._els.dhx_cal_data[0].innerHTML=
"",a=0;a<2;a++){var m=scheduler._cols[a],c="dhx_wa_column";a==1&&(c+=" dhx_wa_column_last");b+="<div class='"+c+"' style='width: "+m+"px;'>";for(var h=0;h<scheduler._colsS[a].length;h++){var k=scheduler.xy.week_agenda_scale_height-2,e=scheduler._colsS[a][h]-k-2;b+="<div class='dhx_wa_day_cont'><div style='height:"+k+"px; line-height:"+k+"px;' class='dhx_wa_scale_bar'></div><div style='height:"+e+"px;' class='dhx_wa_day_data'></div></div>"}b+="</div>"}scheduler._els.dhx_cal_date[0].innerHTML=scheduler.templates[scheduler._mode+
"_date"](scheduler._min_date,scheduler._max_date,scheduler._mode);scheduler._els.dhx_cal_data[0].innerHTML=b;for(var i=scheduler._els.dhx_cal_data[0].getElementsByTagName("div"),l=[],a=0;a<i.length;a++)i[a].className=="dhx_wa_day_cont"&&l.push(i[a]);scheduler._wa._selected_divs=[];for(var f=scheduler.get_visible_events(),j=scheduler.date.week_start(scheduler._date),n=scheduler.date.add(j,1,"day"),a=0;a<7;a++){l[a]._date=j;var s=l[a].childNodes[0],t=l[a].childNodes[1];s.innerHTML=scheduler.templates.week_agenda_scale_date(j);
for(var o=[],q=0;q<f.length;q++){var r=f[q];r.start_date<n&&r.end_date>j&&o.push(r)}o.sort(function(a,b){return a.start_date.valueOf()==b.start_date.valueOf()?a.id>b.id?1:-1:a.start_date>b.start_date?1:-1});for(h=0;h<o.length;h++){var d=o[h],g=document.createElement("div");scheduler._rendered.push(g);g.className="dhx_wa_ev_body";if(d._text_style)g.style.cssText=d._text_style;if(d.color)g.style.backgroundColor=d.color;if(d.textColor)g.style.color=d.textColor;scheduler._select_id&&d.id==scheduler._select_id&&
(g.className+=" dhx_cal_event_selected",scheduler._wa._selected_divs.push(g));var p="";d._timed||(p="middle",d.start_date.valueOf()>=j.valueOf()&&d.start_date.valueOf()<=n.valueOf()&&(p="start"),d.end_date.valueOf()>=j.valueOf()&&d.end_date.valueOf()<=n.valueOf()&&(p="end"));g.innerHTML=scheduler.templates.week_agenda_event_text(d.start_date,d.end_date,d,j,p);g.setAttribute("event_id",d.id);t.appendChild(g)}j=scheduler.date.add(j,1,"day");n=scheduler.date.add(n,1,"day")}};scheduler.week_agenda_view=
function(b){scheduler._min_date=scheduler.date.week_start(scheduler._date);scheduler._max_date=scheduler.date.add(scheduler._min_date,1,"week");scheduler.set_sizes();if(b)scheduler._table_view=!0,scheduler._wa._prev_data_border=scheduler._els.dhx_cal_data[0].style.borderTop,scheduler._els.dhx_cal_data[0].style.borderTop=0,scheduler._els.dhx_cal_data[0].style.overflowY="hidden",scheduler._els.dhx_cal_date[0].innerHTML="",scheduler._els.dhx_cal_data[0].style.top=parseInt(scheduler._els.dhx_cal_data[0].style.top)-
scheduler.xy.bar_height-1+"px",scheduler._els.dhx_cal_data[0].style.height=parseInt(scheduler._els.dhx_cal_data[0].style.height)+scheduler.xy.bar_height+1+"px",scheduler._els.dhx_cal_header[0].style.display="none",e(),f();else{scheduler._table_view=!1;if(scheduler._wa._prev_data_border)scheduler._els.dhx_cal_data[0].style.borderTop=scheduler._wa._prev_data_border;scheduler._els.dhx_cal_data[0].style.overflowY="auto";scheduler._els.dhx_cal_data[0].style.top=parseInt(scheduler._els.dhx_cal_data[0].style.top)+
scheduler.xy.bar_height+"px";scheduler._els.dhx_cal_data[0].style.height=parseInt(scheduler._els.dhx_cal_data[0].style.height)-scheduler.xy.bar_height+"px";scheduler._els.dhx_cal_header[0].style.display="block"}};scheduler.mouse_week_agenda=function(b){for(var a=b.ev,c=a.srcElement||a.target;c.parentNode;){if(c._date)var e=c._date;c=c.parentNode}if(!e)return b;b.x=0;var h=e.valueOf()-scheduler._min_date.valueOf();b.y=Math.ceil(h/6E4/this.config.time_step);if(this._drag_mode=="move"){this._drag_event._dhx_changed=
!0;this._select_id=this._drag_id;for(var k=0;k<scheduler._rendered.length;k++)if(scheduler._drag_id==this._rendered[k].getAttribute("event_id"))var f=this._rendered[k];if(!scheduler._wa._dnd){var i=f.cloneNode(!0);this._wa._dnd=i;i.className=f.className;i.id="dhx_wa_dnd";i.className+=" dhx_wa_dnd";document.body.appendChild(i)}var l=document.getElementById("dhx_wa_dnd");l.style.top=(a.pageY||a.clientY)+20+"px";l.style.left=(a.pageX||a.clientX)+20+"px"}return b};scheduler.attachEvent("onBeforeEventChanged",
function(){if(this._mode=="week_agenda"&&this._drag_mode=="move"){var b=document.getElementById("dhx_wa_dnd");b.parentNode.removeChild(b);scheduler._wa._dnd=!1}return!0});scheduler.attachEvent("onEventSave",function(b,a,c){if(c)this._select_id=b;return!0});scheduler._wa._selected_divs=[];scheduler.attachEvent("onClick",function(b){if(this._mode=="week_agenda"){if(scheduler._wa._selected_divs)for(var a=0;a<this._wa._selected_divs.length;a++){var c=this._wa._selected_divs[a];c.className=c.className.replace(/ dhx_cal_event_selected/,
"")}this.for_rendered(b,function(a){a.className+=" dhx_cal_event_selected";scheduler._wa._selected_divs.push(a)});this._select_id=b;return!1}return!0})});
