<?php 

	session_start();
	if(isset($_SESSION['usuario']))
	{  
		//include "layouts/header2.php"; 
		//include "config.php"; 
		
		 $iddoc = $_REQUEST['id'];
		//$sql="SELECT * FROM m_chat WHERE iddoc_curso=".$iddoc;

		//$query = mysqli_query($conn,$sql);
	}
	/*require ("clases/alumno.class.php");
	require ("clases/autor.class.php");
	require ("clases/m_chat.class.php"); $objmchat = new m_chat();*/
?>
<meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="Shortcut Icon" type="image/x-icon" href="assets/icons/book.ico" />
    <script src="js/sweet-alert.min.js"></script>
    <link rel="stylesheet" href="css/sweet-alert.css">
    <link rel="stylesheet" href="css/material-design-iconic-font.min.css">
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/jquery.mCustomScrollbar.css">
    <link rel="stylesheet" href="css/style.css">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="js/jquery-1.11.2.min.js"><\/script>')</script>
    <script src="js/modernizr.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="js/main.js"></script>

<script src="js/jquery1.min.js"></script>


<style>
.text_docentes{ font-size:11px; font-family:Arial, Helvetica, sans-serif;}
</style>
<style>
  h2{
color:#006699;
  }
  label{
color:006699;
  }
  span{
	  color:#673ab7;
	  font-weight:bold;
  }
  
  .btn-primary {
    background-color: #673AB7;
	}
	.display-chat{
		height:370px;
		background-color:#FFFFFF;
		margin-bottom:4%;
		overflow:auto;
		padding:15px;
	}
	.message{
		background-color:#ffffff;
		color:#404040;
		border-radius: 5px; border:#999999;
		padding: 5px;
		margin-bottom: 3%;
	}
  </style>


<script>
function Hola(nombre,mensaje,doc,text) {  

     var parametros = {"name":nombre,"msg":mensaje,"iddoc":doc,"text":text};	 
		$.ajax({
			data:parametros,
			url:'controladores/procesam_chat.php',
			type: 'post',
			
			beforeSend: function () {
				$("#message").html("");  				
			},
			success: function (results) {  			
				$("#message").html(results);
				$('#msg').val("");
			} 		
			
		   });
		   
}


      $(document).ready(function(){
        // Set trigger and container variables
        var trigger = $('.container .display-chat '),
            container = $('#content');
        
        // Fire on click
        trigger.on('click', function(){
          // Set $this for re-use. Set target from data attribute
          var $this = $(this),
            target = $this.data('target');       
          
          // Load target page into container
          container.load(target + '.php');
          
          // Stop normal link behavior
          return false;
        });
      });
    </script>

	
	
	
	
	<div class="container">   
	<div class="display-chat" id = "display-chat">
          <div id="message"></div>
      </div>
   <form name="f" method="post" action="chatpage.php" id="formularioaenviar" onsubmit="return false">
      
    <div class="form-group">
      <div class="col-sm-10">          
        <div class="input-group">
	     <input name="msg" id="msg" type="text" class="form-control" placeholder="Ingresa tu mensaje acá..."/>    
		 <div class="input-group-addon"><span class="glyphicon glyphicon-send" aria-hidden="true"></span></div>		
      </div>
	         
      <div class="col-sm-2">
        <button type="submit" class="btn btn-success" style="visibility:hidden" >Enviar</button>
        <input type="hidden" name="name" id="name" value="<?=$_SESSION['usuario'];?>" />
        <input type="hidden" name="iddoc" id="iddoc" value="<?=$iddoc;?>" />
        <input type="hidden" name="text" id="text" value="R" />
      </div>
    </div>
	
  </form>
  
      
 </div>
</body>
</html>
<script>
$(document).ready(function(){
 // $("#msg").click(function(){
 $("#msg").keypress(function(e){
    // if(document.f.msg.value==""){document.f.msg.focus();return false;} 
	 var keyCode= e.which;
	 if (keyCode == 13){
     // Evitamos que se ejecute eventos
        
     // Devolvemos falso
        
    
    var formulario = $("#formularioaenviar").serializeArray();
    $.ajax({
      type: "POST",
      dataType: 'json',
      url: "controladores/procesam_chat.php",
      data: formulario,
    }).done(function(respuesta/*quitar luego*/){
	   $("#message").html(respuesta.mensaje);//quitar luego
	   alert(respuesta.mensaje);
	  // CierraPopupv();
	   
    }); 
	document.f.msg.value="";
	 event.preventDefault();
	 return false;
      }   
	//alert("Se guardo Correctamente, puede cerrar la ventana de registro de persona");	//activar luego   
	//CierraPopup();//activar luego
  }); 
  
  
  
  function limpiarformulario(formulario){ 
     
  $(formulario).find('input').each(function() {
      switch(this.type) {
          case 'password':
          case 'text':
                $(this).val('');
              break;
          case 'checkbox':
          case 'radio':
              this.checked = false;
          }
      });
  
      $(formulario).find('select').each(function() {
          $("#"+this.id + " option[value=0]").attr("selected",true);  
      });
	  
  }
});

function CierraPopupv() {
  /*  $("#nuevovehiculo").modal('hide');//ocultamos el modal
    $('body').removeClass('modal-open');//eliminamos la clase del body para poder hacer scroll
    $('.modal-backdrop').remove();//eliminamos el backdrop del modal
	*/
  }
</script>

<script>
$(document).ready(function(){
 /*  $('#submit').click(function(){
    var msg_txt = $('#msg').val();
	 if($.trim(msg_txt)!='')
	 {
	   $.ajax({
	      url:"fetch.php",
		  method:"POST",
		  data:{msg:msg_txt},
		  dataType:"text",
		  success:function(data)
		  {
		    $('#msg').val("");
		  }
	   });
	 }
  });*/
 
  setInterval(function()
  {
      $('#message').load("chatpage_details.php?id=<?php echo $iddoc;?>").fadeIn("slow");
  },1000)
});
</script>
