var mobUser =
{
	// =========================================================================

	messages: {
		illegalCharsInLogin: 'Введены запрещенные символы!<br>Нельзя вводить &lt; и &gt',

		mailEmpty: 'E-mail адрес не указан.',
		mailInvalid: 'Введен неверный E-mail адрес.',
		mailExists: 'Пользователь с таким E-mail уже существует. <a href="' + forAll.domen + 'password_reminder/">Востановить пароль.</a>',

		mailLoginEmpty: 'Имя или E-mail адрес не указан.',

		mailNotFound: 'Пользователя с таким E-mail не существует.',

		mailLoginNotFound: 'Пользователя с таким Именем или E-mail не существует',

		loginEmpty: 'Имя пользователя не указано.',
		loginExists: 'Пользователь с таким Именем уже существует.',

		passwordShort: 'Пароль должен быть не менее 4 символов.',
		passwordDifferent: 'Введенные пароли не совпадают!',

		captchaInvalid: 'Код с картинки введен неверно.',

		authFailed: 'Вы ошиблись при вводе E-mail или пароля.',

		passwordReminderOK: 'На указанный адрес было выслано письмо, в котором будет ссылка, перейдя по которой вы сможете восстановить пароль.'
	},

	images: {
		error: '<img src="http://images.mob.ua/img/@server@_reg.gif" width="16" height="16" style="margin-bottom:4px">'
	},

	blocks: {
		authorization: false,
		registration: false,
		authRegistration: false,
		forgetPassword: false,
		message: false
	},

	timers: {
		checkMail: false,
		checkLogin: false,
		checkPassword: false,
		checkCaptcha: false
	},

	cache: {
		mode: false
	},

	overlay: false,

	// =========================================================================

	staticIsLogged: function()
	{
		if (getCookie('isLogged') == 'true')
		{
			return true;
		}
		return false;
	},

	// =========================================================================

	onComplete: function()
	{
		window.location.reload(true);
	},

	// =========================================================================

	init: function()
	{
		// -------------------------------------------------------------------------

		this.overlay = $('#hideDiv');
		this.overlay.css({
			width: '100%',
//			height: Math.max(document.documentElement.scrollHeight, 0) + 'px'
			height: Math.max(document.body.scrollHeight, 0) + 'px'
		});

//		alert(document.documentElement.scrollHeight);
//		alert(document.body.scrollHeight);

		// -------------------------------------------------------------------------

		// Основные блоки

		this.blocks.authorization		= $('#logInMessageSmall');
		this.blocks.registration		= $('#regMessageSmall');
		this.blocks.authRegistration	= $('#regMessage');
		this.blocks.authRegistrationR	= $('#authRegistrationR');
		this.blocks.authRegistrationL	= $('#authRegistrationL');
		this.blocks.passwordReminder	= $('#forgetPass');
		this.blocks.message				= $('#userMessage');

		// -------------------------------------------------------------------------

		// Форма регистрации

		this.blocks.registration.find('form').submit(function()
		{
			mobUser.staticRegisterSubmit(this);
			return false;
		});

		this.blocks.registration.find('.x-mail')
			.bind('keyup focus blur', function(e)
			{
				clearTimeout(mobUser.timers.checkMail);
				mobUser.cache.mail = this.value;

				var time = 2000;
				switch(e.type)
				{
					case 'blur': time = 5; break;
				}

				mobUser.timers.checkMail = window.setTimeout(mobUser.staticCheckMail, time);
			});

		this.blocks.registration.find('.x-login')
			.bind('keyup focus blur', function(e)
			{
				clearTimeout(mobUser.timers.checkLogin);
				mobUser.cache.login = this.value;

				var time = 750;
				switch(e.type)
				{
					case 'blur': time = 5; break;
				}

				mobUser.timers.checkLogin = window.setTimeout(mobUser.staticCheckLogin, time);
			});

		this.blocks.registration.find('.x-password')
			.bind('keyup blur', function()
			{
				clearTimeout(mobUser.timers.checkPassword);
				mobUser.cache.password = this.value;
				mobUser.timers.checkPassword = window.setTimeout(mobUser.staticCheckPassword, 2500);
			});

		this.blocks.registration.find('.x-password-again')
			.bind('blur', function()
			{
				clearTimeout(mobUser.timers.checkPassword);
				mobUser.cache.passwordAgain = this.value;
				mobUser.timers.checkPassword = window.setTimeout(mobUser.staticCheckPassword, 5);
			});

		this.blocks.registration.find('.x-captcha')
			.bind('keyup blur', function(e)
			{
				clearTimeout(mobUser.timers.checkCaptcha);
				mobUser.cache.captcha = this.value;
				switch(e.type)
				{
					case 'keyup':
						mobUser.timers.checkCaptcha = window.setTimeout(mobUser.staticCheckCaptchaNoError, 100);
					break;

					case 'blur':
						mobUser.timers.checkCaptcha = window.setTimeout(mobUser.staticCheckCaptchaError, 5);
					break;
				}
			});

		this.blocks.registration.find('.x-captcha-reload')
			.bind('click', function()
			{
				mobUser.staticReloadCaptcha('registration');
			});

		// -------------------------------------------------------------------------

		// Форма авторизации + регистрации ? регистрация

		this.blocks.authRegistrationR.submit(function()
		{
			mobUser.cache.mode = 'authRegistrationR';
			mobUser.staticRegisterSubmit(this);
			return false;
		});

		this.blocks.authRegistrationR.find('.x-mail')
			.bind('keyup focus blur', function(e)
			{
				mobUser.cache.mode = 'authRegistrationR';
				clearTimeout(mobUser.timers.checkMail);
				mobUser.cache.mail = this.value;

				var time = 2000;
				switch(e.type)
				{
					case 'blur': time = 5; break;
				}

				mobUser.timers.checkMail = window.setTimeout(mobUser.staticCheckMail, time);
			});

		this.blocks.authRegistrationR.find('.x-login')
			.bind('keyup focus blur', function(e)
			{
				mobUser.cache.mode = 'authRegistrationR';
				clearTimeout(mobUser.timers.checkLogin);
				mobUser.cache.login = this.value;

				var time = 1000;
				switch(e.type)
				{
					case 'blur': time = 5; break;
				}

				mobUser.timers.checkLogin = window.setTimeout(mobUser.staticCheckLogin, time);
			});

		this.blocks.authRegistrationR.find('.x-password')
			.bind('blur', function()
			{
				mobUser.cache.mode = 'authRegistrationR';
				clearTimeout(mobUser.timers.checkPassword);
				mobUser.cache.password = this.value;
				mobUser.timers.checkPassword = window.setTimeout(mobUser.staticCheckPassword, 2500);
			});

		this.blocks.authRegistrationR.find('.x-password-again')
			.bind('blur', function()
			{
				mobUser.cache.mode = 'authRegistrationR';
				clearTimeout(mobUser.timers.checkPassword);
				mobUser.cache.passwordAgain = this.value;
				mobUser.timers.checkPassword = window.setTimeout(mobUser.staticCheckPassword, 5);
			});

		this.blocks.authRegistrationR.find('.x-captcha')
			.bind('keyup blur', function(e)
			{
				clearTimeout(mobUser.timers.checkCaptcha);
				mobUser.cache.captcha = this.value;
				switch(e.type)
				{
					case 'keyup':
						mobUser.timers.checkCaptcha = window.setTimeout(mobUser.staticCheckCaptchaNoError, 100);
					break;

					case 'blur':
						mobUser.timers.checkCaptcha = window.setTimeout(mobUser.staticCheckCaptchaError, 5);
					break;
				}
			});

		this.blocks.authRegistrationR.find('.x-captcha-reload')
			.bind('click', function()
			{
				mobUser.cache.mode = 'authRegistrationR';
				mobUser.staticReloadCaptcha('authRegistrationR');
			});

		// -------------------------------------------------------------------------

		// Форма авторизации + регистрации ? авторизация

		this.blocks.authRegistrationL.submit(function()
		{
			mobUser.cache.mode = 'authRegistrationL';
			if(mobUser.staticCheckForm())
			{
				var data = $(this).serializeArray();
				data.push({name: 'mode', value: 'userLogin'});
				$.ajax({
					type: 'POST',
					url: '/hint/account/',
					data: data,
					complete: function(request)
					{
						mobUser.staticClearTimers();
						switch(request.responseText.split('|')[0])
						{
							case 'mailLoginEmpty':
								mobUser.cache.isValidMail = false;
								mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.mailLoginEmpty);
								mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
							break;

							case 'authFailed':
								mobUser.cache.isValidMail = false;
								mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.authFailed);
								mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
							break;

							case 'messageStop':
								mobUser.staticShowResponseMessage(request.responseText, 'close');
							break;

							case 'OK':
								mobUser.staticShowResponseMessage(request.responseText, 'ok', {onOK: mobUser.onComplete});
							break;
						}
						mobUser.staticCheckForm();
					}
				});
			}
			return false;
		});

		// -------------------------------------------------------------------------

		// Форма авторизации

		this.blocks.authorization.find('form').submit(function()
		{
			mobUser.staticLoginSubmit(this);
			return false;
		});

		// -------------------------------------------------------------------------

		// Форма восстановления пароля

		this.blocks.passwordReminder.find('.x-mail')
			.bind('keyup focus blur', function()
			{
				mobUser.cache.mode = 'passwordReminder';
				clearTimeout(mobUser.timers.checkMail);
				mobUser.cache.mail = this.value;
				mobUser.timers.checkMail = window.setTimeout(mobUser.staticCheckMail, 500);
			});

		// -------------------------------------------------------------------------

		// Кнопки вызова регистрации
		
		$('.x-user-register')
			.click(function()
			{
				mobUser.staticCloseAll();
				mobUser.cache.mode = 'registration';

				mobUser.staticMoveToCenter(mobUser.blocks.registration);
				mobUser.blocks.registration.find('.x-close')
					.click(function()
					{
						mobUser.staticCloseAll();
						return false;
					});
				mobUser.overlay
					.click(function()
					{
						mobUser.staticCloseAll();
						return false;
					});

				mobUser.staticLoadCaptcha('registration');

				mobUser.overlay.show();
				mobUser.blocks.registration.show();
				return false;
			});

			// -------------------------------------------------------------------------

			// Форма восстановления пароля

			this.blocks.passwordReminder.find('form').submit(function()
			{
				if(mobUser.staticCheckForm())
				{
					var data = $(this).serializeArray();
					data.push({name: 'mode', value: 'passwordRemind'});
					$.ajax({
						type: 'POST',
						url: '/hint/account/',
						data: data,
						complete: function(request)
						{
							mobUser.staticClearTimers();
							switch(request.responseText.split('|')[0])
							{
								case 'mailLoginEmpty':
									mobUser.cache.isValidMail = false;
									mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.mailLoginEmpty);
									mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
								break;

								case 'mailLoginNotFound':
									mobUser.cache.isValidMail = false;
									mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.mailLoginNotFound);
									mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
								break;

								case 'messageStop':
									mobUser.staticShowMessage('Восстановление пароля', request.responseText.substr(request.responseText.indexOf(' ')));
								break;

								case 'OK':
									mobUser.staticShowMessage('Восттановление пароля', mobUser.messages.passwordReminderOK);
								break;
							}
							mobUser.staticCheckForm();
						}
					});
				}
				return false;
			});

		// -------------------------------------------------------------------------

		// Кнопки вызова авторизации

		$('.x-user-login')
			.click(function()
			{
				mobUser.staticCloseAll();
				mobUser.cache.mode = 'authorization';

				mobUser.staticMoveToCenter(mobUser.blocks.authorization);
				mobUser.blocks.authorization.find('.x-close')
					.click(function()
					{
						mobUser.staticCloseAll();
						return false;
					});
				mobUser.overlay
					.click(function()
					{
						mobUser.staticCloseAll();
						return false;
					});

				mobUser.overlay.show();
				mobUser.blocks.authorization.show();
				return false;
			});

		// -------------------------------------------------------------------------
		
		// Кнопки вызова напоминалки пароля

		$('.x-user-remindPassword')
			.click(function()
			{
				mobUser.staticCloseAll();
				mobUser.cache.mode = 'passwordReminder';

				mobUser.staticMoveToCenter(mobUser.blocks.passwordReminder);
				mobUser.blocks.passwordReminder.find('.x-close')
					.click(function()
					{
						mobUser.staticCloseAll();
						return false;
					});
				mobUser.overlay
					.click(function()
					{
						mobUser.staticCloseAll();
						return false;
					});

				mobUser.overlay.show();
				mobUser.blocks.passwordReminder.show();
				return false;
			});

//			this.staticShowMessage('Заголовок', 'Сообщение', 'okcancel');
//			this.staticShowResponseMessage('messageStop|Поздравляем!|Вы почти зарегистрированы.<br /><br /><b>Внимание!</b><br />Для завершения регистрации подтвердите адрес электронной почты указанный при регистрации: %mail%.<br />Для этого перейдите по ссылке, которая пришла к вам письме.');
	},

	// =========================================================================

	showAuthForm: function()
	{
		mobUser.staticCloseAll();

		mobUser.staticMoveToCenter(mobUser.blocks.authRegistration);
		mobUser.blocks.authRegistration.find('.x-close')
			.click(function()
			{
				mobUser.staticCloseAll();
				return false;
			});
		mobUser.overlay
			.click(function()
			{
				mobUser.staticCloseAll();
				return false;
			});

		mobUser.staticLoadCaptcha('authRegistration');

		mobUser.cache.mode = 'authRegistrationR';
		
		mobUser.overlay.show();
		mobUser.blocks.authRegistration.show();
		mobUser.blocks.authRegistrationR.show();
		mobUser.blocks.authRegistrationL.show();
		return false;
	},

	// =========================================================================

	staticMoveToCenter: function(obj)
	{
		var width = obj.width();
		var height = obj.height();
		var scrollTop = 120;
		if($.browser.msie)
		{
			scrollTop += document.body.scrollTop;
		}
//		var windowWidth = document.documentElement.scrollWidth;
//		alert(windowWidth);
		obj.css({
			position: $.browser.msie && $.browser.version <= 7 ? 'absolute' : 'fixed',
			top: scrollTop + 'px',
//			left: parseInt((windowWidth - width)/2) + 'px',
			left: 50 + '%',
			marginLeft: -parseInt(width/2) + 'px'
		});
	},

	// =========================================================================

	staticCloseAll: function()
	{
		delete mobUser.cache.mode;
		for(var key in mobUser.blocks)
		{
			if(mobUser.blocks[key])
			{
				mobUser.blocks[key].hide();
			}
		}
		mobUser.overlay.hide();
	},

	// =========================================================================

	staticCheckMail: function()
	{
		if(!mobUser.cache.mail)
		{
			return false;
		}

		if(!mobUser.cache.mode)
		{
			return false;
		}

		mobUser.cache.isValidMail = true;

		if (!/^\w+([.-]\w+)*@\w+([.-]?\w+)*(\.\w{2,4})+$/.test(mobUser.cache.mail))
		{
			mobUser.cache.isValidMail = false;
			mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.mailInvalid);
			mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
			return false;
		};

		if(mobUser.cache.mode != 'registration' && mobUser.cache.mode != 'authRegistrationR')
		{
			mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html('');
			mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'yes'));
			return true;
		}

		$.ajax({
			async: false,
			type: 'POST',
			url: '/hint/account/',
			data: {
				mode: 'isMailExists',
				value: mobUser.cache.mail
			},
			complete: function(request)
			{
				switch(request.responseText)
				{
					case 'true':
						mobUser.cache.isValidMail = false;
						mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.mailExists);
						mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
					break;

					case 'false':
						mobUser.cache.isValidMail = true;
						mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html('');
						mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'yes'));
					break;
				}
				mobUser.staticCheckForm();
			}
		});
	},

	// =========================================================================

	staticCheckLogin: function()
	{
		if(!mobUser.cache.login)
		{
			return false;
		}

		if(!mobUser.cache.mode)
		{
			return false;
		}

		$.ajax({
			async: false,
			type: 'POST',
			url: '/hint/account/',
			data: {
				mode: 'isLoginExists',
				value: mobUser.cache.login
			},
			complete: function(request)
			{
				switch(request.responseText)
				{
					case 'true':
						mobUser.cache.isValidLogin = false;
						mobUser.blocks[mobUser.cache.mode].find('.x-login-error-text').html(mobUser.messages.loginExists);
						mobUser.blocks[mobUser.cache.mode].find('.x-login-error-img').html(mobUser.images.error.replace('@server@', 'no'));
					break;

					case 'false':
						mobUser.cache.isValidLogin = true;
						mobUser.blocks[mobUser.cache.mode].find('.x-login-error-text').html('');
						mobUser.blocks[mobUser.cache.mode].find('.x-login-error-img').html(mobUser.images.error.replace('@server@', 'yes'));

					break;
				}
				mobUser.staticCheckForm();
			}
		});
	},

	// =========================================================================

	staticCheckPassword: function()
	{
		if(typeof mobUser.cache.password == 'undefined')
		{
			return false;
		}

		if(typeof mobUser.cache.passwordAgain == 'undefined')
		{
			return false;
		}

		if(!mobUser.cache.mode)
		{
			return false;
		}

		mobUser.cache.isValidPassword = false;

		if(mobUser.cache.password.length < 4)
		{
			mobUser.blocks[mobUser.cache.mode].find('.x-password-error-text').html(mobUser.messages.passwordShort);
			mobUser.blocks[mobUser.cache.mode].find('.x-password-error-img').html(mobUser.images.error.replace('@server@', 'no'));
		}
		else if(mobUser.cache.password != mobUser.cache.passwordAgain)
		{
			mobUser.blocks[mobUser.cache.mode].find('.x-password-error-text').html(mobUser.messages.passwordDifferent);
			mobUser.blocks[mobUser.cache.mode].find('.x-password-error-img').html(mobUser.images.error.replace('@server@', 'no'));
		}
		else
		{
			mobUser.cache.isValidPassword = true;
			mobUser.blocks[mobUser.cache.mode].find('.x-password-error-text').html('');
			mobUser.blocks[mobUser.cache.mode].find('.x-password-error-img').html(mobUser.images.error.replace('@server@', 'yes'));
		}

		mobUser.staticCheckForm();
	},

	// =========================================================================

	staticCheckCaptcha: function(show_error)
	{
		if(typeof mobUser.cache.captcha == 'undefined')
		{
			return false;
		}

		if(!mobUser.cache.mode)
		{
			return false;
		}

		if(mobUser.cache.captcha.length < 4)
		{
			if(show_error)
			{
				mobUser.cache.isValidCaptcha = false;
				mobUser.blocks[mobUser.cache.mode].find('.x-captcha-error-text').html();
				mobUser.blocks[mobUser.cache.mode].find('.x-captcha-error-img').html(mobUser.images.error.replace('@server@', 'no'));
			}
		}
		else
		{
			mobUser.cache.isValidCaptcha = true;
			mobUser.blocks[mobUser.cache.mode].find('.x-captcha-error-text').html('');
			mobUser.blocks[mobUser.cache.mode].find('.x-captcha-error-img').html('');
		}

		mobUser.staticCheckForm();
	},

	// =========================================================================

	staticCheckCaptchaError: function()
	{
		mobUser.staticCheckCaptcha(true);
	},

	// =========================================================================

	staticCheckCaptchaNoError: function()
	{
		mobUser.staticCheckCaptcha(false);
	},

	// =========================================================================

	staticLoadCaptcha: function(mode)
	{
		var img = $('<img>')
			.attr({
				src: forAll.domen + 'kapcha/' + Math.random() + '.gif',
				width: 150,
				height: 50
			})
			.addClass('hand x-captcha-image')
			.click(function()
			{
				mobUser.staticReloadCaptcha();
			});
		mobUser.blocks[mode].find('.x-captcha-box').html(img);
	},

	// =========================================================================

	staticReloadCaptcha: function(mode)
	{
		mode = mode || mobUser.cache.mode;
		mobUser.blocks[mode].find('.x-captcha-image')
		.attr({
			src: forAll.domen + 'kapcha/' + Math.random() + '.gif'
		});
	},

	// =========================================================================

	staticCheckForm: function()
	{
		$('.x-error-img').html('');

		switch(mobUser.cache.mode)
		{
			case 'registration':
				if(mobUser.cache.isValidMail && mobUser.cache.isValidLogin && mobUser.cache.isValidPassword && mobUser.cache.isValidCaptcha)
				{
					mobUser.blocks.registration.find('.x-submit').attr({
						disabled: false
					});
					return true;
				}
				else
				{
					mobUser.blocks.registration.find('.x-submit').attr({
						disabled: true
					});
					return false;
				}
			break;

			case 'authRegistrationR':
				if(mobUser.cache.isValidMail && mobUser.cache.isValidLogin && mobUser.cache.isValidPassword && mobUser.cache.isValidCaptcha)
				{
					mobUser.blocks.authRegistrationR.find('.x-submit').attr({
						disabled: false
					});
					return true;
				}
				else
				{
					mobUser.blocks.authRegistrationR.find('.x-submit').attr({
						disabled: true
					});
					return false;
				}
			break;

			case 'authorization':
			case 'authRegistrationL':
				return true;
			break;

			case 'passwordReminder':
				if(mobUser.cache.isValidMail)
				{
					mobUser.blocks.passwordReminder.find('.x-submit').attr({
						disabled: false
					});
					return true;
				}
				else
				{
					mobUser.blocks.passwordReminder.find('.x-submit').attr({
						disabled: true
					});
					return false;
				}
			break;
		}
	},

	// =========================================================================

	staticClearTimers: function()
	{
		for(var timer in mobUser.timers)
		{
			if(mobUser.timers[timer])
			{
				window.clearTimeout(mobUser.timers[timer]);
			}
		}
	},

	// =========================================================================

	staticShowResponseMessage: function(responseText, style, callbacks)
	{
		var title = '';
		var message = '';
		var space_one = responseText.indexOf('|');

		style = style || false;
		callbacks = callbacks || {};

		if(space_one !== -1)
		{
			var space_two = responseText.indexOf('|', space_one + 1);
			if(space_two == -1)
			{
				message = responseText.substring(space_one + 1);
			}
			else
			{
				title = responseText.substring(space_one + 1, space_two);
				message = responseText.substr(space_two + 1);
			}
		}

		for(var key in mobUser.blocks)
		{
			if(mobUser.blocks[key])
			{
				mobUser.blocks[key].parent().find('form').get(0).reset();
				mobUser.staticReloadCaptcha(key);
			}
		}

		if(message.length)
		{
			mobUser.staticShowMessage(title, message, style, callbacks);
		}
		else
		{
			if(callbacks.onOK)
			{
				callbacks.onOK();
			}
		}
	},

	// =========================================================================

	staticShowMessage: function(title, message, style, callbacks)
	{
		mobUser.cache.onMessageComplete = {};

		if(typeof callbacks != 'undefined' && callbacks)
		{
			mobUser.cache.onMessageComplete = callbacks;
		}

		mobUser.blocks.message.find('.x-button').hide();
		mobUser.blocks.message.find('.x-close').hide();
		switch(style)
		{
			default:
			case 'close':
				mobUser.blocks.message.find('.x-button-close').show();
				mobUser.blocks.message.find('.x-close').show();
			break;

			case 'okcancel':
				mobUser.blocks.message.find('.x-button-cancel').show();
				mobUser.blocks.message.find('.x-button-ok').show();
			break;

			case 'ok':
				mobUser.blocks.message.find('.x-button-ok').show();
				mobUser.cache.onMessageComplete.onCancel = mobUser.cache.onMessageComplete.onOK;
			break;

			case 'cancel':
				mobUser.blocks.message.find('.x-button-cancel').show();
			break;
		}

		mobUser.staticMoveToCenter(mobUser.blocks.message);
		
		mobUser.blocks.message.find('.x-button-close')
			.click(function()
			{
				var close = true;
				if(mobUser.cache.onMessageComplete.onCancel)
				{
					close = mobUser.cache.onMessageComplete.onCancel();
				}

				if(close || typeof close == 'undefined')
				{
					mobUser.staticCloseAll();
				}
			});
		mobUser.blocks.message.find('.x-button-ok')
			.click(function()
			{
				var close = true;
				if(mobUser.cache.onMessageComplete.onOK)
				{
					close = mobUser.cache.onMessageComplete.onOK();
				}

				if(close || typeof close == 'undefined')
				{
					mobUser.staticCloseAll();
				}
			});
		mobUser.blocks.message.find('.x-button-cancel')
			.click(function()
			{
				var close = true;
				if(mobUser.cache.onMessageComplete.onCancel)
				{
					close = mobUser.cache.onMessageComplete.onCancel();
				}

				if(close || typeof close == 'undefined')
				{
					mobUser.staticCloseAll();
				}
			});
		mobUser.blocks.message.find('.x-close')
			.click(function()
			{
				var close = true;
				if(mobUser.cache.onMessageComplete.onCancel)
				{
					close = mobUser.cache.onMessageComplete.onCancel();
				}

				if(close || typeof close == 'undefined')
				{
					mobUser.staticCloseAll();
				}

				return false;
			});
		mobUser.overlay
			.click(function()
			{
				var close = true;
				if(mobUser.cache.onMessageComplete.onClose)
				{
					close = mobUser.cache.onMessageComplete.onClose();
				}

				if(close || typeof close == 'undefined')
				{
					mobUser.staticCloseAll();
				}

				return false;
			});

		this.blocks.message.find('.x-title').html(title);
		this.blocks.message.find('.x-message').html(message);

		mobUser.staticCloseAll();
		mobUser.overlay.show();
		mobUser.blocks.message.show();
	},

	// =========================================================================

	staticRegisterSubmit: function(form)
	{
		if(mobUser.staticCheckForm())
		{
			var data = $(form).serializeArray();
			data.push({name: 'mode', value: 'userRegister'});

			$.ajax({
				type: 'POST',
				url: '/hint/account/',
				data: data,
				complete: function(request)
				{
					mobUser.staticClearTimers();

					switch(request.responseText.split('|')[0])
					{
						case 'mailEmpty':
							mobUser.cache.isValidMail = false;
							mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.mailEmpty);
							mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
						break;

						case 'mailInvalid':
							mobUser.cache.isValidMail = false;
							mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.mailInvalid);
							mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
						break;

						case 'mailExists':
							mobUser.cache.isValidMail = false;
							mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.mailExists);
							mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
						break;

						case 'loginEmpty':
							mobUser.cache.isValidLogin = false;
							mobUser.blocks[mobUser.cache.mode].find('.x-login-error-text').html(mobUser.messages.loginEmpty);
							mobUser.blocks[mobUser.cache.mode].find('.x-login-error-img').html(mobUser.images.error.replace('@server@', 'no'));
						break;

						case 'loginExists':
							mobUser.cache.isValidLogin = false;
							mobUser.blocks[mobUser.cache.mode].find('.x-login-error-text').html(mobUser.messages.loginExists);
							mobUser.blocks[mobUser.cache.mode].find('.x-login-error-img').html(mobUser.images.error.replace('@server@', 'no'));
						break;

						case 'passwordShort':
							mobUser.cache.isValidPassword = false;
							mobUser.blocks[mobUser.cache.mode].find('.x-password-error-text').html(mobUser.messages.passwordShort);
							mobUser.blocks[mobUser.cache.mode].find('.x-password-error-img').html(mobUser.images.error.replace('@server@', 'no'));
						break;

						case 'passwordDifferent':
							mobUser.cache.isValidPassword = false;
							mobUser.blocks[mobUser.cache.mode].find('.x-password-error-text').html(mobUser.messages.passwordDifferent);
							mobUser.blocks[mobUser.cache.mode].find('.x-password-error-img').html(mobUser.images.error.replace('@server@', 'no'));
						break;

						case 'captchaInvalid':
							mobUser.staticReloadCaptcha(mobUser.cache.mode);
							mobUser.cache.isValidCaptcha = true;
							mobUser.blocks[mobUser.cache.mode].find('.x-captcha-error-text').html(mobUser.messages.captchaInvalid);
							mobUser.blocks[mobUser.cache.mode].find('.x-captcha-error-img').html(mobUser.images.error.replace('@server@', 'no'));
						break;

						case 'messageStop':
							mobUser.staticShowResponseMessage(request.responseText);
						break;

						case 'OK':
							mobUser.onComplete();
						break;
					}
					mobUser.staticCheckForm();
				}
			});
		}
	},

	// =========================================================================

	staticLoginSubmit: function(form)
	{
		if(mobUser.staticCheckForm())
		{
			var data = $(form).serializeArray();
			data.push({name: 'mode', value: 'userLogin'});
			$.ajax({
				type: 'POST',
				url: '/hint/account/',
				data: data,
				complete: function(request)
				{
					mobUser.staticClearTimers();
					switch(request.responseText.split('|')[0])
					{
						case 'mailLoginEmpty':
							mobUser.cache.isValidMail = false;
							mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.mailLoginEmpty);
							mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
						break;

						case 'authFailed':
							mobUser.cache.isValidMail = false;
							mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-text').html(mobUser.messages.authFailed);
							mobUser.blocks[mobUser.cache.mode].find('.x-mail-error-img').html(mobUser.images.error.replace('@server@', 'no'));
						break;

						case 'messageStop':
							mobUser.staticShowResponseMessage(request.responseText);
						break;

						case 'OK':
							mobUser.staticShowResponseMessage(request.responseText, 'ok', {onOK: mobUser.onComplete});
						break;
					}
					mobUser.staticCheckForm();
				}
			});
		}
	}

	// =========================================================================
};

var messageTitleShort = 'Заголовок сообщения слишком короткий';
var messageTextShort = 'Текст сообщения слишком короткий';

$(function()
{
	mobUser.init();

	// Форма отзывов
	$('#formReviewAdd').submit(function()
	{
		if (this.time_us.value == '-')
		{
			alert('Вы не указали время пользования!');
			this.time_us.focus();
			return false;
		}

		if (this.reiting.value == '')
		{
			alert('Вы не дали оценку!');
			this.time_us.focus();
			return false;
		}

		if ((this.text_adv.value == '') && (this.text_disadv.value == ''))
		{
			alert('Вы не написали достоинства или недостатки!');
			this.text_adv.focus();
			return false;
		}

		if(mobUser.staticIsLogged())
		{
			if(mobUser.cache.messageOK)
			{
				return true;
			}

			mobUser.staticShowMessage(
				'Отправить сообщение?',
				'Ваше сообщение будет отправлено на проверку.<br />Оно появится на сайте после проверки Администратора.',
				'okcancel',
				{
					onOK: function()
					{
						mobUser.cache.messageOK = true;
						$('#formReviewAdd').submit();
					},
					onClose: function(){
						return false;
					},
					onCancel: function(){
						
					}
				}
			);
			return false;
		}

		mobUser.cache.messageOK = false;
		mobUser.onComplete = function()
		{
			$('#formReviewAdd').submit()
		};
		mobUser.showAuthForm();
		return false;
	});

	// Форма вопросов
	$('#postform').find('input[type=submit]').click(function()
	{
		var form = $(this.form);
		form.find('input[rel="auto_input"]').remove();
		form.append('<input type="hidden" rel="auto_input" name="' + this.name + '" value="' + this.value + '" />');
		return true;
	});

	$('#postform').submit(function()
	{
		if(!this.subject.value.length)
		{
			alert(messageTitleShort);
			this.subject.focus();
			return false;
		}

		if (!this.message.value.length)
		{
			alert(messageTextShort);
			this.message.focus();
			return false;
		}

		if(mobUser.staticIsLogged())
		{
			this.form_token.value = getCookie('form_token_posting');
			this.creation_time.value = getCookie('form_token_posting_time');
			return true;
		}

		mobUser.onComplete = function()
		{
			$('#postform').submit()
		};
		mobUser.showAuthForm();
		return false;
	});
	
	$('#formGamesReview').submit(function()
	{
		if(mobUser.staticIsLogged())
		{
			return true;
		}

		mobUser.onComplete = function()
		{
			$('#formGamesReview').submit()
		};
		
		mobUser.showAuthForm();
		return false;
	});
	
	$('a.x-create-new-topic').click(function()
	{
		if(mobUser.staticIsLogged())
		{
			return true;
		}
		
		mobUser.cache.onCompleteHref = this.href;
		mobUser.onComplete = function()
		{
			window.location.href = mobUser.cache.onCompleteHref;
		};

		mobUser.showAuthForm();
		return false;
	});
	
	$('a.x-create-new-post').click(function()
	{
		if(mobUser.staticIsLogged())
		{
			return true;
		}
		
		mobUser.cache.onCompleteHref = this.href;
		mobUser.onComplete = function()
		{
			window.location.href = mobUser.cache.onCompleteHref;
		};
		mobUser.showAuthForm();
		return false;
	});

	// Форма быстрого ответа
	$('#quickReplyForm').find('input[name=post]').click(function()
	{
		var form = $(this.form);
		form.find('input[rel="auto_input"]').remove();
		form.append('<input type="hidden" rel="auto_input" name="' + this.name + '" value="' + this.value + '" />');
		return true;
	});

	$('#quickReplyForm').submit(function()
	{
		if (!this.message.value.length)
		{
			alert(messageTextShort);
			this.message.focus();
			return false;
		}

		if(mobUser.staticIsLogged())
		{
			this.form_token.value = getCookie('form_token_posting');
			this.creation_time.value = getCookie('form_token_posting_time');
			return true;
		}

		mobUser.onComplete = function()
		{
			$('#quickReplyForm').submit()
		};
		mobUser.showAuthForm();
		return false;
	});
});