function linkJtfrm() {
    const params = new URLSearchParams(document.location.search);
    const newsol = params.get("newsol");
    
    if (newsol == "1") {
        let monto = document.getElementById("amount").value;
        let monto_inicial = document.getElementById("initial_amount").value;
        let plz = localStorage.getItem('plazo');
        let tic = localStorage.getItem('tic');
        let tcv = localStorage.getItem('tcv');
        let kic = localStorage.getItem('kic');
        let kcv = localStorage.getItem('kcv');
        let fecha = localStorage.getItem('fecha');
        let modalidad = localStorage.getItem('moda');
        let pagostotal = localStorage.getItem('pagostotal');
        let type = localStorage.getItem('typeinver');
        let submissionID = params.get('id');
        console.log(submissionID);

        const apiKey = '6e2676fa4067aecefdfae6fca7c4bb41';
        const apiUrl = `https://api.jotform.com/submission/${submissionID}?apiKey=${apiKey}`;
        
        // Use fetch to make the API call
        fetch(apiUrl)
            .then(response => {
                if (!response.ok) {
                    throw new Error('Network response was not ok ' + response.statusText);
                }
                return response.json();
            })
            .then(data => {
                if (!data.content) {
                    throw new Error('data.content is undefined');
                }

                const response = data.content.answers;
                const answerTextPairs = [];

                Object.entries(response).forEach(([key, value]) => {
                    if (value.hasOwnProperty("answer") && value.hasOwnProperty("text")) {
                        if (Object.prototype.toString.call(value.answer) === "[object Object]") {
                            value.answer = Object.values(value.answer).join(", ");
                        }
                        answerTextPairs.push([value.answer, value.text]);
                    }
                });

                const newDictionary = answerTextPairs.reduce((dictionary, [answer, text]) => {
                    dictionary[text] = answer;
                    return dictionary;
                }, {});

                // Assign the newDictionary object to jsonData
                const jsonData = newDictionary;

                // Log the jsonData to verify
                console.log(jsonData);
                
                // Ensure that "Nombre completo" is found
                const partsNombre = jsonData["Nombre completo"].split(",");
                const nombres = partsNombre[0];
                const apellido1 = partsNombre[1];
                const apellido2 = partsNombre[2];
                console.log(nombres, apellido1, apellido2);
                
                const NumTel = jsonData["Número de teléfono"];
                const email = jsonData["Email"];
                const domicilio = jsonData["Domicilio"];
                const partsDomicilio = domicilio.split(",");
                const calleNum = partsDomicilio[0];
                const colonia = partsDomicilio[2];
                const municipio = partsDomicilio[3];
                const cp = partsDomicilio[1];
                const estado = partsDomicilio[4];
                const rfc = jsonData["RFC"];

                const typeInver = jsonData["Tipo de inversionista"];
                if (typeInver == "Persona f\u00edsica") {
                    const regFisc = jsonData["Régimen fiscal"];
                    const eciv = jsonData["Estado Civil"];
                    const partsLugarO = jsonData["Lugar de Origen"].split(",");
                    const ciudadOrigen = partsLugarO[0];
                    const edoOrigen = partsLugarO[1];
                    const dateBirth = jsonData["Fecha de Nacimiento"];

                    window.location.href = `https://form.jotform.com/243167507287867?modalidad=${modalidad}&monto=${monto}&montoInicial=${monto_inicial}&plz=${plz}&tic=${tic}&tcv=${tcv}&kic=${kic}&kcv=${kcv}&pagostotal=${pagostotal}&fecha=${fecha}&type=${type}&typeInv=${typeInver}&nombrecompleto[first]=${nombres}&nombrecompleto[middle]=${apellido1}&nombrecompleto[last]=${apellido2}&tel=${NumTel}&email=${email}&domicilio[1]=${cp}&domicilio[0]=${calleNum}&domicilio[4]=${estado}&domicilio[2]=${colonia}&domicilio[3]=${municipio}&rfc=${rfc}&estadoCivil=${eciv}&regimenFiscal=${regFisc}&lorigen[0]=${ciudadOrigen}&lorigen[1]=${edoOrigen}&nacimiento=${dateBirth}`;
                } else if (typeInver == "Persona moral") {
                    const repLegal = jsonData["Nombre de Representante Legal"];
                    const razn = jsonData["Razón social"];
                    const econAct = jsonData["Principales Actividades Económicas"];
                    const feCon = jsonData["Fecha de Constitución"];

                    window.location.href = `https://form.jotform.com/243167507287867?modalidad=${modalidad}&monto=${monto}&montoInicial=${monto_inicial}&plz=${plz}&tic=${tic}&tcv=${tcv}&kic=${kic}&kcv=${kcv}&pagostotal=${pagostotal}&fecha=${fecha}&type=${type}&typeInv=${typeInver}&nombrecompleto[first]=${nombres}&nombrecompleto[middle]=${apellido1}&nombrecompleto[last]=${apellido2}&tel=${NumTel}&email=${email}&domicilio[1]=${cp}&domicilio[0]=${calleNum}&domicilio[4]=${estado}&domicilio[2]=${colonia}&domicilio[3]=${municipio}&rfc=${rfc}&nombreDe=${repLegal}&razonSocial=${razn}&activEcon=${econAct}&dateConst=${feCon}`;
                }
            })
            .catch(error => {
                console.error('Error:', error);
            });
    } else {
        let monto = localStorage.getItem('monto')
        let monto_inicial = localStorage.getItem('monto_inicial')
        let plz = localStorage.getItem('plazo');
        let tic = localStorage.getItem('tic');
        let fecha = localStorage.getItem('fecha');
        let modalidad = localStorage.getItem('moda');
        let pagostotal = localStorage.getItem('pagostotal');
        let compra = localStorage.getItem('compra')

        window.location.href = `https://form.jotform.com/243167507287867?modalidad=${modalidad}&monto=${monto}&montoInicial=${monto_inicial}&plz=${plz}&tic=${tic}&pagostotal=${pagostotal}&fecha=${fecha}&compra=${compra}`;
    }
}
