window['cbHtml0']='';


 jQuery.expr[':'].icontains = function(a, i, m) {
    return jQuery(a).text().toUpperCase()
        .indexOf(m[3].toUpperCase()) >= 0;
  };

 var contact_addresses = {
    "BRCLYSBANKDE" :   "BARCLAYS",
    "CCB/CENTURY":     "COMENITYCAPITALBANK",
    "CAP1/BSTBY" :     "CAP1",
    "CREDITONEBANK" :     "CREDIT ONE",
    "CHRYSLERCAP" :     "CHRYSLER CAPITAL",
    "DISCOVERBA"   : "DISCOVER"
 };

 var creditor_aler_msg = '';
 var wave_html ='';

function epicreplaceAll(str, find, replace) {
    return str.replace(new RegExp(find, 'g'), replace);
}
 function scrollFunction() {
   if (document.body.scrollTop > 0 || document.documentElement.scrollTop > 0) {
     document.getElementById("top-btn").style.display = "block";
   } else {
     document.getElementById("top-btn").style.display = "none";
   }
 }
 function topFunction() {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
  }

 $('select[name=source_type]').change(function(){
      var url = "";
      if($(this).data('url')){
          url = $(this).data('url')
      }
      getClient(url);
  });

 function getClient(url){
        $('select[name=source_type]').attr('data-url',url);
        $('.generate-letter').attr('disabled',true);
        var val = $('#choose_work').val();
        if(val =='') return false;

        if (val > 0 ){
          window.location.href = url +'/'+ val;
        }
        else{
          var client_id = $('#client_id').val();

          $('#client_name').val($("#client_id option:selected").data('name'));
          $('input[name=client_email]').val($("#client_id option:selected").data('email'));
          if(client_id > 0 ){
           $('#resource-loader').show();
            var source_type = $('select[name=source_type]').val();
            $('#client-loader').show();
            $('.view-html').html('');
            $.ajax({
                type: "POST",
                data: {'client_id':client_id,'source_type':source_type,'action':'GET_CLIENT_INFO'},
                url: GET_CLIENT_INFO,
                success:function (data) {
                    $('#resource-loader').hide();
                    data = JSON.parse(data);

                    setClientValues(data);

                    $('.main-content').remove();
                    $('#btn-up-1').html('');

                    creditor_aler_msg ='';
                    item_count = -1;
                    addContent();
                    $('.view-html').html('');
                    //$('#toggle-dest-'+item_count).toggleClass("glyphicon-chevron-down").toggleClass("glyphicon-chevron-up");
                    $('#top-btn').show();
                    var source_type = $('select[name=source_type]').val();
                    if(data.report ){
                      data.report = remove_non_ascii(data.report);

                      $(".rpt_fullReport_header").eq(1).attr('id','PersonalInformation');// set id attribute on pinfo
                      data.report = data.report.replace(/<script[^>]*>(?:(?!<\/script>)[^])*<\/script>/g, "");
                      //$('input[name=current_html_content]').val(data.report);
                      $('input[name=current_html_content]').val('');
                      if(source_type == 3){
                        data.report = setSmartCreditUI(data.report);
                      }
                      $('.view-html').html(data.report);
                      $('.view-html').show()
                      $('#reportTop').removeClass('container');
                        $('#reportTop').removeClass('content');
                      $('.generate-letter').attr('disabled',false);
                      //var html = getDF();


                      /*$('.select-df').each(function(){
                         $(this).html(html);
                      })*/

                      $('.main-content').remove();
                      item_count = -1;

                      if(source_type == 3){
                          setSmartCreditCreditorContacts();
                      }

                        if (val == 'auto') {
                            if(source_type == 3){
                                SmartCreditAIpersonalInfo();
                                SmartCreditAIpublicInfo();
                                SmartCreditAIInquiry();
                                SmartCreditAIAccounts();
                            }else{
                               AIpersonalInfo();
                               AIpublicInfo();
                               AIInquiry();
                               AIAccounts();
                            }
                        } else if (val == 'pi') {
                            if(source_type == 3){
                                SmartCreditAIpersonalInfo();
                            }else{
                                AIpersonalInfo();
                            }
                        } else if (val == 'iq') {
                            if(source_type == 3){
                                SmartCreditAIInquiry();
                            }else{
                                AIInquiry();
                            }
                        } else if (val == 'pr') {
                            if(source_type == 3){
                                SmartCreditAIpublicInfo();
                            }else{
                                AIpublicInfo();
                            }
                        } else if (val == 'ac') {
                            if(source_type == 3){
                                SmartCreditAIAccounts();
                            }else{
                                AIAccounts();
                            }
                        } else {
                            addContent();
                        }
                    }

                    if(data.uploadmedia){
                        $('#att-img-area').html(data.uploadmedia);
                    }

                    $('#client-loader').hide();
                    $('#btn-up-1').children().last().remove();
                    if(creditor_aler_msg !='') alert('Please verify creditor address for following Content Boxes  '+creditor_aler_msg );
                    $('.dest-collapse').collapse();
                },
                error: function () {
                   $('#client-loader').hide();
                }
            });
          }

    }
 }

 function setSmartCreditUI(report){
    var link = '<meta charset="utf-8">' +
        '<link rel="stylesheet" type="text/css" href="https://www.smartcredit.com/resources/css/sc/pages/member/credit-report/3b/base.css" charset="utf-8"/>' ;
    var content = report;
    content = content.replace('<h1>undefined</h1>', '');
    content = epicreplaceAll(content, 'src="/resources/images/', 'src="https://www.smartcredit.com/resources/images/');
    content = link + content;
    return content;
    // return report;
 }

 function getClientEdit(elem){

     var client_id = $('#client_id').val();
     var client_email = $("#client_id option:selected").data('email');
     $('#client_name').val($("#client_id option:selected").data('name'));
     $('input[name=client_email]').val(client_email);

     var letter_id = $('input[name=letter_id]').val();
     var source_type = $('select[name=source_type]').val();
     var formData = {
       'action':'GET_LETTER_INFO',
       'letter_id':letter_id,
       'client_id':client_id
     };
     if(client_id > 0 ){
        $('#client-edit-loader').show();
     $.ajax({
         type: "POST",
         data: formData,
         url: GET_LETTER_INFO,
         success:function (data) {
             $('#client-edit-loader').hide();
             data = JSON.parse(data);
             console.log('data',data);

             setClientValues(data);
             $('.view-html').html('');
             if(data.report){
                 if(source_type == 3){
                   data.report =  setSmartCreditUI(data.report)
                 }

               $(".rpt_fullReport_header").eq(1).attr('id','PersonalInformation');
               data.report = remove_non_ascii(data.report);
               data.report = data.report.replace(/<script[^>]*>(?:(?!<\/script>)[^])*<\/script>/g, "");
               //$('input[name=current_html_content]').val(data.report);
               $('input[name=current_html_content]').val('');
               $('.view-html').html(data.report);


               var html = getDF();
               $('.select-df').each(function(){
                  $(this).html(html).show().val($(this).next().val()).prev().find(":checkbox").prop('checked',true);
               })

               $('.btn-top-html').each(function(){
                  $('#btn-up-1').prepend($(this).html());
                  $(this).remove();
               })
               //setLetterContentImage(data.client.letter_images);
             }
             $('.dest-collapse').collapse();
             /*var removeBtn = '<div class="col-md-4 "> <button class="btn btn-danger btn2-danger" onclick="removeContent('+item_count+')" type="button"> <span class="glyphicon glyphicon-minus" title="remove"></span>Remove this Content Box</button> </div>';
             $('.main-content').append(removeBtn);*/
             $('#client-loader').hide();


         },
         error: function () {
            $('#client-loader').hide();
         }
     });
    }
  }

 function setLetterContentImage(imagesObj){
      if(imagesObj){
          $.each(imagesObj,function(i,value){
              var ROOT_URL = JSON.parse(APP_SERVER_HOST_URL_JS);
              $('#letter_img_'+i).attr('src','');
              if(value){
                  var image_path = ROOT_URL+'epicvelocity/letters/'+value;
                $('#letter_img_'+i).attr('src',image_path);
              }
          })
      }

  }

 function setClientValues(data){
     $('#name').val('');
     $('#today').val('');
     $('#address').val('');
     $('#dob').val('');
     $('#cr_resource').val('');
     $('#ssn').val('');
     $('#email').val('');
     if(data.client){
         if(data?.client?.email){
             $('#email').val(data.client.email);
         }
        if(data.client.firstname){
           $('#name').val(data.client.firstname);
        }
        if(data.client.today)
       $('#today').val(data.client.today);
       if(data.client.json_address){
            $('#address').val(data.client.json_address);
       }else{
           $('#address').val(data.client.address+', '+data.client.city+', '+data.client.state+', '+data.client.zip);
       }
       if(data.client.dob){
           //var date = moment(data.client.dob).format('DD/MM/YYYY');
            $('#dob').val(data.client.dob);
        }
       if(data.client.ssn){
           var ssn = data.client.ssn;
           ssn = ssn.substr(ssn.length - 4);
           $('#ssn').val(ssn);
       }
       if(data.client.cr_data){
           $('#cr_resource').val(data.client.cr_data);
       }else{
        if(data.company_name && data.report_date){
            $('#cr_resource').val(data.company_name+' '+data.report_date);
        }
       }
       $('#div-img-bottom').show();
       $('#identity_proof_file').html(data.client.identity_proof_file);
       $('#ssn_proof_file').html(data.client.ssn_proof_file);
       $('#address_proof_file').html(data.client.address_proof_file);
       $('#other_file').html(data.client.other_file);

       $('#identity_proof_file1').val(data.client.identity_proof_file);
       $('#ssn_proof_file1').val(data.client.ssn_proof_file);
       $('#address_proof_file1').val(data.client.address_proof_file);
       $('#other_file1').val(data.client.other_file);

       $('#top-btn').show();//show top arrow button.
     }
 }
 //get client letters
 function getClientLetters(elem) {
     var id = $('#client_id').val();
     $('#letter-steps-btn').hide();
     if(id > 0){
        $('#client-ajax-loader').show();
        $('input[name=client_name]').val($(elem).data('name'));
        $.ajax({
          type: "GET",
          //url: "/lg/getClientLetters/"+id, //replace with your url
          url: GET_CLIENT_LETTER_URL+id,
          success: function(response) {
              $('#client-ajax-loader').hide();
              response = JSON.parse(response);

              var html = '<option value="">Please select</option><option value="0" title="New blank with user manually doing everything on own">New Blank</option>';
              html += '<option value="auto">New Auto ( ALL) </option><option value="pi"> New (Personal Information)</option><option value="iq">New (Inquiries)</option><option value="pr">New (Public records)</option><option value="ac">New (Accounts)</option>';
              if(0){
              var letters = response.letters;
                for (var key in letters) {
                    if (letters.hasOwnProperty(key)) {
                        var date = new Date(letters[key].updated_at);
                        date = date.toLocaleString('en-us', { month: 'long' }) +' '+ date.getDate() +' '+date.getFullYear();
                        var files = letters[key].num_of_files;
                        if(files==null) files= 0;
                        html +='<option value ="'+letters[key].id +'">'+date + '  ('+files +' files )</option>';
                    }
                }
            }

            $('#letter-steps-btn').show();

            $('#choose_work').html(html);
              var wave = parseInt(response.client);
              if(wave>5) wave = 5;
              $('#choose_wave').val(wave+1);
          }
      });
     }
 }

 function AIpublicInfo(){

  //if(item_count>0)

  var html = $('#PublicInformation >ng >div').each(function(){
    if($(this).hasClass('ng-hide')) return false;
    $('.publicrecord').remove();
    addContent();
    var header = $.trim($(this).find('.sub_header').first().text());
    if(header.length == 0){
         header = $.trim($(this).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 df_address ='';

    var table =  $(this).find('.sub_header').first().next();
    if(table.length == 0){
         table = $(this).first().next();
    }
    table.find('tr').each(function (i, el) {
      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=='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( typeof df_address =='undefined') df_address = getContactAdd(item_count,text2);
        if( typeof df_address =='undefined') df_address = getContactAdd(item_count,text3);
      }
      if(text1==text2 && text2==text3) {
        if(text1=='-'){
          tds.eq(1).html('<span class="bg-yellow">-</span>');
          tds.eq(2).html('<span class="bg-yellow">-</span>');
          tds.eq(3).html('<span class="bg-yellow">-</span>');
        }
      }

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


    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 img = '<div style="width:80%;" class="bg-white"><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 AIAccounts(){

  //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 ='';
    verbiage = '<p><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>';

    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 = 'AUDIT-Ew1L1D1-audit_40';
        }
    }
    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 = 'AUDIT-Ew1L1D1-audit_40';
        }
    }
    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 = 'AUDIT-Ew1L1D1-audit_40';
        }
    }
    // 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';

        }

        //var conditional_string = 'bankruptcy';
        if($(this).is(':icontains("bankruptcy")') ){
            negative = true;
            template = 'GEN-Ew1L1D1-bureau_1';
        }

         //console.log($(this).find("table.addr_hsrty").find('tr').length);

    }


    var is_find = false;
    $(this).find("table.addr_hsrty").find('tr').each(function(){
        is_find = false;
        $(this).find('td').each(function(){
           if($.trim($(this).text()) == "CO"){
                dtype = 7;
                template = 'COFF-Ew1L4D1-bureau_4';
                template_df = 'COFF-Ew1L3D1-df-creditor_3';
                is_find = true;
                negative = true;
                //return false;
            }

            if(!$.trim($(this).text())){
                negative = true;
            }
        });

        if(is_find){
           return false;
        }
    })

    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) {
        //console.log('current',$(this))
        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

    setCBValues(item_count,address,dtype,template,template_df,html);
    //$('#summernote-'+item_count).summernote('code',html); // insert content in text area.

  });

}

function getContactAdd(i,add){
  add = add.replace('BNK', 'BANK');
  var alert_html ='';
  var address = $('#select-df-'+i+' option:icontains("'+add+'")').val();

    if (typeof address === 'undefined') {
      if (/\s/.test(add)) {
         add = add.replace(/  +/g, ' ');
         var myStringArray = add.split(" ");
         alert_html = ','+ (i+1);
         myStringArray.forEach(function(entry) {
            if(typeof address ==='undefined') address = $('#select-df-'+i+' option:icontains("'+entry+'")').val();
            else return;

         });
      }
      else if(add.indexOf('/') !== -1 ){
         var myStringArray = add.split("/");
          alert_html = ','+(i+1);
         myStringArray.forEach(function(entry) {
            if(typeof address ==='undefined') address = $('#select-df-'+i+' option:icontains("'+entry+'")').val();
            else return;

         });
      }
    }
    if (typeof address === 'undefined') {
        var add2 = contact_addresses[add];
        alert_html = ','+(i+1);
        address = $('#select-df-'+i+' option:icontains('+add2+')').val();
    }
    if (typeof address === 'undefined') {
        address = 'AS REPORTED, the item  <strong>' + add + '</strong> does NOT have an exactly matching Data Furnisher/Creditor Contract address location.';
    }
    creditor_aler_msg +=alert_html;
    return address;
}
 function AIInquiry(){


  var table =  $('#Inquiries ').find('.rpt_content_table').first();
  $('.inquiries').remove();

  table.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.
    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 = $.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());

    var address = getContactAdd(item_count,td0);
    //var address = $('#select-df-'+item_count+' option:contains('+td0+')').val();

    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 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="rpt_content_table rpt_content_header rpt_table4column"><tbody><tr><th class="tbheader" width="30%">Creditor Name</th><th class="tbheader" width="30%">Type of Business</th><th class="tbheader" width="15%">Date of inquiry</th><th class="tbheader" width="15%"> Credit Bureau</th></tr>'+$(this).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);
  })

}
 function AIpersonalInfo(){

  var table ='';
  $(' .view-html .rpt_fullReport_header').each(function(){
    var head = $.trim($(this).text());
    if (head == 'Personal Information'){
        table = $(this).next().next();
        return false; // exit each loop.
    }
  })

  $('.all-select').remove();//remove all dropdowns inside public report of report
  var html ='';
  addContent();
  table.find('tr').each(function (i, el) {

    if(i==0 || i==1) return true; // skip first tr
    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());

    var trans = '<p ><span class="bg-yellow">'+td0+'</span>&nbsp;&nbsp;&nbsp;<span class="bg-tra">'+text1+'</span><span class="bg-exp">&nbsp;&nbsp;&nbsp;&nbsp;'+text2+'</span><span class="bg-equ">&nbsp;&nbsp;&nbsp;&nbsp;'+text3+'</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 img = '<div style="width:80%;" class="bg-white"><div class="rpt_fullReport_header">Personal Information</div><table class="rpt_content_table rpt_content_header rpt_table4column"><tbody><tr><th></th><th class="headerTUC">TransUnion</th><th class="headerEXP" ng-show="true">Experian</th><th class="headerEQF" ng-show="true">Equifax</th></tr>'+$(this).html()+'</tbody></table></div>';

    var name ="XXXXX";
    var p1 ='';
    var td2=td0;
    if(td0.trim()=='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.trim()=='Current Address(es):' || td0.trim()=='Previous Address(es):'){
       name = $('#address').val();
       td2 = "Current Address";
    }

    else{
      td2=td0;
    }
    p1 = td0 +'(s) of <span class="bg-tra">'+text1+'</span>' + ' and ' + '<span class="bg-exp">'+text2+'</span>  and <span class="bg-equ">'+text3 +'</span>' ;

    var verbiage = '<p class="bg-yellow2" style="font-size:14px;width:98%;" >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.trim()=='Employers:'){
      verbiage = '<p class="bg-yellow2" style="font-size:14px;width:98%;">Please remove the reported allegations of employer(s) of  <span class="bg-tra">'+text1+'</span>' + ' and ' + '<span class="bg-exp">'+text2+'</span>  and <span class="bg-equ">'+text3 +'</span> 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 += trans + img + 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

}
// set dropdowns and destinations for each CB  Params (item_count,df_address,derogatery type)
function setCBValues(i,df_add,dtype,template,template_df='',html){
  $('#summernote-'+i).summernote('code',html); // insert content in text area.
  //$('.note-editor .span-cl-green').remove();
  // check all thre bureau destinations by default
  $('.check-exp1','#main-content-'+i).prop('checked',true);
  $('.check-equ1','#main-content-'+i).prop('checked',true);
  $('.check-tra1','#main-content-'+i).prop('checked',true);
  //check DF destination and show DF dropdown with selected value
  $('.check-df','#main-content-'+i).prop('checked',true);

  if(df_add=='' || typeof df_add=='undefined' || df_add.substring(0, 8)=='AS REPOR'){
    $('#select-df-'+i).show().val('1').next().show();

  }else{
    $('#select-df-'+i).show().val(df_add);
  }
  var wave = $('#choose_wave').val();
  // set template dropdowns
  $('#wave-'+i).val('w'+wave);
  $('#div-dtype-'+i).show();
  $('#dtype-'+i).val(dtype);
  showTemplate($('#dtype-'+i),i);

  $('#lt_template-'+i).val(template);
  $('#lt_template_df-'+i).val(template_df);
  if(wave>1){
    // var lt_template = $("#lt_template-"+i + "option:first");
    // var lt_template_df = $("#lt_template-"+i + "option:first");
    // lt_template.val(lt_template.val());
    $("#lt_template-"+i).val($("#lt_template-"+i +" option:first").val());
    $("#lt_template_df-"+i).val($("#lt_template_df-"+i +" option:first").val());

  }
}
 // get creditor contacts from report and make select box.
function getDF() {
    var source_type = $('select[name=source_type]').val();
    var table = $("#CreditorContacts .rpt_content_table");

    var html = '<option value="">Please Select</option>';
    if (source_type == 3) {
        html = getSmartCreditCreditorDropDown();
    } else {
        table.find('tr').each(function (i, el) {
            var $tds = $(this).find('td');
            var key = $tds.eq(0).text();
            var key = $tds.eq(0).text();
            if (key != "") {
                var name = $tds.eq(0).text().replace(/<(?:.|\n)*?>/gm, '');
                name = name.replace(/\r?\n|\r/g, '');
                name = name.replace('_', '');
                name = name.replace('-', '');
                name = name.replace(/\s+/g, " ");
                name = name.trim();


                var address = $tds.eq(1).text().replace(/<(?:.|\n)*?>/gm, '');
                address = address.replace(/\r?\n|\r/g, '');
                address = address.replace('_', '');
                address = address.replace('-', '');
                address = address.replace(/\s+/g, " ");
                address = address.trim();

                html = html + '<option value="' + name + ' : ' + address + '" title="' + address + '">' + name + '</option>';
            }
        });
    }
    html = html + '<option value="1" >Other</option>';
    return html;

}

 function toggleDest(id){

  $('#toggle-dest-'+id).toggleClass("glyphicon-chevron-down").toggleClass("glyphicon-chevron-up");
  if($('#toggle-dest-'+id).hasClass('glyphicon-chevron-up')){
    $('#toggle-dest-'+id).attr('title','Hide');
  }else{
    $('#toggle-dest-'+id).attr('title','Show');
  }
 }
 function showDtype(ele,id){
  $('#div-dtype-'+id).show();
  $('#dtype-'+id).val('');
 }
 function showTemplate(ele,id){

  $('#template-'+id).show();
  $('#template-df-'+id).show();
  var val = $(ele).find(":selected").val();
  var html ='';
  var wave ='Ew1';
  var day = 'D1';
  var title = '';
  var html_df ='';
  if(val == '') return false;

  var wv = $('#wave-'+id).val(); // selected wave value.

  if(wv == 'w1'){
    if(val==1){
      html ='<option value="PI-'+wave+'L1'+day+'-bureau_1">&nbsp;For Bureaus use Ew1L1D1 bureaus General Item Attack for Bureau on Questionable Items</option>';
      html_df ='<option value="PI-'+wave+'L1'+day+'-df-creditor_1">&nbsp;For Data Furnisher Creditor or Collector use Ew1L1D1 bureaus General Item Attack for Bureau on Questionable Items</option>';
    }
    else if(val==2){
      html ='<option value="INQ-'+wave+'L2'+day+'-bureau_2">&nbsp;For Bureaus use Ew1L2D1 bureaus Inquiry(ies)</option>';
      html_df ='<option value="INQ-'+wave+'L2'+day+'-bureau_2"> For Data Furnisher or Creditor use Ew1L2D1 bureaus Inquiry(ies)</option>';
    }
    else if(val==3){
      html ='<optgroup label="If ONLY 1 or 2 Lates reported in last 4 years"><option value="NLP12-'+wave+'L1'+day+'-bureau_1">&nbsp;&nbsp;For Bureaus use Ew1L1D1 bureaus General Item Attack for Bureau on Questionable Items</option></optgroup><optgroup label="If 3+ Lates reported in last 4 years"><option value="NLP3-'+wave+'LPR'+day+'-bureau_17" title="For Bureaus use Ew1LPRD1 BureausORcredittors for accounts with AT LEAST(3+) Late Payments in last 4 years(48 months) with GOAL of REMOVAL FROM REPORTING (but would be HAPPY with PAANL or PAANLPR status)">&nbsp;&nbsp;For Bureaus use Ew1LPRD1 BureausORcredittors for accounts with AT LEAST(3+) Late Payments in last 4 years(48 months) with GOAL of REMOVAL FROM REPORTING (but would be HAPPY with PAANL or PAANLPR status)</option></optgroup>';
      html_df ='<optgroup label="If ONLY 1 or 2 Lates reported in last 4 years"><option value="NLP12-'+wave+'L1'+day+'-df-creditor_1">&nbsp;&nbsp;For Data Furnisher Creditor or Collector use Ew1L1D1 bureaus General Item Attack for Bureau on Questionable Items</option></optgroup><optgroup label="If 3+ Lates reported in last 4 years"><option value="NLP3-'+wave+'LPRx1'+day+'-df-creditor_17" title="For Data Furnisher Creditor or Collector use Ew1LPRx1D1 BureausORcredittors also for accounts with AT LEAST THREE(3+) Late Payments in last 4 years(48 months) with GOAL of REMOVAL FROM REPORTING (but would be HAPPY with PAANL or PAANLPR status)">&nbsp;&nbsp;For Data Furnisher Creditor or Collector use Ew1LPRx1D1 BureausORcredittors also for accounts with AT LEAST THREE(3+) Late Payments in last 4 years(48 months) with GOAL of REMOVAL FROM REPORTING (but would be HAPPY with PAANL or PAANLPR status)</option></optgroup>';
    }
    else if(val==4){
      html ='<optgroup label="If a Student Loan with ONLY 1 or 2 Late Payments (that you WANT TO TRY FOR PAANL STATUS) reported in last 4 years"><option value="SL12-'+wave+'L9'+day+'-bureau_9">&nbsp;&nbsp;For Bureaus use Ew1L9D1 for PAANL STUDENT LOAN</option></optgroup><optgroup label="If a Student Loan with 3+ Late Payments (That you WANT to attempt REMOVAL of REPORTING)  reported in last 4 years"><option value="SL3-'+wave+'L11'+day+'-bureau_11">&nbsp;&nbsp;For Bureaus use Ew1L11D1 bureau for STUDENT LOAN DELETION</option></optgroup>';
      html_df ='<optgroup label="If a Student Loan with ONLY 1 or 2 Late Payments (that you WANT TO TRY FOR PAANL STATUS) reported in last 4 years"><option value="SL12-'+wave+'L10'+day+'-df-creditor_10">&nbsp;&nbsp;For Data Furnisher Creditor or Collector use Ew1L10D1 Data Furnisher creditor for PAANL STUDENT LOANS</option></optgroup><optgroup label="If a Student Loan with 3+ Late Payments (That you WANT to attempt REMOVAL of REPORTING)  reported in last 4 years"><option value="SL3-'+wave+'L12'+day+'-df-creditors_12">&nbsp;&nbsp;For Data Furnisher Creditor or Collector use Ew1L12D1 Data Furnisher creditor for STUDENT LOAN DELETION</option></optgroup>';
    }
    else if(val==5){
      html ='<option value="NMCOL-'+wave+'L5'+day+'-bureau_5">&nbsp;For Bureaus use Ew1L5D1 bureau for Non-Medical Collection</option>';
      html_df ='<option value="NMCOL-'+wave+'L6'+day+'-df-creditor_6">&nbsp;or Data Furnisher Creditor or Collector use Ew1L6D1 Data Furnisher creditor for non-MEDICAL Collections</option>';
    }
    else if(val==6){
      html ='<option value="MCOL-'+wave+'L7'+day+'-bureau_7">&nbsp;For Bureaus use Ew1L7D1 bureau for Medical Collections</option>';
      html_df ='<option value="MCOL-'+wave+'L8'+day+'-df-creditor_8">&nbsp;For Data Furnisher Creditor or Collector use Ew1L8D1 Data Furnisher creditor for MEDICAL Collections</option>';
    }
    else if(val==7){
      html ='<option value="COFF-'+wave+'L4'+day+'-bureau_4">&nbsp;For Bureaus use Ew1L4D1 bureau for CHARGE OFFS</option>';
      html_df ='<option value="COFF-'+wave+'L3'+day+'-df-creditor_3">&nbsp;For Data Furnisher Creditor or Collector use Ew1L3D1 Data Furnisher creditor for CHARGE OFF</option>';
    }
    else if(val==8){
      html ='<option value="REPO-'+wave+'L4'+day+'-bureau_4">&nbsp;For Bureaus use Ew1L14D1 bureau for REPOSSESSIONS</option>';
      html_df ='<option value="REPO-'+wave+'L3'+day+'-df-creditor_3">&nbsp;For Data Furnisher Creditor or Collector use Ew1L13D1 Data Furnisher creditor for REPOSSESSION</option>';
    }
    else if(val==9){
      html ='<option value="PR-'+wave+'L15'+day+'-bureau_15">&nbsp;For Bureaus use Ew1L15D1 bureau for PUBLIC RECORDS</option>';
      html_df ='<option value="PR-'+wave+'L1'+day+'-df-creditor_1">&nbsp;For Data Furnisher Creditor or Collector use Ew1L1D1 bureaus General Item Attack for Bureau on Questionable Items</option><option value="PR-'+wave+'L16'+day+'-df-creditor_16">&nbsp;For Data Furnisher Creditor or Collector use Ew1L16D1 Data Furnisher creditor collectors  courts for PUBLIC RECORDS</option>';
    }
    else if(val==10){
     // html ='<option value="AUDIT-'+wave+'L1'+day+'-audit_40">&nbsp;AUDIT ANALYSIS DOCUMENT</option>'
      html = '<option value="GEN-'+wave+'L1'+day+'-bureau_1">&nbsp;For Bureaus use Ew1L1D1 bureaus General Item Attack for Bureau on Questionable Items</option>';
      html_df ='<option value="GEN-'+wave+'L18'+day+'-df-creditor-other_29">&nbsp;For Data Furnisher Creditor or Collector use Ew1L18D1  DF for general Other</option>';
    }
    html ='<option value="">Please select template</option>'+html;
    html_df ='<option value="">Please select template</option>'+html_df;
  }
  else if(wv == 'w2'){
    // inquiry templates
    //personal info
     if(val==1){
      wave = 'Ew2';
      day = 'D20';
      html ='<option value="PI-'+wave+'L2'+day+'-bureau_34">&nbsp;Ew2L1D20 bureaus for Personal Identifier Information</option>';
      html_df ='<option value="PI-'+wave+'L17'+day+'-df-other_40">&nbsp;EW2L17D20  DF for general or other</option>';
    }
    else if(val==2){
      wave = 'Ew2';
      day = 'D20';
      html ='<option value="INQ-'+wave+'L2'+day+'-bureau_35">&nbsp;Ew2L2D20 bureaus for INQUIRY(ies)</option>';
      html_df ='<option value="INQ-'+wave+'L3'+day+'-df-creditor_36">&nbsp;Ew2L3D20 Data Furnisher Creditor Collector for INQUIRY(ies)</option>';
    }
    // late payment non-student
    else if(val==3){
      wave = 'Ew2';
      day = 'D20';
      html ='<option value="NLP-'+wave+'L16'+day+'-bureau-general_43">&nbsp; EW2L16D20 bureaus for General or “OTHER” for DELETION</option>';
      html_df ='<option value="NLP-'+wave+'L9'+day+'-df-creditor_41">&nbsp; Ew2L9D20 DF DC DB for LATE COLLECT and COFF</option>';
    }
    // student loan
    else if(val==4){
      wave = 'Ew2';
      day = 'D20';
      html ='<option value="SL-'+wave+'L6A'+day+'-bureau_37">&nbsp;Ew2L6AD20  for Student Loan deletion attempt</option>';
      html_df ='<option value="SL-'+wave+'L7'+day+'-df-creditor_38">&nbsp;Ew2L7D20 DF DC DB for ALL STUDENT LOANS for DELETION attempt</option>';
    }
    // regular non-medical
    else if(val==5){
      wave = 'Ew2';
      day = 'D20';
      html ='<option value="NMCOL-'+wave+'L8'+day+'-bureau_39">&nbsp;Ew2L8D20 Bureaus for regular non medical collection accounts</option>';
      html_df ='<option value="NMCOL-'+wave+'L7'+day+'-df-creditor_38">&nbsp;Ew2L7D20 DF DC DB for ALL STUDENT LOANS for DELETION attempt</option>';
    }
    // medical collection
    else if(val==6){
      wave = 'Ew2';
      day = 'D20';
      html ='<option value="MCOL-'+wave+'L16'+day+'-bureau-general_43">&nbsp; EW2L16D20 bureaus for General or “OTHER” for DELETION</option>';
      html_df ='<option value="MCOL-'+wave+'L17'+day+'-df-other_40">&nbsp;EW2L17D20  DF for general or other</option>';
    }
    // charge off
    else if(val==7){
      wave = 'Ew2';
      day = 'D20';
      html ='<option value="COFF-'+wave+'L12'+day+'-bureau-coff_42">&nbsp;Ew2L12D20 Bureaus for CHARGE OFF</option>';
      html_df ='<option value="COFF-'+wave+'L17'+day+'-df-other_40">&nbsp;EW2L17D20  DF for general or other</option>';
    }
    // repossesion information
    else if(val==8){
      wave = 'Ew2';
      day = 'D20';
      html ='<option value="REPO-'+wave+'L16'+day+'-bureau-general_43">&nbsp; EW2L16D20 bureaus for General or “OTHER” for DELETION</option>';
      html_df ='<option value="REPO-'+wave+'L17'+day+'-df-other_40">&nbsp;EW2L17D20  DF for general or other</option>';
    }
    // public record information
    else if(val==9){
      wave = 'Ew2';
      day = 'D20';
      html ='<option value="PR-'+wave+'L16'+day+'-bureau-general_43">&nbsp; EW2L16D20 bureaus for General or “OTHER” for DELETION</option>';
      html_df ='<option value="PR-'+wave+'L17'+day+'-df-other_40">&nbsp;EW2L17D20  DF for general or other</option>';
    }
    // general deliquent.
    else if(val==10){
      wave = 'Ew2';
      day = 'D20';
      html ='<option value="GEN-'+wave+'L16'+day+'-bureau-general_43">&nbsp; EW2L16D20 bureaus for General or “OTHER” for DELETION</option>';
      html_df ='<option value="GEN-'+wave+'L17'+day+'-df-other_44">&nbsp;EW2L17D20  DF for general or other</option>';
    }
  }
  ////////////////////////////////////////////////////////// wve3 ///////////////////////////////////////////////////////////////////////
  else if(wv == 'w3'){


     wave = 'Ew3';
     day = 'D40';
     //personal info
     if(val==1){

      html ='<option value="PI-'+wave+'L13'+day+'-bureau_53">&nbsp;EW3L13D40 bureaus for General or “OTHER” for DELETION</option>';
      html_df ='<option value="PI-'+wave+'L14'+day+'-df-other_54">&nbsp;EW3L14D40 DF for General or Other</option>';
    }
    // inquiry templates
    else if(val==2){
      html ='<option value="INQ-'+wave+'L1A'+day+'-bureau-equifax_45">&nbsp;Ew3L1AD40 EQUIFAX CORP Bureau for INQUIRY(ies)</option>';
      html +='<option value="INQ-'+wave+'L1B'+day+'-bureau-tra_46">&nbsp;Ew3L1BD40 TRANS UNION  CORP Bureau for INQUIRY(ies)</option>';
      html +='<option value="INQ-'+wave+'L1C'+day+'-bureau-exp_47">&nbsp;Ew3L1CD40 EXPERIAN NORTH AMERICA Bureau for INQUIRY(ies)</option>';

      html_df ='<option value="INQ-'+wave+'L14'+day+'-df-other_54">&nbsp;EW3L14D40 DF for General or Other</option>';
    }
    // late payment non-student
    else if(val==3){
      html ='<option value="NLP-'+wave+'L5'+day+'-bureau_51">&nbsp; Ew3L5D40 BUREAUS for late payment non student</option>';
      html_df ='<option value="NLP-'+wave+'L6'+day+'-df-other_52">&nbsp;EW3L14D40 DF for late payment non student</option>';
    }
    // student loan
    else if(val==4){
      html ='<option value="SL-'+wave+'L3A'+day+'-bureau-exp_48">&nbsp;Ew3L3AD40 Experian CORP for Student Loans Deletion Attempt</option>';
      html +='<option value="SL-'+wave+'L3B'+day+'-bureau-equifax_49">&nbsp;Ew3L3BD40 EQUIFAX Corp for Student Loans Deletion Attempt</option>';
      html +='<option value="SL-'+wave+'L3C'+day+'-bureau-tra_50">&nbsp;Ew3L3CD40 Trans Union Corporation  for Student Loans Deletion Attempt</option>';

      html_df ='<option value="SL-'+wave+'L14'+day+'-df-other_54">&nbsp;EW3L14D40 DF for General or Other</option>';
    }
    // regular non-medical
    else if(val==5){
      html ='<option value="NMCOL-'+wave+'L5'+day+'-bureau_51">&nbsp; Ew3L5D40 BUREAUS for regular non-medical</option>';
      html_df ='<option value="NMCOL-'+wave+'L6'+day+'-df-other_52">&nbsp;EW3L14D40 DF for regular non-medical</option>';
    }
    // medical collection
    else if(val==6){
      html ='<option value="MCOL-'+wave+'L5'+day+'-bureau_51">&nbsp; Ew3L5D40 BUREAUS for medical collection</option>';
      html_df ='<option value="MCOL-'+wave+'L6'+day+'-df-other_52">&nbsp;EW3L14D40 DF for medical collection</option>';
    }
    // charge off
    else if(val==7){
      html ='<option value="COFF-'+wave+'L5'+day+'-bureau_51">&nbsp; Ew3L5D40 BUREAUS for charge off</option>';
      html_df ='<option value="COFF-'+wave+'L6'+day+'-df-other_52">&nbsp;EW3L14D40 DF for charge off</option>';
    }
    // repossesion information
    else if(val==8){
      html ='<option value="REPO-'+wave+'L5'+day+'-bureau_51">&nbsp; Ew3L5D40 BUREAUS for repossesion information</option>';
      html_df ='<option value="REPO-'+wave+'L6'+day+'-df-other_52">&nbsp;EW3L14D40 DF for repossesion information</option>';
    }
    // public record information
    else if(val==9){
      html ='<option value="PR-'+wave+'L13'+day+'-bureau_53">&nbsp;EW3L13D40 bureaus for General or “OTHER” for DELETION</option>';
      html_df ='<option value="PR-'+wave+'L14'+day+'-df-other_54">&nbsp;EW3L14D40 DF for General or Other</option>';
    }
    // general deliquent.
    else if(val==10){
      html ='<option value="GEN-'+wave+'L13'+day+'-bureau_53">&nbsp;EW3L13D40 bureaus for General or “OTHER” for DELETION</option>';
      html_df ='<option value="GEN-'+wave+'L14'+day+'-df-other_54">&nbsp;EW3L14D40 DF for General or Other</option>';
    }
  }
  /////////////////////////////////////////////////////////////   wave 4   /////////////////////////////////////////////////////

  else if(wv == 'w4'){


     wave = 'Ew4';
     day = 'D60';

     //personal info
     if(val==1) title = "PI";
    // inquiry templates

    // late payment non-student
    else if(val==3) title = "NLP";
    // student loan

    // regular non-medical
    else if(val==5) title = "NMCOL";
    // medical collection
    else if(val==6) title = "MCOL";
    // charge off
    else if(val==7) title = "COFF";
    // repossesion information
    else if(val==8) title = "REPO";
    // public record information
    else if(val==9) title = "PR";
    // general deliquent.
    else if(val==10) title = "GEN";

    html ='<option value="'+title+'-'+wave+'L9'+day+'-bureau_59">&nbsp;EW4L9D60 bureaus for General or “OTHER” for DELETION</option>';
    html_df ='<option value="'+title+'-'+wave+'L10'+day+'-df-other_60">&nbsp;EW4L10D60 DF for General or Other</option>';

    if(val==2){
      html ='<option value="INQ-'+wave+'L1A'+day+'-bureau-equifax_55">&nbsp;Ew4L1AD60 EQUIFAX CORP Bureau for INQUIRY(ies)</option>';
      html +='<option value="INQ-'+wave+'L1C'+day+'-bureau-tra_57">&nbsp;Ew4L1BD40 TRANS UNION  CORP Bureau for INQUIRY(ies)</option>';
      html +='<option value="INQ-'+wave+'L1B'+day+'-bureau-exp_56">&nbsp;Ew4L1CD40 EXPERIAN NORTH AMERICA Bureau for INQUIRY(ies)</option>';

      html_df ='<option value="INQ-'+wave+'L2'+day+'-df-other_58">&nbsp;Ew4L2D60 DF to Office of GC  for INQUIRY(ies)</option>';
    }
    else if(val==4){
      html ='<option value="SL-'+wave+'L11A'+day+'-bureau-exp_61">&nbsp;Ew4L11AD60 Experian CORP for Student Loans Deletion Attempt</option>';
      html +='<option value="SL-'+wave+'L11B'+day+'-bureau-equifax_62">&nbsp;Ew4L11BD60 EQUIFAX Corp for Student Loans Deletion Attempt</option>';
      html +='<option value="SL-'+wave+'L11C'+day+'-bureau-tra_63">&nbsp;Ew4L11CD60 Trans Union Corporation  for Student Loans Deletion Attempt</option>';

      title = "SL";
      html_df ='<option value="'+title+'-'+wave+'L10'+day+'-df-other_60">&nbsp;EW4L10D60 DF for General or Other</option>';
    }
  }
  /////////////////////////////////////////////////////////////   wave 5   /////////////////////////////////////////////////////

  else if(wv == 'w5'){


     wave = 'Ew5';
     day = 'D80';

     //personal info
     if(val==1) title = "PI";
    // inquiry templates

    // late payment non-student
    else if(val==3) title = "NLP";
    // student loan

    // regular non-medical
    else if(val==5) title = "NMCOL";
    // medical collection
    else if(val==6) title = "MCOL";
    // charge off
    else if(val==7) title = "COFF";
    // repossesion information
    else if(val==8) title = "REPO";
    // public record information
    else if(val==9) title = "PR";
    // general deliquent.
    else if(val==10) title = "GEN";


    html ='<option value="'+title+'-'+wave+'L7'+day+'-bureau_65">&nbsp;EW5L7D80 bureaus for General or “OTHER” for DELETION</option>';
    html_df ='<option value="'+title+'-'+wave+'L7'+day+'-bureau_65">&nbsp;EW5L7D80 bureaus for General or “OTHER” for DELETION</option>';
    //html_df ='<option value="'+title+'-'+wave+'L10'+day+'-df-other_60">&nbsp;EW4L10D60 DF for General or Other</option>';

    //inquiry  Ew5L2D80 DF for INQUIRY(ies)
    if(val==2){
      html ='<option value="INQ-'+wave+'L1'+day+'-bureau-cfpb_69">&nbsp;Ew5L1D80 Bureaus AND CFPB for INQUIRY(ies)</option>';
      html_df ='<option value="INQ-'+wave+'L2'+day+'-df-other_64">&nbsp;Ew5L2D80 DF for INQUIRY(ies)</option>';
    }
    else if(val==4){
      html ='<option value="SL-'+wave+'L9A'+day+'-bureau-exp_66">&nbsp;Ew5L9AD80  EXPERIAN CORPORATION for STUDENT LOAN deletion attempt</option>';
      html +='<option value="SL-'+wave+'L9B'+day+'-bureau-equifax_67">&nbsp;Ew5L9BD80  EQUIFAX CORPORATION for STUDENT LOAN deletion attempt</option>';
      html +='<option value="SL-'+wave+'L9C'+day+'-bureau-tra_68">&nbsp;Ew5L9CD80  Trans Union Corporation for STUDENT LOAN deletion attempt</option>';

      title = "SL";
      html_df ='<option value="'+title+'-'+wave+'L7'+day+'-bureau_65">&nbsp;EW5L7D80 bureaus for General or “OTHER” for DELETION</option>';
    }
  }
  /////////////////////////////////////////////////////////////   wave 6   /////////////////////////////////////////////////////

  else if(wv == 'w6'){


     wave = 'Ew6';
     day = 'D100';

     //personal info
     if(val==1) title = "PI";
    // inquiry templates

    // late payment non-student
    else if(val==3) title = "NLP";
    // student loan
    else if(val==4) title = "SL";
    // regular non-medical
    else if(val==5) title = "NMCOL";
    // medical collection
    else if(val==6) title = "MCOL";
    // charge off
    else if(val==7) title = "COFF";
    // repossesion information
    else if(val==8) title = "REPO";
    // public record information
    else if(val==9) title = "PR";
    // general deliquent.
    else if(val==10) title = "GEN";


    html ='<option value="'+title+'-'+wave+'L3'+day+'-bureau_71">&nbsp;EW6L3D100 bureaus for General or “OTHER” for DELETION</option>';
    html_df =html;
    //html_df ='<option value="'+title+'-'+wave+'L10'+day+'-df-other_60">&nbsp;EW4L10D60 DF for General or Other</option>';

    //personal info  Ew6L5D100 bureau AND OR DATA FURNISHERS for Personal Identifiers
    if(val==1){
      html ='<option value="INQ-'+wave+'L5'+day+'-bureau-cfpb_72">&nbsp;Ew6L5D100 bureau AND OR DATA FURNISHERS for Personal Identifiers</option>';
      html_df =html;
    }
    //inquiry
    else if(val==2){
      html ='<option value="INQ-'+wave+'L1'+day+'-bureau-cfpb_70">&nbsp;Ew6L1D100 Bureaus and DOE for CFPB  for INQUIRY(ies)</option>';

    }

  }

  $('#lt_template-'+id).html(html);
  $('#lt_template_df-'+id).html(html_df);
 }

 function clearContent(id){
  //onsole.log(el);
  if(confirm("Do you want to clear contents")){
    // put content in global variable for each content box, that can be undo by clicking plus button.
    window['cbHtml'+id] = $('#summernote-'+id).summernote('code');

    $('#summernote-'+id).summernote("reset");
    $('#summernote-'+id).summernote('code','');
    // remove required attribute if textarea is empty.
    $('#wave-'+id).prop('required',false);
    $('#letter_type-'+id).prop('required',false);
    $('#lt_template-'+id).prop('required',false);
  }
 }
 function addLineBreak(id){
  //onsole.log(el);
  var html = $('#summernote-'+id).summernote('code');
  var brk = '<p >........................................................................................................................................................</p>';
  html =html +brk ;
  $('#summernote-'+id).summernote('code',html);
 }
 function undoClearContent(id){

  if(window['cbHtml'+id]) $('#summernote-'+id).summernote('code',window['cbHtml'+id]);

  }
 function gen_rand(){
   var seq1 = (Math.floor(Math.random() * 10000) + 10000).toString().substring(1);
   var seq2 = (Math.floor(Math.random() * 10000) + 10000).toString().substring(1);
   var seq3 = (Math.floor(Math.random() * 10000) + 10000).toString().substring(1);
   var seq4 = (Math.floor(Math.random() * 10000) + 10000).toString().substring(1);
   var seq5 = (Math.floor(Math.random() * 10000) + 10000).toString().substring(1);
   var num = seq1+' '+seq2+' '+seq3+' '+seq4+' '+seq5;
   $('#p_tracking_number').val(num);
 }
 function addImage(){
   //if(image_count>2) return false;
   image_count ++;
   var attach_image_area = '<div id="img-content-'+image_count+'">'+
                            '<div class="col-md-12" style="padding-top:10px;padding-bottom:10px">'+
                                '<div class="row">'+
                                    '<div class="col-md-12 text-center">'+
                                        '<img id="att_image_'+image_count+'" class="letter-attach-img" src="" alt="">'+
                                        '<input type="hidden" id="attach_image_file_'+image_count+'" name="attach_image_file[]" value=""/>'+
                                        '<input type="hidden" id="oldAttImage_'+image_count+'"  name="oldAttImage[]" value=""/>'+
                                        '<input type="hidden" id="isAttImageChange_'+image_count+'"  name="isAttImageChange[]" value="0"/>'+
                                        '<input type="hidden" id="isUploadMedia_'+image_count+'" name="isUploadMedia[]" value="0"/>'+
                                        '</div>'+
                                         '</div>'+
                                         '</div>';


    var image_clear_btn = ' <div class="col-md-1" style="margin-top: 5px;margin-right: 20px">'+
                                '<label id="label1">'+
                                    '<a style="cursor:hand;cursor:pointer;padding: 1px 6px;" onclick="clearAttImage('+image_count+')" >Clear</a>'+
                                         '</label>'+
                                     '</div>';
   var html ='<div class="col-md-12 img-content"><div class="col-md-offset-3 col-md-6"><input id="attachment_img_'+image_count+'" type="file" onchange="uploadphotos(this,false)" name="img_bottom[]" class="form-control"></div>'+image_clear_btn+'<div class="col-md-1" style="margin-right:20px;margin-top: 5px;"><label id="label1"><a onclick="addImage()" id="add-image-btn" style="padding: 1px 6px;" class="btn btn-success"><i class="fa fa-plus"></i></a></label> <label id="label1"><a onclick="removeImage('+image_count+')" id="remove" style="padding: 1px 6px;" class="btn btn-danger"><i class="fa fa-minus"></i></a></label></div> </div>';

     $('#img-container').append(attach_image_area+html+'</div>');
 }
 function removeImage(val){
   $('#img-content-'+val).remove();
   //item_count --;
 }
 $("a[href^='#']").click(function(e) {
   if($(this).prop('id')== 'upgrade-btn'){
       return;
   }
  //e.preventDefault();
//  if($($(this).attr("href")).offset()){
//    var position = $($(this).attr("href")).offset().top;
//
//    $("body, html").animate({
//      scrollTop: position
//    } /* speed */ );
//  }
 });

 function addContent(){

   item_count ++;
   var btn_html = '<a href="#main-content-'+item_count+'" id="btn-arrow-up-'+item_count+'"  ><span class="fa-stack fa-lg" style="font-size:16px;font-weight: 500;" title="Go To Content Area '+(item_count+1)+'"><i class="fa fa-circle fa-stack-2x"></i><i class="fa-stack-1x fa-inverse">'+(item_count+1)+'</i></span></a>';
   $('#btn-up-1').prepend(btn_html);
   var image_content_area = '<div class="form-group file-txt">'+
                            '<img id="letter_img_'+item_count+'" class="letter-content-img" src="" alt="">'+
                            '<input type="hidden" id="letter_image_file_'+item_count+'" name="letter_image_file[]" value=""/>'+
                            '<input type="hidden" id="isImageChange_'+item_count+'"  name="isImageChange[]" value="0"/>'+
                            '</div>';
   var letter_html ='<div class="col-md-8"> <div class="form-group" style="clear: both;" > <label>Decisions</label> <select name="info_item[wave][]" id="wave-'+item_count+'" class="form-control" onchange="showDtype(this,'+item_count+')" >' + wave_html + '</select> </div> <div class="form-group" style="clear: both;display: none;" id="div-dtype-'+item_count+'"> <label>Type of Reported Issues</label> <select name="info_item[letter_type][]" id="dtype-'+item_count+'" class="form-control" onchange="showTemplate(this,'+item_count+')"  > <option value="">Please select template</option> <option value="1">Personal Identifier Information</option> <option value="2">INQUIRY(ies) information</option> <option value="3">LATE PAYMENT (not Student Loan) Information</option> <option value="4">STUDENT LOAN LATE PAYMENT Information</option> <option value="5">Regular Non-Medical Collection Information</option> <option value="6">Medical Collection Information</option> <option value="7">CHARGE OFF Information</option> <option value="8">REPOSSESSION Information</option> <option value="9">PUBLIC RECORDS Information</option> <option value="10">GENERAL DELINQUENT , DEROGATORY, or QUESTIONABLY REPORTED Information</option> </select> </div> <div class="form-group" style="clear: both;display: none;" id="template-'+item_count+'"> <label>TEMPLATE LETTER FOR THIS ITEM</label> <select name="info_item[template][]" id="lt_template-'+item_count+'" class="form-control " > </select> </div><div class="form-group" style="clear: both;display: none;" id="template-df-'+item_count+'"><label>TEMPLATE LETTER FOR DATA FURNISHER/CREDITOR</label><select name="info_item[template_df][]" id="lt_template_df-'+item_count+'" class="form-control" ></select></div> </div>';

   var html ='<div class="col-md-12 main-content" id="main-content-'+item_count+'">' +
       '<fieldset class="add-nother" >' +
       '<div class="cb-numbers">' +
       '<span class="fa-stack fa-lg">' +
       '<i class="fa fa-circle fa-stack-2x"></i>' +
       '<i class="fa-stack-1x fa-inverse">'+(item_count+1)+'</i>' +
       '</span>' +
       '<span class="pull-right" title="Exclude content box from letter" style="margin-top:10px;" >' +
       '<label class="lbl-dest check-btn" style="color:red !important">' +
       '<input type="checkbox" name="info_item[exclude]['+item_count+'][]" value="1" class="check-exclude"  />&nbsp;Exclude<span class="cr"></span></label></span></div><div class="col-md-9 "> <div class="col-md-4 " style="overflow: hidden;"> <div class="form-group"> <label>ADD IMAGE </label> <input onchange="uploadphotos(this)" type="file" name="info_item[file][]" class="" id="content_file_'+item_count+'"> </div><div class="col-md-12" style="margin-top: 5px;padding-left: 0px;"><label ><a onclick="removeContentImage('+item_count+')"  style="padding: 1px 6px;" class="btn btn-danger" title="Clear attached file"><i class="fa fa-minus"></i></a></label></div>'+image_content_area+'</div>'+letter_html+'<div class="col-md-12"> <div class="goto_report_div" ><label>Go to Report &rarr;</label>&nbsp;&nbsp; <a href="#view-html"><span class="glyphicon glyphicon-info-sign icon-goto-report" title="Personal Information"></span></a> <a href="#Summary"><span class="glyphicon glyphicon glyphicon-open-file icon-goto-report" title="Summary Information"></span></a> <a href="#AccountHistory"><span class="glyphicon glyphicon glyphicon-list-alt icon-goto-report" title="AccountHistory Information"></span></a> <a href="#Inquiries"><span class="glyphicon glyphicon glyphicon-question-sign icon-goto-report" title="Inquiries Information"></span></a> <a href="#PublicInformation"><span class="glyphicon glyphicon-globe icon-goto-report" title="Public Information"></span></a> <a href="#CreditorContacts"><span class="glyphicon glyphicon-user icon-goto-report" title="Creditor Contacts Information"></span></a><a href="#main-content-'+(item_count-1)+'"  style="float:right;" ><span class="glyphicon glyphicon-circle-arrow-up icon-goto-report" title="Go To Previous Content Box"></span></a><a href="#lg-form" title="Go To Top of Page" style="float: right;"><label style="font-weight: bold;font-size: 16px"> &nbsp;&nbsp;TOP &uarr;</label></a><a href="#div-img-bottom" title="Go To Generate Button" style="float: right;"><label style="font-weight: bold;font-size: 16px"> &nbsp;&nbsp;GENERATE &darr;</label></a></div><div class="form-group"><textarea class="form-control " id="summernote-'+item_count+'" name="info_item[content][]" rows="13" placeholder="" ></textarea><span class="glyphicon glyphicon-menu-hamburger btn-add-line-break" title="Add Line Break" onclick="addLineBreak('+item_count+')"></span><span class="glyphicon glyphicon-plus btn-add-content" title="Add Cleared Content" onclick="undoClearContent('+item_count+')"></span><span class="glyphicon glyphicon-remove btn-remove-content" title="Clear Content Box" onclick="clearContent('+item_count+')"></span></div></div></div><div class="col-md-3 pull-right div-item-dest"> <div class="tbg"><label>CONTENT DESTINATION(s)</label><span class="glyphicon glyphicon-chevron-down pull-right gly-dest" id="toggle-dest-'+item_count+'" onclick="toggleDest('+item_count+')" title="Show" data-toggle="collapse" href="#dest-side-'+item_count+'"></span></div><div id="dest-side-'+item_count+'" class="collapse dest-collapse" > <label class="lbl-dest check-btn" style="font-size:14px"> <input type="checkbox" name="all" value="Select All Destinations" id="check-all-'+item_count+'" onchange="checkall('+item_count+')" />&nbsp;<strong>Select All Destinations</strong> <span class="cr"></span></label> <hr style="margin:2px 0 5px"> <label class="lbl-dest check-btn"><input type="checkbox" name="info_item[dest]['+item_count+'][]" value="" class="check-df" onchange="showDf(event,'+item_count+')" />&nbsp;Data Furnisher<span class="cr"></span></label><select name="info_item[dest]['+item_count+'][]" class="form-control select-df" id="select-df-'+item_count+'" style="display: none;" ></select><input type="text" name="info_item[dest]['+item_count+'][]" class="form-control" placeholder="OTHER" style="width: 96%; display:none;" id="other-text-'+item_count+'"><label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="EXPERIAN PO BOX 9701, ALLEN, TX 75013" class="check-exp1" />&nbsp;EXPERIAN PO BOX 9701, ALLEN, TX 75013 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="EXPERIAN PO BOX 4500, ALLEN, TX 75013" class="check-exp2" />&nbsp;EXPERIAN PO BOX 4500, ALLEN, TX 75013 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="EQUIFAX PO Box740256, ATLANTA,GA 30374-0256" class="check-equ1" />&nbsp;EQUIFAX PO Box740256, ATLANTA,GA 30374-0256 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="EQUIFAX PO Box740241, ATLANTA,GA 30374-0241" class="check-equ2" />&nbsp;EQUIFAX PO Box740241, ATLANTA,GA 30374-0241 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="Trans Union PO Box 2000, CHESTER, PA 19016-2000" class="check-tra1" />&nbsp;Trans Union PO Box 2000, CHESTER, PA 19016-2000 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="Trans Union PO Box 1000, CHESTER, PA 19022-1000" class="check-tra2" />&nbsp;Trans Union PO Box 1000, CHESTER, PA 19022-1000 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="Trans Union PO Box 2000, CHESTER, PA 19022-2000" class="check-tra3" />&nbsp;Trans Union PO Box 2000, CHESTER, PA 19022-2000 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="INNOVIS PO Box 1640, Pittsburgh, PA 15230-1640" class="check-ino1" />&nbsp;INNOVIS PO Box 1640, Pittsburgh, PA 15230-1640 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="Innovis Consumer Assistance PO Box 530088, Atlanta, GA 30353-0088" class="check-ino2" />&nbsp;Innovis Consumer Assistance PO Box 530088, Atlanta, GA 30353-0088 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="LexisNexis PO Box 105108, Atlanta, GA 30348" class="check-lex1" />&nbsp;LexisNexis PO Box 105108, Atlanta, GA 30348 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="SageStream, LLC, LexisNexis Risk Solutions Consumer Center P. O. Box 105108. Atlanta, Georgia 30348-5108" class="check-sag1" />&nbsp;SageStream, LLC, LexisNexis Risk Solutions Consumer Center P. O. Box 105108. Atlanta, Georgia 30348-5108 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="Chex Systems ATTN: Consumer Relations, 7805 Hudson Rd., Ste. 100, Woodbury, MN 55125" class="check-chex1" />&nbsp;Chex Systems ATTN: Consumer Relations, 7805 Hudson Rd., Ste. 100, Woodbury, MN 55125 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="(US RESIDENTS) MIB Inc 50 Braintree Hill Park, Suite 400, Braintree, MA 02184-8734" class="check-mib1" />&nbsp;(US RESIDENTS) MIB Inc 50 Braintree Hill Park, Suite 400, Braintree, MA 02184-8734 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="(CANADIAN RESIDENTS) MIB Inc 330 university Avenue, Suite 501, Toronto, Canada M5G 1R7" class="check-mib2" />&nbsp;(CANADIAN RESIDENTS) MIB Inc 330 university Avenue, Suite 501, Toronto, Canada M5G 1R7 <span class="cr"></span></label> <label class="lbl-dest check-btn"> <input type="checkbox" name="info_item[dest]['+item_count+'][]" value="FactorTrust PO Box 3653,Alpharhetta, GA 30023" class="check-fact1" />&nbsp;FactorTrust PO Box 3653,Alpharhetta, GA 30023 <span class="cr"></span></label><label class="lbl-dest check-btn"><input type="checkbox" name="info_item[dest]['+item_count+'][]" value="" class="check-aa" />&nbsp;Audit Analysis<span class="cr"></span></label><input type="text" name="info_item[dest]['+item_count+'][]" class="form-control" placeholder="OTHER" style="width: 96%" id="other-text-'+item_count+'"><span class="glyphicon glyphicon-plus btn-add-other" title="Add Other"></span></div></div> <div class="col-md-4 " style="clear: both;"> <button class="btn btn-success btn2" onclick="addContent()" type="button"> <span class="glyphicon glyphicon-plus" title="add"></span>Add Another Content</button> </div> <div class="col-md-4 "> <button class="btn btn-danger btn2-danger" onclick="removeContent('+item_count+')" type="button"> <span class="glyphicon glyphicon-minus" title="remove"></span>Remove this Content Box</button> </div></fieldset></div>';
   $('#content-area').append(html);

   $('#univ-dest option:selected').each(function(){

    var title = $(this).val();

    if(title==='') {

      $('.check-df','#main-content-'+item_count).prop('checked',true);
    }

    else if(title=='EXPERIAN PO BOX 9701, ALLEN, TX 75013'){
      $('.check-exp1','#main-content-'+item_count).prop('checked',true);

    }
    else if(title=='EXPERIAN PO BOX 4500, ALLEN, TX 75013'){
      $('.check-exp2','#main-content-'+item_count).prop('checked',true);
    }
    else if(title=='EQUIFAX PO Box740256, ATLANTA,GA 30374-0256'){
      $('.check-equ1','#main-content-'+item_count).prop('checked',true);

    }
    else if(title=='EQUIFAX PO Box740241, ATLANTA,GA 30374-0241'){
      $('.check-equ2','#main-content-'+item_count).prop('checked',true);
    }
    else if(title=='Trans Union PO Box 2000, CHESTER, PA 19016-2000'){
      $('.check-tra1','#main-content-'+item_count).prop('checked',true);
    }
    else if(title=='Trans Union PO Box 1000, CHESTER, PA 19022-1000'){
      $('.check-tra2','#main-content-'+item_count).prop('checked',true);
    }
    else if(title=='Trans Union PO Box 2000, CHESTER, PA 19022-2000'){
      $('.check-tra3','#main-content-'+item_count).prop('checked',true);
    }
    else if(title=='INNOVIS PO Box 1640, Pittsburgh, PA 15230-1640'){
      $('.check-ino1','#main-content-'+item_count).prop('checked',true);
    }
    else if(title=='Innovis Consumer Assistance PO Box 530088, Atlanta, GA 30353-0088'){
      $('.check-ino2','#main-content-'+item_count).prop('checked',true);
    }
    else if(title=='LexisNexis PO Box 105108, Atlanta, GA 30348'){
      $('.check-lex1','#main-content-'+item_count).prop('checked',true);
    }
    else if(title=='SageStream, LLC, LexisNexis Risk Solutions Consumer Center P. O. Box 105108. Atlanta, Georgia 30348-5108'){
      $('.check-sag1','#main-content-'+item_count).prop('checked',true);
    }
    else if(title=='Chex Systems ATTN: Consumer Relations, 7805 Hudson Rd., Ste. 100, Woodbury, MN 55125'){
      $('.check-chex1','#main-content-'+item_count).prop('checked',true);
    }
    else if(title=='(US RESIDENTS) MIB Inc 50 Braintree Hill Park, Suite 400, Braintree, MA 02184-8734'){
      $('.check-mib1','#main-content-'+item_count).prop('checked',true);
    }
     else if(title=='(CANADIAN RESIDENTS) MIB Inc 330 university Avenue, Suite 501, Toronto, Canada M5G 1R7'){
      $('.check-mib2','#main-content-'+item_count).prop('checked',true);

    }
     else if(title=='FactorTrust PO Box 3653,Alpharhetta, GA 30023'){
      $('.check-fact1','#main-content-'+item_count).prop('checked',true);
    }

   });

   init_summernote(item_count);// initialize summer note.
   //$('.note-insert').remove();// remove image button d
}

function init_summernote(item_count){
  $('#summernote-'+item_count).summernote({
     placeholder: 'Inside the Content box enter manually or however the item’s NAME, item’s account number if an account, item’s inquiry date if an inquiry, Data furnisher /creditor contact address, and any other pertinent information that you WANT TO DISPLAY ON THE END-RESULT TEMPLATE ATTACK LETTER(s) for THIS ITEM(s).&#10;**IF ENTERING MORE THAN ONE ITEM because multiple issues are going to same destinations of your choice then be sure there is AT LEAST a SEPARATING LINE OF LARGE “X’s? going across whole width of Content box such as XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX    so to CLEARLY mark a separation of the multiple items from one another on the END-RESULT TEMPLATE ATTACK LETTER DOCUMENT(s).&#10;***Obviously if entering MULTIPLE ITEMS as opposed to only ONE ITEM in any single content box you do NOT want to add an IMAGE of the items because no way to detail WHICH OF THE ITEMS manually entered would be associated with the accompanying image.',
     tabsize: 2,
     height: 350,
     callbacks: {
        onImageUpload: function(files) {
            uploadFile(files[0],item_count);
        }
      }
   });
  window['cbHtml'+item_count] ='';
  $('#select-df-'+item_count).html(getDF());// set newly created data furnisher dropdown.
}

 function removeContent(val){
   $('#main-content-'+val).remove();
   $('#btn-arrow-up-'+val).remove();
   //item_count --;
 }
 function checkall(val){
    var checkboxes = $('#main-content-'+val).find(':checkbox').not('.check-exclude');

    checkboxes.prop('checked', $('#check-all-'+val).is(':checked'));
 }
 function excludeall(){

  $('.check-exclude').prop('checked', $('#exclude-all').is(':checked'));
}
  function removeContentImage(val){
     // if no file attached then return.
     if(!$('#letter_image_file_'+val).val()) return false;
     if(confirm('Do you want to clear attached file?')){
         $('#content_file_'+val).val(null);
         $('#letter_img_'+val).attr('src','');
         $('#letter_image_file_'+val).val('');
         $('#isImageChange_'+val).val(1);
     }
  }

  $('#select-df').change(function() {
     if($(this).val()==='1') $('#univ-other').show();
     else $('#univ-other').hide();
 });
  // **************************************************** code for showing hiding download busy icon *************************
  var setCookie = function(name, value, expiracy) {
    var exdate = new Date();
    exdate.setTime(exdate.getTime() + expiracy * 1000);
    var c_value = escape(value) + ((expiracy == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = name + "=" + c_value + '; path=/';
  };

  var getCookie = function(name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
      x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
      y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
      x = x.replace(/^\s+|\s+$/g, "");
      if (x == name) {
        return y ? decodeURI(unescape(y.replace(/\+/g, ' '))) : y; //;//unescape(decodeURI(y));
      }
    }
  };
  var downloadTimeout;
  var checkDownloadCookie = function() {
    if (getCookie("downloadStarted") == 1) {
      setCookie("downloadStarted", "false", 40000); //Expiration could be anything... As long as we reset the value
      $('#client-loader2').hide();
      //location.reload();
    } else {
      downloadTimeout = setTimeout(checkDownloadCookie, 3000); //Re-run this function in 1 second.
    }
  };

  jQuery("#lg-form").submit(function (evt) {
    //$('#client-loader2').show();
    setCookie('downloadStarted', 0, 40000); //Expiration could be anything... As long as we reset the value
    setTimeout(checkDownloadCookie, 3000); //Initiate the loop to check the cookie.
    //perform destination check on each content box.
    var flag=true;
    $('.main-content').each(function(i){

      //if textarea value is not empty or null then perform destination check and letter template check.
      var cbval = $('#summernote-'+i).val();
      if(cbval && cbval !='<p><br></p>'){
         $('#wave-'+i).prop('required',true);
         $('#letter_type-'+i).prop('required',true);
         $('#lt_template-'+i).prop('required',true);
         if(!$('#lt_template-'+i).val() ) {
           alert('Please select letter template for content box '+(i+1));
           $('#summernote-'+i).focus();
           flag=false;
           $('#client-loader2').hide();
           return false;
         }
         var len = $('#main-content-'+i+' :checkbox:checked').length;
         var other_text = $('#other-text-'+i).val();
         var univ_other = $('#univ-other').find('input[type=text]').first().val();
         // check if no checkbox is check, no other field has text, no universal other has text
         if(len<2 && !other_text && !univ_other){
           evt.preventDefault();
           alert('Please select at least one destination for content box '+(i+1));
           $('#summernote-'+i).focus();
           flag=false;
           $('#client-loader2').hide();
           return false;
         }
         // if no data furnisher selected and template selected for data furnisher then alert messte.
        if($('#lt_template_df-'+i).val() !='' && $('#select-df-'+i).val()=='') {
          evt.preventDefault();
          alert('Please select Data Furnisher for content box'+(i+1));
          $('#client-loader2').hide();
          return false;
        }

      }

    });

    // remove all unused content boxes before geneate.
    $('.main-content').each(function(i){
     if(i==0) return false //skip first iteratin because first CB is required.
     var cbval = $('#summernote-'+i).val();
       if(cbval && cbval !='<p><br></p>'){

       }else{
           if(flag){
             $('#wave-'+i).prop('required',false);
              $('#letter_type-'+i).prop('required',false);
              $('#lt_template-'+i).prop('required',false);
              $('a[href$="main-content-'+i+'"]').remove();
              $('#main-content-'+i).remove();
           }
       }
    })

  })

  function showDf(ele,id){
   if(ele.target.checked) $('#select-df-'+id).show();
    else  $('#select-df-'+id).hide();

  }


  $(document).on('click', '.btn-add-other', function () {
     var html ='<input type="text" name="info_item[dest][0][]" class="form-control" placeholder="OTHER" style="width: 96%" autofocus >';
     $(this).before(html);
     var d = $(this).parent('.div-item-dest');
     var div = $(this).closest('.div-item-dest');
     div.animate({ scrollTop: div.prop("scrollHeight")}, 1000);

   });
  $(document).on('click', '.btn-univ-add-other', function () {

   var html ='';
      html = '<div><input type="text" name="destination[]" class="form-control" placeholder="OTHER" style="width: 93%"><span class="glyphicon glyphicon-plus btn-univ-add-other" title="Add Other"></span><span class="glyphicon glyphicon-minus btn-univ-remove-other"  title="Remove Other"></span></div>';
     $('.univ-other').append(html);
   });
  $(document).on('click', '.btn-univ-remove-other', function () {

     $(this).parent().remove();
   });
  function setClientDateTime(){
    var date_time = new Date();
    var zone = new Date().toLocaleTimeString('en-us',{timeZoneName:'short'}).split(' ')[2];
    date_time = (('0'+(date_time.getMonth()+1)).slice(-2))+'-'+(('0'+(date_time.getDate()+1)).slice(-2))+'-'+date_time.getFullYear()+' '+date_time.getHours()+date_time.getMinutes()+zone;
    $('#date_time').val(date_time);

  }

  $(document).ready(function() {
    $('#client-loader2').hide();
    setClientDateTime();//set client_date time used for generating pdf files names.
    //$('.datepicker').datepicker({format:'mm/dd/yyyy'});
     //show hide up arrows on mouse hover.
     $("#btn-up-0").hover(function(){
       $('#btn-up-1').fadeIn();
       }, function(){
       $('#btn-up-1').fadeOut();
     });
     $('.dest-collapse').collapse();// collapse destinations side area at start.
   $('#univ-dest').multiselect({

     includeSelectAllOption: true,
     allSelectedText: 'All',
     enableCollapsibleOptGroups: true,
     maxHeight: 300,
     numberDisplayed: 1,
     //buttonWidth: 100,
     onSelectAll: function() {
         //alert("ALL");
         $("input[type='checkbox']").prop( "checked" , true );
     },
     onDeselectAll: function() {
         $("input[type='checkbox']").prop( "checked" , false );
     },
     onChange: function(option, checked, select) {

         var title = option[0].value;


         if(title==='1') {
          if(checked)$('#univ-other').show();
          else $('#univ-other').hide();
         }
         if(title==='') {
            if(checked){
             $('#univ-df').show();
             $('#select-df').prop('required',true);
            }
            else{
              $('#univ-df').hide();
              $('#select-df').prop('required',false);
            }

            var checkboxes = $('.check-df');
            checkboxes.prop('checked',checked );
         }

         else if(title=='EXPERIAN PO BOX 9701, ALLEN, TX 75013'){
           var checkboxes = $('.check-exp1');
           checkboxes.prop('checked',checked );
         }
         else if(title=='EXPERIAN PO BOX 4500, ALLEN, TX 75013'){
           var checkboxes = $('.check-exp2');
           checkboxes.prop('checked',checked );
         }
         else if(title=='EQUIFAX PO Box740256, ATLANTA,GA 30374-0256'){
           var checkboxes = $('.check-equ1');
           checkboxes.prop('checked',checked );
         }
         else if(title=='EQUIFAX PO Box740241, ATLANTA,GA 30374-0241'){
           var checkboxes = $('.check-equ2');
           checkboxes.prop('checked',checked );
         }
         else if(title=='Trans Union PO Box 2000, CHESTER, PA 19016-2000'){
           var checkboxes = $('.check-tra1');
           checkboxes.prop('checked',checked );
         }
         else if(title=='Trans Union PO Box 1000, CHESTER, PA 19022-1000'){
           var checkboxes = $('.check-tra2');
           checkboxes.prop('checked',checked );
         }
         else if(title=='Trans Union PO Box 2000, CHESTER, PA 19022-2000'){
           var checkboxes = $('.check-tra3');
           checkboxes.prop('checked',checked );
         }
         else if(title=='INNOVIS PO Box 1640, Pittsburgh, PA 15230-1640'){
           var checkboxes = $('.check-ino1');
           checkboxes.prop('checked',checked );
         }
         else if(title=='Innovis Consumer Assistance PO Box 530088, Atlanta, GA 30353-0088'){
           var checkboxes = $('.check-ino2');
           checkboxes.prop('checked',checked );
         }
         else if(title=='LexisNexis PO Box 105108, Atlanta, GA 30348'){
           var checkboxes = $('.check-lex1');
           checkboxes.prop('checked',checked );
         }
         else if(title=='SageStream, LLC, LexisNexis Risk Solutions Consumer Center P. O. Box 105108. Atlanta, Georgia 30348-5108'){
           var checkboxes = $('.check-sag1');
           checkboxes.prop('checked',checked );
         }
         else if(title=='Chex Systems ATTN: Consumer Relations, 7805 Hudson Rd., Ste. 100, Woodbury, MN 55125'){
           var checkboxes = $('.check-chex1');
           checkboxes.prop('checked',checked );
         }
         else if(title=='(US RESIDENTS) MIB Inc 50 Braintree Hill Park, Suite 400, Braintree, MA 02184-8734'){
           var checkboxes = $('.check-mib1');
           checkboxes.prop('checked',checked );
         }
          else if(title=='(CANADIAN RESIDENTS) MIB Inc 330 university Avenue, Suite 501, Toronto, Canada M5G 1R7'){
           var checkboxes = $('.check-mib2');
           checkboxes.prop('checked',checked );
         }
          else if(title=='FactorTrust PO Box 3653,Alpharhetta, GA 30023'){
           var checkboxes = $('.check-fact1');
           checkboxes.prop('checked',checked );
         }
      }
    });

   $('#summernote-0').summernote({
     placeholder: 'Inside the Content box enter manually or however the item’s NAME, item’s account number if an account, item’s inquiry date if an inquiry, Data furnisher /creditor contact address, and any other pertinent information that you WANT TO DISPLAY ON THE END-RESULT TEMPLATE ATTACK LETTER(s) for THIS ITEM(s).&#10;**IF ENTERING MORE THAN ONE ITEM because multiple issues are going to same destinations of your choice then be sure there is AT LEAST a SEPARATING LINE OF LARGE “X’s? going across whole width of Content box such as XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX    so to CLEARLY mark a separation of the multiple items from one another on the END-RESULT TEMPLATE ATTACK LETTER DOCUMENT(s).&#10;***Obviously if entering MULTIPLE ITEMS as opposed to only ONE ITEM in any single content box you do NOT want to add an IMAGE of the items because no way to detail WHICH OF THE ITEMS manually entered would be associated with the accompanying image.',
     tabsize: 2,
     height: 350,
     callbacks: {
      onImageUpload: function(files) {
          uploadFile(files[0],0);
      }
    }

   });
   $.ajaxSetup({
      headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
      }
    });
    wave_html = $('#wave-0').html();// set global wave_html variable.

  });// end of document ready
  //upload file via ajax, uploaded in CB
  function uploadFile(file,id) {
    data = new FormData();
    data.append("file", file);

    $.ajax({
        data: data,
        type: "POST",
        url: "ajax/letter/cbimage", //replace with your url
        cache: false,
        contentType: false,
        processData: false,
        success: function(url) {

            if(url.response){
              var image = $('<img>').attr('src', url.response);
              $('#summernote-'+id).summernote("insertNode", image[0]);
            }
            else console.log('error while uploading file for CB# ' +id );
        }
    });
  }

