Ways to improve performance of this javascript code?
<p>Don't be frightened, its a very basic code. 
Just wanted to check with you guys if you know any methods to make it faster ? (still learning)
It looks so ugly :)</p>

<p>Or, if you notice anything which could be made differently... Thanks!</p>

<pre><code>function pic_form_function(form, nr, val) {
    document.getElementById("image_to_delete").value=0;
    var re = /\..+$/;
    var extension = val.match(re);
    if (extension==".jpg" || extension==".jpeg" || extension==".gif" || extension==".png" || extension==".bmp") {
     if (nr==1){
      var ID_file1 = document.getElementById("pic_id_nr1").value;
      window.parent.document.getElementById("pic1_filename").value=ID_file1+extension;
      window.parent.document.getElementById("annonsera_nr_pics").value=1;
      window.parent.document.getElementById("iframe_upload_pic").style.height="180px";
      document.getElementById("pic_target").style.height="160px";
      document.getElementById("pic_target").style.display="block";
      document.getElementById("remove_pic").value=0;
      document.getElementById("extra_pic_checkbox").style.display="inline";
      document.getElementById("extra_pic_fnt").style.display="inline";
     }
     else if (nr==2){
      var ID_file2 = document.getElementById("pic_id_nr2").value;
      window.parent.document.getElementById("pic2_filename").value=ID_file2+extension; //Passing fileInputName to parent window...
      window.parent.document.getElementById("annonsera_nr_pics").value=2;
      document.getElementById("extrapic").value=2;
      document.getElementById("pic_file3").disabled=false;
     }
     else if (nr==3){
      var ID_file3 = document.getElementById("pic_id_nr3").value;
      window.parent.document.getElementById("annonsera_nr_pics").value=3;
      window.parent.document.getElementById("pic3_filename").value=ID_file3+extension;

      document.getElementById("extrapic").value=3;
      document.getElementById("pic_file4").disabled=false;
     }
     else if (nr==4){
      var ID_file4 = document.getElementById("pic_id_nr4").value;
      window.parent.document.getElementById("annonsera_nr_pics").value=4;
      window.parent.document.getElementById("pic4_filename").value=ID_file4+extension;

      document.getElementById("extrapic").value=4;
      document.getElementById("pic_file5").disabled=false;
     }
     else if (nr==5){
      var ID_file5 = document.getElementById("pic_id_nr5").value;
      window.parent.document.getElementById("annonsera_nr_pics").value=5;
      window.parent.document.getElementById("pic5_filename").value=ID_file5+extension;

      document.getElementById("extrapic").value=5;
     }
    }
    if (extension!=".jpg" &amp;&amp; extension!=".jpeg" &amp;&amp; extension!=".gif" &amp;&amp; extension!=".png" &amp;&amp; extension!=".bmp") { 
     window.parent.document.getElementById("annonsera_imagenotvalid_error").style.display="block";
    }
    else {
     window.parent.document.getElementById("annonsera_imagenotvalid_error").style.display="none";
     form.submit();
    }
}
</code></pre>
