function bpLoginSuccess(memberid, email, username, byline) {
	window.location.reload(true);
}

function bpCreateSuccess() {
	// $('#register_popup .register_proper').hide();
	// $('#register_popup .register_finish').show();
	$("#register_popup").hide();
	alert("Click on the link in the email we just sent you to activate your account.");
}

function bpLoginError() {
	document.getElementById('loginError').innerHTML = 'Invalid Login. Try Again.';
	document.getElementById('key').value = '';
	return false;
}

function bpUsernameInUse() {
	alert('That username is already in use; try another name.');
	return false;
}

function bpInvalidEmail() {
	alert("Invalid email address.");
	return false;
}

function bpInvalidPassword() {
	alert("Invalid Password.");
	return false;
}

function bpAccountExists() {
	alert("An account already exists for this email address.");
	return false;
}

function bpRecoverSuccess() {
	alert("Your password has been sent to the email address you entered.");
}

$(document).ready(function () {
	$("#jSignIn").click(function (e) {
		e.preventDefault();
		
		var pos = $(this).position();
		var height = $(this).height();

		$("#register_popup").hide();
		$("#forgot_popup").hide();
		$("#login_popup").show();
	});
	
	$("#login_submit").click(function (e) {
		e.preventDefault();
		
		var username = $("#login-un").val();
		var password = $("#login-pw").val();
		
		$.post("/bp_access/login/", [ {"name": "un", "value": username}, {"name": "key", "value": password } ], function (data) {
		}, "script");
	});

	$(".jSignOut").click(function (e) {
		e.preventDefault();
		
		$(this).html("Signing out...");
		
		$.get("?signout=true", [ ], function (data) {
			window.location.reload(true);
		});
	});

	$("#login_cancel").click(function (e) {
		e.preventDefault();

		$("#login_popup").hide();
	});
	
	$("#forgot_submit").click(function (e) {
		e.preventDefault();

		var email = $("#recoverEmail").val();
		
		$.post("/bp_access/recover/", [ {"name": "email", "value": email} ], function (data) {
		}, "script");
	});

	$("#jRegister").click(function (e) {
		e.preventDefault();
		
		var pos = $(this).position();
		var height = $(this).height();

		$("#login_popup").hide();
		$("#forgot_popup").hide();
		$("#register_popup").show();
	});

	$("#register_submit").click(function (e) {
		e.preventDefault();

		var email = $("#emailaddr").val();
		var username = $("#newusername").val();
		var password = $("#newkey").val();

		$.post("/bp_access/create/", [ {"name": "email", "value": email },  {"name": "un", "value": username }, {"name": "key", "value": password } ], function (data) {
		}, "script");
	});

	$("#register_cancel").click(function (e) {
		e.preventDefault();

		$("#register_popup").hide();
	});
	
	$("#forgot_link").click(function(e) { 
		e.preventDefault(); 
		$("#login_popup").hide();
		$("#register_popup").hide();
		$("#forgot_popup").show();
	});
});