function LexLogin_AJAX_history() {
	//dhtmlHistory.initialize();
	//dhtmlHistory.addListener( LexLogin_AJAX_historyChange );
}

function LexLogin_AJAX_historyChange( newLocation, historyData ) {
	//var historyMsg = historyData;
	//LexLogin_AJAX_task( historyMsg, true );
}


function LexLogin_AJAX_init()
{
	if( _login_window )
	{
		
	}else{
		_window = document.createElement('div');
		_window.id = "cms-login-window";
		_window.style.display = "none";
		_window.align = "center";
		document.body.appendChild( _window );
		LexBoxBubble( 'cms-login-window', '' );
	}
	
	var inithandlerFunc = function(t) {

		if( _login_window )
		{
			if( t.responseText.search(/indow.location.href/) > 0 )
			{ 
				eval(t.responseText); 
			}else{ 
				$(_login_window).innerHTML = t.responseText; 
			}	
		}else{
			if( t.responseText.search(/indow.location.href/) > 0 )
			{ 
				eval(t.responseText); 
			}else{ 
				LexBoxBubble( 'cms-login-window', t.responseText );
				$('lex-box-bubble-container').style.width = "400px";
				$('lex-box-bubble-container').style.height = "250px";
				new Effect.Appear( 'cms-login-window', { duration: 0.50 } );
			}
		}
	}
	
	var initerrFunc = function(t) {
		alert('Error ' + t.status + ' -- ' + t.statusText);
	}
	
	//dhtmlHistory.add("init", "init");
	
	new Ajax.Request( LexLogin_AJAX_path + 'function_login.php', {method:'post', postBody:'action=init', onSuccess:inithandlerFunc, onFailure:initerrFunc });
}

function LexLogin_AJAX_task( _task, _history )
{
	
	var handlerFunc = function(t) {

		if( _login_window )
		{
			if( t.responseText.search(/indow.location.href/) > 0 ){ eval(t.responseText); }else{ $(_login_window).innerHTML = t.responseText; }
		}else{
			if( t.responseText.search(/indow.location.href/) > 0 ){ eval(t.responseText); }else{ $('lex-box-bubble-container').innerHTML = t.responseText; }
		}
	}
	
	var errFunc = function(t) {
		alert('Error ' + t.status + ' -- ' + t.statusText);
	}

	if( _task == "init" ){
		//dhtmlHistory.add("init", "init");
		new Ajax.Request( LexLogin_AJAX_path + 'function_login.php', {method:'post', postBody:'action=init', onSuccess:handlerFunc, onFailure:errFunc });
		if( !_history )
		{ 
			if( _login_window )
			{
				$( _login_window ).innerHTML = '<div class="body-load-indicator-large"></div>';
			}else{
				$('lex-box-bubble-container').innerHTML = '<div class="body-load-indicator-large"></div>';
			}
		}
		return;
	}
	
	if( _task == "retrieve" ){
		
		//dhtmlHistory.add("retrieve", "retrieve");
		new Ajax.Request( LexLogin_AJAX_path + 'function_login.php', {method:'post', postBody:'action=retrieve', onSuccess:handlerFunc, onFailure:errFunc });
		if( !_history )
		{ 
			if( _login_window )
			{
				$( _login_window ).innerHTML = '<div class="body-load-indicator-large"></div>';
			}else{
				$('lex-box-bubble-container').innerHTML = '<div class="body-load-indicator-large"></div>';
			}
		}
		return;
	}

	if( _task == "retrieve_email" ){
		_action = '&user_email=' + $('user_email').value;
		//dhtmlHistory.add("retrieve_email", "retrieve_email");
		new Ajax.Request( LexLogin_AJAX_path + 'function_login.php', {method:'post', postBody:'action=retrieve_email' + _action, onSuccess:handlerFunc, onFailure:errFunc });
		if( !_history )
		{ 
			if( _login_window )
			{
				$( _login_window ).innerHTML = '<div class="body-load-indicator-large"></div>';
			}else{
				$('lex-box-bubble-container').innerHTML = '<div class="body-load-indicator-large"></div>';
			}
		}
		return;
	}
	
	if( _task == "authenticate" ){
		_action = '&user_username=' + $('user_username').value + '&user_password=' + hex_sha1( $('user_password').value );
		//dhtmlHistory.add("authenticate", "authenticate");
		new Ajax.Request( LexLogin_AJAX_path + 'function_login.php', {method:'post', postBody:'action=authenticate' + _action, onSuccess:handlerFunc, onFailure:errFunc });
		if( !_history )
		{ 
			if( _login_window )
			{
				$( _login_window ).innerHTML = '<div class="body-load-indicator-large"></div>';
			}else{
				$('lex-box-bubble-container').innerHTML = '<div class="body-load-indicator-large"></div>';
			}
		}
		return;
	}

	if( _task == "logout" ){
		//dhtmlHistory.add("logout", "");
		new Ajax.Request( LexLogin_AJAX_path + 'function_login.php', {method:'post', postBody:'action=logout', onSuccess:handlerFunc, onFailure:errFunc });
		if( !_history )
		{ 
			if( _login_window )
			{
				$( _login_window ).innerHTML = '<div class="body-load-indicator-large"></div>';
			}else{
				$('lex-box-bubble-container').innerHTML = '<div class="body-load-indicator-large"></div>';
			}
		}
		return;
	}
}

function LexLogin_AJAX_logout()
{

	var logouthandlerFunc = function(t) {
		if( _logout_window )
		{
			document.location.href = _logout_window;
		}else{
			document.location.href = t.responseText;
		}
	}
	
	var logouterrFunc = 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:logouterrFunc });
}