function validateMood(theForm) {
	var ANNOTATION_CHAR_LIMIT = 140;
	var msg = '';

	if ($RF(theForm, 'instant_mood_survey[symbolic_mood_score]') == null) {
		msg += 'Please rate your mood before submitting the form.\n';
	}

	if ($F(theForm['instant_mood_survey[annotation]']).length > ANNOTATION_CHAR_LIMIT) {
		msg += 'Reason can be no longer than ' + ANNOTATION_CHAR_LIMIT + ' characters.\n';
	}

	// Check for errors and handle accordingly
	if (msg != '') {
		alert(msg);
		return false;
	}

	return true;
}

function toggleEditTimeZone() {
	var timebox = $('timezone-box');
	if (timebox.visible()) {
		timebox.hide();
		$('mood-survey-box').show();
	}
	else {
		timebox.show();
		$('mood-survey-box').hide();
	}
}

function timeZoneUpdateSuccess(request) {
	toggleEditTimeZone();
	$('current-time').update(request.responseJSON.time);
	PLM.Notify.good(request.responseJSON.message);
}

function timeZoneUpdateFailure(request) {
	PLM.Notify.bad('An error occurred. Time was not updated.');
}

function updateChart(sourceEl, period, patientId) {
	new Ajax.Updater({success: 'history_and_chart'}, '/instant_mood/history', {
		method: 'get', 
		parameters: { 
			period: period, 
			id: patientId
		}, 
		onCreate: function() {
			showWait(sourceEl);
		}, 
		onComplete: function(transport) {
			hideWait();
		}
	});
}