function handleFlagSubmit(id) {

	var reason = document.getElementById('flag_reason_text').value;
	var post_body = 'babble_post_id=' + id + '&reason=' + reason;

	if (reason.length > 0) {
		divLinkName = 'flag_div';
		divFlagFormName = 'flag_form';

		var dd = document.getElementById(divLinkName);

		new Ajax.Request('/babble/process_ajax_flag_submit',{

			method:'post',
			postBody:post_body,
			asynchronous:true,

			onSuccess: function(t) {
				dd.innerHTML = "Flag Submitted";
				hideFlagForm(divFlagFormName);
			},

			onFailure: function(t) {
				dd.innerHTML = "Error!";
				hideFlagForm(divFlagFormName);
			}
		});
	} else {
		alert('You must submit a reason for flagging this post');
	}
}

function ShowFlagForm(d,id) {
	if(d.length < 1) { return; }

	//requires scriptaculous builder
	Effect.Appear('popup_overlay', { duration: 0.2, from: 0.0, to: 0.8 });

	ajaxUpdater(d,'/babble/get_ajax_flag_form?id=' + id);
	var dd = document.getElementById(d);
	AssignPositionCenter(dd,400,400);
	dd.style.display = "block";

	//requires scriptaculous builder
	$('popup_overlay').observe('click', (function() {
		 hideFlagForm(d);
	}).bind(this));
}

function hideFlagForm(d) {
	Effect.Fade(d, { duration: 0 });
	Effect.Fade('popup_overlay', { duration: 0.2 });
}


