troubleshoot javascript
<p>I've been trying to solve what's wrong with this javascript code but I can't find my way around it.</p>

<p>This is the javascript function I got:</p>

<pre><code>    function picValidate(arrInputs) {
        var _validFileExtensions = [ ".jpg", ".jpeg", ".bmp", ".gif", ".png" ];
        if (typeof arrInputs == "undefined") {
            alert("sdfsdfsdfs");
            return true;
        } else {
            for ( var i = 0; i &lt; arrInputs.length; i++) {
                var oInput = arrInputs[i];
                if (oInput.type == "file") {
                    var sFileName = oInput.value;
                    if (sFileName.length &gt; 0) {
                        var blnValid = false;
                        for ( var j = 0; j &lt; _validFileExtensions.length; j++) {
                            var sCurExtension = _validFileExtensions[j];
                            if (sFileName.substr(
                                    sFileName.length - sCurExtension.length,
                                    sCurExtension.length).toLowerCase() == sCurExtension
                                    .toLowerCase()) {
                                blnValid = true;
                                break;
                            }
                        }

                        if (!blnValid) {
                            alert("Sorry, " + sFileName
                                    + " is invalid, allowed extensions are: "
                                    + _validFileExtensions.join(", "));
                            return false;
                        }
                    }
                }
            }
        }
    }
</code></pre>

<p>Now I need it to return true if the extension of the file is right and also I need to return true in case there was not picture selected because it's not mandatory to attach a picture.</p>

<p>Here is the complete javascript code which I'm using.</p>

<p>This is the main function that I used to call other javascript functions and in it I retrieved data from the form before posting it:</p>

<pre><code>    function formValidator(){

        var _validFileExtensions  = [".jpg", ".jpeg", ".bmp", ".gif", ".png"];
        var applicationStatus     = document.getElementById('applicationStatus');
        var prefix                = document.getElementById('prefix');
        var firstName             = document.getElementById('firstName');
        var middleName            = document.getElementById('middleName');
        var lastName              = document.getElementById('lastName');
        var dob                   = document.getElementById('dob');
        var email                 = document.getElementById('email');
        var secondaryEmail        = document.getElementById('secondaryEmail');
        var homeTelephoneNumber   = document.getElementById('homeTelephoneNumber');
        var mobileNumber          = document.getElementById('mobileNumber');
        var emrgCntctName         = document.getElementById('emrgCntctName');
        var emrgCntctRelationship =document.getElementById('emrgCntctRelationship');
        var emrgCntctPhoneNumber  = document.getElementById('emrgCntctPhoneNumber');
        var emrgCntctEmail        = document.getElementById('emrgCntctEmail');
</code></pre>

<p>This is the variable that I used to fetch all input data:   </p>

<pre><code>            var arrInputs             = document.getElementsByTagName("input");
</code></pre>

<p>Here I started using if statements and calling the functions in Javascript:</p>

<pre><code>        if(madeSelection(applicationStatus,"No \"Application status\" selected!")){
</code></pre>

<p>This is where i called the picture validation function and i expect it to return true if the extension is right or even if a picture is not selected!</p>

<pre><code>                 if(picValidate(arrInputs)){
                if(madeSelection(prefix, "No \"Prefix\" selected!")){
                    if(notEmpty(firstName, "No \"First name\" entered!")){
                        if(isAlphabet(firstName, "Only alphabetical characters are allowed in \"First name\" field!")){
                            if(isAlphabet(middleName, "Only alphabetical characters are allowed in \"Middle name\" field!")){
                                if(notEmpty(lastName, "No \"Last name\" entered!")){
                                    if(lastName(firstName, "Only alphabetical characters are allowed in \"Last name\" field!")){
                                        if(notEmpty(dob, "No \"Date of birth\" entered!")){
                                            if(notEmpty(email, "No \"Email\" entered for !"+firstName)){
                                                return true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return false;
    }


        function notEmpty(elem, helperMsg){
            if(elem.value.length == 0){
                alert(helperMsg);
                elem.focus(); // set the focus to this input
                return false;
            }
            return true;
        }

        function isNumeric(elem, helperMsg){
            var numericExpression = /^[0-9]+$/;
            if(elem.value.match(numericExpression)){
                return true;
            }
            else{
                alert(helperMsg);
                elem.focus();
                return false;
            }
        }

        function isAlphabet(elem, helperMsg){
            var alphaExp = /^[a-zA-Z]+$/;
            if(elem.value.match(alphaExp)){
                return true;
            }
            else{
                alert(helperMsg);
                elem.focus();
                return false;
            }
        }

        function madeSelection(elem, helperMsg){
            if(elem.value == "Please Choose"){
                alert(helperMsg);
                elem.focus();
                return false;
            }
            else{
                return true;
            }
        }

        function emailValidator(elem, helperMsg){
            var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
            if(elem.value.match(emailExp)){
                return true;
            }
            else{
                alert(helperMsg);
                elem.focus();
                return false;
            }
        }



        function picValidate(arrInputs) {
            var _validFileExtensions  = [".jpg", ".jpeg", ".bmp", ".gif", ".png"];
            if (typeof arrInputs=="undefined"){ alert("sdfsdfsdfs");
            return true;
            }
            else
            {
                for (var i = 0; i &lt; arrInputs.length; i++) {
                    var oInput = arrInputs[i];
                    if (oInput.type == "file") {
                        var sFileName = oInput.value;
                        if (sFileName.length &gt; 0) {
                            var blnValid = false;
                            for (var j = 0; j &lt; _validFileExtensions.length; j++) {
                                var sCurExtension = _validFileExtensions[j];
                                if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
                                    blnValid = true;
                                    break;
                                }
                            }

                            if (!blnValid) {
                                alert("Sorry, " + sFileName + " is invalid, allowed extensions are: " + _validFileExtensions.join(", "));
                                return false;
                            }
                        }
                    }
                }
            }
        }
&lt;/script&gt;
</code></pre>

<p>And this is the form I have all my input in:</p>

<pre><code>&lt;body&gt;
    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
    &lt;table width="287" align="center"&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;form name="studentForm" id="studentForm" enctype="multipart/form-data" action="addStudentProc.php" onsubmit="return formValidator();" method="POST"&gt;
          &lt;table width="279" border="1" class="borderer"&gt;
            &lt;tr&gt;
                &lt;th colspan="2"&gt;
                &lt;div align="center"&gt;Student Details         &lt;/div&gt;&lt;/th&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td width="110" nowrap="nowrap" scope="col"&gt;&lt;div align="right"&gt;Application status: &lt;font color="#FF0000"&gt;*&lt;/font&gt;&lt;/div&gt;&lt;/td&gt;
              &lt;td width="153" nowrap="nowrap"&gt;&lt;div align="left"&gt;
                &lt;select name="applicationStatus" id="applicationStatus"&gt;
                  &lt;option selected="selected" value="Please Choose"&gt;Please Choose&lt;/option&gt;
                  &lt;option value="Porspect"&gt;Porspect&lt;/option&gt;
                  &lt;option value="Converted"&gt;Converted&lt;/option&gt;
                  &lt;option value="Lost"&gt;Lost&lt;/option&gt;
                &lt;/select&gt;
                &lt;/div&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;
                &lt;label&gt;&lt;/label&gt;
                &lt;div align="right"&gt;Picture:&lt;/div&gt;&lt;/td&gt;
              &lt;td nowrap="nowrap"&gt;&lt;div align="left"&gt;&lt;input type="file" name="picture" class="BtnInTable"&gt;&lt;/div&gt;&lt;/td&gt;
            &lt;/tr&gt;
</code></pre>
