﻿var authentication =
{
	resetPwdVisible: false,

	login: function()
	{
		$('#' + rg('CID_Login_AuthHidden')).click();
	},
	reset: function()
	{
		$.post(rg('HDL_Login_ResetPassword'),
		{
			e: $('#' + rg('CID_Login_ForgotEmail')).val()
		},
		function(response)
		{
			$('#' + rg('CID_Login_Error')).html(response.Message);
			$('#' + rg('CID_Login_Error')).attr('class', response.Success ? 'sBoxGreen' : 'sBoxRed');
			$('#' + rg('CID_Login_AuthError')).show();
		},
		'json');
	},
	toggle: function()
	{
		if (authentication.resetPwdVisible)
		{
			$('#trAuthForgot').hide();
			authentication.resetPwdVisible = false;
		}
		else
		{
			$('#trAuthForgot').show();
			authentication.resetPwdVisible = true;
		}
	},
	init: function(showPwdReset)
	{
		preventEnter(rg('CID_Login_ForgotEmail'));
		$('#' + rg('CID_Login_Nickname') + ', #' + rg('CID_Login_Password')).keydown(function(event)
		{
			if (events.keyCode(event) == 13)
			{
				authentication.login();
				return false;
			}
			return true;
		});
		$('#tblAuth').show();
		if (showPwdReset)
			authentication.toggle();
		authentication.resetPwdVisible = showPwdReset;
	}
};
