<?php

session_start();
if($_SESSION['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($_SESSION['dbName'],$connection) or die("Could not find DB");


$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}

$frm	   = $_GET['frm']; if ($frm == ""){$frm = $_POST["frm"];}
$item 	   = $_GET['item'];if ($item == ""){$item = $_POST["item"];}
$PLedgerNo = $_POST["PLedgerNo"]; if ($PLedgerNo == ""){$PLedgerNo = $_GET["PLedgerNo"];}
		
print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Search Salesmen</title>
<script type="text/javascript" language="javascript">

function SelectRecord(value1,value2){

	vFrm  = document.search.frm.value;
	vItem = document.search.item.value;

	if(vFrm=='1'){
		opener.document.retailpay.txtRetSalesmanCode.value = value1;
		opener.document.retailpay.txtRetSalesmanName.value = value2;
		opener.document.retailpay.txtRetSalesmanName.focus();
		opener.document.retailpay.submit();
	}
	

	self.close();
}


function clearform()
{
  vFrm  = document.search.frm.value;
  document.search.PLedgerNo.value='';
  document.search.action='List_RetSalesman.php?frm='+vFrm;
  document.search.submit();

}

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

}

function SetNextPage(startrange,perpage){
	vFrm  = document.search.frm.value;
	document.search.action='List_RetSalesman.php?PLedgerNo=&frm='+vFrm+'&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SetPrvPage(startrange,perpage){
    vFrm  = document.search.frm.value;
	document.search.action='List_RetSalesman.php?PLedgerNo=&frm='+vFrm+'&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}




</script>

<style type="text/css">

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

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


.style1 {color: #999999; font-weight: bold; }
.style2 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style3 {color: #999999; font-weight: bold; font-size: 10px; }
.style4 {
	color: #3333FF; 
    
}

</style>

</head>
<body onLoad='LoadForm();'>
<form name='search' method='post' action=''>
<input type='hidden' name='item'  value='$item'>
<input type='hidden' name='frm' value='$frm'>

HERE;

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

	  <col width=3%>
	  <col width=15%>
	  <col width=76%>
	
		     
	  <tr bgcolor='#DDDDDD'>
	    <td align='center' colspan='3'><span class='style2'>List of Salesmen</span></td></tr>
	  <tr bgcolor='#DDDDDD' height=30px>
	    <td align='left' colspan='2'><span class='style1'>Search by Code/Name</span></td>
		<td align='left' colspan='1'><span class='style1'><input type='text' name='PLedgerNo' id='PLedgerNo' value='$PLedgerNo' 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='3'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	
	  <tr bgcolor='#CCD8E6'>
	  
	
		<td  height='25' align='left' width=50% colspan=2><span class='style3'>Code </span></td>
		<td  height='25' align='center'><span class='style3'>Name </span></td>
		
	  </tr>";
		

$querysearch=" Select Salesmen.Ledger_Number, Salesmen.Ledger_Name From Salesmen ".
             " Where (Salesmen.Ledger_Number Like "."('%".$PLedgerNo."%') or Salesmen.Ledger_Name Like "."('%".$PLedgerNo."%')) ".
			 " Order By Salesmen.Ledger_Number ";

//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",$Ledger_Name);

	echo"<tr $Color>";
	echo"  <td align='left' colspan='2'><a onclick=\"SelectRecord('$Ledger_Number','$desc');\" href='#'><span class='style4'>$Ledger_Number</span></a></td>";
	echo"  <td align='left'><span class='style4'>$Ledger_Name</span></td>";
    echo"</tr>";
	
}
							
	
		
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;

?>