
$(document).ready(function() {

 $('#send_message').click(function(e){
    e.preventDefault();
    var error=false;
    var email=$('#email').val();
    var comments=$('#comments').val();
    
    
    if($('#name1').val()=='') {
    var error=true;
      $('#name_error').fadeIn(500);
    }else {
      $('#name_error').fadeOut(500);
    }
   
   if(comments=='') {
      var error=true;
      $('#comments_error').fadeIn(500);
    }else {
      $('#comments_error').fadeOut(500);
    }
   
    if(email.length == 0 || email.indexOf('@') == '-1'){  
              var error = true;  
          $('#email_error').fadeIn(500);  
                   }else{  
            $('#email_error').fadeOut(500);  
         }
         
         
    if(error==false) {
       $('#send_message').attr({'disabled' : 'true', 'value' : 'Γίνεται αποστολή' });
    
       $.post("modules/contact/send_message.php", $("#contact_form").serialize(),function(result){
                    //and after the ajax request ends we check the text returned
                   
                    if(result == 'sent'){
                        //if the mail is sent remove the submit paragraph
                         $('#submit_button').remove();
                        //and show the mail success div with fadeIn
                        $('#mail_success').fadeIn(500);
                    }else{
                        //show the mail failed div
                        $('#mail_fail').fadeIn(500);
                        //reenable the submit button by removing attribute disabled and change the text back to Send The Message
                        $('#send_message').removeAttr('disabled').attr('value', 'Αποστολή');
                    }
                });
       
       
       
       
    }   
 });


});


