var rpx_grecaptcha_length=0;function rpx_resetCaptcha(){if("undefined"!=typeof grecaptcha){var e=jQuery(".g-recaptcha").length;e<rpx_grecaptcha_length&&(e=rpx_grecaptcha_length);for(var r=0;r<e;r++)grecaptcha.reset(r)}}function rpx_ajaxFailed(e,r){console.log(r),jQuery("#"+e).off("submit"),jQuery("#"+e+"_hasCaptcha").length>0?(alert(Joomla.JText._("COM_RAPIDCONTACTEX_FORM_AN_ERROR_OCCURRED")),rpx_resetCaptcha(),jQuery("#"+e+"rpx_loading").hide(),jQuery("#"+e).fadeIn()):jQuery("#"+e).submit()}function rpx_hasClass(e,r){return(" "+e.className+" ").indexOf(" "+r+" ")>-1}function rpx_getElementsByClassName(e,r){for(var t=new Array,a=0;a<e.elements.length;a++)rpx_hasClass(e.elements[a],r)&&t.push(e.elements[a]);return t}function rpx_checkForm(e){var r=!0,t=rpx_getElementsByClassName(document.getElementById(e),"required"),a=new Array,n=!1;if(t.length>0)for(var i=0;i<t.length;i++){var o=t[i];if(null===o.offsetParent);else if(jQuery(o).removeClass("rpx-error"),""==o.value){var l="";jQuery('label[for="'+jQuery(o).attr("id")+'"]').length>0&&(l=jQuery('label[for="'+jQuery(o).attr("id")+'"]').html()),void 0!==jQuery(o).attr("placeholder")&&""!=jQuery(o).attr("placeholder")&&(l=jQuery(o).attr("placeholder")),""!=l?a.push(Joomla.JText._("FIELD_S_IS_REQUIRED").replace("%s",l)):n=!0,jQuery(o).addClass("rpx-error"),r=!1}}return 0==r?(n?alert(Joomla.JText._("PLEASE_FILL_IN_ALL_REQUIRED_DETAILS")):alert(a.join("\n")),!1):(jQuery("#"+e+"_hasCaptcha").length>0&&grecaptcha&&1==jQuery(".g-recaptcha").length&&0==grecaptcha.getResponse().length&&(alert(Joomla.JText._("PLEASE_COMPLETE_THE_CAPTCHA")),r=!1),r)}function rpx_updateGroups(e,r,t,a,n,i){for(var o=r.split(",").indexOf(t),l=0;l<a;l++){var s=l<o&&"all"==i||l==o,p=document.getElementById(e+"rpx_group_"+n+"_"+l);p&&(s?p.setAttribute("style","display: block;"):p.removeAttribute("style"))}}function rpx_updateCheckboxGroup(e,r,t,a,n){t?(document.getElementById(e+"rpx_checkbox_group_"+a+"_"+n).setAttribute("style","pointer-events:all"),document.getElementById(e+"rpx_checkbox_group_"+a+"_"+n+"_overlay").setAttribute("style","display:none")):(document.getElementById(e+"rpx_checkbox_group_"+a+"_"+n).removeAttribute("style"),document.getElementById(e+"rpx_checkbox_group_"+a+"_"+n+"_overlay").removeAttribute("style"))}function updateSuggestionTexts(e,r,t){jQuery(".rpx_filter_text[data-form-id='"+e+"'][data-if-id='"+r+"']").each(function(){for(var e=jQuery(this).data("ifSign"),r=!1,a=jQuery(this).data("ifValue").split("|"),n=0;n<a.length;n++)"="==e?r=t.toLowerCase()==a[n].toLowerCase()||r:"*="==e&&(r=t.toLowerCase().includes(a[n].toLowerCase())||r);r?jQuery(this).fadeIn():jQuery(this).fadeOut()})}jQuery(document).ready(function(){jQuery(".rpx_field input, .rpx_field textarea, .rpx_field select").change(function(){updateSuggestionTexts(jQuery(this).data("formId"),jQuery(this).data("id"),jQuery(this).val()),""!=jQuery(this).val()&&jQuery(this).removeClass("rpx-error")}),jQuery(".rpx_field textarea").on("input",function(){updateSuggestionTexts(jQuery(this).data("formId"),jQuery(this).data("id"),jQuery(this).val())}),jQuery(".rpx_form").on("submit",function(e){var r=jQuery(this).attr("id");rpx_checkForm(r)?(void 0!==jQuery("#"+r).attr("action")&&(jQuery("#"+r).off("submit"),jQuery("#"+r).submit()),jQuery("#"+r).hide(),jQuery("#"+r+"rpx_loading").fadeIn(),jQuery.ajax({type:"POST",url:Joomla.getOptions("system.paths").base+"/index.php?option=com_rapidcontactex&task=ajax.post&t="+Math.random(),data:new FormData(jQuery("#"+r)[0]),dataType:"json",processData:!1,contentType:!1}).done(function(e){if(console.log(e),e.hasOwnProperty("action"))if("success"==e.action&&e.hasOwnProperty("page_text"))jQuery("#"+r+"rpx_loading").hide(),jQuery("#"+r).parent().html(e.page_text),e.hasOwnProperty("redirect_target")&&(window.location=e.redirect_target);else if("error"==e.action&&e.hasOwnProperty("errors")){for(var t in jQuery("#"+r).find(".rpx_inline_error").empty(),jQuery("#"+r+" .rpx_msg").empty(),e.errors){if(e.errors.hasOwnProperty(t))if(jQuery("#"+t).length>0)0==(a=jQuery("#"+t).parent().siblings(".rpx_inline_error")).length&&(jQuery("#"+t).parent().parent().append('<div class="rpx_inline_error"></div>'),a=jQuery("#"+t).parent().siblings(".rpx_inline_error")),a.html(e.errors[t]);else if(jQuery("[id^='"+t+"']").length>0){0==(a=jQuery("[id^='"+t+"']").first().parent().siblings(".rpx_inline_error")).length&&(jQuery("[id^='"+t+"']").first().parent().parent().append('<div class="rpx_inline_error"></div>'),a=jQuery("[id^='"+t+"']").first().parent().siblings(".rpx_inline_error")),a.html(e.errors[t])}else if(t==r+"rpx_anti_spam_answer"&&jQuery("#"+r+"_hasCaptcha").length>0){var a,n=jQuery("#"+r).find(".rpx_field_captcha");if(n.length)0==(a=n.find(".rpx_inline_error")).length&&(n.append('<div class="rpx_inline_error"></div>'),a=n.find(".rpx_inline_error")),a.html(e.errors[t])}else 0==jQuery("#"+r).find(".rpx_msg").length&&jQuery("#"+r).prepend('<div class="rpx_msg"></div>'),jQuery("#"+r+" .rpx_msg").html(e.errors[t])}rpx_resetCaptcha(),jQuery("#"+r+"rpx_loading").hide(),jQuery("#"+r).fadeIn()}else rpx_ajaxFailed(r,e);else rpx_ajaxFailed(r,e)}.bind(r)).fail(function(e){rpx_ajaxFailed(r,e)}.bind(r)),e.preventDefault()):e.preventDefault()}),rpx_grecaptcha_length=jQuery(".g-recaptcha").length});