/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

function clearTextBox(elem){
    event.preventDefault();
    if(confirm('Are you sure want to clear ?')){
        removeCheckedData(elem)
        $(elem).prev('textarea').val('');
        $(elem).prev('input[type=text]').val('');
        
        
    }
}

function validateLetterStreamAddress(address) {
    var result = "";

    var splited_address = address.split(',');

    if (splited_address.length == 2) {
        var second_part_of_comma = splited_address[1];

        if (second_part_of_comma) {
            var reverseString = second_part_of_comma.split("").reverse().join("");
            var charlist = reverseString.split('');

            var count = 0;
            for (var key in charlist) {
                var value = charlist[key]
                if (value != ' ') {
                    count++;
                }
                if (count == 8) {

                    result = result + ",";
                }
                result = result + value;


            }
        }
        if(result){
            result = result.split("").reverse().join("");

            if (splited_address[0]) {
                result = splited_address[0] + ", " + result;
            }
        }
    } else {
        result = address;
    }


    return result;

}

function removeCheckedData(elem){
    var class_name = "";
    if($(elem).prev('textarea')){
        class_name = $(elem).prev('textarea').attr('class')
    }else if($(elem).prev('input[type=text]')){
         class_name = $(elem).prev('input[type=text]').attr('class')
    }
    var classList = []
    $(elem).parent().find('a').each(function(){
        var text = $(this).clone().children().remove().end().text();
        if(text){
            classList.push($.trim(text));
        }
    });
    console.log('classList',classList);
    if($.inArray("Personal Information", classList) !== -1){
        
        $('#personal-info-subcat-name-1').html('');
        $('#personal-info-subcat-name-1').parent('a').find('span.choose-dest').show();
        $('#rtg-personal-info-list  input[type=checkbox]').each(function(){
            $(this).prop('checked',false);
        });
        personal_info_selected_items = [];
    }else if($.inArray("Negative Item", classList) !== -1 && $.inArray("Public Record", classList) !== -1) {
        negative_info_selected_items = [];
        $('#negative-subcat-name-1').html('');
        $('#negative-subcat-name-1').parent('a').find('span.choose-dest').show();
        $('#rtg-negative-list  input[type=checkbox]').each(function(){
            $(this).prop('checked',false);
        });
        
        $('#publicrecord-subcat-name-1').html('');
        $('#publicrecord-subcat-name-1').parent('a').find('span.choose-dest').show();
        $('#rtg-publicrecord-list  input[type=checkbox]').each(function(){
            $(this).prop('checked',false);
        });
    }else if($.inArray("Creditor Name & Address", classList) !== -1 && $.inArray("(Public Records)Creditor Name & Address", classList) !== -1) {
//        $('#negative-creditor-info-subcat-name-1').html('');
//        $('#negative-creditor-info-subcat-name-1').parent('a').find('span.choose-dest').show();
//        $('#rtg-negative-creditor-list  input[type=checkbox]').each(function(){
//            $(this).prop('checked',false);
//        });
    }else if($.inArray("Negative Item", classList) !== -1){
        
    }
    
    
}

function setClearIcon(){
    return '<a href="#" style="float:left" onclick="clearTextBox(this)"><i class="fa fa-eraser" aria-hidden="true"></i> Clear</a>';
}


function setCreditorNameIcon() {
    $('.creditor-name').parent().find('a').remove();
    var html = '<a href="#" onclick="getCreditorNameModal(this)" class="pull-left" title="Creditor Name">' +
        '<i class="fa fa-edit"></i>' +
        ' Creditor Name' +
        '</a>';

    $('.creditor-name').parent().append(setClearIcon());
    $('.creditor-name').parent().prepend(html);
    return html;
}

function setCreditorAccountOnlyIcon() {
    $('.creditor-account-only').parent().find('a').remove();
    var html = '<a href="#" onclick="getCreditorAccountOnlyModal(this)" class="pull-left" title="Creditor Account">' +
        '<i class="fa fa-edit"></i>' +
        ' Creditor Account' +
        '</a>';

    $('.creditor-account-only').parent().append(setClearIcon());
    $('.creditor-account-only').parent().prepend(html);
    return html;
}

function setCreditorAccountIcon() {
    $('.creditor-account').parent().find('a').remove();
    var html = '<a href="#" onclick="getCreditorAccountModal(this)" class="pull-left" title="Creditor Name & Account">' +
        '<i class="fa fa-edit"></i>' +
        ' Creditor Name & Account' +
        '</a>';

    $('.creditor-account').parent().append(setClearIcon());
    $('.creditor-account').parent().prepend(html);
    return html;
}

function setInquiryCreditorIcon() {
    $('.inquiry-creditor').parent().find('a').remove();
    var html = '<a href="#" onclick="getInquiriesCreditorModal(this)" class="pull-left" title="Creditor Name & Address">' +
        '<i class="fa fa-edit"></i>' +
        ' Creditor Name & Address' +
        '</a>';
    $('.inquiry-creditor').parent().append(setClearIcon());
    $('.inquiry-creditor').parent().prepend(html);
    return html;
}

function setNegativeCreditorIcon() {
    $('.negative-creditor').parent().find('a').remove();
    var html = '<a href="#" onclick="getNegativeCreditorModal(this)" class="pull-left" title="Creditor Name & Address">' +
        '<i class="fa fa-edit"></i>' +
        ' Creditor Name & Address' +
        '</a>';
    if(hasNegativeWithPublicRecord()){
        var pb_html = '<a href="#" onclick="getPublicRecordCreditorModal(this)" class="pull-right" title="Public Record">' +
        '<i class="fa fa-edit"></i>' +
        ' (Public Records)Creditor Name & Address' +
        '</a>';

        html +=pb_html; 
    }
    $('.negative-creditor').parent().append(setClearIcon());
    $('.negative-creditor').parent().prepend(html)
    return html;
}

function setLatePaysCreditorIcon() {
    $('.latepays-creditor').parent().find('a').remove();
    var html = '<a href="#" onclick="getLatepaysCreditorModal(this)" class="pull-left" title="Creditor Name & Address">' +
        '<i class="fa fa-edit"></i>' +
        ' Creditor Name & Address' +
        '</a>';
    $('.latepays-creditor').parent().append(setClearIcon());
    $('.latepays-creditor').parent().prepend(html)
    return html;
}

function setPersonalInfoIcon() {
    $('.personal-info-area').parent().find('a').remove();
    var html = '<a href="#" onclick="getPersonalInfoModal(this)" class="pull-left" title="Personal Information">' +
        '<i class="fa fa-edit"></i>' +
        ' Personal Information' +
        '</a>';
    if(FORM_ID == 62){
        var negative_icon_html = '<a href="#" onclick="getNegativeModal(this)" class="pull-left" title="Negative Item">' +
        '<i class="fa fa-edit"></i>' +
        ' Negative Item' +
        '</a>';

        var inquiry_icon_html = '<a href="#" onclick="getInquriesModal(this)" class="pull-right" title="Inquiries">' +
        '<i class="fa fa-edit"></i>' +
        ' Inquiries' +
        '</a>';

        html = negative_icon_html+inquiry_icon_html;
    }    
    
    $('.personal-info-area').parent().append(setClearIcon());
    $('.personal-info-area').parent().prepend(html)
    return html;
}


function setInquiriesIcon() {
    $('.inquries-modal-area textarea').parent('.col-sm-12').find('a').remove();
    $('.inquries-modal-area input').parent('.col-sm-6').find('a').remove();
    var html = '<a href="#" onclick="getInquriesModal(this)" class="pull-left" title="Inquiries">' +
        '<i class="fa fa-edit"></i>' +
        ' Inquiries' +
        '</a>';
    $('.inquries-modal-area textarea').parent('.col-sm-12').append(setClearIcon());
    $('.inquries-modal-area textarea').parent('.col-sm-12').prepend(html);
    $('.inquries-modal-area input').parent('.col-sm-6:contains("Date #")').append(setClearIcon());
    $('.inquries-modal-area input').parent('.col-sm-6:contains("Creditor #")').append(setClearIcon());
    $('.inquries-modal-area input').parent('.col-sm-6:contains("Creditor #")').prepend(html)
    return html;
}

function setLatePaysIcon() {
    $('.latepays-modal-area textarea').parent('.col-sm-12').find('a').remove();
    $('.latepays-modal-area input').parent('.col-sm-6').find('a').remove();
    var html = '<a href="#" onclick="getLatepaysModal(this)" class="pull-left" title="Late Pays / 2 Or Less">' +
        '<i class="fa fa-edit"></i>' +
        ' Late Pays / 2 Or Less ' +
        '</a>';
    $('.latepays-modal-area textarea').parent('.col-sm-12').append(setClearIcon());
    $('.latepays-modal-area textarea').parent('.col-sm-12').prepend(html);
    $('.latepays-modal-area input').parent('.col-sm-6:contains("Account #")').append(setClearIcon());;
    var content_3 = $('.latepays-modal-area input').parent('.col-sm-6:contains("Creditor#")');
    if (content_3.length > 0) {
        content_3.append(setClearIcon());
        content_3.prepend(html)
    }

    
    return html;
}

function setNegativeIcon() {
    $('.negative-modal-area textarea').parent('.col-sm-12').find('a').remove();
    $('.negative-modal-area input').parent('.col-sm-6').find('a').remove();
    $('.negative-modal-area input').parent('.col-sm-12').find('a').remove();
    $('.negative-item-class').prev('a[title="Negative Item"]')
    var html = '<a href="#" onclick="getNegativeModal(this)" class="pull-left" title="Negative Item">' +
        '<i class="fa fa-edit"></i>' +
        ' Negative Item' +
        '</a>';
     
    if(hasNegativeWithPublicRecord()){
         var public_html = '<a href="#" onclick="getPublicRecordModal(this)" class="pull-right" title="Public Record">' +
                            '<i class="fa fa-edit"></i>' +
                            ' Public Record' +
                            '</a>';
                    
        $('.negative-modal-area textarea').parent('.col-sm-12').each(function(){
            var text = $.trim($(this).text());
            
            $(this).contents().filter(function(){
                return this.nodeType === 3;
            }).remove();
            $(this).find('br').remove();
            //$(this).text('');
            $(this).append(setClearIcon());
            $(this).prepend(html+""+text+""+public_html+"<br/>");
        })
        
        
    }else{    
        $('.negative-modal-area textarea').parent('.col-sm-12').append(setClearIcon());
        $('.negative-modal-area textarea').parent('.col-sm-12').prepend(html);
        $('.negative-item-class').parent().find('a').remove();
        $('.negative-item-class').parent().prepend(html);
        $('.negative-item-class').parent().append(setClearIcon());
    }
    var content_1 = $('.negative-modal-area input').parent('.col-sm-6:contains("CREDITOR #")');
    var content_2 = $('.negative-modal-area input').parent('.col-sm-6:contains("Medical creditor#")');
    $('.negative-modal-area input').parent('.col-sm-6:contains("ACCOUNT #")').append(setClearIcon());
    $('.negative-modal-area input').parent('.col-sm-6:contains("Account #")').append(setClearIcon());
    var content_3 = $('.negative-modal-area input').parent('.col-sm-6:contains("Creditor#")');

    if (content_1.length > 0) {
        content_1.append(setClearIcon());
        content_1.prepend(html)
    } else if (content_2.length > 0) {
        content_2.append(setClearIcon());
        content_2.prepend(html)
    } else if (content_3.length > 0) {
        content_3.append(setClearIcon());
        content_3.prepend(html)
    }

    $('.negative-modal-area input').parent('.col-sm-12').append(setClearIcon());
    $('.negative-modal-area input').parent('.col-sm-12').prepend(html)
    return html;
}

function setPublicRecordIcon() {
    $('.public-record-modal-area textarea').parent('.col-sm-12').find('a').remove();
    $('textarea.public-record-textarea').parent().find('a').remove();
    var html = '<a href="#" onclick="getPublicRecordModal(this)" class="pull-left" title="Public Record">' +
        '<i class="fa fa-edit"></i>' +
        ' Public Record' +
        '</a>';

    if(hasNegativeWithPublicRecord()){
         var negative_html = '<a href="#" onclick="getNegativeModal(this)" class="pull-right" title="Negative Item">' +
                            '<i class="fa fa-edit"></i>' +
                            ' Negative Item' +
                            '</a>';
                    
        $('.public-record-modal-area textarea').parent('.col-sm-12').each(function(){
            var text = $.trim($(this).text());
            
            $(this).contents().filter(function(){
                return this.nodeType === 3;
            }).remove();
            $(this).find('br').remove();
            $(this).append(setClearIcon());
            $(this).prepend(html+""+text+""+negative_html+"<br/>");
        })
        
        
    }else{
        $('.public-record-modal-area textarea').parent('.col-sm-12').prepend(html);
    }
    
    $('.public-record-textarea').parent().append(setClearIcon());
    $('.public-record-textarea').parent().prepend(html);
    return html;
}

function getInquiriesCreditorModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    if (textarea.length > 0) {
        var name = textarea.attr('name');
    } else {
        var textarea = $(elem).parent().find('input');
        var name = textarea.attr('name');
    }
    $('#inquiries-creditor-info-subcat-name-1').html('')
    $('.choose-dest').show();
    $('select[name=item_inquiries_creditor_info_1]').val(4).trigger('change');
    $('input[name=inquiries_creditor_textarea_name]').val(name);
    $('#inquiries-creditor-modal').modal('show');

}


function getCreditorNameModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    var account_input_tag_name = "";
    if (textarea.length > 0) {
        var name = textarea.attr('name');
    } else {
        var textarea = $(elem).parent().find('input');
        var name = textarea.attr('name');

    }
    $('#creditor-name-subcat-name-1').html('')
    $('.choose-dest').show();
    $('select[name=creditor_name_1]').val(4).trigger('change');
    $('input[name=creditor_name_textarea]').val(name);
    $('#creditor-name-modal').modal('show');
}


function getCreditorAccountOnlyModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    var account_input_tag_name = "";
    if (textarea.length > 0) {
        var name = textarea.attr('name');
    } else {
        var textarea = $(elem).parent().find('input');
        var name = textarea.attr('name');

    }
    $('#creditor-account-subcat-name-1').html('')
    $('.choose-dest').show();
    $('select[name=creditor_account_1]').val(4).trigger('change');
    $('input[name=creditor_account_textarea]').val(name);
    $('#creditor-account-modal').modal('show');

}

function getCreditorAccountModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    var account_input_tag_name = "";
    if (textarea.length > 0) {
        var name = textarea.attr('name');
    } else {
        var textarea = $(elem).parent().find('input');
        var name = textarea.attr('name');

    }
    $('#negative-creditor-info-subcat-name-1').html('')
    $('.choose-dest').show();
    $('select[name=creditor_account_1]').val(4).trigger('change');
    $('input[name=creditor_account_textarea]').val(name);
    $('#creditor-account-modal').modal('show');

}

function getNegativeCreditorModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    var account_input_tag_name = "";
    if (textarea.length > 0) {
        var name = textarea.attr('name');
    } else {
        var textarea = $(elem).parent().find('input');
        var name = textarea.attr('name');

    }
    $('#negative-creditor-info-subcat-name-1').html('')
    $('.choose-dest').show();
    $('select[name=item_negative_creditor_info_1]').val(4).trigger('change');
    $('input[name=negative_creditor_textarea_name]').val(name);
    $('#negative-creditor-modal').modal('show');

}

function getLatepaysCreditorModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    if (textarea.length > 0) {
        var name = textarea.attr('name');
    } else {
        var textarea = $(elem).parent().find('input');
        var name = textarea.attr('name');
    }

    $('#latepays-creditor-info-subcat-name-1').html('')
    $('.choose-dest').show();
    $('select[name=item_latepays_creditor_info_1]').val(4).trigger('change');
    $('input[name=latepays_creditor_textarea_name]').val(name);
    $('#latepays-creditor-modal').modal('show');

}

function getPersonalInfoModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    if (textarea.length > 0) {
        var name = textarea.attr('name');
    } else {
        var textarea = $(elem).parent().find('input');
        var name = textarea.attr('name');
    }
    //$('#personal-info-subcat-name-1').html('')
    //$('.choose-dest').show();
    $('select[name=item_personal_info_1]').val(4).trigger('change');
    $('input[name=personal_info_textarea_name]').val(name);


    $('#personal-info-modal').modal('show');

}

function getInquriesModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    var date_input_tag_name = "";
    if (textarea.length > 0) {
        var name = textarea.attr('name');
    } else {
        var textarea = $(elem).parent().find('input');
        var name = textarea.attr('name');
        var date_input_tag = $(elem).parent().next('.col-sm-6').find('input');
        date_input_tag_name = date_input_tag.attr('name')
    }
    if(FORM_ID != 62){
        $('#inquiry-subcat-name-1').html('')
        $('.choose-dest').show();
    }
    $('select[name=item_inquirey_1]').val(4).trigger('change');
    $('input[name=inq_textarea_name]').val(name + "|" + date_input_tag_name);



    $('#inquruies-modal').modal('show');
}

function getLatepaysModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    var account_input_tag_name = "";
    if (textarea.length > 0) {
        var name = textarea.attr('name');
    } else {
        var textarea = $(elem).parent().find('input');
        var name = textarea.attr('name');
        var account_input_tag = textarea.parent().next('.col-sm-6').find('input');
        account_input_tag_name = account_input_tag.attr('name');
    }
    
    $('#latepays-subcat-name-1').html('')
    $('.choose-dest').show();
    $('select[name=item_latePays_1]').val(4).trigger('change');
    $('input[name=latepays_textarea_name]').val(name + "|" + account_input_tag_name);
    $('#latespays-modal').modal('show');
}

function getNegativeModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    var account_input_tag_name = "";
    if (textarea.length > 0) {
        var name = textarea.attr('name');
    } else {
        var textarea = $(elem).parent().find('input');
        var name = textarea.attr('name');
        var account_input_tag = textarea.parent().next('.col-sm-6').find('input');
        account_input_tag_name = account_input_tag.attr('name');
    }
    //$('#negative-subcat-name-1').html('')
    //$('.choose-dest').show();
    $('select[name=item_negative_1]').val(4).trigger('change');
    $('input[name=negative_textarea_name]').val(name + "|" + account_input_tag_name);
    $('#negative-modal').modal('show');
}

function getPublicRecordModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    var name = textarea.attr('name');
    //    $('#publicrecord-subcat-name-1').html('')
    //    $('.choose-dest').show();
    $('select[name=item_publicrecord_1]').val(4).trigger('change');
    $('input[name=publicrecord_textarea_name]').val(name);
    $('#publicrecord-modal').modal('show');
}

function getPublicRecordCreditorModal(elem) {
    event.preventDefault();
    var textarea = $(elem).parent().find('textarea');
    var name = textarea.attr('name');
    //    $('#publicrecord-subcat-name-1').html('')
    //    $('.choose-dest').show();
    $('select[name=item_publicrecord_creditor_1]').val(4).trigger('change');
    $('input[name=publicrecord_creditor_textarea_name]').val(name);
    $('#publicrecord-creditor-modal').modal('show');
}

function getInquiryByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};
    if (value == 1) {
        inqCompanyData = INQ_WITH_COMPANY_ASSOC['Exp']
    } else if (value == 2) {
        inqCompanyData = INQ_WITH_COMPANY_ASSOC['Equif']
    } else if (value == 3) {
        inqCompanyData = INQ_WITH_COMPANY_ASSOC['Trans']
    } else if (value == 4) {
        inqCompanyData = INQ_ALL_ASSOC
    }

    if (!inqCompanyData) {
        inqCompanyData = {
            key_date: {},
            key_name: {}
        }

    }

    setInquryList(inqCompanyData.key_date, inqCompanyData.key_name);
}

function getInquiriesCreditorByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};
    if (value == 1) {
        inqCompanyData = INQ_WITH_COMPANY_ASSOC['Exp']
    } else if (value == 2) {
        inqCompanyData = INQ_WITH_COMPANY_ASSOC['Equif']
    } else if (value == 3) {
        inqCompanyData = INQ_WITH_COMPANY_ASSOC['Trans']
    } else if (value == 4) {
        inqCompanyData = INQ_ALL_ASSOC
    }

    if (!inqCompanyData) {
        inqCompanyData = {
            key_date: {},
            key_name: {}
        }

    }

    setInquriesCreditorList(inqCompanyData.key_date, inqCompanyData.key_name);
}

function getLatepaysByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};

    if (value == 1) {
        inqCompanyData = LATE_PAYS_CATEGORY['exp']
    } else if (value == 2) {
        inqCompanyData = LATE_PAYS_CATEGORY['equif']
    } else if (value == 3) {
        inqCompanyData = LATE_PAYS_CATEGORY['trans']
    } else if (value == 4) {
        inqCompanyData = LATE_PAYS_ALL
    }


    setlatepaysList(inqCompanyData);
}

function getNegativeCreditorByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};

    if (value == 1) {
        inqCompanyData = NEGATIVE_CATEGORY['exp']
    } else if (value == 2) {
        inqCompanyData = NEGATIVE_CATEGORY['equif']
    } else if (value == 3) {
        inqCompanyData = NEGATIVE_CATEGORY['trans']
    } else if (value == 4) {
        inqCompanyData = NEGATIVE_ALL
    }


    setNegativeCreditorList(inqCompanyData);
}


function getCreditorAccountByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};

    if (value == 1) {
        inqCompanyData = NEGATIVE_CATEGORY['exp']
    } else if (value == 2) {
        inqCompanyData = NEGATIVE_CATEGORY['equif']
    } else if (value == 3) {
        inqCompanyData = NEGATIVE_CATEGORY['trans']
    } else if (value == 4) {
        inqCompanyData = NEGATIVE_ALL
    }


    setCreditorAccountList(inqCompanyData);
}

function getLatepaysCreditorByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};

    if (value == 1) {
        inqCompanyData = LATE_PAYS_CATEGORY['exp']
    } else if (value == 2) {
        inqCompanyData = LATE_PAYS_CATEGORY['equif']
    } else if (value == 3) {
        inqCompanyData = LATE_PAYS_CATEGORY['trans']
    } else if (value == 4) {
        inqCompanyData = LATE_PAYS_ALL
    }


    setLatepaysCreditorList(inqCompanyData);
}

function getNegativeByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};

    if (value == 1) {
        inqCompanyData = NEGATIVE_CATEGORY['exp']
    } else if (value == 2) {
        inqCompanyData = NEGATIVE_CATEGORY['equif']
    } else if (value == 3) {
        inqCompanyData = NEGATIVE_CATEGORY['trans']
    } else if (value == 4) {
        inqCompanyData = NEGATIVE_ALL
    }

    
    
    setNegativeList(inqCompanyData);
}


function getPublicRecordByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};

    if (value == 1) {
        inqCompanyData = PUBLIC_RECORD_CATEGORY_WISE['exp']
    } else if (value == 2) {
        inqCompanyData = PUBLIC_RECORD_CATEGORY_WISE['equif']
    } else if (value == 3) {
        inqCompanyData = PUBLIC_RECORD_CATEGORY_WISE['trans']
    } else if (value == 4) {
        inqCompanyData = MAIN_PUBLIC_RECORDS
    }


    setPublicRecordList(inqCompanyData);
}

function getCreditorAccountOnlyByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};

    if (value == 1) {
        inqCompanyData = NEGATIVE_CATEGORY['exp']
    } else if (value == 2) {
        inqCompanyData = NEGATIVE_CATEGORY['equif']
    } else if (value == 3) {
        inqCompanyData = NEGATIVE_CATEGORY['trans']
    } else if (value == 4) {
        inqCompanyData = NEGATIVE_ALL
    }


    setNegativeCreditorAccountOnlyList(inqCompanyData);
}

function getCreditorNameByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};

    if (value == 1) {
        inqCompanyData = NEGATIVE_CATEGORY['exp']
    } else if (value == 2) {
        inqCompanyData = NEGATIVE_CATEGORY['equif']
    } else if (value == 3) {
        inqCompanyData = NEGATIVE_CATEGORY['trans']
    } else if (value == 4) {
        inqCompanyData = NEGATIVE_ALL
    }

    setNegativeCreditorNameList(inqCompanyData);
}

function getPublicRecordCreditorByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};

    if (value == 1) {
        inqCompanyData = PUBLIC_RECORD_CATEGORY_WISE['exp']
    } else if (value == 2) {
        inqCompanyData = PUBLIC_RECORD_CATEGORY_WISE['equif']
    } else if (value == 3) {
        inqCompanyData = PUBLIC_RECORD_CATEGORY_WISE['trans']
    } else if (value == 4) {
        inqCompanyData = MAIN_PUBLIC_RECORDS
    }


    setPublicRecordCreditorList(inqCompanyData);
}

function getPersonalInfoByCompanyForRTG(elem) {
    var value = $(elem).val();
    var inqCompanyData = {};

    if (value == 1) {
        inqCompanyData = PERSONAL_INFO_CATEGORY_WISE['exp']
    } else if (value == 2) {
        inqCompanyData = PERSONAL_INFO_CATEGORY_WISE['equif']
    } else if (value == 3) {
        inqCompanyData = PERSONAL_INFO_CATEGORY_WISE['trans']
    } else if (value == 4) {
        inqCompanyData = ALL_PERSONAL_INFO
    }


    setPersonalInfoList(inqCompanyData);
}

function setInquryList(inquiries_keydate, inquiries_keyname) {
    $('#rtg-inqury-list ul').empty();
    $('p.multiSel').html('');
    $('.choose-dest').show();
    if (inquiry_info_selected_items.length > 0) {
       // $('.choose-dest').hide();
    }

    $.each(inquiries_keydate, function(key, value) {
        
        var checked = "";

        if ($.inArray(key, inquiry_info_selected_items) !== -1) {
            checked = "";
        }

        var current_html = '<li>'
        current_html += '<input value="'+key+'" data-name="' + inquiries_keyname[key] + '" data-date="' + value + '" data-inq_negative="1" onclick="getRTGOption(this);" type="checkbox" ' + checked + '> '
        current_html += inquiries_keyname[key]
        current_html += '</li>'
        $('#rtg-inqury-list ul').append(current_html);
    })
}

function setlatepaysList(latepayslist) {
    $('#rtg-latepays-list ul').empty();
    $('p.multiSel').html('');
    $('.choose-dest').show();
    if (late_pays_info_selected_items.length > 0) {
        //$('.choose-dest').hide();
    }
    $.each(latepayslist, function(key, value) {
        var checked = "";

        if ($.inArray(key, late_pays_info_selected_items) !== -1) {
            checked = "";
        }
        var current_html = '<li>'
        current_html += '<input value="' + key + '" data-bank="1" data-name="' + value + '" onclick="getRTGOption(this);" type="checkbox" ' + checked + '> '
        current_html += value
        current_html += '</li>'
        $('#rtg-latepays-list ul').append(current_html);
    })
}

function setNegativeCreditorList(negativeList) {
    $('#rtg-negative-creditor-list ul').empty();
    $('p.multiSel').html('');
    $('.choose-dest').show();
    $.each(negativeList, function(key, value) {
        var current_html = '<li>'
        current_html += '<input value="' + key + '" data-neg_creditor="1" data-name="' + value + '" onclick="getRTGOption(this);" type="checkbox"> '
        current_html += value
        current_html += '</li>'
        $('#rtg-negative-creditor-list ul').append(current_html);
    })
}


//function setNegativeCreditorNameList(negativeList) {
//    $('#rtg-creditor-name-list ul').empty();
//    $('p.multiSel').html('');
//    $('.choose-dest').show();
//    $.each(negativeList, function(key, value) {
//        var current_html = '<li>'
//        current_html += '<input value="' + key + '" data-neg_creditor_name="1" data-name="' + value + '" onclick="getRTGOption(this);" type="checkbox"> '
//        current_html += value
//        current_html += '</li>'
//        $('#rtg-creditor-name-list ul').append(current_html);
//    })
//}

function setNegativeCreditorNameList(negativeList) {
    $('#rtg-creditor-name-list ul').empty();
    $('p.multiSel').html('');
    $('.choose-dest').show();
    $.each(negativeList, function(key, value) {
        var current_html = '<li>'
        current_html += '<input value="' + key + '" data-neg_creditor_name="1" data-name="' + value + '" onclick="getRTGOption(this);" type="checkbox"> '
        current_html += value
        current_html += '</li>'
        $('#rtg-creditor-name-list ul').append(current_html);
    })
}

function setNegativeCreditorAccountOnlyList(negativeList) {
    $('#rtg-creditor-account-list ul').empty();
    $('p.multiSel').html('');
    $('.choose-dest').show();
    $.each(negativeList, function(key, value) {
        var current_html = '<li>'
        current_html += '<input value="' + key + '" data-neg_creditor_account="1" data-name="' + value + '" onclick="getRTGOption(this);" type="checkbox"> '
        current_html += value
        current_html += '</li>'
        $('#rtg-creditor-account-list ul').append(current_html);
    })
}

function setCreditorAccountList(negativeList) {
    $('#rtg-creditor-account-list ul').empty();
    $('p.multiSel').html('');
    $('.choose-dest').show();
    $.each(negativeList, function(key, value) {
        var current_html = '<li>'
        current_html += '<input value="' + key + '" data-creditor_account="1" data-name="' + value + '" onclick="getRTGOption(this);" type="checkbox"> '
        current_html += value
        current_html += '</li>'
        $('#rtg-creditor-account-list ul').append(current_html);
    })
}

function setLatepaysCreditorList(negativeList) {
    $('#rtg-latepays-creditor-list ul').empty();
    $('p.multiSel').html('');
    $('.choose-dest').show();

    $.each(negativeList, function(key, value) {



        var current_html = '<li>'
        current_html += '<input value="' + key + '" data-latepays_creditor="1" data-name="' + value + '" onclick="getRTGOption(this);" type="checkbox" > '
        current_html += value
        current_html += '</li>'
        $('#rtg-latepays-creditor-list ul').append(current_html);
    })
}

function setNegativeList(negativeList) {
    $('#rtg-negative-list ul').empty();
    //$('p.multiSel').html('');
    $('.choose-dest').show();
    if (negative_info_selected_items.length > 0) {
        $('.choose-dest').hide();
    }
    $.each(negativeList, function(key, value) {

        var checked = "";

        if ($.inArray(key, negative_info_selected_items) !== -1) {
            checked = "checked";
        }

        var current_html = '<li>'
        current_html += '<input value="' + key + '" data-negative="1" data-name="' + value + '" onclick="getRTGOption(this);" type="checkbox" ' + checked + '> '
        current_html += value
        current_html += '</li>'
        $('#rtg-negative-list ul').append(current_html);
    })
}


function setPublicRecordList(publicrecordlist) {
    $('#rtg-publicrecord-list ul').empty();
    $('p.multiSel').html('');
    $('.choose-dest').show();
    if (public_info_selected_items.length > 0) {
       // $('.choose-dest').hide();
    }
    $.each(publicrecordlist, function(key, value) {
        var checked = "";

        if ($.inArray(key, public_info_selected_items) !== -1) {
            checked = "";
        }
        var current_html = '<li>'
        current_html += '<input value="' + key + '" data-public="1" onclick="getRTGOption(this);" type="checkbox" ' + checked + '> '
        current_html += value.key
        current_html += '</li>'
        $('#rtg-publicrecord-list ul').append(current_html);
    })
}

function setPublicRecordCreditorList(publicrecordlist) {
    $('#rtg-publicrecord-creditor-list ul').empty();
    $('p.multiSel').html('');
    $('.choose-dest').show();
    if (public_info_selected_items.length > 0) {
       // $('.choose-dest').hide();
    }
    $.each(publicrecordlist, function(key, value) {
        var checked = "";

        if ($.inArray(key, public_info_selected_items) !== -1) {
            checked = "";
        }
        var current_html = '<li>'
        current_html += '<input value="' + key + '" data-public_creditor="1" onclick="getRTGOption(this);" type="checkbox" ' + checked + '> '
        current_html += value.key
        current_html += '</li>'
        if(value.key.toLowerCase() == "court-1"){
            $('#rtg-publicrecord-creditor-list ul').append(current_html);
        }
    })
}


function setPersonalInfoList(personalinfolist) {

    $('#rtg-personal-info-list ul').empty();

    $('.choose-dest').show();
    if (personal_info_selected_items.length > 0) {
        $('.choose-dest').hide();
    }


    $.each(personalinfolist, function(key, value) {
        var checked = "";

        if ($.inArray(key, personal_info_selected_items) !== -1) {
            checked = "checked";
        }
        var current_html = '<li>'
        current_html += '<input value="' + key + '" data-personal="1" onclick="getRTGOption(this);" type="checkbox" ' + checked + '> '
        current_html += value
        current_html += '</li>'
        $('#rtg-personal-info-list ul').append(current_html);
    })
}

function setInquriesCreditorList(inquiries_keydate, inquiries_keyname) {
    $('#rtg-inquiries-creditor-list ul').empty();
    $('p.multiSel').html('');
    $('.choose-dest').show();
    $.each(inquiries_keydate, function(key, value) {
        if (INQ_WITH_ADDRESS[key]) {
            var current_html = '<li>'
            current_html += '<input value="' + key + '" data-name="' + inquiries_keyname[key] + '" data-date="' + value + '" data-inq_creditor="1" onclick="getRTGOption(this);" type="checkbox"> '
            current_html += inquiries_keyname[key]
            current_html += '</li>'
            $('#rtg-inquiries-creditor-list ul').append(current_html);
        }
    })
}

// common methods for all popup

function chooseDropDown(elem) {
    event.preventDefault();

    $(elem).parent().parent().parent().children('dd').children('div.mutliSelect').children('ul').slideToggle('fast');

    $(".dropdown-x dd ul").hide();
    $(elem).parent().parent().next('dd').children('div').children('ul').show();
    ////console.log();
}

function getRTGOption(elem, isTextArea = true) {
    var isNotSaved = $('input[name=isNotSaved]').val();

    if (isNotSaved == 1) {
        getallAccLength(elem);
    }

    var value = $(elem).val();
    var flag = false;
    var title = $(elem).parent().text();
    var multiSelP = $(elem).parent().parent().parent().parent().prev('dt').children('div').children('a').children('p.multiSel');
    //alert(title);
    var html = '<span class="hida" title="' + title + '">' + title + '</span>';
    $(elem).parents('dl').next('span.help-block').hide();
    if ($(elem).is(':checked')) {

        multiSelP.prev("span").hide();
        multiSelP.next("span").hide();
        multiSelP.append(html);


        if (value == 73 || value == 72) {
            $(elem).parents('dl').next('span.help-block').show();
        }



        if (value == -1) {
            flag = true;
            $(elem).parent().parent().parent().parent().prev('dt').parent().next('.help-block').show();
        }



    } else {
        
        
        //
        multiSelP.children('span[title="' + title + '"]').remove();
        //console.log('multiSelP',multiSelP,title);
    }

    if (!multiSelP.children("span").is(':visible')) {
        //alert(12);
        multiSelP.prev("span").show();
    }

    if (value != -1) {
        //alert(12);
        //$(elem).parent().parent().parent().parent().prev('dt').parent().next('.help-block').hide();
    }
    if (isTextArea && $(elem).prop('checked')) {
        var isItemBank = $(elem).data('bank');
        if (isItemBank) {
            var name_texarea_with_account = $('input[name=latepays_textarea_name]').val().split('|');
            var name_texarea = name_texarea_with_account[0];
            var account_tag_name = name_texarea_with_account[1];

            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                var old_value = $('textarea[name="' + name_texarea + '"]').val();
            } else {
                var old_value = $('input[name="' + name_texarea + '"]').val();
            }
            var bankInfo = ALL_BANK_ASSOC[$(elem).val()];
            var bankName = $(elem).data('name');
            
            var companyType = $('select[name=item_latePays_1]').val();
            var account_no = getAccountFromBankInfo(bankInfo, "", companyType);
            account_no = $.trim(account_no);

            var valueString = createBankStringFromObj(bankInfo, bankName, companyType);

            if ($('input[name="' + account_tag_name + '"]').length > 0 && account_no) {
                $('input[name="' + account_tag_name + '"]').val(account_no);
                valueString = valueString.replace(account_no, "");
            }

            if (old_value) {
                old_value += "\n\n ";
            } else {
                old_value = "";
            }
            var finalValue = old_value + valueString;



            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                $('textarea[name="' + name_texarea + '"]').val(finalValue);
            } else {
                $('input[name="' + name_texarea + '"]').val(finalValue);
            }
        }

        var isItemBank = $(elem).data('negative');
        
        if (isItemBank) {

            var name_texarea_with_account = $('input[name=negative_textarea_name]').val().split('|');
            var name_texarea = name_texarea_with_account[0];
            var account_tag_name = name_texarea_with_account[1];

            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                var old_value = $('textarea[name="' + name_texarea + '"]').val();
            } else {
                var old_value = $('input[name="' + name_texarea + '"]').val();
            }
            var bankInfo = ALL_BANK_ASSOC[$(elem).val()];

            var bankName = $(elem).data('name');
            bankName = removeKeyIndex(bankName);
            var companyType = $('select[name=item_negative_1]').val();
            var valueString = createBankStringFromObj(bankInfo, bankName, companyType);
            if (companyType == 4 && $('input[name="' + account_tag_name + '"]').length > 0) {

                var trans_acc = getAccountFromBankInfo(bankInfo, "", 3);
                trans_acc = $.trim(trans_acc);
                var exp_acc = getAccountFromBankInfo(bankInfo, "", 1);
                exp_acc = $.trim(exp_acc);
                var equif_acc = getAccountFromBankInfo(bankInfo, "", 2);
                equif_acc = $.trim(equif_acc);

                //                var valueString3 = createBankStringFromObj(bankInfo, bankName, 3);
                //                var valueString1 = createBankStringFromObj(bankInfo, bankName, 1);
                //                var valueString2 = createBankStringFromObj(bankInfo, bankName, 2);
                //                
                valueString = valueString.replace(trans_acc, "");
                valueString = valueString.replace(exp_acc, "");
                valueString = valueString.replace(equif_acc, "");

                var acc_no_string = "";

                if (trans_acc) {
                    acc_no_string = trans_acc;
                }

                if (exp_acc) {
                    if (acc_no_string) {
                        acc_no_string += " " + exp_acc
                    } else {
                        acc_no_string = exp_acc;
                    }

                }

                if (equif_acc) {
                    if (acc_no_string) {
                        acc_no_string += " " + equif_acc;
                    } else {
                        acc_no_string = equif_acc;
                    }

                }

                acc_no_string = getAccountFromBankInfo(bankInfo, "", 4);

                if ($('input[name="' + account_tag_name + '"]').length > 0 && acc_no_string) {
                    $('input[name="' + account_tag_name + '"]').val(acc_no_string);
                }

            } else {
                var account_no = getAccountFromBankInfo(bankInfo, "", companyType);
                account_no = $.trim(account_no);
                if ($('input[name="' + account_tag_name + '"]').length > 0 && account_no) {
                    $('input[name="' + account_tag_name + '"]').val(account_no);
                    valueString = valueString.replace(account_no, "");
                }
            }

            if (old_value) {
                old_value += "\n\n ";
            } else {
                old_value = "";
            }

            var finalValue = old_value + valueString;

            if (finalValue) {
                negative_info_selected_items = array_manage(elem, negative_info_selected_items, $(elem).val())
            }
            
            if(FORM_ID == 62){
                if(companyType == 4){
                    var temp_acc_no_string = getAccountFromBankInfo(bankInfo, "", 4);
                    temp_acc_no_string = temp_acc_no_string.split('\n');
                    
                    var acc_array_unique = array_unique_values(temp_acc_no_string);
                    var unique_string = "";
                    for(var i in acc_array_unique){
                        if(acc_array_unique[i]){
                            if(unique_string){
                                unique_string += ", "+acc_array_unique[i]
                            }else{
                                unique_string = acc_array_unique[i]
                            }
                        }
                    }
                    finalValue = specialStringPutForAAA(bankName,unique_string);
                } else {
                    finalValue = specialStringPutForAAA(bankName,account_no);
                }
            }
            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                $('textarea[name="' + name_texarea + '"]').val(finalValue);
            } else {
                $('input[name="' + name_texarea + '"]').val(finalValue);

            }

        }

        var isItemBank = $(elem).data('creditor_account');
        if (isItemBank) {

            var name_texarea_with_account = $('input[name=creditor_account_textarea_name]').val().split('|');
            var name_texarea = name_texarea_with_account[0];
            var account_tag_name = name_texarea_with_account[1];
            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                var old_value = $('textarea[name="' + name_texarea + '"]').val();
            } else {
                var old_value = $('input[name="' + name_texarea + '"]').val();
            }
            var bankInfo = ALL_BANK_ASSOC[$(elem).val()];

            var bankName = $(elem).data('name');
            var companyType = $('select[name=item_creditor_account_info_1]').val();
            var valueString = "";
            if (companyType == 4) {

                var trans_acc = getAccountFromBankInfo(bankInfo, "", 3);
                trans_acc = $.trim(trans_acc);
                var exp_acc = getAccountFromBankInfo(bankInfo, "", 1);
                exp_acc = $.trim(exp_acc);
                var equif_acc = getAccountFromBankInfo(bankInfo, "", 2);
                equif_acc = $.trim(equif_acc);

                //                var valueString3 = createBankStringFromObj(bankInfo, bankName, 3);
                //                var valueString1 = createBankStringFromObj(bankInfo, bankName, 1);
                //                var valueString2 = createBankStringFromObj(bankInfo, bankName, 2);
                //                
//                valueString = valueString.replace(trans_acc, "");
//                valueString = valueString.replace(exp_acc, "");
//                valueString = valueString.replace(equif_acc, "");

                var acc_no_string = "";
                var final_obj = {};
                if (trans_acc) {
                    acc_no_string = bankName+"\n"+trans_acc;
                }
                final_obj[trans_acc] = acc_no_string;
                if (exp_acc) {
//                    if (acc_no_string) {
//                        acc_no_string += "\n\n" + bankName+": "+exp_acc
//                    } else {
//                        acc_no_string = bankName+"\n"+exp_acc;
//                    }
                acc_no_string = bankName+"\n"+exp_acc;

                }
                
                final_obj[exp_acc] = acc_no_string;
                
                if (equif_acc) {
//                    if (acc_no_string) {
//                        acc_no_string += "\n\n" + bankName+": "+equif_acc;
//                    } else {
//                        acc_no_string = bankName+"\n"+equif_acc;
//                    }
                    acc_no_string = bankName+"\n"+equif_acc;
                }
                
                final_obj[equif_acc] = acc_no_string;
                
                acc_no_string = "";
                $.each(final_obj,function(index,value){
                    if(value && index){
                        if(acc_no_string){
                            acc_no_string += "\n\n"+value
                        }else{
                            acc_no_string = value
                        }
                    }
                })
                valueString = acc_no_string;
                //acc_no_string = getAccountFromBankInfo(bankInfo, "", 4);

                
                

            } else {
                var account_no = getAccountFromBankInfo(bankInfo, "", companyType);
                account_no = $.trim(account_no);
                valueString = bankName+"\n"+account_no;
                //console.log('valueString',valueString);
            }







            if (old_value) {
                old_value += "\n\n";
            } else {
                old_value = "";
            }

            var finalValue = old_value+valueString;

            if (finalValue) {
                //negative_info_selected_items = array_manage(elem, negative_info_selected_items, $(elem).val())
            }

            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                $('textarea[name="' + name_texarea + '"]').val(finalValue);
            } else {
                $('input[name="' + name_texarea + '"]').val(finalValue);

            }

        }

        var isItemBank = $(elem).data('neg_creditor_name');
        if (isItemBank) {

            var name_texarea_with_account = $('input[name=creditor_name_textarea]').val().split('|');
            var name_texarea = name_texarea_with_account[0];
            var account_tag_name = name_texarea_with_account[1];
            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                var old_value = $('textarea[name="' + name_texarea + '"]').val();
            } else {
                var old_value = $('input[name="' + name_texarea + '"]').val();
            }
            var bankInfo = ALL_BANK_ASSOC[$(elem).val()];

            var bankName = $(elem).data('name');
            bankName = removeKeyIndex(bankName);
            var companyType = $('select[name=creditor_name_1]').val();
            var valueString = "";
            var valueAccNumString = "";
            if (companyType == 4) {

                var trans_acc = getAccountFromBankInfo(bankInfo, "", 3);
                trans_acc = $.trim(trans_acc);
                var exp_acc = getAccountFromBankInfo(bankInfo, "", 1);
                exp_acc = $.trim(exp_acc);
                var equif_acc = getAccountFromBankInfo(bankInfo, "", 2);
                equif_acc = $.trim(equif_acc);

                //                var valueString3 = createBankStringFromObj(bankInfo, bankName, 3);
                //                var valueString1 = createBankStringFromObj(bankInfo, bankName, 1);
                //                var valueString2 = createBankStringFromObj(bankInfo, bankName, 2);
                //                
//                valueString = valueString.replace(trans_acc, "");
//                valueString = valueString.replace(exp_acc, "");
//                valueString = valueString.replace(equif_acc, "");

                var acc_no_string = "";
                var account_number_string = "";
                var final_obj = {};
                var final_acc_obj = {};
                if (trans_acc) {
                    acc_no_string = bankName;
                    account_number_string = trans_acc;
                }
                
                final_obj[trans_acc] = acc_no_string;
                final_acc_obj[trans_acc] = account_number_string;
                if (exp_acc) {
//                    if (acc_no_string) {
//                        acc_no_string += "\n\n" + bankName+": "+exp_acc
//                    } else {
//                        acc_no_string = bankName+"\n"+exp_acc;
//                    }
                acc_no_string = bankName;
                account_number_string = exp_acc;
                }
                
                final_obj[exp_acc] = acc_no_string;
                final_acc_obj[exp_acc] = account_number_string;
                if (equif_acc) {
//                    if (acc_no_string) {
//                        acc_no_string += "\n\n" + bankName+": "+equif_acc;
//                    } else {
//                        acc_no_string = bankName+"\n"+equif_acc;
//                    }
                    acc_no_string = bankName;
                    account_number_string = equif_acc;
                }
                
                final_obj[equif_acc] = acc_no_string;
                final_acc_obj[equif_acc] = account_number_string;
                
                acc_no_string = "";
                account_number_string = "";
                
                $.each(final_obj,function(index,value){
                    if(value && index){
                        if(acc_no_string){
                            acc_no_string += "\n\n"+value
                        }else{
                            acc_no_string = value
                        }
                    }
                })
                
                $.each(final_acc_obj,function(index,value){
                    if(value && index){
                        if(account_number_string){
                            account_number_string += "\n\n"+value
                        }else{
                            account_number_string = value
                        }
                    }
                });
                
                valueString = acc_no_string;
                valueAccNumString = account_number_string;
                //acc_no_string = getAccountFromBankInfo(bankInfo, "", 4);

            } else {
                var account_no = getAccountFromBankInfo(bankInfo, "", companyType);
                account_no = $.trim(account_no);
                valueString = bankName;
                valueAccNumString = account_no;
                //console.log('valueString',valueString);
            }


            if (old_value) {
                old_value += "\n\n";
            } else {
                old_value = "";
            }
             var finalValue = old_value + valueString;
             
            var old_acc_value = "";
            
            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                var old_value_name_tag = $('textarea[name="' + name_texarea + '"]');
            } else {
                var old_value_name_tag = $('input[name="' + name_texarea + '"]');
            }
            
            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                $('textarea[name="' + name_texarea + '"]').val(finalValue);
            } else {
                $('input[name="' + name_texarea + '"]').val(finalValue);

            }
            
            var acc_tag = $('.negative-modal-area');
            
            //console.log($(this),acc_tag.length);
            acc_tag.each(function(){
                var acc_textarea_only = $(this).find('.creditor-account-only');
                if(acc_textarea_only.length > 0){
                    var current_value = "";
                    if(acc_textarea_only.val()){
                        current_value = acc_textarea_only.val()
                    }
                    
                    old_acc_value = current_value;
                    
                    if (old_acc_value) {
                        old_acc_value += "\n\n";
                    } else {
                        old_acc_value = current_value;
                    }

                    var finalAccValue = old_acc_value + valueAccNumString;
                    //alert(finalAccValue);
                    acc_textarea_only.val(finalAccValue);
                    
                }
            })
            
            

        }

        var isItemBank = $(elem).data('neg_creditor_account');
        if (isItemBank) {

            var name_texarea_with_account = $('input[name=creditor_account_textarea]').val().split('|');
            var name_texarea = name_texarea_with_account[0];
            var account_tag_name = name_texarea_with_account[1];
            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                var old_value = $('textarea[name="' + name_texarea + '"]').val();
            } else {
                var old_value = $('input[name="' + name_texarea + '"]').val();
            }
            var bankInfo = ALL_BANK_ASSOC[$(elem).val()];

            var bankName = $(elem).data('name');
            var companyType = $('select[name=creditor_account_1]').val();
            var valueString = "";
            if (companyType == 4) {

                var trans_acc = getAccountFromBankInfo(bankInfo, "", 3);
                trans_acc = $.trim(trans_acc);
                var exp_acc = getAccountFromBankInfo(bankInfo, "", 1);
                exp_acc = $.trim(exp_acc);
                var equif_acc = getAccountFromBankInfo(bankInfo, "", 2);
                equif_acc = $.trim(equif_acc);

                //                var valueString3 = createBankStringFromObj(bankInfo, bankName, 3);
                //                var valueString1 = createBankStringFromObj(bankInfo, bankName, 1);
                //                var valueString2 = createBankStringFromObj(bankInfo, bankName, 2);
                //                
//                valueString = valueString.replace(trans_acc, "");
//                valueString = valueString.replace(exp_acc, "");
//                valueString = valueString.replace(equif_acc, "");

                var acc_no_string = "";
                var final_obj = {};
                if (trans_acc) {
                    acc_no_string = trans_acc;
                }
                
                final_obj[trans_acc] = acc_no_string;
                if (exp_acc) {
//                    if (acc_no_string) {
//                        acc_no_string += "\n\n" + bankName+": "+exp_acc
//                    } else {
//                        acc_no_string = bankName+"\n"+exp_acc;
//                    }
                acc_no_string = exp_acc;

                }
                
                final_obj[exp_acc] = acc_no_string;
                
                if (equif_acc) {
//                    if (acc_no_string) {
//                        acc_no_string += "\n\n" + bankName+": "+equif_acc;
//                    } else {
//                        acc_no_string = bankName+"\n"+equif_acc;
//                    }
                    acc_no_string = equif_acc;
                }
                
                final_obj[equif_acc] = acc_no_string;
                
                acc_no_string = "";
                $.each(final_obj,function(index,value){
                    if(value && index){
                        if(acc_no_string){
                            acc_no_string += "\n\n"+value
                        }else{
                            acc_no_string = value
                        }
                    }
                })
                valueString = acc_no_string;
                //acc_no_string = getAccountFromBankInfo(bankInfo, "", 4);

                
                

            } else {
                var account_no = getAccountFromBankInfo(bankInfo, "", companyType);
                account_no = $.trim(account_no);
                valueString = account_no;
                //console.log('valueString',valueString);
            }


            if (old_value) {
                old_value += "\n\n";
            } else {
                old_value = "";
            }

            var finalValue = old_value+valueString;

            if (finalValue) {
                //negative_info_selected_items = array_manage(elem, negative_info_selected_items, $(elem).val())
            }

            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                $('textarea[name="' + name_texarea + '"]').val(finalValue);
            } else {
                $('input[name="' + name_texarea + '"]').val(finalValue);

            }

        }
        
        var isInqItemNegetive = $(elem).data('inq_negative');
        if (isInqItemNegetive) {
            var name_texarea_with_date = $('input[name=inq_textarea_name]').val()
            var split_array = name_texarea_with_date.split('|');
            name_texarea = split_array[0];
            var creditor_date_name = split_array[1];
            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                var old_value = $('textarea[name="' + name_texarea + '"]').val();
            } else {
                var old_value = $('input[name="' + name_texarea + '"]').val();
                var old_value1 = $('input[name="' + creditor_date_name + '"]').val();
            }

            var value1 = $(elem).data('name')
            var value2 = $(elem).data('date')
            if (old_value) {
                old_value += "\n\n ";
            } else {
                old_value = "";
            }

            if (old_value1) {
                old_value1 += "\n\n ";
            } else {
                old_value1 = "";
            }

            var finalValue = old_value + value1 + "\n " + value2;
            if ($('input[name="' + creditor_date_name + '"]').length > 0) {
                finalValue = value1 + "\n ";
                var finalValue1 = value2 + "\n ";
                if (finalValue1) {
                    $('input[name="' + creditor_date_name + '"]').val(finalValue1);
                }
            }
            
            if (finalValue) {
                inquiry_info_selected_items = array_manage(elem, inquiry_info_selected_items, $(elem).val())
            }
            
            if(FORM_ID == 62){
                finalValue = specialStringPutForAAA(value1,value2);
            }
            
            if ($('textarea[name="' + name_texarea + '"]').length > 0) {
                $('textarea[name="' + name_texarea + '"]').val(finalValue);
            } else {
                $('input[name="' + name_texarea + '"]').val(finalValue);

            }

            

        }

        var isPublicItemNegetive = $(elem).data('public');
        if (isPublicItemNegetive) {
            var name_texarea = $('input[name=publicrecord_textarea_name]').val()
            var old_value = $('textarea[name="' + name_texarea + '"]').val();
            var companyType = $('select[name=item_publicrecord_1]').val();
            var pb_id = $(elem).val();
            var pbInfo = MAIN_PUBLIC_RECORDS[pb_id];
            var current_value = createPublicRecordStringFromObj(pbInfo, companyType)
            if (old_value) {
                old_value += "\n";
            } else {
                old_value = "";
            }

            if (old_value + current_value) {
                public_info_selected_items = array_manage(elem, public_info_selected_items, $(elem).val())
            }
            $('textarea[name="' + name_texarea + '"]').val(old_value + current_value);
        }
        
        var isPublicItemNegetive = $(elem).data('public_creditor');
        if (isPublicItemNegetive) {
            var name_texarea = $('input[name=publicrecord_creditor_textarea_name]').val()
            var old_value = $('textarea[name="' + name_texarea + '"]').val();
            var companyType = $('select[name=item_publicrecord_creditor_1]').val();
            var pb_id = $(elem).val();
            var pbInfo = PUBLIC_RECORD_ADDRESS_LIST[pb_id];
            var current_value = "";
            if(pbInfo){
                if(pbInfo.creditor_name && pbInfo.creaditor_address){
                    current_value = pbInfo.creditor_name+", "+pbInfo.creaditor_address;
                }
            }
            if (old_value) {
                old_value += "\n ";
            } else {
                old_value = "";
            }

           
            $('textarea[name="' + name_texarea + '"]').val(old_value + current_value);
        }

        // personal info
        var isPublicItemNegetive = $(elem).data('personal');
        if (isPublicItemNegetive) {
            
            var name_texarea = $('input[name=personal_info_textarea_name]').val()
            var old_value = $('textarea[name="' + name_texarea + '"]').val();
            var companyType = $('select[name=item_personal_info_1]').val();
            var pb_id = $(elem).val();
            var personalInfo = PERSONAL_INFO_ALL_CATEGORY[pb_id];
            var pi_info_assoc = PERSONAL_INFO_CATEGORY_WISE_ASSOC

            var current_value = "";
            if (personalInfo.value) {
                current_value = personalInfo.data_key
            }
            if (old_value) {
                old_value += "\n\n ";
            } else {
                old_value = "";
            }

            if (companyType == 4) {
                
                current_value = "";
                var data_key_name = personalInfo.data_key;
                
                if (pi_info_assoc.trans[pb_id] && pi_info_assoc.trans[pb_id].value) {
                    current_value = pi_info_assoc.trans[pb_id].value;
                }
                 
                if (pi_info_assoc.exp[pb_id] && pi_info_assoc.exp[pb_id].value) {
                    if (current_value) {
                        current_value += "\n" + pi_info_assoc.exp[pb_id].value
                    } else {
                        current_value = pi_info_assoc.exp[pb_id].value;
                    }
                }
                 
                if (pi_info_assoc.equif[pb_id] && pi_info_assoc.equif[pb_id].value) {
                    if (current_value) {
                        current_value += "\n" + pi_info_assoc.equif[pb_id].value
                    } else {
                        current_value = pi_info_assoc.equif[pb_id].value;
                    }
                }
                
                
                if (data_key_name) {
                    current_value = data_key_name + ":\n" + current_value;
                }
            } else {

                if (companyType == 3) {
                    current_value = getCategoryWisePersonalInfo(pi_info_assoc.trans, pb_id, current_value)

                } else if (companyType == 1) {
                    current_value = getCategoryWisePersonalInfo(pi_info_assoc.exp, pb_id, current_value)
                } else if (companyType == 2) {
                    current_value = getCategoryWisePersonalInfo(pi_info_assoc.equif, pb_id, current_value)
                }
            }

            if (old_value + current_value) {
                personal_info_selected_items = array_manage(elem, personal_info_selected_items, pb_id)
            }
            
            $('textarea[name="' + name_texarea + '"]').val(old_value + current_value);
        }

        var isPublicItemNegetive = $(elem).data('neg_creditor');
        if (isPublicItemNegetive) {
            var name_texarea = $('input[name=negative_creditor_textarea_name]').val()
            var old_value = $('textarea[name="' + name_texarea + '"]').val();
            var companyType = $('select[name=item_negative_creditor_info_1]').val();
            var pb_id = $(elem).val();
            var personalInfo = RTG_BANK_ASSOC[pb_id];
            var current_value = "";
            if (personalInfo) {
                var creditor_name = $(elem).data('name');
                creditor_name = removeKeyIndex(creditor_name);
                current_value = creditor_name
                if (personalInfo.value2)
                    var commaOrNewLine = ", ";
                    if(hasDfAddressApplicable()){
                        commaOrNewLine = ", ";
                    }
                    
                    if(personalInfo.value2)
                    current_value +=  commaOrNewLine+ personalInfo.value2
            }

            if (old_value) {
                old_value += "\n\n ";
            } else {
                old_value = "";
            }
            $('textarea[name="' + name_texarea + '"]').val(current_value);
        }

        var isPublicItemNegetive = $(elem).data('latepays_creditor');
        if (isPublicItemNegetive) {
            var name_texarea = $('input[name=latepays_creditor_textarea_name]').val()
            var old_value = $('textarea[name="' + name_texarea + '"]').val();
            var companyType = $('select[name=item_latepays_creditor_info_1]').val();
            var pb_id = $(elem).val();
            var personalInfo = RTG_BANK_ASSOC[pb_id];
            var current_value = "";
            if (personalInfo) {
                var creditor_name = $(elem).data('name');
                creditor_name = removeKeyIndex(creditor_name);
                current_value = creditor_name
                if (personalInfo.value2){
                        var commaOrNewLine = "\n ";
                        if(hasDfAddressApplicable()){
                            commaOrNewLine = ", ";
                        }
                        current_value += commaOrNewLine + personalInfo.value2
                    }
            }

            if (old_value) {
                old_value += "\n\n";
            } else {
                old_value = "";
            }
            $('textarea[name="' + name_texarea + '"]').val(current_value);
        }

        var isPublicItemNegetive = $(elem).data('inq_creditor');
        if (isPublicItemNegetive) {
            var name_texarea = $('input[name=inquiries_creditor_textarea_name]').val()
            var old_value = $('textarea[name="' + name_texarea + '"]').val();
            var companyType = $('select[name=item_inquiries_creditor_info_1]').val();
            var pb_id = $(elem).val();
            var personalInfo = INQ_WITH_ADDRESS[pb_id];
            var current_value = "";
            var creditor_name = $(elem).data('name');
            current_value = creditor_name.replace(/\s\s+/g, ' ');
            DF_CREDITOR_NAME = $.trim(current_value);
            if (personalInfo) {
                var curr_address = personalInfo.replace(/\s\s+/g, ' ');
                DF_CREDITOR_ADDRESS = curr_address;
                var commaOrNewLine = "\n ";
                if(hasDfAddressApplicable()){
                    commaOrNewLine = ", ";
                }
                current_value += commaOrNewLine + curr_address;
            }

            if (old_value) {
                old_value += "\n\n ";
            } else {
                old_value = "";
            }
            if(current_value){
                current_value = validateLetterStreamAddress(current_value)
            }
            $('textarea[name="' + name_texarea + '"]').val(current_value);
        }

    }else {
        //personal_info_selected_items
        var isPublicItemNegetive = $(elem).data('personal');
        if (isPublicItemNegetive) {
            var index = personal_info_selected_items.indexOf($(elem).val());
            if (index > -1) {
              personal_info_selected_items.splice(index, 1);
            }
        }else if($(elem).data('negative') || $(elem).data('creditor_account')){
            
             var index = negative_info_selected_items.indexOf($(elem).val());
            if (index > -1) {
              negative_info_selected_items.splice(index, 1);
            }
        }
        
    }
}

function createPublicRecordStringFromObj(pbInfo, companyType) {
    var finalString = "";
    if (companyType == 1) {
        if (pbInfo) {
            if (pbInfo.key && pbInfo.value1) {
                var key = removeKeyIndex(pbInfo.key);
                finalString = key + ":" + pbInfo.value1
            }
        }
    } else if (companyType == 2) {
        if (pbInfo) {
            if (pbInfo.key && pbInfo.value2) {
                var key = removeKeyIndex(pbInfo.key);
                finalString = key + ":" + pbInfo.value2
            }
        }
    } else if (companyType == 3) {
        if (pbInfo) {
            if (pbInfo.key && pbInfo.value3) {
                var key = removeKeyIndex(pbInfo.key);
                finalString = key + ":" + pbInfo.value3
            }
        }
    } else if (companyType == 4) {
        if (pbInfo) {
            if (pbInfo.key) {
                var key = removeKeyIndex(pbInfo.key);
                if (pbInfo.value3) {
                    finalString = key + ":" + pbInfo.value3
                } else if (pbInfo.value2) {
                    finalString = key + ":" + pbInfo.value2
                } else if (pbInfo.value1) {
                    finalString = key + ":" + pbInfo.value1
                }
            }
        }
    }

    return finalString;
}

function removeKeyIndex(bank_name) {
    var bankNameArray = bank_name.split('-');
    $.each(bankNameArray, function(i, value) {
        var index = value;

        if (index != null && index >= 1 && index <= 100) {
            bank_name = bank_name.replace("-" + index, "");
            return false;
        }
    })

    return bank_name;
}

function createBankStringFromObj(bankInfo, bankName, companyType) {

    var finalString = "";
    var accTypeString = "Account type: ";
    var accAllarray = [];
    if (bankName) {
        finalString = bankName;
    }
    var bank_name = bankName;
    bank_name = removeKeyIndex(bank_name);
    if (companyType == 1) {
        if (bankInfo.isJson == 1) {
            finalString = getExpNegativeString(bankInfo, accTypeString, finalString)
        } else {
            if (bankInfo.value5) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value5;
                } else {
                    finalString = bankInfo.value5;
                }
            }
        }
    } else if (companyType == 2) {

        if (bankInfo.isJson == 1) {
            finalString = getEquifNegativeString(bankInfo, accTypeString, finalString)
        } else {
            if (bankInfo.value6) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value6;
                } else {
                    finalString = bankInfo.value6;
                }
            }
        }

    } else if (companyType == 3) {

        if (bankInfo.isJson == 1) {

            finalString = getTransNegativeString(bankInfo, accTypeString, finalString)

        } else {
            if (bankInfo.value1) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value1;
                } else {
                    finalString = bankInfo.value1;
                }
            }
        }

    } else if (companyType == 4) {
        var final_obj = {};
        if (bankInfo.isJson && bankInfo.isJson == 1) {
            var final_string = "";
            // Transunion start
            finalString = getTransNegativeString(bankInfo, accTypeString, finalString)
                // Transunion end

            if (finalString) {
                final_obj[bankInfo.value1.account] = finalString;
            }

            // Experian start
            finalString = bank_name;

            finalString = getExpNegativeString(bankInfo, accTypeString, finalString)
            if (finalString) {
                final_obj[bankInfo.value5.account] = finalString;
            }
            // Experian end


            finalString = bank_name;

            // Equifax start

            finalString = getEquifNegativeString(bankInfo, accTypeString, finalString)

            if (finalString) {
                final_obj[bankInfo.value6.account] = finalString;
            }
            // Equifax end
            var temp_array = [];
            var finalString = "";
            $.each(final_obj, function(index, value) {
                if (value) {
                    if (finalString) {
                        finalString += "\n\n" + value;
                    } else {
                        finalString = value;
                    }
                }
            })

        } else {
            if (bankInfo.value1) {
                if (finalString) {
                    finalString += "\n\n " + bankInfo.value1;
                } else {
                    finalString = bankInfo.value1;
                }
            }

            if (bankInfo.value5) {
                if (finalString) {
                    finalString += "\n\n " + bankInfo.value5;
                } else {
                    finalString = bankInfo.value5;
                }
            }

            if (bankInfo.value6) {
                if (finalString) {
                    finalString += "\n\n " + bankInfo.value6;
                } else {
                    finalString = bankInfo.value6;
                }
            }
        }

    }


    return finalString;

}

function getAccountFromBankInfo(bankInfo, bankName, companyType) {
    var finalString = "";
    var accTypeString = "Account type: ";
    var accAllarray = [];
    if (bankName) {
        finalString = bankName;
    }
    var bank_name = bankName;
    if (companyType == 1) {
        if (bankInfo.isJson == 1) {
            if (bankInfo.value5) {
                if (bankInfo.value5.account) {
                    if (finalString) {
                        finalString += "\n " + bankInfo.value5.account;
                    } else {
                        finalString = bankInfo.value5.account;
                    }
                }


            }
        } else {
            if (bankInfo.value5) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value5;
                } else {
                    finalString = bankInfo.value5;
                }
            }
        }
    } else if (companyType == 2) {

        if (bankInfo.isJson == 1) {
            if (bankInfo.value6.account) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value6.account;
                } else {
                    finalString = bankInfo.value6.account;
                }
            }
        } else {
            if (bankInfo.value6) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value6;
                } else {
                    finalString = bankInfo.value6;
                }
            }
        }

    } else if (companyType == 3) {

        if (bankInfo.isJson == 1) {
            if (bankInfo.value1.account != null) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value1.account;
                } else {
                    finalString = bankInfo.value1.account;
                }
            }
        } else {
            if (bankInfo.value1) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value1;
                } else {
                    finalString = bankInfo.value1;
                }
            }
        }

    } else if (companyType == 4) {

        if (bankInfo.isJson && bankInfo.isJson == 1) {
            if (bankInfo.value1.account) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value1.account;
                } else {
                    finalString = bankInfo.value1.account;
                }
            }

            if (bankInfo.value5.account) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value5.account;
                } else {
                    finalString = bankInfo.value5.account;
                }
            }

            if (bankInfo.value6.account) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value6.account;
                } else {
                    finalString = bankInfo.value6.account;
                }
            }




        } else {
            if (bankInfo.value1) {
                if (finalString) {
                    finalString += "\n" + bankInfo.value1;
                } else {
                    finalString = bankInfo.value1;
                }
            }

            if (bankInfo.value5) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value5;
                } else {
                    finalString = bankInfo.value5;
                }
            }

            if (bankInfo.value6) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value6;
                } else {
                    finalString = bankInfo.value6;
                }
            }
        }

    }


    return finalString;

}

function getCreditorNameFromBankInfo(bankInfo, bankName, companyType) {
    var finalString = "";
    var accTypeString = "Account type: ";
    var accAllarray = [];
    if (bankName) {
        finalString = bankName;
    }
    var bank_name = bankName;
    if (companyType == 1) {
        if (bankInfo.isJson == 1) {
            if (bankInfo.value5) {
                if (bankInfo.value5.account) {
                    if (finalString) {
                        finalString += "\n " + bankInfo.value5.account;
                    } else {
                        finalString = bankInfo.value5.account;
                    }
                }


            }
        } else {
            if (bankInfo.value5) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value5;
                } else {
                    finalString = bankInfo.value5;
                }
            }
        }
    } else if (companyType == 2) {

        if (bankInfo.isJson == 1) {
            if (bankInfo.value6.account) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value6.account;
                } else {
                    finalString = bankInfo.value6.account;
                }
            }
        } else {
            if (bankInfo.value6) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value6;
                } else {
                    finalString = bankInfo.value6;
                }
            }
        }

    } else if (companyType == 3) {

        if (bankInfo.isJson == 1) {
            if (bankInfo.value1.account != null) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value1.account;
                } else {
                    finalString = bankInfo.value1.account;
                }
            }
        } else {
            if (bankInfo.value1) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value1;
                } else {
                    finalString = bankInfo.value1;
                }
            }
        }

    } else if (companyType == 4) {

        if (bankInfo.isJson && bankInfo.isJson == 1) {
            if (bankInfo.value1.account) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value1.account;
                } else {
                    finalString = bankInfo.value1.account;
                }
            }

            if (bankInfo.value5.account) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value5.account;
                } else {
                    finalString = bankInfo.value5.account;
                }
            }

            if (bankInfo.value6.account) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value6.account;
                } else {
                    finalString = bankInfo.value6.account;
                }
            }




        } else {
            if (bankInfo.value1) {
                if (finalString) {
                    finalString += "\n" + bankInfo.value1;
                } else {
                    finalString = bankInfo.value1;
                }
            }

            if (bankInfo.value5) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value5;
                } else {
                    finalString = bankInfo.value5;
                }
            }

            if (bankInfo.value6) {
                if (finalString) {
                    finalString += "\n " + bankInfo.value6;
                } else {
                    finalString = bankInfo.value6;
                }
            }
        }

    }


    return finalString;

}

$(document).bind('click', function(e) {
    //$('.client-html-close').click();


    var $clicked = $(e.target);

    if (!$clicked.hasClass('rtg-save-btn') && !$clicked.parents('#client-html').length) {
        $('.view-html').html('')
    }

    if (!$clicked.parents().hasClass("dropdown-x"))
        $(".dropdown-x dd ul").hide();
});

// common methods for all popup


function getTransNegativeString(bankInfo, accTypeString, finalString) {
    if (bankInfo.value1.account) {
        if (finalString) {
            finalString += "\n " + bankInfo.value1.account;
        } else {
            finalString = bankInfo.value1.account;
        }
    }
    if (bankInfo.value2) {
        if (finalString) {
            finalString += "\n " + bankInfo.value2;
        } else {
            finalString = bankInfo.value2;
        }
    }
    if (bankInfo.value3) {
        if (finalString) {
            finalString += "\n " + bankInfo.value3;
        } else {
            finalString = bankInfo.value3;
        }
    }
    if (bankInfo.value1.accType) {
        if (finalString) {
            finalString += "\n " + accTypeString + bankInfo.value1.accType;
        } else {
            finalString = accTypeString + bankInfo.value1.accType;
        }
    }

    return finalString;
}


function getExpNegativeString(bankInfo, accTypeString, finalString) {
    if (bankInfo.value5.account) {
        if (finalString) {
            finalString += "\n " + bankInfo.value5.account;
        } else {
            finalString = bankInfo.value5.account;
        }
    }

    if (bankInfo.value2) {
        if (finalString) {
            finalString += "\n " + bankInfo.value2;
        } else {
            finalString = bankInfo.value2;
        }
    }

    if (bankInfo.value3) {
        if (finalString) {
            finalString += "\n" + bankInfo.value3;
        } else {
            finalString = bankInfo.value3;
        }
    }

    if (bankInfo.value5.accType) {
        if (finalString) {
            finalString += "\n " + accTypeString + bankInfo.value5.accType;
        } else {
            finalString = accTypeString + bankInfo.value5.accType;
        }
    }

    return finalString;
}


function getEquifNegativeString(bankInfo, accTypeString, finalString) {
    if (bankInfo.value6.account) {
        if (finalString) {
            finalString += "\n " + bankInfo.value6.account;
        } else {
            finalString = bankInfo.value6.account;
        }
    }

    if (bankInfo.value2) {
        if (finalString) {
            finalString += "\n " + bankInfo.value2;
        } else {
            finalString = bankInfo.value2;
        }
    }

    if (bankInfo.value3) {
        if (finalString) {
            finalString += "\n " + bankInfo.value3;
        } else {
            finalString = bankInfo.value3;
        }
    }

    if (bankInfo.value6.accType) {
        if (finalString) {
            finalString += "\n " + accTypeString + bankInfo.value6.accType;
        } else {
            finalString = accTypeString + bankInfo.value6.accType;
        }
    }

    return finalString;
}


function getCategoryWisePersonalInfo(info, pb_id, data_key) {
    if (info) {
        if (info[pb_id].value) {
            data_key += ":\n" + info[pb_id].value;
        }
    }

    return data_key;
}


function array_unique(array) {
    return array.filter(function(el, index, arr) {
        return index === arr.indexOf(el);
    });
}

function array_unique_values(array) {
   var temp_array = [];
   if(array.length > 0){
       for(var i in array){
           array[i] = $.trim(array[i]);
           if(!($.inArray(array[i], temp_array) !== -1)){
               temp_array.push(array[i]);
           }
       }
   }else{
       temp_array = array;
   }
   
   return temp_array;
   
}


function array_manage(elem, array, index) {
    if ($(elem).prop('checked')) {
        array.push(index)
    } else {
        array = $.grep(array, function(value) {
            return value != index;
        });
    }

    return array;
}


function specialStringPutForAAA(creditor,dateOrAcc){
    
    creditor = creditor.trim();
    dateOrAcc = dateOrAcc.trim();
    
    if(!creditor || typeof creditor === "undefined"){
        creditor = "";
    }
    
    if(!dateOrAcc || typeof dateOrAcc === "undefined"){
        dateOrAcc = "";
    }
    
    var string = 'Alleged creditor of '+creditor+' displaying claimed account of '+dateOrAcc+' is not testimonial in documented certificate of fact to be entirely reported compliantly, truthfully, correctly, completely, timely, or adequately perfect as is REQUIRED DEMONSTRATED so item MUST BE DELETED now to be appropriately reported in lawful standing!';
    
    return string;
}


