
function getAjax()
{
	var xmlhttp; 
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp ;
}

function showLogin ()
{
	document.getElementById('login_name').value="";

	document.getElementById('login_screen').style.display="block";
	document.getElementById('login_name').focus();
}

function hideLogin ()
{
	document.getElementById('login_screen').style.display="none";
}

function loginRequest()
{
	var url="loginrequest.php";
	url +="?loginname=" ;
	url += document.getElementById('login_name').value ;
	var xmlhttp = getAjax();

	xmlhttp.open("GET",url,false);

	xmlhttp.send(null);

	return (xmlhttp.responseText=="YES");
}

function tryLogin ()
{
	//alert('tryLogin');

	document.getElementById('login_error_text').innerHTML="" ;

	if ( loginRequest() )
	{
		document.getElementById('is_admin').innerHTML="admin=1" ;
		document.getElementById('login_error_text').innerHTML="" ;
		hideLogin();
	}
	else
	{
		document.getElementById('login_error_text').innerHTML="Väärä salasana" ;
		document.getElementById('is_admin').innerHTML="admin=0" ;
	}

}

function isAdmin()
{
	return ($_SESSION['gb_admin'] == "YES") ;
}


