// prepare the form when the DOM is ready 
$(document).ready(function(){
	
	$('#notice').fadeIn('slow');humanizedLite($('#notice')); 
	
});

$(document).ready(function() { 
	var options = { 
		clearForm: true,
		beforeSubmit: validate_login,
		success: function() {
			document.location = "index.php?inloggad";
		}
	}; 
	$('#login').ajaxForm(options);
});

function validate_login(formData, jqForm, options) { 
 
    var u	= $('input[name=txtUsername]').fieldValue(); 
    var p 	= $('input[name=txtPassword]').fieldValue(); 
	/*  
	if (u != 'rickard' || u != 'toni' || u != 'jonatan') {
		$('#notice').html('<span class="red">Mailphooner är tillfälligt stängt för underhåll, försök igen senare! vid frågor ring 019-611 75 00</span>');
		$('#notice').fadeIn('slow');
		humanizedLite($('#notice'));
		return false;
	} 
	*/
    if (!u[0]) { 
        $('#notice').html('<span class="red">Du m&aring;ste ange ett användarnamn.</span>');
		$('#notice').fadeIn('slow');
		humanizedLite($('#notice'));
		return false;
    }
	if (!p[0]) { 
        $('#notice').html('<span class="red">Du m&aring;ste ange ett lösenord.</span>');
		$('#notice').fadeIn('slow');
		humanizedLite($('#notice'));
		return false;
    }
    return true;
}

var humanizedLite = function (elem, speed) {
  setTimeout(function () {
	$(document).one('mousemove', function () {
	  elem.slideUp(speed ? speed : 1000, function () {
		elem.fadeOut();
	  });
	});
  }, 7000);
}
