<?php
print <<<HERE
<script>
function deletestaff(code){
		var staffcode=document.getElementById('searchby').value;
			var searcchcondition=document.getElementById('searcchcondition').value;
		if (confirm ( "Are you sure you want to Delete this Record ?")){
		
		
 if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
				//document.getElementById('staffchanging').innerHTML='';
					document.getElementById('staffsearch').innerHTML=xmlhttp.responseText;
					
				}
		}
  }

  
xmlhttp.open("GET","staff_action.php?actionmode=deletestaff&code="+code+"&staffcode="+staffcode+"&searcchcondition="+searcchcondition,true);
xmlhttp.send();
	}}
	
	function searchforvalue(){
	var staffcode=document.getElementById('searchby').value;
	var searcchcondition=document.getElementById('searcchcondition').value;
	//var fromto=document.getElementById('fromto').value;
	//alert(searcchcondition);
	//alert('dg');
	 if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 	
					document.getElementById('staffsearch').innerHTML=xmlhttp.responseText;
					//alert('dg');
				}
		}
  }

  
xmlhttp.open("GET","staff_action.php?actionmode=staffsearch&staffcode="+staffcode+"&searcchcondition="+searcchcondition,true);
xmlhttp.send();

}
function editstaff(codehouse){
		opener.document.form.staff_code.value=codehouse;
		opener.document.form.submit();
		self.close();		
}

/*function SetNextPage(startrange,perpage){ 
	document.search.action='staffsearch.php?keyword=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

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

function SetFirstPage(startrange,perpage){
	document.search.action='staffsearch.php?startrange=0&perpage='+perpage;
	document.search.submit();
}

function SetLastPage(perpage,totalrows){
	var result=totalrows % perpage;
	if (result == 0) result = perpage;
	startrange=totalrows-result;
	document.search.action='staffsearch.php?startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SearchKeyword(){
	document.search.action='staffsearch.php?startrange=0';
	document.search.submit();
}*/


	</script>
HERE;
session_start();

if($_SESSION['dbName']==""){
	header("location:../index.php");
}
include("config.inc.php");
//include("function_staff.php");
include("stafffunction.php");
//include("stafffunction.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");
$perpage    = $_POST["perpage"]; if ($perpage == ""){$perpage = $_GET["perpage"];}
$startrange = $_POST["startrange"]; if ($startrange == ""){$startrange = $_GET["startrange"];}
if ($perpage=='')     $perpage = 2;
echo "<div id='staffsearch'>";
staffsearch($connection,'','');
//staffchanging($connection,'');
/*echo "<table>";
echo "<tr><td></td><td>";
echo "<table  align='left' border='1' style='table-layout:fixed'  style='width:100%; margin_left:10px;'>";
echo"<col width=10>
<col width=10>
<col width=100>
<col width=100>
<col width=100>";

$querysetup="select grid_color1,grid_color2,DecimalBase, DecimalBase1, DecimalBase2, base1, base2, maxperpage from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());

echo"<tr>";
		//<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	echo "<td id='search-top2' style='height:34px; width:908px' align='center' valign='middle' colspan='5'>
			<table style='border:solid 1px white'>
			<tr><td ><span class='style3'>List of Staff</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";
echo "
	  <tr bgcolor='#DDDDDD' height=30px>
	    <td align='left' colspan='3'><span class='style1'>Search by Name/No</span></td>
		<td align='left' colspan=''><span class='style1'><input type='text' name='searchby' id='searchby' value='$code' size='15' maxlength='30'/>";
		//<input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/>
		echo "</span>
		    <button type='button' name='Submit' value='Find' onclick='searchforvalue()' /><span><span>Find</span></span></button>
			<button type='button' name='btnCancel' value='Cancel' onclick='clearform();'/><span><span>Cancel</span></span></button></td>
		<td  colspan='' align='left' valign='center'><span class='style4'>Result/page</span><span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
         echo "  <tr bgcolor='' height=30px><td colspan='5' align='center'>perpage:
		 <select name='perpage' id='perpage'>
		 <option value='10'>10</option>
		 <option value='20'>20</option>
					<option value='30'>30</option>
		 </select >
		  </td></tr> "; 
//echo "<tr><td colspan='3'> search by name /No </td><td><input type='text name='searchby' id='searchby' value='$code'></td>
//<td><button type='button' onclick='searchforvalue()'><span><span>search</span></span>
//</td></tr>";
if($result=mysql_fetch_array($resultsetup)){
	$grid_color1=$result[0];
$grid_color2=$result[1];}
echo "<tr  height='30px' style='background-color:darkgray;'>
		<td  align='center'><span class='style1'></span></td>
		<td  align='center'><span style='style1'></span></td>
		<td  align='center' ><span style='style1'>staff code</span></td>
		<td  align='center'><span style='style1'> staff first name</span></td>
		<td align='center'><span style='style1'>staff last name</span></td>
	</tr>";
	if ($code=='')
	{$staffinf="select staff_code, staff_firstname,staff_lastname from staff";}
else {$staffinf="select staff_code, staff_firstname,staff_lastname from staff where staff_code like '%$code%' or staff_firstname like '%$code%' "; }
	$result=mysql_query($staffinf, $connection) or die(mysql_error(''));
	$i=0;
	while($rows=mysql_fetch_array($result)){
		if($i%2==0)
								$Color="style='background-color:".$grid_color1."'";
							else			
								$Color="style='background-color:".$grid_color2."'";
		echo "<tr height='20px'>";
		echo"<td align='center'><img src='img/c_delete.png' onmouseover=\"style.cursor='pointer'\" name='' title='Delete' onclick=\" deletestaff('$rows[0]')\"></td>";
		echo"<td align = 'center' ><img src='img/button_edit.png' onmouseover=\"style.cursor='pointer'\" id = '$imgSubmit[$i]' name='$imgSubmit[$i]' title='Save' onclick=\"editstaff('$rows[0]')\"></td>";
		echo "<td $Color  class='roundedtext_countrycode' >  $rows[0]</td>" ;
		echo "<td $Color  class='roundedtext_countrycode'>  $rows[1]</td>" ;
		echo "<td $Color  class='roundedtext_countrycode'>  $rows[2]</td>" ;
	/*	
		echo "<td><input type='text' $Color class='roundedtext_countrycode' value= '$rows[2]'></td>" ;*/
		/*echo "</tr>";
		$i++;
		
}
echo "</table>";
echo "</td></tr></table>";*/
	echo "</div>";




?>