function DatePickerDelegate()
{
	/// <summary>
	/// Класс, описывающий делегаты
	/// </summary>
	this.Functions = [];
	this.clear = function()
	{
		/// <summary>
		/// Очистка списка функций
		/// </summary>
		this.Functions = [];
	}
	this.push = function(Func)
	{
		/// <summary>
		/// Добавление элемента в список
		/// </summary>
		this.Functions.push(Func);
	}
	this.pop = function()
	{
		/// <summary>
		/// Удаление последнего элемента из списка
		/// </summary>
		/// <returns>
		/// Последний элемент
		/// </returns>
		return this.Functions.pop();
	}
	this.add = function(Func)
	{
		/// <summary>
		/// Добавление элемента в список
		/// </summary>
		this.push(Func);
	}
	this.remove = function(Func)
	{
		/// <summary>
		/// Удаление элемента из списка
		/// </summary>
		var cnt = this.Functions.length;
		for (var i = 0; i < cnt; i++)
			if (this.Functions == Func)
		{
			this.Functions.splice(i, 1);
			break;
		}
	}
	this.invoke = function(EventArgs)
	{
		//debugger;
		/// <summary>
		/// Вызов делегата
		/// </summary>
		/// <param name="EventArgs" optional="true" mayBeNull="true">Аргументы</param>
		var cnt = this.Functions.length;
		for (var i = 0; i < cnt; i++)
			this.Functions[i](EventArgs);
	}
}
function DatePickerObject(DateValue)
{
	/// <summary>
	/// Объект таблицы календаря
	/// </summary>
	/// <param name="DateValue" optional="true" mayBeNull="false">Значение даты. Если опущено, берётся текущая дата.</param>
	this.to12hMode = function(Hour)
	{
		/// <summary>
		/// 24h -> 12h
		/// </summary>
		/// <param name="Hour">0-23 hour</param>
		/// <returns>[Hours, AmFlag]</returns>
		Hour = parseInt(Hour,10);
		Hour = Hour % 24;
		if (Hour == 0)
			return [12, true];
		var AmFlag = Hour < 12;
		if (!AmFlag)
			Hour -= 12;
		if (Hour == 0)
			return [12, false];
		return [Hour, AmFlag];
	}
	this.to24hMode = function(Hour, AmFlag)
	{
		/// <summary>
		/// 12h -> 24h
		/// </summary>
		/// <param name="Hour">1-12 hour</param>
		/// <param name="AmFlag">true if AM, false if PM</param>
		/// <returns>Hours</returns>
		Hour = parseInt(Hour,10);
		if ((Hour < 1) || (Hour > 12))
			throw "Invalid hour range";
		if (Hour == 12)
			return AmFlag ? 0 : 12;
		return AmFlag ? Hour : Hour + 12;
	}
	if (typeof (DatePickerResources) != "undefined")
	{
		this.ShortDayNames = DatePickerResources.ShortDayNames;
		this.MonthNames = DatePickerResources.MonthNames;
		this.PreviousMonthName = DatePickerResources.PreviousMonthName;
		this.NextMonthName = DatePickerResources.NextMonthName;
		this.PreviousYearName = DatePickerResources.PreviousYearName;
		this.NextYearName = DatePickerResources.NextYearName;
		this.IsSundayFirst = DatePickerResources.IsSundayFirst;
		this.IsMonthFirst = DatePickerResources.IsMonthFirst;
		this.DateSeparator = DatePickerResources.DateSeparator;
		this.DateOrder = DatePickerResources.DateOrder;
		this.TimeAmPm = DatePickerResources.TimeAmPm;
		this.Hour24Mode = DatePickerResources.Hour24Mode;
		this.TimeSeparator = DatePickerResources.TimeSeparator;
		this.TitleBgImage = DatePickerResources.TitleBgImage;
		this.CalendarNextyear = DatePickerResources.CalendarNextyear;
		this.CalendarNextyear_h = DatePickerResources.CalendarNextyear_h;
		this.CalendarNextmonth = DatePickerResources.CalendarNextmonth;
		this.CalendarNextmonth_h = DatePickerResources.CalendarNextmonth_h;
		this.CalendarPrevyear = DatePickerResources.CalendarPrevyear;
		this.CalendarPrevyear_h = DatePickerResources.CalendarPrevyear_h;
		this.CalendarPrevmonth = DatePickerResources.CalendarPrevmonth;
		this.CalendarPrevmonth_h = DatePickerResources.CalendarPrevmonth_h;
	} else
	{
		this.ShortDayNames = ["ПН", "ВТ", "СР", "ЧТ", "ПТ", "СБ", "ВС"];
		this.MonthNames = ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"];
		this.PreviousMonthName = "Предыдущий месяц";
		this.NextMonthName = "Следующий месяц";
		this.PreviousYearName = "Предыдущий год";
		this.NextYearName = "Следующий год";
		this.IsSundayFirst = false;
		this.IsMonthFirst = false;
		this.DateSeparator = ".";
		this.DateOrder = "dmy";
		this.TimeAmPm = ["PM", "AM"];
		this.Hour24Mode = false;
		this.TimeSeparator = ":";
		this.TitleBgImage = "/template/css/img/cal_bg.gif";;
		this.CalendarNextyear = "/template/css/img/cal_next_year.gif";
		this.CalendarNextyear_h = "/template/css/img/cal_next_year_h.gif";;
		this.CalendarNextmonth = "/template/css/img/cal_next_month.gif";
		this.CalendarNextmonth_h = "/template/css/img/cal_next_month_h.gif";
		this.CalendarPrevyear = "/template/css/img/cal_prev_year.gif";
		this.CalendarPrevyear_h = "/template/css/img/cal_prev_year_h.gif";
		this.CalendarPrevmonth = "/template/css/img/cal_prev_month.gif";
		this.CalendarPrevmonth_h = "/template/css/img/cal_prev_month_h.gif";
	}

	this.DropDownClose = true;
	this.ShowDropDown = true;
	//if (typeof(DateValue)=="undefined")
	if (DateValue == "" || typeof (DateValue) == "undefined")
	{
		//when component loading with not assigned value
		var TempDate = new Date();
		this.CurrentDay = TempDate.getDate();
		this.CurrentMonth = TempDate.getMonth();
		this.CurrentYear = TempDate.getFullYear();
		this.CurrentHour = TempDate.getHours();
		this.CurrentMinute = TempDate.getMinutes();
		this.ShowTime = false;
		this.ShowDate = false;
	} else
	{
		if (typeof (DateValue) != "string")
			throw "DateValue must be type of string";
		if (this.DateOrder.length != 3)
			this.DateOrder = "dmy";
		this.ShowTime = false;
		this.ShowDate = false;

		if ((DateValue + "").indexOf(this.DateSeparator) >= 0)
			this.ShowDate = true;

		if ((DateValue + "").indexOf(this.TimeSeparator) >= 0)
			this.ShowTime = true; //if ((DateValue+"").indexOf(" ")>=0)        

		if (this.ShowTime)
		{
			var TimeValue = null;
			var DateTimeArr = null;
			if (this.ShowDate)
			{
				DateTimeArr = (DateValue + "").split(" ");
				DateValue = DateTimeArr[0];
				TimeValue = DateTimeArr[1];
			}
			else
			{
				DateTimeArr = (DateValue + "").split(" ");
				TimeValue = DateValue;
			}
			var TimeArr = TimeValue.split(this.TimeSeparator);
			this.CurrentHour = parseInt(TimeArr[0],10);
			this.CurrentHour = this.CurrentHour % 24;
			this.CurrentMinute = parseInt(TimeArr[1],10);
			this.CurrentMinute = this.CurrentMinute % 60;
			if (!this.Hour24Mode)
			{
				if (this.CurrentHour > 12)
					this.CurrentHour -= 12;
				if (this.CurrentHour == 0)
					this.CurrentHour = 12;

				var AmFlag = null;
				if (this.ShowDate)
					var AmFlag = DateTimeArr[2];
				else
					var AmFlag = DateTimeArr[1];

				if (!AmFlag)
					AmFlag = true;
				else
					AmFlag = ((AmFlag + "").toLowerCase() != this.TimeAmPm[1].toLowerCase());
				this.CurrentHour = this.to24hMode(this.CurrentHour, AmFlag);
			}


		}

		if (this.ShowDate)
		{
			var DateArr = (DateValue + "").split(this.DateSeparator);
			if (DateArr.length < 3)
				throw "DateValue must contain separators";
			var DateObj = {};
			for (var i = 0; i < 3; i++)
				DateObj[this.DateOrder.substr(i, 1)] = DateArr[i];
			var Day = parseInt(DateObj["d"],10);
			if (isNaN(Day))
				throw "DateValue parse error: Day";
			var Month = parseInt(DateObj["m"],10);
			var Year = parseInt(DateObj["y"],10);
			if ((DateObj["y"] + "").length == 2)
				Year = (Year <= 50) ? parseInt("20" + DateObj["y"],10) : parseInt("19" + DateObj["y"],10);
			this.CurrentDay = Day;
			this.CurrentMonth = Month - 1;
			this.CurrentYear = Year;
		}
	}
	this.updateDate = function()
	{
		if (this.ShowDate)
		{
			this.CurrentDate = this.ShowTime ? new Date(this.CurrentYear, this.CurrentMonth, this.CurrentDay, this.CurrentHour, this.CurrentMinute) : new Date(this.CurrentYear, this.CurrentMonth, this.CurrentDay);
			this.CurrentDay = this.CurrentDate.getDate();
			this.CurrentMonth = this.CurrentDate.getMonth();
			this.CurrentYear = this.CurrentDate.getFullYear();
			this.CurrentHour = this.CurrentDate.getHours();
			this.CurrentMinute = this.CurrentDate.getMinutes();
		}
		else
		{
			// time only
			var mCurrentDate = new Date();
			mCurrentDate.setHours(this.CurrentHour, this.CurrentMinute, 0);
			this.CurrentDate = mCurrentDate;
			this.CurrentDay = this.CurrentDate.getDate();
			this.CurrentMonth = this.CurrentDate.getMonth();
			this.CurrentYear = this.CurrentDate.getFullYear();
			this.CurrentHour = this.CurrentDate.getHours();
			this.CurrentMinute = this.CurrentDate.getMinutes();
		}
	}
	this.updateDate();
	this.render = function(DomNode)
	{
		if (this.ShowDropDown == false)
			return;
			
		var dropDownClose = null;
		if (this.DropDownClose)
			dropDownClose = "true";
		else
			dropDownClose = "false";

		if (typeof (DomNode) == "string")
			DomNode = document.getElementById(DomNode);
		var Tables = DomNode.getElementsByTagName("TABLE");
		var Table = null;
		if (Tables.length)
			Table = Tables[0];
		if (Table == null)
		{
			DomNode.innerHTML = "";
			Table = document.createElement("TABLE");
			Table.className = "calendar";
			Table.cellPadding = 2;
			Table.cellSpacing = 0;
			Table.border = 0;
			DomNode.appendChild(Table);
		} else
		{
			while (Table.rows.length)
				Table.deleteRow(0);
		}
		Table.style.visibility = "hidden";
		var Row = Table.insertRow(-1);
		var Cell = Row.insertCell(-1);
		Cell.innerHTML = "<img alt='' src='" + this.CalendarPrevmonth + "' onmouseover='src=\"" + this.CalendarPrevmonth_h + "\"' ' onmouseout='src=\"" + this.CalendarPrevmonth + "\"'/>";
		Cell.className = "title_button";
		if (this.TitleBgImage) Cell.style.backgroundImage = "url(" + this.TitleBgImage + ")";
		Cell.DatePicker = this;
		Cell.RefreshNode = DomNode;
		Cell.onclick = new Function("this.DatePicker.setPMD(this)");
		Cell.onmouseover = this.onmouseover;
		Cell.onmouseout = this.onmouseout;
		Cell.title = this.PreviousMonthName;
		Cell = Row.insertCell(-1);
		Cell.innerHTML = "<img alt='' src='" + this.CalendarPrevyear + "' onmouseover='src=\"" + this.CalendarPrevyear_h + "\"' ' onmouseout='src=\"" + this.CalendarPrevyear + "\"'/>";
		Cell.className = "title_button";
		if (this.TitleBgImage) Cell.style.backgroundImage = "url(" + this.TitleBgImage + ")";
		Cell.DatePicker = this;
		Cell.RefreshNode = DomNode;
		Cell.onclick = new Function("this.DatePicker.setPY(this)");
		Cell.onmouseover = this.onmouseover;
		Cell.onmouseout = this.onmouseout;
		Cell.title = this.PreviousYearName;
		Cell = Row.insertCell(-1);
		Cell.colSpan = 3;
		Cell.className = "title_header";
		if (this.TitleBgImage) Cell.style.backgroundImage = "url(" + this.TitleBgImage + ")";
		Cell.style.width = "auto";
		Cell.innerHTML = this.getCurrentMonthName() + "&nbsp;" + this.CurrentYear;
		Cell = Row.insertCell(-1);
		Cell.innerHTML = "<img alt='' src='" + this.CalendarNextyear + "' onmouseover='src=\"" + this.CalendarNextyear_h + "\"' ' onmouseout='src=\"" + this.CalendarNextyear + "\"'/>";
		Cell.className = "title_button";
		if (this.TitleBgImage) Cell.style.backgroundImage = "url(" + this.TitleBgImage + ")";
		Cell.DatePicker = this;
		Cell.RefreshNode = DomNode;
		Cell.onclick = new Function("this.DatePicker.setNY(this)");
		Cell.onmouseover = this.onmouseover;
		Cell.onmouseout = this.onmouseout;
		Cell.title = this.NextYearName;
		Cell = Row.insertCell(-1);
		Cell.innerHTML = "<img alt='' src='" + this.CalendarNextmonth + "' onmouseover='src=\"" + this.CalendarNextmonth_h + "\"' ' onmouseout='src=\"" + this.CalendarNextmonth + "\"'/>"; 
		Cell.className = "title_button";
		if (this.TitleBgImage) Cell.style.backgroundImage = "url(" + this.TitleBgImage + ")";
		Cell.DatePicker = this;
		Cell.RefreshNode = DomNode;
		Cell.onclick = new Function("this.DatePicker.setNMD(this)");
		Cell.onmouseover = this.onmouseover;
		Cell.onmouseout = this.onmouseout;
		Cell.title = this.NextMonthName;
		Row = Table.insertRow(-1);
		var cnt = this.ShortDayNames.length;
		for (var i = 0; i < cnt; i++)
		{
			Cell = Row.insertCell(-1);
			Cell.innerHTML = this.ShortDayNames[i];
			if (this.IsSundayFirst)
				Cell.className = ((i > 5) || (i == 0)) ? "dayheader holiday" : "dayheader";
			else
				Cell.className = (i > 4) ? "dayheader holiday" : "dayheader";
		}
		var Now = new Date();
		var IsCurrentMonth = ((Now.getFullYear() == this.CurrentYear) && (Now.getMonth() == this.CurrentMonth));
		var Weeks = this.getMonthWeeks();
		for (var i = 0; i < Weeks.length; i++)
		{
			Row = Table.insertRow(-1);
			var Week = Weeks[i];
			for (var j = 0; j < Week.length; j++)
			{
				var Day = Week[j];
				Cell = Row.insertCell(-1);
				Cell.DatePicker = this;
				var Cls = ["day"];
				if (Day.IsPrevMonth)
				{
					Cls.push("prev");
					Cell.onclick = new Function("this.DatePicker.setPMD(this, " + Day.No + ", true)");
					Cell.onmouseover = this.onmouseover;
					Cell.onmouseout = this.onmouseout;
				}
				if (Day.IsCurrentMonth)
				{
					Cls.push("current");
					if (IsCurrentMonth)
						if (Now.getDate() == Day.No)
						Cls.push("today");
					if (!Day.IsActive)
					{
						Cell.onclick = new Function("this.DatePicker.setCMD(this, " + Day.No + ", " + dropDownClose + ")");
						Cell.onmouseover = this.onmouseover;
						Cell.onmouseout = this.onmouseout;
					}
				}
				if (Day.IsNextMonth)
				{
					Cls.push("next");
					Cell.onclick = new Function("this.DatePicker.setNMD(this, " + Day.No + ", true)");
					Cell.onmouseover = this.onmouseover;
					Cell.onmouseout = this.onmouseout;
				}
				if (this.IsSundayFirst)
				{
					if ((Day.Index > 5) || (Day.Index == 0))
						Cls.push("holiday");
				} else
				{
					if (Day.Index > 4)
						Cls.push("holiday");
				}
				if (Day.IsActive)
					Cls.push("active");
				Cell.className = Cls.join(" ");
				Cell.innerHTML = Day.No;
				Cell.RefreshNode = DomNode;
			}
		}
		Table.style.visibility = "visible";
	}

	this.getCurrentMonthName = function()
	{
		return this.MonthNames[this.CurrentMonth];
	}
	this.ChangeCounter = 0;
	this.OldDay = 0;
	this.OldMonth = 0;
	this.OldYear = 0;
	this.beginChange = function()
	{
		this.ChangeCounter++;
	}
	this.endChange = function(AItem, SkipRefresh)
	{
		this.ChangeCounter--;
		if (this.ChangeCounter < 0)
			this.ChangeCounter = 0;
		if (this.ChangeCounter == 0)
			this.onchange.invoke({ Item: AItem, SkipRefresh: (SkipRefresh == true) });
	}
	this.setCurrentYear = function(NewYear)
	{
		this.beginChange();
		if (typeof (NewYear) == "string")
		{
			var Multiplier = 0;
			if (NewYear.indexOf("+") == 0)
				Multiplier = 1;
			if (NewYear.indexOf("-") == 0)
				Multiplier = -1;
			if (0 != Multiplier)
			{
				var YearSpan = parseInt(NewYear.substring(1, NewYear.length),10);
				this.CurrentYear = this.CurrentYear + (Multiplier * YearSpan);
			}
		} else
			this.CurrentYear = NewYear;
		if (this.CurrentYear < 1890)
			this.CurrentYear = 1890;
		if (this.CurrentYear > 2099)
			this.CurrentYear = 2099;
		this.updateDate();
		this.endChange("y");
	}
	this.setCurrentMonth = function(NewMonth)
	{
		this.beginChange();
		if (typeof (NewMonth) == "string")
		{
			var Multiplier = 0;
			if (NewMonth.indexOf("+") == 0)
				Multiplier = 1;
			if (NewMonth.indexOf("-") == 0)
				Multiplier = -1;
			if (0 != Multiplier)
			{
				var MonthSpan = parseInt(NewMonth.substring(1, NewMonth.length),10);
				var NextMonth = this.CurrentMonth + (Multiplier * MonthSpan);
				while (NextMonth < 0)
				{
					NextMonth += 12;
					this.CurrentYear--;
				}
				while (NextMonth >= 12)
				{
					NextMonth -= 12;
					this.CurrentYear++;
				}
				this.CurrentMonth = NextMonth;
			}
		} else
			this.CurrentMonth = NewMonth;
		this.updateDate();
		this.endChange("m");
	}
	this.setCurrentDay = function(NewDay)
	{
		this.beginChange();
		if (typeof (NewDay) == "string")
		{
			var Multiplier = 0;
			if (NewDay.indexOf("+") == 0)
				Multiplier = 1;
			if (NewDay.indexOf("-") == 0)
				Multiplier = -1;
			if (0 != Multiplier)
			{
				var DaySpan = parseInt(NewDay.substring(1, NewDay.length),10);
				var NextDay = this.CurrentDay + (Multiplier * DaySpan);
				this.CurrentDay = NextDay;
			}
		} else
			this.CurrentDay = NewDay;
		this.updateDate();
		this.endChange("d");
	}
	this.setCurrentHour = function(NewHour)
	{
		this.beginChange();
		if (typeof (NewHour) == "string")
		{
			var Multiplier = 0;
			if (NewHour.indexOf("+") == 0)
				Multiplier = 1;
			if (NewHour.indexOf("-") == 0)
				Multiplier = -1;
			if (0 != Multiplier)
			{
				var HourSpan = parseInt(NewHour.substring(1, NewHour.length),10);
				this.CurrentHour = this.CurrentHour + (Multiplier * HourSpan);
			}
		} else
			this.CurrentHour = NewHour;
		while (this.CurrentHour < 0)
			this.CurrentHour += 24;
		this.CurrentHour = this.CurrentHour % 24;
		this.updateDate();
		this.endChange("h");
	}
	this.setCurrentMinute = function(NewMinute)
	{
		this.beginChange();
		if (typeof (NewMinute) == "string")
		{
			var Multiplier = 0;
			if (NewMinute.indexOf("+") == 0)
				Multiplier = 1;
			if (NewMinute.indexOf("-") == 0)
				Multiplier = -1;
			if (0 != Multiplier)
			{
				var MinuteSpan = parseInt(NewMinute.substring(1, NewMinute.length),10);
				this.CurrentMinute = this.CurrentMinute + (Multiplier * MinuteSpan);
			}
		} else
			this.CurrentMinute = NewMinute;
		while (this.CurrentMinute < 0)
			this.CurrentMinute += 60;
		this.CurrentMinute = this.CurrentMinute % 60;
		this.updateDate();
		this.endChange("n");
	}
	this.invertAmFlag = function()
	{
		if (this.CurrentHour < 12)
			this.setCurrentHour("+12");
		else
			this.setCurrentHour("-12");
	}
	this.getMonthWeeks = function()
	{
		var CurrentMonth = this.CurrentMonth;
		var CurrentYear = this.CurrentYear;
		var PrevYear = CurrentYear;
		var NextYear = CurrentYear;
		var PrevMonth = CurrentMonth - 1;
		if (PrevMonth < 0)
		{
			PrevMonth = 11;
			PrevYear--;
		}
		var NextMonth = CurrentMonth + 1;
		if (NextMonth > 11)
		{
			NextMonth = 0;
			NextYear++;
		}
		var CurrentDays = DatePickerEvents.getDaysInMonth(CurrentMonth, CurrentYear);
		var PrevDays = DatePickerEvents.getDaysInMonth(PrevMonth, PrevYear);
		var NextDays = DatePickerEvents.getDaysInMonth(NextMonth, NextYear);
		var Weeks = new Array();
		var WeekIdx = 0;
		var dt = new Date(CurrentYear, CurrentMonth, 1);
		var DayIdx = (this.IsSundayFirst) ? dt.getDay() % 7 : (dt.getDay() + 6) % 7;
		var WeekIdx = 0;
		// processing current month
		for (var i = 1; i <= CurrentDays; i++)
		{
			var Week = Weeks[WeekIdx];
			if (typeof (Week) == "undefined")
			{
				Week = new Array();
				Weeks[WeekIdx] = Week;
			}
			Week[DayIdx] = { Index: DayIdx, No: i, IsPrevMonth: false, IsCurrentMonth: true, IsNextMonth: false, IsActive: (i == this.CurrentDay) };
			DayIdx++;
			if (DayIdx > 6)
			{
				DayIdx = 0;
				WeekIdx++;
			}
		}
		// processing prev month
		var Week = Weeks[0];
		var DayIdx = PrevDays;
		for (var i = 6; i >= 0; i--)
		{
			if (typeof (Week[i]) == "undefined")
			{
				Week[i] = { Index: i, No: DayIdx, IsPrevMonth: true, IsCurrentMonth: false, IsNextMonth: false, IsActive: false };
				DayIdx--;
			}
		}
		// processing next month
		var Week = Weeks[Weeks.length - 1];
		var DayIdx = 1;
		for (var i = 0; i < 7; i++)
		{
			if (typeof (Week[i]) == "undefined")
			{
				Week[i] = { Index: i, No: DayIdx, IsPrevMonth: false, IsCurrentMonth: false, IsNextMonth: true, IsActive: false };
				DayIdx++;

			}
		}
		return Weeks;
	}
	this.setPMD = function(Cell, DayNo, CloseDropDown)
	{
		this.beginChange();
		var Item = "d";
		var CurrentMonth = this.CurrentMonth;
		var CurrentDay = this.CurrentDay;
		this.setCurrentDay(1);
		this.setCurrentMonth("-1");
		var dn = parseInt(DayNo,10);
		if (isNaN(dn))
		{
			Item = "m";
			dn = CurrentDay;
			var CurrentYear = this.CurrentYear;
			var PrevYear = CurrentYear;
			var PrevMonth = CurrentMonth - 1;
			if (PrevMonth < 0)
			{
				PrevMonth = 11;
				PrevYear--;
			}
			var PrevDays = DatePickerEvents.getDaysInMonth(PrevMonth, PrevYear);
			if (dn > PrevDays)
				dn = PrevDays;
		}
		this.setCurrentDay(dn);

		// rerender when change date
		if (!CloseDropDown)
		{
			var Node = Cell.RefreshNode;
			if (Node)
				this.render(Node);
		}
		this.endChange(Item, CloseDropDown);
		if (CloseDropDown)
			this.closeDropDown();
	}
	this.setPY = function(Cell)
	{
		this.beginChange();
		var CurrentMonth = this.CurrentMonth;
		var dn = this.CurrentDay;
		this.setCurrentDay(1);
		var CurrentYear = this.CurrentYear;
		var PrevYear = CurrentYear - 1;
		var PrevDays = DatePickerEvents.getDaysInMonth(CurrentMonth, PrevYear);
		if (dn > PrevDays)
			dn = PrevDays;
		this.setCurrentDay(dn);
		this.setCurrentYear("-1");

		// processing rerender when change date
		if (!this.DropDownClose)
		{
			var Node = Cell.RefreshNode;
			if (Node)
				this.render(Node);
		}
		this.endChange("y");
	}
	this.setCMD = function(Cell, DayNo, CloseDropDown)
	{
		this.beginChange();
		this.setCurrentDay(parseInt(DayNo,10));
		// processing rerender when change date
		if (!CloseDropDown)
		{
			var Node = Cell.RefreshNode;
			if (Node)
				this.render(Node);
		}
		this.endChange("d", CloseDropDown);
		if (CloseDropDown)
			this.closeDropDown();
	}
	this.setNMD = function(Cell, DayNo, CloseDropDown)
	{
		this.beginChange();
		var Item = "d";
		var CurrentMonth = this.CurrentMonth;
		var CurrentDay = this.CurrentDay;
		this.setCurrentDay(1);
		this.setCurrentMonth("+1");
		var dn = parseInt(DayNo,10);
		if (isNaN(dn))
		{
			Item = "m";
			dn = CurrentDay;
			var CurrentYear = this.CurrentYear;
			var NextYear = CurrentYear;
			var NextMonth = CurrentMonth + 1;
			if (NextMonth > 11)
			{
				NextMonth = 0;
				NextYear++;
			}
			var NextDays = DatePickerEvents.getDaysInMonth(NextMonth, NextYear);
			if (dn > NextDays)
				dn = NextDays;
		}
		this.setCurrentDay(dn);

		// processing rerender when change date
		if (!CloseDropDown)
		{
			var Node = Cell.RefreshNode;
			if (Node)
				this.render(Node);
		}
		this.endChange(Item, CloseDropDown);
		if (CloseDropDown)
			this.closeDropDown();
	}
	this.setNY = function(Cell)
	{
		this.beginChange();
		var CurrentMonth = this.CurrentMonth;
		var dn = this.CurrentDay;
		this.setCurrentDay(1);
		var CurrentYear = this.CurrentYear;
		var NextYear = CurrentYear + 1;
		var NextDays = DatePickerEvents.getDaysInMonth(CurrentMonth, NextYear);
		if (dn > NextDays)
			dn = NextDays;
		this.setCurrentDay(dn);
		this.setCurrentYear("+1");

		// processing rerender when change date
		if (!this.DropDownClose)
		{
			var Node = Cell.RefreshNode;
			if (Node)
				this.render(Node);
		}

		this.endChange("y");
	}
	this.onmouseover = function()
	{
		this.style.textDecoration = "underline";
	}
	this.onmouseout = function()
	{
		this.style.textDecoration = "";
	}
	this.getValue = function()
	{
		var DatePartObj = {};
		var s = this.CurrentDay + "";
		if (s.length < 2)
			s = "0" + s;
		DatePartObj["d"] = s;
		var s = (this.CurrentMonth + 1) + "";
		if (s.length < 2)
			s = "0" + s;
		DatePartObj["m"] = s;
		DatePartObj["y"] = this.CurrentYear;
		var Result = [];
		for (var i = 0; i < 3; i++)
			Result[i] = DatePartObj[this.DateOrder.substr(i, 1)];
		var DateValue = Result.join(this.DateSeparator);
		if (!this.ShowTime)
			return DateValue;
		var TimeValue = "";
		var MinuteValue = this.CurrentMinute + "";
		if (MinuteValue.length < 2)
			MinuteValue = "0" + MinuteValue;
		if (!this.Hour24Mode)
		{
			var HourArr = this.to12hMode(this.CurrentHour)
			TimeValue = HourArr[0] + this.TimeSeparator + MinuteValue + " " + this.TimeAmPm[HourArr[1] ? 0 : 1];
		} else
			TimeValue = this.CurrentHour + this.TimeSeparator + MinuteValue;

		if (this.ShowDate)
			return DateValue + " " + TimeValue;
		else
			return TimeValue;
	}
	this.closeDropDown = function()
	{
		this.onclosedropdown.invoke({DatePicker: this});
	}
	this.onchange = new DatePickerDelegate();
	this.onclosedropdown = new DatePickerDelegate();
}
function DatePickerEventsObject()
{
	this.SelectionLocked = true;
	this.DateSeparator = ".";
	this.TimeSeparator = ":";
	this.DateOrder = "dmy";
	this.Hour24Mode = true;
	this.TimeAmPm = ["ДП", "ПП"];
	this.PopupObject = null;
	this.FocusFromOut = true;
	this.UpDownPressed = false; 
	this.FocusFromMouseDown=false;
	this.getData = function(Editor)
	{
		if (!Editor.Data)
		{
			if (Editor.defaultValue)
			{
				if ((Editor.defaultValue + "").indexOf(this.TimeSeparator) >= 0)
				{
					if ((Editor.defaultValue + "").indexOf(this.DateSeparator) < 0)
					{
						// only time
						Editor.Data =
						{
							Focused: false,
							ShowTime: true,
							ShowDate: false,
							CaretPosItem: "h",
							RenderCounter: 0,
							EditorValue: this.getEditorValue(Editor)
						}
					}
					else
					{	// date & time
						Editor.Data =
						{
							Focused: false,
							ShowTime: true,
							ShowDate: true,
							CaretPosItem: "d",
							RenderCounter: 0,
							EditorValue: this.getEditorValue(Editor)
						}
					}
				}
				else
				{   //only date
					Editor.Data =
						{
							Focused: false,
							ShowTime: false,
							ShowDate: true,
							CaretPosItem: "d",
							RenderCounter: 0,
							EditorValue: this.getEditorValue(Editor)
						}
				}
			}
			else
			{
				//default date only
				Editor.Data =
				{
					Focused: false,
					ShowTime: false,
					ShowDate: true,
					CaretPosItem: "d",
					RenderCounter: 0,
					EditorValue: this.getEditorValue(Editor)
				}
			}
		}
		return Editor.Data;
	}

	this.getEditorValue = function(Editor)
	{
		if (!Editor.ProposedValue)
		{
			if (!document.all)
			{
				Editor.ProposedValue = Editor.getAttribute("ProposedValue");
				if (!Editor.ProposedValue)
					Editor.ProposedValue = Editor.value + "";
			}
			else
				Editor.ProposedValue = Editor.value + "";
			if (Editor.ProposedValue == "")
			{
				// TODO: Инициализируем
				//var s = "{дата}";

				if (typeof (DatePickerResources) != "undefined")
				{
					this.DateSeparator = DatePickerResources.DateSeparator;
					this.DateOrder = DatePickerResources.DateOrder;
					this.TimeAmPm = DatePickerResources.TimeAmPm;
					this.Hour24Mode = DatePickerResources.Hour24Mode;
					this.TimeSeparator = DatePickerResources.TimeSeparator;
				}

				var s = "";
				//debugger;
				this.ShowDate = false;
				this.ShowTime = false;
				if (Editor.getAttribute("showdate") == "true")
					this.ShowDate = true;
				if (Editor.getAttribute("showtime") == "true")
					this.ShowTime = true;

				//debugger;
				var curDate = new Date();
				var sep = "";
				if (this.ShowDate && this.DateOrder != "")
				{
					for (var i = 0; i < this.DateOrder.length; i++)
					{
						var partOfDate = this.DateOrder.substr(i, 1);
						switch (partOfDate)
						{
							case "d":
								var curD = curDate.getDate().toString();
								if (curD.length < 2)
									curD = "0" + curD;
								s += curD;
								break;
							case "m":
								var curM = (curDate.getMonth() + 1).toString();
								if (curM.length < 2)
									curM = "0" + curM;
								s += curM;
								break;
							case "y":
								s += curDate.getFullYear().toString();
								break;
						}

						if (i < this.DateOrder.length - 1)
							sep = this.DateSeparator;
						else
							sep = " ";

						s += sep;
					}
				}

				if (this.ShowTime)
				{
					var h = curDate.getHours();
					var n = curDate.getMinutes().toString();
					if (n.length < 2)
						n = "0" + n;
					var AmFlag = this.TimeAmPm[0];
					if (!this.Hour24Mode)
					{
						if (h > 12)
						{
							h -= 12;
							AmFlag = this.TimeAmPm[1];
						}
						if (h == 0)
						{
							h = 12;
							AmFlag = this.TimeAmPm[1];
						}

						s += h.toString() + this.TimeSeparator + n + " " + AmFlag;
					}
					else
						s += h.toString() + this.TimeSeparator + n;
				}

				Editor.ProposedValue = s;
				Editor.value = s;
				Editor.defaultValue = s;
			}
		}
		else
		{
			if (Editor.ProposedValue != (Editor.value + ""))
				Editor.value = Editor.ProposedValue;
		}
		return Editor.ProposedValue;
	}

	this.setEditorValue = function(Editor, Value)
	{
		Editor.value = Value;
		Editor.ProposedValue = Editor.value + "";
	}

	this.getDaysInMonth = function(Month, Year)
	{
		return 32 - new Date(Year, Month, 32).getDate();
	}
	this.checkObject = function(Sender, SkipCreation)
	{
		if (!Sender.DateObject)
		{
			if (SkipCreation)
				if (Sender.value == "")
				return false;
			Sender.DateObject = new DatePickerObject(this.getEditorValue(Sender));
			Sender.DateObject.EditorNode = Sender;
			if (Sender.getAttribute("dropdownclose") == "false")
				Sender.DateObject.DropDownClose = false;
			if (Sender.getAttribute("showdropdown") == "false")
				Sender.DateObject.ShowDropDown = false;	
			Sender.DateObject.onchange.add(this.ondatepickerchange);
			Sender.DateObject.onclosedropdown.add(this.ondatepickerclosedropdown);
			this.DateSeparator = Sender.DateObject.DateSeparator;
			this.TimeSeparator = Sender.DateObject.TimeSeparator;
			this.DateOrder = Sender.DateObject.DateOrder;
			var Data = this.getData(Sender);
			Data.ShowTime = Sender.DateObject.ShowTime;
			this.Hour24Mode = Sender.DateObject.Hour24Mode;
			this.TimeAmPm = Sender.DateObject.TimeAmPm;
			Data.EditorValue = this.getEditorValue(Sender);
			Data.RenderCounter = 0;
			return true;
		}
	}
	this.beginRender = function(Editor)
	{
		var Data = this.getData(Editor);
		if (Data.RenderCounter == 0)
			Data.CaretPosItem = this.getCaretPosItem(Editor);
		Data.RenderCounter++;
		if (!Data.EditorValue)
			Data.EditorValue = this.getEditorValue(Editor);
	}
	this.endRender = function(Editor, Value, SkipRefresh)
	{	
		var Data = this.getData(Editor);
		Data.RenderCounter--;
		if (typeof (Value) == "string")
			Data.EditorValue = Value;
		if (Data.RenderCounter <= 0)
		{
			Data.RenderCounter = 0;
			var OldValue = this.getEditorValue(Editor);
			var NewValue = Data.EditorValue + "";
			if (OldValue != NewValue)
				this.setEditorValue(Editor, Data.EditorValue);
			this.setCaretPosItem(Editor, Data.CaretPosItem);
			if (!SkipRefresh)
			{
				var OldValueArr = OldValue.split(" ");
				var NewValueArr = NewValue.split(" ");
				var PopupObject = this.PopupObject;
				if (PopupObject)
					if (OldValueArr[0] != NewValueArr[0])
					Editor.DateObject.render(PopupObject);
			}
		}
	}
	this.ondatepickerchange = function(EventArgs)
	{
		DatePickerEvents.datepickerchange(EventArgs);
	}
	this.ondatepickerclosedropdown = function(EventArgs)
	{
		if (DatePickerEvents.PopupObject)
			DatePickerEvents.popup();
		var Picker = EventArgs.DatePicker;
		if (Picker)
		{
			var input = Picker.EditorNode;
			if (input)
			{
				var Attr = input.getAttribute("autopostback");
				if (Attr && (Attr + "").toLowerCase() == "true")
					__doPostBack(input.name);
			}
		}
	}
	this.onblur = function(Sender, Event)
	{
		var Data = this.getData(Sender);
		Data.Focused = false;
		if (this.PopupObject)
			return false;
		this.checkObject(Sender);
		this.validate(Sender);
		var Attr = Sender.getAttribute("autopostback");		
		if (Attr)
			if ((Attr + "").toLowerCase() == "true")
			if (Sender.ValueBeforeFocus)
			if ((Sender.ValueBeforeFocus + "") != (this.getEditorValue(Sender)) || this.UpDownPressed)
				if (this.FocusFromOut || !(navigator.userAgent.indexOf(' Firefox/') > -1))					
					__doPostBack(Sender.name);			
		return false;
	}
	this.ondragstart = function(Sender, Event)
	{
		this.checkObject(Sender);
		return false;
	}
	this.onfocus = function(Sender, Event)
	{
		Sender.ValueBeforeFocus = this.getEditorValue(Sender);
		var Data = this.getData(Sender);
		Data.Focused = true;
		if (this.PopupObject)
			return false;
		this.checkObject(Sender);
		this.beginRender(Sender);
		if (Sender.LastSelected && !this.FocusFromOut)
			Data.CaretPosItem = Sender.LastSelected;
		else
		{
			if (this.FocusFromMouseDown)
				Data.CaretPosItem = this.getCaretPosItem(Sender);	
			else
				this.setStartPos(Sender);
		}
		this.FocusFromMouseDown=false;
		this.endRender(Sender);
		this.FocusFromOut = true;
		return false;
	}
	this.onkeydown = function(Sender, Event)
	{
		this.checkObject(Sender);
		var Data = this.getData(Sender);
		// Data.ShowDate == true then Alt+Down make popup
		if (typeof (Data) != "undefined" && Data.ShowDate == true && Event.altKey && Event.keyCode == 40)
		{
			this.popup(null, Sender);
		}
		else
		{
			if (Event.shiftKey)
			{
				switch (Event.keyCode)
				{
					case 9:
						{	//Shift+Tab
							Data.RenderCounter = 0;
							if (this.PopupObject)
							{
								this.checkObject(this.ActiveEditor);
								this.validate(this.ActiveEditor);
								this.detachEvent(document, "mousedown", this.onpopup);
								this.PopupObject.parentNode.removeChild(this.PopupObject);
								this.PopupObject = null;
								this.ActiveEditor = null;
								this.ActiveButton = null;
							}
							this.FocusFromOut = true;
							if (navigator.userAgent.indexOf(' Firefox/') > -1)
								Sender.blur();
							return true;							
						}
				}
				return false;
			}
			switch (Event.keyCode)
			{
				case 9:
					{	//Tab
						Data.RenderCounter = 0;
						if (this.PopupObject)
						{
							this.checkObject(this.ActiveEditor);
							this.validate(this.ActiveEditor);
							this.detachEvent(document, "mousedown", this.onpopup);
							this.PopupObject.parentNode.removeChild(this.PopupObject);
							this.PopupObject = null;
							this.ActiveEditor = null;
							this.ActiveButton = null;
						}
						this.FocusFromOut = true;
						if (navigator.userAgent.indexOf(' Firefox/') > -1)
							Sender.blur();
						return true;						
					}
				case 13:
					{
						this.validate(Sender);
						return false;
					}
				case 8:
					{
						this.beginRender(Sender);
						var i = Data.CaretPosItem;
						var s = this.getEditorSymbols(Sender, i);
						s = "0" + s;
						var MaxLen = 2;
						if (i == "y")
							MaxLen = 4;
						if (s.length > MaxLen)
							s = s.substr(0, MaxLen)
						this.setEditorSymbols(Sender, i, s);
						this.endRender(Sender);
						return false;
					}
				case 48:
				case 49:
				case 50:
				case 51:
				case 52:
				case 53:
				case 54:
				case 55:
				case 56:
				case 57:
					{
						var Char = Event.keyCode - 48;
						this.addCharacter(Sender, Char);
						return false;
					}
				case 96:
				case 97:
				case 98:
				case 99:
				case 100:
				case 101:
				case 102:
				case 103:
				case 104:
				case 105:
					{
						var Char = Event.keyCode - 96;
						this.addCharacter(Sender, Char);
						return false;
					}
				case 37:
					{
						this.beginRender(Sender);
						var DateTimeOrder = this.DateOrder;
						if (Data.ShowTime)
						{
							DateTimeOrder += "hn";
							if (!this.Hour24Mode)
								DateTimeOrder += "a";
						}
						var i = DateTimeOrder.indexOf(Data.CaretPosItem);
						var Result = true;
						if (i > 0)
							i--;
						else
							Result = false;
						if (Result)
						{
							Data.CaretPosItem = DateTimeOrder.substr(i, 1);
							this.validate(Sender);
						}
						this.endRender(Sender);
						return Result;
					}
				case 39:
				case 109:
				case 110:
				case 111:
				case 189:
				case 190:
				case 191:
					{
						this.beginRender(Sender);
						var SelItem = Data.CaretPosItem;
						var DateTimeOrder = this.DateOrder;
						if (Data.ShowTime)
						{
							DateTimeOrder += "hn";
							if (!this.Hour24Mode)
								DateTimeOrder += "a";
						}
						var Result = true;
						var i = DateTimeOrder.indexOf(SelItem);
						if (i < (DateTimeOrder.length - 1))
							i++;
						else
							Result = false;
						if (Result)
						{
							Data.CaretPosItem = DateTimeOrder.substr(i, 1);
							this.validate(Sender);
						}
						this.endRender(Sender);
						return Result;
					}
				case 38:
					{
						this.beginRender(Sender);
						this.validate(Sender);
						this.setCurrentItem(Sender, Data.CaretPosItem, "+1");
						this.endRender(Sender);
						return false;
					}
				case 40:
					{
						if (!Event.altKey)
						{
							this.beginRender(Sender);
							this.validate(Sender);
							this.setCurrentItem(Sender, Data.CaretPosItem, "-1");
							this.endRender(Sender);
							return false;
						}
					}
			} return false;
		}
		//return false;
	}
	this.onkeypress = function(Sender, Event)
	{
		this.checkObject(Sender);
		return false;
	}
	this.onkeyup = function(Sender, Event)
	{
		this.checkObject(Sender);
		this.selectNumber(Sender);
		return false;
	}
	this.onmousedown = function(Sender, Event)
	{
		this.checkObject(Sender);
		var curData = this.getData(Sender);
		this.FocusFromMouseDown=true;
		var leftClick = Sender.getAttribute("leftclickoperate");
		if (typeof (curData) != "undefined" && (this.DateOrder).indexOf(curData.CaretPosItem) >= 0 && (leftClick == "popup"))
		{
			//render calendar on left click	if flag leftClickOperate="popup" and content is a date
			this.popup(null, Sender);
			return true;
		}
		else
		{
			if (!document.all)
			{
				this.SelectionLocked = false;
				Sender.selectionEnd = Sender.selectionStart;
				this.SelectionLocked = true;
			}
			return true;
		}
	}
	this.onmousemove = function(Sender, Event)
	{
		if (Sender.disabled)
			return false;
		if (!this.checkObject(Sender, true))
			return false;
		var Data = this.getData(Sender);
		if (Data.Focused)
			return true;
		this.getEditorValue(Sender);
		return true;
	}
	this.onmouseup = function(Sender, Event)
	{
		if (Sender.disabled)
			return false;
		this.checkObject(Sender);
		this.selectNumber(Sender);
		return true;
	}
	this.onselect = function(Sender, Event)
	{
		this.checkObject(Sender);
		return false;
	}
	this.onselectstart = function(Sender, Event)
	{
		//this.checkObject(Sender);
		return !this.SelectionLocked;
	}
	this.onpaste = function(Sender, Event)
	{
		this.checkObject(Sender);
		return false;
	}
	this.onmousewheel = function(Sender, Event)
	{
		if (Sender.disabled)
			return false;
		var Data = this.getData(Sender);
		if (!Data.Focused)
			return true;
		var IsDown = event.wheelDelta < 0;
		this.xCrease(Sender, !IsDown);
		return false;
	}
	this.addCharacter = function(Sender, Char)
	{
		this.beginRender(Sender);
		var i = this.getData(Sender).CaretPosItem;
		var s = this.getEditorSymbols(Sender, i);
		s += Char;
		while ((s.indexOf("0") == 0) && (s.length > 1))
			s = s.substring(1, s.length);
		var tst = parseInt(s,10);
		switch (i)
		{
			case "h":
				if (this.Hour24Mode)
				{
					while (tst > 23)
					{
						s = s.substring(1, s.length);
						tst = parseInt(s,10);
					}
					while ((s.indexOf("0") == 0) && (s.length > 1))
						s = s.substring(1, s.length);
				} else
				{
					while (tst > 12)
					{
						s = s.substring(1, s.length);
						tst = parseInt(s,10);
					}
				}
				break;
			case "n":
				while (tst > 60)
				{
					s = s.substring(1, s.length);
					tst = parseInt(s,10);
				}
				if (s.length < 2)
					s = "0" + s;
				break;
		}
		var MaxLen = this.getItemMaxLength(i);
		if (s.length > MaxLen)
			s = s.substr(s.length - MaxLen, MaxLen)
		this.setEditorSymbols(Sender, i, s);
		this.endRender(Sender);
	}
	this.getItemMaxLength = function(Item)
	{
		switch (Item)
		{
			case "d":
			case "m":
			case "h":
			case "n":
				return 2;
			case "y":
				return 4;
		}
		return 0;
	}
	this.getCaretPos = function(EditorNode)
	{
		/// <param name="EditorNode" mayBeNull="false" type="Object">Input type=text node</param>
		/// <returns type="Number">Caret position of input node</returns>        
		//debugger;
		if (document.selection)
		{
			var R = document.selection.createRange();
			R.moveStart("character", -this.getData(EditorNode).EditorValue.length);
			return (R.text + "").length;
		} else
		{
			return EditorNode.selectionEnd;
		}
		return 0;
	}
	this.getCaretPosItem = function(EditorNode)
	{
		/// <param name="EditorNode" mayBeNull="false" type="Object">Input type=text node</param>
		/// <returns type="String">Caret pos in "d" - day, "m" - month, "y" - year, "h" - hour, "n" - minute, "a" - am/pm</returns>
		var Pos = this.getCaretPos(EditorNode);
		var s = this.getData(EditorNode).EditorValue;
		var ShowDateOnly = !this.getData(EditorNode).ShowTime;
		var ShowTimeOnly = !this.getData(EditorNode).ShowDate;
		//debugger;

		if (!ShowTimeOnly)
		{
			if (!ShowDateOnly)
			{
				var DatePos = s.indexOf(" ");
				if (Pos <= DatePos)
					ShowDateOnly = true;
				if (!ShowDateOnly)
				{ // show time
					if (!this.Hour24Mode) // check for am
					{
						var AmPos = s.lastIndexOf(" ");
						if (AmPos != DatePos)
							if (Pos > AmPos)
							return "a";
					}
					var MinutePos = s.indexOf(EditorNode.DateObject.TimeSeparator, DatePos);
					if (Pos <= MinutePos)
						return "h";
					return "n";
				}
			}

			if (ShowDateOnly)
			{
				var MonthPos = s.indexOf(this.DateSeparator);
				var YearPos = s.lastIndexOf(this.DateSeparator);
				if (Pos <= MonthPos)
					return this.DateOrder.substr(0, 1);
				if (Pos <= YearPos)
					return this.DateOrder.substr(1, 1);
				return this.DateOrder.substr(2, 1);
			}
		}
		else
		{
			// show time only
			if (!this.Hour24Mode) // check for am
			{
				var AmPos = s.lastIndexOf(" ");
				if (AmPos != DatePos)
					if (Pos > AmPos)
					return "a";
			}
			//debugger;
			var hpos = s.indexOf(this.TimeSeparator);
			if (Pos <= hpos)
				return "h";
			else
				return "n";
		}
	}
	this.setCaretPosItem = function(EditorNode, ItemName)
	{
		/// <param name="EditorNode" mayBeNull="false" type="Object">Input type=text node</param>
		/// <param name="ItemName" mayBeNull="false" type="String">Caret pos in "d" - day, "m" - month, "y" - year, "h" - hour, "n" - minute, "a" - am/pm</param>
		
		var Data = this.getData(EditorNode);
		if (!Data.Focused)
			return;
		if (document.selection)
		{
			EditorNode.focus();
			var s = Data.EditorValue;
			var R = EditorNode.createTextRange();
			R.moveStart("character", -s.length);
			R.moveEnd("character", -s.length);
			var TimePos = -1;
			if (Data.ShowDate)
			{
				var TimePos = s.indexOf(" ");
				if (TimePos < 0)
					TimePos = s.length;
			}
			if (Data.ShowTime)
				if ("hna".indexOf(ItemName) >= 0)
			{
				var MinutePos = s.indexOf(EditorNode.DateObject.TimeSeparator, TimePos);
				var AmPos = s.length;
				if (!this.Hour24Mode)
					AmPos = s.lastIndexOf(" ");
				switch (ItemName)
				{
					case "h":
						R.moveStart("character", TimePos + 1);
						R.moveEnd("character", MinutePos - TimePos - 1);
						break;
					case "n":
						R.moveStart("character", MinutePos + 1);
						R.moveEnd("character", AmPos - MinutePos - 1);
						break;
					case "a":
						R.moveStart("character", AmPos + 1);
						R.moveEnd("character", s.length);
						break;
				}
				this.SelectionLocked = false;
				R.select();
				this.SelectionLocked = true;
				EditorNode.LastSelected = ItemName;
				return;
			}
			if (Data.ShowDate)
			{
				var f = s.indexOf(this.DateSeparator);
				var l = s.lastIndexOf(this.DateSeparator);
				switch (this.DateOrder.indexOf(ItemName))
				{
					case 0:
						//R.moveStart("character", 0);
						R.moveEnd("character", f);
						break;
					case 1:
						R.moveStart("character", f + 1);
						R.moveEnd("character", l - f - 1);
						break;
					default:
						R.moveStart("character", l + 1);
						R.moveEnd("character", TimePos - l - 1);
						break;
				}
				this.SelectionLocked = false;
				R.select();
				this.SelectionLocked = true;
			}
		} else
		{
			EditorNode.focus();
			var s = Data.EditorValue;
			var TimePos = -1;
			if (Data.ShowDate)
			{
				var TimePos = s.indexOf(" ");
				if (TimePos < 0)
					TimePos = s.length;
			}
			if (Data.ShowTime)
				if ("hna".indexOf(ItemName) >= 0)
			{
				var MinutePos = s.indexOf(EditorNode.DateObject.TimeSeparator, TimePos);
				var AmPos = s.length;
				if (!this.Hour24Mode)
					AmPos = s.lastIndexOf(" ");
				this.SelectionLocked = false;
				switch (ItemName)
				{
					case "h":
						EditorNode.selectionStart = TimePos + 1;
						EditorNode.selectionEnd = MinutePos;
						break;
					case "n":
						EditorNode.selectionStart = MinutePos + 1;
						EditorNode.selectionEnd = AmPos;
						break;
					case "a":
						EditorNode.selectionStart = AmPos + 1;
						EditorNode.selectionEnd = s.length;
						break;
				}
				this.SelectionLocked = true;
				EditorNode.LastSelected = ItemName;
				return;
			}
			if (Data.ShowDate)
			{
				var f = s.indexOf(this.DateSeparator);
				var l = s.lastIndexOf(this.DateSeparator);
				this.SelectionLocked = false;
				switch (this.DateOrder.indexOf(ItemName))
				{
					case 0:
						EditorNode.selectionStart = 0;
						EditorNode.selectionEnd = f;
						break;
					case 1:
						EditorNode.selectionStart = f + 1;
						EditorNode.selectionEnd = l;
						break;
					default:
						EditorNode.selectionStart = l + 1;
						EditorNode.selectionEnd = TimePos;
						break;
				}
				this.SelectionLocked = true;
			}
		}
		EditorNode.LastSelected = ItemName;
	}
	this.selectNumber = function(EditorNode)
	{
		/// <param name="EditorNode" mayBeNull="false" type="Object">Input type=text node</param>
		this.beginRender(EditorNode);
		var i = this.getData(EditorNode).CaretPosItem;
		this.endRender(EditorNode);
		return i;
	}
	this.setStartPos = function(EditorNode)
	{
		this.beginRender(EditorNode);
		var Data = this.getData(EditorNode);
		var i = "";
		if (Data.ShowDate)
			i = (this.DateOrder).substring(0, 1);
		else
			if (Data.ShowTime)
			i = "h";
		else
			i = this.selectNumber(EditorNode);
		Data.CaretPosItem = i;
		this.endRender(EditorNode);
		this.UpDownPressed = false;
		return i;
	}
	this.getEditorSymbols = function(EditorNode, ItemName)
	{
		/// <param name="ItemName" type="String">d - day, m - month, y - year, h - hour, n - minute, a - amflag</param>
		/// <returns type="String">One or two-symboled string</returns>
		var Data = this.getData(EditorNode);
		if (Data.RenderCounter == 0)
			throw "Method getEditorSymbols() must be called between beginRender() and endRender() methods";
		if ("dmy".indexOf(ItemName) >= 0)
		{
			var s = Data.EditorValue;
			var f = s.indexOf(this.DateSeparator);
			var l = s.lastIndexOf(this.DateSeparator);
			var t = s.length;
			if (Data.ShowTime)
				t = s.indexOf(" ");
			switch (this.DateOrder.indexOf(ItemName))
			{
				case 0:
					return s.substring(0, f);
				case 1:
					return s.substring(f + 1, l);
				default:
					return s.substring(l + 1, t);
			}
		}
		if ("hna".indexOf(ItemName) >= 0)
		{
			var s = Data.EditorValue;
			var sarr = s.split(" ");
			if (Data.ShowDate)
			{
				if (sarr.length < 2)
					return "";
				s = sarr[1];
			}
			else
			{
				s = sarr[0];
			}
			var hmarr = s.split(this.TimeSeparator);
			switch (ItemName)
			{
				case "h":
					return hmarr[0];
				case "n":
					return hmarr[1];
				case "a":
					{
						if (Data.ShowDate)
							return sarr[2];
						else
							return sarr[1];
					}

			}
		}
		return "";
	}
	this.setEditorSymbols = function(EditorNode, ItemName, Value, IgnorePosition)
	{
		/// <param name="EditorNode" mayBeNull="false" type="Object">Input type=text node</param>
		/// <param name="ItemNo" type="String">d - day, m - month, y - year</param>
		/// <param name="Value" type="String">string value</param>
		this.beginRender(EditorNode);
		var Data = this.getData(EditorNode);
		if (!IgnorePosition)
			var iname = Data.CaretPosItem;
		var DatePartObj = { d: this.getEditorSymbols(EditorNode, "d"), m: this.getEditorSymbols(EditorNode, "m"), y: this.getEditorSymbols(EditorNode, "y") };
		if (Data.ShowTime)
		{
			DatePartObj["h"] = this.getEditorSymbols(EditorNode, "h");
			DatePartObj["n"] = this.getEditorSymbols(EditorNode, "n");
			if (!this.Hour24Mode)
				DatePartObj["a"] = this.getEditorSymbols(EditorNode, "a");
		}
		DatePartObj[ItemName] = Value;
		var DateValue = [];
		for (var i = 0; i < 3; i++)
			DateValue[i] = DatePartObj[this.DateOrder.substr(i, 1)];
		var DateValueStr = DateValue.join(this.DateSeparator);
		if (Data.ShowDate)
		{
			if (Data.ShowTime)
			{
				DateValueStr += " " + DatePartObj["h"] + this.TimeSeparator + DatePartObj["n"];
				if (!this.Hour24Mode)
					DateValueStr += " " + DatePartObj["a"];
			}
		}
		else
		{
			DateValueStr = DatePartObj["h"] + this.TimeSeparator + DatePartObj["n"];
			if (!this.Hour24Mode)
				DateValueStr += " " + DatePartObj["a"];
		}
		if (!IgnorePosition)
			Data.CaretPosItem = iname;
		this.endRender(EditorNode, DateValueStr);
	}
	this.setCurrentItem = function(EditorNode, ItemName, Value)
	{
		/// <param name="EditorNode" mayBeNull="false" type="Object">Input type=text node</param>
		/// <param name="ItemName" type="String">d - day, m - month, y - year, h - hour, n - minute, a - am/pm</param>
		/// <param name="Value">item value</param>
		this.beginRender(EditorNode);
		//debugger;
		switch (ItemName)
		{
			case "d":
				EditorNode.DateObject.setCurrentDay(Value);
				break;
			case "m":
				EditorNode.DateObject.setCurrentMonth(Value);
				break;
			case "y":
				EditorNode.DateObject.setCurrentYear(Value);
				break;
			case "h":
				EditorNode.DateObject.setCurrentHour(Value);
				break;
			case "n":
				EditorNode.DateObject.setCurrentMinute(Value);
				break;
			case "a":
				EditorNode.DateObject.invertAmFlag();
				break;
			default:
				return;
		}
		this.getData(EditorNode).CaretPosItem = ItemName;
		this.endRender(EditorNode, EditorNode.DateObject.getValue());
	}

	this.setNow = function(EditorNode)
	{
		/// <summary>set current system date</summary>
		/// <param name="EditorNode" mayBeNull="false" type="Object">Input type=text node</param>
		this.setDate(EditorNode, new Date());
	}
	this.setDate = function(EditorNode, DateValue)
	{
		/// <summary>set custom date</summary>
		/// <param name="EditorNode" mayBeNull="false" type="Object">Input type=text node</param>
		/// <param name=DateValue type="Object"> Input type=Date object</param>
		//debugger;
		this.checkObject(EditorNode);
		this.beginRender(EditorNode);
		EditorNode.DateObject.setCurrentDay(DateValue.getDate());
		EditorNode.DateObject.setCurrentMonth(DateValue.getMonth());
		EditorNode.DateObject.setCurrentYear(DateValue.getFullYear());
		EditorNode.DateObject.setCurrentHour(DateValue.getHours());
		EditorNode.DateObject.setCurrentMinute(DateValue.getMinutes());
		this.endRender(EditorNode, EditorNode.DateObject.getValue());
	}

	this.validate = function(EditorNode)
	{
		/// <param name="EditorNode" mayBeNull="false" type="Object">Input type=text node</param>
		this.beginRender(EditorNode);
		var Data = this.getData(EditorNode);
		var ItemName = Data.CaretPosItem;
		//debugger;
		if (Data.ShowDate)
		{
			var Day = this.getEditorSymbols(EditorNode, "d") + "";
			while (Day.indexOf("0") == 0)
				Day = Day.substr(1, Day.length - 1);
			Day = parseInt(Day,10);
			if (isNaN(Day))
				Day = 1;
			var Month = this.getEditorSymbols(EditorNode, "m") + "";
			while (Month.indexOf("0") == 0)
				Month = Month.substr(1, Month.length - 1);
			Month = parseInt(Month,10);
			if (isNaN(Month))
				Month = 1;
			var Year = this.getEditorSymbols(EditorNode, "y") + "";
			while (Year.indexOf("0") == 0)
				Year = Year.substr(1, Year.length - 1);
			Year = parseInt(Year,10);
			if (isNaN(Year))
				Year = (new Date()).getFullYear();
		}
		if (Data.ShowTime)
		{
			var Hour = this.getEditorSymbols(EditorNode, "h") + "";
			var Minute = this.getEditorSymbols(EditorNode, "n") + "";
			while ((Minute.indexOf("0") == 0) && (Minute.length > 1))
				Minute = Minute.substring(1, Minute.length);
			Minute = parseInt(Minute,10);
			Minute = Minute % 60;
			if (!this.Hour24Mode)
			{
				var AmFlag = this.getEditorSymbols(EditorNode, "a") + "";
				Hour = parseInt(Hour,10);
				Hour = Hour % 12;
				if (Hour == 0)
					Hour = 12;
				Hour = EditorNode.DateObject.to24hMode(Hour, (AmFlag.toLowerCase() != this.TimeAmPm[1].toLowerCase()));
			} else
			{
				Hour = parseInt(Hour,10);
				Hour = Hour % 24;
			}
		}

		if (Data.ShowDate)
		{
			if (Day < 1)
				Day = 1;
			if (Month < 1)
				Month = 1;
			if (Month > 12)
				Month = 12;
			if (Year < 100)
				Year = (Year >= 50) ? 1900 + Year : 2000 + Year;
//			if (Year < 1890)
//				Year = 1890;
//			if (Year > 2099)
//				Year = 2099;

			//check min max
			var minday = parseInt(EditorNode.getAttribute("minday"),10);
			var minmonth = parseInt(EditorNode.getAttribute("minmonth"),10);
			var minyear = parseInt(EditorNode.getAttribute("minyear"),10);

			var maxday = parseInt(EditorNode.getAttribute("maxday"),10);
			var maxmonth = parseInt(EditorNode.getAttribute("maxmonth"),10);
			var maxyear = parseInt(EditorNode.getAttribute("maxyear"),10);
			// min
			if (Year < minyear)
			{
				Year = minyear;
				Month = minmonth;
				Day = minday;
			}
			if (Year == minyear && Month < minmonth)
			{
				Month = minmonth;
				Day = minday;
			}
			if (Year == minyear && Month == minmonth && Day < minday)
				Day = minday;
			// max	
			if (Year > maxyear)
			{
				Year = maxyear;
				Month = maxmonth;
				Day = maxday;
			}
			if (Year == maxyear && Month > maxmonth)
			{
				Month = maxmonth;
				Day = maxday;
			}
			if (Year == maxyear && Month == maxmonth && Day > maxday)
				Day = maxday;
					
			var AvailableDays = this.getDaysInMonth(Month - 1, Year);
			if (Day > AvailableDays)
				Day = AvailableDays;
			EditorNode.DateObject.setCurrentDay(Day);
			EditorNode.DateObject.setCurrentMonth(Month - 1);
			EditorNode.DateObject.setCurrentYear(Year);
			Day = Day + "";
			Month = Month + "";
			if (Day.length < 2)
				Day = "0" + Day;
			if (Month.length < 2)
				Month = "0" + Month;
			var DatePartObj = { "d": Day, "m": Month, "y": Year };
			var DateValue = [];
			for (var i = 0; i < 3; i++)
				DateValue[i] = DatePartObj[this.DateOrder.substr(i, 1)];
			var DateSource = DateValue.join(this.DateSeparator);
			var NodeValue = "";
		}
		if (Data.ShowTime)
		{
			EditorNode.DateObject.setCurrentMinute(parseInt(Minute,10));
			Minute = Minute + "";
			if (Minute.length == 1)
				Minute = "0" + Minute;
			if (this.Hour24Mode)
				var TimeSource = Hour + EditorNode.DateObject.TimeSeparator + Minute;
			else
			{
				var HourAm = EditorNode.DateObject.to12hMode(Hour);
				var TimeSource = HourAm[0] + EditorNode.DateObject.TimeSeparator + Minute + " " + EditorNode.DateObject.TimeAmPm[(HourAm[1] ? 0 : 1)];
			}
			EditorNode.DateObject.setCurrentHour(parseInt(Hour,10));
			if (Data.ShowDate)
				NodeValue = DateSource + " " + TimeSource;
			else
				NodeValue = TimeSource;
		}
		else
			NodeValue = DateSource;
		if (Data.RenderCounter == 0)
			Data.CaretPosItem = ItemName;
		this.endRender(EditorNode, NodeValue);
	}
	this.calculateOffset = function(Node)
	{
		var curleft = curtop = 0;
		while (Node)
		{
			curleft += Node.offsetLeft;
			curtop += Node.offsetTop - Node.scrollTop;
			Node = Node.offsetParent;
		}
		return { X: curleft, Y: curtop };
	}
	this.attachEvent = function(Node, EventName, Func)
	{
		if (Node.attachEvent)
			Node.attachEvent("on" + EventName, Func);
		else
			Node.addEventListener(EventName, Func, false);
	}
	this.detachEvent = function(Node, EventName, Func)
	{
		if (Node.detachEvent)
			Node.detachEvent("on" + EventName, Func);
		else
			Node.removeEventListener(EventName, Func, false);
	}
	this.contains = function(Source, Target)
	{
		if (typeof (Target) == 'undefined')
			return false;
		if (Source.contains)
			return Source.contains(Target);
		while (Target.parentNode)
			if ((Target = Target.parentNode) == Source)
			return true;
		return false;
	}
	this.onpopup = function(Event)
	{
		if (!Event)
			Event = event;
		var Node = Event.srcElement;
		if (!Node)
			Node = Event.target;
		if (DatePickerEvents.PopupObject)
		{
			if (DatePickerEvents.contains(DatePickerEvents.PopupObject, Node))
				return;
			if (Node == DatePickerEvents.ActiveEditor)
				return;
			if (Node == DatePickerEvents.ActiveButton)
				return;
		}
		DatePickerEvents.popup();
	}
	this.getEditorNode = function(ButtonNode)
	{
		var EditorNode = ButtonNode.parentNode.parentNode;
		var TempNodes = EditorNode.getElementsByTagName("INPUT");
		EditorNode = null;
		for (var i = 0; i < TempNodes.length; i++)
		{
			var TempNode = TempNodes.item(i);
			if (TempNode.type)
				if ((TempNode.type + "").toLowerCase() == "text")
			{
				EditorNode = TempNode;
				break;
			}
		}
		if (!EditorNode)
			EditorNode = ButtonNode.nextSibling;
		return EditorNode;
	}
	this.popup = function(ButtonNode, EditorNode)
	{
		
		if (typeof (PanelComboManager) != "undefined" && PanelComboManager && PanelComboManager.ActiveCombo)
			return PanelComboManager.close();
		if (typeof (TreeComboManager) != "undefined" && TreeComboManager && TreeComboManager.ActiveCombo)
			return TreeComboManager.close();
		if (this.PopupObject)
		{
			this.checkObject(this.ActiveEditor);
			this.validate(this.ActiveEditor);
			this.detachEvent(document, "mousedown", this.onpopup);
			this.detachEvent(window, "resize", this.onpopup);
			this.PopupObject.parentNode.removeChild(this.PopupObject);
			this.PopupObject = null;
			if (typeof (ButtonNode) == "undefined" && typeof (EditorNode) == "undefined")
				this.onblur(this.ActiveEditor, null)
			this.ActiveEditor = null;
			this.ActiveButton = null;
			return;
		}
		if (typeof (EditorNode) == "undefined")
			EditorNode = this.getEditorNode(ButtonNode);
		if (EditorNode.disabled)
			return false;

		window.clearTimeout(this.PostBackTimeout);	
		
		this.checkObject(EditorNode);
		var Data = this.getData(EditorNode);
		this.validate(EditorNode);
		var Div = document.getElementById("DatePickerPopupObject");
		if (!Div)
		{
			var Div = document.createElement("DIV");
/*			if (App.JQAnimate)
				$(Div).css("opacity", 0);
*/
			document.body.insertBefore(Div, document.body.firstChild);
			Div.id = "DatePickerPopupObject";
			Div.style.position = "absolute";
			Div.style.backgroundColor = "#ffffff";
			//Div.style.border = "1px solid #aaaaaa";
			Div.style.zIndex = 900;
/*			if (App.JQAnimate)
				$(Div).animate({ opacity: 1 }, App.JQAnimateTime);
*/
			//Div.style.cssText = "filter: progid:DXImageTransform.Microsoft.Shadow(direction=135,color=#cccccc,strength=5);";
		}
		var Coords = this.calculateOffset(EditorNode.parentNode.parentNode.parentNode);
		var leftCorrection = 0;
		if (navigator.userAgent.indexOf(' Firefox/') > -1)
			leftCorrection = 0;
		else
			leftCorrection = -1;
		Div.style.left = Coords.X +leftCorrection + "px";
		Div.style.top = (Coords.Y+2 + EditorNode.parentNode.parentNode.parentNode.offsetHeight) + "px";
		EditorNode.DateObject.render(Div);
		this.PopupObject = Div;
		this.ActiveEditor = EditorNode;
		this.ActiveButton = ButtonNode;
		this.attachEvent(document, "mousedown", this.onpopup);
		this.attachEvent(window, "resize", this.onpopup);
		if (!this.ActiveEditor.ValueBeforeFocus)
			this.ActiveEditor.ValueBeforeFocus = this.getEditorValue(this.ActiveEditor);
	}
	this.datepickerchange = function(EventArgs)
	{
		if (this.ActiveEditor)
		{
			this.beginRender(this.ActiveEditor);
			var Data = this.getData(this.ActiveEditor);
			if (Data.RenderCounter == 0)
			{
				this.ActiveEditor.focus();
				Data.Focused = true;
				Data.CaretPosItem = EventArgs.Item;
			}
			this.endRender(this.ActiveEditor, this.ActiveEditor.DateObject.getValue(), EventArgs.SkipRefresh);
		}
	}
	this.down = function(Event, Button, Obj)
	{		
		return this.updown(Event, Button, Obj, false);
	}
	this.up = function(Event, Button, Obj)
	{	
		return this.updown(Event, Button, Obj, true);
	}
	this.updownrelease = function(Event, Button, Incr)
	{
		clearTimeout(this.XTimer);
		Button.releaseCapture();
		this.LastObject = null;
		var nsrc = Button.getAttribute("hoversrc");
		if (nsrc)
			Button.style.backgroundImage = "url(" + nsrc + ")";
		return true;
	}
	this.updown = function(Event, Button, Obj, Incr)
	{
		if (typeof (Obj) == "string")
			Obj = document.getElementById(Obj);
		if (Obj.disabled)
			return false;
		var Data = this.getData(Obj);
		if (!Data.Focused)
		{
			this.FocusFromOut = true;
			this.onfocus(Obj, null);
		}
		this.FocusFromOut = false;
		this.UpDownPressed = true;
		this.xCrease(Obj, Incr);
		Button.setCapture();
		var asrc = Button.getAttribute("activesrc");
		if (asrc)
			Button.style.backgroundImage = "url(" + asrc + ")";
		Button.onmouseup = new Function("event", "return DatePickerEvents.updownrelease(event, this, " + (Incr ? "true" : "false") + ");");
		this.XTimer = setTimeout("DatePickerEvents.checkXCrease(" + (Incr ? "true" : "false") + ")", 500);
		
		return true;
	}
	this.xCrease = function(Obj, Incr)
	{
		if (typeof (Obj) == "string")
			Obj = document.getElementById(Obj);
		if (!Obj)
			return;
		this.checkObject(Obj);
		this.beginRender(Obj);
		this.validate(Obj);
		var i = (Obj.LastSelected) ? Obj.LastSelected : this.getData(Obj).CaretPosItem;
		this.setCurrentItem(Obj, i, Incr ? "+1" : "-1");
		this.endRender(Obj);
		this.LastObject = Obj;
		setTimeout("DatePickerEvents.makeFocus()", 10);
	}
	this.checkXCrease = function(Incr)
	{
		clearTimeout(this.XTimer);		
		if (!this.LastObject)
			return;
		this.xCrease(this.LastObject, Incr);
		this.XTimer = setTimeout("DatePickerEvents.checkXCrease(" + (Incr ? "true" : "false") + ")", 100);
	}
	this.makeFocus = function()
	{
		if (!this.LastObject)
			return;
		this.LastObject.focus();
	}
	if (!document.all)
		if (window.HTMLElement)
	{
		var element = HTMLElement.prototype;
		var capture = ["click", "mousedown", "mouseup", "mousemove", "mouseover", "mouseout"];
		element.setCapture = function()
		{
			var self = this;
			var flag = false;
			this._capture = function(e)
			{
				if (flag) return;
				flag = true;
				var event = document.createEvent("MouseEvents");
				var type = e.type;
				var bubbles = e.bubbles;
				var cancelable = e.cancelable;
				var view = e.view;
				var detail = e.detail;
				var screenX = e.screenX;
				var screenY = e.screenY;
				var clientX = e.clientX;
				var clientY = e.clientY;
				var ctrlKey = e.ctrlKey;
				var altKey = e.altKey;
				var shiftKey = e.shiftKey;
				var metaKey = e.metaKey;
				var button = e.button;
				var relatedTarget = e.relatedTarget;
				if (Object.prototype.toString.call(relatedTarget) == "[object XULElement]")
				{
					relatedTarget = null;
				}
				event.initMouseEvent(type,
            		bubbles, cancelable, view, detail,
            		screenX, screenY, clientX, clientY,
            		ctrlKey, altKey, shiftKey, metaKey,
            		button, relatedTarget);
				self.dispatchEvent(event);
				flag = false;
			};
			for (var i = 0; i < capture.length; i++)
			{
				window.addEventListener(capture[i], this._capture, true);
			}
		};
		element.releaseCapture = function()
		{
			for (var i = 0; i < capture.length; i++)
			{
				window.removeEventListener(capture[i], this._capture, true);
			}
			this._capture = null;
		};
	}
	this.resetToEmpty = function(NodeEditor)
	{
		setTimeout("DatePickerEvents.resetToEmptyProcess('" + NodeEditor + "')", 100);
	}
	this.resetToEmptyProcess = function(NodeEditor)
	{
		NodeDim = NodeEditor.split(",");
		for (var i = 0; i < NodeDim.length; i++)
		{
			var Editor = document.getElementById(NodeDim[i]);
			if (Editor != null)
				if (Editor.Data)
			{

				Editor.removeAttribute("Data");
				Editor.removeAttribute("DateObject");
				Editor.removeAttribute("ProposedValue");
				Editor.removeAttribute("ValueBeforeFocus");
				Editor.value = "";
			}
		}
	}
}
var DatePickerEvents = new DatePickerEventsObject();
