var selected_string = "";
function user_login() {
	$("#error").html('');
	var username = $("#username").val();
	var password = $("#password").val();
	$.post("login.php", { username: username, password: password }, function(data) { 
		var status = data.split("!");
		if(status[0] == "success") {
			$("#reply").html('Please wait while we load your messages....');
			load_messages();
		} else {
			$("#error").html('We could not authenticate you with the details you provided. Please try again.');
		}
	});	
}

function delete_selected() {
	$("#alert").html('Deleting your requested messages...this may take up to 2 minutes.');
	$(".selectionbox").each(
	 function() {
       var thisid = $(this).parent().attr('id');
       var thischecked = $(this).attr('checked');
       if(thischecked == true || thischecked == "checked") {
       		$.post("deletemessage.php", { message: thisid });
       }
     });
     load_messages();
}

function load_messages() {
	$.post("load_messages.php", function(data) { 
		$("#reply").html(data);
	});
}

function selectall() {
	$(".selectionbox").attr('checked', true);
}

function selectnone() {
	$(".selectionbox").attr('checked', false);
}
