Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 11408 | Rev 11583 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php 
use LeadersLinked\Model\ChatGroupUser;

$siteurl  = $this->url('home', [], ['force_canonical' => true]);
$audioogg  = $this->basePath('audio/chat.ogg');
$audiomp3 = $this->basePath('audio/chat.mp3');
$emojione_image_path_png  = $this->basePath('vendors/smiley/assets/png/');
$users_group_png = $this->basePath('images/users-group.png');

$flash_swf_url = $this->basePath('vendors/uploader/Moxie.swf');
$silverlight_xap_url = $this->basePath('vendors/uploader/Moxie.xap');

$this->inlineScript()->captureStart();
echo <<<EOT
var siteurl = '$siteurl';
var windowFocus = true;
var username;
var image_href;
var scrollcode;
var chatHeartbeatCount = 0;
var minChatHeartbeat = 800;
var maxChatHeartbeat = 33000;
var chatHeartbeatTime = minChatHeartbeat;
var originalTitle;
var blinkOrder = 0;
var audioogg = new Audio('$audioogg');
var audiomp3 = new Audio('$audiomp3');
var groupChatIcon = '$users_group_png';

var chatboxFocus = new Array();
var newMessages = new Array();
var newMessagesWin = new Array();
var newMessagesSender = new Array();
var chatBoxes = new Array();
var lastBeat;

emojione.imageType = 'png';
emojione.sprites = false;
emojione.ascii = true;
emojione.imagePathPNG = '$emojione_image_path_png';
//emojione.imagePathSVG = 'app/plugins/smiley/assets/svg/';

function msg_eventpl(chatboxtitle,sender,img,message_content,time,position){
    var zechat_eventpl = '<li class="clearfix m-t-10 conversers2">' +
        '<div class="conversation-text" data-toggle="tooltip" data-placement="left" data-html="true">' +
        '<div class="ctext-wrap"><p class="">'+message_content+' <br><i class="text-right">'+time+'</i></p></div></div></li>';

    if(position == "append"){
        $("#chatbox_"+chatboxtitle+" .chatboxcontent").append(zechat_eventpl);
        $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
    }
    else{
        $("#chatbox_"+chatboxtitle+" .chatboxcontent").prepend(zechat_eventpl);
    }

}
function msg_oddtpl(chatboxtitle,sender,img,message_content,time,position){
    var zechat_oddtpl = '<li class="clearfix m-t-10 odd conversers1">' +
        '<div class="conversation-text" data-toggle="tooltip" data-placement="right" data-html="true">' +
        '<div class="ctext-wrap"><p class="">'+message_content+'</p><i class="text-right">'+time+'</i></div></div></li>';

    if(position == "append"){
        $("#chatbox_"+chatboxtitle+" .chatboxcontent").append(zechat_oddtpl);
        $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
    }
    else{
        $("#chatbox_"+chatboxtitle+" .chatboxcontent").prepend(zechat_oddtpl);
    }
}
function typePlace() {

    if(!$('#textarea').html() == '')
    {
        $(".input-placeholder").css({'visibility':'hidden'});
    }
    else{
        $(".input-placeholder").css({'visibility':'visible'});
    }
}

$(document).ready(function(){
    $(document).on('click', ".e1", function (e){
        
        e.stopPropagation();
        
        e.preventDefault();
        var item = $(this).closest('.chatbox');
        var client = item.attr('client');
        //alert(client);
        var prevMsg = $("#chatbox_"+client+" .chatboxtextarea").val();
        var shortname = $(this).data('shortname');
    
        $("#chatbox_"+client+" .chatboxtextarea").val(prevMsg+' '+shortname+' ');
        $("#chatbox_"+client+" .chatboxtextarea").focus();
    
    });
    
    $(document).on('click', "#toggle-emoji", function (e){
        
        e.stopPropagation();
        
        e.preventDefault();
        var item = $(this).closest('.chatbox');
        var client = item.attr('client');
        //alert(client);
        $("#chatbox_"+client+" .target-emoji").slideToggle( 'fast', function(){
    
            if ($("#chatbox_"+client+" .target-emoji").css('display') == 'block') {
                $('#chatbox_'+client+' .btn-emoji').removeClass('ti-face-smile').addClass('ti-arrow-circle-down');
            } else {
                $('#chatbox_'+client+' .btn-emoji').removeClass('ti-arrow-circle-down').addClass('ti-face-smile');
            }
        });
        var heit = $('#resultchat').css('max-height');
    });


    $("#minmaxchatlist").click(function(){
        if(eval(localStorage.chatlist)){
            localStorage.chatlist = false;
            $("#showhidechatlist").css('display','none');
        }
        else{
            localStorage.chatlist = true;
            $("#showhidechatlist").css('display','block');
        }
    });

    $("#mute-sound").click(function(){
        if(eval(localStorage.sound)){
            localStorage.sound = false;
            $("#mute-sound").html('<i class="icon icon-volume-off"></i>');
        }
        else{
            localStorage.sound = true;
            $("#mute-sound").html('<i class="icon icon-volume-2"></i>');
            audiomp3.play();
            audioogg.play();
        }
    });

    if(eval(localStorage.chatlist)){
        $("#showhidechatlist").css('display','block');
    }
    else{
        $("#showhidechatlist").css('display','none');
    }

    if(eval(localStorage.sound)){
        $("#mute-sound").html('<i class="icon icon-volume-2"></i>');
    }
    else{
        $("#mute-sound").html('<i class="icon icon-volume-off"></i>');
    }


    originalTitle = document.title;
    startChatSession();
    loadGroups();

    $([window, document]).blur(function(){
        windowFocus = false;
    }).focus(function(){
        windowFocus = true;
        document.title = originalTitle;
    });

    $( "body" ).on( "click", "#new-chat-group", function() {
        $("#form-new-group").dialog({
            appendTo: 'body',
            title: "Nuevo Grupo",
            modal: true,
            resizable: false
        });
    });

    $( "body" ).on( "click", "#btn_submit_group", function() {
        var name = $("#group_name").val().trim();
        if(name!=""){
            $('#form-new-group').dialog("close");
            $("#group_name").val("");
            createGroupChatBox(create_UUID(),false,name);
        }
        
    });
});

function restructureChatBoxes() {
    align = 0;
    for (x in chatBoxes) {
        chatboxtitle = chatBoxes[x];

        if ($("#chatbox_"+chatboxtitle).css('display') != 'none') {
            if (align == 0) {
                $("#chatbox_"+chatboxtitle).css('right', '295px');
            } else {
                width = (align)*(273+7)+295;
                $("#chatbox_"+chatboxtitle).css('right', width+'px');
            }
            $("#chatbox_"+chatboxtitle).css('z-index',1);
            align++;
        }
    }
}

function chatWith(chatuser,chatheaderimg,status,name) {
    

    createChatBox(chatuser,chatheaderimg,status,0,name);
    $("#chatbox_"+chatuser+" .chatboxtextarea").focus();
}

function create_UUID(){
    var dt = new Date().getTime();
    var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = (dt + Math.random()*16)%16 | 0;
        dt = Math.floor(dt/16);
        return (c=='x' ? r :(r&0x3|0x8)).toString(16);
    });
    return uuid;
}

function chatGroup(uuid,name)
{
    createGroupChatBox(uuid,true,name);
    $("#chatbox_"+uuid+" .chatboxtextarea").focus();
}

function createChatBox(chatboxtitle,chatheaderimg,status,minimizeChatBox,name) {
    if ($("#chatbox_"+chatboxtitle).length > 0) {
        if ($("#chatbox_"+chatboxtitle).css('display') == 'none') {
            $("#chatbox_"+chatboxtitle).css('display','block');
            restructureChatBoxes();
        }
        $("#chatbox_"+chatboxtitle+" .chatboxtextarea").focus();
        return;
    }   
    var tipo = "single";
    $("<div />" ).attr("id","chatbox_"+chatboxtitle)
        .addClass("chatbox active-chat")
        .attr("client",chatboxtitle)
        .html('<div class="chatbox-icon" onclick="javascript:toggleChatBoxGrowth(\''+chatboxtitle+'\')" href="javascript:void(0)"><div class="contact-floating red"><img class="chat-image img-circle pull-left" src="'+chatheaderimg+'"><small class="unread-msg">2</small><small class="status"'+ status+'></small></div></div>' +
        '<div class="panel personal-chat"> ' +
        '<div class="panel-heading chatboxhead"> ' +
        '<div class="panel-title">' +
        '<img class="chat-image img-circle pull-left" height="36" width="36" src="'+chatheaderimg+'" alt="avatar-image"> ' +
        '<div class="header-elements">' +
        '<a href="">'+name+'</a>' +
        '</h3>' +
        '<br> ' +
        '<small class="status Offline"><b>Offline</b>' +
        '</small> ' +
        '<div class="pull-right options"> ' +
        '<!--<div class="btn-group uploadFile" id="uploadFile" data-client="'+chatboxtitle+'"><span><i class="fa fa-trash"></i></span></div>--> ' +
        '<!--<div class="btn-group" onclick="javascript:clearHistory(\''+chatboxtitle+'\')" href="javascript:void(0)"><span><i class="fa fa-trash"></i></span></div>--> ' +
        '<div class="btn-group" onclick="javascript:toggleChatBoxGrowth(\''+chatboxtitle+'\')" href="javascript:void(0)">' +
        '<span>' +
        '<i class="fa fa-minus-circle"></i>' +
        '</span>' +
        '</div> ' +
        '<div class="btn-group" onclick="javascript:closeChatBox(\''+chatboxtitle+'\')" href="javascript:void(0)">' +
        '<span><i class="fa fa-times-circle"></i></span>' +
        '</div> ' +
        '</div> ' +
        '</div> ' +
        '</div> ' +
        '</div> ' +
        '<div class="panel-body"><div id="uploader_'+chatboxtitle+'" style="display: none;height: 342px;"><p>Your browser does not have Flash, Silverlight or HTML5 support.</p></div>' +
        '<div class="chat-conversation"> ' +
        '<ul class="conversation-list chatboxcontent" id="resultchat_'+chatboxtitle+'"> </ul> ' +
        '<div class="wchat-footer wchat-chat-footer chatboxinput"> ' +
        '<div id="chatFrom"> ' +
        '<div class="block-wchat"> ' +
        '<button class="icon ti-clip attachment font-24 btn-attach btn-attach uploadFile" id="uploadFile" data-client="'+chatboxtitle+'" style="display: block"></button> ' +
        '<button class="icon ti-face-smile font-24 btn-emoji" id="toggle-emoji"></button>' +
        '<div class="input-container"> ' +
        '<div class="input-emoji"> ' +
        '<div class="input-placeholder" style="visibility: hidden; display: none;">Escribe un mensaje</div> ' +
        '<textarea class="input chatboxtextarea" id="chatboxtextarea" name="chattxt" contenteditable="" spellcheck="true" style="resize:none;height:20px" placeholder="Escribe un mensaje" onkeydown="javascript:return checkChatBoxInputKey(event,this,\''+chatboxtitle+'\',\''+tipo+'\');"></textarea>' +
        '<input id="to_uname" name="to_uname" value="'+chatboxtitle+'" type="hidden">' +
        '<input id="from_uname" name="from_uname" value="Beenny" type="hidden"> ' +
        '</div> ' +
        '</div> ' +
        '</div> ' +
        '</div> ' +
        '<div class="wchat-box-items-positioning-container"><div class="wchat-box-items-overlay-container"><div class="target-emoji" style="display: none"><div id="include-smiley-panel"></div></div></div></div>'+
        '</div> ' +
        '</div> ' +
        '</div>' +
        '</div>')
        .appendTo($( "body" ));

    var scrollcode = $("#resultchat_"+chatboxtitle).scroll(function(){
        if ($("#resultchat_"+chatboxtitle).scrollTop() == 0){

            var client = $("#chatbox_"+chatboxtitle).attr("client");

            if($("#chatbox_"+client+" .pagenum:first").val() != $("#chatbox_"+client+" .total-page").val()) {

                $("#loader").show();
                var pagenum = parseInt($("#chatbox_"+client+" .pagenum:first").val()) + 1;

                var URL = siteurl+"chat/get-all-messages/" + client + "?page="+pagenum;

                get_all_msg(URL);

                $("#loader").hide();                                                                    // Hide loader on success

                if(pagenum != $("#chatbox_"+client+" .total-page").val()) {
                    setTimeout(function () {                                                                            //Simulate server delay;

                        $("#resultchat_"+chatboxtitle).scrollTop(100);                                                  // Reset scroll
                    }, 458);
                }
            }

        }
    });



    $('<script type="text/javascript">scrollcode</' + 'script>').appendTo(document.body);

    get_all_msg(siteurl+"chat/get-all-messages/" + chatboxtitle + "?page=1");

    //lastseen(chatboxtitle);

    smiley_tpl(chatboxtitle);

    $("#chatbox_"+chatboxtitle).css('bottom', '0px');

    chatBoxeslength = 0;
    for (x in chatBoxes) {
        if ($("#chatbox_"+chatBoxes[x]).css('display') != 'none') {
            chatBoxeslength++;
        }
    }

    if (chatBoxeslength == 0) {
        $("#chatbox_"+chatboxtitle).css('right', '295px');
    } else {
        width = (chatBoxeslength)*(273+7)+295;
        $("#chatbox_"+chatboxtitle).css('right', width+'px');
    }
    $("#chatbox_"+chatboxtitle).css('z-index',1);
    chatBoxes.push(chatboxtitle);

    if (minimizeChatBox == 1) {
        minimizedChatBoxes = new Array();

        if ($.cookie('chatbox_minimized')) {
            minimizedChatBoxes = $.cookie('chatbox_minimized').split(/\|/);
        }
        minimize = 0;
        for (j=0;j<minimizedChatBoxes.length;j++) {
            if (minimizedChatBoxes[j] == chatboxtitle) {
                minimize = 1;
            }
        }

        if (minimize == 1) {
            $('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display','none');
            $('#chatbox_'+chatboxtitle+' .chatboxinput').css('display','none');
        }
    }

    chatboxFocus[chatboxtitle] = false;

    $("#chatbox_"+chatboxtitle+" .chatboxtextarea").blur(function(){
        chatboxFocus[chatboxtitle] = false;
        $("#chatbox_"+chatboxtitle+" .chatboxtextarea").removeClass('chatboxtextareaselected');
    }).focus(function(){
        chatboxFocus[chatboxtitle] = true;
        newMessages[chatboxtitle] = false;
        $('#chatbox_'+chatboxtitle+' .chatboxhead').removeClass('chatboxblink');
        $("#chatbox_"+chatboxtitle+" .chatboxtextarea").addClass('chatboxtextareaselected');
    });


    $("#chatbox_"+chatboxtitle).show();

}

function removeOfGroup(user, group) {

    var c = confirm("Esta seguro de eliminar este usuario de este grupo de chat?");
     if(c){
        var url = siteurl+"chat/remove-user-from-group/" + group + '/' + user;
        $.post(url, {} , function(data){
            showGroupContacts(group);
        });   
    }

}

function createGroupChatBox(id,creado=false,name){
    if ($("#chatbox_"+id).length > 0) {
        if ($("#chatbox_"+id).css('display') == 'none') {
            $("#chatbox_"+id).css('display','block');
            restructureChatBoxes();
        }
        $("#chatbox_"+id+" .chatboxtextarea").focus();
        return;
    }


    var tipo = "group";
    
    $("<div />" ).attr("id","chatbox_"+id)
        .addClass("chatbox active-chat")
        .attr("client",id)
        .html('<div class="chatbox-icon" onclick="javascript:toggleChatBoxGrowth(\''+id+'\')" href="javascript:void(0)"><div class="contact-floating red"><img class="chat-image img-circle pull-left" src=""><small class="unread-msg">2</small><small class="status Online"></small></div></div>' + 
        '<div class="panel personal-chat"> ' +
        '<div class="panel-heading chatboxhead"> ' +
        '<div class="panel-title">' +
        '<img class="chat-image img-circle pull-left" height="36" width="36" src="'+groupChatIcon+'" alt="avatar-image"> ' +
        '<div class="header-elements">' +
        '<a href="">'+name.substring(0, 12)+'</a>' +
        '</h3>' +
        '<br> ' +
        '<small class="status Online"><b>Online</b>' +
        '</small> ' +
        '<div class="pull-right options"> ' +
        '<div class="btn-group addUser" data-client="'+id+'" data-name="'+name+'"><span><i class="fa fa-user-plus"></i></span></div>' +
        '<div class="btn-group" onclick="javascript:toggleChatBoxGrowth(\''+id+'\')" href="javascript:void(0)">' +
        '<span>' +
        '<i class="fa fa-minus-circle"></i>' +
        '</span>' +
        '</div> ' +
        '<div class="btn-group" onclick="javascript:closeChatBox(\''+id+'\')" href="javascript:void(0)">' +
        '<span><i class="fa fa-times-circle"></i></span>' +
        '</div> ' +
        '</div> ' +
        '</div> ' +
        '</div> ' +
        '</div> ' +
        '<div class="panel-body"><div id="uploader_'+id+'" style="display: none;height: 342px;"><p>Your browser does not have Flash, Silverlight or HTML5 support.</p></div>' +
        '<div id="participants_'+id+'" style="display: none;height: 342px;"><div style="text-align:center;">Agregue integrantes al grupo</div>' + 
        '<div class="participants_list"><ul id="contact-list-ul-gchat-'+id+'" class="ul-participants-list" style="padding-left:5px;"></ul></div>' +
        '<div class="participants_controls">' +
        '<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary closeAddUser" style="font-size: 14px; z-index: 1;margin-left:10px;" role="button" aria-disabled="false" data-client="'+id+'"><span class="ui-button-icon-primary ui-icon ui-icon-circle-close "></span><span class="ui-button-text">Cerrar</span></a></div>' +
        '</div>' +
        '<div class="chat-conversation"> ' +
        '<ul class="conversation-list chatboxcontent" id="resultchat_'+id+'"> </ul> ' +
        '<div class="wchat-footer wchat-chat-footer chatboxinput"> ' +
        '<div id="chatFrom"> ' +
        '<div class="block-wchat"> ' +
        '<button class="icon ti-clip attachment font-24 btn-attach btn-attach uploadFile" id="uploadFile" data-client="'+id+'" style="display: block"></button> ' +
        '<button class="icon ti-face-smile font-24 btn-emoji" id="toggle-emoji"></button>' +
        '<div class="input-container"> ' +
        '<div class="input-emoji"> ' +
        '<div class="input-placeholder" style="visibility: hidden; display: none;">Escribe un mensaje</div> ' +
        '<textarea class="input chatboxtextarea" id="chatboxtextarea" name="chattxt" contenteditable="" spellcheck="true" style="resize:none;height:20px" placeholder="Escribe un mensaje" onkeydown="javascript:return checkChatBoxInputKey(event,this,\''+id+'\',\''+tipo+'\');"></textarea>' +
        '<input id="to_uname" name="to_uname" value="'+id+'" type="hidden">' +
        '<input id="from_uname" name="from_uname" value="Beenny" type="hidden"> ' +
        '</div> ' +
        '</div> ' +
        '</div> ' +
        '</div> ' +
        '<div class="wchat-box-items-positioning-container"><div class="wchat-box-items-overlay-container"><div class="target-emoji" style="display: none"><div id="include-smiley-panel"></div></div></div></div>'+
        '</div> ' +
        '</div> ' +
        '</div>' +
        '</div>')
        .appendTo($( "body" ));

        $('<script type="text/javascript">scrollcode</' + 'script>').appendTo(document.body);
        get_all_msg(siteurl+"chat/get-all-group-messages/" + id + "?page=1");

        smiley_tpl(id);

        $("#chatbox_"+id).css('bottom', '0px');
    
        chatBoxeslength = 0;
        for (x in chatBoxes) {
            if ($("#chatbox_"+chatBoxes[x]).css('display') != 'none') {
                chatBoxeslength++;
            }
        }


        if (chatBoxeslength == 0) {
            $("#chatbox_"+id).css('right', '295px');
        } else {
            width = (chatBoxeslength)*(273+7)+295;
            $("#chatbox_"+id).css('right', width+'px');
        }
        $("#chatbox_"+id).css('z-index',1);
        chatBoxes.push(id);

        chatboxFocus[id] = false;

        $("#chatbox_"+id+" .chatboxtextarea").blur(function(){
            chatboxFocus[id] = false;
            $("#chatbox_"+id+" .chatboxtextarea").removeClass('chatboxtextareaselected');
        }).focus(function(){
            chatboxFocus[id] = true;
            newMessages[id] = false;
            $('#chatbox_'+id+' .chatboxhead').removeClass('chatboxblink');
            $("#chatbox_"+id+" .chatboxtextarea").addClass('chatboxtextareaselected');
        });

        $("#chatbox_"+id).show();

        if(!creado){
            createChatGroup(id,name);
        }


    
}

function chatHeartbeat(){

    var itemsfound = 0;
    if (windowFocus == false) {

        var blinkNumber = 0;
        var titleChanged = 0;
        for (x in newMessagesWin) {
            if (newMessagesWin[x] == true) {
                ++blinkNumber;
                if (blinkNumber >= blinkOrder) {
                    document.title = newMessagesSender[x]+' dice...';
                    titleChanged = 1;
                    break;
                }
            }
        }

        if (titleChanged == 0) {
            document.title = originalTitle;
            blinkOrder = 0;
        } else {
            ++blinkOrder;
        }

    } else {
        for (x in newMessagesWin) {
            newMessagesWin[x] = false;
        }
    }

    for (x in newMessages) {
        if (newMessages[x] == true) {
            if (chatboxFocus[x] == false) {
                //FIXME: add toggle all or none policy, otherwise it looks funny
                $('#chatbox_'+x+' .chatboxhead').toggleClass('chatboxblink');
            }
        }
    }

    $.ajax({
        url: siteurl+"chat/heart-beat",
        cache: false,
        dataType: "json",
        success: function(data) {
            $.each(data.items, function(i,item){
                if (item)       { // fix strange ie bug
                    var isGroup = false;
                    if(item.g){
                        isGroup = 1;
                        chatboxtitle = item.f;
                        sender = item.f;
                        senderimg = item.p;
                        img = item.p2;
                        status = item.st;
                        msgtype = item.mtype;
                        time = item.time;
                        id = item.g;
                        sender_name = item.n;
                        group_name = item.gn;
                    }else{
                        isGroup         = 0;
                        chatboxtitle    = item.f;
                        sender          = item.f;
                        senderimg       = item.p;
                        img             = item.p2;
                        status          = item.st;
                        msgtype         = item.mtype;
                        time            = item.time;
                        id              = item.x;
                        sender_name     = item.n;    
                    }


                    console.log("heart-beat - #chatbox_"+id);
                    

                    if ($("#chatbox_"+id).length <= 0) {
                        if(isGroup){
                            createGroupChatBox(id,true,group_name);
                        }else{
                            createChatBox(id,senderimg,status,"",sender_name);
                        }
                        if (eval(localStorage.sound)) {
                            //audiomp3.play();
                            //audioogg.play();
                        }
                        return;
                    }
                    if ($("#chatbox_"+id).css('display') == 'none') {
                        $("#chatbox_"+id).css('display','block');
                        restructureChatBoxes();
                    }

                    var message_content = item.m;
                    if (msgtype=="text") {
                        message_content = item.m;
                    } else { 
                        var path = item.m
                        if (msgtype == "image") {
                            message_content = "<a url='" + path + "' onclick='trigq(this)'><img src='" + path + "' class='userfiles'/></a>";
                        }
                        else if (file_content.file_type == "video") {
                            message_content = '<video class="userfiles" controls>' +
                            '<source src="' + path + '" type="video/mp4">' +
                            'Your browser does not support HTML5 video.' +
                            '</video>';
                        }
                        else {
                            message_content = "<a href='" + path + "' class='download-link' download></a>";
                        }

                    }

                    if (msgtype == "text") {
                            message_content = emojione.shortnameToImage(message_content);  // Set imotions
                        }
                        newMessages[id] = true;
                        newMessagesWin[id] = true;
                        newMessagesSender[id] = sender_name;
                        msg_eventpl(id,sender,senderimg,message_content,time,"append");

                        if (eval(localStorage.sound)) {
                            audiomp3.play();
                            audioogg.play();
                        }
                    //}
                    
                    itemsfound += 1;
                }
            });

            chatHeartbeatCount++;

            if (itemsfound > 0) {
                chatHeartbeatTime = minChatHeartbeat;
                chatHeartbeatCount = 1;
            } else if (chatHeartbeatCount >= 10) {
                chatHeartbeatTime *= 2;
                chatHeartbeatCount = 1;
                if (chatHeartbeatTime > maxChatHeartbeat) {
                    chatHeartbeatTime = maxChatHeartbeat;
                }
            }
            if (itemsfound > 0) {
                $("#chatbox_"+id+" .chatboxcontent").scrollTop($("#chatbox_"+id+" .chatboxcontent")[0].scrollHeight);
            }
        }});
    setTimeout('chatHeartbeat();',chatHeartbeatTime);

}

function get_all_msg(url){
    $.ajax({
        url: url,
        cache: false,
        dataType: "json",
        success: function(data) {

            $.each(data.items, function(i,item){
                if (item) { 
                    chatboxtitle = item.f;
                    chatboximg = item.p2;
                    senderimg = item.p;
                    status = item.st;
                    sender = item.sender;
                    page = item.page;
                    pages = item.pages;
                    msgtype = item.mtype;
                    time = item.time;   

                    if (item.page != "" && i == 0) {
                        $("#chatbox_" + chatboxtitle + " .chatboxcontent").prepend('<input type="hidden" class="pagenum" value="' + item.page + '" /><input type="hidden" class="total-page" value="' + pages + '" />');
                    }

                    if (item.s == 1) {
                        //item.f = username;
                    }

                    var message_content = item.m;
                    if (msgtype == "text") {
                        message_content = item.m;
                        message_content = emojione.shortnameToImage(message_content);
                    }
                    else { 
                        var path = item.m;
                    
                        if (msgtype=="image") {
                            message_content = "<a url='" + path + "' onclick='trigq(this)'><img src='" + path + "' class='userfiles'/></a>";
                        }
                        else if(msgtype == "video") {
                            message_content = '<video class="userfiles" controls>' +
                            '<source src="' + path + '" type="video/mp4">' +
                            'Your browser does not support HTML5 video.' +
                            '</video>';
                        }
                        else{
                            message_content = "<a href='"+path+"' class='download-link' download></a>";
                        }

                    }

                    if (item.s == 2) {
                        $("#chatbox_"+chatboxtitle+" .chatboxcontent").prepend('<div class="chatboxmessage"><div class="_5w-5"><div class="_5w-6"><abbr class="livetimestamp">'+item.m+'</abbr></div></div></div>');
                    } else {
                        if (item.u == 2) {
                            msg_eventpl(chatboxtitle,sender,senderimg,message_content,time,"prepend");
                        } else {
                            msg_oddtpl(chatboxtitle,sender,senderimg,message_content,time,"prepend");
                        }
                    }
                }
                if (page == 1) {
                    $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
                }
            });

        }});


}

function checkChatBoxInputKey(event,chatboxtextarea,chatboxtitle,tipo) {
    if(event.keyCode == 13 && event.shiftKey == 0)  {
        message = $(chatboxtextarea).val();
        message = message.replace(/^\s+|\s+$/g,"");


        $(chatboxtextarea).val('');
        $(chatboxtextarea).focus();
        $(chatboxtextarea).css('height','20px');
        if (message != '') {
            if(tipo=="single"){
                var url = siteurl+"chat/send/" + chatboxtitle;
            }else{
                var url = siteurl+"chat/send-group/" + chatboxtitle;                
            }
            $.post(url, {message: message} , function(data){
                message = message.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");

                var con = message;
                var words = con.split(' ');
                for (i in words) {
                    if (words[i].indexOf('http://') == 0 || words[i].indexOf('https://') == 0) {
                        words[i] = '<a href="' + words[i] + '">' + words[i] + '</a>';
                    }
                    else if (words[i].indexOf('www') == 0 ) {
                        words[i] = '<a href="' + words[i] + '">' + words[i] + '</a>';
                    }
                }
                message = words.join(' ');
                message = emojione.shortnameToImage(message); // Set imotions

                $('#chatbox_'+chatboxtitle+' .target-emoji').css({'display':'none'});
                $('#chatbox_'+chatboxtitle+' .btn-emoji').removeClass('ti-arrow-circle-down').addClass('ti-face-smile');

                msg_oddtpl(chatboxtitle,data.sender,data.sender_profile_img,message,"Ahora","append");

                $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
            });
        }
        chatHeartbeatTime = minChatHeartbeat;
        chatHeartbeatCount = 1;

        return false;
    }

    var adjustedHeight = chatboxtextarea.clientHeight;
    var maxHeight = 94;

    if (maxHeight > adjustedHeight) {
        adjustedHeight = Math.max(chatboxtextarea.scrollHeight, adjustedHeight);
        if (maxHeight)
            adjustedHeight = Math.min(maxHeight, adjustedHeight);
        if (adjustedHeight > chatboxtextarea.clientHeight)
            $(chatboxtextarea).css('height',adjustedHeight+8 +'px');
    } else {
        $(chatboxtextarea).css('overflow','auto');
    }

}

function lastseen(uname){
    $.ajax({
        url: siteurl + "chat/last_seen?uname="+uname,
        cache: false,
        type: "POST",
        success: function (data) {
            var data = data.trim().replace('"','').replace('"','');
            if(data == "Online"){
                $("#chatbox_"+uname+" .panel-heading .status").removeClass("Offline");
            } else{
                $("#chatbox_"+uname+" .panel-heading .status").removeClass("Online");
            }
            $("#chatbox_"+uname+" .panel-heading .status").addClass(data).html(data);
        },
        error: function( error )
        {
            
        }
    });
}

function startChatSession(){
    $.ajax({
        url: siteurl+"chat/start-session",
        cache: false,
        dataType: "json",
        success: function(data) {

            username = data.username;

            $.each(data.items, function(i,item){
                if (item)       {

                    chatboxtitle = item.f;
                    chatboximg = item.p;
                    sesimg = item.p2;
                    status = item.st;

                    if ($("#chatbox_"+chatboxtitle).length <= 0) {
                        createChatBox(chatboxtitle,chatboximg,status,1);
                    }

                    if (item.s == 1) {
                        item.f = username;
                    }

                    if (item.s == 2) {
                        
                    } else {

                        if (item.u == 2) {
                            
                        } else {
                            
                        }
                    }
                }
            });

            for (i=0;i<chatBoxes.length;i++) {
                chatboxtitle = chatBoxes[i];
                $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
                setTimeout('$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);', 100); // yet another strange ie bug

            }

            setTimeout('chatHeartbeat();',1000);
        }});

        setInterval(function () { globalUpdate(); }, 10000);
}

function globalUpdate(){
    onlineSignal();
    loadGroups();
    updateContacts();
    getContactStatus();   
}

function onlineSignal(){
    var url = siteurl+"chat/online-signal";
    $.post(url, {} , function(data){
    });
}

function updateContacts(){
  if (typeof $("#live-search-box").val() !== 'undefined'){
    if($("#live-search-box").val().trim()==""){
        var url = siteurl+"chat/update-contacts";
        $.get(url, {} , function(response){
            if(response.success) {
                $("#contact-list-ul").html(response.data);
            }
        });
    }
  }
}

function getContactStatus()
{
    var url = siteurl+"chat/get-contact-status";
    $.get(url, {} , function(response){

        console.log('get-contact-status');
        console.log(response);
        if(response.success) {
            for(var i=0;i<response.data.length;i++){
                if(response.data[i].status == "Online"){
                    $("#chatbox_"+response.data[i].id+" .panel-heading .status").removeClass("Offline");
                    $("#chatbox_"+response.data[i].id+" .panel-heading .status").addClass("Online");
                    $("#chatbox_"+response.data[i].id+" .panel-heading .status").text("Online");
                } else{
                    $("#chatbox_"+response.data[i].id+" .panel-heading .status").removeClass("Online");
                    $("#chatbox_"+response.data[i].id+" .panel-heading .status").addClass("Offline");
                    $("#chatbox_"+response.data[i].id+" .panel-heading .status").text("Offline");
                }
            }
        }          
    });
}

function closeChatBox(uuid) {
    $('#chatbox_'+uuid).css('display','none');
    restructureChatBoxes();
    var url = siteurl+"chat/close/" + uuid;
    $.post(url, {} , function(data){
    });
}


function clearHistory(uuid){
    var url = siteurl+"chat/clear/" + uuid;
    $.post(url, { } , function(data){
    });
}

function toggleChatBoxGrowth(chatboxtitle) {

    if ($('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display') == 'none') {
        var minimizedChatBoxes = new Array();

        if ($.cookie('chatbox_minimized')) {
            minimizedChatBoxes = $.cookie('chatbox_minimized').split(/\|/);
        }

        var newCookie = '';

        for (i=0;i<minimizedChatBoxes.length;i++) {
            if (minimizedChatBoxes[i] != chatboxtitle) {
                newCookie += chatboxtitle+'|';
            }
        }

        newCookie = newCookie.slice(0, -1)


        $.cookie('chatbox_minimized', newCookie);
        $('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display','block');
        $('#chatbox_'+chatboxtitle+' .chatboxinput').css('display','block');
        $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
    } else {
        var newCookie = chatboxtitle;

        if ($.cookie('chatbox_minimized')) {
            newCookie += '|'+$.cookie('chatbox_minimized');
        }


        $.cookie('chatbox_minimized',newCookie);
        $('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display','none');
        $('#chatbox_'+chatboxtitle+' .chatboxinput').css('display','none');
    }

}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { 
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

var lastTypedTime = new Date(0); 
var typingDelayMillis = 5000; 

function refreshTypingStatus(chatboxtitle){
    /*if (!$('#textarea').is(':focus') || $('#textarea').val() == '' || new Date().getTime() - lastTypedTime.getTime() > typingDelayMillis) {
        $("#typing_on").html('');
    } else {
        $.post(siteurl+"chat/chat.php?action=typingstatus", {to: chatboxtitle, typing: 1} , function(data){

        });
    }*/
}
function updateLastTypedTime() {
    lastTypedTime = new Date();
}

function scrollDown2(chatboxtitle){
    var wtf    = $("#chatbox_"+chatboxtitle+" .chatboxcontent");
    var height = wtf[0].scrollHeight;
    wtf.scrollTop(height);
}

//Search User In contactList
jQuery(document).ready(function(){
    $('.live-search-list li').each(function(){
        $(this).attr('data-search-term', $(this).text().toLowerCase());
    });
    $('.live-search-box').on('keyup', function(){
        var searchTerm = $(this).val().toLowerCase();
        var found = false;

        if($('#contact-list-ul:visible').length == 0){
            $('.live-search-list-group li').each(function(){
                if ($(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1) {
                    $(this).show();
                    found = true;
                } else {
                    $(this).hide();
                }
            });
        }else{

            $('.live-search-list li').each(function(){
                if ($(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1) {
                    $(this).show();
                    found = true;
                } else {
                    $(this).hide();
                }
            });
        }
        if(!found){
            $("#search_result").show();
        }else{
            $("#search_result").hide();
        }
    });



});

function loadGroups()
{

    var url = siteurl+"chat/group-list";
    $.get(url, {} , function(response){

        if(response.success) {
            $("#group-list-ul").html("");
            $("#group-list-ul").html(response.data);
        }
    });
}

function createChatGroup(uuid,name){
    var url = siteurl+"chat/create-group";
    $.post(url, {uuid: uuid,name:name} , function(response){
        if(response.success) {
            loadGroups();
        }
    });
}

function deleteGroup(uuid){
     var c = confirm("Esta seguro de eliminar este grupo de chat?");
     if(c){
        var url = siteurl+"chat/delete-group/" + uuid;
        $.post(url, {} , function(response){
            if(response.success) {
                loadGroups();
            }
        });   
    }
}

function outOfGroup(uuid){
     var c = confirm("Esta seguro de salir de este grupo de chat?");
     if(c){
        var url = siteurl+"chat/leave/" + uuid;
        $.post(url, {} , function(data){
            loadGroups();
        });   
    }
}

function showGroupContacts(uuid){
    var url = siteurl+"chat/contact-group-list/" + uuid;
    $.get(url, {} , function(response){
        if(response.success) {
            $("#contact-group-list-ul").html("");
            $("#contact-group-list-ul").html(response.data);
    
            $(".group-list").css({'display':'none'});
            $(".contact-list").css({'display':'none'});
            $(".group-contacts-list").css({'display':'block'});
        }
    }); 
}

$(document).on('click', ".addUser", function (e){
    var touname = $(this).data('client');
    var name = $(this).data('name');
    var url = siteurl+"chat/contacts-list/" + touname;
    $.get(url, {} , function(response){
        if(response.success) {
            $("#contact-list-ul-gchat-"+touname).html("");
            $("#contact-list-ul-gchat-"+touname).html(response.data);
            $('#chatbox_'+touname+' .chat-conversation').css({'display':'none'});
            $('#participants_'+touname).css({'display':'block'});
        }
    });
    
});

$(document).on('click', ".closeAddUser", function (e){
    var touname = $(this).data('client');
    $('#participants_'+touname).css({'display':'none'});
    $('#chatbox_'+touname+' .chat-conversation').css({'display':'block'});
    
});

$(document).on('click', ".chat-contacts", function (e){
    $(".chat-groups").removeClass('blue-color');
    $(this).addClass('blue-color')
    $(".group-list").css({'display':'none'});
    $(".group-contacts-list").css({'display':'none'});
    $(".contact-list").css({'display':'block'});
    
});

$(document).on('click', ".chat-groups", function (e){
    $(".chat-contacts").removeClass('blue-color');
    $(this).addClass('blue-color');
    $(".contact-list").css({'display':'none'});
    $(".group-contacts-list").css({'display':'none'});
    $(".group-list").css({'display':'block'});
});


function addToGroup(uid,group,name){
    var url = siteurl+"chat/add-user-to-group/" + group + "/" + uid;
    var li = $("#li_user_" + uid  + '_group_' + group);
    $.post(url, {} , function(response){
        if(response.success) {
            li.remove();
        }
    });
}

function removeFromGroup(uid,group){
    var url = siteurl+"chat/add-user-to-group/" + group + "/" + uid;
    $.post(url, {} , function(response){
        if(response.success) {
            showGroupContacts( group );
        }
    });
}


function addMessageUploadFile(item) {
    console.log('S1');

    if (item.hasOwnProperty('id')) {
console.log('S2');
console.log('item');
console.log(item);

        var id = item.id;
        var toName = item.toName;
        var username = item.username;
        var picname = item.picname;
        var msgtype = item.type;

        var path = item.content;
        if (msgtype=="image") {
            message_content = "<a url='" + path + "' onclick='trigq(this)'><img src='" + path + "' class='userfiles'/></a>";
        }
        else if(msgtype == "video") {
            message_content = '<video class="userfiles" controls>' +
            '<source src="' + path + '" type="video/mp4">' +
            'Your browser does not support HTML5 video.' +
            '</video>';
        }
        else {
            message_content = "<a href='"+path+"' class='download-link' download></a>";
        }
        msg_oddtpl(toName,username,picname,message_content,"Ahora","append");

        //$("#chatbox_"+toName+" .chatboxcontent").scrollTop($("#chatbox_"+toName+" .chatboxcontent")[0].scrollHeight);
    }

    return false;
}


EOT;
$this->inlineScript()->captureEnd();

?>
<div id="drupalchat-wrapper">
        <div id="drupalchat" style="">
        <div class="item-list" id="chatbox_chatlist">
                <ul id="mainpanel">
                        <li id="chatpanel" class="first last">
                        <div class="subpanel" style="display: block;">
                                <div class="subpanel_title">
                                        <div style="width: 89%;height: 100%;" id="minmaxchatlist" >Chat</div>
                                        <span class="min localhost-icon-minus-1" id="mute-sound"><i class="icon icon-volume-2 text-20" aria-hidden="true"></i></span>
                                        <span class="min localhost-icon-minus-1" id="new-chat-group" style="margin-right:5%;" title="Crear grupo"><i class="fa fa-edit"></i></span>
                                </div>
                                <div id="showhidechatlist">
                                        <div class="drupalchat_search_main chatboxinput" style="background:#f9f9f9">
                                                <div class="drupalchat_search" style="height:auto;">
                                        <input class="drupalchat_searchinput live-search-box" id="live-search-box" placeholder="Buscar" value="" size="24" type="text">
                                        <input class="searchbutton" id="searchbutton" title="" value="" style="height:30px;border:none;margin:0px; padding-right:13px; vertical-align: middle;" type="submit">
                                        <div id="search_result" style="text-align:center;font-size:11px;display:none;">Sin resultados</div>
                                        </div>
                                </div>
                                <div class="drupalchat_search_main chatboxinput" style="background:#f9f9f9">
                                        <div style="width: 50%;float:left;display:inline-block;padding:5px;text-align:center;font-size:14px;">
                                        <a href="#" class="blue-color chat-contacts">Contactos</a>
                                        </div>
                                        <div style="width: 50%;display:inline-block;padding:5px;text-align:center;font-size:14px;">
                                        <a href="#" class="chat-groups">Grupos</a>
                                        </div>
                                </div>
                                <div class="contact-list chatboxcontent">
                                        <ul id="contact-list-ul" class="live-search-list">
                                                                <?php foreach($contacts as $contact) : 
                                                                
                                                                $url_image = $this->url('storage', ['code' => $contact['id_encrypted'],  'type' =>  'user', 'filename' => $contact['image'] ]);
                                                                
                                                                ?>
                                                                <li class="iflychat-olist-item iflychat-ol-ul-user-img iflychat-userlist-room-item chat_options" data-search-term="<?php echo trim(strtolower($contact['name'])) ?>">
                                                        <div class="drupalchat-self-profile">
                                                                <span title="<?php echo $contact['status'] ?>" class="'. $status. ' statuso" style="text-align: right">
                                                                        <span class="statusIN"><i class="fa fa-circle" style="font-size:10px;margin-top:4px" aria-hidden="true"></i></span>
                                                                </span>
                                                                <div class="drupalchat-self-profile-div">
                                                                        <div class="drupalchat-self-profile-img + localhost-image-sprite-28">
                                                                                <img class="chat-image img-circle pull-left" height="36" width="36" src="<?php echo $url_image ?>" alt="image-image">
                                                                        </div>
                                                                </div>
                                                                <div class="drupalchat-self-profile-namdiv">
                                                                <a class="drupalchat-profile-un drupalchat_cng" href="javascript:void(0)" onclick="javascript:chatWith('<?php echo $contact['id'] ?>','<?php echo $url_image ?>','<?php echo $contact['status'] ?>','<?php echo $contact['name'] ?>')"><?php echo $contact['name'] ?></a>
                                                        </div>
                                                        </div>
                                                </li>
                                                <?php endforeach; ?>
                                                                
                                                                
                                        </ul>
                                </div>
                                <div class="group-list chatboxcontent" style="display:none;">
                                        <ul id="group-list-ul" class="live-search-list-group">
                                                <?php foreach($groups as $group) :
                                                if($group['owner']){
                                                    $action_icon = "fa fa-trash";
                                                    $click_icon = 'javascript:deleteGroup(\'' . $group['id'] . '\')';
                                                    $title_action = "Eliminar Grupo";
                                                }else{
                                                    $action_icon = "fa fa-sign-out";
                                                    $click_icon = 'javascript:outOfGroup(\'' .$group['id'] . '\')';
                                                    $title_action = "Salir del Grupo";
                                                }
                                ?>
                                    

                    
                                <li class="iflychat-olist-item iflychat-ol-ul-user-img iflychat-userlist-room-item chat_options" data-search-term="<?php echo trim(strtolower($group['name'])) ?>">
                                        <div class="drupalchat-self-profile">
                                                <span style="text-align: right" class="Offline statuso">
                                                        <span class="statusIN"><i title="Integrantes" class="fa fa-users" style="font-size:14px;margin-top:4px;" aria-hidden="true" 
                                                                 onclick="javascript:showGroupContacts('<?php echo $group['id'] ?>')"></i>
                                                        </span>
                                                        <span class="statusIN">
                                                                <i title="<?php echo $title_action ?>" class="<?php echo  $action_icon ?>" style="font-size:14px;margin-top:4px;" aria-hidden="true" onclick="<?php echo $click_icon ?>"></i>
                                                        </span>
                                                </span>
                                                <div class="drupalchat-self-profile-div">
                                                        <div class="drupalchat-self-profile-img + localhost-image-sprite-28">
                                                                <img class="chat-image img-circle pull-left" height="36" width="36" src="<?php echo $users_group_png ?>" alt="image-image">
                                                        </div>
                                                </div>
                                                <div class="drupalchat-self-profile-namdiv">
                                                        <a class="drupalchat-profile-un drupalchat_cng" href="javascript:void(0)" onclick="javascript:chatGroup('<?php echo $group['id'] ?>','<?php echo $group['name'] ?>')"> <?php echo $group['name'] ?> </a>
                                                </div>
                                        </div>
                                </li>
                                        
                                                <?php endforeach; ?>
                                        </ul>
                                </div>
                                <div class="group-contacts-list chatboxcontent" style="display:none;">
                                        <div style="text-align:center;font-size:13px;">Integrantes del grupo</div>
                                                                <ul id="contact-group-list-ul" class="live-search-list"></ul>
                                        </div>
                                </div>
                        </div>
                        </li>
                </ul>
        </div>
        </div>
</div>

<!--This div for modal light box chat box image-->
<table id="lightbox" class="lightbox"  style="display: none;height: 100%">
    <tr>
        <td height="10px"><p><img src="<?php echo $this->basePath('images/close-icon-white.png')?>" width="30px" style="cursor: pointer"/></p></td>
    </tr>
    <tr>
        <td valign="middle"><div id="content"><img src="#"/></div></td>
    </tr>
</table>
<!--This div for modal light box chat box image-->
<!--This div for modal light box chat box image-->
<table id="lightbox_group" class="lightbox" style="display: none;height: 100%">
    <tr>
        <td height="10px"><p><img src="<?php echo $this->basePath('images/close-icon-white.png')?>" width="30px" style="cursor: pointer"/></p></td>
    </tr>
    <tr>
        <td valign="middle"><div id="gcontent"></div></td>
    </tr>
</table>
<!--This div for modal light box chat box image-->

<form id="form-new-group" style="display: none; z-index: 1000">
  Nombre del grupo:
  <input type="text" id="group_name" maxlength="50" />
  <input type="button" id="btn_submit_group" value="Crear" class="pull-right">
</form>