<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}
include("config.inc.php");
include("supplier_function.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(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

class tabs {
	var $name;
	var $tabs;
	var $active;
	var $current;
function start($name){
		if (empty($this->active)){ $this->active = $name; }
		$this->current = $name;
		ob_start();
	}
	function end(){
		$this->tabs[$this->current] = ob_get_contents();
		ob_end_clean();
	}
	function run(){
	
	
	
		if (count($this->tabs) > 0){
			echo "<DIV CLASS='tabs'>\n";
			$jsClear = "";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				$jsClear .= "\tdocument.getElementById('$tabid').className = 'tab_inactive';\n";
				$jsClear .= "\tdocument.getElementById('$contentid').style.display = 'none';\n";
			}
			echo "<script type=\"text/javascript\">\n";
			echo "function tab_".$this->name."(id,fieldname){\n";
			echo "$jsClear";
			
			echo "\tdocument.getElementById('tab_".$this->name."_'+id).className = 'tab_active';\n";
			echo "\tdocument.getElementById('tabcontent_".$this->name."_'+id).style.display = '';\n";
			
			echo"	
				//alert(fieldname);
				if(fieldname!='' && fieldname!=undefined)
					
					document.clientdt[fieldname].focus();
				";
			echo "}\n";
			echo "</script>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV CLASS='";
				if ($this->active == $tabname){ echo "tab_active"; }else{ echo "tab_inactive"; }
				echo "' ID='$tabid' ";
				echo "onClick=\"tab_".$this->name."('$tabname');\">$tabname</DIV>\n";
			}
			echo "<DIV STYLE='float: center; clear:both;'></DIV>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display: ";
				if ($this->active == $tabname){ echo "block"; }else{ echo "none"; }
				echo ";'>$tabcontent</DIV>\n";
			}
			echo "</DIV>\n";
			echo "<DIV STYLE='clear: both;'></DIV>\n";
		}}
}

$query_language  = "select user_account, Language from ".$_SESSION['dbLabel'].".login  where user_account = '".$_SESSION['useraccount']."'";
$result_language = mysql_query($query_language, $connection); 
$row_language    = mysql_fetch_array($result_language);
extract($row_language);

$query_cost_labels  = "select Language as Language1, Code as Code1, Name as Name1, Deactivate as Deactivate1, CreationDate as CreationDate1, Parent as Parent1, AddCostCenter as AddCostCenter1
                       From ".$_SESSION['dbLabel'].".costcenter_label
                       where language = '".$Language."'";
$result_cost_labels = mysql_query($query_cost_labels, $connection);
$row_cost_labels    = mysql_fetch_array($result_cost_labels);
extract($row_cost_labels);
$query_project  = "select Costcenter as Costcenter1, ResultsPage as ResultsPage1
                   from ".$_SESSION['dbLabel'].".mainform_label
				   where Language = '".$Language."'";
$result_project = mysql_query($query_project, $connection);
$row_project    = mysql_fetch_array($result_project);
extract($row_project);

$query_navigator = "SELECT LANGUAGE,
       ClearPage,
       Excel,
       Save,
       Print,
       Addd,
       SEARCH,
       Pending,
       CopyJV,
       PaymentRequests,
       ExportExcel
FROM ".$_SESSION['dbLabel'].".mainform_label
WHERE LANGUAGE = '".$Language."'";
$result_navigator = mysql_query($query_navigator, $connection);
$row_navigator    = mysql_fetch_array($result_navigator);
extract($row_navigator);


$querylog="SELECT CostCenter as loginaccess 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);
	}

if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
	
$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2,maxperpage from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
	

//User Access
$querylog=" select ifNull(FA_CostCenterApp,0) As FA_CostCenterApp, ifNull(FA_CostCenterDel,0) As FA_CostCenterDel,".
          " FA_CostCenterMod As FA_CostCenterMod  from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
//echo$querylog;
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

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

if(!isset($mode))
$mode='';

if($Costcent_active=='')
	$Costcent_active=0;

$saveEnabled = 0;
if ( ($FA_CostCenterMod == 1 && $mode=='editmode') || ($FA_CostCenterApp == 1))
	$saveEnabled = 1;

if($mode=='editmode' or $mode=='view'){

	$query_edit="select Costcent_Id, Costcent_code,Costcent_name, date_format(Costcent_CreationDate,'%d-%m-%Y'),Costcent_Deactivate,parent_code
	 from Costcent where Costcent_Id='".$Costcent_Id."'";

	 $resultedit = mysql_query($query_edit, $connection);
	while($row=mysql_fetch_array($resultedit)){

	$Costcent_Id=$row[0];
	$Costcent_code=$row[1];
	$Costcent_name=$row[2];
	$Costcent_CreationDate=$row[3];
	$Costcent_active=$row[4];
	$parent_code=$row[5];

	}
	$mode='edit';
}

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/tabs.css">
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<script type="text/javascript" src="jquery-1.9.1.js"></script>
<script type="text/javascript" language="javascript">

function saveval(){

	var Costcent_code 	= document.CostCent.Costcent_code.value;
	var cost_id 		= document.CostCent.cost_id.value;
	var cost_percentage = document.CostCent.cost_percentage.value;
	var cost_number 	= document.CostCent.cost_number.value;

if (cost_id == ''){
	alert("Please select a Costcenter first!");
	return 0;

} else { 
	document.getElementById('loadergif').style.display = 'block';
		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.split("[BRK]");
					document.getElementById('childdiv').innerHTML = '';
					document.getElementById('childdiv').innerHTML = data[1];

					
				}
			  }
		xmlhttp.open("GET","Form_CostCenter_Actions.php?mode=&modedt=saveval&Costcent_code="+Costcent_code+"&cost_id="+cost_id+"&cost_percentage="+cost_percentage+"&cost_number="+cost_number,true);
		xmlhttp.send();
	}

	
}


function editmode () {

	document.CostCent.action="Form_CostCenter.php?mode=edit";
	document.CostCent.submit();
}

function AddCostCent () {
	ClearForm('All');
	document.CostCent.mode.value='insert'; 
	document.CostCent.action="Form_CostCenter.php";
	document.CostCent.submit();
}



function SubmitRecord() {
var perpage=document.CostCent.perpage.value; 
if (document.CostCent.Costcent_code.value=='' )
		{alert('Unable to save : check missing field Code ');
		document.CostCent.Costcent_code.focus();
	}
		
else  if (document.CostCent.Costcent_name.value=='' )
		{alert('Unable to save : check missing field Name ');
		document.CostCent.Costcent_name.focus();
		}
		
		else {
		
		document.CostCent.action="Form_CostCenter_Actions.php?&perpage='+perpage";
				document.CostCent.submit();
		
		}


}


function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		
		x.cost_percentage.value='';
		x.cost_number.value='';
		x.cost_id.value='';
		x.mode.value='';
		x.message.value='';
		x.action='Form_CostCenter.php';
		x.submit();
	}	
}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.CostCent;
	x.Costcent_Id.value='';
	x.Costcent_code.value='';
	x.Costcent_name.value='';
	x.Costcent_CreationDate.value='';
	x.Costcent_active.value='';
	x.parent_code.value='';
	
}

/*
function SearchForCostCent(){
    ClearForm('All');
    x = document.CostCent;
    win = window.open('Form_CostCenterSearch.php', 'Form_CostCenterSearch', '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_CostCenterPreview.php';
	window.open(str);

}



function ExportExcel() {
	var str = 'Form_CostcentExcel.php';
	window.open(str);
}


function ChkActive(){

	x = document.CostCent;
	if(x.Chk_Active.checked)
		x.Costcent_active.value=1;
	else x.Costcent_active.value=0;	
}

function SetCostcent(CostcentId){
	
	document.CostCent.Costcent_Id.value=CostcentId;
	document.CostCent.message.value='';
	document.CostCent.mode.value='editmode';
	document.CostCent.submit();
}
function SetCostcent1(CostcenterID){
	document.CostCent.cost_id.value=CostcenterID;
	document.CostCent.submit();
}

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

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

function Opencostcenter(){
	XPos = (screen.availHeight - 560) / 2;
	YPos = (screen.availWidth - 970) / 2;
	
    win = window.open('Form_NewCostcenter.php?pagetype=C', 'Form_NewCostcenter', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=550,height=280,left='+YPos+',top='+XPos);		
	win.creator = self;
	win.focus();
}

function SearchForCostCent(){
	x = document.CostCent;
	document.CostCent.action='Form_CostCenter.php?startrange=0';
	document.CostCent.submit();
}

function ClearKeyword(){
	x = document.CostCent;
	x.txtKeyword.value='';
	document.CostCent.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.CostCent.action='Form_CostCenter.php?startrange=0';
	document.CostCent.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.CostCent.mode.value='delete';	
		
		document.CostCent.action='Form_CostCenter_Actions.php?CostCentId='+Code;
		document.CostCent.submit();
		document.CostCent.submit();
	}
					
}

function set_limit(){

	perpage=document.CostCent.perpage.value;
	document.CostCent.action='Form_CostCenter.php?perpage='+perpage+'&startrange=0';
	document.CostCent.submit();
}

function returnMsg(){
	alert('Access Denied!');
	return 0;
}


function SetCostcent1(cost_id){
	var Costcent_code = document.CostCent.Costcent_code.value;

	if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = xmlhttp.responseText.split("[BRK]");
				document.getElementById('childdiv').innerHTML = '';
				document.getElementById('childdiv').innerHTML = data[1];
				
			}
		  }
	xmlhttp.open("GET","Form_CostCenter_Actions.php?mode=&modedt=SetCostcent1&Costcent_code="+Costcent_code+"&cost_id="+cost_id,true);
	xmlhttp.send();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>$AddCostCenter1</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;
}
.style1 {color: #999999; font-weight: bold; }
.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;}

</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>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
</head>
<body >
<form name='CostCent' method='post' onKeyPress="return submitenter(this,event)">
<input type=hidden name='mode' value='$mode'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='Costcent_Id' value='$Costcent_Id'>
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'>";
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' style='text-transform: uppercase'>".$Costcenter1."</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'>
									<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>$ClearPage</span></span></button>
									<button type='button' id='btnPost' name='btnPost' onclick=\"";
if ($saveEnabled == 1)
	echo "SubmitRecord(1); ";
else 
	echo "returnMsg(); ";
	echo "return false;\" title='Save Changes'><span><span>$Save</span></span></button>
				<button type='button'  name='btnPrint' type='button' id='btnPrint'   onclick='PrintPreview();' $style title='Print' ";
			if ($mode=='')
						echo " disabled ";
echo" onclick='PrintPreview(;' $style	title='Print' /><span><span>$Print</span></span></button>
									<button type='button' id='btnExcel' name='btnExcel' onclick='ExportExcel(); return false;' title='Export Excel' ><span><span>$Excel</span></span></button>
									<button type='button' id='btnnewcost' name='btnnewcost' onclick='Opencostcenter(); return false;' title='New Cost' ><span><span>New Costcenter</span></span></button>
								</td>
								
								<td align='left' width='250px'>
									<input type='text' name='txtKeyword' value='$txtKeyword' style='width:105px;' onKeyPress='return submitenter(this,event)'>
									<button type='button' id='btnSearch' name='btnSearch' onclick='SearchForCostCent(); return false;' title='Search CostCenter'><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>".$ResultsPage1."</b></span>
									<span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
									if ($startrange=='')
										$startrange = 0;
									if ($perpage=='')
										$perpage = 20;
									//row limit loop
									foreach ($config['trowlimit'] as $value) {
										echo "<option value='$value' ";
										if($value==$perpage) echo "selected";
										echo " >$value</option>";
									}
echo"							</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					
					<td id='content-body'><table width='97%'><col width=5%><col width=95%><tr><td></td><td>";

					$tabs = new tabs("CostCenter");

					$tabs->start("Main Page");

					echo"	<table border='0'  align='center' valign='top' width='1100px' class='tablecontent'  >
							<col width=65%>
							<tr bgcolor='#F7F7F7' >
								<td valign='top' align='left'>
									<table border='0' style='table-layout:fixed' align='left' valign='top'>
										<col width=120>
										<tr bgcolor='#F7F7F7' height='25'>
											<td valign='center' align='left' ><span class='style1'>".$CreationDate1."&nbsp;<span class='style26'>*</span></span></td>";
			 
												if($mode!=''){
														
													$today = date('d-m-Y');
												$Costcent_CreationDate = $today;
												}		
 echo"										<td align='left'>
												<input type='text' name='Costcent_CreationDate' id='Costcent_CreationDate' value='$Costcent_CreationDate' style='font-size:12px; width:100px; height:18px;' readonly />";
												if ($mode!=''){
													$Costcent_CreationDate = "disabled";
												}

echo" 										</td>
										</tr>
										<tr bgcolor='#F7F7F7' height='25'>
											<td valign='center' align='left' ><span class='style1'>".$Code1."&nbsp;<span class='style26'>*</span></span>
											<td align='left'><input type='text' name='Costcent_code'  value='".htmlspecialchars($Costcent_code, ENT_QUOTES)."' style='font-size:12px; width:100px; height:18px;'  $status maxlength='20' /></td>
										</tr>
										<tr bgcolor='#F7F7F7' height='25'>
											<td valign='center' align='left' ><span class='style1'>".$Name1."&nbsp;<span class='style26'>*</span></span>
											<td><input type='text' name='Costcent_name' value='".htmlspecialchars($Costcent_name, ENT_QUOTES)."' style='font-size:12px; width:400px; height:18px;'  $status maxlength='100' /></td>
										</tr>";
										
										$query="select costcent_code,costcent_name from costcent where (parent_code is null  or parent_code='') ";
										$result_parent=mysql_query($query,$connection);


echo"									<tr bgcolor='#F7F7F7' height='25'>
											<td valign='center' align='left' ><span class='style1'>".$Parent1." &nbsp;</span></td><td>
												<select name='parent_code'  $dis>
													<option value=''></option>";
														while ($rowwp=mysql_fetch_row($result_parent)){
															if ($parent_code==$rowwp[0])
																echo "<option value='$rowwp[0]' selected>$rowwp[0] - $rowwp[1]</option>";
															else
																echo "<option value='$rowwp[0]'>$rowwp[0] - $rowwp[1]</option>";
														}
echo"											</select>
											</td>
										</tr>
										<tr bgcolor='#F7F7F7' height='25'>
											<td valign='center' align='left' ><span class='style1'>$Deactivate1</span>
											<td align='left'><input type='checkbox' name='Chk_Active' ";if($Costcent_active==1) echo ' checked ';echo"onclick='ChkActive();' $dis>
												<input type='hidden' name='Costcent_active' value='".htmlspecialchars($Costcent_active, ENT_QUOTES)."' style='font-size:12px; width:400px; height:18px;'  $status maxlength='50' />
											</td>
										</tr>
									</table>
								</td>
							</tr>
							";

						
	echo "</table>";								
$tabs->end();
if ($Costcent_code!=''){
									$tabs->start("Calculations");
									echo"	<table border='0'  align='center' valign='top' width='100%' class='tablecontent' >
									<tr bgcolor='#F7F7F7' >
								<td valign='top' align='left'><div id='childdiv' style='height:350px;'>";

							getCostcentChild($Costcent_code, $cost_id, $connection);
											
echo "										</div>	</td>
											</tr>
										";
											
													
															
echo"	</table>";


	$tabs->end();
}
	$tabs->run();
	
echo"</td></tr>";
echo "<tr><td></td>
			<td  valign='top'style='width:1100px;'>
				<table style='width:1100px;' border='0' cellspacing=0>
					<col width=150>
					<col width=500>
					<col width=500>
					<tr style='background-color:darkgray;'>
						<td align='left' ></td>
						<td align='left' ><span class='style1'><b>".$Code1."</b></td>
						<td align='left' ><span class='style1'><b>".$Name1."</b></td>
					</tr>
				</table>
			</td>
	</tr>";
echo"		<tr><td></td><td><table  border='0' width='1100px;'>
													<col width=30>
													<col width=170>
													<col width=162>";

													$querysearch="select costcent_id,costcent_code,costcent_name from costcent ";
													$querysearch=$querysearch." where (costcent_code like"."('%".$txtKeyword."%') or costcent_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' && $Costcent_Id==$rows[0]){
																
																$Color="style='background-color:#1e87a5'";
																$stylefont='style28';
														}	
																		
													echo'<tr '.$Color.' height="20px" >';
															
															if($FA_CostCenterDel==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($FA_CostCenterMod==1) echo " onclick=SetCostcent('$rows[0]');";echo"><span class='$stylefont' >$rows[1]&nbsp;</span></font></td>
															<td style='cursor:pointer;' ";if($FA_CostCenterMod==1) echo " onclick=SetCostcent('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[2]&nbsp;</span></font></td>";
echo"													</tr>";
}		
echo"												</table>";
												//	</div>
echo "											</td>
											</tr>
										<tr>
											<td >&nbsp;</td>
											<td align='center'>";
												$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"										&nbsp;&nbsp;&nbsp;&nbsp;";
												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>
									";
echo "</table></td>";

echo"</tr>";



	
	

echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	
echo" </table>  ";//end of last table menu		 



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

HERE;

?>
