$(document).ready(function(){
	
   //submission scripts
  $('.contactForm').submit( function(){
		//statements to validate the form	
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('cfEmail');
		if (!filter.test(email.value)) {
			$('.email-missing').show();
			$('#cfEmail').addClass('invalid');
		} else {$('.email-missing').hide(); $('#cfEmail').removeClass('invalid');}
		if (document.cform.cfName.value == "" || document.cform.cfName.value == "Name") {
			$('.name-missing').show(); $('.cfNameEB').addClass('invalid');
		} else {$('.name-missing').hide(); $('.cfNameEB').removeClass('invalid');}	
		if (document.cform.cfMessage.value == "") {
			$('.message-missing').show();$('#message').addClass('invalid');
		} else {$('.message-missing').hide(); $('#message').removeClass('invalid');}		
		if ((document.cform.cfName.value == "") || (!filter.test(email.value)) || (document.cform.cfMessage.value == "")){
			return false;
		} 
		
		if ((document.cform.cfName.value != "") && (filter.test(email.value)) && (document.cform.cfMessage.value != "")) {
			//hide the form
			$('.contactForm').hide();
		
			//show the loading bar
			$('.loaderCF').append($('.bar'));
			$('.bar').css({display:'block'});
		
			//send the ajax request
			$.post('formulare/bin/contact.php',{
				   			  name:$('#cfName').val(),
							  email:$('#cfEmail').val(),
							  phone:$('#cfTel').val(),
							  message:$('#cfMessage').val()},
		
			//return the data
			function(data){
			  //hide the graphic
			  $('.bar').css({display:'none'});
			  $('.loaderCF').append(data);
			});
					
			//stay on the page
			return false;
		} 
  });
  
});
