$(document).ready(function() {

	$("#avatar_filename").change(function() {
		$("#upload_form").submit();
	});
	
	$("#id_username").focus(function () {
		var username = $(this).val();
		if (username == 'USERNAME'){
			$(this).val('');
			
		}
	});

	$("#id_username").blur(function () {
		var username = $(this).val();
		if (username == ''){
			$(this).val('USERNAME');
		}
	});
	
	$("#id_password_text").focus(function () {
		$(this).hide();
		$("#id_password").show();
		$("#id_password").focus();
	});

	$("#id_password").blur(function () {
		var password = $(this).val();
		if (password == ''){
			$(this).hide();
			$("#id_password_text").show();
		}
	});
	
	$(".login_form").submit(function() {
	
		$("#login_error").html('');
		$("#login_status").html("Please wait, logging in...");
		$.post("/login/",
			{ username: $("#id_username").val(), password: $("#id_password").val()},
			function (data){
			    if(data.result=="error"){
				$("#login_error").html(data.error);
			    } else {
				window.location.reload();
			    }
			    $("#login_status").html("");
			}, "json"
		);
		
		//$("#search_results").load("/thread/search/",data);
		return false;
	
	});
});

   
