Maybe use something in javascript along the lines of:
function validateImage(url){
var img = new Image();
img.src = url;
return img.height>0;
}
which should return true if the image exists (i.e. height is greater than 0). Thismight fail if the image takes time to load, so test a lot. You might be able to mitigate this by running your validation function using the body onload event. And in this case, you should be able to avoid the image loading lag, because your browser would have cached the image and the height would be readily available. Hmm, so something like:
function replaceMissingImages(){
for (var i=0; i<document.images.length; i++){
img = new Image();
img.src = document.images[i].src;
if (img.height == 0)
document.images[i].src = 'mydefault.jpg';
}
}
Alternatively, you can do an XMLHTTPRequest to the image, to get the return code (I think you can use some kind of HTTP HEAD instruction to avoid actually requesting/retrieving the entire image). 404 would indicate a missing picture, 200 it's good, 304 it's not modified if you use the right headers, etc.. There are plenty of pages where they have these codes available..