function inbox_view(message_id) {
	window.location = PATH_BASE+'/messages/view/'+message_id+'/';
}

function inbox_delete(message_id) {

	//Do an AJAX deletion, then redirect to the inbox
	$.post(PATH_BASE+'/messages/delete/'+message_id+'/',
		null, function(data) {
			$('#status').html(data);
			setTimeout('window.location = PATH_BASE+"/messages/inbox";', 1500);
		});
}

function checkSignupForm(update) {
	//Handle default values
	if(typeof update == "undefined") {
		update = false;
	}
	
	//Load all of the form values
	fdata = $('#UserAddForm').formToArray();
	data = associate(fdata);
	
	//Validate the required fields
	if(!data['data[User][userName]']) {
		alert("Please enter a user name");
		return;
	}
	if(data['data[User][userName]'].match(" ") != null) {
		alert("User name cannot contain spaces");
		return;
	}
	if((data['data[User][userName]'].match("'") != null)
			|| (data['data[User][userName]'].match("`") != null)
			|| (data['data[User][userName]'].match("\"") != null)) {
		alert("User name cannot contain special charters ` or ' or \"");
		return;
	}
	if(update && !data['data[User][email2]']) {
		//Allow the user to not update their email address
	} else {
		if(!checkEmail(data['data[User][email]'])) {
			alert("Please enter a valid email address");
			return;
		}
		if(data['data[User][email]'] != data['data[User][email2]']) {
			alert("Your email address must match");
			return;
		}
	}
	if(update && !data['data[User][password2]']) {
		//Allow the user to not update their password
	} else {
		if((data['data[User][password]'] === undefined) || (data['data[User][password]'].length < 6)) {
			alert("Your password must be at least 6 characters long");
			return;
		}
		if(data['data[User][password]'] != data['data[User][password2]']) {
			alert("Your password must match");
			return;
		}
		if(!data['data[User][fName]']) {
		  alert("You must enter a first name");
		  return;
		}
	}

	//Sumit the request via AJAX
	if(!update) {
		GB_show("Registration Status", PATH_BASE+'/profile/create/', 
			200,300, doneSignup,
			fdata);
	} else {
		GB_show("Profile Change Status", PATH_BASE+'/profile/update/',
			200,300, doneUpdate,
			fdata);
	}
}

function doneSignup() {
	window.location = PATH_BASE+'/';
}

function doneUpdate() {
	window.location = PATH_BASE+'/account/';
}

function clearSignupForm() {
	$('#UserAddForm').clearForm();
}