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

if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Obsrevation Report</title>

<script type="text/javascript" src="js/jquery.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>

<script type="text/javascript">
	window.onload = function(){

		new JsDatePick({
			useMode:2,
			target:"inputField1",
			dateFormat:"%Y-%m-%d"
			
		});
              
	};

</script>


<script>
       var  cur3=1;
       var obs=[];

        function newrow(r){
              var rowCount = document.getElementById('myTable3').rows.length;
              var x=document.getElementById('myTable3').insertRow(rowCount);
              var a=x.insertCell(0)
		var y=x.insertCell(1)
		var y1=x.insertCell(2);

              a.innerHTML=cur3;
              y.innerHTML="<textarea   name=obs[] id=obs"+cur3+"></textarea>"; 
              y1.innerHTML="<input type='button'  onClick='delrow3(this)' value='X' >";
           
              cur3++; 

         }

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

   

       </script>


<script>


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

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

   
  	 var values1 = $("#f1").serialize();
 	

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

 

           	 if(parseInt(msg)!=0)    

          	  {

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

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

	 }); 
	 }); 


</script>

<script type="text/javascript">
 

</script>

<style>

  #tbl td{
     
    border-collapse:collapse;
    border:1px solid grey;
    }

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


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









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


<style>
.tble1 input {
background-color:transparent;
border: 0px solid;
height:20px;
//width:160px;
color:black;
}
.tble1
{
border-collapse:collapse;
border:1px solid silver;
margin-top:20px;
}	
.tble1 td, th
{
border-collapse:collapse;
border:1px solid silver;
}


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

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

}
#tbl1 td{
 text-align:left;

}
#tbl2{
 //margin:50px 20px 10px 20px;
 width:100%;
}
#tbl3{
 width:100%;
border-collapse:collapse;

}
#myTable{
width:100%;
border-collapse:collapse;

}
#myTable2{
width:100%;
border-collapse:collapse;
}
#myTable td,th{
border:1px solid grey;
}
#myTable2 td,th{
border:1px solid grey;
}
#tbl3 td,th{
border:1px solid grey;
}
#jctbl{
box-shadow: 0px 0px 10px 4px rgba(119, 119, 119, 0.75);
-moz-box-shadow: 0px 0px 10px 4px rgba(119, 119, 119, 0.75);
-webkit-box-shadow: 0px 0px 10px 4px rgba(119, 119, 119, 0.75);
}
</style>

      <style>
         

        #myTable3 th{

         border-collapse:collapse;

         border:1px solid white;

      }

       #myTable3 td{

        // background-color:white;
         }
     </style>
<?php
  $re=mysqli_query($db,"select max(invno) from invoice where brcode='$brcode' ");
//print "select max(invno) from invoice where brcode='$brcode' ";
     if(mysqli_num_rows($re)<1)
       {
           $inv=1; 
       }
       else
       {
        $row=mysqli_fetch_array($re);
         $inv=$row[0]+1;
        }
?>

<?php include('includes/top.php'); ?>
<body style="text-align: center;"  >

<div id="msg">
 <p align='right' ><a href="#" class="hide_show" ><img src="images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a></p>

  <div id='msgbox'></div>
</div>  

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

            <!-- <td  style="text-align:right;"><input style="height:32px;width:110px;" value="Edit"  type="submit" onClick="window.open('editestimate1.php')">  --> 
           <td  style="text-align:right;"><input style="height:32px;width:110px;" value="Print"  type="submit" onClick="window.open('print_observ_repo1.php')">
          <!--<a href="#" class='svbttn' id='svbttn1' style="text-decoration:none;"><input type='button' style="height:32px;width:110px;"  value='  Update form  ' name='upd' style="font-size:15; font-weight:bold" ></a>-->
<!--<a href="#" class='svbttn' id='svbttn2' style="text-decoration:none;"><input type='button' style="height:32px;width:200px;"  value='Update form and Print Bill' name='updprn' style="font-size:15; font-weight:bold">-->
</td></tr>
	
<tr><td id='tbltd1' colspan='6'>

<div>
 <fieldset style="border:2px solid grey; border-style:dotted;">
            <legend style="text-align:center;">NEW OBSERVATION</legend>

<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>
Select Jcno.<select name='jcno'><option>--select--</option>
<?
 $qry=mysqli_query($db,"select distinct(jcno) from gateentry where invno='0' and brcode='$brcode' order by jcno");
while($row=mysqli_fetch_array($qry))
{
  
     print "<option>$row[0]</option>";
    
}
?>
</select>
<input type=submit value='Show ->' name='show'>
</form>

<?
     if($show)
{
$qry2=mysqli_query($db,"select * from observation_repo where jcno='$jcno' and brcode='$brcode'");
$row2=mysqli_fetch_array($qry2);
?>
             <form id='f1' name='f1'>
<center>
        <fieldset style="border:2px solid white; border-style:dotted;"><legend></legend>
         <table width='100%' id='jctbl'>
       <tr><td align='left'>Add Observation</td><td align='right'>Jcno.<input type='text' name='jcno' value='<? echo $jcno;?>' style='border:0px solid black;' size='4' readonly></td>
        </tr></table>
       <table id='myTable3' >

 <?        
  $qry1=mysqli_query($db,"select * from observation_repo where jcno='$jcno' and brcode='$brcode'");
  $i=1;
  while($row1=mysqli_fetch_array($qry1)){
       		
	       print "<tr><td>".$i."</td><td><textarea name='obs[]' id='obs1'>$row1[2]</textarea></td><td><input type='button' name='del' value='X' onclick='delrow3(this)'/></td></tr>";
              $i++;
              print "<script>cur3++;</script>";
   }
   
  if($i<2){ 
           for($j=$i;$j<5;$j++){
   		print "<tr><td>".$j."</td><td><textarea name='obs[]' id='obs1'></textarea></td><td><input type='button' name='del' value='X' onclick='delrow3(this)'/></td></tr>";
              $i++;	
              print "<script>cur3++;</script>";
           }
  } 
?>
	</table>
        
        <input type='hidden' id='updflg' name='updflg' value='2'/>
       <input type='button' name='obs_save' id='obs_save' value='Save'>
	<a href='#' id='addbutton' onclick='newrow(this)'> <input type='button' name='addnew' value='Add new'></a>

     </fieldset></form>
</center>
<div id='msgbox1' style="height:30px;"></div>
<?
}
?>