

if (jQuery) (function(jQuery) {
	jQuery.extend(jQuery.ark, { loginBox: function() { } });
	jQuery.extend(jQuery.ark.loginBox, {
		SignInProcessor: function SignInProcessor()
		{
			this.id = '';
			this.loggedInDivId = '';
			this.loggedInMode = '';
			this.guestMode = '';
			this.loggingInText = '';
			this.loggingOutText = '';
			this.waitText = '';
			this.passwordInputId = '';
			this.defaultEmailText = '';
			this.defaultPasswordText = '';
			this.ProcessSignIn = function()
			{
				if (document.getElementById(this.loggedInDivId) == null)
				{
					//assert(authCookie != null);
					ShowUniversalTransition(this.id, this.loggingInText);
					DoServiceCall(this.id, this.loggedInMode);
					var passwordInput = document.getElementById(this.passwordInputId);
					if (passwordInput)
					{
						passwordInput.value = '';
					}
				}
			};
			this.ProcessSignOut = function()
			{
				//assert(authCookie == null);
				ShowUniversalTransition(this.id, this.loggingOutText);
				DoServiceCall(this.id, this.guestMode);
			};
		},
		SignIn: null,
		dummy: 0
	});
})(jQuery);

function HideLoginTransition(){}
function DoServiceCall(clientId, mode, submitData)
{
	jQuery('#' + clientId).load('http://www.greatdaygames.com/ajaxServices/LoginBox.aspx', {
		'_': Math.random(),
		'_id': clientId,
		'_mode': mode,
		'_d': typeof(submitData) == 'undefined' ? '' : submitData });
}
function DoForgotPassword()
{
	ShowUniversalTransition(jQuery.ark.loginBox.SignIn.id, jQuery.ark.loginBox.SignIn.waitText);
	DoServiceCall(jQuery.ark.loginBox.SignIn.id, 'ForgotPassword');
}
function DoGuest()
{
	ShowUniversalTransition(jQuery.ark.loginBox.SignIn.id, jQuery.ark.loginBox.SignIn.waitText);
	DoServiceCall(jQuery.ark.loginBox.SignIn.id, 'Guest');
}
function DoAjaxLogout()
{
	ShowUniversalTransition(jQuery.ark.loginBox.id, jQuery.ark.loginBox.SignIn.loggingOutText);
	ProcessLoginCall('', '', null, HideLoginTransition);
	jQuery.ark.login.RestoreDefaultText_Force(document.getElementById('textName'), jQuery.ark.loginBox.SignIn.defaultEmailText);
	jQuery.ark.login.RestoreDefaultText_Force(document.getElementById('textPassword'), jQuery.ark.loginBox.SignIn.defaultPasswordText, 'textPasswordS');
}
function SetDefaultControlColor(controlId)
{
	jQuery('#' + controlId).css( { backgroundColor: 'white' } );
}
function DoAjaxLogin(emailControlId, passwordControlId, passwordSControlId, rememberPasswordControlId)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	emailValue = document.getElementById(emailControlId).value;
	passwordValue = document.getElementById(passwordControlId).value;
	isRemember = document.getElementById(rememberPasswordControlId).checked;
	if (emailValue != jQuery.ark.loginBox.SignIn.defaultEmailText && emailValue != '' && passwordValue != '' && reg.test(emailValue))
	{
		ShowUniversalTransition(jQuery.ark.loginBox.SignIn.id, jQuery.ark.loginBox.SignIn.loggingInText);
		ProcessLoginCall(emailValue, passwordValue, isRemember, HideLoginTransition, ShowMasterLoginFailPopup);
	}
	else
	{
		if (emailValue == jQuery.ark.loginBox.SignIn.defaultEmailText || emailValue == '' || !reg.test(emailValue))
		{
			jQuery("#" + emailControlId).css({ backgroundColor: "#ff6d6d" });
		}
		else
		{
			jQuery("#" + emailControlId).css({ backgroundColor: "white" });
		}
		if (passwordValue == '')
		{
			jQuery("#" + passwordControlId).css({ backgroundColor: "#ff6d6d" });
			jQuery("#" + passwordSControlId).css({ backgroundColor: "#ff6d6d" });
		}
	}
}
