<?php

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


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



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

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


$querylog="SELECT FI_SubGrouping as loginaccess,language from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}

	
	
	
$querylang="select language,creation_date, code, name, group_code, parent, 
type, dimension, color, sub_order
 from ".$_SESSION['dbLabel'].".subgroup_label 
where language='$language'";


$resultlang=mysql_query($querylang,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlang)){
		//extract($rows);
		
		$subcreationdate=$rows[1];
		$subcode=$rows[2];
		$subname=$rows[3];
		
		$subgroupcode=$rows[4];
		$subparent=$rows[5];
		$subtype=$rows[6];
		$subdimension=$rows[7];
		$subcolor=$rows[8];
		$suborder=$rows[9];

		
	}

$querylang="select language, buttonclear, save, print, find, clear, results, page from ".$_SESSION['dbLabel'].".buttons_label 
where language='$language'";


$resultlang=mysql_query($querylang,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlang)){
		//extract($rows);
		
		$buttonclear=$rows[1];
		$save=$rows[2];
		$print=$rows[3];
		$find=$rows[4];
		$clear=$rows[5];
		$results=$rows[6];
		$page=$rows[7];
		
	}

	
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
	
	//Read From module Table							
$querysetup= " select module_rawmaterial,ifNull(Module_AutoItemcode,0) as Module_AutoItemcode  from module ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
	
//User Access
$querylog=" select ifNull(FI_SubGroupingApp,0) As FI_SubGroupingApp, ifNull(FI_SubGroupingDel,0) As FI_SubGroupingDel, ".
          " ifNull(FI_SubGroupingMod,0) As FI_SubGroupingMod from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$HideMenu     = $_POST["HideMenu"]; if ($HideMenu == ""){$HideMenu = $_GET["HideMenu"];}   
$actionmode   = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$mode   	  = $_POST["mode"]; if ($mode == ""){$mode = $_GET["mode"];}   
$message 	  = $_POST["message"]; if ($message == ""){$message = $_GET["message"];}   
$Increment    = $_POST["Increment"]; if ($Increment == ""){$Increment = $_GET["Increment"];} 
$checkduplicate   = $_POST["checkduplicate"]; if ($checkduplicate == ""){$checkduplicate = $_GET["checkduplicate"];} 
$showfield 	  = $_POST["showfield"]; if ($showfield == ""){$showfield = $_GET["showfield"];} 

$txtKeyword  = $_POST["txtKeyword"]; if ($txtKeyword == ""){$txtKeyword = $_GET["txtKeyword"];}   
$perpage 	 = $_POST["perpage"]; if ($perpage == ""){$perpage = $_GET["perpage"];} 
$startrange	 = $_POST["startrange"]; if ($startrange == ""){$startrange = $_GET["startrange"];} 
$vTabFocus   = $_POST["vTabFocus"]; if ($vTabFocus == ""){$vTabFocus = $_GET["vTabFocus"];} 

$Subgroup_CreationDate	= $_POST["Subgroup_CreationDate"]; if ($Subgroup_CreationDate == ""){$Subgroup_CreationDate = $_GET["Subgroup_CreationDate"];} 
$SubGroup_Code    	= $_POST["SubGroup_Code"]; if ($SubGroup_Code == ""){$SubGroup_Code = $_GET["SubGroup_Code"];} 
$SubGroup_Name 		= $_POST["SubGroup_Name"]; if ($SubGroup_Name == ""){$SubGroup_Name = $_GET["SubGroup_Name"];} 
$group_code 		= $_POST["group_code"]; if ($group_code == ""){$group_code = $_GET["group_code"];} 
$group_name 		= $_POST["group_name"]; if ($group_name == ""){$group_name = $_GET["group_name"];} 
$SubGroup_Parent	= $_POST["SubGroup_Parent"]; if ($SubGroup_Parent == ""){$SubGroup_Parent = $_GET["SubGroup_Parent"];} 
$SubGroup_Type		= $_POST["SubGroup_Type"]; if ($SubGroup_Type == ""){$SubGroup_Type = $_GET["SubGroup_Type"];} 
$SubGroup_Color		= $_POST["SubGroup_Color"]; if ($SubGroup_Color == ""){$SubGroup_Color = $_GET["SubGroup_Color"];} 
$subgroup_order		= $_POST["subgroup_order"]; if ($subgroup_order == ""){$subgroup_order = $_GET["subgroup_order"];} 

//Access Mode On Insert/Edit/Delete
$InsMode = '';
if ($FI_SubGroupingApp == 0)
	$InsMode = ' disabled ';
	
	
if(!isset($mode))
$mode='';

/// Parent list


$query_parents="select Increment,SubGroup_Code,SubGroup_Name from subgroup where Increment<>'".$Increment."'";
$result_parent=mysql_query($query_parents,$connection) or die(mysql_error());




//$query_policy="select subgrouppolicy_id,subgrouppolicy_name from subgrouppolicy ";
//$result_policy=mysql_query($query_policy,$connection) or die(mysql_error());
/*
if(empty($subgrouptype))
	$subgrouptype='S';*/


if(($mode=='editmode' or $mode=='view') && $checkduplicate!='1' && $checkduplicate!='0'){

	$query_edit=" select SubGroup.Increment, SubGroup_Code, SubGroup_Name, Grouping.group_code, Grouping.group_name, date_format(Subgroup_CreationDate,'%d-%m-%Y'),SubGroup.Parent_Code,SubGroup_Type,SubGroup_Color,subgroup_order
				,subgroup_length, button_dimwidth,button_dimheight ".
				" from SubGroup Left Join Grouping on SubGroup.Group_Code = Grouping.Group_Code ".
				" where SubGroup.Increment='".$Increment."'";

	//echo$query_edit;
	$resultedit = mysql_query($query_edit, $connection);
	while($row=mysql_fetch_array($resultedit)){
        
		$Increment=$row[0];
		$SubGroup_Code=$row[1];
		$SubGroup_Name=$row[2];
		$group_code=$row[3];
		$group_name=$row[4];
		$Subgroup_CreationDate=$row[5];
		$SubGroup_Parent=$row[6];
		$SubGroup_Type=$row[7];
		$SubGroup_Color=$row[8];
		$subgroup_order=$row[9];
		$subgroup_length=$row[10];
		$buttondimwidth=$row[11];
		$buttondimheight=$row[12];
		/*$subgrouptype=$row[7];
		$SubGroup_seqnumber=$row[8];
		$SubGroup_policy=$row[9];*/
		
	}
	$mode='edit';
}
/*
if($subgrouptype=='S')
	$selectedsubgroup='selected';
	
if($subgrouptype=='A')
	$selectedattribut='selected';
*/	
	if($mode=='') $mode='insert';
	
	
print <<<HERE

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 


<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<script type="text/javascript" src="js/jscolor/jscolor.js"></script>
<script type="text/javascript" language="javascript">

function set_policy(){
	document.SubGroup.SubGroup_policy.value=document.SubGroup.subgrouppolicy.value;
}

function set_type(){
	
	document.SubGroup.showfield.value=document.SubGroup.subgrouptype.value;
	document.SubGroup.action="Form_SubGroup.php?mode=insert";
	document.SubGroup.submit();
}

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

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

function editmode () {

	document.SubGroup.mode.value='edit';
	document.SubGroup.action="Form_SubGroup.php";
	document.SubGroup.submit();
}

function AddSubGroup() {
	ClearForm('All');
	document.SubGroup.mode.value='insert';
	document.SubGroup.action="Form_SubGroup.php?mode=insert";
	document.SubGroup.submit();
}




function CancelRecord () {


if (confirm ( "Are you sure you want to Cancel Page?")){
	ClearForm('All');
			document.SubGroup.action="Form_SubGroup.php?mode=";
				document.SubGroup.submit();
}
}






function SubmitRecord() {

	x = document.SubGroup;
	if (x.SubGroup_Code.value=='' ){
		alert('Unable to save : check missing field Code ');
		document.SubGroup.SubGroup_Code.focus();
		
	}
		
	else 
	if (x.SubGroup_Name.value=='' ){
		alert('Unable to save : check missing field Name ');
		document.SubGroup.SubGroup_Name.focus();
		
	}
	
	else {
		x.checkduplicate.value=1;
		x.action="Form_SubGroup_Actions.php";
		x.submit();
	}
}



function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		
		
		

		x.mode.value='';
		x.action='Form_SubGroup.php';
		x.submit();
	}	
}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.SubGroup;
	x.Increment.value='';
	x.SubGroup_Code.value='';
	x.SubGroup_Name.value='';
	x.Subgroup_CreationDate.value='';
    x.group_code.value='';
	x.group_name.value='';	
	x.checkduplicate.value='';	
	//x.SubGroup_Parent.value='';
	//x.SubGroup_seqnumber.value='';
	//x.SubGroup_policy.value='';
	x.message.value='';
	x.SubGroup_Type.value='';
	x.SubGroup_Color.value='';
	x.subgroup_order.value='';
}


function SearchForSubGroup(){
    ClearForm('All');
    x = document.SubGroup;
    win = window.open('Form_SubGroupSearch.php', 'Form_SubGroupSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	win.creator = self;
	win.focus();		
			
}
   function PrintPreview() {
	var str = '';
	
	str = 'Form_SubGroupPreview.php';
	window.open(str);

}

function SetSub(SubId){
	
	document.SubGroup.Increment.value=SubId;
	document.SubGroup.message.value='';
	document.SubGroup.actionmode.value='';
	
	document.SubGroup.mode.value='editmode';
	document.SubGroup.submit();
}

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

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

function SearchForSub(){
	x = document.SubGroup;
	document.SubGroup.action='Form_SubGroup.php?startrange=0';
	document.SubGroup.submit();
}

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

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

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

function confirm_delete(Code) {
	
				
	if (confirm ( "Are you sure you want to Delete this Record " + "?")) {
		//window.event.returnValue = true;
		document.SubGroup.mode.value='delete';	
		
		document.SubGroup.action='Form_SubGroup_Actions.php?IncrementId='+Code;
		document.SubGroup.submit();
	}
					
}

function set_limit(){

	perpage=document.SubGroup.perpage.value;
	document.SubGroup.action='Form_SubGroup.php?perpage='+perpage+'&startrange=0';
	document.SubGroup.submit();
}
function setDim(){
	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 = xmlhttp.responseText;
					var resp = data;
					if(resp == 1) {
						document.getElementById("buttondimwidth").disabled = false;
						document.getElementById("buttondimheight").disabled = false;
					}
					else {
						document.getElementById("buttondimwidth").disabled = true;
						document.getElementById("buttondimheight").disabled = true;
					}

				}
		}
  }
var subgtype = document.getElementById("SubGroup_Type").value;
xmlhttp.open("GET","Form_SubGroup_Actions.php?mode=checktype&subgtype="+subgtype,true);
xmlhttp.send();

	
	
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add SubGroup</title>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}
.selectstyle {font-size: 12px; font-family:arial,verdana,geneva; color:#000000; width=118px}

</style>

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

</head>
<body >
<form name='SubGroup' method='post' enctype='multipart/form-data'>
<input type='hidden' name='HideMenu' value='$HideMenu'>
<input type='hidden' name='mode' value='$mode'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='message' value='$message'>
<input type='hidden' name='Increment' value='$Increment'>
<input type='hidden' name='checkduplicate' value='$checkduplicate'>
<input type='hidden' name='showfield' value='$showfield'>

HERE;

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

}


if($mode=='view'){

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

}

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

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

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

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


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


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


echo"		<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(); return false;' title='Save Changes' $Insmode><span><span>$save</span></span></button>";
echo"		<button type='button' id='btnPrt' name='btnPrt' onclick='PrintPreview(); return false;' title='Print' ><span><span>$print</span></span></button>";


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

echo"<tr><td id='content-body'>";
echo"<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
	<col width=64%>";

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

	  
echo"<table border='0' style='table-layout:fixed' align='left' valign='top'>
      <col width=120>
	  <col width=150>
	  <col width=260>";
	  
echo"<tr bgcolor='#F7F7F7' height='25'>
     <td valign='center' align='left' ><span class='style1'>$subcreationdate &nbsp;<span class='style26'>*</span></span>";
echo"</td>";


	if($mode!=''){
		$today = date('d-m-Y');
		$Subgroup_CreationDate = $today;
	}			
	echo" <td colspan='2' align='left'><input type='text' name='Subgroup_CreationDate' id='Subgroup_CreationDate' value='$Subgroup_CreationDate' style='font-size:12px; width:120px; height:18px;' readonly />";
	 if ($mode!=''){
	    $Subgroup_CreationDate = "disabled";
	}
echo" </td></tr>";

echo"<tr bgcolor='#F7F7F7' height='25'><td valign='center' align='left' ><span class='style1'>$subcode&nbsp;<span class='style26'>*</span></span></td>";
echo"<td colspan='2' align='left'><input type='text' name='SubGroup_Code'  value='".htmlspecialchars($SubGroup_Code, ENT_QUOTES)."' style='font-size:12px; width:120px; height:18px;'  $status maxlength='15' /></td></tr>";

echo"<tr bgcolor='#F7F7F7' height='25'><td valign='center' align='left' ><span class='style1'>$subname&nbsp;<span class='style26'>*</span></span></td>";
echo"<td colspan='2'><input type='text' name='SubGroup_Name' value='".htmlspecialchars($SubGroup_Name, ENT_QUOTES)."' style='font-size:12px; width:408px; height:18px;'  $status maxlength='30' /></td></tr>";

//echo"<tr bgcolor='#F7F7F7' height='25'><td align='left'><span class='style1'>$subtype</span></td><td colspan='2'><select name='subgrouptype' class='selectstyle' onchange='set_type();' $dis><option value='S' $selectedsubgroup>Subgroup</option><option value='A' $selectedattribut>Attribut</option></select></td></tr>";	


	echo"<tr bgcolor='#F7F7F7' height='25'><td valign='center' align='left' ><span class='style1'>$subgroupcode&nbsp;<span class='style26'></span></span></td>";
	echo"<td align='left'><input type='text' name='group_code' value='".htmlspecialchars($group_code, ENT_QUOTES)."' style='font-size:12px; width:120px; height:18px;'  $status maxlength='15' />";

	if($mode!='view' && $mode!='')
		echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistgrouping(1); return false' /></span></label></td>";
	echo"<td ><input type='text' name='group_name' value='".htmlspecialchars($group_name, ENT_QUOTES)."' readonly size='31' style='font-size:12px; width:256px; height:18px;'></td></tr>";	
	/*echo"<input type='hidden' name='SubGroup_Parent' value='$SubGroup_Parent'>";
	echo"<input type='hidden' name='SubGroup_seqnumber' value='$SubGroup_seqnumber'>";
	echo"<input type='hidden' name='SubGroup_policy' value='$SubGroup_policy'>";*/



	echo"<tr bgcolor='#F7F7F7' height='25'><td valign='center' align='left' ><span class='style1'>$subparent</span></td>
	<td align='left'>
	<select name='SubGroup_Parent' $dis style='width:125px;'>
	<option value=''>&nbsp;</option>";
	while ($row_parent=mysql_fetch_row($result_parent)){
		if($row_parent[1]==$SubGroup_Parent)
			echo "<option value='$row_parent[1]' selected>$row_parent[1]</option>";
		else echo "<option value='$row_parent[1]'>$row_parent[1]</option>";
	}
	echo"</select>";
	echo"</td>
		 <td align='center' rowspan='3'><img src='GetButtonImage.php?option=subgroup&id=$SubGroup_Code' alt='Photo' style='width:60px; height:60px;'></img></td>
		</tr>";
	
	echo"<tr bgcolor='#F7F7F7' height='25'>
			<td valign='center' align='left' ><span class='style1'>$subtype</span></td>
			<td align='left'>
			<select name='SubGroup_Type' id='SubGroup_Type' style='width:125px;' onchange=\"setDim();\">
				<option value='' "; if($SubGroup_Type=='') echo "selected"; echo">&nbsp;</option>
				<option value='PLU' "; if($SubGroup_Type=='PLU') echo "selected"; echo">PLU</option>";
	echo"	</select>";
	echo"	</td>
		</tr>";
	
	echo"<tr bgcolor='#F7F7F7' height='25'>
			<td valign='center' align='left' ><span class='style1'>$subdimension</span></td>
			<td align='left'>";
	echo "<input type='text' name='buttondimwidth' id='buttondimwidth' value='$buttondimwidth' style='width:50px;' onkeypress='return (event.charCode >= 48 && event.charCode <= 57) || (event.charCode== 46)' ".($SubGroup_Type=='PLU'?'':'disabled')." >
	X <input type='text' name='buttondimheight' id='buttondimheight' value='$buttondimheight' style='width:50px;' onkeypress='return (event.charCode >= 48 && event.charCode <= 57) || (event.charCode== 46)' ".($SubGroup_Type=='PLU'?'':'disabled')." >";
	echo"	</td>
		</tr>";
		
		
	echo"<tr bgcolor='#F7F7F7' height='25'>
			<td valign='center' align='left' ><span class='style1'>$subcolor</span></td>
			<td align='left'><input type='text' name='SubGroup_Color'  value='".htmlspecialchars($SubGroup_Color, ENT_QUOTES)."' style='font-size:12px; width:120px; height:18px;' class='color'  $status maxlength='15' /></td>
		</tr>";

		echo"<tr bgcolor='#F7F7F7' height='25'>
			<td valign='center' align='left' ><span class='style1'>$suborder</span></td>
			<td align='left'><input type='text' name='subgroup_order'  value='".$subgroup_order."' style='font-size:12px; width:120px; height:18px;'   $status maxlength='15' /></td>
		</tr>";

if($Module_AutoItemcode==1){
	echo"<tr bgcolor='#F7F7F7' height=25><td valign='center' align='left' colspan='1'><span class='style1'>Item Length</span></td>";
	echo"<td><input type='text' name='subgroup_length' value='".htmlspecialchars($subgroup_length, ENT_QUOTES)."' style='font-size:12px; width:100px; height:18px;'  $status maxlength='10' /></td>";
	echo"</tr>";
}		
	echo"<tr bgcolor='#F7F7F7' height='25'>
			<td colspan='2'>&nbsp;</td>
			<td rowspan=2><input type='file' name='photo' id='photo' style='width:200px;' accept='image/jpeg,image/gif,image/png'></td>
		</tr>";
		
		
//	echo"<tr bgcolor='#F7F7F7' height='25'><td><span class='style1'>Sequential No</span></td><td colspan='2'><input type='text' name='SubGroup_seqnumber' value='$SubGroup_seqnumber' maxlength='30' style='font-size:12px; width:120px; height:18px;' maxlength='10'  $status></td>";
//	echo"</tr>";
	/*echo"<tr bgcolor='#F7F7F7' height='25'><td align='left'><span class='style1'>Policy</span></td><td colspan='2'>";
	echo"<select name=subgrouppolicy onchange='set_policy()'>
		<option value=''>&nbsp;</option>";
	while ($row_policy=mysql_fetch_row($result_policy)){
		if($row_policy[0]==$SubGroup_policy)
			echo "<option value='$row_policy[0]' selected>$row_policy[1]</option>";
		else echo "<option value='$row_policy[0]'>$row_policy[1]</option>";
	}
	
	echo"<input type='hidden' name='SubGroup_policy' value='$SubGroup_policy' maxlength='10' style='font-size:12px; width:120px; height:18px;' maxlength='10'  $status></td></tr>";
	echo"<input type='hidden' name='group_code' value='$group_code'><input type='hidden' name='group_name' value='$group_name'>";
}*/

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

echo"<td  valign='top'>";
// richard
echo"<table style='width:1050px;' border='0' cellspacing=0>
	<col width=50>
	 <col width=500>
	 <col width=500>
	<tr><td id='' style='width:1050px;height:15px;' colspan='4'></td>
	</tr>
	 <tr><td  valign='top' colspan=3 id='' style='width:1050px;'>
	 <table style='width:1050px;' border='0' cellspacing=0>
	 <col width=50>
	 <col width=500>
	 <col width=500>
	<tr height='30px' style='background-color:darkgray;'>
	<td>&nbsp;</td>
	<td align='center'><span class='style1'><b>$subcode</b></td>
	<td align='center'><span class='style1'><b>$subname</b></td>
	</tr></table></td></tr>";
	 
	echo"<tr><td colspan=3 id=''>
	<div style='overflow-y:scroll;height:320px;width:1050px;border:0px solid #000000;'>
	<table  border='0' width='1050px'>
	<col width=50>
	 <col width=500>
	 <col width=500>";
	
	
	
	$querysearch="select Increment,SubGroup_Code,SubGroup_Name,group_code from subgroup ";
	$querysearch=$querysearch." where (SubGroup_Code like"."('%".$txtKeyword."%') or SubGroup_Name like"."('%".$txtKeyword."%') ) ";

	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
	$totalrows = mysql_num_rows($resultsearch);
	
	if ($startrange=='')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 20;
	
	$querysearch = $querysearch." limit ".$startrange.",".$perpage;
	

	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
	while($rows=mysql_fetch_array($resultsearch)){
		$ct+=1;
		$stylefont='style15';
		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
				
		if($mode=='edit' && $Increment==$rows[0]){
			
			$Color="style='background-color:#1e87a5'";
			$stylefont='style28';
	}	
		
	echo'<tr '.$Color.' height="20px" >';
	if($FI_SubGroupingDel==1)	
print<<<HERE

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

HERE;
else 
	print<<<HERE

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

HERE;
	echo"<td style='cursor:pointer;' ";if($FI_SubGroupingMod==1) echo " onclick=SetSub('$rows[0]');";echo"><span class='$stylefont' >$rows[1]&nbsp;</span></font></td>
		<td style='cursor:pointer;' ";if($FI_SubGroupingMod==1) echo " onclick=SetSub('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[2]&nbsp;</span></font></td>
		<td style='cursor:pointer;' ";if($FI_SubGroupingMod==1) echo " onclick=SetSub('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[3]&nbsp;</span></font></td>";
	echo"";
	

	echo"	</tr>";
}		
	
	echo"</table></div></td></tr>";
echo"<tr height='50px'><td id='' colspan='2'><table width=100% border='0'><tr><td align='center' width=50%>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td  align='center'>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td></tr><tr>
					<td id='' style='width:1050px;height:20px;' colspan='6'></td>
				</tr></table></td></tr>";
		

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

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

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

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

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

/*echo"           <input name='btnSearch' type='button' id='btnSearch' value='Search' onclick='SearchForSubGroup();' $style title='Search SubGroup' ";
                if ($mode=='edit' or $mode=='insert') 
				    echo " disabled ";
			
		        echo " />";

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

						echo"</td>";
				

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

print <<< HERE
       </td>
      </tr> <tr height='30'><td align='center' id='content-bottom' ></td></tr>
	  </table>
HERE;

/*
if($checkduplicate=='1'){
		$SubGroup_Code=trim($SubGroup_Code);
		
		$query_testcode="select count(*) from subgroup where subgroup_code='".$SubGroup_Code."' ";
		
		if($mode=='edit')
			$query_testcode=$query_testcode." and increment<>'".$Increment."'";
			//echo$query_testcode;exit;
		$result_testcode=mysql_query($query_testcode, $connection);
		$row_code=mysql_fetch_row($result_testcode);
		$num=$row_code[0];
	
		if($num>0){
			$message="Code Already exists";
			
			echo"<script type='text/javascript'>";
			echo"	document.SubGroup.message.value='Code Already Exists';";
			echo"	document.SubGroup.checkduplicate.value='0';";
			echo"	document.SubGroup.submit();";	
			echo"</script>";
		}
		
		else{
			echo"<script type='text/javascript'>";
			echo"	document.SubGroup.action='Form_SubGroup_Actions.php';";
			echo"	document.SubGroup.submit();";
			echo"</script>";
		}
	
	}*/

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

HERE;

?>