$(document).ready(registerLoginAction);

function registerLoginAction()
{
	$('.loginSubmitLink').click(function(event) {
		event.preventDefault();
		$('#loginForm').ajaxSubmit({
			//target: 'login-form-wrapper',
			beforeSubmit: preLoginAjax,
			success: showAjaxLogin,
			dataType: 'html',
			//type: 'post',
			timeout: '3000'
		}); 
	});
	$('.login-forgotten a[title]').tooltip({ 
		tip: '#dynatip', 
		offset: [10, 2],
		effect: 'slide',
		position: 'bottom center'
	});
}

function preLoginAjax()
{
	$('#loginForm')[0].innerHTML='<div class="login1 loading">Loading</div>';
}

function showAjaxLogin(responseText, statusText)
{
	$('#login-panel-wrapper')[0].innerHTML=responseText.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	registerLoginAction();
	postLoginAjax();
}

function postLoginAjax()
{
	loginLink = $('.register-link');
	if (loginLink.length > 0)
	{
		if (loginLink[0].innerHTML == 'register') {
			loginLink[0].innerHTML = 'my account';
			loginLink[0].href='/changeClientDetails.jsp';
			showLoginInfo();
		} else {
			loginLink[0].innerHTML = 'register';
			loginLink[0].href='/registerClient.jsp';
		}
	}
}
function showLoginInfo()
{
	//window.open("/info.html", "logininfo", 'height=300, width=400,left=300,top=200,location=no').focus();
}

