<?
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>Muscat</title>
    <script src=" rightclick_deactive.js"></script> 
    <script src="datetimepicker_css.js"></script>
    <script type="text/javascript" src="scripts/jquery-latest.js"></script>
	<link type="text/css" href="includes/style1.css" rel="stylesheet" />
      <link type="text/css" href="css/form.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.1.min.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>




<script>




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

 }



 /* ********* 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;
          
        
     
      }
    }
xmlhttp.open("GET","getval_gateentry.php?id="+str+"&& val="+val,true);
xmlhttp.send();
}


function fld_active(str){
     alert (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()
{
        var x = document.f1.labour.value;


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

function Validate()
{
        var x = document.f1.policyexcess.value;


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

function Validate()
{
        var x = document.f1.depreciation.value;


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

function Validate()
{
        var x = document.f1.others.value;


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

</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>




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









        #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: rgb(181,189,200); /* 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;

}


 </style>

<script>

/** code below for drag the confirmation div */
window.onload = function(){
    draggable('conf_panel');
};

var dragObj = null;
function draggable(id)
{
    var obj = document.getElementById(id);
    obj.style.position = "absolute";
    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";
};
</script>


<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);
	
	
	/*log( ui.item ?
	"Selected: " + ui.item.label :
	"Nothing selected, input was " + this.value);
	*/
	 }
	
	});

					
});







});
</script>






<?php echo "<body onload='f1.entrydate.focus()'>\n"; ?>

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


<?




if($sv)
{

$remarks='';
$i=0;

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

//echo $remarks.$i;

$tbl='estentry';


$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')";
// mysqli_query($db,$sql) or die(mysqli_error($db));

 
$sql="update $tbl set gateno='$gateno',vehiclename='$make',model='$model',regno='$regno',chasisno='$chasisno',policereport='$policereport',instype='$instype',insurance='$insurance',labour='$labour',receivedby='$receivedby',entrydate='$entrydate',
duedate='$estdate',colour='$colour',customer='$customer',owner='$owner',address='$address',license='$license',remarks='$remarks',telephone='$telephone',mobile='$mobile',email='$email',fileno='$fileno',jobtype='$jobtype',policyexcess='$policyexcess',others='$others',depreciation='$depreciation',estdate='$estdate',kms='$km' ,deli_dt='$del_dt',work_status='$work_status',model_det ='$model_det' where jcno='$jcno' and brcode='$brcode'";


mysqli_query($db,$sql) or die(mysqli_error($db));



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

}



if($del)
{
  //mysqli_query($db,"delete from machmaster where code='$code'");
}
?>
<?

 $res=mysqli_query($db,"select * from estentry where jcno='$jcno' and brcode='$brcode'");
 $jrow=mysqli_fetch_array($res);
?>
<title>MUSCAT</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">



<div id="conf_panel" class="alist" style="display:none;">
 
<?
   
   $tot_payment=0;

   $outstanding=0;

   $sql=mysqli_query($db,"select sum(amt) from down_payment where jcno='$jcno' and brcode='$brcode'");
   $res=mysqli_fetch_array($sql);

    $adv=$res[0];


   if((mysqli_num_rows($sql)<=0)||($res[0]==''))
    {
      $adv=0; 
    }
 

   $sql1=mysqli_query($db,"select sum(gtot) from jcardparts where jcno='$jcno' and brcode='$brcode'");
   $res1=mysqli_fetch_array($sql1);

   $sql2=mysqli_query($db,"select sum(servamt),sum(dis) from jcardserv where jcno='$jcno' and brcode='$brcode'");
   $res2=mysqli_fetch_array($sql2);

   $tot_payment=$res1[0]+$res2[0]-$res2[1];

   if((mysqli_num_rows($sql1)<=0)&&(mysqli_num_rows($sql2)<=0))
       {
      $tot_payment=0; 
       }
   if($tot_payment>0){
      
       $outstanding=$tot_payment-$adv;
    }
?>  
   <form name='form2'>
  <table  border='1' class='conf_tbl' style="border_collpase:collapse;background-color:white;  " width='100%'>
  
 	  <tr><th colspan=2>Add Down Payment &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value='X' id='close'  onclick='close_div();'/></th></tr>
  
  	  <tr> <td> JobNo:</td> <td><input type='text' name='jobno' readonly value='<? echo $jcno;?>' size=8/></td></tr>

 	  <tr>  <td>Adv Amt: </td><td> <input type='text' name='down_amt' value='<? echo $adv; ?>' size=8 readonly/> </td></tr>

         <tr>  <td>Outstanding: </td><td> <input type='text' name='outstanding' id='outstanding' value='<? echo $outstanding; ?>' size=8 readonly/>
                                           <input type='hidden' name='tot' id='tot_val' value='<? echo $tot_payment; ?>' size=8 readonly/> </td></tr>

  	 <tr>  <td>Add New Amt: </td><td> <input type='text' name='down_amt' id='down_amt' value='0' size=8/> </td></tr>

 	 <tr>  <td>DPR Date: </td><td><input type="text" id="d1" value="<?echo date('d');?>"  name="d1"  size=1 >
                                     <input type="text" id="d2" value="<?echo date('m');?>"  name="d2"  size=1 >
                                     <input type="text" id="d3" value="<?echo date('Y');?>"  name="d3"  size=2 >
        </td></tr>

        <tr>  <td colspan=2>With A/c :<input type='radio' name='flag' id='with' value='yes' checked /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Without A/c:<input type='radio' name='flag' value='no' id='without'/> </td></tr>
  	 <tr>  <th colspan=2><input type='button' name='add_amt' value='Save' onclick="upd_down_amt('<? echo $jcno;?>' )"/> </td></tr>

  
  </table>
 </form>

</div>




<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()"  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="post">
<table width="100%" border="1" cellpadding="1" cellspacing="1" align="center" bgcolor="#0033FF">
  <tr>
    <td colspan="7" bgcolor="#666"><h3 style="color:#fff"><strong>Gate entry</strong></h3></td>
    </tr>
  <tr>
    <td width="135">Serial Number</td>

<?

  $gateno=($jrow[gateno]);
?>

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

<?

  $jcno=($jrow[jcno]);
?>
    <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="18"  value="<?print dateandtimetoHtml($jrow[entrydate])?>" readonly/>
<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)" >
      <option><?print $jrow[instype]?></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" value="<?print $jrow[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)" >
      <option><?print $jrow[insurance]?></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"  value="<?print $jrow[model]?>" 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"  value="<?print $jrow[model_det]?>" 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"  value="<?print $jrow[vehiclename]?>" 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" value="<?print $jrow[colour]?>" onKeyPress="return handleEnter(this, event)"/></td>

</tr>
<tr>
    
<td >Police Report</td>
    <td colspan="4"><input name="policereport" type="text" id="policereport" size="40" value="<?print $jrow[policereport]?>" 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" value="<?print $jrow[chasisno]?>"  autocomplete='off' list='htmlListTags'  onKeyup='xx(this.id,event,this)' onKeyPress="return handleEnter(this, event)" /></td>
</tr>
<tr>    
<td >Ministry Description</td>
    <td colspan="4"><input name="fileno" type="text" id="fileno" size="40" value="<?print $jrow[fileno]?>" onKeyPress="return handleEnter(this, event)"/></td>
 
    
    <td width="164">Labour</td>
    <td width="327"><input name="labour" type="text" id="labour" size="40" value="<?print $jrow[labour]?>" onKeyPress="return handleEnter(this, event)"/></td>
  </tr>
<tr>  
<td >Job Type</td>
    <td colspan="4"><input name="jobtype"  id="jobtype" size="40" value="<?print $jrow[jobtype]?>" onKeyPress="return handleEnter(this, event)"/>

</td>
    <td width="164">Policy Excess</td>
    <td width="327"><input name="policyexcess" type="text" id="policyexcess" size="40" value="<?print $jrow[policyexcess]?>" onKeyPress="return handleEnter(this, event)"/></td>
 </tr>
<tr>   
<td >Others Deductions</td>
    <td colspan="4"><input name="others" type="text" id="others" size="40" value="<?print $jrow[others]?>" onKeyPress="return handleEnter(this, event)"/></td>
 
    
    <td width="164">Depreciation</td>
    <td width="327"><input name="depreciation" type="text" id="depreciation" size="40" value="<?print $jrow[depreciation]?>" 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><?print $jrow[work_status]?></option>
        <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="18" value="<?print dateandtimetoHtml($jrow[estdate])?>" readonly/>
</td>
 
    </tr>
<tr>
<td >Kilometer </td><td colspan="4"><input name="km" type="text" id="km" value="<?print $jrow[kms]?>" size="40" /></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="18" value="<?print dateandtimetoHtml($jrow[deli_dt])?>" readonly/>
</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"><select name='customer' onkeypress="return handleEnter(this, event)">
<option><?print $jrow[customer]?></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"  value="<?print $jrow[telephone]?>" onKeyPress="return handleEnter(this, event)"/></td>
  </tr>
  <tr>
    <td >Owner's Name</td>
    <td colspan="4"><input name="owner" type="text" id="textfield6" size="40" class='owner' value="<?print $jrow[owner]?>"  onkeypress="return handleEnter(this, event)"/></td>
    <td width="164">mobile</td>
    <td width="327"><input name="mobile" type="text" id="textfield9" size="40" value="<?print $jrow[mobile]?>" onKeyPress="return handleEnter(this, event)"/></td>
  </tr>
  <tr>
    <td >address</td>
    <td colspan="4"><textarea name="address" cols="32" id="textarea"> <?print($jrow[address])?> </textarea></td>
    <td width="164">email</td>
    <td width="327"><input name="email" type="text" id="textfield10" size="40"  value="<?print $jrow[email]?>" onKeyPress="return handleEnter(this, event)"/></td>
  </tr>
  <tr>
    <td >license number</td>
    <td colspan="4"><input name="license" type="text" id="textfield5" size="40" value="<?print $jrow[license]?>" onKeyPress="return handleEnter(this, event)"/></td>
 <td >Received By </td><td colspan="4">
<select name="receivedby" id="receivedby" style="width:320px;" onKeyPress="return handleEnter(this, event)"/>
<option><? print $jrow[receivedby]; ?></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 >Customer Complaints<input type='button' value='+' name='compl_btn' id='compl_btn' onclick='add_comp()' /></td>
    <td colspan="6" ><fieldset><legend>complaint</legend>
       <table id='comp_table' name='comp_table'  border='1' style="border:1px solid grey; border-collapse:collapse;">
      <?
print "<script>var cur=1;</script>";
$cmpl = explode("*", $jrow[19]);

  $j=0;
  $k=1;
 foreach($cmpl as $a){
  if($cmpl[$j]!=''){
 ?>
 <tr><td><? echo $k;?></td><td>
       <input type='text' name=comp[] id='comp$j'  class='comp' value='<?print $cmpl[$j];?>'>
      </td><td><input onClick='delrow(this)'  value='X' type='button' class='del' ></td></tr>
  <?
$j++;
$k++;
print "<script>cur++;</script>";
  }
  }
  ?>
</table>

     </fieldset>

    </td>
    </tr>

<!--

<?
$result=mysqli_query($db,"select * from gateentry order by jcno");
print "<table cellspacing=1 cellpadding=5 class='report'>";
?>
<tr>
    <td><strong>sl no</strong></td>

    <td colspan="3" ><strong>job card no.</strong></td>
    <td ><strong>date </strong></td>
    <td ><strong>time</strong></td>
    <td ><strong>vehicle account</strong></td>
  </tr>
<?
$i=1;
while($row=mysqli_fetch_row($result))
{
?>

  
   <tr>
    <td ><?print $row[0]?></td>
    <td colspan="3" ><?print $row[1]?></td>
    <td ><?print $row[9]?></td>
    <td >&nbsp;</td>
    <td ><?print $row[4]?></td>
  </tr>
<? 
}
?>
-->



 </table>






</form>


<div id="msgbox" >
 
</div>


</body>
</html>
<Hr><input type=submit value='Save' name='sv'>

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

<script>
function valid()
{


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

if(document.f1.model.value.length<=0)
{
   
alert('Enter Model');
document.f1.model.focus();
return false; 
}
if(document.f1.estimatedate.value.length<=0)
 {
   
   alert('Enter Delivery Date');
document.f1.estimatedate.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; 
}

if(document.f1.policereport.value.length<=0)
 {
alert('Enter police report');
document.f1.receivedby.focus();
return false; 
}
if(document.f1.instype.value=='SELECT')
 {
alert('select proper value');
document.f1.instype.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; 
}

}
</script>


<CENTER>
<H3><font color='darkbrown'>Estimate Entry- EDIT</font></h3>
</center>
<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>
Select Jobcard No. <select name=jcno>
<?
$re=mysqli_query($db,"select jcno,regno from estentry where brcode='$brcode' order by jcno desc");
while($row=mysqli_fetch_row($re))
{
 print "<option value='$row[0]'>$row[0]-$row[1]</option>";
}
?>
</select>
<input type=submit value='Show ->' name='show'>
</form>



<div id='msg1'>
</div>
<datalist id="htmlListTags"></datalist>
<div id='txtHint'></div>



<script>




 function valid1()
 {
  if(document.f2.jcno.value.length<=0)
   {
    alert('Invalid jcno');
    return false
   }


 }


 
  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' />";  
     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); 
 }  

/** code below for down payment options  */
 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 upd_down_amt(jcno){

   if (document.getElementById('with').checked) {
               flag = document.getElementById('with').value;
    }

   if (document.getElementById('without').checked) {
               flag = document.getElementById('without').value;
    }

    var dt1= document.getElementById('d1').value;
    
    var dt2= document.getElementById('d2').value;

    var dt3= document.getElementById('d3').value;

    var dpr_dt=dt3+'-'+dt2+'-'+dt1;

    var down_amt= document.getElementById('down_amt').value;

    var outstanding= document.getElementById('outstanding').value;

    var job_amt= document.getElementById('tot_val').value;

    var rem=outstanding-down_amt;

    if(isNaN(down_amt)){
    
      alert('Invalid Amount');

      document.getElementById('down_amt').value=0;
   
      document.getElementById('down_amt').focus();

      return false;
    }

    /*  if((rem<0)&&(job_amt>0)){
    
      alert('Amount Not Matching');

      document.getElementById('down_amt').value=0;
   
      document.getElementById('down_amt').focus();

      return false;
    } 

   else
    { */

   	 document.getElementById('conf_panel').innerHTML="Loading...";

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

             			var input = document.getElementById ("myTable");
             			input.style.filter = 'alpha(opacity=' + 20 + ')';


         
        		}

      		}
    
   xmlhttp.open("GET","ajaxupd_down_amt.php?jcno="+jcno+"&& flg="+flag+"&& amt="+down_amt+"&&dpr_dt="+dpr_dt,true);
 xmlhttp.send(); 

  //}//else close

 }//function close


</script>



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

