<?php

session_start();
if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}


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

		
		
print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


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


function fillfield(value1,value2){
		var xx = document.getElementById(value2).value;	
		opener.document.vehicle.item_code.value=value1;
	    opener.document.vehicle.item_description.value=xx;	
		self.close();
		
	
	}

	





function clearform()
{	
  document.search.PRef.value='';
  document.search.action='Form_VehicleItemlist.php';
  document.search.submit();

}

function LoadForm() 
{
	x=document.search;
	x.PRef.focus();
	

}

function SetNextPage(startrange,perpage){
	document.search.action='';
  document.search.action='Form_VehicleItemlist.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SetPrvPage(startrange,perpage){
	document.search.action='';
  document.search.action='Form_VehicleItemlist.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}




function Viewclient(value1,value2){



opener.document.clientdt.agent_code.value=value1;
opener.document.clientdt.agent_name.value=value2;
opener.document.clientdt.keepcompany.value=1;
opener.clientdt.submit();


self.close();
}


</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}

a:visited {
	text-decoration: none;
	color: #0000FF;
}


.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; }
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #000000 ;font-size: 10px;}

</style>

</head>
<body >
<form name='search' method='post' action=''>
<input type='hidden' name='str'  value='$str'>
HERE;

echo"<table border='0' style='table-layout:fixed'>

	  
	  <col width=40%>
	  <col width=60%>
	   
	
		     
	  <tr bgcolor='#DDDDDD'>
	    <td align='center' colspan='2'><span class='style16'>$label</span></td></tr>
	  <tr bgcolor='#DDDDDD' height=30px>
	    <td align='left' colspan='2'><span class='style11'>Search</span>
		<span class='style11'><input type='text' name='PRef' id='PRef' value='$PRef' size='15' maxlength='30'/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
		    <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='btnCancel' value='Cancel' onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td>
		";
echo" </tr>
	  <tr bgcolor='#DDDDDD'>
		<td height='15' align='center' colspan='2'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	
	  <tr bgcolor='#CCD8E6'>
	  
	
		<td  height='25' align='left'  ><span class='style25'>Item  </span></td>
		<td  height='25' align='center'><span class='style25'>Description </span></td>	
	  </tr>";
		

	

	$querysearch="select item_code,item_description from items";
	$querysearch=$querysearch." where ";
	$querysearch=$querysearch."  (item_description like"."('%".$PRef."%') or item_code like"."('%".$PRef."%') ) order by item_description";

//echo$querysearch;
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);
	
if ($startrange=='')
	$startrange = 0;
if ($perpage=='')
	$perpage = 20;
		
$querysearch = $querysearch." limit ".$startrange.",".$perpage;
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());		


while($rows=mysql_fetch_array($resultsearch)){
		
	extract($rows);
	$ct+=1;

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




$desc=ereg_replace("'","%27",$rows[1]);

  echo"<tr $Color>";
  
  print<<<HERE
      <td align='left' ><a onclick="fillfield('$rows[0]','od$ct');" href=''>$rows[0]</a></td>
	  <td><a onclick="fillfield('$rows[0]','od$ct');" href=''>$rows[1]</a></td>
	  <input type='hidden' name='od$ct' id='od$ct' value='$rows[1]'>
      </tr>
HERE;
}
							
//<td height="20" align="left"><a href="#" onClick="SelectRef('.$Purchase_ID.');" class="style15"><span class="style15 style17" style="text-decoration:underline;">'.$Purchase_Reference.'</span></a></td>			
			
		
echo"   <tr><td colspan='3'>&nbsp;</td></tr>
		<tr><td colspan=3><table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' align='center'>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.jpg' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td width='150' align='center'>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.jpg' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td><td width='170'>&nbsp;</td></tr>";
		echo"<table>";

echo"</td></tr></table>";

print <<<HERE
</form>
</body>

HERE;

?>