$(document).ready(function() {

//==================================================================================================

$('form#form_ask_question').submit(function() {

	// Отправка формы добавления поста.
	var successCallback = function(responseText, statusText, xhr, $form) {
		$('form#form_ask_question .error_field').text('');
//		alert($(responseText).find('mailed').text());
		// Если всё нормально.
		if ($(responseText).find('accept').text() == '1') {
			alert($(responseText).find('glob_message').text());
			//location.href = $(responseText).find('blog_post url').text();
			setTimeout(function() {
				window.location.reload();
			}, 1000);
		}
		// Если всё ненормально.
		if ($(responseText).find('accept').text() == '0') {
			$(responseText).find('field').each(function() {
				alert(($(this).text()))
//				$('#error_' + $(this).attr('name')).text($(this).text());
				$('form#form_ask_question input[name=' + $(this).attr('name') + ']').addClass('error');
				$('form#form_ask_question textarea[name=' + $(this).attr('name') + ']').addClass('error');
			});
			$('.pls_check_fields').show();
		}
	}; // successCallback

	$(this).ajaxSubmit({
		success: successCallback,
		dataType: 'xml'
	});

	return false;
});

//==================================================================================================

$('#ask_question_button').click(function() {
	$('#ask_question_window').show();
});

//$('.list_quest .read_more').click(function() {
//	alert('woot');
//});

$(".list_quest .read_more").click(function() {
	var jParent = $(this).parents('.list_quest');
	jParent.find('.read_more').hide();
	jParent.find('.read_no').show();
	jParent.find('.replay').slideDown("slow");
});

$(".list_quest .read_no").click(function() {
	var jParent = $(this).parents('.list_quest');
	jParent.find('.replay').slideUp("slow");
	jParent.find('.read_more').show();
	jParent.find('.read_no').hide();
});

$('#sort_questions_button').click(function() {
	$('.list_quest .select_type span:not(.green)').parents('.list_quest').show();
	$('.list_quest .select_type span.green').parents('.list_quest').hide();

	if ($('#other_faq:visible').size() == 0) {
		if ($('#other_faq .list_quest .select_type span:not(.green)').size() > 0) {
			$('#more_faq').show();
		} else {
			$('#more_faq').hide();
		}
	}
});

$('#sort_posts_button').click(function() {
	$('.list_quest .select_type span:not(.green)').parents('.list_quest').hide();
	$('.list_quest .select_type span.green').parents('.list_quest').show();

	if ($('#other_faq:visible').size() == 0) {
		if ($('#other_faq .select_type span.green').size() > 0) {
			$('#more_faq').show();
		} else {
			$('#more_faq').hide();
		}
	}
});

});


