<?php

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


include("config.inc.php");
include("function.inc.php");
include("Functions_Trans.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");

$querylog=" select ifNull(FA_ChargingDel,0) As FA_ChargingDel, ifNull(FA_ChargingMod,0) As FA_ChargingMod, ifNull(FA_ChargingApp,0) As FA_ChargingApp, ".
          " ifNull(login_belongstogrp,0) As FI_BelongsToGrp from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}


//Access Mode On Insert/Edit/Delete
$DelMode = 1;
$EditMode =1;
$PrevMode = 1;

$PrevHint = '';
$EditHint = '';
$DelHint = '';

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

$MainCompanyName=explode('_',$_SESSION['dbName']);

$queryperiod= " Select ifNull(LockViewPeriod,0) As LockViewPeriod, ViewPeriodDate, ifNull(ViewLockDaily,0) As ViewLockDaily, ViewNumberOfDays ".
              " From ".$_SESSION['dbLabel'].".ListUserDir  ".
			  " Where Usercode='".$_SESSION['useraccount']."' ".
			  " And Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
			  " And Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
			  
$resultperiod = mysql_query($queryperiod,$connection) or die(mysql_error());
$rowsperiod   = mysql_num_rows($resultperiod);

while($rows=mysql_fetch_array($resultperiod)){
	extract($rows);
}	
			  
//echo $queryperiod;	

$queryledger= " select distinct ledger_number, ledger_include ".
              " from ".$_SESSION['dbLabel'].".ledgerstk  ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " order by ledger_number";
$ledgerresult = mysql_query($queryledger,$connection) or die(mysql_error());
$ledgerexist  = mysql_num_rows($ledgerresult);	
$rows=mysql_fetch_array($ledgerresult) ;
$ledgerinclude = $rows[1];


if ($startrange=='') $startrange = 0;
if ($perpage=='')	 $perpage = 20;


print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<title>Search Charging</title>
<script type="text/javascript" language="javascript">

function ClearForm()
{
	document.search.keyword.value='';
	document.search.SelectedID.value = '';
	
	document.search.action='Form_PrepaymentSearch.php';
	document.search.submit();

}

function LoadForm() 
{
	x=document.search;
	x.keyword.focus();
	
	ChangeLocation();
}

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

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

function SelectRef (sref) {

	document.search.action="Form_Prepayment_Actions.php?mainmode=search&SPrePayMId="+sref;
	document.search.submit();
		
	opener.document.prepayment.txtPrePayMId.value=sref;
	opener.document.prepayment.mainaction.value='search';
	opener.document.prepayment.actionmode.value='';
	opener.document.prepayment.action='Form_Prepayment.php';
	opener.document.prepayment.submit();
	self.close();

}

function DeleteRecord(PrePayMId, LedgerNo){

	if (PrePayMId != '') {
		if (confirm ( "Are you sure you want to Delete this record with ledger = "+LedgerNo+" ?") )
		{
			document.search.action="Form_Prepayment_Actions.php?mainmode=delete&SPrePayMId="+PrePayMId;
			document.search.submit();
		}
	}
	
}

function UpdateRecord(PrePayMId){
		
	document.search.action="Form_Prepayment_Actions.php?mainmode=search&SPrePayMId="+PrePayMId;
	document.search.submit();
	
	document.search.PMode.value=1;
	
	opener.document.prepayment.txtPrePayMId.value=PrePayMId;
	opener.document.prepayment.mainaction.value='edit';
	opener.document.prepayment.actionmode.value='';
	
	//opener.document.prepayment.action='Form_Prepayment.php';
	//opener.document.prepayment.submit();
	
	
	//self.close();
	

}


function ShowHideDetails(PrePayMId, Option) {
	if (Option == 'S') {
		document.search.SelectedID.value = PrePayMId;
	}
	else if (Option == 'H') {
		document.search.SelectedID.value = '';
	}	
	document.search.action='Form_PrepaymentSearch.php?SelectedID='+PrePayMId;
	document.search.submit();
}

function PrintPreview(PrePayMId)
{
	var str = '';
	
	str = 'Form_PrepaymentPreview.php?PrePayMId='+PrePayMId;
	window.open(str);

}


function ChangeLocation()
{
    if (document.search.PMode.value == 1) {
		opener.document.prepayment.action='Form_Prepayment.php';
		opener.document.prepayment.submit();
		self.close();
	} else {
		opener.document.prepayment.txtPrePayMId.value='';
		opener.document.prepayment.mainaction.value='';
		opener.document.prepayment.actionmode.value='';
	}
}


function SubmitForm()
{	
  
  document.search.SelectedID.value = '';
  //document.search.keyword.value='';
  document.search.action='Form_PrepaymentSearch.php?startrange=0';
  document.search.submit();

}

function kd(e)
{
	x=document.search;
    var intKey = (window.Event) ? e.which : e.keyCode;
	
    if (intKey == 13) { //enter key
        x.btnSubmit.click();
		return false;
    }
    return true;
}

function RefreshPage()
{
  
  //document.search.keyword.value='';
   document.search.action='Form_PrepaymentSearch.php?startrange=0';
  document.search.submit();

}

function SetFirstPage(startrange,perpage){
	document.search.action='Form_PrepaymentSearch.php?startrange=0&perpage='+perpage;
	document.search.submit();
}

function SetLastPage(perpage,totalrows){
	var result=totalrows % perpage;
	if (result == 0) result = perpage;
	startrange=totalrows-result;
	document.search.action='Form_PrepaymentSearch.php?startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}
</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 0px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}

.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {color: #5151FF; text-decoration:underline}

.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #000000 ;font-size: 10px;}

</style>

</head>
<body onLoad='LoadForm();' class='bodybackground'>
<form name='search' method='post' action=''>
<input type='hidden' name='SelectedID' id='SelectedID' value='$SelectedID'>
HERE;

$PRef = GetSQLValueString($keyword, 'text');

if (empty($ViewPeriodDate))
   $ViewPeriodDate = 'Null';
if (empty($ViewNumberOfDays))   
   $ViewNumberOfDays = 1;
			
			 
$querysearch=" Select PrePaymentM.PrePaymentM_Id As PrePaymentMId, PrePaymentM.Ledger_Number As LedgerNumber, Ledger_Name As LedgerName, PrePaymentM.PrePayment_dbcd As PrePaymentdbcd, ".
			 " ifNull(PrePaymentM.PrePayment_TotalB1,0) As PrePaymentTotalB1, ifNull(PrePaymentM.PrePayment_TotalB2,0) As PrePaymentTotalB2, ".
			 " ifNull(PrePaymentM.PrePayment_RemainB1,0) As PrePaymentRemainB1, ifNull(PrePaymentM.PrePayment_RemainB2,0) As PrePaymentRemainB2,  ".
			 " ifNull(Temp_PrePaymentM.Ledger_Number, -1) As TempPrepaymentLedger ".
			 " From PrePaymentM ".
			 " Inner Join Ledger on PrePaymentM.Ledger_Number = Ledger.Ledger_Number ".
			 " Left Join Temp_PrePaymentM on Temp_PrePaymentM.Ledger_Number = PrePaymentM.Ledger_Number ";
			 
if ($ledgerexist > 0)
	$querysearch = $querysearch." Inner join ( select distinct ledger_number from ".$_SESSION['dbLabel'].".ledgerstk ".
								"			   where user_account='".$_SESSION['useraccount']."' ".
								"              and (ledger_number is not null and ledger_number != '') ".
								"			 )  Q1 on (($ledgerinclude = 1 and PrePaymentM.Ledger_Number like concat(Q1.ledger_number,'%') ) or ($ledgerinclude = 0 and PrePaymentM.Ledger_Number Not like concat(Q1.ledger_number,'%') ) or PrePaymentM.Ledger_Number is null) ";							 
			 

$querysearch= $querysearch." Where PrePaymentM.Ledger_Number Like Concat(ifNull($PRef, PrePaymentM.Ledger_Number),'%') ";
$querysearch= $querysearch." Order By PrePaymentM.Ledger_Number ";
	
			 
//echo $querysearch;			 

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);

		
$querysearch = $querysearch." limit ".$startrange.",".$perpage;

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());		


echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' width='1030px'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>List of Charging</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";
echo"<table border='0' cellspacing='1'  style='table-layout:fixed'>
	  <col width=20>
	  <col width=20>
	  <col width=20>
	  <col width=100>
	  <col width=255>
	  <col width=40>
	  <col width=120>
	  <col width=120>
	  <col width=120>
	  <col width=180>
	       

	  <tr ><td align='left' colspan='10'>";
echo"   <table border='0' cellspacing='1'  style='table-layout:fixed'>
		  <col width=150>
		  <col width=700>
		  <col width=120>";
echo"   <tr class='Search-header-bg'>";  		  
echo"   <td align='left'><span class='style4'>Search By Ledger No.</span></td>
		<td align='left' colspan='5'><span class='style4'><input type='text' name='keyword' id='keyword' value='$keyword' size='15' maxlength='30' onkeydown='return kd(event)'/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
		";

echo"	  	<button type='button' id='btnSubmit' name='btnSubmit' onclick='SubmitForm(); return false;' title='Find'><span><span>Find</span></span></button>
			<button type='button' id='btnCancel' name='btnCancel' onclick='ClearForm(); return false;' title='Cancel'><span><span>Cancel</span></span></button>
			<button type='button' id='btnPrint' name='btnPrint' onclick='PrintPreview(); return false;' title='Print'><span><span>Print</span></span></button>
		
		</td>";

echo" </tr>
</table></td></tr></table>
		</td>
		<td id='search-content3' style='width:31px;'>&nbsp;</td>"; 
echo" </tr>";

echo"<tr>
		<td  id='search-content1' style='height:34px;width:31px;'>&nbsp;</td>
		<td  id='search-content2' style='height:34px;width:1025px;'>
		<table width='100%' border=0>
		<tr>
			<td align='right' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'><select name='perpage' id='perpage' value='$perpage' onchange='RefreshPage();'>";
              
			if ($perpage==20)
				$s20 = 'selected';
			else if ($perpage==30)
				$s30 = 'selected';
			else if ($perpage==40)
				$s40 = 'selected';
			else if ($perpage==50)
				$s50 = 'selected';

						
							
			echo'<option '.$s20.' value="20">20</option>
				 <option '.$s30.' value="30">30</option>
				 <option '.$s40.' value="40">40</option>
				 <option '.$s50.' value="50">50</option>
				 </select></span></td>
			<td  style="width:74px;border-right:1px solid #000000;text-align:right;">';
			
			if($startrange > 0)
				echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."')>";

			$diff= $startrange - $perpage;
				
			if (($diff) >= 0 ){
				$prvstartrange = $startrange - $perpage;
				echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
			}
			else
				echo "&nbsp;";
		
echo"		</td><td  align='left' style='width:74px;'>";
		
		
			if ($startrange <= $totalrows){
				$startrange1 = $startrange + $perpage;
				if  ($startrange1 < $totalrows){
					echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."')>";
					echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."')>";	
				}
			} else
				echo "&nbsp;";
				
			
echo"		</td><td style='width:380px;'>&nbsp;</td>
		</tr>";
echo"	</table></td>
		<td id='search-content3' style='width:31px;'>&nbsp;</td>";
echo"</tr>";			


	  
 echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		<td id='search-content2'>
			<div style='overflow:scroll;height:400px;width:960px;'>
			<table border='0'  cellpadding='0' cellspacing='1' >
			 <col width=20>
			  <col width=20>
			  <col width=20>
			  <col width=100>
			  <col width=255>
			  <col width=40>
			  <col width=120>
			  <col width=120>
			  <col width=120>
			  <col width=120>";	 
	if($message!=''){
		echo"	  <tr class='Search-header-bg'>
		<td height='15' align='center' colspan='10' class='searchmessage'>".$message."</td>
		</tr>";
	}		  
echo"<tr class='Search-Label-bg'>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style4'>Ledger No. </span></td>
		<td  height='25' align='left'><span class='style4'>Ledger Name </span></td>
		<td  height='25' align='center'><span class='style4'>D/C </span></td>
		<td  height='25' align='center'><span class='style4'>Total $base1</span></td>
		<td  height='25' align='center'><span class='style4'>Total $base2</span></td>
		<td  height='25' align='center'><span class='style4'>Remain $base1</span></td>
		<td  height='25' align='center'><span class='style4'>Remain $base2</span></td>
	  </tr>";
		

	

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."'";	
		
	
	$PrevHint    = 'Preview Record';
	$EditHint    = 'Edit Record';
	$DelHint     = 'Delete Record';
	
	if ($TempPrepaymentLedger != -1) {$PrevHint=$EditHint=$DelHint = 'Exists in Pending';}

	if ($FA_ChargingMod == 0)	$EditMode = 0; 
	else if ($FA_ChargingMod == 1 && $TempPrepaymentLedger != -1) $EditMode =0; 
	else if ($FA_ChargingMod == 1 && $TempPrepaymentLedger == -1) $EditMode = 1;
	
	if ($FA_ChargingDel == 0)	$DelMode =0; 
	else if ($FA_ChargingDel == 1 && $TempPrepaymentLedger != -1) $DelMode =0;
	else if ($FA_ChargingDel == 1 && $TempPrepaymentLedger == -1) $DelMode =1;
	
	if ($TempPrepaymentLedger != -1) $PrevMode =0; else $PrevMode =1;
	
	echo'<tr '.$Color.'>';
	
	if($EditMode==1)	
		echo'<td align="center"><span class="style5"><img src="img/edit.png" onMouseOver="style.cursor=\'hand\'" onclick="UpdateRecord('.$PrePaymentMId.');" title="'.$EditHint.'" style="width:20px; height:20px; "></span></td>';
	else echo'<td align="center">&nbsp;</td>';		   	
	
	if($DelMode==1)	
		echo'<td align="center"><span class="style5"><img src="img/delete.png" onMouseOver="style.cursor=\'hand\'" onclick="DeleteRecord('.$PrePaymentMId.', \''.$LedgerNumber.'\');" title="'.$DelHint.'" style="width:20px; height:20px; "></span></td>';
	else echo'<td align="center">&nbsp;</td>';		
			
	if ($SelectedID != "" && $PrePaymentMId == $SelectedID)		
		echo'<td align="center"><span class="style5"><img src="img/hide.png" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$PrePaymentMId.', \''.'H'.'\');" title="Hide Details" height="15px" width="15px"></span></td>';
	else	
		echo'<td align="center"><span class="style5"><img src="img/show.png" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$PrePaymentMId.', \''.'S'.'\');" title="Show Details" height="15px" width="15px"></span></td>';		
		
	echo'	<td align="left"><span class="style5">'.$LedgerNumber.'</span></td>
			<td align="left"><span class="style5">'.$LedgerName.'</span></td>
			<td align="center"><span class="style5">'.$PrePaymentdbcd.'</span></td>
			<td align="right"><span class="style5">'.number_format($PrePaymentTotalB1, $DecimalBase1).'</span></td>
			<td align="right"><span class="style5">'.number_format($PrePaymentTotalB2, $DecimalBase2).'</span></td>
			<td align="right"><span class="style5">'.number_format($PrePaymentRemainB1, $DecimalBase1).'</span></td>
			<td align="right"><span class="style5">'.number_format($PrePaymentRemainB2, $DecimalBase2).'</span></td>
		</tr>';
		
	if ($SelectedID != "" && $PrePaymentMId == $SelectedID) {
		$sub_query = " Select PrePaymentD.Ledger_Number, Ledger.Ledger_Name, PrePaymentD.Description, ".
					 " Date_Format(PrePaymentD.Date1,'%d/%m/%Y') As PrePayDate, PrePaymentD.Division, PrePaymentD.DivisionGenerate, ".
					 " concat(ifNull(PrePaymentD.DivisionGenerate,''), '/', ifNull(PrePaymentD.Division,'')) as RemainDivision,  ".
					 " PrePaymentD.Project_Code, PrePaymentD.Costcent_Code, PrePaymentD.Project_CodeD, PrePaymentD.Costcent_CodeD,   ".
					 " PrePaymentD.Currency_Code, Round(PrePaymentD.Amount, ".$DecimalBase.") As Amount, ".
					 " Round(PrePaymentD.AmountGenerate, ".$DecimalBase.") As AmountGenerate, ".
					 " Round((PrePaymentD.Amount - PrePaymentD.AmountGenerate), ".$DecimalBase.") As AmountBalance ".
					 " From PrePaymentD Left Join Ledger on PrePaymentD.Ledger_Number = Ledger.Ledger_Number ".
					 " Where PrePaymentD.PrePaymentM_Id = '".$PrePaymentMId."' ".
					 " Order By PrePaymentD.Ledger_Number ";
		
		$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());	
		$sub_totalrows = mysql_num_rows($sub_result);
		
		if ($sub_totalrows > 0) {
			echo "<tr>";
			echo "<td colspan='3' valign='top' align='left'>&nbsp;</td>";
			echo "<td colspan='7' valign='top' align='left'><div style='border:1px solid #33CCFF; z-index:9999; background-color:#CCFFFF; padding-left:5px; padding-bottom:5px;'>";
			echo "<table width='95%' border='0' cellpading='0' cellspacing='1' style='table-layout:fixed'>";
			echo" <col width=100>
				  <col width=80>
				  <col width=70>
				  <col width=70>
				  <col width=70>
				  <col width=50>
				  <col width=100>
				  <col width=100>
				  <col width=100>";
			echo"<tr height='20'>";
			echo"  <td align='center'><span class='style17'>Ledger No./Desc.</span></td>";
			echo"  <td align='center'><span class='style17'>Date</span></td>";
			echo"  <td align='center'><span class='style17'>Division</span></td>";
			echo"  <td align='center'><span class='style17'>Gen.Division</span></td>";
			echo"  <td align='center'><span class='style17'>Remain</span></td>";
			echo"  <td align='center'><span class='style17'>Curr</span></td>";
			echo"  <td align='center'><span class='style17'>Amount</span></td>";
			echo"  <td align='center'><span class='style17'>Gen. Amount</span></td>";
			echo"  <td align='center'><span class='style17'>Balance</span></td>";
			echo"</tr>";
			while($sub_rows=mysql_fetch_array($sub_result)){
				echo "<tr>";
				echo "	<td align='left'><span class='style5'>".$sub_rows[0]."</span></td>";
				echo "	<td align='left'><span class='style5'>".$sub_rows[3]."</span></td>";
				echo "	<td align='left'><span class='style5'>".$sub_rows[4]."</span></td>";
				echo "	<td align='left'><span class='style5'>".$sub_rows[5]."</span></td>";
				echo "	<td align='left'><span class='style5'>".$sub_rows[6]."</span></td>";
				echo "	<td align='center'><span class='style5'>".$sub_rows[11]."</span></td>";
				echo "	<td align='right'><span class='style5'>".number_format($sub_rows[12], $DecimalBase)."</span></td>";
				echo "	<td align='right'><span class='style5'>".number_format($sub_rows[13], $DecimalBase)."</span></td>";
				echo "	<td align='right'><span class='style5'>".number_format($sub_rows[14], $DecimalBase)."</span></td>";
				echo "</tr>";
				
				echo "<tr>";
				echo "	<td align='left' colspan='5'><span class='style5'>".$sub_rows[1]."</span></td>";
				echo "	<td align='left' colspan='4'><span class='style5'>".$sub_rows[2]."</span></td>";
				echo "</tr>";
				
				
				
			}
			
			echo "</table></div></td></tr>";
			
		}
		
	}	
}
echo"</table></div></td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";		
//echo"   <tr bgcolor='#CCD8E6' height='30px'><td colspan='10' align='center'><input type='button' name='btnPrint' value='Print' onclick='PrintPreview();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td></tr>";
		
echo"   <tr ><td id='search-content1'>&nbsp;</td><td id='search-content2'>&nbsp;</td><td id='search-content3'>&nbsp;</td></tr>";
echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:908px;' valign='top'><table width='100%' border=0 height=28px>
		<tr><td style='width:380px;'>&nbsp;</td><td align='right' style='width:74px;border-right:1px solid #000000;'>";

		
		if($startrange>0)
			echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."')>";

		//$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			//$prvstartrange = $startrange - $perpage;
			echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td  align='left' style='width:74px;'>";
		
		
		if ($startrange <= $totalrows){
			//$startrange = $startrange + $perpage;
			if  ($startrange1 < $totalrows){
				echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."')>";
				echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."')>";	
			}
		} else
			echo "&nbsp;";
	
			
		echo"</td><td style='width:380px;'>&nbsp;</td></tr>";
		echo"</table></td><td id='search-bottom3' style='height:34px; width:31px;'>&nbsp;</td>";

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


          

		  

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

HERE;

?>