function submit_d3form(which) {
	which.form.submitted.value = 'yes';
	which.form.submit();
}

function ajax_submit(which){
	//get the form id
	var fname = which.form.name;
	
	//set submitted to yes
	$("form[name='"+fname+"']").find("input[name='submitted']").val('yes');
	
	//serialize the data
	var serialized = $("form[name='"+fname+"']").serialize();
	
	//add the post mode
	serialized += '&post_mode=ajax';
	
	//prepend a div
	if($("#post_ajax_message").length < 1){
		$("form[name='"+fname+"']").before('<div id="post_ajax_message"></div>');
	}
	
	//show the loader
	$("#post_ajax_message").html('<img src="/app/modules/d3forms/images/ajax-loader.gif" />');
	
	//post the data and get the result
	$.ajax({
		   type:"POST",
		   url:'/ajax-post',
		   data: serialized,
		   dataType:'json',
		   success:function(data){
			   if(data.error == 'true'){
					//add the message to the div
					$("#post_ajax_message").html(data.message);
			   } else {
				   $("form[name='"+fname+"']").remove();
				   $("#post_ajax_message").html(data.message);
				   $("#post_ajax_message").after(data.form);
			   }
		   }
	});
}
