////////////////////////////////////
var MonthDays = new Array();
MonthDays[0] = new Array(); // not Leap year
MonthDays[0][0]  = 0;
MonthDays[0][1]  = 31;
MonthDays[0][2]  = 28;
MonthDays[0][3]  = 31;
MonthDays[0][4]  = 30;
MonthDays[0][5]  = 31;
MonthDays[0][6]  = 30;
MonthDays[0][7]  = 31;
MonthDays[0][8]  = 31;
MonthDays[0][9]  = 30;
MonthDays[0][10] = 31;
MonthDays[0][11] = 30;
MonthDays[0][12] = 31;
MonthDays[1] = new Array(); // Leap year
MonthDays[1][0]  = 0;
MonthDays[1][1]  = 31;
MonthDays[1][2]  = 29;
MonthDays[1][3]  = 31;
MonthDays[1][4]  = 30;
MonthDays[1][5]  = 31;
MonthDays[1][6]  = 30;
MonthDays[1][7]  = 31;
MonthDays[1][8]  = 31;
MonthDays[1][9]  = 30;
MonthDays[1][10] = 31;
MonthDays[1][11] = 30;
MonthDays[1][12] = 31;
/*
 m - month, y - year
 dayobj - object of the day because we must update it if necessary
*/
function checkMonth(dayobj, m, y)
{
	__checkMonth__(dayobj, m, y);
}
function __checkMonth__(dayobj, m, y)
{
	if (MonthDays[isLeapYear(y)][m] < dayobj.value)
		dayobj.value = MonthDays[isLeapYear(y)][m];
}

/*
Indicates whether a specified year is a leap year.(returns the first index of two-dimensional MonthDays array)
The second index is a number of month (1..12).
Определяет високосность года. Возвращает значение первого индекса двумерного массива MonthDays)
Второй индекс - номер месяца (1..12)
*/
function isLeapYear(_Year)
{
  return ((_Year % 4) == 0) && (((_Year % 100) != 0) || ((_Year % 400) == 0)) ? 1 : 0;
}

/////////////////////////////////////////////////////////////////////////////////////////


