Compara Asigurari

") > -1) { s = s.replace("", inj + "\n"); } else { s = s + inj; } return s; } f.srcdoc = srcdocFor(metaWith({}), "[]", null); root.appendChild(f); function dec(v){ if(v==null) return ""; try { return decodeURIComponent(String(v)); } catch(e){ return String(v); } } function detFZ(s){ return /fara|zero|^0$|^0 |0%|0 EUR/i.test(String(s||"")); } function buildOferte(rows, ld){ var veh = (((ld&&ld.marca)||"") + " " + ((ld&&ld.model)||"")).trim(); var groups = {}; var order = []; (rows||[]).forEach(function(o){ var key = String(o.asigurator||"") + "|" + String(o.id||o.nr_oferta||""); if(!groups[key]){ groups[key] = []; order.push(key); } groups[key].push(o); }); return order.map(function(k){ var rs = groups[k]; var f0 = rs[0]; var acop = null; try { var aj = dec(f0.acoperiri_json); if (aj && aj.charAt(0) === "{") acop = JSON.parse(aj); } catch(e){ acop = null; } var t = (f0.acoperiri_text||"") + " " + (f0.note||""); function has(re){ return re.test(t) ? "inclus" : "neacoperit"; } var acoperiri = { avarii: has(/avari/i), incendiu: has(/incendiu/i), fenomene: has(/fenomen|natur|grindin/i), furt_total: has(/furt/i), furt_partial: has(/furt/i), vandalism: has(/vandal/i), animale: has(/animal|rozat/i), geamuri: has(/geam|parbriz/i), anvelope: has(/anvelop/i), chei: has(/chei/i), asistenta: has(/asisten/i), inlocuire: has(/inlocuir|schimb/i), offroad: has(/off[ -]?road/i), accidente: has(/accident/i), apa_motor: has(/apa|hidro/i) }; if (acop) { Object.keys(acoperiri).forEach(function(kk){ if (typeof acop[kk] !== "undefined") { var v = acop[kk]; if (v === true) v = "inclus"; if (v === false) v = "neacoperit"; acoperiri[kk] = String(v); } }); } return { id: String(f0.id||f0.nr_oferta||""), asigurator: String(f0.asigurator||""), produs: "CASCO", vehicul: veh, brandColor: "", pdfUrl: "", sursaPdf: "", valabil: String(f0.valabil||""), note: String(f0.note||""), variante: rs.map(function(o, i){ var fz = detFZ(o.fransiza); var et = String(o.eticheta||"").trim(); if(!et){ et = fz ? "F\u0103r\u0103 fran\u0219iz\u0103" : ("Oferta " + (i+1)); } return { eticheta: et, nrOferta: String(o.nr_oferta||o.id||""), moneda: String(o.moneda||"EUR"), suma: parseFloat(o.suma_asigurata)||0, fransiza: String(o.fransiza||""), fransizaZero: fz, integral: parseFloat(o.prima)||0, rateN: parseInt(o.rate_n)||0, rateTotal: parseFloat(o.rate_total)||0 }; }), acoperiri: acoperiri }; }); } window.addEventListener("message", function(e){ if (!e.data || typeof e.data.cascoCode === "undefined") return; var code = String(e.data.cascoCode||"").trim(); fetch(API, { method: "POST", headers: {"Content-Type": "text/plain"}, body: JSON.stringify({ event: "cerere_oferte", lead_id: lead, access_code: code }) }) .then(function(r){ return r.json(); }) .then(function(d){ if (!d || !d.ok) { f.contentWindow.postMessage({ cascoError: "Cod incorect sau lead inexistent. Verifica ultimele 4 cifre din CNP/CUI." }, "*"); return; } var oferte = buildOferte(d.oferte, d.lead); var ud = d.lead ? (((d.lead.marca||"") + " " + (d.lead.model||"") + (d.lead.an ? " - " + d.lead.an : "")).trim()) : ""; var auto = "(function(){ function go(){ var i=[].slice.call(document.querySelectorAll(" + JSON.stringify("input") + ")).find(function(x){return x.type!==" + JSON.stringify("button") + " && x.type!==" + JSON.stringify("submit") + ";}); var b=[].slice.call(document.querySelectorAll(" + JSON.stringify("button, a, input") + ")).find(function(x){ return /vezi ofertele/i.test(x.textContent||x.value||String()); }); if(!i||!b){ setTimeout(go,300); return; } i.value = " + JSON.stringify(code) + "; b.click(); } if(document.readyState===" + JSON.stringify("loading") + ") document.addEventListener(" + JSON.stringify("DOMContentLoaded") + ", go); else go(); })();"; f.srcdoc = srcdocFor(metaWith({ accessCode: code, udtitle: ud }), JSON.stringify(oferte), auto); }) .catch(function(){ f.contentWindow.postMessage({ cascoError: "Eroare de conexiune. Incearca din nou." }, "*"); }); }); })();