<?
require("conectar.php");
$id=$_POST['usu'];
$log=$_POST['logeo'];

/*$sql="SELECT * FROM usuchat WHERE login != '$log' AND id_usu NOT IN (SELECT DISTINCT emisor FROM chat) AND id_usu NOT IN (SELECT DISTINCT destino FROM chat)";
//$re=mysql_query($sql);
?>
 
<?
//while($li=mysql_fetch_array($re))
{
//$aux=mysql_num_rows($re);
//
     //if($li["status"]==1){$bk="#3ADF00";}
     //if($li["status"]==2){$bk="#DF0101";}
     ?>
	     <div class="contacto" onclick="javascript:new conversa('<?echo $li["id_usu"]?>','<?echo $li["alias"]?>');"><?echo $li["alias"]?><div style="position:absolute;margin-top:-13px;right:5px;width:10px;height:10px;background:<?echo $bk?>;-moz-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;-khtml-border-radius: 5px;"></div></div>
	 <?
}*/
?> 
<div class="section">Clientes sin atender</div>
<?
$joy=date("Y-m-d");
/*
$sql="SELECT * FROM usuchat WHERE login = '$log' and id_usu!='$id' AND fecha='$joy' AND id_usu NOT IN (SELECT DISTINCT emisor FROM chat WHERE destino='$id') AND id_usu NOT IN (SELECT DISTINCT destino FROM chat  WHERE emisor='$id')";*/
$sql="SELECT * FROM usuchat WHERE (atendido='0' and login='')or (login<>'') and id_usu!='$id' AND fecha='$joy' ORDER BY login asc";
$re=mysql_query($sql);
$mem="";
while($li=mysql_fetch_array($re)){
if($li['login']=="")
  {
	$ubo++; 
?>
<script>			
	alertaCliente();	
</script>
<? }
         if($li["status"]==1){$bk="#3ADF00";}
         if($li["status"]==2){$bk="#DF0101";}
		 if($li["login"]!=$mem){$mem=$li["login"];?> <div class="section">Ejecutivos</div><?}?>
	     <div class="contacto" onclick="javascript:new conversa('<?echo $li["id_usu"]?>','<?echo $li["alias"]?>');"><div style="position:absolute;margin-top:0px;right:5px;width:10px;height:10px;background:<?echo $bk?>;-moz-border-radius: 5px;-webkit-border-radius: 15px;border-radius: 5px;-khtml-border-radius: 5px;"></div><?echo $li['alias'];?></div>
	 <?
}
?>
<div  class="section">Conversaciones</div>

<?
 $hoy=date("Y-m-d");
         $sql="SELECT * FROM chat WHERE destino='$id' AND status='' AND fecha='$hoy' order by fecha, hora ";
		 $con=mysql_query($sql);
		 while($ls=mysql_fetch_array($con)){
		 $ban++;
	 if($ls["notificacion"]==''){?>	 
	  <script>
		if(!document.getElementById("n<?echo $li["id_chat"]?>")){
	new notification("<?echo $ls["alias"]?>","<?echo $ls["mensaje"]?>","<?echo $ls["id_chat"]?>","<?echo $ls["emisor"];?>");	
		}
         </script>
	 <? }
	    }
		
		
		if($ubo<1){echo"<script>normal();</script>"; if($ban<1){?>
		 <script>
		// var camtitulo;
		
		 clearInterval(camtitulo);
		 document.title='Mexico en Renta es como estar en casa';nctit=0;
		</script>
		<?}		
		}/*
		else{?>
		<script>
		 var camtitulo;
		 clearInterval(camtitulo);
		camtitulo=setInterval(function(){cambiaTit("Mexico en Renta","<?echo $ls["alias"]." Te ha enviado un mensaje";?>");},500);
		</script>
	 <?}*/?>