let fms = ""; let un = -1; const domain = "https://renetsheet.leadmarketer.com"; function onLoadBody() { let _dm = document.location.hostname; let encKey = "U2FsdGVkX1923T3IdMWknL"; let text = _dm; let iv = CryptoJS.enc.Hex.parse("FgLFXEr1MZl2mEnk"); var encryptedText = CryptoJS.AES.encrypt(text, encKey, { iv: iv, }).toString(); let payload = { dm: encryptedText, }; const url = `${domain}/calculation/calcjs/fm`; const xhttp = new XMLHttpRequest(); xhttp.onload = function () { const result = JSON.parse(this.response); const { status, data, message } = result; if (status == false) { window.alert(message); return; } const unit = parseInt(data[3]); un = unit; const fmLen = parseInt(data.substring(4, 7)); const fm = data.substring(17, 17 + fmLen); fms = fm; }; xhttp.open("POST", url); xhttp.setRequestHeader("Content-type", "application/json"); xhttp.send(JSON.stringify(payload)); } function getConstants() { const url = `${domain}/calculation/calcjs/getconstants`; const xhttp = new XMLHttpRequest(); xhttp.onload = function () { const result = JSON.parse(this.response); const { status, data, message } = result; if (status == false) { window.alert(message); return; } const constants = data["constants"]; decryptConstants(constants); return; }; xhttp.open("GET", url); xhttp.send(); } function decryptConstants(constants) { const url = `${domain}/calculation/calcjs/decryptconstants`; const xhttp = new XMLHttpRequest(); xhttp.onload = function () { const result = JSON.parse(this.response); const { status, data, message } = result; if (status == false) { window.alert(message); return; } formulaList = data["constants"]; }; xhttp.open("POST", url); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send(`constants=${constants}`); } !(function () { var originalPrice = document.getElementById("js-in-original-home-price"); var currentHomePrice = document.getElementById("js-in-current-home-price"); var newHomePrice = document.getElementById("js-in-new-home-price"); var diffPrimaryReplace = document.getElementById( "js-out-diff-primary-replacement" ); var taxableValue = document.getElementById("js-out-taxable-value"); var withoutProp19 = document.getElementById("js-out-without-prop-19"); var withProp19 = document.getElementById("js-out-with-prop-19"); var withProp19730 = document.getElementById("js-out-with-prop-19-730"); var taxableValue730 = document.getElementById("js-out-taxable-value-730"); [ diffPrimaryReplace, taxableValue, withoutProp19, withProp19, withProp19730, taxableValue730, ].forEach(function (x) { if(x){ x.innerText = "0.00"; } }); var calculator = document.getElementById("prop-19-calculator"); var inputs = [originalPrice, currentHomePrice, newHomePrice]; inputs.forEach(function (x) { x.value = "0.00"; x.addEventListener("keyup", function () { // updateValues(); x.value = numFormat(removeFormat(x.value)); }); }); // newHomePrice.addEventListener('keypress', function(i) { // return createValidator(newHomePrice,i); // }); const options = { licenseKey: "gpl-v3", }; function doSecureCalc(valueList, formula) { for (var i = 0; i < formula.length; i++) { formula[i] = formula[i].replace(" ", "+"); } const data = [valueList, formula]; const hfInstance = HyperFormula.buildFromArray(data, options); let result = Array(); for (var i = 0; i < formula.length; i++) { result.push( hfInstance.getCellValue({ col: i, row: 1, sheet: 0, }) ); } return result; } function pafm(string, unit) { const fmLen = string.length; var tmpfmlist = []; for (var i = 0; i < fmLen; i += unit) { tmpfmlist.push(string.substring(i, i + unit)); } var fmlist = []; const listCount = tmpfmlist.length; for (var i = 0; i < listCount - 1; i++) { let tmp = tmpfmlist[listCount - i - 2]; fmlist.push(tmp); } fmlist.push(tmpfmlist[listCount - 1]); const fmString = fmlist.join("").toUpperCase(); var tmpFmList = fmString.split("$").map((x) => x.split("#")); return tmpFmList; } function updateValues() { if (fms == "" || un == -1) { return; } const formulaList = pafm(fms, un); let vTaxableValue = 0; let vTaxableValue730 = 0; let VwithProp19730 = 0; // declare const value const _newHomePrice = parseFloat(removeFormat(newHomePrice.value)); const _currentHomePrice = parseFloat(removeFormat(currentHomePrice.value)); const _originalPrice = parseFloat(removeFormat(originalPrice.value)); const _vTaxableValue = parseFloat(removeFormat(vTaxableValue)); // initial calc const formula1 = formulaList[0]; const valueList1 = [_newHomePrice, _currentHomePrice, _originalPrice]; const initFormulaRes = doSecureCalc(valueList1, formula1); diffPrice = initFormulaRes[0]; vTaxableValue = initFormulaRes[1]; vTaxableValue730 = initFormulaRes[2]; VwithProp19730 = initFormulaRes[3]; if (diffPrice < 0) { const formula2 = formulaList[1]; const valueList2 = [_originalPrice]; const conditionRes = doSecureCalc(valueList2, formula2); vTaxableValue = conditionRes[0]; vTaxableValue730 = conditionRes[1]; VwithProp19730 = conditionRes[2]; } if (vTaxableValue < 0) { const formula3 = formulaList[2]; const valueList3 = [_currentHomePrice, _originalPrice]; const conditionRes = doSecureCalc(valueList3, formula3); vTaxableValue = conditionRes[0]; vTaxableValue730 = conditionRes[1]; VwithProp19730 = conditionRes[2]; } // display calc const formula4 = formulaList[3]; const valueList4 = [ _newHomePrice, diffPrice, vTaxableValue, vTaxableValue730, VwithProp19730, ]; const displayRes = doSecureCalc(valueList4, formula4); if (withoutProp19) withoutProp19.innerText = numFormat(displayRes[0]); if (withProp19) withProp19.innerText = numFormat(displayRes[1]); if (withProp19730) withProp19730.innerText = numFormat(displayRes[2]); if (taxableValue) taxableValue.innerText = numFormat(displayRes[3]); if (taxableValue730) taxableValue730.innerText = numFormat(displayRes[4]); if (diffPrimaryReplace) diffPrimaryReplace.innerText = numFormat(displayRes[5]); console.log("displayRes:",displayRes); } function numFormat(x) { // if(x < Number.MAX_SAFE_INTEGER) { // return x.toString().replace(/\B(? max) { if ( (evt.keyCode >= 48 && evt.keyCode <= 57) || (evt.keyCode >= 96 && evt.keyCode <= 105) ) { evt.preventDefault(); } } } })();