$(document).ready(function(){
	// Submit form
	$(".mailinglist-sign-in-form").live("submit", function(){
		var form_action = $(this).attr("action");
		
		if (form_action.match(/\?/))
		{ // There are some parameters
			form_action += "&" + $(this).serialize();
		}
		else
		{ // There are any parameters
			form_action += "?" + $(this).serialize();
		}
		form_action += "&request_type=json"
		
		$.getJSON(form_action, function(data){
			if (data.result == "ok")
			{// The user was added to mailinglist
				window.location = data.redirect_url;
			}
			else
			{ // The error occurred	
				//$("#e_mail").after(data.messages);
				alert(data.messages);
			}
		});
		
		return false;
	});
});

