//<script type='text/javascript' id='Date Prototypes'>

if(typeof(Date.prototype.CompareTo) == 'undefined')
{
	Date.prototype.CompareTo = function(date)
	{
		if(!this.valueOf()) return 0;
		if(!(date instanceof Date)) return 'Not a date';
		if(this.getFullYear() == date.getFullYear() && this.getMonth() == date.getMonth() && this.getDate() == date.getDate()) return 0;
		if(	(this.getFullYear() > date.getFullYear())
		|| (this.getFullYear() == date.getFullYear() && this.getMonth() > date.getMonth()) 
		|| (this.getFullYear() == date.getFullYear() && this.getMonth() == date.getMonth() && this.getDate() > date.getDate()) )
		{
			return 1;
		}
		if(	(this.getFullYear() < date.getFullYear())
		|| (this.getFullYear() == date.getFullYear() && this.getMonth() < date.getMonth()) 
		|| (this.getFullYear() == date.getFullYear() && this.getMonth() == date.getMonth() && this.getDate() < date.getDate()) )
			{
				return -1;
			}
	}
}
if(typeof(Date.prototype.AddDays) == 'undefined')
{
	Date.prototype.AddDays = function(days){
		return new Date(this.getFullYear(),this.getMonth(), this.getDate() + days);
	}
}
if(typeof(Date.prototype.AddMonths) == 'undefined')
{
	Date.prototype.AddMonths = function(months)
	{
		
		var daysInMonth = [31,this.getFullYear()%4 == 0?29:28,31,30,31,30,31,31,30,31,30,31];
		var date = new Date(this.getFullYear(),this.getMonth()+months, 1);
		return new Date(date.getFullYear(), date.getMonth(), (this.getDate() > daysInMonth[date.getMonth()])?daysInMonth[date.getMonth()]:this.getDate());
	}
}
if(typeof(Date.prototype.AddYears) == 'undefined')
{
	Date.prototype.AddYears = function(years){
		return new Date(this.getFullYear() + years,this.getMonth(), this.getDate());
	}
}
if(typeof(Date.prototype.DaysInMonth) == 'undefined')
{
	Date.prototype.DaysInMonth = function DaysInMonth()
	{
		return 32 - new Date(this.getFullYear(), this.getMonth(), 32).getDate();
	}
}


//<script id='Date Prototypes 2' type='text/javascript' >

if(typeof(Date.prototype.Format) == 'undefined')
{
	Date.prototype.Format = function(f,useCulture)
	{
		if (!this.valueOf())
			return '';

		var gsMonthNames;
		var gsDayNames; 
		if(!useCulture)
		{
			gsMonthNames = new Array(
				'January',
				'February',
				'March',
				'April',
				'May',
				'June',
				'July',
				'August',
				'September',
				'October',
				'November',
				'December'
			);

			gsDayNames= new Array(
				'Sunday',
				'Monday',
				'Tuesday',
				'Wednesday',
				'Thursday',
				'Friday',
				'Saturday'
			);
		}
		else
		{
			gsMonthNames = globalizedMMDatePickerMonthNames;
			gsDayNames = globalizedMMDatePickerDayNames;
		}
		var d = this;
		
		return f.replace(/(yyyy|yy|MMMM|MMM|MM|M|dddd|ddd|dd|d|HH|hh|mm|ss|fff|a\/p)/gi,
			function($1)
			{
				switch ($1)
				{
				case 'yyyy':	return d.getFullYear();
				case 'yy':		return d.getFullYear() % 100 < 10 ? '0' + d.getFullYear() % 100: d.getFullYear() % 100;
				case 'MMMM':	return gsMonthNames[d.getMonth()];
				case 'MMM':		return gsMonthNames[d.getMonth()].substr(0, 3);
				case 'MM':		return (d.getMonth() + 1) < 10 ? '0' +  (d.getMonth() + 1):(d.getMonth() + 1);
				case 'M':		return d.getMonth() + 1;
				case 'dddd':	return gsDayNames[d.getDay()];
				case 'ddd':		return gsDayNames[d.getDay()].substr(0, 3);
				case 'dd':		return d.getDate() < 10 ? '0' + d.getDate():d.getDate();
				case 'd':		return d.getDate();
				case 'HH':		return d.getHours() < 10? '0' + d.getHours(): d.getHours();
				case 'hh':		return ((h = d.getHours() % 12) ? h : 12) < 10 ? '0' + ((h = d.getHours() % 12) ? h : 12): ((h = d.getHours() % 12) ? h : 12);
				case 'mm':		return d.getMinutes() < 10 ? '0' + d.getMinutes(): d.getMinutes();
				case 'ss':		return d.getSeconds() < 10 ? '0' + d.getSeconds(): d.getSeconds();
				case 'fff':		return d.getMilliseconds() < 100? ('0' + (d.getMilliseconds()<10? '0' + d.getMilliseconds():d.getMilliseconds())) : d.getMilliseconds();
				case 'a/p':		return d.getHours() < 12 ? 'am' : 'pm';
				}
			}
		);
	}
}


//<script type='text/javascript'>

function MMCalendarSpecialDay(_Date,_CssClass,_ToolTip,_Available,_NoArrival,_NoDeparture)
{
	this.Date = _Date;
	this.CssClass = _CssClass;
	this.ToolTip = _ToolTip;
	this.Available = _Available;
	this.NoArrival = _NoArrival;
	this.NoDeparture = _NoDeparture;
}


//<script id='AppendChild(Obj,Child)' type='text/javascript'>

	function MMCalendarAppendChild(Obj,Child, replace)
	{
		if(replace)
		{
			Obj.innerHTML = '';
		}
		if(Child.outerHTML)
			Obj.innerHTML += Child.outerHTML;
		else
			Obj.appendChild(Child);
	}


//<script id='CSS' type='text/javascript'>

function MMCalendarCSS(_Calendar,_CalendarHeader,_VisibleDate,
						_FastNavigationForth,_SlowNavigationForth,
						_FastNavigationBack,_SlowNavigationBack,
						_Weekday,_OtherMonthDay,_RegularDay,
						_TodaysDay,_SelectedDay,_ClosedDay,_ToolTip,
						_FVDHolder, _FVDMonth, _FVDYear,
						_FVDMonthSlct, _FVDYearSlct, _FVDDateSlct,
						_FVDToday, _FVDOK, _FVDCancel)
{
	if(typeof(_Calendar) == 'undefined')
	{
		this.Calendar = 'MMDP_Calendar';
	}
	if(typeof(_CalendarHeader) == 'undefined')
	{
		this.CalendarHeader = 'MMDP_CalendarHeader';
	}
	if(typeof(_VisibleDate) == 'undefined')
	{
		this.VisibleDate = 'MMDP_VisibleDate';
	}
	if(typeof(_FastNavigationForth) == 'undefined')
	{
		this.FastNavigationForth = 'MMDP_FastNavigation';
	}
	if(typeof(_SlowNavigationForth) == 'undefined')
	{
		this.SlowNavigationForth = 'MMDP_SlowNavigation';
	}
	if(typeof(_FastNavigationBack) == 'undefined')
	{
		this.FastNavigationBack = 'MMDP_FastNavigation';
	}
	if(typeof(_SlowNavigationBack) == 'undefined')
	{
		this.SlowNavigationBack = 'MMDP_SlowNavigation';
	}
	if(typeof(_Weekday) == 'undefined')
	{
		this.Weekday = 'MMDP_Weekday';
	}
	if(typeof(_OtherMonthDay) == 'undefined')
	{
		this.OtherMonthDay = 'MMDP_OtherMonthDay';
	}
	if(typeof(_RegularDay) == 'undefined')
	{
		this.RegularDay = 'MMDP_RegularDay';
	}
	if(typeof(_TodaysDay) == 'undefined')
	{
		this.TodaysDay = 'MMDP_TodaysDay';
	}
	if(typeof(_SelectedDay) == 'undefined')
	{
		this.SelectedDay = 'MMDP_SelectedDay';
	}
	if(typeof(_ClosedDay) == 'undefined')
	{
		this.ClosedDay = 'MMDP_ClosedDay';
	}
	if(typeof(_ToolTip) == 'undefined')
	{
		this.ToolTip = 'MMDP_ToolTip';
	}
	if(typeof(_FVDHolder) == 'undefined')
	{
		this.FastVisibleDateSelectorHolder = 'MMDP_FVDSHolder';
	}
	if(typeof(_FVDMonth) == 'undefined')
	{
		this.FastVisibleDateSelectorMonth = 'MMDP_FVDSMonth';
	}
	if(typeof(_FVDYear) == 'undefined')
	{
		this.FastVisibleDateSelectorYear = 'MMDP_FVDSYear';
	}
	if(typeof(_FVDMonthSlct) == 'undefined')
	{
		this.FastVisibleDateSelectorSelectedMonth = 'MMDP_FVDSSelectedMonth';
	}
	if(typeof(_FVDYearSlct) == 'undefined')
	{
		this.FastVisibleDateSelectorSelectedYear = 'MMDP_FVDSSelectedYear';
	}
	if(typeof(_FVDDateSlct) == 'undefined')
	{
		this.FastVisibleDateSelectorSelectedDate = 'MMDP_FVDSSelectedDate';
	}
	if(typeof(_FVDToday) == 'undefined')
	{
		this.FastVisibleDateSelectorToday = 'MMDP_FVDSToday';
	}
	if(typeof(_FVDOK) == 'undefined')
	{
		this.FastVisibleDateSelectorOK = 'MMDP_FVDSOK';
	}
	if(typeof(_FVDCancel) == 'undefined')
	{
		this.FastVisibleDateSelectorCancel = 'MMDP_FVDSCancel';
	}
}


//<script id='NavigationBar' type='text/javascript'>

function SetMMCalendarNavigationBar(_Sender, CalendarTableRow)
{
	var NavBarCell = CalendarTableRow.insertCell(0);
	NavBarCell.setAttribute('colspan','7');
	NavBarCell.setAttribute('class',_Sender.CSS.CalendarHeader);
	// CREATING NAVIGATION BAR	
	var NavBarTable = document.createElement('table');	
	NavBarTable.setAttribute('border','0');
	NavBarTable.setAttribute('cellpadding','0');
	NavBarTable.setAttribute('cellspacing','0');
	NavBarTable.setAttribute('width','100%');
	//NavBarTable.setAttribute('class',_Sender.CSS.CalendarHeader);
	var NavBarTableRow = NavBarTable.insertRow(0);
	var NavBarRowCellIndex = 0;
	var d = _Sender.VisibleDate.AddMonths(-1);
	var dm = _Sender.MinimalDate;
	//CREATING FAST BACK CELL
	if(_Sender.EnableFastNavigation)
	{
		var NavBarFastBackCell = NavBarTableRow.insertCell(NavBarRowCellIndex++);
		NavBarFastBackCell.style.cursor = 'pointer';
		NavBarFastBackCell.style.visibility = new Date(d.getFullYear(),d.getMonth(),1).CompareTo(new Date(dm.getFullYear(),dm.getMonth(),1)) < 0? 'hidden':'visible';
		NavBarFastBackCell.setAttribute('class',_Sender.CSS.FastNavigationBack);
		NavBarFastBackCell.setAttribute('nowrap','nowrap');
		NavBarFastBackCell.setAttribute('align','center');
		NavBarFastBackCell.style.width = (100/7) + '%';
		NavBarFastBackCell.setAttribute('onclick',"MMCalendarNavigateTo(event,eval(" + _Sender.id + "),-3)");
		if(_Sender.FastNavigationBackImageOff != '' && _Sender.FastNavigationBackImageOff != null && _Sender.FastNavigationBackImageOff != 'undefined')
		{	
			var img = document.createElement('img');
			img.setAttribute('alt', _Sender.FastNavigationBackSymbol);
			img.setAttribute('src',_Sender.FastNavigationBackImageOff);
			img.style.border = 'none';
			if(_Sender.FastNavigationBackImageOn != '')
			{
				img.setAttribute('onmouseover','this.src="' + _Sender.FastNavigationBackImageOn + '"');
				img.setAttribute('onmouseout','this.src="' + _Sender.FastNavigationBackImageOff + '"');
			}
			
			NavBarFastBackCell.innerHTML = '';
			MMCalendarAppendChild(NavBarFastBackCell,img);
		}
		else
		{
			NavBarFastBackCell.innerHTML = _Sender.FastNavigationBackSymbol;
		}
	NavBarFastBackCell.title = _Sender.VisibleDate.AddMonths(-3).Format(', MMMM , yyyy',true);
	}
	//END CREATING FAST BACK CELL
	//CREATING BACK CELL
	var NavBarBackCell = NavBarTableRow.insertCell(NavBarRowCellIndex++);
	NavBarBackCell.style.cursor = 'pointer';
	d = _Sender.VisibleDate.AddMonths(-1);
	NavBarBackCell.style.visibility = new Date(d.getFullYear(),d.getMonth(),1).CompareTo(new Date(dm.getFullYear(),dm.getMonth(),1)) < 0? 'hidden':'visible';
	NavBarBackCell.setAttribute('class',_Sender.CSS.SlowNavigationBack);
	NavBarBackCell.setAttribute('nowrap','nowrap');
	NavBarBackCell.setAttribute('align','center');
	NavBarBackCell.style.width = 100/(_Sender.EnableFastNavigation?7:3.5) + '%';
	NavBarBackCell.setAttribute('onclick',"MMCalendarNavigateTo(event,eval(" + _Sender.id + "),-1)");
	if(_Sender.NavigationBackImageOff != '' && _Sender.NavigationBackImageOff != null && _Sender.NavigationBackImageOff != 'undefined')
	{
		var img = document.createElement('img');
		img.setAttribute('alt', _Sender.NavigationBackSymbol);
		img.setAttribute('src',_Sender.NavigationBackImageOff);
		img.style.border = 'none';
		if(_Sender.NavigationBackImageOn != '')
		{
			img.setAttribute('onmouseover','this.src="' + _Sender.NavigationBackImageOn + '"');
			img.setAttribute('onmouseout','this.src="' + _Sender.NavigationBackImageOff + '"');
		}
		NavBarBackCell.innerHTML = '';
		MMCalendarAppendChild(NavBarBackCell,img);
	}
	else
	{
		NavBarBackCell.innerHTML = _Sender.NavigationBackSymbol;
	}
	NavBarBackCell.title = _Sender.VisibleDate.AddMonths(-1).Format(', MMMM , yyyy',true);
	//END CREATING BACK CELL
	//CREATING CENTRAL CELL
	var NavBarCentralCell = NavBarTableRow.insertCell(NavBarRowCellIndex++);
	NavBarCentralCell.setAttribute('id',_Sender.id + '_NavBarCentralCell');
	NavBarCentralCell.setAttribute('class',_Sender.CSS.VisibleDate);
	NavBarCentralCell.setAttribute('nowrap','nowrap');
	NavBarCentralCell.setAttribute('align','center');
	var div = document.createElement('div');
	div.id = _Sender.id + '_FastVisibleDatePicker';
	div.setAttribute('class',_Sender.CSS.FastVisibleDateSelectorHolder);
	div.style.position = 'absolute';
	div.style.display = 'none';
	div.style.top = '0px';
	div.style.left = '0px';
	var table = document.createElement('table'); // this table has one row with two cells. a cell for monthes and a cell for years
	table.id = _Sender.id + '_table';
	table.setAttribute('border','0');
	table.setAttribute('cellpadding','0');
	table.setAttribute('cellspacing','0');
	table.setAttribute('width','131');
	var tableRow = table.insertRow(0);
	var tableRowMonthsCell = tableRow.insertCell(0);
	tableRowMonthsCell.id = _Sender.id + '_tableRowMonthsCell';
	tableRowMonthsCell.setAttribute('valign','top');
	var tableRowYearsCell = tableRow.insertCell(1);
	tableRowYearsCell.id = _Sender.id + '_tableRowYearsCell';
	tableRowYearsCell.setAttribute('valign','top');
	var tableRow2 = table.insertRow(1);
	var tableRowButtonsCell = tableRow2.insertCell(0);
	tableRowButtonsCell.setAttribute('colspan',2);
	
	var monthListTable = document.createElement('table');
	monthListTable.id = _Sender.id + '_MonthListTable';
	monthListTable.setAttribute('border','0');
	monthListTable.setAttribute('cellpadding','1');
	monthListTable.setAttribute('cellspacing','0');
	monthListTable.setAttribute('width','100%');
	
	var month = 0;
	var date = new Date((new Date()).getFullYear(),0,1);
	for(var row = 0; row < 6; row++)
	{
		var monthRow = monthListTable.insertRow(row);
		for(var cel = 0; cel < 2; cel++)
		{
			var monthCell = monthRow.insertCell(cel);
			monthCell.innerHTML = date.AddMonths(month+row+cel*6).Format('MMM', true);
			monthCell.setAttribute('class',_Sender.CSS.FastVisibleDateSelectorMonth);
			monthCell.setAttribute('align','center');
			monthCell.style.cursor = 'pointer';
			monthCell.setAttribute('onclick','MMCalendarFastVisibleDateSelectMonth(eval(' + _Sender.id + '),this.parentNode.parentNode.parentNode,' + row + ',' + cel + ')');
		}
	}
	var yearListTable = document.createElement('table');
	yearListTable.id = _Sender.id + '_YearListTable';
	yearListTable.setAttribute('border','0');
	yearListTable.setAttribute('cellpadding','1');
	yearListTable.setAttribute('cellspacing','0');
	yearListTable.setAttribute('width','100%');
	var startYear = _Sender.VisibleDate.getFullYear();
	for(var row = 0; row < 6; row++)
	{
		var yearRow = yearListTable.insertRow(row);
		for(var cel = 0; cel < 2; cel++)
		{
			var yearCell = yearRow.insertCell(cel);
			yearCell.innerHTML = row < 5 ? (startYear+row+cel*5) + '' : (cel == 0? _Sender.NavigationBackSymbol:_Sender.NavigationForthSymbol) ;
			yearCell.setAttribute('align','center');
			yearCell.style.cursor = 'pointer';
			if(row < 5)
			{
				yearCell.setAttribute('onclick','MMCalendarFastVisibleDateSelectYear(eval(' + _Sender.id + '),this.parentNode.parentNode.parentNode,' + row + ',' + cel + ')');
				yearCell.setAttribute('class',_Sender.CSS.FastVisibleDateSelectorYear);
			}
			else
			{
				yearCell.setAttribute('onclick','MMCalendarShiftVisibleYear(eval(' + _Sender.id + '),\'' + yearListTable.id + '\',\'' + (cel == 0?'-':'+') + '\')');
				yearCell.setAttribute('class',_Sender.CSS.SlowNavigation);
			}
		}
	}
	var buttonsTable = document.createElement('table');
	var buttonTableRow = buttonsTable.insertRow(0);
	var buttonTableRowCellToday = buttonTableRow.insertCell(0);
	var buttonTableRowCellOK = buttonTableRow.insertCell(1);
	var buttonTableRowCellCancel = buttonTableRow.insertCell(2);
	buttonsTable.setAttribute('width','100%');
	buttonsTable.setAttribute('border','0');
	buttonsTable.setAttribute('cellpadding','1');
	buttonsTable.setAttribute('cellspacing','0');
	var btnToday = document.createElement('input');
	btnToday.type = 'button';
	btnToday.value = 'Today';
	btnToday.setAttribute('onclick','MMCalendarFastVisibleDateToday(event,eval(' + _Sender.id + '))');
	btnToday.setAttribute('class',_Sender.CSS.FastVisibleDateSelectorToday);
	var btnOK = document.createElement('input');
	btnOK.type = 'button';
	btnOK.value = 'OK';
	btnOK.setAttribute('onclick','MMCalendarFastVisibleDateOK(event,eval(' + _Sender.id + '))');
	btnOK.setAttribute('class',_Sender.CSS.FastVisibleDateSelectorOK);
	var btnCancel = document.createElement('input');
	btnCancel.type = 'button';
	btnCancel.value = 'Cancel';
	btnCancel.setAttribute('onclick','MMCalendarFastVisibleDateCancel(event,eval('+ _Sender.id +'),\'' + div.id + '\')');
	btnCancel.setAttribute('class',_Sender.CSS.FastVisibleDateSelectorCancel);
	MMCalendarAppendChild(buttonTableRowCellToday,btnToday);
	MMCalendarAppendChild(buttonTableRowCellOK,btnOK);
	MMCalendarAppendChild(buttonTableRowCellCancel,btnCancel);
	MMCalendarAppendChild(tableRowButtonsCell,buttonsTable);
	MMCalendarAppendChild(tableRowMonthsCell,monthListTable);
	MMCalendarAppendChild(tableRowYearsCell,yearListTable);
	MMCalendarAppendChild(div,table);
	MMCalendarAppendChild(NavBarCentralCell,div);
	NavBarCentralCell.setAttribute('onclick','MMDatePickerNavBarClick(eval(' + _Sender.id + '), \'' + div.id + '\')');
	NavBarCentralCell.innerHTML += _Sender.VisibleDate.Format(_Sender.VisibleDateFormat,true);
	//END CREATING CENTRAL CELL
	//CREATING FORTH CELL
	var NavBarForthCell = NavBarTableRow.insertCell(NavBarRowCellIndex++);
	NavBarForthCell.style.cursor = 'pointer';
	NavBarForthCell.style.visibility = _Sender.VisibleDate.AddMonths(1).CompareTo(new Date(_Sender.MaximalDate.getFullYear(), _Sender.MaximalDate.getMonth(), _Sender.MaximalDate.DaysInMonth())) > 0? 'hidden':'visible';
	NavBarForthCell.setAttribute('class',_Sender.CSS.SlowNavigationForth);
	NavBarForthCell.setAttribute('nowrap','nowrap');
	NavBarForthCell.setAttribute('align','center');
	NavBarForthCell.style.width = 100/(_Sender.EnableFastNavigation?7:3.5) + '%';
	NavBarForthCell.setAttribute('onclick',"MMCalendarNavigateTo(event,eval(" + _Sender.id + "),1)");
	if(_Sender.NavigationForthImageOff != '' && _Sender.NavigationForthImageOff != null && _Sender.NavigationForthImageOff != 'undefined')
	{
		var img = document.createElement('img');
		img.setAttribute('alt', _Sender.NavigationForthSymbol);
		img.setAttribute('src',_Sender.NavigationForthImageOff);
		img.style.border = 'none';
		if(_Sender.NavigationForthImageOn != '')
		{
			img.setAttribute('onmouseover','this.src="' + _Sender.NavigationForthImageOn + '"');
			img.setAttribute('onmouseout','this.src="' + _Sender.NavigationForthImageOff + '"');
		}
		
		NavBarForthCell.innerHTML = '';
		MMCalendarAppendChild(NavBarForthCell,img);
	}
	else
	{
		NavBarForthCell.innerHTML = _Sender.NavigationForthSymbol;
	}
	NavBarForthCell.title = _Sender.VisibleDate.AddMonths(1).Format(', MMMM , yyyy',true);
	//END CREATING FORTH CELL
	//CREATING FAST FORTH CELL
	if(_Sender.EnableFastNavigation)
	{ 
		var NavBarFastForthCell = NavBarTableRow.insertCell(NavBarRowCellIndex++);
		NavBarFastForthCell.style.cursor = 'pointer';
		NavBarFastForthCell.style.visibility = _Sender.VisibleDate.AddMonths(3).CompareTo(_Sender.MaximalDate) > 0? 'hidden':'visible';
		NavBarFastForthCell.setAttribute('class',_Sender.CSS.FastNavigationForth);
		NavBarFastForthCell.setAttribute('nowrap','nowrap');
		NavBarFastForthCell.setAttribute('align','center');
		NavBarFastForthCell.style.width = (100/7) + '%';
		NavBarFastForthCell.setAttribute('onclick',"MMCalendarNavigateTo(event,eval(" + _Sender.id + "),3)");
		if(_Sender.FastNavigationForthImageOff != '' && _Sender.FastNavigationForthImageOff != null && _Sender.FastNavigationForthImageOff != 'undefined')
		{	
			var img = document.createElement('img');
			img.setAttribute('alt', _Sender.FastNavigationForthSymbol);
			img.setAttribute('src',_Sender.FastNavigationForthImageOff);
			img.style.border = 'none';
			if(_Sender.FastNavigationForthImageOn != '')
			{
				img.setAttribute('onmouseover','this.src="' + _Sender.FastNavigationForthImageOn + '"');
				img.setAttribute('onmouseout','this.src="' + _Sender.FastNavigationForthImageOff + '"');
			}
			
			NavBarFastForthCell.innerHTML = '';
			MMCalendarAppendChild(NavBarFastForthCell,img);
		}
		else
		{
			NavBarFastForthCell.innerHTML = _Sender.FastNavigationForthSymbol;
		}
		NavBarFastForthCell.title = _Sender.VisibleDate.AddMonths(3).Format(', MMMM , yyyy',true);
	}
	// END CREATING FAST FORTH CELL
	// END CREATING NAVIGATION BAR
	MMCalendarAppendChild(NavBarCell,NavBarTable);
}


//<script id='WeekdaysRow' type='text/javascript'>

function SetMMCalendarWeekdaysRow(_Sender, WeekDayRow )
{
	// creating row with weekday names
	var tmpDate = new Date();
	tmpDate.setFullYear(_Sender.VisibleDate.getFullYear(),_Sender.VisibleDate.getMonth(),1);
	
	var WeekCellCount = 0;
	
	for(var weekdayname=_Sender.Weekstart; weekdayname<(7+_Sender.Weekstart); weekdayname++)
	{
		var WeekDayCell = WeekDayRow.insertCell(WeekCellCount++);
		WeekDayCell.setAttribute('align','center');
		WeekDayCell.setAttribute('class',_Sender.CSS.Weekday);
		WeekDayCell.innerHTML = _Sender.Weekdays[weekdayname % 7];
	}
	return WeekDayRow;
}


//<script id='MonthRows' type='text/javascript' >

function SetMMCalendarMonthRows(_Sender, CalenderTable)
{
	var cellCount = 0;
	for(var row = 0; row < 6; row++)
	{
		var WeekRow = CalenderTable.insertRow(CalenderTable.rows.length);
		for(var col = 0; col < 7; col++)
		{
			var WeekRowCell = WeekRow.insertCell(col);
			WeekRowCell.setAttribute('id',_Sender.id + '_MMCell_' + cellCount++);
			WeekRowCell.setAttribute('tooltip','');
			WeekRowCell.setAttribute('onmouseover',"MMCalendarToggleToolTip(eval("+_Sender.id+"),document.getElementById('"+WeekRowCell.id+"'))");
			WeekRowCell.setAttribute('onmouseout',"MMCalendarToggleToolTip(eval("+_Sender.id+"),document.getElementById('"+WeekRowCell.id+"'))");
			WeekRowCell.setAttribute('onclick',"MMCalendarSelectDate(eval(" + _Sender.id + "),'"+WeekRowCell.id+"',new Date(this.getAttribute('date')))");
			WeekRowCell.innerHTML = '&nbsp;';
		}
	}
}


//<script id='GetMMCalendarGrid(_Sender)' type='text/javascript'>

function  GetMMCalendarGrid(_Sender)
{
	if(_Sender.NavigationBackSymbol == '' || _Sender.NavigationBackSymbol == null || typeof(_Sender.NavigationBackSymbol) == 'undefined' )
	{
		_Sender.NavigationBackSymbol = '&lt;';
	}
	if(_Sender.NavigationForthSymbol == '' || _Sender.NavigationForthSymbol == null || typeof(_Sender.NavigationForthSymbol) == 'undefined' )
	{
		_Sender.NavigationForthSymbol = '&gt;';
	}
	
	if(_Sender.FastNavigationBackSymbol == '' || _Sender.FastNavigationBackSymbol == null || typeof(_Sender.FastNavigationBackSymbol) == 'undefined' )
	{
		_Sender.FastNavigationBackSymbol = '&lt;&lt;';
	}
	if(_Sender.FastNavigationForthSymbol == '' || _Sender.FastNavigationForthSymbol == null || typeof(_Sender.FastNavigationForthSymbol) == 'undefined' )
	{
		_Sender.FastNavigationForthSymbol = '&gt;&gt;';
	}
	
	if(_Sender.NavigationBackImageOff.indexOf('.') == -1)
	{
		_Sender.NavigationBackImageOff = '';
	}
	
	if(_Sender.NavigationForthImageOff.indexOf('.') == -1)
	{
		_Sender.NavigationForthImageOff = '';
	}
	
	if(_Sender.FastNavigationBackImageOff.indexOf('.') == -1)
	{
		_Sender.FastNavigationBackImageOff = '';
	}
	
	if(_Sender.FastNavigationForthImageOff.indexOf('.') == -1)
	{
		_Sender.FastNavigationForthImageOff = '';
	}
	var CalendarTable = document.createElement('table');
	CalendarTable.setAttribute('id',_Sender.id + '_tblCalendar');
	CalendarTable.setAttribute('border','0');
	CalendarTable.setAttribute('cellpadding','0');
	CalendarTable.setAttribute('cellspacing','0');
	CalendarTable.setAttribute('class',_Sender.CSS.Calendar);
	CalendarTable.style.width = _Sender.CalendarWidth + 'px';
	
	var CalendarTableRow = CalendarTable.insertRow(0);
	SetMMCalendarNavigationBar(_Sender, CalendarTableRow);
	
	
	CalendarTableRow = CalendarTable.insertRow(CalendarTable.rows.length);
	SetMMCalendarWeekdaysRow(_Sender,CalendarTableRow);
	SetMMCalendarMonthRows(_Sender, CalendarTable);
	return CalendarTable;
}


//<script id='FillMMCalendarGrid' type='text/javascript'>

function FillMMCalendarGrid(_Sender, _CalendarTable)
{
	var calTableID = _CalendarTable.id;
	MMCalendarAppendChild(document.getElementById(_Sender.CalendarHolderId),_CalendarTable, true);
	_CalendarTable = document.getElementById(calTableID);
	var monthDaysCount=1;
	var tmpDate = new Date();
	tmpDate.setFullYear( _Sender.VisibleDate.getFullYear(), _Sender.VisibleDate.getMonth(),1);
	
	var prevMonthDaysCount = _Sender.VisibleDate.AddMonths(-1).DaysInMonth();
	var prevMonthStartShowDate = prevMonthDaysCount - tmpDate.getDay() + 1 + _Sender.Weekstart;
	var prevMonthMonth = _Sender.VisibleDate.AddMonths(-1).getMonth();
	var prevMonthYear =_Sender.VisibleDate.AddMonths(-1).getFullYear();
	var nextMonthMonth = _Sender.VisibleDate.AddMonths(1).getMonth();
	var nextMonthYear =_Sender.VisibleDate.AddMonths(1).getFullYear();
	prevMonthStartShowDate -= prevMonthStartShowDate>prevMonthDaysCount?7:0;
	var nextMonthShowDate = 1;
	var cellCount = 0;
	
	for(var week=0; week < 6; week++) // each row represents a week
	{
		for(var weekday=0; weekday<7;weekday++) // each week has 7 days (strange but it's always so :^) )
		{
			var cell = _CalendarTable.rows[week+2].cells[weekday];
			cell.align = 'center';
			cell.style.width = (100/7)+ '%';
			if(prevMonthStartShowDate<=prevMonthDaysCount) // previous month days
			{
				cell.className = _Sender.CSS.OtherMonthDay;
				var prevMonthRenderedDate = new Date();
				prevMonthRenderedDate.setFullYear(_Sender.VisibleDate.AddMonths(-1).getFullYear());
				prevMonthRenderedDate.setMonth(_Sender.VisibleDate.AddMonths(-1).getMonth());
				prevMonthRenderedDate.setDate(prevMonthStartShowDate);
				if(_Sender.NoOtherMonthDates || ((_Sender.MinimalDate instanceof Date) && _Sender.MinimalDate.CompareTo(prevMonthRenderedDate) == 1))
				{
					cell.disabled = true;
					if(_Sender.NoOtherMonthDates)
						cell.innerHTML = '&nbsp;';
				}
				else
				{
					cell.setAttribute('onclick',"MMCalendarSelectDate(eval(" + _Sender.id + "),'"+cell.id+"',new Date('" + prevMonthRenderedDate.Format("MMMM dd, yyyy", false) + "'))");
					try {_Sender.OnClientOtherMonthDayRender(_Sender,cell.id,prevMonthRenderedDate);} catch(err) {}
					cell.setAttribute('title',prevMonthRenderedDate.Format('MMMM dd, yyyy', true));
					cell.innerHTML = prevMonthStartShowDate;
				}
				prevMonthStartShowDate++;
			}
			else // current month days. here is where the problems begin
			{
				var VisibleRenderedDate = new Date(_Sender.VisibleDate.getFullYear(),_Sender.VisibleDate.getMonth(),monthDaysCount);
				if(monthDaysCount <= _Sender.VisibleDate.DaysInMonth())
				{
					cell.style.cursor = 'pointer';
					if( ((_Sender.MinimalDate instanceof Date && _Sender.MinimalDate != 'Invalid Date' && _Sender.MinimalDate != 'NaN') &&  _Sender.MinimalDate.CompareTo(VisibleRenderedDate) == 1)  || (( _Sender.MaximalDate instanceof Date) &&   _Sender.MaximalDate.CompareTo(VisibleRenderedDate) == -1))
					{
						cell.disabled = true;
						cell.className = _Sender.CSS.ClosedDay;
					}
					else
					{
						if(_Sender.SelectedDate!=null && (_Sender.SelectedDate instanceof Date && _Sender.SelectedDate != 'Invalid Date' && _Sender.SelectedDate != 'NaN' ) && (_Sender.SelectedDate.CompareTo(VisibleRenderedDate) == 0))
						{
							// selected date
							cell.className = _Sender.CSS.SelectedDay;
						}
						else // well it's just a regular day... nothing special..
						{
							if(_Sender.TodaysDate.CompareTo(VisibleRenderedDate) == 0)
							{
								// TODAY's date
								cell.className = _Sender.CSS.TodaysDay;
							}
							else 
							{
								cell.className = _Sender.CSS.RegularDay;
							}
						}	
						cell.setAttribute('date',VisibleRenderedDate.Format("MMMM dd, yyyy", false));
					}
					try {_Sender.OnClientDayRender(_Sender,cell.id,VisibleRenderedDate);} catch(err) {}
					cell.setAttribute('title',VisibleRenderedDate.Format('MMMM dd, yyyy', true));
					cell.innerHTML = monthDaysCount;
					monthDaysCount++;
				}
				else
				{
					cell.className = _Sender.CSS.OtherMonthDay;
					var nextMonthRenderedDate = new Date();
					nextMonthRenderedDate.setFullYear(_Sender.VisibleDate.AddMonths(1).getFullYear());
					nextMonthRenderedDate.setMonth(_Sender.VisibleDate.AddMonths(1).getMonth());
					nextMonthRenderedDate.setDate(nextMonthShowDate);
					if(_Sender.NoOtherMonthDates || ((_Sender.MaximalDate instanceof Date) && _Sender.MaximalDate.CompareTo(nextMonthRenderedDate) == -1 ))
					{
						cell.disabled = true;
						if(_Sender.NoOtherMonthDates)
							cell.innerHTML = '&nbsp;'
					}
					else
					{
						cell.setAttribute('onclick',"MMCalendarSelectDate(eval(" + _Sender.id + "),'"+cell.id+"',new Date('" + nextMonthRenderedDate.Format("MMMM dd, yyyy", false) +"'))");
						try {_Sender.OnClientOtherMonthDayRender(_Sender,cell.id,prevMonthRenderedDate);} catch(err) {}
						cell.setAttribute('title',nextMonthRenderedDate.Format('MMMM dd, yyyy', true));
						cell.innerHTML = nextMonthShowDate;
					}
					nextMonthShowDate++;
				}
			}
		}
	}
}


//<script id='SetCalendarPosition' type='text/javascript'>

function MMCalendarSetCalendarPosition(_Sender)
{
	var calHolder = document.getElementById(_Sender.CalendarHolderId);
	var offsetLeft = 0
	var offsetTop = 0
	var calHolderPos = MMCalendarFindPos(calHolder);
	calHolder.style.left = calHolderPos[0] + offsetLeft + 'px';
	calHolder.style.top = calHolderPos[1] + offsetTop + 'px';
	calHolderPos[0] = eval(calHolder.style.left.replace('px',''));
	calHolderPos[1] = eval(calHolder.style.top.replace('px',''));
	var body = document.documentElement? document.documentElement:document.body;
	var calTable = document.getElementById(_Sender.id + '_tblCalendar');
	var width = calTable.offsetWidth;
	var height = calTable.offsetHeight;
	if((calHolderPos[0] + width) >= (body.clientWidth - body.scrollLeft) )
	{
		calHolder.style.left = (body.clientWidth - width) + 'px';
	}
	if(calHolderPos[0] < 0 )
	{
		calHolder.style.left = '0px';
	}
	if(calHolderPos[1] + height >= (window.innerHeight?window.innerHeight:body.clientHeight) + body.scrollTop )
	{
		calHolder.style.top = ((window.innerHeight?window.innerHeight:body.clientHeight) + body.scrollTop - height) + 'px';
	}
	if(calHolderPos[1]<0 )
	{
		calHolder.style.top = '0px';
	}
}


//<script id='CalendarEvents' type='text/javascript'>

function MMCalendarNavigateTo(e,_Sender, _Months)
{
	if(_Months < 0)
	{
		var d = _Sender.VisibleDate.AddMonths(_Months);
		var dm = _Sender.MinimalDate;
		if(new Date(d.getFullYear(),d.getMonth(),1).CompareTo(new Date(dm.getFullYear(),dm.getMonth(),1)) < 0) return false;
	}
	if(_Sender.VisibleDate.AddMonths(_Months).CompareTo(new Date(_Sender.MaximalDate.getFullYear(), _Sender.MaximalDate.getMonth(), _Sender.MaximalDate.DaysInMonth())) > 0) return false;
	var ret
	try { ret = _Sender.OnClientNavigating(_Sender,_Sender.VisibleDate.AddMonths(_Months),_Months);} catch(err) {}
	if(ret == false) return false;
	_Sender.VisibleDate = _Sender.VisibleDate.AddMonths(_Months);
	_Sender.Create();
	try { _Sender.OnClientNavigation (_Sender,_Sender.VisibleDate.AddMonths(-1*_Months),_Months);} catch(err) {}
	if(!e) e = window.event;
	e.cancelBubble = true;
	if(e.stopPropagation) e.stopPropagation();
}
function MMCalendarSlide(_Sender, table, gridId, InTableIndex, dir, shiftedDay)	
{	
	var calGrid = document.getElementById(gridId);	
	var shiftTable = new Array();	
	var shiftRow = new Array();
	var freeMember = '&nbsp;';
	if(InTableIndex == 9)	
	{	
		//_Sender.Create();	
		MMCalendarAppendChild(document.getElementById(_Sender.CalendarHolderId),_Sender.CalendarTable, true);	
		return;	
	}	
		
	if(dir > 0) // if ltr then scroll right else scroll left	
	{	
		for(var c = 0; c < 7; c++)	
		{	
			for(var r = 2; r < 8; r++)	
			{		
				if(shiftTable[r-2] == null)	shiftTable[r-2] = new Array();	
					
				if(c+1 < calGrid.rows[r].cells.length)	
				{	
					if(calGrid.rows[r].cells[c+1].style.visibility == 'hidden')	
					{	
						calGrid.rows[r].cells[c+1].innerHTML = '&nbsp;';	
						calGrid.rows[r].cells[c+1].style.visibility = 'visible';	
					}	
					shiftTable[r-2][c] = calGrid.rows[r].cells[c+1].innerHTML;	
				}	
				else	
				{	
					var val = table[r-2][(c+InTableIndex-1) - (calGrid.rows[r].cells.length)];	
					shiftTable[r-2][c] = InTableIndex == 1?'&nbsp;':val == 0? '&nbsp;':val;	
				}	
				calGrid.rows[r].cells[c].setAttribute('onmouseover','');	
				calGrid.rows[r].cells[c].setAttribute('onmouseout','');	
			}	
			if(c+1 < calGrid.rows[1].cells.length)	
			{	
				shiftRow[c] = calGrid.rows[1].cells[c+1].innerHTML;
			}
			else
			{
				shiftRow[c] = InTableIndex == 1?'&nbsp;':shiftedDay;
			}
			if(c==0)
			{
				freeMember = calGrid.rows[1].cells[c].innerHTML;
			}
		}	
	}	
	else //if ltr then scroll left else scroll right	
	{	
		for(var c = 0; c < 7; c++)	
		{	
			for(var r = 2; r < 8; r++)	
			{	
				if(shiftTable[r-2] == null)	shiftTable[r-2] = new Array();	
				if(c == 0)	
				{	
					var val = table[r-2][table[r-2].length-(InTableIndex-1)];	
					shiftTable[r-2][c] = InTableIndex == 1?'&nbsp;':val == 0? '&nbsp;':val;	
				}	
				else	
				{	
					if(calGrid.rows[r].cells[c-1].style.visibility == 'hidden')	
					{	
						calGrid.rows[r].cells[c-1].innerHTML = '&nbsp;';	
						calGrid.rows[r].cells[c-1].style.visibility = 'visible';	
					}	
					shiftTable[r-2][c] = calGrid.rows[r].cells[c-1].innerHTML;	
				}	
				calGrid.rows[r].cells[c].setAttribute('onmouseover','');	
				calGrid.rows[r].cells[c].setAttribute('onmouseout','');	
			}	
			if(c == 0)	
			{	
				shiftRow[c] = InTableIndex == 1?'&nbsp;':shiftedDay;
				freeMember = calGrid.rows[1].cells[calGrid.rows[1].cells.length-1].innerHTML;
			}
			else
			{
				shiftRow[c] = calGrid.rows[1].cells[c-1].innerHTML;
			}
		}	
	}	
		
	for(var c =0; c< 7; c++)	
	{	
		for(var r = 2; r < 8; r++)	
		{		
			calGrid.rows[r].cells[c].innerHTML = shiftTable[r-2][c] ;	
		}	
		calGrid.rows[1].cells[c].innerHTML = shiftRow[c];
	}	
	if(InTableIndex < 9)	
	{	
		InTableIndex++;	
		var str = '[[' + table[0] + '],[' + table[1] + '],[' + table[2] + '],[' + table[3] + '],[' + table[4] + '],['+ table[5] + ']]';	
		setTimeout("MMCalendarSlide(eval('" + _Sender.id + "')," + str + ", '" + gridId + "'," + InTableIndex + "," + dir + ",'" + freeMember + "')",50);
	}	
}	
function MMCalendarToggleToolTip(_Sender, _Cell)
{
	var ttpos = MMCalendarFindPos(_Cell);
	var ttel = document.getElementById(_Sender.ToolTipElementId);
	ttel.className = _Sender.CSS.ToolTip;
	if(ttel.style.display == 'none')
	{
		ttel.style.left = '0px';
		ttel.style.top = '0px';
		
		
		if(_Sender.DebugMode)
		{
			ttel.innerHTML = _Cell.getAttribute('title');
		}
		else
		{
			ttel.innerHTML = _Cell.getAttribute('tooltip');
		}
		//alert(ttel.innerHTML);
		if(ttel.innerHTML != '')
			ttel.style.display = 'block';
		
		//------------------------------------
		// םו הא¸ע עףכעטןף גץמהטע חא דנאםטצף ‎ךנאםא.
		var bodyElement = document.documentElement;
		var width = ttel.offsetWidth;
		if (ttpos[0] + ttel.offsetWidth <= bodyElement.clientWidth + bodyElement.scrollLeft)
		{
			ttel.style.left = ttpos[0] + 'px';
		}
		else
		{
			ttel.style.left = (bodyElement.clientWidth + bodyElement.scrollLeft - ttel.offsetWidth) + 'px';
		}
		ttel.noWrap = true;
		ttel.style.top = (ttpos[1] - _Cell.offsetHeight + 70) + 'px';
		//------------------------------------
	}
	else
	{
		ttel.style.display = 'none';
	}
}
function MMCalendarSelectDate(_Sender, _CellId, _Date)
{
	var ret = true;
	try {ret = _Sender.OnClientDateSelecting (_Sender,_CellId, _Date);} catch(err) {}
	if(ret == false) return false;
	_Sender.SelectedDate = _Date;
	_Sender.inputs[4].value = _Date.Format('MMMM dd, yyyy',false);
	var textBox = document.getElementById(_Sender.DateTextBoxId);
	if(textBox != null)
	{
		textBox.value = _Date.Format(_Sender.DateFormat);
	}
	MMDatePickerToggleMMCalendar(_Sender);
	try { _Sender.OnClientDateSelected(_Sender, _CellId, _Date);} catch(err) {}
}
function MMCalendarFindPos(obj)
{
var curleft = curtop = 0;
if (obj.offsetParent)
{
	curleft = obj.offsetLeft;
	curtop = obj.offsetTop;
	
	while (obj = obj.offsetParent)
	{
		if (obj.tagName.toLowerCase() == 'div') break;	
			
		var sTop; // = obj.style.top.replace('px','');
		var sLeft; // = obj.style.left.replace('px','');
		if (obj.currentStyle)
		{
			if(!obj.style.top || obj.style.top == '')
				sTop = obj.currentStyle['top'].replace('px','');
			if(!obj.style.left || obj.style.left == '')
				sLeft = obj.currentStyle['left'].replace('px','');
		}
		else
		{
			try
			{
				if(!obj.style.top || obj.style.top == '')
					sTop = document.defaultView.getComputedStyle(obj,null).getPropertyValue('top');
				if(!obj.style.left || obj.style.left == '')
					sLeft = document.defaultView.getComputedStyle(obj,null).getPropertyValue('left');
			}
			catch(e)
			{
			}
		}

		var styletop = eval(sTop == null?obj.offsetTop:(sTop == '' || sTop == 'auto'?0:sTop));
		var styleleft = eval(sLeft == null?obj.offsetLeft:(sLeft == '' || sLeft == 'auto'?0:sLeft));
		curleft += obj.offsetLeft - (styleleft == null?0:styleleft);
		curtop += obj.offsetTop - (styletop == null?0:styletop);
	}
}	return [curleft,curtop];
}
function MMDatePickerNavBarClick(Instance, _FastVisDateSelectorHolderID)
{
	var fvdsh = document.getElementById(_FastVisDateSelectorHolderID);
	fvdsh.style.display = 'block'
	fvdsh.style.left = '0px'
	fvdsh.style.top = '0px'
}
function MMCalendarFastVisibleDateSelectMonth(_Sender, _Table, r, c)
{	
	var table = _Table;
	for(var row=0; row < 6; row++)
	{
		for(var cel = 0; cel < 2; cel++)
		{
			if(row == r && cel == c)
			{
				table.rows[row].cells[cel].className = _Sender.CSS.FastVisibleDateSelectorSelectedMonth;
				_Sender.InnerFastVisibleMonth = row + cel * 6; //table.rows[row].cells[cel].innerHTML;
			}
			else
			{
				table.rows[row].cells[cel].className = _Sender.CSS.FastVisibleDateSelectorMonth;
			}
		}
	}
}
function MMCalendarFastVisibleDateSelectYear(_Sender, _Table, r, c)
{	
	var table = _Table;
	for(var row=0; row < 5; row++)
	{
		for(var cel = 0; cel < 2; cel++)
		{
			if(row == r && cel == c)
			{
				table.rows[row].cells[cel].className = _Sender.CSS.FastVisibleDateSelectorSelectedYear;
				_Sender.InnerFastVisibleYear = eval(table.rows[row].cells[cel].innerHTML);
			}
			else
			{
				table.rows[row].cells[cel].className = _Sender.CSS.FastVisibleDateSelectorYear;
			}
		}
	}
}
function MMCalendarShiftVisibleYear(Instance,YearTableID, shift)
{	
	var yearTable = document.getElementById(YearTableID);
	for(var r = 0; r < 5; r++)
	{
		for(var c = 0; c < 2; c++)
		{
			yearTable.rows[r].cells[c].innerHTML = eval(yearTable.rows[r].cells[c].innerHTML + shift + '5');
			if(yearTable.rows[r].cells[c].innerHTML == Instance.InnerFastVisibleYear)
			{
				yearTable.rows[r].cells[c].className = Instance.CSS.FastVisibleDateSelectorSelectedYear;
			}
			else
			{
				yearTable.rows[r].cells[c].className = Instance.CSS.FastVisibleDateSelectorMonth;
			}
		}
	}
}	
function MMCalendarFastVisibleDateCancel(e,_Sender, id)
{
	document.getElementById(id).style.display = 'none';
	if(!e) e = window.event;
	e.cancelBubble = true;
	if(e.stopPropagation) e.stopPropagation();
	_Sender.InnerFastVisibleYear = null;
	_Sender.InnerFastVisibleMonth = null;
}
function MMCalendarFastVisibleDateOK(e,_Sender)
{
	if(_Sender.InnerFastVisibleYear != null)
	{
		_Sender.VisibleDate.setFullYear(_Sender.InnerFastVisibleYear);
	}
	if(_Sender.InnerFastVisibleMonth != null)
	{
		_Sender.VisibleDate.setMonth(_Sender.InnerFastVisibleMonth);
	}
	document.getElementById(_Sender.CalendarHolderId).innerHTML = '';
	if(!e) e = window.event;
	e.cancelBubble = true;
	if(e.stopPropagation) e.stopPropagation();
	_Sender.Create();
}
function MMCalendarFastVisibleDateToday(e,_Sender)
{
	_Sender.VisibleDate = _Sender.TodaysDate;
	document.getElementById(_Sender.CalendarHolderId).innerHTML = '';
	if(!e) e = window.event;
	e.cancelBubble = true;
	if(e.stopPropagation) e.stopPropagation();
	_Sender.Create();
}


//<script type='text/javascript' id='MMCalendar'>

function MMCreateCalendar()
{
	if(!this.valueOf()) return false;
	FillMMCalendarGrid(this,GetMMCalendarGrid(this, this.CalendarHolderId));
	try {
	var calHolder = document.getElementById(this.CalendarHolderId);
	calHolder.style.left = (parseInt(calHolder.style.left.replace('px','')) - 0) + 'px';
	calHolder.style.top = (parseInt(calHolder.style.top.replace('px','')) - 0) + 'px';
	} catch (err) {}
	MMCalendarSetCalendarPosition(this);
}
function MMCalendarSetSpecialDays()
{
	if(!this.valueOf()) return false;
	try
	{
		this.SpecialDays = new Array();
		var allSpecialDays = new Array();
		var specDays = arguments.length!=0? arguments[0] : this.inputs[5].value;
		//--------------------------------
		var specials = new Array();
		var i = 0;
		while(specDays.indexOf('}')!= -1)
		{
			specials[i] = specDays.substring(0,specDays.indexOf('}')+1);
			specials[i] = specials[i].substring(1,specials[i].length -1);
			var date = new Date(specials[i].split('|')[0]);
			var css = specials[i].split('|')[1];
			var ttip = specials[i].split('|')[2];
			var available = specials[i].split('|')[3].toLowerCase() == 'true';
			var noarr = specials[i].split('|')[4].toLowerCase() == 'true';
			var nodep = specials[i].split('|')[5].toLowerCase() == 'true';
			
			allSpecialDays[i] = new MMCalendarSpecialDay(date,css,ttip,available,noarr,nodep);
			
			specDays = specDays.substring(specDays.indexOf('}')+1);
			i++;
		}
		for(i=0;i<allSpecialDays.length;i++)
		{
			if(this.SpecialDays[allSpecialDays[i].Date.getFullYear()] == null)
			{
				this.SpecialDays[allSpecialDays[i].Date.getFullYear()]=new Array();
			}
			if(this.SpecialDays[allSpecialDays[i].Date.getFullYear()][allSpecialDays[i].Date.getMonth()] == null)
			{
				this.SpecialDays[allSpecialDays[i].Date.getFullYear()][allSpecialDays[i].Date.getMonth()] = new Array();
			}
			this.SpecialDays[allSpecialDays[i].Date.getFullYear()][allSpecialDays[i].Date.getMonth()][allSpecialDays[i].Date.getDate()] = allSpecialDays[i];
		}
		//--------------------------------
	}
	catch(err)
	{
		this.SpecialDays = null;
	}
}
function MMCalendarSetSelectedDate()
{	
	if(arguments.length == 0 || !(arguments[0] instanceof Date)) return;
	this.SelectedDate = arguments[0];
	this.inputs[4].value = arguments[0].Format('MMMM dd, yyyy',false);
	document.getElementById(this.DateTextBoxId).value = arguments[0].Format(this.DateFormat,true);
}	
function MMCalendarSetVisibleDate()
{	
	if(arguments.length==0 || !(arguments[0] instanceof Date)) return;
	this.VisibleDate = arguments[0];
	this.inputs[2].value = arguments[0].Format('MMMM dd, yyyy',false);
}	
function MMCalendarSetMinimalDate()
{	
	if(arguments.length==0 || !(arguments[0] instanceof Date)) return;
	this.MinimalDate = arguments[0];
}	
function MMCalendarSetMaximalDate()
{	
	if(arguments.length==0 || !(arguments[0] instanceof Date)) return;
	this.MaximalDate = arguments[0];
}	
function MMCalendarSetTodaysDate()
{	
	if(arguments.length==0 || !(arguments[0] instanceof Date)) return;
	this.TodaysDate = arguments[0];
}	
function MMCalendarClear()
{	
	document.getElementById(this.DateTextBoxId).value = this.DateFormat.replace(/y|M|d/gi,' ');
	this.inputs[4].value = '';
	this.SelectedDate = null;
	//this.MinimalDate = null;
	//this.MaximalDate = null;
	try
	{
		this.OnClientClear(this);
	}
	catch(err)
	{}
}	
function MMCalendarDisable()
{	
	try{document.getElementById(this.DateTextBoxId).disabled = true;}catch(err){}
	try{document.getElementById(this.ImagePopUpId).disabled = true;}catch(err){}
}	
function MMCalendarEnable()
{	
	try{document.getElementById(this.DateTextBoxId).disabled = false;}catch(err){}
	try{document.getElementById(this.ImagePopUpId).disabled = false;}catch(err){}
}	
function MMCalendarLoad()
{
	var selDate = this.inputs[4];
	var txtDate = document.getElementById(this.DateTextBoxId);
	if(selDate.value != "")
	{
		var date = new Date(selDate.value).Format(this.DateFormat,false);
		if(date == null)
		{
			date = this.DateFormat.replace('yyyy','    ').replace('MM','  ').replace('dd','  ')
		}
		txtDate.value = date;
	}
	try {this.OnClientDatePickerLoading(this);} catch(err) {}
}
function MMCalendar(_Inputs)
{
	this.inputs = _Inputs;
	this.id = 'MMCalendar1';
	if(_Inputs != 'undefned')
	{
		try{this.MinimalDate = new Date(_Inputs[0].value);}catch(err){this.MinimalDate = null;}
		try{this.MaximalDate = new Date(_Inputs[1].value);}catch(err){this.MaximalDate = null;}
		try{this.VisibleDate = new Date(_Inputs[2].value);}catch(err){this.VisibleDate = null;}
		try{this.TodaysDate = new Date(_Inputs[3].value);}catch(err){this.TodaysDate = null;}
		try{this.SelectedDate = new Date(_Inputs[4].value);}catch(err){this.SelectedDate = null;}
	}
	this.SetSpecialDays();
	
	this.CSS = new MMCalendarCSS();
	this.Months = new Array(31,((this.VisibleDate.getFullYear() % 4 )== 0)? 29:28,31,30,31,30,31,31,30,31,30,31);
	this.Weekdays = new Array('Su','Mo','Tu','We','Th','Fr','Sa');
	this.Weekstart = 0;
	this.NavigationBackSymbol = '';
	this.NavigationForthSymbol = '';
	this.NavigationBackImageOff = '';
	this.NavigationForthImageOff = '';
	this.NavigationBackImageOn = '';
	this.NavigationForthImageOn = '';
	this.EnableFastNavigation = false; 
	this.FastNavigationBackSymbol = '';
	this.FastNavigationForthSymbol = '';
	this.FastNavigationBackImageOff = '';
	this.FastNavigationForthImageOff = '';
	this.FastNavigationBackImageOn = '';
	this.FastNavigationForthImageOn = '';
	this.CalendarHolderId = '';
	this.ToolTipElementId = '';
	this.DateTextBoxId = '';
	this.ImagePopUpId = '';
	this.CalendarWidth = 180;
	this.InnerFastVisibleYear = null;
	this.InnerFastVisibleMonth = null;
	this.DateFormat = 'yyyy-MM-dd';
	this.VisibleDateFormat = 'MMM yy';
	this.DebugMode = false;
	this.OnClientCalendarClose = null;
	this.OnClientCalendarPreRender = null;
	this.OnClientDatePickerLoading = null;
	this.OnClientDateSelected = null;
	this.OnClientDateSelecting = null;
	this.OnClientDayRender = null;
	this.OnClientNavigating = null;
	this.OnClientNavigation = null;
	this.OnClientOtherMonthDayRender = null;
	this.OnClientClear = null;
}
MMCalendar.prototype.Create = MMCreateCalendar;
MMCalendar.prototype.SetSpecialDays = MMCalendarSetSpecialDays;
MMCalendar.prototype.SelectDate = MMCalendarSetSelectedDate;
MMCalendar.prototype.SetVisibleDate = MMCalendarSetVisibleDate;
MMCalendar.prototype.SetMinimalDate = MMCalendarSetMinimalDate;
MMCalendar.prototype.SetMaximalDate = MMCalendarSetMaximalDate;
MMCalendar.prototype.SetTodaysDate = MMCalendarSetTodaysDate;
MMCalendar.prototype.Clear = MMCalendarClear;
MMCalendar.prototype.Disable = MMCalendarDisable;
MMCalendar.prototype.Enable = MMCalendarEnable;
MMCalendar.prototype.Load = MMCalendarLoad;


//<script id='DatePickerFunctions' type='text/javascript' >

function MMDatePickerToggleMMCalendar(Instance)
{
	var CalendarHolder = document.getElementById(Instance.CalendarHolderId);
	if(CalendarHolder.style.display == 'none')
	{
		try{ var res = Instance.OnClientCalendarPreRender(Instance); if(res == false) return;}catch(err){}
		CalendarHolder.style.display = 'block';
		Instance.Create();
	}
	else
	{
		CalendarHolder.style.display = 'none';
		//document.getElementById(Instance.id + '_NavBarCentralCell').innerHTML = '';
		try {Instance.OnClientCalendarClose(Instance);} catch(err) {}
	}
}
function MMDatePickerWhichElement(e,_Sender, _TargetId)
{
	var targ;
	if (!e) e = window.event;
	if (e.target) targ = e.target;
	else targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	
	var ClickedOnMe = false;
	while(targ.parentNode)
	{
		if(targ.id == _TargetId)
		{
			ClickedOnMe = true;
			break;
		}
		targ = targ.parentNode;
	}
	if(!ClickedOnMe)
	{
		var cHolder = document.getElementById(_Sender.CalendarHolderId);
		if(cHolder.style.display != 'none')
		{
			document.getElementById(_Sender.id + '_NavBarCentralCell').innerHTML = '';
			cHolder.style.display = 'none';
			cHolder.style.left = '';
			cHolder.style.top = '';
			try {_Sender.OnClientCalendarClose(_Sender);} catch(err) {}
		}
	}
}
function MMDatePickerDateInputKeyDown(e, _Sender)
{
	if(!e) e = window.event;
	if(e.keyCode == 8)
	{
		_Sender.Clear();
		
	}
}


//<script id='MMCalendarCallBackScript' type='text/javascript' >

function MMCalendar_CallBackError(arg, context)
{

}
function MMCalendar_CallBackNavigationEnd(arg, context)
{
	var args = arg.split('$^$');
	var cal = eval(args[0]);
	cal.inputs[0].value = args[1]; //minimal
	try{cal.MinimalDate = new Date(args[1]);}catch(e){cal.MinimalDate = null;}
	cal.inputs[1].value = args[2]; //maximal
	try{cal.MaximalDate = new Date(args[2]);}catch(e){cal.MaximalDate = null;}
	cal.inputs[2].value = args[3]; //visible
	try{cal.VisibleDate = new Date(args[3]);}catch(e){cal.VisibleDate = null;}
	cal.inputs[3].value = args[4]; //today
	try{cal.TodaysDate = new Date(args[4]);}catch(e){cal.TodaysDate = null;}
	cal.inputs[4].value = args[5]; //selected
	if(args[5] == '')
	{
		document.getElementById(cal.DateTextBoxId).value = cal.DateFormat.replace(/(y|M|d)/gi,' ');
	}
	else
	{
		try{cal.SelectedDate = new Date(args[5]);}catch(e){cal.SelectedDate = null;}
		document.getElementById(cal.DateTextBoxId).value = cal.SelectedDate.Format(cal.DateFormat,false);
	}
	cal.inputs[5].value = args[6]; //specials
	cal.SetSpecialDays();
}
function MMCalendar_CallBackSelectDateEnd(arg, context)
{
	var args = arg.split('$^$');
	var cal = eval(args[0]);
	cal.inputs[0].value = args[1]; //minimal
	try{cal.MinimalDate = new Date(args[1]);}catch(e){cal.MinimalDate = null;}
	cal.inputs[1].value = args[2]; //maximal
	try{cal.MaximalDate = new Date(args[2]);}catch(e){cal.MaximalDate = null;}
	cal.inputs[2].value = args[3]; //visible
	try{cal.VisibleDate = new Date(args[3]);}catch(e){cal.VisibleDate = null;}
	cal.inputs[3].value = args[4]; //today
	try{cal.TodaysDate = new Date(args[4]);}catch(e){cal.TodaysDate = null;}
	cal.inputs[4].value = args[5]; //selected
	if(args[5] == '')
	{
		document.getElementById(cal.DateTextBoxId).value = cal.DateFormat.replace(/(y|M|d)/gi,' ');
	}
	else
	{
		try{cal.SelectedDate = new Date(args[5]);}catch(e){cal.SelectedDate = null;}
		document.getElementById(cal.DateTextBoxId).value = cal.SelectedDate.Format(cal.DateFormat,false);
	}
	cal.inputs[5].value = args[6]; //specials
	cal.SetSpecialDays();
}
//No filthy comments as you can see. Happy now??



