URL to image transformation
<p>I use this function for transforming URLs to images on output.</p>

<pre><code>function InsertLink(T){
 var Out = '';
 var T1=T;
 var LinkR = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&amp;%@!\-\/]))?([^?#]*\.(?:jpg|jpeg|gif|png))/;
 var Pos=0;
 for(var N=0;(N=T1.search(LinkR))!==-1;){
    var S1 = T1.match(LinkR)[0];
    var S1L = S1.length;
    Out += T1.substr(0,N)+"&lt;a href='"+S1+"' target='_blank'&gt;&lt;img class='sml' src='"+S1+"' /&gt;&lt;/a&gt;&lt;br /&gt;";
    T1 = T1.substr(N+S1L);
    Pos=N+S1L;
 };
 Out+=T1;
 return Out;
}
</code></pre>

<p>But it working only for one URL in post body. If text contains more than one URL, all URLs attached to one image ("broken" image).</p>

<p>What's wrong? </p>
