$(document).ready(function() {

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

$('form#form_feedback button').click(function() {
	$(this).parents('form#form_feedback button').submit();
})

$('.div_feed .close_button').click(function () {
//	$('.div_feed form').clear();
	$('.div_feed').hide();
});

$('form#form_feedback').submit(function() {
	$('form#form_feedback input').removeClass('error');
	$('form#form_feedback textarea').removeClass('error');

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

	var completeCallback = function(jqXHR, textStatus) {
		$('form#form_feedback').find('*[type="submit"]').attr('disabled', false);
	}
	
	var beforeSendCallback = function(jqXHR, settings) {
		$('form#form_feedback').find('*[type="submit"]').attr('disabled', true);
	}

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

	return false;
});

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

});
