<?
session_start();
include("test.php");
include("opendb.php");
include("includes/function.php");

if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
$us=mysqli_query($db,"select level from bruser where username='$user'")or die(mysqli_error($db));
$r=mysqli_fetch_row($us);
$user_level=$r[0];
 //print "User Level:".$user_level;       
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Xpress</title>


<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />
<script src="datetimepicker_css.js"></script>
<!--<script src="rightclick_deactive.js"></script> 
<script type="text/javascript" src="scripts/jquery-latest.js"></script>

<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>

<link rel="stylesheet" href="css/AutoComplete.css" media="screen" type="text/css">
   <script language="javascript" type="text/javascript" src="js/AutoComplete.js"></script>



    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
	<script type="text/javascript">
    $(document).ready(function() {
        var cont_left = $("#container").position().left;
        $("a img").hover(function() {
            // hover in
            //$(this).parent().parent().css("z-index", 1);
            $(this).animate({
               height: "110",
               width: "110",
              
            }, "fast");
        }, function() {
            // hover out
         //   $(this).parent().parent().css("z-index", 0);
            $(this).animate({
                height: "80",
                width: "80",
                
            }, "fast");
        });
        
        $(".img").each(function(index) {
            var left = (index * 160) + cont_left;
            $(this).css("left", left + "px");
        });
    });


</script>-->


<!-- js code below for active enter with textfield-->


<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
                
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;
		} 
		else
		return true;
	}      

</script>


<script>
function fld_active(str){
  
     if(str!='Insurance'){
        document.getElementById("policereport").disabled=true;
        document.getElementById("fileno").disabled=true;
        document.getElementById("policyexcess").disabled=true;
        document.getElementById("others").disabled=true;
        document.getElementById("depreciation").disabled=true;
        
     }
     else{
        document.getElementById("policereport").disabled=false;
        document.getElementById("fileno").disabled=false;
        document.getElementById("policyexcess").disabled=false;
        document.getElementById("others").disabled=false;
        document.getElementById("depreciation").disabled=false;
        
     }
   


}


function Validate()
{

if(document.f1.instype.value=='--select--')
 {
alert('select proper Service Type');
document.f1.instype.focus();
return false; 
}


        var x = document.f1.labour.value;


if(isNaN(x)|| x.indexOf(" ")!=-1)
	{
              			alert("Enter numeric value");
                              document.f1.labour.select();
			return false;
                }



if(document.f1.dt.value.length<=0)
 {
   
alert('Enter date');
document.f1.dt.focus();
return false; 
}

if(document.f1.regno.value.length<=0)
 {
   
alert('Enter RegNo');
document.f1.regno.focus();
return false; 
}

if(document.f1.model_det.value.length<=0)
 {
   
   alert('Enter model details');
document.f1.model_det.focus();
return false; 
}




if((document.f1.instype.value=='INSURANCE')&& (document.f1.insurance.value=='SELECT'))
 {
alert('Please select insurance company');
document.f1.insurance.focus();
return false; 
}

 var str=document.getElementById("instype").value;
var str1=str.toUpperCase();   
var n=str1.indexOf("INSURANCE");
//alert (n);
 if(n>=0) {
if(document.f1.policereport.value.length<=0)
 {
alert('Enter police report');
document.f1.policereport.focus();
return false; 
}
if(document.f1.fileno.value.length<=0)
{
   
alert('Enter File no');
document.f1.fileno.focus();
return false; 
}
if(document.f1.policyexcess.value.length<=0)
{
   
alert('Enter Policy excess');
document.f1.policyexcess.focus();
return false; 
}

if(document.f1.depreciation.value.length<=0)
{
   
alert('Enter Depreciation');
document.f1.depreciation.focus();
return false; 
}

}

if(document.f1.estd.value.length<=0)
 {
   
   alert('Enter estimate Date');
document.f1.estd.focus();
return false; 
}
if(document.f1.deldt.value.length<=0)
 {
   
   alert('Enter delivery Date');
document.f1.deldt.focus();
return false; 
}
if(document.f1.km.value.length<=0)
 {
   
   alert('Enter Kilometer');
document.f1.km.focus();
return false; 
}

if(document.f1.mobile.value.length<=0)
{
   
alert('Enter Mobile No');
document.f1.mobile.focus();
return false; 
}

if(document.f1.receivedby.value.length<=0)
 {
alert('Enter Received By');
document.f1.receivedby.focus();
return false; 
}
}




  var rawTags;
   var inputField;
   var  initInputFieldValue;
   var dataList;
    var initNbVirgules ;




<?



$select=mysqli_query($db,"select * from vehicle_master where brcode='$brcode' ") or die("ERR6:".mysqli_error($db));
  $reg="[";

  $chno="[";
 while($row=mysqli_fetch_array($select))
 
   {
        $reg.='"'.$row[1].'",';
        $chno.='"'.$row[9].'",';

   
    } 

  
   $reg.="]"; 
   $chno.="]"; 
  ?>

   


  function xx(str,event,this1)
  {
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
 


   if(str=='regno'){
    
   rawTags=<?echo $reg;?>;
   }
   else
  rawTags=<?echo $chno;?>;



 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;


	// vide la liste initiale (pas utile si elle est vide au début) // FIXME

	while(dataList.childNodes.length > 0) {
		dataList.removeChild(dataList.childNodes[0]);
	}

	// la recréé avec les tags de l?array

	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!='')){
            
           var itemval=document.getElementById(str).value;
           getval(str,itemval);
            handleEnter(this1, event);
    }

 }



 /* ********* below function is to get other values from vehmast as per regno or chasisno ********* */

 function getval(str,val){

    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("txtHint").innerHTML=xmlhttp.responseText;

         if(str=='regno'){

          document.getElementById("chasisno").value=document.getElementById("cno").value;
          document.getElementById("owner").value=document.getElementById("ow").value;
          document.getElementById("customer").value=document.getElementById("ac_ow").value;
	  document.getElementById("model_det").value=document.getElementById("mod_dat").value;
         }
      if(str=='chasisno'){

          document.getElementById("regno").value=document.getElementById("rno").value;
          document.getElementById("owner").value=document.getElementById("ow").value;
           document.getElementById("customer").value=document.getElementById("ac_ow").value;
	    document.getElementById("model_det").value=document.getElementById("mod_dat").value;
         } 
       document.getElementById("textfield8").value=document.getElementById("tel_ph").value;
       document.getElementById("textfield9").value=document.getElementById("tel_mob").value;
       document.getElementById("textarea").value=document.getElementById("cus_addr").value;
       document.getElementById("textfield10").value=document.getElementById("cus_email").value;
       document.getElementById("make").value=document.getElementById('mk').value;
       document.getElementById("model").value=document.getElementById("mod").value;
          
        
     
      }
    }
xmlhttp.open("GET","getval_gateentry.php?id="+str+"&& val="+val,true);
xmlhttp.send();
}


 function print_preview(gateno){

  window.open('print_est_order.php?gateno='+gateno);
 }
</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;
}
#pg{
       text-decoration:none;
       text-align: center;
       vertical-align: top;
}
.pgbtn{
      float:left;
margin-left: 10px;
height: 20px;
line-height: 22px;
text-align:center;
background-color:#fbfbfb;
border:1px solid #b7b7b7;
color:#606060;
cursor:pointer;
display:inline-block;
font:bold 12px/100% Arial,sans-serif;
       
}


#msg {
    height:80px auto;
    background-color:grey;
    padding:2px;
    margin-top:0px;
    border-bottom:5px solid white;
    border:5px solid #F8F8FF;
    width:150px auto;
    text_align:center;
    display: none;
    position: fixed; left: 600px; top: 0; 
    z-index: 10;
    opacity: 0.8;
    z-index: 999;
    color:white;
     }
 
  .show_hide {
    display:none;
    }


/*  code below for search button* /


/* reset webkit search input browser style */
input[type=search] {
	outline: none;
}
input[type=search] {
	-webkit-appearance: textfield;
	-webkit-box-sizing: content-box;
	font-family: inherit;
	font-size: 100%;
}
input[type=search]::-webkit-search-decoration,
input[type=search]::-webkit-search-cancel-button {
	display: none; /* remove the search and cancel icon */
}

/* search input field */
input[type=search] {
	background: #ededed url(images/search-icon.png) no-repeat 9px center;
	border: solid 1px #ccc;
	padding: 9px 10px 9px 32px;
	width: 45px;
	
	-webkit-border-radius: 10em;
	-moz-border-radius: 10em;
	border-radius: 10em;
	
	-webkit-transition: all .5s;
	-moz-transition: all .5s;
	transition: all .5s;
}
input[type=search]:focus {
	width: 130px;
	background-color: #fff;
	border-color: #6dcff6;
	
	-webkit-box-shadow: 0 0 5px rgba(109,207,246,.5);
	-moz-box-shadow: 0 0 5px rgba(109,207,246,.5);
	box-shadow: 0 0 5px rgba(109,207,246,.5);
}

/* placeholder */
input[type=search]:-moz-placeholder {
	color: #999;
}
input[type=search]::-webkit-input-placeholder {
	color: #999;
}

#reg_sea_bttn{

       background-color: #fff;
	border-color: #6dcff6;
	
	-webkit-box-shadow: 0 0 5px rgba(109,207,246,.5);
	-moz-box-shadow: 0 0 5px rgba(109,207,246,.5);
	box-shadow: 0 0 5px rgba(109,207,246,.5);
      border: solid 1px #ccc;
	padding: 9px 10px 9px 2px;
	width: 30px;
	
	-webkit-border-radius: 10em;
	-moz-border-radius: 10em;
	border-radius: 10em;
	
	-webkit-transition: all .5s;
	-moz-transition: all .5s;
	transition: all .5s;
       outline: none;
        -webkit-appearance: textfield;
	-webkit-box-sizing: content-box;
	font-family: inherit;
	font-size: 100%;

 }

/* #sea_td{

       background-color:#ededed;
	border-color: #6dcff6;
	
	-webkit-box-shadow: 0 0 5px rgba(109,207,246,.5);
	-moz-box-shadow: 0 0 5px rgba(109,207,246,.5);
	box-shadow: 0 0 5px rgba(109,207,246,.5);
      border: solid 0px #ccc;

	
	
	-webkit-border-radius: 10em;
	-moz-border-radius: 10em;
	border-radius: 10em;
	
	-webkit-transition: all .5s;
	-moz-transition: all .5s;
	transition: all .5s;
       outline: none;
     
	-webkit-box-sizing: content-box; 
	


 }*/




	
</style>
<body bgcolor="#0033FF">
<div class='cont'>

<?php include('includes/top.php'); ?>
<br>
<table class="container"><tr><td>


	<!--<link type="text/css" href="css/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
		<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
		<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>-->
<script type="text/javascript">
/* $(function(){

$(".regno").live("keydown.autocomplete",function(){

$regno = $(this);

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

		$.ajax({
			url: "search1.php",
			dataType: "json",
			data: "key="+$regno.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {
					return {
						label: item.regno+' | '+  item.chasisno + '| '+ item.make +'|'+item.model    ,
						value: item.regno,
						name:item.chasisno,
						qty:item.make,
						price:item.model,
						


					}
				}));
			}
		});
	}
	
,
	minLength: 2,
	select: function( event, ui ) {

	$row.find('.chasisno').val(ui.item.name);
	$row.find('.make').val(ui.item.qty);
	$row.find('.model').val(ui.item.price);
	
	
	
	 }
	
	});

					
});


}); */
function pgnfn(str){
            document.getElementById('pgbtn'+str).style.background = "#ccc";
            document.f1.entrydate.focus();
}
</script>
<?
$xx=$_GET['id']+1;
?>
<body onload='pgnfn(<? echo $xx;?>)'>




<link href="css1/xp.css" type="text/css" rel="stylesheet" media="print,screen"  />


<?

$tbl="estentry";
//mysqli_query($db,"drop table $tbl");


mysqli_query($db,"CREATE TABLE $tbl (gateno double(10,2) default 0,jcno double(10,2) default 0,vehiclename varchar(200),model varchar(20),regno varchar(20),chasisno varchar(50),policereport varchar(100),instype varchar(20),insurance varchar(200),labour double(10,2) default 0,receivedby varchar(200),entrydate datetime,duedate date, brcode varchar(20),colour varchar(20),customer varchar(200),owner varchar(200),address varchar(250),license varchar(200),remarks varchar(100),telephone varchar(100),mobile varchar(100),email varchar(100),fileno varchar(50),jobtype varchar(20),policyexcess double(10,2),others double(10,2),depreciation double(10,2),estdate datetime,del_dt datetime)");

//	mysqli_query($db,"delete from $tbl");


if($sv)
{

$remarks='';
$i=0;

foreach($comp as $a)
{
  
  $comp[$i]=$a;
  $remarks.=$comp[$i]."*";
  $i++;
 }



$entrydate2=explode(' ',$dt);
$entrydate1=explode('-',$entrydate2[0]);
$entrydate=$entrydate1[2].'-'.$entrydate1[1].'-'.$entrydate1[0].' '.$entrydate2[1];

$estdate2=explode(' ',$estd);
$estdate1=explode('-',$estdate2[0]);
$estdate=$estdate1[2].'-'.$estdate1[1].'-'.$estdate1[0].' '.$estdate2[1];



$del_dt2=explode(' ',$deldt);
$del_dt1=explode('-',$del_dt2[0]);
$del_dt=$del_dt1[2].'-'.$del_dt1[1].'-'.$del_dt1[0].' '.$del_dt2[1];
 


  $sql="insert into $tbl values('$gateno','$jcno','$make','$model','$regno','$chasisno','$policereport','$instype','$insurance','$labour','$receivedby','$entrydate',
'$duedate','$brcode','$colour','$customer','$owner','$address','$license','$remarks','$telephone','$mobile','$email','$fileno','$jobtype','$policyexcess','$others','$depreciation','$estdate','','0','$km','$del_dt','$work_status','$model_det',' ','0000-00-00','0','0000-00-00','$entrydate','0','0000-00-00')";
 	
	mysqli_query($db,$sql) or die(mysqli_error($db));


// print"<script>window.open('print_serv_order.php?gateno=$gateno');</script>"; 

}



if($del)
{
  //mysqli_query($db,"delete from machmaster where code='$code'");
}
?>
<title>World Wide Automotive Center</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="scripts/jquery-latest.js"></script>
<body background="back_ground.jpg">
<form name='f1' action='<?print $PHP_SELF?>'  method='post'> 

<br>
<table class="container" bgcolor="#0033FF"><tr><td>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  Insurance >>Estimate Entry</font>
<br>
<center>
<body bgcolor="#0033FF">





<form action="" method="get" name='f1' >
<table width="100%" border="1" cellpadding="1" cellspacing="1" align="center" class='form'>
  <tr>
    <td colspan="7" bgcolor="#666"><h3 style="color:#fff"><strong>Gate entry</strong></h3></td>
    </tr>
  <tr>
    <td width="135">Serial Number</td>

<?
 $jcres=mysqli_query($db,"select max(gateno) from estentry where brcode='$brcode'");
 $jcrow=mysqli_fetch_row($jcres);
 if($jcrow[0]<=0)
   $gateno=1;
 else
  $gateno=($jcrow[0]+1);
?>

    <td colspan="4"><input name="gateno"  type="text" id="gateno"   this.focus() size="40" value='<?print $gateno?>'  onkeypress="return handleEnter(this, event)"/></td>
    <td width="164">job card number	</td>

<?
 $jcres=mysqli_query($db,"select max(jcno) from estentry where brcode='$brcode'");
 $jcrow=mysqli_fetch_row($jcres);
 if($jcrow[0]<=0)
   $jcno=1;
 else
  $jcno=($jcrow[0]+1);
?>
    <td width="327"><input  name="jcno" type="text" id="textfield7" size="40" value='<?print $jcno?>'  onkeypress="return handleEnter(this, event)"/></td>
   
   
  </tr>
  <tr>
    <td >Date and Time</td>
  <td><input type="Text" id="demo2" name = 'dt' maxlength="25" size="37" readonly onkeypress="return handleEnter(this, event)"/>
<img src="img/cal.gif" onclick="javascript:NewCssCal ('demo2','ddMMyyyy','dropdown',true,'24',true)"  style="cursor:pointer"/>
</td><td></td><td></td><td></td>
    <td width="164" >service type</td>
    <td width="327"><select name="instype" id="instype" onkeypress="return handleEnter(this, event)" onchange="fld_active(this.value)" style="width:345px;">
    <option>--select--</option>

 <?
 $qry=mysqli_query($db,"select jobtype from jobtype_master where brcode='$brcode'");
 while($qry1=mysqli_fetch_row($qry))
 {
  print "<option>$qry1[0]</option>";
 }
 ?>

</select></td>
  </tr>

  <tr>
    <td >Registration Number</td>
    <td colspan="4"><input name="regno" type="text"   id="regno"   size="40"  class="regno"   autocomplete='off' list='htmlListTags'  onkeypress='xx(this.id,event,this)' /></td>
    <td width="164">Insurance company</td>
    <td width="327"><select name="insurance" id="insurance" onkeypress="return handleEnter(this, event)" style="width:345px;" >
      <option>--SELECT--</option>
      <?
 $empre=mysqli_query($db,"select cname from insmaster");
 while($emprow=mysqli_fetch_row($empre))
 {
  print "<option>$emprow[0]</option>";
 }
?>
    </select></td>
  </tr>
  <tr>

    <td >model</td>
    <td colspan="4"><input name="model" type="text" id="model" size="40"  onkeypress="return handleEnter(this, event)" class="model"/></td>
<td width="164">year</td>
    <td width="327"><input name="model_det" type="text" id="model_det" size="40"  onkeypress="return handleEnter(this, event)" class="model_det"/></td>
  </tr>
  <tr>
<td >Make</td>
 <td colspan="4"><input name="make" type="text" id="make" size="40"  onkeypress="return handleEnter(this, event)" class="make"/></td>
    <td width="164">Color</td>
   <td width="327"><input name="colour" type="text" id="colour" size="40" onKeyPress="return handleEnter(this, event)" class="colour"/></td>

</tr>
<tr>
    
<td >Police Report</td>
    <td colspan="4"><input name="policereport" type="text" id="policereport" size="40" onKeyPress="return handleEnter(this, event)"/></td>
 
    
    <td width="164">ChasisNo</td>
    <td width="327"><input name="chasisno" type="text" id="chasisno"  size="40"  class="chasisno"   autocomplete='off' list='htmlListTags'  onKeyup='xx(this.id,event,this)' /></td>
</tr>
<tr>    
<td >Ministry Description</td>
    <td colspan="4"><input name="fileno" type="text" id="fileno" size="40" onKeyPress="return handleEnter(this, event)"/></td>
 
    
    <td width="164">Labour</td>
    <td width="327"><input name="labour" type="text" id="labour" size="40" onKeyPress="return handleEnter(this, event)"/></td>
  </tr>
<tr>  
<td >Claim No.</td>
    <td colspan="4"><input name="jobtype"  id="jobtype" size="40" onKeyPress="return handleEnter(this, event)"/>

</td>
    <td width="164">Policy Excess</td>
    <td width="327"><input name="policyexcess" type="text" id="policyexcess" size="40" onKeyPress="return handleEnter(this, event)"/></td>
 </tr>
<tr>   
<td >Others Deductions</td>
    <td colspan="4"><input name="others" type="text" id="others" size="40" onKeyPress="return handleEnter(this, event)"/></td>
 
    
    <td width="164">Depreciation</td>
    <td width="327"><input name="depreciation" type="text" id="depreciation" size="40" onKeyPress="return handleEnter(this, event)"/></td>
 </tr>

<tr><td>Estimate Type </td><td colspan="4"><select name="work_status" id="work_status" onkeypress="return handleEnter(this, event)" style="width:345px;" >
      <option>Primary Estimate</option>
      <option>Secondary Estimate</option>


    </select>

</td>

   
<td width="164">Estimated Date and time </td>
    <td width="327"><img src="img/cal.gif" onclick="javascript:NewCssCal ('demo1','ddMMyyyy','dropdown',true,'24',true)"  style="cursor:pointer"/>
<input type="Text" id="demo1" name = 'estd' maxlength="25" size="37" readonly onKeyPress="return handleEnter(this, event)"/>
</td>
 
    </tr>
<tr>
<td >Kilometer </td><td colspan="4"><input name="km" type="text" id="km" size="40" onKeyPress="return handleEnter(this, event)"/></td>
<td width="164">Delivery Date and time </td>
    <td width="327"><img src="img/cal.gif" onclick="javascript:NewCssCal ('demo','ddMMyyyy','dropdown',true,'24',true)"  style="cursor:pointer"/>
<input type="Text" id="demo" name = 'deldt' maxlength="25" size="37" readonly onKeyPress="return handleEnter(this, event)"/>
</td>
</tr>
 


  <tr>
    <td colspan="7" height="4px" bgcolor="#666"><h3 style="color:#fff"><strong>Owner's Details</strong></h3></td>
    </tr>
  <tr>
    <td >Customer Account</td>
    <td colspan="4" id=><select name='customer' id='customer' onkeypress="return handleEnter(this, event)"  style="width:345px;">
<option></option>
<?
$i=1;
$re=mysqli_query($db,"select * from customer order by acname");
while($row=mysqli_fetch_array($re))
{
 print "\n<option value='$row[acname]'>$row[acname]</option>";
 print "\n<script>adr[$i]='$row[addr1] - $row[city] - $row[dist] - $row[stat] - $row[pin] - $row[phone1]' </script>";
 $i++;
}
?>
</select> </td>




</td>
    <td width="164">telephone</td>
    <td width="327"><input name="telephone" type="text" id="textfield8" size="40" onKeyPress="return handleEnter(this, event)"/></td>
  </tr>
  <tr>
    <td >Owner's Name</td>
    <td colspan="4"><input name="owner" id="owner" type="text" id="textfield6" size="40" class='owner' onKeyPress="return handleEnter(this, event)"/></td>
    <td width="164">mobile</td>
    <td width="327"><input name="mobile" type="text" id="textfield9" size="40" onKeyPress="return handleEnter(this, event)"/></td>
  </tr>
  <tr>
    <td >address</td>
    <td colspan="4"><textarea name="address" cols="38" id="textarea" onKeyPress="return handleEnter(this, event)"></textarea></td>
    <td width="164">email</td>
    <td width="327"><input name="email" type="text" id="textfield10" size="40"  onkeypress="return handleEnter(this, event)"/></td>
  </tr>
  <tr>
    <td >license number</td>
    <td colspan="4"><input name="license" type="text" id="textfield5" size="40" onKeyPress="return handleEnter(this, event)"/></td>
 <td >Received By </td><td colspan="4"><select name="receivedby" id="receivedby" style="width:345px;" onKeyPress="return handleEnter(this, event)"/>
<option>--SELECT--</option>
<?
$xx=mysqli_query($db,"select * from empprofile where Desig='SERVICE ADVISOR'");
while($xx1=mysqli_fetch_array($xx))
{
 print "\n<option >$xx1[EName]</option>";

}
?>
</select></td>
 
  </tr>
  <tr>
    <td >Terms and Conditions<input type='button' value='+' name='compl_btn' id='compl_btn' onclick='add_comp()' /></td>
    <td colspan="6" ><fieldset><legend>condition</legend>
       <table id='comp_table' name='comp_table'  border='1' style="border:1px solid grey; border-collapse:collapse;"><tr><td>1</td><td>
<input type='text' name=comp[] id='comp1'  class='comp'  size="40"  placeholder='Conditions..'/>
</td><td><input onClick='delrow(this)'  value='X' type='button' class='del' ></td></tr></table>

     </fieldset>
<!--<textarea name="remarks" cols="88" id="textfield2"></textarea>--></td>
    </tr>

    
    
    



<tr><td colspan=8 align=center bgcolor='lightsteelblue'>
<input type=submit value='Save' name='sv' onclick="return Validate()"> 
</td></tr>




</table>
</form>
<br><br>


<?



if(!isset($_GET['id'])){
     $_GET['id']=0;
  }
if($search_bttn){

  $fldnm='regno';
  $fldval=$sea_reg;
 if($sea_jcno !=''){

  $fldnm='jcno';
  $fldval=$sea_jcno;

 }
  $qry=mysqli_query($db,"select count(*) from estentry where brcode='$brcode' and $fldnm='$fldval' ");
}
else{
$qry=mysqli_query($db,"select count(*) from estentry where brcode='$brcode'");
 }



$qry1=mysqli_fetch_array($qry);
$cnt=$qry1[0];


if($search_bttn){
 $rowcnt=$cnt;
}
else{

$rowcnt=50;

}

$pgno=floor($cnt/$rowcnt);
if(($cnt%$rowcnt)>0){
   $pgno=$pgno+1;
}
print "<table align='center' id='pagen' width='100%'><tr>";

  if($pgno>6){
      
     if($_GET['id']>0)
        $m=$_GET['id']-1;
     else
        $m=$_GET['id'];
      
  }
$nxtid=$_GET['id']+2;
$nxtval=$_GET['id']+1;
$prvid=$_GET['id']-2;
$prval=$_GET['id']-1;
$flg=1;
for($i=$m;$i<$pgno;$i++){
    $j=$i+1;
     
    if(($flg==1)&& ($_GET['id']>0)){
       print "<td><a href='estmtentry.php?id=$prval' id='pg'><input type='button' class='pgbtn' id='pgbtn".$prvid."' value='Previous' /></a></td>";
    }

    if(($_GET['id']==2) && ($flg==1)){
       print "<td><a href='estmtentry.php?id=0' id='pg'><input type='button' class='pgbtn' id='pgbtn1' value='1' /></a></td>";
    }

    if(($_GET['id']>=3) && ($flg==1)) {
       print "<td><a href='estmtentry.php?id=0' id='pg'><input type='button' class='pgbtn' id='pgbtn1' value='1' /></a></td><td>...</td>";
    }

    if($flg<5){
       print "<td><a href='estmtentry.php?id=$i' id='pg'><input type='button' class='pgbtn' id='pgbtn".$j."' value='".$j."' /></a></td>";
    }

    if($flg==5){
       print "<td>.</td><td>.</td><td>.</td>"; 
       $i=$pgno-2; 
    }

    if($flg==6){  
 	  
       print "<td><a href='estmtentry.php?id=$i' id='pg'><input type='button' class='pgbtn' id='pgbtn".$j."' value='".$j."' /></a></td>";
 	print "<td><a href='estmtentry.php?id=$nxtval' id='pg'><input type='button' class='pgbtn' id='pgbtn".$nxtid."' value='Next' /></a></td>";  
    }
  
    $flg++;
}


print "<td width='480'></td><td width='400' align='right' id='sea_td'><form name='f2' action='estmtentry.php' method='post'><input type='search' name='sea_reg' placeholder='Search By Regno'>&nbsp;<input type='search' name='sea_jcno' placeholder='Search By Jcno'><input type='submit' value='Go' id='reg_sea_bttn' name='search_bttn'/></form></td></tr></table>";
?>



<?



$lmt1=$_GET['id']*$rowcnt;
$k=$lmt1+1;

if($search_bttn){

  $fldnm='regno';
  $fldval=$sea_reg;

 if($sea_jcno !=''){

  $fldnm='jcno';
  $fldval=$sea_jcno;

 }
 

 $result=mysqli_query($db,"select * from estentry where brcode='$brcode' and $fldnm='$fldval'  order by jcno desc limit $lmt1,$rowcnt");

}

else{
$result=mysqli_query($db,"select * from estentry where brcode='$brcode' order by jcno desc limit $lmt1,$rowcnt ");
}
?>

<table cellspacing=1 cellpadding=5 class='report'>
    <th>sl no

    <th>job card no.
    <th>date 
    <th>vehicle
    <th>register number
    <th>owner
    <th>Action
  
<?

while($row=mysqli_fetch_array($result))
{
?>

  <form action='editestmt.php'><input type=hidden name='jcno' value=<? echo $row[1] ?>>
   <tr>
    <td ><? echo $k++;?></td>
    <td><?print (int)$row[1]?></td>
    <td ><?print $row[11]?></td>
    <td ><?print $row[2]?></td>
    <td ><?print $row[4]?></td>
    <td ><?print $row[16]?></td>
    <td ><input type=submit value='Edit' name='edit'><input type=button value='Print' name='print' onclick="print_preview('<?print $row[0]; ?>')"></td>
  </tr>
</form>
<? 
}

?>


 </table>


<datalist id="htmlListTags"></datalist>
<div id='txtHint'></div>
</body>
</html>


</td></tr></table>

<script>


  var cur=2;
  var comp=[];
  

  function add_comp(){
 
     
     var rowCount = document.getElementById('comp_table').rows.length;
     var x=document.getElementById('comp_table').insertRow(rowCount);
     var a=x.insertCell(0);
     var b=x.insertCell(1);
     var dd=x.insertCell(2);
     a.innerHTML=cur;
     b.innerHTML="<input type='text'  name=comp[] id=comp"+cur+"  class='comp'  placeholder='Conditions..'/>";  
     dd.innerHTML="<input onClick='delrow(this)'  value='X' type='button' class='del' >";
     cur++;

  }

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

</script>
<style>
.comp{
  width:250px;
  }
</style>

