<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
include_once("opendb.php");
if(strlen($brcode)<=0)
{
    print "<script> alert('Session timed out'); parent.document.location='index.php'; </script>";
    return;
}
include_once('includes/top.php');
$jtype=$_REQUEST[jtype];
$jrqry=mysqli_query($db,"select max(tr_no) from journal2 where brcode='$brcode' and j_type='$jtype'");
    if(mysqli_num_rows($jrqry)<1)
    {
	$invno='000000000001'; 
    }
    else
    {
	$row=mysqli_fetch_array($jrqry);
        $inv=substr($row[0],-12)+1;
	$inv=substr('000000000000'.$inv,-12);
	if($inv==0)
	{
		$inv='000000000001'; 
	}
	$invno=$inv; 
    }
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>AMPLC</title>
<link type="text/css" href="jquery/jquery-ui.min.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="cal/jquery-ui1.js"></script>
<script type="text/javascript" src="jquery/jquery-1.7.min.js"></script>
<script type="text/javascript" src="jquery/jquery-ui.min.js"></script>
<script type="text/javascript" src="jquery/jquery.jqEasyCharCounter.min.js"></script>
<script type="text/javascript">
  $(function() {
    $( "#docdtvl" ).datepicker({ dateFormat: 'dd-mm-yy' });

  });
 
  </script>
<script type="text/javascript">

$(function(){
$(".cr").live("keydown.autocomplete",function(){
$cr = $(this);
$row = $cr.parent().parent();

var trntyp= document.invoice_form.jtype.value;



 

$(this).autocomplete({
		source: function(request, response ) {

		$.ajax({

                    
                 url: "searchjour_17032017.php?type="+trntyp,

			dataType: "json",
			data: "key="+$cr.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {


					return {
						label: '<span class="la-code">'+item.cr+' </span><span class="la-name">'+  item.cbal + '</span><span class="la-stok"> '+ item.stock +'</span><span class="la-rate">'+item.rate +'</span>',
						value: item.cr,
						name:item.cbal,
						tax:item.tax,
						stock:item.stock,
						rate:item.rate,
						reduct:item.reduct,


					}
				}));
			}
		});
	}

,
	minLength: 2,
	select: function( event, ui ) {
	$row.find('.cr').val(ui.item.cr);	
        $row.find('.cbal').val(ui.item.name);
	$row.find('.stok').val(ui.item.stock);
	$row.find('.unitprice').val(ui.item.rate);
	$row.find('.tax').val(ui.item.tax);
	$row.find('.itmvl').val(ui.item.reduct);
	$row.find('.dr_amt').focus();
	
	 }

	}).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append( item.label )
             .appendTo(ul);
     };
			
















});

});








function showHint()
{
	document.getElementById("popScroll2").innerHTML="<img src='images/loader.GIF' />";
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
    	document.getElementById("popScroll2").innerHTML=xmlhttp.responseText;
    	}
}
xmlhttp.open("GET","brec/view_brec1.php", true);
xmlhttp.send();
}

function viewinv()
{
 var str=document.getElementById('jvno').value;
document.getElementById("popScroll2").innerHTML="<img src='images/loader.GIF' />";


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("popScroll2").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","brec/view_brec.php?jvno="+str,true);
xmlhttp.send();
}

</script>




<style>
.la-code {
    display: inline-block;
    width: 200px;
}

#mask {
	display: none;
	background:url(images/bgimg1.gif) repeat;
	//background: #000; 
	position: fixed; left: 0; top: 0; 
	z-index: 10;
	width: 100%; height: 100%;
	opacity: 0.8;
	z-index: 999;
}

.login-popup{
		display:none;
	background:white;
	padding: 10px; 	
	border: 2px solid #ddd;
	float: left;
	font-size: 1.2em;
	position: fixed;
	top: 4%; left: 45%;
	z-index: 99999;
	box-shadow: 0px 0px 20px #999;
	-moz-box-shadow: 0px 0px 20px #999; /* Firefox */
    -webkit-box-shadow: 0px 0px 20px #999; /* Safari, Chrome */
	border-radius:3px 3px 3px 3px;
    -moz-border-radius: 3px; /* Firefox */
    -webkit-border-radius: 3px; /* Safari, Chrome */
}


img.btn_close {
	float: right; 
	margin: -28px -28px 0 0;
}

fieldset { 
	border:none; 
}

form.signin .textbox label { 
	display:block; 
	padding-bottom:7px; 
}

form.signin .textbox span { 
	display:block;
}

form.signin p, form.signin span { 
	color:white; 
	font-size:11px; 
	line-height:18px;
} 

form.signin .textbox input { 
	background:#666666; 
	border-bottom:1px solid #333;
	border-left:1px solid #000;
	border-right:1px solid #333;
	border-top:1px solid #000;
	color:white; 
	border-radius: 3px 3px 3px 3px;
	-moz-border-radius: 3px;
    -webkit-border-radius: 3px;
	font:13px Arial, Helvetica, sans-serif;
	padding:6px 6px 4px;
	width:200px;
}

form.signin input:-moz-placeholder { color:white; text-shadow:0 0 2px #000; }
form.signin input::-webkit-input-placeholder { color:hwite; text-shadow:0 0 2px #000;  }

.submit button { 
	background: -moz-linear-gradient(center top, #f3f3f3, #dddddd);
	background: -webkit-gradient(linear, left top, left bottom, from(#f3f3f3), to(#dddddd));
	background:  -o-linear-gradient(top, #f3f3f3, #dddddd);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#f3f3f3', EndColorStr='#dddddd');
	border-color:#000; 
	border-width:1px;
	border-radius:4px 4px 4px 4px;
	-moz-border-radius: 4px;
    -webkit-border-radius: 4px;
	color:#333;
	cursor:pointer;
	display:inline-block;
	padding:6px 6px 4px;
	margin-top:10px;
	font:12px; 
	width:100px;
}
#tbl2{
 margin:0px 20px 10px 20px;
 min-width:95%;
}
.button:hover { background:#ddd; }


.del{
      border: none;
     background: url("images/delete.png") no-repeat scroll 0 0 transparent;
}


.pop-up2 {position:absolute; top:10px; left:50px;padding-left:180px;}
.pop-up2:target {position:static; left:0;}

.popBox2 {
  background:#ffffff;

 
  width:75%;
  min-height:100%;



   z-index:1;

  border:1px solid #3a3a3a;


  -moz-border-radius:12px;
  border-radius:12px;
  -webkit-box-shadow:2px 2px 4px #3a3a3a;
  -moz-box-shadow:2px 2px 4px #3a3a3a;
  box-shadow:2px 2px 4px #3a3a3a;
  opacity:0;
 -webkit-transition: opacity 0.5s ease-in-out;
  -moz-transition: opacity 0.5s ease-in-out;
  -o-transition: opacity 0.5s ease-in-out;
  -ms-transition: opacity 0.5s ease-in-out;
  transition: opacity 0.5s ease-in-out;  
}
:target .popBox2 {position:fixed; opacity:1;}

.popBox2:hover {box-shadow:3px 3px 6px #5a5a5a;}



.lightbox {display:none; text-indent:0em; background:#000; opacity:0.0; width:100%; height:100%; position:fixed; top:0; left:0; bottom:0; right:0;}
:target .lightbox {display:block}

/* .popScroll {max-height:99%; overflow-y:scroll;} removed 17/07/2012 */
.popScroll2 {position:absolute; top:9%; left:3%; right:3%; bottom:9%; overflow-y:auto; *overflow-y:scroll; padding-right:0.5em}
</style>

<script>
$(document).ready(function() {
	$('a.login-window').click(function() {
		
		// Getting the variable's value from a link 
		var loginBox = $(this).attr('href');

		//Fade in the Popup and add close button
		$(loginBox).fadeIn(300);
		
		//Set the center alignment padding + border
		var popMargTop = ($(loginBox).height() + 24) / 2; 
		var popMargLeft = ($(loginBox).width() + 24) / 2; 
		
		$(loginBox).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		// Add the mask to body
		$('body').append('<div id="mask"></div>');
		$('#mask').fadeIn(300);
		
		return false;
	});
	
	// When clicking on the button close or the mask layer the popup closed
	$('a.close, #mask').live('click', function() { 
	  $('#mask , .login-popup').fadeOut(300 , function() {
		$('#mask').remove();  
	}); 
	return false;
	});
});


 $(document).ready(function(){
  $("#svbttn").click(function(){

$("#msgbox").html('<small>Loading...</small>');
      

    	// var name= $(this).attr('name');

    	 //$('#type_name').val(name);
   
  	 var values1 = $("#jforms").serialize();

  	  $.ajax({
   	   url: "svjournew.php",
    	  type: "POST",
   	  data:   values1,
     	  success: function(msg){

 

           	 if(parseInt(msg)!=0)    

          	  {

                $('#msgbox').html(msg);
           
		}
           

      	},
      error:function(){
          alert("failure");
          $("#msgbox").html('there is error while submit');
      }   
   	 }); 

	 }); 
	 }); 




$(document).bind('keydown', 'Alt+n',function (e){
      
    if(e.which==78 && e.altKey){
	 //alert (e.which);
        shortkey_tblopen();
        return false;
    } 
     if(e.which==83 && e.altKey){
	 
         $( "#svbttn" ).click();
        return false;
    } 
   if(e.which==82 && e.altKey){
	 
         window.location.reload(true);
        return false;
    } 
      
    
});



</script>







<script type="text/javascript">



  function shortkey_tblopen(){
               
               var rowCounts = document.getElementById('myTable').rows.length;
		 if(rowCounts<=1){
		          
			document.getElementById('insrowbttn').click(); 
               }		   					
 		 else
			document.getElementById('insrowbttn2').click(); 
 }





function handleEnter (field, event) {
               
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 



                if (keyCode == 38){
                    var row=field.parentNode.parentNode.rowIndex;
			 var col  =field.parentNode.cellIndex ;
			 
                     document.getElementById('myTable').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();
			
			 
              }

                  if (keyCode == 40){
                    var row=field.parentNode.parentNode.rowIndex;
			 var col  =field.parentNode.cellIndex ;
			 
                     document.getElementById('myTable').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();
			
			 
              }
                     if (keyCode == 37){


                    /* var row=field.parentNode.parentNode.rowIndex;
			 var col  =field.parentNode.cellIndex ;
			 
                     document.getElementById('myTable').rows[row].cells[col-1].getElementsByTagName("input")[0].focus();*/

                   var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i - 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
			
			 
              }
               
                   	 if (keyCode == 46){
			  var i=field.parentNode.parentNode.rowIndex;
			  
                       var r=confirm("Do you want to delete the row?");
			  if (r==true)
 				 {
 					//document.getElementById('myTable').deleteRow(i);
					delRow(field);
                                  document.getElementById('myTable').rows[i].cells[1].getElementsByTagName("input")[0].focus();
                                  
					//var nxt =document.getElementById('myTable').rows[i].cells[0].innerHTML;
					//alert(nxt);
  				 }
			  
        }
		else
		return true;
	}      



function counttot(r,val)
{
var i=r.parentNode.parentNode.rowIndex;
var str1=0;

   var tbl = document.getElementById('myTable');
   var id1=tbl.rows[i].cells[0].innerHTML;

if(isNaN(val))
  {
  alert('Enter Digit');
 document.getElementById("dr_amt"+id1).value=0;
  
  }
else
 {

       if(document.getElementById("dr_amt"+id1).value>0)
          {
            document.getElementById("cr_amt"+id1).value=0;
          }

           var l=0;
   	   var ups = document.getElementsByName('dr_amt[]'), sumnw = 0, l;   
    			for(l = ups.length; l--;)
				{
                                 
        			if(ups[l].value)
					{
            				sumnw += parseFloat(ups[l].value, 10);
					}
					
	 			}
                   
                   document.getElementById("dbtot").value= sumnw.toFixed(2);


       var k=0;
       var ups = document.getElementsByName('cr_amt[]'), sum = 0, k;   
       for(k = ups.length; k--;)
	 {
           if(ups[k].value)
		{
            	sum += parseFloat(ups[k].value, 10);
		}
					
	 }
         document.getElementById("crtot").value= sum.toFixed(2);

}
}
function countcrtot(r,val)
{
   var i=r.parentNode.parentNode.rowIndex;
   var str1=0;

   var tbl = document.getElementById('myTable');
   var id1=tbl.rows[i].cells[0].innerHTML;
   if(isNaN(val))
     {
       alert('Enter Digit');
       document.getElementById("cr_amt"+id1).value=0;
  
     }
   else
     {

        if(document.getElementById("cr_amt"+id1).value>0)
          {
            document.getElementById("dr_amt"+id1).value=0;
          } 


                        var k=0;
   			var ups = document.getElementsByName('cr_amt[]'), sum = 0, k;   
    			for(k = ups.length; k--;)
				{
        			if(ups[k].value)
					{
            				sum += parseFloat(ups[k].value, 10);
					}
					
	 			}
                   document.getElementById("crtot").value= sum.toFixed(2);
                   var l=0;
   			var ups = document.getElementsByName('dr_amt[]'), sumnw = 0, l;   
    			for(l = ups.length; l--;)
				{
        			if(ups[l].value)
					{
            				sumnw += parseFloat(ups[l].value, 10);
					}
					
	 			}
                   document.getElementById("dbtot").value= sumnw.toFixed(2);

   }




       
}



function closingbal(str, r, id2, tabl)
{


   var i=r.parentNode.parentNode.rowIndex;
   var tbl = document.getElementById(tabl);
   var id1=tbl.rows[i].cells[0].innerHTML;



 if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("clb").innerHTML=xmlhttp.responseText;
    var clbal= document.getElementById("clbal").value;
    document.getElementById(id2+id1).value=clbal;
    }
  }


xmlhttp.open("GET","getclbal_crec.php?led="+str+"&& id="+id1,true);
xmlhttp.send();
}



</script>




<script type="text/javascript">
var tq=0,tq2=0;
var cur=1;
var cnt=1;
var vv;
var drs=[];
var dr=[];
var cr=[];
var dr_amt=[];
var dr_narr=[];
var dragain=[];
var dragval=[];
function setval(a)
{
 vv=a.name;
}
function insRow(event,i1,id2)
{


var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

var cur_val=i1.value;


switch(keyCode)
{
case 38:
   var row=i1.parentNode.parentNode.rowIndex;
   var col  =i1.parentNode.cellIndex ;
			 
   document.getElementById('myTable').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();
  break;
case 40:
  var row=field.parentNode.parentNode.rowIndex;
  var col  =field.parentNode.cellIndex ;
			 
   document.getElementById('myTable').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();
			
  break;
case 37:
  var row=field.parentNode.parentNode.rowIndex;
  var col  =field.parentNode.cellIndex ;
			 
  document.getElementById('myTable').rows[row].cells[col-1].getElementsByTagName("input")[0].focus();
	
}

if(id2!="insrowbttn")
  {
   var i2=i1.parentNode.parentNode.rowIndex;
   var i3=parseFloat(i2)+parseFloat(1);
   var rowCounts = document.getElementById('myTable').rows.length;
   var rowCounts1= rowCounts-1;
   
  
  }
else
  {
   var i2=0;
   var rowCounts1=0;
  }
//alert(cur);



if(((keyCode == 13) && (i2==rowCounts1))||(cnt==1))
 {
var rowCount = document.getElementById('myTable').rows.length;
var rowcount1=parseFloat(rowCount)+parseFloat(1);
//alert(rowCount);
var x=document.getElementById('myTable').insertRow(rowCount);


if(rowCount>=1)
 {
  document.getElementById('insrowbttn').type='hidden';
 }

var k;
var a=x.insertCell(0);
var y=x.insertCell(1);
var z=x.insertCell(2);
var nq=x.insertCell(3);	
var z1=x.insertCell(4);	
var ag=x.insertCell(5);
var prftdr=x.insertCell(6);


var op=x.insertCell(7);
var dd=x.insertCell(8);
a.innerHTML=cur;
y.innerHTML="<input type=text name='cr[]' id=cr"+cur+" class='cr' size=35 autocomplete='off' list='htmlListTags' onkeypress='handleEnter(this, event)'>";

z.innerHTML="<input type=text name=dr_amt[] id=dr_amt"+cur+" class='dr_amt' value='0' size=10 onKeydown='return handleEnter(this, event)' onchange='counttot(this,this.value)'>";
nq.innerHTML="<input type=text name=cr_amt[] id=cr_amt"+cur+" class='cr_amt' value='0' size=10 onKeydown='return handleEnter(this, event)' onchange='countcrtot(this,this.value)'>";

z1.innerHTML="<input type=text id='dr_narr"+cur+"' name=dr_narr[] cr_amt size=30 onKeydown='return handleEnter(this, event)'>"

ag.innerHTML="<select name='dragain[]' id='dragain"+cur+"' onKeydown='return handleEnter(this, event)'><option>OFNO</option><option>MSNO</option><option> ON Acc </option> <option>CHEQ</option></select>";
<?
$pmpqr="select comp_name from company_master";
$pmprs=mysqli_query($db,$pmpqr);
?>
var vm="";
vm= "<select name='prftcntdr[]' id=prftcntdr"+cur2+" onKeydown='return handleEnter(this, event)'> <option value='select'>--select--</option>";
<? while($pmrow=mysqli_fetch_array($pmprs))
{
?>
vm=vm+'<option value="<? echo $pmrow[0] ?>"><? echo $pmrow[0] ?></option>';
<?
}
?>
prftdr.innerHTML=vm+"</select> ";
op.innerHTML="<input type=text readonly id='cbal"+cur2+"' class='cbal'  onKeyup='insRow(event,this,this.id)' >";
dd.innerHTML="<input type='button'  onClick='delRow(this)' class='del'>";
document.getElementById("cr"+cur).focus();
  cur++; 

cnt++;

var table = document.getElementById("myTable");
var row = table.rows[index];
console.log(secondRow.id);
}

if(keyCode == 13)
{
var tbl = document.getElementById('myTable');
   var id3=tbl.rows[i3].cells[0].innerHTML;
document.getElementById("cr"+id3).focus();
} 

}
function delRow(r)
{
 var i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable').deleteRow(i);

  var rowCount = document.getElementById('myTable').rows.length;
   var tbl = document.getElementById('myTable');  

  if(rowCount<=1)
 {
  document.getElementById('insrowbttn').type='button';
 }



var str1=0;

 
var n=document.getElementById('myTable').rows.length-1;
var m;
for(m=1;m<=n;m++)	
    {
     var tbl1 = document.getElementById('myTable');
     var id2=tbl1.rows[m].cells[0].innerHTML;
    var itemval = document.getElementById("dr_amt"+id2).value;
    
         str1=parseFloat(str1)+parseFloat(itemval); 
        
     }
  document.getElementById("dbtot").value= str1.toFixed(2);


cnt--;

}

//************************************
function calcdr()
{
var tq=0;
for(i=1;i<cur;i++)
{
 var ele='cr'+i; //alert(ele);
 if(document.getElementById(ele).value>0)
  {
   amount=document.getElementById(ele).value;
   tq+=parseFloat(amount);
  }
 }
document.f1.tdamt.value=tq;
}

function calccr()
{
var tq2=0;
for(i=1;i<cur2;i++)
{
 var ele2='cr'+i; //alert(ele);
 if(document.getElementById(ele2).value>0)
  {
   amount=document.getElementById(ele2).value;
   tq2+=parseFloat(amount);
  }
 }
document.f1.tcamt.value=tq2;
}




function handleEnter2 (field, event) {
               
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 


                if (keyCode == 38){
                    var row=field.parentNode.parentNode.rowIndex;
			 var col  =field.parentNode.cellIndex ;
			 
                     document.getElementById('myTable2').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();
			
			 
              }

                  if (keyCode == 40){
                    var row=field.parentNode.parentNode.rowIndex;
			 var col  =field.parentNode.cellIndex ;
			 
                     document.getElementById('myTable2').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();
			
			 
              }
                     if (keyCode == 37){


                    /* var row=field.parentNode.parentNode.rowIndex;
			 var col  =field.parentNode.cellIndex ;
			 
                     document.getElementById('myTable2').rows[row].cells[col-1].getElementsByTagName("input")[0].focus();*/

                   var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i - 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
			
			 
              }
                     	  if (keyCode == 46){
			  var i=field.parentNode.parentNode.rowIndex;
			  
                       var r=confirm("Do you want to delete the row?");
			  if (r==true)
 				 {
 					//document.getElementById('myTable2').deleteRow(i);
					delRow2(field);
                                  document.getElementById('myTable2').rows[i].cells[1].getElementsByTagName("input")[0].focus();
                                  
					//var nxt =document.getElementById('myTable2').rows[i].cells[0].innerHTML;
					//alert(nxt);
  				 }
			   
                       }
                   
		else
		return true;
	}    



//-------*888888888888888888888888*********************8888
var cur2=1;
var cnt2=1;
var cr=[];
var cr_amt=[];
var cr_narr=[];
var cragain=[];
var cragval=[];;
function insRow2(event,i1,id2)
{


var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

var cur_val=i1.value;


switch(keyCode)
{
case 38:
   var row=i1.parentNode.parentNode.rowIndex;
   var col  =i1.parentNode.cellIndex ;
			 
   document.getElementById('myTable2').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();
  break;
case 40:
  var row=field.parentNode.parentNode.rowIndex;
  var col  =field.parentNode.cellIndex ;
			 
   document.getElementById('myTable2').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();
			
  break;
case 37:
  var row=field.parentNode.parentNode.rowIndex;
  var col  =field.parentNode.cellIndex ;
			 
  document.getElementById('myTable2').rows[row].cells[col-1].getElementsByTagName("input")[0].focus();
	
}



if(id2!="insrowbttn2")
  {
   var i2=i1.parentNode.parentNode.rowIndex;
   var i3=parseFloat(i2)+parseFloat(1);
   var rowCounts = document.getElementById('myTable2').rows.length;
   var rowCounts1= rowCounts-1;
   
  
  }
else
  {
   var i2=0;
   var rowCounts1=0;
  }
//alert(cur2);



		if(((keyCode == 13) && (i2==rowCounts1))||(cnt2==1))
 {
var rowCount = document.getElementById('myTable2').rows.length;
var rowcount1=parseFloat(rowCount)+parseFloat(1);
//alert(rowCount);
var x=document.getElementById('myTable2').insertRow(rowCount);


if(rowCount>=1)
 {
  document.getElementById('insrowbttn2').type='hidden';
 }
var k;
var a=x.insertCell(0);
var y=x.insertCell(1);
var z=x.insertCell(2);	
var z1=x.insertCell(3);
var crag=x.insertCell(4);
var prftcr=x.insertCell(5);
var cragval1=x.insertCell(6);
var op=x.insertCell(7);
var dd=x.insertCell(8);
a.innerHTML=cur2;
y.innerHTML="<input type=text name='cr[]' id=cr"+cur2+"  size=35 onkeyup='xx1(this.id,event,this)'  autocomplete='off' list='htmlListTags'  >";

z.innerHTML="<input type=text name=cr_amt[] id=cr_amt"+cur2+" size=10 value='0' onchange='countcrtot(this,this.value)' onKeydown='return handleEnter2(this, event)'>"
z1.innerHTML="<input type=text id='cr_narr"+cur2+"' name=cr_narr[] size=30 onKeydown='return handleEnter2(this, event)'>"

crag.innerHTML="<select name='cragain[]' id='cragain"+cur2+"' onChange=getda(this,cur2,cr) onKeydown='return handleEnter2(this, event)'><option>OFNO</option><option>MSNO</option><option> ON Acc </option> <option>CHEQ</option></select>";



<?
$pmpqr="select comp_name from company_master";
$pmprs=mysqli_query($db,$pmpqr);
?>
var vn="";
vn= "<select name='prftcntcr[]' id=prftcntcr"+cur2+" onKeydown='return handleEnter(this, event)'> <option value='select'>--select--</option>";
<? while($pmrow=mysqli_fetch_array($pmprs))
{
?>
vn=vn+'<option value="<? echo $pmrow[0] ?>"><? echo $pmrow[0] ?></option>';
<?
}
?>
prftcr.innerHTML=vn+"</select> ";




cragval1.innerHTML="<input type=text id='cragval"+cur2+"' name='cragval[]'  onKeydown='return handleEnter2(this, event)'  >";
op.innerHTML="<input type=text readonly id='crcbal"+cur2+"'  onKeyup='insRow2(event,this,this.id)' >";
dd.innerHTML="<input type='button'  onClick='delRow2(this)' class='del'>";
document.getElementById("cr"+cur2).focus();
  cur2++; 

cnt2++;



var table = document.getElementById("myTable2");
var row = table.rows[index];
console.log(secondRow.id);
}

if(keyCode == 13)
{
var tbl = document.getElementById('myTable2');
   var id3=tbl.rows[i3].cells[0].innerHTML;
document.getElementById("cr"+id3).focus();
} 
}
function delRow2(r)
{
 var i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable2').deleteRow(i);

  var rowCount = document.getElementById('myTable2').rows.length;
   var tbl = document.getElementById('myTable2');

  if(rowCount<=1)
 {
  document.getElementById('insrowbttn2').type='button';
 }


var str1=0;
var n=document.getElementById('myTable2').rows.length-1;
var m;
for(m=1;m<=n;m++)	
    {
     var tbl1 = document.getElementById('myTable2');
     var id2=tbl1.rows[m].cells[0].innerHTML;
    var itemval = document.getElementById("cr_amt"+id2).value;
    
         str1=parseFloat(str1)+parseFloat(itemval); 
        
     }
  document.getElementById("crtot").value= str1.toFixed(2);
cnt2--;
}

function valid()
{
 calccr();
 calcdr();
 if(document.f1.tdamt.value==document.f1.tcamt.value)
   return true;
 else
   {alert('Dr, Cr Amount mis-match'); return false;}
}
</script>
<script>


function newcustomer()
{
 document.getElementById("to_new_customerTD").innerHTML=" <input id='to_new_customer' name='cus' style='outline:none;border:0px solid white;width:287px; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:silver;' name='to_new_customer' onkeyup='sanitizeNames(this);' onfocus='field_onfocus(this,'Customer name');' onblur='field_onblur(this,'Customer name');' value='Customer name' type='text'>";
 document.getElementById("to_new_registerTD").innerHTML=" <input id='to_new_register' name='reg' style='outline:none;border:0px solid white;width:287px; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:silver;' name='to_new_register' onkeyup='sanitizeNames(this);' onfocus='field_onfocus(this,'Register number');' onblur='field_onblur(this,'Register number');' value='Register number' type='text'>"
 document.getElementById("show").innerHTML="<a href='#' style='text-decoration:none; color:black;' onclick='showcustomer()'>Click Here to Show Existing Customer</a>";
}


</script>



<style>
.cont
	{
	background-color:#3b5998;

	//background:url(images/bg-inner.jpg) #e9e0c3 repeat-x;
  	width: 100%;position: absolute ;
	height:99%;
    	/* Optional - just for DIV)*/
    	//border: solid 1px #000000;
	-moz-box-shadow: 0px 5px 5px #888;
	-webkit-box-shadow: 0px 5px 5px #888;
	box-shadow: 0px 5px 10px #888;
    }
.tble1 input {
background-color:transparent;
border: 0px solid;
height:20px;
//width:160px;
color:black;
}
.tble1
{
border-collapse:collapse;
border:1px solid silver;

}	
.tble1 td
{
//border-collapse:collapse;
border:1px solid silver;

}



</style>
<style>








		
.darkClass
{
    background-color: white;
    filter:alpha(opacity=50); /* IE */
    opacity: 0.5; /* Safari, Opera */
    -moz-opacity:0.50; /* FireFox */
    z-index: 20;
    height: 1000px;
    width: 100%;
    background-repeat:no-repeat;
    background-position:center;
    position:absolute;
    top: 400px;
    left: 0px;
}		
		
		

		










		</style>

		

   	   <!--[if IE]>

   	   <style>

		.inputInvoiceDataItem			{ border:0px solid white; padding:5px; padding-top:4px;padding-left:1px; width:86px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;}

		.divWithCustomizationLinkIMG	{ margin:0px;padding:0px;padding-top:2px;}		    



		</style>

 	   <![endif]-->

 	   

  	   	<!--[if lte IE 7]>

   	   	<style>

       	.send_button				{ margin-top:3px;}	  

		.inputInvoiceDataItem		{ outline:none;border:0px solid white; padding:5px; margin-top:5px;padding-left:1px; width:80px; margin-right:6px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;}

		.divWithCustomizationLinkTable   { width:100%;margin:0px; margin-top:10px; padding:0px;background-color:#FFFADC;border-top:2px solid #FCF5CD; border-bottom:2px solid #FCF5CD;padding:3px;padding-left:10px; }		

		.divWithCustomizationLinkIMG	{ margin:0px;padding:0px;padding-top:4px;}		    

	   	</style>

	   	<![endif]-->

 	   
				<style type="text/css">
			iframe {
				display:none;
			}
		</style>

<link type="text/css" href="includes/style1.css" rel="stylesheet" />
      <link type="text/css" href="css/form1.css" rel="stylesheet" />

<style>


        



        .left-light-gray-border{
            position:relative;
            border-left:solid 1px #ccc;
            top: 0px;
        }

        .right-light-gray-border{
            position:relative;
            border-right:solid 1px #ccc;
            top: 0px;
        }

        .right-light-none-border{
            position:relative;
            border-right:solid 1px transparent;
            top: 0px;
        }

        .left-light-none-border{
            position:relative;
            border-left:solid 1px transparent;
            top: 0px;
        }



    </style>            
            
       <br>


        	<table id="main_table_wrapper" style=" top: 0px; width: 800px; margin: 0px auto ! important; text-align: left;" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td>
        
        <!-- TB 2 -->
        <link rel="stylesheet" href="tabjs/thickbox.css" type="text/css" media="screen">
        <script type="text/javascript" src="tabjs/thickbox-compressed.js"></script>

        <table style="width:100%;margin:0px;padding:0px;padding-bottom:10px;" cellpadding="0" cellspacing="0">
        <tbody><tr>
        <td colspan="100" style="text-align:left;" width="100%">

        <!-- TB 3 -->

        <table style="padding:0px; margin:0px;text-align:left;" cellpadding="0" cellspacing="0" width="100%">

        <tbody><tr>       
           
           <!-- </form>-->         


        <td style="width:200px; padding-top:0px;margin:0px;text-align:left;">&nbsp;

        </td>
<?
if(($jtype=='CR')||($jtype=='BR'))
{
?>
<td><a href='brrecpt_printinv1.php?jtype=<? echo $jtype ?>' style="text-decoration:none;" target=blank><input style="height:32px;width:110px;" value="Print"  type="submit" ></a></td>
<?
}
 ?>           
            <td style="padding-top:0px;margin:0px;text-align:right;">

              <!--  <form method="post" action="" >-->

                      <a href="#login-box" class="login-window" style="text-decoration:none;"> <input  style="height:32px;width:110px;" value="Save" type="button" id='svbttn'></a>


             <!--   </form>-->

            </td>

                
        </tr>
  
        </tbody></table> <!-- TB 3 -->

        </td>

        </tr>



        </tbody></table>





    <form name="invoice_form"  id="jforms"  >

           


    <!-- TB 2 -->

<table class='tbl2' id='tbl2' >
<?
$re11=mysqli_query($db,"select login_date from branch where brcode='$brcode'");
$row11=mysqli_fetch_array($re11);
$mlogin_date = $row11[0];
$qry=mysqli_query($db,"select * from  transactmast order by trnstyp ASC");
?>



<tr>
<td align='left' colspan=2>
Transaction Type</td>
<td id="to_new_customerTD">
<input id="jtype" name='jtype' readonly style="outline:none;border:1px solid grey; border-style:dotted; width:150px; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:black;" type="text" value='<? echo $jtype ?>' onKeydown="return handleEnter(this, event)" onfocus='sel(this.id)'>
      

 
    
 </td>
<td>
 </td><td></td>
<td>
   SAP Entry Date:</td>
<td style="text-align:right;" colspan=3>
   dd<select name='d'  >
<option><?print substr($mlogin_date,8,2);?></option>
<?
for($i=1;$i<=31;$i++)
{
if($i<'10')
{
$i='0'.$i;
}
print "<option>".$i."</option>";
}
?>
</select>
mm <select name='m'  >
<option><?print substr($mlogin_date,5,2);?></option>
<?
for($i=1;$i<=12;$i++)
{
if($i<'10')
{
$i='0'.$i;
}
print "<option>".$i."</option>";
}
?>
</select>
yy <select name='y'  >
<option><?print substr($mlogin_date,0,4);?></option>
<?
for($i=2000;$i<=2020;$i++)
{
print "<option>".$i."</option>";
}
?>
</select>

</td></tr>
<tr><td align='left' colspan=2>               
    Doc. No. </td>
<td id="to_new_registerTD">       
      <input id="docno" name='docno' style="outline:none;border:1px solid grey; border-style:dotted; width:150px; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:black;" type="text" onKeydown="return handleEnter(this, event)" onfocus='sel(this.id)'>
             
</td>
<td></td><td></td>
<td >   

   Doc. Date:</td>
  <td style="text-align:right;" class="invoiceForm_fromNameTD" id="invoice_dateTD" colspan=3>                
<input id="docdtvl" name="docdtvl" readonly style="width:150px;outline:none;border:1px solid grey; border-style:dotted; cursor:pointer; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;" type=text  value="" onKeydown="return handleEnter(this, event)">

  </td></tr>
<tr><td align='left' colspan=2>  
</td>
<td> 



               
</td> <td ></td><td ></td>
<td >

  SAP Invoice No:</td>
  <td style="text-align:right;" class="invoiceForm_fromNameTD" id="invoice_dateTD" colspan=3>
<input id="invno" name='invno' value='<? echo $invno ?>' style="outline:none;border:1px solid grey; border-style:dotted; width:150px; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;" type="text" onKeydown="return handleEnter(this, event)" onfocus='sel(this.id)'>


  </td>

</tr>




  





    



    



        <!-- TB 4 -->

    <!-- TB 4 -->


    <script type="text/javascript" src="scripts/jquery-latest.js"></script>
	
    


<tr><td colspan='9'>   


 <input type="button" id='insrowbttn' onclick="insRow(event,this,this.id)"  value=" Add Item ">
</td>
</tr>
<!--<input type='button' onclick='delRow2(this)' value=' - '>-->
</table>

<br>&nbsp;
<input type='hidden' name='savecount' id='savecount' value='0'>
<table id="myTable" border="1" class='tble1' width=120%>
<th>No.<th width='300'>Account Head<th>Dr Amt<th>Cr Amt<th> Narr<th>Against <th>Profit Cntr<th>Cl.Bal<th>Delete
</table>

<datalist id="htmlListTags"></datalist>
<br>
<div id='clb'></div>
<Hr>


</form>
</div>


<div id="login-box" class="login-popup">
        <a href="#" class="close"><img src="images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>
          <div id='msgbox'></div>
		</div>   



    <tr>

    <td>

    <!-- TB 4 -->

    <table border="0" cellpadding="0" cellspacing="0">



    <tbody>                      
        

        

 <tr>

                <td style="width:15px; border-top:2px solid #eaedee;">&nbsp;</td>

                <td style="border-top:2px solid #eaedee;font-family:verdana; font-size:13px; color:#3c3c3c; font-weight:bold;padding-top:7px;">

                    Total Debit Amount
                </td>

                <td style="padding-top:7px; text-align:right;padding-right:4px;border-right:1px solid white;border-top:2px solid #eaedee;border-left:1px solid white;">

                    <input onclick="alert('The total is calculated automatically as soon as you have entered something into amount field.')" style="border:0px solid white;text-align:right; width:100px; padding-right:5px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;" readonly="readonly"  name='tdamt' id='dbtot' type="text">

                </td>

            </tr>
            
            
            <tr>

                <td style="width:15px; border-top:2px solid #eaedee;">&nbsp;</td>

                <td style="border-top:2px solid #eaedee;font-family:verdana; font-size:13px; color:#3c3c3c; font-weight:bold;padding-top:7px;">

                    Total Credit Amount
                </td>

                <td style="padding-top:7px; text-align:right;padding-right:4px;border-right:1px solid white;border-top:2px solid #eaedee;border-left:1px solid white;">

                    <input onclick="alert('The total amount is calculated automatically as soon as you have entered something into amount field.')" style="border:0px solid white;text-align:right; width:100px; padding-right:5px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;" readonly="readonly"  name='tcamt' id='crtot' type="text">

                </td>

            </tr>


            
            


            
           




            <!-- TB 5 -->

        </tbody></table>










    </tbody></table>

    </td>





    



    </tr>



    <!-- TB 3 -->

    </tbody></table>

    </td>



    </tr>
<div id='nwtest'></div>
    <!-- TB 2 -->

    </tbody></table>

  </form>

    <br><br><br><br>
						
		
		
		<!-- end main table wrapper -->
		</td></tr></tbody></table>
		
</body></html>


</html>
<script type="text/javascript">
function getinv(str1)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
 var nwtest=xmlhttp.responseText;
 document.getElementById("invno").value=xmlhttp.responseText;
	
    }
  }
var strurl="getinvno.php?prod="+str1;

xmlhttp.open("GET",strurl,true);
xmlhttp.send();
}
</script>
