function showLoginForm(action)
{
	if (typeof action != 'undefined')
	{
		var login_form_el = document.getElementById('login_form');
		if (login_form_el == null)
			return false;
		login_form_el.action = action;
	}
	
	var frmLogin = document.getElementById('frmLogin');
	if (frmLogin != null)
	{
		if (frmLogin.style.display == 'block')
		{
			fadeElement(frmLogin, 0, 300);
		}
		else
		{
			setElementOpacity(frmLogin, 0);
			fadeElement(frmLogin, 100, 300);
			frmLogin.style.position = 'absolute';
			
			if (!document.body)
				document.body = document.getElementsByTagName("body")[0];
			var winWidth = window.innerWidth;
			if (!winWidth)
				winWidth = document.body.offsetWidth;
			var winHeight = window.innerHeight;
			if (!winHeight)
				winHeight = document.body.offsetHeight;
			
			frmLogin.style.left = ((winWidth - frmLogin.offsetWidth) / 2) + 'px';
			frmLogin.style.top = ((winHeight - frmLogin.offsetHeight) / 2) + 'px';
		}
	}
	
	var txtUsername = document.getElementById('komixEmail');
	if (txtUsername != null)
	{
		txtUsername.focus();
		return true;
	}
	return false;
}

function addLoginForm(success, data)
{
	if (!success)
		return;

	// Create form and add to body
	var frmLogin = document.createElement('div');
	var body = document.getElementsByTagName('body')[0];
	frmLogin.id = 'frmLogin';
	frmLogin.style.width = '300px';
	frmLogin.style.display = 'none';
	frmLogin.style.zIndex = 99;
	frmLogin.innerHTML = data;
	body.appendChild(frmLogin);
}

addToOnload(function() {
	// Create login form by calling PHP
	var frmLogin = document.getElementById('login_form');
	if (frmLogin == null)
	{
		var uri = document.location.toString().substring(document.location.host.length + base_url.length + 7);
		PerformRemoteAction(addLoginForm, base_url + 'login/login_form.inc.php', 'popup&after=' + urlencode(uri));
	}
});