
jQuery(function($)
{
	$('.x_btn_login').click(function()
	{
		$('#modalDialogIcon > img').attr("src", "/img/loading_ani.gif");
		$('#modalDialogTitle').html("Процедура авторизации");
		$('#modalDialogMsg').html('<h1 class="black">Выполняется авторизация пользователя... </h1>');
		$('#modalDialog').modal({close: false});

		$.ajax({
			type: "GET",
			dataType: 'text',
			url: "/login/?ext=rss",
			data: $('#loginForm').serialize(),
			success: function(data)
			{
				var status = $(data).filter('.ajaxout').attr("status") || 'ok';
				var msg = $(data).filter('.ajaxout').attr("msg") || '';

				if (status != 'ok')
				{
					$('#modalDialogIcon > img').attr("src", "/img/alertbig.gif");
					$('#modalDialogMsg').html("<h1>" + msg + '</h1><br><a href="/register/">Регистрация</a>&nbsp;&nbsp;&nbsp;<a href="/forgot/">Напомнить пароль</a>');
					$('#modalDialog .modalClose').show();
				}
				else
				{
					document.location.href = document.location.href;
				}
			},
			error: function()
			{
				$('#modalDialogIcon > img').attr("src", "/img/alertbig.gif");
				$('#modalDialogMsg').html("<h1>Ошибка получения данных с сервера.</h1>");
				$('#modalDialog .modalClose').show();
			}
		});

		return false;
	});
});


jQuery(function($)
{
	$('#pollForm .btn_golos').click(function()
	{
		$('#modalDialogIcon > img').attr("src", "/img/loading_ani.gif");
		$('#modalDialogTitle').html("Опросы");
		$('#modalDialogMsg').html('<h1 class="black">Идет отправка Вашего голоса..</h1>');
		$('#modalDialog').modal({close: false});

		$.ajax({
			type: "GET",
			dataType: 'text',
			url: "/polls/?ext=rss&ajaxout=1",
			data: $('#pollForm').serialize(),
			success: function(data)
			{
				var statusDiv = $(data).find("div.ajaxout");
				if (statusDiv.length == 0) statusDiv = $(data).filter("div.ajaxout");

				var status = statusDiv.attr("status") || 'error';
				var msg = statusDiv.attr("msg") || '<h1>Ошибка получения данных с сервера.</h1>';

				if (status != 'ok')
				{
					$('#modalDialogIcon > img').attr("src", "/img/alertbig.gif");
					$('#modalDialogMsg').html(msg);
					$('#modalDialog .modalClose').show();
				}
				else
				{
					$('#modalDialogIcon > img').attr("src", "/img/info48x48.gif");
					$('#modalDialogMsg').html(msg);
					$('#modalDialog .modalClose').show();
				}
			},
			error: function()
			{
				$('#modalDialogIcon > img').attr("src", "/img/alertbig.gif");
				$('#modalDialogMsg').html("<h1>Ошибка получения данных с сервера.</h1>");
				$('#modalDialog .modalClose').show();
			}
		});

		return false;
	});
});
