
var C_LIST_SUSPECT              = "77114";
var C_SUSPECT_ADD               = "77115";
var C_SUSPECT_CONVERSATION      = "77116";
var C_PERSON_CONTACT            = "77118";
var C_LIST_FOLLOWUP             = "77120";
var C_UPDATE_CALL_SCRIPT        = "77121";

var person_datas                = "";
var commun_tab_style            = "";
var gift_tab_style              = "none";
var software_used_style         = "none";
var subsidiary_style            = "none";

// A company renders collapsed, and every dropdown it owns is then either hidden, disabled,
// or showing a single value. So each one ships holding only its selected option and is given
// the full list when the company is expanded. Rendering every option of every dropdown for
// every row is what made the filter slow.
// Status and Status2 stay enabled while collapsed, so they keep their full list.
var suspect_tpl_cache  = {};
var suspect_time_label = null;
var suspect_user_label = null;

function resetSuspectTemplates() {
    suspect_tpl_cache  = {};
    suspect_time_label = null;
    suspect_user_label = null;
}

//serialise each hidden template once per render instead of re-reading the DOM for every row
function suspectTplHtml(tplId) {
    if (suspect_tpl_cache[tplId] === undefined) {
        suspect_tpl_cache[tplId] = $('#' + tplId).html();
    }
    return suspect_tpl_cache[tplId];
}

function suspectLabelMap(tplId) {
    var map = {};
    $('#' + tplId + ' option').each(function () { map[this.value] = this.text; });
    return map;
}
function suspectTimeLabel() {
    if (suspect_time_label === null) suspect_time_label = suspectLabelMap('cobTimeOption');
    return suspect_time_label;
}
function suspectUserLabel() {
    if (suspect_user_label === null) suspect_user_label = suspectLabelMap('cobUserList');
    return suspect_user_label;
}

//the single option a collapsed select carries: keeps the visible text right and keeps
//.val() returning the saved value for the save routine
function suspectOneOption(value, label) {
    var v = (value === null || value === undefined) ? "" : String(value);
    var t = (label === null || label === undefined || label === "") ? v : label;
    return '<option value="' + v + '" selected>' + t + '</option>';
}
function suspectOneOptionFromMap(value, labels) {
    var v = (value === null || value === undefined) ? "" : String(value);
    return suspectOneOption(v, labels[v]);
}

//swap every placeholder select on this company for its full option list, keeping the value
function fillSuspectOptions(coId) {
    $('select[data-lazy-co="' + coId + '"]').each(function () {
        var $s = $(this);
        var v  = $s.val();
        $s.html(suspectTplHtml($s.attr('data-lazy-tpl'))).val(v);
        $s.removeAttr('data-lazy-tpl').removeAttr('data-lazy-co');
    });
}

$(document).ready(function () {
	$('#uploading').hide();
	$('#view_doc').hide();

	$('#txtDoc').on('change', function () {
		upload_form = this.form;
	});
            $('#followup-table-body').html(''); 
            $('#followup-table-body').append('<tr><td colspan="8">No follow-up records found.</td></tr>');
		upload_form = this.form;

        
    $(document).on("click", ".toggle-btn", function () {
        const $text = $(this).siblings(".truncate-text");
        $text.toggleClass("expanded");
        $(this).text($text.hasClass("expanded") ? "Show less" : "Show more");

    });
});

function clearFilter(){
    $('#txtSuspectIndustry').val('');
    $('#txtSuspectBusinessSector').val('');
    $('#txtSuspectNoOfEmployee').val('');
    $('#txtSuspectCompanyName').val('');
    $('#txtSuspectTelephone').val('');
    $('#txtSuspectState').val('');
    $('#cobSuspectAccountFlag').val('');
}

function filterFollowUpTable(){
    LoadingScreen("show");
    var data = {
        "type"          : C_LIST_FOLLOWUP,
        "action_from"   : $('#txtFollowUpActionDateFrom').val(),
        "action_to"     : $('#txtFollowUpActionDateTO').val(),
    };

    var url = "request.pzx?c=" + telemarketing_url + "&d=" + new Date().getTime();
    callServer(url, "json", data, onResponseSuspectEntry, null);
}

function endOfAction(contact_id){
    LoadingScreen("show");
    var data = {
        "type"       : "C_END_OF_ACTION",
        "contact_id" : contact_id
    };

    var url = "request.pzx?c=" + telemarketing_url + "&d=" + new Date().getTime();
    callServer(url, "json", data, onResponseSuspectEntry, null);
}

function showFollowUpList(myObj) {
    prospect_idx = 1;

    $('#followup-table-body').html('');

    for (i in myObj) {
        prospect_id         = myObj[i].prospect_id;
        contact_id          = myObj[i].contact_id;
        action_date         = myObj[i].action_date;
        best_time           = myObj[i].best_time;
        full_name           = myObj[i].full_name;
        last_conversation   = myObj[i].last_conversation;
        next_action         = myObj[i].next_action;
        phone_number        = myObj[i].phone_number;
        assign_to           = myObj[i].assign_to;

        $('#followup-table-body').append(
            '<tr id="tr_followup' + prospect_idx + '">' +
                '<td></td>' +
                '<td style="vertical-align: top !important; padding-top: 5px !important;"><label id="action_date' + prospect_idx + '" class="action_date" value="' + action_date + '" >' + action_date + '</label></td>' +
                '<td style="vertical-align: top !important; padding-top: 5px !important;"><label id="best_time' + prospect_idx + '" class="best_time" value="' + best_time + '" >' + best_time + '</label></td>' +
                '<td style="vertical-align: top !important; padding-top: 5px !important;"><label id="full_name' + prospect_idx + '" class="full_name" value="' + full_name + '" >' + full_name + '</label></td>' +
                '<td style="vertical-align: top !important; padding-top: 5px !important;"><span id="last_conversation' + prospect_idx + '" class="last_conversation truncate-text" value="' + last_conversation + '" >' + last_conversation + '</span><a class="toggle-btn">Show more</a></td>' +
                '<td style="vertical-align: top !important; padding-top: 5px !important;"><span id="next_action' + prospect_idx + '" class="next_action truncate-text" value="' + next_action + '" >' + next_action + '</span><a class="toggle-btn">Show more</a></td>' +
                '<td style="vertical-align: top !important; padding-top: 5px !important;"><label id="phone_number' + prospect_idx + '" class="phone_number" value="' + phone_number + '" >' + phone_number + '</label></td>' +
                '<td style="vertical-align: top !important; padding-top: 5px !important;"><label id="assign_to' + prospect_idx + '" class="assign_to" value="' + assign_to + '" >' + assign_to + '</label></td>' +
                '<td style="text-align:center!important;vertical-align: top !important; white-space: nowrap;"><label id="action' + prospect_idx + '" class="action">'+
                    '<button class="btn btn-secondary" style="background-color:grey;color:white;margin-top:5px;margin-right:8px;" type="button" onclick="filterSuspectList(' + prospect_id + ');">View</button>'+
                    '<button class="btn btn-danger" style="margin-top:5px;margin-right:8px;" type="button" onclick="endOfAction('+ contact_id +');">End of action</button>'+
                '</td>' +
                '<td style="display:none" class="prospect_id" id="prospect_id' + prospect_idx + '">' + prospect_id + '</td>' +
                '<td style="display:none" class="contact_id" id="contact_id' + prospect_idx + '">' + contact_id + '</td>' +
                '<td style="display:none" class="prospect_idx" id="prospect_idx' + prospect_idx + '">' + prospect_idx + '</td>' +
            '</tr>'
        );

        prospect_idx++;
    }
    $(".truncate-text").each(function () {
        if (this.scrollWidth <= this.clientWidth) {
            $(this).siblings(".toggle-btn").hide();
        }
    });
}

function showHideFollowUpTable(view_detail=false){
    if(!view_detail) {
        if($('#followup-table-body').css('display') == 'none') {
            //show
            $('#followup-table-body').css("display", "");
            $('#followUpTable').height("200px"); 
            $('#collapse-followup').html('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-down-fill" viewBox="0 0 16 16">'
                                        +'<path d="M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z"/>'
                                    +'</svg>');
            
        } else {
            //hide
            $('#followup-table-body').css("display", "none");
            $('#followUpTable').height("65px"); 
            $('#collapse-followup').html('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-right-fill" viewBox="0 0 16 16">'
                                        +'<path d="m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z"/>'
                                    +'</svg>');
        }
    } else {
        //hide
        $('#followup-table-body').css("display", "none");
            $('#followUpTable').height("65px"); 
            $('#collapse-followup').html('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-right-fill" viewBox="0 0 16 16">'
                                        +'<path d="m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z"/>'
                                    +'</svg>');
    }
    
    
}

function filterSuspectList(prospect_id=0){
    LoadingScreen("show");

    var data = {
        "type"              : C_LIST_SUSPECT,
        "industry"          : $('#txtSuspectIndustry').val(),
        "business_sector"   : $('#txtSuspectBusinessSector').val(),
        "total_employee"    : $('#txtSuspectNoOfEmployee').val(),
        "company_name"      : $('#txtSuspectCompanyName').val(),
        "telephone"         : $('#txtSuspectTelephone').val(),
        "state"             : $('#txtSuspectState').val(),
        "account_flag"      : $('#cobSuspectAccountFlag').val(),
        "prospect_id"       : prospect_id,
    };

    var url = "request.pzx?c=" + telemarketing_url + "&d=" + new Date().getTime();
    callServer(url, "json", data, onResponseSuspectEntry, prospect_id);
}

function htmlSuspectHeader(id, myObj = null, list_options = null){
    account_flag            = "";
    account_flag_desc       = "";
    company_name            = "";
    company_status          = "";
    sales_status            = "";
    sales_status2           = "";
    status_color            = "";
    telephone               = "";
    telephone2              = "";
    website                 = "";
    business_desc           = "";
    industry                = "";
    business_sector         = "";
    business_nature         = "";
    total_employee          = "";
    acc_software            = "";
    acc_software_c          = "";
    acc_software_n          = "";
    acc_software_user       = "";
    sales_software          = "";
    sales_software_c        = "";
    sales_software_n        = "";
    sales_software_user     = "";
    other_software          = "";
    other_software_n        = "";
    other_software_c        = "";
    other_software_user     = "";
    company_detail          = "";
    proposal_1              = "";
    proposal_2              = "";
    subsidiary_location     = "";
    subsidiary_entity       = "";
    company_email           = "";
    company_linkedin        = "";
    company_source          = "";
    company_state           = "";
    // sales_status_option     = "";
    // sales_status2_option    = "";
    // company_status_option   = "";
    // industry_option         = "";
    // business_sector_option  = "";
    // soft_acc_option         = "";
    // soft_sales_option       = "";
    // soft_other_option       = "";
    if(myObj != null){
        account_flag            = myObj.account_flag;
        account_flag_desc       = myObj.account_flag_desc;
        company_name            = myObj.company_name;
        company_status          = myObj.company_status;
        sales_status            = myObj.sales_status;
        sales_status2           = myObj.sales_status2;
        status_color            = myObj.status_color;
        telephone               = myObj.telephone;
        telephone2              = myObj.telephone2;
        website                 = myObj.website;
        business_desc           = myObj.business_desc;
        industry                = myObj.industry;
        business_sector         = myObj.business_sector;
        business_nature         = myObj.business_nature;
        total_employee          = myObj.total_employee;
        acc_software            = myObj.acc_software;
        acc_software_c          = myObj.acc_software_c;
        acc_software_n          = myObj.acc_software_n;
        acc_software_user       = myObj.acc_software_user;
        sales_software          = myObj.sales_software;
        sales_software_c        = myObj.sales_software_c;
        sales_software_n        = myObj.sales_software_n;
        sales_software_user     = myObj.sales_software_user;
        other_software          = myObj.other_software;
        other_software_c        = myObj.other_software_c;
        other_software_n        = myObj.other_software_n;
        other_software_user     = myObj.other_software_user;
        company_detail          = myObj.company_detail;
        proposal_1              = myObj.proposal_1;
        proposal_2              = myObj.proposal_2;
        subsidiary_location     = myObj.subsidiary_location;
        subsidiary_entity       = myObj.subsidiary_entity;
        company_email           = myObj.company_email;
        company_linkedin        = myObj.company_linkedin;
        company_source          = myObj.company_source;
        company_state           = myObj.company_state;
        // sales_status_option     = list_options['status_option'];
        // sales_status2_option    = list_options['status2_option'];
        // company_status_option   = list_options['company_option'];
        // industry_option         = list_options['industry_option'];
        // business_sector_option  = list_options['business_sector_option'];
        // soft_acc_option         = list_options['soft_acc_option'];
        // soft_sales_option       = list_options['soft_sales_option'];
        // soft_other_option       = list_options['soft_other_option'];
    }

    html = '<tr id="tr_suspect_'+id+'">'
                +'<td style="padding: 4px !important;" onclick="showSuspectDetail(\''+id+'\')" id="change-icon'+id+'">'
                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-right-fill" viewBox="0 0 16 16">'
                        +'<path d="m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z"/>'
                    +'</svg>'
                +'</td>'
                +'<td style="padding-top:5px !important; vertical-align: top !important;">'
                    +'<div class="form-group rows">'
                        +'<div class="col-lg-7" style="padding-left:0px; padding-right: 0px;">'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderAccountFlag'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-flag" viewBox="0 0 16 16">'
                                        + '<path d="M14.778.085A.5.5 0 0 1 15 .5V8a.5.5 0 0 1-.314.464L14.5 8l.186.464-.003.001-.006.003-.023.009a12 12 0 0 1-.397.15c-.264.095-.631.223-1.047.35-.816.252-1.879.523-2.71.523-.847 0-1.548-.28-2.158-.525l-.028-.01C7.68 8.71 7.14 8.5 6.5 8.5c-.7 0-1.638.23-2.437.477A20 20 0 0 0 3 9.342V15.5a.5.5 0 0 1-1 0V.5a.5.5 0 0 1 1 0v.282c.226-.079.496-.17.79-.26C4.606.272 5.67 0 6.5 0c.84 0 1.524.277 2.121.519l.043.018C9.286.788 9.828 1 10.5 1c.7 0 1.638-.23 2.437-.477a20 20 0 0 0 1.349-.476l.019-.007.004-.002h.001M14 1.221c-.22.078-.48.167-.766.255-.81.252-1.872.523-2.734.523-.886 0-1.592-.286-2.203-.534l-.008-.003C7.662 1.21 7.139 1 6.5 1c-.669 0-1.606.229-2.415.478A21 21 0 0 0 3 1.845v6.433c.22-.078.48-.167.766-.255C4.576 7.77 5.638 7.5 6.5 7.5c.847 0 1.548.28 2.158.525l.028.01C9.32 8.29 9.86 8.5 10.5 8.5c.668 0 1.606-.229 2.415-.478A21 21 0 0 0 14 7.655V1.222z"/>'
                                    + '</svg> : ' + account_flag_desc
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderAccountFlag'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-flag" viewBox="0 0 16 16">'
                                        + '<path d="M14.778.085A.5.5 0 0 1 15 .5V8a.5.5 0 0 1-.314.464L14.5 8l.186.464-.003.001-.006.003-.023.009a12 12 0 0 1-.397.15c-.264.095-.631.223-1.047.35-.816.252-1.879.523-2.71.523-.847 0-1.548-.28-2.158-.525l-.028-.01C7.68 8.71 7.14 8.5 6.5 8.5c-.7 0-1.638.23-2.437.477A20 20 0 0 0 3 9.342V15.5a.5.5 0 0 1-1 0V.5a.5.5 0 0 1 1 0v.282c.226-.079.496-.17.79-.26C4.606.272 5.67 0 6.5 0c.84 0 1.524.277 2.121.519l.043.018C9.286.788 9.828 1 10.5 1c.7 0 1.638-.23 2.437-.477a20 20 0 0 0 1.349-.476l.019-.007.004-.002h.001M14 1.221c-.22.078-.48.167-.766.255-.81.252-1.872.523-2.734.523-.886 0-1.592-.286-2.203-.534l-.008-.003C7.662 1.21 7.139 1 6.5 1c-.669 0-1.606.229-2.415.478A21 21 0 0 0 3 1.845v6.433c.22-.078.48-.167.766-.255C4.576 7.77 5.638 7.5 6.5 7.5c.847 0 1.548.28 2.158.525l.028.01C9.32 8.29 9.86 8.5 10.5 8.5c.668 0 1.606-.229 2.415-.478A21 21 0 0 0 14 7.655V1.222z"/>'
                                    + '</svg>'
                                +'</label>'
                                +'<select id="cboSuspectHeaderAccountFlag'+id+'" class="form-control showInput'+id+'" style="max-width: 175px;display:none;" placeholder="Account Flag" value="'+account_flag+'"'
                                + (myObj != null ? ' data-lazy-tpl="cobAccountFlagsOption" data-lazy-co="'+id+'"' : '') + '>'
                                + (myObj != null ? suspectOneOption(account_flag, account_flag_desc) : suspectTplHtml('cobAccountFlagsOption'))
                                +'</select>'
                                +'<input type="text" class="form-control" style="max-width: 175px;visibility:hidden;" placeholder="Account Flag" value="'+account_flag+'" disabled>'
                            +'</div>'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderCompanyName'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-building" viewBox="0 0 16 16">'
                                        +'<path d="M4 2.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm3 0a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm3.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5zM4 5.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zM7.5 5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5zm2.5.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zM4.5 8a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5zm2.5.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm3.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5z"/>'
                                        +'<path d="M2 1a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1zm11 0H3v14h3v-2.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 .5.5V15h3z"/>'
                                    +'</svg> : '+ company_name
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderCompanyName'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-building" viewBox="0 0 16 16">'
                                        +'<path d="M4 2.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm3 0a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm3.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5zM4 5.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zM7.5 5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5zm2.5.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zM4.5 8a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5zm2.5.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm3.5-.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5z"/>'
                                        +'<path d="M2 1a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1zm11 0H3v14h3v-2.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 .5.5V15h3z"/>'
                                    +'</svg> '
                                +'</label>'
                                +'<input id="txtSuspectHeaderID'+id+'" type="hidden" value="'+id+'">'
                                +'<input id="txtSuspectHeaderCompanyName'+id+'" type="text" class="form-control showInput'+id+'" style="max-width: 350px;display:none;" placeholder="Company Name" value="'+company_name+'">'
                            +'</div>'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter" id="inputSuspectHeaderTelephone'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-telephone" viewBox="0 0 16 16">'
                                        +'<path d="M3.654 1.328a.678.678 0 0 0-1.015-.063L1.605 2.3c-.483.484-.661 1.169-.45 1.77a17.6 17.6 0 0 0 4.168 6.608 17.6 17.6 0 0 0 6.608 4.168c.601.211 1.286.033 1.77-.45l1.034-1.034a.678.678 0 0 0-.063-1.015l-2.307-1.794a.68.68 0 0 0-.58-.122l-2.19.547a1.75 1.75 0 0 1-1.657-.459L5.482 8.062a1.75 1.75 0 0 1-.46-1.657l.548-2.19a.68.68 0 0 0-.122-.58zM1.884.511a1.745 1.745 0 0 1 2.612.163L6.29 2.98c.329.423.445.974.315 1.494l-.547 2.19a.68.68 0 0 0 .178.643l2.457 2.457a.68.68 0 0 0 .644.178l2.189-.547a1.75 1.75 0 0 1 1.494.315l2.306 1.794c.829.645.905 1.87.163 2.611l-1.034 1.034c-.74.74-1.846 1.065-2.877.702a18.6 18.6 0 0 1-7.01-4.42 18.6 18.6 0 0 1-4.42-7.009c-.362-1.03-.037-2.137.703-2.877z"/>'
                                    +'</svg>'
                                +'</label>'
                                +'<input id="txtSuspectHeaderTelephone'+id+'" type="text" class="form-control txtSoftware'+id+'" style="max-width: 175px;" disabled placeholder="Telephone" value="'+telephone+'">'
                                +'<input id="txtSuspectHeaderTelephone2'+id+'" type="text" class="form-control txtSoftware'+id+'" style="max-width: 175px;" disabled placeholder="Telephone 2" value="'+telephone2+'">'
                            +'</div>'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderCompEmail'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-envelope" viewBox="0 0 16 16">'
                                        +'<path d="M0 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v.217l7 4.2 7-4.2V4a1 1 0 0 0-1-1zm13 2.383-4.708 2.825L15 11.105zm-.034 6.876-5.64-3.471L8 9.583l-1.326-.795-5.64 3.47A1 1 0 0 0 2 13h12a1 1 0 0 0 .966-.741M1 11.105l4.708-2.897L1 5.383z"/>'
                                    +'</svg> : ' + company_email
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderCompEmail'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-envelope" viewBox="0 0 16 16">'
                                        +'<path d="M0 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v.217l7 4.2 7-4.2V4a1 1 0 0 0-1-1zm13 2.383-4.708 2.825L15 11.105zm-.034 6.876-5.64-3.471L8 9.583l-1.326-.795-5.64 3.47A1 1 0 0 0 2 13h12a1 1 0 0 0 .966-.741M1 11.105l4.708-2.897L1 5.383z"/>'
                                    +'</svg>'
                                +'</label>'
                                +'<input id="txtSuspectHeaderCompEmail'+id+'" type="text" class="form-control showInput'+id+'" style="max-width: 350px;display:none;" placeholder="Company Email" value="'+company_email+'">'
                            +'</div>'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderWebsite'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-globe" viewBox="0 0 16 16">'
                                        +'<path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8m7.5-6.923c-.67.204-1.335.82-1.887 1.855A8 8 0 0 0 5.145 4H7.5zM4.09 4a9.3 9.3 0 0 1 .64-1.539 7 7 0 0 1 .597-.933A7.03 7.03 0 0 0 2.255 4zm-.582 3.5c.03-.877.138-1.718.312-2.5H1.674a7 7 0 0 0-.656 2.5zM4.847 5a12.5 12.5 0 0 0-.338 2.5H7.5V5zM8.5 5v2.5h2.99a12.5 12.5 0 0 0-.337-2.5zM4.51 8.5a12.5 12.5 0 0 0 .337 2.5H7.5V8.5zm3.99 0V11h2.653c.187-.765.306-1.608.338-2.5zM5.145 12q.208.58.468 1.068c.552 1.035 1.218 1.65 1.887 1.855V12zm.182 2.472a7 7 0 0 1-.597-.933A9.3 9.3 0 0 1 4.09 12H2.255a7 7 0 0 0 3.072 2.472M3.82 11a13.7 13.7 0 0 1-.312-2.5h-2.49c.062.89.291 1.733.656 2.5zm6.853 3.472A7 7 0 0 0 13.745 12H11.91a9.3 9.3 0 0 1-.64 1.539 7 7 0 0 1-.597.933M8.5 12v2.923c.67-.204 1.335-.82 1.887-1.855q.26-.487.468-1.068zm3.68-1h2.146c.365-.767.594-1.61.656-2.5h-2.49a13.7 13.7 0 0 1-.312 2.5m2.802-3.5a7 7 0 0 0-.656-2.5H12.18c.174.782.282 1.623.312 2.5zM11.27 2.461c.247.464.462.98.64 1.539h1.835a7 7 0 0 0-3.072-2.472c.218.284.418.598.597.933M10.855 4a8 8 0 0 0-.468-1.068C9.835 1.897 9.17 1.282 8.5 1.077V4z"/>'
                                    +'</svg> : ' + website
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderWebsite'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-globe" viewBox="0 0 16 16">'
                                        +'<path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8m7.5-6.923c-.67.204-1.335.82-1.887 1.855A8 8 0 0 0 5.145 4H7.5zM4.09 4a9.3 9.3 0 0 1 .64-1.539 7 7 0 0 1 .597-.933A7.03 7.03 0 0 0 2.255 4zm-.582 3.5c.03-.877.138-1.718.312-2.5H1.674a7 7 0 0 0-.656 2.5zM4.847 5a12.5 12.5 0 0 0-.338 2.5H7.5V5zM8.5 5v2.5h2.99a12.5 12.5 0 0 0-.337-2.5zM4.51 8.5a12.5 12.5 0 0 0 .337 2.5H7.5V8.5zm3.99 0V11h2.653c.187-.765.306-1.608.338-2.5zM5.145 12q.208.58.468 1.068c.552 1.035 1.218 1.65 1.887 1.855V12zm.182 2.472a7 7 0 0 1-.597-.933A9.3 9.3 0 0 1 4.09 12H2.255a7 7 0 0 0 3.072 2.472M3.82 11a13.7 13.7 0 0 1-.312-2.5h-2.49c.062.89.291 1.733.656 2.5zm6.853 3.472A7 7 0 0 0 13.745 12H11.91a9.3 9.3 0 0 1-.64 1.539 7 7 0 0 1-.597.933M8.5 12v2.923c.67-.204 1.335-.82 1.887-1.855q.26-.487.468-1.068zm3.68-1h2.146c.365-.767.594-1.61.656-2.5h-2.49a13.7 13.7 0 0 1-.312 2.5m2.802-3.5a7 7 0 0 0-.656-2.5H12.18c.174.782.282 1.623.312 2.5zM11.27 2.461c.247.464.462.98.64 1.539h1.835a7 7 0 0 0-3.072-2.472c.218.284.418.598.597.933M10.855 4a8 8 0 0 0-.468-1.068C9.835 1.897 9.17 1.282 8.5 1.077V4z"/>'
                                    +'</svg>'
                                +'</label>'
                                +'<input id="txtSuspectHeaderWebsite'+id+'" type="text" class="form-control showInput'+id+'" style="max-width: 350px;display:none;" placeholder="Website" value="'+website+'">'
                            +'</div>'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderLinkedIn'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-linkedin" viewBox="0 0 16 16">'
                                        +'<path d="M0 1.146C0 .513.526 0 1.175 0h13.65C15.474 0 16 .513 16 1.146v13.708c0 .633-.526 1.146-1.175 1.146H1.175C.526 16 0 15.487 0 14.854zm4.943 12.248V6.169H2.542v7.225zm-1.2-8.212c.837 0 1.358-.554 1.358-1.248-.015-.709-.52-1.248-1.342-1.248S2.4 3.226 2.4 3.934c0 .694.521 1.248 1.327 1.248zm4.908 8.212V9.359c0-.216.016-.432.08-.586.173-.431.568-.878 1.232-.878.869 0 1.216.662 1.216 1.634v3.865h2.401V9.25c0-2.22-1.184-3.252-2.764-3.252-1.274 0-1.845.7-2.165 1.193v.025h-.016l.016-.025V6.169h-2.4c.03.678 0 7.225 0 7.225z"/>'
                                    +'</svg> : ' + company_linkedin
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderLinkedIn'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-linkedin" viewBox="0 0 16 16">'
                                        +'<path d="M0 1.146C0 .513.526 0 1.175 0h13.65C15.474 0 16 .513 16 1.146v13.708c0 .633-.526 1.146-1.175 1.146H1.175C.526 16 0 15.487 0 14.854zm4.943 12.248V6.169H2.542v7.225zm-1.2-8.212c.837 0 1.358-.554 1.358-1.248-.015-.709-.52-1.248-1.342-1.248S2.4 3.226 2.4 3.934c0 .694.521 1.248 1.327 1.248zm4.908 8.212V9.359c0-.216.016-.432.08-.586.173-.431.568-.878 1.232-.878.869 0 1.216.662 1.216 1.634v3.865h2.401V9.25c0-2.22-1.184-3.252-2.764-3.252-1.274 0-1.845.7-2.165 1.193v.025h-.016l.016-.025V6.169h-2.4c.03.678 0 7.225 0 7.225z"/>'
                                    +'</svg>'
                                +'</label>'
                                +'<input id="txtSuspectHeaderLinkedIn'+id+'" type="text" class="form-control showInput'+id+'" style="max-width: 350px;display:none;" placeholder="LinkedIn" value="'+company_linkedin+'">'
                            +'</div>'
                        +'</div>'
                        +'<div class="col-lg-5" style="padding-left:0px; padding-right: 0px;">'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                            +'<input type="text" class="form-control" style="max-width: 175px;visibility:hidden;" disabled>'
                            +'</div>'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderIndustry'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-buildings" viewBox="0 0 16 16">'
                                        +'<path d="M14.763.075A.5.5 0 0 1 15 .5v15a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5V14h-1v1.5a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5V10a.5.5 0 0 1 .342-.474L6 7.64V4.5a.5.5 0 0 1 .276-.447l8-4a.5.5 0 0 1 .487.022M6 8.694 1 10.36V15h5zM7 15h2v-1.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 .5.5V15h2V1.309l-7 3.5z"/>'
                                        +'<path d="M2 11h1v1H2zm2 0h1v1H4zm-2 2h1v1H2zm2 0h1v1H4zm4-4h1v1H8zm2 0h1v1h-1zm-2 2h1v1H8zm2 0h1v1h-1zm2-2h1v1h-1zm0 2h1v1h-1zM8 7h1v1H8zm2 0h1v1h-1zm2 0h1v1h-1zM8 5h1v1H8zm2 0h1v1h-1zm2 0h1v1h-1zm0-2h1v1h-1z"/>'
                                    +'</svg> : ' + industry
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderIndustry'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-buildings" viewBox="0 0 16 16">'
                                        +'<path d="M14.763.075A.5.5 0 0 1 15 .5v15a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5V14h-1v1.5a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5V10a.5.5 0 0 1 .342-.474L6 7.64V4.5a.5.5 0 0 1 .276-.447l8-4a.5.5 0 0 1 .487.022M6 8.694 1 10.36V15h5zM7 15h2v-1.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 .5.5V15h2V1.309l-7 3.5z"/>'
                                        +'<path d="M2 11h1v1H2zm2 0h1v1H4zm-2 2h1v1H2zm2 0h1v1H4zm4-4h1v1H8zm2 0h1v1h-1zm-2 2h1v1H8zm2 0h1v1h-1zm2-2h1v1h-1zm0 2h1v1h-1zM8 7h1v1H8zm2 0h1v1h-1zm2 0h1v1h-1zM8 5h1v1H8zm2 0h1v1h-1zm2 0h1v1h-1zm0-2h1v1h-1z"/>'
                                    +'</svg>'
                                +'</label>';
        // if(industry_option != null){
        //     html +=             '<select class="form-control showInput'+id+'" id="txtSuspectHeaderIndustry'+id+'" style="display: none;">'
        //                             +industry_option
        //                         +'</select>';
        // }else{
            html +=             '<select class="form-control showInput'+id+'" id="txtSuspectHeaderIndustry'+id+'" style="display: none;"'
                                    + (myObj != null ? ' data-lazy-tpl="cobIndustryOption" data-lazy-co="'+id+'"' : '') + '>'
                                    + (myObj != null ? suspectOneOption(myObj.industry_id, industry) : suspectTplHtml('cobIndustryOption'))
                                +'</select>';
        // }
        html +=              '</div>'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderBusinessSector'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-suitcase-lg" viewBox="0 0 16 16">'
                                        +'<path d="M5 2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2h3.5A1.5 1.5 0 0 1 16 3.5v9a1.5 1.5 0 0 1-1.5 1.5H14a.5.5 0 0 1-1 0H3a.5.5 0 0 1-1 0h-.5A1.5 1.5 0 0 1 0 12.5v-9A1.5 1.5 0 0 1 1.5 2zm1 0h4a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1M1.5 3a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5H3V3zM15 12.5v-9a.5.5 0 0 0-.5-.5H13v10h1.5a.5.5 0 0 0 .5-.5m-3 .5V3H4v10z"/>'
                                    +'</svg> : ' + business_sector
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderBusinessSector'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-suitcase-lg" viewBox="0 0 16 16">'
                                        +'<path d="M5 2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2h3.5A1.5 1.5 0 0 1 16 3.5v9a1.5 1.5 0 0 1-1.5 1.5H14a.5.5 0 0 1-1 0H3a.5.5 0 0 1-1 0h-.5A1.5 1.5 0 0 1 0 12.5v-9A1.5 1.5 0 0 1 1.5 2zm1 0h4a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1M1.5 3a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5H3V3zM15 12.5v-9a.5.5 0 0 0-.5-.5H13v10h1.5a.5.5 0 0 0 .5-.5m-3 .5V3H4v10z"/>'
                                    +'</svg>'
                                +'</label>';
        // if(business_sector_option != null){
        //     html +=             '<select class="form-control showInput'+id+'" id="txtSuspectHeaderBusinessSector'+id+'" style="display: none;">'
        //                             +business_sector_option
        //                         +'</select>';
        // }else{
            html +=             '<select class="form-control showInput'+id+'" id="txtSuspectHeaderBusinessSector'+id+'" style="display: none;"'
                                    + (myObj != null ? ' data-lazy-tpl="cobBusinessSectorOption" data-lazy-co="'+id+'"' : '') + '>'
                                    + (myObj != null ? suspectOneOption(myObj.business_sector_id, business_sector) : suspectTplHtml('cobBusinessSectorOption'))
                                +'</select>';
        // }
        html +=             '</div>'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderBusinessNature'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-briefcase" viewBox="0 0 16 16">'
                                        +'<path d="M6.5 1A1.5 1.5 0 0 0 5 2.5V3H1.5A1.5 1.5 0 0 0 0 4.5v8A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-8A1.5 1.5 0 0 0 14.5 3H11v-.5A1.5 1.5 0 0 0 9.5 1zm0 1h3a.5.5 0 0 1 .5.5V3H6v-.5a.5.5 0 0 1 .5-.5m1.886 6.914L15 7.151V12.5a.5.5 0 0 1-.5.5h-13a.5.5 0 0 1-.5-.5V7.15l6.614 1.764a1.5 1.5 0 0 0 .772 0M1.5 4h13a.5.5 0 0 1 .5.5v1.616L8.129 7.948a.5.5 0 0 1-.258 0L1 6.116V4.5a.5.5 0 0 1 .5-.5"/>'
                                    +'</svg> : ' + business_nature
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderBusinessNature'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-briefcase" viewBox="0 0 16 16">'
                                        +'<path d="M6.5 1A1.5 1.5 0 0 0 5 2.5V3H1.5A1.5 1.5 0 0 0 0 4.5v8A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-8A1.5 1.5 0 0 0 14.5 3H11v-.5A1.5 1.5 0 0 0 9.5 1zm0 1h3a.5.5 0 0 1 .5.5V3H6v-.5a.5.5 0 0 1 .5-.5m1.886 6.914L15 7.151V12.5a.5.5 0 0 1-.5.5h-13a.5.5 0 0 1-.5-.5V7.15l6.614 1.764a1.5 1.5 0 0 0 .772 0M1.5 4h13a.5.5 0 0 1 .5.5v1.616L8.129 7.948a.5.5 0 0 1-.258 0L1 6.116V4.5a.5.5 0 0 1 .5-.5"/>'
                                    +'</svg>'
                                +'</label>';
            html +=             '<select class="form-control showInput'+id+'" id="txtSuspectHeaderBusinessNature'+id+'" style="display: none;"'
                                    + (myObj != null ? ' data-lazy-tpl="cobBusinessNatureOption" data-lazy-co="'+id+'"' : '') + '>'
                                    + (myObj != null ? suspectOneOption(myObj.business_nature_id, business_nature) : suspectTplHtml('cobBusinessNatureOption'))
                                +'</select>';
        html +=             '</div>'
                            +'<div class="col-lg-12" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderTotalEmployee'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person-standing" viewBox="0 0 16 16">'
                                        +'<path d="M8 3a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3M6 6.75v8.5a.75.75 0 0 0 1.5 0V10.5a.5.5 0 0 1 1 0v4.75a.75.75 0 0 0 1.5 0v-8.5a.25.25 0 1 1 .5 0v2.5a.75.75 0 0 0 1.5 0V6.5a3 3 0 0 0-3-3H7a3 3 0 0 0-3 3v2.75a.75.75 0 0 0 1.5 0v-2.5a.25.25 0 0 1 .5 0"/>'
                                    +'</svg> : ' + total_employee
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderTotalEmployee'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person-standing" viewBox="0 0 16 16">'
                                        +'<path d="M8 3a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3M6 6.75v8.5a.75.75 0 0 0 1.5 0V10.5a.5.5 0 0 1 1 0v4.75a.75.75 0 0 0 1.5 0v-8.5a.25.25 0 1 1 .5 0v2.5a.75.75 0 0 0 1.5 0V6.5a3 3 0 0 0-3-3H7a3 3 0 0 0-3 3v2.75a.75.75 0 0 0 1.5 0v-2.5a.25.25 0 0 1 .5 0"/>'
                                    +'</svg>'
                                +'</label>'
                                +'<input id="txtSuspectHeaderTotalEmployee'+id+'" type="text" class="form-control showInput'+id+'" style="max-width: 350px;display:none;" placeholder="Total Employee" value="'+total_employee+'">'
                            +'</div>'
                            +'<div class="col-lg-6" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderSource'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search" viewBox="0 0 16 16">'
                                        +'<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0"/>'
                                    +'</svg> : ' + company_source
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderSource'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search" viewBox="0 0 16 16">'
                                        +'<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0"/>'
                                    +'</svg>'
                                +'</label>'
                                +'<input id="txtSuspectHeaderSource'+id+'" type="text" class="form-control showInput'+id+'" style="max-width: 350px;display:none;" placeholder="Source" value="'+company_source+'">'
                            +'</div>'
                            +'<div class="col-lg-6" style="display:flex; padding-left:0px;">'
                                +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderState'+id+'">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pin-map-fill" viewBox="0 0 16 16">'
                                        +'<path fill-rule="evenodd" d="M3.1 11.2a.5.5 0 0 1 .4-.2H6a.5.5 0 0 1 0 1H3.75L1.5 15h13l-2.25-3H10a.5.5 0 0 1 0-1h2.5a.5.5 0 0 1 .4.2l3 4a.5.5 0 0 1-.4.8H.5a.5.5 0 0 1-.4-.8z"/>'
                                        +'<path fill-rule="evenodd" d="M4 4a4 4 0 1 1 4.5 3.969V13.5a.5.5 0 0 1-1 0V7.97A4 4 0 0 1 4 3.999z"/>'
                                    +'</svg> : ' + company_state
                                +'</label>'
                                +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderState'+id+'" style="display:none;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pin-map-fill" viewBox="0 0 16 16">'
                                        +'<path fill-rule="evenodd" d="M3.1 11.2a.5.5 0 0 1 .4-.2H6a.5.5 0 0 1 0 1H3.75L1.5 15h13l-2.25-3H10a.5.5 0 0 1 0-1h2.5a.5.5 0 0 1 .4.2l3 4a.5.5 0 0 1-.4.8H.5a.5.5 0 0 1-.4-.8z"/>'
                                        +'<path fill-rule="evenodd" d="M4 4a4 4 0 1 1 4.5 3.969V13.5a.5.5 0 0 1-1 0V7.97A4 4 0 0 1 4 3.999z"/>'
                                    +'</svg>'
                                +'</label>'
                                +'<input id="txtSuspectHeaderState'+id+'" type="text" class="form-control showInput'+id+'" style="max-width: 350px;display:none;" placeholder="State" value="'+company_state+'">'
                            +'</div>'
                        +'</div>'
                    +'</div>'
                +'</td>'
                +'<td style="padding:5px !important; vertical-align: top !important; display:'+subsidiary_style+';" class="colSubsidiary">'
                    +'<div class="col-lg-12" style="padding-left:0px; display:flex;">'
                        +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderSubsidiaryLocation'+id+'">'
                            +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-geo-alt" viewBox="0 0 16 16">'
                                +'<path d="M12.166 8.94c-.524 1.062-1.234 2.12-1.96 3.07A32 32 0 0 1 8 14.58a32 32 0 0 1-2.206-2.57c-.726-.95-1.436-2.008-1.96-3.07C3.304 7.867 3 6.862 3 6a5 5 0 0 1 10 0c0 .862-.305 1.867-.834 2.94M8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10"/>'
                                +'<path d="M8 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4m0 1a3 3 0 1 0 0-6 3 3 0 0 0 0 6"/>'
                            +'</svg> : ' + subsidiary_location
                        +'</label>'
                        +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderSubsidiaryLocation'+id+'" style="display:none;">'
                            +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-geo-alt" viewBox="0 0 16 16">'
                                +'<path d="M12.166 8.94c-.524 1.062-1.234 2.12-1.96 3.07A32 32 0 0 1 8 14.58a32 32 0 0 1-2.206-2.57c-.726-.95-1.436-2.008-1.96-3.07C3.304 7.867 3 6.862 3 6a5 5 0 0 1 10 0c0 .862-.305 1.867-.834 2.94M8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10"/>'
                                +'<path d="M8 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4m0 1a3 3 0 1 0 0-6 3 3 0 0 0 0 6"/>'
                            +'</svg>'
                        +'</label>'
                        +'<input id="txtSuspectHeaderSubsidiaryLocation'+id+'" type="text" class="form-control showInput'+id+'" style="max-width: 250px; display:none;" placeholder="Location" value="'+subsidiary_location+'">'
                    +'</div>'
                    +'<div class="col-lg-12" style="padding-left:0px; display:flex;">'
                        +'<label class="labelSVGCenter showLabel'+id+'" id="lblSuspectHeaderSubsidiaryEntity'+id+'">'
                            +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-buildings" viewBox="0 0 16 16">'
                                +'<path d="M14.763.075A.5.5 0 0 1 15 .5v15a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5V14h-1v1.5a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5V10a.5.5 0 0 1 .342-.474L6 7.64V4.5a.5.5 0 0 1 .276-.447l8-4a.5.5 0 0 1 .487.022M6 8.694 1 10.36V15h5zM7 15h2v-1.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 .5.5V15h2V1.309l-7 3.5z"/>'
                                +'<path d="M2 11h1v1H2zm2 0h1v1H4zm-2 2h1v1H2zm2 0h1v1H4zm4-4h1v1H8zm2 0h1v1h-1zm-2 2h1v1H8zm2 0h1v1h-1zm2-2h1v1h-1zm0 2h1v1h-1zM8 7h1v1H8zm2 0h1v1h-1zm2 0h1v1h-1zM8 5h1v1H8zm2 0h1v1h-1zm2 0h1v1h-1zm0-2h1v1h-1z"/>'
                            +'</svg> : ' + subsidiary_entity
                        +'</label>'
                        +'<label class="labelSVGCenter showInput'+id+'" id="inputSuspectHeaderSubsidiaryEntity'+id+'" style="display:none;">'
                            +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-buildings" viewBox="0 0 16 16">'
                                +'<path d="M14.763.075A.5.5 0 0 1 15 .5v15a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5V14h-1v1.5a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5V10a.5.5 0 0 1 .342-.474L6 7.64V4.5a.5.5 0 0 1 .276-.447l8-4a.5.5 0 0 1 .487.022M6 8.694 1 10.36V15h5zM7 15h2v-1.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 .5.5V15h2V1.309l-7 3.5z"/>'
                                +'<path d="M2 11h1v1H2zm2 0h1v1H4zm-2 2h1v1H2zm2 0h1v1H4zm4-4h1v1H8zm2 0h1v1h-1zm-2 2h1v1H8zm2 0h1v1h-1zm2-2h1v1h-1zm0 2h1v1h-1zM8 7h1v1H8zm2 0h1v1h-1zm2 0h1v1h-1zM8 5h1v1H8zm2 0h1v1h-1zm2 0h1v1h-1zm0-2h1v1h-1z"/>'
                            +'</svg>'
                        +'</label>'
                        +'<input id="txtSuspectHeaderSubsidiaryEntity'+id+'" type="text" class="form-control showInput'+id+'" style="max-width: 250px; display:none;" placeholder="Entity" value="'+subsidiary_entity+'">'
                    +'</div>'
                +'</td>'
                +'<td style="padding:5px !important; vertical-align: top !important;">'
                    +'<label id="suspect_status" class="showLabel'+id+'">'+business_desc+'</label>'
                    +'<textarea id="txtSuspectHeaderBusinessDesc'+id+'" class="form-control showInput'+id+'" rows="4" style="display:none;" placeholder="Business Description">'+business_desc+'</textarea>'
                +'</td>'
                +'<td style="padding:5px !important; vertical-align: top !important; display:'+software_used_style+'" class="colSoftwareUsed">'
                    +'<div class="form-group-rows">'
                        +'<div class="col-lg-2" style="padding:6px 0px 0px 0px;">'
                            +'<label>Acc : </label>'
                        +'</div>'
                        +'<div class="col-lg-5" style="padding:0px;">'
    // if(soft_acc_option != null){
    //     html +=             '<select class="form-control txtSoftware'+id+'" id="txtSuspectHeaderAccSoft'+id+'" disabled>'
    //                             +soft_acc_option
    //                         +'</select>';
    // }else{
        html +=             '<select class="form-control txtSoftware'+id+'" id="txtSuspectHeaderAccSoft'+id+'" disabled'
                                + (myObj != null ? ' data-lazy-tpl="cobSoftwareAccountingOption" data-lazy-co="'+id+'"' : '') + '>'
                                + (myObj != null ? suspectOneOption(myObj.acc_software_id, acc_software) : suspectTplHtml('cobSoftwareAccountingOption'))
                            +'</select>';
    // }
        html +=          '</div>'
                        +'<div class="col-lg-2" style="padding:0px;">'
                            +'<input id="txtSuspectHeaderAccSoftC'+id+'" type="text" class="form-control txtSoftware'+id+'" placeholder="C/N/No" value="'+acc_software_c+'" disabled>'
                        +'</div>'
                        +'<div class="col-lg-2" style="padding:0px;">'
                            +'<input id="txtSuspectHeaderAccSoftN'+id+'" type="text" class="form-control txtSoftware'+id+'" placeholder="C/P" value="'+acc_software_n+'" disabled>'
                        +'</div>'
                        +'<div class="col-lg-1" style="padding:0px;">'
                            +'<input id="txtSuspectHeaderAccSoftUser'+id+'" type="text" class="form-control txtSoftware'+id+'" placeholder="5" value="'+acc_software_user+'" disabled>'
                        +'</div>'
                    +'</div>'
                    +'<div class="form-group-rows">'
                        +'<div class="col-lg-2" style="padding:6px 0px 0px 0px;">'
                            +'<label>Sales : </label>'
                        +'</div>'
                        +'<div class="col-lg-5" style="padding:0px;">'
    // if(soft_sales_option != null){
    //     html +=             '<select class="form-control txtSoftware'+id+'" id="txtSuspectHeaderSalesSoft'+id+'" disabled>'
    //                             +soft_sales_option
    //                         +'</select>';
    // }else{
        html +=             '<select class="form-control txtSoftware'+id+'" id="txtSuspectHeaderSalesSoft'+id+'" disabled'
                                + (myObj != null ? ' data-lazy-tpl="cobSoftwareSalesOption" data-lazy-co="'+id+'"' : '') + '>'
                                + (myObj != null ? suspectOneOption(myObj.sales_software_id, sales_software) : suspectTplHtml('cobSoftwareSalesOption'))
                            +'</select>';
    // }
        html +=          '</div>'
                        +'<div class="col-lg-2" style="padding:0px;">'
                            +'<input id="txtSuspectHeaderSalesSoftC'+id+'" type="text" class="form-control txtSoftware'+id+'" placeholder="C/N/No" value="'+sales_software_c+'" disabled>'
                        +'</div>'
                        +'<div class="col-lg-2" style="padding:0px;">'
                            +'<input id="txtSuspectHeaderSalesSoftN'+id+'" type="text" class="form-control txtSoftware'+id+'" placeholder="C/P" value="'+sales_software_n+'" disabled>'
                        +'</div>'
                        +'<div class="col-lg-1" style="padding:0px;">'
                        +'<input id="txtSuspectHeaderSalesSoftUser'+id+'" type="text" class="form-control txtSoftware'+id+'" placeholder="5" value="'+sales_software_user+'" disabled>'
                        +'</div>'
                    +'</div>'
                    +'<div class="form-group-rows">'
                        +'<div class="col-lg-2" style="padding:6px 0px 0px 0px;">'
                            +'<label>Other : </label>'
                        +'</div>'
                        +'<div class="col-lg-5" style="padding:0px;">'
    // if(soft_other_option != null){
    //     html +=             '<select class="form-control txtSoftware'+id+'" id="txtSuspectHeaderOtherSoft'+id+'" disabled>'
    //                             +soft_other_option
    //                         +'</select>';
    // }else{
        html +=             '<select class="form-control txtSoftware'+id+'" id="txtSuspectHeaderOtherSoft'+id+'" disabled'
                                + (myObj != null ? ' data-lazy-tpl="cobSoftwareOtherOption" data-lazy-co="'+id+'"' : '') + '>'
                                + (myObj != null ? suspectOneOption(myObj.other_software_id, other_software) : suspectTplHtml('cobSoftwareOtherOption'))
                            +'</select>';
    // }
        html +=          '</div>'
                        +'<div class="col-lg-2" style="padding:0px;">'
                            +'<input id="txtSuspectHeaderOtherSoftC'+id+'" type="text" class="form-control txtSoftware'+id+'" placeholder="C/N/No" value="'+other_software_n+'" disabled>'
                        +'</div>'
                        +'<div class="col-lg-2" style="padding:0px;">'
                            +'<input id="txtSuspectHeaderOtherSoftN'+id+'" type="text" class="form-control txtSoftware'+id+'" placeholder="C/P" value="'+other_software_c+'" disabled>'
                        +'</div>'
                        +'<div class="col-lg-1" style="padding:0px;">'
                            +'<input id="txtSuspectHeaderOtherSoftUser'+id+'" type="text" class="form-control txtSoftware'+id+'" placeholder="5" value="'+other_software_user+'" disabled>'
                        +'</div>'
                    +'</div>'
                +'</td>'
                +'<td style="padding:5px !important; vertical-align: top !important;">'
                    +'<div class="form-group-rows">'
                        +'<div class="col-lg-12 showLabel'+id+'" style="padding:6px 0px 0px 0px;">'
                            +'<label>Status: </label>'
                            +'<label> &nbsp;'+sales_status+'</label>'
                        +'</div>'
                        +'<div class="col-lg-3 showInput'+id+'" style="padding:6px 0px 0px 0px; display: none;">'
                            +'<label>Status: </label>'
                        +'</div>'
                        +'<div class="col-lg-9 showInput'+id+'" style="padding:0px; display:none;">';
    // if(sales_status_option != null){
    //     html +=             '<select class="form-control" id="txtSuspectHeaderStatus'+id+'" onchange="changeStatus2(\''+id+'\')">'
    //                             +sales_status_option
    //                         +'</select>'
    //                         ;
    // }else{
        html +=             '<select class="form-control" id="txtSuspectHeaderStatus'+id+'" onchange="changeStatus2(\''+id+'\')">'
                                +suspectTplHtml('cobStatusOption')
                            +'</select>';
    // }
    html +=             '</div>'
                    +'</div>'
                    +'<br>'
                    +'<div class="form-group-rows">'
                        +'<div class="col-lg-12 showLabel'+id+'" style="padding:6px 0px 0px 0px;">'
                            +'<label>Status2: </label>'
                            +'<label style="color:'+status_color+';"> &nbsp;'+sales_status2+'</label>'
                        +'</div>'
                        +'<div class="col-lg-3 showInput'+id+'" style="padding:6px 0px 0px 0px; display: none;">'
                            +'<label>Status2: </label>'
                        +'</div>'
                        +'<div class="col-lg-9 showInput'+id+'" style="padding:0px; display:none;">';
    // if(sales_status2_option != null){
    //     html +=             '<select class="form-control" id="txtSuspectHeaderStatus2'+id+'" style="color:'+status_color+'" onchange="onchangeStatusColor('+id+')">'
    //                             +sales_status2_option
    //                         +'</select>'
    //                         ;
    // }else{
        html +=             '<select class="form-control" id="txtSuspectHeaderStatus2'+id+'" style="color:red" onchange="onchangeStatusColor('+id+')">'
                                +suspectTplHtml('cobStatus2Option')
                            +'</select>';
    // }
    html +=             '</div>'
                    +'</div>'
                    +'<br>'
                    +'<div class="form-group-rows">'
                        +'<div class="col-lg-12 showLabel'+id+'" style="padding:6px 0px 0px 0px;">'
                            +'<label>CStatus: </label>'
                            +'<label> &nbsp;'+company_status+'</label>'
                        +'</div>'
                        +'<div class="col-lg-3 showInput'+id+'" style="padding:6px 0px 0px 0px; display: none;">'
                            +'<label>CStatus: </label>'
                        +'</div>'
                        +'<div class="col-lg-9 showInput'+id+'" style="padding:0px; display:none;">';
    // if(company_status_option != null){
    //     html +=             '<select class="form-control" id="txtSuspectHeaderActiveStatus'+id+'">'
    //                             +company_status_option
    //                         +'</select>'
    //                         ;
    // }else{
        html +=             '<select class="form-control" id="txtSuspectHeaderActiveStatus'+id+'">'
                                +'<option value="0">Inactive</option>'
                                +'<option value="1">Active</option>'
                            +'</select>';
    // }
    html +=             '</div>'
                    +'</div>'
                    +'<br>'
                    +'<div class="form-group-rows">'
                        +'<div class="col-lg-12 showLabel'+id+'" style="padding:6px 0px 0px 0px;">'
                            +'<label>P1 : '+proposal_1+'</label>'
                        +'</div>'
                        +'<div class="col-lg-3 showInput'+id+'" style="padding:6px 0px 0px 0px; display: none;">'
                            +'<label>P1 : </label>'
                        +'</div>'
                        +'<div class="col-lg-9 showInput'+id+'" style="padding:0px; display:none;">'
                            +'<input id="txtSuspectHeaderProposal1'+id+'" type="text" class="form-control" placeholder="P1" value="'+proposal_1+'">'
                        +'</div>'
                    +'</div>'
                    +'<br>'
                    +'<div class="form-group-rows" style="display:none;">'
                        +'<div class="col-lg-12 showLabel'+id+'" style="padding:6px 0px 0px 0px;">'
                            +'<label>P2 : '+proposal_2+'</label>'
                        +'</div>'
                        +'<div class="col-lg-3 showInput'+id+'" style="padding:6px 0px 0px 0px; display: none;">'
                            +'<label>P2 : </label>'
                        +'</div>'
                        +'<div class="col-lg-9 showInput'+id+'" style="padding:0px; display:none;">'
                            +'<input id="txtSuspectHeaderProposal2'+id+'" type="text" class="form-control" placeholder="P2" value="'+proposal_2+'">'
                        +'</div>'
                    +'</div>'
                +'</td>'
            +'</tr>';
    return html;
}

function htmlSuspectContactHeader(id, detail_html = ""){
    html = '<tr id="tr_suspect_child'+id+'" style="display:none;">'
                +'<td style="padding: 4px !important;" class="innerTableContent">'
                    +'<button class="btn btn-success btn-sm btn-icon btn-icon-md" type="button" id="btnNewContact" onclick="addSuspectDetail(\''+id+'\');"><i class="fa fa-plus"></i></button>'
                +'</td>'
                +'<td colspan="5" style="padding: 5px !important;">'
                    +'<input type="hidden" id="current_count'+id+'" value="1">'
                    +'<input type="hidden" id="current_delete'+id+'" value="0">'
                    +'<table class="table ">'
                        +'<thead style="background-color: #808080 !important;">'
                            +'<tr style="background-color: #808080 !important;">'
                                +'<td class="innerTableHeader" style="width: 2%">Seq</td>'
                                +'<td class="innerTableHeader" style="width: 12%">Designation</td>'
                                +'<td class="innerTableHeader" style="width: 12%">Name</td>'
                                +'<td class="innerTableHeader" style="width: 12%">Contact</td>'
                                +'<td class="innerTableHeader" style="width: 15%">'
                                    +'<label style="width:49%;display:inline-block">Conversation</label>'
                                +'</td>'
                                +'<td class="innerTableHeader" style="width: 15%">Next Action</td>'
                                +'<td class="innerTableHeader" style="width: 5%">Action Date</td>'
                                +'<td class="innerTableHeader" style="width: 7%">Best Time</td>'
                                +'<td class="innerTableHeader" style="width: 7%">Lunch Time</td>'
                                +'<td class="innerTableHeader" style="width: 7%">'
                                    +'<label>Assign to</label>'
                                    +'<input type="hidden" id="communTabStyle'+id+'" value="">'
                                +'</td>'
                                +'<td class="innerTableHeader center-svg col-commu-'+id+'" style="width: 2%;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-telephone" viewBox="0 0 16 16">'
                                        +'<path d="M3.654 1.328a.678.678 0 0 0-1.015-.063L1.605 2.3c-.483.484-.661 1.169-.45 1.77a17.6 17.6 0 0 0 4.168 6.608 17.6 17.6 0 0 0 6.608 4.168c.601.211 1.286.033 1.77-.45l1.034-1.034a.678.678 0 0 0-.063-1.015l-2.307-1.794a.68.68 0 0 0-.58-.122l-2.19.547a1.75 1.75 0 0 1-1.657-.459L5.482 8.062a1.75 1.75 0 0 1-.46-1.657l.548-2.19a.68.68 0 0 0-.122-.58zM1.884.511a1.745 1.745 0 0 1 2.612.163L6.29 2.98c.329.423.445.974.315 1.494l-.547 2.19a.68.68 0 0 0 .178.643l2.457 2.457a.68.68 0 0 0 .644.178l2.189-.547a1.75 1.75 0 0 1 1.494.315l2.306 1.794c.829.645.905 1.87.163 2.611l-1.034 1.034c-.74.74-1.846 1.065-2.877.702a18.6 18.6 0 0 1-7.01-4.42 18.6 18.6 0 0 1-4.42-7.009c-.362-1.03-.037-2.137.703-2.877z"/>'
                                    +'</svg>'
                                +'</td>'
                                +'<td class="innerTableHeader center-svg col-commu-'+id+'" style="width: 2%;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-whatsapp" viewBox="0 0 16 16">'
                                        +'<path d="M13.601 2.326A7.85 7.85 0 0 0 7.994 0C3.627 0 .068 3.558.064 7.926c0 1.399.366 2.76 1.057 3.965L0 16l4.204-1.102a7.9 7.9 0 0 0 3.79.965h.004c4.368 0 7.926-3.558 7.93-7.93A7.9 7.9 0 0 0 13.6 2.326zM7.994 14.521a6.6 6.6 0 0 1-3.356-.92l-.24-.144-2.494.654.666-2.433-.156-.251a6.56 6.56 0 0 1-1.007-3.505c0-3.626 2.957-6.584 6.591-6.584a6.56 6.56 0 0 1 4.66 1.931 6.56 6.56 0 0 1 1.928 4.66c-.004 3.639-2.961 6.592-6.592 6.592m3.615-4.934c-.197-.099-1.17-.578-1.353-.646-.182-.065-.315-.099-.445.099-.133.197-.513.646-.627.775-.114.133-.232.148-.43.05-.197-.1-.836-.308-1.592-.985-.59-.525-.985-1.175-1.103-1.372-.114-.198-.011-.304.088-.403.087-.088.197-.232.296-.346.1-.114.133-.198.198-.33.065-.134.034-.248-.015-.347-.05-.099-.445-1.076-.612-1.47-.16-.389-.323-.335-.445-.34-.114-.007-.247-.007-.38-.007a.73.73 0 0 0-.529.247c-.182.198-.691.677-.691 1.654s.71 1.916.81 2.049c.098.133 1.394 2.132 3.383 2.992.47.205.84.326 1.129.418.475.152.904.129 1.246.08.38-.058 1.171-.48 1.338-.943.164-.464.164-.86.114-.943-.049-.084-.182-.133-.38-.232"/>'
                                    +'</svg>'
                                +'</td>'
                                +'<td class="innerTableHeader center-svg col-commu-'+id+'" style="width: 2%;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-telegram" viewBox="0 0 16 16">'
                                        +'<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0M8.287 5.906q-1.168.486-4.666 2.01-.567.225-.595.442c-.03.243.275.339.69.47l.175.055c.408.133.958.288 1.243.294q.39.01.868-.32 3.269-2.206 3.374-2.23c.05-.012.12-.026.166.016s.042.12.037.141c-.03.129-1.227 1.241-1.846 1.817-.193.18-.33.307-.358.336a8 8 0 0 1-.188.186c-.38.366-.664.64.015 1.088.327.216.589.393.85.571.284.194.568.387.936.629q.14.092.27.187c.331.236.63.448.997.414.214-.02.435-.22.547-.82.265-1.417.786-4.486.906-5.751a1.4 1.4 0 0 0-.013-.315.34.34 0 0 0-.114-.217.53.53 0 0 0-.31-.093c-.3.005-.763.166-2.984 1.09"/>'
                                    +'</svg>'
                                +'</td>'
                                +'<td class="innerTableHeader center-svg col-commu-'+id+'" style="width: 2%;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-envelope" viewBox="0 0 16 16">'
                                        +'<path d="M0 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v.217l7 4.2 7-4.2V4a1 1 0 0 0-1-1zm13 2.383-4.708 2.825L15 11.105zm-.034 6.876-5.64-3.471L8 9.583l-1.326-.795-5.64 3.47A1 1 0 0 0 2 13h12a1 1 0 0 0 .966-.741M1 11.105l4.708-2.897L1 5.383z"/>'
                                    +'</svg>'
                                +'</td>'
                                +'<td class="innerTableHeader center-svg col-commu-'+id+'" style="width: 2%;">'
                                    +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-envelope-check" viewBox="0 0 16 16">'
                                        +'<path d="M2 2a2 2 0 0 0-2 2v8.01A2 2 0 0 0 2 14h5.5a.5.5 0 0 0 0-1H2a1 1 0 0 1-.966-.741l5.64-3.471L8 9.583l7-4.2V8.5a.5.5 0 0 0 1 0V4a2 2 0 0 0-2-2zm3.708 6.208L1 11.105V5.383zM1 4.217V4a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v.217l-7 4.2z"/>'
                                        +'<path d="M16 12.5a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0m-1.993-1.679a.5.5 0 0 0-.686.172l-1.17 1.95-.547-.547a.5.5 0 0 0-.708.708l.774.773a.75.75 0 0 0 1.174-.144l1.335-2.226a.5.5 0 0 0-.172-.686"/>'
                                    +'</svg>'
                                +'</td>'
                                +'<td class="innerTableHeader center-svg col-gift-'+id+'" style="width: 3%; display: none;">Mcake</td>'
                                +'<td class="innerTableHeader center-svg col-gift-'+id+'" style="width: 3%; display: none;">Xmas</td>'
                                +'<td class="innerTableHeader center-svg col-gift-'+id+'" style="width: 3%; display: none;">CNY</td>'
                                +'<td class="innerTableHeader" style="width: 3%;">'
                                    +'<input type="hidden" id="giftTabStyle'+id+'" value="none">'
                                    +'<label style="float: left;" onclick="hideCommunTab(\''+id+'\')" id="lblCommunTab-'+id+'">'
                                        +'C<i style="padding-left:3px;" id="iconCommunTab-'+id+'" class="fa fa-chevron-right"></i>'
                                    +'</label>'
                                    +'<label style="float: left; font-weight: bold !important;" onclick="showGiftTab(\''+id+'\')" id="lblGiftTab-'+id+'">'
                                        +'<i style="padding-right:3px;" id="iconGiftTab-'+id+'" class="fa fa-chevron-left"></i>G'
                                    +'</label>'
                                +'</td>'
                            +'</tr>'
                        +'</thead>'
                        +'<tbody id="suspectInnerTable'+id+'">';
    html += detail_html;
    html +=             '</tbody>'
                        +'<tfoot>'
                        +'<tr>'
                            +'<td colspan="14" style="border:0px;" id="tdColspan-'+id+'"></td>'
                            +'<td colspan="2" style="padding: 5px 0px 0px 5px !important; border:0px;">'
                                +'<button class="col-sm-12 btn btn-secondary" style="background-color:grey;color:white;margin-right: 10px;" type="button" data-toggle="modal" id="btnSaveSuspect'+id+'" onclick="updateSuspectContact(\''+id+'\')"><i class="fa fa-save"></i> Save</button>'
                            +'</td>'
                        +'</tr>'
                    +'</tfoot>'
                +'</table>'
            +'</td>'
        +'</tr>'
    return html;
}

function htmlSuspectContactDetail(id, row = "New", company_detail=""){
    person_id       = "-1";
    contact_id      = "-1";
    sequence        = "";
    designation     = "";
    full_name       = "";
    prefer_name     = "";
    telephone       = "";
    email           = "";
    report_to       = "";
    next_action     = "";
    action_date     = "";
    email_promo     = "";
    prefer_phone    = "";
    prefer_whatsapp = "";
    prefer_telegram = "";
    prefer_email    = "";
    mooncake        = "";
    xmas_card       = "";
    cny             = "";
    assign_to       = "";
    best_time       = "";
    lunch_time      = "";
    if(company_detail != ""){
        contact_id      = company_detail.id;
        person_id       = company_detail.person_id;
        sequence        = company_detail.sequence;
        designation     = company_detail.designation;
        full_name       = company_detail.full_name;
        prefer_name     = company_detail.prefer_name;
        telephone       = company_detail.telephone;
        email           = company_detail.email;
        report_to       = company_detail.report_to;
        next_action     = company_detail.next_action;
        action_date     = company_detail.action_date;
        email_promo     = company_detail.email_promo;
        prefer_phone    = company_detail.prefer_phone;
        prefer_whatsapp = company_detail.prefer_whatsapp;
        prefer_telegram = company_detail.prefer_telegram;
        prefer_email    = company_detail.prefer_email;
        mooncake        = company_detail.mooncake;
        xmas_card       = company_detail.xmas_card;
        cny             = company_detail.cny;
        assign_to       = company_detail.assign_to;
        best_time       = company_detail.best_time;
        lunch_time      = company_detail.lunch_time;
    }

    var commun_style    = $('#communTabStyle'+id).val();
    var gift_style      = $('#giftTabStyle'+id).val();

    if(commun_style == undefined){
        commun_style = "";
    }
    
    if(gift_style == undefined){
        gift_style = "none";
    }

    html = '<tr id="suspectContactDetail'+id+'_'+row+'">'
                    +'<td class="innerTableContent">'
                        +'<input type="hidden" class="form-control innerTdInput" placeholder="Seq" id="txtSuspectContactID'+id+'_'+row+'" value="'+contact_id+'">'
                        +'<input type="text" class="form-control innerTdInput" placeholder="Seq" id="txtSuspectContactSeq'+id+'_'+row+'" value="'+sequence+'">'
                    +'</td>'
                    +'<td class="innerTableContent">'
                        +'<input type="text" class="form-control innerTdInput" placeholder="Designation" id="txtSuspectContactDesignation'+id+'_'+row+'" value="'+designation+'">'
                        +'<input type="hidden" id="txtSuspectContactPersonID'+id+'_'+row+'" onchange="getPersonContactDetail(\''+id+'\',\''+row+'\')" value="'+person_id+'">'
                        +'<input type="text" class="form-control innerTdInput inputSuspectFullName" onkeyup="filterOptions(\''+id+'\',\''+row+'\')" onclick="showOptions(\''+id+'\',\''+row+'\')" placeholder="Full Name" id="txtSuspectContactFullName'+id+'_'+row+'" value="'+full_name+'">'
                        +'<div id="personContactDropdown'+id+'_'+row+'" class="dropdown-content">'
                            +'<div style="position: absolute; background-color: white; width:100%">'
                                +htmlPersonContactOption(id,row)
                            +'</div>'
                        +'</div>'
                    +'</td>'
                    +'<td class="innerTableContent">'
                        +'<input type="text" class="form-control innerTdInput" placeholder="Preferred Name" id="txtSuspectContactPreferName'+id+'_'+row+'" onchange="updateReportToOption(\''+id+'\')" value="'+prefer_name+'">'
                        +'<select class="form-control innerTdInput" id="cobSuspectContactReportTo'+id+'_'+row+'">'
                            +'<option>None</option>'
                        +'</select>'
                        +'<input type="hidden" id="txtSuspectContactReportTo'+id+'_'+row+'" value="'+report_to+'">'
                    +'</td>'
                    +'<td class="innerTableContent">'
                        +'<div class="input-with-button">'
                            +'<input type="text" class="form-control innerTdInput" placeholder="Phone" id="txtSuspectContactPhone'+id+'_'+row+'" value="'+telephone+'">'
                            +'<button onclick="copyTelephone(\''+id+'\',\''+row+'\')">'
                                +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-copy" viewBox="0 0 16 16">'
                                    +'<path fill-rule="evenodd" d="M4 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1zM2 5a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-1h1v1a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h1v1z"/>'
                                +'</svg>'
                            +'</button>'
                        +'</div>'
                        +'<input type="text" class="form-control innerTdInput" placeholder="Email" id="txtSuspectContactEmail'+id+'_'+row+'" value="'+email+'">'
                    +'</td>'
                    +'<td class="innerTableContent">'
                        +'<div class="textarea-container">'
                            // +'<textarea id="myTextarea" rows="4" cols="50"></textarea>'
                            +'<textarea class="form-control innerTdInput myTextarea" rows="3" placeholder="Conversation" id="txtSuspectContactConversation'+id+'_'+row+'"></textarea>'
                            +'<button class="icon-button" onclick="showConversationHistory(\''+id+'\',\''+contact_id+'\',\''+row+'\')">'
                                +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clock-history" viewBox="0 0 16 16">'
                                    +'<path d="M8.515 1.019A7 7 0 0 0 8 1V0a8 8 0 0 1 .589.022zm2.004.45a7 7 0 0 0-.985-.299l.219-.976q.576.129 1.126.342zm1.37.71a7 7 0 0 0-.439-.27l.493-.87a8 8 0 0 1 .979.654l-.615.789a7 7 0 0 0-.418-.302zm1.834 1.79a7 7 0 0 0-.653-.796l.724-.69q.406.429.747.91zm.744 1.352a7 7 0 0 0-.214-.468l.893-.45a8 8 0 0 1 .45 1.088l-.95.313a7 7 0 0 0-.179-.483m.53 2.507a7 7 0 0 0-.1-1.025l.985-.17q.1.58.116 1.17zm-.131 1.538q.05-.254.081-.51l.993.123a8 8 0 0 1-.23 1.155l-.964-.267q.069-.247.12-.501m-.952 2.379q.276-.436.486-.908l.914.405q-.24.54-.555 1.038zm-.964 1.205q.183-.183.35-.378l.758.653a8 8 0 0 1-.401.432z"/>'
                                    +'<path d="M8 1a7 7 0 1 0 4.95 11.95l.707.707A8.001 8.001 0 1 1 8 0z"/>'
                                    +'<path d="M7.5 3a.5.5 0 0 1 .5.5v5.21l3.248 1.856a.5.5 0 0 1-.496.868l-3.5-2A.5.5 0 0 1 7 9V3.5a.5.5 0 0 1 .5-.5"/>'
                                +'</svg>'
                            +'</button>'
                        +'</div>'
                    +'</td>'
                    +'<td class="innerTableContent">'
                        +'<textarea class="form-control innerTdInput" rows="3" placeholder="Next Action" id="txtSuspectContactNextAction'+id+'_'+row+'">'+next_action+'</textarea>'
                    +'</td>'
                    +'<td class="innerTableContent">'
                        +'<input type="date" class="form-control innerTdInput" id="txtSuspectContactDate'+id+'_'+row+'" value="'+action_date+'">'
                    +'</td>';
    //existing rows carry just the selected option and are filled in on expand; a brand new
    //row is cheap and immediately editable, so it gets the full list straight away.
    //strict compare: assign_to is a number and 0 == "" is true in js, which would send
    //every unassigned contact down the full-template path
    if(best_time !== ""){
        html +=     '<td class="innerTableContent">'
                        +'<select class="form-control innerTdInput" data-lazy-tpl="cobTimeOption" data-lazy-co="'+id+'" id="cobSuspectContactTime'+id+'_'+row+'">'
                            +suspectOneOptionFromMap(best_time, suspectTimeLabel())
                        +'</select>'
                    +'</td>';
    }else{
        html +=     '<td class="innerTableContent">'
                        +'<select class="form-control innerTdInput" id="cobSuspectContactTime'+id+'_'+row+'">'
                            +suspectTplHtml('cobTimeOption')
                        +'</select>'
                    +'</td>';
    }
    if(lunch_time !== ""){
        html +=     '<td class="innerTableContent">'
                        +'<select class="form-control innerTdInput" data-lazy-tpl="cobLunchTimeOption" data-lazy-co="'+id+'" id="cobSuspectContactLunchTime'+id+'_'+row+'">'
                            +suspectOneOptionFromMap(lunch_time, suspectTimeLabel())
                        +'</select>'
                    +'</td>';
    }else{
        html +=     '<td class="innerTableContent">'
                        +'<select class="form-control innerTdInput" id="cobSuspectContactLunchTime'+id+'_'+row+'">'
                            +suspectTplHtml('cobLunchTimeOption')
                        +'</select>'
                    +'</td>';
    }
    if(assign_to !== ""){
        html +=     '<td class="innerTableContent">'
                        +'<select class="form-control innerTdInput" data-lazy-tpl="cobUserList" data-lazy-co="'+id+'" id="cobSuspectContactAssignTo'+id+'_'+row+'">'
                            +suspectOneOptionFromMap(assign_to, suspectUserLabel())
                        +'</select>'
                    +'</td>'
    }else{
        html +=     '<td class="innerTableContent">'
                        +'<select class="form-control innerTdInput" id="cobSuspectContactAssignTo'+id+'_'+row+'">'
                            +suspectTplHtml('cobUserList')
                        +'</select>'
                    +'</td>';
    }
        html +=     '<td class="innerTableContent col-commu-'+id+'" style="display: '+commun_style+'; text-align: center;">'
                        +'<input type="checkbox" class="form-control innerTdInput" style="width: 28px; display:inline-block;" id="chkSuspectContactPhone'+id+'_'+row+'" '+prefer_phone+' >'
                        +'<br/>'
                        +'<a href="#" id="btnCallSuspect'+id+'_'+row+'" class="btn btn-sm btn-primary" style="display:none; margin-top:6px;"><i class="fa fa-phone"></i></a>'
                    +'</td>'
                    +'<td class="innerTableContent col-commu-'+id+'" style="display: '+commun_style+'">'
                        +'<input type="checkbox" class="form-control innerTdInput" style="width: 28px;" id="chkSuspectContactWhatsapp'+id+'_'+row+'" '+prefer_whatsapp+'>'
                    +'</td>'
                    +'<td class="innerTableContent col-commu-'+id+'" style="display: '+commun_style+'">'
                        +'<input type="checkbox" class="form-control innerTdInput" style="width: 28px;" id="chkSuspectContactTelegram'+id+'_'+row+'" '+prefer_telegram+'>'
                    +'</td>'
                    +'<td class="innerTableContent col-commu-'+id+'" style="display: '+commun_style+'">'
                        +'<input type="checkbox" class="form-control innerTdInput" style="width: 28px;" id="chkSuspectContactEmail'+id+'_'+row+'" '+prefer_email+'>'
                    +'</td>'
                    +'<td class="innerTableContent col-commu-'+id+'" style="display: '+commun_style+'">'
                        +'<input type="checkbox" class="form-control innerTdInput" style="width: 28px;" id="chkSuspectContactEmailPromo'+id+'_'+row+'" '+email_promo+'>'
                    +'</td>'
                    +'<td class="innerTableContent col-gift-'+id+'" style="display: '+gift_style+';">'
                        +'<input type="text" class="form-control innerTdInput" id="txtSuspectContactMooncake'+id+'_'+row+'" value="'+mooncake+'">'
                    +'</td>'
                    +'<td class="innerTableContent col-gift-'+id+'" style="display: '+gift_style+';">'
                        +'<input type="text" class="form-control innerTdInput" id="txtSuspectContactXmasCard'+id+'_'+row+'" value="'+xmas_card+'">'
                    +'</td>'
                    +'<td class="innerTableContent col-gift-'+id+'" style="display: '+gift_style+';">'
                        +'<input type="text" class="form-control innerTdInput" id="txtSuspectContactCNY'+id+'_'+row+'" value="'+cny+'">'
                    +'</td>'
                    +'<td class="innerTableContent center-svg" style="color:red; padding:4px !important; text-align: center;">'
                        +'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16" onclick="deleteContactDetailRow(\''+id+'\', '+row+')">'
                            +'<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0z"/>'
                            +'<path d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4zM2.5 3h11V2h-11z"/>'
                        +'</svg>'
                    +'</td>'                    
                    
                +'</tr>';
    return html;
}

function htmlPersonContactOption(id, row){
    var html = '';
    if(person_datas.length > 0){
        for(x=0; x < person_datas.length; x++){
            person_data = person_datas[x];
            html += '<a onclick="selectOption(\''+person_data.person_id+'\', \''+person_data.person_name+'\', \''+id+'\', \''+row+'\')">'+person_data.person_name+'</a>';
        }
    }
    return html;
}

function onchangeStatusColor(id){
    var status = $('#txtSuspectHeaderStatus2'+id).val();

    if(status == 0){
        $('#txtSuspectHeaderStatus2'+id).css('color', 'red');
    }else if(status == 1){
        $('#txtSuspectHeaderStatus2'+id).css('color', 'brown');
    }else if(status == 2){
        $('#txtSuspectHeaderStatus2'+id).css('color', 'orange');
    }else{
        $('#txtSuspectHeaderStatus2'+id).css('color', 'green');
    }
}

function changeStatus2(id){
    var status = $('#txtSuspectHeaderStatus'+id).val();
    if(status == 0){
        $('#txtSuspectHeaderStatus2'+id).css('color', 'red');
        $('#txtSuspectHeaderStatus2'+id).val(0);
        $('#txtSuspectHeaderStatus2'+id).prop('disabled', 'disabled');
    }else{
        $('#txtSuspectHeaderStatus2'+id).prop('disabled', '');
    }
}

function showSuspectList(myObj, assign_to = "", best_time = "", list_options = "") {
    resetSuspectTemplates();   //re-read the hidden templates once per render, not once per row
    $('#suspect-table-body').html('');

    //build every row first, then write the table once: appending per company made the
    //browser re-parse and re-lay out the growing table on each pass
    var all_html = "";
    var rendered = [];
    for (i in myObj) {
        id        = myObj[i].id;

        var html                = htmlSuspectHeader(id, myObj[i]);   //also sets company_detail
        var htmlContactDetail   = "";
        var x                   = 0;

        if(company_detail.length > 0){
            for(x; x < company_detail.length; x++){
                htmlContactDetail += htmlSuspectContactDetail(id, x, company_detail[x]);
            }
        }
        html += htmlSuspectContactHeader(id, htmlContactDetail);

        all_html += html;
        rendered.push({ id : id, count : x+1, row : myObj[i] });
    }

    $('#suspect-table-body').append(all_html);

    for (var k = 0; k < rendered.length; k++) {
        var co  = rendered[k].id;
        var row = rendered[k].row;

        $('#current_count'+co).val(rendered[k].count);

        $('#cboSuspectHeaderAccountFlag'+co).val(row.account_flag);
        $('#txtSuspectHeaderIndustry'+co).val(row.industry_id);
        $('#txtSuspectHeaderBusinessSector'+co).val(row.business_sector_id);
        $('#txtSuspectHeaderBusinessNature'+co).val(row.business_nature_id);
        $('#txtSuspectHeaderAccSoft'+co).val(row.acc_software_id);
        $('#txtSuspectHeaderSalesSoft'+co).val(row.sales_software_id);
        $('#txtSuspectHeaderOtherSoft'+co).val(row.other_software_id);
        $('#txtSuspectHeaderActiveStatus'+co).val(row.company_status_id);
        $('#txtSuspectHeaderStatus'+co).val(row.sales_status_id);
        $('#txtSuspectHeaderStatus2'+co).val(row.sales_status2_id);
    }
}

function updateReportToOption(id, first = false) {
    var html_option = "<option value='None'>None</option>";
    //get all prefer name option
    $('#suspectInnerTable'+id+' tr').each(function () {
        var idx = $(this).attr('id');
        idx = idx.substring(idx.lastIndexOf('_') + 1);

        var prefer_name = $('#txtSuspectContactPreferName'+id+'_'+idx).val();
        if(prefer_name != ""){
            html_option += "<option value='"+prefer_name+"'>"+prefer_name+"</option>";
        }
    });

    //update option in report
    $('#suspectInnerTable'+id+' tr').each(function () {
        var idx = $(this).attr('id');
        idx = idx.substring(idx.lastIndexOf('_') + 1);

        if(first){
            var selected = $('#txtSuspectContactReportTo'+id+'_'+idx).val();
        }else{
            var selected = $('#cobSuspectContactReportTo'+id+'_'+idx).val();
        }
        $('#cobSuspectContactReportTo'+id+'_'+idx).html('');
        $('#cobSuspectContactReportTo'+id+'_'+idx).html(html_option);
        $('#cobSuspectContactReportTo'+id+'_'+idx).val(selected);
        
        if($('#cobSuspectContactReportTo'+id+'_'+idx).blank()){
            $('#cobSuspectContactReportTo'+id+'_'+idx).val('');
        };

    });
}

function copyTelephone(id,row) {
    var comp_tel = $('#txtSuspectHeaderTelephone'+id).val();
    $('#txtSuspectContactPhone'+id+'_'+row).val(comp_tel);
}

function deleteNewSuspect(){
    $('#tr_suspect_new').remove();
    $('#tr_suspect_childnew').remove();
}

function deleteContactDetailRow(id, row){
    var contact_id = $('#txtSuspectContactID'+id+'_'+row).val();
    var current = $('#current_delete'+id).val();
    current += ","+contact_id;
    
    $('#current_delete'+id).val(current);
    $('#suspectContactDetail'+id+'_'+row).remove();
}

function showSuspectDetail(id){
    fillSuspectOptions(id);   //give this company's dropdowns their full option lists
    changeStatus2(id);
    updateReportToOption(id, true);
    updateCallButtonState(id);
    $('#tr_suspect_child'+id).css("display", "");
    $('.showLabel'+id).css("display", "none");
    $('.showInput'+id).css("display", "");
    $('.txtSoftware'+id).prop("disabled", false);
    $('#change-icon'+id).attr('onclick', 'hideSuspectDetail('+id+')');
    $('#change-icon'+id).html('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-down-fill" viewBox="0 0 16 16">'
                                +'<path d="M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z"/>'
                            +'</svg>');
}

function hideSuspectDetail(id){
    $('#tr_suspect_child'+id).css("display", "none");
    $('.showLabel'+id).css("display", "");
    $('.showInput'+id).css("display", "none");
    $('.txtSoftware'+id).prop("disabled", true);
    $('#change-icon'+id).attr('onclick', 'showSuspectDetail('+id+')');
    $('#change-icon'+id).html('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-right-fill" viewBox="0 0 16 16">'
                                +'<path d="m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z"/>'
                            +'</svg>');
}

function saveCurrentConversation(id,row){
    var current_conv = $('#txtCurrentConversation').val();

    $('#txtSuspectContactConversation'+id+'_'+row).val(current_conv);
}

function showConversationHistory(id, contact_id, row) {
    $('#btnSaveConversation').attr('onclick', 'saveCurrentConversation(\''+id+'\',\''+row+'\')');
    $('#conversationHistory').modal('show');
    
    if(id == "" || id == 0){
        swal.fire("Warning", "ID cannot be blank", "warning");
        return
    }

    var datas = {
        "type"       : C_SUSPECT_CONVERSATION,
        "id"         : id,
        "contact_id" : contact_id
    }
    
    var url  = "index.pzx?c=" + telemarketing_url +"&d=" +new Date().getTime();
    callServer(url,"json",datas,onResponseSuspectEntry,null);
}

function addSuspectHeader(){
    if ($('#tr_suspect_new').length){
        swal.fire("Warning", "You can only add 1 suspect at a time", "warning");
        return;
    }else{
        var html        = htmlSuspectHeader("new");
        var htmldetail  = htmlSuspectContactDetail("new", 1);

        html           += htmlSuspectContactHeader("new", htmldetail);
        $('#suspect-table-body').prepend(html);
        showSuspectDetail("new");
        $('#change-iconnew').html('');
        $('#change-iconnew').html(
            '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">'
                +'<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0z"/>'
                +'<path d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4zM2.5 3h11V2h-11z"/>'
            +'</svg>');
        $('#change-iconnew').css('color', 'red');
        $('#change-iconnew').attr('onclick', 'deleteNewSuspect()');

        $('#btnSaveSuspectnew').attr('onclick', 'addSuspectContact(\'new\')');
    }
}
function addSuspectDetail(id){
    var current_count = $('#current_count'+id).val();
    current_count++;
    $('#current_count'+id).val(current_count);

    var html = htmlSuspectContactDetail(id,current_count);

    $('#suspectInnerTable'+id).append(html);
}

function addSuspectContact(id){
    saveSuspectContact(id, C_ADD);
}

function updateSuspectContact(id){
    saveSuspectContact(id, C_UPDATE);
}

function saveSuspectContact(id, type){
    LoadingScreen("show");
    var contact_array   = [];
    var error           = false;

    if($('#txtSuspectHeaderCompanyName'+id).blank()){
        LoadingScreen("hide");
        error = true;
        swal.fire("Warning", "Suspect Company Name cannot be blank", "warning");
        return;
    }

    var data_header = {
        "account_flag"          : $('#cboSuspectHeaderAccountFlag'+id).val(),
        "company_name"          : $('#txtSuspectHeaderCompanyName'+id).val(),
        "telephone"             : $('#txtSuspectHeaderTelephone'+id).val(),
        "telephone2"            : $('#txtSuspectHeaderTelephone2'+id).val(),
        "website"               : $('#txtSuspectHeaderWebsite'+id).val(),
        "industry"              : $('#txtSuspectHeaderIndustry'+id).val(),
        "business_sector"       : $('#txtSuspectHeaderBusinessSector'+id).val(),
        "business_nature"       : $('#txtSuspectHeaderBusinessNature'+id).val(),
        "total_empolyee"        : $('#txtSuspectHeaderTotalEmployee'+id).val(),
        "business_desc"         : $('#txtSuspectHeaderBusinessDesc'+id).val(),
        "acc_software"          : $('#txtSuspectHeaderAccSoft'+id).val(),
        "acc_software_c"        : $('#txtSuspectHeaderAccSoftC'+id).val(),
        "acc_software_n"        : $('#txtSuspectHeaderAccSoftN'+id).val(),
        "acc_software_user"     : $('#txtSuspectHeaderAccSoftUser'+id).val(),
        "sales_software"        : $('#txtSuspectHeaderSalesSoft'+id).val(),
        "sales_software_c"      : $('#txtSuspectHeaderSalesSoftC'+id).val(),
        "sales_software_n"      : $('#txtSuspectHeaderSalesSoftN'+id).val(),
        "sales_software_user"   : $('#txtSuspectHeaderSalesSoftUser'+id).val(),  
        "other_software"        : $('#txtSuspectHeaderOtherSoft'+id).val(),
        "other_software_c"      : $('#txtSuspectHeaderOtherSoftC'+id).val(),
        "other_software_n"      : $('#txtSuspectHeaderOtherSoftN'+id).val(),
        "other_software_user"   : $('#txtSuspectHeaderOtherSoftUser'+id).val(),  
        "proposal_1"            : $('#txtSuspectHeaderProposal1'+id).val(),  
        "proposal_2"            : $('#txtSuspectHeaderProposal2'+id).val(),  
        "subsidiary_location"   : $('#txtSuspectHeaderSubsidiaryLocation'+id).val(),
        "subsidiary_entity"     : $('#txtSuspectHeaderSubsidiaryEntity'+id).val(),
        "company_status"        : $('#txtSuspectHeaderActiveStatus'+id).val(),  
        "deleted_contact"       : $('#current_delete'+id).val(),
        "sales_status"          : $('#txtSuspectHeaderStatus'+id).val(),
        "sales_status2"         : $('#txtSuspectHeaderStatus2'+id).val(),
        "company_email"         : $('#txtSuspectHeaderCompEmail'+id).val(),
        "company_linkedin"      : $('#txtSuspectHeaderLinkedIn'+id).val(),
        "company_source"        : $('#txtSuspectHeaderSource'+id).val(),
        "company_state"         : $('#txtSuspectHeaderState'+id).val(),
    }
    $('#suspectInnerTable'+id+' tr').each(function() {
        var idx = $(this).attr('id');
        idx = idx.substring(idx.lastIndexOf('_') + 1);

        if(id == "" || id == 0){
            LoadingScreen("hide");
            error = true;
            swal.fire("Warning", "Suspect ID cannot be blank", "warning");
            return;
        }
        if($('#txtSuspectContactFullName'+id+'_'+idx).blank()){
            LoadingScreen("hide");
            error = true;
            swal.fire("Warning", "Contact full name cannot be blank", "warning");
            return;
        }
        if($('#txtSuspectContactPreferName'+id+'_'+idx).blank()){
            LoadingScreen("hide");
            error = true;
            swal.fire("Warning", "Contact prefer name cannot be blank", "warning");
            return;
        }

        // if($('#txtSuspectContactPhone'+id+'_'+idx).blank()){
        //     LoadingScreen("hide");
        //     error = true;
        //     swal.fire("Warning", "Phone number cannot be blank", "warning");
        //     return;
        // }
        var data = {
            "contact_id"        : $('#txtSuspectContactID'+id+'_'+idx).val(),
            "person_id"         : $('#txtSuspectContactPersonID'+id+'_'+idx).val(),
            "sequence"          : $('#txtSuspectContactSeq'+id+'_'+idx).val(),
            "designation"       : $('#txtSuspectContactDesignation'+id+'_'+idx).val(),
            "full_name"         : $('#txtSuspectContactFullName'+id+'_'+idx).val(),
            "prefer_name"       : $('#txtSuspectContactPreferName'+id+'_'+idx).val(),
            "telephone"         : $('#txtSuspectContactPhone'+id+'_'+idx).val(),
            "email"             : $('#txtSuspectContactEmail'+id+'_'+idx).val(),
            "report_to"         : $('#cobSuspectContactReportTo'+id+'_'+idx).val(),
            "conversation"      : $('#txtSuspectContactConversation'+id+'_'+idx).val(),
            "next_action"       : $('#txtSuspectContactNextAction'+id+'_'+idx).val(),
            "action_date"       : $('#txtSuspectContactDate'+id+'_'+idx).val(),
            "best_time"         : $('#cobSuspectContactTime'+id+'_'+idx).val(),
            "lunch_time"        : $('#cobSuspectContactLunchTime'+id+'_'+idx).val(),
            "assign_to"         : $('#cobSuspectContactAssignTo'+id+'_'+idx).val(),
            "prefer_telephone"  : ($('#chkSuspectContactPhone'+id+'_'+idx).is(":checked") == false ? 0 : 1),
            "prefer_whatsapp"   : ($('#chkSuspectContactWhatsapp'+id+'_'+idx).is(":checked") == false ? 0 : 1),
            "prefer_telegram"   : ($('#chkSuspectContactTelegram'+id+'_'+idx).is(":checked") == false ? 0 : 1),
            "prefer_email"      : ($('#chkSuspectContactEmail'+id+'_'+idx).is(":checked") == false ? 0 : 1),
            "email_promo"       : ($('#chkSuspectContactEmailPromo'+id+'_'+idx).is(":checked") == false ? 0 : 1),
            "mooncake"          : $('#txtSuspectContactMooncake'+id+'_'+idx).val(),
            "xmas_card"         : $('#txtSuspectContactXmasCard'+id+'_'+idx).val(),
            "cny"               : $('#txtSuspectContactCNY'+id+'_'+idx).val(),
        }
        contact_array.push(data);
    });

    if(error != true){
        var datas = {
            "type"           : type,
            "id"             : id,
            "contact_detail" : contact_array,
            "suspect_header" : data_header,
        }
    
        var url = "index.pzx?c=" + telemarketing_url + "&d=" + new Date().getTime();
        callServer(url, "json", datas, onResponseSuspectEntry, null);
    }
}

function showOptions(id, row) {
    document.getElementById("personContactDropdown"+id+"_"+row).classList.toggle("show");
}

function selectOption(person_id, person_name, id, row) {
    document.getElementById("txtSuspectContactPersonID"+id+"_"+row).value = person_id;
    document.getElementById("txtSuspectContactFullName"+id+"_"+row).value = person_name;
    document.getElementById("personContactDropdown"+id+"_"+row).classList.remove("show");
    $("#txtSuspectContactPersonID"+id+"_"+row).trigger('change');
}

function filterOptions(id, row) {
    var input, filter, div, a, i;
    input   = document.getElementById("txtSuspectContactFullName"+id+"_"+row);
    filter  = input.value.toUpperCase();
    div     = document.getElementById("personContactDropdown"+id+"_"+row);
    a       = div.getElementsByTagName("a");
    for (i = 0; i < a.length; i++) {
        txtValue = a[i].textContent || a[i].innerText;
        if (txtValue.toUpperCase().indexOf(filter) > -1) {
            a[i].style.display = "";
        } else {
            a[i].style.display = "none";
        }
    }
}

function showGiftTab(id){
    gift_tab_style = "";
    hideCommunTab(id);
    $('#giftTabStyle'+id).val('');

    $('.col-gift-'+id).css('display', '');
    $('#iconGiftTab-'+id).attr('class', 'fa fa-chevron-right');
    $('#lblGiftTab-'+id).attr('onclick', 'hideGiftTab(\''+id+'\')');
    $('#tdColspan-'+id).attr('colspan', '12');
}
function hideGiftTab(id){
    gift_tab_style = "none";
    $('#giftTabStyle'+id).val('none');

    $('.col-gift-'+id).css('display', 'none');
    $('#iconGiftTab-'+id).attr('class', 'fa fa-chevron-left');
    $('#lblGiftTab-'+id).attr('onclick', 'showGiftTab(\''+id+'\')');
    $('#tdColspan-'+id).attr('colspan', '9');
}

function showCommunTab(id){
    commun_tab_style = "";
    hideGiftTab(id);
    $('#communTabStyle'+id).val('');

    $('.col-commu-'+id).css('display', '');
    $('#iconCommunTab-'+id).attr('class', 'fa fa-chevron-right');
    $('#lblCommunTab-'+id).attr('onclick', 'hideCommunTab(\''+id+'\')');
    $('#tdColspan-'+id).attr('colspan', '14');
}
function hideCommunTab(id){
    commun_tab_style = "none";
    $('#communTabStyle'+id).val('none');

    $('.col-commu-'+id).css('display', 'none');
    $('#iconCommunTab-'+id).attr('class', 'fa fa-chevron-left');
    $('#lblCommunTab-'+id).attr('onclick', 'showCommunTab(\''+id+'\')');
    $('#tdColspan-'+id).attr('colspan', '9');
}

function showMemo(){
    $('#divMemoField').css('display', '');
    $('#divMemoField').attr('class', 'col-lg-2');
    $('#divTelemarketingTable').attr('class', 'tableFixHead col-lg-10');
    $('#iconMemo').attr('class', 'fa fa-chevron-left');
    $('#lblShowMemo').attr('onclick', 'hideMemo()');
}
function hideMemo(){
    $('#divMemoField').css('display', 'none');
    $('#divTelemarketingTable').attr('class', 'tableFixHead col-lg-12');
    $('#iconMemo').attr('class', 'fa fa-chevron-right');
    $('#lblShowMemo').attr('onclick', 'showMemo()');
}

function showSubsidiary(){
    subsidiary_style = "";
    $('.colSubsidiary').css('display', '');
    $('#lblSubsidiary').attr('onclick', 'hideSubsidiary()');
    $('#iconSubsidiary').attr('class', 'fa fa-chevron-right');
}
function hideSubsidiary(){
    subsidiary_style = "none";
    $('.colSubsidiary').css('display', 'none');
    $('#lblSubsidiary').attr('onclick', 'showSubsidiary()');
    $('#iconSubsidiary').attr('class', 'fa fa-chevron-left');
}

function showSoftwareUsed(){
    software_used_style = "";
    $('.colSoftwareUsed').css('display', '');
    $('#lblSoftwareUsed').attr('onclick', 'hideSoftwareUsed()');
    $('#iconSoftwareUsed').attr('class', 'fa fa-chevron-right');
}
function hideSoftwareUsed(){
    software_used_style = "none";
    $('.colSoftwareUsed').css('display', 'none');
    $('#lblSoftwareUsed').attr('onclick', 'showSoftwareUsed()');
    $('#iconSoftwareUsed').attr('class', 'fa fa-chevron-left');
}

function saveMemo(){
    var data = {
        "type"             : C_UPDATE_CALL_SCRIPT,
        "memo"             : $('#txtMemo').val(),
    };

    var url = "request.pzx?c=" + telemarketing_url + "&d=" + new Date().getTime();
    callServer(url, "json", data, onResponseSuspectEntry, null);
}

function exportReport(){
    var url = "index.pzx?c=" + telemarketing_url + "&t=" + "C_DOWNLOAD_FOLLOW_UP" + "&r=1";
    showReport(url) ;
}

function getPersonContactDetail(id, row){
    var person_id = $('#txtSuspectContactPersonID'+id+'_'+row).val()
    var data = {
        "type"              : C_PERSON_CONTACT,
        "person_id"         : person_id,
        "id"                : id,
        "row"               : row,
    };

    var url = "request.pzx?c=" + telemarketing_url + "&d=" + new Date().getTime();
    callServer(url, "json", data, onResponseSuspectEntry, null);

}

//hide dropdown when click outside the box
window.onclick = function(event) {
    if (!event.target.matches('.inputSuspectFullName')) {
        var dropdowns = document.getElementsByClassName("dropdown-content");
        for (var i = 0; i < dropdowns.length; i++) {
            var openDropdown = dropdowns[i];
            if (openDropdown.classList.contains('show')) {
                openDropdown.classList.remove('show');
            }
        }
    }
}

//Show import modal
function showImportSuspect() {
    $('#importSuspectModal').modal('show');
}

//Show export modal
function showExportSuspect() {
    $('#exportSuspectModal').modal('show');
}
    
//Download Function
function downloadSuspectExcelTemplate() {
    var url = "index.pzx?c=" + telemarketing_url + "&t=" + "C_DOWNLOAD_SUSPECT_EXCEL_TEMPLATE" + "&r=1";
    showReport(url) ;
}

//Download Function
function exportNewContact() {
    var url = "index.pzx?c=" + telemarketing_url + "&t=" + "C_EXPORT_NEW_CONTACT" + "&r=1";
    showReport(url) ;
}

//Download Function
function exportAllContact() {
    var url = "index.pzx?c=" + telemarketing_url + "&t=" + "C_EXPORT_ALL_CONTACT" + "&r=1";
    showReport(url) ;
}

//IMPORT FUNCTION
//=============================================================
function triggerSuspectUploadExcel () {
    $("#uploadFileSuspect").trigger("click");
}

function processSuspectUploadExcel(obj) {
    upload_form_suspect = obj.form;
	uploadExcelSuspect(upload_form_suspect);
}

function uploadExcelSuspect(form){
    var url  = "index.pzx?c=" + telemarketing_url + "&t=" + "C_SUSPECT_UPLOAD_EXCEL"  + "&d=" + new Date().getTime();
    $('#importSuspectModal').modal('hide');
    LoadingScreen("show");
    ajaxUpload(form,url,suspectUploadEnd);
}

function suspectUploadEnd(resp) {
    LoadingScreen("hide");
    var msgArr      = resp.split("*");
    var status      = msgArr[0];

    if (status == C_OK){
        LoadingScreen("show");
        readSuspectExcel(msgArr[1]);
    } else {
        LoadingScreen("hide");
        swal.fire('Warning',msgArr[1] + msgArr[2],'warning');
        $("#uploadFileSuspect").val('');
        return false;
    }
}

function readSuspectExcel(new_name) {
    var data = { "type"     : "C_SUSPECT_READ_EXCEL",
                 "new_name" : new_name
                };
    var url  = "index.pzx?c=" + telemarketing_url +"&d=" +new Date().getTime();
    callServer(url,"json",data,onResponseSuspectEntry,null);
}

function onResponseSuspectEntry(obj,resp) {
    LoadingScreen("hide");
    if(resp.status!=C_OK){
		swal.fire('Warning',resp.mesg,'warning');
        if (resp.type == "C_SUSPECT_READ_EXCEL"){
            $("#uploadFileSuspect").val('');
        }
		return;
	}
    if(resp.type == C_ADD){
        swal.fire('Success',resp.mesg,'success');
        filterSuspectList();
    } else if(resp.type == C_UPDATE){
        swal.fire('Success',resp.mesg,'success');
        filterSuspectList();
    } else if (resp.type == "C_SUSPECT_READ_EXCEL"){
        swal.fire('Success',resp.mesg,'success');
        $("#uploadFileSuspect").val('');
        filterSuspectList();
	} else if(resp.type == C_SUSPECT_CONVERSATION){
        $('#conversationHistoryContent').html(resp.data);
    } else if (resp.type == C_LIST_SUSPECT) {
        commun_tab_style    = "";
        gift_tab_style      = "none";
        suspect_code_list   = [];
        var myObj           = JSON.parse(resp.data.details);
        person_datas        = resp.data.person_con
        prospect_id         = resp.data.prospect_id

        showSuspectList(myObj, resp.data.assign_to, resp.data.best_time, resp.data.list_options);
        if(resp.data.prospect_id != 0){
            showSuspectDetail(resp.data.prospect_id);
        }
    } else if(resp.type == C_PERSON_CONTACT){
        $('#txtSuspectContactFullName'+resp.data.id+'_'+resp.data.row).val(resp.data.full_name);
        $('#txtSuspectContactPreferName'+resp.data.id+'_'+resp.data.row).val(resp.data.prefer_name);
        $('#txtSuspectContactPhone'+resp.data.id+'_'+resp.data.row).val(resp.data.telephone);
        $('#txtSuspectContactEmail'+resp.data.id+'_'+resp.data.row).val(resp.data.email);
    } else if (resp.type == C_LIST_FOLLOWUP) {
        var myObj = JSON.parse(resp.data.details);

        showFollowUpList(myObj);
    } else if (resp.type == C_UPDATE_CALL_SCRIPT){
        swal.fire('Success',resp.mesg,'success');
        $('#txtMemo').val(resp.data);
    } else if (resp.type == "C_END_OF_ACTION"){
        swal.fire('Success',resp.mesg,'success');
        filterFollowUpTable();
        filterSuspectList();
    }
}
//=============================================================
// ---------------- Call button helpers ----------------
function updateCallButtonState(suspectId){
    var $table = $('#suspectInnerTable'+suspectId);
    if($table.length == 0) return;

    // hide all per-row call buttons first
    $table.find('a[id^="btnCallSuspect'+suspectId+'_"]').hide().attr('href','#');

    // iterate every phone checkbox and show the row button if checked and phone available
    var prefix = 'chkSuspectContactPhone' + suspectId + '_';
    $table.find('input[id^="' + prefix + '"]').each(function(){
        var chkId = $(this).attr('id');
        var row = chkId.substring(prefix.length);
        var $rowBtn = $('#btnCallSuspect' + suspectId + '_' + row);
        if(!$(this).is(':checked')){
            if($rowBtn.length) $rowBtn.hide().attr('href','#');
            return; // continue
        }

        var phone = $('#txtSuspectContactPhone' + suspectId + '_' + row).val();
        // fallback to header telephone(s) if row phone empty (useful for new rows)
        if(!(phone && phone.trim() != '')){
            var h1 = $('#txtSuspectHeaderTelephone'+suspectId).val();
            var h2 = $('#txtSuspectHeaderTelephone2'+suspectId).val();
            if(h1 && h1.trim() != '') phone = h1;
            else if(h2 && h2.trim() != '') phone = h2;
        }

        if(phone && phone.trim() != ''){
            var normalized = phone.trim().replace(/\s+/g,'');
            if(normalized.indexOf('tel:') !== 0) normalized = 'tel:' + normalized;
            if($rowBtn.length) $rowBtn.attr('href', normalized).show();
        } else {
            if($rowBtn.length) $rowBtn.hide().attr('href','#');
        }
    });
}

// delegated handler: when any phone-preference checkbox changes
$(document).on('change', 'input[id^="chkSuspectContactPhone"]', function(){
    var id = $(this).attr('id');
    var m = id.match(/^chkSuspectContactPhone(\d+)_(.+)$/);
    if(m){
        updateCallButtonState(m[1]);
    }
});

// update call button when phone input value changes (only if its checkbox is checked)
$(document).on('input', 'input[id^="txtSuspectContactPhone"]', function(){
    var id = $(this).attr('id');
    var m = id.match(/^txtSuspectContactPhone(\d+)_(.+)$/);
    if(m){
        var chk = $('#chkSuspectContactPhone'+m[1]+'_'+m[2]);
        if(chk.is(':checked')) updateCallButtonState(m[1]);
    }
});

// prevent action when disabled
$(document).on('click', 'a[id^="btnCallSuspect"]', function(e){
    if($(this).hasClass('disabled') || $(this).attr('href') == '#'){
        e.preventDefault();
        return false;
    }
});

// initialize existing tables on DOM ready
$(document).ready(function(){
    $('tbody[id^="suspectInnerTable"]').each(function(){
        var id = $(this).attr('id').replace('suspectInnerTable','');
        updateCallButtonState(id);
    });
});