// JavaScript Document
$(document).ready(function(){
	$("#categoryList li a").hover(function(){
		var currentId = $(this).attr('id');
		
		if(currentId != "currentCat"){
			$(this).addClass('currentCategory');
			}
		},
		function(){
			var currentId = $(this).attr('id');
		
			if(currentId != "currentCat"){
				$(this).removeClass('currentCategory');
			}
		});
	

	$("#username").focus();
	$("#errorSpan").hide();
	$("#username").keypress(function(e){
		if(e.keyCode == 13){
			$("#password").focus();
		}	
	});
	$("#password").keypress(function(e){
		if(e.keyCode == 13){
			checkLogin();
		}	
	});
	
	$("#loginBtn").click(checkLogin);
	
	
	
	
});


	
function checkLogin(){
		var formData = {
			username: $("#username").val(),
			password: $("#password").val()			
		};
		
		$.ajax({
			type: "POST",
			url: "checkLogin.php",
			data: formData,
			success: function(response){
				
				if(response == 'success'){
					
					$(location).attr('href',"index.php");
				}
				else {
					//password is wrong
					$("#errorSpan").css("display","block");
				}
			}
			});
	}
