/**
 *	Performs the login to the SMF forum
 */
function smfLogin(username, password) {
	try {
		var smfForm = getForumFrameDocument().getElementById("form.login");
		smfForm.user.value = username;
		smfForm.passwrd.value = password;
		smfForm.submit();
	} catch(ex) { }
}

/**
 *	Performs the logout of the SMF forum
 */
function smfLogout(silent) {
	var smfForm = getForumFrameDocument().getElementById("form.login");
	var key = smfForm.session.value;
	var url = "../smf/index.php?action=logout&sesc=" + key;
	if (silent) AJAX.get(url);
	else document.getElementById("forum.frame").src = url;
}

function onSmfReload() {
	var smfForm = getForumFrameDocument().getElementById("form.login");
	// update personal message count
	var pm = 0;
	if (smfForm) pm = parseInt(smfForm.pm_count.value);
	var html = "<a href='#' onClick='javascript:showSmfPersonalMessages()'>" + pm;
	if (pm == 1) html = html + " " + getString("pm");
	else html = html + " " + getString("pms"); 
	html = html + "</a>";
	document.getElementById("pm_count").innerHTML = html;
	// decide on admin link
	var admin = parseInt(smfForm.allow_admin.value);
	if (admin > 0) {
		document.getElementById("link.admin").style.display = "";
		document.getElementById("link.stats").style.display = "";
	} else {
		document.getElementById("link.admin").style.display = "none";
		document.getElementById("link.stats").style.display = "none";
	}
}

function showSmfPersonalMessages() {
	showSmfAction("pm");
}

function showSmfAction(action) {
	var append = (action && action.length > 0) ? "?action=" + action : "";
	document.getElementById("forum.frame").src = "../smf/index.php" + append;
}

