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');
if(localStorage.getItem('imguse')){
	myimgs = localStorage.getItem('imguse');
}else{
	myimgs = 'images/icon-user-default.png';
}

var divs = '';
$.ajax({
  type: "POST",
  crossDomain: true,
  url: "http://m2s.es/app/api/getfriends.php",
  data: {"key": keyuser},
  cache: false,
  dataType: 'json',
  beforeSend: function() {
      console.log('Reading list of your friends...');
      $('#list-friends').append('<div id="loading-user" id="load-idsd"><img src="images/loading.gif" width="25px" height="25px"/> <span>'+Language.loading+'</span></div>');
  },
  success: function(result) {
    if (result.friends) {
      if (result.friends.length == '0') {
        $('#list-friends').append("<div class='no-friends'><h4>"+Language.nofriends+"</h4><p>"+Language.nofriendsinfo+"</p></div>");
        $('#loading-user').remove();
      }else{
	      localStorage.setItem('lasturl', document.URL);
      for (var i = 0; i < result.friends.length; i++) {
        id = result.friends[i].id;
        username = result.friends[i].username;
        imagepr = result.friends[i].imagepr;
        state = result.friends[i].lastmessage;
        unreadmsm = result.friends[i].unreadmsm;
        if(imagepr == null){
          imagepr = 'images/icon-user-default.png';
        }
        if(state != null){
          statemeis = result.friends[i].lastmessage.meis;
        }else{
          statemeis = 'yes';
        }
        if (unreadmsm == '0') {
          unreadmsm = '';
        }
        var localidsfdf = localStorage.getItem('lastmsmc-' + result.friends[i].id);
        if(localidsfdf != null){
            mstate = localidsfdf;
            mstated = localStorage.getItem('lastmsmcd-' + result.friends[i].id);
        }else{
            mstate = '--';
            mstated = '';
        }

        divs += '<a href="chat.html?id='+id+'" class="backck"';
        if (state == null) {
            divs += ' last-date="'+mstated+'">';
        } else {
          	if(statemeis == 'yes'){
            	divs += ' last-date="'+mstated+'">';
          	}else{
            	divs += ' last-date="'+state.date+'">';
          	}
        }
        divs += '<li class="li-chats" id="list-' + id + '"><img src="';
        divs += imagepr;
        divs += '" class="img"/><div class="right-info">';
        if(unreadmsm != ''){
        	divs += '<font>'+unreadmsm+'</font>';
        }
        divs += '<span class="icon chevron-right"></span></div><div class="right-p"><div><span class="name">';
        divs += username;
        divs += '</span><span class="state">';

        if (state == null) {
            divs += mstate;
        } else {
          if(statemeis == 'yes'){
            divs += mstate;
          }else{
            divs += state.text;
          }
        }

        divs += '</span></div></div></li></a>';
      };
      $('#loading-user').remove();
      $('#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(Language.errorconection);
    $('#list-notifications').click(function() {
      window.location.reload();
    })
  }
});
}