<? 
$adjacents = 3;
$page =1;
if(mysql_query($query)){
	$total_pages =mysql_num_rows(mysql_query($query));
	}
	$targetpage = "emp-leave-req-view.php"; 	
	$limit = 1000; 	
	
	if(isset($_GET['page']))
	{							
	$page = $_GET['page'];
	}
	if($page) 
	$start = ($page - 1) * $limit; 			
	else
	$start = 0;	
	
	if ($page == 0) $page = 1;					
	$prev = $page - 1;							
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$lpm1 = $lastpage - 1;						
	
	
	$pagination = "";
	if($lastpage > 1)
	{	
	$pagination .= "<div class=\"pagination\">";
	if ($page > 1) 
	$pagination.= "<a href=\"javascript:".$function."($prev,'0')\">« previous</a>";
	else
	$pagination.= "<span class=\"disabled\">« previous</span>";	
	if ($lastpage < 7 + ($adjacents * 2))	
	{	
	for ($counter = 1; $counter <= $lastpage; $counter++)
	{
	if ($counter == $page)
	$pagination.= "<span class=\"current\">$counter</span>";
	else
	$pagination.= "<a href=\"javascript:".$function."($counter,'0')\">$counter</a>";					
	}
	}
	elseif($lastpage > 5 + ($adjacents * 2))	
	{
	if($page < 1 + ($adjacents * 2))		
	{
	for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
	{
	if ($counter == $page)
	$pagination.= "<span class=\"current\">$counter</span>";
	else
	$pagination.= "<a href=\"javascript:".$function."(".$counter.",'0')\">$counter</a>";					
	}
	$pagination.= "...";
	$pagination.= "<a href=\"javascript:".$function."(".$lpm1.",'0')\">$lpm1</a>";
	$pagination.= "<a href=\"javascript:".$function."(".$lastpage.",'0')\">$lastpage</a>";		
	}
	elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
	{
	$pagination.= "<a href=\"javascript:".$function."(1,'0')\">1</a>";
	$pagination.= "<a href=\"javascript:".$function."(2,'0')\">2</a>";
	$pagination.= "...";
	for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
	{
	if ($counter == $page)
	$pagination.= "<span class=\"current\">$counter</span>";
	else
	$pagination.= "<a href=\"javascript:".$function."(".$counter.",'0')\">$counter</a>";					
	}
	$pagination.= "...";
	$pagination.= "<a href=\"javascript:".$function."(".$lpm1.",'0')\">$lpm1</a>";
	$pagination.= "<a href=\"javascript:".$function."(".$lastpage.",'0')\">$lastpage</a>";		
	}
	else
	{
	$pagination.= "<a href=\"javascript:".$function."(1,'0')\">1</a>";
	$pagination.= "<a href=\"javascript:".$function."(2,'0')\">2</a>";
	$pagination.= "...";
	for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
	{
	if ($counter == $page)
	$pagination.= "<span class=\"current\">$counter</span>";
	else
	$pagination.= "<a href=\"javascript:".$function."(".$counter.",'0')\">$counter</a>";					
	}
	}
	}
		
	if ($page < $counter - 1) 
	$pagination.= "<a href=\"javascript:".$function."(".$next.",'0')\">next »</a>";
	else
	$pagination.= "<span class=\"disabled\">next »</span>";
	$pagination.= "</div>\n";		
	}
	?>	