$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgboxLogin").removeClass().addClass('messagebox').text('Bitte warten').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("ajax_login.php",{ user_name:$('#usernameLogin').val(),password:$('#passwortLogin').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='yes') //if correct login detail
		  {
		  	$("#msgboxLogin").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Du wirst eingeloggt.....').addClass('messageboxok').fadeTo(900,1,function()
			  { 
			  	 location.href = 'http://www.eventkiste.de'; 
				});
			});
		  }
		  else 
		  {
		  	$("#msgboxLogin").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Benutzername oder Passwort falsch!').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from 
	$("#password").blur(function()
	{
		$("#login_form").trigger('submit');
	});
});

