$(document).ready(function(){

   //submission scripts
  $('.commentForm').submit( function(){
		

		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('email');
		if (!filter.test(email.value)) {
			$('#email').addClass('invalid');
		} else {$('#email').removeClass('invalid');}
		
		if (document.coform.user.value == "")
		{
			$('#user').addClass('invalid');
		}else{
			$('#user').removeClass('invalid');
		}
		if (document.coform.text.value == "")
		{
			$('#text').addClass('invalid');
		}else{
			$('#text').removeClass('invalid');
		}	
		if (document.coform.c_code.value == "")
		{
			$('#c_code').addClass('invalid');
		}else{
			$('#c_code').removeClass('invalid');
		}	
		
		

if ((document.coform.user.value == "") || (!filter.test(email.value)) || (document.coform.text.value == "") || (document.coform.c_code.value == "") ){
			return false;
		} 
	
	if ((document.coform.user.value != "") && (filter.test(email.value)) && (document.coform.text.value != "") && (document.coform.c_code.value != "")) {
			//hide the form
			$('.commentForm').hide();
		
			//show the loading bar
			$('.loader').append($('.bar'));
			$('.bar').css({display:'block'});
		
			//send the ajax request
			$.post('send_lesevorschlag.php',{
							  user:$('#user').val(),
							  email: $('#email').val(),
							  text:$('#text').val(),
							  c_code:$('#c_code').val()
							  },
		
			//return the data
			function(data){
			  //hide the graphic
			  $('.bar').css({display:'none'});
			  $('.loader').append(data);
			});
					
			//stay on the page
			return false;
		} 


  });
  
});
