<?php
session_start();

include("config.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'])
		or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

$query1="select grid_color1,grid_color2 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}



if($_GET['lcode']!="") { 

	$query1="select assets_id,assets_ref as Ledger_number, assets_name as Ledger_name from assets where assets_ref='".$_GET['lcode']."'";

    $result1=mysql_query($query1,$connection) or die(mysql_error());
	
	while($rows=mysql_fetch_array($result1)){
    	extract($rows);
		
	}

    $post="1";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Select Ledgers</title>
<script type="text/javascript" language="javascript">



function dokey(e,obj,rowindx){

	//var vindx = rowindx;
	if (!e) { var e = window.Events;}
	
    var intKey = (window.Events) ? e.which : e.keyCode;
	
	if (intKey == 40) 
		{	var xx = rowindx + 1;
			var itm = 'ledger_number' + '[' + xx + ']';
			document.getElementById(itm).focus();
		}
	else
	if (intKey == 38) 
		{	var xx = rowindx - 1;
			var itm = 'ledger_number' + '[' + xx + ']';
			document.getElementById(itm).focus();
		}
}

function clearform()
{
  document.form1.PLedger_Name.value='';
  document.form1.PLedger_Number.value='';

}
</script>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style1 {
	color: #333333;
	font-weight: bold;
}
.style2 {
	color: #999999;
	font-weight: bold;
}
.style3 {color: #999999}
-->
</style></head>

<body >
<form id="form1" name="form1" method="post" action="">
  <table width="700" border="0" align="center">
    <tr>
      <th colspan="5" bgcolor="#DDDDDD"><span class="style1"> Ledgers </span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD" width="136"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Ledger  <br> Number / Name</span></td>
      <td bgcolor="#DDDDDD" width="100"><input type="text" name="PLedger_Number" value="<?php echo $PLedger_Number; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $Ledger_number; ?>"></td>
        <input name="assets_id" type="hidden" id="assets_id"  value="<?php echo $assets_id; ?>"></td>
      <td bgcolor="#DDDDDD" width="450"><input type="text" name="PLedger_Name"  value="<?php echo $PLedger_Name; ?>" size='35'/>
	    <input type="Submit" name="Submit" value="Find" style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
		<input type="button" name="cancelbtn" value="Cancel" onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
        <input name="desc1" type="hidden" id="desc1" value="<?php echo $Ledger_name; ?>" />
        <input name="item1" type="hidden" id="item1" value="<?php echo $_GET['item']; ?>" />
        <input name="type" type="hidden" id="type" value="<?php echo $_GET['vtype']; ?>" />
        <input name="text1" type="hidden" id="text1" value="<?php echo $_GET['vtext1']; ?>" />
        <input name="text2" type="hidden" id="text2" value="<?php echo $_GET['vtext2']; ?>" />
        <input name="text1value" type="hidden" id="text1value" value="<?php echo $_GET['text1value']; ?>" /></td>
    </tr>
 
<?php if($post=="1") { ?>
<script type="text/javascript" language="javascript">

x=document.form1;

item1=x.item1.value;

if(item1=="1"){
 
opener.document.vehicle.assets_id.value   = document.form1.assets_id.value;
opener.document.vehicle.assets_ref.value   = document.form1.code1.value;
opener.document.vehicle.assets_name1.value = document.form1.desc1.value;
self.close();
}

</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td><span class="style2">Ledger Number </span></td>
      <td colspan="2"><span class="style2">Ledger Name </span></td>
    </tr>
<?php
$query1=" select assets_id,assets_ref, assets_name from assets ".
        " where ifnull(assets_ref,'') like '%".$PLedger_Number."%' ".
		" and assets_name like '%".$PLedger_Name."%' ".
		"  ";
		

$result1=mysql_query($query1,$connection) or die(mysql_error());
$i=0;
while($rows=mysql_fetch_array($result1)){
extract($rows);

$ct+=1;

if($ct%2==0)
{
	$Color="style='color:#0000FF;background-color:".$grid_color1."'";
	
	}else{
		
	$Color="style='color:#0000FF;background-color:".$grid_color2."'";	
}


?>
<?php
$lnk = "vtype=$vtype&vtext1=$vtext1&vtext2=$vtext2&text1value=$text1value";

//
    echo"<tr  $Color;>
      <td align='left'>
	  <a href='List_Asset.php?$lnk&assets_id=$assets_id&lcode=$assets_ref&item=".$_GET['item']."'>$assets_ref ";
	  //<input type='text' onkeydown='dokey(event,this,$i)' style='border-top:0px;border-left:0px;border-right:0px;border-bottom:0px'  name='ledger_number[$i]' //id='ledger_number[$i]' value='$Ledger_number' ></a></td>
      echo"<td align='left' colspan='2'><a href='List_Asset.php?$lnk&assets_id=$assets_id&lcode=$assets_ref&item=".$_GET['item']."'>
	  $assets_name</a></td>
    </tr>";


$i+=1;
}
?>

<script type="text/javascript" language="javascript">

//document.getElementById('assets_ref[0]').focus();
</script>
</table>
</form>
</body>
</html>

