$(document).ready(function(){ 
	
	$('#loginform').click(function(){
		window.document.getElementById('loginhere').style.display="";
		return false;
	});
	
	$('#closelogin').click(function(){
		window.document.getElementById('loginhere').style.display="none";
		return false;
	});
	
	
	$('#loginbutton').click(function(){
		// alert($(this).attr("id")); 
		// src = $(this).attr("id");s
		user = $('#login_user').val();
		pass = $('#login_pass').val();
		var xhr = new XMLHttpRequest();
		xhr.open("GET", "http://www.stephensons.eu/includes/login.php?username="+user+"&password="+pass, true);
		xhr.onreadystatechange = function(){
			if ( xhr.readyState == 4 ){
				if ( xhr.status == 200 ){
					if (xhr.responseText == 1){
						alert("LOG-IN ERROR:\n\nYou have entered an incorrect username or password.");
						window.document.getElementById('loginhere').style.display="none";
					} else {
						// Reload the page on success
						window.document.getElementById('loginform').style.display="none";
						window.document.getElementById('loggedindiv').style.display="";
						window.document.getElementById('loginhere').style.display="none";
						location.reload();	
					}
					//document.body.innerHTML = "My Name is: " + xhr.responseText;
					return false;
	    		} else {
				    alert("LOG-IN ERROR:\n\nYou are unable to log-in at this time.");
		  		}
	  		}
		};
		xhr.send(null);
	}); 
}); 

