$(function(){
// console.log('loaded.');
    $("#mail-form").submit(function(){

        // console.log('clicked!!!');
        // $("#loading").fadeIn(100).show();
        
        var from = $("#from").val();
        var to = $("#to").val();
        var image_id = $("#image-id").val();
        var email_image_width = $('#email-image-width').val();
        var email_image_height = $('#email-image-height').val();

        var data = "from=" + from + "&to=" + to + "&image_id=" + image_id + "&email_image_width=" + email_image_width + "&email_image_height=" + email_image_height;
        
        if(to == "") {
            $("#error-to").fadeIn(700).show();
        } 
        else if(from == ""){
            $("#error-from").fadeIn(700).show();
        }

        else {
            
            $.ajax({
                type: "POST",
                url: "/php/send_image.php",
                data: data,
                success: function(result) {
                    
                    // $("#loading").fadeOut(100).hide();
                    $('#message-sent').fadeIn(500).show();

					$("#error-from").fadeOut(700).hide();
		             $("#error-to").fadeOut(700).hide();
		  			$("#error-subject").fadeOut(700).hide();
					
				    $('#from').val("");
				    $('#to').val("");
                },
                error: function() {
                    $('#mail-form').fadeOut(300, function() {
                        alert('Sorry, there was an error.');
                    });
                }
                    

            });
            
        }

        return false;
        
    });    


}); 

