<?
include_once('includes/top.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}

include('opendb.php');
?>
<!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">
  $(function() {
    $("#grndt1").datepicker({ dateFormat: 'yy-mm-dd' });

  });
  $(function() {
    $("#invoice_date" ).datepicker({ dateFormat: 'yy-mm-dd' });

  });
  </script>
<script type="text/javascript">
var count1=1;
var count2=1;
var count3=1;
var pname=[];
var pcode=[];
var pname1=[];
var pcode1=[];
var empname=[];
var ndpcost=[];
function sel(id1)
{

   document.getElementById(id1).select();
  
}



function showHint1()
{
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","delete_viewinv1.php", true);
xmlhttp.send();
}

function viewinv1(str)
{
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","delete_viewinv.php?inno="+str,true);
xmlhttp.send();
}

/** code below for close popup div **/
function close_div(){
   var list = document.getElementsByClassName("pop-up2");
             for (var i = 0; i < list.length; i++) {
               list[i].style.display = 'none';
             }
    		var e = document.getElementById('pop2');
   		 if(e.style.display == 'block') {
       		 e.style.display = 'none';
   		 } else {
        	e.style.display = 'none';
              }

 }
function itemclose_div(){
   var list = document.getElementsByClassName("pop-up2");
             for (var i = 0; i < list.length; i++) {
               list[i].style.display = 'none';
             }
    		var e = document.getElementById('pop2');
   		 if(e.style.display == 'block') {
       		 e.style.display = 'none';
   		 } else {
        	e.style.display = 'none';
              }

 }


 function check_empname(str,id1){

   var flg=0;
   for(var j=0;j<count1;j++){

       if(str==empname[j]){

         flg++;

       }//close of if cond.
  

   }//close of for loop.

   var len=str.length;

   if((!isNaN(str))&&len<=1){

   flg++;
   }
 
   if(flg<1){
    alert('Invalid employee');
    document.getElementById(id1).value='';
    document.getElementById(id1).focus();
    
   }
   
 }//function closed.





</script>
<style>
#txt{
font-family: Tahoma,Verdana,Geneva,sans-serif !important;
   
background-color: #F2F2F2;

}
</style>
<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:2px; 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:60%; 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:2%; left:3%; right:3%; bottom:9%; overflow-y:auto; *overflow-y:scroll; padding-right:0.5em}


</style>

<script type="text/javascript">

$(document).bind('keydown', 'Alt+n',function (e){

if(e.which==83 && e.ctrlKey) {
e.preventDefault()
 $( "#svbttn" ).click();
        return false;
}   
    if(e.which==78 && e.altKey){
	 //alert (e.which);
        shortkey_tblopen();
        return false;
    } 
 
   if(e.which==82 && e.altKey){
	 
         window.location.reload(true);
        return false;
    } 
      
    
});
function myFunction()
	{
		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(); 
               	}		   					
 		 
 	}

</script>


<script type="text/javascript">
 var count1=0;
 var empname=[];

 var cur=1;
 //var partcode=[];
 var partname=[];
 var unitprice=[];
 var qty=[];
 var tot=[];
 var typ=[];
 var cnt=1;

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 b1=x.insertCell(0);
var c1=x.insertCell(1);
var z1=x.insertCell(2);
var d1=x.insertCell(3);	
var e1=x.insertCell(4);
var f1=x.insertCell(5);
var w1=x.insertCell(6);
var q1=x.insertCell(7);
var g1=x.insertCell(8);
var a=x.insertCell(9);
var h1=x.insertCell(10);
var j1=x.insertCell(11);
var l1=x.insertCell(12);
var m1=x.insertCell(13);
var ab=x.insertCell(14);
var n1=x.insertCell(15);
var r1=x.insertCell(16);
var o1=x.insertCell(17);
var p1=x.insertCell(18);
var k;//=this.rowIndex;
var k1;

b1.innerHTML="<input type=text name=partcode[] id=partcode"+cur+"  class='partcode' size=6 autocomplete='off' list='partcodelist' onkeypress='handleEnter(this, event)'>";
c1.innerHTML="<input type=text name=partname[] id=partname"+cur+" class='partname' size=9  autocomplete='off' list='partlist' onkeypress='handleEnter3(this, event)' >";

d1.innerHTML="<input type=text name='qty[]' class='qty' id=qty"+cur+" size=6 onkeypress='handleEnter(this, event)'>";
e1.innerHTML="<input type=text name=unitprice[] id=unitprice"+cur+" size=9 class='unitprice' onKeydown='return handleEnter(this, event)'>";
f1.innerHTML="<input type=text id='tot"+cur+"' name=tot[] value='0' size=4 class='tot' onKeydown='return handleEnter(this, event)' onKeyup='calamt(this.value,this,this.id)' >";
w1.innerHTML="<input type=text id='befrtx"+cur+"' name=befrtx[] value='0' class='befrtx' onKeyup='calamt(this.value,this,this.id)' onkeypress='handleEnter(this, event)'>";
q1.innerHTML="<input type=text id='tax"+cur+"' name=tax[] value='0' size=3 class='tax' onKeydown='return handleEnter(this, event)' onKeyup='calamt(this.value,this,this.id)'  >";

o1.innerHTML="<input type=text id='ntamt"+cur+"' name=ntamt[] value='0' size=3 class='ntamt'  onKeydown='return handleEnter(this, event)' onKeyup='insRow(event,this,this.id)'>";
p1.innerHTML="<input type='button' onClick='delrow(this)' class='del' id=del"+cur+">";
document.getElementById("partcode"+cur).focus();
cur++;
cnt++;
var table = document.getElementById("myTable");
var row = table.rows[index];
console.log(secondRow.id);
}
if(keyCode == 40)
{
return handleEnter(this, event);
}
if(keyCode == 13)
	{
		var tbl = document.getElementById('myTable');
   		var id3=tbl.rows[i3].cells[0].innerHTML;	
		document.getElementById("partcode"+id3).focus();
	} 

}// end function insrow
function newcustomer()
{
document.getElementById("to_new_customerTD").innerHTML=" <input id='to_new_customer' name='cus' style='outline:none;border:1px solid grey; border-style:dotted;width:150px; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;'   placeholder='Customer name' type='text'>";

 document.getElementById("to_new_registerTD").innerHTML=" <input id='to_new_register' name='reg' style='outline:none;border:1px solid grey;width:150px; padding-left:7px; font-weight:normal;border-style:dotted; font-family:verdana;font-size:13px;'  placeholder='Customer id' type='text'>"
 
document.getElementById("pmode").value='CASH';
}
function showcustomer()
{

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("to_new_customerTD").innerHTML=xmlhttp.responseText;
    
    }
  }
document.getElementById("pmode").value='CREDIT';
xmlhttp.open("GET","showcus.php",true);
xmlhttp.send();
}

function khadicustomer()
{

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("to_new_customerTD").innerHTML=xmlhttp.responseText;
    
    }
  }
document.getElementById("pmode").value='CREDIT';

xmlhttp.open("GET","showkhadistf.php",true);
xmlhttp.send();
}


function showregister(str)
{
//var str="hello";
//alert (str);
if (str=="")
  {
  document.getElementById("to_new_registerTD").innerHTML="";
  return;
  }
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("strbl").innerHTML=xmlhttp.responseText;
        document.getElementById("to_new_register").value=document.getElementById("reg").value;
        document.getElementById("clsbl").value= document.getElementById("mclbl").value;
        document.getElementById("blamt").value= document.getElementById("mblamt").value;
		document.getElementById("crlimit").value= document.getElementById("mcrlmt").value;
        document.getElementById("disclimit").value= document.getElementById("mdslmt").value;
		alert(document.getElementById("mdsbl").value);
        document.getElementById("dsbl").value= document.getElementById("mdsbl").value;
        document.getElementById("dsvn").value= document.getElementById("mdsbll").value;
		document.getElementById("disavlbl").value= document.getElementById("dscntvl").value;

    }
  }
xmlhttp.open("GET","showreg.php?cname="+str,true);
xmlhttp.send();

}

function showkhadiregister(str)
{
//var str="hello";
//alert (str);
if (str=="")
  {
  document.getElementById("to_new_registerTD").innerHTML="";
  return;
  }
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("strbl").innerHTML=xmlhttp.responseText;
        document.getElementById("to_new_register").value=document.getElementById("reg").value;
        document.getElementById("clsbl").value= document.getElementById("mclbl").value;
        document.getElementById("blamt").value= document.getElementById("mblamt").value;
        document.getElementById("crlimit").value= document.getElementById("mcrlmt").value;
        document.getElementById("disclimit").value= document.getElementById("mdslmt").value;
        document.getElementById("dsbl").value= document.getElementById("mdsbl").value;
        document.getElementById("dsvn").value= document.getElementById("mdsbll").value;
		document.getElementById("disavlbl").value= document.getElementById("dscntvl").value;



    }
  }
xmlhttp.open("GET","showkhadireg.php?cname="+str,true);
xmlhttp.send();

}



function showinfo(str)
{
//var str="hello";


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("to_new_model").innerHTML=xmlhttp.responseText;
    var  mod= document.getElementById("mod").value;
    document.getElementById('to_new_model').value=mod;
    document.getElementById("chno").innerHTML=xmlhttp.responseText;
    var  chasis= document.getElementById("chasis").value;
    document.getElementById('chno').value=chasis;
    
    }
  }
xmlhttp.open("GET","showinfo.php?reg="+str,true);
xmlhttp.send();

}
</script>









<style>
.tble1 input {
background-color:transparent;
border: 0px solid;


color:black;
font-size: 12px;
}
.tble1
{

border:1px solid silver;
margin-top:20px;
font-family: Tahoma,Verdana,Geneva,sans-serif !important;
    font-size: 12px;
}
.trcls
{

background-color:#BDBDBD;
border:1px solid silver;

}	
.tble1 td, th
{
border-collapse:collapse;
border:1px solid silver;
}
.tble1 tr
{
height:30px;
}
#tbl1{
 //margin-top:40px;
min-width:65%;
 text-align:center;
}

#tbltd1{
vertical-align: top;
margin-top:20px;
font-family:calibri;
 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:0px 20px 10px 20px;
 min-width:95%;
}
#conf_panel{  

        width:250px;
        margin-top:200px;
        position:fixed; 
        top: 1px;  
        left: 450px;  
        text_align:center;
        
        -moz-box-shadow: 0 0 2px 2px #888;
        -webkit-box-shadow: 0 0 2px 2px#888;
         box-shadow: 0 0 2px 2px #888;
     
        background-color: white;  
      
        color: black;  
        display: none; 
        border:1px solid #C2DFFF; 

    }  

.conf_tbl th{
  
    font-weight: bold;  
    color: white; 
    border:1px solid #D7D7D1;
    height:45px;
    border-collapse:collapse;

   

background: steelblue; /* Old browsers */
//background: -moz-linear-gradient(top, rgba(181,189,200,1) 0%, rgba(130,140,149,1) 36%, rgba(40,52,59,1) 100%); /* FF3.6+ */
//background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(181,189,200,1)), color-stop(36%,rgba(130,140,149,1)), //color-stop(100%,rgba(40,52,59,1))); /* Chrome,Safari4+ */
//background: -webkit-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Chrome10+,Safari5.1+ */
//background: -o-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Opera 11.10+ */
//background: -ms-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* IE10+ */
//background: linear-gradient(to bottom, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* W3C */
//filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=0 ); /* IE6-9 */

 }




.conf_tbl td{

    height:32px;
    border: 1px solid #A9A9A9;
  
  //text-align:left;
    // font-size:4 px;  
    color: black; 
background: -moz-linear-gradient(top, rgba(246,248,249,1) 0%, rgba(229,235,238,0.94) 50%, rgba(215,222,227,0.94) 51%, rgba(233,237,240,0.91) 81%, rgba(245,247,249,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(246,248,249,1)), color-stop(50%,rgba(229,235,238,0.94)), color-stop(51%,rgba(215,222,227,0.94)), color-stop(81%,rgba(233,237,240,0.91)), color-stop(100%,rgba(245,247,249,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* W3C */
//filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f6f8f9', endColorstr='#f5f7f9',GradientType=0 ); /* IE6-9 */



 }

.conf_tbl input[type="text"]  {
   // padding: 0px 5px 0px 5px;
    border-style:none;
    border-color: white;//transparent;
    background-color: transparent;
   // font-size:12px;

}
.conf_tbl input[type="select"]  {
   // padding: 0px 5px 0px 5px;
    border-style:none;
    border-color: white;//transparent;
    background-color: transparent;
   // font-size:12px;
height:25px;
}

</style>
<script>

/** code below for drag the confirmation div */
window.onload = function(){
    //draggable('conf_panel');
};
window.onload = function(){
    //draggable('aditem_panel');
};
var dragObj = null;
function draggable(id)
{
    var obj = document.getElementById(id);
    obj.style.position = "absolute";
	
	//obj.style="left:300px;top:150px;"
    obj.onmousedown = function(){
            dragObj = obj;
    }
}

document.onmouseup = function(e){
    dragObj = null;
};

document.onmousemove = function(e){
    var x = e.pageX;
    var y = e.pageY;

    if(dragObj == null)
        return;

    dragObj.style.left = x +"px";
    dragObj.style.top= y +"px";
};
function showrebtvl(str)
    {
	if(str=='Yes')
            {
                document.getElementById("rbtvl").style.visibility = "visible";
            }
        else
            {
                document.getElementById("rbtvl").style.visibility ="hidden";
       
            }
   
 
}
function chkey(abc)
{
 yy=abc.value
 if(yy.length>35)
 { 
   alert('Name exeeds the limit');
   return;
 }

 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
 if(yy.indexOf("'")>-1) 
  {
    alert("\' is not allowed");
    abc.value='';
  }
 if(yy.indexOf('"')>-1) 
  {
    alert("\" is not allowed");
    abc.value='';
  }

}
</script>





<?php //include('includes/top.php'); ?>
<?php //include('help_window.php'); ?>
<div align='left'><font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;</font></div>

<body style="background-image:url(images/bg.jpg);" onload="document.getElementById('grnno').focus();if (document.invoice_form.RadioGroup1[0].checked == true) 
		{shortkey_tblopen();
  		}">
        
<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:blue;margin:0px; padding:0px;">
		Purchase</h1></td></tr>
		
		<tr>
 

		<td><a href="#pop2" id="linkss" onclick='showHint()' style="text-decoration:none;"><input value="View"  style="height:32px;width:110px;" type="submit" ></a></td>
                <td><a href='countersale_editinv1.php' style="text-decoration:none;"><input style="height:32px;width:110px;" value="Edit"  type="submit" ></a></td>

                <td><a href="#pop2" id="linkss" onclick='showHint1()' style="text-decoration:none;"><input value="Delete"  style="height:32px;width:110px;" type="submit" ></a></td>
			
			
		<td><a href='countersale_printinv1.php' style="text-decoration:none;"><input style="height:32px;width:110px;" value="Print"  type="submit" ></a></td>
		<td><input style="height:32px;width:110px;" type="button" onclick="myFunction()" value="Reset"></td>
		 <td><a href="#login-box" class="login-window" style="text-decoration:none;"> <input style="height:32px;width:110px;" value="Save" type="button" id='svbttn'></a></td>

		 <td><?php include('help_window.php'); ?></td>
           </tr>
	
<tr><td id='tbltd1' colspan='7'>

<div id="conf_panel" class="alist" style="display:none;position: absolute;">
 
   

</div>

<div id="aditem_panel" class="itemalist" style="display:none;position: absolute;">
 
 

</div>



<div>
 <fieldset style="border:2px solid grey; border-style:dotted;">
            <legend style="text-align:center;">Purchase</legend>
 <form id="jforms" name="invoice_form" method='POST' >
<input type='hidden' name='updprint' id='upd_flag' value='2'>
    <table class='tbl2' id='tbl2' >



 				  
                           	  <tr><td align='right'>
                             Purchase Order No:</td>
                             <td >
<?
$qry="select distinct(invno) from pordersprtmp where brcode='$brcode' and cusid!=''";
$rs=mysqli_query($db,$qry);

$qry1="select distinct(invno) from pordersprtmp where tobrcode='$brcode'";
$rs1=mysqli_query($db,$qry1);
?>

<select name='grnno'>
<option value='select'>-select-</option>
<?
while($rw=mysqli_fetch_array($rs))
{
?>
<option value='<? echo $rw[invno] ?>'><? echo $rw[invno] ?></option>
<?
}
?>
<?
while($rw1=mysqli_fetch_array($rs1))
{
?>
<option value='<? echo $rw1[invno] ?>'><? echo $rw1[invno] ?></option>
<?
}
?>
</select><input type='submit' name='searchinv' Value='search'>

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

<table border=1 id="myTable" class='tble1' width=100%>
<tr class='trcls'><td>No.</td><td>Item Cd</td><td>Item Name</td><td>Qty</td><td>Unit Price</td><td>Total</td><td>others/handling</td><td>round off</td><td>Total</td><td>Del</td></tr>



<?
if(isset($_POST[searchinv]))
{
     $grnno=$_POST[grnno];
	
     $sr=mysqli_query($db,"select * from pordersprtmp where invno='$grnno'");
     $sw=mysqli_fetch_array($sr);
     if($sw[cusid]!='')
     {
        $re=mysqli_query($db,"select * from pordersprtmp where invno='$grnno' and brcode='$brcode'");
        $sql="select * from pordersprtmp where invno='$grnno' and brcode='$brcode'";
     }       	
     else
     {
        $re=mysqli_query($db,"select * from pordersprtmp where invno='$grnno' and tobrcode='$brcode'");
        $sql="select * from pordersprtmp where invno='$grnno' and tobrcode='$brcode'";
     }
      
        

     $i=1;
     $l_tot=0;
     $s_tot=0;
     while($jrow=mysqli_fetch_array($re))
     {
        ?>
      <tr><td><? echo $i ?></td>
      <?
      print "<td><input type=text  name='partcode[]' value='$jrow[6]' id='partcode$i' class='partcode'  autocomplete='off' list='partcodelist'  onkeypress='handleEnter(this, event)' ></td>";
      print "<td><input type=text name='partname[]' value='$jrow[5]' id='partname$i' class='partname' autocomplete='off' list='partlist' onkeypress='handleEnter3(this, event)' ></td>";
      print "<td><input type=text name='qty[]' class='qty' id='qty$i' size=2 value='$jrow[7]' onKeydown='return handleEnter(this, event)' onKeyup='qtycheck(this)'></td>";
      print "<td><input type=text name=unitprice[] id='unitprice$i' size=3 value='$jrow[8]' class='unitprice' onfocus='sel(this.id)' onKeydown='return handleEnter(this, event)' onKeyup='qtycheck(this)'></td>";
      print "<td><input type=text id='tot$i' name=tot[] readonly value='$jrow[9]' size=3 class='tot' onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)' onKeyup='insRow(event,this,this.id)'></td>";

      print "<td><input type=text id='befrtx$i' name=befrtx[] readonly value='' size=3 class='beftx' onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)' ></td>";
      print "<td><input type=text id='tax$i' name=tax[] readonly value='' size=3 class='tax' onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  ></td>";

     print "<td><input type=text id='ntamt$i' name=ntamt[] readonly value='$jrow[9]' size=3 class='ntamt'  onKeydown='return handleEnter(this, event)'></td>";
     print "<td><input type='button' onClick='delrow(this)' class='del' id='del$i'></td> </tr>";

         //$beftot+=$jrow[10];
         $l_tot+=$jrow[9];

         //print"<script>cur++;</script>";
         //print"<script>cnt++;</script>";
         $i++;
}
?>
</table>











 
<?
}
?>
<script>
var cnt=1;
</script>

<div id="livesearch" style="display: inline-block;"></div>


<input type='hidden' name='brcode' id='brcode' value='<? print $brcode;?>'>
<input type='hidden' name='curqty' id='curqty' value='0'>
<input type='hidden' name='prtname' id='prtname' value='0'>
<input type='hidden' name='savecount' id='savecount' value='0'>
<div id='txtHint'></div>
<div id='partvalid'></div>

<div id="view" class="login-popup">

</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 colspan='8' style="text-align:right;">                  
              Net Total</td><td colspan='2'>
                <input 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="sum_total" id="sum_total" value="<? echo $l_tot ?>" type="text">

</td></tr>

<tr><td colspan='9'><hr></hr></td></tr>

 </form>
   
</table>
   
</fieldset> 
</div>
</td></tr></table>
		

</body></html>
<script type="text/javascript">
$(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: "svpurchs.php",
    	  type: "POST",
   	  data:   values1,
     	  success: function(msg){


           	 if(parseInt(msg)!=0)

          	  {

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

                //$(".typeselecter").attr("disabled", false);
		}


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

	 });
	 });






 function downpayment(){

    var e = document.getElementById('conf_panel');
    if(e.style.display == 'block') {
        e.style.display = 'none';
    } else {
        e.style.display = 'block';
    }
 }
function close_div(){
   var list = document.getElementsByClassName("alist");
             for (var i = 0; i < list.length; i++) {
               list[i].style.display = 'none';
             }
    		var e = document.getElementById('conf_panel');
   		 if(e.style.display == 'block') {
       		 e.style.display = 'none';
   		 } else {
        	e.style.display = 'none';
              }

 }
function itemclose_div(){
   var list = document.getElementsByClassName("itemalist");
             for (var i = 0; i < list.length; i++) {
               list[i].style.display = 'none';
             }
    		var e = document.getElementById('aditem_panel');
   		 if(e.style.display == 'block') {
       		 e.style.display = 'none';
   		 } else {
        	e.style.display = 'none';
              }

 }
 function custclose_div(){
   var list = document.getElementsByClassName("itemalist");
             for (var i = 0; i < list.length; i++) {
               list[i].style.display = 'none';
             }
    		var e = document.getElementById('adcust_panel');
   		 if(e.style.display == 'block') {
       		 e.style.display = 'none';
   		 } else {
        	e.style.display = 'none';
              }

 }


function aditem(str)
{
    var e = document.getElementById('aditem_panel');
    if(e.style.display == 'block') {
        e.style.display = 'none';
    } else {
        e.style.display = 'block';
    }
 
}
function adcust(str)
{


    var e = document.getElementById('adcust_panel');
    if(e.style.display == 'block') {
        e.style.display = 'none';
    } else {
        e.style.display = 'block';
    }
 
}
</script>
<script type="text/javascript">
 function delfun(x)
 {
 	if (confirm('do you want to delete '+x+' ?'))
		{
			document.location='delcountersale.php?code='+x;
		}
 
 }
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 delRow(r)
{
alert(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('insrowbttn2').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("cr_amt"+id2).value;
    
         str1=parseFloat(str1)+parseFloat(itemval); 
        
     }
  document.getElementById("crtot").value= str1.toFixed(2);

cnt2--;
     
 }
</script>
<script type="text/javascript">
$(document).ready(function(){

    $("select.grp").change(function(){

        var selectedGrp = $(".grp option:selected").val();

        $.ajax({

            type: "POST",

            url: "selectsubgrp.php",

            data: { grp : selectedGrp } 

        }).done(function(data){

            $("#response").html(data);

        });

    });

});
function calamt(str,r,qid)
{
    var i=r.parentNode.parentNode.rowIndex;
    var tbl = document.getElementById('myTable');
    var id1=i;
    document.getElementById("fivetax"+id1).value=parseFloat(document.getElementById("fivebfrtx"+id1).value*(5/100));
    if(document.getElementById("sprfrtn"+id1).value>0)
        {
        document.getElementById("fourteentax"+id1).value=parseFloat(document.getElementById("sprfrtn"+id1).value*(14.5/100));
        }
    if(document.getElementById("btryfrtn"+id1).value>0)
        {
        document.getElementById("fourteentax"+id1).value=parseFloat(document.getElementById("btryfrtn"+id1).value*(14.5/100));
        }
    document.getElementById("lubtx"+id1).value=parseFloat((document.getElementById("lubamt"+id1).value)*(document.getElementById("vatcst"+id1).value/100));

    document.getElementById("ntamt"+id1).value=parseFloat(document.getElementById("zerobfrtx"+id1).value)+parseFloat(document.getElementById("fivebfrtx"+id1).value)+parseFloat(document.getElementById("fivetax"+id1).value)+parseFloat(document.getElementById("sprfrtn"+id1).value)+parseFloat(document.getElementById("fourteentax"+id1).value)+parseFloat(document.getElementById("btryfrtn"+id1).value)+parseFloat(document.getElementById("lubamt"+id1).value)+parseFloat(document.getElementById("lubtx"+id1).value)-parseFloat(document.getElementById("discnt"+id1).value)+parseFloat(document.getElementById("others"+id1).value);
        
}

</script>