; $(function() { $('body').on('mouseenter mouseleave','.dropdown',function(e){ var _d=$(e.target).closest('.dropdown'); _d.addClass('show'); setTimeout(function(){ _d[_d.is(':hover')?'addClass':'removeClass']('show'); },300); }); $('body').on('click', '#accept_cookies',function(e){ var consent_necessary = $("#consent_necessary").is(':checked'); var consent_preferences = $("#consent_preferences").is(':checked'); var consent_statistics = $("#consent_statistics").is(':checked'); var consent_marketing = $("#consent_marketing").is(':checked'); $.cookie('configure_consent', null, {path: '/'}); $.cookie('consent_necessary', (consent_necessary ? 'Y':'N'), { expires: 20*365, path: '/' }); $.cookie('consent_preferences', (consent_preferences ? 'Y':'N'), { expires: 20*365, path: '/' }); $.cookie('consent_statistics', (consent_statistics ? 'Y':'N'), { expires: 20*365, path: '/' }); $.cookie('consent_marketing', (consent_marketing ? 'Y':'N'), { expires: 20*365, path: '/' }); if ($(".cookies-advice").length) { $('.cookies-advice').hide(); location.reload(); } }); $('body').on('click', '.gohome-500error',function(e){ document.location.href = "https://www.legaltrust24.com/"+"co"; }); $('body').on('click','#first_free_advice',function(e){ document.location.href = "https://www.legaltrust24.com/"+"co"+"/primer-asesoramiento-gratuito"; }); $('body').on('click','.expand',function(e){ var _d=$(e.target).closest('.dropdown'); if (!_d.hasClass('show')) { $(_d).addClass('show'); } _d = $(_d).find('.dropdown-menu'); setTimeout(function(){ if (_d.is(':visible')) {$(_d).hide();} else {$(_d).show();} },300); }); $('body').on('click','.accept-legal',function(e){ check_accept_legal_warning(false, e); }); var unloadHandler = function(e){ $.ajax({ url: "https://www.legaltrust24.com/co/salir", type: 'post', success: function (response) { console.log("La llamada ajax fue con éxito!"); }, error: function(xhr, status, error) { console.log("Ocurrió un error: " + error); }, }); }; window.unload = unloadHandler; $(".button-dropdown i.dropdown-toggle").click(function() { var parent = $(this).closest( ".button-dropdown" ); var children = parent.find( ".dropdown-menu" ); if ($(this).hasClass("fa-plus-circle")) { parent.addClass("show"); $(children[0]).show(); $(this).removeClass("fa-plus-circle"); $(this).addClass("fa-minus-circle"); } else { parent.removeClass("show"); $(children[0]).hide(); $(this).removeClass("fa-minus-circle"); $(this).addClass("fa-plus-circle"); } }); $('label[for]').on('mouseenter',function() { var el = $(this).attr('for'); $('#'+el).addClass('hovered'); }); $('label[for]').on('mouseleave',function() { var el = $(this).attr('for'); $('#'+el).removeClass('hovered'); }); $('[data-toggle="tooltip"]').tooltip({ container: "body", }); $('body').on('click', '#contact_form .send',function(e){ var params = {"url" : $('#contact_form #navigate_link').val()}; params["csrf_legaltrust"] = $.cookie('csrf_cookie_legaltrust'); var $form = $("#contact_form"); $.ajax({ url: "https://www.legaltrust24.com/"+"co"+"/leer-url", type: 'post', data: params }).done(function(result) { url = result; if (url != 0) { $form.attr("action", "https://www.legaltrust24.com/"+url); $('#contact_form input[name="'+"csrf_legaltrust"+'"]').attr("value", $.cookie('csrf_cookie_legaltrust')); $form[0].submit(); } }).fail(function() { console.log("Ocurrió un error"); }); }); }); $(window).scroll(function() { var scrollTop = $(this).scrollTop(); if (scrollTop > 0 ){ $('.footer-contact').slideDown(350); } else { $('.footer-contact').slideUp(350); } }); function check_accept_legal_warning(required, e) { required = typeof required === typeof undefined ? true : required; var is_checked = $(".accept-legal").prop('checked'); if (required || is_checked) { set_alert('alert_legal_warning', !is_checked); } return is_checked; } function set_alert(id, state) { if (state) { $('#'+id).show(); } else { $('#'+id).hide(); } } function init_accept_legal() { $('.accept-legal').prop('checked', false); set_alert('alert_legal_warning', false); } function validate_value(ele, e) { var result = ""; var type = $(ele).data("quest-type"); switch (type) { case 'NUMBER': result = validate_number(ele, e); break; case 'DATE': case 'LONG_DATE': result = validate_date(ele, e); break; default: result = $(ele).val(); break; } return result; } function validate_number(ele, e) { var val = $(ele).val(); var min = $(ele).attr("min"); var max = $(ele).attr("max"); if (val !== "") { val = Number(val); if (typeof min !== typeof undefined && min !== false) { min = Number(min); if (min > 0 && val < min) { $(ele).val(min); val = min; } } if (typeof max !== typeof undefined && max !== false) { max = Number(max); if (max > 0 && val > max) { var newVal = val.toString(); newVal = newVal.substring(0, newVal.length-1); $(ele).val(newVal); val = newVal; } } } return val; } function validate_date(ele, e) { var val = $(ele).val(); if (val != null && val !== "") { var dt = val.split("/"); if (dt.length === 3) { var year = dt[2]; var month= dt[1]-1; var day = dt[0]; if (typeof gijgo_locale !== "undefined") { month = gijgo_locale === 'en-us' ? dt[0] - 1 : dt[1] - 1; day = gijgo_locale === 'en-us' ? dt[1] : dt[0]; } if (!isValidDate(year,month,day)) { val = ''; } } else { val = ''; } } return val; } function isValidDate(year, month, day) { var d = new Date(year, month, day); if (d.getFullYear() == year && d.getMonth() == month && d.getDate() == day) { return true; } return false; } function format_text_value(text) { if (text != null && text != '') { text = text.replace(/\r\n|\r|\n/g, '
'); text = text.replace(/ class="selected-background"/g, ''); } return text; } function ReplaceAt(input, search, replace, start, end) { return input.slice(0, start) + input.slice(start, end).replace(search, replace) + input.slice(end); } function pad(n, width, z) { z = z || '0'; n = n + ''; return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; } function my_escape(str) { var result = str; result = encodeURIComponent(result); result = result.replace(/'/g, "%27"); result = result.replace(/"/g, "%22"); return result; } function my_unescape(str) { var result = str; result = decodeURIComponent(result); result = result.replace(/%20/g, " "); result = result.replace(/%27/g, "'"); result = result.replace(/%22/g, '"'); return result; } function configure_cookies() { $.cookie('configure_consent', 'Y', {path: '/'}); location.reload(); } ; ;var empty_spacer = '________'; var dialog_login; var dialog_saved; $(function() { dialog_saved = $('#dialog_saved').dialog({ autoOpen: false }); dialog_login = $('#dialog_login').dialog({ autoOpen: false }); $('.viewer .scrollable').addClass('text-noselect'); $('.viewer').bind('contextmenu',function(e) { //return true; //DISABLE FOR TESTING }); if ($('#template_id').length) { var cnt = 1; $('.template.viewer .scrollable p').each(function() { var paragraphs_obfuscate = $('#paragraphs_obfuscate').val(); paragraphs_obfuscate = paragraphs_obfuscate.trim().split(','); if (paragraphs_obfuscate.length > 0) { for (i=0; i0 ? $('form').parent() : "body"; $('input[name="date"]').each(function() { $(this).datepicker({ locale: gijgo_locale, modal: true, header: true, footer: true, format: "dd/mm/yyyy", change: function (e) { after_changed_element(this, e); }, open: function (e) { $(this).attr('autocomplete', 'off'); } }); $(this).datepicker({ uiLibrary: 'bootstrap4' }); }); $('body').on('click','#btn_fill_template',function(e){ var seoName = $(".template #description").attr("data-seo-name"); var url = "https://www.legaltrust24.com/"+"co"+'/'+"preconfeccion"+'/'+seoName; $.ajax({ url: url, type: 'get', success: function (response) { /*console.log("La llamada ajax fue con éxito!");*/ url = "https://www.legaltrust24.com/"+"co"+"/"+"confeccion"+"/"+seoName+"/1"; location.href = url; }, error: function(xhr, status, error) { console.log("Ocurrió un error: " + error); }, }); }); $('body').on('keyup click input propertychange paste','.template .question',function(e){ var type = $(this).data("quest-type"); if (type!=='DATE' && type!=='LONG_DATE') { on_change_html_element(this, true, e); } else if (e.type == "keyup") { var k = e.keyCode; if ((k >= 48 && k <= 57) || (k >= 96 && k <= 105) || k == 111) { /*Do nothing*/ } else { var newVal = $(this).val(); newVal = newVal.toString(); newVal = newVal.substring(0, newVal.length-1); $(this).val(newVal); } } }); $('body').on('change','.template select.question',function(e){ change_dependents_elements(this, null, null, null, true, false, e); after_changed_element(this, e); }); $('body').on('focus','.template .question',function(e){ var id = $(this).attr("id"); if (id !== undefined) { scroll_to_element_pos(id); } }); $('body').on('blur','.template.questions .question',function(e){ var type = $(this).attr("quest-type"); if (type !== 'DATE' && type !== 'LONG_DATE') { after_changed_element(this, e); } }); $('body').on('click','#prev_questions',function(e){ var currentPag = $(this).data('current-pag'); save_draft_answers(currentPag-1, e); }); $('body').on('click','#next_questions',function(e){ var currentPag = $(this).data('current-pag'); save_draft_answers(currentPag+1, e); }); $('body').on('click','#finish_contract',function(e){ e.preventDefault(); var user_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; var user_datetime = getCurrentDatetime(); var template_id = $('#template_id').val(); var contract_id = $('#contract_id').val(); var jsonString = JSON.stringify(arrUserAnswers); var jsonAnswersLabels = JSON.stringify(arrUserAnswersLabels); var params = { "template_id" : template_id, "contract_id" : contract_id, "answers" : jsonString, "answers_labels" : jsonAnswersLabels, "user_timezone": user_timezone, "user_datetime": user_datetime }; var csrf = $.cookie('csrf_cookie_legaltrust'); params["csrf_legaltrust"] = csrf; $.ajax({ data: params, url: "https://www.legaltrust24.com/"+"co"+"/"+"finalizar-contrato", type: 'post', success: function (response) { /*console.log("La llamada ajax fue con éxito!");*/ location.href = "https://www.legaltrust24.com/"+"co"+"/"+"pagar-contrato"; }, error: function(xhr, status, error) { console.log("Ocurrió un error: " + error); }, }); }); $('body').on('click','#save_user_answers',function(e){ var user_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; var user_datetime = getCurrentDatetime(); var template_id = $('#template_id').val(); var contract_id = $('#contract_id').val(); var jsonString = JSON.stringify(arrUserAnswers); var jsonAnswersLabels = JSON.stringify(arrUserAnswersLabels); var params = { "template_id" : template_id, "contract_id" : contract_id, "answers" : jsonString, "answers_labels" : jsonAnswersLabels, "user_timezone": user_timezone, "user_datetime": user_datetime }; var csrf = $.cookie('csrf_cookie_legaltrust'); params["csrf_legaltrust"] = csrf; /*console.log(params);*/ $.ajax({ data: params, url: "https://www.legaltrust24.com/"+"co"+"/"+"guardar-contrato", type: 'post', success: function (response) { /*console.log("La llamada ajax fue con éxito!");*/ /*console.log(response);*/ var mydata = JSON.parse(response); if (mydata.result === 1) { dialog_saved.open(); } else { dialog_login.open(); $('body').on('click','#dialog_login .accept',function(e){ location.href = "/"+mydata.url; }); } }, error: function(xhr, status, error) { console.log("Ocurrió un error: " + error); }, }); }); $('body').on('click', '#dialog_saved button#accept',function(e){ dialog_saved.close(); location.href = "https://www.legaltrust24.com/"+"co"+"/"+"mis-contratos"; }); $('body').on('mouseover','label',function(e){ e.preventDefault(); var code = $(this).attr('name'); $('#qgroup_'+code).addClass('selected-background'); }); $('body').on('mouseout','label',function(e){ e.preventDefault(); var code = $(this).attr('name'); $('#qgroup_'+code).removeClass('selected-background'); }); $('body').on('click','#btn_download_word',function(e){ var contractId = $('#contract_id').val(); location.href = "https://www.legaltrust24.com/"+"co"+"/"+"descargar-contrato-word"+"/"+contractId; }); $('body').on('click','#btn_download_pdf',function(e){ var contractId = $('#contract_id').val(); location.href = "https://www.legaltrust24.com/"+"co"+"/"+"descargar-contrato-pdf"+"/"+contractId; }); $('body').on('click','#btn_create_contract',function(e){ location.href = "https://www.legaltrust24.com/"+"co"+"/"+"confeccion"; }); $('body').on('submit', '#form_payment', function(e){ var accept = check_accept_legal_warning(true,e); if (accept) { return true; } else { e.preventDefault(); return false; } }); $('body').on('mouseover','.text-obfuscate',function(e){ e.preventDefault(); $(".obfuscate-tooltip").show(); var position = $(this).position(); if (position != null) { var pTop = position.top; pTop = (pTop < 65) ? -50 : pTop-65; $(".obfuscate-tooltip").css({top: pTop}); } }); $('body').on('mouseout','.text-obfuscate',function(e){ e.preventDefault(); $(".obfuscate-tooltip").hide(); }); $('body').on('click','#my_contracts',function(e){ location.href = "https://www.legaltrust24.com/"+"co"+"/"+"mis-contratos"; }); if ($(".progressbar").length) { var iniQuestion = $("#ini_question").val(); var progress = (iniQuestion/numQuestions); progress = Math.ceil(progress*100); $(".progressbar").progressbar({ value: progress }); } init_accept_legal(); if ($('#num_pag').length && $('#num_pag').val() == 1) { check_select_questions_default_value(); } if (('.template.viewer .scrollable').length) { fill_template_viewer(); } //NOT MOVE TO FIRST FORM QUESTION //move_to_first_template_question(); if ($('#num_pag').length && $('#num_pag').val() > 1) { check_select_questions_default_value(); if (('.template.viewer .scrollable').length) { fill_template_viewer(); } } /* $(window).on('hashchange',function(){ check_is_confection_uri_and_hash_change(); }); check_is_confection_uri_and_hash_change(); */ if ($('#btn_fill_template').length && $(window).width() <= 991) { window.scroll(0, findPos(document.getElementById("btn_fill_template"))); } }); function check_select_questions_default_value() { $('.template select.question').each(function (e) { var val = $(this).val(); if (val !== "") { change_dependents_elements(this, null, null, null, false, true, e); after_changed_element(this, e); } }); } function check_is_confection_uri_and_hash_change() { var hash = window.location.hash; var is_confection = $('a.btn.confeccion-template').length; if(hash && is_confection > 0) { refresh_template_description(hash.substr(1)); } } function refresh_template_description(txt_search) { var params = { search: txt_search }; var csrf = $.cookie('csrf_cookie_legaltrust'); params["csrf_legaltrust"] = csrf; $('a.btn.confeccion-template').each(function() { $(this).removeClass('active'); var href = $(this).attr('href'); if (href.indexOf(txt_search) > 0) { $(this).addClass('active'); } }); var uri = "https://www.legaltrust24.com/"+"co"+"/"+"descripcion-plantilla"; $.ajax({ data: params, url: uri, type: 'post', success: function (response) { /*console.log("La llamada ajax fue con éxito!");*/ if (response !== null && response !== "") { var obj = JSON.parse(response); var title = (obj.name); var description = obj.description; var meta_keywords = obj.meta_keywords; var meta_description = obj.meta_description; $(document).attr("title", "LEGALTRUST24 - "+title); $("meta[name='keywords']").attr("content", meta_keywords); $("meta[name='description']").attr("content", meta_description); $(".template #title").html(title); $(".template #title").css("display", "block"); $(".template #description").addClass("flexcroll"); $(".template #description").html(description); $(".template #description").attr("data-seo-name", obj.seo_name); $(".template #btn_fill_template").removeClass("disabled").removeClass("btn-success"); $(".template #btn_fill_template").removeAttr("disabled"); if (!obj.has_questions) { $(".template #btn_fill_template").addClass("disabled"); $(".template #btn_fill_template").attr("disabled", "disabled"); $(".template #btn_fill_template").html("Próximamente"); } else { $(".template #btn_fill_template").addClass("btn-success"); $(".template #btn_fill_template").html("Pulsa aquí para comenzar y rellenar el modelo"); } $(".template #btn_fill_template").removeClass("d-none").addClass("d-display"); $(".template #steps").removeClass("d-none").addClass("d-display"); window.scroll(0, findPos(document.getElementById("btn_fill_template"))); } }, error: function(xhr, status, error) { console.log("Ocurrió un error: " + error); $(".template #description").html(""); $(".template #description").attr("seo-name", ""); $(".template #btn_fill_template") .removeClass("d-display").addClass("d-none"); }, }); } function scroll_to_element_pos(id) { var position = null; var offset = null; var viewer = $('.template.viewer .scrollable'); var prevTop = viewer.scrollTop(); var prevOffset = $(viewer).offset(); $('.scrollable label[name="'+id+'"]').each(function() { position = $(this).position(); offset = $(this).first().offset(); return false; }); if (position != null) { var top = position.top; /*viewer.animate({scrollTop: top});*/ newTop = offset.top - prevOffset.top + prevTop - 35; viewer.stop(true).animate({ scrollTop: newTop },600, function() { /*Animation complete.*/ }); } } function clean_all_answers_bgcolor() { $(".template.viewer .scrollable label").each(function() { $(this).removeClass("selected-background"); }); } function set_all_id_answers_bgcolor(id, type, fill_label, value, answer_labels) { var newValue = null; if (fill_label == 1) { $('.template.viewer .scrollable [name="'+id+'"]').each(function() { if (newValue === null) { newValue = value; $(this).addClass("selected-background"); if (newValue !== '' && newValue != empty_spacer) { $(this).removeClass('underline'); } if (type === 'NUMBER' && newValue !== '' && newValue != empty_spacer) { newValue = formatNumber(newValue); } } $(this).html(newValue); }); } newValue = null; if (answer_labels !== null && answer_labels.length > 0) { for (i = 0; i < answer_labels.length; ++i) { var elementName = answer_labels[i]['name']; var elementValue = answer_labels[i]['desc']; $('.template.viewer label[name="'+elementName+'"]').each(function() { newValue = elementValue; $(this).addClass("selected-background"); if (newValue !== '' && newValue != empty_spacer) { $(this).removeClass('underline'); } $(this).html(newValue); }); } } } function formatNumber(number) { var value = ''; if (number != null && number != '' && number != empty_spacer) { number = Number(number); decimals = (number % 1 != 0) ? 2: 0; value = number.toLocaleString("es-ES", {minimumFractionDigits: decimals}); } return value; } function formatTextDate(date) { var day = date.getDate(); var monthIndex = date.getMonth(); var year = date.getFullYear(); var event = new Date(Date.UTC(year, monthIndex, day, 0, 0, 0)); var options = { year: 'numeric', month: 'long', day: 'numeric' }; var result = (event.toLocaleDateString(gijgo_locale, options)); var day_nth = nth(day, gijgo_locale); if (day != day_nth) { result = result.replace(day+",", day_nth+","); } return result; } function nth(d, locale) { if (!locale.startsWith("en-")) { return d; } d = parseInt(d); if (d > 3 && d < 21) { return d+'th'; } switch (d % 10) { case 1: return d+"st"; case 2: return d+"nd"; case 3: return d+"rd"; default: return d+"th"; } } function get_template_viewer_panel(content) { $result = "
"+content+"
"; return $result; } function save_draft_answers(newPag, e) { var template_id = $('#template_id').val(); var contract_id = $('#contract_id').val(); var jsonString = JSON.stringify(arrUserAnswers); var jsonAnswersLabels = JSON.stringify(arrUserAnswersLabels); var params = {"template_id" : template_id, "contract_id" : contract_id, "answers" : jsonString, "answers_labels": jsonAnswersLabels, "csrf_legaltrust": $.cookie('csrf_cookie_legaltrust') }; var uri = "https://www.legaltrust24.com/"+"co"+"/guardar-borrador"; $.ajax({ data: params, url: uri, type: 'post', success: function (response) { /*console.log("La llamada ajax fue con éxito!");*/ get_template_questions(newPag); }, error: function(xhr, status, error) { console.log("Ocurrió un error: " + error); }, }); e.preventDefault(); } function get_template_questions(newPag) { var contractId = $('#contract_id').val(); var seoName = $("#template_id").attr("data-seo-name"); var uri = "https://www.legaltrust24.com/"+"co"+"/confeccion/"+seoName; if (contractId!==null && contractId!=='') { uri+= "/"+contractId; } uri+= "/"+newPag; location.href = uri; } function on_change_html_element(ele, dependsOnValue, e) { var a_fil = null, f_lbl = null, titl = null, dtitl = null; var type = $(ele).data("quest-type"); var def_val= $(ele).data("default-value"); var id = $(ele).attr("id"); var code = id; var value = validate_value(ele, e); var answer_labels = null; if (dependsOnValue && def_val!=null && def_val!='') { value = def_val; } var objRef = (type!=='MULTIPLE') ? $(ele) : $(ele).parents(".checkbox-group").eq(0); code = $(objRef).attr("id"); a_fil= $(objRef).data("auto-fill"); f_lbl= $(objRef).data("fill-label"); titl = $(objRef).data("title"); dtitl= $(objRef).data("detail-title"); switch (type) { case 'MULTIPLE': val = get_all_multiple_values(code); value = get_all_multiple_labels(code); desc = get_all_multiple_descriptions(code); id = code; if (desc != null && desc.trim() != '') { value = desc; } break; case 'LIST': var opt = $("#"+id+" option:selected"); val = $(opt).val(); value = $(opt).text(); desc = $(opt).attr('data-description'); if (val == null || val.trim() == '') { value = ''; } else if (typeof desc !== 'undefined' && desc !== false && desc !== null && desc.trim() !== '') { if (desc == '_blank') { value = ''; } else { value = desc; } } /*Answer labels*/ answer_labels = get_answer_labels(opt); break; case 'LONG_DATE': value = format_long_date(value); break; default: break; } if (dependsOnValue) { value = get_element_value(code, type, titl, dtitl, a_fil, value); } set_all_id_answers_bgcolor(id, type, f_lbl, value, answer_labels); } function get_all_multiple_values(code) { var result = ""; $("input[name='"+code+"']:checked").each(function() { result += (result !== "") ? "," : ""; result += $(this).val(); }); return result; } function get_all_multiple_labels(code) { var result = ""; $("input[name='"+code+"']:checked").each(function() { result += (result !== "") ? "
" : ""; result += $(this).closest("label").text().trim(); }); return result; } function get_all_multiple_descriptions(code) { var result = ""; $("input[name='"+code+"']:checked").each(function() { result += (result !== "") ? "
" : ""; result += $(this).attr('data-description'); }); return result; } function fill_element_value(id, value) { if (typeof arrUserAnswers !== 'undefined') { for (var i in arrUserAnswers) { var answer = arrUserAnswers[i]; var code = answer[0]; if (code !== id) { var type = answer[1]; var text = my_unescape(answer[3]); $('label[name="'+code+'"]').each(function() { $(this).html(text); }); } } } } function get_element_value(code, type, title, detail_title, auto_fill, value) { var newValue = (value==null || value=='') ? (auto_fill==1 ? empty_spacer : '') : value; if (type === 'LIST' && has_children_labels(newValue)) { newValue = fill_children_labels(newValue); } if (title!=null && title!='' && newValue!=='' && newValue!== empty_spacer) { newValue = ""+title.toUpperCase()+""+ "
"+ detail_title+ "
"+"
"+ newValue; } return newValue; } function has_children_labels(value) { if (value !== '' && value.length > 0) { return (value.indexOf("= 0); } return false; } function fill_children_labels(value) { var newValue = value; var ini = 0; while (true) { var iLabel=newValue.indexOf('', fName); len = eLabel-(iLabel+2); oldText = newValue.substr(iLabel+2, len); newText = get_first_valid_label_text(id); newValue = ReplaceAt(newValue, oldText, newText, iLabel, eLabel); ini = eLabel+9; if (ini > newValue.length) { break; } } else { break; } } return newValue; } function get_first_valid_label_text(id) { var newText = empty_spacer; $('label[name="'+id+'"]').each(function() { var text = $(this).html(); if (text !== empty_spacer) { newText = text; return false; } }); return newText; } function after_changed_element(obj, e) { on_change_html_element(obj, true, e); set_array_user_answers(obj, true, false, null, e); } function set_array_user_answers(obj, replaceParent, textException, valTextException, e) { var q_id = id = val = null; var type = $(obj).data("quest-type"); if (type === 'MULTIPLE') { var parent = $(obj).parents(".checkbox-group").eq(0); q_id = $(parent).data("question-id"); id = $(parent).attr("id"); val = get_all_multiple_values(id); } else { q_id = $(obj).data("question-id"); id = $(obj).attr("id"); val = $(obj).val(); opt = $("#"+id+" option:selected"); /* Answer labels*/ var answer_labels = get_answer_labels(opt); if (answer_labels !== null && answer_labels.length) { set_array_user_answer_labels(q_id, id, answer_labels); } } if (id!==undefined && id!==null && id!=='') { val = format_text_value(val); var text = ''; $('label[name="'+id+'"]').each(function() { text = $(this).html(); text = format_text_value(text); return false; }); if (text.trim() === '' && textException && valTextException !== null) { text = format_text_value(valTextException); } val = my_escape(val); text= my_escape(text); arrUserAnswers[q_id] = "";/*Clean*/ arrUserAnswers[q_id] = [id,type,val,text]; /*Replace Text in parent container*/ if (replaceParent) { set_parent_item_user_answer(q_id, id); } } } function set_array_user_answer_labels(q_id, id, answer_labels) { for (i=0; i < answer_labels.length; i++) { var name = answer_labels[i]['name']; var val = my_escape(answer_labels[i]['desc']); arrUserAnswersLabels[name] = "";/*Clean*/ arrUserAnswersLabels[name] = [name, val]; } } function get_answer_labels(obj) { var answer_labels = null; if (obj !== null && obj.length) { var attrib_names = [].filter.call(obj[0].attributes, function (at) { return /^data-label-name-/.test(at.name); }); var attrib_descs = [].filter.call(obj[0].attributes, function (at) { return /^data-label-desc-/.test(at.name); }); if (attrib_names.length && attrib_descs.length) { answer_labels = []; for (var i = 0; i < attrib_names.length; i++) { answer_labels.push({name: attrib_names[i].value, desc: attrib_descs[i].value}); } } } return answer_labels; } function set_parent_item_user_answer(q_id, id) { var parent = get_parent_container(q_id, id); if (parent != null) { q_id = parent.question_id; id = parent.code; $('label[name="'+id+'"]').each(function() { text = $(this).html(); text = format_text_value(text); return false; }); text = my_escape(text); if (typeof arrUserAnswers[q_id] == 'undefined') { } else { arrUserAnswers[q_id][3] = text; } } } function get_parent_container(q_id, id) { if (typeof arrTemplateQuestions!=='undefined') { var str = $('#dependent_questions').val(); var list = JSON.parse(str); for (i = 0; i < list.length; i++) { var item = list[i]; if (item.id == q_id) { return get_template_question("question_id", item.depends_on); } } } return null; } function get_template_question(attribute, dependsOn) { var result = null; for (i=0; i= 0) { $(this).addClass("selected-background"); } }); } function list_label_for() { var list = []; $('.template.questions label').each(function() { list.push($(this).attr('for')); }); return list; } function format_long_date(value) { if (value!==null && value!=='' && undefined!==value) { var from = value.split("/"); value = ''; if (from.length == 3) { var year = from[2]; var month = gijgo_locale === 'en-us' ? from[0]-1 : from[1]-1; var day = gijgo_locale === 'en-us' ? from[1] : from[0]; var date = new Date(year, month, day); value = isNaN(date.getTime())?'':formatTextDate(date); } } else { value = ''; } return value; } function move_to_first_template_question(e) { if ($('.form-control.question').length) { $('.form-control.question').each(function() { $(this).focus(); return false; }); } } function get_obfuscate_tooltip() { var str = "
"+ "Los párrafos borrosos se visualizarán en la descarga"+ "
"; return str; } function getCurrentDatetime() { var date = new Date(); var cur_day = date.toJSON().slice(0,10).replace(/-/g,'/'); var hours = date.getHours(); var minutes = date.getMinutes(); var seconds = date.getSeconds(); if (hours < 10) { hours = "0" + hours; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; } return cur_day + " " + hours + ":" + minutes + ":" + seconds; } /*Finds y value of given object*/ function findPos(obj) { var curtop = 0; if (obj.offsetParent) { do { curtop += obj.offsetTop; } while (obj = obj.offsetParent); return [curtop]; } } ;