function replaceAll(str, find, replace) {
    return str.replace(new RegExp(find, 'g'), replace);
}

function getTextValueFromTdByColumn(tds, col) {
    var text = $.trim(tds.eq(col)
            .clone()    //clone the element
            .children() //select all the children
            .remove()   //remove all the children
            .end()  //again go back to selected element
            .text());
    text = text.replace(/\r?\n|\r/g, '');
    if (text) {
        return text;
    } else {
        return null;
    }
}

function getSmartCreditAddressPhoneByBankName(bank_name) {
    var obj = "";
    var creditorInfo = creditorContactsSmartCredit();
    for (var i in creditorInfo) {
        if (creditorInfo[i].bank_name == bank_name) {
            obj = creditorInfo[i];
            break;
        }
    }

    return obj;
}

function creditorContactsSmartCredit() {
    var contactInfo = [];
    var creditor_tbl = $("td").filter(function () {
        var current_text = $(this).text().replace(/<(?:.|\n)*?>/gm, '');
        current_text = current_text.replace(/\r?\n|\r/g, '');
        current_text = $.trim(current_text);
        return current_text == "Creditor Contacts" && $(this).attr('style');
    }).parents('table[border = 1]').first().next('table').next('table');

    creditor_tbl.find('tr').each(function (i, el) {
        var key_tds = $(this).find('td').children('table').each(function () {
            var tds = $(this).find('tr td');
            var obj = {};
            var bank_name = getTextValueFromTdByColumn(tds, 1);
            var address = "";
            var phone = "";
            if (getTextValueFromTdByColumn(tds, 2)) {
                address = getTextValueFromTdByColumn(tds, 2);
            }

            if (getTextValueFromTdByColumn(tds, 3)) {
                phone = getTextValueFromTdByColumn(tds, 3);
            }

            if (bank_name) {
                obj = {
                    'bank_name': bank_name,
                    'address': address,
                    'phone': phone
                }
                contactInfo.push(obj);
            }
        });
    });
    return contactInfo;
}


function SmartCreditAIpersonalInfo() {
    var table = $('#personalInfo:contains(Personal Information)').parents('table').next('table');
    var html = '';
    addContent();
    table.find('tr').each(function (i, el) {
        if (i == 0 || i == 1)
            return;
        var tds = $(this).find('td');
        var $key_tds = $(this).find('td span b');
        var key = $key_tds.eq(0).clone().children().remove().end().text().replace(/<(?:.|\n)*?>/gm, '');
        var obj = {};
        var text1 = "";
        var text2 = "";
        var text3 = "";
        if (key != "") {
            var tq_eq_1 = tds.eq(1);
            text1 = tq_eq_1.clone().children().remove().end().text().replace(/<(?:.|\n)*?>/gm, '');
            if (tq_eq_1.has('span').length) {
                text1 = tq_eq_1.children('span').text().replace(/<(?:.|\n)*?>/gm, '');
            }
            text1 = text1.replace(/\r?\n|\r/g, '');
            text1 = text1.replace('_', '');
            text1 = text1.replace('-', '');
            text1 = text1.replace(/\s+/g, " ");
            text1 = $.trim(text1);
            text1 = text1.replace('updatenegativepositive', '');

            var tq_eq_2 = tds.eq(2);

            text2 = tq_eq_2.clone().children().remove().end().text().replace(/<(?:.|\n)*?>/gm, '');
            if (tq_eq_2.has('span').length) {
                text2 = tq_eq_2.children('span').text().replace(/<(?:.|\n)*?>/gm, '');
            }
            text2 = text2.replace(/\r?\n|\r/g, '');
            text2 = text2.replace('_', '');
            text2 = text2.replace('-', '');
            text2 = text2.replace(/\s+/g, " ");
            text2 = $.trim(text2);
            text2 = text2.replace('updatenegativepositive', '');

            var tq_eq_3 = tds.eq(3);
            text3 = tq_eq_3.clone().children().remove().end().text().replace(/<(?:.|\n)*?>/gm, '');
            if (tq_eq_3.has('span').length) {
                text3 = tq_eq_3.children('span').text().replace(/<(?:.|\n)*?>/gm, '');
            }
            text3 = text3.replace(/\r?\n|\r/g, '');
            text3 = text3.replace('_', '');
            text3 = text3.replace('-', '');
            text3 = text3.replace(/\s+/g, " ");
            text3 = $.trim(text3);
            text3 = text3.replace('updatenegativepositive', '');

            var key_name = key.replace(/<(?:.|\n)*?>/gm, '');
            key_name = key.replace(/\r?\n|\r/g, '');
            key_name = key.replace(':', " ");
            key_name = key.replace(/\s+/g, " ");
            key_name = $.trim(key);
            var td0 = key_name;
            tds.eq(1).html('<span class="bg-yellow">' + text1 + '</span>');
            tds.eq(2).html('<span class="bg-yellow">' + text2 + '</span>');
            tds.eq(3).html('<span class="bg-yellow">' + text3 + '</span>');
            var trans = '<p style="display:block"><span class="crTableBackground">' + td0 + '</span>&nbsp;&nbsp;&nbsp;<span class="crTableBackground">' + text1 + '</span><span class="crTableBackground">&nbsp;&nbsp;&nbsp;&nbsp;' + text2 + '</span><span class="crTableBackground">&nbsp;&nbsp;&nbsp;&nbsp;' + text3 + '</span></p>';
            trans = "";


            var img = '<div class="bg-white"><div class="sectionHeader">Personal Information</div><table class="" width="560"><tbody><tr class="crTableHeader"><th></th><th class="tranunionHeaderColum">TransUnion</th><th class="experianHeaderColum" ng-show="true">Experian</th><th class="equifaxHeaderColum" ng-show="true">Equifax</th></tr>' + $(this).html() + '</tbody></table></div>';

            var name = "XXXXX";

            var p1 = '';
            var td2 = td0;
            if (td0 == 'CREDIT REPORT DATE:') {
                name = $('#today').val();
                name = new Date(name);
                name = name.toLocaleString('en-us', {month: 'long'}) + ' ' + name.getDate() + ' ' + name.getFullYear();
            }else if (td0 == 'NAME:') {
                td2 = "FIRST & LAST NAME";
                name = $('#name').val();
            } else if (td0 == 'ALSO KNOWN AS:') {
                td2 = "FIRST & LAST NAME";
                name = $('#name').val();
            } else if (td0 == 'FORMER:') {
                td2 = "FIRST & LAST NAME";
                name = $('#name').val();
            } else if (td0 == 'DATE OF BIRTH:') {
                name = $('#dob').val();
                //name = new Date(name);
                //name = name.toLocaleString('en-us', {month: 'long'}) + ' ' + name.getDate() + ' ' + name.getFullYear();
            } else if (td0 == 'CURRENT ADDRESS:' || td0 == 'PREVIOUS ADDRESS:' || td0 == 'PREVIOUSADDRESS:') {
                name = $('#address').val();
                td2 = "Current Address";
            } else {
                td2 = td0;
            }


            p1 = td0 + '(s) of <span class="crTableBackground">' + text1 + '</span>' + ' and ' + '<span class="crTableBackground">' + text2 + '</span>  and <span class="crTableBackground">' + text3 + '</span>';
            //p1 = "";
            var verbiage = '<p class="bg-yellow2" style="font-size:14px;" >REMOVE the display reported ' + p1 + ' as my REQUISITE REPORTED CURRENT CORRECT COMPLETE ' + td2 + ' is <span class="bg-tra">' + name + '</span>. I DO NOT AUTHORIZE you to retain nor report any not proven true correct valid and required reported personal identifier information that is not in exact agreement with my submitted FACTUALLY CORRECT CURRENT PERSONAL IDENTIFIERS as indicated.</p>';
            if (td0 == 'EMPLOYER:') {
                verbiage = '<p class="bg-yellow2" style="font-size:14px;">Please remove the reported allegations of employer(s) of';

                if(text1){
                    verbiage += ' <span class="bg-tra">' + text1 + '</span>';
                }

                if(text2){
                    verbiage += ' and ' + '<span class="bg-exp">' + text2 + '</span>'
                }

                if(text3){
                    verbiage += ' and <span class="bg-equ">' + text3 + '</span>';
                }

                verbiage += ' as there is not federal reporting requisites to report alleged employers.I DO NOT AUTHORIZE you to retain nor report any personal identifier data of which is not EACH of being VERIFIABLE, TRUE, CORRECT, COMPLETE, TIMELY, or elsewise documented VALIDATED, so do NOT!</p>';
            }

            var br = '<p class="cb-br" >*****************************************************************************************************</p>';
            html += img + trans + verbiage + br; // merge all three beauroes
        }

    });

    setCBValues(item_count, '', 1, 'PI-Ew1L1D1-bureau_1', '', html);
    $('.check-df', '#main-content-' + item_count).prop('checked', false);// uncheck data furnisher checkbox for personal info
}

function SmartCreditAIAccounts() {

    var bankInfo = [];
    var verbiage = '<p style="width:100%"><span style="background-color:yellow;">My state and the applicable federal regulations and standards for proper lawful reporting requires that any injurious claim of delinquency and or derogatoriness be factual and physically verified as being fully True, ACCURATE, COMPLETE, TIMELY, of a known ownership of responsibility, and else wise undeniably VALIDATED and further mandates that all such allegations are reported in a perfect and certifiable compliant manner such as in relation to the mandatorily perfect correct and complete certificated Metro 2 Format reporting standard(s). Being that the noted allegation(s) of delinquencies and derogatoriness\'s are reported as one or more fallible conditions of being "missing or incomplete", inconsistent, questionable, and or else wise UNPROVEN reporting. Inability to validate and certify compliant reporting is grounds to demand eradication of claims, and this is my REBUTTAL to  ANY AND ALL NEGATIVE ACCUSATIONS and my rightful DEMAND TO REMOVE such claims from REPORTING!</span></p>';

    $('.crWhiteTradelineHeader b').each(function (i, el1) {
        var bank_table_html = $(this).parents('tr').first().html();
        var bank = $.trim($(this)
                .clone()    //clone the element
                .children() //select all the children
                .remove()   //remove all the children
                .end()  //again go back to selected element
                .text());

        var endDropdownClass = 'smart-cerdit-subAccount-history-' + i;

        if (bank) {
            //console.log('bank',bank);
            addContent();
            var header = bank;
            var trans = '<p ><span class="bg-yellow">' + header + '</span>';
            var exp = '<p ><span class="bg-yellow">' + header + '</span>';
            var equ = '<p ><span class="bg-yellow">' + header + '</span>';

            var inconsistancy = '<span class="glyphicon glyphicon-remove " title="Inconsistency" style="color:red;font-size:14px;margin-top:5px"></span>';
            var advice = '<span class="glyphicon glyphicon-plus advice-text" title="Inconsistency" style="font-size:14px;margin-top:5px;"></span>';
            var table = $(this).parent().parents('table').first().next('table').find('table.crLightTableBackground');
            var html = '';
            var quest = '&nbsp;&nbsp;<span class="glyphicon glyphicon-question-sign acct-quest" title="QUESTIONABLE REPORTED" style="color:red;font-size:16px;"></span>';

            var m = '<span style="color:red" title="Missing">M</span>';
            var u = '<span  style="color:red;" title="Unproven">-U</span>';
            var inc = '<span  style="color:red;" title="Inconsistency">-I</span>';


            var transType = 3;
            var equfType = 3;
            var expType = 3;
            var creditorObj = getSmartCreditAddressPhoneByBankName(bank);
            var current_bankInfo = [];
            var current_table = $(this).parent().parents('table').first().next('table').find('table.crLightTableBackground');
            table.find('tr').each(function (j, el2) {
                var obj = {};
                var tds = $(this).find('td');
                var key_tds = $(this).find('td b');
                var title = $.trim(key_tds.eq(0)
                        .clone()    //clone the element
                        .children() //select all the children
                        .remove()   //remove all the children
                        .end()  //again go back to selected element
                        .text());
                var experian = getTextValueFromTdByColumn(tds, 2);
                var equifax = getTextValueFromTdByColumn(tds, 3);
                var mytrans = getTextValueFromTdByColumn(tds, 1);
                var text1 = "";
                var text2 = "";
                var text3 = "";
                var td0 = title;

                if (experian && experian != 'Experian') {

                    text2 = tds.eq(2).text().replace(/<(?:.|\n)*?>/gm, '');
                    text2 = text2.replace(/\r?\n|\r/g, '');
                    text2 = replaceAll(text2, '_', '');
                    text2 = replaceAll(text2, '-', '');
                    text2 = text2.replace(/\s+/g, " ");
                    text2 = $.trim(text2);
                    text2 = text2.replace('updatenegativepositive', '');
                } else if (experian && experian == 'Experian') {
                    return;
                    if (tds.eq(2).children('select').val()) {
                        expType = tds.eq(2).children('select').val();
                    }
                }

                if (equifax && equifax != 'Equifax') {

                    text3 = tds.eq(3).text().replace(/<(?:.|\n)*?>/gm, '');
                    text3 = text3.replace(/\r?\n|\r/g, '');
                    text3 = replaceAll(text3, '_', '');
                    text3 = replaceAll(text3, '-', '');
                    text3 = text3.replace(/\s+/g, " ");
                    text3 = $.trim(text3);
                    text3 = text3.replace('updatenegativepositive', '');
                } else if (equifax && equifax == 'Equifax') {
                    return;
                    if (tds.eq(3).children('select').val()) {
                        equfType = tds.eq(3).children('select').val();
                    }
                }

                if (mytrans && mytrans != 'TransUnion') {

                    text1 = tds.eq(1).text().replace(/<(?:.|\n)*?>/gm, '');
                    text1 = text1.replace(/\r?\n|\r/g, '');
                    text1 = replaceAll(text1, '_', '');
                    text1 = replaceAll(text1, '-', '');
                    text1 = text1.replace(/\s+/g, " ");
                    text1 = $.trim(text1);
                    text1 = text1.replace('updatenegativepositive', '');
                } else if (mytrans && mytrans == 'TransUnion') {
                    return;
                    if (tds.eq(1).children('select').val()) {
                        transType = tds.eq(1).children('select').val();
                    }
                }
                if (title) {
//                    obj = {
//                        'TransUnion': {account: text1, 'key_name': title},
//                        'Experian': {account: text2, 'key_name': title},
//                        'Equifax': {account: text3, 'key_name': title},
//                    }

                    current_bankInfo.push(obj);
                }

                if (td0.trim() == 'Account #:' || td0.trim() == 'Account Type:' || td0.trim() == 'Account Type - Detail:') {
                    if (td0.trim() == 'Account #:') {
                        if (text1 != '')
                            tds.eq(1).html(text1.replace(/\*/g, '<span class="bg-yellow acct-quest">*</span>') + quest);
                        if (text2 != '')
                            tds.eq(2).html(text2.replace(/\*/g, '<span class="bg-yellow acct-quest">*</span>') + quest);
                        if (text3 != '')
                            tds.eq(3).html(text3.replace(/\*/g, '<span class="bg-yellow acct-quest">*</span>') + quest);
                    }
                    trans += '<p ><span class="bg-yellow">' + td0 + '</span> &nbsp;&nbsp;&nbsp;<span class="bg-tra">' + text1 + '</span>&nbsp;&nbsp;&nbsp;<span class="bg-exp">' + text2 + '</span>&nbsp;&nbsp;&nbsp;<span class="bg-equ">' + text3 + '</span> </p>';
                } else if (td0.trim() == 'Account Status:') {
                    tds.eq(0).html(advice + '&nbsp;&nbsp;&nbsp;<span >' + td0 + '&nbsp; </span><span class="span-cl-green">KEEP OPEN</span>');
                } else if (td0.trim() == 'Monthly Payment:') {
                    tds.eq(0).html(advice + '&nbsp;&nbsp;&nbsp;<span >' + td0 + '&nbsp; </span><span class="span-cl-green">STAY CURRENT</span>');
                } else if (td0.trim() == 'Balance:') {
                    tds.eq(0).html(advice + '&nbsp;&nbsp;&nbsp;<span >' + td0 + '&nbsp; </span><span class="span-cl-green" title="KEEP AT NO GREATER THAN 30% of reported credit limit but BEST IF AT OR BELOW 10% of the reported credit limit!">KEEP AT 10%</span>');
                } else if (td0.trim() == 'High Credit:') {
                    tds.eq(0).html(advice + '&nbsp;&nbsp;&nbsp;<span >' + td0 + '&nbsp; </span><span class="span-cl-green" title="NEVER GO OVER 50% at any time">NEVER GO OVER 50%</span>');
                } else if (td0.trim() == 'Past Due:') {
                    tds.eq(0).html(advice + '&nbsp;&nbsp;&nbsp;<span >' + td0 + '&nbsp; </span><span class="span-cl-green" title="OBVIOUSLY PAY BILLS IN FULL ON TIME ALWAYS, DO NOT MISS , OR BE LATE OR HAVE INCOMPLETE PAYMENT IN ACCOUNT HISTORY">DON\'T BE LATE</span>');
                }

                if (td0.trim() != 'Account #:') {
                    if ((text1 == '' || text1 == '-'))
                        tds.eq(1).html(text1 + m);
                    else {
                        if (text1 != text2 && text2 != '') {
                            tds.eq(1).html(text1 + inc);
                        } else {
                            tds.eq(1).html(text1 + u);
                        }
                    }

                    if (text2 == '' || text2 == '-')
                        tds.eq(2).html(text2 + m);
                    else {
                        if (text2 != text3 && text3 != '') {
                            tds.eq(2).html(text2 + inc);
                        } else {
                            tds.eq(2).html(text2 + u);
                        }
                    }
                    if (text3 == '' || text3 == '-')
                        tds.eq(3).html(text3 + m);
                    else {
                        if (text3 != text1 && text1 != '') {
                            tds.eq(3).html(text3 + inc);
                        } else {
                            tds.eq(3).html(text3 + u);
                        }
                    }
                }

            });
            var newaddress = "";
            var phone = "";
            if (creditorObj.hasOwnProperty('address') && creditorObj.address) {
                newaddress = creditorObj.address
            }

            if (creditorObj.hasOwnProperty('phone') && creditorObj.phone && creditorObj.phone != "BYM-AIL-ONLY") {
                phone = creditorObj.phone
            }
            var type = {
                'TransUnion': transType,
                'Experian': expType,
                'Equifax': equfType,
            }

            $(this).find('.hstry-header').first().append('<p class="span-cl-green">OBVIOUSLY PAY BILLS IN FULL ON TIME ALWAYS, DO NOT MISS , OR BE LATE OR HAVE INCOMPLETE PAYMENT IN ACCOUNT HISTORY</p>')
            var address = getContactAdd(item_count, header);
            trans += '<p ><span class="bg-yellow">Address: </span> &nbsp;&nbsp;&nbsp;<span class="bg-tra">' + newaddress + '</span>';
            var negative = true;

            var dtype;
            var template;

            var template_df;

            var parent_table = $(this).parents('table').first();
            var parent_next_tbl = parent_table.next('table');

            var has_chargeoff = false;
            var has_medical = false;
            var has_collection = false;
            var has_student = false;

            parent_next_tbl.find('td').each(function(){
                if($(this).is(':icontains("Collection/Chargeoff")')
                    || $(this).is(':icontains("Chargeoff")')
                    || $(this).is(':icontains("Writtenoff")')){

                    has_chargeoff = true;
                    return false;

                }else if ($(this).is(':icontains("Medical")')) {

                    has_medical = true;
                    return false;

                }else if ($(this).is(':icontains("Collection")')) {

                    has_collection = true;
                    return false;

                }else if ($(this).is(':icontains("Student")')
                        || $(this).is(':icontains("Student loan")')
                        || $(this).is(':icontains("subsidized")')
                        || $(this).is(':icontains("unsubsidized")')
                        || $(this).is(':icontains("SAllIE MAE")')){

                    has_student = true;
                    return false;
                }
            });

            if (has_chargeoff) {
                dtype = 7;
                template = 'COFF-Ew1L4D1-bureau_4';
                template_df = 'COFF-Ew1L3D1-df-creditor_3';
            } else if (has_medical) {
                if ($(this).find(".hstry-120 ").length > 0 || $(this).find(".hstry-150 ").length > 0 || $(this).find(".hstry-180 ").length > 0) {
                    dtype = 6;
                    template = 'MCOL-Ew1L7D1-bureau_7';
                    template_df = 'MCOL-Ew1L8D1-df-creditor_8';
                } else {
                    $('.check-aa', '#main-content-' + item_count).prop('checked', false);
                    negative = false;
                    dtype = 10;
                    template = 'GEN-Ew1L1D1-bureau_1';
                }
            } else if (has_collection) {
                if ($(this).find(".hstry-120 ").length > 0 || $(this).find(".hstry-150 ").length > 0 || $(this).find(".hstry-180 ").length > 0) {
                    dtype = 5;
                    template = 'NMCOL-Ew1L5D1-bureau_5';
                    template_df = 'NMCOL-Ew1L6D1-df-creditor_6';
                } else {
                    $('.check-aa', '#main-content-' + item_count).prop('checked', false);
                    negative = false;
                    dtype = 10;
                    template = 'GEN-Ew1L1D1-bureau_1';
                }
            } else if (has_student) {
                var count = ($(this).find(".hstry-120 ").length) + ($(this).find(".hstry-150 ").length) + ($(this).find(".hstry-180 ").length) + ($(this).find(".hstry-other ").length) + ($(this).find(".hstry-90 ").length) + ($(this).find(".hstry-60 ").length) + ($(this).find(".hstry-30 ").length);
                if (count > 3) {
                    dtype = 4;
                    template = 'SL3-Ew1L11D1-bureau_11';
                    template_df = 'SL3-Ew1L12D1-df-creditors_12';
                } else if (late_counts > 1 && late_counts <= 3) {
                    dtype = 4;
                    template = 'SL12-Ew1L9D1-bureau_9';
                    template_df = 'SL12-Ew1L10D1-df-creditor_10';
                } else {
                    $('.check-aa', '#main-content-' + item_count).prop('checked', false);
                    negative = false;
                    dtype = 10;
                    template = 'GEN-Ew1L1D1-bureau_1';
                }
            }
            // check for non student loan deogatory (3+ lates) and deliquency (1 or 2 lates)
            // else if( $(this).is(':icontains("LATE")') || $(this).is(':icontains("PAST DUE")')){
            //     var count = ($(this).find(".hstry-120 ").length) + ($(this).find(".hstry-150 ").length) + ($(this).find(".hstry-180 ").length) + ($(this).find(".hstry-other ").length) +($(this).find(".hstry-90 ").length) +($(this).find(".hstry-60 ").length) + ($(this).find(".hstry-30 ").length);
            //     if(count>3 ) setCBValues(item_count,address,3,'NLP3-Ew1LPRD1-bureau_17',html);
            //     else if(count>0<3) setCBValues(item_count,address,3,'NLP12-Ew1L1D1-bureau_1',html);
            // }

            else {
                var late_counts = ($(this).find(".hstry-120 ").length) + ($(this).find(".hstry-150 ").length) + ($(this).find(".hstry-180 ").length) + ($(this).find(".hstry-other ").length) + ($(this).find(".hstry-90 ").length) + ($(this).find(".hstry-60 ").length) + ($(this).find(".hstry-30 ").length);
                if (late_counts > 3) {
                    dtype = 3;
                    template = 'NLP3-Ew1LPRD1-bureau_17';
                    template_df = 'NLP3-Ew1LPRx1D1-df-creditor_17';
                } else if (late_counts > 1 && late_counts <= 3) {
                    dtype = 3;
                    template = 'NLP12-Ew1L1D1-bureau_1';
                    template_df = 'NLP12-Ew1L1D1-df-creditor_1';
                } else {
                    $('.check-aa', '#main-content-' + item_count).prop('checked', false);//check audit analysis checkbox in destination
                    negative = false;
                    dtype = 10;
                    template = 'GEN-Ew1L1D1-bureau_1';
                }

            }


            if (negative) {
                $('.span-cl-green', '#main-content-' + item_count).remove();
                $('.advice-text', '#main-content-' + item_count).remove();
                $(this).find('.span-cl-green').remove();
                $(this).find('.advice-text').remove();
                var ph_table = $(this).find('.addr_hsrty').first();
                var tdlength = ph_table.find(" tr:first > td").length;

                var tds0, tds1, tds2;
                var m = '<span style="color:red" title="Missing">M</span>';
                var u = '<span  class="cl-diff" title="Unproven">-U</span>';
                var inc = '<span  class="cl-diff" title="Inconsistency">-I</span>';
                ph_table.find('tr').each(function (i, el) {
                    if (i == 0 || i == 1)
                        return true;
                    else if (i == 2)
                        tds0 = $(this).find('td');
                    else if (i == 3)
                        tds1 = $(this).find('td');
                    else if (i == 4)
                        tds2 = $(this).find('td');
                })

                if(tds0)
                tds0.each(function (i, el) {
                    if (i == 0) {
                        tds0.eq(i).removeClass("rowAlt");
                        tds1.eq(i).removeClass("rowAlt");
                        tds2.eq(i).removeClass("rowAlt");
                        return true;
                    }
                    var text1 = $.trim(tds0.eq(i).text());
                    var text2 = $.trim(tds1.eq(i).text());
                    var text3 = $.trim(tds2.eq(i).text());

                    if (text1 == '')
                        tds0.eq(i).html(m);
                    else if (text1 != 'OK') {
                        if (text1 != text2) {
                            if (text2 == 'OK' && text3 == 'OK')
                                tds0.eq(i).html(text1 + u);
                            else if (text2 == '' && text3 == '')
                                tds0.eq(i).html(text1 + u);
                            else
                                tds0.eq(i).html(text1 + inc);
                        } else {
                            tds0.eq(i).html(text1 + u);
                        }

                    }

                    if (text2 == '')
                        tds1.eq(i).html(m);
                    else if (text2 != 'OK') {
                        if (text2 != text3) {
                            if (text1 == 'OK' && text3 == 'OK')
                                tds1.eq(i).html(text2 + u);
                            else if (text1 == '' && text3 == '')
                                tds1.eq(i).html(text2 + u);
                            else
                                tds1.eq(i).html(text2 + inc);
                        } else {
                            tds1.eq(i).html(text1 + u);
                        }

                    }
                    if (text3 == '')
                        tds2.eq(i).html(m);
                    else if (text3 != 'OK') {
                        if (text3 != text1) {
                            if (text1 == 'OK' && text2 == 'OK')
                                tds2.eq(i).html(text3 + u);
                            else if (text1 == '' && text2 == '')
                                tds2.eq(i).html(text3 + u);
                            else
                                tds2.eq(i).html(text3 + inc);
                        } else {
                            tds2.eq(i).html(text1 + u);
                        }

                    }
                })


            } else {
                $('.acct-quest', '#main-content-' + item_count).remove();


                //$('.bg-yellow','#main-content-'+item_count).remove();
            }

            if(header == 'JC PENNEY/MCCBG'){
                console.log('$(this)',$(this).parents('table'))
            }

            var img = '<div  style="width:100%;" class="acct-cb-img"><table class="table rpt_content_table rpt_content_header rpt_table4column ng-scope" >' + $(this).parents('table').first().parents('tr').first().html() + '</table></div>';

            var br = '<p class="cb-br" >*****************************************************************************************************</p>';

            var lower_part = "";

            $(this).parents('table').first().parents('table').nextAll().each((i,j)=>{
                //late-count-section-content
                if($.inArray("late-count-section-content", j.classList) !== -1){
                    return false;
                }
                //console.log('i',j.classList)
                lower_part += j.outerHTML
            })
            lower_part = `<div class="lower-part">${lower_part}</div>`
            html = trans + img + verbiage + br; // merge all three beauroes

            setCBValues(item_count, address, dtype, template, template_df, html);

            bankInfo.push({'bank_name': bank, 'bank_info': current_bankInfo, 'address': newaddress, 'phone': phone, 'type': type});
        }
    });



    /*
     ==============================================================================
     Epic velocity Account part js logic here
     ==============================================================================
     */
    //if(item_count>0)
    var html = '';
    $(".crPrint").each(function (i, el) {
        addContent();
        var header = $.trim($(this).find('.sub_header').first().text());

        var trans = '<p ><span class="bg-yellow">' + header + '</span>';
        var exp = '<p ><span class="bg-yellow">' + header + '</span>';
        var equ = '<p ><span class="bg-yellow">' + header + '</span>';

        var inconsistancy = '<span class="glyphicon glyphicon-remove " title="Inconsistency" style="color:red;font-size:14px;margin-top:5px"></span>';
        var advice = '<span class="glyphicon glyphicon-plus advice-text" title="Inconsistency" style="font-size:14px;margin-top:5px;"></span>';
        var table = $(this).find('.rpt_content_table').first();
        var html = '';
        var quest = '&nbsp;&nbsp;<span class="glyphicon glyphicon-question-sign acct-quest" title="QUESTIONABLE REPORTED" style="color:red;font-size:16px;"></span>';

        var m = '<span style="color:red" title="Missing">M</span>';
        var u = '<span  style="color:red;" title="Unproven">-U</span>';
        var inc = '<span  style="color:red;" title="Inconsistency">-I</span>';

        table.find('tr').each(function (i, el) {
            if (i == 0)
                return true;
            var tds = $(this).find('td');
            var td0 = $.trim(tds.eq(0).text());
            var text1 = $.trim(tds.eq(1).text());
            var text2 = $.trim(tds.eq(2).text());
            var text3 = $.trim(tds.eq(3).text());

            if (td0.trim() == 'Account #:' || td0.trim() == 'Account Type:' || td0.trim() == 'Account Type - Detail:') {
                if (td0.trim() == 'Account #:') {
                    if (text1 != '')
                        tds.eq(1).html(text1.replace(/\*/g, '<span class="bg-yellow acct-quest">*</span>') + quest);
                    if (text2 != '')
                        tds.eq(2).html(text2.replace(/\*/g, '<span class="bg-yellow acct-quest">*</span>') + quest);
                    if (text3 != '')
                        tds.eq(3).html(text3.replace(/\*/g, '<span class="bg-yellow acct-quest">*</span>') + quest);
                }
                trans += '<p ><span class="bg-yellow">' + td0 + '</span> &nbsp;&nbsp;&nbsp;<span class="bg-tra">' + text1 + '</span>&nbsp;&nbsp;&nbsp;<span class="bg-exp">' + text2 + '</span>&nbsp;&nbsp;&nbsp;<span class="bg-equ">' + text3 + '</span> </p>';
                // if account # then add questionable sign


            } else if (td0.trim() == 'Account Status:') {
                tds.eq(0).html(advice + '&nbsp;&nbsp;&nbsp;<span >' + td0 + '&nbsp; </span><span class="span-cl-green">KEEP OPEN</span>');
            } else if (td0.trim() == 'Monthly Payment:') {
                tds.eq(0).html(advice + '&nbsp;&nbsp;&nbsp;<span >' + td0 + '&nbsp; </span><span class="span-cl-green">STAY CURRENT</span>');
            } else if (td0.trim() == 'Balance:') {
                tds.eq(0).html(advice + '&nbsp;&nbsp;&nbsp;<span >' + td0 + '&nbsp; </span><span class="span-cl-green" title="KEEP AT NO GREATER THAN 30% of reported credit limit but BEST IF AT OR BELOW 10% of the reported credit limit!">KEEP AT 10%</span>');
            } else if (td0.trim() == 'High Credit:') {
                tds.eq(0).html(advice + '&nbsp;&nbsp;&nbsp;<span >' + td0 + '&nbsp; </span><span class="span-cl-green" title="NEVER GO OVER 50% at any time">NEVER GO OVER 50%</span>');
            } else if (td0.trim() == 'Past Due:') {
                tds.eq(0).html(advice + '&nbsp;&nbsp;&nbsp;<span >' + td0 + '&nbsp; </span><span class="span-cl-green" title="OBVIOUSLY PAY BILLS IN FULL ON TIME ALWAYS, DO NOT MISS , OR BE LATE OR HAVE INCOMPLETE PAYMENT IN ACCOUNT HISTORY">DON\'T BE LATE</span>');
            }


            if (td0.trim() != 'Account #:') {


                if (text1 == '' || text1 == '-')
                    tds.eq(1).html(text1 + m);
                else {
                    if (text1 != text2 && text2 != '') {
                        tds.eq(1).html(text1 + inc);
                    } else {
                        tds.eq(1).html(text1 + u);
                    }

                }

                if (text2 == '' || text2 == '-')
                    tds.eq(2).html(text2 + m);
                else {
                    if (text2 != text3 && text3 != '') {
                        tds.eq(2).html(text2 + inc);
                    } else {
                        tds.eq(2).html(text2 + u);
                    }

                }
                if (text3 == '' || text3 == '-')
                    tds.eq(3).html(text3 + m);
                else {
                    if (text3 != text1 && text1 != '') {
                        tds.eq(3).html(text3 + inc);
                    } else {
                        tds.eq(3).html(text3 + u);
                    }

                }
            }
        })
        $(this).find('.hstry-header').first().append('<p class="span-cl-green">OBVIOUSLY PAY BILLS IN FULL ON TIME ALWAYS, DO NOT MISS , OR BE LATE OR HAVE INCOMPLETE PAYMENT IN ACCOUNT HISTORY</p>')


        var address = getContactAdd(item_count, header);
        trans += '<p ><span class="bg-yellow">Address: </span> &nbsp;&nbsp;&nbsp;<span class="bg-tra">' + address + '</span>';

        var negative = true;

        var dtype;
        var template;
        var verbiage = '';
        var template_df;

        if ($(this).is(':icontains("Collection/Chargeoff")') || $(this).is(':icontains("Chargeoff")') || $(this).is(':icontains("Writtenoff")')) {
            dtype = 7;
            template = 'COFF-Ew1L4D1-bureau_4';
            template_df = 'COFF-Ew1L3D1-df-creditor_3';
        } else if ($(this).is(':icontains("Medical")')) {
            if ($(this).find(".hstry-120 ").length > 0 || $(this).find(".hstry-150 ").length > 0 || $(this).find(".hstry-180 ").length > 0) {
                dtype = 6;
                template = 'MCOL-Ew1L7D1-bureau_7';
                template_df = 'MCOL-Ew1L8D1-df-creditor_8';
            } else {
                $('.check-aa', '#main-content-' + item_count).prop('checked', false);
                negative = false;
                dtype = 10;
                template = 'GEN-Ew1L1D1-bureau_1';
            }
        } else if ($(this).is(':icontains("Collection")')) {
            if ($(this).find(".hstry-120 ").length > 0 || $(this).find(".hstry-150 ").length > 0 || $(this).find(".hstry-180 ").length > 0) {
                dtype = 5;
                template = 'NMCOL-Ew1L5D1-bureau_5';
                template_df = 'NMCOL-Ew1L6D1-df-creditor_6';
            } else {
                $('.check-aa', '#main-content-' + item_count).prop('checked', false);
                negative = false;
                dtype = 10;
                template = 'GEN-Ew1L1D1-bureau_1';
            }
        } else if ($(this).is(':icontains("Student")') || $(this).is(':icontains("Student loan")') || $(this).is(':icontains("subsidized")') || $(this).is(':icontains("unsubsidized")')
                || $(this).is(':icontains("SAllIE MAE")')) {
            var count = ($(this).find(".hstry-120 ").length) + ($(this).find(".hstry-150 ").length) + ($(this).find(".hstry-180 ").length) + ($(this).find(".hstry-other ").length) + ($(this).find(".hstry-90 ").length) + ($(this).find(".hstry-60 ").length) + ($(this).find(".hstry-30 ").length);
            if (count > 3) {
                dtype = 4;
                template = 'SL3-Ew1L11D1-bureau_11';
                template_df = 'SL3-Ew1L12D1-df-creditors_12';
            } else if (late_counts > 1 && late_counts <= 3) {
                dtype = 4;
                template = 'SL12-Ew1L9D1-bureau_9';
                template_df = 'SL12-Ew1L10D1-df-creditor_10';
            } else {
                $('.check-aa', '#main-content-' + item_count).prop('checked', false);
                negative = false;
                dtype = 10;
                template = 'GEN-Ew1L1D1-bureau_1';
            }
        }
        // check for non student loan deogatory (3+ lates) and deliquency (1 or 2 lates)
        // else if( $(this).is(':icontains("LATE")') || $(this).is(':icontains("PAST DUE")')){
        //     var count = ($(this).find(".hstry-120 ").length) + ($(this).find(".hstry-150 ").length) + ($(this).find(".hstry-180 ").length) + ($(this).find(".hstry-other ").length) +($(this).find(".hstry-90 ").length) +($(this).find(".hstry-60 ").length) + ($(this).find(".hstry-30 ").length);
        //     if(count>3 ) setCBValues(item_count,address,3,'NLP3-Ew1LPRD1-bureau_17',html);
        //     else if(count>0<3) setCBValues(item_count,address,3,'NLP12-Ew1L1D1-bureau_1',html);
        // }

        else {
            var late_counts = ($(this).find(".hstry-120 ").length) + ($(this).find(".hstry-150 ").length) + ($(this).find(".hstry-180 ").length) + ($(this).find(".hstry-other ").length) + ($(this).find(".hstry-90 ").length) + ($(this).find(".hstry-60 ").length) + ($(this).find(".hstry-30 ").length);
            if (late_counts > 3) {
                dtype = 3;
                template = 'NLP3-Ew1LPRD1-bureau_17';
                template_df = 'NLP3-Ew1LPRx1D1-df-creditor_17';
            } else if (late_counts > 1 && late_counts <= 3) {
                dtype = 3;
                template = 'NLP12-Ew1L1D1-bureau_1';
                template_df = 'NLP12-Ew1L1D1-df-creditor_1';
            } else {
                $('.check-aa', '#main-content-' + item_count).prop('checked', false);//check audit analysis checkbox in destination
                negative = false;
                dtype = 10;
                template = 'GEN-Ew1L1D1-bureau_1';
            }

        }
        if (negative) {
            $('.span-cl-green', '#main-content-' + item_count).remove();
            $('.advice-text', '#main-content-' + item_count).remove();
            $(this).find('.span-cl-green').remove();
            $(this).find('.advice-text').remove();
            var ph_table = $(this).find('.addr_hsrty').first();
            var tdlength = ph_table.find(" tr:first > td").length;

            verbiage = '<p >My state and the applicable federal regulations and standards for proper lawful reporting requires that any injurious claim of delinquency and or derogatoriness be factual and physically verified as being fully True, ACCURATE, COMPLETE, TIMELY, of a known ownership of responsibility, and else wise undeniably VALIDATED and further mandates that all such allegations are reported in a perfect and certifiable compliant manner such as in relation to the mandatorily perfect correct and complete certificated Metro 2 Format reporting standard(s). Being that the noted allegation(s) of delinquencies and derogatoriness\'s are reported as one or more fallible conditions of being "missing or incomplete", inconsistent, questionable, and or else wise UNPROVEN reporting. Inability to validate and certify compliant reporting is grounds to demand eradication of claims, and this is my REBUTTAL to  ANY AND ALL NEGATIVE ACCUSATIONS and my rightful DEMAND TO REMOVE such claims from REPORTING!</p>';

            var tds0, tds1, tds2;
            var m = '<span style="color:red" title="Missing">M</span>';
            var u = '<span  class="cl-diff" title="Unproven">-U</span>';
            var inc = '<span  class="cl-diff" title="Inconsistency">-I</span>';
            ph_table.find('tr').each(function (i, el) {
                if (i == 0 || i == 1)
                    return true;
                else if (i == 2)
                    tds0 = $(this).find('td');
                else if (i == 3)
                    tds1 = $(this).find('td');
                else if (i == 4)
                    tds2 = $(this).find('td');
            })
            tds0.each(function (i, el) {
                if (i == 0) {
                    tds0.eq(i).removeClass("rowAlt");
                    tds1.eq(i).removeClass("rowAlt");
                    tds2.eq(i).removeClass("rowAlt");
                    return true;
                }
                var text1 = $.trim(tds0.eq(i).text());
                var text2 = $.trim(tds1.eq(i).text());
                var text3 = $.trim(tds2.eq(i).text());

                if (text1 == '')
                    tds0.eq(i).html(m);
                else if (text1 != 'OK') {
                    if (text1 != text2) {
                        if (text2 == 'OK' && text3 == 'OK')
                            tds0.eq(i).html(text1 + u);
                        else if (text2 == '' && text3 == '')
                            tds0.eq(i).html(text1 + u);
                        else
                            tds0.eq(i).html(text1 + inc);
                    } else {
                        tds0.eq(i).html(text1 + u);
                    }

                }

                if (text2 == '')
                    tds1.eq(i).html(m);
                else if (text2 != 'OK') {
                    if (text2 != text3) {
                        if (text1 == 'OK' && text3 == 'OK')
                            tds1.eq(i).html(text2 + u);
                        else if (text1 == '' && text3 == '')
                            tds1.eq(i).html(text2 + u);
                        else
                            tds1.eq(i).html(text2 + inc);
                    } else {
                        tds1.eq(i).html(text1 + u);
                    }

                }
                if (text3 == '')
                    tds2.eq(i).html(m);
                else if (text3 != 'OK') {
                    if (text3 != text1) {
                        if (text1 == 'OK' && text2 == 'OK')
                            tds2.eq(i).html(text3 + u);
                        else if (text1 == '' && text2 == '')
                            tds2.eq(i).html(text3 + u);
                        else
                            tds2.eq(i).html(text3 + inc);
                    } else {
                        tds2.eq(i).html(text1 + u);
                    }

                }
            })


        } else {
            $('.acct-quest', '#main-content-' + item_count).remove();


            //$('.bg-yellow','#main-content-'+item_count).remove();
        }
        var img = '<div  style="width:109%;" class="acct-cb-img"><table class="table rpt_content_table rpt_content_header rpt_table4column ng-scope" >' + $(this).html() + '</table></div>';

        var br = '<p class="cb-br" >*****************************************************************************************************</p>';
        html = trans + img + verbiage + br; // merge all three beauroes
console.log('template',template)
        setCBValues(item_count, address, dtype, template, template_df, html);
        //$('#summernote-'+item_count).summernote('code',html); // insert content in text area.

    });

}


function SmartCreditAIInquiry() {

    var inq_tbl_label = $("td").filter(function () {
        var current_text = $(this).clone().children().remove().end().text().replace(/<(?:.|\n)*?>/gm, '')
        current_text = $.trim(current_text);
        return current_text == "Inquiries" && $(this).attr('style');
    });
    inq_tbl_label.closest('table').attr('id','Inquiries');
    var inquries_tbl = inq_tbl_label.parents('table[border = 1]').first().next('table').next('table');

    inquries_tbl.find('tr').each(function (i, el) {

        //if(i==0) return true; // skip first tr
        //if(i>1) return true; // skip first tr
        //if(item_count>0) addContent();//add new content box if not first.

        var key_tds = $(this).find('td').children('table').each(function () {
            var mytds = $(this).find('tr td');
            var obj = {};
            var type = 3;
            var bank_name = getTextValueFromTdByColumn(mytds, 1);
            var date_of_inq = "";
            var creditor_bereau = "";
            if (getTextValueFromTdByColumn(mytds, 2)) {
                date_of_inq = getTextValueFromTdByColumn(mytds, 2);
            }

            if (getTextValueFromTdByColumn(mytds, 3)) {
                creditor_bereau = getTextValueFromTdByColumn(mytds, 3);
            }


            if (bank_name) {

                obj = {
                    'key_name': bank_name + "_" + date_of_inq,
                    'creditor_bereau': creditor_bereau,
                }

            }

            addContent();
            var trans = '<p ><span class="bg-yellow">Inquiries</span></p>';
            var exp = '<p ><span class="bg-yellow">Inquiries</span></p>';
            var equ = '<p ><span class="bg-yellow">Inquiries</span></p>';

            var tds = $(this).find('td');
            var td0 = bank_name;
            var text1 = $.trim(tds.eq(1).text());
            var text2 = date_of_inq;
            var text3 = $.trim(tds.eq(3).text());

//        if(creditor_bereau == 'Equifax'){
//
//        }else if(creditor_bereau == 'TransUnion'){
//
//        }else if(creditor_bereau == 'Experian'){
//
//        }
            var address = getContactAdd(item_count, td0);
            trans += '<p><span class="bg-yellow">CREDITOR NAME</span>&nbsp;&nbsp;&nbsp;<span class="bg-tra">' + td0 + '</span> </p>';
            exp += '<p><span class="bg-yellow">CREDITOR NAME</span>&nbsp;&nbsp;&nbsp;<span class="bg-exp">' + td0 + '</span> </p>';
            equ += '<p><span class="bg-yellow">CREDITOR NAME</span>&nbsp;&nbsp;&nbsp;<span class="bg-equ" >' + td0 + '</span> </p>';

            trans += '<p><span class="bg-yellow">INQUIRY DATE</span>&nbsp;&nbsp;&nbsp;<span class="bg-tra">' + text2 + '</span> </p>';
            exp += '<p><span class="bg-yellow">INQUIRY DATE</span>&nbsp;&nbsp;&nbsp;<span class="bg-exp">' + text2 + '</span> </p>';
            equ += '<p><span class="bg-yellow">INQUIRY DATE</span>&nbsp;&nbsp;&nbsp;<span class="bg-equ" >' + text2 + '</span> </p>';

            trans += '<p><span class="bg-yellow"> CREDITOR ADDRESS</span>&nbsp;&nbsp;&nbsp;<span class="bg-tra">' + address + '</span> </p>';
            exp += '<p><span class="bg-yellow"> CREDITOR ADDRESS</span>&nbsp;&nbsp;&nbsp;<span class="bg-exp">' + address + '</span> </p>';
            equ += '<p><span class="bg-yellow"> CREDITOR ADDRESS</span>&nbsp;&nbsp;&nbsp;<span class="bg-equ" >' + address + '</span> </p>';

            tds.eq(1).html('<span class="bg-yellow">' + text1 + '</span>');
            tds.eq(2).html('<span class="bg-yellow">' + text2 + '</span>');
            tds.eq(3).html('<span class="bg-yellow">' + text3 + '</span>');
            var tr_html = $(this).html();
            var inq_table_html = $(this).html();
            inq_table_html.replace('<td width="3" class="crLightTableBackground"> </td>', '');
            var img = '<div style="width:80%;" class="bg-white"><div class="rpt_fullReport_header">Inquiries</div><table class="help_text"><tbody><tr><td class="help_text_img"><img src="https://www.identityiq.com/images/tu/info_icon.gif"></td><td>Below are the names of people and/or organizations who have obtained a copy of your Credit Report. Inquiries such as these can remain on your credit file for up to two years.</td></tr></tbody></table><table class="smart-credit-inq-table rpt_content_table rpt_content_header rpt_table4column"><tbody><tr><th class="tbheader" width="30%">Creditor Name</th><th class="tbheader" width="15%">Date of inquiry</th><th class="tbheader" width="15%"> Credit Bureau</th></tr>' + inq_table_html + '</tbody></table></div>';

            var verbiage = "<p >This INQUIRY to date has NOT been proven COMPLIANTLY REPORTED such as to posses factually demonstrated document PHYSICALLY VERIFIED PROOF of adequate lawful PERMISSIBLE PURPOSE achieved from accused and LEGALLY IDENTIFIED consumer and or from an entity otherwise with authority above and beyond said accused consumer's knowledge or refusal.COMPLIANCE OF REPORTING, even for true valid claims is a MINIMAL CRITERIA of reporting so ERADICATE this inquiry allegation HERE AND NOW. Additionally , remove from reporting any associated ALLEGED delinquencies and or derogatoriness , as there can not be ASSUMPTIONS of compliant reporting!</p>";
            var br = '<p class="cb-br" >*****************************************************************************************************</p>';
            var html = trans + br + exp + br + equ + br + img + verbiage + br; // merge all three beauroes

            setCBValues(item_count, address, 2, 'INQ-Ew1L2D1-bureau_2', 'INQ-Ew1L2D1-bureau_2', html);

        });

    })

    $('.smart-credit-inq-table').find('tr').each(function (i, el) {
        $(this).find('th').attr('width','15%');
        var td_text = $.trim($(this).find('td').clone()
                .children() //select all the children
                .remove()   //remove all the children
                .end()  //again go back to selected element
                .text().replace(/<(?:.|\n)*?>/gm, ''));
        if(!td_text){
            $(this).find('td').eq(0).remove();
        }
    });
}

function SmartCreditAIpublicInfo() {

    var header = "";
    var infotbl = "";
    var pbInfo_label = $("td").filter(function () {
        var result = false;
        var current_text = $(this).clone().children().remove().end().text().replace(/<(?:.|\n)*?>/gm, '')
        current_text = current_text.replace(/\r?\n|\r/g, '');
        current_text = $.trim(current_text);
        if (current_text == "Public Information" && $(this).attr('style')) {
            return true;
        }
    });
    pbInfo_label.closest('table').attr('id','PublicInformation');
    var public_tbl = pbInfo_label.parent('tr').first().next('tr').children('td').children('table');

    public_tbl.each(function () {
        var public_bank = $(this).find('td.crGrantedTradelineHeader b').clone().children().remove().end().text().replace(/<(?:.|\n)*?>/gm, '');
        if (public_bank) {
            header = public_bank;
        }
    });



        $('.publicrecord').remove();
        addContent();
        var trans = '<p ><span class="bg-yellow">' + header + ' </span>';
        var exp = '<p ><span class="bg-yellow">' + header + ' </span>';
        var equ = '<p ><span class="bg-yellow">' + header + ' </span>';
        var df_address ='';
        var no_of_tbl = 3
        var table = public_tbl.eq(no_of_tbl);
        var prev_table = public_tbl.eq(no_of_tbl - 1);
        table.find('tr').each(function (i, el) {
          var tds = $(this).find('td.crLightTableBackground');
          var key_tds = $(this).find('td.crLightTableBackground b');
          var td0 = $.trim(key_tds.text());
          var text1 = $.trim(tds.eq(2).text());
          var text2 = $.trim(tds.eq(3).text());
          var text3 = $.trim(tds.eq(4).text());

          if(td0=='Type:'){
            trans += '<span class="bg-tra">'+text1+'</span> </p>';
            exp += '<span class="bg-exp">'+text2+'</span> </p>';
            equ += '<span class="bg-equ" >'+text3+'</span> </p>';
          }
          else if(td0=='Date Filed/Reported:'){
            trans += '<p ><span class="bg-yellow">'+td0+' </span> <span class="bg-tra">'+text1+'</span> </p>';
            exp += '<p ><span class="bg-yellow">'+td0+' </span><span class="bg-exp">'+text2+'</span> </p>';
            equ += '<p ><span class="bg-yellow">'+td0+' </span><span class="bg-equ">'+text3+'</span> </p>';
          }
          else if(td0=='Reference#:'){
            trans += '<p ><span class="bg-yellow">'+td0+' </span><span class="bg-tra">'+text1+'</span> </p>';
            exp += '<p ><span class="bg-yellow">'+td0+' </span><span class="bg-exp">'+text2+'</span> </p>';
            equ += '<p ><span class="bg-yellow">'+td0+' </span><span class="bg-equ">'+text3+'</span> </p>';
          }
          else if(td0=='Court:'){
            trans += '<p ><span class="bg-yellow">Account Name: </span> <span class="bg-tra">'+text1+'</span> </p>';
            exp += '<p ><span class="bg-yellow">Account Name: </span><span class="bg-exp">'+text2+'</span> </p>';
            equ += '<p ><span class="bg-yellow">Account Name: </span><span class="bg-equ">'+text3+'</span> </p>';

            df_address = getContactAdd(item_count,text1);
            if(!df_address) df_address = getContactAdd(item_count,text2);
            if(!df_address) df_address = getContactAdd(item_count,text3);

          }
          if(text1==text2 && text2==text3) {
            if(text1=='-'){
              tds.eq(2).html('<span class="bg-yellow">-</span>');
              tds.eq(3).html('<span class="bg-yellow">-</span>');
              tds.eq(4).html('<span class="bg-yellow">-</span>');
            }
          }

          else if(text1 == text2 && text2 != text3  ) {
            tds.eq(4).html('<span class="bg-yellow">'+text3+'</span>');
          }
          else if(text1 != text2 && text2 == text3  ) {
            tds.eq(2).html('<span class="bg-yellow">'+text1+'</span>');
          }
          else if(text1 == text3 && text2 != text3  ) {
            tds.eq(3).html('<span class="bg-yellow">'+text2+'</span>');
          }
          else if(text1 != text3 && text2 != text3  ) {
            tds.eq(2).html('<span class="bg-yellow">'+text1+'</span>');
            tds.eq(3).html('<span class="bg-yellow">'+text2+'</span>');
            tds.eq(4).html('<span class="bg-yellow">'+text3+'</span>');
          }
        })

        trans += '<p ><span class="bg-yellow">Address:</span><span class="bg-tra">'+df_address+'</span></p>';
        exp += '<p ><span class="bg-yellow">Address:</span><span class="bg-exp">'+df_address+'</span></p>';
        equ += '<p ><span class="bg-yellow">Address:</span><span class="bg-equ">'+df_address+'</span></p>';
        var pb_th =                     '<tr><td class="crLightTableBackground" width=""></td>'+
                        '<tr><td class="crLightTableBackground" width="2"></td>'+
                            '<td class="crLightTableBackground" width="136">'+
                                'TransUnion'+
                            '</td>'+
                            '<td class="crLightTableBackground" width="136">'+
                                'Experian'+
                            '</td>'+
                            '<td class="crLightTableBackground" width="136">'+
                                'Equifax'+
                            '</td>'+
                        '</tr>';

        var img = '<div style="width:80%;" class="bg-white">'
            +'<table class="rpt_content_table rpt_content_header rpt_table4column">'
            +prev_table.html()+
            '</table>'+
            '<table class="rpt_content_table rpt_content_header rpt_table4column">'

                    +table.html()+
            '</table></div>';

        var br = '<p class="cb-br" >*****************************************************************************************************</p>';
        var html = trans +br + exp + br + equ + img;


        setCBValues(item_count,df_address,9,'PR-Ew1L15D1-bureau_15','PR-Ew1L16D1-df-creditor_16',html);

}

function setSmartCreditCreditorContacts(){
    var creditor_tbl = $("td").filter(function () {
        var current_text = $(this).text().replace(/<(?:.|\n)*?>/gm, '');
        current_text = current_text.replace(/\r?\n|\r/g, '');
        current_text = $.trim(current_text);
        return current_text == "Creditor Contacts" && $(this).attr('style');
    }).closest('table').attr('id','CreditorContacts');
}

function getSmartCreditCreditorDropDown(){
    var html = "";
    var all_crditors_contacts_smart_credit = creditorContactsSmartCredit();
    if(all_crditors_contacts_smart_credit){
          $.each(all_crditors_contacts_smart_credit,function(index,value){
              var bank_name = $.trim(value.bank_name);
              var address = value.address.replace(/ +(?= )/g,'');
              html = html+'<option value="'+bank_name+' : '+address+'" title="'+address+'">'+bank_name+'</option>';
          })
    }



    return html;

}
