Can you use jQuery. This is a solution for the problem you described. If an image comes back as a 404 then it gets the default image applied
http://jsfiddle.net/gunderson/D3DSt/
var photo = document.createElement("img");
photo.setAttribute("id", "myPhoto");
$('body').append(photo);
$("#myPhoto").attr("src", 'alogo3w.png').error(function() {
$(this).attr("src", "https://www.google.com/images/srpr/logo3w.png");
})