')
} else if (check.hasClass('goodlead')) {
check.append('
')
}
is_c_valid = false;
}
return is_c_valid;
}
function qRp_validate_question (question, display) {
var is_q_valid = true
if (display !== false) {
display = true;
}
if (display) {
question.find('.error').remove();
question.find('.success').remove();
}
var qkey = question.data('qid');
var type= question.data('type');
if (question.is(':visible')) {
switch (type) {
case 'choice':
var error = '';
if (question.find('.button').length && !question.find('.button.active').length) {
for (var i = 0; i < qRp_questions_walker.length; i++) {
if (qRp_questions_walker[i].name === qkey) {
if (qRp_questions_walker[i].errors !== "") {
for (var j = 0; j < qRp_questions_walker[i].errors.length; j++) {
if (qRp_questions_walker[i].errors[j].nobutton) {
error = qRp_questions_walker[i].errors[j].nobutton;
}
}
}
}
}
if (error) {
if (display) {
question.append('
' + error + '
')
}
is_q_valid = false
}
}
break;
case 'checkbox':
var error = '';
if (question.find('.checkbox_inner input[data-required=true]').length && !question.find('.checkbox_inner input').is(':checked')) {
for (var i = 0; i < qRp_questions_walker.length; i++) {
if (qRp_questions_walker[i].name === qkey) {
if (qRp_questions_walker[i].errors !== "") {
for (var j = 0; j < qRp_questions_walker[i].errors.length; j++) {
if (qRp_questions_walker[i].errors[j].notchecked) {
error = qRp_questions_walker[i].errors[j].notchecked;
}
}
}
}
}
if (error) {
if (display) {
question.append('
' + error + '
')
}
is_q_valid = false
}
}
break;
case 'custom':
var error = '';
if (question.find('.custom_inner input').length && !question.find('.custom_inner input').val()) {
for (var i = 0; i < qRp_questions_walker.length; i++) {
if (qRp_questions_walker[i].name === qkey) {
if (qRp_questions_walker[i].errors !== "") {
for (var j = 0; j < qRp_questions_walker[i].errors.length; j++) {
if (qRp_questions_walker[i].errors[j].nodata) {
error = qRp_questions_walker[i].errors[j].nodata;
}
}
}
}
}
if (error) {
if (display) {
question.append('
' + error + '
')
}
is_q_valid = false
}
}
if (question.find('.custom_inner input').length && question.find('.custom_inner input').val()) {
var ctype = question.find('.custom_inner input').data('type');
var cval = question.find('.custom_inner input').val();
var regex_string = '';
var error = '';
var success = '';
var checkerror = false;
if (ctype == 'text') {
regex_string = /[^0-9]/;
if (!cval.match(regex_string)) {
checkerror = true;
}
} else if (ctype == 'phone') {
regex_string = /^0((5|7)\d{8,8})$|^0((2|3|4|8|9)\d{7,7})$/;
if (!cval.match(regex_string)) {
checkerror = true;
}
} else if (ctype == 'idnum') {
regex_string = /^\d{9,9}$/;
if (!cval.match(regex_string)) {
checkerror = true;
}
} else if (ctype == 'sum') {
if (parseInt(cval) <= 0) {
checkerror = true;
}
}
if (checkerror) {
for (var i = 0; i < qRp_questions_walker.length; i++) {
if (qRp_questions_walker[i].name === qkey) {
if (qRp_questions_walker[i].errors !== "") {
for (var j = 0; j < qRp_questions_walker[i].errors.length; j++) {
if (qRp_questions_walker[i].errors[j].wrongdata) {
error = qRp_questions_walker[i].errors[j].wrongdata;
}
}
}
}
}
}
for (var i = 0; i < qRp_questions_walker.length; i++) {
if (qRp_questions_walker[i].name === qkey) {
if (qRp_questions_walker[i].success !== "") {
success = qRp_questions_walker[i].success
}
}
}
if (error) {
if (display) {
question.append('
' + error + '
')
}
is_q_valid = false
} else {
if (display) {
question.append('
' + success + '
');
}
}
}
if (question.find('.custom_inner .dateselect_wrapper').length) {
var answer = question.find('.answer_val').val();
if (answer === '##-##-##') {
for (var i = 0; i < qRp_questions_walker.length; i++) {
if (qRp_questions_walker[i].name === qkey) {
if (qRp_questions_walker[i].errors !== "") {
for (var j = 0; j < qRp_questions_walker[i].errors.length; j++) {
if (qRp_questions_walker[i].errors[j].nodata) {
error = qRp_questions_walker[i].errors[j].nodata;
}
}
}
}
}
}
if (answer.indexOf('##')>= 0) {
for (var i = 0; i < qRp_questions_walker.length; i++) {
if (qRp_questions_walker[i].name === qkey) {
if (qRp_questions_walker[i].errors !== "") {
for (var j = 0; j < qRp_questions_walker[i].errors.length; j++) {
if (qRp_questions_walker[i].errors[j].wrongdata) {
error = qRp_questions_walker[i].errors[j].wrongdata;
}
}
}
}
}
}
if (error) {
if (display) {
question.append('
' + error + '
')
}
is_q_valid = false
}
}
break;
case 'slider':
var error = '';
if (question.find('.answer_val').length && !question.find('.answer_val').val()) {
for (var i = 0; i < qRp_questions_walker.length; i++) {
if (qRp_questions_walker[i].name === qkey) {
if (qRp_questions_walker[i].errors !== "") {
for (var j = 0; j < qRp_questions_walker[i].errors.length; j++) {
if (qRp_questions_walker[i].errors[j].nodata) {
error = qRp_questions_walker[i].errors[j].nodata;
}
}
}
}
}
if (error) {
if (display) {
question.append('
' + error + '
')
}
is_q_valid = false
}
}
break;
}
}
return is_q_valid;
}
function qRp_question_after_change(screen,question,toanimate) {
if (toanimate !== true) {
toanimate = false;
}
qRp_questions_appearance(screen, toanimate);
qRp_send_question_datalayer(question);
}
function qRp_send_question_datalayer(question) {
var qkey = question.data('qid');
for (var i = 0; i < qRp_questions_walker.length; i++) {
if (qRp_questions_walker[i].name === qkey) {
if (qRp_questions_walker[i].datalayer) {
var dataLayer = window.dataLayer || [];
dataLayer.push({
'event': qRp_questions_walker[i].datalayer
});
}
}
}
}
function qRp_send_screen_datalayer(screen) {
var skey = screen.data('sid');
for (var i = 0; i < qRp_screens_walker.length; i++) {
if (qRp_screens_walker[i].name === skey) {
if (qRp_screens_walker[i].datalayer) {
var dataLayer = window.dataLayer || [];
dataLayer.push({
'event': qRp_screens_walker[i].datalayer
});
}
}
}
}
function qRp_GetURLParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
}
}
function qRp_loanerparam() {
if (GetURLParameter('loaner') != null) {
var loaner = GetURLParameter('loaner');
qRp_eventLoaner = decodeURIComponent(loaner);
}
}
function qRp_locationparam() {
if (GetURLParameter('location') != null) {
var location = GetURLParameter('location');
var loacation_obj = {};
loacation_obj.widget_location = location;
var dataLayer = window.dataLayer || [];
dataLayer.push(loacation_obj);
}
}
function qRp_addQueryString(url, queryString) {
// Check if the URL already has a query string.
if (url.indexOf('?') > -1) {
// Add the new query string parameter using '&'.
url += `&${queryString}`;
} else {
// Add the new query string parameter using '?'.
url += `?${queryString}`;
}
// Return the updated URL.
return url;
}
function qRp_scroll_to_top() {
var newtop = jQuery('#afteru_widget_qRp_23681').length ? jQuery('#afteru_widget_qRp_23681').offset().top : 0;
var animatetop = 60;
jQuery('body,html').animate({
scrollTop: newtop - parseInt(animatetop)
},500,"linear");
}
function qRp_send_lead(callback, current_step, only_save) {
var takanonA = jQuery('.check.takanon input[type=checkbox]').is(':checked');
var goodlLead = jQuery('.check.goodlead input[type=checkbox]').is(':checked');
var full_url = window.location.href;
var qRp_site_url = "widget.naorcredit.co.il";
var qRp_formid = "252";
var referer = document.referrer;
var lead_status = only_save ? 'savelead' : 'sendlead';
var qRp_params = [];
var qRp_field_params = [];
$.each(qRp_questions_walker, function(index,value) {
var qid = value.name;
var ans = $('#afteru_widget_qRp_23681 .answer_val[data-qid=' + qid +']').val() ? $('#afteru_widget_qRp_23681 .answer_val[data-qid=' + qid +']').val(): '';
qRp_params.push({"question" : qid, "value" : ans});
});
$.each(qRp_contant_fields_walker, function(index,value) {
qRp_field_params.push({"param" : value.parameter, "value" : value.data});
});
qRp_formerLeadId = qRp_GetURLParameter('formerLeadId');
if (!only_save) {
jQuery.ajax({
type: "POST",
url: "https://www.naorcredit.co.il/wp-admin/admin-ajax.php",
dataType: 'json',
data: {
'postid' : '23681',
'pageid' : '2717',
'takanonA' : takanonA,
'goodlLead' : goodlLead,
'params' : qRp_params,
'field_params' : qRp_field_params,
'site_url': qRp_site_url,
'formid': qRp_formid,
'url': full_url,
'leadId': qRp_leadId,
'status': qRp_status,
'logleadId': qRp_logleadId,
'referer': referer,
'finish': qRp_finish,
'eventLoaner': qRp_eventLoaner,
'formerLeadId': qRp_formerLeadId,
'action': 'send_lead_ajax'
},
success: function (result) {
if (result) {
console.log(result);
if (typeof result.leadId != 'undefined') {
if (result.leadId) {
qRp_leadId = result.leadId;
}
if (result.status) {
qRp_status = result.status;
}
if (result.logleadId) {
qRp_logleadId = result.logleadId;
}
if (result.curlcode) {
qRp_curlcode = result.curlcode;
}
}
}
jQuery.ajax({
type: "POST",
url: "https://www.naorcredit.co.il/wp-admin/admin-ajax.php",
dataType: 'json',
data: {
'postid' : '23681',
'pageid' : '2717',
'takanonA' : takanonA,
'goodlLead' : goodlLead,
'params' : qRp_params,
'field_params' : qRp_field_params,
'site_url': qRp_site_url,
'formid': qRp_formid,
'url': full_url,
'leadId': qRp_leadId,
'status': qRp_status,
'logleadId': qRp_logleadId,
'referer': referer,
'finish': qRp_finish,
'eventLoaner': qRp_eventLoaner,
'formerLeadId': qRp_formerLeadId,
'lead_status': lead_status,
'curlcode': qRp_curlcode,
'action': 'save_lead_ajax'
},
success: function (result) {
if (result) {
console.log(result);
if (typeof result.leadId != 'undefined') {
if (result.leadId) {
qRp_leadId = result.leadId;
}
if (result.logleadId) {
qRp_logleadId = result.logleadId;
}
}
/*if (typeof callback != 'undefined') {
callback(fName, current_step);
}*/
}
}
});
}
});
} else {
jQuery.ajax({
type: "POST",
url: "https://www.naorcredit.co.il/wp-admin/admin-ajax.php",
dataType: 'json',
data: {
'postid' : '23681',
'pageid' : '2717',
'takanonA' : takanonA,
'goodlLead' : goodlLead,
'params' : qRp_params,
'field_params' : qRp_field_params,
'site_url': qRp_site_url,
'formid': qRp_formid,
'url': full_url,
'leadId': qRp_leadId,
'status': qRp_status,
'logleadId': qRp_logleadId,
'referer': referer,
'finish': qRp_finish,
'eventLoaner': qRp_eventLoaner,
'formerLeadId': qRp_formerLeadId,
'lead_status': lead_status,
'curlcode': qRp_curlcode,
'action': 'save_lead_ajax'
},
success: function (result) {
if (result) {
console.log(result);
if (typeof result.leadId != 'undefined') {
if (result.leadId) {
qRp_leadId = result.leadId;
}
if (result.logleadId) {
qRp_logleadId = result.logleadId;
}
}
/*if (typeof callback != 'undefined') {
callback(fName, current_step);
}*/
}
}
});
}
}
})( jQuery );