$(document).ready(function() {

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

$('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('');
//		alert($(responseText).find('preged').text());
//		$(responseText).find('mails mail').each(function() {
//			alert($(this).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_feedback input[name=' + $(this).attr('name') + ']').addClass('error');
				$('form#form_feedback textarea[name=' + $(this).attr('name') + ']').addClass('error');
			});
			$('.pls_check_fields').show();
		}
	}; // successCallback

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

	return false;
});

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

$('#feedback').click(function() {
	$('#feedback_window').show();

	$(this).unbind('mouseover');
	$(this).unbind('mouseout');
	
	$(this).find('A IMG').css("margin-top", "-34px");
	
});

$('#feedback_window .window_cancel').click(function() {
	$('#feedback A IMG').css("margin-top", "0");
	$('.pop_window').hide();

	$("#feedback").mouseover(function() {
		$(this).find('A IMG').css("margin-top", "-34px");
	});
	$("#feedback").mouseout(function() {
		$(this).find('A IMG').css("margin-top", "0");
	});
});

});


