//for closure compiler to ensure it gets exported
window['loadApp'] = loadApp;

var router = window['router'];



function loadApp()
{
	initializeRoutes();
	router.reload();

	//login and logout
	$('form.form-signin').submit(login);
	//$('#logout').click(logout);
	
	//when a bootstrap tab is shown, then trigger a redraw of its table
	$('#screen-sd').delegate('a[data-toggle="tab"]', 'shown.bs.tab', function(e)
	{
		var id_company = $(this).closest('li').data('id_company');
		
		tables[id_company].draw();
	});
}

function login(e)
{
	e.preventDefault();
	
	$.post('api/login.php',
	{
		'email': $('#email').val(),
		'password': $('#password').val()
	})
	.done(function(response)
	{
		console.log(response);
		
		router('/sd');
	})
	.fail(function(err, xhr, text)
	{
		console.error(err.responseText);
	});
	
	return false;
}