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

if (!function_exists('ConvertCurrency')) {
	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];

	}
}

if (!empty($_GET["action"])) {
	$dftorderby   = $_GET["dftorderby"];
	$action 	  = $_GET["action"];
	$orderby 	  = $_GET["orderby"];
	$morelines	  = $_GET["morelines"];
	$startrange   = $_GET["startrange"];
	$perpage 	  = $_GET["perpage"];
	$totalrows    = $_GET["totalrows"];
	$direction    = $_GET["direction"];
	$filepath     = $_GET["filepath"];
	$transid      = $_GET["transid"];
	$transdtid    = $_GET["transdtid"];
	$form      	  = $_GET["form"];
		
	
	include("config.inc.php");
	include("Functions_Sales.php");
	
	$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
	mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");
	
	
	
	if ($form == 'PRD-FAC-1') {
		ShowProdFacFGGrid($connection,$form,$transid,$_SESSION['gprdtpl_parameters'],$_SESSION['gprdtpl_arrayaccess'],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	}
	else if ($form == 'PRD-FAC-2'  ) {
		ShowProdFacSFGrid($connection,$form,$transid,$_SESSION['gprdtpl_parameters'],$_SESSION['gprdtpl_arrayaccess'],$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	}
}


function ShowProdFacFGGrid($connection,$form,$PPrdId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction){
	
	$SetupDftWareHouse = $arrayparams['SetupDftWareHouse'];
	$defaultwarehouse  = $arrayparams['defaultwarehouse'];
	
	$Module_ProjectDt 		= $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt  	= $arrayparams['Module_CostCenterDt'];
	
	$DecimalBase = $arrayparams['DecimalBase'];
	$Base1       = $arrayparams['Base1'];
	$Base2       = $arrayparams['Base2'];
	$txtDate     = $arrayparams['txtDate'];
	
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGrid_ProductionFactory.php';
	
	$i = 0;
	$k = 0;
	
	if ($startrange=='') $startrange = 0;
	if ($perpage=='')	 $perpage = 50;
	if ($orderby=='')	 $orderby = $dftorderby;
	if ($morelines=='')	 $morelines = 1;
	
	if ($action == 'COR' || $direction == '') {
		if ($direction == 'asc') $direction = 'desc';
		else if ($direction == 'desc') $direction = 'asc';
		else $direction = 'asc';
	}
	
	$columnsarray = array("itemcodefg", "itemdescriptionfg", "warehousecodefg", "itemcreatedfg", "prdqtyfg", "prdcostpricefg", "totalprice","netweightfg");
	$columnsarrayall = array("itemcodefg", "itemdescriptionfg", "warehousecodefg", "itemcreatedfg", "prdqtyfg", "prdcostpricefg", "totalprice","netweightfg", "prdfgid");
	$orderbyarray = array( "Items.Item_Code", "Items.Item_Description", "productionFactoryFG.warehouse_code");
	if ($Module_ProjectDt == 1) array_push($columnsarray, 'projectcodedt');
	if ($Module_CostCenterDt == 1) array_push($columnsarray, 'costcentcodedt');
	
	for ($j=1; $j<=count($orderbyarray); $j++){
				
		$index = array_search($orderby, $orderbyarray);
		$index += 1;
		
		$orderimg = 'orderimg'.$index;
		
		if (in_array($orderby, $orderbyarray) && $direction=='asc')
			$$orderimg = "<img src='img/asc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";
		else if (in_array($orderby, $orderbyarray) && $direction=='desc')
			$$orderimg = "<img src='img/desc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";	
		else
			$$orderimg = "";
			
	}	

		
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
	
	
	$TableWidth = 1193;
	if ($Module_ProjectDt == 1)    $TableWidth += 160;
	if ($Module_CostCenterDt == 1) $TableWidth += 160;
	//Initializations for Div Ids
	$ContainerDiv = 'container1';
	$LoaderDiv    = 'Loader1';
	$HeaderDiv    = 'grid_headerDiv1';
	$ContentDiv   = 'grid_contentDiv1';
	$TableFocus   = 'table-focus-g1';
	
	$TableWidthStyle = 'width:'.$TableWidth.'px;';
	
	echo"<div id='$ContainerDiv' style='position: relative;z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''></div>";
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:1073px;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
	
		echo"<tr height='25'>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		
		echo"  <th width='140px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code".$orderimg2."</span></th>";
		echo"  <th width='205px;' align='left' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Description','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Description".$orderimg3."</span></th>";
		echo"  <th width='105px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','productionFactoryFG.warehouse_code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Warehouse".$orderimg4."</span></th>";
		echo"  <th width='65px;' align='center'><span>Item Created</span></th>";
		echo"  <th width='75px;' align='center'><span>Qty</span></th> ";		
		echo"  <th width='100px;' align='center'><span>Cost Price</span></th>";
		echo"  <th width='120px;' align='center'><span>Total</span></th>";	
		echo"  <th width='120px;' align='center'><span>Net Weight</span></th>";	
		if ($Module_ProjectDt == 1) {
			echo"  <th width='160px;' align='center'><span>Project</span></th>";	
		}
		if ($Module_CostCenterDt == 1) {
			echo"  <th width='160px;' align='center'><span>Costcenter</span></th>";	
		}
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv');\" style='width:1090px;height:60px;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
		echo"<input type='hidden' name='SelectedRec_G1' id='SelectedRec_G1' value='$SelectedRec_G1'>
			 <input type='hidden' name='SelectedRecColor_G1' id='SelectedRecColor_G1' value='$SelectedRecColor_G1'>
			 <input type='hidden' name='ModRec_G1' id='ModRec_G1' value='$ModRec_G1'>";  
		
			 
		
		
		if ($PPrdId != '' ) {
	 
			$query = " Select productionFactoryfg_id, productionFactoryFG.Item_code, Item_Description, productionFactoryFG.Warehouse_Code, ".
					 " item_created, productionFactoryfg_qty, productionFactoryfg_price, productionFactoryfg_net, items.Item_NetWeight, project_codedt, costcent_codedt ".
					 " From temp_productionFactoryFG as productionFactoryFG ".
					 " Left Join Items on productionFactoryFG.Item_code = Items.Item_code ".
					 " Where productionFactory_id = ".$PPrdId.
					 " Order By $orderby $direction ";
					 
			//echo $query;
					
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);

			$query = $query." limit ".$startrange.",".$perpage;
			$resultdt=mysql_query($query,$connection);
			
			
			while($rowsdt=mysql_fetch_array($resultdt)){
			    				
				$recno = $i+1;
				$k = $k + 1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$TextColor = 'style7';
				
				$sub_query = " SELECT ifNull(Item_Pack, 0), ifNull(item_zeroPrice, 0), Item_UnitSalesDesc, Item_UnitPurchaseDesc, ifNull(Item_Unit,1), ifNull(Item_NonStock, 0), ifNull(Item_MinimumPrice, 0), ifNull(Item_Expire,0), ifNull(item_withserialno,0) ".
							 " FROM Items ".
							 " WHERE Items.Item_Code = '".$rowsdt[1]."'";
					
				//echo "<br><br>".$sub_query;
				$sub_result = selectData($connection, $sub_query);
				$i_pack       = $sub_result[0];
				$i_zeroprice  = $sub_result[1];
				$i_unit1      = $sub_result[2];
				$i_unit2 	  = $sub_result[3]; 
				$i_unitcoef	  = $sub_result[4];
				$i_nonstock   = $sub_result[5];
				$i_minprice   = $sub_result[6];
				$i_expire	  = $sub_result[7];
				$i_withserial = $sub_result[8];
				
				
				
					
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_1['.$i.']\')"';
				
				echo"<tr id='CurRec_G1$i' class='$bgcolor $TableFocus'>";		
				echo"	<td width='25px;' $RecStyle>$recno</td>";
				echo "	<td width='25px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteRecordGridFG('".$filepath."','".$form."', '".$PPrdId."','".$rowsdt[0]."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."', '".$form2."');return false;\" title='Delete Record'  ></td>";
				
				//if ($Module_Pack == 1)
				//	echo "	<td width='125px;' align='left'><span class='".$TextColor."'>".$rowsdt[1]."</span></td>";
				$indexed = 'indexed'.$rowsdt[0];
							
				echo "	<td width='140px;' align='left'>
							<input type='hidden' name='txtPrdFGId[$i]' id='prdfgid[$i]' value='".$rowsdt[0]."' >
							<input type='hidden' name='$indexed' id='$indexed' value='$i' >
							<input type='text' name='txtItemCodeFG[$i]' id='itemcodefg[$i]' value='".$rowsdt[1]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:130px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCodeFG[$i]');GetItemInfo('$i','$DecimalBase');\" onkeyup=\"AutoCompleteData(event,this.id,'itemcodefg[$i]','itemdescriptionfg[$i]','items');\" ".$KeyDown.">
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsFG(1,$i); ' style='vertical-align:bottom;'/></span></label>
						</td>";
										
				echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDescFG[$i]' id='itemdescriptionfg[$i]' value='".$rowsdt[2]."' class='".$ClassE."' style='font-size:12px; width:200px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDescFG[$i]');\" ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDescFG(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
						</td>";
				echo"  	<td width='105px;' align='center'>
							<input type='text' name='txtWarehouseCodeFG[$i]' id='warehousecodefg[$i]' value='".$rowsdt[3]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:85px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeFG[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecodefg[$i]','warehousenamefg[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseFG($i);' style='vertical-align:bottom;'/></span></label>
						</td>";
						
				echo "	<td width='65px;' align='center'><input type='text' name='txtItemCreatedFG[$i]' id='itemcreatedfg[$i]' value='".$rowsdt[4]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:65px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdQtyFG[$i]' id='prdqtyfg[$i]' value='".$rowsdt[5]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:75px; height:20px;' onchange=\"getAmountFG('$DecimalBase','$i');SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";
				
				echo"   <td width='100px;' align='center'><span>";
				echo"  	<input type='text' name='txtCostPriceFG[$i]' id='prdcostpricefg[$i]' value='".$rowsdt[6]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:100px; height:20px;' onchange=\"getAmountFG('$DecimalBase','$i');SetModRecord('ModRec_G1','$i');\" ".$KeyDown." >";
				echo"	</span></td>";
				
				echo"	<td width='120px;' align='center'><input type='text' name='txtPrdNetTotal[$i]' id='totalprice[$i]' value='".$rowsdt[7]."'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:120px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";	
				echo"	<td width='120px;' align='center'><input type='text' name='txtPrdNetWeightFG[$i]' id='netweightfg[$i]' value='".$rowsdt[8]."'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:120px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." readonly ></td>";	
				if ($Module_ProjectDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='".$rowsdt[9]."' class='".$ClassE."' style='width:120px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(1,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
				} else {
					echo"  <input type='hidden' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='' >";
				}
				if ($Module_CostCenterDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='".$rowsdt[10]."' class='".$ClassE."' style='width:130px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				} else {
					echo"  <input type='hidden' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='' >";
				}
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_1[$i]' onclick=\"SubmitRecordGridFG('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
				echo "</tr>";
						
				
				$i+=1;
				
				$LastItemWarehouse = $rowsdt[3];
			}
			
			
		}
		
		
						
		for ($k=1;$k <= 1;$k++) {
			$recno = $i+1;
			$mode = 'i';
			
			if ($i%2==0) $bgcolor='bgcolor1';
			else $bgcolor='bgcolor2';	
			
			if (empty($txtWarehouseCodeFG[$i])) {
				if (!empty($LastItemWarehouse))
					$txtWarehouseCodeFG[$i] = $LastItemWarehouse;
				else if (!empty($SetupDftWareHouse))
					$txtWarehouseCodeFG[$i] = $SetupDftWareHouse;
				else	
					$txtWarehouseCodeFG[$i] = $defaultwarehouse;
			}

			$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_1['.$i.']\')"';
			
				
			echo"<tr id='CurRec_G1$i' class='$bgcolor $TableFocus' >";
			echo"	<td width='25px;'>$recno</td>";
			echo"	<td width='25px;' align='center' valign='center'><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"ClearRecordGrid('".$columnslistall."','".$i."','ModRec_G1');return false;\" title='Clear Record' style='vertical-align:bottom;'></td>";
						
			echo "	<td width='140px;' align='left'>
						<input type='hidden' name='txtPrdFGId[$i]' id='prdfgid[$i]' value='$txtPrdFGId[$i]' >
						<input type='text' name='txtItemCodeFG[$i]' id='itemcodefg[$i]' value='$txtItemCodeFG[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:130px; height:20px;'  onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','items','item_code',this.value,'lstItemCodeFG[$i]');GetItemInfo('$i','$DecimalBase'); \" onkeyup=\"AutoCompleteData(event,this.id,'itemcodefg[$i]','itemdescriptionfg[$i]','items');\"  ".$KeyDown.">
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsFG(1,$i); ' style='vertical-align:bottom;'/></span></label>
					</td>";
									
			echo"  	<td width='205px;' align='center'><input type='text' name='txtItemDescFG[$i]' id='itemdescriptionfg[$i]' value='$txtItemDescFG[$i]'  class='".$ClassI."' style='font-size:12px; width:200px; height:20px;' onchange=\"CheckLookup('chkcodeexists','items','item_description',this.value,'lstItemDescFG[$i]');\" ".$KeyDown." />
						<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDescFG(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
					</td>";
			echo"  	<td width='105px;' align='center'>
						<input type='text' name='txtWarehouseCodeFG[$i]' id='warehousecodefg[$i]' value='$txtWarehouseCodeFG[$i]'  maxlength='20'  class='".$ClassI."' style='font-size:12px; width:85px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeFG[$i]'); \" onkeyup=\"AutoCompleteData(event,this.id,'warehousecodefg[$i]','warehousenamefg[$i]','warehouse');\"  ".$KeyDown."  />
						<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeFG[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseFG($i);' style='vertical-align:bottom;'/></span></label>
					</td>";
					
			echo"   <td width='65px;' align='center'><input type='text' name='txtItemCreatedFG' id='itemcreatedfg[$i]' value='$txtItemCreatedFG' maxlength='20' class='".$ClassI."' onchange=\"SetModRecord('ModRec_G1','$i'); \"   style='text-align:center; font-size:12px; width:65px; height:20px; '  ".$KeyDown." ></td>";
			echo"	<td width='75px;' align='center'><input type='text' name='txtPrdQtyFG[$i]' id='prdqtyfg[$i]' value='$txtPrdQtyFG[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:75px; height:20px;' onchange=\"getAmountFG('$DecimalBase','$i');SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." ></td>";
			echo"	<td width='100px;' align='center'><input type='text' name='txtCostPriceFG[$i]' id='prdcostpricefg[$i]' value='$txtCostPriceFG[$i]' maxlength='20'  class='".$ClassI."' style='font-size:12px; font-weight:bold; text-align:center; width:100px; height:20px;' onchange=\"getAmountFG('$DecimalBase','$i');SetModRecord('ModRec_G1','$i'); \" ".$KeyDown." ></td>";
			
			echo"	<td width='120px;' align='center'><input type='text' name='txtPrdNetTotal[$i]' id='totalprice[$i]' value='$txtPrdNetTotal[$i]'  maxlength='20' class='".$ClassI."'  style='font-size:12px;font-weight:bold; text-align:center; width:120px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></td>";	
			echo"	<td width='120px;' align='center'><input type='text' name='txtPrdNetWeightFG[$i]' id='netweightfg[$i]' value='$txtPrdNetWeightFG[$i]'  maxlength='20' class='".$ClassI."'  style='font-size:12px;font-weight:bold; text-align:center; width:120px; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." readonly></td>";	
			if ($Module_ProjectDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='".$txtProjectCodeDt[$i]."' class='".$ClassE."' style='width:120px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(1,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
				} else {
					echo"  <input type='hidden' name='txtProjectCodeDt[$i]' id='projectcodedt[$i]' value='' >";
				}
				if ($Module_CostCenterDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='".$txtCostCentCodeDt[$i]."' class='".$ClassE."' style='width:130px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(1,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				} else {
					echo"  <input type='hidden' name='txtCostCentCodeDt[$i]' id='costcentcodedt[$i]' value='' >";
				}
			echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_1[$i]' onclick=\"SubmitRecordGridFG('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
			echo"</tr>";  

			$i+=1;	
		}
		

	
	echo"	</table>";  
	echo"	</div>";
	
	showDataGridFooter($filepath,$form,$PPrdId,'datagrid',$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	
}


function ShowProdFacSFGrid($connection,$form,$PPrdId,$arrayparams,$arrayaccess,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction){
	
	$SetupDftWareHouse = $arrayparams['SetupDftWareHouse'];
	$defaultwarehouse  = $arrayparams['defaultwarehouse'];
	
	$Module_ProjectDt 		= $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt  	= $arrayparams['Module_CostCenterDt'];

	$DecimalBase = $arrayparams['DecimalBase'];
	$Base1       = $arrayparams['Base1'];
	$Base2       = $arrayparams['Base2'];
	$txtDate     = $arrayparams['txtDate'];
	$DefaultCur  = $arrayparams['DefaultCur'];
	
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGrid_ProductionFactory.php';
	
	$i = 0;
	$k = 0;
	
	if ($startrange=='') $startrange = 0;
	if ($perpage=='')	 $perpage = 100;
	if ($orderby=='')	 $orderby = $dftorderby;
	if ($morelines=='')	 $morelines = 1;
	
	if ($action == 'COR' || $direction == '') {
		if ($direction == 'asc') $direction = 'desc';
		else if ($direction == 'desc') $direction = 'asc';
		else $direction = 'asc';
	}
	
	$columnsarray = array("itemcodesf", "itemdescriptionsf", "warehousecodesf", "prdweightsf", "prdqtysf", "prdpricesf", "prdnetsf");
	$columnsarrayall = array("itemcodesf", "itemdescriptionsf", "warehousecodesf", "prdweightsf", "prdqtysf", "prdpricesf", "prdnetsf", "prdsfid");
	$orderbyarray = array("Items.Item_Code", "Items.Item_Description", "productionFactorySF.warehouse_code");
	
	if ($Module_ProjectDt == 1) array_push($columnsarray, 'projectcodedt2');
	if ($Module_CostCenterDt == 1) array_push($columnsarray, 'costcentcodedt2');

	for ($j=1; $j<=count($orderbyarray); $j++){
				
		$index = array_search($orderby, $orderbyarray);
		$index += 1;
		
		$orderimg = 'orderimg'.$index;
		
		if (in_array($orderby, $orderbyarray) && $direction=='asc')
			$$orderimg = "<img src='img/asc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";
		else if (in_array($orderby, $orderbyarray) && $direction=='desc')
			$$orderimg = "<img src='img/desc-2.png' name='w' width='10'  height='10' style='padding-left:5px;'>";	
		else
			$$orderimg = "";
			
	}	

		
	$columnslist = implode(',', $columnsarray);
	$columnslistall = implode(',', $columnsarrayall);
	
	
	$TableWidth = 1523;
	//if ($Module_Pack == 1) $TableWidth += 125;
	
	if ($Module_ProjectDt == 1)    $TableWidth += 160;
	if ($Module_CostCenterDt == 1) $TableWidth += 160;
	//Initializations for Div Ids
	$ContainerDiv = 'container2';
	$LoaderDiv    = 'Loader2';
	$HeaderDiv    = 'grid_headerDiv2';
	$ContentDiv   = 'grid_contentDiv2';
	$TableFocus   = 'table-focus-g2';
	
	$TableWidthStyle = 'width:'.$TableWidth.'px;';
	
	echo"<div id='$ContainerDiv' style='position: relative;z-index:1;' >";
	echo"	<div id='$LoaderDiv' class=''></div>";
	echo" 	<div id='$HeaderDiv' class='grid_headerDiv' style='width:1073px;'>";
	echo"  	<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
	
		echo"<tr height='25'>";
		echo"  <th width='20px;' align='center'><span>&nbsp;</span></th>";
		echo"  <th width='20px;' align='center'><span>&nbsp;</span></th>";
		
		//if ($Module_Pack == 1)
		//	echo"  <th width='125px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','ProdRecipeRM.Item_CodePacked','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code Packed".$orderimg1."</span></th>";
			
		echo"  <th width='100px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Item Code".$orderimg2."</span></th>";
		echo"  <th width='270px;' align='left' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','Items.Item_Description','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Description".$orderimg3."</span></th>";
		echo"  <th width='105px;' align='center' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$PPrdId."', 'datagrid', 1, '".$dftorderby."', 'COR','ProdRecipeRM.Warehouse_Code','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\"><span>Warehouse".$orderimg4."</span></th>";
		echo"  <th width='150px;' align='center' <span>Group</span></th>";
		echo"  <th width='150px;' align='center' <span>Subgroup</span></th>";
		echo"  <th width='150px;' align='center' <span>Category</span></th>";
		echo"  <th width='65px;' align='center' <span>Weight</span></th>";
		echo"  <th width='75px;' align='center'><span>Qty</span></th> ";	
		echo"  <th width='100px;' align='center'><span>Price</span></th>";
		echo"  <th width='120px;' align='center'><span>Total</span></th>";
		if ($Module_ProjectDt == 1) {
			echo"  <th width='160px;' align='center'><span>Project</span></th>";	
		}
		if ($Module_CostCenterDt == 1) {
			echo"  <th width='160px;' align='center'><span>Costcenter</span></th>";	
		}
		echo"  <th width='25px;' align='center'><span>&nbsp;</span></th>";
		echo"</tr>";
		echo"</table></div>";
		
		echo"<div id='$ContentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('$HeaderDiv','$ContentDiv');\" style='width:1090px;height:335px;'>";
		echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='$TableWidthStyle'>";
		echo"<input type='hidden' name='SelectedRec_G2' id='SelectedRec_G2' value='$SelectedRec_G2'>
			 <input type='hidden' name='SelectedRecColor_G2' id='SelectedRecColor_G2' value='$SelectedRecColor_G2'>
			 <input type='hidden' name='ModRec_G2' id='ModRec_G2' value='$ModRec_G2'>";  
		
			 
		
		
		if ($PPrdId != '' ) {
	
			$query = " Select productionFactorysf_id, productionFactorySF.item_code, ifnull(concat(items.item_description, ''), itemsFG.item_description), productionFactorysf_weight, ".
					 " productionFactorySF.warehouse_code, productionFactorysf_qty, productionFactorysf_price, productionFactorySF.productionFactoryfg_id, productionFactorySF.project_codedt, ".
					 " productionFactorySF.costcent_codedt, items.SubGroup_Code, items.Category_code, items.Group_code  ".
					 " From temp_productionFactorySF as productionFactorySF ".
					 " Left Join Items on productionFactorySF.Item_code = Items.Item_code ".
					 " inner join temp_productionFactoryFG as productionFactoryFG on productionFactoryFG.productionFactoryfg_id = productionFactorySF.productionFactoryfg_id ".
					 " left join items as itemsFG on productionFactoryFG.item_code = itemsFG.item_code ".
					 " Where productionFactorySF.productionFactory_id = ".$PPrdId.
					 " Order By $orderby $direction ";
					 
			//echo $query;
					
			$result=mysql_query($query,$connection);
			$totalrows = mysql_num_rows($result);

			$query = $query." limit ".$startrange.",".$perpage;
			$resultdt=mysql_query($query,$connection);
			
			
			while($rowsdt=mysql_fetch_array($resultdt)){
			    				
				$recno = $i+1;
				$k = $k + 1;
				
				if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';
				
				$TextColor = 'style7';
				
				$sub_query = " SELECT ifNull(Item_Pack, 0), ifNull(item_zeroPrice, 0), Item_UnitSalesDesc, Item_UnitPurchaseDesc, ifNull(Item_Unit,1), ifNull(Item_NonStock, 0), ifNull(Item_MinimumPrice, 0), ifNull(Item_Expire,0), ifNull(item_withserialno,0) ".
							 " FROM Items ".
							 " WHERE Items.Item_Code = '".$rowsdt[1]."'";
					
				//echo "<br><br>".$sub_query;
				$sub_result = selectData($connection, $sub_query);
				$i_pack       = $sub_result[0];
				$i_zeroprice  = $sub_result[1];
				$i_unit1      = $sub_result[2];
				$i_unit2 	  = $sub_result[3]; 
				$i_unitcoef	  = $sub_result[4];
				$i_nonstock   = $sub_result[5];
				$i_minprice   = $sub_result[6];
				$i_expire	  = $sub_result[7];
				$i_withserial = $sub_result[8];
				
				
				$querycurrency="select currency_code from currency order by currency_code";
				$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error($connection));

					
				$KeyDown   = 'onkeydown="return dokey(event,this,'.$i.',\''.$columnslist.'\',\'imgSubmit_2['.$i.']\')"';
				
				echo"<tr id='CurRec_G2$i' class='$bgcolor $TableFocus'>";		
				echo"	<td width='20px;' $RecStyle>$recno</td>";
				echo "	<td width='20px;' align='center' valign='center'><img src='img/delete.png' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"DeleteRecordGridSF('".$filepath."','".$form."', '".$PPrdId."','".$rowsdt[0]."','".$i."','".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."');return false;\" title='Delete Record'  ></td>";
				
				//if ($Module_Pack == 1)
				//	echo "	<td width='125px;' align='left'><span class='".$TextColor."'>".$rowsdt[1]."</span></td>";
					
				echo "	<td width='100px;' align='left'>
							<input type='hidden' name='txtPrdSFId[$i]' id='prdsfid[$i]' value='".$rowsdt[0]."' >
							<input type='text' name='txtItemCodeSF[$i]' id='itemcodesf[$i]' value='".$rowsdt[1]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:110px; height:18px;' onchange=\"SetModRecord('ModRec_G2','$i'); \" onkeyup=\"AutoCompleteData(event,this.id,'itemcodesf[$i]','itemdescriptionsf[$i]','items');\" ".$KeyDown.">
  					    </td>";
				
				echo"  	<td width='270px;' align='left'><input type='text' name='txtItemDescSF[$i]' id='itemdescriptionsf[$i]' value='".$rowsdt[2]."' class='".$ClassE."' style='font-size:12px; width:270px; height:18px;' ".$KeyDown." />
							<label><span><img src='img/openlist.png' title='Select Item' id='lstItemDescRM[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistItemsDescRM(1,$i); ' style='vertical-align:bottom; display:none;'/></span></label>
						</td>";
				echo"  	<td width='105px;' align='center'>
							<input type='text' name='txtWarehouseCodeSF[$i]' id='warehousecodesf[$i]' value='".$rowsdt[4]."'  maxlength='20' class='".$ClassE."' style='font-size:12px; width:75px; height:18px;' onchange=\"SetModRecord('ModRec_G2','$i'); CheckLookup('chkcodeexists','warehouse','warehouse_code',this.value,'lstWarehouseCodeSF[$i]');\" onkeyup=\"AutoCompleteData(event,this.id,'warehousecodesf[$i]','warehousenamesf[$i]','warehouse');\" ".$KeyDown."   />
							<label><span><img src='img/openlist.png' title='Select Warehouse' id='lstWarehouseCodeSF[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistWarehouseSF($i);' style='vertical-align:bottom;'/></span></label>
						</td>";
				echo "<td width='150px;'><input type='text' name='group_code[$i]' id='group_code[$i]' value='".$rowsdt[12]."' readonly style='width: 140px;height: 18px;'>";
				echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistgroups('10', '$i');\"  /></span></label>
					</td>";		
				echo "<td width='150px;'><input type='text' name='subgroup_code[$i]' id='subgroup_code[$i]' value='".$rowsdt[10]."' readonly style='width: 140px;height: 18px;'>";
				echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select SubGroup ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistsubgroups('7', '$i');\"  /></span></label>
					</td>";
				echo "<td width='150px;'><input type='text' name='category_code[$i]' id='category_code[$i]' value='".$rowsdt[11]."' style='width: 140px;height: 18px;' readonly>";
				echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Category ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=\"showlistcategory('5','$i');\"  /></span></label>
					</td>";		
				echo"	<td width='65px;' align='center'><input type='text' name='txtPrdWeightSF[$i]' id='prdweightsf[$i]' value='".$rowsdt[3]."' maxlength='20' onkeyup=\"CalcWeight('$i','$DecimalBase','$rowsdt[7]','$rowsdt[0]');\" class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:65px; height:18px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";
				echo"	<td width='75px;' align='center'><input type='text' name='txtPrdQtySF[$i]' id='prdqtysf[$i]' value='".$rowsdt[5]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:75px; height:18px;' onchange=\"getAmountSF('$DecimalBase','$i');SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";
				
				echo"   <td width='100px;' align='center'><input type='text' name='txtPrdPriceSF[$i]' id='prdpricesf[$i]' value='".$rowsdt[6]."' maxlength='20'  class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:100px; height:18px;' onchange=\"getAmountSF('$DecimalBase','$i');SetModRecord('ModRec_G2','$i');\" ".$KeyDown." >";
				echo"	</td>";
				
				$prdnetsf[$i] = $rowsdt[5] * $rowsdt[6];
				echo"	<td width='120px;' align='center'><input type='text' name='txtPrdNetSF[$i]' id='prdnetsf[$i]' value='".$prdnetsf[$i]."'   class='".$ClassE."' style='font-size:12px; font-weight:bold; text-align:center; width:120px; height:18px;' onchange=\"SetModRecord('ModRec_G2','$i');\" ".$KeyDown." ></td>";	
				if ($Module_ProjectDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtProjectCodeDt2[$i]' id='projectcodedt2[$i]' value='".$rowsdt[8]."' class='".$ClassE."' style='width:120px;height: 18px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Project' id='lstProjectCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistProjectDt(2,$i); ' style='vertical-align:bottom;'/></span></label></td>";	
				} else {
					echo"  <input type='hidden' name='txtProjectCodeDt2[$i]' id='projectcodedt2[$i]' value='' >";
				}
				if ($Module_CostCenterDt == 1) {
					echo"<td width='160px;' align='center'><input type='text' name='txtCostCentCodeDt2[$i]' id='costcentcodedt2[$i]' value='".$rowsdt[9]."' class='".$ClassE."' style='width:130px;height: 18px;' maxlength='20' onchange=\"SetModRecord('ModRec_G1','$i'); CheckLookup('chkcodeexists','costcent','costcent_code',this.value,'lstCostCentCode[$i]');\" ".$KeyDown." /></span>
							<label><span><img src='img/openlist.png' title='Select Costcenter' id='lstCostCentCode[$i]' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onClick='showlistCostcenterDt(2,$i); ' style='vertical-align:bottom;' /></span></label></td>";	
				} else {
					echo"  <input type='hidden' name='txtCostCentCodeDt2[$i]' id='costcentcodedt2[$i]' value='' >";
				}
				echo "	<td width='25px;' align='center' valign='center'><input type='button' id='imgSubmit_2[$i]' onclick=\"SubmitRecordGridSF('".$i."','".$filepath."', '".$form."', '".$PPrdId."', '".$dftorderby."','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$direction."'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ></td>";
				echo "</tr>";
						
				
				$i+=1;
				
				$LastItemWarehouse = $rowsdt[4];
			}
			
			
		}
		echo "<input type='hidden' name='lastrow' id='lastrow' value='$i'>";
		
							
	
	
	echo"	</table>";  
	echo"	</div>";
	
	showDataGridFooter($filepath,$form,$PPrdId,'datagrid',$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction);
	
	echo"</div>";
	
	
}


function showDataGridFooter($filepath,$form,$transid,$gridid,$dftorderby,$action,$orderby,$morelines,$startrange,$perpage,$totalrows,$direction) {
	
	echo"<div class='grid_toolbarDiv'>
			<table width='100%' border=0 cellpadding='0' cellspacing='0'>
			<tr>";
	
	$rangefrom = ($startrange + 1);
	if (($startrange + $perpage) >= $totalrows) $rangeto = $totalrows; else $rangeto = ($startrange + $perpage);
				
	if ($totalrows > 0)			
		echo"	<td align='left' style='width:33%; padding-left:10px;border-top:1px solid #000000;'><span class='toolbar_style'>View ".$rangefrom." - ".$rangeto." of ".$totalrows."</span></td>";
	else
		echo"	<td align='left' style='width:33%; padding-left:10px;border-top:1px solid #000000;'><span class='toolbar_style'>No records to view</span></td>";
	
	echo"		<td align='center' style='width:15%;border-top:1px solid #000000;'><span class='toolbar_style'>Per Page </span><span class='toolbar_style'><select name='perpage' id='perpage' value='$perpage' onchange=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'CP','".$orderby."','".$morelines."',0,this.value,'".$totalrows."','".$direction."');\">";
				  
				if ($perpage==10)		 $s10 = 'selected';
				else if ($perpage==20)	 $s20 = 'selected';
				else if ($perpage==30)	 $s30 = 'selected';
				else if ($perpage==40)	 $s40 = 'selected';
				else if ($perpage==50)	 $s50 = 'selected';
				else if ($perpage==100)	 $s100 = 'selected';
				else if ($perpage==1000) $s1000 = 'selected';

								
				echo'<option '.$s10.' value="10">10</option>
					 <option '.$s20.' value="20">20</option>
					 <option '.$s30.' value="30">30</option>
					 <option '.$s40.' value="40">40</option>
					 <option '.$s50.' value="50">50</option>
					 <option '.$s100.' value="100">100</option>
					 <option '.$s1000.' value="1000">1000</option>
					 </select></span>
				</td>';
				
	echo"		<td  style='width:10%;border-right:1px solid #000000;text-align:right;border-top:1px solid #000000;'>";
				
				if($startrange > 0)
					echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='pointer'\"    onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'F','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";

				$diff= $startrange - $perpage;
					
				if (($diff) >= 0 ){
					$prvstartrange = $startrange - $perpage;
					echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'P','".$orderby."','".$morelines."','".$prvstartrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";
				}
				else
					echo "&nbsp;";
			
	echo"		</td><td  align='left' style='width:10%;border-top:1px solid #000000;'>&nbsp;";
			
			
				if ($startrange <= $totalrows){
					$startrange1 = $startrange + $perpage;
					if  ($startrange1 < $totalrows){ 
						echo"<img src='img/arrowright.png' title='Next' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'N','".$orderby."','".$morelines."','".$startrange1."','".$perpage."','".$totalrows."','".$direction."');return false;\" onmouseover=\"style.cursor='pointer'\" >";
						echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='pointer'\" onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'L','".$orderby."','".$morelines."','".$prvstartrange."','".$perpage."','".$totalrows."','".$direction."');return false;\" >";	
					}
				} else
					echo "&nbsp;";
			
				
				$currentpage = ($startrange / $perpage) + 1;
				$totalpages  = ceil($totalrows / $perpage);
				
	echo"		</td><td style='text-align:center; width:14%;border-top:1px solid #000000;'>&nbsp;<span class='toolbar_style'>Page $currentpage / $totalpages</span></td>";
	

	
	echo"		<td style='text-align:center; width:6%;border-top:1px solid #000000;'><img src='img/Refresh-icon.png'  onMouseOver=\"style.cursor='pointer'\"  width='20' height='20' onclick=\"ReloadGrid('".$filepath."', '".$form."', '".$transid."', '".$gridid."', 1, '".$dftorderby."', 'R','".$orderby."','".$morelines."','".$startrange."','".$perpage."','".$totalrows."','".$direction."');\" ></td>";
	echo"		<td align='right' style='width:12%; padding-right:10px;border-top:1px solid #000000;'>&nbsp;</td>";
	
	echo"	</tr>";
	echo"	</table></div>";

}


?>