function loadPage(_page) {
	new Ajax.Updater('content', 'includes/' +_page+ '.php');	
}

function login(_data) {
	new Ajax.Updater('content', 'includes/login.php', {
		method: 'post',
		postBody: _data
	});
}

function changeType(_data) {
	new Ajax.Request('includes/change_type.php', {
		method: 'post',
		postBody: _data
	});
}

function changeEmail(_data) {
	new Ajax.Request('includes/change_email.php', {
		method: 'post',
		postBody: _data
	});
}

function changePass(_data) {
	new Ajax.Request('includes/change_password.php', {
		method: 'post',
		postBody: _data
	});
}

function addUser() {
	var username = prompt('Please enter a Username for the new user:');
	new Ajax.Request('includes/add_user.php', {
		method: 'post',
		postBody: 'username=' + username,
		onSuccess: function(response) {
			loadPage('users');	
		}
	});
}

function deleteUser(_id) {
	if (confirm('Delete this user?')) {
		new Ajax.Request('includes/delete_user.php', {
			method: 'post',
			postBody: 'userid=' + _id,
			onSuccess: function(response) {
				loadPage('users');	
			}
		})
	}
}

function addTraining(_data) {
	if (confirm('Are you sure to add these information?')) {
		new Ajax.Request('includes/add_training.php', {
			method: 'post',
			postBody: _data,
			onSuccess: function(response) {
				loadPage('training_view');
			}
		});
	}
}

function deleteTraining(_id) {
	if (confirm('Are you sure to delete this entry?')) {
		new Ajax.Request('includes/delete_training.php', {
			method: 'post',
			postBody: "id=" + _id,
			onSuccess: function(response) {
				loadPage('training_view');
			}
		});
	}
}
