<?php

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


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

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

$querylog="SELECT FA_banks as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['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);
	}

if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
	
	
//User Access
$querylog=" select ifNull(FA_bankApp,0) As FA_bankApp, ifNull(FA_bankDel,0) As FA_bankDel,".
          "ifNull(FA_bankMod,0) As FA_bankMod 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);
}

//Access Mode On Insert/Edit/Delete
$InsMode = '';
if ($FI_bankApp == 0)
	$InsMode = ' disabled ';

if(!isset($actionmode))
$actionmode='';

if($mode=='')
	$mode='insert';

class tabs {
	var $name;
	var $tabs;
	var $active;
	var $current;
function start($name){
		if (empty($this->active)){ $this->active = $name; }
		$this->current = $name;
		ob_start();
	}
	function end(){
		$this->tabs[$this->current] = ob_get_contents();
		ob_end_clean();
	}
	function run(){
	
		if (count($this->tabs) > 0){
			echo "<DIV CLASS='tabs'>\n";
			$jsClear = "";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				$jsClear .= "\tdocument.getElementById('$tabid').className = 'tab_inactive';\n";
				$jsClear .= "\tdocument.getElementById('$contentid').style.display = 'none';\n";
			}
			echo "<script type=\"text/javascript\">\n";
			echo "function tab_".$this->name."(id,fieldname){\n";
			
			
			
			echo "$jsClear";
			echo "\tdocument.getElementById('tab_".$this->name."_'+id).className = 'tab_active';\n";
			echo "\tdocument.getElementById('tabcontent_".$this->name."_'+id).style.display = '';\n";
			echo"	
				//alert(fieldname);
				if(fieldname!='' && fieldname!=undefined)
					
					document.bank[fieldname].focus();
				";
			echo "}\n";
			echo "</script>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV CLASS='";
				if ($this->active == $tabname){ echo "tab_active"; }else{ echo "tab_inactive"; }
				echo "' ID='$tabid' ";
				echo "onClick=\"tab_".$this->name."('$tabname');\">$tabname</DIV>\n";
			}
			echo "<DIV STYLE='float: center; clear:both;'></DIV>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display: ";
				if ($this->active == $tabname){ echo "block"; }else{ echo "none"; }
				echo ";'>$tabcontent</DIV>\n";
			}
			echo "</DIV>\n";
			echo "<DIV STYLE='clear: both;'></DIV>\n";
		}}
}	
	
if($mode=='editmode' or $mode=='view'){

	$query_edit=" select bank_name,Bank_Branch,Bank_Telephone1,Bank_Telephone2,Bank_Fax,Bank_Address,Bank_Email,Bank_Website,Bank_creditlimit1,Bank_creditlimit2 ".
				"  from banks where bank_Id='".$bank_Id."'";
	//echo $query_edit;
	$resultedit = mysql_query($query_edit, $connection);
	while($row=mysql_fetch_array($resultedit)){
		$bank_name=$row[0];
		$bank_branch=$row[1];
		$bank_tel1=$row[2];
        $bank_tel2=$row[3];
		$bank_fax=$row[4];
		$Address=$row[5];
		$bank_email=$row[6];
		$bank_webpage=$row[7];
		$Bank_creditlimit1=$row[8];
		$Bank_creditlimit2=$row[9];
	}
	$mode='edit';
}

if($BankLedger_ID!='' && $checkcode!=1){

	$query="select bankledger.Ledger_Number,Bank_InterestRate,Bank_InterestRate2,Bank_CrdLimit,bankledger.Currency_Code,BankType_id,BankLedgerType_id,bankledger_outstandingcheck,Bank_ID,ledger_name
			from bankledger ".
			" left join ledger on ledger.ledger_number=bankledger.Ledger_Number ".
			" where BankLedger_ID='".$BankLedger_ID."'";
	$result=mysql_query($query, $connection);
	$row=mysql_fetch_row($result);
	
	$ledger_number=$row[0];
	$interest_rate=$row[1];
	$commission_rate=$row[2];
	$credit_limit=$row[3];
	$currency=$row[4];
	$banktype=$row[5];
	$bankledgertype=$row[6];
	$outstanding_check=$row[7];
	$bank_Id=$row[8];
	$ledger_name=$row[9];
}

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" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
		<meta name="viewport" content="width=device-width, initial-scale=1.0"> 

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

function CheckTransit() {
	if(document.bank.transit.checked){
		document.bank.bank_transit.value=1;

	}
	else
	{
		document.bank.bank_transit.value=0;

	}
}
function editmode () {

	document.bank.action="Form_Banks.php?mode=edit";
	document.bank.submit();
}

function Addbank () {
ClearForm('All');

	document.bank.mode.value='insert';
	document.bank.action="Form_Banks.php";
	document.bank.submit();
}


function SubmitRecord(option) {

	var Bank_creditlimit1=document.bank.Bank_creditlimit1.value;
	var Bank_creditlimit2=document.bank.Bank_creditlimit2.value;
	var credit_limit=document.bank.credit_limit.value;
	var outstanding_check=document.bank.outstanding_check.value;
	
	var Bankcrdt1=Bank_creditlimit1*1/1;
	var Bankcrdt2=Bank_creditlimit2*1/1;
	var credit_limit1=credit_limit*1/1;
	var outstanding_check1=outstanding_check*1/1;
	
	if (document.bank.bank_name.value=='' ){
		alert('Unable to save : check missing field Name ');
		tab_('Main Page','bank_name');
	}
		
	else  if (document.bank.bank_branch.value=='' ){
		alert('Unable to save : check missing field Branch ');
		tab_('Main Page','bank_branch');
	}
	else  if (document.bank.ledger_number.value=='' && option==2 ){
		alert('Unable to save : check missing field Ledger ');
		tab_('Ledgers','ledger_number');
	}
	
	else if(Bankcrdt1!=Bank_creditlimit1){
		alert('Unable to save : Please Fill Digits in Comission Credit Limit ');
		tab_('Main Page','Bank_creditlimit1');
	}
	else if(Bankcrdt2!=Bank_creditlimit2){
		alert('Unable to save : Please Fill Digits in Comission Credit Limit ');
		tab_('Main Page','Bank_creditlimit2');
	}
	else if(option==2 && credit_limit1!=credit_limit){
		alert('Unable to save : Please Fill Digits in Credit Limit ');
		tab_('Ledgers','credit_limit');
	}
	else if(option==2 && outstanding_check1!=outstanding_check){
		alert('Unable to save : Please Fill Digits in OutStanding Check ');
		tab_('Ledgers','outstanding_check');
	}
	else {
		if(option==2)
			document.bank.actionmode.value='submitledger';
			
			
		document.bank.action="Form_Banks_Actions.php";
		document.bank.submit();
	}
}

function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		
		
		x.message.value='';
		x.mode.value='';
		x.actionmode.value='';
		x.action='Form_Banks.php';
		x.submit();
	}	
}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.bank;
	x.bank_Id.value='';
	x.bank_name.value='';
	x.bank_branch.value='';
	x.bank_tel1.value='';
    x.bank_tel2.value='';
	x.bank_fax.value='';
	x.Address.value='';
	x.bank_email.value='';
	x.bank_webpage.value='';
	x.Bank_creditlimit1.value='';
	x.Bank_creditlimit2.value='';
	
	}

/*
function SearchForbank(){
    ClearForm('All');
    x = document.bank;
    win = window.open('Form_bankSearch.php', 'Form_bankSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	win.creator = self;
	win.focus();		
			
}*/

   function PrintPreview() {
	var str = '';
	
	str = 'Form_bankPreview.php';
	window.open(str);

}

function SetWh(bankId){
	
	document.bank.bank_Id.value=bankId;
	document.bank.message.value='';
	document.bank.actionmode.value='';
	
	document.bank.mode.value='editmode';
	document.bank.submit();
}

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

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

function SearchForSup(){
	x = document.bank;
	document.bank.action='Form_Banks.php?startrange=0';
	document.bank.submit();
}

function ClearKeyword(){
	x = document.bank;
	x.txtKeyword.value='';
	document.bank.action='Form_Banks.php?startrange=0';
	document.bank.submit();
}


function submitenter(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   	document.bank.action='Form_Banks.php?startrange=0';
	document.bank.submit();
  
   return false;
   }
else
   return true;
}

function confirm_delete(Code) {

				
	if (confirm ( "Are you sure you want to Delete this Record " + "?")) {
		window.event.returnValue = true;
		document.bank.mode.value='delete';	
		
		document.bank.action='Form_Banks_Actions.php?bankId='+Code;
		document.bank.submit();
	}
					
}

function set_limit(){

	perpage=document.bank.perpage.value;
	document.bank.action='Form_Banks.php?perpage='+perpage+'&startrange=0';
	document.bank.submit();
}


function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters center' counter
else {
countfield.value = maxlimit - field.value.length;}

}

function showlistclient(str){

  window.open('List_Agents_orderbycode.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function UpdateDetail(bankledgerId){
	 x = document.bank;
	 x.BankLedger_ID.value=bankledgerId;
	x.actionmode.value='refresh';
	x.action='Form_Banks.php?vTabFocus=Ledgers';
	x.submit();
}

function cleardetail(){
	 x = document.bank;

	x.ledger_number.value='';
	x.interest_rate.value='';
	x.commission_rate.value='';
	x.credit_limit.value='';
	x.currency.value='';
	x.banktype.value='';
	x.bankledgertype.value='';
	x.outstanding_check.value='';
	
	x.ledger_name.value='';
	x.BankLedger_ID.value='';
	x.actionmode.value='';
	x.submit();	
}

function DeleteDetail(bankledgerId){

	if (confirm ( "Are you sure you want to Delete record?"))
	{
		
		document.bank.BankLedger_ID.value = bankledgerId;
		document.bank.actionmode.value = 'deletebankledger';
		
		document.bank.action="Form_Banks_Actions.php";
		document.bank.submit();
	}	
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add bank</title>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<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: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;
}
.style15 {color: #5151FF; font-size: 10px;}
.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: #FFFFFF ;font-size: 10px;}

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body >
<form name='bank' method='post'>
<input type=hidden name='mode' value='$mode'>
<input type=hidden name='actionmode' value='$actionmode'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='bank_Id' value='$bank_Id'>
<input type=hidden name='BankLedger_ID' value='$BankLedger_ID'>

HERE;


if($mode==''){
$status='disabled';
$dis='disabled';

}

if($mode=='view'){

$status='readonly';
$dis='disabled';

}

if($mode=='insert')
$status='';

//$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>BANKS</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";


echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='38'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px'>";
echo"		<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>Clear Page</span></span></button>";
echo"		<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(); return false;' title='Save Changes' $Insmode><span><span>Save</span></span></button>";

			
echo"   </td><td align='left' width='250px'>
	<input type='text' name='txtKeyword' value='$txtKeyword' style='width:105px;' onKeyPress='return submitenter(this,event)'>
	<button type='button' id='btnSearch' name='btnSearch' onclick='SearchForSup(); return false;' title='Search Bank'><span><span>Find</span></span></button>
<button type='button' id='btnClear' name='btnClear' onclick='ClearKeyword(); return false;' title='Clear Keyword'><span><span>Clear</span></span></button>
    </td><td align='left'>&nbsp;<span class='style1'><b>Results/page</b></span>
	 <span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
	 
	if ($startrange=='')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 20;
		
	for($i=10;$i<=$maxperpage;$i=$i+10){
		if($i==$perpage)
			echo "<option value='$i'  selected>$i</option>";
		else echo "<option value='$i'>$i</option>";
		
	} 
	 echo"</td></tr>";
echo"	</table>";
echo"</td></tr>";

echo"<tr><td id='content-body'>";		

$tabs = new tabs("Banks");	
$tabs->start("Main Page");

echo"<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
	<col width=65%>";

echo"   <tr bgcolor='#F7F7F7'  ><td valign='top'>";	 

	  
echo" <table border='0' style='table-layout:fixed' align='center' valign='top'>
      <col width=120>
	  <col width=170>
	  <col width=90>
	  <col width=140>
	   <col width=60>
	";

echo"<tr bgcolor='#F7F7F7' height='25'><td valign='center' align='left' ><span class='style1'>Name <span class='style26'>*</span></span>";
echo"<td><input type='text' name='bank_name'  value='".htmlspecialchars($bank_name, ENT_QUOTES)."' style='font-size:12px; width:150px; height:18px;'  $status maxlength='50' /></td>";
echo"<td valign='center' align='left' ><span class='style1'>Branch <span class='style26'>*</span></span>";
echo"<td><input type='text' name='bank_branch' value='".htmlspecialchars($bank_branch, ENT_QUOTES)."' style='font-size:12px; width:150px; height:18px;'  $status maxlength='50' /></td>
<td colspan=2><span class='style1'><b>Commission Credit Limit</b></td></tr>";

echo"<tr bgcolor='#F7F7F7' height='25'><td valign='center' align='left' ><span class='style1'>Telephone</span>";
echo"<td><input type='text' name='bank_tel1'  value='".htmlspecialchars($bank_tel1, ENT_QUOTES)."' style='font-size:12px; width:150px; height:18px;'  $status maxlength='25' /></td>";
echo"<td valign='center' align='left' ><span class='style1'>Telephone 2</span>";
echo"<td><input type='text' name='bank_tel2' value='".htmlspecialchars($bank_tel2, ENT_QUOTES)."' style='font-size:12px; width:150px; height:18px;'  $status maxlength='25' /></td>
<td align='center'><span class='style1'><b>$base1</b></td><td><input type='text' name='Bank_creditlimit1' value='".htmlspecialchars($Bank_creditlimit1, ENT_QUOTES)."' style='font-size:12px; width:150px; height:18px;'  $status maxlength='25' /></td></tr>
<tr height='25' bgcolor='#F7F7F7'>
<td valign='center' align='left' ><span class='style1'>Fax</span>";
echo"<td><input type='text' name='bank_fax' value='".htmlspecialchars($bank_fax, ENT_QUOTES)."' style='font-size:12px; width:150px; height:18px;'  $status maxlength='25' /></td>
<td colspan=2>&nbsp;</td><td align='center'><span class='style1'><b>$base2</b></td><td><input type='text' name='Bank_creditlimit2' value='".htmlspecialchars($Bank_creditlimit2, ENT_QUOTES)."' style='font-size:12px; width:150px; height:18px;'  $status maxlength='25' /></td>
</tr>";
			  
echo"<tr bgcolor='#F7F7F7' height='25'><td valign='center' align='left' ><span class='style1'>Email</span>";
echo"<td colspan=3><input type='text' name='bank_email'  value='".htmlspecialchars($bank_email, ENT_QUOTES)."' style='font-size:12px; width:300px; height:18px;'  $status maxlength='30' /></td>
</tr>
<tr height='25' bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Webpage</span>";
echo"<td colspan=3><input type='text' name='bank_webpage'  value='".htmlspecialchars($bank_webpage, ENT_QUOTES)."' style='font-size:12px; width:300px; height:18px;'  $status maxlength='30' /></td>
";


echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Address</span>";
echo"<td colspan=5><textarea name='Address'  size=100% maxlength='100' cols=73 rows=3 $status onKeyDown='textCounter(this.form.Address,this.form.remLenaddress,100);' onKeyUp='textCounter(this.form.Address,this.form.remLenaddress,100)';>".htmlspecialchars($Address, ENT_QUOTES)."</textarea></td></tr>";  

$len=strlen($Address); 
$rest=100-$len;

echo"<tr bgcolor='#F7F7F7' height='25'><td colspan=9 align=center><span class='style12'>Remaining Chars</span>&nbsp;<input readonly type=text name=remLenaddress size=1 maxlength=3 value='$rest' style='font-size:12px; width:25px; height:18px;' style='font-size:11px; width:25px; height:18px; border:none; background-color:#F7F7F7; '></td></tr>";



echo"</table></td></tr><tr>";
//richard
echo"<td  valign='top'>";

echo"<table style='width:1050px;' border='0' cellspacing=0><col width=100><col width=150>
	<tr>
	<td id='' style='width:1050px;height:15px;' colspan='4'></td>
	</tr>
	 <tr>
	 <td  valign='top' colspan=3 id='' style='width:1050px;'>
	 <table style='width:1050px; position:relative; left:15px;' border='0' cellspacing=0>
	 <col width=50>
	 <col width=350>
	 <col width=350>
	 <col width=350>
	<tr height='30px' style='background-color:darkgray;'><td>&nbsp;</td>
	<td align='center'><span class='style1'><b>Name</b></td>
	<td align='center'><span class='style1'><b>Branch</b></td>
	<td align='center'><span class='style1'><b>Telephone 1</b></td></tr>";
	 
	echo"<tr><td colspan=4 id=''><div style='overflow-y:scroll;height:250px;width:1050px;border:0px solid #000000;'>
	<table  border='0' width='1050px'>
	<col width=50>
	 <col width=350>
	 <col width=350>
	 <col width=350>
	";
	
	$querysearch="select bank_Id,bank_name,Bank_Branch,Bank_Telephone1 from banks ";
	$querysearch=$querysearch." where (bank_name like"."('%".$txtKeyword."%') or Bank_Branch like"."('%".$txtKeyword."%')  or Bank_Telephone1 like"."('%".$txtKeyword."%')) ";

	$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)){
		$ct+=1;
		$stylefont='style15';
		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
				
		if($mode=='edit' && $bank_Id==$rows[0]){
			
		$Color="style='background-color:#1e87a5'";
			$stylefont='style28';
	}	
		
	echo'<tr '.$Color.' height="20px" >';
	
	if($FA_bankDel==1)	
print<<<HERE

<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>

HERE;
else print<<<HERE

<td align=center >&nbsp;</td>

HERE;

	echo"<td onMouseOver=\"style.cursor='hand'\" ";if($FA_bankMod==1) echo " ondblclick=SetWh('$rows[0]');";echo"><span class='$stylefont' >$rows[1]&nbsp;</span></font></td>
		<td onMouseOver=\"style.cursor='hand'\" ";if($FA_bankMod==1) echo " ondblclick=SetWh('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[2]&nbsp;</span></font></td>
		<td onMouseOver=\"style.cursor='hand'\" ";if($FA_bankMod==1) echo " ondblclick=SetWh('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[3]&nbsp;</span></font></td>
		";

	echo"	</tr>";
}		
	
	echo"</table></div></td></tr>";	
echo"<tr ><td >&nbsp;</td><td align='right'>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td  align='center' colspan=2>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td></tr>";


		
echo"</table></td></tr><tr>
					<td id='search-bottom' style='width:1050px;height:20px;' colspan='4'></td>
				</tr></table></td></tr></table>";
				
$tabs->end();

$tabs->start('Ledgers');

echo" <table border='0' class='tablecontent' align='center' valign='top'>
      <col width=160>
	  <col width=300>";
	  
//// Currency
	function get_currency($connection)
{		$query_cr = "select currency_code,currency_name from currency";
//echo$query_cr;
		$result_cr=mysql_query($query_cr, $connection);
		return $result_cr;
}
$curr = get_currency($connection);	  

if($currency=='' && $mode=='insert')
	$currency=$base1;

echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Ledger Number/Name <span class='style26'>*</span></span>";
echo"<td align=left colspan=2><input type=text name='ledger_number' value='$ledger_number' maxlength='10'  readonly size='10' style='font-size:12px; width:100px; height:18px;'>&nbsp;";
		
echo"<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Agent '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistclient(18); return false' /></span></label>";
		
echo"&nbsp;<input type=text name='ledger_name' value='$ledger_name'   readonly size='10' style='font-size:12px; width:250px; height:18px;'></td></tr>";

echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Interest Rate</span></td><td colspan=2><input type=text name='interest_rate' value='$interest_rate'  size='10' style='font-size:12px; width:250px; height:18px;'></td></tr>";
echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Commission Rate</span></td><td colspan=2><input type=text name='commission_rate' value='$commission_rate'  size='10' style='font-size:12px; width:250px; height:18px;'></td></tr>";


echo"<tr bgcolor='#F7F7F7'><td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>Currency</span>";
echo"</td><td colspan=2><select  name='currency'  $status $dis  >
				<option value=''></option>";
				while ($cr=mysql_fetch_row($curr)){
					if ($cr[0]==$currency)
						echo"<option selected value='$cr[0]'>$cr[0]</option>";
					else
						echo"<option value='$cr[0]'>$cr[0]</option>";
				}	
	echo"</select></td></tr>";	

	
$query="select banktype_id,banktype_code,banktype_description from banktype ";
$resultbank=mysql_query($query,$connection);
	
echo"<tr bgcolor='#F7F7F7'><td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>Bank Type</span>";
echo"</td><td colspan=2><select  name='banktype'  $dis  style='width:250px;'>
				<option value=''></option>";
				while ($banktyperow=mysql_fetch_row($resultbank)){
					if ($banktyperow[0]==$banktype)
						echo"<option selected value='$banktyperow[0]'>$banktyperow[1] - $banktyperow[2]</option>";
					else
						echo"<option value='$banktyperow[0]'>$banktyperow[1] - $banktyperow[2]</option>";
				}	
	echo"</select></td></tr>";	



$query="select BankLedgerType_id,BankLedgerType_code,BankLedgerType_description from bankledgertype ";
$resultbankledger=mysql_query($query,$connection);



echo"<tr bgcolor='#F7F7F7'><td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>Bank Ledger Type</span>";
echo"</td><td colspan=2><select  name='bankledgertype'  $dis  style='width:250px;'>
				<option value=''></option>";
				while ($bankledgertyperow=mysql_fetch_row($resultbankledger)){
					if ($bankledgertyperow[0]==$bankledgertype)
						echo"<option selected value='$bankledgertyperow[0]'>$bankledgertyperow[1] - $bankledgertyperow[2]</option>";
					else
						echo"<option value='$bankledgertyperow[0]'>$bankledgertyperow[1] - $bankledgertyperow[2]</option>";
				}	
	echo"</select></td></tr>";	
	
	echo"<tr bgcolor='#F7F7F7'><td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>Credit Limit</span></td>
<td colspan=2><input type=text name='credit_limit' value='$credit_limit'  size='10' style='font-size:12px; width:250px; height:18px;'></td></tr>";	


echo"<tr bgcolor='#F7F7F7'><td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>OutStanding Check</span></td>
<td><input type=text name='outstanding_check' value='$outstanding_check'  size='10' style='font-size:12px; width:250px; height:18px;' maxlength=3></td>
<td align=left ><button type='button' id='submitrecord' name='submitrecord' onclick='SubmitRecord(2); return false;' title='Save Changes' $Insmode><span><span>Submit</span></span></button>";
echo"<button type='button' id='clearbutton' name='clearbutton' onclick='cleardetail(); return false;' title='Clear Detail' $Insmode><span><span>Clear</span></span></button></td></tr>";	


echo"<tr ><td colspan=3><table  border='0'>
<col width=30><col width=30><col width=180><col width=120><col width=120><col width=120><col width=120><col width=140><col width=140><col width=120>
						<tr bgcolor='#D0D0D0' height='25px'><td colspan=2>&nbsp;&nbsp;</td>
						<td align='center'><span class='style27'>Ledger</span></td>
						<td align='center'><span class='style27'>Interest Rate</span></td>
						<td align='center'><span class='style27'>Commission Rate</span></td>
						<td align='center'><span class='style27'>Currency </span></td>
						<td align='center'><span class='style27'>Credit Limit</span></td>
						<td align='center'><span class='style27'>Bank Type</span></td>
						<td align='center'><span class='style27'>Ledger Type</span></td>
						<td align='center'><span class='style27'>Outstanding Check</span></td>
					
</tr>";

$querydt = " select BankLedger_ID,concat(bankledger.Ledger_Number,' - ',ledger_name),Bank_InterestRate,Bank_InterestRate2,bankledger.Currency_Code,Bank_CrdLimit,BankType_description,BankLedgerType_description,bankledger_outstandingcheck ".
		   " from bankledger ".
		   " left join ledger on ledger.ledger_number=bankledger.Ledger_Number ".
		   " left join banktype on banktype.BankType_id=bankledger.BankType_id ".
		   " left join bankledgertype on bankledgertype.BankLedgerType_id=bankledger.BankLedgerType_id ".
		   " where Bank_ID='".$bank_Id."'";

	//echo $querydt;
	$resultdt = mysql_query($querydt, $connection);
	while($rowsdt=mysql_fetch_array($resultdt)){
					
		$ct+=1;

		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
							
					
		echo "<tr ".$Color." >";
		echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetail('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
		echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetail('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
		echo "	<td align='left'><span class='style15'>".$rowsdt[1]."</span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsdt[2]."</span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsdt[3]."</span></td>";
		echo "	<td align='center'><span class='style15'>".$rowsdt[4]."</span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsdt[5]."</span></td>";
		echo "	<td align='left'><span class='style15'>".$rowsdt[6]."</span></td>";
		echo "	<td align='left'><span class='style15'>".$rowsdt[7]."</span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsdt[8]."</span></td>";
		echo "</tr>";
	}					

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

echo"</table>";
$tabs->end();


$tabs->run();	
				
echo"</td></tr>";

 



			/*echo"<table border=0 align=center width=100%> <tr bgcolor=#D8D8D8 height='35'>

			 ";
			
	
			echo"	<td align=center><input type='button'  value='Add bank'";  	
			
			if($mode=='insert' or $mode=='edit')
			echo "disabled ";
			
			echo"onclick='Addbank()' $style title='Add bank' $InsMode>";
				
echo"           <input type='button' id='btnClear' name='BtnClear' value='Clear Page'   onclick='ClearPage();' $style title='Clear Page'>";

				
				
		if($mode=='view'){
echo"           <input type='button' name='btnEdit' id='btnEdit' value='Edit' ";//Edit
				
				
				echo" onclick='editmode();' $style	title='Edit bank' />";
	}
else	{
echo"           <input type='button' name='btnPost' id='btnPost' value='Save' ";//post
				if ($mode=='')
						echo " disabled ";
				
				echo" onclick='SubmitRecord();' $style	title='Save Changes' />";}


				
echo" 			<input name='btnPrint' type='button' id='btnPrint' value='Print' onclick='PrintPreview();' $style title='Print' ";
				if ($mode=='edit' or $mode=='insert') echo " disabled ";
						echo" onclick='PrintPreview();' $style	title='Print' />";

						echo"</td>";
				

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


echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	
echo" </table>  ";//end of last table menu		

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

HERE;
if($vTabFocus!=''){
	echo'<script type="text/javascript" language="javascript">';
	echo"tab_('$vTabFocus','');";
	echo'</script>';	
}	
?>