<?php

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


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

$querylog=" select ifNull(Login_TipsMaxAmount,0) As Login_TipsMaxAmount ".
          " 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);
}

	
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From SalesSetup Table
$querySalesSetup="Select SalesTTC, CashAccount, ifNull(TipsMaxBase1,0) as TipsMaxBase1 From SalesSetup";
$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die(mysql_error());
while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
	extract($rowSalesSetup);
}


$queryLedgers="Select Ledger_Name As CashAccountName From Ledger Where Ledger_Number = '".$CashAccount."'";
$resultLedgers=mysql_query($queryLedgers,$connection) or die(mysql_error());
while($rowLedgers=mysql_fetch_array($resultLedgers)){
	extract($rowLedgers);
}



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

function SubmitRecord(currbase1, currbase2, currrate, currrate1, currrate2, dec, SetupTipsMaxAmount) {
	x = document.cashpay;
	
	var result = CheckFields(currbase1, currbase2, currrate, currrate1, currrate2, dec, SetupTipsMaxAmount);
	var vSaId  = x.PSaId.value;
	   
	if (result == 1) {
		x.action="Form_ReturnDelivery_Actions.php?mode=CashPayment&SRSaId="+vSaId;
		x.submit();
		
	}	
}


function CheckFields(currbase1, currbase2, currrate, currrate1, currrate2, dec, SetupTipsMaxAmount){
  
    x = document.cashpay;
	
	var vCurr        = x.txtSaCurr.value;
	var vLedger      = x.txtLedgerNo.value;
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	var vCurrRate    = currrate;
	var vCurrRateB1  = currrate1;
	var vCurrRateB2  = currrate2;

	
	var vNetTotal   = x.txtSaNetTotal.value;  
	var vCashInB1   = x.txtSaCashInB1.value;
	var vCashInB2   = x.txtSaCashInB2.value;
	var vCashOutB1  = x.txtSaCashOutB1.value;
	var vCashOutB2  = x.txtSaCashOutB2.value;
	var vTipsB1     = x.txtSaTipsB1.value;
	

	if (vNetTotal == '')   vNetTotal = 0;
	if (vCashInB1 == '')   vCashInB1 = 0;
	if (vCashInB2 == '')   vCashInB2 = 0;
	if (vCashOutB1 == '')  vCashOutB1 = 0;
	if (vCashOutB2 == '')  vCashOutB2 = 0;
	if (vTipsB1 == '')     vTipsB1 = 0;

	
	vNetTotal   = parseFloat(vNetTotal);
	vCashInB1   = parseFloat(vCashInB1);
	vCashInB2   = parseFloat(vCashInB2);
	vCashOutB1  = parseFloat(vCashOutB1);
	vCashOutB2  = parseFloat(vCashOutB2);
	vTipsB1  	= parseFloat(vTipsB1);
	
	
	if (vCurr == vCurrBase1) 
		vAmtPayed =   vNetTotal - (vCashInB1 + (vCashInB2*vCurrRateB2/vCurrRateB1) + vTipsB1) + vCashOutB1 + (vCashOutB2*vCurrRateB2/vCurrRateB1);	
	else if (vCurr == vCurrBase2)
		vAmtPayed =   vNetTotal - ((vCashInB1*vCurrRateB1/vCurrRateB2) + vCashInB2 + (vTipsB1*vCurrRateB1/vCurrRateB2)) + (vCashOutB1*vCurrRateB1/vCurrRateB2) + vCashOutB2;
	else 
		vAmtPayed =   (vNetTotal*vCurrRate/vCurrRateB1) - (vCashInB1 + (vCashInB2*vCurrRateB2/vCurrRateB1) + vTipsB1) + vCashOutB1 + (vCashOutB2*vCurrRateB2/vCurrRateB1);
					   
	
	vAmtPayed =  Math.round((vAmtPayed)*Math.pow(10,0))/Math.pow(10,0);
	
	if (vLedger == '') {
		alert("Cash Account is mandatory!");
		x.txtLedgerNo.focus();
		return 0;
	}
	else if (Math.abs(vTipsB1) > SetupTipsMaxAmount) {
		alert("Tips amount exceeds max allowed amount ("+SetupTipsMaxAmount+")!");
		x.txtSaCashInB1.focus();
		return 0;
	}
	else if (vCashInB1==0 && vCashInB2==0 && vCashOutB1 && vCashOutB2) 
	{
		alert("Amount is mandatory!");
		x.txtSaCashInB1.focus();
		return 0;
	}
	else if (vAmtPayed != 0) {
		alert("Amount payed differs from Amount Due.!");
		x.txtSaCashInB1.focus();
		return 0;
	
	}
		
	
	else
	return 1 ;	
}


function CalcCashInB1(currbase1, currbase2, currrate, currrate1, currrate2, dec)
{
	x = document.cashpay;
	
	
	var vCurr        = x.txtSaCurr.value;
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	var vCurrRate	 = currrate;
	var vCurrRateB1  = currrate1;
	var vCurrRateB2  = currrate2;
	
	var vNetTotal    = x.txtSaNetTotal.value;  
	var vCashInB1    = x.txtSaCashInB1.value;
	var vCashInB2    = x.txtSaCashInB2.value;
	var vCashOutB1   = x.txtSaCashOutB1.value;
	var vCashOutB2   = x.txtSaCashOutB2.value;
	var vTipsAmt     = x.txtSaTipsB1.value;
	
	if (vNetTotal == '')   vNetTotal = 0;
	if (vCashInB1 == '')   vCashInB1 = 0;
	if (vCashInB2 == '')   vCashInB2 = 0;
	if (vCashOutB1 == '')  vCashOutB1 = 0;
	if (vCashOutB2 == '')  vCashOutB2 = 0;
	if (vTipsAmt == '')    vTipsAmt = 0;
	
	vNetTotal   = parseFloat(vNetTotal);
	vCashInB1   = parseFloat(vCashInB1);
	vCashInB2   = parseFloat(vCashInB2);
	vCashOutB1  = parseFloat(vCashOutB1);
	vCashOutB2  = parseFloat(vCashOutB2);
	vTipsAmt    = parseFloat(vTipsAmt);
	
	
	x.txtSaCashOutB1.value = 0;
	x.txtSaCashInB2.value = 0;
	x.txtSaCashOutB2.value = 0;
	x.txtSaTipsB1.value = 0;
		
	if (vCurr == vCurrBase1) 
		vCashOutB1 =   vNetTotal - vCashInB1;	
	else if (vCurr == vCurrBase2) 
		vCashOutB1 =   (vNetTotal*vCurrRateB2/vCurrRateB1) - vCashInB1;	
	else  
		vCashOutB1 =   (vNetTotal*vCurrRate/vCurrRateB1) - vCashInB1;	
	
	if (vCashOutB1 < 0) {  
		x.txtSaCashOutB1.value = Math.round(Math.abs(vCashOutB1)*Math.pow(10,dec))/Math.pow(10,dec);
	}
	else {
		x.txtSaCashInB2.value =  Math.round((vCashOutB1*vCurrRateB1/vCurrRateB2)*Math.pow(10,dec))/Math.pow(10,dec);
	}		
			
}

function CalcCashOutB1(currbase1, currbase2, currrate, currrate1, currrate2, dec)
{
	x = document.cashpay;
	
	var vCurr        = x.txtSaCurr.value;
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	var vCurrRate	 = currrate;
	var vCurrRateB1  = currrate1;
	var vCurrRateB2  = currrate2;
	
	var vNetTotal    = x.txtSaNetTotal.value;  
	var vCashInB1    = x.txtSaCashInB1.value;
	var vCashInB2    = x.txtSaCashInB2.value;
	var vCashOutB1   = x.txtSaCashOutB1.value;
	var vCashOutB2   = x.txtSaCashOutB2.value;
	var vTipsAmt     = x.txtSaTipsB1.value;
	
	if (vNetTotal == '')   vNetTotal = 0;
	if (vCashInB1 == '')   vCashInB1 = 0;
	if (vCashInB2 == '')   vCashInB2 = 0;
	if (vCashOutB1 == '')  vCashOutB1 = 0;
	if (vCashOutB2 == '')  vCashOutB2 = 0;
	if (vTipsAmt == '')    vTipsAmt = 0;
	
	vNetTotal   = parseFloat(vNetTotal);
	vCashInB1   = parseFloat(vCashInB1);
	vCashInB2   = parseFloat(vCashInB2);
	vCashOutB1  = parseFloat(vCashOutB1);
	vCashOutB2  = parseFloat(vCashOutB2);
	vTipsAmt    = parseFloat(vTipsAmt);
	
	    
	x.txtSaCashOutB2.value = 0;
	x.txtSaTipsB1.value = 0;
	
	if (vCurr == vCurrBase1) 
		vCashOut =   vNetTotal - vCashInB1 - (vCashInB2*vCurrRateB2/vCurrRateB1) + vCashOutB1;	
	else if (vCurr == vCurrBase2) 
		vCashOut =   (vNetTotal*vCurrRateB2/vCurrRateB1) - vCashInB1 - (vCashInB2*vCurrRateB2/vCurrRateB1) + vCashOutB1;	
	else  
		vCashOut =   (vNetTotal*vCurrRate/vCurrRateB1) - vCashInB1 - (vCashInB2*vCurrRateB2/vCurrRateB1) + vCashOutB1;	
		
	if (vCashOut < 0) {         
		vCashOut =   (vCashOut*vCurrRateB1/vCurrRateB2);
		x.txtSaCashOutB2.value = Math.round(Math.abs(vCashOut)*Math.pow(10,dec))/Math.pow(10,dec);
	}	
	else {	
		x.txtSaTipsB1.value =  Math.round(Math.abs(vCashOut)*Math.pow(10,dec))/Math.pow(10,dec);
	}		
		
}

function CalcCashInB2(currbase1, currbase2, currrate, currrate1, currrate2, dec)
{
	x = document.cashpay;
	
	var vCurr        = x.txtSaCurr.value;
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	var vCurrRate	 = currrate;
	var vCurrRateB1  = currrate1;
	var vCurrRateB2  = currrate2;
	
	var vNetTotal    = x.txtSaNetTotal.value;  
	var vCashInB1    = x.txtSaCashInB1.value;
	var vCashInB2    = x.txtSaCashInB2.value;
	var vCashOutB1   = x.txtSaCashOutB1.value;
	var vCashOutB2   = x.txtSaCashOutB2.value;
	var vTipsAmt     = x.txtSaTipsB1.value;
	
	if (vNetTotal == '')   vNetTotal = 0;
	if (vCashInB1 == '')   vCashInB1 = 0;
	if (vCashInB2 == '')   vCashInB2 = 0;
	if (vCashOutB1 == '')  vCashOutB1 = 0;
	if (vCashOutB2 == '')  vCashOutB2 = 0;
	if (vTipsAmt == '')    vTipsAmt = 0;
	
	vNetTotal   = parseFloat(vNetTotal);
	vCashInB1   = parseFloat(vCashInB1);
	vCashInB2   = parseFloat(vCashInB2);
	vCashOutB1  = parseFloat(vCashOutB1);
	vCashOutB2  = parseFloat(vCashOutB2);
	vTipsAmt    = parseFloat(vTipsAmt);
	
	x.txtSaCashOutB1.value = 0;
	x.txtSaCashOutB2.value = 0;
	x.txtSaTipsB1.value = 0;
		
	if (vCurr == vCurrBase1) 
		vCashOutB1 =   vNetTotal - vCashInB1 - (vCashInB2*vCurrRateB2/vCurrRateB1);	
	else if (vCurr == vCurrBase2)
		vCashOutB1 =   (vNetTotal*vCurrRateB2/vCurrRateB1) - vCashInB1 - (vCashInB2*vCurrRateB2/vCurrRateB1);	
	else 
		vCashOutB1 =   (vNetTotal*vCurrRate/vCurrRateB1) - vCashInB1 - (vCashInB2*vCurrRateB2/vCurrRateB1);		
	
	if (vCashOutB1 < 0)         
		x.txtSaCashOutB1.value = Math.round(Math.abs(vCashOutB1)*Math.pow(10,dec))/Math.pow(10,dec);
	else 	
		x.txtSaTipsB1.value =  Math.round((vCashOutB1)*Math.pow(10,dec))/Math.pow(10,dec);
			
}



function CalcCashOutB2(currbase1, currbase2, currrate, currrate1, currrate2, dec)
{
	x = document.cashpay;
	
	var vCurr        = x.txtSaCurr.value;
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	var vCurrRate	 = currrate;
	var vCurrRateB1  = currrate1;
	var vCurrRateB2  = currrate2;
	
	var vNetTotal    = x.txtSaNetTotal.value;  
	var vCashInB1    = x.txtSaCashInB1.value;
	var vCashInB2    = x.txtSaCashInB2.value;
	var vCashOutB1   = x.txtSaCashOutB1.value;
	var vCashOutB2   = x.txtSaCashOutB2.value;
	var vTipsAmt     = x.txtSaTipsB1.value;
	
	if (vNetTotal == '')   vNetTotal = 0;
	if (vCashInB1 == '')   vCashInB1 = 0;
	if (vCashInB2 == '')   vCashInB2 = 0;
	if (vCashOutB1 == '')  vCashOutB1 = 0;
	if (vCashOutB2 == '')  vCashOutB2 = 0;
	if (vTipsAmt == '')    vTipsAmt = 0;
	
	vNetTotal   = parseFloat(vNetTotal);
	vCashInB1   = parseFloat(vCashInB1);
	vCashInB2   = parseFloat(vCashInB2);
	vCashOutB1  = parseFloat(vCashOutB1);
	vCashOutB2  = parseFloat(vCashOutB2);
	vTipsAmt    = parseFloat(vTipsAmt);
	
	x.txtSaTipsB1.value = 0;
	
	if (vCurr == vCurrBase2) 
		vTipsBase =   vNetTotal - ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) - vCashInB2 + vCashOutB2;	
	else if (vCurr == vCurrBase1) 
		vTipsBase =   (vNetTotal*vCurrRateB1/vCurrRateB2) - ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) - vCashInB2 + vCashOutB2;	
	else  
		vTipsBase =   (vNetTotal*vCurrRate/vCurrRateB2) - ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) - vCashInB2 + vCashOutB2;	
	
	vTipsBase =   (vTipsBase*vCurrRateB2/vCurrRateB1);
	x.txtSaTipsB1.value =  Math.round((vTipsBase)*Math.pow(10,dec))/Math.pow(10,dec);
	
}

function showlistLedger(){
	x = document.cashpay;
	
	XPos = (screen.availHeight - 500) / 2;
	YPos = (screen.availWidth - 780) / 2;
	
	var keyword = encodeURIComponent(document.getElementById('ledgernumber').value);
		
	window.open('List_Agents_orderbycode.php?str=24&PRef='+keyword,'Ledgers','width=780,height=500,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,left='+YPos+',top='+XPos);
}

function CloseForm() {
	self.close();
}

function LoadForm() 
{
	
	x=document.cashpay;
	x.txtSaCashInB1.focus();
	
	ChangeLocation();
}

function ChangeLocation()
{
    if (document.cashpay.PMode.value == 1) {
		self.close();
	}	
}

function kd(e)
{ 
	x=document.cashpay;
	if (!e) { var e = window.event;}
    var intKey = (window.Event) ? e.which : e.keyCode;
	
	if (intKey == 13) { //enter key
	
		if(document.activeElement.id == 'txtSaCashInB1') {
			if (document.getElementById('txtSaCashInB2').type == 'text') {
				x.txtSaCashInB2.focus();
				x.txtSaCashInB2.select();
			}	
				
		}	
		else if(document.activeElement.id == 'txtSaCashInB2') {
			if (document.getElementById('txtSaCashOutB1').type == 'text') {
				x.txtSaCashOutB1.focus();
				x.txtSaCashOutB1.select();
			}	
		}
		else if(document.activeElement.id == 'txtSaCashOutB1') {
			if (document.getElementById('txtSaCashOutB2').type == 'text') {
				x.txtSaCashOutB2.focus();
				x.txtSaCashOutB2.select();
			}	
		}
		else if(document.activeElement.id == 'txtSaCashOutB2') {
			if (document.getElementById('txtSaCashInB1').type == 'text') {
				x.txtSaCashInB1.focus();	
				x.txtSaCashInB1.select();
			}	
		}
		
		return false;
    }
	
	
    return true;
}

</script>
<title>Cash Payment</title>

<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;
}
.style11 {color: #999999; font-weight: bold; }
.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>

</head>
<body onLoad='LoadForm();' onkeydown='return kd(event);' >
<form name='cashpay' method='post'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='PSaId' value='$PSaId'>
<input type='hidden' name='PMode' id='PMode' value='$PMode' />
HERE;
	


if($PSaId != ''){
	$query = " Select Deliveries.Delivery_Id, Deliveries.Currency_Code, ".
			 " ( ifNull(Delivery_Total,0) + IfNull(Delivery_VAT,0) + IfNull(Delivery_TransportAmount,0) + IfNull(Delivery_BonusAmount,0) - IfNull(Delivery_DiscountAmount,0) + ".
			 "  (ifNull(Delivery_Tax1,0) + ifNull(Delivery_Tax2,0) + ifNull(Delivery_Tax3,0) + ifNull(Delivery_Tax4,0) + ifNull(Delivery_Tax5,0))) As Sale_NetTotal,  ".
			 " Round(ifNull(Delivery_CashInBase1,0), ".$DecimalBase1."), Round(ifNull(Delivery_CashInBase2,0), ".$DecimalBase2."), ".
			 " Round(ifNull(Delivery_CashOutBase1,0), ".$DecimalBase1."), Round(ifNull(Delivery_CashOutBase2,0), ".$DecimalBase2."), ".
			 " Round(ifNull(Delivery_TipsBase1,0), ".$DecimalBase1."), Deliveries.Delivery_CashAccount, Ledger.Ledger_Name ".
			 " From Temp_Deliveries As Deliveries ".
			 " Left Join Ledger on Ledger.Ledger_Number = Deliveries.Delivery_CashAccount ".
			 " Where Deliveries.Delivery_Id = '".$PSaId."'";
			   
	//echo $query;
	$result=mysql_query($query,$connection) or die(mysql_error());
    $rows=mysql_fetch_array($result);

	$txtSaCurr      = $rows[1];
	$txtSaNetTotal  = $rows[2];
	$txtSaCashInB1  = $rows[3];
	$txtSaCashInB2  = $rows[4];
	$txtSaCashOutB1 = $rows[5];
	$txtSaCashOutB2 = $rows[6];
	$txtSaTipsB1 	= $rows[7];
	
	$txtLedgerNo   = $rows[8];
	$txtLedgerName = $rows[9];
	
	if (empty($txtLedgerNo)) {
		$txtLedgerNo   = $CashAccount;
		$txtLedgerName = $CashAccountName;
	}
	
}

$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$txtSaCurr."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$txtSaCurr."' )";
$result = selectData($connection, $query);
$rate_dt = $result[0];

$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$base1."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$base1."' )";
$result = selectData($connection, $query);
$rate_dt1 = $result[0];
	
$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$base2."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$base2."' )";
$result = selectData($connection, $query);
$rate_dt2 = $result[0];


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

echo"	<table border='0' cellpadding='1' style='table-layout:fixed' align='center' valign='top' >
		<col width=50>
		<col width=140>
		<col width=140>
			<tr bgcolor='#F7F7F7'>
				<td align='center' colspan='3'><span class='style16'>Total: ". number_format($txtSaNetTotal, $DecimalBase) . "  " . $txtSaCurr ."</span></td>
			</tr>	
			<tr bgcolor='#F7F7F7'>
				<td align='center' colspan='3'><b>".$message."</b></td>
			</tr>
			<tr bgcolor='#F7F7F7'>
				<td align='left'><span class='style11'>Cash</span></td>
				<td align='left' colspan='2'>";
echo "				<input type='text' name='txtLedgerNo' id='ledgernumber' value='$txtLedgerNo'  maxlength='10' style='font-size:12px; width:75px; height:20px;'   />
						<label><span><img src='img/btnopen.jpg' title='Select Ledger' id='lstLedgerCode' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistLedger();\" style='vertical-align:bottom;'/></span></label>
					<input type='text' name='txtLedgerName' id='ledgername' value='$txtLedgerName' style='font-size:12px; width:165px; height:20px;'  />
				</td>
			</tr>";
			
echo"	    <tr bgcolor='#F7F7F7'>
				<td align='center'>&nbsp;</td>
				<td align='center'><span class='style16'>Pay</span></td>
				<td align='center'><span class='style16'>Return</span></td>
			</tr>	
			<tr bgcolor='#F7F7F7'>
				<td align='left'><span class='style16'>$base1</span></td>
				<input type='hidden' name='txtSaCurr' id='txtSaCurr' value='$txtSaCurr' >
				<input type='hidden' name='txtSaNetTotal' id='txtSaNetTotal' value='$txtSaNetTotal' >
				<input type='hidden' name='txtSaTipsB1' id='txtSaTipsB1' value='$txtSaTipsB1'  >
				<td align='right'><input type='text' name='txtSaCashInB1' id='txtSaCashInB1' value='$txtSaCashInB1' onChange=\"CalcCashInB1('".$base1."', '".$base2."', $rate_dt, $rate_dt1, $rate_dt2, $DecimalBase1);\"   maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:130px; height:22px;'></td>
				<td align='right'><input type='text' name='txtSaCashOutB1' id='txtSaCashOutB1' value='$txtSaCashOutB1'  onChange=\"CalcCashOutB1('".$base1."', '".$base2."', $rate_dt, $rate_dt1, $rate_dt2, $DecimalBase1);\"  maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:130px; height:22px;'></td>
			</tr>
			<tr bgcolor='#F7F7F7'>
				<td align='left'><span class='style16'>$base2</span></td>
				<td align='right'><input type='text' name='txtSaCashInB2' id='txtSaCashInB2' value='$txtSaCashInB2' onChange=\"CalcCashInB2('".$base1."', '".$base2."', $rate_dt, $rate_dt1, $rate_dt2, $DecimalBase1);\"  maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:130px; height:22px;'></td>
				<td align='right'><input type='text' name='txtSaCashOutB2' id='txtSaCashOutB2' value='$txtSaCashOutB2' onChange=\"CalcCashOutB2('".$base1."', '".$base2."', $rate_dt, $rate_dt1, $rate_dt2, $DecimalBase1);\"  maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:130px; height:22px;'></td>
			</tr>
			<tr bgcolor='#F7F7F7'>
				<td align='left' colspan='3'><span class='style16'>&nbsp;</span></td>
			</tr>
			<tr bgcolor='#F7F7F7'>
				<td align='center' colspan='3'>
					<input type='button' id='btnOk' name='btnOk'  value='Ok'  onclick=\"SubmitRecord('".$base1."', '".$base2."', $rate_dt, $rate_dt1, $rate_dt2, $DecimalBase1, '".$Login_TipsMaxAmount."');\" $style title='Save Changes'>
					<input type='button' id='btnClose' name='btnClose'  value='Close'  onclick='CloseForm();' $style title='Close'>
				</td>	
			</tr>";
echo"	</table>";	
	
	
	

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

HERE;

?>