// Standard jQuery function to load the script when the page is loaded
$(document).ready(function()
{
	// Standard function from the jQuery Form plugin to submit the form and return 
	// the response page from poMMo to the processResponse custom function
	$('#footer-form').ajaxForm({
		success: processResponse
	});
});

// Custom function made to understand the submission page from the poMMo newsletter software.
// Returned HTML is parsed and different messages are shown depending on the original error message
function processResponse(responseText)
{
	// Getting the error message inside a "li" markup
	var message = $(responseText).find("li").text();
	
	switch (message)
	{
		case "Email address already exists. Duplicates are not allowed.":
			alert("Vous êtes déjà abonné à cette newsletter !");
			break;
		case "Invalid Email Address":
			alert("L'adresse e-mail que vous avez entrée est invalide. Soyez sûr de l'avoir écrite correctement.");
			break;
		default:
			if (message.search("Subscription request received") > -1)
			{
				$('#footer-form-container')
					.addClass("footer-form-container-message")
					.hide()
					.html("Votre demande d'abonnement a bien été prise en compte. Vous allez recevoir un e-mail de confirmation.")
					.fadeIn("slow");
			}
			else
			{
				alert(message);
			}
	}
}