/**
* Classes included in this file:
*     SmallMonthCalendar : CalendarBase
* Enumerators included in this file:
*     MonthlyView
*     TimeBoxIncrement
* This file requires the use of the following files:
*     base.js
*     base_classes.js
*     cls_calendar_base.js
**/

MonthlyView = {};
MonthlyView.SingleMonth = 1;
MonthlyView.ThreeMonthHorizontal = 2;
MonthlyView.ThreeMonthVertical = 3;
MonthlyView.SixMonth = 4;
MonthlyView.TwelveMonth = 5;

/**************************************************************************/

TimeBoxIncrement = {};
TimeBoxIncrement.ThirtyMinute = 1;
TimeBoxIncrement.FifteenMinute = 2;
TimeBoxIncrement.OneHour = 3;

/**************************************************************************/

function SmallMonthCalendar(p_elementId, p_instanceName, p_date)
{
	SmallMonthCalendar.baseConstructor.call(this, p_elementId, p_instanceName, p_date);
	this.View                  = MonthlyView.SingleMonth;
	this.ShowMonthButtons      = false;
	this.MonthButtonHeight     = 14;
	this.MonthButtonBorder     = new RectangleBorder(1, BorderStyle.Solid, '#666666');
	this.MonthButtonBackground = new Background('#E8EEF7');
	this.MonthButtonFont       = new Font('verdana', '9px');
	this.MonthDividor          = new Border(1, BorderStyle.Solid, 'blue');
	this.DayAreaBorder         = this.DefaultBorder();
	this.AllowYearEdit         = false;
	this._IsEditingCurrentYear = false;
	this._CurrentYearEditError = false;
	this.DayAreaBorder.Right.Set(0, BorderStyle.None, '#FFFFFF');
	return;
}
Extend(SmallMonthCalendar, CalendarBase);
SmallMonthCalendar.prototype.GetType = function() { return 'SmallMonthCalendar'; }
SmallMonthCalendar.prototype.ToString = function() { return 'SmallMonthCalendar: ' + this.Name; }
SmallMonthCalendar.prototype.Next = function()
{
	switch(this.View)
	{
		case MonthlyView.SingleMonth:
			if(this.ShowMonthButtons) { this.CurrentDate.AddYears(1); }
			else { this.CurrentDate.AddMonths(1); }
			break;
		case MonthlyView.ThreeMonthHorizontal:
		case MonthlyView.ThreeMonthVertical: this.CurrentDate.AddMonths(3); break;
		case MonthlyView.SixMonth: this.CurrentDate.AddMonths(6); break;
		case MonthlyView.TwelveMonth: this.CurrentDate.AddYears(1); break;
	}
	this.Refresh();
	return;
}
SmallMonthCalendar.prototype.Previous = function()
{
	switch(this.View)
	{
		case MonthlyView.SingleMonth:
			if(this.ShowMonthButtons) { this.CurrentDate.AddYears(-1); }
			else { this.CurrentDate.AddMonths(-1); }
			break;
		case MonthlyView.ThreeMonthHorizontal:
		case MonthlyView.ThreeMonthVertical: this.CurrentDate.AddMonths(-3); break;
		case MonthlyView.SixMonth: this.CurrentDate.AddMonths(-6); break;
		case MonthlyView.TwelveMonth: this.CurrentDate.AddYears(-1); break;
	}
	this.Refresh();
	return;
}
SmallMonthCalendar.prototype.CalculateWidth = function() { return (7 * this.DayBoxSize.Width) + (this.WeekNumbers.Visible ? this.DayBoxSize.Width : 0); }
SmallMonthCalendar.prototype.CalculateHeight = function() { return (6 * this.DayBoxSize.Height) + (this.Header.Visible ? this.Header.Size.Height : 0) + (this.Footer.Visible ? this.Footer.Size.Height : 0) + (this.WeekDayHeaders.Visible ? this.DayBoxSize.Height : 0) + (this.ShowMonthButtons ? (this.MonthButtonHeight + 4 + (this.MonthButtonBorder.Left.Width * this.MonthButtonBorder.Right.Width)) * 3 : 0); }
SmallMonthCalendar.prototype.Render = function()
{
	this.RenderSetup();
	Utils.GetElement(this.ElementId).innerHTML = this.GetRenderHtml();
	return;
}
SmallMonthCalendar.prototype.RenderSetup = function()
{
	SmallMonthCalendar.superClass.RenderSetup.call(this);
	if(this.DayBoxSize.Width > 0)
	{
		if(this.View == MonthlyView.ThreeMonthHorizontal || this.View == MonthlyView.SixMonth) { this.Size.Width = this.Size.Width * 3; }
		else if(this.View == MonthlyView.TwelveMonth) { this.Size.Width = this.Size.Width * 4; }
	}
	if(this.DayBoxSize.Height > 0)
	{
		if(this.View == MonthlyView.SixMonth) { this.Size.Height = this.Size.Height * 2; }
		else if(this.View == MonthlyView.ThreeMonthVertical || this.View == MonthlyView.TwelveMonth) { this.Size.Height = this.Size.Height * 3; }
	}
	this.Footer.Colspan = this.View == MonthlyView.ThreeMonthHorizontal || this.View == MonthlyView.SixMonth ? 3 : (this.View == MonthlyView.TwelveMonth ? 4 : this.GetColumnCount());
	this.WeekDayHeaders.Size.Set(this.DayBoxSize.Width, this.DayBoxSize.Height);
	this.WeekNumbers.Size.Set(this.DayBoxSize.Width, this.DayBoxSize.Height);
	return;
}
SmallMonthCalendar.prototype.GetRenderHtml = function()
{
	var v_sb = new StringBuilder('<table border="0" cellpadding="0" cellspacing="0"');
	v_sb.Append(Utils.CreateAttributeString('id', this.ElementId + '_container'))
		.Append(Utils.CreateAttributeString('class', this.CssClassName))
		.Append(Utils.CreateAttributeString('title', this.ToolTipText));
	this.GetEventAttributeString(v_sb);
	v_sb.Append(' style="');
	this.GetStyleString(v_sb);
	v_sb.Append('">');
	if(this.View == MonthlyView.ThreeMonthVertical)
	{
		this.Header.PercentWidth = 100;
		var v_temp_date = this.VisibleStartDate.Clone();
		for(var i = 0; i < 3; i++)
		{
			this._RenderHeader(v_sb, v_temp_date, true, i == 0, i == 0);
			this._RenderWeekDayHeaders(v_sb, v_temp_date);
			this._RenderMonth(v_sb, i.toString() + '_' , v_temp_date);
			v_temp_date.AddMonths(1);
		}
	}
	else if(this.View == MonthlyView.ThreeMonthHorizontal)
	{
		this.Header.PercentWidth = 33.3;
		this.Header.Colspan = 1;
		this._RenderMonthRow(v_sb, 1, this.VisibleStartDate, 3, true);
	}
	else if(this.View == MonthlyView.SixMonth)
	{
		this.Header.PercentWidth = 33.3;
		this.Header.Colspan = 1;
		this._RenderMonthRow(v_sb, 1, this.VisibleStartDate, 3, true);
		var v_date = this.VisibleStartDate.Clone();
        v_date.AddMonths(3);
		this._RenderMonthRow(v_sb, 2, v_date, 3, false);
	}
	else if(this.View == MonthlyView.TwelveMonth)
	{
		this.Header.PercentWidth = 25;
		this.Header.Colspan = 1;
		this._RenderMonthRow(v_sb, 1, this.VisibleStartDate, 4, true);
		var v_date = this.VisibleStartDate.Clone();
        v_date.AddMonths(4);
		this._RenderMonthRow(v_sb, 2, v_date, 4, false);
		v_date.AddMonths(4);
		this._RenderMonthRow(v_sb, 3, v_date, 4, false);
	}
	else
	{
		this.Header.PercentWidth = 100;
		this._RenderHeader(v_sb, this.CurrentDate, true, true, true);
		if(this.ShowMonthButtons)
		{
			v_sb.Append('<tr><td colspan="8" style="background: ').Append(this.Header.Background.ToCssString()).Append(';"><table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">');
			var v_month = 0;
			for(var i = 0; i < 3; i++)
			{
				v_sb.Append('<tr>');
				for(var j = 0; j < 4; j++)
				{
					v_sb.Append('<td style="width: 25%; padding: 2px;">');
					this._RenderMonthButton(v_sb, v_month);
					v_sb.Append('</td>');
					v_month++;
				}
				v_sb.Append('</tr>');
			}
			v_sb.Append('</table></td></tr>');
		}
		this._RenderWeekDayHeaders(v_sb, this.CurrentDate);
		this._RenderMonth(v_sb, '', this.CurrentDate);
	}
	if(this.Footer.Visible)
	{
		v_sb.Append('<tr>');
		this.Footer.Render(v_sb);
		v_sb.Append('</tr>');
	}
	v_sb.Append('</table>');
	return v_sb.ToString();
}
SmallMonthCalendar.prototype._RenderMonthButton = function(p_stringBuilder, p_month)
{
	p_stringBuilder.Append('<div id="month_button_').Append(p_month).Append('" title="').Append(Date.LongMonthName(p_month)).Append('" style="cursor: pointer; height: ').Append(this.MonthButtonHeight.ToCssString()).Append('; ')
		.Append(this.MonthButtonBorder.ToCssString())
		.Append('; font: ').Append(this.MonthButtonFont.ToCssString())
		.Append('; background: ').Append(this.MonthButtonBackground.ToCssString()).Append(';" onclick="').Append(this.Name).Append('.ShowMonth(').Append(this.CurrentDate.getFullYear()).Append(', ').Append(p_month).Append('); Utils.CancelEventBubble(event);">')
		.Append(Date.ShortMonthName(p_month))
		.Append('</div>');
	return;
}
SmallMonthCalendar.prototype._RenderMonthRow = function(p_stringBuilder, p_rowNumber, p_date, p_cols, p_isTopRow)
{
	var v_temp_date = p_date.Clone();
	p_stringBuilder.Append('<tr>');
	for(var i = 0; i < p_cols; i++) { this._RenderHeader(p_stringBuilder, v_temp_date, false, i == 0 && p_isTopRow, (i == p_cols - 1) && p_isTopRow); v_temp_date.AddMonths(1); }
	p_stringBuilder.Append('</tr><tr>');
	v_temp_date.AddMonths(p_cols * -1);
	for(var i = 0; i < p_cols; i++)
	{
		p_stringBuilder.Append('<td style=" width: ')
			.Append(this.Header.PercentWidth).Append('%;');
		if(i != 0) { p_stringBuilder.Append(Utils.CreateCssPropertyString('border-left', this.MonthDividor.ToCssString())); }
		p_stringBuilder.Append('"><table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">');
		this._RenderWeekDayHeaders(p_stringBuilder, v_temp_date);
		this._RenderMonth(p_stringBuilder, (p_rowNumber * i).toString() + '_', v_temp_date);
		p_stringBuilder.Append('</table></td>');
		v_temp_date.AddMonths(1);
	}
	p_stringBuilder.Append('</tr>');
	return;
}
SmallMonthCalendar.prototype._RenderHeader = function(p_stringBuilder, p_date, p_includeRow, p_showPrevButton, p_showNextButton)
{
	if(this.Header.Visible)
	{
		var v_text = '';
		if(this.Header.ButtonsVisible && (p_showPrevButton || p_showNextButton))
		{
			if(p_showPrevButton) { v_text += '<div style="cursor: pointer; float: left;" title="Previous" onclick="' + this.Name + '.Previous(); Utils.CancelEventBubble(event);">&nbsp;&#171;&nbsp;</div>'; }
			if(p_showNextButton) { v_text += '<div style="cursor: pointer; float: right;" title="Next" onclick="' + this.Name + '.Next(); Utils.CancelEventBubble(event);">&nbsp;&#187;&nbsp;</div>'; }
		}
		if(this.AllowYearEdit) { this.Header.Text = v_text + Date.LongMonthName(p_date.getMonth()) + ' <span id="' + this.ElementId + '_current_year" style="cursor: pointer;" onclick="' + this.Name + '._OnCurrentYearClick(this); Utils.CancelEventBubble(event);" title="Click to type in a year.">' + p_date.getFullYear() + '</span>'; }
		else { this.Header.Text = v_text + Date.LongMonthName(p_date.getMonth()) + ' ' + p_date.getFullYear(); }
		if(p_includeRow) { p_stringBuilder.Append('<tr>'); }
		this.Header.ElementIdExt = '_' + p_date.getFullYear().Pad(4) + '_' + p_date.getMonth().Pad(2) + '_01';
		this.Header.Render(p_stringBuilder);
		this.Header.ElementIdExt = '';
		if(p_includeRow) { p_stringBuilder.Append('</tr>'); }
	}
	return;
}
SmallMonthCalendar.prototype._OnCurrentYearClick = function(p_span)
{
    if(!this.AllowYearEdit || this._IsEditingCurrentYear) { return; }
    this._IsEditingCurrentYear = true;
    p_span.innerHTML = '<input type="text" maxlength="4" value="' + this.CurrentDate.getFullYear() + '" id="' + this.ElementId + '_current_year_input" style="width: 35px; font: 10px \'verdana\'; ' + this.MonthButtonBorder.ToCssString() + '" onkeydown="return ' + this.Name + '._OnChangeCurrentYearKeyDown(event, this);" onblur="' + this.Name + '._SetCurrentYearFromInput(this);" title="Type in a year and press Enter, or press Escape to cancel." />';
    var v_input = Utils.GetElement(this.ElementId + '_current_year_input');
    v_input.select();
    v_input.focus();
    return;
}
SmallMonthCalendar.prototype._OnChangeCurrentYearKeyDown = function(p_event, p_input)
{
    if(!this.AllowYearEdit) { return true; }
    var v_key_code = Utils.GetKeyCode(p_event);
    if(v_key_code == 27) { Utils.GetElement(this.ElementId + '_current_year').innerHTML = this.CurrentDate.getFullYear(); this._IsEditingCurrentYear = false; return true; } // Escape key.
    if(v_key_code == 8 || v_key_code == 37 || v_key_code == 39) { return true; } // Backspace & Right/Left arrows.
	if(v_key_code == 13) { this._SetCurrentYearFromInput(p_input); return true; } // Enter key.
	if(!Utils.IsNumericKey(v_key_code)) { return false; }
	return true;
}
SmallMonthCalendar.prototype._SetCurrentYearFromInput = function(p_input)
{
    if(!this.AllowYearEdit || this._CurrentYearEditError) { return; }
    this._CurrentYearEditError = true;
    var v_year = Utils.GetIntValue(p_input.value);
    if(v_year < 1582) { alert('Years before 1582 are not supported.'); var v_input = Utils.GetElement(this.ElementId + '_current_year_input'); v_input.select(); v_input.focus(); }
    else { this.ShowMonth(v_year, this.CurrentDate.getMonth()); this._IsEditingCurrentYear = false; }
    this._CurrentYearEditError = false;
    return;
}
SmallMonthCalendar.prototype._RenderWeekDayHeaders = function(p_stringBuilder, p_date)
{
	if(this.WeekDayHeaders.Visible)
	{
		p_stringBuilder.Append('<tr>');
		this.WeekDayHeaders.Render(p_stringBuilder, p_date);
		p_stringBuilder.Append('</tr>');
	}
	return;
}
SmallMonthCalendar.prototype._RenderMonth = function(p_stringBuilder, p_weekNumberIdPrefix, p_date)
{
	var v_current_date = p_date.GetFirstMonthDay().GetFirstWeekDay();
	var v_current_dow = 0;
	var v_cur_inactive = false, v_cur_today = false, v_cur_selected = false, v_cur_weekend = false;
	p_stringBuilder.Append('<tr>');
	for(var i = 0, j = 0, w = 0; i < 42; i++, j++)
	{
		if(j > 6) { p_stringBuilder.Append('</tr><tr>'); j = 0; w++; }
		if(j == 0 && this.WeekNumbers.Visible) { this.WeekNumbers.Render(p_stringBuilder, p_weekNumberIdPrefix, v_current_date, p_date, w == 0, w == 5); }
		v_current_dow  = v_current_date.getDay();
		v_cur_inactive = v_current_date.getMonth() != p_date.getMonth();
		v_cur_today    = v_current_date.Equals(Date.Today());
		v_cur_selected = this.IsSelected(v_current_date);
		v_cur_weekend  = v_current_dow == 0 || v_current_dow == 6;
		this._RenderDay(p_stringBuilder, v_current_date, v_cur_inactive, v_cur_today, v_cur_selected, v_cur_weekend, w == 0, w == 5, j == 0, j == 6);
		v_current_date.AddDays(1);
	}
	p_stringBuilder.Append('</tr>');
	return;
}
SmallMonthCalendar.prototype._RenderDay = function(p_stringBuilder, p_date, p_inactive, p_today, p_selected, p_weekend, p_isTop, p_isBottom, p_isLeft, p_isRight)
{
	var v_year = p_date.getFullYear(), v_month = p_date.getMonth(), v_day = p_date.getDate();
	var v_day_id = this.ElementId + '_day_' + v_year.toString() + '_' + v_month.toString() + '_' + v_day.toString();
	if(p_inactive) { v_day_id += '_i' }
	p_stringBuilder.Append('<td').Append(Utils.CreateAttributeString('id', v_day_id));
	var v_key = 'd' + v_year.Pad(4) + v_month.Pad(2) + v_day.Pad(2);
	if(this.DayText.Contains(v_key)) { p_stringBuilder.Append(Utils.CreateAttributeString('title', this.DayText.Item(v_key))); }
	var v_border = new RectangleBorder(this.DayBorder.Width, this.DayBorder.Style, this.DayBorder.Color);
	if(p_isTop)
	{
		v_border.Top.Set(this.DayAreaBorder.Top.Width, this.DayAreaBorder.Top.Style, this.DayAreaBorder.Top.Color);
		v_border.Bottom.Set(0, BorderStyle.None, '#FFFFFF');
		if(!p_isLeft) { v_border.Left.Set(0, BorderStyle.None, '#FFFFFF'); }
	}
	if(p_isRight)
	{
		v_border.Right.Set(this.DayAreaBorder.Right.Width, this.DayAreaBorder.Right.Style, this.DayAreaBorder.Right.Color);
		v_border.Left.Set(0, BorderStyle.None, '#FFFFFF');
		if(!p_isBottom) { v_border.Bottom.Set(0, BorderStyle.None, '#FFFFFF'); }
	}
	if(p_isBottom)
	{
		v_border.Bottom.Set(this.DayAreaBorder.Bottom.Width, this.DayAreaBorder.Bottom.Style, this.DayAreaBorder.Bottom.Color);
		if(!p_isLeft) { v_border.Left.Set(0, BorderStyle.None, '#FFFFFF'); }
	}
	if(p_isLeft)
	{
		v_border.Left.Set(this.DayAreaBorder.Left.Width, this.DayAreaBorder.Left.Style, this.DayAreaBorder.Left.Color);
		if(!p_isBottom) { v_border.Bottom.Set(0, BorderStyle.None, '#FFFFFF'); }
	}
	if(!p_isTop && !p_isBottom && !p_isLeft && !p_isRight)
	{
		v_border.Bottom.Set(0, BorderStyle.None, '#FFFFFF');
		v_border.Left.Set(0, BorderStyle.None, '#FFFFFF');
	}
	if(!p_inactive)
	{
		p_stringBuilder.Append(Utils.CreateAttributeString('onclick', this.Name + '.OnDayClick(event, this); Utils.CancelEventBubble(event);'))
			.Append(Utils.CreateAttributeString('ondblclick',  this.Name + '.OnDayDoubleClick(event, this); Utils.CancelEventBubble(event);'))
			.Append(Utils.CreateAttributeString('onmousemove', this.Name + '.OnDayMouseMove(event, this); Utils.CancelEventBubble(event);'))
			.Append(Utils.CreateAttributeString('onkeypress',  this.Name + '.OnDayKeyPress(event, this); Utils.CancelEventBubble(event);'))
			.Append(Utils.CreateAttributeString('onkeydown',   this.Name + '.OnDayKeyDown(event, this); Utils.CancelEventBubble(event);'))
			.Append(Utils.CreateAttributeString('onkeyup',     this.Name + '.OnDayKeyUp(event, this); Utils.CancelEventBubble(event);'))
			.Append(Utils.CreateAttributeString('onmouseover', this.Name + '.OnDayMouseOver(event, this); Utils.CancelEventBubble(event);'))
			.Append(Utils.CreateAttributeString('onmouseout',  this.Name + '.OnDayMouseOut(event, this); Utils.CancelEventBubble(event);'))
			.Append(Utils.CreateAttributeString('onmousedown', this.Name + '.OnDayMouseDown(event, this); Utils.CancelEventBubble(event);'))
			.Append(Utils.CreateAttributeString('onmouseup',   this.Name + '.OnDayMouseUp(event, this); Utils.CancelEventBubble(event);'));
	}
	p_stringBuilder.Append(' style="')
		.Append(Utils.CreateCssPropertyString('width', (this.DayBoxSize.Width > 0) ? this.DayBoxSize.Width.ToCssString() : Math.floor(100 / this.GetColumnCount()).toString() + '%'))
		.Append(Utils.CreateCssPropertyString('height', (this.DayBoxSize.Height > 0) ? this.DayBoxSize.Height.ToCssString() : Math.floor(100 / this.GetRowCount()).toString() + '%'))
		.Append(Utils.CreateCssPropertyString('padding', this.DayPadding.ToCssString()))
		.Append(v_border.ToCssString())
		.Append(Utils.CreateCssPropertyString('font', this.Font.ToCssString()))
		.Append(ContentAlignment.CreateCssString(this.TextAlign));
	if(p_inactive && !p_weekend)
	{
		p_stringBuilder.Append(Utils.CreateCssPropertyString('background', this.InactiveDayBackground.ToCssString()))
			.Append(Utils.CreateCssPropertyString('color', this.InactiveDayForeColor))
			.Append(Utils.CreateCssPropertyString('cursor', this.Cursor));
	}
	else if(p_inactive && p_weekend)
	{
		p_stringBuilder.Append(Utils.CreateCssPropertyString('background', this.WeekendDayBackground.ToCssString()))
			.Append(Utils.CreateCssPropertyString('color', this.InactiveDayForeColor))
			.Append(Utils.CreateCssPropertyString('cursor', this.Cursor));
	}
	else if(this.ShowToday && p_today)
	{
		p_stringBuilder.Append(Utils.CreateCssPropertyString('background', this.TodayBackground.ToCssString()))
			.Append(Utils.CreateCssPropertyString('color', this.TodayDayForeColor))
			.Append(Utils.CreateCssPropertyString('cursor', this.DayCursor));
	}
	else if(this.SelectionEnabled && p_selected)
	{
		p_stringBuilder.Append(Utils.CreateCssPropertyString('background', this.SelectedDayBackground.ToCssString()))
			.Append(Utils.CreateCssPropertyString('color', this.SelectedDayForeColor))
			.Append(Utils.CreateCssPropertyString('cursor', this.DayCursor));
	}
	else if(p_weekend)
	{
		p_stringBuilder.Append(Utils.CreateCssPropertyString('background', this.WeekendDayBackground.ToCssString()))
			.Append(Utils.CreateCssPropertyString('color', this.WeekendDayForeColor))
			.Append(Utils.CreateCssPropertyString('cursor', this.DayCursor));
	}
	else
	{
		p_stringBuilder.Append(Utils.CreateCssPropertyString('background', this.NormalDayBackground.ToCssString()))
			.Append(Utils.CreateCssPropertyString('color', this.ForeColor))
			.Append(Utils.CreateCssPropertyString('cursor', this.DayCursor));
	}
	p_stringBuilder.Append('">').Append(p_date.getDate().toString()).Append('</td>');
	return;
}
SmallMonthCalendar.prototype.UpdateVisibleDates = function()
{
	this.VisibleStartDate = this.CurrentDate.GetFirstMonthDay();
	if(this.View == MonthlyView.ThreeMonthHorizontal || this.View == MonthlyView.ThreeMonthVertical)
	{
		this.VisibleEndDate = this.VisibleStartDate.Clone();
		this.VisibleEndDate.AddMonths(2);
		this.VisibleEndDate.setDate(this.VisibleEndDate.GetDaysInMonth());
	}
	else if(this.View == MonthlyView.SixMonth)
	{
		this.VisibleEndDate = this.VisibleStartDate.Clone();
		this.VisibleEndDate.AddMonths(5);
		this.VisibleEndDate.setDate(this.VisibleEndDate.GetDaysInMonth());
	}
	else if(this.View == MonthlyView.TwelveMonth)
	{
		this.VisibleStartDate.setMonth(0);
		this.VisibleEndDate = new Date(this.CurrentDate.getFullYear(), 11, 31, 0, 0, 0, 0);
	}
	else { this.VisibleEndDate = this.CurrentDate.GetLastMonthDay(); }
	return;
}
SmallMonthCalendar._PickerCalendar = null;
SmallMonthCalendar._PickerPopupParentNode = null;
SmallMonthCalendar._InputElement = null;
SmallMonthCalendar._TimePickerCallback = null;
SmallMonthCalendar.ShowDatePicker = function(p_input, p_dateFormat, p_showToday, p_showWeekNumbers, p_showWeekDayHeaders, p_callback, p_selectedValue, p_options)
{
    var v_date = null;
    if (TypeOf(p_selectedValue) == 'Date') { v_date = p_selectedValue; }
    else if (TypeOf(p_selectedValue) == 'String' && p_selectedValue.length > 0) { v_date = Date.IsDate(p_selectedValue) ? new Date(Date.parse(p_selectedValue)) : Date.Today(); }
    else { try { v_date = Date.IsDate(p_input.value) ? new Date(Date.parse(p_input.value)) : Date.Today(); } catch (e) { v_date = Date.Today(); } }
    p_dateFormat = !p_dateFormat || TypeOf(p_dateFormat) != 'String' ? 'M/d/yyyy' : p_dateFormat;
    if (SmallMonthCalendar._PickerPopupParentNode != null) { SmallMonthCalendar.ClosePopup(); }
    SmallMonthCalendar._PickerPopupParentNode = p_input.parentNode;
    SmallMonthCalendar._PickerCalendar = new SmallMonthCalendar('smc_modal_popup_cal', 'SmallMonthCalendar._PickerCalendar', v_date.Clone());
    SmallMonthCalendar._PickerCalendar.ShowMonthButtons = true;
    SmallMonthCalendar._PickerCalendar.AllowYearEdit = true;
    SmallMonthCalendar._PickerCalendar.MultipleSelection = false;
    SmallMonthCalendar._PickerCalendar.ShowToday = TypeOf(p_showToday) == 'Boolean' ? p_showToday : true;
    SmallMonthCalendar._PickerCalendar.Header.ToolTipText = '';
    SmallMonthCalendar._PickerCalendar.WeekNumbers.ToolTipText = 'Week [WN] of the year [YEAR]';
    SmallMonthCalendar._PickerCalendar.DayBoxSize.Set(25, 20);
    SmallMonthCalendar._PickerCalendar.Footer.Visible = false;
    SmallMonthCalendar._PickerCalendar.WeekNumbers.Visible = TypeOf(p_showWeekNumbers) == 'Boolean' ? p_showWeekNumbers : true;
    SmallMonthCalendar._PickerCalendar.WeekDayHeaders.Visible = TypeOf(p_showWeekDayHeaders) == 'Boolean' ? p_showWeekDayHeaders : true;
    SmallMonthCalendar._PickerCalendar.LoadOptions(p_options);
    SmallMonthCalendar._PickerCalendar.DaySelected = _OnDaySelected;
    var v_div = document.createElement('div');
    v_div.setAttribute('id', 'smc_modal_popup_cal_container');
    v_div.setAttribute('onclick', 'SmallMonthCalendar.ClosePopup();');
    v_div.style.position = 'absolute';
    v_div.style.width = SmallMonthCalendar._PickerCalendar.CalculateWidth().ToCssString();
    v_div.style.height = (SmallMonthCalendar._PickerCalendar.CalculateHeight() + 16 + p_input.offsetHeight).ToCssString();
    v_div.style.paddingTop = (p_input.offsetHeight + 1).ToCssString();
    v_div.style.zIndex = '9999';
    SmallMonthCalendar._PickerCalendar.SelectedDays.Add(v_date);
    SmallMonthCalendar._PickerCalendar.RenderSetup();
    v_div.innerHTML = '<div style="font-weight: bold; height: 15px; font-family: verdana; font-size: 12px; color: blue; border-top: 1px solid blue; border-left: 1px solid blue; border-right: 1px solid blue; background-color: #C3D9FF; text-align: left;"><div style="background-color: #D4D0C8; cursor: pointer; color: black; text-align: center; border: 1px solid black; font-size: 9px; font-weight: bold; float: right; width: 13px; height: 13px;" title="Close" onclick="SmallMonthCalendar.ClosePopup();">X</div>Date Picker</div><div id="smc_modal_popup_cal">' + SmallMonthCalendar._PickerCalendar.GetRenderHtml() + '</div>';
    p_input.parentNode.insertBefore(v_div, p_input);
    function _OnDaySelected(p_date, p_object)
    {
        var v_date = p_date.Format(p_dateFormat);
        try { p_input.value = v_date; } catch (e) { }
        SmallMonthCalendar._PickerPopupParentNode.removeChild(v_div);
        SmallMonthCalendar._PickerCalendar = null;
        SmallMonthCalendar._PickerPopupParentNode = null;
        if (p_callback) { p_callback(v_date); }
        return;
    }
    return;
}
SmallMonthCalendar.ShowTimePicker = function(p_input, p_timeFormat, p_callback, p_selectedValue, p_increment)
{
    p_timeFormat = !p_timeFormat || TypeOf(p_timeFormat) != 'String' ? 'h:mm tt' : p_timeFormat;
    if (p_increment != TimeBoxIncrement.ThirtyMinute && p_increment != TimeBoxIncrement.FifteenMinute && p_increment != TimeBoxIncrement.OneHour) { p_increment = TimeBoxIncrement.ThirtyMinute; }
    if (SmallMonthCalendar._PickerPopupParentNode != null) { SmallMonthCalendar.ClosePopup(); }
    SmallMonthCalendar._InputElement = p_input;
    SmallMonthCalendar._PickerPopupParentNode = p_input.parentNode;
    var v_div = document.createElement('div');
    v_div.setAttribute('id', 'smc_modal_popup_cal_container');
    v_div.setAttribute('onclick', 'SmallMonthCalendar.ClosePopup();');
    v_div.style.position = 'absolute';
    v_div.style.width = '102px';
    v_div.style.height = (p_input.offsetHeight + 168).ToCssString();
    v_div.style.paddingTop = (p_input.offsetHeight + 1).ToCssString();
    v_div.style.fontFamily = 'verdana';
    v_div.style.fontSize = '12px';
    v_div.style.zIndex = '9999';
    var v_html = '<div style="border: 1px solid blue; background-color: #FFFFFF;"><div style="background-color: #C3D9FF; font-weight: bold; height: 15px; color: blue; border-bottom: 1px solid blue;">';
    v_html += '<div style="background-color: #D4D0C8; cursor: pointer; color: black; text-align: center; border: 1px solid black; font-size: 9px; font-weight: bold; float: right; width: 13px; height: 13px;" title="Close" onclick="SmallMonthCalendar.ClosePopup();">X</div>';
    v_html += 'Time Picker';
    v_html += '</div>';
    v_html += '<select name="smc_time_picker" style="width: 100px; height: 150px; border: none;" multiple="multiple" onchange="SmallMonthCalendar._TimePickerTimeClickHandler(this);">';
    var v_current_date = Date.UTCToday();
    var v_time = '';
    var v_input_time = '';
    if (TypeOf(p_selectedValue) == 'Date') { v_input_time = p_selectedValue.Format(p_timeFormat); }
    else
    {
        try
        {
            var v_time_string = '01/01/2000 ' + ((TypeOf(p_selectedValue) == 'String' && p_selectedValue.length > 0) ? p_selectedValue : p_input.value);
            v_input_time = Date.IsDate(v_time_string) ? (new Date(Date.parse(v_time_string))).Format(p_timeFormat) : '';
        } catch (e) { v_input_time = ''; }
    }
    switch (p_increment)
    {
        case TimeBoxIncrement.FifteenMinute:
            for (i = 0; i < 97; i++)
            {
                if (i == 96) { v_current_date.UTCAddMinutes(-1); }
                v_time = v_current_date.UTCFormat(p_timeFormat);
                v_html += '<option value="' + v_time + '"';
                if (v_time == v_input_time) { v_html += ' selected="selected"'; }
                v_html += '>' + v_time + '</option>';
                v_current_date.UTCAddMinutes(15);
            }
            break;
        case TimeBoxIncrement.OneHour:
            for (i = 0; i < 25; i++)
            {
                if (i == 24) { v_current_date.UTCAddMinutes(-1); }
                v_time = v_current_date.UTCFormat(p_timeFormat);
                v_html += '<option value="' + v_time + '"';
                if (v_time == v_input_time) { v_html += ' selected="selected"'; }
                v_html += '>' + v_time + '</option>';
                v_current_date.UTCAddHours(1);
            }
            break;
        default:
        case TimeBoxIncrement.ThirtyMinute:
            for (i = 0; i < 49; i++)
            {
                if (i == 48) { v_current_date.UTCAddMinutes(-1); }
                v_time = v_current_date.UTCFormat(p_timeFormat);
                v_html += '<option value="' + v_time + '"';
                if (v_time == v_input_time) { v_html += ' selected="selected"'; }
                v_html += '>' + v_time + '</option>';
                v_current_date.UTCAddMinutes(30);
            }
            break;
    }
    v_html += '</select></div>';
    v_div.innerHTML = v_html;
    SmallMonthCalendar._PickerPopupParentNode.insertBefore(v_div, p_input);
    SmallMonthCalendar._TimePickerCallback = p_callback;
    return;
}
SmallMonthCalendar._TimePickerTimeClickHandler = function(p_select)
{
	var v_time = p_select.options[p_select.selectedIndex].value;
	try { SmallMonthCalendar._InputElement.value = v_time; } catch(e) {  }
	SmallMonthCalendar.ClosePopup();
	if(SmallMonthCalendar._TimePickerCallback) { SmallMonthCalendar._TimePickerCallback(v_time); }
	SmallMonthCalendar._InputElement = null;
	SmallMonthCalendar._TimePickerCallback = null;
	return;
}
SmallMonthCalendar.ClosePopup = function()
{
	if(SmallMonthCalendar._PickerPopupParentNode != null) { SmallMonthCalendar._PickerPopupParentNode.removeChild($('smc_modal_popup_cal_container')); }
	SmallMonthCalendar._PickerCalendar = null;
	SmallMonthCalendar._PickerPopupParentNode = null;
	SmallMonthCalendar._InputElement = null;
	return;
}
SmallMonthCalendar._ShowDatePickerHelper = function(p_name)
{
    var v_dtbox = FindDateBox(p_name + '_date');
    if(v_dtbox != null && v_dtbox.Enabled)
    {
        SmallMonthCalendar.ShowDatePicker($(p_name + '_date_container'), 'MM/dd/yyyy', true, true, true, __callback, v_dtbox.GetValue());
    }
    function __callback(p_date)
    {
        FindDateBox(p_name + '_date').SetValue(new Date(Date.parse(p_date + ' 00:00:00')));
        return;
    }
    return;
}
SmallMonthCalendar._ShowTimePickerHelper = function(p_name, p_increment)
{
    var v_dtbox = FindTimeBox(p_name + '_time');
    if(v_dtbox != null && v_dtbox.Enabled)
    {
        SmallMonthCalendar.ShowTimePicker($(p_name + '_time_container'), 'hh:mm TT', __callback, v_dtbox.GetValue(), p_increment);
    }
    function __callback(p_time)
    {
        FindTimeBox(p_name + '_time').SetValue(new Date(Date.parse('1/1/2000 ' +  p_time)));
        return;
    }
    return;
}
