var extractThumbnail = function(html) {
    return html;
}

var getThumbnail = function(url, success) {
    if(url) {
        $.get('/get_picture?' + $.param({'url': url}), function(data) {
            var image = new Image();
            image.src = 'data:image/png;base64,' + data;
            success(image);
        });
    }
    else {
        var image1 = new Image();
        image1.src = "./images/noimg.png";
        success(image1);
    }
}

var bookCover = function(target_id, url) {
    getThumbnail(url, function(result) {
        // console.log($(target_id));
        $(target_id).text('');
        // console.log(result);

        $(target_id).append(result);
    });
    $(target_id).text('please wait');
}

var getSimilarBooks = function(title, success) {
    $.get('/search?' + $.param({'query': title}), function(data) {
        success(data);
    });
}

var bookInfo = function(section, bookId, bookJSON) {
    var book = document.createElement("div");
    book.className = "book";

    var book_cover = document.createElement("div");
    book_cover.className = "book-cover";
    book_cover.id = bookId + "-cover";
    var img = document.createElement("img");
    img.src = "./images/noimg.png";
    book_cover.appendChild(img);
    bookCover('#'+ bookId + '-cover', bookJSON.url);
    book.appendChild(book_cover);

    var book_info = document.createElement("div");
    book_info.className = "book-info";
    book.appendChild(book_info);

    var book_attrs = document.createElement("ul");
    book_info.appendChild(book_attrs);
    
    // li
    var title = document.createElement("li");
    book_attrs.appendChild(title);

    var title_lable = document.createElement("span");
    title_lable.className = "lable";
    title_lable.appendChild(document.createTextNode("Загалвие:"));
    title.appendChild(title_lable);
    
    var title_name = document.createElement("span");
    title_name.className = "text";
    title_name.appendChild(document.createTextNode(bookJSON.title));
    title.appendChild(title_name);
    // li
    var author = document.createElement("li");
    book_attrs.appendChild(author);

    var author_lable = document.createElement("span");
    author_lable.className = "lable";
    author_lable.appendChild(document.createTextNode("Автор:"));
    author.appendChild(author_lable);
    
    var author_name = document.createElement("span");
    author_name.className = "text";
    author_name.appendChild(document.createTextNode(bookJSON.author));
    author.appendChild(author_name);
    // li
    var words = document.createElement("li");
    book_attrs.appendChild(words);

    var words_lable = document.createElement("span");
    words_lable.className = "words";
    words_lable.appendChild(document.createTextNode("Често срещани думи:"));
    words.appendChild(words_lable);
    
    var friquent_words = document.createElement("span");
    friquent_words.className = "text";
    friquent_words.appendChild(document.createTextNode(bookJSON.words));
    words.appendChild(friquent_words);

    $("." + section).append(book);
}

var booksInfo = function(JSON_data) {
    bookInfo("searched-book", "book", JSON_data.book);                   
    for(var index in JSON_data.recommended){
        var target_id = "recommended" + index;
        var bookJSON = JSON_data.recommended[index];
        bookInfo("suggested-books", target_id, bookJSON);
    }
}

$(document).ready(function() {
    $('#get-similar').click(function(e){
        e.preventDefault();
        var el = $(this);
        el.attr("disabled", "disabled");
        query =  $('#title').val();
        getSimilarBooks(query, function(data) {
            JSON_data = JSON.parse(data);
            booksInfo(JSON_data);
        });
    });
});

$(document).ready(function() {
    $('#title').keydown(function(e) {
        $(".searched-book").empty();
        $(".suggested-books").empty();
        $("#get-similar").removeAttr("disabled");
    })
});
@@ -93,24 +93,160 @@
  success) %7B%0A
+    var fail = function() %7B%0A        var image1 = new Image();%0A        image1.src = %22./images/noimg.png%22;%0A        success(image1);%0A    %7D%0A
     if(url) 
@@ -311,32 +311,105 @@
 unction(data) %7B%0A
+            if(!data) %7B%0A                fail();%0A            %7D else %7B%0A    
             var 
@@ -421,32 +421,36 @@
  = new Image();%0A
+    
             imag
@@ -494,32 +494,36 @@
 ta;%0A            
+    
 success(image);%0A
@@ -526,28 +526,24 @@
 e);%0A        
-%7D);%0A
     %7D%0A    el
@@ -544,114 +544,46 @@
     
-else %7B%0A        var image1 = new Image(
+    %7D
 );%0A    
+%7D%0A
     
-image1.src = %22./images/noimg.png%22;%0A        success(image1
+else %7B%0A        fail(
 );%0A 

Change the getting of book covers