
$(function () {

	// Close-Button für die Nachrichten
	$('.notification .close').live('click',function () {
		$(this).parent().fadeOut(1000);
		return false;
	});
	
	newsletter_form();	
});

function newsletter_form(){ 
	var my_error;
	jQuery("#newsletter-form").bind("submit", function(event){
		my_error = false;
		jQuery("#newsletterEmail").each(function(i){
			var surrounding_element = jQuery(this);
			var value               = jQuery(this).attr("value");

			// check email
			surrounding_element.removeClass("error valid");
			baseclases = surrounding_element.attr("class");
			if(!value.match(/^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/)){
				surrounding_element.attr("class",baseclases).addClass("error");
				my_error = true;
			}else{
				//surrounding_element.attr("class",baseclases).addClass("valid");
			}

			if(my_error == false){
				jQuery("#newsletter").html('<p class="sending"><img id="sending" src="images/layout_template/ajax-loader.gif" style="margin-top:8px;"></p>');

				var $datastring = "ajax=true&newsletter_email="+$('#newsletterEmail').val();

				jQuery.ajax({
				   type: "POST",
				   url: "./newsletter_aj.php",
				   data: $datastring,
				   success: function(response){
						jQuery("#newsletter").html(response);
					}
				});
			}
		})
		return false;
	});
};


