function writePages (c_page, n_index, n_pages) 
{
	var n_links = n_pages;
	
	document.write('<table cellpadding="3" cellspacing="0" border="0" align="center"><tr>');	
	if (n_index != 1)
	{
		document.write('<td>');
		document.write('  <a href="' + c_page + '?pag=1><img src="images/button_page_first.gif" alt="Prima pagina" width="20" height="20" border="0"></a>');
		document.write('  <a href="' + c_page + '?pag=' + (n_index - 1) + '"><img src="images/button_page_prev.gif" alt="Precedente" width="20" height="20" border="0"></a>');
		document.write('</td>');
	}
	document.write('<td>Pagina ' + n_index + ' di ' + n_pages + '.</td>');

	if (n_links) 
	{
		if (n_links > n_pages)
			n_links = n_pages;
		
		document.write('<td>Pagina: ');
		var n_sideLinks = Math.floor((n_links - 1) / 2), n_firstLink, n_lastLink;
		
		if (n_index + n_sideLinks >= n_pages) 
		{
			n_firstLink = n_pages - n_links + 1;
			n_lastLink = n_pages;
		}
		else if (n_index - n_sideLinks <= 0) 
		{
			n_firstLink = 1;
			n_lastLink = n_links;
		}
		else 
		{
			n_firstLink = n_index - n_sideLinks;
			n_lastLink = n_firstLink + n_links - 1;
		}
		for (var i = n_firstLink; i <= n_lastLink; i++)
			document.write(i == n_index ? i + ' ' : '<a href="' + c_page + '?pag=' + i + '" title="Vai a pagina ' + i + '">' + i + '</a> ');
		document.write('</td>');
	}
	
	if (n_index != n_pages)
	{
		document.write('<td>');
		document.write('  <a href="' + c_page + '?pag=' + (n_index + 1) + '"><img src="images/button_page_next.gif" alt="Prossima" width="20" height="20" border="0"></a>');
		document.write('  <a href="' + c_page + '?pag=' + n_pages + '"><img src="images/button_page_last.gif" alt="Ultima pagina" width="20" height="20" border="0"></a>');
		document.write('</td>');
	}
	document.write('</tr></table>');
}
