(function($){
    $.fn.refreshSMSlist = function(options) {
        var ele = $(this).find("tbody");
        var content = $(ele).html();
        $.ajax({
            type: 'post',
            url: 'contents/plugins/messaging/ajax.php',
            data: {action: 'get_sms_list'}
        }).done(function(data){
            try {
                data = JSON.parse(data);
                var i = 1;
                $(ele).html("");
                for(var name in data) {
                    if(data[name].callback == 'custom_sms_receivers_list') {
                        var html = '<tr><td>'+i+'</td><td>';
                        html += data[name].group_name+'</td><td>';
                        html += '<a href="javaScript:void(0);" class="ajax-action" data-callback="refreshSMSlist" data-name="'+name+'" data-action-callback="delete_from_sms_list">delete</a>&nbsp;|&nbsp;<a href="edit-sms-list?list='+name+'">edit</a></td></tr>';
                        $(ele).append(html);
                        i++;
                    }
                }
            }
            catch(err) {
                $(ele).html(content);
                console.log(err);
                console.log(data);
            }
            finally{}
        }).fail(function(){
            $(ele).html(content);
        })
    }

    $.extend({
        refreshSMSlist: function(options) {
            var ele = $("#sms-list").find("tbody");
            var content = $(ele).html();
            $.ajax({
                type: 'post',
                url: 'contents/plugins/messaging/ajax.php',
                data: {action: 'get_sms_list'}
            }).done(function(data){
                try {
                    data = JSON.parse(data);
                    var i = 1;
                    $(ele).html("");
                    for(var name in data) {
                        if(data[name].callback == 'custom_sms_receivers_list') {
                            var html = '<tr><td>'+i+'</td><td>';
                            html += data[name].group_name+'</td><td>';
                            html += '<a href="javaScript:void(0);" class="ajax-action" data-callback="refreshSMSlist" data-name="'+name+'" data-action-callback="delete_from_sms_list">delete</a>&nbsp;|&nbsp;<a href="edit-sms-list?list='+name+'">edit</a></td></tr>';
                            $(ele).append(html);
                            i++;
                        }
                    }
                }
                catch(err) {
                    $(ele).html(content);
                    console.log(err);
                    console.log(data);
                }
                finally{}
            }).fail(function(){
                $(ele).html(content);
            })
        }
    })
})(jQuery);

function count_chars(string)
{
  //var special = ['^', '{', '}', '\\', '[', '~', ']', '|', '€'];

    var j = 0;

    for (var i = 0; i < string.length; i++)
    {
        if (string.charAt(i) == '\n') {
          j++;
        }
        else if (string.charAt(i) == '^') {
         j++;
        }
        else if (string.charAt(i) == '{') {
         j++;
        }
        else if (string.charAt(i) == '}') {
         j++;
        }
        else if (string.charAt(i) == '\\') {
         j++;
        }
        else if (string.charAt(i) == '[') {
         j++;
        }
        else if (string.charAt(i) == '~') {
         j++;
        }
        else if (string.charAt(i) == ']') {
         j++;
        }
        else if (string.charAt(i) == '|') {
         j++;
        }
        else if (string.charAt(i) == '€') {
         j++;
        }
        else {
         //do nothing
        }
    }

    return string.length + j;
}