function doLogin(usernamefield, passwordfield, comingfrom) {
	var username = document.getElementById(usernamefield).value;
	var password = document.getElementById(passwordfield).value;
	var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
	var nucleuslogin;
	var requestedurl = "http://helpdesk.nucleus.be/ajax/order_login.php?user="+ username +"&pass="+ password;

	// Gebruiker meedelen dat de gebruikersnaam/wachtwoord wordt gecontroleerd
	document.getElementById('loginform_message').innerHTML = '<!-- EMPTY -->';
	document.getElementById("user_validate_loading").height = 18;
	document.getElementById("user_validate_loading").width = 18;

	request.open("GET", requestedurl);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			nucleuslogin = request.responseText;

			// Loading-image verstoppen
			document.getElementById("user_validate_loading").height = 0;
			document.getElementById("user_validate_loading").width = 0;

			if (nucleuslogin == "OK") {
				// Gebruiker succesvol ingelogd
				loadUserInfo();		// Login-scherm herladen

				// Mededeling verstoppen
				document.getElementById('loginform_message').innerHTML = '';

				// Login kader verkleinen
				hideLoginForm();
			} else {
				document.getElementById('loginform_message').innerHTML = 'Incorrect username or password';
			}
		}
	}
	request.send(null);
}

function doLogout(comingfrom) {
	var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
	var nucleususer;
	var requestedurl = "http://helpdesk.nucleus.be/ajax/order_logout.php";

	request.open("GET", requestedurl);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			loadUserInfo();		// Login-scherm herladen
		}
	}
	request.send(null);
}

function loadUserInfo() {
	var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
	var nucleususer;
	var requestedurl = "http://helpdesk.nucleus.be/ajax/order_userinfo.php";

	request.open("GET", requestedurl);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			nucleususer = request.responseText;

			document.getElementById('navv').innerHTML = nucleususer;
		}
	}
	request.send(null);
}

function hideLoginForm() {
	document.getElementById('loginform').style.display = 'none';
	document.getElementById('fade').style.display = 'none';
}

function showLoginForm() {
	// Zwarte overlay moet de volledige hoogte van de pagina hebben
	var xWithScroll = 0, yWithScroll = 0;
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}

  	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	var width;
	var height;
	if (myHeight > yWithScroll)
		height = myHeight;
	else
		height = yWithScroll;

	if (myWidth > xWithScroll)
		width = myWidth;
	else
		width = xWithScroll;

	document.getElementById('fade').style.height = height +'px';
	document.getElementById('fade').style.width = width +'px';

	document.getElementById('loginform').style.display = 'block';
	document.getElementById('fade').style.display = 'block';
}