//############_Текущая дата_################
var bissextileFeb = 0;
function numToString(tdate)
{
	tdate += "";
	return tdate;
}

var today = new Date;
var todayDay = today.getDate();// < 10 ? "0" + today.getDate() : today.getDate()
var todayMonth = today.getMonth()+1;// < 10 ? "0" + (today.getMonth()+1) : (today.getMonth()+1)
if (document.layers || window.navigator.userAgent.toLowerCase().match("gecko"))
	{var todayYear = 1900 + today.getYear();}
else
	{var todayYear = today.getYear();}

var arrTodayMonth = new Array();

arrTodayMonth[0] = "Месяц";
arrTodayMonth[1] = "января";
arrTodayMonth[2] = "февраля";
arrTodayMonth[3] = "марта";
arrTodayMonth[4] = "апреля";
arrTodayMonth[5] = "мая";
arrTodayMonth[6] = "июня";
arrTodayMonth[7] = "июля";
arrTodayMonth[8] = "августа";
arrTodayMonth[9] = "сентября";
arrTodayMonth[10] = "октября";
arrTodayMonth[11] = "ноября";
arrTodayMonth[12] = "декабря";

var arrMonth = new Array();

arrMonth[0] = "Месяц";
arrMonth[1] = "январь";
arrMonth[2] = "февраль";
arrMonth[3] = "март";
arrMonth[4] = "апрель";
arrMonth[5] = "май";
arrMonth[6] = "июнь";
arrMonth[7] = "июль";
arrMonth[8] = "август";
arrMonth[9] = "сентябрь";
arrMonth[10] = "октябрь";
arrMonth[11] = "ноябрь";
arrMonth[12] = "декабрь";

var arrDayIntoMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

var tmpBissextile = (todayYear/4)*4;
if (tmpBissextile == todayYear)
	{arrDayIntoMonth[1] = 29;}
else
	{arrDayIntoMonth[1] = 28;}


var m;
var selDayFlag = 0;
//onchange="changeSelectForm('model',this.options[this.selectedIndex].value);"
function changeSelectForm(nameSelectForm,varYear,selectMonth,varDay)
{
//получение значения формы "Месяц" и значения формы "День", если "День" был выбран
	var changeMonth = document.forms[nameSelectForm].elements[selectMonth].value;
	if (document.forms[nameSelectForm].elements[varDay].selectedIndex)
	{
		var changeDay = document.forms[nameSelectForm].elements[varDay].value;
		selDayFlag = 1;
	}
	else
		{selDayFlag = 0;}
//Выяснение номера месяца
	if (changeMonth && changeMonth != 0)//arrMonth[]
	{
		for (var i = 1; i < arrMonth.length; i++)
		{
			if (i == changeMonth)//arrMonth[]
				{m = i;}
		}
//Проверка на "Февраль"
		if (m == 2)//arrMonth[]arrMonth[]
		{
//Выяснение високосности
			var tmpChangeYear = document.forms[nameSelectForm].elements[varYear].options[document.forms[nameSelectForm].elements[varYear].selectedIndex].value;
			var tmpBissextile = (parseInt(tmpChangeYear) % 4);
//Корректировка количества дней в феврале
			if (tmpBissextile == 0)
				{arrDayIntoMonth[1] = 29;}
			else
				{arrDayIntoMonth[1] = 28;}
		}
//Построение списка дней в месяце
		document.forms[nameSelectForm].elements[varDay].length = 0;
		document.forms[nameSelectForm].elements[varDay].length = 1;
		document.forms[nameSelectForm].elements[varDay].options[0] = new Option("День","День",true,false);
		document.forms[nameSelectForm].elements[varDay].length = arrDayIntoMonth[m-1];

		for (var i = 1; i <= arrDayIntoMonth[m-1]; i++)
		{
			document.forms[nameSelectForm].elements[varDay].options[i] = new Option(i,i,true,false);
		}
	}

	if (selDayFlag != 0)
	{
		//document.forms[nameSelectForm].elements[varDay].options[i].selected = true;
		var daySelLength = document.forms[nameSelectForm].elements[varDay].length;//options[document.forms['formFilterRating'].elements['dayafter'].
		for (var i = 0; i < daySelLength; i++)
		{
			tmpOptSelDay = document.forms[nameSelectForm].elements[varDay].options[i].value;//alert(todayDay + " " + tmpOptSelDay);
			if (tmpOptSelDay == changeDay)
				{document.forms[nameSelectForm].elements[varDay].options[i].selected = true;}
		}
	}
}

function afterLife()
{
	var yearSelLength = document.forms['formFilterRating'].elements['yearafter'].length;
	for (var i = 0; i < yearSelLength; i++)
	{
		tmpOptSelYear = document.forms['formFilterRating'].elements['yearafter'].options[i].value;
		if (tmpOptSelYear == todayYear)
			{document.forms['formFilterRating'].elements['yearafter'].options[i].selected = true;}
	}

	var monthSelLength = document.forms['formFilterRating'].elements['monthafter'].length;
	for (var i = 0; i < monthSelLength; i++)
	{
		tmpOptSelMonth = document.forms['formFilterRating'].elements['monthafter'].options[i].value;
		if (tmpOptSelMonth == todayMonth)//arrMonth[]
			{document.forms['formFilterRating'].elements['monthafter'].options[i].selected = true;}
	}

	changeSelectForm('formFilterRating','yearafter','monthafter','dayafter');

	var daySelLength = document.forms['formFilterRating'].elements['dayafter'].length;
	for (var i = 0; i < daySelLength; i++)
	{
		tmpOptSelDay = document.forms['formFilterRating'].elements['dayafter'].options[i].value;
		if (tmpOptSelDay == todayDay)
			{document.forms['formFilterRating'].elements['dayafter'].options[i].selected = true;}
	}
}


function changeDate(nameForm,BoAdate,varY,varM,varD)//месяц передаётся натуральным числом
{
	/*if (BoAdate == "before")
	{*/
		var yearSelLength = document.forms[nameForm].elements['year' + BoAdate].length;
		for (var i = 0; i < yearSelLength; i++)
		{
			tmpOptSelYear = document.forms[nameForm].elements['year' + BoAdate].options[i].value;
			if (tmpOptSelYear == varY)
				{document.forms[nameForm].elements['year' + BoAdate].options[i].selected = true;}
		}

		var monthSelLength = document.forms[nameForm].elements['month' + BoAdate].length;
		for (var i = 0; i < monthSelLength; i++)
		{
			tmpOptSelMonth = document.forms[nameForm].elements['month' + BoAdate].options[i].value;
			if (tmpOptSelMonth == varM)//arrMonth[]
				{document.forms[nameForm].elements['month' + BoAdate].options[i].selected = true;}
		}

		eval("changeSelectForm('" + nameForm + "','year" + BoAdate + "','month" + BoAdate + "','day" + BoAdate + "')");

		var daySelLength = document.forms[nameForm].elements['day' + BoAdate].length;
		for (var i = 0; i < daySelLength; i++)
		{
			tmpOptSelDay = document.forms[nameForm].elements['day' + BoAdate].options[i].value;
			if (tmpOptSelDay == varD)
				{document.forms[nameForm].elements['day' + BoAdate].options[i].selected = true;}
		}
		
	/*}
	else if (BoAdate == "after")
	{
		
	}*/
}


function afterLifeBond()
{
	var yearSelLength = document.forms['formFilterRating'].elements['yearafter_bond'].length;
	for (var i = 0; i < yearSelLength; i++)
	{
		tmpOptSelYear = document.forms['formFilterRating'].elements['yearafter_bond'].options[i].value;
		if (tmpOptSelYear == todayYear)
			{document.forms['formFilterRating'].elements['yearafter_bond'].options[i].selected = true;}
	}

	var monthSelLength = document.forms['formFilterRating'].elements['monthafter_bond'].length;
	for (var i = 0; i < monthSelLength; i++)
	{
		tmpOptSelMonth = document.forms['formFilterRating'].elements['monthafter_bond'].options[i].value;
		if (tmpOptSelMonth == todayMonth)//arrMonth[]
			{document.forms['formFilterRating'].elements['monthafter_bond'].options[i].selected = true;}
	}

	changeSelectForm('formFilterRating','yearafter_bond','monthafter_bond','dayafter_bond');

	var daySelLength = document.forms['formFilterRating'].elements['dayafter_bond'].length;
	for (var i = 0; i < daySelLength; i++)
	{
		tmpOptSelDay = document.forms['formFilterRating'].elements['dayafter_bond'].options[i].value;
		if (tmpOptSelDay == todayDay)
			{document.forms['formFilterRating'].elements['dayafter_bond'].options[i].selected = true;}
	}
}


function changeDateBond(nameForm,BoAdate,varY,varM,varD)//месяц передаётся натуральным числом
{
	/*if (BoAdate == "before")
	{*/
		var yearSelLength = document.forms[nameForm].elements['year' + BoAdate + '_bond'].length;
		for (var i = 0; i < yearSelLength; i++)
		{
			tmpOptSelYear = document.forms[nameForm].elements['year' + BoAdate + '_bond'].options[i].value;
			if (tmpOptSelYear == varY)
				{document.forms[nameForm].elements['year' + BoAdate + '_bond'].options[i].selected = true;}
		}

		var monthSelLength = document.forms[nameForm].elements['month' + BoAdate + '_bond'].length;
		for (var i = 0; i < monthSelLength; i++)
		{
			tmpOptSelMonth = document.forms[nameForm].elements['month' + BoAdate + '_bond'].options[i].value;
			if (tmpOptSelMonth == varM)//arrMonth[]
				{document.forms[nameForm].elements['month' + BoAdate + '_bond'].options[i].selected = true;}
		}

		eval("changeSelectForm('" + nameForm + "','year" + BoAdate + "_bond','month" + BoAdate + "_bond','day" + BoAdate + "_bond')");

		var daySelLength = document.forms[nameForm].elements['day' + BoAdate + '_bond'].length;
		for (var i = 0; i < daySelLength; i++)
		{
			tmpOptSelDay = document.forms[nameForm].elements['day' + BoAdate + '_bond'].options[i].value;
			if (tmpOptSelDay == varD)
				{document.forms[nameForm].elements['day' + BoAdate + '_bond'].options[i].selected = true;}
		}
		
	/*}
	else if (BoAdate == "after")
	{
		
	}*/
}
