var input_text = Array();
var allowClick = true;

function showFLVPlayer() {};

$(document).ready( function() {
							
							
	// ------- ссылки в разделе "Помощь" ---------							
	$("div.help_text_block a.help_block_link").click( function() {
		var display = $(this).parent().find("div.help_text_content").css("display");
		$("div.help_text_block div.help_text_content").slideUp();
		if (display == 'none') $(this).parent().find("div.help_text_content").slideDown();
	});
	// -------------------------------------------							
							

	$(".multibutton").mouseover( function() {
		var src = $(this).attr("src");
		var reg = /(.+)_inactive/;
		var arr = reg.exec(src);
		if (arr) {
			var filename = arr[1]+"_hover.png";
			$(this).attr("src", filename);
		}
	});
	$(".multibutton").mouseout( function() {
		var src = $(this).attr("src");
		var reg = /(.+)_hover/;
		var arr = reg.exec(src);
		if (arr) {
			var filename = arr[1]+"_inactive.png";
			$(this).attr("src", filename);
		}
	});
	$(".multibutton").mousedown( function() {
		var src = $(this).attr("src");
		var reg = /(.+)_hover/;
		var arr = reg.exec(src);
		if (arr) {
			var filename = arr[1]+"_clicked.png";
			$(this).attr("src", filename);
		}
	});
	$(".multibutton").mouseup( function() {
		var src = $(this).attr("src");
		var reg = /(.+)_clicked/;
		var arr = reg.exec(src);
		if (arr) {
			var filename = arr[1]+"_hover.png";
			$(this).attr("src", filename);
		}
	});
	
	$(".multibutton").bind("mouseleave",function(){
		var src = $(this).attr("src");
		var reg = /(.+)_clicked/;
		var arr = reg.exec(src);
		if (arr) {
			var filename = arr[1]+"_inactive.png";
			$(this).attr("src", filename);
		}
    });
	
	
	
	$("input.input_text").focus( function() {
		var value = $(this).val();
		var name = $(this).attr("name");
		//Адрес эл. почты
		if (!input_text[name]) {
			input_text[name] = $(this).val();
			if (name == 'USER_LOGIN' && value == 'Адрес эл. почты')
				$(this).val("");
			if (name != 'USER_LOGIN')
				$(this).val("");
		}
	});
		$("input.input_text").blur( function() {
		var name = $(this).attr("name");
		var val = $(this).val();
		if (input_text[name] && (val.length == 0 || input_text[name] == val)) {
			$(this).val(input_text[name]);
			delete input_text[name];
		}
	});
		
		
	
	$("#fake_registration_password").focus( function() {
		$(this).hide();
		$("#registration_password").show();
		$("#registration_password").focus();
	});
	$("#fake_registration_password_verify").focus( function() {
		$(this).hide();
		$("#registration_password_verify").show();
		$("#registration_password_verify").focus();
	});
	$("#registration_password").blur( function() {
		if ($(this).val() == '') {
			$(this).hide();
			$("#fake_registration_password").show();
		}
	});
	$("#registration_password_verify").blur( function() {
		if ($(this).val() == '') {
			$(this).hide();
			$("#fake_registration_password_verify").show();
		}
	});
	
	
	
	
	/* курсы, внутренняя */
	$('.calendar_link').click(function(){
		var id = $(this).attr("id");
		var reg = /(.+)_(\d+)/;
		var arr = reg.exec(id);
		var date_in = $(this).parent().find('input').val();
		activeCourseId = arr[2];
		var offset = $(this).offset();
		if (date_in)
		{
			//получить день, месяц, год
			var reg = /(\d+).(\d+).(\d+)/;
			var tmpArr = reg.exec(date_in);
			date = new Date(tmpArr[3], tmpArr[2] - 1, tmpArr[1]);
		}
		else
		{
			date = new Date();	
		}
		$.jMonthCalendar.ChangeMonth(date);
		$('#popup_calendar_unique').css({'top' : offset.top - 6, 'left': offset.left - 93}).appendTo('body').show();
		$('.lessons_close_link').click();
	});
	
	$('.calendar_close_link').click(function(){
		$('#popup_calendar_unique').hide();
	});
	
	var openPopupLessonsId;
	var tmpPopupLessonsId;
	$('.lessons_link').click(function(){
		tmpPopupLessonsId = $(this).attr('id');
		if (openPopupLessonsId == tmpPopupLessonsId) 
		{
			$('#popup_' + openPopupLessonsId).hide();
		}
		else
		{
			openPopupLessonsId = $(this).attr('id');
			$('.lessons_popup').hide();
			var offset = $(this).offset();
			$('#popup_' + openPopupLessonsId).css({'top' : offset.top - 6, 'left': offset.left - 53}).appendTo('body').show();
		}
	});
	
	$('.lessons_close_link').click(function(){
		$('#popup_' + openPopupLessonsId).hide();
		openPopupLessonsId = 0;
	});
	
	// скрытие списка
	$('.course_programm_open_arrow').click(function(){
		var id = $(this).attr("id");
		var reg = /(.+)_(\d+)/;
		var arr = reg.exec(id);
		$('#course_programm_div_' + arr[2]).slideUp(200);
		$(this).hide();
		$('#course_programm_close_' + arr[2]).show();
		$('#popup_' + openPopupId).hide();
		$('#popup_' + openPopupLessonsId).hide();
		openPopupId = 0;
		openPopupLessonsId = 0;
	});
	
	// показ списка
	$('.course_programm_close_arrow').click(function(){
		var id = $(this).attr("id");
		var reg = /(.+)_(\d+)/;
		var arr = reg.exec(id);
		$('#course_programm_div_' + arr[2]).slideDown(200);
		$(this).hide();
		$('#course_programm_open_' + arr[2]).show();
		$('#popup_' + openPopupId).hide();
		$('#popup_' + openPopupLessonsId).hide();
		openPopupId = 0;
		openPopupLessonsId = 0;
	});
	
	$('#courses_list select').change(function(){
		var value = ($('#courses_list select').attr('value'));
		$('#courses_lessons table').hide();
		$('#courses_lessons_' + value).show();
		
	});
	

	// всплывающие окошки для уроков
	$('.active_day').live("mouseover", 
						   function(){
							var id = $(this).attr("id");
							var reg = /(.+)_(\d+)/;
							var arr = reg.exec(id);
							var offset = $(this).offset();
							var popupHeight = $('#active_day_popup_' + arr[2]).height();
							$('#active_day_popup_' + arr[2]).css({'top': offset.top - popupHeight - 3, 'left': offset.left - 108}).appendTo('body').show();
							
							   });
	$('.active_day').live("mouseout", function(){ $('.active_day_popup').hide()});
	/* \ курсы, внутренняя */
	
	
	
	
	// --------------- всплывающие уроки -------------------
	$('.lessons_link').click(function(){
		var id = $(this).attr("id");
		var reg = /(.+)_(\d+)/;
		var arr = reg.exec(id);
		activeCourseId = arr[2];
		
		$('.calendar_close_link').click();
		
		if ($('#popup_lesson_'+activeCourseId+' div.lessons_popup_middle table.lessons_table').length == 0)
		{
			var req = new JsHttpRequest();
			req.onreadystatechange = function()
			{
				if (req.readyState == 4)
				{
					$('#popup_lesson_'+activeCourseId+' div.lessons_popup_middle').html(req.responseText);
				}
			}
		   req.caching = false;
		   req.open("POST", "/course_program/get_lessons_by_course_id.php", true);
		   req.send({ COURSE_ID: activeCourseId });
		}
		
		var offset = $(this).offset();
		$('#popup_lesson_'+activeCourseId).css({'top' : offset.top - 6, 'left': offset.left - 53, 'position': 'absolute'}).show();
		$('#popup_lesson_'+activeCourseId+' div.lessons_popup_tab').fadeIn(200);
	});
	
	$('.lessons_close_link').click(function(){
		$(this).parent().fadeOut(200);
	});
	
	/* подсчет цен в программе курсов */
	
	$('.courses_checkbox').live("click", function(){
		$(this).attr('disabled', 'disabled');
		$('#basket_total_price').show();
		var currentPrice = parseInt($(this).parent().find('div').text()); // цена курса, который только что выбрали/удалили
		var coursePriseElement = $(this).closest('.course_item').find('.course_item_header .course_price span'); // элемент, в котором хранится цена
		var coursePrise = parseInt($(this).closest('.course_item').find('.course_item_header .course_price span').text()); // общая цена курса
		if (!coursePrise) coursePrise = 0;
		var _teacherID = parseInt($(this).closest('tr').find('.teacher_id').text());
		var reg = /(.+)_(\d+)/;
		var arr = reg.exec( $(this).attr("id") );
		var courseId = arr[2];
		/* AJAX-запрос для записи/удаления данных из сессии */
		var req = new JsHttpRequest();
		req.onreadystatechange = function(){}
		req.caching = false;
		req.open("POST", "/course_program/changeSessionArray.php", true);
		
		/* AJAX-запрос для записи/удаления из корзины */
		var req2 = new JsHttpRequest();
		if ($(this).attr('checked'))
		{
			$('#basket').show();
			//если добавляем	
			coursePrise+= currentPrice;
			req2.onreadystatechange = function()
			{
				if (req2.readyState == 4)
				{
					$('#basket_middle').prepend(req2.responseJS.NEW_ITEM);
					$('#basket_total_price span').text(req2.responseJS.TOTAL_SUM);
				}
			}
			req2.caching = false;
			req.send({ID: courseId});

			req2.open("POST", "/course_program/put_into_basket.php", true);
			if ( $(this).closest('#courses_lessons').length )
			{
				req2.send({TYPE: 'lesson', ID: courseId, TEACHER_ID: _teacherID});	
			}
			else
			{
				req2.send({TYPE: 'course', ID: courseId,  TEACHER_ID: _teacherID});
			}
		}
		else
		{
			//если удаляем
			coursePrise-= currentPrice;
			req.send({ID: courseId, DELETE: true});
			if ( $(this).closest('#courses_lessons').length )
			{
				
			}
			else
			{
				
			}
		}
		//$(coursePriseElement).text(coursePrise);
		//if (coursePrise > 0)
		//	$(coursePriseElement).parent().show(); // и показываем
		//else
		//	$(coursePriseElement).parent().hide(); // если цена нулевая, то скрываем блок с ценой

	});
	
	/* частные занятия */
	$('#add_to_chart_checkbox').click(function(){
		if ($(this).attr('checked'))
		{
			$('#basket').show();
			$(this).attr('disabled', 'disabled');
			var _SUBJECT_ID = $('#SUBJECT_ID').val();
			var _TIME = $('#private_lessons_time').val();
			var _TEACHER = $('#private_lessons_teacher').val();
			var _THEMES = $('#private_lessons_themes').val();
			var req = new JsHttpRequest();
			req.onreadystatechange = function()
			{
				if (req.readyState == 4)
				{
					$('#basket_middle').prepend(req.responseJS.NEW_ITEM);
					$('#basket_total_price span').text(req.responseJS.TOTAL_SUM);
				}
			}
			req.caching = false;
			req.open("POST", "/course_program/put_into_basket.php", true);
			req.send({TYPE: 'private_lesson', THEMES: _THEMES, TIME: _TIME, TEACHER_ID: _TEACHER, SUBJECT_ID: _SUBJECT_ID});	
			// добавление в сессию
			var req2 = new JsHttpRequest();
			req2.onreadystatechange = function(){}
			req2.caching = false;
			req2.open("POST", "/course_program/changeSessionArrayPrivate.php", true);
			req2.send({ID: _SUBJECT_ID, THEMES: _THEMES, TIME: _TIME, TEACHER_ID: _TEACHER, SUBJECT_ID: _SUBJECT_ID});
		}
	});
	
	$('#private_lessons_themes').keyup(function(){
		if ($(this).val().length > 5)										
			$('#add_to_chart_checkbox').removeAttr('disabled');
		else
			$('#add_to_chart_checkbox').attr('disabled', 'disabled');
	});
	
	/* удаление из корзины */
	/*$('.basket_item .delete_icon').live("click", function(){
		if (!allowClick) return false;
		allowClick = false;
		var id = $(this).closest('.basket_item').attr("id");
		var reg = /(.+)_(\d+)/;
		var arr = reg.exec(id);
		var basketID = arr[2];
		var realID = parseInt($(this).closest('.basket_item').find('.real_id').text());
		var basketPrice = parseInt( $('#basket_total_price span').text() );// текущая цена корзины
		var currentPrice = parseInt( $(this).closest('.basket_item').find('.itemPrice').text() );
		var req = new JsHttpRequest();
		req.onreadystatechange = function(){}
		req.caching = false;
		req.open("POST", "/course_program/delete_from_basket.php", true);
		req.send({ID: basketID});	 // удаляю из битриксовой корзины
		$(this).closest('.basket_item').remove(); // удаляю из корзины на странице
		if ($(this).closest('.basket_item').find('.is_private').length)
		{
			// сделать чекбокс для частного занятия активным
			if (parseInt($('#SUBJECT_ID').val()) == realID)
			{
				$('#add_to_chart_checkbox').removeAttr('checked');
				if ($('#private_lessons_themes').val().length > 5)
					$('#add_to_chart_checkbox').removeAttr('disabled');
			}
			// удаление из сессии
			var req2 = new JsHttpRequest();
			req2.onreadystatechange = function(){
				if (req2.readyState == 4)
				{
					allowClick = true;	
				}
			}
			req2.caching = false;
			req2.open("POST", "/course_program/changeSessionArrayPrivate.php", true);
			req2.send({ID: realID, DELETE: true});
		}
		else
		{
			// удаление из сессии
			basketPrice -= currentPrice;
			var req2 = new JsHttpRequest();
			req2.onreadystatechange = function()
			{
				if (req2.readyState == 4)
				{
					allowClick = true;	
					// сделать чекбокс для курсов или уроков активным
					$('#course_checkbox_' + realID).removeAttr('checked');
					$('#course_checkbox_' + realID).removeAttr('disabled');
					if (basketPrice) 
						$('#basket_total_price span').text(basketPrice);
					else
						$('#basket_total_price').hide();
				}
			}
			req2.caching = false;
			req2.open("POST", "/course_program/changeSessionArray.php", true);
			req2.send({ID: realID, DELETE: true});
		}
		if (!$('#basket_middle .basket_item').size()) $('#basket').hide();
	});
	*/
	/* ИЗМЕНЕНИЕ ПРОФИЛЯ */
	
	$('#profile_user_login').keyup(function(){
		$('#profile_user_email').val( $(this).val() );
	});
	
	$('#profile_edit_day_of_b').change(function(){
		generateDateForProfile();
												
	});
	$('#profile_edit_month_of_b').change(function(){
		generateDateForProfile();
	});
	$('#profile_edit_year_of_b').keyup(function(){
		generateDateForProfile();											
	});	
	
	/* РАСПИСАНИЕ, ПОПАПЫ */
	$('.schedule_lesson').hover(
		function(){
			var id = $(this).attr("id");
			var reg = /(.+)_(\d+)/;
			var arr = reg.exec(id);
			var offset = $(this).offset();
			var popupHeight = $('#lesson_' + arr[2] + '_popup').height();
			$('#lesson_' + arr[2] + '_popup').css({'top': offset.top - popupHeight - 3, 'left': offset.left - 114}).appendTo('body').show();
		},
		function(){
			$('#' + $(this).attr('id') + '_popup').hide();
		}
	);
	
	
	/* МЕНЮ РАЗДЕЛА ПОМОЩЬ */
	
	$('#help_menu a.parent').click(function(){
		if( $(this).closest('li').find('ul:first').css('display') == 'block' )
			$(this).closest('li').find('ul:first').slideUp(200);
		else
			$(this).closest('li').find('ul:first').slideDown(200);
	});
	
	/* ---------- новая программа курсов --------------- */
	isPopupListVisible = false;
	$(".subject_popup").bind("mouseleave", function() {
													
		$(this).fadeOut(200);
		$(this).find('.arrow_up_down').attr('src' , '/images/schedule_arrow_down.png');
		$(this).find('tr.hidden').hide();
		isPopupListVisible = false;
	});
	/*$(".arrow_up_down").click(function(){
		if (isPopupListVisible)
		{
			$(this).attr('src' , '/images/schedule_arrow_down.png');
			$(this).closest('.subject_popup').find('tr.hidden').hide();	
			isPopupListVisible = false;
		}
		/*else
		{
			$(this).attr('src' , '/images/schedule_arrow_up.png');
			$(this).closest('.subject_popup').find('tr.hidden').show();
			isPopupListVisible = true;
		}*/
	/*});*/
	$('.subject_popup_middle tr td.clickable').click(function(){
		if (isPopupListVisible)
		{
			var parentID = $(this).closest('.subject_popup').attr('id');
			var reg = /subject_popup_(.+)/;
			var arr = reg.exec(parentID);
			thisRow = $(this).closest('tr');
			
			targetRow = $('#subject_row_' + arr[1]);
			targetRow.find('.first_col').html( thisRow.find('.first_col').html() );
			targetRow.find('.second_col').html( thisRow.find('.second_col').html() );
			targetRow.find('.third_col').html( thisRow.find('.third_col').html() );
			targetRow.find('.fourth_col').html( thisRow.find('.fourth_col').html() );
			targetRow.find('.fifth_col').html( thisRow.find('.fifth_col').html() );
			
			targetRow.find('input.total_course_price').val( thisRow.find('input.course_item_price').val() );
			targetRow.find('input.total_course_id').val( thisRow.find('input.course_item_id').val() );
			targetRow.closest('.subject_course_item').find('.course_program_link a').attr('href', '/schedule/course_program/' + thisRow.find('input.course_item_id').val() + '/');
			targetRow.find('input.total_course_discount').val( thisRow.find('input.course_item_discount').val() );
			targetRow.closest('.subject_course_item').find('div.course_name').text( thisRow.find('input.course_item_name').val() );
			$(this).attr('src' , '/images/schedule_arrow_down.png');
			$(this).closest('.subject_popup').find('tr.hidden').hide();	
			$(this).closest('.subject_popup').hide();
			isPopupListVisible = false;
			
			thisRow.prependTo(thisRow.parent());
			thisRow.parent().find("tr").addClass("hidden").css('display', '');
			thisRow.removeClass("hidden");
			$(this).closest('table').find('img').attr('src', '/images/schedule_arrow_down.png').prependTo(thisRow.parent().find("tr:first > td:last") );
		}
		else
		{
			$(this).parent().find('img').attr('src' , '/images/schedule_arrow_up.png');
			$(this).closest('.subject_popup').find('tr.hidden').show();
			isPopupListVisible = true;
		}
	});
	
	$('.subject_row').mouseover(function(){
		var offset = $(this).offset();
		var id = $(this).attr('id');
		var reg = /subject_row_(.+)/;
		var arr = reg.exec(id);
		$('#subject_popup_'  + arr[1]).find('tr.hidden').show();
		isPopupListVisible = true;
		$('#subject_popup_'  + arr[1]).css({'top' : offset.top - 5, 'left' : offset.left}).appendTo('#main_container').show();
	});
	
	// кладем курс в корзину
	$('.put_into_basket_link').click(function(){
		var _subjectName = $(this).closest('.subject_course_item').find('input.subject_name').val();
		var _blockName = $(this).closest('.subject_course_item').find('div.subject_name').text();
		var _courseName = _blockName+': '+$(this).closest('.subject_course_item').find('.period_name').text();
		var _price = $(this).closest('.subject_course_item').find('.total_course_price').val();
		var _id = $(this).closest('.subject_course_item').find('.total_course_id').val();
		var _subjectId = $(this).closest('.subject_course_item').find('.total_subject_id').val();
		var _discount = $(this).closest('.subject_course_item').find('.total_course_discount').val();
		if (!_discount) _discount = 0;
		var req = new JsHttpRequest();
		// скрываем кнопку "добавить в корзину" для текущего предмета
		$(this).find('img').css('visibility', 'hidden');
		req.onreadystatechange = function(){
			if (req.readyState == 4)
			{
				// положили в корзину и теперь выводим
				$('#basket_container').html(req.responseJS.NEW_ITEM);
			}
		}
		req.caching = false;
		req.open("POST", "/schedule/put_into_basket.php", true);
		req.send({COURSE_NAME: _courseName, ID: _id, PRICE: _price, SUBJECT_ID: _subjectId, SUBJECT_NAME: _subjectName, DISCOUNT: _discount });	
	});
	// удаляем курс из корзины
	$('.basket_item .delete_icon').live('click', function()	{
		// удаление из корзины
		var cirrent_el_id = $(this).closest('.basket_item').attr('id');
		var reg = /basket_item_(.+)/;
		var real_id = $(this).closest('.basket_item').find('.real_id').text();
		var arr = reg.exec(cirrent_el_id);
		basketID = arr[1];
		var req = new JsHttpRequest();
		req.onreadystatechange = function(){
			if (req.readyState == 4)
			{
				
				// удалили и теперь выводим обновленную корзину
				$('#basket_container').html(req.responseJS.NEW_ITEM);
			}	
		}
		req.caching = false;
		req.open("POST", "/schedule/delete_from_basket.php", true);
		req.send({ID: basketID});
		// делаю видимой кнопку "добавить в корзину" для удаляемого периода
		$('#put_into_basket_link_' + real_id + ' img').css('visibility', 'visible');
		//$('input.total_subject_id[value=' + $(this).closest('.basket_item').find('.subject_id').text() + ']').closest('.subject_course_item').find('.put_into_basket_link img').css('visibility', 'visible');
	});
	
	/* FEEDBACK POPUP */
	$('#feedback_submit_btn').click(function(){
		if ( !$('#feedback_email').val() )
		{
			$('#feedback_popup_errors').html('<span style="color:red;">Укажите, пожалуйста, Ваш e-mail</span>');
			return false;
		}
		if ( !$('#feedback_message').val() )
		{
			$('#feedback_popup_errors').html('<span style="color:red;">Введите, пожалуйста, текст сообщения</span>');
			return false;
		}
		
		var req = new JsHttpRequest();
		req.onreadystatechange = function(){
		if (req.readyState == 4)
		{
			if (req.responseJS.error) 
			{
				// wrong captcha
				$('#feedback_popup_errors').html('<span style="color:red;">Неверное подтверждение кода</span>');
			}
			else
			{
				// success	
				$('#feedback_popup_errors').html('<span style="color:green;">Спасибо! Ваше письмо отправлено</span>');
				$('#feedback_submit_btn').hide();
			}
		}
		}
		req.caching = false;
		req.open("POST", "/js/feedback_popup.php", true);
		req.send({ 
				 feedback_problem: $('#feedback_problem').val(), 
				 feedback_email: $('#feedback_email').val(), 
				 feedback_message: $('#feedback_message').val(), 
				 feedback_captcha_code: $('#feedback_captcha_code').val(),
				 feedback_captcha: $('#feedback_captcha').val()
				 });	
	});
	
	
	$('.view_block_program_link').click(function(){
		var id = $(this).attr('id');
		var reg = /view_block_program_link_(\d+)/;
		var arr = reg.exec(id);
		var offset = $(this).offset();
		if (arr)
		{
			$('#subject_popup_' + arr[1]).appendTo('body').css({"top" : offset.top - 10 , "left" : offset.left - 10}).fadeIn(200);
		}
	});
});

var activeCourseId;

function showMainRegForm() {
	$(".bottom_block_header").hide();
	$(".register_bottom_block_header").show();
	$("#advantages_block").hide();
	$("#registration_block").show();
	$("#advantages_arrows").hide();
}
function showMainAdvForm() {
	$(".register_bottom_block_header").hide();
	$(".bottom_block_header").show();
	$("#registration_block").hide();
	$("#advantages_block").show();
	$("#advantages_arrows").show();
}

//функция расстановки уроков на календаре
function markLessons(month_in, year_in, course_id_in)
{
	month_in++;
	var req = new JsHttpRequest();
	req.onreadystatechange = function()
	{
		if (req.readyState == 4)
		{
			for (var i = 0; i < req.responseJS.lessons.length; i++)
			{
				var dayNum = $('#c_' + req.responseJS.lessons[i].DATE + ' div:first').text();
				if ( $('#active_day_' + req.responseJS.lessons[i].DATE).length == 0) 
					$('#c_' + req.responseJS.lessons[i].DATE).html('<div class="active_day" id="active_day_' + req.responseJS.lessons[i].DATE + '">' + dayNum + '</div>');

				if ( $('#active_day_popup_' + req.responseJS.lessons[i].DATE).length == 0)
				{
					if ($('#lesson_text_' + req.responseJS.lessons[i].LESSON_ID).length == 0)
						$('#c_' + req.responseJS.lessons[i].DATE).append('<div class="active_day_popup" id="active_day_popup_' + req.responseJS.lessons[i].DATE + '"><div class="active_day_popup_top"></div><div class="active_day_popup_middle"><div id="lesson_text_' + req.responseJS.lessons[i].LESSON_ID + '">' + req.responseJS.lessons[i].NAME + '</div>' + req.responseJS.lessons[i].TIME + '</div><div class="active_day_popup_bottom"></div></div> ');
				}
				else
				{
					if ($('#lesson_text_' + req.responseJS.lessons[i].LESSON_ID).length == 0)
						$('#active_day_popup_' + req.responseJS.lessons[i].DATE + ' div.active_day_popup_middle').append('<div id="lesson_text_' + req.responseJS.lessons[i].LESSON_ID + '">' + req.responseJS.lessons[i].NAME + '</div>' + req.responseJS.lessons[i].TIME);
				}

			}
		}
	}
   req.caching = false;
   req.open("POST", "/course_program/get_lessons.php", true);
   req.send({ year: year_in, month: month_in, course: course_id_in });
}

function generateDateForProfile(){
	var day = $('#profile_edit_day_of_b').val();
	if ( parseInt(day) <= 9 ) day = '0' + day;
	var month = $('#profile_edit_month_of_b').val();
	if ( parseInt(month) <= 9 ) month = '0' + month;
	var year = $('#profile_edit_year_of_b').val();
	$('#profile_edit_birthday').val(day + '.' + month + '.' + year);
}




// -------------------- профиль (СПИСОК МАТЕРИАЛОВ, ПОСЛЕДНИЕ МАТЕРИАЛЫ) раскрывающиеся списки ---------------------
function openSubjectList(id) {
	$("#subject_content_"+id).slideDown(200);
	$("#subject_content_"+id).parent().find("a.subject_open_arrow").hide();
	$("#subject_content_"+id).parent().find("a.subject_close_arrow").show();
}
function closeSubjectList(id) {
	$("#subject_content_"+id).slideUp(200);
	$("#subject_content_"+id).parent().find("a.subject_close_arrow").hide();
	$("#subject_content_"+id).parent().find("a.subject_open_arrow").show();
}

function openLessonList(id) {
	$("#lesson_content_"+id).slideDown(200);
	$("#lesson_content_"+id).parent().find("a.lesson_open_arrow").hide();
	$("#lesson_content_"+id).parent().find("a.lesson_close_arrow").show();
}
function closeLessonList(id) {
	$("#lesson_content_"+id).slideUp(200);
	$("#lesson_content_"+id).parent().find("a.lesson_close_arrow").hide();
	$("#lesson_content_"+id).parent().find("a.lesson_open_arrow").show();
}