function LexLogin_AJAX_init()
{
	if( _login_window == "" )
	{
		loginContainer = new LexBoxBubble( 'cms-login-window', {text: 'Loading', align: 'center', constrainBoxWidth:400, constrainBoxHeight:250} );
	}
	
	LexLogin_AJAX_task('initialize');
}

function LexLogin_AJAX_task( _task )
{
	
	var AuthHandlerFunc = function(t) 
	{
		if( t.responseText.search(/indow.location.href/) > 0 )
		{
			eval(t.responseText); 
		}else{
			if( _login_window )
			{
				$( _login_window ).innerHTML = t.responseText;
			}else{
				loginContainer.content( t.responseText ); 
			}
		}
	}
	
	var AuthErrorFunc = function(t) { alert('Error ' + t.status + ' -- ' + t.statusText); }

	if( _task == 'initialize' ){ _post = 'action=init'; }

	if( _task == "retrieve" ){ _post = 'action=retrieve'; }

	if( _task == "retrieve_email" ){ _post = 'action=retrieve_email&user_email=' + $('user_email').value; }

	if( _task == "authenticate" ){ _post = 'action=authenticate&user_username=' + $('user_username').value + '&user_password=' + hex_sha1( $('user_password').value ); }
	
	if( _task == "logout" ){ _post = 'action=logout'; }
	
	if( _login_window )
	{
		$( _login_window ).innerHTML = '<div class="body-load-indicator-large"></div>';
	}else{
		loginContainer.content( '<div class="body-load-indicator-large"></div>' );
	}
	
	new Ajax.Request( LexLogin_AJAX_path + 'function_login.php', {method:'post', postBody:_post, onSuccess:AuthHandlerFunc, onFailure:AuthErrorFunc });

}

function LexLogin_AJAX_logout()
{
	var LogoutHandlerFunc = function(t) {
		if( _logout_window )
		{
			document.location.href = _logout_window;
		}else{
			document.location.href = t.responseText;
		}
	}
	
	var LogoutErrorFunc = function(t) { alert('Error ' + t.status + ' -- ' + t.statusText); }

	new Ajax.Request( LexLogin_AJAX_path + 'function_login.php', {method:'post', postBody:'action=applicationlogout', onSuccess:LogoutHandlerFunc, onFailure:LogoutErrorFunc });
}