<?php

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



include("config.inc.php");
include("Functions_Sales.php");
include("function.inc.php");

$PhpPort = $config['PhpPort'];
set_time_limit(0);

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


	
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ifNull(ShowSlipNumber,0) As ShowSlipNumber, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage, ".
			 " ifNull(Setup_TipsMaxAmount, 0) As Setup_TipsMaxAmount, Company_Name As CompanyName, ifNull(CashReg_DispLedMsg, 'Welcome !') As CashReg_DispLedMsg, ".
			 " ifNull(CashReg_RoundDivisor,1) As CashReg_RoundDivisor,ifnull(cashreg_colortheme,'default') as cashreg_colortheme, ifnull(POS_RedeemPoints,0) as POS_RedeemPoints  ".
			 " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

$querylog=" select ifNull(FC_CashRegisterCredit,0) As FC_CashRegisterCredit, ifNull(FC_CashRegisterCheck,0) As FC_CashRegisterCheck, ".
		  " ifNull(FC_CashRegisterCoupon,0) As FC_CashRegisterCoupon, ifNull(FC_CashRegisterCustomer,0) As FC_CashRegisterCustomer, ".
		  " ifNull(FC_ShowBtnOpenDrawer,0) As FC_ShowBtnOpenDrawer ".
		  " 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);
}


//Read From CashRegister Table
$queryCashRegister=" Select Upper(CashRegister_Name) As CashRegister_Name, Currency_Code As StpCurrCode, CostCenter_Code As StpCostCentCode, Project_Code As StpProjectCode, ".
                   " CashRegister_SerialNo, CashRegister_Discount, CashRegisterTTC, Client_Account As StpClientAccount, Warehouse_Code As StpWarehouseCode, ifNull(CashReg_Vendor,0) As CashReg_Vendor,  ".
				   " ifNull(CashRegister_DisplayLed,0) As CashRegister_DisplayLed, ifNull(CashRegister_DispCOM,0) As CashRegister_DispCOM, ".
				   " ifNull(CashRegister_LedDescLength,0) As CashRegister_LedDescLength,ifNull(CashRegister_DrawerCOM,0) As CashRegister_DrawerCOM, ".
				   " ifNull(CashRegister_Printer,0) As CashRegister_Printer, ifNull(CashRegister_Drawer,0) As CashRegister_Drawer, CashRegister_DrawerPrinter, ".
				   " ifNull(CashRegister_SlipPrinter,0) As CashRegister_SlipPrinter, ifnull(Show_CustomerInRetail,0) as Show_CustomerInRetail, ".
				   " ifNull(CashRegister_RestrictSlipNoOnPay,0) As CashRegister_RestrictSlipNoOnPay  ".
				   " From CashRegister ".
				   " Where CashRegister_Name = '".$_SESSION['cashregister']."' ";
$resultCashRegister=mysql_query($queryCashRegister,$connection) or die(mysql_error());
while($rowCashRegister=mysql_fetch_array($resultCashRegister)){
	extract($rowCashRegister);
}


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

$querycurrency="select Currency_code from currency order by currency_code";
$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());

if ($CashRegister_DisplayLed != 1) $CashRegister_DispCOM = 0;



$actionmode    = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$mainaction	   = $_POST["mainaction"]; if ($mainaction == ""){$mainaction = $_GET["mainaction"];}   
$message 	   = $_POST["message"]; if ($message == ""){$message = $_GET["message"];}   
$noprint 	   = $_POST["noprint"]; if ($noprint == ""){$noprint = $_GET["noprint"];}   
$PRetId 	   = $_POST["PRetId"]; if ($PRetId == ""){$PRetId = $_GET["PRetId"];}   
$txtFocusField = $_POST["txtFocusField"]; if ($txtFocusField == ""){$txtFocusField = $_GET["txtFocusField"];}   

$txtRetDate 		= $_POST["txtRetDate"]; if ($txtRetDate == ""){$txtRetDate = $_GET["txtRetDate"];} 
$txtRetCurr 		= $_POST["txtRetCurr"]; if ($txtRetCurr == ""){$txtRetCurr = $_GET["txtRetCurr"];} 
$txtRetCustomerCode = $_POST["txtRetCustomerCode"]; if ($txtRetCustomerCode == ""){$txtRetCustomerCode = $_GET["txtRetCustomerCode"];} 
$txtRetCustomerName = $_POST["txtRetCustomerName"]; if ($txtRetCustomerName == ""){$txtRetCustomerName = $_GET["txtRetCustomerName"];} 
$txtRetSalesmanCode = $_POST["txtRetSalesmanCode"]; if ($txtRetSalesmanCode == ""){$txtRetSalesmanCode = $_GET["txtRetSalesmanCode"];} 
$txtRetSalesmanName = $_POST["txtRetSalesmanName"]; if ($txtRetSalesmanName == ""){$txtRetSalesmanName = $_GET["txtRetSalesmanName"];} 
$txtRetRemark 		= $_POST["txtRetRemark"]; if ($txtRetRemark == ""){$txtRetRemark = $_GET["txtRetRemark"];} 

$txtRetCouponId 	= $_POST["txtRetCouponId"]; if ($txtRetCouponId == ""){$txtRetCouponId = $_GET["txtRetCouponId"];} 
$txtRetCouponCode 	= $_POST["txtRetCouponCode"]; if ($txtRetCouponCode == ""){$txtRetCouponCode = $_GET["txtRetCouponCode"];}   
$txtRetCouponName 	= $_POST["txtRetCouponName"]; if ($txtRetCouponName == ""){$txtRetCouponName = $_GET["txtRetCouponName"];}   
$txtRetCouponAmt 	= $_POST["txtRetCouponAmt"]; if ($txtRetCouponAmt == ""){$txtRetCouponAmt = $_GET["txtRetCouponAmt"];}   
$txtRetCouponRemAmt	= $_POST["txtRetCouponRemAmt"]; if ($txtRetCouponRemAmt == ""){$txtRetCouponRemAmt = $_GET["txtRetCouponRemAmt"];}   

$txtRetCreditCard 	= $_POST["txtRetCreditCard"]; if ($txtRetCreditCard == ""){$txtRetCreditCard = $_GET["txtRetCreditCard"];}   
$txtRetCreditName 	= $_POST["txtRetCreditName"]; if ($txtRetCreditName == ""){$txtRetCreditName = $_GET["txtRetCreditName"];}   
$txtRetCreditCurr 	= $_POST["txtRetCreditCurr"]; if ($txtRetCreditCurr == ""){$txtRetCreditCurr = $_GET["txtRetCreditCurr"];}   
$txtRetCreditAmt 	= $_POST["txtRetCreditAmt"]; if ($txtRetCreditAmt == ""){$txtRetCreditAmt = $_GET["txtRetCreditAmt"];}   

$txtRetCheckNo 		= $_POST["txtRetCheckNo"]; if ($txtRetCheckNo == ""){$txtRetCheckNo = $_GET["txtRetCheckNo"];}   
$txtRetCheckDate 	= $_POST["txtRetCheckDate"]; if ($txtRetCheckDate == ""){$txtRetCheckDate = $_GET["txtRetCheckDate"];}   
$txtRetBankName 	= $_POST["txtRetBankName"]; if ($txtRetBankName == ""){$txtRetBankName = $_GET["txtRetBankName"];}   
$txtRetBranchName 	= $_POST["txtRetBranchName"]; if ($txtRetBranchName == ""){$txtRetBranchName = $_GET["txtRetBranchName"];}   
$txtRetCashCurr 	= $_POST["txtRetCashCurr"]; if ($txtRetCashCurr == ""){$txtRetCashCurr = $_GET["txtRetCashCurr"];}   
$txtRetCashAmt 		= $_POST["txtRetCashAmt"]; if ($txtRetCashAmt == ""){$txtRetCashAmt = $_GET["txtRetCashAmt"];}   

$txtRetCashInB1 	= $_POST["txtRetCashInB1"]; if ($txtRetCashInB1 == ""){$txtRetCashInB1 = $_GET["txtRetCashInB1"];}   
$txtRetCashOutB1 	= $_POST["txtRetCashOutB1"]; if ($txtRetCashOutB1 == ""){$txtRetCashOutB1 = $_GET["txtRetCashOutB1"];}   
$txtRetCashInB2 	= $_POST["txtRetCashInB2"]; if ($txtRetCashInB2 == ""){$txtRetCashInB2 = $_GET["txtRetCashInB2"];}   
$txtRetCashOutB2 	= $_POST["txtRetCashOutB2"]; if ($txtRetCashOutB2 == ""){$txtRetCashOutB2 = $_GET["txtRetCashOutB2"];}   
$txtRetTipsB1H 		= $_POST["txtRetTipsB1H"]; if ($txtRetTipsB1H == ""){$txtRetTipsB1H = $_GET["txtRetTipsB1H"];}   
$txtRetTipsB1 		= $_POST["txtRetTipsB1"]; if ($txtRetTipsB1 == ""){$txtRetTipsB1 = $_GET["txtRetTipsB1"];}   



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" />
HERE;

if($cashreg_colortheme=='red'){
	echo'<link rel="stylesheet" type="text/css" media="all" href="css-v2/style-red.css">';
	echo'<link rel="stylesheet" type="text/css" href="js/menu-v2/menu-red.css" />';
}	
else if($cashreg_colortheme=='' || $cashreg_colortheme=='default')	{
	echo'<link rel="stylesheet" type="text/css" media="all" href="css-v2/style-default.css">';
	echo'<link rel="stylesheet" type="text/css" href="js/menu-v2/menu-default.css" />';
}

if ($CashRegister_SlipPrinter == 1) $ReportName = 'Form_RetailSlip.php';
else $ReportName = 'Form_RetailPreview.php';


print <<<HERE
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<script type="text/javascript" language="javascript">
		
function SetPort(ParPort) { 
    var port = document.getElementById("comport"); //find the serial port ActiveX object
    port.Port=ParPort; //Please check what the port number is correct!!
    port.BaudRate=9600;
    port.DataBits=8;
    port.Parity=0; //NOPARITY
    port.StopBits=0; //one stop bit
    port.DataMode=1; //Gives us data as text strings instead of byte arrays
	port.Connected=0; //Connects to the serial port
    port.Connected=1; //Connects to the serial port
    if(port.error>0) //Display errors if found
       alert(port.ErrorDescription);
}
  
function SendData(VarData) { 
    var port = document.getElementById("comport");
	port.Send(VarData);
	//alert(VarData);   
}

function ClosePort(ParPort) { 
    var port = document.getElementById("comport"); //find the serial port ActiveX object
	
    port.Port=ParPort; //Please check what the port number is correct!!
    port.BaudRate=9600;
    port.DataBits=8;
    port.Parity=0; //NOPARITY
    port.StopBits=0; //one stop bit
    port.DataMode=1; //Gives us data as text strings instead of byte arrays
    port.Connected=0; //Connects to the serial port
    if(port.error>0) //Display errors if found
       alert(port.ErrorDescription);
   // CommEvent(port.event,EVT_DISCONNECT);	   
}
   
function MakeCursorHourglass()
{
    document.body.style.cursor = "wait";
}

function SubmitRecord(currbase1, currbase2, currrate1, currrate2, dec, SetupTipsMaxAmount) {
	x = document.retailpay;
	var result;
	result = CheckFields(currbase1, currbase2, currrate1, currrate2, dec, SetupTipsMaxAmount);
	var vRetId    = x.PRetId.value;
	
	var vMainMode = x.mainaction.value;
	var vNoPrint = x.noprint.value;
	var vMode = 'payment';	
	
	var vCurr        = x.txtRetCurr.value;
	
	var dueamnt     = x.txtRetNetTotal.value;
		
	var creditamnt  = x.txtRetCreditAmt.value;
	var cashamnt1   = x.txtRetCashInB1.value;
	var cashamnt2   = x.txtRetCashInB2.value;
	var differamnt1 = x.txtRetCashOutB1.value;
	var differamnt2 = x.txtRetCashOutB2.value;
	var checkamnt   = x.txtRetCashAmt.value;
	var tipsamnt    = x.txtRetTipsB1.value;
	var vslipNo    = x.txtslipNO.value;
	var vledgernbr = document.getElementById("txtRetCreditCard").value;
	var checkCur    		= x.txtRetCashCurr.value;
	var RetCustomerAmount	= x.txtRetCustomerAmount.value;
	var RetCouponAmt = 0;
	if(x.txtRetCouponAmt)
		RetCouponAmt = x.txtRetCouponAmt.value;
	
	var chkRedeemCustomerPt = 0;
		
	if(document.getElementById('chkRedeemCustomerPt').checked)	
		chkRedeemCustomerPt = 1;
	var CreditCur	= '';
	for(i=0;i<x.txtRetCreditCurr.length;i++){
		if(x.txtRetCreditCurr[i].checked) CreditCur = x.txtRetCreditCurr.value;
	}
		
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp5=new XMLHttpRequest();
	}
	else{//code for IE6, IE5
		xmlhttp5=new ActiveXObject("Microsoft.xmlhttp");
	}
	xmlhttp5.onreadystatechange=function()
	{
		if (xmlhttp5.readyState==4 && xmlhttp5.status==200)
		{
	 
			var data = xmlhttp5.responseText.split("[BRK]");
			
		 //alert (xmlhttp5.responseText);
			
			if(data[1] == 1){
				alert("Amount payed differs from Amount Due!");
				//x.txtRetCreditAmt.value=dueamnt;
			}else if(data[1] == 2){
				alert("Check Slip Number!");
				x.txtslipNO.focus();
			}
			else {
				if (result == 1) {
					if (confirm ( "Are you sure you want to Save current invoice?"))
					{
						x.btnOk.disabled = true;
						x.btnCancel.disabled = true;
						x.btnClose.disabled = true;
							
						if (document.getElementById('btnDrawer'))
							x.btnDrawer.disabled = true;	

						var ledgernbr = document.getElementById("txtRetCreditCard").value;		
						x.action="Form_Retail_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&noprint="+vNoPrint+"&SRetId="+vRetId+"&txtLedgernbr="+ledgernbr
							+"&chkRedeemCustomerPt="+chkRedeemCustomerPt+"&slipNo="+vslipNo;
						x.submit();
									
						document.getElementById("mainDiv").style.display="block";
						document.getElementById("imgDiv").style.display="block";
						MakeCursorHourglass();
					}	
				}
			}			
		}			
	}
		
	xmlhttp5.open("GET","Form_Retail_Actions.php?mode=checkpayment&SRetId="+vRetId+"&dueamnt="+dueamnt+"&creditamnt="+creditamnt+"&cashamnt1="+cashamnt1+"&cashamnt2="+cashamnt2+"&differamnt1="+differamnt1+
				"&differamnt2="+differamnt2+"&checkamnt="+checkamnt+"&checkCur="+checkCur+"&CreditCur="+CreditCur+"&tipsamnt="+tipsamnt+"&RetCustomerAmount="+RetCustomerAmount+"&RetCouponAmt="+RetCouponAmt+"&SlipNo="+vslipNo+"&creditcard="+vledgernbr);
	xmlhttp5.send();
	
}

function CancelRecord() {
	x = document.retailpay;
	ClearForm();
	
	x.submit();
	
	//self.close();
}

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

function CheckFields(currbase1, currbase2, currrate1, currrate2, dec, SetupTipsMaxAmount){
  
    x = document.retailpay;
	var vAmtPayed = 0;
	
	var vCurr        = x.txtRetCurr.value;
	
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	var vCurrRateB1  = currrate1;
	var vCurrRateB2  = currrate2;

	
	var vNetTotal   		= x.txtRetNetTotal.value;  
	var vCouponAmt  		= x.txtRetCouponAmt.value;  
	var vCreditAmt  		= x.txtRetCreditAmtB12.value;
	var vCashAmt    		= x.txtRetCashAmtB12.value;
	var vCashInB1   		= x.txtRetCashInB1.value;
	var vCashInB2   		= x.txtRetCashInB2.value;
	var vCashOutB1  		= x.txtRetCashOutB1.value;
	var vCashOutB2  		= x.txtRetCashOutB2.value;
	var vTipsB1     		= x.txtRetTipsB1H.value;
	var RetCustomerAmount   = x.txtRetCustomerAmount.value;
	

	if (vNetTotal == '')   			vNetTotal = 0;
	if (vCouponAmt == '')  			vCouponAmt = 0;
	if (vCreditAmt == '')  			vCreditAmt = 0;
	if (vCashAmt == '')    			vCashAmt = 0;
	if (vCashInB1 == '')   			vCashInB1 = 0;
	if (vCashInB2 == '')   			vCashInB2 = 0;
	if (vCashOutB1 == '')  			vCashOutB1 = 0;
	if (vCashOutB2 == '')  			vCashOutB2 = 0;
	if (vTipsB1 == '')     			vTipsB1 = 0;
	if (RetCustomerAmount == '')    RetCustomerAmount = 0;

	
	vNetTotal   		= parseFloat(vNetTotal);
	vCouponAmt  		= parseFloat(vCouponAmt);
	vCreditAmt  		= parseFloat(vCreditAmt);
	vCashAmt    		= parseFloat(vCashAmt);
	vCashInB1   		= parseFloat(vCashInB1);
	vCashInB2   		= parseFloat(vCashInB2);
	vCashOutB1  		= parseFloat(vCashOutB1);
	vCashOutB2  		= parseFloat(vCashOutB2);
	vTipsB1  			= parseFloat(vTipsB1);
	RetCustomerAmount  	= parseFloat(RetCustomerAmount);
	
	
	if (vCurr == vCurrBase1) 
		vAmtPayed =   vNetTotal - (RetCustomerAmount + vCouponAmt + vCreditAmt + vCashAmt + vCashInB1 + (vCashInB2*vCurrRateB2/vCurrRateB1) + vTipsB1) + vCashOutB1 + (vCashOutB2*vCurrRateB2/vCurrRateB1);	
	else 	
		vAmtPayed =   vNetTotal - (RetCustomerAmount + vCouponAmt + vCreditAmt + vCashAmt + (vCashInB1*vCurrRateB1/vCurrRateB2) + vCashInB2 + (vTipsB1*vCurrRateB1/vCurrRateB2)) + (vCashOutB1*vCurrRateB1/vCurrRateB2) + vCashOutB2;
					   
	
	vAmtPayed =  Math.round((vAmtPayed)*Math.pow(10,0))/Math.pow(10,0);
	
	if (Math.abs(vTipsB1) > SetupTipsMaxAmount) {
		alert("Tips amount exceeds max allowed amount ("+SetupTipsMaxAmount+")!");
		x.txtRetCashInB1.focus();
		return 0;
	}
	else if (RetCustomerAmount == 0 && vCashInB1==0 && vCashInB2==0 && vCouponAmt==0 && vCreditAmt==0 && vCashAmt==0 && vCashOutB1 && vCashOutB2) 
	{
		alert("Amount is mandatory!");
		x.txtRetCashInB1.focus();
		return 0;
	}
	/*else if (x.txtRetCustomerCode.value=='') 
	{
		alert("Customer is mandatory!");
		x.txtRetCustomerCode.focus();
		return 0;
	}*/
	else if (x.txtRetCreditAmt.value!=0 && x.txtRetCreditCard.value=='') 
	{
		alert("Missing credit information!");
		x.txtRetCreditCard.focus();
		return 0;
	}
	else if (vCouponAmt!=0 && vCouponAmt > 0 && x.txtRetCouponCode.value=='') 
	{
		alert("Missing coupon information!");
		x.txtRetCouponCode.focus();
		return 0;
	}
	else if (x.txtRetCashAmt.value!=0 && (x.txtRetCheckNo.value=='' || x.txtRetCheckDate.value=='' || x.txtRetBankName.value=='' || x.txtRetBranchName.value=='' || x.txtRetCashCurr.value=='')) 
	{
		alert("Missing bank information!");
		x.txtRetCheckNo.focus();
		return 0;
	}
	else if (x.txtRetCheckNo.value!='' && x.txtRetCashAmt.value==0 ) 
	{
		alert("Missing bank information!");
		x.txtRetCheckNo.focus();
		return 0;
	}
	else if ((vCurr == vCurrBase2 && vAmtPayed != 0) || (vCurr == vCurrBase1 && vNetTotal > 0 && Math.abs(vAmtPayed) > SetupTipsMaxAmount) || 
			 (vCurr == vCurrBase1 && vNetTotal < 0 && vAmtPayed != 0))
	{
		alert("Amount payed differs from Amount Due.!");
		//alert(vCurr+'='+vCurrBase1+'='+vCurrBase2+'='+vAmtPayed+'='+vNetTotal+'='+SetupTipsMaxAmount);
		x.txtRetCashInB1.focus();
		return 0;
	
	}
		
	
	else
	return 1 ;	
}

/*function OpenDrawer() {
	XPos = (screen.availHeight - 50) / 2;
	YPos = (screen.availWidth - 50) / 2;
	
	var disp_setting="toolbar=no,location=no,menubar=no,addressbar=no,status=no,";
	disp_setting+="scrollbars=no,resizable=no,width=50, height=50,left="+YPos+",top="+XPos; 
	
	var docprint=window.open("Form_Retail_Drawer.php","Drawer",disp_setting);
	docprint.focus(); 
}*/

function OpenDrawer(){
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else{//code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data = $.parseJSON(xmlhttp.responseText);
			var msg = data[0].message;
			
			if (msg !='') alert(msg);
									
		}			
	}			
			
	xmlhttp.open("GET","Functions_Retail.php?form=OpenDrawer&action=OpenDrawer");
	xmlhttp.send();	

}

function ChangeLocation(Vphpport,VarPort)
{
	x = document.retailpay;
	var vMode  = x.actionmode.value;
	var vMsg   = x.message.value;
	var vNoPrint = x.noprint.value;
	var vRetId =  x.PRetId.value;
	
    if (vMode == 'payed') {
		opener.document.retail.actionmode.value = '';
		opener.document.retail.mainaction.value = '';
		opener.document.retail.noprint.value = vNoPrint;
		opener.document.retail.message.value = vMsg;
		opener.document.retail.PrRetId.value = vRetId;

		if (VarPort!=0 && (Vphpport==0 || Vphpport=='')) {
			ClosePort(VarPort);
		}
			
		
		//opener.document.retail.action='Form_Retail.php?actionmode=&mainaction=&message='+vMsg;
		
		opener.document.retail.copiedVers.value=0;
		opener.document.retail.noprint.value=0;
		opener.document.retail.action='Form_Retail.php';
		opener.document.retail.submit();
		self.close();
	} 
	
	x.txtRetCashInB1.focus();
	x.txtRetCashInB1.select();
}


function LoadForm(Vphpport,VarPort) 
{
	//window.resizeTo(400,400)
	
	x=document.retailpay;
	x.txtRetCashInB1.focus();
	
	ChangeLocation(Vphpport,VarPort);
}

function ClearForm(){
    x = document.retailpay;
	var vmode = x.actionmode.value;
	
	x.txtRetDate.value='';
	x.txtRetCurr.value='';
	x.txtRetNetTotal.value='';  
	x.txtRetNetTotalB1Disp.value='';
	x.txtRetCurrB1.value='';
	x.txtRetNetTotalB2Disp.value='';
	x.txtRetCurrB2.value='';

	x.txtRetCustomerCode.value='';
	x.txtRetCustomerName.value='';
	x.txtRetSalesmanCode.value='';
	x.txtRetSalesmanName.value='';
	x.txtRetRemark.value='';

	x.txtRetCouponId.value='';
	x.txtRetCouponCode.value='';
	x.txtRetCouponName.value='';
	x.txtRetCouponAmt.value='';
	x.txtRetCouponRemAmt.value='';
	
	x.txtRetCreditCard.value='';
	x.txtRetCreditCurr.value='';
	x.txtRetCreditName.value='';
	x.txtRetCreditAmt.value='';

	x.txtRetCheckNo.value='';
	x.txtRetCheckDate.value='';
	x.txtRetBankName.value='';
	x.txtRetBranchName.value='';
	x.txtRetCashCurr.value='';
	x.txtRetCashAmt.value='';
	

	x.txtRetCashInB1.value='';
	x.txtRetCashOutB1.value='';
	x.txtRetCashInB2.value='';
	x.txtRetCashOutB2.value='';
	
	x.txtRetCreditAmtB12.value='';
	x.txtRetCashAmtB12.value='';
	x.txtRetTipsB1.value='';
	x.txtLedgerClientCard.value='';
	x.txtRetCustomerDisc.value='';
	x.txtRetCustomerPt.value='';
	
	x.message.value='';
	x.actionmode.value = '';
	

}

// create the XMLHttpRequest object, according browser
function get_XmlHttp() {
  // create the variable that will contain the instance of the XMLHttpRequest object (initially with null value)
  var xmlHttp = null;

  if(window.XMLHttpRequest) {		// for Forefox, IE7+, Opera, Safari, ...
    xmlHttp = new XMLHttpRequest();
  }
  else if(window.ActiveXObject) {	// for Internet Explorer 5 or 6
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }

  return xmlHttp;
}



function ConvertCurrency(FromCurr, ToCurr, FromDate, Amount, tagID) {
    
	var request =  get_XmlHttp();		// calls the function for the XMLHttpRequest instance
	
	request.open("GET","GetCurrencyRate.php?FromCurr="+FromCurr+"&ToCurr="+ToCurr+"&FromDate="+FromDate+"&Amount="+Amount,true);
	request.send();
	
	request.onreadystatechange=function()
	{
		if (request.readyState==4 && request.status==200)
		{   
		    document.getElementById(tagID).value=request.responseText;
		} 
		
	}
	
	
		
}

function ConvertAmount(tagID) {

//alert(tagID);
	x = document.retailpay;
	
	for (var i=0; i < x.txtRetCreditCurr.length; i++)
	{
		if (x.txtRetCreditCurr[i].checked)
		{
			var vCreditCurr = x.txtRetCreditCurr[i].value;
		}
	}
	
	var vDate       = x.txtRetDate.value;
	var vCurr       = x.txtRetCurr.value;
	var vCashCurr   = x.txtRetCashCurr.value;

	var vCreditAmt  = x.txtRetCreditAmt.value;
	var vCashAmt    = x.txtRetCashAmt.value;
	
	if (vCreditAmt == '')  vCreditAmt = 0;
	if (vCashAmt == '')    vCashAmt = 0;
	
	vCreditAmt  = parseFloat(vCreditAmt);
	vCashAmt    = parseFloat(vCashAmt);
	
	if (tagID == 'txtRetCreditCurr' || tagID == 'txtRetCreditAmt') {
		ConvertCurrency(vCreditCurr, vCurr, vDate, vCreditAmt, 'txtRetCreditAmtB12'); 
	}	
	else if (tagID == 'txtRetCashCurr' || tagID == 'txtRetCashAmt') {
		ConvertCurrency(vCashCurr  , vCurr, vDate, vCashAmt  , 'txtRetCashAmtB12');
	}	
	
}

function ConvertAmount2(tagID) {

//alert(tagID);
	x = document.retailpay;
	
	for (var i=0; i < x.txtRetCreditCurr.length; i++)
	{
		if (x.txtRetCreditCurr[i].checked)
		{
			var vCreditCurr = x.txtRetCreditCurr[i].value;
		}
	}
	
	var vDate       = x.txtRetDate.value;
	var vCurr       = x.txtRetCurr.value;
	var vCashCurr   = x.txtRetCashCurr.value;
	
	var vNetTotal   = x.txtRetNetTotal.value;  

	/*var vCreditAmt  = x.txtRetCreditAmtB12.value;
	var vCashAmt    = x.txtRetCashAmtB12.value;
	
	if (vCreditAmt == '')  vCreditAmt = 0;
	if (vCashAmt == '')    vCashAmt = 0;
	
	vCreditAmt  = parseFloat(vCreditAmt);
	vCashAmt    = parseFloat(vCashAmt);*/
	
	if (tagID == 'txtRetCreditCurr' || tagID == 'txtRetCreditAmt') {
		ConvertCurrency(vCurr, vCreditCurr, vDate, vNetTotal, 'txtRetCreditAmt'); 
	}	
	else if (tagID == 'txtRetCashCurr' || tagID == 'txtRetCashAmt') {
		ConvertCurrency(vCurr, vCashCurr, vDate, vNetTotal, 'txtRetCashAmt');
	}	
	
}

function ConvertAmount1(tagID, currbase1, currbase2, dec) {
	ConvertAmount2(tagID);
	window.setTimeout('ConvertAmount(\''+tagID+'\')',100);
	window.setTimeout('CalcCopounCreditCheck(\''+currbase1+'\', \''+currbase2+'\', '+dec+')',200);

}

function CalcBalanceAmount(tagID, currbase1, currbase2, dec) {
	x = document.retailpay;
	
	for (var i=0; i < x.txtRetCreditCurr.length; i++)
	{
		if (x.txtRetCreditCurr[i].checked)
		{
			var vCreditCurr = x.txtRetCreditCurr[i].value;
		}
	}
	
	var vDate       = x.txtRetDate.value;
	var vCurr       = x.txtRetCurr.value;
	var vCashCurr   = x.txtRetCashCurr.value;
	
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	//var vCurrRateB1  = currrate1;
	//var vCurrRateB2  = currrate2;

	
	x.txtRetCashInB1.value   = 0;
	x.txtRetCashInB2.value   = 0;
	x.txtRetCashOutB1.value  = 0;
	x.txtRetCashOutB2.value  = 0;
	//x.txtRetTipsB1.value     = 0;
	
	var vNetTotal   = x.txtRetNetTotal.value;  
	var vCouponAmt  = x.txtRetCouponAmt.value;  
	var vCreditAmt  = x.txtRetCreditAmtB12.value;
	var vCashAmt    = x.txtRetCashAmtB12.value;
	var vRetTipsB1  =x.txtRetTipsB1.value;

	if (vNetTotal == '')   vNetTotal = 0;
	if (vCouponAmt == '')  vCouponAmt = 0;
	if (vCreditAmt == '')  vCreditAmt = 0;
	if (vCashAmt == '')    vCashAmt = 0;
	
	
	vNetTotal   = parseFloat(vNetTotal);
	vCouponAmt  = parseFloat(vCouponAmt);
	vCreditAmt  = parseFloat(vCreditAmt);
	vCashAmt    = parseFloat(vCashAmt);
	

	
	if (tagID == 'btnCreditAmt' || tagID == 'txtRetCreditAmt' || tagID == 'txtRetCreditCurr') {
		x.txtRetCreditAmtB12.value = 0;
		x.txtRetCreditAmt.value    = 0;
		
		vObjID = 'txtRetCreditAmt';
		
		vBalanceAmt =  vNetTotal-vRetTipsB1 - (vCouponAmt + vCashAmt);
		
		ConvertCurrency(vCurr, vCreditCurr, vDate, vBalanceAmt, 'txtRetCreditAmt');
		window.setTimeout('ConvertAmount(\''+vObjID+'\')',100);
		window.setTimeout('CalcCopounCreditCheck(\''+currbase1+'\', \''+currbase2+'\', '+dec+')',200);
	}
	else if (tagID == 'btnCheckAmt' || tagID == 'txtRetCashCurr') {
		x.txtRetCashAmtB12.value = 0;
		x.txtRetCashAmt.value    = 0;
		
		vObjID = 'txtRetCashAmt';
		
		vBalanceAmt =  vNetTotal-vRetTipsB1 - (vCouponAmt + vCreditAmt);
		
		ConvertCurrency(vCurr, vCashCurr, vDate, vBalanceAmt, 'txtRetCashAmt');
		window.setTimeout('ConvertAmount(\''+vObjID+'\')',100);
		window.setTimeout('CalcCopounCreditCheck(\''+currbase1+'\', \''+currbase2+'\', '+dec+')',200);
	}
	else if (tagID == 'btnCouponAmt') {
		x.txtRetCouponAmt.value = 0;
		
		vBalanceAmt =  vNetTotal-vRetTipsB1 - (vCashAmt + vCreditAmt);
		x.txtRetCouponAmt.value = vBalanceAmt;
	}
}

function CalcCopounCreditCheck(currbase1, currbase2, dec)
{ 
	x = document.retailpay;
	
	for (var i=0; i < x.txtRetCreditCurr.length; i++)
	{
		if (x.txtRetCreditCurr[i].checked)
		{
			var vCreditCurr = x.txtRetCreditCurr[i].value;
		}
	}
	var vRetCustomerRedeemPt = document.getElementById('txtRetCustomerRedeemPt').value;
	var vRetCustomerPt = document.getElementById('txtRetCustomerPt').value;
			
	var chkRedeemCustomerPt = 0;
	if(document.getElementById('chkRedeemCustomerPt').checked)
		chkRedeemCustomerPt = 1;
	
	var vDate       = x.txtRetDate.value;
	var vCurr       = x.txtRetCurr.value;
	var vCashCurr   = x.txtRetCashCurr.value;
	
	var vCurrBase1  = currbase1;
	var vCurrBase2  = currbase2;
	
	var vNetTotal   = x.txtRetNetTotal.value;  
	var vCouponAmt  = x.txtRetCouponAmt.value;  
	var vCreditAmt  = x.txtRetCreditAmtB12.value;
	var vCashAmt    = x.txtRetCashAmtB12.value;
	var vPtAmount = 0;
	
	if (vNetTotal == '')   		vNetTotal = 0;
	if (vCouponAmt == '')  		vCouponAmt = 0;
	if (vCreditAmt == '')  		vCreditAmt = 0;
	if (vCashAmt == '')    		vCashAmt = 0;
	if (vRetCustomerPt == '')   vRetCustomerPt = 0;
	
	vNetTotal   	= parseFloat(vNetTotal);
	vCouponAmt  	= parseFloat(vCouponAmt);
	vCreditAmt  	= parseFloat(vCreditAmt);
	vCashAmt    	= parseFloat(vCashAmt);
	vRetCustomerPt  = parseFloat(vRetCustomerPt);
	vPtAmount  		= parseFloat(vPtAmount);
	
	
	x.txtRetCashInB1.value = 0;
	x.txtRetCashOutB1.value = 0;
	x.txtRetCashInB2.value = 0;
	x.txtRetCashOutB2.value = 0;
	x.txtRetTipsB1.value = 0;
	
	
	if (vCurr == vCurrBase1) { 
		
		if (vNetTotal > 0) {
			vCashInB1 =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt;
			
			if(chkRedeemCustomerPt == 1){
				vPtAmount = parseFloat(vRetCustomerPt*vRetCustomerRedeemPt);
				if(vPtAmount <= vCashInB1){
					document.getElementById('txtRetCustomerAmount').value = vPtAmount;
					vCashInB1 = vCashInB1 - vPtAmount;
				}
				else {
					document.getElementById('txtRetCustomerAmount').value = vCashInB1;
					vCashInB1 = 0;
				}
			} else document.getElementById('txtRetCustomerAmount').value = 0;
				
			if (Math.abs(vCashInB1) > 100) {
				if (vCashInB1 < 0)         
					x.txtRetCashOutB1.value = Math.round(Math.abs(vCashInB1)*Math.pow(10,dec))/Math.pow(10,dec);
				else 	
					x.txtRetCashInB1.value =  Math.round(vCashInB1*Math.pow(10,dec))/Math.pow(10,dec);
			} else {
				x.txtRetTipsB1.value =  Math.round(Math.abs(vCashInB1)*Math.pow(10,dec))/Math.pow(10,dec);
			}
		} else {
			vCashInB1 =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt;
			
			if(chkRedeemCustomerPt == 1){
				vPtAmount = parseFloat(vRetCustomerPt*vRetCustomerRedeemPt);
				if(vPtAmount <= vCashInB1){
					document.getElementById('txtRetCustomerAmount').value = vPtAmount;
					vCashInB1 = vCashInB1 - vPtAmount;
				}
				else {
					document.getElementById('txtRetCustomerAmount').value = vCashInB1;
					vCashInB1 = 0;
				}
			} else document.getElementById('txtRetCustomerAmount').value = 0;
			
			if (Math.abs(vCashInB1) > 100) {
				if (vCashInB1 < 0)         
					x.txtRetCashOutB1.value = Math.round(Math.abs(vCashInB1)*Math.pow(10,dec))/Math.pow(10,dec);
				else 	
					x.txtRetCashInB1.value =  Math.round(vCashInB1*Math.pow(10,dec))/Math.pow(10,dec);
			} else {
				x.txtRetTipsB1.value =  Math.round(Math.abs(vCashInB1)*Math.pow(10,dec))/Math.pow(10,dec);
			}		
		}	
			
	}
   	else if (vCurr == vCurrBase2)	{
	
		if (vNetTotal > 0) {	
			vCashInB2 =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt;
		
			if(chkRedeemCustomerPt == 1){
				vPtAmount = parseFloat(vRetCustomerPt*vRetCustomerRedeemPt);
				if(vPtAmount <= vCashInB2){
					document.getElementById('txtRetCustomerAmount').value = vPtAmount;
					vCashInB2 = vCashInB2 - vPtAmount;
				}
				else {
					document.getElementById('txtRetCustomerAmount').value = vCashInB2;
					vCashInB2 = 0;
				}
			} else document.getElementById('txtRetCustomerAmount').value = 0;
			
			if (vCashInB2 < 0)         
				x.txtRetCashOutB2.value = Math.round(Math.abs(vCashInB2)*Math.pow(10,dec))/Math.pow(10,dec);
			else 	
				x.txtRetCashInB2.value =  Math.round(vCashInB2*Math.pow(10,dec))/Math.pow(10,dec);
		} else {
			vCashInB2 =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt;
			
			if(chkRedeemCustomerPt == 1){
				vPtAmount = parseFloat(vRetCustomerPt*vRetCustomerRedeemPt);
				if(vPtAmount <= vCashInB2){
					document.getElementById('txtRetCustomerAmount').value = vPtAmount;
					vCashInB2 = vCashInB2 - vPtAmount;
				}
				else {
					document.getElementById('txtRetCustomerAmount').value = vCashInB2;
					vCashInB2 = 0;
				}
			} else document.getElementById('txtRetCustomerAmount').value = 0;
			
			if (vCashInB2 < 0)         
				x.txtRetCashOutB2.value = Math.round(Math.abs(vCashInB2)*Math.pow(10,dec))/Math.pow(10,dec);
			else 	
				x.txtRetCashInB2.value =  Math.round(vCashInB2*Math.pow(10,dec))/Math.pow(10,dec);
		}	
	}

}

function CalcCashInB1(currbase1, currbase2, currrate1, currrate2, dec, modulebase2)
{
	x = document.retailpay;
	
	for (var i=0; i < x.txtRetCreditCurr.length; i++)
	{
		if (x.txtRetCreditCurr[i].checked)
		{
			var vCreditCurr = x.txtRetCreditCurr[i].value;
		}
	}
	
	var vDate       = x.txtRetDate.value;
	var vCurr       = x.txtRetCurr.value;
	var vCashCurr   = x.txtRetCashCurr.value;
	
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	var vCurrRateB1  = currrate1;
	var vCurrRateB2  = currrate2;
	
	var vNetTotal   = x.txtRetNetTotal.value;  
	var vCouponAmt  = x.txtRetCouponAmt.value;  
	var vCreditAmt  = x.txtRetCreditAmtB12.value;
	var vCashAmt    = x.txtRetCashAmtB12.value;
	
	var vCashInB1    = x.txtRetCashInB1.value;
	var vCashInB2    = x.txtRetCashInB2.value;
	var vCashOutB1   = x.txtRetCashOutB1.value;
	var vCashOutB2   = x.txtRetCashOutB2.value;
	var vTipsAmt     = x.txtRetTipsB1H.value;
	
	if (vNetTotal == '')   vNetTotal = 0;
	if (vCouponAmt == '')  vCouponAmt = 0;
	if (vCreditAmt == '')  vCreditAmt = 0;
	if (vCashAmt == '')    vCashAmt = 0;
	if (vCashInB1 == '')   vCashInB1 = 0;
	if (vCashInB2 == '')   vCashInB2 = 0;
	if (vCashOutB1 == '')  vCashOutB1 = 0;
	if (vCashOutB2 == '')  vCashOutB2 = 0;
	if (vTipsAmt == '')    vTipsAmt = 0;
	
	vNetTotal   = parseFloat(vNetTotal);
	vCouponAmt  = parseFloat(vCouponAmt);
	vCreditAmt  = parseFloat(vCreditAmt);
	vCashAmt    = parseFloat(vCashAmt);
	vCashInB1   = parseFloat(vCashInB1);
	vCashInB2   = parseFloat(vCashInB2);
	vCashOutB1  = parseFloat(vCashOutB1);
	vCashOutB2  = parseFloat(vCashOutB2);
	vTipsAmt    = parseFloat(vTipsAmt);
	
	
	if (vNetTotal > 0) {
		x.txtRetCashOutB1.value = 0;
		x.txtRetCashInB2.value = 0;
		x.txtRetCashOutB2.value = 0;
		//x.txtRetTipsB1.value = 0;
		
		if (vCurr == vCurrBase1) 
			vCashOutB1 =   vNetTotal - vTipsAmt - vCouponAmt - vCreditAmt - vCashAmt - vCashInB1;	
		else 	
			vCashOutB1 =   (vNetTotal*vCurrRateB2/vCurrRateB1) - vTipsAmt - (vCouponAmt*vCurrRateB2/vCurrRateB1) - 
						   (vCreditAmt*vCurrRateB2/vCurrRateB1) - (vCashAmt*vCurrRateB2/vCurrRateB1) - 
						   vCashInB1;	
	
		if (vCashOutB1 < 0) {  
			x.txtRetCashOutB1.value = Math.round(Math.abs(vCashOutB1)*Math.pow(10,dec))/Math.pow(10,dec);
		}
		else {
			if (modulebase2 == 1) {
				x.txtRetCashInB2.value =  Math.round((vCashOutB1*vCurrRateB1/vCurrRateB2)*Math.pow(10,dec))/Math.pow(10,dec);
			}	
		}		
	}
	else {
		x.txtRetCashOutB1.value = 0;
		x.txtRetCashInB2.value = 0;
		x.txtRetCashOutB2.value = 0;
		x.txtRetTipsB1.value = 0;
		
		if (vCurr == vCurrBase1) 
			vCashOutB1 =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt - vCashInB1;	
		else 	
			vCashOutB1 =   (vNetTotal*vCurrRateB2/vCurrRateB1) - (vCouponAmt*vCurrRateB2/vCurrRateB1) - 
						   (vCreditAmt*vCurrRateB2/vCurrRateB1) - (vCashAmt*vCurrRateB2/vCurrRateB1) - 
						   vCashInB1;	
						   
		if (vCashOutB1 < 0) {        
			/*if (modulebase2 == 1)
				x.txtRetCashOutB2.value = Math.round(Math.abs(vCashOutB1*vCurrRateB1/vCurrRateB2)*Math.pow(10,dec))/Math.pow(10,dec);
			else*/
				x.txtRetCashOutB1.value = Math.round(Math.abs(vCashOutB1)*Math.pow(10,dec))/Math.pow(10,dec);
		}	
		else 	
			x.txtRetCashInB2.value =  Math.round((vCashOutB1*vCurrRateB1/vCurrRateB2)*Math.pow(10,dec))/Math.pow(10,dec);
	}	
		
}

function CalcCashOutB1(currbase1, currbase2, currrate1, currrate2, dec, modulebase2)
{
	x = document.retailpay;
	
	for (var i=0; i < x.txtRetCreditCurr.length; i++)
	{
		if (x.txtRetCreditCurr[i].checked)
		{
			var vCreditCurr = x.txtRetCreditCurr[i].value;
		}
	}
	
	
	
	var vDate       = x.txtRetDate.value;
	var vCurr       = x.txtRetCurr.value;
	var vCashCurr   = x.txtRetCashCurr.value;
	
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	var vCurrRateB1  = currrate1;
	var vCurrRateB2  = currrate2;
	
	var vNetTotal   = x.txtRetNetTotal.value;  
	var vCouponAmt  = x.txtRetCouponAmt.value;  
	var vCreditAmt  = x.txtRetCreditAmtB12.value;
	var vCashAmt    = x.txtRetCashAmtB12.value;
	
	var vCashInB1    = x.txtRetCashInB1.value;
	var vCashInB2    = x.txtRetCashInB2.value;
	var vCashOutB1   = x.txtRetCashOutB1.value;
	var vCashOutB2   = x.txtRetCashOutB2.value;
	var vTipsAmt     = x.txtRetTipsB1H.value;
	
	if (vNetTotal == '')   vNetTotal = 0;
	if (vCouponAmt == '')  vCouponAmt = 0;
	if (vCreditAmt == '')  vCreditAmt = 0;
	if (vCashAmt == '')    vCashAmt = 0;
	if (vCashInB1 == '')   vCashInB1 = 0;
	if (vCashInB2 == '')   vCashInB2 = 0;
	if (vCashOutB1 == '')  vCashOutB1 = 0;
	if (vCashOutB2 == '')  vCashOutB2 = 0;
	if (vTipsAmt == '')    vTipsAmt = 0;
	
	vNetTotal   = parseFloat(vNetTotal);
	vCouponAmt  = parseFloat(vCouponAmt);
	vCreditAmt  = parseFloat(vCreditAmt);
	vCashAmt    = parseFloat(vCashAmt);
	vCashInB1   = parseFloat(vCashInB1);
	vCashInB2   = parseFloat(vCashInB2);
	vCashOutB1  = parseFloat(vCashOutB1);
	vCashOutB2  = parseFloat(vCashOutB2);
	vTipsAmt    = parseFloat(vTipsAmt);
	
	
	
	if (vNetTotal > 0) {	
	    
		x.txtRetCashOutB2.value = 0;
		x.txtRetTipsB1.value = 0;
	
		if (vCurr == vCurrBase1) 
			vCashIn =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt - vCashInB1 - (vCashInB2*vCurrRateB2/vCurrRateB1) + vCashOutB1;	
		else 	
			vCashIn =   (vNetTotal*vCurrRateB2/vCurrRateB1) - (vCouponAmt*vCurrRateB2/vCurrRateB1) - 
						(vCreditAmt*vCurrRateB2/vCurrRateB1) - (vCashAmt*vCurrRateB2/vCurrRateB1) - 
						((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) - vCashInB1 - 
						(vCashInB2*vCurrRateB2/vCurrRateB1) + vCashOutB1;	
	
		
		if (vCashIn < 0) {         
			if (modulebase2 == 1) {
				vCashIn =   (vCashIn*vCurrRateB1/vCurrRateB2);
				x.txtRetCashOutB2.value = Math.round(Math.abs(vCashIn)*Math.pow(10,dec))/Math.pow(10,dec);
			}	
			else
				x.txtRetTipsB1.value =  Math.round(Math.abs(vCashIn)*Math.pow(10,dec))/Math.pow(10,dec);
		}	
		else {	
			/*if (modulebase2 == 1) {
				vCashIn =   (vCashIn*vCurrRateB1/vCurrRateB2);
				x.txtRetCashInB2.value =  Math.round((vCashIn)*Math.pow(10,dec))/Math.pow(10,dec);
			}	
			else*/
				x.txtRetTipsB1.value =  Math.round(Math.abs(vCashIn)*Math.pow(10,dec))/Math.pow(10,dec);
		}		
	} 
	else {	
	    x.txtRetCashInB1.value = 0;
		x.txtRetCashInB2.value = 0;
		x.txtRetCashOutB2.value = 0;
		x.txtRetTipsB1.value = 0;
	
		if (vCurr == vCurrBase1) 
			vCashIn =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt + vCashOutB1;	
		else 	
			vCashIn =   (vNetTotal*vCurrRateB2/vCurrRateB1) - (vCouponAmt*vCurrRateB2/vCurrRateB1) - 
						(vCreditAmt*vCurrRateB2/vCurrRateB1) - (vCashAmt*vCurrRateB2/vCurrRateB1) + 
						vCashOutB1;	
				
		if (vCashIn < 0) {
			if (modulebase2 == 1)
				x.txtRetCashOutB2.value = Math.round(Math.abs((vCashIn*vCurrRateB1/vCurrRateB2))*Math.pow(10,dec))/Math.pow(10,dec);
			else
				x.txtRetTipsB1.value =  Math.round((vCashIn)*Math.pow(10,dec))/Math.pow(10,dec);
		}		
		else 	
			x.txtRetCashInB1.value =  Math.round((vCashIn)*Math.pow(10,dec))/Math.pow(10,dec);	
	}
	
}

function CalcCashInB2(currbase1, currbase2, currrate1, currrate2, dec)
{
	x = document.retailpay;
	
	for (var i=0; i < x.txtRetCreditCurr.length; i++)
	{
		if (x.txtRetCreditCurr[i].checked)
		{
			var vCreditCurr = x.txtRetCreditCurr[i].value;
		}
	}
	
	var vDate       = x.txtRetDate.value;
	var vCurr       = x.txtRetCurr.value;
	var vCashCurr   = x.txtRetCashCurr.value;
	
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	var vCurrRateB1  = currrate1;
	var vCurrRateB2  = currrate2;
	
	var vNetTotal   = x.txtRetNetTotal.value;  
	var vCouponAmt  = x.txtRetCouponAmt.value;  
	var vCreditAmt  = x.txtRetCreditAmtB12.value;
	var vCashAmt    = x.txtRetCashAmtB12.value;
	
	var vCashInB1    = x.txtRetCashInB1.value;
	var vCashInB2    = x.txtRetCashInB2.value;
	var vCashOutB1   = x.txtRetCashOutB1.value;
	var vCashOutB2   = x.txtRetCashOutB2.value;
	var vTipsAmt     = x.txtRetTipsB1H.value;
	
	if (vNetTotal == '')   vNetTotal = 0;
	if (vCouponAmt == '')  vCouponAmt = 0;
	if (vCreditAmt == '')  vCreditAmt = 0;
	if (vCashAmt == '')    vCashAmt = 0;
	if (vCashInB1 == '')   vCashInB1 = 0;
	if (vCashInB2 == '')   vCashInB2 = 0;
	if (vCashOutB1 == '')  vCashOutB1 = 0;
	if (vCashOutB2 == '')  vCashOutB2 = 0;
	if (vTipsAmt == '')    vTipsAmt = 0;
	
	vNetTotal   = parseFloat(vNetTotal);
	vCouponAmt  = parseFloat(vCouponAmt);
	vCreditAmt  = parseFloat(vCreditAmt);
	vCashAmt    = parseFloat(vCashAmt);
	vCashInB1   = parseFloat(vCashInB1);
	vCashInB2   = parseFloat(vCashInB2);
	vCashOutB1  = parseFloat(vCashOutB1);
	vCashOutB2  = parseFloat(vCashOutB2);
	vTipsAmt    = parseFloat(vTipsAmt);
	
	if (vNetTotal > 0) {
		x.txtRetCashOutB1.value = 0;
		x.txtRetCashOutB2.value = 0;
		//x.txtRetTipsB1.value = 0;
		
		if (vCurr == vCurrBase1) 
			vCashOutB1 =   vNetTotal - vTipsAmt - vCouponAmt - vCreditAmt - vCashAmt - vCashInB1 - (vCashInB2*vCurrRateB2/vCurrRateB1);	
		else 	
			vCashOutB1 =   (vNetTotal*vCurrRateB2/vCurrRateB1) - vTipsAmt - (vCouponAmt*vCurrRateB2/vCurrRateB1) - 
						   (vCreditAmt*vCurrRateB2/vCurrRateB1) - (vCashAmt*vCurrRateB2/vCurrRateB1) - 
						   vCashInB1 - (vCashInB2*vCurrRateB2/vCurrRateB1);	
	
		if (vCashOutB1 < 0)         
			x.txtRetCashOutB1.value = Math.round(Math.abs(vCashOutB1)*Math.pow(10,dec))/Math.pow(10,dec);
		else 	
			x.txtRetTipsB1.value =  Math.round((vCashOutB1)*Math.pow(10,dec))/Math.pow(10,dec);
			
			
		
		/*if (vCurr == vCurrBase2) 
			vCashOutB2 =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt - ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) - vCashInB2;	
		else 	
			vCashOutB2 =   (vNetTotal*vCurrRateB1/vCurrRateB2) - (vCouponAmt*vCurrRateB1/vCurrRateB2) - 
						   (vCreditAmt*vCurrRateB1/vCurrRateB2) - (vCashAmt*vCurrRateB1/vCurrRateB2) - 
						   ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) - vCashInB2;	

		if (vCashOutB2 < 0)         
			x.txtRetCashOutB2.value = Math.round(Math.abs(vCashOutB2)*Math.pow(10,dec))/Math.pow(10,dec);
		else 	
			x.txtRetTipsB1.value =  Math.round((vCashOutB2*vCurrRateB2/vCurrRateB1)*Math.pow(10,dec))/Math.pow(10,dec);
		*/	
	} else {
		x.txtRetCashOutB2.value = 0;
	    x.txtRetTipsB1.value = 0;
	
		if (vCurr == vCurrBase2) 
			vCashOutB2 =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt - ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) - vCashInB2;	
		else 	
			vCashOutB2 =   (vNetTotal*vCurrRateB1/vCurrRateB2) - (vCouponAmt*vCurrRateB1/vCurrRateB2) - 
						   (vCreditAmt*vCurrRateB1/vCurrRateB2) - (vCashAmt*vCurrRateB1/vCurrRateB2) - 
						   ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) - vCashInB2;	
		
		//vTipsBase =   (vTipsBase*vCurrRateB2/vCurrRateB1);
		//x.txtRetTipsB1.value =  Math.round((vTipsBase)*Math.pow(10,dec))/Math.pow(10,dec);
		if (vCashOutB2 < 0)         
			x.txtRetCashOutB2.value = Math.round(Math.abs(vCashOutB2)*Math.pow(10,dec))/Math.pow(10,dec);
		else 	
			x.txtRetTipsB1.value =  Math.round((vCashOutB2*vCurrRateB2/vCurrRateB1)*Math.pow(10,dec))/Math.pow(10,dec);
	
	}	
}



function CalcCashOutB2(currbase1, currbase2, currrate1, currrate2, dec)
{
	x = document.retailpay;
	
	for (var i=0; i < x.txtRetCreditCurr.length; i++)
	{
		if (x.txtRetCreditCurr[i].checked)
		{
			var vCreditCurr = x.txtRetCreditCurr[i].value;
		}
	}
	
	var vDate       = x.txtRetDate.value;
	var vCurr       = x.txtRetCurr.value;
	var vCashCurr   = x.txtRetCashCurr.value;
	
	var vCurrBase1   = currbase1;
	var vCurrBase2   = currbase2;
	var vCurrRateB1  = currrate1;
	var vCurrRateB2  = currrate2;
	
	var vNetTotal   = x.txtRetNetTotal.value;  
	var vCouponAmt  = x.txtRetCouponAmt.value;  
	var vCreditAmt  = x.txtRetCreditAmtB12.value;
	var vCashAmt    = x.txtRetCashAmtB12.value;
	
	var vCashInB1    = x.txtRetCashInB1.value;
	var vCashInB2    = x.txtRetCashInB2.value;
	var vCashOutB1   = x.txtRetCashOutB1.value;
	var vCashOutB2   = x.txtRetCashOutB2.value;
	
	if (vNetTotal == '')   vNetTotal = 0;
	if (vCouponAmt == '')  vCouponAmt = 0;
	if (vCreditAmt == '')  vCreditAmt = 0;
	if (vCashAmt == '')    vCashAmt = 0;
	if (vCashInB1 == '')   vCashInB1 = 0;
	if (vCashInB2 == '')   vCashInB2 = 0;
	if (vCashOutB1 == '')  vCashOutB1 = 0;
	if (vCashOutB2 == '')  vCashOutB2 = 0;
	
	vNetTotal   = parseFloat(vNetTotal);
	vCouponAmt  = parseFloat(vCouponAmt);
	vCreditAmt  = parseFloat(vCreditAmt);
	vCashAmt    = parseFloat(vCashAmt);
	vCashInB1   = parseFloat(vCashInB1);
	vCashInB2   = parseFloat(vCashInB2);
	vCashOutB1  = parseFloat(vCashOutB1);
	vCashOutB2  = parseFloat(vCashOutB2);
	
	x.txtRetTipsB1.value = 0;
	
	if (vCurr == vCurrBase2) 
		vTipsBase =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt - ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) - vCashInB2 + vCashOutB2;	
	else 	
		vTipsBase =   (vNetTotal*vCurrRateB1/vCurrRateB2) - (vCouponAmt*vCurrRateB1/vCurrRateB2) - 
		              (vCreditAmt*vCurrRateB1/vCurrRateB2) - (vCashAmt*vCurrRateB1/vCurrRateB2) - 
					  ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) - vCashInB2 + vCashOutB2;	
	
	if (vNetTotal > 0) {
		vTipsBase =   (vTipsBase*vCurrRateB2/vCurrRateB1);
		
		x.txtRetTipsB1.value =  Math.round((vTipsBase)*Math.pow(10,dec))/Math.pow(10,dec);
	}
	else {
	    x.txtRetCashInB2.value = 0;
		x.txtRetTipsB1.value = 0;
		
		if (vCurr == vCurrBase2) 
			vCashInB2 =   vNetTotal - vCouponAmt - vCreditAmt - vCashAmt - ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) + vCashOutB2;	
		else 	
			vCashInB2 =   (vNetTotal*vCurrRateB1/vCurrRateB2) - (vCouponAmt*vCurrRateB1/vCurrRateB2) - 
					      (vCreditAmt*vCurrRateB1/vCurrRateB2) - (vCashAmt*vCurrRateB1/vCurrRateB2) - 
						  ((vCashInB1 - vCashOutB1)*vCurrRateB1/vCurrRateB2) + vCashOutB2;	

		if (vCashInB2 > 0)         
			x.txtRetCashInB2.value = Math.round(Math.abs(vCashInB2)*Math.pow(10,dec))/Math.pow(10,dec);
		else 	
			x.txtRetTipsB1.value =  Math.round((vCashInB2*vCurrRateB2/vCurrRateB1)*Math.pow(10,dec))/Math.pow(10,dec);
			
		/*if (vTipsBase < 0)         
			x.txtRetTipsB1.value = Math.round(Math.abs(vTipsBase*vCurrRateB2/vCurrRateB1)*Math.pow(10,dec))/Math.pow(10,dec);
		else 	
			x.txtRetCashInB2.value =  Math.round((vTipsBase)*Math.pow(10,dec))/Math.pow(10,dec);
		*/	
	}
		
		
}

function PayCheck(event) {
	x = document.retailpay;
	
	if (event == 1) {
		x.txtRetCashAmt.value = x.txtRetNetTotal.value;
		x.txtRetCashAmt.onkeyup();
	} 
	else if (event == 2) {	
		x.txtRetCashAmt.onchange();
	}	
}

function PayCard(AccountNo, AccountDesc, currbase1, currbase2, dec) {
	x = document.retailpay;

	x.txtRetCreditCard.value = AccountNo;
	x.txtRetCreditName.value = AccountDesc;
	x.txtRetCreditAmt.value  = x.txtRetNetTotal.value;
	//ConvertAmount1('txtRetCreditAmt', currbase1, currbase2, dec);
	CalcBalanceAmount('txtRetCreditAmt', currbase1, currbase2, dec);
	
}

function addCommas(nStr)
{
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
  }
  return x1 + x2;
}
// This function removes non-numeric characters
function stripNonNumeric( str )
{
  str += '';
  var rgx = /^\d|\.|-$/;
  var out = '';
  for( var i = 0; i < str.length; i++ )
  {
    if( rgx.test( str.charAt(i) ) ){
      if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) ||
             ( str.charAt(i) == '-' && out.length != 0 ) ) ){
        out += str.charAt(i);
      }
    }
  }
  return out;
}

function showlistCustomer(str){
  var vdate, vcode;
  
  x = document.retailpay;
  vdate = x.txtRetDate.value;
  vcode = x.txtRetCustomerCode.value;
  
  //window.open('List_SorClient.php?frm=4&item='+str+'&PLedger_number='+vcode+'&TransDate='+vdate,'List_SorClient','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
  window.open('List_Customers.php?frm=1&item='+str+'&PLedgerNo='+vcode,'List_Customers','width=770,height=485,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function checkcustomercard(){
	var x = document.retailpay;
	var vLedgerClientCard = document.getElementById("txtLedgerClientCard").value;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					var res = xmlhttp.responseText;
					if(res != 0) {
						x.txtRetCustomerCode.value=res;
						x.submit();
					}
					else {
						showlistCustomer(1);
					}
				} 
		}
  }

xmlhttp.open("GET","Form_Retail_Actions.php?actionmode=checkcustomer&txtLedgerClientCard="+vLedgerClientCard,true);
xmlhttp.send();
}
function showlistSalesman(str){
  var vdate, vcode;
  
  x = document.retailpay;
  vcode = x.txtRetSalesmanCode.value;
  
  window.open('List_RetSalesman.php?frm=1&item='+str+'&PLedgerNo='+vcode,'List_RetSalesman','width=650,height=450,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCoupon(str){
  var vcode;
  
  x = document.retailpay;
  vcode      = x.txtRetCouponCode.value;
  vcurrcode  = x.txtRetCurr.value;
  vcltcode   = x.txtRetCustomerCode.value;
  vnettotal  = x.txtRetNetTotal.value;  
  
  window.open('List_Coupon.php?frm=1&item='+str+'&PCouponCode='+vcode+'&PCurrCode='+vcurrcode+'&PLedgerNo='+vcltcode+'&PNetTotal='+vnettotal,'List_Coupon','width=690,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCreditCard(str){
  var vcode;
  
  x = document.retailpay;
  var vcode  = x.txtRetCreditCard.value;
  var vtotal = x.txtRetNetTotal.value;
  var SRetId = x.PRetId.value;
 for (var i=0; i < x.txtRetCreditCurr.length; i++)
	{
		if (x.txtRetCreditCurr[i].checked)
		{
			var vCreditCurr = x.txtRetCreditCurr[i].value;
		}
	}
  
  window.open('List_CreditCards.php?frm=1&item='+str+'&PLedgerNo='+vcode+'&PTotal='+vtotal+'&txtRetCurr='+vCreditCurr+'&SRetId='+SRetId,'List_CreditCards','width=600,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function RefreshPage()
{
	x = document.retailpay;
	x.submit();

}


function kd(e)
{ 
	
	x=document.retailpay;
	if (!e) { var e = window.event;}
    var intKey = (window.Event) ? e.which : e.keyCode;
	
	
	
	// Block browser short cuts     
	//F1, F3, F4, F11, TAB  key
	if (intKey == 112 || intKey == 114 || intKey == 115 || intKey == 122 || intKey == 9) {
		if(e.preventDefault) // non-IE browsers         
			e.preventDefault();     
		else  // IE Only  
		{
			e.keyCode=0;  
			e.returnValue = false; 
			
		}	
	}

	
    if (intKey == 113) { //F2 key
		x.btnOk.click();
		return false;
	}
	else if (intKey == 114) { //F3 key
		x.btnCancel.click();
		return false;
	}
	else if (intKey == 27) { //ESC key
		self.close();
		
		return false;
	}
	else if (intKey == 122 && document.getElementById('btnDrawer')) { //F11 key
		x.btnDrawer.click();
		return false;
	}
	else if (intKey == 13) { //enter key
	
		if(document.activeElement.id == 'txtRetCashInB1') {
			if (document.getElementById('txtRetCashInB2').type == 'text') {
				x.txtRetCashInB2.focus();
				x.txtRetCashInB2.select();
			} else if (document.getElementById('txtRetCashOutB1').type == 'text') {
				x.txtRetCashOutB1.focus();	
				x.txtRetCashOutB1.select();
			}
				
		}	
		else if(document.activeElement.id == 'txtRetCashInB2') {
			if (document.getElementById('txtRetCashOutB1').type == 'text') {
				x.txtRetCashOutB1.focus();
				x.txtRetCashOutB1.select();
			}	
		}
		else if(document.activeElement.id == 'txtRetCashOutB1') {
			if (document.getElementById('txtRetCashOutB2').type == 'text') {
				x.txtRetCashOutB2.focus();
				x.txtRetCashOutB2.select();
			}	
			else if (document.getElementById('txtRetRemark').type == 'text')
				x.txtRetRemark.focus();
		}
		else if(document.activeElement.id == 'txtRetCashOutB2') {
			if (document.getElementById('txtRetRemark').type == 'text')
				x.txtRetRemark.focus();
			else if (document.getElementById('txtRetCashInB1').type == 'text') {
				x.txtRetCashOutB2.focus();	
				x.txtRetCashOutB2.select();
			}	
		}
		else if(document.activeElement.id == 'txtRetRemark') {
			if (document.getElementById('txtRetCreditAmt').type == 'text')
				x.txtRetCreditAmt.focus();
			else if (document.getElementById('txtRetCheckNo').type == 'text')	
				x.txtRetCheckNo.focus();
			else if (document.getElementById('txtRetCashInB1').type == 'text')	
				x.txtRetCashInB1.focus();	

		}
		else if(document.activeElement.id == 'txtRetCreditAmt') {
			if (document.getElementById('txtRetCheckNo').type == 'text')
				x.txtRetCheckNo.focus();
			else if (document.getElementById('txtRetCashInB1').type == 'text')	
				x.txtRetCashInB1.focus();
		}
		else if(document.activeElement.id == 'txtRetCheckNo') {
			if (document.getElementById('txtRetCheckDate').type == 'text')
				x.txtRetCheckDate.focus();
		}
		else if(document.activeElement.id == 'txtRetCheckDate') {
			if (document.getElementById('txtRetBankName').type == 'text')
				x.txtRetBankName.focus();
		}
		else if(document.activeElement.id == 'txtRetBankName') {
			if (document.getElementById('txtRetBranchName').type == 'text')
				x.txtRetBranchName.focus();
		}
		else if(document.activeElement.id == 'txtRetBranchName') {
			if (document.getElementById('txtRetCashAmt').type == 'text')
				x.txtRetCashAmt.focus();
		}
		else if(document.activeElement.id == 'txtRetCashAmt') {
			if (document.getElementById('txtRetCashInB1').type == 'text')
				x.txtRetCashInB1.focus();
		}
		
		return false;
    }
	
	
    return true;
}

function OpenKeyboard(field){
	VirtualKeyboard.attachInput(field);
	if(field!='skip'){
		
		VirtualKeyboard.open(field,'td');
	}	
}

function FillInput(PValue,currbase1,currbase2,dec){
	var vField=document.retailpay.txtFocusField.value;
	
	if(isTextSelected(document.getElementById(vField))){
		document.retailpay[vField].value=PValue;
	} else {
		document.retailpay[vField].value=document.retailpay[vField].value+PValue;
	}

if(vField == 'txtRetCashAmt' || vField == 'txtRetCreditAmt') {
	window.setTimeout('ConvertAmount(\''+vField+'\')',100);
	window.setTimeout('CalcCopounCreditCheck(\''+currbase1+'\', \''+currbase2+'\', '+dec+')',200);
}
	


}
function isTextSelected(input) {
    if (typeof input.selectionStart == "number") {
        return input.selectionStart == 0 && input.selectionEnd == input.value.length;
    } else if (typeof document.selection != "undefined") {
        input.focus();
        return document.selection.createRange().text == input.value;
    }
}

function EraseInput(PValue){
	var vField=document.retailpay.txtFocusField.value;
	document.retailpay[vField].value='';
	
	window.setTimeout('ConvertAmount(\''+vField+'\')',100);
	window.setTimeout('CalcCopounCreditCheck(\''+currbase1+'\', \''+currbase2+'\', '+dec+')',200);
	
}

function EraseFromInput(){
	var vField=document.retailpay.txtFocusField.value;
	document.retailpay[vField].value=document.retailpay[vField].value+2;
}


function FillHidden(PField){
	document.retailpay.txtFocusField.value=PField;
}


function ClickEnter(){
	x=document.retailpay;
		
	var Field=document.retailpay.txtFocusField.value;
	
	if(Field == 'txtRetCashInB1') { 
		$(document.getElementById(Field)).trigger("change");
		if (document.getElementById('txtRetCashInB2').type == 'text') {
			x.txtRetCashInB2.focus();
			x.txtRetCashInB2.select();
			document.retailpay.txtFocusField.value='txtRetCashInB2';
		}	
				
	}	
	else if(Field == 'txtRetCashInB2') {
		$(document.getElementById(Field)).trigger("change");
		if (document.getElementById('txtRetCashOutB1').type == 'text') {
			x.txtRetCashOutB1.focus();
			x.txtRetCashOutB1.select();
			document.retailpay.txtFocusField.value='txtRetCashOutB1';
		}	
	}
	else if(Field == 'txtRetCashOutB1') {
		$(document.getElementById(Field)).trigger("change");
		if (document.getElementById('txtRetCashOutB2').type == 'text') {
			x.txtRetCashOutB2.focus();
			x.txtRetCashOutB2.select();
			document.retailpay.txtFocusField.value='txtRetCashOutB2';
		}	
	}
	else if(Field == 'txtRetCashOutB2') {
		$(document.getElementById(Field)).trigger("change");
		if (document.getElementById('txtRetRemark').type == 'text'){
			x.txtRetRemark.focus();
			document.retailpay.txtFocusField.value='txtRetRemark';
		}	
		else if (document.getElementById('txtRetCashInB1').type == 'text') {
			x.txtRetCashOutB2.focus();	
			x.txtRetCashOutB2.select();
			document.retailpay.txtFocusField.value='txtRetCashInB1';
		}	
	}
	else if(Field == 'txtRetRemark') {
		if (document.getElementById('txtRetCreditAmt').type == 'text'){
			x.txtRetCreditAmt.focus();
			x.txtRetCreditAmt.select();
			document.retailpay.txtFocusField.value='txtRetCreditAmt';
		}	
		else if (document.getElementById('txtRetCheckNo').type == 'text')	{
			x.txtRetCheckNo.focus();
			document.retailpay.txtFocusField.value='txtRetCheckNo';
		}	
		else if (document.getElementById('txtRetCashInB1').type == 'text'){	
			x.txtRetCashInB1.focus();
			x.txtRetCashInB1.select();
			document.retailpay.txtFocusField.value='txtRetCashInB1';
		}
	}
	else if(Field == 'txtRetCreditAmt') {
		$(document.getElementById(Field)).trigger("change");
		if (document.getElementById('txtRetCheckNo').type == 'text'){
			x.txtRetCheckNo.focus();
			document.retailpay.txtFocusField.value='txtRetCheckNo';
		}	
		else if (document.getElementById('txtRetCashInB1').type == 'text'){	
			x.txtRetCashInB1.focus();
			x.txtRetCashInB1.select();
			document.retailpay.txtFocusField.value='txtRetCashInB1';
		}	
	}
	else if(Field == 'txtRetCheckNo') {
		if (document.getElementById('txtRetCheckDate').type == 'text'){
			x.txtRetCheckDate.focus();
			document.retailpay.txtFocusField.value='txtRetCheckDate';
		}	
	}
	else if(Field == 'txtRetCheckDate') {
		if (document.getElementById('txtRetBankName').type == 'text'){
			x.txtRetBankName.focus();
			document.retailpay.txtFocusField.value='txtRetBankName';
		}	
	}
	else if(Field == 'txtRetBankName') {
		if (document.getElementById('txtRetBranchName').type == 'text'){
			x.txtRetBranchName.focus();
			document.retailpay.txtFocusField.value='txtRetBranchName';
		}	
	}
	else if(Field == 'txtRetBranchName') {
		if (document.getElementById('txtRetCashAmt').type == 'text'){
			x.txtRetCashAmt.focus();
			x.txtRetCashAmt.select();
			document.retailpay.txtFocusField.value='txtRetCashAmt';
		}
	}
	else if(Field == 'txtRetCashAmt') {
		$(document.getElementById(Field)).trigger("change");
		if (document.getElementById('txtRetCashInB1').type == 'text') {
			x.txtRetCashInB1.focus();
			x.txtRetCashInB1.select();
			document.retailpay.txtFocusField.value='txtRetCashInB1';
		}	
	}
	
	

}

function SetNoPrint(){
	if (document.retailpay.noprint.value == 1) {
		document.retailpay.noprint.value=0;
		document.getElementById("img-print").className = "bg-print";
	} else {
		document.retailpay.noprint.value=1;
		document.getElementById("img-print").className = "bg-noprint";
	}	
}

function PrintPreview()
{
	
	var str = '';
	RetId = document.retailpay.PRetId.value;
	ReportName = document.retailpay.ReportName.value;
	
	
	str = ReportName+'?RetailId='+RetId;
	window.open(str, 'Form_RetailSlip', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=350,height=500,top=100');	
								  
	//self.close();

}

function calcCustomerDisc(){
	var x = document.retailpay;
	RetId = document.retailpay.PRetId.value;
	RetCustomerCode = document.retailpay.txtRetCustomerCode.value;
	alert();
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					var res = xmlhttp.responseText;
					x.submit();
					
				} 
		}
  }

xmlhttp.open("GET",'Form_Retail_Actions.php?actionmode=calcCustomerDisc&RetailId='+RetId+'&RetCustomerCode='+RetCustomerCode,true);
xmlhttp.send();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Exchange</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;
}



div#mainDiv, div#imgDiv {
	font-size: 12px; 
    font-weight:bold; 
	color: #FF0000 ;
	text-align: center; 
	margin-top:10px;
	display:none;
}
	
div.payment-type-radio
{
    /*width: 49%;*/
    margin-bottom: 3px;
    float: left;
    padding-right: 3px;
	margin-right: 10px;
	cursor: pointer;
}
div.payment-type-radio label#card-label
{
    border: none;
	display:inline;
    text-indent: 0px;
    margin-top: 5px;
}	
div.payment-type-radio label#card-label span.card-label {
		
    margin: 0px 0 0 42px;
	padding-top: 2px;
	width: 98px;
	height: 23px;

}
label#card-label span.wrapped {
	padding-top: 0px !important;
	margin-top: -5px !important;
}
div.payment-type-radio label span.card-logo {
    height: 23px;
    width: 37px;
	position: absolute;
	cursor: pointer;
}

 button {
  padding: 0 0 0 0;
  margin: 0 3px 0 3px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  outline: none;
  white-space: nowrap;
  overflow: visible;
  height: 22px; 
  font-family: 11px Arial, sans-serif;
  font-size: 13px;
  color: #000000;
  background: none;
  font-weight: bold;

}


.style26 {color: #FF0000; font-weight: bold; font-size: 24px;}
</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 onLoad='LoadForm($PhpPort,$CashRegister_DispCOM);' onkeydown='return kd(event);'>
<form name='retailpay' method='post'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='message' value='$message'>
<input type='hidden' name='noprint' value='$noprint'>
<input type='hidden' name='PRetId' value='$PRetId'>
<input type='hidden' name='PRetDate' value='$PRetDate'>
<input type='hidden' name='txtFocusField' value='$txtFocusField'>
<input type='hidden' name='ReportName' value='$ReportName'>
		
HERE;


	//exit;


if($PRetId != ''){

	$sub_query = " Select Sale_ID, Date_Format(Sale_Date,'%d/%m/%Y') As Sale_Date, Retail.Currency_code, ".
				 " Round(ifNull(Sale_NetTotal,0), ".$DecimalBase."), Round(ifNull(Sale_NetTotalBase1,0), ".$DecimalBase1."), ".
				 " Round(ifNull(Sale_NetTotalBase2,0), ".$DecimalBase2."),  ".
				 " ifNull(Sales_CashInBase1,0), ifNull(Sales_CashInBase2,0), ifNull(Sales_CashOutBase1,0), ifNull(Sales_CashOutBase2,0),  ".
				 " Retail.Customer_Code, Customer.Customer_Name, Sale_Information,  ".
				 " Retail.Coupon_Id, Coupon_Reference, Coupon_Name, ifNull(Retail.Coupon_Amount,0), ".
				 " ifNull(Coupon.Coupon_Amount,0) - ifNull(convertcurfunc(Coupon.Currency_Code, Retail.Currency_code, Coupon_Date, 0, 0, '', '', ifNull(Coupon.Coupon_AmountConsum,0)),0) , ".
				 " Sale_CashCur, ifNull(Sale_Cash,0), Sale_CheckNo, Date_Format(Sale_CheckDate,'%d/%m/%Y'), Sale_Bank, Sale_BankBranch, ".
				 " Sales_CreditAccCur, ifNull(Sales_CreditAmount,0), Sales_CreditAcc, Ledger.Ledger_Name As Sale_CreditName,  ".
				 " ifNull(Sales_TipsBase1,0), Retail.Salesman_Code, Salesmen.Ledger_Name, sale_customerDiscount, sale_customerAwardPt, ifnull(sale_redeemPtAmount,0), ifnull(sale_redeemPtAmount2,0),  ".
				 " ifnull(sale_customerRedeemChk,0) as sale_customerRedeemChk ".
				 " From Temp_Retail As Retail ".
				 " Left Join Customer on Retail.Customer_Code = Customer.Customer_Code ".
				 " Left Join Salesmen on Retail.Salesman_Code = Salesmen.Ledger_Number ".
				 " Left Join Coupon on Retail.Coupon_Id =  Coupon.Coupon_Id ".
				 " Left Join Ledger on Retail.Sales_CreditAcc =  Ledger.Ledger_Number ".
				 " Where Sale_ID = ".$PRetId;
				 
	//echo $sub_query;
	$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
    $sub_rows=mysql_fetch_array($sub_result);
	
	$txtRetDate          = $sub_rows[1];
	$txtRetCurr          = $sub_rows[2];
	$txtRetNetTotal      = $sub_rows[3];
	$txtRetNetTotalB1Disp  = number_format($sub_rows[4], $DecimalBase1);
	$txtRetNetTotalB2Disp  = number_format($sub_rows[5], $DecimalBase2);
	
	$txtRetCashInB1   = $sub_rows[6];
	$txtRetCashInB2   = $sub_rows[7];
	$txtRetCashOutB1  = $sub_rows[8];
	$txtRetCashOutB2  = $sub_rows[9];
	
	
	
	
	if (empty($txtRetCustomerCode)) {
		$txtRetCustomerCode  = $sub_rows[10];
		$txtRetCustomerName  = $sub_rows[11];
	}
	
	if (empty($txtRetSalesmanCode)) {
		$txtRetSalesmanCode  = $sub_rows[29];
		$txtRetSalesmanName  = $sub_rows[30];
	}
	
	if (empty($txtRetRemark))	
		$txtRetRemark = $sub_rows[12];
		
	if (empty($txtRetCouponCode)) {
		$txtRetCouponId      = $sub_rows[13];
		$txtRetCouponCode    = $sub_rows[14];
		$txtRetCouponName    = $sub_rows[15];
		$txtRetCouponAmt     = $sub_rows[16];
		$txtRetCouponRemAmt  = $sub_rows[17];
	}	
	
	if (empty($txtRetCheckNo)) {	
		$txtRetCashCurr    = $sub_rows[18];
		$txtRetCashAmt     = $sub_rows[19];
		$txtRetCheckNo     = $sub_rows[20];
		$txtRetCheckDate   = $sub_rows[21];
		$txtRetBankName    = $sub_rows[22];
		$txtRetBranchName  = $sub_rows[23];
	}

	if (empty($txtRetCreditCard)) {
		$txtRetCreditCurr = $sub_rows[24];
		$txtRetCreditAmt  = $sub_rows[25];
		$txtRetCreditCard = $sub_rows[26];
		$txtRetCreditName = $sub_rows[27];
	}
	
	if (empty($txtRetTipsB1)) {
		$txtRetTipsB1  = $sub_rows[28];
	}
	$txtRetCustomerDisc 	 = $sub_rows[31];
	$txtRetCustomerPt		 = $sub_rows[32];
	$txtRetCustomerAmount	 = $sub_rows[33];
	$txtRetCustomerAmount2	 = $sub_rows[34];
	$chkRedeemCustomerPt	 = $sub_rows[35];
	
	if(empty($txtRetCouponAmt))  		$txtRetCouponAmt = 0;
	if(empty($txtRetCashAmt))    		$txtRetCashAmt = 0;
	if(empty($txtRetCreditAmt))  		$txtRetCreditAmt = 0;
	if(empty($txtRetCashOutB1))  		$txtRetCashOutB1 = 0;
	if(empty($txtRetCashOutB2))  		$txtRetCashOutB2 = 0;
	if(empty($txtRetTipsB1))     		$txtRetTipsB1 = 0;
	if(empty($txtRetCustomerAmount))    $txtRetCustomerAmount = 0;
	if(empty($chkRedeemCustomerPt))     $chkRedeemCustomerPt = 0;
	
	$txtRetCashInB1   = 0;
	$txtRetCashInB2   = 0;
	$txtRetCashOutB1  = 0;
	$txtRetCashOutB2  = 0;
	$txtRetTipsB1     = 0;
		
	
	if ($txtRetCurr == $base1) { 
		$txtRetCreditAmtB12 = ConvertCurrency($txtRetCreditCurr, $base1, insertMySQLDate($txtRetDate), $txtRetCreditAmt, $connection);
		$txtRetCashAmtB12   = ConvertCurrency($txtRetCashCurr  , $base1, insertMySQLDate($txtRetDate), $txtRetCashAmt, $connection);
	
		if ($txtRetNetTotal > 0) {
			$txtRetCashInB1 =   $txtRetNetTotal
							  - $txtRetCouponAmt
							  - $txtRetCreditAmtB12
							  - $txtRetCashAmtB12
							  - $txtRetCustomerAmount;
							  
			$txtRetCashInB1 =   RoundTotal($txtRetCashInB1, $CashReg_RoundDivisor, $connection);
				
			$vCashOutBase1 =   $txtRetNetTotal
							 - $txtRetCouponAmt
							 - $txtRetCreditAmtB12
							 - $txtRetCashAmtB12
							 - $txtRetCashInB1
							 - $txtRetCustomerAmount;	


			if (abs($vCashOutBase1) > 250) {
				$txtRetCashOutB1 = abs($vCashOutBase1);
			}	
			else {	
				$txtRetTipsB1 = number_format(abs($vCashOutBase1), $DecimalBase1);
				$txtRetTipsB1H = number_format($vCashOutBase1, $DecimalBase1);
				//$txtRetCashInB2 =  ConvertCurrency($base1, $base2, insertMySQLDate($txtRetDate), $vCashOutBase1, $connection);  
			}	
		} else {
			$txtRetCashOutB1 =  abs($txtRetNetTotal)
							  - abs($txtRetCouponAmt)
							  - abs($txtRetCreditAmtB12)
							  - abs($txtRetCashAmtB12)
							  - abs($txtRetCustomerAmount);
				
			$vCashInBase1  =   abs($txtRetNetTotal)
							 - abs($txtRetCouponAmt)
							 - abs($txtRetCreditAmtB12)
							 - abs($txtRetCashAmtB12)
							 - abs($txtRetCashOutB1)
							 - abs($txtRetCustomerAmount);	

			if ($vCashInBase1 < 0)         
				$txtRetCashInB1 = abs($vCashInBase1);
			else 	
				$txtRetCashOutB2 =  ConvertCurrency($base1, $base2, insertMySQLDate($txtRetDate), $vCashInBase1, $connection);  
		}	
	}
   	else if ($txtRetCurr == $base2)	{
	
		$txtRetCreditAmtB12 = ConvertCurrency($txtRetCreditCurr, $base2, insertMySQLDate($txtRetDate), $txtRetCreditAmt, $connection);
		$txtRetCashAmtB12   = ConvertCurrency($txtRetCashCurr  , $base2, insertMySQLDate($txtRetDate), $txtRetCashAmt, $connection);
		
		if ($txtRetNetTotal > 0) {
			$txtRetCashInB2 =   $txtRetNetTotal
							  - $txtRetCouponAmt
							  - $txtRetCreditAmtB12
							  - $txtRetCashAmtB12
							  - $txtRetCustomerAmount2;
							  
								  
			$vCashOutBase2 =   $txtRetNetTotal
							 - $txtRetCouponAmt
							 - $txtRetCreditAmtB12
							 - $txtRetCashAmtB12
							 - $txtRetCashInB2
							 - $txtRetCustomerAmount2;	

			if ($vCashOutBase2 < 0)         
				$txtRetCashOutB2 = abs($vCashOutBase2);
			else 	
				$txtRetCashInB1 =  ConvertCurrency($base2, $base1, insertMySQLDate($txtRetDate), $vCashOutBase2, $connection);   											
				
		} else {
			$txtRetCashOutB2 =  abs($txtRetNetTotal)
							  - abs($txtRetCouponAmt)
							  - abs($txtRetCreditAmtB12)
							  - abs($txtRetCashAmtB12)
							  - abs($txtRetCustomerAmount2);
								  
			$vCashInBase2 =    abs($txtRetNetTotal)
							 - abs($txtRetCouponAmt)
							 - abs($txtRetCreditAmtB12)
							 - abs($txtRetCashAmtB12)
							 - abs($txtRetCashOutB2)
							 - abs($txtRetCustomerAmount2);	

			if ($vCashInBase2 < 0)         
				$txtRetCashInB2 = abs($vCashInBase2);
			else 	
				$txtRetCashOutB1 =  ConvertCurrency($base2, $base1, insertMySQLDate($txtRetDate), $vCashInBase2, $connection);   											
		}
	}	
		
	
	$txtRetCashInB1  = number_format($txtRetCashInB1,  $DecimalBase1, '.', '');
	$txtRetCashInB2  = number_format($txtRetCashInB2,  $DecimalBase2, '.', '');
	$txtRetCashOutB1 = number_format($txtRetCashOutB1, $DecimalBase1, '.', '');
	$txtRetCashOutB2 = number_format($txtRetCashOutB2, $DecimalBase2, '.', '');
	
}


//Display Led Section
$com = 0;
//$CashRegister_DisplayLed=1;
if ($CashRegister_DisplayLed == 1) {
	$com = $CashRegister_DispCOM;
	if (empty($com)) $com = 0;
	
	if ($config['PhpPort']==0 or $config['PhpPort']=='' ) {
		echo '<object classid="CLSID:7E42B8C5-73BE-4806-8904-FF4080A696EC" id="comport"></object>';
		if (($txtRetNetTotalB1Disp<>0) &&  ($txtRetNetTotalB2Disp<>0))  {
			$line1= $base1.' '.$txtRetNetTotalB1Disp.'                                 ';
			$line2= $base2.' '.$txtRetNetTotalB2Disp.'                                 ';
			$string=substr($line1,0,20).substr($line2,0,18); //simulating device
			echo "<script language='javascript'>SetPort(".$com.");SendData(String.fromCharCode(12));SendData('".$string."');</script>";	   	
		} else {
			echo "<script language='javascript'>SetPort(".$com.");SendData(String.fromCharCode(12));SendData('".'      Welcome!'."');</script>";	   	
		}
	} else {
	    
		$fp = fopen ("com".$com.":9600,n,8,1,DS", "wb+");
	               	$string=chr(12); //simulating device
					fputs ($fp, $string );           
	              	fclose ($fp);
        if (($txtRetNetTotalB1Disp<>0) &&  ($txtRetNetTotalB2Disp<>0))  {
			$fp = fopen ("com".$com.":9600,n,8,1,DS", "wb+");
	   		//$line1= $base1.' '.$txtRetNetTotalB1Disp.'                                 ';
	     	//$line2= $base2.' '.$txtRetNetTotalB2Disp.'                                 ';
			$line1= str_pad($base1,($CashRegister_LedDescLength - strlen($txtRetNetTotalB1Disp))," ",STR_PAD_RIGHT).$txtRetNetTotalB1Disp;
	     	$line2= str_pad($base2,($CashRegister_LedDescLength - strlen($txtRetNetTotalB2Disp))," ",STR_PAD_RIGHT).$txtRetNetTotalB2Disp;
	        $string=substr($line1,0,$CashRegister_LedDescLength).substr($line2,0,$CashRegister_LedDescLength); //simulating device
			//echo "in";	
			//echo  $line1.$line2;
			//echo $string.$CashRegister_LedDescLength;
			//exit;
			fputs ($fp, $string );          
	        fclose ($fp);

		} else {
			$fp = fopen ("com".$com.":9600,n,8,1,DS", "wb+");
			//$string='Welcome !'; //simulating device
			$string=str_pad($CashReg_DispLedMsg,$CashRegister_LedDescLength," ",STR_PAD_RIGHT); 
			$string=$string.substr($CompanyName,0,$CashRegister_LedDescLength); //simulating device	
			//echo  $string;
			//exit;
			fputs ($fp, $string );          
	        fclose ($fp);
		}
	
	}
		
}


$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];

$txtRateB1 = $rate_dt2;
//$style= "style='width:80px; height:22px; 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' style='table-layout:fixed' width='710px;'>";
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 style='height:30px'><td valign='middle'><span class='style3'>Cash </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' cellpadding='1' style='table-layout:fixed' align='center' valign='top' >
          <col width=85>
		  <col width=280>
		  
		<tr bgcolor='#F7F7F7' height='25'>
		     <td colspan='3' align='left' valign='top' bgcolor=#D8D8D8><div style='position:relative; float:left;'>";
			echo"<button type='button' id='btnOk' name='btnOk' onclick=\"SubmitRecord('".$base1."', '".$base2."', $rate_dt1, $rate_dt2, $DecimalBase1, '".$Setup_TipsMaxAmount."');\"   title='Save Changes'><span><span>F2:Ok</span></span></button>";
			echo"<button type='button' id='btnCancel' name='btnCancel' onclick='CancelRecord();return false;'   title='Cancel Changes'><span><span>F3:Clear</span></span></button>";
				
			if ($FC_ShowBtnOpenDrawer == 1 && $CashRegister_Drawer == 1)
				echo"<button type='button' id='btnDrawer' name='btnDrawer'    onclick='OpenDrawer();return false;'   title='Open Drawer'><span><span>F11:Drawer</span></span></button>";
				
			echo"<button type='button' id='btnClose' name='btnClose'    onclick='CloseForm();return false;'   title='Close'><span><span>Esc:Close</span></span></button></div>";
			if ($CashRegister_Printer == 1)
				echo"<div style='position:relative; float:right;'><button type='button' id='btnNoPrint' name='btnNoPrint' onclick='SetNoPrint();return false;'  style='height:35px;' ><img id='img-print' class='bg-print'></img></button></div>";
echo"		 </td>
		  </tr>
		   <tr bgcolor='#F7F7F7'>	
			 <td colspan='3' align='center'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td></tr>

		
		  <tr bgcolor='#F7F7F7' >
             <td valign='center' align='left'><span class='style4'>Due</span></td> 
			 <td align='left' >
			     <input type='hidden' name='txtRetDate' value='$txtRetDate' > 
				 <input type='hidden' name='txtRetCurr' value='$txtRetCurr' >
				 <input type='hidden' name='txtRetNetTotal' value='$txtRetNetTotal' >
				 <input type='hidden' name='txtRetCreditAmtB12' id='txtRetCreditAmtB12' value='$txtRetCreditAmtB12' >
				 <input type='hidden' name='txtRetCashAmtB12' id='txtRetCashAmtB12' value='$txtRetCashAmtB12' >
				 <input type='text' name='txtRetNetTotalB1Disp' value='$txtRetNetTotalB1Disp' maxlength='20' style='background-color: #000000; color:#00FF00; text-align:right; font-size:16px; font-weight:bold; width:200px; height:27px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly >
				<input type='text' name='txtRetCurrB1' value='$base1' maxlength='20' style='background-color: #000000; color:#00FF00; font-size:16px; font-weight:bold; width:65px; height:27px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly ></td>
		 
			 <td align='left' >
			     <input type='text' name='txtRetNetTotalB2Disp' value='$txtRetNetTotalB2Disp' maxlength='20' style='background-color: #000000; color:#00FF00; text-align:right; font-size:16px; font-weight:bold; width:195px; height:27x;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly >
			 <input type='text' name='txtRetCurrB2' value='$base2' maxlength='20' style='background-color: #000000; color:#00FF00; font-size:16px; font-weight:bold; width:65px; height:27px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly ></td>
		  </tr>	";	  

if ($FC_CashRegisterCustomer == 1) {		
	echo"<tr bgcolor='#F7F7F7' height='25'>
					<td  colspan='4' style='border-right:0px solid #000000;' align='center' id='search-top2' valign='bottom'>
					 <font size='2' color='#ffffff'><b	</b></font>
				  </td></tr>";
	echo" <tr bgcolor='#F7F7F7' height='25'>
		     <td valign='center' align='left' ><span class='style4'>Card</span></td> 
			 <td align='left' >
				<input type='text'   name='txtLedgerClientCard' id='txtLedgerClientCard' value='$txtLedgerClientCard' style='width:220px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;	border-radius: 5px 5px 5px 5px;'   />
				<img src='img/openlist.png' title=' Select Customer ' width='17' height='17' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='checkcustomercard(); ' />
			 </td>
			    <td valign='center' align='left' ><span class='style4'>Salesman</span> 
				<input type='hidden'  name='txtRetSalesmanCode' id='txtRetSalesmanCode' value='$txtRetSalesmanCode' maxlength='10'  />
				<input type='text'   name='txtRetSalesmanName' id='txtRetSalesmanName' value='$txtRetSalesmanName' style='width:170px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;border-radius: 5px 5px 5px 5px;'   />
				<img src='img/openlist.png' title=' Select Salesman ' width='17' height='17' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistSalesman(1); ' />
			 </td></tr>";	
			 
	echo" <tr bgcolor='#F7F7F7' height='25'>
		     <td valign='center' align='left' ><span class='style4'>Customer</span></td> 
			 <td align='left' >
				<input type='hidden'  name='txtRetCustomerCode' id='txtRetCustomerCode' value='$txtRetCustomerCode' maxlength='10' />"; 
	if(trim($txtRetCustomerCode) != ''){
		$q1 = "select Customer_Name from customer where Customer_Code='".trim($txtRetCustomerCode)."'";
		$rs = mysql_query($q1, $connection);
		$rw = mysql_fetch_row($rs);
		$txtRetCustomerName = $rw[0];
	}
	echo 	"<input type='text'   name='txtRetCustomerName' id='txtRetCustomerName' value='$txtRetCustomerName' style='width:220px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;'  ";
	if($Show_CustomerInRetail == 0)	
	echo " onchange=\"calcCustomerDisc();\" ";			
	echo		" />";
	if($Show_CustomerInRetail == 0)			
		echo "<img src='img/openlist.png' title=' Select Customer ' width='17' height='17' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCustomer(1); ' />";
	echo " </td>	
			<td><span class='style4'>Discount %</span>
			<input type='text' name='txtRetCustomerDisc' id='txtRetCustomerDisc' value='$txtRetCustomerDisc' readonly style='width:160px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
				-webkit-border-radius: 5px 5px 5px 5px;border-radius: 5px 5px 5px 5px;'>
			</td>
		  </tr> ";
	
if($POS_RedeemPoints == 1){
	$disabled = '';
	$queryPt = "select retail_MinRedeemPoint, retail_redeemPoint from retailpoint limit 1;";
	$resultPt = mysql_query($queryPt,$connection);
	$rowPt = mysql_fetch_row($resultPt);
	$MinRedeemPoint = $rowPt[0];
	$txtRetCustomerRedeemPt = $rowPt[1];
	if($txtRetCustomerPt < $MinRedeemPoint)
		$disabled = "disabled";
	echo "<tr bgcolor='#F7F7F7' height='25'><td><span class='style4'>Rewarded Points</span></td>
			<td>  <input type='text' name='txtRetCustomerPt' id='txtRetCustomerPt' value='$txtRetCustomerPt' readonly style='width:125px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
				-webkit-border-radius: 5px 5px 5px 5px;border-radius: 5px 5px 5px 5px;'>
			</td>
			<td><span class='style4'><input type='checkbox' name='chkRedeemCustomerPt' id='chkRedeemCustomerPt' value='$chkRedeemCustomerPt' ".($chkRedeemCustomerPt==1?"checked":"")."
				$disabled onclick=\"CalcCopounCreditCheck('".$base1."', '".$base2."', $DecimalBase1);\">Redeem Award Points</span></td>
		</tr>";
	echo "<tr bgcolor='#F7F7F7' height='25'><td><span class='style4'>Redeemed Amount</span></td>
			<td><input type='text' name='txtRetCustomerAmount' id='txtRetCustomerAmount' value='$txtRetCustomerAmount' readonly style='width:125px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
				-webkit-border-radius: 5px 5px 5px 5px;border-radius: 5px 5px 5px 5px;'>
				<input type='hidden' name='txtRetCustomerRedeemPt' id='txtRetCustomerRedeemPt' value='$txtRetCustomerRedeemPt'>
			</td><td></td>
		</tr>";
}
	else echo "<input type='hidden' name='txtRetCustomerPt' id='txtRetCustomerPt' value='$txtRetCustomerPt'>
			<input type='hidden' name='chkRedeemCustomerPt' id='chkRedeemCustomerPt' value='0'>
			<input type='hidden' name='txtRetCustomerAmount' id='txtRetCustomerAmount' value='$txtRetCustomerAmount'>
			<input type='hidden' name='txtRetCustomerRedeemPt' id='txtRetCustomerRedeemPt' value='$txtRetCustomerRedeemPt'>";	
	

		  
} else {
	echo" <input type='hidden' name='txtRetCustomerCode' id='txtRetCustomerCode' value='$txtRetCustomerCode' />
		  <input type='hidden' name='txtRetCustomerName' id='txtRetCustomerName' value='$txtRetCustomerName'  >
		  <input type='hidden' name='txtRetCustomerDisc' id='txtRetCustomerDisc' value='$txtRetCustomerDisc'  >
		  <input type='hidden' name='txtRetCustomerPt' id='txtRetCustomerPt' value='$txtRetCustomerPt'  >
		  <input type='hidden' name='txtRetCustomerAmount' id='txtRetCustomerAmount' value='$txtRetCustomerAmount'>
		  <input type='hidden' name='txtRetCustomerRedeemPt' id='txtRetCustomerRedeemPt' value='$txtRetCustomerRedeemPt'>
		  <input type='hidden' name='chkRedeemCustomerPt' id='chkRedeemCustomerPt' value='0'>
		  <input type='hidden'  name='txtRetSalesmanCode' id='txtRetSalesmanCode' value='$txtRetSalesmanCode' maxlength='10'  />
		  <input type='hidden'   name='txtRetSalesmanName' id='txtRetSalesmanName' value='$txtRetSalesmanName' style='width:247px; height:22px;'  />";
}


echo"	<tr bgcolor='#F7F7F7' height='25'>
		     <td valign='center' align='left' ><span class='style4'>Info.</span></td> 
			 <td align='left'  colspan='2'>
				<input type='text' name='txtRetRemark' id='txtRetRemark' value='".htmlspecialchars($txtRetRemark, ENT_QUOTES)."'  style='width:520px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' maxlength='100'  ></span>
			 </td>	
		 </tr>	";		  
		 


if ($FC_CashRegisterCoupon == 1) {		  
		  
	echo" <tr bgcolor='#F7F7F7' height='25'>
		<td  colspan='3' style='border-right:0px solid #000000;' align='center' id='search-top2' valign='bottom'>
		 <font size='2' color='#ffffff'><b>COUPON</b></font>
		</td></tr>
		
		<tr>
		     <td valign='center' align='left' ><span class='style4'>Coupon</span></td> 
			 <td align='left' colspan='2'>
				<input type='hidden'  name='txtRetCouponId' id='txtRetCouponId' value='$txtRetCouponId' maxlength='10' />";
				
	if ($txtRetNetTotal >= 0) {
		echo"	<input type='text'  name='txtRetCouponCode' id='txtRetCouponCode' value='$txtRetCouponCode' maxlength='10' style='width:70px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly/>
				<input type='text'  name='txtRetCouponName' id='txtRetCouponName' value='$txtRetCouponName' style='width:110px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly />
				<img src='img/openlist.png' title=' Select Coupon ' width='17' height='17' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCoupon(1); ' />";
	} else {
		echo"	<input type='hidden'  name='txtRetCouponCode' id='txtRetCouponCode' value='$txtRetCouponCode' maxlength='10'  />
				<input type='text'  name='txtRetCouponName' id='txtRetCouponName' value='".htmlspecialchars($txtRetCouponName, ENT_QUOTES)."' style='width:240px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;'  />";
	}
				
	echo"		";
	
	if ($txtRetNetTotal >= 0) {	  
		echo"     <span class='style4'>&nbsp; Amount ";
	} else {
		echo"    <button type='button' id='btnCouponAmt' name='btnCouponAmt'    onclick=\"CalcBalanceAmount(this.id, '".$base1."', '".$base2."', $DecimalBase1);\"   title='Calculate Coupon Amount'><span><span>Amount</span></span></button> ";
	}
	echo"	
				<input type='text' name='txtRetCouponAmt' id='txtRetCouponAmt'  value='$txtRetCouponAmt' onfocus=FillHidden('txtRetCouponAmt'); onChange=\"CalcCopounCreditCheck('".$base1."', '".$base2."', $DecimalBase1);\"  maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:98px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;'  >
				";
				
	if ($txtRetNetTotal >= 0) {			
		echo"	<span class='style4'>Remain</span>
				<input type='text' name='txtRetCouponRemAmt' value='$txtRetCouponRemAmt' maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:90px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly>";
	} else {
		echo"<input type='hidden' name='txtRetCouponRemAmt' value='$txtRetCouponRemAmt' maxlength='20' >";	
	}
	
	echo"	<span class='style16'>$txtRetCurr&nbsp;</span> </td>	
		  </tr>
		";
} else {
	echo" <input type='hidden' name='txtRetCouponId' id='txtRetCouponId' value='$txtRetCouponId' />
		  <input type='hidden' name='txtRetCouponCode' id='txtRetCouponCode' value='$txtRetCouponCode'  >
		  <input type='hidden' name='txtRetCouponName' id='txtRetCouponName' value='$txtRetCouponName'  />
		  <input type='hidden' name='txtRetCouponRemAmt' id='txtRetCouponRemAmt' value='$txtRetCouponRemAmt'  />
		  <input type='hidden' name='txtRetCouponAmt'  id='txtRetCouponAmt'  value='$txtRetCouponAmt'  />";
				
}		  
		  
if ($FC_CashRegisterCredit == 1) {

	echo" <tr bgcolor='#F7F7F7' height='25'>
		<td  colspan='3' style='border-right:0px solid #000000;' align='center' id='search-top2' valign='bottom'>
		 <font size='2' color='#ffffff'><b>CREDIT CARD</b></font>
		</td></tr>
		<tr bgcolor='#F7F7F7' height='25'>
		     <td valign='center' align='left' ><span class='style4'>Credit</span></td> 
			 <td align='left'>
				<input type='text'  name='txtRetCreditCard' id='txtRetCreditCard' value='$txtRetCreditCard' maxlength='10' style='width:90px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly/>
				<input type='text'  name='txtRetCreditName' id='txtRetCreditName' value='$txtRetCreditName' style='width:140px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly />
				<img src='img/openlist.png' title=' Select Credit ' width='17' height='17' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCreditCard(1); ' />
			 </td>	
		 
		     <td valign='left' align='left' >
			 <button type='button' id='btnCreditAmt' name='btnCreditAmt'    onclick=\"CalcBalanceAmount(this.id, '".$base1."', '".$base2."', $DecimalBase1);\"   title='Calculate Credit Amount' ><span><span>Amount</span></span></button>
			";
			
		if (($txtRetCreditCurr == $base1) || ($txtRetCreditCurr == "" && $txtRetCurr == $base1))
			echo "<input name='txtRetCreditCurr' id='txtRetCreditCurr' type='radio' value='$base1' onClick=\"CalcBalanceAmount(this.id, '".$base1."', '".$base2."', $DecimalBase1);\" checked/>$base1";
		else 
			echo "<input name='txtRetCreditCurr' id='txtRetCreditCurr' type='radio' value='$base1' onClick=\"CalcBalanceAmount(this.id, '".$base1."', '".$base2."', $DecimalBase1);\"/>$base1";
		
		if (($txtRetCreditCurr == $base2) || ($txtRetCreditCurr == "" && $txtRetCurr == $base2))	
			echo "<input name='txtRetCreditCurr' id='txtRetCreditCurr' type='radio' value='$base2' onClick=\"CalcBalanceAmount(this.id, '".$base1."', '".$base2."', $DecimalBase1);\" checked/>$base2";
		else 
			echo "<input name='txtRetCreditCurr' id='txtRetCreditCurr' type='radio' value='$base2' onClick=\"CalcBalanceAmount(this.id, '".$base1."', '".$base2."', $DecimalBase1);\"/>$base2";

	//echo"   &nbsp;";
	echo"	<input type='text' name='txtRetCreditAmt' id='txtRetCreditAmt' value='$txtRetCreditAmt' onfocus=FillHidden('txtRetCreditAmt'); onKeyup=\"ConvertAmount(this.id);\"  onChange=\"CalcCopounCreditCheck('".$base1."', '".$base2."', $DecimalBase1);\" maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:100px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;'  >	
			&nbsp;&nbsp; <span class='style4'>Disc%</span> <input type='text' name='txtRetCreditDisc' id='txtRetCreditDisc' value='$txtRetCreditDisc' style='text-align:right; font-size:16px; font-weight:bold; width:60px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly>
			</td>	
		  </tr>";
		  if($CashRegister_RestrictSlipNoOnPay == 1 ){			  
			echo" <tr>";
			echo"  <td valign='center' align='left' ><span class='style4'>Slip No.</span></td> 
			 <td align='left'>
				<input type='text' name='txtslipNO' id='txtslipNO' value='$txtslipNO' maxlength='10' style='width:120px; height:22px;-moz-border-radius: 0px 5px 5px 5px;-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px;' /></td>";
			echo" </tr>";
		  }else{
			  echo"  <input type='hidden' name='txtslipNO' id='txtslipNO' value='$txtslipNO'  /></td>";
		  }
		  
		  
	$sub_query1 = " Select Payment_Id, Payment_Account, Payment_Description, Payment_Image ".
				  " From PaymentMethods ";
	//echo $sub_query1;
	$sub_result1=mysql_query($sub_query1,$connection) or die(mysql_error());
    $sub_rowcount=mysql_num_rows($sub_result1);	  
	
	if ($sub_rowcount > 0) {
		echo" <tr bgcolor='#F7F7F7'>
				 <td colspan='3'><div style='float:left; margin-left:90px;'>";
			
		$i = 0;	
		while($sub_rows1=mysql_fetch_array($sub_result1)){
			extract($sub_rows1);
			
			
			echo"	<div class='payment-type-radio'><img border='0' src='PaymentLogoFile.php?PayId=$Payment_Id' width='37' height='23' title='$Payment_Description' onclick=\"PayCard('".$Payment_Account."','".$Payment_Description."', '".$base1."', '".$base2."', $DecimalBase1);\" /></div>";
					
			$i = $i + 1;		
		}			
			
		echo"		  <div></td></tr>";	
		
	}		  

} else {
	echo" <input type='hidden' name='txtRetCreditCard' id='txtRetCreditCard' value='$txtRetCreditCard' />
		  <input type='hidden' name='txtRetCreditName' id='txtRetCreditName' value='$txtRetCreditName'  >
		  <input type='hidden' name='txtRetCreditCurr' id='txtRetCreditCurr' value='$txtRetCreditCurr'  />
		  <input type='hidden' name='txtRetCreditAmt'  id='txtRetCreditAmt'  value='$txtRetCreditAmt'  />";
				
}	  

if ($FC_CashRegisterCheck == 1) {		
	echo"<tr bgcolor='#F7F7F7' height='25'>
		<td  colspan='3' style='border-right:0px solid #000000;' align='center' id='search-top2' valign='bottom'>
		 <font size='2' color='#ffffff'><b>CHECKS</b></font>
		</td></tr>";
	echo" <tr bgcolor='#F7F7F7' height='25'>
		     <td valign='center' align='left' ><span class='style4'>Check No.</span></td> 
			  
			 <td align='left'  valign='center'  colspan='3'>
				<input type='text'  name='txtRetCheckNo' id='txtRetCheckNo' value='$txtRetCheckNo'  maxlength='20' style='width:100px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' onfocus=/>
				&nbsp;&nbsp;<span class='style4'>Bank/Branch</span>
			
				<input type='text'  name='txtRetBankName' id='txtRetBankName' value='$txtRetBankName' style='width:100px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' maxlength='30'  />
				<input type='text'  name='txtRetBranchName' id='txtRetBranchName' value='$txtRetBranchName' style='width:100px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' maxlength='20'  />
				&nbsp;&nbsp;<span class='style4'>Date</span>
				<input type='text' size='8' name='txtRetCheckDate' id='txtRetCheckDate' value='$txtRetCheckDate' maxlength='10' style='-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' >
				  <A HREF=\"#\" onClick=\"displayCalendar(document.retailpay.txtRetCheckDate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A>
			 </td>	
		  </tr>
		 
		  <tr bgcolor='#F7F7F7' height='25'><td>&nbsp;</td>
		     <td valign='center' align='left' colspan='2'>
			 <button type='button' id='btnCheckAmt' name='btnCheckAmt'    onclick=\"CalcBalanceAmount(this.id, '".$base1."', '".$base2."', $DecimalBase1);\"   title='Calculate Check Amount'><span><span>Amount</span></span></button>
			 
			    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name='txtRetCashCurr' id='txtRetCashCurr' style='width:60px;' onChange=\"CalcBalanceAmount(this.id, '".$base1."', '".$base2."', $DecimalBase1);\"  >";
				echo"<option></option>";
				while($curf=mysql_fetch_row($resultcurrency)){
					echo"<option ";
					if ($txtRetCashCurr==$curf[0] || $txtRetCurr==$curf[0])
						echo " selected ";
					echo" value='$curf[0]'>$curf[0] </option>";
				}
				echo"</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				  
				<input type='text' name='txtRetCashAmt' id='txtRetCashAmt' value='$txtRetCashAmt' onfocus=FillHidden('txtRetCashAmt'); onKeyup=\"ConvertAmount(this.id);\"  onChange=\"CalcCopounCreditCheck('".$base1."', '".$base2."', $DecimalBase1);\"  maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:205px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;'  >
			 </td>	
		  </tr>";
} else {
	echo" <input type='hidden' name='txtRetCheckNo' id='txtRetCheckNo' value='$txtRetCheckNo' />
		  <input type='hidden' name='txtRetCheckDate' id='txtRetCheckDate' value='$txtRetCheckDate'  >
		  <input type='hidden' name='txtRetBankName' id='txtRetBankName' value='$txtRetBankName'  />
		  <input type='hidden' name='txtRetBranchName' id='txtRetBranchName' value='$txtRetBranchName'  />
		  <input type='hidden' name='txtRetCashCurr' id='txtRetCashCurr' value='$txtRetCashCurr'  >
		  <input type='hidden' name='txtRetCashAmt' id='txtRetCashAmt' value='$txtRetCashAmt'  >";
				
}		  
			     
				 
		  
echo"	  <tr bgcolor='#F7F7F7'>
		     <td colspan='3'>
			    <table border='0' cellpadding='1' style='table-layout:fixed' align='center' valign='top' >
				  <col width=60>
				  <col width=140>
				  <col width=150>
				  <tr bgcolor='#F7F7F7' height='25'>
					<td  colspan='4' style='border-right:0px solid #000000;' align='center' id='search-top2' valign='bottom'>
					 <font size='2' color='#ffffff'><b>PAYMENT</b></font>
				  </td></tr>
				   <tr height='25px'>
						<td align='center'>&nbsp;</td>
						<td align='center'><span class='style16'>Pay</span></td>
						<td align='center'><span class='style16'>Return</span></td>";
						
						echo"<td valign='top'  align='left' rowspan=6>
<table cellspacing=1 cellpadding=1 border='0' style='padding-top:5px;'>

<tr>
<td><input type='button' value='.' class='calculatorbutton' onclick=\"FillInput('.','".$base1."','".$base2."',$DecimalBase1);\"></td>
<td rowspan='2'><input type='button' value='Enter' class='submitbutton' onclick=\"ClickEnter();\"></td>

<td><input type='button' value='1' class='calculatorbutton' onclick=\"FillInput(1,'".$base1."','".$base2."',$DecimalBase1);\"></td>
<td><input type='button' value='2' class='calculatorbutton' onclick=\"FillInput(2,'".$base1."','".$base2."',$DecimalBase1);\" id='button2'></td>
<td><input type='button' value='3' class='calculatorbutton' onclick=\"FillInput(3,'".$base1."','".$base2."',$DecimalBase1);\"></td>
</tr>


<tr>
<td><input type='button' value='00' class='calculatorbutton' onclick=FillInput('00','".$base1."','".$base2."',$DecimalBase1);></td>

<td><input type='button' value='4' class='calculatorbutton' onclick=\"FillInput(4,'".$base1."','".$base2."',$DecimalBase1);\"></td>

<td><input type='button' value='5' class='calculatorbutton' onclick=\"FillInput(5,'".$base1."','".$base2."',$DecimalBase1);\"></td>
<td><input type='button' value='6' class='calculatorbutton' onclick=\"FillInput(6,'".$base1."','".$base2."',$DecimalBase1);\"></td>
</tr>

<tr><td><input type='button' value='0' class='calculatorbutton' onclick=\"FillInput(0,'".$base1."','".$base2."',$DecimalBase1);\"></td>
	<td><input type='button' value='Clr' class='calculatorbutton' onclick='EraseInput();'></td>
	
	<td><input type='button' value='7' class='calculatorbutton' onclick=\"FillInput(7,'".$base1."','".$base2."',$DecimalBase1);\"></td>
	<td><input type='button' value='8' class='calculatorbutton' onclick=\"FillInput(8,'".$base1."','".$base2."',$DecimalBase1);\"></td>
	<td><input type='button' value='9' class='calculatorbutton' onclick=\"FillInput(9,'".$base1."','".$base2."',$DecimalBase1);\"></td>
</tr>";
//echo"<tr><td><input type='button' value='<=' class='calculatorbutton' onclick='EraseFromInput();'></td></tr>";

echo"</table></td>
					</tr>	
					<tr height='25px'>
						<td align='left'><span class='style16'>$base1</span></td>
						<td align='left'><input type='text' name='txtRetCashInB1' id='txtRetCashInB1' value='$txtRetCashInB1' onfocus=FillHidden('txtRetCashInB1'); onChange=\"CalcCashInB1('".$base1."', '".$base2."', $rate_dt1, $rate_dt2, $DecimalBase1, $Module_CashRegisterBase2);\"   maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:130px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;'  ></td>
						<td align='left'><input type='text' name='txtRetCashOutB1' id='txtRetCashOutB1' value='$txtRetCashOutB1'  onfocus=FillHidden('txtRetCashOutB1'); onChange=\"CalcCashOutB1('".$base1."', '".$base2."', $rate_dt1, $rate_dt2, $DecimalBase1, $Module_CashRegisterBase2);\"  maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:130px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;'  ></td>
					";
					

			
		echo"</tr>";
					
if ($Module_CashRegisterBase2 == 1) {				
	echo"			<tr >
						<td align='left'><span class='style16'>$base2</span></td>
						<td align='left'><input type='text' name='txtRetCashInB2' id='txtRetCashInB2' value='$txtRetCashInB2' onfocus=FillHidden('txtRetCashInB2');  onChange=\"CalcCashInB2('".$base1."', '".$base2."', $rate_dt1, $rate_dt2, $DecimalBase1);\"  maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:130px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;'  ></td>
						<td align='left'><input type='text' name='txtRetCashOutB2' id='txtRetCashOutB2' value='$txtRetCashOutB2' onfocus=FillHidden('txtRetCashOutB2');  onChange=\"CalcCashOutB2('".$base1."', '".$base2."', $rate_dt1, $rate_dt2, $DecimalBase1);\"  maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:130px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;'  ></td>
					</tr>";
} else {
	echo"          <input type='hidden' name='txtRetCashInB2' id='txtRetCashInB2' value='$txtRetCashInB2'  maxlength='20' >";
	echo"          <input type='hidden' name='txtRetCashOutB2' id='txtRetCashOutB2' value='$txtRetCashOutB2'  maxlength='20' >";

}

	echo" <tr bgcolor='#F7F7F7' height='25'>
			<td valign='center' align='left' ><span class='style4'>Rate ($base1)</span></td> 
			
		  <td align='left'  colspan='2'>
				<input type='text' name='txtRateB1' id='txtRateB1' value='$txtRateB1' maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:70px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly  >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='style4'>DIFF</span>
			<input type='hidden' name='txtRetTipsB1H' id='txtRetTipsB1H' value='$txtRetTipsB1H' maxlength='20'  >
				<input type='text' name='txtRetTipsB1' id='txtRetTipsB1' value='$txtRetTipsB1' maxlength='20' style='text-align:right; font-size:16px; font-weight:bold; width:130px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' readonly  >
				<tr><td></td><td colspan=2>
				
			</td>	</tr>";
			
			if ($txtRetCurr == $base1) { 
				echo"  <tr height='40px;'><td colspan='3' align='center'><span class='style26'>". number_format(RoundTotal($txtRetNetTotal, $CashReg_RoundDivisor, $connection), $DecimalBase1) ."  ". $txtRetCurr ."</span></td></tr>";
			}			 
			else if ($txtRetCurr == $base2) { 
				echo"  <tr height='40px;'><td colspan='3' align='center'><span class='style26'>". number_format(RoundTotal($txtRetNetTotal, $CashReg_RoundDivisor, $connection), $DecimalBase2) ."  ". $txtRetCurr ."</span></td></tr>";
			}
echo"			</table>	
			 </td>
		  </tr>	 
		 ";
		  


echo"      </table>";
 echo "</td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";			 
	echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:560px;' valign='top'>";
		
	//include("toolbar.php");	
		echo"</td>
		<td id='search-bottom3' style='height:34px; width:31px;' valign='top'></td>";
echo" </tr>";	  
echo "<div id='mainDiv' >Working, please wait ...</div>";	
echo "<div id='imgDiv'><p><image src='img/ajax-loader.gif' id='loader-img' /></p></div>";

if($noprint == '0' && $noprint != ''){
	echo "<script> PrintPreview(); </script>";
}

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

HERE;

if ($CashRegister_Drawer == 1 && $CashRegister_DrawerCOM != '' && $CashRegister_DrawerCOM != 0) {
	$com = $CashRegister_DrawerCOM;
	if (empty($com)) $com = 0;
	$fp = fopen ("com".$com.":9600,n,8,1,DS", "wb+") or die("Can't Open Port");
	$string=chr(12); //simulating device
	fputs ($fp, $string );             
	fclose ($fp);

}
else if ($CashRegister_Drawer == 1 && $CashRegister_DrawerPrinter != '') { 
	$handle = fopen("PRN", "w"); 
	if ($fp){	
		fwrite($handle, $CashRegister_DrawerPrinter); 
	} 	
}	

function ConvertCurrency($FromCurr, $ToCurr, $FromDate, $Amount, $connection)
{
	$query = "SELECT ifNull(convertcurfunc('".$FromCurr."', '".$ToCurr."', '".$FromDate."', 0, 0, '', '', ifNull($Amount,0)),0) From Dual ";
	$result = selectData($connection, $query);
	//echo $query;
	Return	$result[0];

}
/*
function RoundTotal($Amount, $Divisor, $Option) {
	$RAmount = 0;
	
	if ($Option == 1) { 
		$Remain = round(fmod(abs($Amount),$Divisor),2); 
		$RAmount = abs($Amount) - $Remain;
		
		$Remain = round(abs($Remain)); 
		if ($Remain >=0 && $Remain <=124) $Round = 0;
		else if ($Remain >=125 && $Remain <=374)  $Round = 250;
		else if ($Remain >=375 && $Remain <=674)  $Round = 500;
		else if ($Remain >=675 && $Remain <=874)  $Round = 750;
		else if ($Remain >=875 && $Remain <=1000) $Round = 1000;
		
		$RAmount = $RAmount + $Round;
		
	}
	else if ($Option == 2) {
		$Remain = ((ceil(abs($Amount)) - abs($Amount))*1000);
		$RAmount = floor(abs($Amount));
		
		if ($Remain >=0 && $Remain <=124) $Round = 0;
		else if ($Remain >=125 && $Remain <=374)  $Round = 250;
		else if ($Remain >=375 && $Remain <=674)  $Round = 500;
		else if ($Remain >=675 && $Remain <=874)  $Round = 750;
		else if ($Remain >=875 && $Remain <=1000) $Round = 1000;
		
		$RAmount = $RAmount + ($Round/1000);
	}
	
	if ($Amount < 0) $RAmount = (-1)*($RAmount);
	
	return $RAmount;
}*/

?>