function pagefunctions(){
var input = document.getElementById('search-input');
input.onkeyup = function() {
  var filter = input.value.toUpperCase();
  var lis = document.getElementsByClassName('li-chats');
  for (var i = 0; i < lis.length; i++) {
    var name = lis[i].getElementsByClassName('name')[0].innerHTML;
    if (name.toUpperCase().indexOf(filter) == 0)
      lis[i].style.display = 'block';
    else
      lis[i].style.display = 'none';
  }
}
var keyuser = localStorage.getItem('keyuser');
var divs = '';
$.ajax({
  type: "POST",
  crossDomain: true,
  url: "http://m2s.es/app/api/getmygroups.php",
  data: {"key": keyuser},
  cache: false,
  dataType: 'json',
  beforeSend: function() {
      console.log('Reading list of your groups...');
      $('#list-friends').append('<div id="loading-user" class="load-idsd"><img src="images/loading.gif" width="25px" height="25px"/> <span>'+Language.loading+'</span></div>');
  },
  success: function(result) {
    if (result.groups) {
      if (result.groups == 'no') {
        $('#list-friends').append("<div class='no-friends'><h4>"+Language.nogroupsjoin+"</h4><p>"+Language.nogroupsjoininfo+"</p></div>");
        $('.load-idsd').remove();
      }else{
	     localStorage.setItem('lasturl', document.URL);
      for (var i = 0; i < result.groups.length; i++) {
        id = result.groups[i].id;
        namegroup = result.groups[i].namegroup;
        official = result.groups[i].official;
        imagepr = result.groups[i].imagepr;
        state = result.groups[i].lastmessage;
        statedate = result.groups[i].lastmessagedate;
        unreadmsm = result.groups[i].unreadmsm;
        var localidsfdf = localStorage.getItem('lastmsmcgr-' + result.groups[i].id);
        if(localidsfdf != null){
            mstate = localidsfdf;
            mstated = localStorage.getItem('lastmsmcgrd-' + result.groups[i].id);
        }else{
            mstate = '--';
            mstated = '';
        }

        if (unreadmsm == '0') {
          unreadmsm = '';
        }
        divs += '<a href="chatgr.html?id='+id+'"'; 
        if (state == null) {
            divs += ' last-date="'+mstated+'">';
        }else{
            divs += ' last-date="'+statedate+'">';
        }
        divs += '<li class="li-chats" id="list-' + id + '">';
        if (imagepr != null) {
          divs += '<img src="' + imagepr + '" class="img"/>';
        } else {
          var namesplit = namegroup.split(' ');
          abv1 = namesplit[0].charAt(0);
          if (namesplit[1]) {
            abv2 = namesplit[1].charAt(0);
            abv = abv1 + abv2;
          } else {
            abv = abv1;
          }
          divs += '<div class="img" style="background-color:#777"><p unselectable="on" onselectstart="return false;" onmousedown="return false;">' + abv + '</p></div>';
        }
        divs += '<div class="right-info">';
        if(unreadmsm != ''){
        	divs += '<font>'+unreadmsm+'</font>';
        }
        if (official == 'yes') {
          divs += '<span class="icon ok"></span>';
        }
        divs += '<span class="icon chevron-right"></span></div><div class="right-p"><div><span class="name">';
        divs += namegroup;
        divs += '</span><span class="state">';

        if(state == null) {
            divs += mstate;
        }else{
            divs += state;
        }

        divs += '</span></div></div></li></a>';
      }
      $('.load-idsd').remove();
      if($('#list-'+id).length == '0'){
        $('#list-friends').append(divs);
      }
      tinysort('#list-friends>a',{attr:'last-date',order:'desc'})
     }
    }
  },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
    console.error(textStatus + ' ' + XMLHttpRequest.status);
    var divno = document.createElement('div');
    divno.innerHTML = '<div id="list-notifications" style="text-align:center;cursor:pointer"></div>';
    divno.className = 'background-dark';
    var modsv = document.getElementById('modsv');
    modsv.appendChild(divno);
    $('#list-notifications').append('<b>Error:</b> '+Language.errorconection);
    $('#list-notifications').click(function() {
      window.location.reload();
    })
  }
});
}