$(document).ready(function(){
	
	$('#newsletterformular').submit(function(){
		
		action = $(this).attr('action');
		
		$(".ergebnis").slideUp(0);
		$("#tmailchild").remove();
		$("#taktionchild").remove();
		$("input,textarea").removeClass("error");

		$.post(action,$("#newsletterformular").serialize(),function(data){
			
			if   (data=='M-01') 
			     {
				 $('#newsletterformular').slideUp(600,function(){
				 $(".ergebnis").replaceWith("<div>Ihre E-Mail Adresse wurde erfolgreich in unser System übertragen. Vielen Dank!</div>"); $(".ergebnis").fadeIn(600);
				 $("#bmail").append("<strong>Hello</strong>");
				 });
				 }
			else if(data=='M-02')
				 {
				 $('#newsletterformular').slideUp(600,function(){
				 $(".ergebnis").replaceWith("<div>Ihre E-Mail Adresse wurde erfolgreich aus unserem System entfernt. Vielen Dank!</div>"); $(".ergebnis").fadeIn(600);
				 $("#bmail").append("<strong>Hello</strong>");
				 });
				 }
			else if(data=='F-00') 
				 {
				 $("#tmail").append('<p style="margin-top: 5px; margin-bottom: 10px; color: #f00" id="tmailchild">Bitte geben Sie eine gültige E-Mail Adresse an!</p>');
				 }
			else if(data=='F-01') 
				 {
				 $("#tmail").append('<p style="margin-top: 5px; margin-bottom: 10px; color: #f00" id="taktionchild">Bitte geben Sie an, ob Sie den Newsletter be- oder abbestellen möchten!</p>');
				 }
 
			$('#newsletterformular #submit').attr('disabled','');
		});

	return false;
	});
});

