__aspxSchedulerMouseEventDataObject = null;
ASPxSchedulerMouseEvents = _aspxCreateClass(null, {
 constructor: function(){
  this.mouseOverHandlerList = [];
  this.mouseMoveHandlerList = [];
  this.mouseOutHandlerList = [];
 },
 CreateHandler: function(handlerObject, param) {
  var result = new Object();
  result.handlerObject = handlerObject;
  result.param = param;
  return result;
 },
 AddMouseOverHandler: function (handlerObject, param) {
  var handler = this.CreateHandler(handlerObject, param);
  _aspxArrayPush(this.mouseOverHandlerList, handler);
 },
 AddMouseMoveHandler: function (handlerObject, param) {
  var handler = this.CreateHandler(handlerObject, param);
  _aspxArrayPush(this.mouseMoveHandlerList, handler);
 },
 AddMouseOutHandler: function (handlerObject, param) {
  var handler = this.CreateHandler(handlerObject, param);
  _aspxArrayPush(this.mouseOutHandlerList, handler);
 }, 
 FireMouseOverEvent: function (evt, dataObject) {
  function fireMouseOver(handlerObject, evt, dataObject, param) {
   return handlerObject.OnMouseOver(evt, dataObject, param);
  }
  this.FireMouseEvent(this.mouseOverHandlerList, fireMouseOver, evt, dataObject );
 },
 FireMouseOutEvent: function (evt, dataObject) {
  function fireMouseOut(handlerObject, evt, dataObject, param) {
   return handlerObject.OnMouseOut(evt, dataObject, param);
  }
  this.FireMouseEvent(this.mouseOutHandlerList, fireMouseOut, evt, dataObject );
 },
 FireMouseMoveEvent: function (evt, dataObject) {
  function fireMouseMove(handlerObject, evt, dataObject, param) {
   return handlerObject.OnMouseMove(evt, dataObject, param);
  }
  this.FireMouseEvent(this.mouseMoveHandlerList, fireMouseMove, evt, dataObject );
 },
 FireMouseEvent: function(handlerList, fireEventFunc, evt, dataObject) {
  for(var i = 0; i < handlerList.length; i++) {
   var handler = handlerList[i];
   fireEventFunc(handler.handlerObject, evt, dataObject, handler.param);
  }
 }
});
function _aspxSchedulerTestIsSupportMouseEvents(element) {
 return _aspxIsExists(element.schedulerMouseEventDataObject) && _aspxIsExists(element.schedulerMouseEventDataObject.mouseEvents);
}
function _aspxSubscribeSchedulerMouseEvents(element, schedulerMouseEventDataObject) {
 if(_aspxIsExists(element.schedulerMouseEventDataObject))
  return;
 element.schedulerMouseEventDataObject = schedulerMouseEventDataObject;
 _aspxAttachEventToElement(element, "mouseover", _aspxOnSchedulerMouseOver);
 _aspxAttachEventToElement(element, "mousemove", _aspxOnSchedulerMouseMove);
 _aspxAttachEventToElement(element, "mouseout", _aspxOnSchedulerMouseOut);
}
function _aspxUnsubscribeSchedulerMouseEvents(element, schedulerMouseEventDataObject) {
 if(!_aspxIsExists(element.schedulerMouseEventDataObject))
  return;
 element.schedulerMouseEventDataObject = null;
 _aspxDetachEventFromElement(element, "mouseover", _aspxOnSchedulerMouseOver);
 _aspxDetachEventFromElement(element, "mousemove", _aspxOnSchedulerMouseMove);
 _aspxDetachEventFromElement(element, "mouseout", _aspxOnSchedulerMouseOut);
}
function _aspxClearCurrentMouseEventDataObject() {
 if(_aspxIsExists(__aspxSchedulerMouseEventDataObject))
  __aspxSchedulerMouseEventDataObject.mouseEvents.FireMouseOutEvent(null, __aspxSchedulerMouseEventDataObject);  
 __aspxSchedulerMouseEventDataObject = null;
}
function _aspxOnSchedulerMouseMove(evt) {
 evt = _aspxGetEvent(evt);
 var eventSource = _aspxGetEventSource(evt);
 eventSource = _aspxFindParentElement(eventSource, _aspxSchedulerTestIsSupportMouseEvents);
 if(!_aspxIsExists(eventSource))
  return true;
 var dataObject = eventSource.schedulerMouseEventDataObject;
 if(dataObject != __aspxSchedulerMouseEventDataObject) {
  __aspxSchedulerMouseEventDataObject = dataObject;
  dataObject.mouseEvents.FireMouseOverEvent(evt, dataObject);
 }
 dataObject.mouseEvents.FireMouseMoveEvent(evt, dataObject);
 return true;
}
function _aspxOnSchedulerMouseOver(evt) {
 evt = _aspxGetEvent(evt);
 var eventSource = _aspxGetEventSource(evt);
 eventSource = _aspxFindParentElement(eventSource, _aspxSchedulerTestIsSupportMouseEvents);
 if(!_aspxIsExists(eventSource))
  return;
 var dataObject = eventSource.schedulerMouseEventDataObject;
 if(__aspxSchedulerMouseEventDataObject == dataObject)
  return;
 dataObject.mouseEvents.FireMouseOverEvent(evt, dataObject);
 __aspxSchedulerMouseEventDataObject = dataObject;
 return _aspxCancelBubble(evt);
}
function _aspxOnSchedulerMouseOut(evt) {
 evt = _aspxGetEvent(evt);
 var eventSource = _aspxGetEventSource(evt);
 var eventTarget = _aspxGetOnMouseOutEventTarget(evt);
 eventSource = _aspxFindParentElement(eventSource, _aspxSchedulerTestIsSupportMouseEvents);
 eventTarget = _aspxFindParentElement(eventTarget, _aspxSchedulerTestIsSupportMouseEvents);
 var sourceDataObject = _aspxIsExists(eventSource) ? eventSource.schedulerMouseEventDataObject : null;
 var targetDataObject = _aspxIsExists(eventTarget) ? eventTarget.schedulerMouseEventDataObject : null;
 if(sourceDataObject == targetDataObject)
  return _aspxCancelBubble(evt);
 sourceDataObject.mouseEvents.FireMouseOutEvent(evt, sourceDataObject);
 __aspxSchedulerMouseEventDataObject = null;
}
ASPxSchedulerToolTipHelper = _aspxCreateClass(null, {
 constructor: function() {
  this.timeBeforeShow = 500;
  this.timerId = -1;
  this.lastX = null;
  this.lastY = null;
  this.dataObject = null;
  this.activeToolTip = null;  
 },
 OnMouseOver: function(evt, dataObject) {
  function isToolTipSource(element) {
   return _aspxIsExists(element.isToolTip) ? element.isToolTip : false;
  }
  _aspxClearTimer(this.timerId);
  var toolTipSource = _aspxFindParentElement(_aspxGetEventSource(evt), isToolTipSource);
  if(_aspxIsExists(toolTipSource)) {
   return;
  }
  this.lastX = _aspxGetEventX(evt);
  this.lastY = _aspxGetEventY(evt);
  this.dataObject = dataObject;
  this.timerId = _aspxSetTimeout(_aspxOnToolTipTimer, this.timeBeforeShow);
 },
 OnMouseMove: function(evt) {
  this.lastX = _aspxGetEventX(evt);
  this.lastY = _aspxGetEventY(evt);
 },
 OnMouseOut: function(evt, dataObject, smartTag) {
  _aspxClearTimer(this.timerId);
    this.HideActiveToolTip();
    this.activeToolTip = null;
    this.dataObject = null;   
 },
 ShowToolTip: function() {
  this.HideActiveToolTip();
  if(!_aspxIsExists(this.dataObject))
   return;  
  var toolTip = this.dataObject.GetToolTip();  
  this.activeToolTip = toolTip;
  toolTip.ShowToolTip(this.lastX, this.lastY);
  _aspxSubscribeSchedulerMouseEvents(toolTip.mainDiv, this.dataObject);  
 },
 HideActiveToolTip: function()  {
  if(!_aspxIsExists(this.activeToolTip))
   return;
  _aspxUnsubscribeSchedulerMouseEvents(this.activeToolTip.mainDiv, this.dataObject);  
  this.activeToolTip.HideToolTip();
  this.activeToolTip = null;    
 }
});
ASPxSchedulerSmartTagHelper = _aspxCreateClass(null, {
 constructor: function() {
  this.timeBeforeShow = 500;
  this.timerId = -1;
  this.lastX = null;
  this.lastY = null;
  this.smartTag = null;
  this.dataObject = null;
  this.activeSmartTag = null;  
  this.smartTagOffsetX = -15; 
  this.smartTagOffsetY = -20; 
 },
 OnMouseOver: function(evt, dataObject, smartTag) {
  this.OnMouseMove(evt, dataObject, smartTag);
 },
 OnMouseMove: function(evt, dataObject, smartTag) {
  function isSmartTagSource(element) {
   return _aspxIsExists(element.isSmartTag) ? element.isSmartTag : false;
  }
  _aspxClearTimer(this.timerId);
  var eventSource = _aspxGetEventSource(evt);
  var smartTagSource = _aspxFindParentElement(eventSource, isSmartTagSource);
  if(_aspxIsExists(smartTagSource)) {
   return;
  }
  this.lastX = _aspxGetEventX(evt);
  this.lastY = _aspxGetEventY(evt);
  this.smartTag = smartTag;
  this.dataObject = dataObject;
  this.timerId = _aspxSetTimeout(_aspxOnSmartTagTimer, this.timeBeforeShow);
 },
 OnMouseOut: function(evt, dataObject, smartTag) {
  _aspxClearTimer(this.timerId);
    this.HideActiveSmartTag();
    this.smartTag = null;
    this.dataObject = null;   
 },
 ShowSmartTag: function() {
  var scheduler = this.smartTag.aspxParentControl;
  if(scheduler.containerCell.parentNode == null)
   return;
  this.HideActiveSmartTag();
  if(!_aspxIsExists(this.smartTag))
   return;  
  if(!_aspxIsExists(scheduler))
   return;
  if(!scheduler.CanShowSmartTag(this.dataObject, this.smartTag))
   return;
  var smartTag = this.smartTag.cloneNode(true);
  smartTag.aspxParentControl = scheduler;
  smartTag.style.left = this.lastX - _aspxGetAbsoluteX(scheduler.containerCell) + this.smartTagOffsetX + "px";
  smartTag.style.top = this.lastY - _aspxGetAbsoluteY(scheduler.containerCell) + this.smartTagOffsetY + "px";
  smartTag.isSmartTag = true;
  smartTag.dataObject = this.dataObject;
  scheduler.containerCell.appendChild(smartTag);
  _aspxSubscribeSchedulerMouseEvents(smartTag, this.dataObject);  
  _aspxSetElementDisplay(smartTag, true);  
  this.activeSmartTag = smartTag;
 },
 HideActiveSmartTag: function() {
  if(!_aspxIsExists(this.activeSmartTag))
   return;
  var scheduler = this.activeSmartTag.aspxParentControl;
  _aspxSetElementDisplay(this.activeSmartTag, false);      
  _aspxRecycleNode(this.activeSmartTag);  
  this.activeSmartTag = null;  
 }
});
_aspxSchedulerSmartTagHelper = new ASPxSchedulerSmartTagHelper();
_aspxSchedulerToolTipHelper = new ASPxSchedulerToolTipHelper();
function _aspxOnSmartTagTimer() {
 if(_aspxIsExists(_aspxSchedulerSmartTagHelper))
  _aspxSchedulerSmartTagHelper.ShowSmartTag();
}
function _aspxOnToolTipTimer() {
 if(_aspxIsExists(_aspxSchedulerToolTipHelper))
  _aspxSchedulerToolTipHelper.ShowToolTip();
}
function _aspxRemoveSmartTag(dataObject, smartTag) { 
 smartTag.isSmartTag = false;
 dataObject.mouseEvents.RemoveMouseOverHandler(_aspxSchedulerSmartTagHelper, smartTag);
 dataObject.mouseEvents.RemoveMouseMoveHandler(_aspxSchedulerSmartTagHelper, smartTag);
 dataObject.mouseEvents.RemoveMouseOutHandler(_aspxSchedulerSmartTagHelper, smartTag);
}
function _aspxAddSmartTag(dataObject, smartTag) { 
 smartTag.isSmartTag = true;
 dataObject.mouseEvents.AddMouseOverHandler(_aspxSchedulerSmartTagHelper, smartTag);
 dataObject.mouseEvents.AddMouseMoveHandler(_aspxSchedulerSmartTagHelper, smartTag);
 dataObject.mouseEvents.AddMouseOutHandler(_aspxSchedulerSmartTagHelper, smartTag);
}
function _aspxAddToolTip(dataObject) { 
 dataObject.mouseEvents.AddMouseOverHandler(_aspxSchedulerToolTipHelper);
 dataObject.mouseEvents.AddMouseMoveHandler(_aspxSchedulerToolTipHelper);
 dataObject.mouseEvents.AddMouseOutHandler(_aspxSchedulerToolTipHelper);
}
function aspxSchedulerLeftResizeDivMouseDown(name, element, evt) {
 evt = _aspxGetEvent(evt);
 var scheduler = aspxGetControlCollection().Get(name);
 if(!_aspxIsExists(scheduler))   
  return;
 var appointmentDiv = element.parentNode;
 var appointmentViewInfo = appointmentDiv.appointmentViewInfo;
 if(_aspxIsExists(appointmentViewInfo))
  scheduler.BeginAppointmentResizeAtLeft(appointmentViewInfo);
}
function aspxSchedulerRightResizeDivMouseDown(name, element, evt) {
 evt = _aspxGetEvent(evt);
 var scheduler = aspxGetControlCollection().Get(name);
 if(!_aspxIsExists(scheduler))   
  return;
 var appointmentDiv = element.parentNode;
 var appointmentViewInfo = appointmentDiv.appointmentViewInfo;
 if(_aspxIsExists(appointmentViewInfo))
  scheduler.BeginAppointmentResizeAtRight(appointmentViewInfo);
}
function aspxSchedulerTopResizeDivMouseDown(name, element, evt) {
 evt = _aspxGetEvent(evt);
 var scheduler = aspxGetControlCollection().Get(name);
 if(!_aspxIsExists(scheduler))   
  return; 
 var appointmentDiv = element.parentNode;
 var appointmentViewInfo = appointmentDiv.appointmentViewInfo;
 if(_aspxIsExists(appointmentViewInfo))
  scheduler.BeginAppointmentResizeAtTop(appointmentViewInfo);
}
function aspxSchedulerBottomResizeDivMouseDown(name, element, evt) {
 evt = _aspxGetEvent(evt);
 var scheduler = aspxGetControlCollection().Get(name);
 if(!_aspxIsExists(scheduler))   
  return; 
 var appointmentDiv = element.parentNode;
 var appointmentViewInfo = appointmentDiv.appointmentViewInfo;
 if(_aspxIsExists(appointmentViewInfo))
  scheduler.BeginAppointmentResizeAtBottom(appointmentViewInfo);
}
function aspxAppointmentResizeLeft(scheduler, appointmentDiv, cell) {
 var cellTime = scheduler.GetCellStartTime(cell);
 var appointment = scheduler.GetAppointment(appointmentDiv.appointmentViewInfo.appointmentId);;
 var newStart = _aspxDateTimeMinValue(cellTime, appointment.interval.GetEnd());
 var newEnd = appointment.interval.GetEnd();
 var newInterval = new ASPxClientTimeInterval(newStart, _aspxDateSubsWithTimezone(newEnd, newStart));
 if(!newInterval.Equals(appointment.operationInterval)) {
  appointment.operationInterval = newInterval;
  return true;
 }
 else
  return false;
}
function aspxAppointmentResizeTop(scheduler, appointmentDiv, cell) {
 var cellTime = scheduler.GetCellStartTime(cell);
 var appointment = scheduler.GetAppointment(appointmentDiv.appointmentViewInfo.appointmentId);;
 var newStart = _aspxDateTimeMinValue(cellTime, appointment.interval.GetEnd());
 var newEnd = appointment.interval.GetEnd();
 var newInterval = new ASPxClientTimeInterval(newStart, _aspxDateSubsWithTimezone(newEnd, newStart));
 if(!newInterval.Equals(appointment.operationInterval)) {
  appointment.operationInterval = newInterval;
  return true;
 }
 else
  return false;
}
function aspxAppointmentResizeRight(scheduler, appointmentDiv, cell) { 
 var cellTime = scheduler.GetCellEndTime(cell);
 var appointment = scheduler.GetAppointment(appointmentDiv.appointmentViewInfo.appointmentId);;
 var newStart = appointment.interval.GetStart();
 var newEnd = _aspxDateTimeMaxValue(cellTime, appointment.interval.GetStart());
 var newInterval = new ASPxClientTimeInterval(newStart, _aspxDateSubsWithTimezone(newEnd, newStart));
 if(!newInterval.Equals(appointment.operationInterval)) {
  appointment.operationInterval = newInterval;
  return true;
 }
 else
  return false;
}
function aspxAppointmentResizeBottom(scheduler, appointmentDiv, cell) { 
 var cellTime = scheduler.GetCellEndTime(cell);  
 var appointment = scheduler.GetAppointment(appointmentDiv.appointmentViewInfo.appointmentId);;
 var newStart = appointment.interval.GetStart();
 var newEnd = _aspxDateTimeMaxValue(cellTime, appointment.interval.GetStart());
 var newInterval = new ASPxClientTimeInterval(newStart, _aspxDateSubsWithTimezone(newEnd, newStart));
 if(!newInterval.Equals(appointment.operationInterval)) {
  appointment.operationInterval = newInterval;
  return true;
 }
 else
  return false;
}
function ResizeHelper_onmouseup(e) {
 if(__aspxResizeHelper != null) {
  __aspxResizeHelper.endResize(e);
  return true;
 }
}
function ResizeHelper_onmousemove(e) {
 if(__aspxResizeHelper != null) {
  __aspxResizeHelper.resize(e);
  return false;
 }
 return true;
}
function ResizeHelper_onkeydown(e) {
 if(__aspxResizeHelper == null) return true;
 if(e.keyCode == 27) 
  __aspxResizeHelper.cancelResize(true, true);
 return true;
}
_aspxAttachEventToDocument("mouseup", ResizeHelper_onmouseup);
_aspxAttachEventToDocument("mousemove", ResizeHelper_onmousemove);
_aspxAttachEventToDocument("keydown", ResizeHelper_onkeydown);
__aspxResizeHelper = null;
ASPxResizeViewHelper = _aspxCreateClass(null, {
 constructor: function(scheduler, appointmentDiv) {
  this.scheduler = scheduler;
  this.horizontalResizePresenter = new ASPxHorizontalAppointmentOperationPresenter(scheduler, appointmentDiv);
  this.verticalResizePresenter = new ASPxVerticalAppointmentOperationPresenter(scheduler, appointmentDiv);
 },
 ShowResizedAppointmentPosition: function(e, resizedAppointment) {
  this.horizontalResizePresenter.ShowAppointment(resizedAppointment, false);  
  this.verticalResizePresenter.ShowAppointment(resizedAppointment, false);
  var content = resizedAppointment.GetToolTipContent(this.scheduler) + "<br />" + this.scheduler.operationToolTipCaption;
  var toolTip = this.scheduler.GetToolTipControl();
  if(_aspxIsExists(toolTip)) {  
   toolTip.SetContent(content);
   toolTip.ShowToolTip(_aspxGetEventX(e), _aspxGetEventY(e));
  }
 },
 HideResizedAppointmentPosition: function(aptId, restoreAptPos) {
  this.horizontalResizePresenter.HideAppointment(aptId, restoreAptPos);
  this.verticalResizePresenter.HideAppointment(aptId, restoreAptPos);
  var toolTip = this.scheduler.GetToolTipControl();
  if(_aspxIsExists(toolTip)) {  
   toolTip.HideToolTip();
  }
 },
 HideToolTip: function() {
  var toolTip = this.scheduler.GetToolTipControl();
  if(_aspxIsExists(toolTip)) {  
   toolTip.HideToolTip();
  }
 }
});
ASPxResizeHelper = _aspxCreateClass(null, {
 constructor: function(scheduler, appointmentDiv, handler, cell) {
  if(__aspxResizeHelper != null)
     __aspxResizeHelper.cancelResize(true);
  scheduler.DisableReminderTimer();
  this.lastCell = cell;
  this.scheduler = scheduler;
  this.appointmentDiv = appointmentDiv;
  this.resizeHandler = handler;
  this.resizeViewHelper = new ASPxResizeViewHelper(scheduler, appointmentDiv);
  __aspxResizeHelper = this;
 },
 resize:function(e) {
  if(__aspxIE)
   this.scheduler.innerContentElement.setActive();
  var hitTestResult = this.scheduler.CalcHitTest(e);
  var cell = hitTestResult.cell;
  if(_aspxIsExists(cell) && cell != this.lastCell) {
   if(this.resizeHandler(this.scheduler, this.appointmentDiv, cell)) {
    var appointment = this.scheduler.GetAppointment(this.appointmentDiv.appointmentViewInfo.appointmentId);
    this.resizeViewHelper.ShowResizedAppointmentPosition(e, appointment);
   }
   this.lastCell = cell;
  }
 },
 endResize: function() {
  var wasCallback = this.ApplyChanges();
  if(!wasCallback)
   this.cancelResize(true);
  else {
   this.resizeViewHelper.HideToolTip();
   __aspxResizeHelper = null;
   this.scheduler.onCallback = _aspxCreateDelegate(this.OnCallback, this);
   this.scheduler.onCallbackError = _aspxCreateDelegate(this.OnCallbackError, this);
  }
 },
 OnCallback: function() {
  this.cancelResize(false);
 },
 OnCallbackError: function() {
  this.cancelResize(true);
 },
 ApplyChanges: function() {
  var id = this.appointmentDiv.appointmentViewInfo.appointmentId;
  var appointment = this.scheduler.GetAppointment(id);
  if(!_aspxIsExists(appointment) || !_aspxIsExists(appointment.operationInterval))
   return false;   
  var wasResized = (appointment.operationInterval.GetStart() - appointment.interval.GetStart() != 0) || (appointment.operationInterval.GetEnd() - appointment.interval.GetEnd() != 0);
  if(wasResized) {
   var params = "APTSCHANGE|" + id;
   params += "?START="+  _aspxDateTimeToMilliseconds(appointment.operationInterval.GetStart());
   params += "?DURATION="+  appointment.operationInterval.GetDuration();
   var operation = new ASPxClientAppointmentOperation(this, params);
   var isHandled = this.scheduler.RaiseAppointmentResize(operation);
   if (isHandled)
    return true;
   this.Apply(params);
   return true;
  }
  else
   return false;
 },
 Apply: function(params) {
  this.scheduler.RaiseCallback(params);
 },
 Cancel: function() {
  this.cancelResize(true, true);
 },
 cancelResize: function(restoreAptPos, restoreTimer) {
  if(!_aspxIsExists(restoreAptPos))
   restoreAptPos = true;
  this.resizeViewHelper.HideResizedAppointmentPosition(this.appointmentDiv.appointmentViewInfo.appointmentId, restoreAptPos);   
  this.scheduler.onCallback = null;
  this.scheduler.onCallbackError = null;
  __aspxResizeHelper = null;
  if(restoreTimer)
   this.scheduler.EnableReminderTimer();
 }
});

