function login(username, password) {
	var ajax = new Ajax.Request('inc/auth.php?log=in', {
		method:'post', 
		parameters: {user: username, pass: password, jscript: true},
		onComplete: function(transport){
			eval(transport.responseText);
		}});
}

function logout() {
	var ajax = new Ajax.Request('inc/auth.php?log=out', {
		onComplete: function(){
			generateLogoutContent();
		}});

}

function changeContent() {
	document.getElementById('loginHeader').childNodes[1].setAttribute('href', '#');
	document.getElementById('loginHeader').childNodes[1].setAttribute('onclick', 'logout()');
}

function clearInnerHTML(obj) {
	while(obj.firstChild) obj.removeChild(obj.firstChild);
}

function generateLogoutContent() {
	clearInnerHTML(document.getElementById('loginHeader'));
	clearInnerHTML(document.getElementById('loginContent'));
	var text = document.createTextNode('Login');
	document.getElementById('loginHeader').appendChild(text);

	var form = document.createElement('form');
	//form.setAttribute('action', '');
	//form.setAttribute('onsubmit', 'login(this.form.user.value, this.form.pass.value);');
	var fieldset = document.createElement('fieldset');
	fieldset.setAttribute('id', 'loginForm');

	var labelUser = document.createElement('label');
	labelUser.setAttribute('for', 'user');
	labelUser.appendChild(document.createTextNode('Username:'));

	var inputUser = document.createElement('input');
	inputUser.setAttribute('type', 'text');
	inputUser.setAttribute('size', '8');
	inputUser.setAttribute('name', 'user');
	inputUser.setAttribute('id', 'user');

	var labelPass = document.createElement('label');
	labelPass.setAttribute('for', 'pass');
	labelPass.appendChild(document.createTextNode('Password:'));

	var inputPass = document.createElement('input');
	inputPass.setAttribute('type', 'password');
	inputPass.setAttribute('size', '8');
	inputPass.setAttribute('name', 'pass');
	inputPass.setAttribute('id', 'pass');

	var inputButton = document.createElement('input');
	inputButton.setAttribute('type', 'button');
	inputButton.setAttribute('value', 'Login');
	inputButton.setAttribute('onclick', 'login(this.form.user.value, this.form.pass.value);');

	fieldset.appendChild(labelUser);
	fieldset.appendChild(inputUser);
	fieldset.appendChild(labelPass);
	fieldset.appendChild(inputPass);
	fieldset.appendChild(inputButton);
	form.appendChild(fieldset);
	document.getElementById('loginContent').appendChild(form);
}

function normalizeHeight() {
	/*var alphaHeight = document.getElementById('alpha').clientHeight;
	var betaHeight = document.getElementById('beta').clientHeight;
	if(alphaHeight > betaHeight)
		document.getElementById('beta').style.height = alphaHeight+"px";
	else
		document.getElementById('alpha').style.height = betaHeight+"px";

document.getElementById('beta').appendChild(document.getElementById('alpha').clientHeight);
document.getElementById('beta').appendChild(document.getElementById('beta').clientHeight);*/
}