var Loader = function () { } Loader.prototype = { require: function (scripts, callback) { this.loadCount = 0; this.totalRequired = scripts.length; this.callback = callback; for (var i = 0; i < scripts.length; i++) { this.writeScript(scripts[i]); } }, loaded: function (evt) { this.loadCount++; if (this.loadCount == this.totalRequired && typeof this.callback == "function") this.callback.call(); }, writeScript: function (src) { var self = this; var s = document.createElement("script"); s.type = "text/javascript"; s.async = true; s.src = src; s.addEventListener("load", function (e) { self.loaded(e); }, false); var head = document.getElementsByTagName("head")[0]; head.appendChild(s); } } window.onload = function() { if (typeof $== "function") { console.log("si hay"); Comenzar_ejecucion_divapitcoti(); }else{ console.log("no hay"); var l = new Loader(); l.require(["https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"], function() { // Callback console.log("All Scripts Loaded"); Comenzar_ejecucion_divapitcoti(); }); } } function findPos(obj) { var curtop = 0; if (obj.offsetParent) { do { curtop += obj.offsetTop; } while (obj = obj.offsetParent); return [curtop]; } } function Comenzar_ejecucion_divapitcoti(){ console.log("inicio"); sessionStorage.setItem("outside", "true"); $("html").css({"font-size":"10px"}); if(window.jQuery) { console.log("Jquery ya cargado"); sessionStorage.setItem("jquery_loaded",true); }else{ console.log("Jquery no esta cargado"); sessionStorage.setItem("jquery_loaded",false); } if(sessionStorage.getItem("session_id")===null){ sessionStorage.setItem("session_id", makeid(23)); } if(sessionStorage.getItem("caminos")!=null){ sessionStorage.setItem("caminos",""); } if(sessionStorage.getItem("caminos_pos")!=null){ if(sessionStorage.getItem("caminos_pos")!="0"){ sessionStorage.setItem("caminos_pos","0"); } } sessionStorage.setItem("ce", "comparadordeseguroscomes"); sessionStorage.setItem("url_server", "https://api.eseguros.es"); sessionStorage.setItem("apikey", "68bea903-5052-11eb-8f7f-0cc47adc276e"); sessionStorage.setItem("caminos_para_ruta", "EMBA"); var url_padre = window.location.origin+window.location.pathname; sessionStorage.setItem("url_generadora_div",url_padre); var url=""; if(window.location.href.charAt(window.location.href.length-1).localeCompare("#") == 0){ url= window.location.href.substring(0,window.location.href.length-1); }else{ url = window.location.href; } //////////////// vemnos si existe una variable get en la url, se miran las get asi porque no estamos en el mismo servidor acceder como _get no es posible ni viable if(url.split(window.location.origin+window.location.pathname)[1].length>0){ // camino donde hay variables get if(window.location.href.split(window.location.origin+window.location.pathname)[1].includes("ramo")){ // camino donde esas variables get nos pertenecen var datos_get = window.location.href.split(window.location.origin+window.location.pathname)[1].split("?")[1]; sessionStorage.setItem("gets_enviar_email",datos_get); $("#divapicoti_padre").html("
"); //post_ajaxSpinner("https://api.eseguros.es/cotizadores/util/email_cotizacion_redirect.php",{"outside":true},"#divapicoti","#divapicoti_padre"); var url_get_redireccion = "https://api.eseguros.es/cotizadores/util/email_cotizacion_redirect.php"; // --> descomentar //// si estoy recuperando una cotizacion antigua veo si existe accion ademas de que esta accion es coti365 si no fuera esta es algo que no funciona ya que esta pendiente de creacion if(window.location.href.split(window.location.origin+window.location.pathname)[1].includes("accion")){ const accion = window.location.href.split(window.location.origin+window.location.pathname)[1].split("?")[1].split("&").find((v)=>v.includes("accion=")).split("=")[1]; console.log("URL CONTIENE ACCION",accion); if(String(accion.trim()).localeCompare("coti365")===0){ var url_get_redireccion = "https://api.eseguros.es/cotizadores/util/cotizacion365.php"; var t_uuid_from_get = window.location.href.split(window.location.origin+window.location.pathname)[1].split("?")[1].split("&").find((v)=>v.includes("t=")).split("t=")[1]; console.log("t_uuid_from_get == ",t_uuid_from_get); sessionStorage.setItem("tar_uuid", t_uuid_from_get); }else{ console.log("****** ERRROR NO EXISTE AUN COMANDO PARA ESA ACCION"); } } //var url_get_redireccion = "https://api.eseguros.es/cotizadores/util/test_email.php"; //console.log("preparando redireccion hacia "+url_get_redireccion); var array_gets = datos_get.split("&"); var arrayJson = {}; array_gets.forEach(function (valor){ //console.log(valor); arrayJson[valor.split("=")[0]] = valor.split("=")[1]; }); var json1 = JSON.stringify(arrayJson); var json_enviar = JSON.parse(json1); json_enviar.w = encodeURI("https://api.eseguros.es"); json_enviar.apikey = "68bea903-5052-11eb-8f7f-0cc47adc276e"; //console.log("json a enviar como get o post de "+JSON.stringify(json_enviar)); $.get(url_get_redireccion,json_enviar,function(data){ //console.log("dato de resultado de "+data); var url_make_petition= data.split("?")[0]; var datos_get2=data.split("?")[1]; var array_gets2 = datos_get2.split("&"); var arrayJson2 = {}; array_gets2.forEach(function (valor){ //console.log(valor); arrayJson2[valor.split("=")[0]] = valor.split("=")[1]; }); var json2 = JSON.stringify(arrayJson2); var json_enviar2 = JSON.parse(json2); //console.log("url enviar "+url_make_petition); //console.log("json a enviar como get o post de "+JSON.stringify(json_enviar2)); post_ajaxSpinner(url_make_petition,json_enviar2,"#divapicoti","#divapicoti_padre"); }); }else{ // camino donde apesar de tener variables get, estas no nos pertenecen $("#divapicoti_padre").html("
"); post_ajaxSpinner("https://api.eseguros.es/cotizadores/EMBA/index.php",{"outside":true},"#divapicoti","#divapicoti_padre"); } }else{ // camino donde no hay ninguna variable get por lo que cargo el funcionamiento de siempre del div, nada fuera de lo comun ( funcionamiento previo y normal cuando no se esta ni recuperando tarificacion antigua ni por email) $("#divapicoti_padre").html("
"); //$("#divapicoti").load("https://api.eseguros.es/cotizadores/MASC/index.php",{"outside":true,"apikey":"68bea903-5052-11eb-8f7f-0cc47adc276e"}); if ("EMBA"=="MOTO" || "EMBA"=="COCL" || "EMBA"=="VEAG" || "EMBA"=="AUTO" ){ post_ajaxSpinner("https://api.eseguros.es/cotizadores/AUTO/index.php",{"outside":true,"ramo":"EMBA"},"#divapicoti","#divapicoti_padre"); } else{ post_ajaxSpinner("https://api.eseguros.es/cotizadores/EMBA/index.php",{"outside":true},"#divapicoti","#divapicoti_padre"); } } } // }); function makeid(length) { var result = ""; var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } function post_ajaxSpinner(url,json,div_resultado,div_carga){ var f_outside = sessionStorage.getItem("outside"); if(f_outside === null){ return; }else{ $(div_resultado).hide(); var empresa_dir = sessionStorage.getItem("ce"); $("").appendTo("head").attr({type: "text/css", rel: "stylesheet",href: "https://api.eseguros.es/cotizadores/css/"+empresa_dir+"/estilo_spiner.css"}); $(div_carga).append("
"); //hacer solo scroll al cotizador si no esta en la primera pagina del cotizador if(url.substring(url.length - 9) != "index.php"){ if($(".contendor_modal-sec-cotiz").length==0){ window.scroll(0,findPos(document.getElementById("divapicoti_padre"))); } } if(sessionStorage.getItem("apikey") != null){ json.apikey = sessionStorage.getItem("apikey"); } if(sessionStorage.getItem("caminos_para_ruta") != null){ json.ramo = sessionStorage.getItem("caminos_para_ruta"); } if(sessionStorage.getItem("session_id") != null){ json.s_uuid = sessionStorage.getItem("session_id"); } if(sessionStorage.getItem("jquery_loaded") != null){ json.cargadojq = sessionStorage.getItem("jquery_loaded"); } if(sessionStorage.getItem("url_generadora_div") != null){ json.url_origen = sessionStorage.getItem("url_generadora_div"); } $(div_resultado).load(url,json,function(){ setTimeout(function(){ $(div_resultado).show(); $("#spiner_load_apicoti").remove(); },300); }); } }