Converting PHP function to JavaScript function
<p>need to convert a PHP function to JavaScript fuction.I have tried it ,however it is not providing the same result as php code.Can anyone help please.</p>

<p><strong>PHP code</strong>  </p>

<pre><code>function check($id){  
    $id = trim($id);  
    if(!is_numeric($id)) return false;  
    if(strlen($id) !== 10) return false;  
    $type = substr ( $id, 0, 1 );  
    if($type != 2 &amp;&amp; $type != 1 ) return false;  

    for( $i = 0 ; $i&lt;10 ; $i++ ) {  

        if ( $i % 2 == 0){  
            $ZFOdd = str_pad ( ( substr($id, $i, 1) * 2 ), 2, "0", STR_PAD_LEFT );  
            $sum += substr ( $ZFOdd, 0, 1 ) + substr ( $ZFOdd, 1, 1 );  
        }else{  

            $sum += substr ( $id, $i, 1 );  
        }  
    }  
    //echo $sum;  
    return $sum%10 ? false : $type;     
}  
</code></pre>

<p><strong>JavaScript code</strong> </p>

<pre><code>var ID = XYZ; // xyz is a ten digit number;
var sum = 0;
var lenght = ID.length;
if ((lenght) != 10) {
    //validation message  
}
var type = ID.Substring(0, 1);
if ((type != 2) &amp;&amp; (type != 1)) {
    //validation message  
}

var count;
var odd;
for (count = 0; count &lt; 10; count++) {
    if (count % 2 == 0) {
        odd = ((ID.Substring(count, 1)) * 2).toString().PadLeft(2, "0");
        sum = sum + (odd.Substring(0, 1) + odd.Substring(1, 1));
    } else {
        sum = sum + ID.Substring(count, 1);
    }
}
if ((sum % 10) == 0) {
    //validation message  
}
</code></pre>

<p>Can anyone kindly review it for me please..there seems to have some problem with "sum"  ,its values are not correct as php code produces.</p>
