function loginObject()
{

	this.checkKeyPress = function(e)
	{
		var charCode = e.keyCode;
		
		if(charCode == 13)
		{
			this.checkId();
		}
	}
	
	this.AJAX = function() 
	{
		try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
		try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
		try { return new XMLHttpRequest(); } catch(e) {}
		alert("XMLHttpRequest not supported");
		return null;
	}	
	
	
	this.checkId = function()
	{
		
		var httpreq = new this.AJAX();
		var loginid = document.getElementById('loginid').value;
				
		httpreq.open('POST', 'login.php', true);
		httpreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		httpreq.send('loginid='+loginid);
		
		httpreq.onreadystatechange = function()
		{
			if(httpreq.readyState == 4)
			{
				if(httpreq.status == 200)
				{
					if(httpreq.responseText == 'NOTVALID')
					{
						alert('Firmaet kunne ikke findes.');
					}
					else
					{
						us.loginid = loginid;
						us.confirmLogin(httpreq.responseText);
					}
				}
				else
					alert('Kunne ikke logge ind...');

			}
		}		
	}
	
	
		
	this.confirmLogin = function(navn)
	{
		var confirmBox = document.getElementById('login_alert');
		var lightbox = document.getElementById('black_overlay');
		var firmanavn = document.getElementById('firmanavn');
		lightbox.style.display='block';
		confirmBox.style.display='block';
		var divh = document.getElementById('container').offsetHeight;
		lightbox.style.height=divh+'px';
		firmanavn.innerHTML = navn;
	
	}
	
	this.annuller = function()
	{
		var confirmBox = document.getElementById('login_alert');
		var lightbox = document.getElementById('black_overlay');
		lightbox.style.display='none';
		confirmBox.style.display='none';
	}
	
	this.confirmMe = function()
	{
		window.location.href='validate.php?id='+this.loginid;
	}
	

};

var us = new loginObject();