var GLOBAL_URL = "";
var DEFAULT_CLENT_LIST = "";
var hasHistory = false;
var is_editable = false;
var history_id = 0;
function isEmptyString(value) {
var result = false;
if (typeof value === "undefined") {
result = true;
} else if (value == null) {
result = true;
} else if (!value) {
result = true;
}
return result;
}
$(document).ready(function() {
var url = $(location).attr('hostname');
var folder_path = window.location.pathname.split('/').slice(0, 2).join('/');
$('#client-contact-id').addClass('client-dropdown');
$('#client-contact-id').parents('div.col-md-10').first().prepend(affiliateCheckboxContent())
$('#client-contact-loading-img').after(viewDFtButton());
hideOldImageTagForNotExistImg()
setClientFilesButton();
$('#resetForm').click(function() {
$('form#inputformId')[0].reset();
$('input#image1').show();
$('input#image2').show();
$('input#image3').show();
$('input#image4').show();
$('input#image5').show();
$('#label1').show();
$('#label2').show();
$('#label3').show();
$('#label4').show();
$('#label5').show();
$('#label6').show();
$('#label7').show();
$('#label8').show();
$("input#image1new").val('');
$("input#image2new").val('');
$("input#image3new").val('');
$("input#image4new").val('');
$("input#image5new").val('');
$("input#image6new").val('');
$("input#image7new").val('');
$("input#image8new").val('');
$('#clientId').val('');
$('#cra_report').val('');
$('#first_name').val('');
$('#last_name').val('');
$('#street_no').val('');
$('#street_name').val('');
$('#city').val('');
$('#state').val('');
$('#credit_bureau_address').val('');
$('#sincerely').val('');
$('#clientInfo').val('');
$('#social_security_no').val('');
$('#birth_date').val('');
$('img#image1-old-view').removeAttr('src');
$('img#image2-old-view').removeAttr('src');
$('img#image3-old-view').removeAttr('src');
$('img#image4-old-view').removeAttr('src');
$('img#image5-old-view').removeAttr('src');
$('img#image6-old-view').removeAttr('src');
$('img#image7-old-view').removeAttr('src');
$('img#image8-old-view').removeAttr('src');
});
$('.loading').show();
$.ajax({
type: 'GET',
url: APP_SERVER_HOST_URL + 'dashboard/clientContact',
cache: false,
success: function(data) {
var response = JSON.parse(data);
var json = response.contacts;
var dropdown = $('#client-contact-id');
DEFAULT_CLENT_LIST = json;
dropdown.empty();
dropdown.append(new Option("Please select client", "0"));
$.each(json, function(index, contact) {
dropdown.append('');
});
$('.loading').hide();
$('img#client-contact-loading-img').css('display', 'none');
if (HAS_RTG_LS_FAX_ACCESS) {
setSelectedDataForRTGLetters();
}
}
});
//$('#view-report-btn').click(function())
$('#report_file_name').change(function() {
var reportId = $(this).val();
if (reportId !== '0') {
$('#credit_bureau_address').attr('required', false);
$('#credit_bureau_field').hide();
} else {
$('#credit_bureau_address').attr('required', true);
$('#credit_bureau_field').show();
}
});
});
function hideOldImageTagForNotExistImg() {
$('img#image1-old-view').hide();
$('img#image2-old-view').hide();
$('img#image3-old-view').hide();
$('img#image4-old-view').hide();
$('img#image5-old-view').hide();
$('img#image6-old-view').hide();
$('img#image7-old-view').hide();
$('img#image8-old-view').hide();
}
function showOldImageTag() {
$('img#image1-old-view').show();
$('img#image2-old-view').show();
$('img#image3-old-view').show();
$('img#image4-old-view').show();
$('img#image5-old-view').show();
$('img#image6-old-view').show();
$('img#image7-old-view').show();
$('img#image8-old-view').show();
}
$('#client-contact-id').change(function() {
var url = $(location).attr('hostname');
var folder_path = window.location.pathname.split('/').slice(0, 2).join('/');
var contactId = $(this).val();
//var brTag = document.write('
');
var clientId = $('#client-contact-id').val();
var client_id = $('#client-contact-id option:selected').data('id');
var report_type = $('select[name=report_type]').val();
var formData = {
contactId: contactId,
'report_type': report_type,
'HAS_RTG_ACCESS_PKG': HAS_RTG_ACCESS_PKG
};
if (contactId !== '0') {
$("#view-report-btn").remove();
//$('img#client-contact-loading-img').css('display', 'block');
$('.loading').show();
$.ajax({
type: 'POST',
url: APP_SERVER_HOST_URL + 'dashboard/getContact',
data: formData,
success: function(data) {
var json = JSON.parse(data);
//console.log('response', response)
//var json = response.contacts;
var form = $('form#inputformId');
form.find('textarea,input').val('');
clientChangeEvent(json.report_type_id);
CLIENT_EMAIL = json.client_email;
if (json.clientDetails) {
if (json.clientDetails.first_name) {
CLIENT_NAME = json.clientDetails.first_name;
}
if (json.clientDetails.last_name) {
CLIENT_NAME += " " + json.clientDetails.last_name;
}
DOB = json.clientDetails.birth_date;
SSN = json.clientDetails.social_secuirty_no;
}
console.log(json);
var form_id = json.form_id;
setAllpopupLink(json);
//console.log('NEGATIVE_ALL',NEGATIVE_ALL);
if (json.clientDetails != null) {
$('#uploadSection').show();
var clientId = json.clientDetails.client_id;
var clientMediaUrl = APP_SERVER_HOST_URL + 'Client/uploadmedia/' + clientId + '#uploadMedia';
$("#uploadSection button").attr('data-toggle', '');
$('#uploadSection button').on("click", function() {
var redirectConfirm = confirm('Are you sure you want to leave this page for uploading photo?');
if (redirectConfirm === true) {
return window.location.href = clientMediaUrl;
}
});
$('input#image1').hide();
$('input#image2').hide();
$('input#image3').hide();
$('input#image4').hide();
$('input#image5').hide();
$('input#image6').hide();
$('#label1').hide();
$('#label2').hide();
$('#label3').hide();
$('#label4').hide();
$('#label5').hide();
$('#label6').hide();
$('#label7').hide();
$('#label8').hide();
$("input#image1new").val('');
$("input#image2new").val('');
$("input#image3new").val('');
$("input#image4new").val('');
$("input#image5new").val('');
$("input#image6new").val('');
$("input#image7new").val('');
$("input#image8new").val('');
$('img#image1-old-view').removeAttr('src');
$('img#image2-old-view').removeAttr('src');
$('img#image3-old-view').removeAttr('src');
$('img#image4-old-view').removeAttr('src');
$('img#image5-old-view').removeAttr('src');
$('img#image6-old-view').removeAttr('src');
$('img#image7-old-view').removeAttr('src');
$('img#image8-old-view').removeAttr('src');
$('#cra_report').val(json.clientDetails.cra_report);
$('#first_name').val(json.clientDetails.first_name);
$('#last_name').val(json.clientDetails.last_name);
$('#street_no').val(json.clientDetails.street_no);
$('#street_name').val(json.clientDetails.street_name);
$('#city').val(json.clientDetails.city);
$('#state').val(json.clientDetails.state);
$('#credit_bureau_address').val(json.clientDetails.credit_bureau_address);
$('#sincerely').val(json.clientDetails.sincerely);
$('#social_security_no').val(json.clientDetails.social_secuirty_no);
$('#birth_date').val(moment(json.clientDetails.birth_date).format('YYYY-MM-DD'));
$('#clientId').val(contactId);
$('#clientInfo').val(json.clientDetails.first_name + ' ' + json.clientDetails.last_name + ', ' + json.clientDetails.street_no + ', ' + json.clientDetails.street_name + ', ' + json.clientDetails.city + ', ' + json.clientDetails.state);
removeUnwantedText();
setCraReportText(json.report_type_id)
//console.log('image', json.clientMedias);
$.each(json.clientMedias, function(index, media) {
var imageUrl = APP_SERVER_HOST_URL + 'webroot/contact_photo/';
var image = imageUrl + media.image_path;
var mediaType = media.rtg_letter_image_id;
var mediaImage = media.image_path;
if (mediaType === 1 && mediaImage && image) { //Evidence of my Proof of identification
$('img#image1-old-view').attr("src", image);
$('img#image1-old-view').show();
$("input#image1new").val(image);
$('#label1').show();
}
if (mediaType === 2 && mediaImage && image) {
$('img#image2-old-view').attr("src", image);
$('img#image2-old-view').show();
$("input#image2new").val(image);
$('#label2').show();
}
if (mediaType === 3 && mediaImage && image) {
$('img#image3-old-view').attr("src", image);
$('img#image3-old-view').show();
$("input#image3new").val(image);
$('#label3').show();
}
if (mediaType === 4 && mediaImage && image) {
$('img#image4-old-view').attr("src", image);
$('img#image4-old-view').show();
$("input#image4new").val(image);
$('#label4').show();
}
if (mediaType === 5 && mediaImage && image) {
$('img#image5-old-view').attr("src", image);
$('img#image5-old-view').show();
$("input#image5new").val(image);
$('#label5').show();
}
if (mediaType === 6 && mediaImage && image) {
$('img#image6-old-view').attr("src", image);
$('img#image6-old-view').show();
$("input#image6new").val(image);
$('#label6').show();
}
if (mediaType === 7 && mediaImage && image) {
$('img#image7-old-view').attr("src", image);
$('img#image7-old-view').show();
$("input#image8new").val(image);
$('#label7').show();
}
if (mediaType === 8 && mediaImage && image) {
$('img#image8-old-view').attr("src", image);
$('img#image8-old-view').show();
$("input#image8new").val(image);
$('#label8').show();
}
});
//showOldImageTag();
$('.loading').hide();
//$('img#client-contact-loading-img').css('display', 'none');
} else {
var client_id_ajax = json.client_id;
$('.loading').hide();
//$('img#client-contact-loading-img').css('display', 'none');
$('.loading').hide();
if (window.confirm('Credit report has not been setup for this client. Please click ok to setup credit report.')) {
window.location.href = APP_SERVER_HOST_URL + 'Client/creditreportsetup/' + client_id_ajax;
}
}
}
});
} else {
$('#resetForm').click();
$('.loading').hide();
//$('img#client-contact-loading-img').css('display', 'none');
$('#uploadSection').css('display', 'none');
}
$('#label1').click(function() {
$("input#image1new").val('');
$('img#image1-old-view').removeAttr('src');
if (contactId !== '0') {
$('#label1').hide();
} else {
$('#label1').show();
}
});
$('#label2').click(function() {
$("input#image2new").val('');
$('img#image2-old-view').removeAttr('src');
if (contactId !== '0') {
$('#label2').hide();
} else {
$('#label2').show();
}
});
$('#label3').click(function() {
$("input#image3new").val('');
$('img#image3-old-view').removeAttr('src');
if (contactId !== '0') {
$('#label3').hide();
} else {
$('#label3').show();
}
});
$('#label4').click(function() {
$("input#image4new").val('');
$('img#image4-old-view').removeAttr('src');
if (contactId !== '0') {
$('#label4').hide();
} else {
$('#label4').show();
}
});
$('#label5').click(function() {
$("input#image5new").val('');
$('img#image5-old-view').removeAttr('src');
if (contactId !== '0') {
$('#label5').hide();
} else {
$('#label5').show();
}
});
$('#label6').click(function() {
$("input#image6new").val('');
$('img#image6-old-view').removeAttr('src');
if (contactId !== '0') {
$('#label6').hide();
} else {
$('#label6').show();
}
});
$('#label7').click(function() {
$("input#image7new").val('');
$('img#image7-old-view').removeAttr('src');
if (contactId !== '0') {
$('#label7').hide();
} else {
$('#label7').show();
}
});
$('#label8').click(function() {
$("input#image8new").val('');
$('img#image8-old-view').removeAttr('src');
if (contactId !== '0') {
$('#label8').hide();
} else {
$('#label8').show();
}
});
});
function removeUnwantedText() {
$('.rtg-make-empty-field').val('');
}
function getHTMLByClientId(elem) {
var client_id = $('#client-contact-id option:selected').data('id');
var source_type = 1;
if ($('select[name=report_type]').val()) {
source_type = $('select[name=report_type]').val();
}
//source_type = 1;
//var saveIdentityID = GLOBAL_URL+'uploadhtml/identityIQSave';
if (client_id > 0) {
$('#client-contact-loading-img').show();
var formData = { 'action': 'htmlinfo', 'client_id': client_id, 'source_type': source_type };
//console.log('formData', formData)
$.ajax({
type: 'POST',
url: saveIdentityID,
data: formData,
cache: false,
success: function(data) {
$('#client-contact-loading-img').hide();
var response = JSON.parse(data);
//console.log(json)
if (response.html) {
var json = response.html;
//$('.view-html').html(json);
json = json.replace('https://www.identityiq.com/Scripts/jquery-1.7.2.min.js', '');
json = json.replace('https://www.identityiq.com/Scripts/angular.js', '');
$('textarea[name=html_content]').val(json)
uploadHTMLUICode(json, true, source_type)
$('#client-html .modal-body').show();
$('.modal-dialog').css({ "margin": "0 auto" });
//$.noConflict();
$('#client-html').modal('show');
} else {
alert('There is no credit report for the client.')
}
}
});
}
}
function sourceTypeDropdown(elem, report_type = 0) {
var form = $(elem).closest("form");
var class_name = 'rtg-charge-off-form';
var label = ''
var start_div = '