<?php

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


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

//Getting Global Values
$keyword    = $_POST["keyword"]; if ($keyword == ""){$keyword = $_GET["keyword"];}
$orderby    = $_POST["orderby"]; if ($orderby == ""){$orderby = $_GET["orderby"];}
$searchby   = $_POST["searchby"]; if ($searchby == ""){$searchby = $_GET["searchby"];}
$PMode      = $_POST["PMode"]; if ($PMode == ""){$PMode = $_GET["PMode"];}
$SelectedID = $_POST["SelectedID"]; if ($SelectedID == ""){$SelectedID = $_GET["SelectedID"];}
$perpage    = $_POST["perpage"]; if ($perpage == ""){$perpage = $_GET["perpage"];}
$startrange = $_POST["startrange"]; if ($startrange == ""){$startrange = $_GET["startrange"];}
$message    = $_POST["message"]; if ($message == ""){$message = $_GET["message"];}


/*
#Access Mode On Insert/Print/View	
$result_access=getformdetails('JournalForm',$_SESSION['accessschemaid'],$_SESSION['dbLabel']);
$row_access=mysql_fetch_row($result_access);

$FA_JournalDel     = $row_access[3];
$FA_JournalMod     = $row_access[2];
$FA_JournalPreview = $row_access[5];
$Form_View         = $row_access[7];

if ($Form_View=='' or $Form_View==0)
	header("location:menu.php");
	

#Reading Setup Data
$DecimalBase  = getSmodulevalue('DecimalBase','integer',$_SESSION['logincompany'],$_SESSION['dbLabel'],$connection);
$DecimalBase1 = getSmodulevalue('DecimalBase1','integer',$_SESSION['logincompany'],$_SESSION['dbLabel'],$connection);
$DecimalBase2 = getSmodulevalue('DecimalBase2','integer',$_SESSION['logincompany'],$_SESSION['dbLabel'],$connection);
$base1 = getSmodulevalue('base1','string',$_SESSION['logincompany'],$_SESSION['dbLabel'],$connection);
$base2 = getSmodulevalue('base2','string',$_SESSION['logincompany'],$_SESSION['dbLabel'],$connection);
$grid_color1 = getSmodulevalue('grid_color1','string',$_SESSION['logincompany'],$_SESSION['dbLabel'],$connection);
$grid_color2 = getSmodulevalue('grid_color2','string',$_SESSION['logincompany'],$_SESSION['dbLabel'],$connection);

//Belongs To Group
$FI_BelongsToGrp=get_belongstogroup($_SESSION['dbLabel'],$_SESSION['accessid'],$connection);


$access_result = getAccessRestriction($_SESSION['accessschemaid'],$_SESSION['dbLabel'],'view',$connection);
$AccessPost = $access_result[0];
$AccessDay = $access_result[1];
$AccessWeek = $access_result[2];
$AccessYear = $access_result[3];
$AccessSign = $access_result[4];

if (empty($AccessPost)) $AccessPost = 0;

//Get Start/End financial Year
$query="select startdate,enddate from ".$_SESSION['dbLabel'].".accessschema where accessschema_id='".$_SESSION['accessschemaid']."'";
$result=mysql_query($query,$connection);
$row=mysql_fetch_row($result);
$StartYear=$row[0];
$EndYear=$row[1];

$vAllowedDate=Get_AllowedDate($AccessDay,$AccessWeek,$AccessYear,$AccessSign,$StartYear,$EndYear,$_SESSION['dbLabel'],$connection);

$FieldArray   = Array();
$ButtonArray  = Array();

$sub_result = get_mandatory('JournalForm',$_SESSION['accessschemaid'],$_SESSION['dbLabel'],$connection);
while($sub_row=mysql_fetch_row($sub_result)){

	$vFieldLabel='';
	$vFieldLabel=get_labelnames('JournalForm',$_SESSION['dbLabel'],$_SESSION['accessid'],$sub_row[2],$connection);
	
	$FieldArray[$sub_row[2]]["FieldLabel"]  = $vFieldLabel;
}


$sub_result=get_labelbuttons($_SESSION['dbLabel'],$_SESSION['accessid'],$connection);
while($sub_row=mysql_fetch_row($sub_result)){

	$ButtonArray[$sub_row[0]]['ButtonLabel']= $sub_row[1];
	$ButtonArray[$sub_row[0]]['ButtonTitle']= $sub_row[2];
}
*/


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


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

//Read From Module Table
$querymodule=" Select ifNull(Module_BelongsToGroup,0) As Module_BelongsToGroup From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


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

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

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

if (empty($ViewPeriodDate))
   $ViewPeriodDate = 'Null';
if (empty($ViewNumberOfDays))   
   $ViewNumberOfDays = 1;

if (empty($orderby))  $orderby = 1;
if (empty($searchby)) $searchby = 2;

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">
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<title>Search Transfer Funds</title>
<script type="text/javascript" language="javascript">

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

}

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

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

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

function SetFirstPage(startrange,perpage){
	document.search.action='Form_TransferFundsSearch.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_TransferFundsSearch.php?startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SearchKeyword(){
	document.search.action='Form_TransferFundsSearch.php?startrange=0';
	document.search.submit();
}


function SelectRecord(JourId){
		
	opener.document.invoices.txtJourId.value=JourId;
	opener.document.invoices.mainaction.value='edit';
	opener.document.invoices.actionmode.value='';
	opener.document.invoices.submit();
	
	self.close();
}


function ShowHideDetails(JourId, Option, startrange) {
	/*if (Option == 'S') {
		document.search.SelectedID.value = JourId;
		document.search.action='Form_TransferFundsSearch.php?startrange='+startrange+'&SelectedID='+JourId;
	}
	else if (Option == 'H') {
		document.search.SelectedID.value = '';
		document.search.action='Form_TransferFundsSearch.php?startrange='+startrange;
	}	
	
	document.search.submit();*/
	
	vSlideDivId = '#displaydetails'+JourId;
	$(vSlideDivId).slideToggle();
}


function SelectSearchBy()
{	
  document.search.SelectedID.value = '';
  //document.search.keyword.value='';
  //document.search.action='Form_TransferFundsSearch.php';
  document.search.submit();

}

function RefreshPage()
{
	document.search.action='Form_TransferFundsSearch.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;
}

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

HERE;


$PSearch = GetSQLValueString($keyword, 'text');
   
			 
/*$querysearch=" Select Journal_ID, Journal_RefGovernment, Journal_Folio, Journal_Type, Journal_TypeRef, Journal_Date, ".
			 " Journal_Remark, Manual_No, Amnt1_db, Amnt2_db, Amnt1_cd, Amnt2_cd, TempJournalId, UserAccount, ".
			 " Posted, JournalDate, AllowviewDate ".
			 " From ( ".*/

			 
			 
$querysearch=" Select SQL_CALC_FOUND_ROWS Journal.Journal_ID, Journal.Journal_RefGovernment, Journal.Journal_Folio, Journal.Journal_Type, Journal.Journal_TypeRef, ".
			 " Date_Format(Journal.Journal_Date,'%d/%m/%Y') As Journal_Date, Journal.Journal_Remark, Journal.Manual_No, ".
			 " (select ledger_number from journaldt where journaldt.journaldt_dbcd='C' and JournalDt.Journal_ID =Journal.journal_id ) as Credit, ".
			 " (select ledger_name from ledger where ledger_number in (select ledger_number from journaldt where journaldt_dbcd='C' and journaldt.journal_id=Journal.journal_id)) as CreditName,  ".
             " (select ledger_number from journaldt where journaldt.journaldt_dbcd='D' and JournalDt.Journal_ID =Journal.journal_id ) as Debit, ".
			 " (select ledger_name from ledger where ledger_number in (select ledger_number from journaldt where journaldt_dbcd='D' and journaldt.journal_id=Journal.journal_id)) as DebitName,  ".
			 " ifNull(Journal.Amnt1_db,0) as Amnt1_db, ifNull(Journal.Amnt2_db,0) as Amnt2_db, Round(ifNull(journal.Amnt1_cd,0), ".$DecimalBase.") as Amnt1_cd, ifNull(Journal.Amnt2_cd,0) as Amnt2_cd,  ".
			 " ifNull(Temp_Journal.Journal_Id, -1) As TempJournalId, ".
			 " Journal.User_Account As UserAccount, Journal.Journal_posted as Posted, Date_Format(Journal.Journal_Date,'%Y-%m-%d') As JournalDate ".
			 " From Journal ".
			 " Left Join Temp_Journal on Temp_Journal.Journal_Id = Journal.Journal_Id ";
	
			 
$querysearch= $querysearch.											 
			 " Where (($searchby = 2 and Journal.Journal_RefGovernment Like Concat(ifNull($PSearch, Journal.Journal_RefGovernment),'%'))  ".
			 " 	   Or ($searchby = 4 and ifnull(Journal.Journal_folio,-1) Like Concat(ifNull($PSearch, ifnull(Journal.Journal_folio,-1)),'%')) ".
			 " 	   Or ($searchby = 5 and ifnull(Journal.manual_no,-1) Like Concat(ifNull($PSearch, ifnull(Journal.manual_no,-1)),'%')) ".
			 " 	   Or ($searchby = 1 and Date_Format(Journal.Journal_Date,'%Y-%m-%d') = ifNull(Date_Format($PSearch,'%Y-%m-%d'), Date_Format(Journal.Journal_Date,'%Y-%m-%d')))  ".
			 "     Or ($searchby = 3 and Upper(Journal.User_Account) Like Concat(ifNull(Upper($PSearch), Upper(Journal.User_Account)),'%'))    ".
			 //"     Or ($searchby = 6 and Upper(Journal.Journal_Type) = ifNull(Upper($PSearch), Upper(Journal.Journal_Type)))    ".
			 "     Or ($searchby = 7 and Upper(Journal.Journal_Remark) Like Concat('%',ifNull(Upper($PSearch), Upper(Journal.Journal_Remark)),'%')) )   ".
			 " And (($rowsperiod = 0 and 1 = 1) Or ($rowsperiod > 0 and (($LockViewPeriod = 1 and  Date_Format(Journal.Journal_Date,'%Y-%m-%d') >= Date_Format(ifNull('".$ViewPeriodDate."',Journal.Journal_Date),'%Y-%m-%d')) Or ($LockViewPeriod = 0 and 1=1 ))   ".
             "                                                      and (($ViewLockDaily = 1 and DateDiff(Date_Format(Now(),'%Y-%m-%d'),Date_Format(Journal.Journal_Date,'%Y-%m-%d')) <= $ViewNumberOfDays) Or ($ViewLockDaily = 0 and  1 = 1 ))) ) ".
			 " And ifNull(Journal.Journal_BelongsToGroup,0) >= ifNull($FI_BelongsToGrp,0) ".
			 " And Upper(Journal.Journal_Type) = 'TF' ";
			 
			 
if ($ShowTransaction != 1)
	$querysearch= $querysearch." And Upper(Journal.User_Account) = Upper('".$HTTP_SESSION_VARS['useraccount']."') ";
			 

if ($orderby == 1)
	$querysearch= $querysearch." Order By Journal.Journal_Date Desc, Journal.Journal_RefGovernment Desc ";
else if ($orderby == 2)
	$querysearch= $querysearch." Order By Journal.Journal_RefGovernment Desc ";	
	
//$querysearch= $querysearch." ) Q4 where Q4.AllowviewDate=1 ";

//echo $querysearch; exit;

if ($PMode != 1) {
	//$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error($connection));
	//$totalrows = mysql_num_rows($resultsearch);
	
	$querysearch = $querysearch." limit ".$startrange.",".$perpage;
	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error($connection));
	$row = mysql_fetch_row(mysql_query("SELECT FOUND_ROWS()"));
	$totalrows = $row[0];
}


echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' width='970px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:908px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>List of Transfer Funds</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' >
			<table border='0' cellspacing='1' style='table-layout:fixed' align='center'>
			  <col width=100>
			  <col width=160>
			  <col width=100>
			  <col width=150>
			  <col width=80>
			  <col width=100>
			  <col width=110>
			  <col width=115>";

echo"		 <tr class='Search-header-bg' height='34px'>
				<td align='left'><span class='style4'>Search By</span></td>
				<td align='left' colspan='5'><span class='style4'><input type='text' name='keyword' id='keyword' value='$keyword' style='width:150px;' maxlength='100'  onkeydown='return kd(event)'/></span>
					<select name='searchby' id='searchby' value='$searchby' onchange='SelectSearchBy();'>";
		
					if ($searchby==1)		$s21 = 'selected';
					else if ($searchby==2)	$s22 = 'selected';
					else if ($searchby==3)	$s23 = 'selected';
					else if ($searchby==4)	$s24 = 'selected';
					else if ($searchby==5)	$s25 = 'selected';
					else if ($searchby==6)	$s26 = 'selected';
					else if ($searchby==7)	$s27 = 'selected';
						
					echo"<option ".$s21." value='1'>Date (yyyy-mm-dd)</option>
						 <option ".$s22." value='2'>Reference</option>
						 <option ".$s23." value='3'>Create User</option>
						 <option ".$s24." value='4'>Folio</option>
						 <option ".$s25." value='5'>Manual No.</option>
						 <option ".$s27." value='7'>Remark</option>
						 </select>";
echo"				<button type='button' id='btnFind' name='btnFind' onclick='SearchKeyword(); 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>
				</td>";
echo"			<td align='right' valign='center' ><span class='style4'>Order By</span></td>
				<td align='left'><span class='style4'><select name='orderby' id='orderby' value='$orderby' onchange='RefreshPage();'>";
		
				if ($orderby==1)
					$s11 = 'selected';
				else if ($orderby==2)
					$s12 = 'selected';
					
				echo"<option ".$s11." value='1'>Date</option>
					 <option ".$s12." value='2'>Reference</option>
					 </select></span></td>";
echo"		 </tr>";
			  
if($message!=''){
	echo"	  <tr class='Search-header-bg'>
				<td height='15' align='center' colspan='8' class='searchmessage'>".$message."</td>
			  </tr>";
}
		
echo"		</table>
		</td>
		<td id='search-content3' style='width:31px;'>&nbsp;</td>
	</tr>";		
	
	
echo"<tr>
		<td  id='search-content1' style='height:34px;width:31px;'>&nbsp;</td>
		<td  id='search-content2' style='height:34px;width:908px;'>
		<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:908px;'>
			<table border='0' style='table-layout:fixed' cellpadding='0' cellspacing='1' width='1000px'>
			  <col width=20>
			  <col width=20>
			  <col width=80>
			  <col width=80>
			  <col width=100>
			  <col width=100>
			  <col width=150>
			  <col width=100>
			  <col width=150>
			  <col width=100>";
	  
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'>Reference</span></td>
				<td  height='25' align='center'><span class='style4'>Date</span></td>
				<td  height='25' align='center'><span class='style4'>Amount</span></td>
				<td  height='25' align='center'><span class='style4'>Transfer From</span></td>
                <td  height='25' align='center'><span class='style4'>Name</span></td>				
				<td  height='25' align='center'><span class='style4'>Transfer To</span></td>
				<td  height='25' align='center'><span class='style4'>Name</span></td>
				<td  height='25' align='center'><span class='style4'>User</span></td>
			</tr>";
		


$i = 0;
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."'";	
	
	
	//$queryjourtype="select ifnull(type_visible,0) from jourtype where type_name = '".$Journal_Type."'";
	//$resultjourtype = selectData($connection, $queryjourtype);
	//$JourTypeVisible = $resultjourtype[0];
	$JourTypeVisible = 1;
	
	$AllowedEditDate   = 1;
	$AllowedDeleteDate = 1;
	
	$PrevHint     = 'Preview';
	$EditHint     = 'Edit Record';
	$DelHint      = 'Delete Record';
	
	//$AllowedEditDate   = getdatestatus($_SESSION['accessschemaid'],$_SESSION['dbLabel'],'edit',$Posted,$JournalDate,$vAllowedDate,$connection);
	//$AllowedDeleteDate = getdatestatus($_SESSION['accessschemaid'],$_SESSION['dbLabel'],'delete',$Posted,$JournalDate,$vAllowedDate,$connection);
	
	
	if ($TempJournalId != -1) {$PrevHint=$EditHint=$DelHint = 'Exists in Pending';}
	
    if ($FA_JournalMod == 0)	$EditMode = ' disabled '; 
	else if ($FA_JournalMod == 1 && $TempJournalId != -1) $EditMode = ' disabled ';
	else if ($FA_JournalMod == 1 && $TempJournalId == -1) $EditMode = '';
	
		
	echo'<tr '.$Color.'>';
	
	if ($FA_JournalMod == 1 && $TempJournalId == -1 && $AllowedEditDate == 1)		
		echo'<td align="center"><span class="style5"><img src="img/edit.png" onMouseOver="style.cursor=\'hand\'" onclick="SelectRecord('.$Journal_ID.');" title="'.$EditHint.'" style="width:20px; height:20px; " '.$EditMode.' ></span></td>';
	else 	
		echo'<td align="center"><span class="style5">&nbsp;</span></td>';	
			
			
	echo'	<td align="center"><span class="style5"><img src="img/details.png" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$Journal_ID.', \''.'S'.'\','.$startrange.');" title="Show Details" style="width:20px; height:20px; "></span></td>';		
	
	echo'	<td align="left"><span class="style5">'.$Journal_RefGovernment.'</span></td>
			<td align="center"><span class="style5">'.$Journal_Date.'</span></td>
			<td align="center"><span class="style5">'.number_format($Amnt1_cd,$DecimalBase).'</span></td>  
			<td align="center"><span class="style5">'.$Credit.'</span></td>  
			<td align="left"><span class="style5">'.$CreditName.'</span></td>  
			<td align="center"><span class="style5">'.$Debit.'</span></td>  
			<td align="left"><span class="style5">'.$DebitName.'</span></td>  
			<td align="left"><span class="style5">'.$UserAccount.'</span></td>';
	echo'</tr>';

	
	//if ($SelectedID != "" && $Journal_ID == $SelectedID) {
		$sub_query = " Select JournalDt.Journaldt_id, Ledger.Ledger_Number, Ledger.Ledger_Name, JournalDt.Journaldt_desc, JournalDt.Journaldt_desc1, ".
					 " Journaldt_dbcd, Round(ifNull(Journaldt_amount,0), ".$DecimalBase."), Round(ifNull(Journaldt_amount1,0), ".$DecimalBase1."),".
					 " Round(ifNull(Journaldt_amount2,0), ".$DecimalBase2."), date_format(Journaldt_ValueDate,'%d-%m-%Y'), JournalDt.currency_code, JournalDt.manual_no ".
					 " From JournalDt ".
					 " Inner Join Ledger on JournalDt.Ledger_Number = Ledger.Ledger_Number ".
					 " Where JournalDt.Journal_ID = '".$Journal_ID."' ".
					 " Order By Ledger.Ledger_Number ";

		$sub_result=mysql_query($sub_query,$connection) or die(mysql_error($connection));	
		$sub_totalrows = mysql_num_rows($sub_result);
		
		if ($sub_totalrows > 0) {
			$SlideDivId = 'displaydetails'.$Journal_ID;
			
			echo "<tr ".$Color.">";
			echo "<td colspan='9' valign='top' align='left'><div id='$SlideDivId' class='div-search-details' style='display:none; margin-left:20px;'>";
			echo "<table border='0' style='table-layout:fixed' cellpadding='0' cellspacing='1' width='920px'>";
			echo "<tr><td width='100px'><span class='style4'>Ledger No.</span></td>
					  <td width='130px'><span class='style4'>Ledger Name</span></td> 
					  <td width='140px'><span class='style4'>Description</span></td> 
					  <td width='50px' align='center'><span class='style4'>Curr.</span></td>
					  <td width='40px' align='center'><span class='style4'>D/C</span></td>
					  <td width='100px' align='center'><span class='style4'>Amount</span></td>
					  <td width='100px' align='center'><span class='style4'>$base1</span></td>
					  <td width='100px' align='center'><span class='style4'>$base2</span></td>
					  <td width='80px' align='center'><span class='style4'>Manual No</span></td>
					  <td width='80px' align='center'><span class='style4'>Value Date</span></td>
				  </tr>";
			while($sub_rows=mysql_fetch_array($sub_result)){
				echo "<tr><td align='left' valign='top' class='style9'>".$sub_rows[1]."</td>
						  <td align='left' valign='top' class='style9'>".$sub_rows[2]."</td>
						  <td align='left' valign='top' class='style9'>".$sub_rows[3]."</td>
						  <td align='center' valign='top' class='style9'>".$sub_rows[10]."</td>
						  <td align='center' valign='top' class='style9'>".$sub_rows[5]."</td>
						  <td align='right' valign='top' class='style9'>".number_format($sub_rows[6],$DecimalBase)."</td>
						  <td align='right' valign='top' class='style9'>".number_format($sub_rows[7],$DecimalBase1)."</td>
						  <td align='right' valign='top' class='style9'>".number_format($sub_rows[8],$DecimalBase2)."</td>
						  <td align='left' valign='top' class='style9' style='padding-left:5px;'>".$sub_rows[11]."</td>
						  <td align='center' valign='top' class='style9'>".$sub_rows[9]."</td>";
  				echo "</tr>";
				
				if ($sub_rows[4] != "") {
					echo "<tr><td align='left' valign='top' class='style9' colspan='2'>&nbsp;</td>
						  <td align='left' valign='top' class='style9' colspan='8'>".$sub_rows[4]."</td>";
					echo "</tr>";	  
				}
			
			}
			
			echo "</table></div></td>";
			echo "</tr>";
		}
	//}
	
}
							
echo"</table></div></td><td id='search-content3' style='width:31px;'>&nbsp;</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;

?>