$(document).ready(function() {
    
    //if submit button is clicked  
    $('#footer_send').click(function () {
        
        //Get the data from all the fields  
        var name = $('input[name=name]');  
        var email = $('input[name=email]');  
        var message = $('textarea[name=message]');
        var footer_question = $('input[name=footer_question]');
        
        //Simple validation to make sure user entered something  
        //If error found, add hightlight class to the text field  
        if (name.val()=='') {  
            name.addClass('footer_highlight');
            name.focus();
            return false;  
        } else name.removeClass('footer_highlight');  
          
        if (email.val()=='') {  
            email.addClass('footer_highlight');
            email.focus();
            return false;  
        } else email.removeClass('footer_highlight');
          
        if (message.val()=='' || message.val()=='Message:') {  
            message.addClass('footer_highlight');
            message.focus();
            return false;  
        } else message.removeClass('footer_highlight');
        
        if (footer_question.val()!='14') {  
            footer_question.addClass('footer_highlight');
            footer_question.focus();
            return false;  
        } else footer_question.removeClass('footer_highlight');
        
        //organize the data properly  
        var data = 'name=' + name.val() + '&email=' + email.val() + '&message='
        + encodeURIComponent(message.val()) + '&footer_question='  
        + footer_question.val();
        
        //disabled all the text fields  
        $('.text').attr('disabled','true');
        
        //show the loading sign  
        $('#footer_sending').fadeIn();
        
        //start the ajax  
        $.ajax({  
            //this is the php file that processes the data and sends mail  
            url: "php/quick_process.php",
            
            //GET method is used  
            type: "GET",
            
            //pass the data           
            data: data,
            
            //Do not cache the page  
            cache: false,
            
            //success  
            success: function (html) {
                
                //if process_quick.php returned 1/true (send mail success)  
                if (html==1) {
                    
                    //hide the sending icon  
                    $('#footer_sending').fadeOut();
                    
                    //show the success message
                    setTimeout(function(){$('#footer_sent').fadeIn();}, 1000);
                    
                    //if quick_process.php returned 0/false (send mail failed)   
                } else alert('Sorry, an unexpected error occurred.');
                
                //hide the loading sign  
                $('#footer_sending').fadeOut();
                
                //enable all the text fields  
                $('.text').attr('disabled','');
            }         
        });  
          
        //cancel the submit button default behaviours  
        return false;  
    });   
}); 
