var submitted = false;
var last_service = null;
if (typeof jQuery === 'undefined') {
var n=document.createElement("script");
n.src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
document.getElementsByTagName("script")[0].append(n);
console.log(document.getElementsByTagName("script")[0]);
setTimeout(function () {
jQuery(document).ready(function () {
jQuery.ajax({
url: "https://dev.my.checknatura.de/samples/form_create/13",
type: "get",
success: function (msg) {
jQuery('#cn-form-wrapper').html(msg);
}
});
});
}, 700);
} else {
jQuery(document).ready(function () {
jQuery.ajax({
url: "https://dev.my.checknatura.de/samples/form_create/13",
type: "get",
success: function (msg) {
jQuery('#cn-form-wrapper').html(msg);
}
});
});
}
function cn_form_save() {
var data1 = jQuery('#cn-form-1').serializeArray();
var data2 = jQuery('#cn-form-2').serializeArray();
var data3 = jQuery('#cn-form-3').serializeArray();
var data = data1.concat(data2, data3);
var loader_box = jQuery('.loading-state');
loader_box.show();
if (!submitted) {
//submitted = true;
jQuery.ajax({
url: "https://dev.my.checknatura.de/samples/form_save",
type: "get",
data: {
values: data
},
success: function (msg) {
loader_box.hide();
jQuery('#cn-form-site-4').html('
' + msg + '
');
console.log(msg);
cn_change_site(null, 4);
jQuery('#site-flow-display').hide()
}
});
} else {
loader_box.hide();
}
return false;
}
function toggleCompany(thisElement) {
var val = jQuery(thisElement).val();
if (val === 'company') {
jQuery('#tr-company').show();
jQuery('#cn-inp-company').attr('required', true);
} else {
jQuery('#tr-company').hide();
jQuery('#cn-inp-company').attr('required', false);
}
}
function cn_trigger_prev_click(thisElement) {
var prev = jQuery(thisElement).parents('tr').find('input[type=radio]');
prev.trigger('click');
}
function toggle_property_type(thisElement) {
var val = jQuery(thisElement).val();
if (val === 'other') {
jQuery('#property-type-other').attr('required', true);
} else {
jQuery('#property-type-other').attr('required', false);
}
}
function selectSubcat(thisElement) {
uncheckSubcats();
jQuery(thisElement).prop('checked', true);
var service_id = jQuery(thisElement).data('id');
var $radios = jQuery('input:radio[name=service]');
var parent_service = $radios.filter('[value=' + service_id + ']')
parent_service.prop('checked', true);
loadQuestions(parent_service);
}
function clickSite(thisElement, site) {
var aktSite = parseInt(jQuery('#site-flow-display').data('site'));
if(aktSite == 1 && site == 2) {
jQuery("#cn-form-1").find('input[type=submit]').trigger('click');
} else if(aktSite === 1 && site === 3) {
var form1 = document.querySelector("#cn-form-1");
var form2 = document.querySelector("#cn-form-2");
if (form2.checkValidity()) {
cn_change_site(aktSite, site);
} else if (form1.checkValidity()) {
cn_change_site(aktSite, 2);
jQuery("#cn-form-2").find('input[type=submit]').trigger('click');
} else {
jQuery("#cn-form-1").find('input[type=submit]').trigger('click');
}
} else if(aktSite === 2 && site === 3) {
jQuery("#cn-form-2").find('input[type=submit]').trigger('click');
} else {
cn_change_site(aktSite, site);
}
}
function checkSevice(thisElement) {
var val = jQuery(thisElement).val();
uncheckSubcats();
loadQuestions(thisElement);
var $radios = jQuery('.subcats-' + val);
$radios.prop('required', true);
}
function loadQuestions(thisElement) {
let service_id = $(thisElement).data('id');
if (last_service === service_id) {
return;
}
$.ajax({
url: "https://dev.my.checknatura.de/samples/request_questions/" + service_id,
data: {},
async: false,
success: function (data) {
let response = data;
console.log(response);
last_service = service_id;
$('#cn-form-questions').html(response.questions);
$('#cn-counter-property').html(response.number + 1);
$('#cn-counter-notice').html(response.number + 2);
$('[data-toggle="tooltip"]').tooltip();
}
});
}
function uncheckSubcats() {
var $radios = jQuery('.service-subcats');
$radios.prop('checked', false);
$radios.prop('required', false);
}
function cn_form_site_down(site) {
var nextsite = site - 1;
cn_change_site(site, nextsite);
}
function cn_change_site(aktSite, newSite) {
if (aktSite === null) {
jQuery('.cn-form-site').hide();
jQuery('#cn-form-site-' + newSite).show();
} else {
jQuery('#site-flow-display').data('site', newSite);
jQuery('#cn-form-site-' + aktSite).hide();
jQuery('#cn-form-site-' + newSite).show();
jQuery('.site-flow-item').removeClass('selected');
jQuery('#site-flow-item-' + newSite).addClass('selected');
}
}
function cn_form_site_up(site) {
var myform = document.querySelector("#cn-form-" + site);
var nextsite = site + 1;
if (myform.checkValidity() ) {
cn_change_site(site, nextsite);
return false;
}
return true;
}
function cn_show_footer(site) {
jQuery('#cn-form-footer').data('site', site);
jQuery('#cn-form-footer-site').html(site);
jQuery('.cn-form-site').hide();
jQuery('#cn-form-site-' + site).show();
jQuery('.cn-form-footer-site-changer').hide();
if (site > 1) {
jQuery('#cn-form-footer-site-down').show();
}
if (site < 3) {
jQuery('#cn-form-footer-site-up').show();
}
}