async function _post(module, method, body={}, formData=false) { if (formData == true) { headers = {headers: { "Content-Type": "multipart/form-data" }} if (body.get("method") == null) { body.append("method", method) } body.append("token", ""); } else { headers = {headers: {'Content-Type': 'application/json'}} if (!("method" in body)) { body["method"] = method; } body["origin"] = window.location.href; body["token"] = "" body = JSON.stringify(body); } if ( module.toLowerCase().includes('tfadmin') || method == "error") { ep = 'https://24pound.com/'+module+'.cfc?method='+method; res = await axios.post(ep, body, headers) } else { ep = 'https://24pound.com/api/api.cfc?method=ep'; res = await axios.post(ep, body, headers) } return res; } async function validateAddress(newAddr, parent, callback, addrObj) { try { for (k in newAddr) { if (newAddr[k] === null) { newAddr[k] = ''; parent[addrObj][k] = ''; } } } catch(err) {} r = await _post("api/api", "validateAddress", {"shipTo": newAddr}); res = r.data; if (parent[addrObj].add1.match(/\b(P\.?O\.?)\b\D+\d+/g) || ( !!parent[addrObj].add2 && parent[addrObj].add2.match(/\b(P\.?O\.?)\b\D+\d+/g) ) || res.status == 'PO_BOX' ) { parent.$buefy.dialog.alert({ title: "PO Box Address", message: "Please Note: We are unable to ship to a PO Box address. Please enter a commercial or residential address to proceed. Residential addresses do not qualify for VIP shipment discount.", confirmText: "Go Back and Edit Address" }) return 0 } else if ("error" in res) { if (true === false) {console.log('')} if ( 'validatedBy' in parent[addrObj] && ( parent[addrObj].validatedBy == 'client' || parent[addrObj].validatedBy.match(/^\d+$/g) ) ) { parent[callback](parent[addrObj].validatedBy) } else { parent[addrObj].isResidential = 0 parent.$buefy.dialog.confirm({ title: "Address Validation Error", message: "We were unable to validate parent address.

Error: " + res.error + "

Please confirm the address is correct before proceeding or adjust if needed.", cancelText: "Go Back and Edit Address", confirmText: "Proceed with the Address", onConfirm: () => parent[callback]("client") }) } } else if (res.status == 'valid') { parent[addrObj].isResidential = res.type=='residential'? 1:0; if (res.type=='residential' && callback != 'quoteShipping' && !('validatedBy' in parent[addrObj]) ) { parent.$buefy.dialog.confirm({ title: "Residential Address", message: "This address validated as a Residential Address with the USPS and does not qualify for VIP Delivery. Please choose one of the following options.

FedEx determines if your address is commercial or residential. If you believe your address should qualify as a commercial address, please contact FedEx and let us know if there are any changes to it.

", cancelText: "Enter a different Shipping Address", confirmText: "Proceed with Residential Shipping Address", onConfirm: () => proceedValidation(parent, callback, newAddr, addrObj, res) }) } else { proceedValidation(parent, callback, newAddr, addrObj, res) } } return res; } async function proceedValidation(parent, callback, newAddr, addrObj, res) { if ('validatedBy' in parent[addrObj] && (parent[addrObj].validatedBy == 'api' || parent[addrObj].validatedBy == 'client' || parent[addrObj].validatedBy.match(/^\d+$/g)) ) { parent[callback](parent[addrObj].validatedBy) } else { if ('changed' in res && Object.keys(res.changed).length > 0) { console.log("ding changed") parent.$buefy.dialog.confirm({ title: "Address Recommendation", message: `

Address standardization suggested the following changes. Would you like to update this address?

Address Entered
${parent[addrObj].add1} ${parent[addrObj].add2 != ''? '
'+parent[addrObj].add2:''}
${parent[addrObj].city}, ${parent[addrObj].state} ${parent[addrObj].zip}

Suggested Address
${res.suggestedAddr.add1} ${res.suggestedAddr.add2!=''? '
'+res.suggestedAddr.add2:''}
${res.suggestedAddr.city}, ${res.suggestedAddr.state} ${res.suggestedAddr.zip}

`, cancelText: "Use Original", confirmText: "Apply Changes", onConfirm: () => updateVal(parent, callback, res.suggestedAddr, addrObj), onCancel: () => parent[callback]("client") }) } else { parent[callback]("api") } } return res; } function updateVal(parent, callback, newAddr, addrObj) { for (k in newAddr) { parent[addrObj][k] = newAddr[k] } parent[addrObj]["acceptedSuggestions"] = true; parent[callback]("api") return res } function showBody() { document.getElementById("spacer").style.display="none"; document.getElementById("spacer").style.visibility="hidden"; document.getElementById("app").style.display="block"; document.getElementById("app").style.visibility="visible"; } function formData(obj) { let fd = new FormData(); for (k in obj) { fd.append(k, obj[k]); } return fd; } function scrollToTop() { window.scrollTo({ top: 0, behavior: 'smooth' }); } function newDate(dstr) { return (new Date(dstr)).toLocaleDateString("en-US") } var formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', }); function formatPhone(v) { vorig = v; if (!v) { return false; } if (v.endsWith(")") || v.endsWith("-")) { return false; } v = v.replace(/\D/g, "") if (v.length == 0 || v.length == 3 || v.length == 6) { return false; } p = "("+v.slice(0,3) if (v.length>2) { p += ") "+v.slice(3,6); } if (v.length>5) { p += "-"+v.slice(6,10); } if (vorig == p) { return false; } return p; } function toTitleCase(str) { return str.replace( /\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); } ); } function printDiv(divName) { var printContents = document.getElementById(divName).innerHTML; w=window.open(); w.document.write(printContents); w.print(); w.close(); } const stateAbbrev = ['AK','AL','AR','AZ','CA','CO','CT','DC','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY']; const states = ['AK','AL','AR','AZ','CA','CO','CT','DC','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY']; function showMore() { var dots = document.getElementById("dots"); var moreText = document.getElementById("more"); var btnText = document.getElementById("myBtn"); if (dots.style.display === "none") { dots.style.display = "inline"; btnText.innerHTML = "Read more"; moreText.style.display = "none"; } else { dots.style.display = "none"; btnText.innerHTML = "Read less"; moreText.style.display = "inline"; } } function downloadText(filename, text) { var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute('download', filename); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); } function checkLuhn(cardNo) { var s = 0; var doubleDigit = false; for (var i = cardNo.length - 1; i >= 0; i--) { var digit = +cardNo[i]; if (doubleDigit) { digit *= 2; if (digit > 9) digit -= 9; } s += digit; doubleDigit = !doubleDigit; } return s % 10 == 0; } function validateCardNo(no) { if (no != null) { no = no.replace(/\D/g, ''); return (no && checkLuhn(no) && no.length == 16 && (no[0] == 4 || no[0] == 5 && no[1] >= 1 && no[1] <= 5 || (no.indexOf("6011") == 0 || no.indexOf("65") == 0)) || no.length == 15 && (no.indexOf("34") == 0 || no.indexOf("37") == 0) || no.length == 13 && no[0] == 4) } } function viewPaymentStr(pmt) { msg = ""; ttl = "Payment info for " + pmt.userID + "TFO-" + pmt.userOrderID; if (pmt.pmtType == "CC") { msg = '

Payment type: '; if (pmt.nickname != "") { msg += "(CC) "+pmt.nickname; } else { msg += pmt.cardType+" "+pmt.acctNo; } msg += "
Transaction date: "+pmt.paidDate+"
Transaction amount: "+pmt.amount+"

"; } else if (pmt.pmtType == "ACH") { msg = '

Payment type: '; if (pmt.nickname != "") { msg += "(ACH) "+pmt.nickname; } else { msg += "Bank Account "+pmt.acctNo; } msg += "
Transaction date: "+pmt.paidDate+"
Transaction amount: "+pmt.amount+"

"; } else if (pmt.pmtType == "test") { msg = "Test Order"; } return {"msg": msg, "ttl": ttl}; } async function checkEmail(e) { if (e.search(/[^@]+@[^@]+\.\w+/) == -1) { return {"fnStatus": "invalid"}; } else { response = await _post("api/api", "validateEmail", {"email":e}); if (response.data.fnStatus == 'exists') { return {"fnStatus": "exists"}; } } return {"fnStatus": "valid"}; } function encode(s) { // encode string to URL-safe base64 that ColdFusion can read return btoa(s).replace(/\+/g, '-') // Convert '+' to '-' .replace(/\//g, '_') // Convert '/' to '_' .replace(/=+$/, ''); // Remove ending '=' }