<script type="text/javascript">
(function(_, $) {
    $(document).on("click","#send_sms_custom",function(){       
        if ($('#alt_orders tbody tr').length){
            var orders_ids = "";
            $('.alt-orders-input').each(function(){
                if ($(this).prop("checked")){
                    orders_ids = orders_ids + $(this).val() + ",";
                }
            });
            $.ceAjax('request', fn_url("addons.send_massive_sms"), {
                data:{
                    orders_ids: orders_ids,
                    text: $("textarea[id^='addon_option_targetsms_custom_sms_content']").val(),
                    senders: $("select[id^='addon_option_targetsms_custom_sms_sender']").val()
                },
                callback: function(response){
                    $("input[id^='addon_option_targetsms_phone_numbers']").val("");
                    $("textarea[id^='addon_option_targetsms_custom_sms_content']").val("");        
                }
            });      
        }else{
            $.ceAjax('request', fn_url("addons.send_sms"), {    
                data:{
                    phones: $("input[id^='addon_option_targetsms_phone_numbers']").val(),
                    text: $("textarea[id^='addon_option_targetsms_custom_sms_content']").val(),
                    senders: $("select[id^='addon_option_targetsms_custom_sms_sender']").val()
                },
                callback: function(response){
                    $("input[id^='addon_option_targetsms_phone_numbers']").val("");
                    $("textarea[id^='addon_option_targetsms_custom_sms_content']").val("");          
                }
            });
        }
    }); 

    $(document).on("click","#search_orders",function(){  
        $.ceAjax('request', fn_url("addons.search_orders_by_date"), {
            data:{
                from: $('#tsms_date_order_from').val(),
                to: $('#tsms_date_order_to').val(),
                result_ids: 'tsms_order_list',
            },
        });
        return false;
    });
    $(document).on("click","#alt_reset_orders",function(){  
        $.ceAjax('request', fn_url("addons.search_orders_by_date"), {
            data:{
                is_reset: true,
                result_ids: 'tsms_order_list',
            },
        });
        return false;
    })
    
}(Tygh, Tygh.$));
</script>