const SOURCE = 'LOCD' const FORM_URL = 'https://bremus4-v1-218915104282.us-east1.run.app//form-intake' function getCookieValue(name) { const cookies = document.cookie.split(';'); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].trim(); if (cookie.startsWith(name + '=')) { return cookie.substring(name.length + 1); } } return null; } function SetLFUUID() { var LFUUID = uuidv4(); const cookies = document.cookie.split(';'); for (let i = 0; i < cookies.length; i++) { let cookie = cookies[i].trim(); if (cookie.startsWith("LFUUID=")) { console.log("Overwriting existing LFUUID cookie"); break; }} document.cookie = "LFUUID=" + LFUUID + "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/"; return LFUUID; } function checkInputs(inputIds) { const emptyFields = []; inputIds.forEach(id => { const input = document.getElementById(id); if (input && input.value.trim() === '') { emptyFields.push(id); } }); return { allFilled: emptyFields.length === 0, emptyFields: emptyFields }; } function shiftSteps(cur, next) { document.getElementById('loader').style.display = 'block'; setTimeout(function() { document.getElementById('loader').style.display = 'none'; document.getElementById(cur).style.display = 'none'; document.getElementById(next).style.display = 'block'; }, 400); } function step1() { if (checkInputs(['RequestedAmount']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['RequestedAmount']).emptyFields) return 'nah' } shiftSteps(1,2) document.cookie = `form_step=2; path=/`; SetLFUUID() const data = { source: SOURCE, requested_amount: document.getElementById("RequestedAmount").value, trk: getCookieValue('trk'), sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:1 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function step1_industry() { if (checkInputs(['RequestedAmount']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['RequestedAmount']).emptyFields) return 'nah' } shiftSteps(1,2) document.cookie = `form_step=2; path=/`; SetLFUUID() const data = { source: SOURCE, requested_amount: document.getElementById("RequestedAmount").value, trk: getCookieValue('trk'), sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:1 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function step2() { if (checkInputs(['UseOfFunds']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['UseOfFunds']).emptyFields) return 'nah' } shiftSteps(2,3) document.cookie = `form_step=3; path=/`; const data = { source: SOURCE, use_of_funds: document.getElementById("UseOfFunds").value, sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:2 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function step3() { if (checkInputs(['MostImportant']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['UseOfFunds']).emptyFields) return 'nah' } shiftSteps(3,4) const data = { source: SOURCE, use_of_funds: document.getElementById("MostImportant").value, sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:3 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function step1_d() { //this is for the contact form cta first step on home page if (checkInputs(['full_name','phone','email']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['RequestedAmount']).emptyFields) return 'nah' } SetLFUUID() const data = { source: SOURCE, requested_amount: document.getElementById("RequestedAmount").value, trk: getCookieValue('trk'), sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:1 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); window.location = '/apply-hcta' }) .catch(error => { console.error('Error:', error); }); } function step1_hcta() { // this if for the first step on the scheduled apply page after calendly call if (checkInputs(['RequestedAmount']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['RequestedAmount']).emptyFields) return 'nah' } shiftSteps(1,2) document.cookie = `form_step=2; path=/`; // SetLFUUID() const data = { source: SOURCE, requested_amount: document.getElementById("RequestedAmount").value, email: document.getElementById("cal_email").value, full_name: document.getElementById("cal_name").value, phone: document.getElementById("cal_phone").value, trk: getCookieValue('trk'), sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:1 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function step1_home() { if (checkInputs(['RequestedAmount']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['RequestedAmount']).emptyFields) return 'nah' } document.cookie = `form_step=2; path=/`; SetLFUUID() const data = { source: SOURCE, requested_amount: document.getElementById("RequestedAmount").value, trk: getCookieValue('trk'), sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:1 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); window.location = '/app/apply-b4' }) .catch(error => { console.error('Error:', error); }); } function step5() { if (checkInputs(['corporate_name','State']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['corporate_name', 'State']).emptyFields) return 'nah' } shiftSteps('5b',6) document.cookie = `form_step=5; path=/`; const data = { source: SOURCE, corporate_name: document.getElementById("corporate_name").value, state: document.getElementById("State").value, sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:5 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function step4() { if (checkInputs(['Phone','Email', 'Full_Name']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['Phone','Email', 'Full_Name']).emptyFields) return 'nah' } // shiftSteps(5,6) const data = { source: SOURCE, phone: document.getElementById("Phone").value, email: document.getElementById("Email").value, full_name: document.getElementById("Name").value, sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:4 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); window.location = '/app/apply-complete-b4' }) .catch(error => { console.error('Error:', error); }); } function step15() { if (checkInputs(['Phone','Email', 'Full_Name']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['Phone','Email', 'Full_Name']).emptyFields) return 'nah' } // shiftSteps(5,6) const data = { source: SOURCE, phone: document.getElementById("phone").value, email: document.getElementById("email").value, full_name: document.getElementById("full_name").value, sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:1 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); window.location = '/apply' }) .catch(error => { console.error('Error:', error); }); } function step6() { if (checkInputs(['Tax_ID','Monthly_Gross', 'Business_Start_Year', 'Business_Address_Raw']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['Tax_ID','Monthly_Gross', 'Business_Start_Year', 'Business_Address_Raw']).emptyFields) return 'nah' } shiftSteps(6,7) document.cookie = `form_step=6; path=/`; const data = { source: SOURCE, tax_id: document.getElementById("Tax_ID").value, monthly_gross: document.getElementById("Monthly_Gross").value, business_start_year: document.getElementById("Business_Start_Year").value, business_address: document.getElementById("Business_Address_Raw").value, sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:6 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function step7() { if (checkInputs(['Full_Name_C','Home_Address_Raw', 'DOB', 'SSN']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['Full_Name_C','Home_Address_Raw', 'DOB', 'SSN']).emptyFields) return 'nah' } shiftSteps(7,8) document.cookie = `form_step=7; path=/`; const data = { source: SOURCE, full_name: document.getElementById("Full_Name_C").value, home_address: document.getElementById("Home_Address_Raw").value, dob: document.getElementById("DOB").value, ssn: document.getElementById("SSN").value, sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:7 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function send_file(file_send) { url_string = window.location.href var url = new URL(url_string); const formData = new FormData(); formData.append('file', file_send); formData.append('form',getCookieValue('LFUUID')) formData.append('name',file_send.name) formData.append('seed_id', getCookieValue('id')) formData.append('form_instance', getCookieValue('LFUUID')) const xhr = new XMLHttpRequest(); xhr.open('POST', 'https://bremus4-v1-218915104282.us-east1.run.app//file-intake'); xhr.send(formData); } function step4_ebook() { if (checkInputs(['Phone','Email', 'Full_Name']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['Phone','Email', 'Full_Name']).emptyFields) return 'nah' } SetLFUUID() // shiftSteps(5,6) const data = { source: SOURCE, phone: document.getElementById("Phone").value, email: document.getElementById("Email").value, full_name: document.getElementById("Name").value, sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:4 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); window.location = '/app/apply-complete-b4' }) .catch(error => { console.error('Error:', error); }); } function showElementAfterDelay(elementId, delay) { setTimeout(() => { const element = document.getElementById(elementId); if (element) { element.style.display = 'block'; // Show the element } }, delay); } function triggerTimer() { showElementAfterDelay('uplater', 5000); // Set timer for 5 seconds } function step1_stateReq() { if (checkInputs(['State']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['RequestedAmount']).emptyFields) return 'nah' } shiftSteps('1s','2s') document.cookie = `form_step=2; path=/`; SetLFUUID() const data = { source: SOURCE, industry: document.getElementById("State").value, trk: getCookieValue('trk'), sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:1 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function step2_stateReq() { if (checkInputs(['Monthly_Gross_Estimate']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['RequestedAmount']).emptyFields) return 'nah' } shiftSteps('2s','3s') document.cookie = `form_step=3; path=/`; const data = { source: SOURCE, monthly_gross: document.getElementById("Monthly_Gross_Estimate").value, trk: getCookieValue('trk'), sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:2 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function step3_stateReq() { if (checkInputs(['Time_In_Business_Estimate']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['RequestedAmount']).emptyFields) return 'nah' } shiftSteps('3s','4s') document.cookie = `form_step=4; path=/`; const data = { source: SOURCE, Time_In_Business_Estimate: document.getElementById("Time_In_Business_Estimate").value, trk: getCookieValue('trk'), sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:3 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); }); } function step4_stateReq() { if (checkInputs(['CreditScore']).allFilled == true) { console.log('All Filled') } else { console.log(checkInputs(['RequestedAmount']).emptyFields) return 'nah' } // shiftSteps('3s','4s') document.cookie = `form_step=4; path=/`; const data = { source: SOURCE, fico: document.getElementById("CreditScore").value, trk: getCookieValue('trk'), sid: getCookieValue('id'), form_instance: getCookieValue('LFUUID'), location: document.location.href, step:3 }; // Send data using fetch fetch(FORM_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { console.log('Success:', data); window.location = '/app/apply-continue' }) .catch(error => { console.error('Error:', error); }); } // mask for requested amount currency //var inputElement = document.getElementById('RequestedAmount'); //inputElement.addEventListener('input', function (e) { // // Get the input value // var inputValue = e.target.value; // inputValue = inputValue.replace('$', ''); // // // Remove any non-numeric characters except for commas // inputValue = inputValue.replace(/[^0-9,]/g, ''); // // // Remove leading zeros // inputValue = inputValue.replace(/^0+/, ''); // // // Replace commas with an empty string to remove them // inputValue = inputValue.replace(/,/g, ''); // // // Format the number with commas and add the dollar sign // inputValue = Number(inputValue).toLocaleString(); // // // Update the input value // e.target.value = '$'+inputValue; //}); //document.getElementById('phone').addEventListener('keyup', function(e) { // // let value = e.target.value.replace(/\D/g, ''); // // if (value.length > 10) { // value = value.slice(0, 10); // } // // value = value.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3'); // // e.target.value = value; //}); function NextSubmitFW(cur, next, data) { if (checkFields(cur) === true || cur === "3") { document.getElementById('loader').style.display = 'block'; setTimeout(function() { document.getElementById('loader').style.display = 'none'; document.getElementById(cur).style.display = 'none'; document.getElementById(next).style.display = 'block'; }, 400); // wait for 400 milliseconds var seed_id = getIdFromCookie(); var LFUUID = getLFUUIDFromCookie(); var currentPath = window.location.pathname; // Get the current URL path console.log(data, seed_id, LFUUID, currentPath); if (data == ':') { console.log('file upload'); } else { var payload = { data: data, seed_id: seed_id, step:cur, ip: GetIp(), LFUUID: LFUUID, current_path: currentPath // Add the current URL path to the payload }; fetch('https://us-central1-temporal-tiger-334020.cloudfunctions.net/Form-Intake-FastWaySBA', { method: 'POST', // or 'PUT' headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(payload), }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch((error) => { console.error('Error:', error); }); } } else { console.log('required') } }