$(document).ready(function () {	

		$('#newsletterfooterok').live('click', function () {
			var newsletter = $('#newsletterfooter').val();
			
			var name='';
			if($('#name').val())
			{
				name = $('#name').val();
			}
			
			$.ajax({
				type: 'POST',
				url: baseDir + 'modules/biere/ajax/newsletter.php',
				async: true,
				cache: false,
				data: 'newsletter=' + newsletter + '&name=' + name,
				dataType : "json",
				beforeSend: function () {					
					$('#newsletterfooterok').parent().next('span').remove();
				},
				success: function(jsonData) {
					if (jsonData.success == 'true' || jsonData.success == true) {
						$('#newsletterfooter').val('');
						$('#name').val('');
						
						if (jsonData.messages) {
							$('#newsletterfooterok').parent().after('<span class="msgtext">' + jsonData.messages[0] + '</span>');
							
								setTimeout('closepopup()',2000);
							
						}
					}
					
					if (jsonData.success == 'false' || jsonData.success == false) {
						if (jsonData.errors) {
							$('#newsletterfooterok').parent().after('<span class="msgtext">' + jsonData.errors[0] + '</span>');
						}
					}
				}
				
			});
		});
});


function closepopup()
{
	$("#closepop").trigger('click');	
}

