ASPxClientWeekDaysCheckEdit = _aspxCreateClass(ASPxClientControl, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
 },
 Initialize: function() {
  this.constructor.prototype.Initialize.call(this);
 },
 GetValue: function() {
  var result = 0;
  for (var day in this.itemsControl) {
   var checkEdit = this.itemsControl[day];
   if(checkEdit.GetChecked())
    result |= day;
  }
  return result;
 },
 SetValue: function(value) {
  for (var day in this.itemsControl) {
   var checkEdit = this.itemsControl[day];
   checkEdit.SetChecked((value & day) == day);
  }
 }
});
ASPxClientRecurrenceRangeControl = _aspxCreateClass(ASPxClientControl, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
 },
 UpdateControl: function(s, e) {
  var range = this.GetRange(); 
  this.UpdateChildControlsControls(range);
 },
 SubscribeEvents: function() {
  this.rbEndAfterNumberOfOccurrences.CheckedChanged.AddHandler(_aspxCreateDelegate(this.OnCheckedChanged, this));
  this.rbEndByDate.CheckedChanged.AddHandler(_aspxCreateDelegate(this.OnCheckedChanged, this));
  this.rbNoEndDate.CheckedChanged.AddHandler(_aspxCreateDelegate(this.OnCheckedChanged, this));
 },
 OnCheckedChanged: function(s, e) {
  var range = this.GetRange();
  this.UpdateChildControlsControls(range);
 },
 UpdateChildControlsControls: function(range) {
  if (range == ASPxClientRecurrenceRange.NoEndDate) {
   this.deRangeEnd.SetEnabled(false);
   this.spinRangeOccurrencesCount.SetEnabled(false);
  }
  else if (range == ASPxClientRecurrenceRange.OccurrenceCount) {
   this.deRangeEnd.SetEnabled(false);
   this.spinRangeOccurrencesCount.SetEnabled(true);
  }
  else if (range == ASPxClientRecurrenceRange.EndByDate) { 
   this.deRangeEnd.SetEnabled(true);
   this.spinRangeOccurrencesCount.SetEnabled(false);
  }
 },
 GetRange: function() {
  if (this.rbNoEndDate.GetChecked())
   return ASPxClientRecurrenceRange.NoEndDate;
  if (this.rbEndAfterNumberOfOccurrences.GetChecked())
   return ASPxClientRecurrenceRange.OccurrenceCount;
  if (this.rbEndByDate.GetChecked())
   return ASPxClientRecurrenceRange.EndByDate;
  return ASPxClientRecurrenceRange.NoEndDate;
 },
 GetOccurrenceCount: function() {
  return this.spinRangeOccurrencesCount.GetValue();
 },
 GetEndDate: function() {
  return this.deRangeEnd.GetValue();
 },
 SetRange: function(range) {
  switch(range) {
   case ASPxClientRecurrenceRange.NoEndDate:
    this.rbNoEndDate.SetChecked(true);
    break;
   case ASPxClientRecurrenceRange.OccurrenceCount:
    this.rbEndAfterNumberOfOccurrences.SetChecked(true);
    break;
   case ASPxClientRecurrenceRange.EndByDate:
    this.rbEndByDate.SetChecked(true);
    break;
  }
  this.UpdateChildControlsControls(range);
 },
 SetOccurrenceCount: function(occurrenceCount) {
  this.spinRangeOccurrencesCount.SetValue(occurrenceCount);
 },
 SetEndDate: function(date) {
  this.deRangeEnd.SetValue(date);
 }
});
ASPxClientRecurrenceControlBase = _aspxCreateClass(ASPxClientControl, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
  this.valueAccessor = this.CreateValueAccessor(this);
 },
 Initialize: function() {
  this.constructor.prototype.Initialize.call(this);
 },
 GetMainElement: function(){
  if(!_aspxIsExistsElement(this.mainElement))
   this.mainElement = _aspxGetElementById(this.name + "_mainDiv");
  return this.mainElement;
 },
 CreateValueAccessor: function(recurrenceControl) {
  return new DefaultRecurrenceRuleValuesAccessor(recurrenceControl);
 },
 Update: function(recurrenceInfo) {
 }
});
ASPxClientDailyRecurrenceControl = _aspxCreateClass(ASPxClientRecurrenceControlBase, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
 },
 Initialize: function(){
  this.constructor.prototype.Initialize.call(this);
 },
 CreateValueAccessor: function(recurrenceControl) {
  return new DailyRecurrenceValuesAccessor(recurrenceControl);
 },
 Update: function(recurrenceInfo) {
  this.SpinDailyDaysCount.SetValue(recurrenceInfo.periodicity);
  if ((recurrenceInfo.weekDays & ASPxClientWeekDays.EveryDay) == ASPxClientWeekDays.EveryDay)
    this.RbDay.SetChecked(true);
  else if ((recurrenceInfo.weekDays & ASPxClientWeekDays.WorkDays) == ASPxClientWeekDays.WorkDays)
   this.RbEveryWeekDay.SetChecked(true);
 }
});
ASPxClientWeeklyRecurrenceControl = _aspxCreateClass(ASPxClientRecurrenceControlBase, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
 },
 Initialize: function(){
  this.constructor.prototype.Initialize.call(this);
 },
 CreateValueAccessor: function(recurrenceControl) {
  return new WeeklyRecurrenceValuesAccessor(recurrenceControl);
 },
 Update: function(recurrenceInfo) {
  this.SpinWeeklyWeeksCount.SetValue(recurrenceInfo.periodicity);
  this.WeekDaysCheckEdit.SetValue(recurrenceInfo.weekDays);
 }
});
ASPxClientMonthlyRecurrenceControl = _aspxCreateClass(ASPxClientRecurrenceControlBase, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
 },
 Initialize: function(){
  this.constructor.prototype.Initialize.call(this);
 },
 CreateValueAccessor: function(recurrenceControl) {
  return new MonthlyRecurrenceValuesAccessor(recurrenceControl);
 },
 Update: function(recurrenceInfo) {
  this.spinMonthlyDayMonthCount.SetValue(recurrenceInfo.periodicity);
  this.spinMonthlyWeekDaysMonthCount.SetValue(recurrenceInfo.periodicity);
  this.wdeMonthlyWeekDays.SetValue(recurrenceInfo.weekDays);
  this.rbDay.SetChecked(false);
  this.rbWeekDays.SetChecked(false);
  var start = (recurrenceInfo.interval) ? recurrenceInfo.interval.start : new Date();
  if (recurrenceInfo.weekOfMonth == ASPxClientWeekOfMonth.None) {
   this.rbDay.SetChecked(true);
   var weekOfMonth =  RecurrenceFormHelper.CalcWeekOfMonth(start, recurrenceInfo.dayOfWeek);
   this.wmeMonthlyWeekOfMonth.SetValue(weekOfMonth);
   this.spinMonthlyDay.SetValue(recurrenceInfo.DayNumber);
  }
  else {
   this.rbWeekDays.SetChecked(true);
   this.wmeMonthlyWeekOfMonth.SetValue(recurrenceInfo.weekOfMonth);
   this.spinMonthlyDay.SetValue(start.getDate());
  }
 }
});
ASPxClientYearlyRecurrenceControl = _aspxCreateClass(ASPxClientRecurrenceControlBase, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
 },
 Initialize: function(){
  this.constructor.prototype.Initialize.call(this);
 },
 CreateValueAccessor: function(recurrenceControl) {
  return new YearlyRecurrenceValuesAccessor(recurrenceControl);
 },
 Update: function(recurrenceInfo) {
  this.meYearlyDayMonth.SetValue(recurrenceInfo.month);
  this.meYearlyWeekDaysMonth.SetValue(recurrenceInfo.month);
  this.wdeYearlyWeekDays.SetValue(recurrenceInfo.weekDays);
  this.spinYearlyDayNumber.SetValue(recurrenceInfo.dayNumber);
  this.rbDay.SetChecked(false);
  this.rbWeekOfMonth.SetChecked(false);
  var start = (recurrenceInfo.interval) ? recurrenceInfo.interval.start : new Date();
  if (recurrenceInfo.weekOfMonth == ASPxClientWeekOfMonth.None) {
   this.rbDay.SetChecked(true);
   var weekOfMonth =  RecurrenceFormHelper.CalcWeekOfMonth(start, recurrenceInfo.dayOfWeek);
   this.wmeYearlyWeekOfMonth.SetValue(weekOfMonth);
  } 
  else {
   this.rbWeekOfMonth.SetChecked(true);
   this.wmeYearlyWeekOfMonth.SetValue(recurrenceInfo.weekOfMonth);
  }
 }
});
RecurrenceFormHelper = _aspxCreateClass(null, {});
RecurrenceFormHelper.CalcWeekOfMonth = function(start, dayOfWeek) {
 var count = 0;
 var date = new Date(start.getFullYear(), start.getMonth(), 1);
 count = 0;
 while(date < start) {
   if(dayOfWeek == date.getDay())
  count++;
   date.setDate(1 + date.getDate());
 }
 if (count <=1) 
  return ASPxClientWeekOfMonth.First;
 else if (count == 2)
  return ASPxClientWeekOfMonth.Second;
 else if (count == 3)
  return ASPxClientWeekOfMonth.Third;
 else if (count == 4)
  return ASPxClientWeekOfMonth.Fourth;
 else if (count >= 5)
  return ASPxClientWeekOfMonth.Last;
}
DefaultRecurrenceRuleValuesAccessor = _aspxCreateClass(null, {
 constructor: function(recurrenceControl) {
  this.recurrenceControl = recurrenceControl;
 },
 GetPeriodicity: function() {
  return ASPxClientRecurrenceInfo.DefaultPeriodicity;
 }, 
 GetDayNumber: function() {
  return 1;
 },
 GetMonth: function() {
  return 1;
 },
 GetWeekDays: function() {
  return ASPxClientRecurrenceInfo.DefaultWeekDays;
 },
 GetWeekOfMonth: function() {
  return ASPxClientRecurrenceInfo.DefaultWeekOfMonth;
 }
});
DailyRecurrenceValuesAccessor = _aspxCreateClass(DefaultRecurrenceRuleValuesAccessor, {
 constructor: function(recurrenceControl) {
  this.constructor.prototype.constructor.call(this, recurrenceControl);
 },
 GetPeriodicity: function() {
  return this.recurrenceControl.SpinDailyDaysCount.GetValue();
 },
 GetWeekDays: function() {
  return (this.recurrenceControl.RbDay.GetChecked()) ? ASPxClientWeekDays.EveryDay : ASPxClientWeekDays.WorkDays;
 }
});
WeeklyRecurrenceValuesAccessor = _aspxCreateClass(DefaultRecurrenceRuleValuesAccessor, {
 constructor: function(recurrenceControl) {
  this.constructor.prototype.constructor.call(this, recurrenceControl);
 },
 GetPeriodicity: function() {
  return this.recurrenceControl.SpinWeeklyWeeksCount.GetValue();
 },
 GetWeekDays: function() {
  return this.recurrenceControl.WeekDaysCheckEdit.GetValue();
 }
});
MonthlyRecurrenceValuesAccessor = _aspxCreateClass(DefaultRecurrenceRuleValuesAccessor, {
 constructor: function(recurrenceControl) {
  this.constructor.prototype.constructor.call(this, recurrenceControl);
 },
 GetDayNumber: function() {
  return this.recurrenceControl.spinMonthlyDay.GetValue();
 },
 GetPeriodicity: function() {
  result = (this.recurrenceControl.rbDay.GetChecked()) ? this.recurrenceControl.spinMonthlyDayMonthCount.GetValue() : this.recurrenceControl.spinMonthlyWeekDaysMonthCount.GetValue();
  return result;
 }, 
 GetWeekDays: function() {
  return this.recurrenceControl.wdeMonthlyWeekDays.GetValue();
 },
 GetWeekOfMonth: function() {
  return (this.recurrenceControl.rbDay.GetChecked()) ? ASPxClientWeekOfMonth.None : this.recurrenceControl.wmeMonthlyWeekOfMonth.GetValue();
 }
});
YearlyRecurrenceValuesAccessor = _aspxCreateClass(DefaultRecurrenceRuleValuesAccessor, {
 constructor: function(recurrenceControl) {
  this.constructor.prototype.constructor.call(this, recurrenceControl);
 },
 GetDayNumber: function() {
  return this.recurrenceControl.spinYearlyDayNumber.GetValue();
 },
 GetMonth: function() {
  return (this.recurrenceControl.rbDay.GetChecked()) ? this.recurrenceControl.meYearlyDayMonth.GetValue() : this.recurrenceControl.meYearlyWeekDaysMonth.GetValue();
 }, 
 GetWeekDays: function() {
  return this.recurrenceControl.wdeYearlyWeekDays.GetValue();
 },
 GetWeekOfMonth: function() {
  return (this.recurrenceControl.rbDay.GetChecked()) ? ASPxClientWeekOfMonth.None : this.recurrenceControl.wmeYearlyWeekOfMonth.GetValue();
 }
});
ASPxClientFormBase = _aspxCreateClass(null, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this);
  this.FormClosed = new ASPxClientEvent();
  this.name = name;
  this.uniqueID = name;
  aspxGetControlCollection().Add(this);
 },
 Close: function() {
  this.RaiseFormClosed();
 },
 RaiseFormClosed: function() {
  var args = new ASPxClientEventArgs();
  this.FormClosed.FireEvent(this, args);
 },
 SetVisibleCore: function(element, isVisible) {
  if (!element)
   return;
  if (isVisible) {
   _aspxSetElementDisplay(element, true);
   aspxGetControlCollection().AdjustControls(element, __aspxCheckSizeCorrectedFlag);
  }
  else
   _aspxSetElementDisplay(element, false);
 }
});
