$(document).ready(function(){
	$(document).pngFix();
	$("#login_form").submit(function()
{
        //remove all the class add the messagebox classes and start fading
        $("#msgbox").removeClass().addClass('messagebox').text('Ověřuji....').fadeIn(1000);

        if( $('#heslo').val() == '' ) 
          {
                $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
                {
                  //add message and change the class of the box and start fading
                  $(this).html('Prázdné heslo!').addClass('messageboxerror').fadeTo(900,1);
                });
				return false;
		}

        $.post("s/ajax_login.php",{ uzivatel:$('#uzivatel').val(),heslo:$('#heslo').val(),rand:Math.random() } ,function(data)
        {
          if(data=='no') //if correct login detail
          {
                $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
                {
                  //add message and change the class of the box and start fading
                  $(this).html('Neplatné heslo nebo jméno ...').addClass('messageboxerror').fadeTo(900,1);
                });
          }
          else 
          {
                $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
                {
                  //add message and change the class of the box and start fading
				  if(data=='new')
				  {
	                  $(this).html('Heslo založeno, přihlašuji .....').addClass('messageboxok').fadeTo(900,1,
	                  function()
	                  {
	                     //redirect to secure page
	                     document.location='index.php?firstuse=1';
	                  });
				  }
				  else
				  {
	                  $(this).html('Přihlašuji .....').addClass('messageboxok').fadeTo(900,1,
	                  function()
	                  {
	                     //redirect to secure page
	                     document.location='informace';
	                  });
				  }
                });
          }
       });
       return false;//not to post the  form physically
	});
	$("#uzivatel").focus();
});
