/*
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
*/
TouchScroll=function(a,b,c,e){this.debug=!!b;this.compat=!!e;this.rough=!!c;this.axisX=this.axisY=!0;typeof a!="object"&&(a=document.getElementById(a));this._init();a.addEventListener("touchstart",this,!1);a.addEventListener("webkitTransitionEnd",this,!1);this.debug&&a.addEventListener("mousedown",this,!1);this.node=a;for(var d=0;d<a.childNodes.length;d++)if(a.childNodes[d].nodeType==1){this.area=a.childNodes[d];break}if(window.getComputedStyle(this.node).position=="static")this.node.style.position=
"relative";this.area.style.cssText+="-webkit-transition: -webkit-transform; -webkit-user-select:none; -webkit-transform-style:preserve-3d;";this.scrolls={}};
TouchScroll.prototype={refresh:function(){this.node.style.webkitTransformStyle="flat";this.node.style.webkitTransformStyle="preserve-3d"},scrollTo:function(a,b,c){this.set_matrix({e:a,f:b},c||0)},onscroll:function(){},handleEvent:function(a){return this["ev_"+a.type](a)},get_matrix:function(a){return new WebKitCSSMatrix(window.getComputedStyle(a||this.area).webkitTransform)},set_matrix:function(a,b,c){(c||this.area).style.webkitTransform="translate("+Math.round(a.e)+"px,"+Math.round(a.f)+"px)";(c||
this.area).style.webkitTransitionDuration=b},ev_touchstart:function(a){this.ev_mousedown(a.touches[0]);a.preventDefault();return!1},ev_mousedown:function(a){var b=a;this.x=b.pageX;this.y=b.pageY;this.dx=this.node.offsetWidth;this.dy=this.node.offsetHeight;this.mx=this.area.scrollWidth;this.my=this.area.scrollHeight;this.target=b.target;if(!this.rough){var c=this.get_matrix();this.target_x=c.e;this.target_y=c.f;if(!this.scroll&&this.compat)c.e=this.node.scrollLeft*-1,c.f=this.node.scrollTop*-1,this.node.scrollTop=
this.node.scrollLeft=0;this.set_matrix(c,0);this._correct_scroll(this.target_x,this.target_y)}this.scroll_x=this.scroll_y=this.scroll=!1;this._init_events()},ev_touchend:function(){return this.ev_mouseup()},ev_mouseup:function(){this._deinit_events();if(!this.scroll){this._remove_scroll();var a=document.createEvent("MouseEvent");a.initMouseEvent("click",!0,!0);this.target.dispatchEvent(a)}this.target=null},ev_webkitTransitionEnd:function(){if(!this.target&&this.scroll){this._remove_scroll();var a=
this.get_matrix();this.node.firstChild._scrollTop=-1*a.f;if(this.compat&&(a.e||a.f)){var b=a.f,c=a.e;a.e=a.f=0;this.set_matrix(a,0);this.node.scrollTop=-1*b;this.node.scrollLeft=-1*c}this.scroll=!1}},ev_touchmove:function(a){return this.ev_mousemove(a.touches[0])},ev_mousemove:function(a){if(this.target){var b=a,c=(b.pageX-this.x)*(this.axisX?5:0),e=(b.pageY-this.y)*(this.axisY?5:0);if(!(Math.abs(c)<10&&Math.abs(e)<10)){if(Math.abs(c)>50)this.scroll_x=!0;if(Math.abs(e)>50)this.scroll_y=!0;if(this.scroll_x||
this.scroll_y){this.x=b.pageX;this.y=b.pageY;this.scroll=!0;var d=this.get_matrix();c+=this.target_x-d.e;e+=this.target_y-d.f;var f="2000ms",g="500ms";this.target_x=c+d.e;this.target_y=e+d.f;if(this.target_x>0)this.target_x=0,f=g;if(this.target_y>0)this.target_y=0,f=g;if(this.mx-this.dx+this.target_x<0)this.target_x=-this.mx+this.dx,f=g;if(this.my-this.dy+this.target_y<0)this.target_y=-this.my+this.dy,f=g;this.set_matrix({e:this.target_x,f:this.target_y},f);this._add_scroll(d.e,d.f);this._correct_scroll(this.target_x,
this.target_y,f);this.onscroll(this.target_x,this.target_y)}return!1}}},_correct_scroll:function(a,b,c){if(this.scrolls.x){var e=this.get_matrix(this.scrolls.x),d=this.dx*a/this.mx;this.set_matrix({e:-1*d,f:0},c,this.scrolls.x)}if(this.scrolls.y){var e=this.get_matrix(this.scrolls.y),f=this.dy*b/this.my;this.set_matrix({e:0,f:-1*f},c,this.scrolls.y)}},_remove_scroll:function(){this.scrolls.x&&this.scrolls.x.parentNode.removeChild(this.scrolls.x);this.scrolls.y&&this.scrolls.y.parentNode.removeChild(this.scrolls.y);
this.scrolls={}},_add_scroll:function(){if(!this.scrolls.ready){var a;if(this.my>5&&this.axisY){var b=this.dy*this.dy/this.my-1;this.scrolls.y=a=document.createElement("DIV");a.className="dhx_scroll_y";a.style.height=b+"px";this.node.appendChild(a)}if(this.mx>5&&this.axisX)b=this.dx*this.dx/this.mx,this.scrolls.x=a=document.createElement("DIV"),a.className="dhx_scroll_x",a.style.width=b+"px",this.node.appendChild(a);var c=this.get_matrix();this._correct_scroll(c.e,c.f,0);this.scrolls.ready=!0}},_init_events:function(){document.addEventListener("touchmove",
this,!1);document.addEventListener("touchend",this,!1);this.debug&&(document.addEventListener("mousemove",this,!1),document.addEventListener("mouseup",this,!1))},_deinit_events:function(){document.removeEventListener("touchmove",this,!1);document.removeEventListener("touchend",this,!1);this.debug&&(document.removeEventListener("mousemove",this,!1),document.removeEventListener("mouseup",this,!1))},_init:function(){document.styleSheets[0].insertRule(".dhx_scroll_x { width:50px;height:4px;background:rgba(0, 0, 0, 0.4);position:absolute; left:0px; bottom:3px; border:1px solid transparent; -webkit-border-radius:4px;-webkit-transition: -webkit-transform;}",
0);document.styleSheets[0].insertRule(".dhx_scroll_y { width:4px;height:50px;background:rgba(0, 0, 0, 0.4);position:absolute; top:0px; right:3px; border:1px solid transparent; -webkit-border-radius:4px;-webkit-transition: -webkit-transform;}",0);this._init=function(){}}};
scheduler._ipad_before_init=function(){scheduler._ipad_before_init=function(){};scheduler.xy.scroll_width=0;for(var a=scheduler._els.dhx_cal_tab,b=42,c=a.length-1;c>=0;c--)a[c].style.cssText+="top:4px;",a[c].style.left="auto",a[c].style.right=b+"px",c==0&&(a[c].style.cssText+=";-webkit-border-top-left-radius: 5px; -webkit-border-bottom-left-radius: 5px;"),c==a.length-1&&(a[c].style.cssText+=";-webkit-border-top-right-radius: 5px; -webkit-border-bottom-right-radius: 5px;"),b+=100;scheduler._els.dhx_cal_prev_button[0].innerHTML=
"&lt;";scheduler._els.dhx_cal_next_button[0].innerHTML="&gt;";var e=document.createElement("div");e.className="dhx_cal_add_button";e.innerHTML="+ ";e.onclick=function(){var a=new Date;a>scheduler._min_date&&a<scheduler._max_date?scheduler.addEventNow():scheduler.addEventNow(scheduler._min_date.valueOf())};scheduler._els.dhx_cal_navline[0].appendChild(e);this._obj.onmousedown=this._obj.onmouseup=this._obj.onmousemove=function(){};var d=null,f=[];this._obj.ontouchmove=function(a){if(d){var b=Math.abs(a.touches[0].pageX-
f[0]),c=Math.abs(a.touches[0].pageY-f[1]);if(b>50||c>50)d=window.clearTimeout(d)}scheduler.config.touch_actions&&scheduler._on_mouse_move(a.touches[0])};this._obj.ontouchstart=function(a){scheduler._lightbox_id||(d=window.setTimeout(function(){scheduler._on_dbl_click(a.touches[0],a.target.className?a.target:a.target.parentNode)},400),f=[a.touches[0].pageX,a.touches[0].pageY],scheduler.config.touch_actions&&scheduler._on_mouse_down(a.touches[0]))};this._obj.ontouchend=function(a){d&&(d=window.clearTimeout(d));
scheduler.config.touch_actions&&scheduler._on_mouse_up(a.touches[0])}};
scheduler._ipad_init=function(){var a=document.createElement("DIV"),b=scheduler._els.dhx_cal_data[0];a.appendChild(b);a.style.cssText="overflow:hidden; width:100%; overflow:hidden;position:relative;";this._obj.appendChild(a);b.style.overflowY="hidden";var c=new TouchScroll(a);c.axisX=!1;scheduler._ipad_init=function(){b.parentNode.style.height=b.style.height;b.parentNode.style.top=b.style.top;b.style.height=b.scrollHeight+"px";b.style.top="0px";Math.abs(b.parentNode.offsetHeight-b.offsetHeight)<5?
(c.axisY=!1,c.scrollTo(0,0,0)):c.axisY=!0;c.refresh()};scheduler.attachEvent("onSchedulerResize",function(){setTimeout(function(){scheduler._ipad_init()});return!0});scheduler._ipad_init()};scheduler.attachEvent("onViewChange",function(){scheduler._ipad_init()});scheduler.attachEvent("onBeforeViewChange",function(){scheduler._ipad_before_init();return!0});
scheduler.showCover=function(a){this.show_cover();if(a){a.style.display="block";var b=getOffset(this._obj);a.style.top=a.offsetHeight*-1+"px";a.style.left=Math.round(b.left+(this._obj.offsetWidth-a.offsetWidth)/2)+"px"}var c=this._get_lightbox(),e=c.addEventListener("webkitTransitionEnd",function(){c.style.top="41px";c.style.webkitTransform="";c.style.webkitTransition="";c.removeEventListener(e)},!1);c.style.webkitTransform="translate(0px,"+(a.offsetHeight+41)+"px)";c.style.webkitTransitionDuration=
"500ms"};scheduler.hideCover=function(a){if(a){var b=a.addEventListener("webkitTransitionEnd",function(){a.style.top=(a.offsetHeight+41)*-1+"px";a.style.webkitTransform="";a.style.webkitTransition="";a.removeEventListener(b)},!1);a.style.webkitTransform="translate(0px,"+(a.offsetHeight+41)*-1+"px)";a.style.webkitTransitionDuration="500ms"}this.hide_cover()};scheduler.config.lightbox.sections[0].height=100;
if(scheduler.form_blocks.calendar_time)scheduler.config.lightbox.sections[1].type="calendar_time",scheduler._mini_cal_arrows=["&lt;","&gt;"];scheduler.xy.menu_width=0;scheduler.attachEvent("onClick",function(){return!1});scheduler.locale.labels.new_event="";
scheduler._mouse_coords=function(a){var b,c=document.body,e=document.documentElement;b=a.pageX||a.pageY?{x:a.pageX,y:a.pageY}:{x:a.clientX+(c.scrollLeft||e.scrollLeft||0)-c.clientLeft,y:a.clientY+(c.scrollTop||e.scrollTop||0)-c.clientTop};b.x-=getAbsoluteLeft(this._obj)+(this._table_view?0:this.xy.scale_width);var d=b.y-=getAbsoluteTop(this._obj)+this.xy.nav_height+this._dy_shift+this.xy.scale_height-(this._els.dhx_cal_data[0]._scrollTop||0);if(this._table_view){for(var f=0,f=1;f<this._colsS.heights.length;f++)if(this._colsS.heights[f]>
b.y)break;b.y=(Math.max(0,Math.ceil(b.x/this._cols[0])-1)+Math.max(0,f-1)*7)*1440/this.config.time_step;b.x=0}else b.x=Math.max(0,Math.ceil(b.x/this._cols[0])-1),b.y=Math.max(0,Math.ceil(b.y*60/(this.config.time_step*this.config.hour_size_px))-1)+this.config.first_hour*(60/this.config.time_step);return b};
