<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

include("../opendb.php");

?>

<!DOCTYPE html>
<html><head>

<title>Journal</title>
<link type="text/css" href="../css/form.css" rel="stylesheet" />
<link type="text/css" href="../jquery/jquery-ui.min.css" rel="stylesheet" />
<script type="text/javascript" src="../scripts/jquery-latest.js"></script>
<script type="text/javascript" src="../js/jquery.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">
  var rawTags;
   var inputField;
   var  initInputFieldValue;
   var dataList;
    var initNbVirgules;

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

$row = $cr.parent().parent();
$(this).autocomplete({
		source: function(request, response ) {

		$.ajax({
			url: "searchcrdtor.php",
			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.crcbal+ '</span><span class="la-stok"> '+ item.stock +'</span><span class="la-rate"> '+item.rate +'</span>'    ,
						value: item.cr,
						name:item.crcbal,
						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('.crcbal').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('.cr_amt').focus();
	
	 }

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


});

}); 


$(function(){
$(".dr").live("keydown.autocomplete",function(){
$dr = $(this);
$row = $dr.parent().parent();
$(this).autocomplete({
		source: function(request, response ) {

		$.ajax({
			url: "searchdbtor.php",
			dataType: "json",
			data: "key="+$dr.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {


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

						stock:item.stock,
						rate:item.rate,
						reduct:item.reduct,


					}
				}));
			}
		});
	}

,
	minLength: 2,
	select: function( event, ui ) {
	$row.find('.dr').val(ui.item.dr);
	
        $row.find('.drcbal').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('.cr_amt').focus();
	
	 }

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


});

});


  function xx(str,event,this1)
  {


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

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

	 }

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

	 }

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

	 }
 
              if (keyCode == 46){
			  var i=this1.parentNode.parentNode.rowIndex;
			  
                       var r=confirm("Do you want to delete the row?");
			  if (r==true)
 				 {
 					//document.getElementById('myTable').deleteRow(i);
					delRow(this1);
                                  document.getElementById('myTable').rows[i].cells[1].getElementsByTagName("input")[0].focus();
                                  
					//var nxt =document.getElementById('myTable').rows[i].cells[0].innerHTML;
					//alert(nxt);
  				 }
			   
                       }


 inputField = document.getElementById(str);

 initInputFieldValue = inputField.value;
 dataList = document.getElementById('htmlListTags');

		if(keyCode!='40')
              {
                if(keyCode!='38')
              {
         

yy(str,event,this1); 


}
 


     }
 
 }
  function yy(str,event,this1)
    {


     initNbVirgules = (initInputFieldValue.match(/,/g)||[]).length;
fillDatalist("",str,event,this1);
    } 
  
function fillDatalist(prefix,str,event,this1) {



	var nbRawList = rawTags.length;
       
	while(dataList.childNodes.length > 0) {
		dataList.removeChild(dataList.childNodes[0]);
	}
	
	for (i=0; i < nbRawList; i++ ) {
		var nOpt = document.createElement("option");
		nOpt.value = prefix+rawTags[i];
		dataList.appendChild(nOpt);
	}

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

  
   var itemval=document.getElementById(str).value;


    if((keyCode=='13') &&(itemval!=''))
              {


         closingbal(itemval, this1, 'drcbal', 'myTable');
         handleEnter(this1, event);
         
   	
              }  
}

//mainLoop();


  function xx1(str,event,this1)
  {


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


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

	 }

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

	 }

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

	 }
           if (keyCode == 46){
			  var i=this1.parentNode.parentNode.rowIndex;
			  
                       var r=confirm("Do you want to delete the row?");
			  if (r==true)
 				 {
 					//document.getElementById('myTable2').deleteRow(i);
					delRow2(this1);
                                  document.getElementById('myTable2').rows[i].cells[1].getElementsByTagName("input")[0].focus();
                                  
					//var nxt =document.getElementById('myTable2').rows[i].cells[0].innerHTML;
					//alert(nxt);
  				 }
			   
                       }


 inputField = document.getElementById(str);

 initInputFieldValue = inputField.value;
 dataList = document.getElementById('htmlListTags');

		if(keyCode!='40')
              {
                if(keyCode!='38')
              {
         

yy1(str,event,this1); 


}
 


     }
 
 }
  function yy1(str,event,this1)
    {


     initNbVirgules = (initInputFieldValue.match(/,/g)||[]).length;
fillDatalist1("",str,event,this1);
    } 
  
function fillDatalist1(prefix,str,event,this1) {



	var nbRawList = rawTags1.length;
       
	while(dataList.childNodes.length > 0) {
		dataList.removeChild(dataList.childNodes[0]);
	}
	
	for (i=0; i < nbRawList; i++ ) {
		var nOpt = document.createElement("option");
		nOpt.value = prefix+rawTags1[i];
		dataList.appendChild(nOpt);
	}

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

  
   var itemval=document.getElementById(str).value;


    if((keyCode=='13') &&(itemval!=''))
              {


         closingbal(itemval, this1, 'crcbal', 'myTable2');
         handleEnter2(this1, event);
         
   	
              }  
}

//mainLoop();



</script>




<style>


#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;
}

.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}
.la-code {
    display: inline-block;
    width: 200px;
}
</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();

 	// $(".typeselecter").attr("disabled", true);
 	 // $("#td1").html('');

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



           	 if(parseInt(msg)!=0)    

          	  {

                $('#msgbox').html(msg);
            
               // $("#load").html(''); 
                //$(".typeselecter").attr("disabled", false);  
		}
           

      	},
      error:function(){
          alert("failure1212");
          $("#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 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
 {
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);
}
}


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

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

if(isNaN(val))
  {
  alert('Enter Digit');
 document.getElementById("cr_amt"+id1).value=0;
  
  }
else
 {
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);
}
}


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 vv;
var dr=[];
var dr_narr=[];
var drs=[];
var crs=[];
var dr_amt=[];
var dragain=[];
var dragval=[];
var cnt=1;

/***********************************************
* Disable "Enter" key in Form script
* This notice must stay intact for use
***********************************************/
function uppercase(str,r,itid)
{
	var i=r.parentNode.parentNode.rowIndex;
   	var tbl = document.getElementById('myTable');
   	var id1=tbl.rows[i].cells[0].innerHTML;
	var str=document.getElementById("dr_narr"+id1).value;

	var narr = str.toUpperCase();
    document.getElementById("dr_narr"+id1).value = narr;
}  
function uppercase1(str,r,itid)
{
    var i=r.parentNode.parentNode.rowIndex;
   	var tbl = document.getElementById('myTable2');
   	var id1=tbl.rows[i].cells[0].innerHTML;
	var str=document.getElementById("cr_narr"+id1).value;

	var narr = str.toUpperCase();
    document.getElementById("cr_narr"+id1).value = narr;
}              
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;
			*/
			 
              }
               
                   		}      










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;
	
}

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 z1=x.insertCell(3);	
var ag=x.insertCell(4);
var agval=x.insertCell(5);
var op=x.insertCell(6);
var dd=x.insertCell(7);
a.innerHTML=cur;

y.innerHTML="<input type=text name='dr[]' id=dr"+cur+"  size=35 class='dr' autocomplete='off' list='htmlListTags'>";

z.innerHTML="<input type='text' name='dr_amt[]' id='dr_amt"+cur+"' value='0'  size=10 onchange='counttot(this,this.value)' onKeydown='return handleEnter(this, event)'>";
z1.innerHTML="<input type='text' id='dr_narr"+cur+"' name='dr_narr[]' size=30 onchange='uppercase(this.value,this,this.id)' autocomplete='on' onKeydown='return handleEnter(this, event)'>";

ag.innerHTML="<select name='dragain[]' id='dragain"+cur+"' onKeydown='return handleEnter(this, event)'><option>CHEQ</option><option>DA</option></select>";
agval.innerHTML="<input type='text' id='dragval"+cur+"' name='dragval[]'  onKeydown='return handleEnter(this, event)'>";
op.innerHTML="<input type=text readonly id='drcbal"+cur2+"' class='drcbal'  onKeyup='insRow(event,this,this.id)' >";
dd.innerHTML="<input type='button'  onClick='delRow(this)' class='del'>";
document.getElementById("dr"+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("dr"+id3).focus();
} 

}





function delRow(r)
{
 var ab=confirm("Do you want to delete the row?");
if (ab==true)
 {
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--;
  }
else{return;}

}

//************************************



$(document).bind('keydown', 'ctrl+s', function (e) {
        if (e.ctrlKey && (e.which == 83)) {

            e.preventDefault();
             $( "#svbttn" ).click();
            return false;
        }
    });
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;
						
			 
              }
                     	 	}    

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

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.toFixed(2);
}

//-------*888888888888888888888888*********************8888
var cnt2=1;
var dr=[];
var cur2=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 cragval1=x.insertCell(5)
var op=x.insertCell(6);
var dd=x.insertCell(7);
a.innerHTML=cur2;
y.innerHTML="<input type=text name='cr[]' id=cr"+cur2+"  size=35 class='cr' 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 onchange='uppercase1(this.value,this,this.id)' autocomplete='on' onKeydown='return handleEnter2(this, event)'>"

crag.innerHTML="<select name='cragain[]' id='cragain"+cur2+"' onKeydown='return handleEnter2(this, event)'><option>CHEQ</option><option>DA</option> </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+"' class='crcbal'  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 ab=confirm("Do you want to delete the row?");
if (ab==true)
 {
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--;
}
else{return;}
}

function getda(x,y,drcr)
{
if(x.selectedIndex==1)
 window.open('getda.php?no='+y+'&drcr='+drcr);
}



</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;
margin-top:20px;
}	
.tble1 td , th
{
border-collapse:collapse;
border:1px solid silver;

}

#tbl1{
 margin-top:40px;
min-width:65%;
 text-align:center;
}

#tbltd1{
vertical-align: top;
margin-top:20px;
 height:400px;
background-color:white;
-moz-box-shadow: 0 0 5px -1px #000;
-webkit-box-shadow: 0 0 5px -1px #000;
box-shadow: 0 0 5px -1px #000;

}
#tbl1 td{
 text-align:left;

}
#tbl2{
 margin:50px 20px 10px 20px;
 min-width:95%;
}

</style>

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


<?php include('includes/top.php'); ?>
<?php include('help_window.php'); ?>
<body style="text-align: center;" onload="document.getElementById('dt').focus();" >
         <div id="pop2" class="pop-up2" >
  <div class="popBox2">

    <div class="popScroll2" id='popScroll2' >

    </div>
 
  </div>


  <a href="#links" class="lightbox"></a>
</div>               
       

         <table class='tbl1' id='tbl1'  align='center'><tr><td align='left' colspan='6'>
		<h1 style="font-size:20px;font-weight:bold;font-family:verdana;color:#FFFFFD;margin:0px; padding:0px;">
		</h1></td></tr>


	
        
<tr><td id='tbltd1' colspan='6'>
<div>
<fieldset style="border:2px solid grey; border-style:dotted;">
<legend style="text-align:center;">Journal</legend>

<form name="invoice_form" method='post' autocomplete="on"  id="jforms"  >    
<table class='tbl2' id='tbl2' >
<tr><td style="align:center;" colspan='4' >


Date:dd<select name='d' id='dt' >
<option><?print date("d",time());?></option>
<?
for($i=1;$i<=31;$i++)
{
if($i<'10')
{
$i='0'.$i;
}
print "<option>".$i."</option>";
}
?>
</select>
mm <select name='m'  >
<option><?print date("m",time());?></option>
<?
for($i=1;$i<=12;$i++)
{
if($i<'10')
{
$i='0'.$i;
}
print "<option>".$i."</option>";
}
?>
</select>
yy <select name='y'  >
<option><?print date("Y",time());?></option>
<?
for($i=2000;$i<=2020;$i++)
{
print "<option>".$i."</option>";
}
?>
</select>
<br>
</td></tr>
<tr><td colspan='4'>   


Debit <input type="button" id='insrowbttn' onclick="insRow(event,this,this.id)" style="color:#6B6B6B;font-weight:bold;font-size:15px;" value="+">

<input type='hidden' name='savecount' id='savecount' value='0'>
<table id="myTable" border="1" class='tble1' width=100%>
<th>No.<th>Dr <th>Amt <th>Narr<th>Against <th>Cheq. No.<th>Cl.Bal<th>Delete
</table>
<br>
Credit <input type="button" id='insrowbttn2' onclick="insRow2(event,this,this.id)" style="color:#6B6B6B;font-weight:bold;font-size:15px;" value="+">
<table id="myTable2" border="1" class='tble1' width=100%>
<th>No.<th>Cr <th>Amt <th>Narr<th>Against <th>Value<th>Cl.Bal<th>Delete
</table>
<datalist id="htmlListTags"></datalist>
<br>
<div id='clb'></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>
</td></tr>

<tr><td></td><td></td><td colspan='2' style="text-align:right;">

                    Total Debit Amount
               <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></td><td></td><td colspan='2' style="text-align:right;">
               Total Credit Amount
                <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>

   </td></tr>
</table>
    </form>
</fieldset> 
</div>
</td></tr>
<tr><td style="width:250px;height:45px;align: right;padding-left: 80%;"><input  style="height:32px;width:110px;" value="Save" type="button" id='svbttn'></td></tr>

</table>

</body></html>
