<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="50" colspan="4" align="left" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="80" height="40" class="TituloPagina" style="padding-left: 5px;"><img src="img/icone_9.fw.png" width="77" height="85" alt=""/></td>
        <td align="left" class="TituloPagina" style="padding-left: 5px;"><span class="TituloPagina" style="padding-left: 5px;">ATENDIMENTO</span></td>
        <td align="right"><table width="100" border="0" align="center" cellpadding="2" cellspacing="0">
          <tr>
            <td width="167" align="left"><table width="190" border="0" cellspacing="0" cellpadding="2" class="BoxMenuCinzaEscuro" onclick="location.href='index.php?pagina=listar_atendimentos.php';">
              <tr>
                <td height="25" align="center" class="TextoMenuCinza"><img src="img/icone_novo.gif" width="29" height="21" /></td>
                <td align="left" class="TextoMenuBranco" style="font-weight:normal;">Todos os Atendimentos</td>
              </tr>
            </table></td>
            <td width="150" align="left"><table width="160" border="0" cellspacing="0" cellpadding="2" class="BoxMenuCinzaEscuro" onclick="location.href='index.php?pagina=manutencao_atendimentos.php';">
              <tr>
                <td height="25" align="center" class="TextoMenuCinza"><img src="img/icone_novo.gif" width="29" height="21" /></td>
                <td align="left" class="TextoMenuBranco" style="font-weight:normal;">Novo Atendimento</td>
              </tr>
            </table></td>
            <td width="125" align="left">&nbsp;</td>
            <td width="370" align="right"><table width="250" border="0" align="right" cellpadding="0" cellspacing="0" class="BoxMenuBranco">
              <form method="post" action="index.php?pagina=listar_atendimentos.php" enctype="multipart/form-data">
                <tr>
                  <td width="148" align="left" bgcolor="#FFFFFF"><input name="busca" type="text" class="InputBranco" id="busca" placeholder="Pesquisar" style="width: 100%; height: 30px; background-color: #D3D3D3;" /></td>
                  <td width="28" align="center" bgcolor="#FFFFFF"><input type="image" src="img/icone_buscar.gif" /></td>
                </tr>
              </form>
            </table></td>
          </tr>
        </table></td>
        <td width="80" align="right" style="padding-right: 8px;"><table width="70" border="0" cellspacing="0" cellpadding="2" class="BoxMenuCinza" onclick="history.go(-1);">
          <tr>
            <td height="25" align="center" class="TextoMenuBranco">Voltar</td>
          </tr>
        </table></td>
      </tr>
    </table></td>
    <td width="250" rowspan="2" align="left" valign="top"><?php require_once('lateral_geral.php');?></td>
  </tr>
  <tr>
    <td colspan="4" align="center" valign="top">    
    <table width="100%" border="0" align="center" cellpadding="3" cellspacing="0" id="tabela_padrao" class="display">
      <thead>
       <tr class="TextoCinzaEscuro">
        <td width="5%" bgcolor="#A6A6A6"><strong>CÓD.</strong></td>
        <td width="15%" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>TITÚLO</strong></td>
        <td width="20%" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>RAZÃO SOCIAL</strong></td>
        <td width="20%" height="30" bgcolor="#A6A6A6" class="TextoCinzaEscuro"><strong>NOME FANTASIA</strong></td>
        <td width="15%" bgcolor="#A6A6A6"><strong>CONTATO</strong></td>
        <td width="15%" align="left" bgcolor="#A6A6A6"><strong>EMAIL</strong></td>
        <td width="15%" align="left" bgcolor="#A6A6A6"><strong>TELEFONE</strong></td>
        <td width="20%" align="left" bgcolor="#A6A6A6"><strong>DATA ATENDIMENTO</strong></td>
        <td width="5%" align="center" bgcolor="#A6A6A6">&nbsp;</td>
        </tr>
        </thead>
        <tbody>
      <?php

		$busca = $_POST['busca'];
			$cor_fundo = "#FFFFFF";			  
		  if(empty($busca)){
			 	
		if($_SESSION['master'] != ""){				
				$seleciona = Seleciona("atendimentos", "", "ORDER BY idatendimento DESC");
		}else{
				$seleciona = Seleciona("atendimentos", "WHERE idusuario_cadastro='".$_SESSION['usuarioID']."'  OR idprofissional='".$_SESSION['usuarioID']."'", "ORDER BY idatendimento DESC");
		}
				
		  }else{
		if($_SESSION['master'] != ""){							  
			  	$seleciona = Seleciona("atendimentos", "WHERE fantasia LIKE '%".$busca."%' OR razaosocial LIKE '%".$busca."%'", "ORDER BY Fantasia ASC");
		}else{
			  	$seleciona = Seleciona("atendimentos", "WHERE fantasia LIKE '%".$busca."%' OR razaosocial LIKE '%".$busca."%' AND idusuario_cadastro='".$_SESSION['usuarioID']."'  OR idprofissional='".$_SESSION['usuarioID']."'", "ORDER BY Fantasia ASC");	
		}
		  }
			while($linha=mysql_fetch_array($seleciona)){
			
			if($cor_fundo == "#FFFFFF"){
				$cor_fundo = "#E4E4E4";
			}else{
				$cor_fundo = "#FFFFFF";
			}
		?>
      <tr class="TextoCinzaPequeno" bgcolor="<?php echo $cor_fundo;?>" onmouseover="javascript:this.style.backgroundColor='#CCCCCC'" onmouseout="javascript:this.style.backgroundColor='<?php echo $cor_fundo;?>'" style="cursor:pointer;" onclick="location.href='index.php?pagina=manutencao_atendimentos.php&idatendimento=<?php echo $linha['idatendimento'];?>';">
        <td width="5%"><?php echo $linha['idatendimento'];?></td>
        <td width="15%"><?php echo $linha['titulo'];?></td>
        <td width="20%"><?php echo $linha['razaosocial'];?></td>
        <td width="20%" height="30"><?php echo $linha['fantasia'];?></td>
        <td width="15%"><?php echo $linha['contato'];?></td>
        <td width="15%" align="left"><?php echo $linha['email1'];?></td>
        <td width="15%" align="left"><?php echo $linha['telefone1'];?></td>
        <td width="20%" align="left"><?php echo $linha['datacontato'];?></td>
        <td width="5%" align="right"><img src="img/icone_detalhe.gif" width="22" height="24" border="0" /></td>
        </tr>
      <?php }?>
      </tbody>
    </table>    
    </td>
  </tr>
  <tr>
    <td colspan="5" align="center" valign="middle">
</td>
  </tr>
</table>