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

session_start();

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

//Set Time Execution For the Report
ini_set('max_execution_time', $config['ReportTimeExecution']);

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


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

$PActionMode = $_POST["PActionMode"]; if ($PActionMode == ""){$PActionMode = $_GET["PActionMode"];}   
$message 	 = $_POST["message"]; if ($message == ""){$message = $_GET["message"];}   
$startrange  = $_POST["startrange"]; if ($startrange == ""){$startrange = $_GET["startrange"];}   

$txtItemButtonId    = $_POST["txtItemButtonId"]; if ($txtItemButtonId == ""){$txtItemButtonId = $_GET["txtItemButtonId"];}   
$txtItemButtonOrder = $_POST["txtItemButtonOrder"]; if ($txtItemButtonOrder == ""){$txtItemButtonOrder = $_GET["txtItemButtonOrder"];}   
$txtItemButtonValue = $_POST["txtItemButtonValue"]; if ($txtItemButtonValue == ""){$txtItemButtonValue = $_GET["txtItemButtonValue"];}   
$txtItemButtonLabel = $_POST["txtItemButtonLabel"]; if ($txtItemButtonLabel == ""){$txtItemButtonLabel = $_GET["txtItemButtonLabel"];}   
$txtItemButtonType  = $_POST["txtItemButtonType"]; if ($txtItemButtonType == ""){$txtItemButtonType = $_GET["txtItemButtonType"];}   
$txtItemButtonLevel = $_POST["txtItemButtonLevel"]; if ($txtItemButtonLevel == ""){$txtItemButtonLevel = $_GET["txtItemButtonLevel"];}   
$txtRelatedItemValue  = $_POST["txtRelatedItemValue"]; if ($txtRelatedItemValue == ""){$txtRelatedItemValue = $_GET["txtRelatedItemValue"];}   
   
print <<<HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" src="js/jscolor/jscolor.js"></script>
<title>Create Shortcuts/Modifiers</title>
<script type="text/javascript" language="javascript">

function LoadForm(){
	var x = document.form1;
	
	//To Check later if the window is opened
	opener.document.retail.openwin.value = 1;
	opener.document.retail.submit();
	
	x.txtItemButtonValue.focus();
}


function CancelRecord() {
	var x = document.form1;
	
	x.PActionMode.value='';
	x.startrange.value=0;
	
	x.txtItemButtonId.value='';
	x.txtItemButtonValue.value='';
	x.txtItemButtonLabel.value='';
	x.txtItemButtonOrder.value='';
	x.txtItemButtonColor.value='';
	x.txtRelatedItemValue.value='';
	x.txtItemButtonLevel.value='';
	x.ItemButton_Width.value='';
	x.ItemButton_Height.value='';
	x.submit();
}

function SubmitRecord() {
	var x = document.form1;
	var result = CheckFields();
	
	if (result == 1) {
		x.PActionMode.value='Submit';
		x.submit();
	}
}

function UpdateRecord(ItemButtonId) {
	var x = document.form1;
	
	x.PActionMode.value='Edit';
	x.txtItemButtonId.value=ItemButtonId;
	x.submit();

}

function DeleteRecord(ItemButtonId) {
	var x = document.form1;
	
	if (confirm ( "Are you sure you want to Delete current record?"))
	{
		x.PActionMode.value='Delete';
		x.txtItemButtonId.value=ItemButtonId;
		x.submit();
	}	

}

function SetOrder(Option, ItemButtonId, ItemButtonOrder) {
	var x = document.form1;
	
	x.PActionMode.value=Option;
	x.txtItemButtonId.value=ItemButtonId;
	x.txtItemButtonOrder.value=ItemButtonOrder;
	x.submit();
}

function CheckFields(){
  
    var x = document.form1;
	
	var vValue = x.txtItemButtonValue.value;
	var vLabel = x.txtItemButtonLabel.value;
	
	if (vValue=='' && vLabel=='')
	{
		alert("Item Code of Description is mandatory!");
		x.txtItemButtonValue.focus();
		return 0;
	}
	/*else if (vLabel=='')
	{
		alert("Description is mandatory!");
		x.txtItemButtonLabel.focus();
		return 0;
	}*/
	
	
	else
	return 1 ;	
}


function SetNextPage(startrange, perpage){
	x=document.form1;
	
	x.startrange.value = startrange;
	x.action='Form_Retail_FastItem.php?startrange='+startrange+'&perpage='+perpage;
	x.submit();
}

function SetPrvPage(startrange, perpage){
	x=document.form1;
	
	x.startrange.value = startrange;
	x.action='Form_Retail_FastItem.php?startrange='+startrange+'&perpage='+perpage;
	x.submit();
}

function showlistItems(str){
  var vdate, vid, vItemBarCode, vItemWh;
  x = document.form1;
  
  window.open('List_ItemsBarcode.php?frm=3&PItem_Code=','mywindow','width=970,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');
}

function showlistItems1(str){
  x = document.form1;
  window.open('List_ItemsBarcode.php?frm=4&PItem_Code=','mywindow','width=970,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');
}
function ChangeType(PValue) {
	x=document.form1;
	x.txtItemButtonType.value = PValue;
	x.submit();
	
}
</script>
<style type="text/css">

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

}
</style>

</head>

<body onload="LoadForm()">
<form id="form1" name="form1" method="post" action="" enctype="multipart/form-data">
<input type='hidden' name='PActionMode' id='PActionMode'  value='$PActionMode' >
<input type='hidden' name='message' value='$message' size='200'>
<input type='hidden' name='startrange' value='$startrange'>
			
			


	
HERE;

if ($startrange=='') $startrange = 0;
if ($perpage=='')	 $perpage = 10;

if ($PActionMode == 'Submit') {
	$ErrorExists = 0;
	
	if ($txtItemButtonValue != '' && $txtItemButtonType != 'MODIFIER') {
		$sub_query = " Select Count(ItemButton_Value) From ItemButtons ".
					 " Where ItemButton_Value = '".$txtItemButtonValue."' And Upper(ItemButton_Type) = Upper('".$txtItemButtonType."')";
					 
		if ($txtItemButtonId != '')	$sub_query = $sub_query." And ItemButton_Id != '".$txtItemButtonId."'"; 
		$sub_result = selectData($connection, $sub_query);
		if ($sub_result[0] != 0) {
			$ErrorExists = 1;
			$message = 'Insert not allowed. Duplicate Code: '.$txtItemButtonValue;
		}

		$sub_query = " Select Count(Item_Code) From Items ".
					 " Where Item_Code = '".$txtItemButtonValue."'";
		$sub_result = selectData($connection, $sub_query);
		if ($sub_result[0] == 0) {
			$ErrorExists = 1;
			$message = 'Insert not allowed. Item Code: ('.$txtItemButtonValue.') Not Found.';
		}	

	}
	
	//$image = 'Null';
	if (isset($_FILES['photo']) && $_FILES['photo']['size'] > 0) { 

		$image_name = addslashes($_FILES['photo']['name']);
		$image_size = getimagesize($_FILES['photo']['tmp_name']);
		$image_type =$_FILES['photo']['type'];
			
		if ($image_size == FALSE) {
			$error['photo'] = "That's not an image.";
		
		}
		else {
			if ($_FILES['photo']['size'] > 204800) {
				$error['photo'] = "Image is too large.";
			}
			else {
				$image = addslashes(file_get_contents($_FILES['photo']['tmp_name']));
			}
		}	
	}
	
	if ($txtItemButtonId == '') {
		
		if (($txtItemButtonValue != "" || $txtItemButtonLabel != "") && $ErrorExists == 0){ 
			$sub_query = " Select ifNull(Max(ItemButton_Order),0) + 1 ".
						 " From ItemButtons Where Upper(ItemButton_Type) = Upper('".$txtItemButtonType."')";
			$sub_result = selectData($connection, $sub_query);
			$txtItemButtonOrder = $sub_result[0];
		
			fbegin();
			$query = " INSERT INTO ItemButtons (ItemButton_Value, ItemButton_Label, ItemButton_Order, ItemButton_Type, ItemButton_Color, ItemButton_Picture, ItemButton_Level, ItemButton_RelatedItem,ItemButton_Width,ItemButton_Height ) ".
					 " VALUES ( '".ereg_replace("'", "\'", trim($txtItemButtonValue))."', '".ereg_replace("'", "\'", trim($txtItemButtonLabel))."', '".$txtItemButtonOrder."', ".
					 "          '".$txtItemButtonType."', '".$txtItemButtonColor."', '$image', '".$txtItemButtonLevel."', '".$txtRelatedItemValue."', '".$ItemButton_Width."','".$ItemButton_Height."' )";
						 
				// echo $query."<br>";exit;	
			$result=mysql_query($query,$connection);
			//echo $query."<br>";exit;	
			
			if ($result){
				$PActionMode = '';
				fcommit();
				
				header ("Location: ./Form_Retail_FastItem.php?startrange=".$startrange."&txtItemButtonType=".$txtItemButtonType);	
			}else{
				$PActionMode = 'Add';
				$message  = mysql_error(); 
				frollback();
			}
	
		}
	} else {
		if (($txtItemButtonValue != "" || $txtItemButtonLabel != "") && $ErrorExists == 0){
			fbegin();
			$query = " UPDATE ItemButtons SET ".
					 " ItemButton_Value = '".ereg_replace("'", "\'", trim($txtItemButtonValue))."', ".
					 " ItemButton_Label = '".ereg_replace("'", "\'", trim($txtItemButtonLabel))."', ".
					 " ItemButton_Color = '".ereg_replace("'", "\'", trim($txtItemButtonColor))."', ".
					 " ItemButton_RelatedItem = '".ereg_replace("'", "\'", trim($txtRelatedItemValue))."', ".
					 " ItemButton_Level = '".ereg_replace("'", "\'", trim($txtItemButtonLevel))."', ".
					 " ItemButton_Picture = '$image', ".
					 " ItemButton_Width = '".$ItemButton_Width."',ItemButton_Height = '".$ItemButton_Height."' ".
					 " WHERE ItemButton_Id = '".$txtItemButtonId."'";
							 
					 
			$result=mysql_query($query,$connection);
			//echo $query."<br>";exit;	
				
			if ($result){
				$PActionMode = '';
				$txtItemButtonId = '';
				fcommit();
					
				header ("Location: ./Form_Retail_FastItem.php?startrange=".$startrange."&txtItemButtonType=".$txtItemButtonType);
			}else{
				$PActionMode = 'Edit';
				$message  = mysql_error(); 
				frollback();
			}
		}	
	}	
	
}

else if ($PActionMode == 'Delete' && $txtItemButtonId != '') {
	$ErrorExists = 0;
	
	fbegin();
	$query = " Delete From ItemButtons ".
			 " Where ItemButton_Id = '".$txtItemButtonId."'";
					 
	$result=mysql_query($query,$connection);
	//echo $query."<br>";exit;	
				
	if ($result){
		$PActionMode = '';
		$txtItemButtonId = '';
		fcommit();
					
		header ("Location: ./Form_Retail_FastItem.php?startrange=".$startrange."&txtItemButtonType=".$txtItemButtonType);
	}else{
		$PActionMode = 'Delete';
		$message  = mysql_error(); 
		frollback();
	}
	
}	

else if (($PActionMode == 'OrderUp' || $PActionMode == 'OrderDown') && $txtItemButtonId != '') {
	$ErrorExists = 0;
	$vNewOrder = 0;
	
	if (($PActionMode == 'OrderUp') || ($PActionMode == 'OrderDown' && $txtItemButtonOrder != 1)) {
	
		fbegin();
		if ($PActionMode == 'OrderUp') {
			$query = " Update ItemButtons Set ItemButton_Order = (ifNull(ItemButton_Order,1) + 1) ".
					 " Where ItemButton_Id = '".$txtItemButtonId."'";
		} else {
			$query = " Update ItemButtons Set ItemButton_Order = (ifNull(ItemButton_Order,1) - 1) ".
					 " Where ItemButton_Id = '".$txtItemButtonId."'";
		}
						 
		$result=mysql_query($query,$connection);
		//echo $query."<br>";exit;	
					
		if ($result){
			fcommit();
			
			if ($PActionMode == 'OrderUp') {
				$vNewOrder = $txtItemButtonOrder + 1;
				$query = " Update ItemButtons Set ItemButton_Order = (ifNull(ItemButton_Order,1) - 1) ".
						 " Where ItemButton_Order = '".$vNewOrder."' ".
						 " And ItemButton_Id != '".$txtItemButtonId."'";
			} else {
				$vNewOrder = $txtItemButtonOrder - 1;
				$query = " Update ItemButtons Set ItemButton_Order = (ifNull(ItemButton_Order,1) + 1) ".
						 " Where ItemButton_Order = '".$vNewOrder."' ".
						 " And ItemButton_Id != '".$txtItemButtonId."'";
			}
						 
			$result=mysql_query($query,$connection);
			//echo $query."<br>";exit;	
			
			if ($result){
				$PActionMode = '';
				$txtItemButtonId = '';
				$txtItemButtonorder = '';
				
				//fcommit();
				header ("Location: ./Form_Retail_FastItem.php?startrange=".$startrange."&txtItemButtonType=".$txtItemButtonType);
			} else{
				$PActionMode = '';
				$message  = mysql_error(); 
				frollback();
			}	
		}else{
			$PActionMode = '';
			$message  = mysql_error(); 
			frollback();
		}
	} else {
		$PActionMode = '';
		$txtItemButtonId = '';
		$txtItemButtonorder = '';
				
		header ("Location: ./Form_Retail_FastItem.php?startrange=".$startrange."&txtItemButtonType=".$txtItemButtonType);
	}			
	
}


if (empty($txtItemButtonType) && !isset($txtItemButtonType)) $txtItemButtonType = 'SHORTCUT';

if ($txtItemButtonId != '') {
	$sub_query = " Select ItemButton_Id, ItemButton_Value, ItemButton_Label, ItemButton_Order, ItemButton_Color, ItemButton_Type, ItemButton_Level, ItemButton_RelatedItem, ".
				 " ItemButton_Width, ItemButton_Height ".
				 " From ItemButtons ".
				 " Where ItemButton_Id = '".$txtItemButtonId."'";
					 
	$sub_result=selectData($connection, $sub_query);
		
	$txtItemButtonId     = $sub_result[0];
	$txtItemButtonValue  = $sub_result[1];
	$txtItemButtonLabel  = $sub_result[2];
	$txtItemButtonOrder  = $sub_result[3];
	$txtItemButtonColor  = $sub_result[4];
	//$txtItemButtonType   = $sub_result[5];
	$txtItemButtonLevel  = $sub_result[6];
	$txtRelatedItemValue = $sub_result[7];
	$ItemButton_Width = $sub_result[8];
	$ItemButton_Height = $sub_result[9];
}




echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='600px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:600px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Create Shortcuts/Modifiers</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";


 echo"<tr  height='25'>
		<td id='search-content1' style='height:34px; width:31px;'>&nbsp;</td>
		<td  align='left' id='search-content2'><table width='100%' align='left' border='0'>";
		
echo"	<tr >";
echo"	  <td align='left'>";
echo"		<input type='hidden' name='txtItemButtonType' id='txtItemButtonType' value='$txtItemButtonType' />";
echo"	  	<input type='radio' name='rdbItemButtonType' id='rdbItemButtonType' value='SHORTCUT' onclick=\"ChangeType(this.value);\" "; if ($txtItemButtonType == 'SHORTCUT') echo " checked "; echo "><span class='style1'>Shortcut</span>";
echo"	  	<input type='radio' name='rdbItemButtonType' id='rdbItemButtonType' value='MODIFIER' onclick=\"ChangeType(this.value);\" "; if ($txtItemButtonType == 'MODIFIER') echo " checked "; echo "><span class='style1'>Modifier</span>";
echo"	  	<input type='radio' name='rdbItemButtonType' id='rdbItemButtonType' value='NOTES' onclick=\"ChangeType(this.value);\" "; if ($txtItemButtonType == 'NOTES') echo " checked "; echo "><span class='style1'>NOTES</span>";
echo"	  </td>";
echo"	  <td align='right'>
			<button type='button' id='btnSubmit' name='btnSubmit' onclick='SubmitRecord(); return false;' title='Submit Record'><span><span>Submit</span></span></button>
			<button type='button' id='btnClear' name='btnClear' onclick='CancelRecord(); return false;' title='Cancel Record'><span><span>Cancel</span></span></button>";
echo"	  </td>";
echo"	</tr>";			
echo"	</table></td><td id='search-content3' style='width:31px;'>&nbsp;</td>
	</tr>";
	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  

echo"  <table width='600' border='0' cellspacing='1' align='left'>";

echo"	<tr bgcolor='#F7F7F7'>";
echo"	  <td width='80'><span class='style1'>Item Code</span></td>";
echo"	  <td width='160'>
			<input type='hidden' name='txtItemButtonId' id='txtItemButtonId' value='$txtItemButtonId' />
			<input type='hidden' name='txtItemButtonOrder' id='txtItemButtonOrder' value='$txtItemButtonOrder' />
			<input type='text' name='txtItemButtonValue' id='txtItemButtonValue' value='".htmlspecialchars($txtItemButtonValue, ENT_QUOTES)."' style='width:120px;' maxlength='45' />
			<label><img src='img/openlist.png' title=' Select Item '  width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistItems(1); ' /></label>
		  </td>";
echo"	  <td width='80' align='right'><span class='style1'>Color&nbsp;</span></td>";
echo"	  <td width='160'><input type='text' name='txtItemButtonColor' id='txtItemButtonColor' value='".htmlspecialchars($txtItemButtonColor, ENT_QUOTES)."' class='color' style='width:120px;' maxlength='50' /></td>";
echo"     <td width='120' rowspan='2'>
			<img src='GetButtonImage.php?option=fast&id=$txtItemButtonId' alt='Photo' style='width:50px; height:50px;'></img>
		  </td>";
echo"	</tr>";
echo "<tr><td width='80'><span class='style1'>Dimension</span></td><td colspan='2'><input type='text' name='ItemButton_Width' id ='ItemButton_Width' value='$ItemButton_Width' 
		onkeypress=\"return (event.charCode >= 48 &amp;&amp; event.charCode <= 57 ) || (event.charCode== 46)\" style='width:50px;'> X <input type='text' name='ItemButton_Height'
		id='ItemButton_Height' value='$ItemButton_Height'  onkeypress=\"return (event.charCode >= 48 &amp;&amp; event.charCode <= 57) || (event.charCode== 46)\" style='width:50px;'></td>";
echo "</tr>";		
 
echo"	<tr bgcolor='#F7F7F7'>";
echo"	  <td><span class='style1'>Description</span></td>";
echo"	  <td colspan='2' ><input type='text' name='txtItemButtonLabel' id='txtItemButtonLabel' value='".htmlspecialchars($txtItemButtonLabel, ENT_QUOTES)."' style='width:230px;' maxlength='100' /></td>";		  
echo"     <td><input type='file' name='photo' id='photo' style='width:200px;' accept='image/jpeg,image/gif,image/png'></td>";
echo"	</tr>";

if ($txtItemButtonType == 'MODIFIER' || $txtItemButtonType == 'NOTES') {
	echo"<tr bgcolor='#F7F7F7'>";
	echo"  <td><span class='style1'>Related Item</span></td>";
	echo"  <td>
			  <input type='text' name='txtRelatedItemValue' id='txtRelatedItemValue' value='".htmlspecialchars($txtRelatedItemValue, ENT_QUOTES)."' style='width:120px;' maxlength='45' />
			  <label><img src='img/openlist.png' title=' Select Item '  width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistItems1(1); ' /></label>
		   </td>";
	echo"  <td align='right'><span class='style1'>Level&nbsp;</span></td>";
	echo"  <td colspan='2'><input type='text' name='txtItemButtonLevel' id='txtItemButtonLevel' value='".htmlspecialchars($txtItemButtonLevel, ENT_QUOTES)."' style='width:50px;' maxlength='2' /></td>";		  
	echo"</tr>";
} else {
	echo"<input type='hidden' name='txtRelatedItemValue' id='txtRelatedItemValue' value='' maxlength='45' />";
	echo"<input type='hidden' name='txtItemButtonLevel' id='txtItemButtonLevel' value='' maxlength='45' />";
}

echo "</table></td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";

echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";
echo"  <div style='overflow-y:scroll;height:250px;width:600px;border:0px solid #000000;' ><table width='580' border='0' cellspacing='1' align='left'>";		 
echo"<tr class='Search-Label-bg' height='25px'>
      <td width='15'>&nbsp;</td>
	  <td width='15'>&nbsp;</td>
	  <td width='15'>&nbsp;</td>
	  <td width='15'>&nbsp;</td>
      <td width='100'><span class='style1'>Item Code </span></td>
      <td width='410'><span class='style1'>Description </span></td>
    </tr>";

$sub_query= " Select Min(ItemButton_Order), Max(ItemButton_Order) ".
			" From ItemButtons ";
$sub_result = selectData($connection, $sub_query);
$MinOrder = $sub_result[0];
$MaxOrder = $sub_result[1];
			
$sub_query= " Select ItemButton_Id, ItemButton_Value, ItemButton_Label, ItemButton_Order ".
			" From ItemButtons ";
			
if ($txtItemButtonType == 'MODIFIER') $sub_query .= " Where Upper(ItemButton_Type) = 'MODIFIER' ";
else if ($txtItemButtonType == 'NOTES') $sub_query .= " Where Upper(ItemButton_Type) = 'NOTES' ";
else $sub_query .= " Where Upper(ItemButton_Type) = 'SHORTCUT' ";
			
$sub_query .= " Order By Lpad(ItemButton_Order,10,'0') Desc ";
		

$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($sub_result);

		
$sub_query = $sub_query." limit ".$startrange.",".$perpage;

$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
while($sub_rows=mysql_fetch_array($sub_result)){
	
	extract($sub_rows);

	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";		

    
	echo"<tr $Color>";
	
	if ($ItemButton_Order != $MaxOrder)
		echo " <td align='center' valign='center'><span class='style15'><img src='img/desc_order.png'  onMouseOver=\"style.cursor='hand'\" onclick=SetOrder('OrderUp','".$ItemButton_Id."','".$ItemButton_Order."') title='Order Up'  ></span></td>";
	else
		echo " <td align='center' valign='center'>&nbsp; </td>";

	if ($ItemButton_Order != $MinOrder)	
		echo " <td align='center' valign='center'><span class='style15'><img src='img/asc_order.png'  onMouseOver=\"style.cursor='hand'\" onclick=SetOrder('OrderDown','".$ItemButton_Id."','".$ItemButton_Order."') title='Order Down'  ></span></td>";
	else
		echo " <td align='center' valign='center'></td>";
		
	echo " <td align='center' valign='center'><span class='style15'><img src='img/edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateRecord('".$ItemButton_Id."') title='Edit Record'  ></span></td>";
	echo " <td align='center' valign='center'><span class='style15'><img src='img/delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteRecord('".$ItemButton_Id."') title='Delete Record'  ></span></td>";
	echo"  <td align='left'><span class='style1'>$ItemButton_Value</span></td>";
	echo"  <td align='left'><span class='style1'>$ItemButton_Label</span></td>";
    echo"</tr>";
	
}
	 echo "</table></div></td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";

echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";	 
echo"<table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' align='center'>";
		
$diff= $startrange - $perpage;
		
if (($diff) >= 0 ){
	$prvstartrange = $startrange - $perpage;
	echo"<img src='img/arrowleft.jpg' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
}
else
	echo "&nbsp;";
		
echo"</td><td width='150' align='center'>";
		
if ($startrange <= $totalrows){
	$startrange = $startrange + $perpage;
	if  ($startrange < $totalrows)
		echo"<img src='img/arrowright.jpg' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
} else
	echo "&nbsp;";
			
echo"</td><td width='40'>&nbsp;</td></tr>";
 echo "</table></td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";



echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:560px;' valign='top'></td>
		<td id='search-bottom3' style='height:34px; width:31px;' valign='top'></td>";
echo" </tr>";



function fbegin()
{
	mysql_query("START TRANSACTION");
}
function fcommit(){
	mysql_query("COMMIT");
}
function frollback()
{
	mysql_query("ROLLBACK");
}

print <<<HERE
  </table>
</form>
</body>
</html>

HERE;
?>