<select name=\"totalPP\" onchange=\"reload('".$id."','".$sub."','".$pagina."',this.value,'".$layout->image_path."')\">";
								?>
										<option value="10" <? if($totalPorPagina == 10) { echo "selected"; } ?> >10</option>
										<option value="15" <? if($totalPorPagina == 15) { echo "selected"; } ?> >15</option>
										<option value="30" <? if($totalPorPagina == 30) { echo "selected"; } ?> >30</option>
										<option value="50" <? if($totalPorPagina == 50) { echo "selected"; } ?> >50</option>
								<?
								echo "</select>
								</li>
							</ul></div>";
							
							$inicio = $pagina * $totalPorPagina;
						
							$regra .= "Order by detalhe DESC, acessos DESC, nome ASC";
							
							$anuncio = $anuncioDAO->Paginacao($regra, $inicio, $totalPorPagina);
							
							$layout->mostraAnuncios($anuncio);
							
							$pagina = $pagina + 1;
							$layout->paginacaoAnuncio($pagina,$paginas,$id,$sub,$totalPorPagina);
						} else {
							echo "Sem anúncios no cadastro";
						}
					?>
					
				</div>
			</div>
		</div>
		<?php 
echo $layout->lateralDireita($banners);
		function AnuncioMostra($totRegistrosPorPagina) { 
			$anuncio = new Anuncio();
			$anuncioDAO = new AnuncioDAO();
			
			$iddepartamento = $_GET["iddepartamento"];
			$idsubdepartamento = $_GET["idsubdepartamento"];
			$letra = $_GET["letra"];
			
			$pagina = $_GET["pag"];
			if(!isset($pagina)) { $pagina = 0;}
			
			if(isset($_GET["letra"])) {
				if(!isset($iddepartamento)) {
					$order = "WHERE nome LIKE '$letra%' ORDER BY idanuncio";
				}elseif(isset($idsubdepartamento)) {
					$order = "WHERE iddepartamento = '$iddepartamento' AND idsubdepartamento = '$idsubdepartamento' AND nome LIKE '$letra%' ORDER BY idanuncio";
				}else{
					$order = "WHERE iddepartamento = '$iddepartamento' AND nome LIKE '$letra%' ORDER BY idanuncio";
				}
			}else{
				if(isset($iddepartamento)) {
					if(isset($idsubdepartamento)) {
						$order = "WHERE iddepartamento = '$iddepartamento' AND idsubdepartamento = '$idsubdepartamento' ORDER BY idanuncio";
					}else{
						$order = "WHERE iddepartamento = '$iddepartamento' ORDER BY idanuncio";
					}
				}else{
					$order = "ORDER BY idanuncio";
				}
			}
			
			$totalPorPagina = $totRegistrosPorPagina;
			$inicio = $pagina * $totalPorPagina;
			?>
			<span class="TituloPage">• Anúncios</span>
	        <br>
	        <br>
	        <table border="0" width="100%" border="0" cellpadding="4" cellspacing="1" class="BordaTabela"> 
	        	<?
					switch ($_GET["msg"]) {
						case 1:
							$this->mostraMSG("Anúncio adicionado com sucesso.");
						break;	
						case 2:
							$this->mostraMSG("Anúncio alterado com sucesso.");
						break;
						case 3:
							$this->mostraMSG("Anúncio removido com sucesso.");
						break;							
					}
				?>
				<tr>
					<td colspan="5">
						<table border="0" width="100%" class="BordaTabela">
						<form method="GET" action="principal.php?menu=7&act=mostra" onsubmit="return valida_dropmenu(iddepartamento,'opção');">
							<input type="hidden" name="menu" value="7">
							<input type="hidden" name="act" value="mostra">
							<tr>
								<td width="12%"><b>Departamento:</b></td>
								<td>
									<? 
										$departamentos = new Departamento();
										$departamentosDAO = new DepartamentoDAO();
										$departamentos = $departamentosDAO->Lista();
										
										$this->selectDepartamentosAdminMostra($departamentos,$iddepartamento); 
									?>
								</td>
								<td><input type="submit" value="Enviar" class="bttn1"></td>							
							</tr>
							</form>
							<?
								$subdepartamentos = new Subdepartamento();
								$subdepartamentosDAO = new SubdepartamentoDAO();
								$subdepartamentos = $subdepartamentosDAO->getSubdepartamentosPorIddepartamento($iddepartamento);
								
								if($subdepartamentos) { ?>
									<form method="GET" action="principal.php?menu=7&act=mostra" onsubmit="return valida_dropmenu(idsubdepartamento,'opção');">
									<input type="hidden" name="menu" value="7">
									<input type="hidden" name="act" value="mostra">
									<input type="hidden" name="iddepartamento" value="<?=$iddepartamento;?>">
									<tr>
										<td width="12%"><b>Subdepartamento:</b></td>
										<td>
											<? 																				
												$this->selectSubdepartamentosAdminMostra($subdepartamentos,$idsubdepartamento); 
											?>
										</td>
										<td><input type="submit" value="Enviar" class="bttn1"></td>							
									</tr>
									</form>
							<?	}
							?>
						</table>
					
					</td>				
				</tr>
	            <tr class="TituloTabela">
	                <td width="5%" align="center">COD</td>
	                <td width="60%">NOME</td>                                              
	                <td>BAIRRO</td>                                              
	                <td>VALIDADE</td>                                              
	                <td>VISUALIZAÇÕES</td>                                              
	            </tr>
	            <?
	            	
					$anuncio = $anuncioDAO->Paginacao($order,$inicio,$totalPorPagina);
					$registros = $anuncioDAO->Registros($order);
					
					$paginas = ceil($registros / $totalPorPagina);
					
					$totAnuncios = count($anuncio);

					for ($i=0;$i<$totAnuncios;$i++) {
	            ?>
				<tr class="Linha1Tabela" onMouseOver="this.style.backgroundColor='#FFECEC'; this.style.cursor='hand';" onMouseOut="this.style.backgroundColor='';" onclick="javascript: window.location='?menu=7&act=alt&idanuncio=<?=$anuncio[$i]->getIdanuncio();?>';"> 
		            <td align="center"><?=$anuncio[$i]->getIdanuncio();?></td>					            
		            <td><?=$anuncio[$i]->getNome();?></td>					            					           
		            <td><?=$anuncio[$i]->getBairro();?></td>					            					           
			        <td><?=$anuncio[$i]->MostraDataSemHora($anuncio[$i]->getAte());?></td>    
			        <td><?=$anuncio[$i]->getAcessos();?></td>    
		        </tr>
		        <?
					}
		        ?>
		        <? if($totAnuncios < 1) { ?>
 				<tr class="Linha1Tabela"> 
		            <td align="center" colspan="4"><b>Não há nenhum anúncio cadastrado.</b></td>
		        </tr>
		        <? } ?>
		        <? 
		        	if(isset($_GET["letra"])) {
		        		if(!isset($iddepartamento)) {
		        			$this->mostraPaginacao($paginas,$pagina,"menu=7&act=mostra&letra=$letra");
		        		}elseif(isset($idsubdepartamento)) {
		        			$this->mostraPaginacao($paginas,$pagina,"menu=7&act=mostra&iddepartamento=$iddepartamento&idsubdepartamento=$idsubdepartamento&letra=$letra");
		        		}else{
		        			$this->mostraPaginacao($paginas,$pagina,"menu=7&act=mostra&iddepartamento=$iddepartamento&letra=$letra");
		        		}
		        	}else{
		        		if(!isset($iddepartamento)) {
		        			$this->mostraPaginacao($paginas,$pagina,"menu=7&act=mostra");
		        		}elseif(isset($idsubdepartamento)) {
		        			$this->mostraPaginacao($paginas,$pagina,"menu=7&act=mostra&iddepartamento=$iddepartamento&idsubdepartamento=$idsubdepartamento");
		        		}else{
		        			$this->mostraPaginacao($paginas,$pagina,"menu=7&act=mostra&iddepartamento=$iddepartamento");
		        		}
		        	}
		        	if(!isset($iddepartamento)) {
		        		$this->mostraPaginacaoLetras("menu=7&act=mostra",$letra);
		        	}elseif(isset($idsubdepartamento)) {
		        		$this->mostraPaginacaoLetras("menu=7&act=mostra&iddepartamento=$iddepartamento&idsubdepartamento=$idsubdepartamento",$letra);
		        	}else{
		        		$this->mostraPaginacaoLetras("menu=7&act=mostra&iddepartamento=$iddepartamento",$letra);
		        	}
		        	
		        ?>
		    </table>
		    <br>
		    <table width="400" cellspacing="1" cellpadding="4" border="0" class="BordaTabela">
		        <tbody>
			        <tr class="TituloTabela">
			            <td height="30" align="center" colspan="2">RESUMO DESTA CONSULTA</td>
			        </tr>
			        <tr class="Linha1Tabela">
			            <td height="20"><b>Total de Registros por Página:</b></td>
			            <td width="40%" height="20"><?=$totAnuncios;?></td>
			        </tr>
			        <tr class="Linha2Tabela">
			            <td height="20"><b>Total de Páginas:</b></td>
			            <td height="20"><?=$paginas;?></td>
			        </tr>
			        <tr class="Linha1Tabela">
			            <td height="20"><b>Total de Registros:</b></td>
			            <td width="40%" height="20"><?=$registros;?></td>
			        </tr>
		    	</tbody>
		    </table>
		    <br>
		    <table>
		    	<tr>
		    		<td><input type="button" value="Cadastrar Anuncio" onclick="document.location='principal.php?menu=7&act=add';" class="bttn2"></td>
		    	</tr>
		    </table>
		    
	<?	}