function handleAjaxForms() {
	
	// Avis du public
	$('#ajaxVote form').submit(
		function() {
			// Détection du type de formulaire : login ou vote ?!
			var postURL = $(this).attr('action');
			var topSrcDir = $('#topSrcDir').attr('value');
			
			if (postURL.indexOf('/news/doCommenter.php') != -1) {
				// Submit AJAX du formulaire
				var id        = $('#ajaxVote :hidden[name=id]').attr('value');
				var cmt  	  = $('#ajaxVote :input[name=commentaire]').attr('value');

				// Soumet le formulaire en ajax !
				$.ajax(
					{	type:	"POST",
						url:	topSrcDir + "/news/doCommenter.php",
						data:	{
									id: id,
									commentaire: cmt,
									ajax: 1
								},
						beforeSend: function() {
							$('#ajaxVote').jqmHide();
						},
						success: function(data, textStatus) {
							if (data != 'OK') {
								$('#ajaxVote').jqmShow();
								alert("Erreur :\n" + data);
							} else {
								// Rechargement total de la page.
								alert("Votre commentaire a été pris en compte");
								document.location.reload();
							}
						}
					}
				);
			} else {
				var login  = $('#ajaxVote :input[name=login]').val();
				var passwd = $('#ajaxVote :input[name=password]').val();
				var rembr  = $('#ajaxVote :input[name=rememberme]:checked').length;
				
				// Connexion !
				$.ajax(
					{	type:	"POST",	// encodage UTF-8 forcé !
						url:	topSrcDir + "/mydvdfr/doLogin.php",
						data:	{
							login: login,
							password: passwd,
							ajax: 1,
							rememberme: rembr
						},
						beforeSend: function() {
							$('#ajaxVote form').attr("disabled","disabled");
						},
						success: function(data, textStatus) {
							if (data != 'OK') {
								$('#ajaxVote form').removeAttr("disabled");
								alert("Erreur :\n" + data);
							} else {
								// Utilisateur connecté : on affiche le formulaire de vote.
								$('#formUserLoginLink').hide();
								$('#formAvisPublic').show();
								$('#ajaxVote').jqmHide();
								$('#commentZone').focus();
							}
						}
					}
				);
			}
			
			return false;
		}
	);
}

$(document).ready(
	function() {
	
		$('#ajaxVote').jqm(
			{	trigger:	'#newsCommentLink'
			}
		).draggable({
			cursor	: 'move',
			handle	: '.jqTitle'
		});
		
		handleAjaxForms();
	}
);
