<?php
header("Content-type: text/html; charset=windows-1256");

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

if($HTTP_SESSION_VARS['cashregister']==""){
header("location:Form_Retail_CashUsers.php");
}

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



$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");



$querylog="SELECT FC_CashRegister as loginaccess,FC_CashRegisterCustomer as FC_CashRegisterCustomer from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')	";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");


		
//$querylog="select * from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')  ";
$querylog=" select ifNull(FC_CashRegisterDel,0) As FC_CashRegisterDel, ifNull(FC_CashRegisterMod,0) As FC_CashRegisterMod, ".
          " ifNull(FC_CashRegisterApp,0) As FC_CashRegisterApp, ifNull(FC_CashRegisterPosting,0) As FC_CashRegisterPosting, ".
		  " ifNull(FC_CashRegisterAskPrint,0) As FC_CashRegisterAskPrint, ifNull(FC_CashRegisterSearch,0) As FC_CashRegisterSearch, ".
		  " ifNull(FC_CashRegisterQtyRet,0) As FC_CashRegisterQtyRet, ifNull(FC_ShowBtnOpenDrawer,0) As FC_ShowBtnOpenDrawer, ".
		  " ifNull(Unmodify_sellingprice,0) As Unmodify_SellingPrice, ifNull(FC_CashRegisterClosing,0) As FC_CashRegisterClosing, ". 
		  " ifNull(FC_ShowBtnCancel,0) As FC_ShowBtnCancel, ifNull(FC_CashRegisterDelItem,0) As FC_CashRegisterDelItem,ifNull(FC_DiscountPerLimit,0) As FC_DiscountPerLimit ".
		  " from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}


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

	
//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, Company_Name As CompanyName, ".
			 " ifNull(CashReg_DispLedMsg, 'Welcome !') As CashReg_DispLedMsg, ifNull(CashReg_Weight,0) As CashReg_Weight, ifNull(CashReg_RoundDivisor,1) As CashReg_RoundDivisor,ifnull(cashreg_colortheme,'default') as cashreg_colortheme ".
			 " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}


//Read From Module Table
$querymodule=" Select ifNull(Module_AdditionalTaxes,0) As Module_AdditionalTaxes, ifNull(Module_Pack,0) As Module_Pack, ".
             " ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_CashRegisterFastItem,0) As Module_CashRegisterFastItem, ifNull(Module_SerialNo,0) As Module_SerialNo,  ".
			 " ifNull(Module_PriceOffer,0) As Module_PriceOffer, ifNull(Module_CashRegAutoItemsList,0) As Module_CashRegAutoItemsList, ".
			 " ifNull(Module_RestaurantDelivery,0) As Module_RestaurantDelivery,ifNull(Module_CashRegisterStandardView,0) As Module_CashRegisterStandardView, ".
			 " ifNull(Module_CashRegisterTable,0) As Module_CashRegisterTable ".
			 " From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

//Read From CashRegister Table
$queryCashRegister=" Select Upper(CashRegister_Name) As CashRegister_Name, Currency_Code As StpCurrCode, CostCenter_Code As StpCostCentCode, Project_Code As StpProjectCode, ".
                   " ifNull(CashRegister_BarCode,0) As CashRegisterBarCode, ifNull(CashRegister_SerialNo,0) As CashRegisterSerialNo, ifNull(CashRegister_Discount,0) As CashRegisterDiscount, ".
				   " CashRegisterTTC, Client_Account As StpClientAccount, ifNull(CashRegister_SlipPrinter,0) As CashRegister_SlipPrinter, ".
				   " ifNull(CashRegister_AutoPost,0) As CashRegister_AutoPost, ifNull(CashReg_Vendor,0) As CashReg_Vendor, ".
				   " ifNull(CashRegister_DisplayLed,0) As CashRegister_DisplayLed, ifNull(CashRegister_DispCOM,0) As CashRegister_DispCOM, ".
				   " ifNull(CashRegister_PrintBarcode,0) As CashRegister_PrintBarcode, ifNull(CashReg_ForcingVendor,0) As CashReg_ForcingVendor, ".
				   " ifNull(CashRegister_LedDescLength,0) As CashRegister_LedDescLength, ifNull(CashRegister_Printer,0) As CashRegister_Printer ".
				   " From CashRegister ".
				   " Where CashRegister_Name = '".$_SESSION['cashregister']."' ";
				 //echo$queryCashRegister;
$resultCashRegister=mysql_query($queryCashRegister,$connection) or die(mysql_error());
while($rowCashRegister=mysql_fetch_array($resultCashRegister)){
	extract($rowCashRegister);
}


	
$queryUsers="SELECT User_Account As UserAccount, FullName As UserFullName From ".$_SESSION['dbLabel'].".Users where user_account='".$_SESSION['useraccount']."' 	";
$resultUsers=mysql_query($queryUsers,$connection) or die(mysql_error());
while($rowUsers=mysql_fetch_array($resultUsers)){
	extract($rowUsers);
}

$actionmode = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$mainaction = $_POST["mainaction"]; if ($mainaction == ""){$mainaction = $_GET["mainaction"];}   

if (empty($mainaction))
	$mainaction = 'insert';

$message = ereg_replace("'"," ",$message);

if($txtSubGroup=='' && $subgroup_codeParent!='') $txtSubGroup=$subgroup_codeParent;

print <<<HERE
<head>

<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<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" />';
}

print <<<HERE
<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">

    
<script type="text/javascript" language="javascript">
var gmyWin=null;
var gmyWin1=null;
var winAddItems;

function CheckFields(){
	
  
    x = document.retail;
	
	var RetDate		  = x.txtDate.value;
	var RetProject 	  = x.txtProjectCode.value;
	var RetCostCenter = x.txtCostCentCode.value;
	var RetCurr		  = x.txtCurr.value;
	var RetClientCode = x.txtClientCode.value;
	var ItemQty		  = x.txtItemQty.value;
	var ItemPrice	  = x.txtItemPrice.value;
	var ItemBarcode   = x.txtItemBarcode.value;
	
	
	if (ItemQty == '')	 ItemQty = 1;
	if (ItemPrice == '') ItemPrice = 0;
	
	var vmode  = x.mainaction.value;
	var vmode1 = x.actionmode.value;
	
	vModuleProject    = x.ModuleProject.value;
	vModuleCostCenter = x.ModuleCostCenter.value;
	vModuleQtyReturn  = x.ModuleQtyReturn.value;
	
	var vPassChecked  = x.passchecked.value;


	var result = 1;
	
	var vMinusSignExists = 0;
	if (ItemBarcode.indexOf("-") !== -1) {
		var vItemPrefix = ItemBarcode.split("-",1);
		if ((vItemPrefix*1 == vItemPrefix/1) || vItemPrefix == "*") vMinusSignExists = 1;
	}
	
	if (RetDate=='' )
	{
		alert("Date is mandatory!");
		x.txtDate.focus();
		result = 0;
	}
	else if (RetProject=='' && vModuleProject==1)
	{
		alert("Project is mandatory!. Please check data in table cashregister.");
		result = 0;
	}
	else if (RetCostCenter=='' && vModuleCostCenter==1)
	{
		alert("CostCenter is mandatory!. Please check data in table cashregister.");
		result = 0;
	}
	else if (RetCurr=='' )
	{
		alert("Currency is mandatory!. Please check data in table cashregister.");
		result = 0;
	}
	else if (RetClientCode=='' )
	{
		alert("Client is mandatory!. Please check data in table cashregister.");
		result = 0;
	}
	else if ((ItemPrice*1 != ItemPrice/1 ) || ItemPrice < 0) {
		alert('Price should be a POSITIVE and NUMERIC value. ');
		x.txtItemPrice.focus();
		result = 0;
	}
	else if (ItemQty*1 != ItemQty/1 ) {
		alert('Quantity should be a NUMERIC value. ');
		x.txtItemQty.focus();
		result = 0;
	}
	
	else if ((ItemQty < 0 || vMinusSignExists == 1) && vModuleQtyReturn==0 && vPassChecked==0)
	{
		//alert('You have no access to return items. ');
		//x.txtItemQty.focus();
		
		win = window.open('Form_Retail_Password.php?actionmode=returnitem',
						  'Form_Retail_Password', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=450,height=200,left=200,top=100');		
		win.creator = self;
		win.focus();
		
		x.passchecked.value = '';
		
		result = 0;
	}		
	
		
	if (result == 0) {
		
		PlayErrorSound();	
	}
	
	return result;	
}

function fillprojectdt(vprojectid){
document.retail.txtProjectDtId.value = vprojectid;
}

function CheckFieldsDt(PIndex,DiscountPerLimit,CashRegForcingVendor){
	
	x = document.retail;
	var vModuleQtyReturn  = x.ModuleQtyReturn.value;
	
	var vPassChecked      = x.passchecked.value;
	
	var vmode = x.actionmode.value;
	
	//var RetDtWarehouseCode = x.txtWarehouseCode[PIndex].value;
	var RetDtQty           =document.getElementById('qtydt['+PIndex+']').value;
	
	var RetDtPrice         =document.getElementById('pricedt['+PIndex+']').value;
	var RetDtDiscount 	   =document.getElementById('discdt['+PIndex+']').value;
	var RetDtVendorCode    =document.getElementById('vendordt['+PIndex+']').value;
	
	if (RetDtPrice == '')    RetDtPrice = 0;
	if (RetDtDiscount == '') RetDtDiscount = 0;
	
	RetDtDiscount    = parseFloat(RetDtDiscount);
	DiscountPerLimit = parseFloat(DiscountPerLimit);

	if (RetDtQty < 0 && vModuleQtyReturn==0 && vPassChecked==0)
	{
		
		win = window.open('Form_Retail_Password.php?actionmode=returnitem2&PIndex='+PIndex,
						  'Form_Retail_Password', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=450,height=250,left=200,top=100');		
		win.creator = self;
		win.focus();
		
		x.passchecked.value = '';
		
		return 0;
	}
	//else if (RetDtWarehouseCode=='')
	//{
	//	alert("Warehouse is mandatory!");
	//	x.txtWarehouseCode.focus();
	//	return 0;
	//}
	else if ((RetDtPrice*1 != RetDtPrice/1 ) || RetDtPrice < 0) {
		alert('Price should be a POSITIVE and NUMERIC value. ');
		document.getElementById('pricedt['+PIndex+']').focus();
		return 0;
	}
	else if (RetDtDiscount > 0 && DiscountPerLimit >= 0 && RetDtDiscount > DiscountPerLimit) {
		alert('Discount should be less than or equal to allowed limit ('+DiscountPerLimit+')');
		document.getElementById('discdt['+PIndex+']').focus();
		return 0;
	}
	else if (CashRegForcingVendor == 1 && RetDtVendorCode == '') {
		alert("Vendor is mandatory!");
		document.getElementById('discdt['+PIndex+']').focus();
		document.getElementById('vendordt['+PIndex+']').focus();
		return 0;
	} 
		
	
	else
	return 1 ;	
}


function ClearPage(CashRegClear,btname){
	x = document.retail;
	var vPassChecked = x.passchecked.value;
	
	if (CashRegClear == 0 && vPassChecked == 0) {
		win = window.open('Form_Retail_Password.php?actionmode=cancelrecord',
						  'Form_Retail_Password', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=400,height=200,left=200,top=100');		
		win.creator = self;
		win.focus();
    } else {
		if (confirm ( "Are you sure you want to "+btname+" Page?"))
		{
			ClearForm('All');
			x.mainaction.value='insert';
			x.actionmode.value='';
			x.action='Form_Retail.php';
			x.submit();
		}	
		
		x.passchecked.value = '';
	}	
}


function OpenTable(vprojectdtid,CashRegClear){
	x = document.retail;
	var vPassChecked = x.passchecked.value;
	
	{
		if (confirm ( "Are you sure you want to Open New Table?"))
		{
			ClearForm('All');
			
			fillprojectdt(vprojectdtid);
			
			x.mainaction.value='insert';
			x.actionmode.value='';
			x.action='Form_Retail.php';
			x.submit();
		}	
		
		x.passchecked.value = '';
	}	
}

function ClearPage1(){
	x = document.retail;
	var msg = x.message.value;
	
	ClearForm('All');
	
	x.mainaction.value='insert';
	x.actionmode.value='';
	x.message.value=msg;
	x.action='Form_Retail.php?message='+x.message.value;
	x.submit();
}

function CancelRecord(CashRegCancel){
	x = document.retail;
	var vmode  = x.mainaction.value;
	var vmode1 = x.actionmode.value;
	var RetId = x.txtId.value;
	var vPassChecked = x.passchecked.value;
	
	var vCancelMsg = "Are you sure you want to Delete current pending invoice permenantly?";
	
	if (CashRegCancel == 0 && vPassChecked == 0) {
		win = window.open('Form_Retail_Password.php?actionmode=cancelrecord',
						  'Form_Retail_Password', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=400,height=200,left=200,top=100');		
		win.creator = self;
		win.focus();
    } else {	
	
		if (confirm ( vCancelMsg))
		{
			ClearForm('All');
			x.txtId.value = RetId;
			x.mainaction.value='insert';
			x.actionmode.value='cancel';
			x.action='Form_Retail.php';
			x.submit();
		}
		
		x.passchecked.value = '';
    }
}



function PostChanges() {
	x = document.retail;
	var RetId  = x.txtId.value;
	var vMainMode = x.mainaction.value;
	
	
	
	
	if (x.txtCountDetail.value == 0 || x.txtCountDetail.value == '') {
		alert('Save not allowed. Please add items.');
	}
	else if (x.QtySerNo.value == 1){
		alert('Please check Item(s) Qty and Serial No.');
	}
	else if (x.txtBalanceAmount.value > 100){
		alert('Payment not done.');
	}
	else {
		if (confirm ( "Are you sure you want to Save current invoice?"))
		{
			
			if (document.getElementById('btnCancel'))
				x.btnCancel.disabled = true;
			if (document.getElementById('btnPost'))
				x.btnPost.disabled = true;
			if (document.getElementById('btnAddItem'))
				x.btnAddItem.disabled = true;
			if (document.getElementById('btnClear'))
				x.btnClear.disabled = true;	
			if (document.getElementById('btnAddSerial'))
				x.btnAddSerial.disabled = true;
			if (document.getElementById('btnDiscount'))
				x.btnDiscount.disabled = true;
			if (document.getElementById('btnCash'))
				x.btnCash.disabled = true;
			if (document.getElementById('btnPosting'))
				x.btnPosting.disabled = true;	
			if (document.getElementById('btnClosing'))
				x.btnClosing.disabled = true;	
				
			
			x.actionmode.value='post';
			x.action="Form_Retail_Actions.php?mode=post&mainmode="+vMainMode+"&SRetId="+RetId;
			x.submit();
		}
	}
}


	
function DeleteRecordDt(RetDtId, ItemCode, CashRegDel,PIndex) {
	x = document.retail;
	var RetId  = x.txtId.value;
	var vMainMode    = x.mainaction.value;
	var vPassChecked = x.passchecked.value;
	var vDelMsg = '';


	
	
	
    vDelMsg = "Are you sure you want to Delete Item "+ItemCode+" ?";
	
	if (CashRegDel == 0 && vPassChecked == 0) {
		win = window.open('Form_Retail_Password.php?actionmode=deletedt&PIndex='+PIndex,
						  'Form_Retail_Password', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=450,height=200,left=200,top=100');		
		win.creator = self;
		win.focus();
    } else {
		
		if(win){
			
			if (win.open) {
				win.close();
			}
		}
		if (confirm ( vDelMsg ))
		{
			
			x.action="Form_Retail_Actions.php?mode=deletedt&mainmode="+vMainMode+"&SRetId="+RetId+"&SRetDtId="+RetDtId;
			x.submit();
		}
		
		x.passchecked.value = '';
			
	}
}
function UpdateRecord(RetId){
		
	document.retail.txtId.value=RetId;
	document.retail.mainaction.value='edit';
	document.retail.actionmode.value='';
	document.retail.action='Form_Retail.php';
	document.retail.submit();

}

function UpdateRecordDt(RetDtId, CashRegMod) {
    x = document.retail;
	var vRetId = x.txtId.value;
	var vRetDate = x.txtDate.value;
		
	var vMainMode    = x.mainaction.value;
	var vPassChecked = x.passchecked.value;
	
	if (CashRegMod == 0 && vPassChecked == 0) {
		win = window.open('Form_Retail_Password.php?actionmode=editdt',
						  'Form_Retail_Password', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=450,height=250,left=200,top=100');		
		win.creator = self;
		win.focus();
    } /*else {
		x.passchecked.value = '';
		
		win = window.open('Form_RetailDetail.php?mainaction='+vMainMode+'&actionmode=&PRetId='+vRetId+'&PRetDate='+vRetDate+'&PRetDtId='+RetDtId, 'Form_RetailDetail', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=860,height=300,top=100');		
		win.creator = self;
		win.focus();		
	}*/
}




//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.retail;
	var vmode = x.actionmode.value;
	
	if (Option == 'All') {
		
		x.txtId.value='';
		x.txtOrderId.value='';
		x.txtOrderRef.value='';
		x.txtRef.value='';
		x.txtDate.value='';
		x.txtCurr.value='';
		x.txtProjectCode.value='';
		x.txtCostCentCode.value='';
		x.txtCashRegister.value='';
		x.txtClientCode.value='';
		
		x.txtItemBarcode.value='';
		x.txtItemQty.value='';
		x.txtItemPrice.value='';
		x.txtVendorCode.value='';
		x.txtSlipNo.value='';
		
		x.txtTaxable.value='';
		x.txtNoneTaxable.value='';
		x.txtGrossTotal.value='';
		x.txtDiscount.value='';
		x.txtDiscountAmt.value='';
		x.txtVat.value='';
		x.txtNetTotal.value='';
		x.txtTotalTaxes.value='';
		
		x.txtCountDetail.value='';	
		x.QtySerNo.value='';		
		x.message.value='';
		x.string.value = '';
		
		x.actionmode.value = '';
		x.mainaction.value = '';
		x.PrRetId.value='';
		x.passchecked.value='';
		x.txtSubGroup.value='';
		x.txtProjectDtId.value='';
		
	} 
}

function AddItems() {
	x = document.retail;
	//x.actionmode.value = '';
	
	var result = CheckFields();

	var vRetId = x.txtId.value;
	var vRetDate = x.txtDate.value;
	var vRetCashRegister = x.txtCashRegister.value;
	var vRetCurr = x.txtCurr.value;
	var vRetClientCode = x.txtClientCode.value;
	var vRetProjectCode = x.txtProjectCode.value;
	var vRetCostCentCode = x.txtCostCentCode.value;
	
	
	
	var vMainMode = x.mainaction.value;
	
	if (result == 1) {
		winAddItems = window.open('Form_RetailDetail.php?mainaction='+vMainMode+'&actionmode=&PRetId='+vRetId+'&PRetDate='+vRetDate+'&PRetCashRegister='+vRetCashRegister+
								  '&PRetCurr='+vRetCurr+'&PRetProjectCode='+vRetProjectCode+'&PRetCostCentCode='+vRetCostCentCode+'&PRetClientCode='+vRetClientCode, 
								  'Form_RetailDetail', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=300,top=100,left=0');		
		winAddItems.creator = self;
		winAddItems.focus();	
		
	}	
	
    
}

function AddSerials() {
	x = document.retail;
	//x.actionmode.value = '';
	var result = CheckFields();
	
	
	var vRetId = x.txtId.value;
	var vRetDate = x.txtDate.value;
	var vRetCashRegister = x.txtCashRegister.value;
	var vRetCurr = x.txtCurr.value;
	var vRetClientCode = x.txtClientCode.value;
	var vRetProjectCode = x.txtProjectCode.value;
	var vRetCostCentCode = x.txtCostCentCode.value;
	
	
	
	var vMainMode = x.mainaction.value;
	
	if (result == 1) {
		win = window.open('Form_RetailAddSerial.php?mainaction='+vMainMode+'&actionmode=&PRetId='+vRetId+'&PRetDate='+vRetDate+'&PRetCashRegister='+vRetCashRegister+
						  '&PRetCurr='+vRetCurr+'&PRetProjectCode='+vRetProjectCode+'&PRetCostCentCode='+vRetCostCentCode+'&PRetClientCode='+vRetClientCode, 
						  'Form_RetailAddSerial', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=850,height=570,top=100,left=0');		
		win.creator = self;
		win.focus();	
		
	}
	
    
}

function AddDiscount() {
	x = document.retail;

	var vRetId   = x.txtId.value;
	var vRetDate = x.txtDate.value;
	
	var vMainMode = x.mainaction.value;
	
	if (vRetId != '') {
		gmyWin = window.open('Form_RetailDiscount.php?mainaction='+vMainMode+'&actionmode=&PRetId='+vRetId,
						  'Form_RetailDiscount', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=710,height=320,left=750,top=400',gmyWin);		
		gmyWin.creator = self;
		gmyWin.focus();		
	}

}

function OpenCustomer(){
	x = document.retail;

	win = window.open('List_Customers.php','List_Customers', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=760,height=520,left=250,top=200');		
		win.creator = self;
		win.focus();


}

function PayCash(VPhpPort,VarPort,CashRegisterPrinter) {
	x = document.retail;

	var vRetId    = x.txtId.value;
	var vRetDate  = x.txtDate.value;
	var vQtySerNo = x.QtySerNo.value;
	
	var vMainMode = x.mainaction.value;
	
	if (x.txtCountDetail.value == 0 || x.txtCountDetail.value == '') {
		alert('Not allowed. Please add items.');
	}
	else if (x.QtySerNo.value == 1){
		alert('Please check Item(s) Qty and Serial No.');
	}
	else if (vRetId != '') {
		if (VarPort!=0 && VPhpPort==0) {
			ClosePort(VarPort);
		}
		
		if (CashRegisterPrinter != 1) OpenDrawer();
		
		win = window.open('Form_RetailPayment.php?mainaction='+vMainMode+'&actionmode=&QtySerNo='+vQtySerNo+'&PRetId='+vRetId,
						  'Form_RetailPayment', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=750,height=720,left=200,top=0');		
		win.creator = self;
		win.focus();		
	}	
}

function check(winObj){
if (winObj)
	if (!winObj.closed) {
      winObj.focus();
      return winObj;
    }
}

function PostRetails() {
	x = document.retail;
	
	XPos = (screen.availHeight - 200) / 2;
	YPos = (screen.availWidth - 400) / 2;
	
	var vMainMode = x.mainaction.value;
	var vRetId    = x.txtId.value;
	
	
	/*if (confirm ( "Are you sure you want to post transactions?" ))
	{
		x.action="Form_Retail_Actions.php?mode=postretails&mainmode="+vMainMode;
		x.submit();
	}*/
	
	win = window.open('Form_Retail_PostOptions.php', 'Form_Retail_PostOptions', 
					  'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=400,height=200,left='+YPos+',top='+XPos);
	win.creator = self;
	win.focus();

}

function SubmitRecord(CashRegForcingVendor,vSubGroup) {
	x = document.retail;
	
	var vMode;
	
	var vMainMode = x.mainaction.value;
	var transid    = x.txtId.value;
	var vItemBarcode = x.txtItemBarcode.value;
	var vVendorCode  = x.txtVendorCode.value;
	var vProjectDtId  = x.txtProjectDtId.value;
	
	if (x.txtItemOption.length == undefined) {
		var vItemOption = 1;
	} else {
		for (var i=0; i < x.txtItemOption.length; i++)
		{
			if (x.txtItemOption[i].checked)
			{
				var vItemOption = x.txtItemOption[i].value;
				
			}
		}
	}	
	
	if (vItemOption == 1) vMode = 'submitrecord1';
	else vMode = 'submitrecord2';
	
	var result = CheckFields();

	if (CashRegForcingVendor == 1 && vVendorCode == '') {
		alert("Vendor is mandatory!");
		x.txtVendorCode.focus();
	} else {
		if (vItemBarcode != '' ) {
			if (result == 1) {
				if (document.getElementById('btnSubmit'))	x.btnSubmit.disabled = true;
				
				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;
						var message1 = data[0].message1;
						
						if (document.getElementById('btnSubmit'))	x.btnSubmit.disabled = false;
						
						
						if (msg != "") {
							x.passchecked.value='';
							
							$("#Loader").removeClass("ajaxsaving");
							if (document.getElementById('SubBtnID'))	document.getElementById('SubBtnID').disabled = false;
							
							if (decodeURIComponent(msg) == 'Item Not Found.' && x.Module_CashRegAutoItemsList.value== 1) {
								x=document.retail; 
								showlistItems(1);
							}

							if (decodeURIComponent(msg) == 'Item Not Found.') {
								PlayErrorSound();
								x.txtItemBarcode.focus();
							}	
						
							alert(decodeURIComponent(msg));
						} else {
							x.passchecked.value='';
							x.txtItemBarcode.value='';
							x.txtItemQty.value='';
							x.txtVendorCode.value='';
							x.txtSlipNo.value='';
							x.txtItemPrice.value='';
						
							if (transid == ""){
									
									transid = data[0].txtId;
									vSubGroup = data[0].txtSubGroup;
									x.txtId.value = transid;
									x.txtSubGroup.value = vSubGroup;
									x.txtItemBarcode.value='';
									x.txtItemBarcode.value='';
									x.txtItemQty.value='';
									x.txtVendorCode.value='';
									x.txtSlipNo.value='';
									x.txtItemPrice.value='';
									x.actionmode.value='';
									x.submit();
							} 
								
							
							
							filepath='Functions_Retail.php';
							formname='CashReg';
							orderby='';
							morelines='';
							startrange='';
							perpage='';
							direction='';
							dftorderby='';
							x.txtItemBarcode.focus(); 
							x.passchecked.value='';
							x.txtSubGroup.value='';
							
							
								ReloadGrid(filepath,formname,transid,'datagrid','1',dftorderby,'ADD',orderby,morelines,startrange,perpage,0,direction,function() {
								ReloadGridDt(filepath,'RT-TOT','TOTALS','totals',transid,-1);
							});
							
						}			
								
					}
				  }
			
				var the_data="mode="+vMode+"&mainmode="+vMainMode+"&SRetId="+transid+"&SItemOption="+vItemOption+"&txtItemBarcode="+encodeURIComponent(x.txtItemBarcode.value)+
							"&txtItemQty="+x.txtItemQty.value+"&txtVendorCode="+encodeURIComponent(x.txtVendorCode.value)+"&txtSlipNo="+encodeURIComponent(x.txtSlipNo.value)+"&txtDate="+x.txtDate.value+
							"&txtCurr="+x.txtCurr.value+"&txtClientCode="+x.txtClientCode.value+"&txtProjectCode="+x.txtProjectCode.value+"&txtCostCentCode="+x.txtCostCentCode.value+
							"&txtItemPrice="+x.txtItemPrice.value+"&txtCashRegister="+x.txtCashRegister.value+"&vSubGroup="+vSubGroup+"&ProjectDtId="+vProjectDtId; 
			
				xmlhttp.open("GET","Form_Retail_Actions.php?"+the_data);
				xmlhttp.send();
			}
		} else	{
			PlayErrorSound();
			alert("Barcode is mandatory!");
			
			x.txtItemBarcode.focus();

		}
	}
}

function SubmitRecordGrid(PIndex,formname,PRedDtId,DiscountPerLimit,CashRegForcingVendor,PItemCode){

	x = document.retail;
	
	var result = CheckFieldsDt(PIndex,DiscountPerLimit,CashRegForcingVendor);
	
	var RetId    = x.txtId.value;
	var RetDtId  = PRedDtId;
	var vMainMode = x.mainaction.value;
	var vMode= x.actionmode.value;
	
	if (RetDtId == '')
		vMode = 'submitrecord';	
	else
		vMode = 'editdt';	

	if (result == 1) {
			
		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;
				var msg1 = data[0].message1;
						
				if (msg != "") {
					alert(decodeURIComponent(msg));
				}
						
				var transid = x.txtId.value;
				x.txtItemBarcode.focus(); 
						
				if(x.passchecked.value==1){
					x.passchecked.value='';
					//x.submit();
				}
							   
				ReloadGrid(filepath,formname,transid,'datagrid','1',dftorderby,'ADD',orderby,morelines,startrange,perpage,0,direction,function() {
						ReloadGridDt(filepath,'RT-TOT','TOTALS','totals',transid,-1);
				});
			}			
		}			
			
			
		filepath='Functions_Retail.php';
		formname='CashReg';
		orderby='';
		morelines='';
		startrange='';
		perpage='';
		direction='';
		dftorderby='';
		
		var date=x.txtDate.value;
	
		var the_data='SRetId='+RetId+'&SRetDtId='+RetDtId+'&mainmode='+x.mainaction.value+'&mode='+vMode+
					'&txtRetDtQty='+document.getElementById('qtydt['+PIndex+']').value+
					'&txtRetDtVendor='+encodeURIComponent(document.getElementById('vendordt['+PIndex+']').value)+
					'&txtSlipNo='+encodeURIComponent(x.txtSlipNo.value)+
					'&txtRetDtPrice='+document.getElementById('pricedt['+PIndex+']').value+
					'&txtRetDtDiscount='+document.getElementById('discdt['+PIndex+']').value+
					'&txtRetDtSlip='+document.getElementById('slipdt['+PIndex+']').value+
					'&PRetDate='+x.txtDate.value+
					'&txtClientCode='+x.txtClientCode.value+
					'&txtItemBarcode='+document.getElementById('barcodedt['+PIndex+']').value+
					'&txtProjectCode='+x.txtProjectCode.value+
					'&txtCostCentCode='+x.txtCostCentCode.value+
					'&txtCashRegister='+x.txtCashRegister.value+
					'&txtCurr='+x.txtCurr.value+'&txtItemCode='+PItemCode+'&txtWarehouseCode='+document.getElementById('Whdt['+PIndex+']').value;
		
		//alert(the_data);
		
		xmlhttp.open("GET","Form_Retail_Actions.php?"+the_data);
		xmlhttp.send();	
		
		
	}	
}

function PlayErrorSound() {

	if( navigator.userAgent.indexOf("Chrome") != -1 ) { 
		document.getElementById('audiotag1').play();
	} else if( navigator.userAgent.indexOf("Opera") != -1 ) {
		document.getElementById('audiotag1').play();
	} else if( navigator.userAgent.indexOf("MSIE") != -1 ) { 
		document.getElementById('soundstrack').play();
	} else if( navigator.userAgent.indexOf("Firefox") != -1 ) {
		document.getElementById('audiotag1').play();
	} else {
		document.getElementById('audiotag1').play();
	}


}

function LoadFastItem(ItemCode,ItemSellPrice,UnmodifySellingPrice,ItemModifySellingPrice) {
	x = document.retail;

	var vItemBarcode = x.txtItemBarcode.value;
	
	var vMinusSignExists = 0;
	if (vItemBarcode.indexOf("-") !== -1) {
		var vItemPrefix = vItemBarcode.split("-",1);
		if (vItemPrefix*1 == vItemPrefix/1 ) vMinusSignExists = 1;
	}
	
	if(vItemBarcode.indexOf("+") != -1 || vMinusSignExists == 1) { 
		x.txtItemBarcode.value = x.txtItemBarcode.value + ItemCode;
	} else {
		x.txtItemBarcode.value = ItemCode;
	}	
	
	
	x.txtItemPrice.value = ItemSellPrice;
	
	//if (x.txtItemQty.value == '')
		//x.txtItemQty.value = 1;
	
	x.txtItemPrice.readOnly = false;
	if (UnmodifySellingPrice == 1 || ItemModifySellingPrice ==	0) {
		x.txtItemPrice.readOnly = true;
		x.btnSubmit.click();
	} else {	
		x.txtItemPrice.focus();
		x.txtItemPrice.select();
	}	
}
function openreservation(){

window.open('../Booking/Form_Booking.php','Form_Retail_FastItem','width=1100,height=450,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');

}

function CreateFastItem() {
	x = document.retail;
	
	window.open('Form_Retail_FastItem.php','Form_Retail_FastItem','width=680,height=450,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');
}


function AddSerialNo(RetDtId) {
	x = document.retail;
	var vRetId = x.txtId.value;
	
	XPos = (screen.availHeight - 450) / 2;
	YPos = (screen.availWidth - 350) / 2;
    win = window.open('Form_RetailSerialNo.php?SRRetDtId='+RetDtId+'&SRRetId='+vRetId, 'Form_RetailSerialNo', 'titlebar=no,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no, width=630,height=450,left='+YPos+',top='+XPos);		
	//win.creator = self;
	//win.focus();		
	
}

function SearchForRef(){
    
	//ClearForm('All');
    x = document.retail;
    win = window.open('Form_RetailSearch.php', 'Form_RetailSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1160,height=580,top=0,left=0');		
	win.creator = self;
	win.focus();		
			
}

function SearchForPending(){
    //ClearForm('All');
    x = document.retail;
    win = window.open('Form_RetailSearchPending.php', 'Form_RetailSearchPending', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=860,height=580,top=0,left=0');		
	win.creator = self;
	win.focus();		
			
}

function SearchItems() {
	x = document.retail;
    win = window.open('Form_RetailSearchItems.php', 'Form_RetailSearchItems', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1420,height=550,top=100,left=0');
	win.creator = self;
	win.focus();

}


function SearchOrders() {
	x = document.retail;
    win = window.open('Form_RetailOrdersList.php', 'Form_RetailOrdersList', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=900,height=450,top=100,left=0');
	win.creator = self;
	win.focus();

}

function PrintRetail(RetId, RetRef, AskPrint, ReportName) {
	var str = '';
	
	if (AskPrint == 1) {
		if (confirm ( "Do you want to Print current invoice with reference "+RetRef+" ?"))
		{
			str = ReportName+'?RetailId='+RetId;
			//window.open(str);
			window.open(str, 'Form_RetailSlip', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=500,top=100');	
		}	
	} else {
		str = ReportName+'?RetailId='+RetId;
		//window.open(str);
		window.open(str, 'Form_RetailSlip', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=500,top=100');	
	}	
	
}

function PrintSummary() {
	var x = document.form1;
	
	var str = 'Form_RetailSummary.php?PDateFrom=';
	window.open(str, 'Form_RetailSummary', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=500,top=100');	
}


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=1; //Connects to the serial port
    if(port.error>0) //Display errors if found
       alert(port.ErrorDescription);
   // CommEvent(port.event,EVT_DISCONNECT);	   
}
  
  
	   
function SendData(VarData) { 
	var port = document.getElementById("comport");
	port.Send(VarData);
	//alert(VarData); 
	//port.Connected=0;	
}

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 LogOut()
{
	x = document.retail;
	
	
	if (confirm ( "Are you sure you want to Logout?" ))
	{
		//x.action="cashregister_logout.php";
		//x.submit();
		top.window.location='../cashregister_logout.php';
	}
}



function LoadForm(ModuleCashRegAutoItemsList) 
{
	x=document.retail;
	
	if((ModuleCashRegAutoItemsList == 0 && 1 == 1) || (ModuleCashRegAutoItemsList == 1 && (x.openwin.value==0 || x.openwin.value==''))){

		x.txtItemBarcode.disabled = false;
		//x.txtItemBarcode.focus();
		document.getElementById('txtItemBarcode').focus();
		document.getElementById('txtItemBarcode').select();
	}	
	
	x.openwin.value=0;
}

function SelectItemOption() {
	x=document.retail;
	
	for (var i=0; i < x.txtItemOption.length; i++)
	{
		if (x.txtItemOption[i].checked)
		{
			var vItemOption = x.txtItemOption[i].value;
			
		}
	}
	
	if (vItemOption == 1) {
		x.txtItemOption[1].checked = true;
		x.ItemOptionLabel.value = 'SerialNo';
		x.txtItemQty.disabled = true;
	}	
	else if (vItemOption == 0) {
		x.txtItemOption[0].checked = true;
		x.ItemOptionLabel.value = 'Barcode';
		x.txtItemQty.disabled = false;
	}	
	

}

function SelectItemQty() {
	x=document.retail;

	var vItemQty = x.txtItemQty.value;
	if (vItemQty == '')   vItemQty = 1;
	
	vItemQty = vItemQty*(-1);
	
	x.txtItemQty.value = vItemQty;
}

function showlistVendors(str){
	var vVendorCode;
	x = document.retail;
  
	vVendorCode  = x.txtVendorCode.value;
	vVendorCode = vVendorCode.replace('&','%26');
	var vendorwin=null;
	

	vendorwin=window.open('List_Vendors.php?frm=3&PVendorCode='+vVendorCode+'&index='+str,'mywindow','width=750,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no',vendorwin);
	check(vendorwin);
	
}

function showlistItems(str){
	var vdate, vid, vItemBarCode, vItemWh;
	x = document.retail;
	x.message.value = '';
	
	vdate = x.txtDate.value;
	vid   = x.txtId.value;
	vItemBarCode  = x.txtItemBarcode.value;
	//vItemWh       = x.txtWarehouseCode.value;
	vItemWh 		= '';
  
	vItemBarCode = vItemBarCode.replace('&','%26');
	//vItemWh	   = vItemWh.replace('&','%26');
  
	win = window.open('List_ItemsBarcode.php?frm=2&PItem_Code='+vItemBarCode+'&TransDate='+vdate+'&ItemWh='+vItemWh,'mywindow','width=970,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');
	win.focus();
}

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


function OnHelp()
{
	return false;
}
function kd(e)
{ 
	x=document.retail;
	if (!e) { var e = window.event;}
    var intKey = (window.Event) ? e.which : e.keyCode;
	
	 
	 
	// Block browser short cuts     
	//F3, F4, F11, F12 key
	if (intKey == 114 || intKey == 115 || intKey == 122 || intKey == 123) {
		if(e.preventDefault) // non-IE browsers         
			e.preventDefault();     
		else  // IE Only  
		{
			e.keyCode=0;  
			e.returnValue = false; 
			
		}	
	}
	
    if (!e.ctrlKey && intKey == 112) { //F1 key
		if ('onhelp' in window) {   // Internet Explorer
	       window.onhelp = OnHelp;
		}
	
		x.btnAddItem.click();
		return false;
	}
	else if (!e.ctrlKey && intKey == 113) { //F2 key
		x.btnCash.click();
		return false;
	}
	else if (!e.ctrlKey && intKey == 114) { //F3 key
		x.btnDiscount.click();
		return false;
	}
	else if (!e.ctrlKey && intKey == 115) { //F4 key
		x.btnClear.click();
		return false;
	}
	else if (!e.ctrlKey && intKey == 117 && document.getElementById('btnCancel')) { //F6 key
		x.btnCancel.click();
		return false;
	}
	else if (!e.ctrlKey && intKey == 118 && document.getElementById('btnSearch')) { //F7 key
		x.btnSearch.click();
		return false;
	}
	else if (!e.ctrlKey && intKey == 119) { //F8 key
		x.btnPending.click();
		return false;
	}
	else if (!e.ctrlKey && intKey == 120 && document.getElementById('Btn_1')) { //F9 key
		document.getElementById('Btn_1').click();
		return false;
	}
	else if (!e.ctrlKey && intKey == 121 && document.getElementById('Btn_2')) { //F10 key
		document.getElementById('Btn_2').click();
		return false;
	}
	else if (!e.ctrlKey && intKey == 122 && document.getElementById('Btn_3')) { //F11 key
		document.getElementById('Btn_3').click();
		return false;
	}
	else if (!e.ctrlKey && intKey == 123 && document.getElementById('Btn_4')) { //F12 key
		document.getElementById('Btn_4').click();
		return false;
	}
	else if (intKey == 9) { //TAB key
		
		if(document.activeElement.id == 'txtItemBarcode') {
			if (x.txtItemQty.disabled == false)
				x.txtItemQty.focus();
			else
				x.txtItemPrice.focus();
		}
		else if(document.activeElement.id == 'txtItemPrice') {
			if (document.getElementById('txtVendorCode').type == 'text')
				x.txtVendorCode.focus();
			else if (document.getElementById('txtSlipNo').type == 'text')
				x.txtSlipNo.focus();
			else		
				x.txtItemBarcode.focus();
		}		
		else if(document.activeElement.id == 'txtItemQty') {
			if (document.getElementById('txtItemPrice').type == 'text')
				x.txtItemPrice.focus();
			else if (document.getElementById('txtVendorCode').type == 'text')
				x.txtVendorCode.focus();
			else if (document.getElementById('txtSlipNo').type == 'text')
				x.txtSlipNo.focus();
			else		
				x.txtItemBarcode.focus();
		}
		else if(document.activeElement.id == 'txtVendorCode') {		
			if (document.getElementById('txtSlipNo').type == 'text')
				x.txtSlipNo.focus();
			else
				x.txtItemBarcode.focus();	
		}
		else if(document.activeElement.id == 'txtSlipNo') {		
			x.txtItemBarcode.focus();
		}
			
		return false;
	}
	else if (intKey == 35) { //End key
		SelectItemOption();
		return false;
	}
	else if (e.ctrlKey && intKey == 112) { //Ctrl + F1 key
		if ('onhelp' in window) {   // Internet Explorer
	       window.onhelp = OnHelp;
		}
		
		showlistItems(1);
		return false;
	}
	else if (e.ctrlKey && intKey == 114 && document.getElementById('btnSearchItems')) { //Ctrl + F3 key
		x.btnSearchItems.click();
		return false;
	}
	else if (e.ctrlKey && intKey == 115 && document.getElementById('btnOrderList')) { //Ctrl + F4 key
		x.btnOrderList.click();
		return false;
	}
	else if (e.ctrlKey && intKey == 117 && document.getElementById('btnClosing')) { //Ctrl + F6 key
		x.btnClosing.click();
		return false;
	}
	else if (e.ctrlKey && intKey == 119 && document.getElementById('txtVendorCode').type == 'text') { //Ctrl + F8 key
		showlistVendors(1);
		return false;
	}
	else if (e.ctrlKey && intKey == 120 && document.getElementById('btnPosting')) { //Ctrl+F9 key
		x.btnPosting.click();
		return false;
	}
	else if (e.ctrlKey && intKey == 121 && document.getElementById('btnAddSerial')) { //Ctrl+F10 key
		x.btnAddSerial.click();
		return false;
	}
	else if (e.ctrlKey && intKey == 122 && document.getElementById('btnDrawer')) { //FCtrl+11 key
		x.btnDrawer.click();
		return false;
	}
	else if (e.ctrlKey && intKey == 123) { //Ctrl+F12 key
		x.btnLogout.click();
		return false;
	}
	
	
    return true;
}

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 ClosingCashRegister() {
	x = document.retail;
	
	XPos = (screen.availHeight - 200) / 2;
	YPos = (screen.availWidth - 400) / 2;
	
	var vMainMode = x.mainaction.value;
	var vRetId    = x.txtId.value;
	
	
	win = window.open('Form_Retail_Closing.php', 'Form_Retail_Closing', 
					  'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=430,height=300,left='+YPos+',top='+XPos);
	win.creator = self;
	win.focus();

}

function ClearValues() {
	x = document.retail;
	
	x.txtItemPrice.value = '';
}


function showSubgroup(vSubGroupCode,vZone,vType){

	/*alert(vSubGroupCode);
	
	alert(vType);*/
	
	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){{ 
			document.getElementById(vZone).innerHTML=xmlhttp.responseText;
		}

		}
	}
	x.txtSubGroup.value='';
	xmlhttp.open("GET","Form_Retail_ItemDisplay.php?vZone="+vZone+"&subgroup_code="+vSubGroupCode+"&vType="+vType,true);
	xmlhttp.send();
}

function Fillitem(vItem,vSubGroup){
	x=document.retail;

	//x.txtItemBarcode.value=vItem;
	var vItemBarcode = x.txtItemBarcode.value;
	var vMinusSignExists = 0;
	if (vItemBarcode.indexOf("-") !== -1) {
		var vItemPrefix = vItemBarcode.split("-",1);
		if (vItemPrefix*1 == vItemPrefix/1 ) vMinusSignExists = 1;
	}
	
	if(vItemBarcode.indexOf("+") != -1 || vMinusSignExists == 1) { 
		x.txtItemBarcode.value = x.txtItemBarcode.value + vItem;
	} else {
		x.txtItemBarcode.value = vItem;
	}
	
	x.txtItemQty.focus();
	var CashReg_ForcingVendor=x.CashReg_ForcingVendor.value;
	SubmitRecord(CashReg_ForcingVendor,vSubGroup);
}

/*function OpenKeyboard(field){
	VirtualKeyboard.attachInput(field);
	VirtualKeyboard.open(field,'td');
}*/


	
function FillInput(PValue){
	var vField=document.retail.txtFocusField.value;
	if(vField=='txtItemPrice' && PValue != '-'){
		document.retail.txtItemPrice.value = document.retail.txtItemPrice.value + PValue;
	}
	else {
		var qty = document.retail.txtItemQty.value;
		
		if (qty.length < 6) {
			document.retail.txtItemQty.value = document.retail.txtItemQty.value + PValue;
		}
		
		document.retail.txtItemBarcode.focus();
	}
	/*else{	
		document.retail[vField].value=document.retail[vField].value+PValue;
	}*/
}

function EraseInput(PValue){
	var vField=document.retail.txtFocusField.value;
	document.retail[vField].value='';
	
	document.retail.txtItemBarcode.focus();
}

function EraseFromInput(){
	var vField=document.retail.txtFocusField.value;
	
}


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

</script>
<title>Cash Register</title>
<style type="text/css">

body,td,th {
	font-family: Arial, Times, sans-serif;
	font-size: 14px;
}
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;
}

.style16 {color: #000000; font-weight: normal; font-size: 14px; font-family: Arial, Times, sans-serif; padding:2px;}
.style17 {color: #FFFFFF; font-weight: bold; font-size: 12px; font-family: Arial, Times, sans-serif; padding:2px;}
.style18 {color: #DE9BA5; font-weight: bold; font-size: 12px; font-family: Arial, Times, sans-serif; padding:2px;}
.style19 {color: #C2DCE4; font-weight: bold; font-size: 12px; font-family: Arial, Times, sans-serif; padding:2px;}
.style20 {color: #FF0000; font-weight: bold; font-size: 13px; font-family: Arial, Times, sans-serif;}
.style21 {color: #FF0000; font-weight: bold; font-size: 14px; font-family: Arial, Times, sans-serif; padding-left:20px; background-color:#81F7D8;}
.style26 {color: #FF0000; font-weight: bold; font-size: 14px;}
.style15 {color: #000000; font-size: 11px; font-family: Arial, Times, sans-serif; padding:2px;}
.style27 {color: #999999 ;font-size: 14px; font-family: Arial, Times, sans-serif;}
.style28 {color: #FFFFFF ;font-size: 14px; font-family: Arial, Times, sans-serif;}
.style39 {color: #C2DCE4; font-weight: bold; font-size: 23px; font-family: Arial, Times, sans-serif; padding:2px;}


.list-containerfast {
	
    /*width: 90px;*/
    /*overflow-x: auto;
    overflow-y: hidden;*/
	/*white-space: nowrap;*/
	border: 0px #D8D8D8 solid;
	
	overflow-y:scroll;
	overflow-x:hidden;

	background:#ffffff;
}

.list-container {
	
    /*width: 90px;*/
    overflow-x: auto;
    overflow-y: hidden;
	/*white-space: nowrap;*/
	border: 1px #D8D8D8 solid;
	height:280px;


	background:#ffffff;
}

.list-item {
	
    width: 70px;
	margin-right:0px;
	margin-left:1px;
	margin-top:3px;
	margin-bottom:3px;
	/*display: inline-block;*/
	display: block;
    /* for ie7 */
    /**display: inline;*/
    zoom: 1;
	border:0px solid #000000;

}

h5 { border-left-style: solid; 
	 border-left-color: black; 
	 border-left-width: 1px;
	 margin-left: 10px;
   }
   


</style>

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

</head>
<body onload='LoadForm($Module_CashRegAutoItemsList);' onkeydown='return kd(event);' >
<form name='retail' method='post' action=''>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='message' value='$message' size='200'>
<input type='hidden' name='QtySerNo' value='$QtySerNo'>
<input type='hidden' name='PrRetId' value='$PrRetId'>
<input type='hidden' name='openwin' value='$openwin'>
<input type='hidden' name='passchecked' value='$passchecked'>
<input type='hidden' name='ModuleProject' value='$Module_Project'>
<input type='hidden' name='ModuleCostCenter' value='$Module_CostCenter'>
<input type='hidden' name='ModuleQtyReturn' value='$FC_CashRegisterQtyRet'>
<input type='hidden' name='string' value='$string'>
<input type='hidden' name='Module_CashRegAutoItemsList' value='$Module_CashRegAutoItemsList'>
<input type='hidden' name='CashReg_ForcingVendor' value='$CashReg_ForcingVendor'>
<input type='hidden' name='txtSubGroup' value='$txtSubGroup'>
<input type='hidden' name='txtFocusField' value='$txtFocusField'>


HERE;


//Display Led Section
$com = 0;
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" style="display:none;"></object>';
		if   ($actionmode == "" || $actionmode == "cancel" ) {
			echo "<script language='javascript'>SetPort(".$com.");SendData(String.fromCharCode(12));SendData('".'      Welcome'."');</script>";	   	
		} else {
			echo "<script language='javascript'>SetPort(".$com.");SendData(String.fromCharCode(12));SendData('".$string."');</script>";	   	
		}
	} else {
		$message = ereg_replace("'"," ",$message);

		//if (!isset($actionmode) ) {
		if ($actionmode == "" || $actionmode == "cancel" ) {
	
			$com=$CashRegister_DispCOM;
			$fp = fopen ("com".$com.":9600,n,8,1,DS", "wb+");
	
			$string=chr(12); //simulating device
			fputs ($fp, $string );           
			fclose ($fp);
			$fp = fopen ("com".$com.":9600,n,8,1,DS", "wb+");
			$string=str_pad($CashReg_DispLedMsg,$CashRegister_LedDescLength," ",STR_PAD_RIGHT); 
			$string=$string.substr($CompanyName,0,$CashRegister_LedDescLength); //simulating device	
			
			fputs ($fp, $string );          
			fclose ($fp);

		}

	}
}


//Invoke Sound For Errors
echo'<div style="display:none">';	
echo'<audio id="audiotag1" src="ringin.wav" ></audio>';
echo'<embed id="soundstrack" src="ringin.wav" autoplay="false" type="audio/mp3"></embed>';
echo'</div >';

//$message='';


	
//Initializations

$PriceLabel    = 'Price';	
$TaxableLabel  = 'Taxable';	
$DiscountLabel = 'Discount';	
if ($CashRegisterTTC == 1) { 	
	$PriceLabel    = 'Price TTC';	
	$TaxableLabel  = 'Taxable TTC';	
	$DiscountLabel = 'Discount TTC';	
}	
	

if ((empty($txtProjectCode)) && $Module_Project == 1)
	$txtProjectCode = $StpProjectCode;
if ((empty($txtCostCentCode)) && $Module_CostCenter == 1)	
	$txtCostCentCode = $StpCostCentCode;	
if (empty($txtCurr))
	$txtCurr = $StpCurrCode;
if (empty($txtDate))	
	$txtDate = displayToday();
if (empty($txtCashRegister))	
	$txtCashRegister = $CashRegister_Name;
if (empty($txtClientCode))	
	$txtClientCode = $StpClientAccount;	
//if (empty($txtItemQty))		
	//$txtItemQty=1;

	
$txtTaxable     = number_format(0,$DecimalBase);
$txtNoneTaxable = number_format(0,$DecimalBase);
$txtGrossTotal  = number_format(0,$DecimalBase);
$txtDiscount    = number_format(0,$DecimalBase);
$txtDiscountAmt = number_format(0,$DecimalBase);
$txtVat         = number_format(0,$DecimalBase);
$txtTotalTaxes  = number_format(0,$DecimalBase);
$txtNetTotal    = number_format(0,$DecimalBase);

if ($txtId != '' && $actionmode != "cancel") {

	// Read From Temp Tables For Selected Record				 
	$query = " Select Sale_ID, Sale_Reference, Date_Format(Sale_Date,'%d/%m/%Y') As Sale_Date, ".
			 " Retail.Currency_code, Retail.Client_code As ClientCode, CashRegister_Name, Sale_Remark, Retail.Project_Code, Retail.Costcenter_code,  ".
			 " Round(ifNull(Sale_Taxable,0), ".$DecimalBase."), Round(ifNull(Sale_NoneTaxable,0), ".$DecimalBase."), ".
			 " Round(ifNull(Sale_Taxable,0) + ifNull(Sale_NoneTaxable,0), ".$DecimalBase.") As GrossTotal, ".
			 " Round(ifNull(Sale_DiscountPer,0), ".$DecimalBase."), Round(ifNull(Sale_DiscountAmount,0), ".$DecimalBase."),  ".
			 " Round(ifNull(Sale_VAT,0), ".$DecimalBase.") As Sale_VAT, ".
			 " Round((ifNull(Sale_Taxable,0) + ifNull(Sale_NoneTaxable,0) + IfNull(Sale_VAT,0) - IfNull(Sale_DiscountAmount,0) + (ifNull(Sale_Tax1,0) + ifNull(Sale_Tax2,0) + ifNull(Sale_Tax3,0) + ifNull(Sale_Tax4,0) + ifNull(Sale_Tax5,0))), ".$DecimalBase.") As Sale_NetTotal,  ".
			 " Round((ifNull(Sale_Tax1,0) + ifNull(Sale_Tax2,0) + ifNull(Sale_Tax3,0) + ifNull(Sale_Tax4,0) + ifNull(Sale_Tax5,0)), ".$DecimalBase.") As TotalTaxes,  ".
			 " Round(ifNull(Sale_NetTotal,0), ".$DecimalBase."),  ".
			 " Round(ifNull(Sale_NetTotalBase1,0) - (ifNull(Coupon_AmountBase1,0) + ifNull(Sales_CreditAmountBase1,0) + ifNull(Sale_CashBase1,0) + ifNull(Sales_CashInBase1,0) + ".
			 "       ifNull(convertcurfunc('".$base2."', '".$base1."', Sale_Date, 0, 0, '', '', ifNull(Sales_CashInBase2,0)),0)) + ifNull(Sales_CashOutBase1,0) + ".
			 "       ifNull(convertcurfunc('".$base2."', '".$base1."', Sale_Date, 0, 0, '', '', ifNull(Sales_CashOutBase2,0)),0)) As BalanceAmount,  ".
			 " Round((ifNull(Sale_Taxable,0)*(1+$Setup_VatPercentage/100)), ".$DecimalBase.") As SaleTaxableTTC, ".
			 " Round((ifNull(Sale_Taxable,0)*(1+$Setup_VatPercentage/100)) + ifNull(Sale_NoneTaxable,0), ".$DecimalBase.") As GrossTotalTTC, ".
			 " Round((((ifNull(Sale_Taxable,0)*(1+$Setup_VatPercentage/100)) + ifNull(Sale_NoneTaxable,0))*(ifNull(Sale_DiscountPer,0)/100)), ".$DecimalBase.") As SaleDiscountTTC, ".
			 " Retail.SaleOrder_Id, Retail.SaleOrder_Reference,Retail.Projectdt_id Projectdt_id ".
			 " From Temp_Retail As Retail ".
	         " Where Sale_ID = ".$txtId;
			 //" And Logged_Code = '".$HTTP_SESSION_VARS['useraccount']."' ";
			 
			 
			 
	//echo $query;
	$result=mysql_query($query,$connection) or die(mysql_error());
    $rows=mysql_fetch_array($result);
	
	$txtId    = $rows[0];
	$txtRef   = $rows[1];
	$txtDate  = $rows[2];
	$txtCurr  = $rows[3];
	$txtClientCode   = $rows[4];
	$txtCashRegister = $rows[5];
	$txtRemark       = $rows[6];
	$txtProjectCode  = $rows[7];
	$txtCostCentCode = $rows[8];
	
	if ($CashRegisterTTC == 1) {
		$txtTaxable     = number_format($rows[19],$DecimalBase);
		$txtGrossTotal  = number_format($rows[20],$DecimalBase);
		$txtDiscountAmt = number_format($rows[21],$DecimalBase);
	} else {
		$txtTaxable     = number_format($rows[9],$DecimalBase);
		$txtGrossTotal  = number_format($rows[11],$DecimalBase);
		$txtDiscountAmt = number_format($rows[13],$DecimalBase);
	}
	
	$txtNoneTaxable = number_format($rows[10],$DecimalBase);
	$txtDiscount    = number_format($rows[12],$DecimalBase);
	$txtVat         = number_format($rows[14],$DecimalBase);
	$txtTotalTaxes  = number_format($rows[16],$DecimalBase);
	$txtNetTotal    = number_format($rows[17],$DecimalBase);
	$NetTotalDisplay = RoundTotal($rows[17], $CashReg_RoundDivisor, $connection);
	
	$txtBalanceAmount = $rows[18];
	$txtOrderId       = $rows[22];
	$txtOrderRef      = $rows[23];
	$txtProjectDtId      = $rows[24];
	
	$query = " Select Count(*) FROM Temp_RetailDt ".
			 " WHERE Sale_id = ".$txtId;
	$result = selectData($connection, $query);
	$txtCountDetail = $result[0];
	if($txtCountDetail == '') $txtCountDetail = 0;
	
	
	if ($Module_PriceOffer > 0) {
		$sub_query = " Select Sum(ifNull(SaleDt_Quantity,0)* ifNull(RetailDt.SaleDt_ActualPrice, 0)) As TotalAmountActual ".
					 " From Temp_RetailDt As RetailDt ".
					 " Where RetailDt.Sale_ID = '".$txtId."' ";
					 //" And ifNull(Price_Offer,0) = 1 ";
		$sub_result = selectData($connection, $sub_query);
		$txtTotalAmountActual = number_format($sub_result[0],$DecimalBase);
	
	}
	
}



//Search/Cancel Mode	
if ($actionmode == "cancel" && $txtId != '') {
	
	// Delete From Temp Tables Already Filled By Search
	$query = " DELETE FROM Temp_Purchasesserialno ".
			 " WHERE RetailDt_ID In (Select SaleDt_id From Temp_RetailDt Where Sale_id = ".$txtId." ) ".
			 " AND Journal_Type In ('DI','DR') ";
			 //" AND Logged_Code = '".$HTTP_SESSION_VARS['useraccount']."' ";
	if (!updateData($connection, $query, true))		 
      $message  = mysql_error(); 

	  
	
	$query = " DELETE FROM Temp_RetailDt ".
			 " WHERE Sale_id = ".$txtId;
			 //" AND Logged_Code = '".$HTTP_SESSION_VARS['useraccount']."' ";
	if (!updateData($connection, $query, true))
      $message  = mysql_error(); 
	  
	
	  
	$query = " DELETE FROM Temp_Retail ".
			 " WHERE Sale_id = ".$txtId;
			 //" AND Logged_Code = '".$HTTP_SESSION_VARS['useraccount']."' ";
	if (!updateData($connection, $query, true))
      $message  = mysql_error();   

	$txtId = '';
}





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

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";

echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'><input type='hidden' name='txtProjectDtId' value='$txtProjectDtId'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:140px; height:26px;'><span class='title'>CASH REGISTER</span></td><td width='180px'><b> $txtCashRegister / $UserAccount
				<td  valign='bottom' style='width:750px;height:26px;'>"; 
				echo'<B>Enter: </b>Submit &nbsp; / <B>Tab: </B>Barcode&Qty &nbsp;/ <B>End:</B>Barcode/SerialNo &nbsp;/ <B>Ctrl + F1: </B> Items List &nbsp; / <B>Ctrl + F8: </B> Vendors List</td>';
				echo'<tD><ul id="menu"> <li ><a href="#" class="drop">MENU</a>
    
			<div class="dropdown_5columns"><!-- Begin 5 columns container -->
			';
	echo"<table border='0'><tr height='25px'>";
$j=0;
if($FC_CashRegisterCustomer==1){
		echo"<td><input type='button' id='btnCustomer' name='btnCustomer' class='mainbuttons' onclick='OpenCustomer(); return false;'  title='Customer' value='   Customer   '><span><span></span></span></button>";				 
		echo"</td>";
	$j+=1;	
	}	

if($j==1) {
			echo"</tr><tr>";
			$j=0;
			}
	
if ($FC_CashRegisterClosing == 1) {
	echo"  <td > <input type='button' name='btnClosing' class='mainbuttons' id='btnClosing'  onclick='ClosingCashRegister();'  title='Closing CashRegister' ";
            if (($actionmode!='' && $actionmode!='cancel') || $txtId!='') 
			    echo " disabled ";
	        echo " value='Ctrl+F6-Closing'/><span><span></span></span></button></td>";					
			$j+=1;
}
		if($j==1) {
			echo"</tr><tr>";
			$j=0;
			}
			
if ($Module_RestaurantDelivery == 1) {
	echo"   <td ><input type='button' name='btnOrderList' type='button' id='btnOrderList'  onclick='SearchOrders();' title='Order List' ";
            if (($actionmode!='' && $actionmode!='cancel') || $txtId!='') 
			    echo " disabled ";
	        echo " value='Ctrl+F4-Order List' class='mainbuttons'/><span><span></span></span></button></td>";	
	$j+=1;			
}			

		if($j==1){
			echo"</tr><tr>";
			$j=0;
			}

if ($FC_ShowBtnOpenDrawer == 1) {
	echo"<td > <input type='button' id='btnDrawer' name='btnDrawer' onclick='OpenDrawer(); return false;'  class='mainbuttons' title='Open Drawer' value='Ctrl+F11-Drawer'></button></td>";
	$j+=1;	
	}

		if($j==1){
			echo"</tr><tr>";
			$j=0;
			}
			
echo" <td ><input type='button' id='btnSearchItems' name='btnSearchItems' onclick='SearchItems(); return false;' title='Search Sold Items'  value='Ctrl+F3-Sold Items' class='mainbuttons'></button></td>";
		$j+=1;	

		if($j==1){
			echo"</tr><tr>";	
			$j=0;
			}

if ($Module_SerialNo == 1){
	echo"<td>&nbsp;<input type='button' id='btnAddSerial' name='btnAddSerial' onclick=\"AddSerials();return false;\" class='mainbuttons' value='Ctrl+F10-Add Serial' $InsMod title='Add Serials'></button></td>";
	$j+=1;	
	}
 
		if($j==1){
			echo"</tr><tr>";
			$j=0;
			}

echo"<td><input type='button' id='btnAddItem' name='btnAddItem' onclick=\"AddItems();return false;\" class='mainbuttons' value='F1-Add Item' $InsMod title='Add Item'></button></td>";
$j+=1;	

		if($j==1){
			echo"</tr><tr>";
			$j=0;
			}

echo" <td><input type='button' id='btnPosting' class='mainbuttons' name='btnPosting' onclick='PostRetails(); return false;' $PostingMode title='Posting' value='Ctrl+F9-Posting'><span><span></span></span></button></td>";
	$j+=1;	

		if($j==1){
			echo"</tr><tr>";
			$j=0;
			}
			
if ($Module_CashRegisterFastItem == 1) {
		echo"<td><div class='list-item' style='border:0px black solid;float:left;'>
		<input type='button' name='btnNew' id='btnNew' value='New Fast Item  '  onclick=\"CreateFastItem();\" title='Add Fast Item' class='mainbuttons'/></div></td>";
		$j+=1;	
}
		if($j==1){
			echo"</tr><tr>";
			$j=0;
			}
			
echo" <td><input type='button' id='btnReservation' name='btnReservation' onclick='openreservation()(); return false;' title='Reservation' value='       Reservation      ' class='mainbuttons' ";
 if (($actionmode!='' && $actionmode!='cancel') || $txtId!='')
			    echo " disabled ";
echo"></td>";
	$j+=1;	
	if($j==1){
			echo"</tr><tr>";
			$j=0;
			}

echo" <td><input type='button' id='btnLogout' name='btnLogout' onclick='LogOut(); return false;' title='Logout' value='Ctrl+F12-Logout     ' class='mainbuttons' ";
 //if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit')
 if (($actionmode!='' && $actionmode!='cancel') || $txtId!='')
			    echo " disabled ";
echo"></td>";
	$j+=1;	

if($j==1){
			echo"</tr><tr>";
			$j=0;
			}
			
echo'</tr></table></div></li></a></ul>';
	echo'</td>';
	echo"</tr></table></td></tr>";
	  
echo"<tr>
		<td    valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0'    >
			<col width=40px>
			<col width=150px>
			<col width=70px>
			<col width=250px>
			<col width=220px>
			<col width=140px>";
	
							
echo"<tr height='20px'><td height='34px'>&nbsp;</td>
		<td align='left' valign='center' ><span class='style1'>Date&nbsp;<span class='style26'>*</span></span>";
         echo"<span class='style16' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $txtDate</span><input type='hidden' size='10' name='txtDate' value='$txtDate' maxlength='10' > 
		</td>
		<td ><span class='style1'>Reference</span></td><td align='left'>
		  <span class='style16'>$txtRef</span>";
		  
		 // if($tablename)
		  
		  if($txtProjectDtId!='' && $Module_CashRegisterTable==1) {
		  
				$subquery = "select projectdt_name from projectdt where projectdt_id = $txtProjectDtId";
				$resultsub=mysql_query($subquery,$connection);
				$rowsub=mysql_fetch_row($resultsub);
		  
			echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='style1'>Table</span>
			<span class='style16'>$rowsub[0]</span>";
			
			
			}
		  
		  echo"</td>";
		  
echo"<td  valign='top'>";

	
if($Module_CashRegisterStandardView==1 && $Module_CashRegisterFastItem==1){
	$height='190px';
}
else if($Module_CashRegisterStandardView==0 && $Module_CashRegisterFastItem==1){
	$height='270px'; 
}
else if($Module_CashRegisterStandardView==0 && $Module_CashRegisterFastItem==0){
	$height='410px'; 
}


$Parameters = array();
$Parameters['Module_PriceOffer'] = $Module_PriceOffer;
$Parameters['CashRegister_PrintBarcode'] = $CashRegister_PrintBarcode;
$Parameters['Module_SerialNo'] = $Module_SerialNo;
$Parameters['DecimalBase'] = $DecimalBase;
$Parameters['CashRegisterTTC'] = $CashRegisterTTC;
$Parameters['CashReg_Weight'] = $CashReg_Weight;
$Parameters['Module_RestaurantDelivery'] = $Module_RestaurantDelivery;

$Parameters['FC_CashRegisterMod'] = $FC_CashRegisterMod;
$Parameters['FC_CashRegisterDelItem'] = $FC_CashRegisterDelItem;
$Parameters['DecimalBase1'] = $DecimalBase1;
$Parameters['Module_AdditionalTaxes'] = $Module_AdditionalTaxes;
$Parameters['PriceLabel'] = $PriceLabel;
$Parameters['TaxableLabel'] = $TaxableLabel;
$Parameters['DiscountLabel'] = $DiscountLabel;
$Parameters['base1'] = $base1;
$Parameters['base2'] = $base2;
$Parameters['Setup_VatPercentage'] = $Setup_VatPercentage;
$Parameters['ShowSlipNumber'] = $ShowSlipNumber;
$Parameters['txtCurr'] = $txtCurr;
$Parameters['txtOrderId'] = $txtOrderId;
$Parameters['Unmodify_SellingPrice'] = $Unmodify_SellingPrice;
$Parameters['passchecked'] = $passchecked;
$Parameters['height'] = $height;
$Parameters['CashReg_Vendor'] = $CashReg_Vendor;
$Parameters['CashReg_RoundDivisor'] = $CashReg_RoundDivisor;
$Parameters['FC_DiscountPerLimit'] = $FC_DiscountPerLimit;
$Parameters['CashReg_ForcingVendor'] = $CashReg_ForcingVendor;
$Parameters['txtTotalAmountActual'] = $txtTotalAmountActual;
$Parameters['Module_CashRegisterTable'] = $Module_CashRegisterTable;


$_SESSION['gret_parameters']  = $Parameters;

			
echo"	<div id='totals' style='width:200px; margin-top:3px; float:center; position:absolute;' >";
			ShowRetailTotals($connection,$_SESSION['gret_parameters'],$txtId);		
		echo"	</div></td>";


		




echo"<td valign='top'  align='left' rowspan=3>
<table cellspacing=1 cellpadding=1 border='0' style='padding-top:5px;'>

<tr>
	<td><input type='button' value='' class='calculatorbutton'  onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' value='0' class='calculatorbutton' onclick='FillInput(0);' id='button0' onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' value='1' class='calculatorbutton' onclick='FillInput(1);' id='button1' onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' value='2' class='calculatorbutton' onclick='FillInput(2);' id='button2' onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' value='3' class='calculatorbutton' onclick='FillInput(3);' id='button3' onkeydown='return Barcodekd(event);'></td>
</tr>


<tr>
	<td><input type='button' value='' class='calculatorbutton'  onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' id='btnSubmit' class='calculatorbutton'  name='btnSubmit' value='Enter' onclick=SubmitRecord($CashReg_ForcingVendor,'$txtSubGroup'); return false; title='Submit Record' ></td>
	<td><input type='button' value='4' class='calculatorbutton' onclick='FillInput(4);' id='button4' onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' value='5' class='calculatorbutton' onclick='FillInput(5);' id='button5' onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' value='6' class='calculatorbutton' onclick='FillInput(6);' id='button6' onkeydown='return Barcodekd(event);'></td>
</tr>

<tr>
	<td><input type='button' value='Sub' class='calculatorbutton' onclick=FillInput('-'); id='buttonminus' onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' value='Clr' class='calculatorbutton' onclick='EraseInput();' id='buttonerase' onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' value='7' class='calculatorbutton' onclick='FillInput(7);' id='button7' onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' value='8' class='calculatorbutton' onclick='FillInput(8);' id='button8' onkeydown='return Barcodekd(event);'></td>
	<td><input type='button' value='9' class='calculatorbutton' onclick='FillInput(9);' id='button9' onkeydown='return Barcodekd(event);'></td>
</tr>";
//echo"<tr><td><input type='button' value='<=' class='calculatorbutton' onclick='EraseFromInput();'></td></tr>";

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



echo"<td rowspan='2' valign='top'><table border='0' cellspacing=3><tr><td>";

if ($FC_CashRegisterSearch == 1) {
	echo"   <input type='button' name='btnSearch' type='button' id='btnSearch' class='searchbutton' title='F7-Search'  onclick='SearchForRef();return false;'  title='Search By Reference'  ";
          //  if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit') 
            if (($actionmode!='' && $actionmode!='cancel') || $txtId!='') {
			    echo " disabled ";
				echo " style='cursor:default;'";
			}	
			else echo " style='cursor:pointer;'";
	        echo " /></button>";		 
}			
				
echo"       <input type='button' name='btnPending' type='button' id='btnPending' title='F8-On Hold' class='pendingsearchbutton' title='Pending Invoices' ";
           // if (($actionmode!='' && $actionmode!='cancel') || $mainaction=='edit')
            if (($actionmode!='' && $actionmode!='cancel') || $txtId!=''){
			    echo " disabled ";
				echo " style='cursor:default;'";
			}	
			else echo " style='cursor:pointer;'";
	         echo " onclick='SearchForPending();return false;'/></button></td></tr>";		

if($txtId!='')
	$butname = 'Hold';
else	
	$butname = 'Clear';

if($txtId!='')	
echo"<tr><td><input type='button' id='btnClear' name='btnClear' onclick=\"ClearPage($FC_ShowBtnCancel,'$butname');return false;\" class='clearbutton'  title='F4-$butname' $InsMod title='$butname Page'></button>";
else
echo"<tr><td><input type='button' id='btnClear' name='btnClear' onclick=\"ClearPage($FC_ShowBtnCancel,'$butname');return false;\" class='clearbutton1'  title='F4-$butname' $InsMod title='$butname Page'></button>";

	
echo"       <input type='button' name='btnCancel' id='btnCancel'  ";//cancel
			//if ($actionmode=='cancel' || ($actionmode=='' && $mainaction!='edit'))
			if ($actionmode=='cancel' || ($actionmode=='' && $txtId=='')){
				
			    echo " disabled ";
				echo " style='cursor:default;'";
			}	
			else echo " style='cursor:pointer;'";
			echo" onclick='CancelRecord($FC_ShowBtnCancel);return false;' class='cancelbutton' title='F6 -Cancel Changes'></button></td></tr>";	echo$DiscountMode;

echo"<tr><td><input type='button' id='btnCash' name='btnCash'  onclick='PayCash(".$config['PhpPort'].",".$com.",".$CashRegister_Printer."); return false;' $PaymentMode  title='F2-Cash '  class='cashbutton'><span><span></span></span></button>

<input type='button' id='btnDiscount' name='btnDiscount' class='discountbutton' onclick='AddDiscount(); return false;' $DiscountMode title='F3-Discount' ";
if($DiscountMode==' disabled ') echo " style='cursor:default;'"; else  echo " style='cursor:pointer;'";

echo"><span><span></span></span></button>";

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


echo"</tr>";

if ($CashRegisterSerialNo == 0) $ItemOptionLabel = 'Barcode';
else $ItemOptionLabel = 'SerialNo';

$sub_query  = " Select ifNull(Item_ModifySellingPrice,0) From Items ".
			  " Where Item_Code = '".$txtItemBarcode."' or  Item_Barcode = '".$txtItemBarcode."' or ".
			  " Item_Barcode2 = '".$txtItemBarcode."' or Item_Barcode3 = '".$txtItemBarcode."'";
$sub_result = selectData($connection, $sub_query);

$ItemModifySellingPrice = $sub_result[0];
	
// User Has No Access To Modify The Price	
$ModeModifySellPrice = '';
if ($Unmodify_SellingPrice == 1 || ($ItemModifySellingPrice == 0 && $txtItemBarcode != ''))	
	$ModeModifySellPrice = ' readonly ';


	 
echo" <tr>
		  <td align='left' id='content-body' colspan='7' valign='top'><table border='0' align='left' style='margin-left:40px;cellpadding:0;width:1170px;' >
		  <col width=65><col width=210><col width=60><col width=60>";
		
echo"<tr height='10px'><td>&nbsp;</td><td colspan=3>";
if ($CashRegisterBarCode == 1 || $txtItemOption == 1 || ($CashRegisterBarCode == 0 && $CashRegisterSerialNo == 0) || $Module_SerialNo == 0)
	echo "<input name='txtItemOption' id='txtItemOption' type='radio' value='1' checked /><span class='style1'> Code/Barcode</span>";
else 
	echo "<input name='txtItemOption' id='txtItemOption' type='radio' value='1' /><span class='style1'> Code/Barcode</span>";

if ($Module_SerialNo == 1) {	
	if ($CashRegisterSerialNo == 1 || $txtItemOption == 2)	
		echo "<input name='txtItemOption' id='txtItemOption' type='radio' value='2' checked /><span class='style1'> Serial No.</span>";
	else 
		echo "<input name='txtItemOption' id='txtItemOption' type='radio' value='2' /><span class='style1'> Serial No.</span>";
}	
echo "	</td></tr>";
		
		 echo" <tr height=30px><td ><span class='style1'><input type='text' name='ItemOptionLabel' id='ItemOptionLabel' value='$ItemOptionLabel'  maxlength='20' style='color: #000000; font-weight: bold; font-size: 12px; font-family: Arial, Times, sans-serif; width:50px; height:22px; border:0px;background-color:#ffffff' readonly ><span class='style26'>*</span></span></td>
          <td><input type='text' name='txtItemBarcode' id='txtItemBarcode' value='".htmlentities($txtItemBarcode)."'  maxlength='40' style='font-size:13px; width:200px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
	-webkit-border-radius: 0px 5px 5px 5px;
	border-radius: 5px 5px 5px 5px;'  onkeydown='return Barcodekd(event);' onchange='ClearValues();' onfocus=FillHidden('txtItemBarcode');></td>
	<td><span class='style1'></span></td><td>&nbsp;</td><td>&nbsp;</td></tr>";

		


echo"<tr >
	<td ><span class='style1'>Price</span></td><td  >
			<input type='text' name='txtItemPrice' id='txtItemPrice' value='$txtItemPrice'  maxlength='20' style='font-size:13px; width:120px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 5px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' onkeydown='return Barcodekd(event);' $ModeModifySellPrice onfocus=FillHidden('txtItemPrice');>
			<span class='style1'>Qty</span>
			<input type='text' name='txtItemQty' id='txtItemQty' value='$txtItemQty'  maxlength='6' style='font-size:13px; width:50px; height:22px;
			-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 0px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' 
	onkeydown='return Barcodekd(event);' onfocus=FillHidden('txtItemQty');></td>";
	
	/*<td>
			<button type='button' id='btnQtySign' name='btnQtySign' onclick='SelectItemQty(); return false;' ><span><span>+/-</span></span></button>
			</td>";	*/


		echo"</tr>";


echo "<tr >";

if ($CashReg_Vendor == 1){
    echo "<td align='left' valign='center' ><span class='style1'>Vendor</span></td>
	      <td ><input type='text' value='$txtVendorCode'  name='txtVendorCode' id='txtVendorCode' maxlength='10' 
		  style='font-size:13px; width:120px; height:22px;-moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 0px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;' >
				<label><span class='style1'><img src='img/openlist.png' title=' Select Vendor '  width='18' height='19' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistVendors(1); ' /></span></label></td></tr>";
} else {
	echo "<td align='left'  ><input type='hidden' name='txtVendorCode' id='txtVendorCode' value='' >&nbsp;";
}

if ($ShowSlipNumber == 1){
    echo "<tr><td><span class='style1'>Slip No.</span></td><td>
	     <input type='text' value='$txtSlipNo'  name='txtSlipNo' id='txtSlipNo' maxlength='20' style='font-size:13px; width:120px; height:22px;
		 -moz-border-radius: 0px 5px 5px 5px;
			-webkit-border-radius: 0px 5px 5px 5px;
			border-radius: 5px 5px 5px 5px;'></td>";
} else {
	echo "<td align='left' ><input type='hidden' name='txtSlipNo' id='txtSlipNo' value='' >&nbsp;</td>";
}			
			
			
echo"</tr></table></td></tr>";

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



/*
echo"<tr><td id='content-body' align='left'>";

//if ($Module_CashRegisterFastItem == 1) {
	echo"<table border='0'  align='left' valign='top'  width='1170px' style='table-layout:fixed'>
	<col width=22>";
//}
/*else {
	echo"<table border='0'  align='center' valign='top' width='100%' class='tablecontent' style='table-layout:fixed'>";
}*/

//echo"<tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";				
			
				
//echo"	<table border='0' style='table-layout:fixed' align='left' cellpadding='0' cellspacing='0'>";

//if ($message != '')
//	echo "<tr><td colspan='2' height='20' align='center'><font size='2' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>";

//echo"</table></td></tr>";
		
/*echo"	<tr  height='20px'><td id='content-body' align='left'><table border='0'  align='left' valign='top'  width='1100px' style='table-layout:fixed' cellspacing=0 cellpadding=0>
<col width=30>
<col width=60>
<col width=180>
<col width=210>
<col width=40>
<col width=100>
<col width=50>
<col width=140>
<col width=50>
<col width=90>
<col width=210>
";*/



         // <td valign='center' align='left' ><span class='style1'>CashRegister</span></td>
		 // <td valign='center'><span class='style16' >&nbsp;$txtCashRegister</span>
		   echo"   <input type='hidden' name='txtOrderId' value='$txtOrderId' size='10'>
			  <input type='hidden' name='txtOrderRef' value='$txtOrderRef' size='10'>
			  <input type='hidden' name='txtId' value='$txtId' size='10'>
			  <input type='hidden' name='txtRef' value='$txtRef' size='10' >
			  <input type='hidden' name='txtCashRegister' value='$txtCashRegister' >
			  <input type='hidden' name='txtCurr' value='$txtCurr' >
			  <input type='hidden' name='txtClientCode' value='$txtClientCode' >
			  <input type='hidden' name='txtProjectCode' id='txtProjectCode' value='$txtProjectCode' />
			  <input type='hidden' name='txtCostCentCode' id='txtCostCentCode' value='$txtCostCentCode' />
			  <input type='hidden' name='txtBalanceAmount' value='$txtBalanceAmount' >";
		  //</td>	  
       






/*
echo"   <tr bgcolor='#F7F7F7'  height='20px'><td>&nbsp;</td>";
echo"</tr>";*/

$PaymentMode  = ' ';
$DiscountMode = '';
$PostingMode  = ' ';

if ($FC_CashRegisterPosting == 0 || $CashRegister_AutoPost == 1 || ($FC_CashRegisterPosting == 1 && $txtId != '')) 
	$PostingMode = ' disabled ';
	
if ($txtId == '') 
	$PaymentMode = ' disabled ';	

if ($CashRegisterDiscount == 0 || ($CashRegisterDiscount == 1 && $txtId == ''))
	$DiscountMode = ' disabled ';


//echo"   <tr bgcolor='#D8D8D8' height='10px'><td colspan='7' align='center' style='padding-top:3px; padding-bottom:3px;'>";
//echo"   </td></tr>";	
//echo"   <tr  ><td colspan='7' align='center' style='padding-top:3px; padding-bottom:3px;'>";
//echo"   </td></tr>";

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


echo"   <tr><td valign='top' align='left' id='content-body' colspan='2'><table border='0'  cellspacing=0 cellpadding=0 valign='top' align='left'>
		
		<tr><td width=30px>&nbsp;</td><td valign='top' align='left'>";
		
		if($Module_CashRegisterTable==1)
			echo"<div style='height:$height;margin-top:3px; float:left;width:720px;' id='datagrid' >";
		else
			echo"<div style='height:$height;margin-top:3px; float:left;width:1140px;' id='datagrid' >";
			
		ShowRetailDtGrid($connection,$_SESSION['gret_parameters'],$txtId);		
		echo "</div></td>";
		
		
		if($Module_CashRegisterTable==1)
		{ 
			echo"<td valign=top align=left>";
			echo"<div style='height:200;margin-top:3px;width:417px;overflow-y:scroll' id='datagridtable' >";
			ShowTableGrid($connection,$_SESSION['gret_parameters'],$txtId);
			echo"</div></td>";
		}
		//$height=$height+20;


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

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

	echo"<table border='0'  align='left' valign='top'  width='1170px' style='table-layout:fixed' >
	<col width=22>
	<col width=725>";

	echo"<tr height='5px'><Td></td><td colspan=2 >&nbsp;</td></tr>";
	echo"<tr ><td >&nbsp;</td>";

if($Module_CashRegisterStandardView==1){
	echo"	<td valign='top' ><div id='subgrouparea' style='overflow-y:scroll;overflow-x:hidden;width:720px;height:220px;border:0px solid #000000;'><table border='0' style='table-layout:fixed;' cellspacing=0 cellpadding=0>";
	
	
	//Get subgroup codes
	if($txtSubGroup!=''){
		$subquery="Select parent_code from subgroup where subgroup_code='".$txtSubGroup."'";
		$resultsub=mysql_query($subquery,$connection);
		$row=mysql_fetch_row($resultsub);
		$parent_code=$row[0];
				
		/*if($parent_code!='')	
			$querysubgroup=$querysubgroup. " select subgroup_code from subgroup where parent_code='".$parent_code."'" ;
		else{ $querysubgroup="select subgroup_code from subgroup where upper(subgroup_type)=upper('cashreg') and (parent_code is null or parent_code='') ";	
			$vSkipActionButtons=1;
		}	*/
		
		$query="select item_code,substr(item_description,1,20) from items where subgroup_code='".$txtSubGroup."'";
		$result=mysql_query($query,$connection);
		
		if($vSkipActionButtons!='1'){
			echo"<tr height='50px'><td width='60px'><input type='button' id='BackButton' onclick=\"showSubgroup('$subgroup_codeParent','subgrouparea','back');return false;\" class='subgroupbuttons' style='background-color:#E8D90D;' value='Back'><span><span></span></span></button></td>
			<td ><input type='button' id='RootButton' onclick=\"showSubgroup('$subgroup_codeParent','subgrouparea','root');return false;\" class='subgroupbuttons' style='background-color:#E8D90D;' value='Root'><span><span></span></span></button></td>"; 
		}
		
		$j=2;
		while($row=mysql_fetch_row($result)){
			
			if($j%10==0)
			echo"</tr><tr>";

			
			echo "<td width='60px'><input type='button' id='btnSub' name='btnSub' onclick=\"Fillitem('$row[0]','$txtSubGroup');return false;\" class='itembuttons' value='$row[1]'><span><span></span></span></button></td>";
			$j=$j+1;
		}
	}	
		
	else {
		$querysubgroup="select subgroup_code from subgroup where upper(subgroup_type)=upper('cashreg') and (parent_code is null or parent_code='') ";
		$vSkipActionButtons=1;
	}

	$result=mysql_query($querysubgroup,$connection);
	$i=0;
	echo"<tr  >";
	while($row=mysql_fetch_row($result)){

		$subquery="select subgroup_code from subgroup where parent_code='".$row[0]."'";
		$resultsub=mysql_query($subquery,$connection);
		$numrow=mysql_num_rows($resultsub);
		
		
		if($numrow>0) $vZone='subgrouparea';
		else $vZone='subgrouparea';
		
	if($i%10==0)
		echo"</tr><tr>";

		echo "<td width='60px'><input type='button' id='btnSub' name='btnSub' onclick=\"showSubgroup('$row[0]','$vZone','main');return false;\" class='subgroupbuttons' value='$row[0]'></button></td>";
		$i=$i+1;
		
		if($vSkipActionButtons!='1'){
			echo"<tr><td width='60px'><input type='button' id='BackButton' onclick=\"showSubgroup('$subgroup_codeParent','subgrouparea','back');return false;\" class='subgroupbuttons' style='background-color:#E8D90D;' value='Back'><span><span></span></span></button></td>
				<td><input type='button' id='RootButton' onclick=\"showSubgroup('$subgroup_codeParent','subgrouparea','root');return false;\" class='subgroupbuttons' style='background-color:#E8D90D;' value='Root'><span><span></span></span></button></td></tr>"; 
		}
	}
		echo"</tr></table></div></td>";	
}

if ($Module_CashRegisterFastItem == 1) {

	if($Module_CashRegisterStandardView==0 ) {$heightfast='150px';$widthfast='1140px';}
	if($Module_CashRegisterStandardView==1 ) $heightfast='220px';

	echo" <td valign='top'  align='left'><div class='list-containerfast' style='height:$heightfast;width:$widthfast;border:0px solid #000000;'><table border='0' cellspacing=0 cellpadding=0 >";
	echo"<tr>";
		
		//<td valign='top' width='60px'> 	 <div class='list-item' style='border:0px black solid;float:left;'><input type='button' name='btnNew' id='btnNew' value='New' class='newfastbuttons' onclick=\"CreateFastItem();\" title='Add Fast Item' /></div></td>";

		$query_buttons = " Select ItemButton_Value, substr(ItemButton_Label,1,20) as ItemButton_Label, ItemButton_Order ".
					 " From ItemButtons ".
					 " Order By ItemButton_Order Desc ";
					
		 $i=0;
		$result_buttons=mysql_query($query_buttons,$connection) or die(mysql_error());
		while($rows_buttons=mysql_fetch_array($result_buttons)){
			extract($rows_buttons);
		
		$ButtonName  = "Btn_".$ItemButton_Order;
		$ButtonLabel = $ItemButton_Label;
		$ButtonValue = $ItemButton_Value;
		
		$sub_query = "SELECT Client_SellingPrice FROM Clients WHERE Ledger_Number = '".$txtClientCode."'";
		//echo $sub_query;
		$sub_result = selectData($connection, $sub_query);
		$c_sp = $sub_result[0];
			
		$sub_query = " Select Currency_Code, ".
					 " ifNull(Item_SellingPrice1,0), ifNull(Item_SellingPrice1Base1,0), ifNull(Item_SellingPrice1Base2,0), ifNull(Item_SellingPrice2,0), ifNull(Item_SellingPrice2Base1,0), ifNull(Item_SellingPrice2Base2,0), ".
					 " ifNull(Item_SellingPrice3,0), ifNull(Item_SellingPrice3Base1,0), ifNull(Item_SellingPrice3Base2,0), ifNull(Item_SellingPrice4,0), ifNull(Item_SellingPrice4Base1,0), ifNull(Item_SellingPrice4Base2,0), ".
					 " ifNull(Item_SellingPrice5,0), ifNull(Item_SellingPrice5Base1,0), ifNull(Item_SellingPrice5Base2,0), ifNull(Item_SellingPrice6,0), ifNull(Item_SellingPrice6Base1,0), ifNull(Item_SellingPrice6Base2,0), ".
					 " ifNull(Item_ModifySellingPrice,0) ".
					 " From Items Where Item_Code = '".$ItemButton_Value."'";
		//echo $sub_query; exit;
		$sub_result = selectData($connection, $sub_query);
		$ItemCurr   = $sub_result[0];	
		$ItemModifySellingPrice = $sub_result[19];
		
		if (empty($ItemCurr)) $ItemCurr = $txtCurr;
			
			if ($txtCurr != $ItemCurr) {
				if ($txtCurr == $base1) { 
					$Item_SellingPrice1 = $sub_result[2];
					$Item_SellingPrice2 = $sub_result[5];
					$Item_SellingPrice3 = $sub_result[8];
					$Item_SellingPrice4 = $sub_result[11];
					$Item_SellingPrice5 = $sub_result[14];
					$Item_SellingPrice6 = $sub_result[17];
				}
				else if ($txtCurr == $base2) {
					$Item_SellingPrice1 = $sub_result[3];
					$Item_SellingPrice2 = $sub_result[6];
					$Item_SellingPrice3 = $sub_result[9];
					$Item_SellingPrice4 = $sub_result[12];
					$Item_SellingPrice5 = $sub_result[15];
					$Item_SellingPrice6 = $sub_result[18];
				}
				else {
					$Item_SellingPrice1 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[1], $connection);
					$Item_SellingPrice2 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[4], $connection);
					$Item_SellingPrice3 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[7], $connection);
					$Item_SellingPrice4 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[10], $connection);
					$Item_SellingPrice5 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[13], $connection);
					$Item_SellingPrice6 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[16], $connection);
					
				}
				
			} else {
				$Item_SellingPrice1 = $sub_result[1];
				$Item_SellingPrice2 = $sub_result[4];
				$Item_SellingPrice3 = $sub_result[7];
				$Item_SellingPrice4 = $sub_result[10];
				$Item_SellingPrice5 = $sub_result[13];
				$Item_SellingPrice6 = $sub_result[16];
			}
			
			
			switch ($c_sp){
				case "I":
					$ItemSellPrice = $Item_SellingPrice1; break;
				case "II":
					$ItemSellPrice = $Item_SellingPrice2; break;
				case "III":
					$ItemSellPrice = $Item_SellingPrice3; break;
				case "IV":
					$ItemSellPrice = $Item_SellingPrice4; break;
				case "V":
					$ItemSellPrice = $Item_SellingPrice5; break;
				case "VI":
					$ItemSellPrice = $Item_SellingPrice6; break;
			}
			
		/*if($i%2==0)
			$float='float:left';
		else {
			$float='float:right;clear:both;';
		}	*/
		
		if($Module_CashRegisterStandardView==0 ){
			if($i%15==0)
				echo"</tr><tr>";
		
		}
		else{
			if($i%5==0)
				echo"</tr><tr>";
		}	
		echo" <td width='80px' align='left'><div class='list-item' style='$float'><input type='button' name='".$ButtonName."' id='".$ButtonName."' class='fastbuttons' onclick=\"LoadFastItem('".$ButtonValue."','".$ItemSellPrice."','".$Unmodify_SellingPrice."','".$ItemModifySellingPrice."'); return false;\" value='$ButtonLabel'></div></td>";	
		
		$i=$i+1;
	}			
	echo"	</tr></table></div>";
	echo"</td>"; 
}	
	
		


/*	echo"	<td valign='top' ><div id='itemarea' style='overflow-y:scroll;height:280px;'><table border='0' style='table-layout:fixed;' width=100% cellspacing=0 cellpadding=0>";
		

	echo"<tr   height='150px'><td  align='left' colspan='8' valign='top' style='border-bottom:0px solid #000000;border-top:0px solid #000000;font-size:13px;color:#000000'><font family='arial' >";
	$query="select item_code,item_description from items where subgroup_code='".$txtSubGroup."'";
	
	$result=mysql_query($query,$connection);
	
	echo"<table border='0' style='table-layout:fixed;' cellspacing=0 cellpadding=0>";
	
	$i=0;
	while($row=mysql_fetch_row($result)){
		
		if($i%6==0)
		echo"</tr><tr>";

		
		echo "<td width='90px'><input type='button' id='btnSub' name='btnSub' onclick=\"Fillitem('$row[0]','$subgroup_code');return false;\" class='itembuttons' value='$row[1]'><span><span></span></span></button></td>";
		$i=$i+1;
	}
	echo"</tr></table>";
	echo"</td>";

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

	echo"</tr>";
	
/*
echo"<tr height='50px'><td align='right'>";
	include("toolbar.php");
echo"</td></tr>";*/
echo" </table></td></tr>";	



	 

	
echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";  
echo" </table>  ";//end of last table menu
echo'<div style="display:none">';	


/*
if ($message == 'Item Not Found.' && $Module_CashRegAutoItemsList == 1) {
	echo'<script type="text/javascript" language="javascript">
			x=document.retail; 
			
			showlistItems(1);
		 </script>';

}*/

//if ($message == 'Item Not Found.') {

//echo"<embed src='beep.mp3' name='soundtrack' id='soundtrack' hidden='true' autostart='false' loop='false' width = 0 height = 0 type='audio/mpeg' />";
//}

//else 
if ($message != '') {

	echo '<script type="text/javascript" language="javascript">
			x=document.retail; 
			
			var vMainMode = x.mainaction.value;
			var vMode     = x.actionmode.value;
			var vRetId    = x.txtId.value;
			var vMsg      = x.message.value;
			
			alert(vMsg); 
			
			x.message.value="";
			x.action="Form_Retail.php?actionmode="+vMode+"&mainaction="+vMainMode+"&txtId="+vRetId;
			x.submit(); 
	</script>';
	
	//$message = '';
}

if ($PrRetId != '') {
	$query    = " SELECT Sale_Reference FROM Retail  ".
                " WHERE Sale_id = $PrRetId ";
	$result   = selectData($connection, $query);
	$PrRetRef = $result[0];
	
	if ($CashRegister_SlipPrinter == 1) $ReportName = 'Form_RetailSlip.php';
	else $ReportName = 'Form_RetailPreview.php';
	
	echo '<script type="text/javascript" language="javascript">';
	
	if ($CashRegister_Printer == 1) 
		echo ' PrintRetail(\''.$PrRetId.'\', \''.$PrRetRef.'\', \''.$FC_CashRegisterAskPrint.'\', \''.$ReportName.'\'); ';
	
	echo ' ClearPage1(); ';
	echo '</script>';

}	




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

}



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

HERE;

?>