<style> 
#jcdetstab { margin-left:10px; color:darkslategrey; border: 1px solid #a5a5a5; max-height:100px; max-width:600px; overflow-y:scroll;}
.pdamsjust {float:right; text-align: right; width:50px;}
</style>
<script type="text/javascript">

function suminvams() {                      // on selecting
    var tot=0;
    var tp = document.getElementsByName('topay');
    for(var i=0;i<tp.length;i++){ 
        var avwc = tp[i].value;
        var av1 = avwc.replace(/[+-][^0-9.]/g,'');   
        var aa = parseFloat(av1);
        if(aa>0) { tot += aa;}  
        else { tp[i].value = 0;}
     };   
     document.getElementById('am').value = tot;
 };
    

</script>
<?php
@session_start();
@include 'includes/database.php';
@include 'includes/funcs.php';
if (isset($_GET['cname'])){
	if (isset($_GET['i'])){ $invno = $_GET['i']; }
    $db=new MySQLDatabase();
    $db->open_connection();
	$cname = $_GET['cname'];		$e = intval($_GET['e']);
	if($e){ $qrystr = "SELECT jdate, jcno, imeino, regno, vehmod FROM jcards WHERE cname = '$cname' AND (invno=0 OR invno='$invno') ORDER BY jcno";  }
    else { $qrystr = "SELECT jdate, jcno, imeino, regno, vehmod FROM jcards WHERE cname = '$cname' AND invno=0 ORDER BY jcno";  }
    $res = mysqli_query($db->connection, $qrystr) or die (mysqli_error($db->connection) );
    echo "<table id='jcdetstab' cellspacing='4px' align='center'>";
    echo "<th>JC No.</th> <th>Date</th> <th>IMEI No.</th> <th>Model</th> <th>Reg. No.</th> <th>To Pay</th>";
	echo '<tr><td></td></tr>';
    while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC)){
        $sd=$row['jdate']; $nd=substr($sd,8,2)."-".substr($sd,5,2)."-".substr($sd,0,4);
        echo "<tr><td>".$row['jcno']."</td> <td>".$nd." <input type='hidden' id='rjcno' name='rjcno' value='".$row['jcno']."'/></td> <td align='left'>".$row['imeino']."</td> <td>".$row['vehmod']."</td> 
		<td align='center'>".$row['regno']."</td> <td><input class='pdamsjust' type='text' id='topay' name='topay' onchange='suminvams();' value='0'/></td> </tr>";
        }
    echo "</table>";
   // echo '</center></td></tr>';
    $db->close_connection(); 
}
else {echo'FAIL';}


?>

