PageSourceSearch

https://hellidonlakeshotel.co.uk/assets/aWgtaGVsbGlkb24=/js/hashes/33e2f3f4806565b902656a7940e28a93.js

js hellidonlakeshotel.co.uk collected 2026-10-01 16:38:56 UTC 83,842 bytes, 2,576 lines download raw bytes

1 const CookieNotice = {
2	oldBodyMargin: null,
3
4	init() {
5		this.prefs = ['analytics','advertising','personalisation'];
6		this.managing = false;
7		this.oldBodyMargin = document.body.style.marginBottom;
8		this.oldBodyMargin = (this.oldBodyMargin == '') ? '0' : this.oldBodyMargin;
9		this.fadeDuration = 500;
10
11		this.loader = setInterval(() => {
12			if (document.readyState !== "complete") return;
13			clearInterval(this.loader);
14
15			this.createSettings();
16
17			this.banner = document.getElementById("st-cookie-notice-banner");
18			if (this.banner) {
19				this.show(this.banner);
20			}
21
22			let savedAny = false;
23			this.prefs.forEach(pref => {
24				const key = 'st-cookie-notice-banner-adv-' + pref; const val = localStorage.getItem(key); if (val != null) { savedAny = true; const el = document.getElementById('cnb-' + pref); if (el != undefined) { el.checked = (val === 'true'); } }
25			}); if (savedAny) {
26				this.addReminderParagraph();
27			}
28		}, 300);
29	},
30
31	show() {
32		const display = localStorage.getItem('st-cookie-notice-banner');
33		const reject = localStorage.getItem('st-cookie-notice-banner-reject');
34		const rejCheck = Date.now() - (7 * 24 * 60 * 60 * 1000);
35		const check = Date.now() - 2419200000;
36		const adv = localStorage.getItem('st-cookie-notice-banner-adv');
37		const advCheck = Date.now() - (7 * 24 * 60 * 60 * 1000);
38
39		// are we going to show the banner?
40		if ((display != undefined
41				&& display <= check
42			)
43			|| display == undefined
44		) {
45			this.banner.classList.add("st-cookie-notice-banner-show");
46			this.banner.addEventListener('click', (event) => this.handleBannerClick(event));
47
48			// Extend the page to cover the notice
49			document.body.style.marginBottom = this.banner.offsetHeight + 'px';
50		} else if (reject != undefined
51				&& reject > check
52		) {
53			this.reject();
54		} else {
55			this.accept(false);
56		}
57	},
58
59	handleBannerClick(event) {
60		if (event.target.tagName === 'BUTTON') {
61			if (event.target.classList.contains('reject-cookies')) {
62				this.reject();
63			} else if (event.target.classList.contains('manage-cookies')) {
64				this.manage();
65			} else {
66				this.accept(true);
67			}
68		}
69	},
70
71	addReminderParagraph() {
72		var r = document.getElementById('st-cookies-remember');
73		if (r != undefined) {
74			r.remove();
75		}
76	const hasSavedPrefs = this.prefs.some(pref => { return localStorage.getItem('st-cookie-notice-banner-adv-' + pref) === 'true'; }); if (hasSavedPrefs) {
77			const bannerDiv = document.getElementById('st-cookie-notice-banner');
78		if (!bannerDiv) return; const paragraphs = bannerDiv.getElementsByTagName('p');
79			const newParagraph = document.createElement('p');
80		newParagraph.setAttribute('id', 'st-cookies-remember');
81			newParagraph.textContent = "We've remembered your previous cookie preferences.";
82		if (paragraphs.length > 1 && paragraphs[1].parentNode) { paragraphs[1].insertAdjacentElement('afterend', newParagraph); } else { bannerDiv.appendChild(newParagraph); }
83		}
84	},
85
86	accept(clicked) {
87		var d = Date.now();
88		if (clicked) {
89			localStorage.setItem('st-cookie-notice-banner', d);
90			localStorage.removeItem('st-cookie-notice-banner-reject');
91			if (this.banner) {
92
93				// if the tickboxes are shown, get the tickbox values
94				const ct = document.querySelector('.cookie-tickboxes');
95				if (ct != undefined && ct.classList.contains('cookie-expanded')) {
96					this.prefs.forEach(pref => {
97						const el = document.getElementById('cnb-' + pref) || this.banner.querySelector('input[name="cnb-' + pref + '"]');
98						if (el) {
99							var checked = el.checked;
100						} else {
101							var checked = true;
102						}
103						const key = 'st-cookie-notice-banner-adv-' + pref;
104						if (checked) {
105							localStorage.setItem(key, true);
106						} else {
107							localStorage.removeItem(key);
108						}
109					});
110				} else {
111					// we can tick each box
112					this.prefs.forEach(pref => {
113						const key = 'st-cookie-notice-banner-adv-' + pref;
114						localStorage.setItem(key, true);
115					});
116				}
117			}
118		}
119
120		const analyticsStatus = localStorage.getItem('st-cookie-notice-banner-adv-analytics') === 'true' ? 'granted' : 'denied';
121		const advertisingStatus = localStorage.getItem('st-cookie-notice-banner-adv-advertising') === 'true' ? 'granted' : 'denied';
122		const personalisationStatus = localStorage.getItem('st-cookie-notice-banner-adv-personalisation') === 'true' ? 'granted' : 'denied';
123
124		if (typeof gtag === "function") {
125			gtag('consent', 'update', {
126				ad_storage: advertisingStatus,
127				analytics_storage: analyticsStatus,
128				functionality_storage: "granted",
129				personalization_storage: personalisationStatus,
130				security_storage: "granted",
131				ad_user_data: advertisingStatus,
132				ad_personalization: personalisationStatus
133			});
134		}
135
136		if (false) {
137			window.uetq = window.uetq || [];
138			window.uetq.push('consent', 'update', {
139				'ad_storage': advertisingStatus
140			});
141		}
142		if (true && clicked) {
143			localStorage.setItem('st-cookie-notice-banner-adv', d);
144		}
145		this.remove();
146	},
147
148	manage() {
149		this.managing = true;
150		document.querySelector('.manage-cookies').style.display = 'none';
151		document.querySelector('.reject-cookies').style.display = 'inline-block';
152		this.moveButtons(true)
153		this.prefs.forEach(pref => {
154			const key = 'st-cookie-notice-banner-adv-' + pref;
155			const saved = localStorage.getItem(key) === 'true';
156			const el = document.getElementById('cnb-' + pref);
157			if (el) {
158				el.checked = saved;
159			}
160		});
161		var ct = document.querySelector('.cookie-tickboxes');
162		ct.classList.add("cookie-expanded");
163	},
164
165	moveButtons(dir) {
166		const cookie_buttons = document.querySelector('.cookie-buttons');
167	const accept_cookies = $('#accept-cookies');
168		if (dir) {
169			var target = document.querySelector('.cookie-tickboxes');
170			var old = document.querySelector('.cookie-o-buttons');
171			old.style.display = 'none';
172			var text = document.querySelector('.cookie-o-text');
173			text.classList.remove("col-md-8");
174			accept_cookies.text(accept_cookies.data('manage'));
175		} else {
176			var target = document.querySelector('.cookie-o-buttons');
177			target.style.display = 'block';
178			var text = document.querySelector('.cookie-o-text');
179			text.classList.add("col-md-8");
180			accept_cookies.text(accept_cookies.data('all'));
181		}
182		if (cookie_buttons && target) {
183			target.appendChild(cookie_buttons);
184		}
185	},
186
187	reject() {
188		var d = Date.now();
189		localStorage.setItem('st-cookie-notice-banner-reject', d);
190		localStorage.setItem('st-cookie-notice-banner', d);
191
192		localStorage.removeItem('st-cookie-notice-banner-adv');
193		this.prefs.forEach(pref => {
194			localStorage.removeItem('st-cookie-notice-banner-adv-' + pref);
195		});
196
197		this.prefs.forEach(pref => { if (pref === 'analytics') return; localStorage.removeItem('st-cookie-notice-banner-adv-' + pref); });
198		if (true) {
199			localStorage.setItem('st-cookie-notice-banner-adv', d);
200		}
201		this.remove();
202	},
203
204	reset() {
205		localStorage.removeItem('st-cookie-notice-banner');
206		localStorage.removeItem('st-cookie-notice-banner-reject');
207		this.show();
208		const manage = document.querySelector('.manage-cookies');
209		this.managing = false;
210		if (manage) {
211			manage.style.display = 'inline-block';
212		}
213		const reject = document.querySelector('.reject-cookies');
214		if (reject) {
215			reject.style.display = 'none';
216		}
217		var ct = document.querySelector('.cookie-tickboxes');
218		if (ct) {
219			this.moveButtons(false)
220			ct.classList.remove("cookie-expanded");
221		}
222		this.addReminderParagraph();
223		this.changeSettings(false);
224		this.banner.style.display = 'block';
225	},
226
227	remove() {
228		this.banner.style.display = 'none';
229		this.changeSettings(true);
230
231		// remove the page extension
232		document.body.style.marginBottom = this.oldBodyMargin + 'px';
233	},
234
235	createSettings() {
236
237		// create the span
238		const span = document.createElement('span');
239		span.classList.add('cookie-arrow-up');
240		span.textContent = ' Cookies';
241
242		// create the link element
243		const cookieLink = document.createElement('a');
244		cookieLink.setAttribute('id', 'st-cookie-settings-link')
245		cookieLink.href = 'javascript:CookieNotice.reset();';
246		cookieLink.appendChild(span);
247		document.body.appendChild(cookieLink);
248	},
249
250	changeSettings(dir) {
251		const settings_link = document.getElementById("st-cookie-settings-link");
252		if (settings_link) {
253			const disp = (dir) ? 'inline-block' : 'none';
254			settings_link.style.display = disp;
255		}
256	},
257};
258
259// Initialize the cookie notice
260CookieNotice.init();
261 var stSubmitting = false;
262window.addEventListener('load', function(){
263	$(document).ready(function(){
264		$(document).on('submit','.st-multi-form form',function(e){
265			e.preventDefault();
266			if(!stSubmitting){
267				submitMultiForm($(this).closest('.st-multi-form'));
268			}
269		});
270		$(document).on('keypress','.st-multi-form input',function(e){
271			if(e.keyCode == 13 && !stSubmitting){
272				e.preventDefault();
273				submitMultiForm($(this).closest('.st-multi-form'));
274			}
275		});
276		$(document).on('keypress','.st-multi-form :input',function(e){
277			if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) {
278				e.preventDefault();
279				submitMultiForm($(this).closest('.st-multi-form'));
280			}
281		});
282	});
283});
284
285function submitMultiForm(wrapper){
286	stSubmitting = true;
287	var name = wrapper.find('input[name=multi-id]').val();
288	var d = {};
289	d[name] = {};
290	d['type'] = 'form-submit';
291	if (wrapper.find('div.st-multi-wrapper').first().length) {
292		if (wrapper.find('div.st-multi-wrapper').first().data('wbid') !== undefined) {
293			if (wrapper.find('div.st-multi-wrapper').first().data('wbid').length) {
294				d[name]['wbid'] = wrapper.find('div.st-multi-wrapper').data('wbid');
295			}
296		}
297	}
298	wrapper.find('form').each(function(){
299		var data = getSTFormData($(this));
300		d[name][data['formId']] = data;
301	});
302	stcMultiCallback(d);
303}
304function getSTFormData(t){
305	var d = {};
306	var id = t.attr('id');
307
308	d['formId'] = id;
309	t.find(':input').each(function(){
310		if (!$(this).hasClass('btn')) {
311			var fid = $(this).attr('id');
312			if($(this).closest('.st-context-screen').length == 0){
313				var elementType = $(this).prop('nodeName');
314				if($(this).attr('type') != "submit" && $(this).attr('id') != undefined){
315					if(elementType == "TEXTAREA"){
316						if(fid != undefined){
317							if(typeof CKEDITOR != "undefined"){
318								if(typeof CKEDITOR.instances != "undefined"){
319									for(var i in CKEDITOR.instances) {
320										if(CKEDITOR.instances[i].name == fid){
321											CKEDITOR.instances[i].updateElement();
322										}
323									}
324								}
325							}
326						}
327						if ($(this).attr('name') == 'g-recaptcha-response') {
328							fid = $(this).attr('name');
329						}
330						var val = $(this).val();
331					} else {
332						if($(this).is(':checkbox')){
333							if($(this).prop('checked')){
334								var val = 1;
335							} else {
336								var val = 0;
337							}
338						} else {
339							var val = $(this).val();
340						}
341					}
342				}
343				d[fid] = val;
344			}
345			i++;
346		}
347	});
348	t.find('.st-radio-wrapper').each(function(){
349		fid = $(this).find('input[type=radio]:first').attr('name');
350		if(fid != undefined){
351			val = $(this).find('input[name=' + fid + ']:checked').val();
352			d[fid] = ((val == undefined) ? '' : val);
353		}
354	});
355	t.find('.small-wysiwyg').each(function(){
356		if($(this).closest('.st-context-screen').length == 0){
357			d[fid] = $(this).html();
358		}
359	});
360	t.find('.st-signature').each(function(){
361		if($(this).closest('.st-context-screen').length == 0){
362			if(fid != undefined){
363				fid = fid.split("-")[1];
364				var img = getSignature($(this));
365				d[fid] = img;
366			}
367		}
368	});
369	return d;
370}
371function stopSubmitting(){
372	stSubmitting = false;
373}
374     // remove all other buttons besides the last one
375if($('.st-multi-form').length) {
376    $('.st-multi-form').each(function() {
377        if($(this).closest('div.modal').length == 0) {
378            $(this).find('.stformfooter').last().addClass('show');
379        }
380    });
381}
382
383// multi form element
384var multiForms = $('.stc-api-multi-form');
385// check for multi-form
386if(multiForms.length){
387    // check if there's reCaptcha within
388    if(multiForms.find('.stc-recaptcha').length){
389        // loop through
390        multiForms.each(function(){
391            // form
392            var form = $(this);
393            // let's generate some string
394            var formId = Math.random().toString(36).substring(5);
395            // prepend form ID
396            form.prepend('<input type="hidden" name="stc_fid" value="'+formId+'">');
397        });
398    }
399}
400
401/**
402 * Multi-Form Callback function
403 *
404 * @param {object} data - The POST inputs of the form
405 * @return void
406 */
407function stcMultiCallback(data)
408{
409    // Multi-Form ID
410    var multiFormId = Object.keys(data)[0];
411    var multiIdInput = $('input[name=multi-id][value='+multiFormId+']');
412
413    // modal?
414    var modal = null;
415
416    // check input
417    if (multiIdInput.closest('div.stc-ls').length) {
418        var container = multiIdInput.closest('div.stc-ls');
419    } else {
420        var container = multiIdInput.closest('div.st-multi-form');
421    }
422
423    // check if the container is in a modal
424    if(container.closest('.modal').length) {
425        modal = container.closest('.modal');
426    }
427
428    // messages container
429    var errorsCon = container.find('.stc-api-form-errors');
430    var successCon = container.find('.stc-api-form-success');
431    if(errorsCon.length == 0){
432        container.prepend('<div class="alert alert-danger stc-api-form-errors hidden" role="alert"></div>');
433        errorsCon = container.find('.stc-api-form-errors');
434    }
435    if(successCon.length == 0){
436        container.prepend('<div class="alert alert-success stc-api-form-success hidden" role="alert"></div>');
437        successCon = container.find('.stc-api-form-success');
438    }
439
440    // last button data
441    var submitBtn = container.find('button[type=submit]').last();
442    // check if its modal
443    if(modal != null
444        && modal.find('.modal-footer').length
445    ){
446
447        // check if it has the submit modal btn
448        if (modal.find('.modal-footer').find('button.submit-modal').length) {
449            submitBtn = modal.find('.modal-footer').find('button.submit-modal');
450
451        // check if its the type
452        } else if (modal.find('.modal-footer').find('button[type=submit]').length) {
453            submitBtn = modal.find('.modal-footer').find('button[type=submit]');
454        }
455
456
457    }
458    var btnText = submitBtn.html();
459
460    // form top offset
461    var formOffset = parseInt(container.offset().top) - parseInt($('nav').height());
462
463    // GA settings
464    var formSettings = container.find('.stc-api-form-settings').length ? container.find('.stc-api-form-settings').html() : null;
465
466    // put recaptcha field
467    data['g-recaptcha-response'] = container.find('#g-recaptcha-response').val();
468
469    // put form ID
470    data['stc_fid'] = container.find('input[name=stc_fid]').val();
471
472    // set the URLs for submission
473    var landingUrl = 'https://hellidonlakeshotel.co.uk/contact-us';
474    var sessionReferer = '';
475    var contactPage = window.location.href;
476    var campaignId = '';
477    var adgroupId = '';
478    var gclid = '';
479    var keyword = '';
480    var gbraid = '';
481	var wbraid = '';
482
483	// check if the landing url contains process/post
484	if(landingUrl.includes('process/post')){
485
486		// set it to the current page
487		landingUrl = window.location.href;
488	}
489
490    // Get the form inputs
491    if(container.find('form input').length) {
492
493        // Get the hidden input elements for the URLs
494        var hiddenElements = container.find('form textarea[name$="-url"]');
495        hiddenElements = hiddenElements.add(container.find('form textarea[name$="-id"]'));
496        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_gclid"]'));
497        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_keyword"]'));
498        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_gbraid"]'));
499        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_wbraid"]'));
500
501        var ids = [];
502
503        if(hiddenElements.length > 0) {
504
505            // Add each hidden input's id to the ids array
506            hiddenElements.each(function() {
507                ids.push($(this).attr('id'));
508            });
509
510            if(ids.length > 0) {
511
512                // Set the formId for the activity form with the hidden inputs
513                var formId = 'form-' + ids[0].split('-')[0];
514
515                // Loop through the ids array
516                for(let i = 0; i < ids.length; i++) {
517
518                    // Check if the submitted data has a value for the current id
519                    if(data[multiFormId][formId][ids[i]].length != "") {
520                        // Reset the value if it exists
521                        data[multiFormId][formId][ids[i]] = "";
522                    }
523
524                    // Check for each URL field in the ids array and set the data to the corresponding URL
525                    if(ids[i].includes('contact-form-url')) {
526                        data[multiFormId][formId][ids[i]] = contactPage.trim();
527                    } else if(ids[i].includes('landing-url')) {
528                        data[multiFormId][formId][ids[i]] = landingUrl.trim();
529                    } else if(ids[i].includes('contact-referer-url')) {
530                        data[multiFormId][formId][ids[i]] = pageReferer.trim();
531                    } else if(ids[i].includes('session-referer-url')) {
532                        data[multiFormId][formId][ids[i]] = sessionReferer.trim();
533                    } else if(ids[i].includes('campaign-id')) {
534                        data[multiFormId][formId][ids[i]] = campaignId.trim();
535                    } else if(ids[i].includes('adgroup-id')) {
536                        data[multiFormId][formId][ids[i]] = adgroupId.trim();
537                    } else if(ids[i].includes('_gclid')) {
538                        data[multiFormId][formId][ids[i]] = gclid.trim();
539                    } else if(ids[i].includes('_keyword')) {
540                        data[multiFormId][formId][ids[i]] = keyword.trim();
541                    } else if(ids[i].includes('_gbraid')) {
542                        data[multiFormId][formId][ids[i]] = gbraid.trim();
543                    } else if(ids[i].includes('_wbraid')) {
544						data[multiFormId][formId][ids[i]] = wbraid.trim();
545					}
546                }
547
548                data['multiFormId'] = multiFormId;
549                data['formId'] = formId;
550
551                // Get the form data for current formid
552                /*var currentForm = data[multiFormId][formId];
553
554                var updatedForm = {};
555
556                // Loop through each key in the object
557                for (var key in currentForm) {
558                    if (currentForm.hasOwnProperty(key)) {
559                        // Split the key at the first underscore
560                        var newKey = key.split('_')[0];
561
562                        // Add the value to a new object
563                        updatedForm[newKey] = currentForm[key];
564                    }
565                }
566
567                // Set the original data to use the updated object with the correct field names
568                data[multiFormId][formId] = updatedForm;*/
569            }
570        }
571
572		// check for an email address field
573		var emailAddress = container.find('input[placeholder*="Enter Email"]');
574		if(emailAddress.length
575			&& emailAddress.val() != ''
576		) {
577
578			// Set the email address to the data
579			data['email'] = emailAddress.val();
580		}
581    }
582
583    // send data
584	$.ajax({
585        type: 'POST',
586        url: site_url+'process/post/',
587        data: data,
588        dataType: 'JSON',
589        beforeSend: function(){
590            // check if we have CRM Google Events
591            if(typeof stGoogleEventsFormSubmit === 'function'){
592                stGoogleEventsFormSubmit(container, 'Attempt');
593            }else {
594                if(formSettings != null && typeof gaEventProcess === 'function'){
595                    gaEventProcess(formSettings, 'attempt');
596                }
597            }
598
599            // disable and show processing
600            submitBtn.attr('disabled', true).html('<i class="fa fa-refresh fa-spin" aria-hidden="true"></i> Processing...');
601            // reset alert messages
602            container.find('div.alert').empty().addClass('hidden');
603        },
604        success: function(rs){
605			var showSuccess = false;
606			var showError = false;
607
608            if(rs.success){
609                // check if we have CRM Google Events
610                if(typeof stGoogleEventsFormSubmit === 'function'){
611                    stGoogleEventsFormSubmit(container, 'Success');
612                }else{
613                    if(formSettings != null && typeof gaEventProcess === 'function'){
614                        gaEventProcess(formSettings, 'success');
615                    }
616                }
617
618                if(rs.hasOwnProperty('result')){
619                    if(rs.result.hasOwnProperty('html') && rs.result.html.length){
620                        $('body').append('<div class="hidden">'+rs.result.html+'</div>');
621                    }else{
622						showSuccess = true;
623					}
624                }else{
625					showSuccess = true;
626				}
627            }else{
628                showError = true;
629            }
630
631			if(showSuccess && rs.hasOwnProperty('message')){
632                resetFields(container);
633                successCon.html(rs.message).removeClass('hidden');
634				scrollAnimate(formOffset, modal);
635			}
636
637			if(showError){
638                errorsCon.html(rs.error).removeClass('hidden');
639				scrollAnimate(formOffset, modal);
640			}
641
642            submitBtn.attr('disabled', false).html(btnText);
643            if(typeof stopSubmitting === 'function'){
644            	stopSubmitting();
645            }
646        },
647        error: function(data){
648            submitBtn.attr('disabled', false).html(btnText);
649			scrollAnimate(formOffset, modal);
650            if(typeof stopSubmitting === 'function'){
651            	stopSubmitting();
652            }
653        }
654    });
655}
656
657/**
658 * For scrolling into the top of the form
659 */
660function scrollAnimate(offset, modal)
661{
662    // set element to scroll to
663    var element = $('html, body');
664
665    // check if modal
666    if(modal != null){
667        var modalId = modal.attr('id');
668        element = $('#'+modalId);
669        offset = 0;
670    }
671
672    // scroll
673    element.animate({
674        scrollTop: offset
675    }, 500);
676}
677
678/**
679 * Resets all fields
680 *
681 * @param {el} el - The multi-form element container
682 */
683function resetFields(el){
684    // check for all elements
685    if(el.find(':input').length){
686        // loop through
687        el.find(':input').each(function(){
688
689			// check that the element is visible
690			if(!$(this).is(':visible')){
691				return true;
692			}
693
694            switch(this.type){
695                case 'checkbox':
696                case 'radio':
697                    $(this).prop('checked', false);
698                    break;
699                case 'hidden':
700                    // reset hidden flag
701                    var resetHiddenFlag = true;
702
703                    // check fields that we don't want to reset
704                    if(['multi-id', 'stc_fid'].indexOf($(this).attr('name')) >= 0 || $(this).attr('name').indexOf('-e') >= 0){
705                        resetHiddenFlag = false;
706                    }
707
708                    // check if reset hidden
709                    if(resetHiddenFlag){
710                        $(this).val('');
711                    }
712                    break;
713                default:
714                    $(this).val('');
715                    break;
716            }
717        });
718    }
719}
720
721/**
722 * Process the GA Event
723 *
724 * @param {json} gaSettings - The GA event details
725 * @param {string} type - The Type of event
726 * @return void
727 */
728function gaEventProcess(gaSettings, type){
729    // check if we have CRM Google Events
730    if(typeof stGoogleEventsFormSubmit === 'function'){
731        return false;
732    }
733
734    // let's try
735    try {
736        // prepare JSON settings
737        var jsonGA = JSON.parse(gaSettings);
738
739        // let's check the proper details
740        if(jsonGA.hasOwnProperty('event_'+type+'_name') && jsonGA.hasOwnProperty('event_'+type+'_category') && jsonGA.hasOwnProperty('event_'+type+'_label') && jsonGA.hasOwnProperty('event_'+type+'_value') && typeof gaEvent === 'function'){
741            // set initial values
742            var name = null;
743            var category = null;
744            var label = null;
745            var value = null;
746            // log type
747            console.log(type);
748
749            // if attempt
750            if(type == 'attempt'){
751                name = jsonGA.event_attempt_name.length ? jsonGA.event_attempt_name : null;
752                category = jsonGA.event_attempt_category.length ? jsonGA.event_attempt_category : null;
753                label = jsonGA.event_attempt_label.length ? jsonGA.event_attempt_label : null;
754                value = jsonGA.event_attempt_value.length ? jsonGA.event_attempt_value : null;
755            }
756
757            // if success
758            if(type == 'success'){
759                name = jsonGA.event_success_name.length ? jsonGA.event_success_name : null;
760                category = jsonGA.event_success_category.length ? jsonGA.event_success_category : null;
761                label = jsonGA.event_success_label.length ? jsonGA.event_success_label : null;
762                value = jsonGA.event_success_value.length ? jsonGA.event_success_value : null;
763            }
764
765            // check values
766            if(typeof gaEvent === 'function' && name !== null && category != null && label != null){
767                // execute
768                gaEvent(name, category, label, value);
769            }
770        }
771    } catch(err) {
772        console.log(err);
773    }
774} var stSubmitting = false;
775window.addEventListener('load', function(){
776	$(document).ready(function(){
777		$(document).on('submit','.st-multi-form form',function(e){
778			e.preventDefault();
779			if(!stSubmitting){
780				submitMultiForm($(this).closest('.st-multi-form'));
781			}
782		});
783		$(document).on('keypress','.st-multi-form input',function(e){
784			if(e.keyCode == 13 && !stSubmitting){
785				e.preventDefault();
786				submitMultiForm($(this).closest('.st-multi-form'));
787			}
788		});
789		$(document).on('keypress','.st-multi-form :input',function(e){
790			if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) {
791				e.preventDefault();
792				submitMultiForm($(this).closest('.st-multi-form'));
793			}
794		});
795	});
796});
797
798function submitMultiForm(wrapper){
799	stSubmitting = true;
800	var name = wrapper.find('input[name=multi-id]').val();
801	var d = {};
802	d[name] = {};
803	d['type'] = 'form-submit';
804	if (wrapper.find('div.st-multi-wrapper').first().length) {
805		if (wrapper.find('div.st-multi-wrapper').first().data('wbid') !== undefined) {
806			if (wrapper.find('div.st-multi-wrapper').first().data('wbid').length) {
807				d[name]['wbid'] = wrapper.find('div.st-multi-wrapper').data('wbid');
808			}
809		}
810	}
811	wrapper.find('form').each(function(){
812		var data = getSTFormData($(this));
813		d[name][data['formId']] = data;
814	});
815	stcMultiCallback(d);
816}
817function getSTFormData(t){
818	var d = {};
819	var id = t.attr('id');
820
821	d['formId'] = id;
822	t.find(':input').each(function(){
823		if (!$(this).hasClass('btn')) {
824			var fid = $(this).attr('id');
825			if($(this).closest('.st-context-screen').length == 0){
826				var elementType = $(this).prop('nodeName');
827				if($(this).attr('type') != "submit" && $(this).attr('id') != undefined){
828					if(elementType == "TEXTAREA"){
829						if(fid != undefined){
830							if(typeof CKEDITOR != "undefined"){
831								if(typeof CKEDITOR.instances != "undefined"){
832									for(var i in CKEDITOR.instances) {
833										if(CKEDITOR.instances[i].name == fid){
834											CKEDITOR.instances[i].updateElement();
835										}
836									}
837								}
838							}
839						}
840						if ($(this).attr('name') == 'g-recaptcha-response') {
841							fid = $(this).attr('name');
842						}
843						var val = $(this).val();
844					} else {
845						if($(this).is(':checkbox')){
846							if($(this).prop('checked')){
847								var val = 1;
848							} else {
849								var val = 0;
850							}
851						} else {
852							var val = $(this).val();
853						}
854					}
855				}
856				d[fid] = val;
857			}
858			i++;
859		}
860	});
861	t.find('.st-radio-wrapper').each(function(){
862		fid = $(this).find('input[type=radio]:first').attr('name');
863		if(fid != undefined){
864			val = $(this).find('input[name=' + fid + ']:checked').val();
865			d[fid] = ((val == undefined) ? '' : val);
866		}
867	});
868	t.find('.small-wysiwyg').each(function(){
869		if($(this).closest('.st-context-screen').length == 0){
870			d[fid] = $(this).html();
871		}
872	});
873	t.find('.st-signature').each(function(){
874		if($(this).closest('.st-context-screen').length == 0){
875			if(fid != undefined){
876				fid = fid.split("-")[1];
877				var img = getSignature($(this));
878				d[fid] = img;
879			}
880		}
881	});
882	return d;
883}
884function stopSubmitting(){
885	stSubmitting = false;
886}
887     // remove all other buttons besides the last one
888if($('.st-multi-form').length) {
889    $('.st-multi-form').each(function() {
890        if($(this).closest('div.modal').length == 0) {
891            $(this).find('.stformfooter').last().addClass('show');
892        }
893    });
894}
895
896// multi form element
897var multiForms = $('.stc-api-multi-form');
898// check for multi-form
899if(multiForms.length){
900    // check if there's reCaptcha within
901    if(multiForms.find('.stc-recaptcha').length){
902        // loop through
903        multiForms.each(function(){
904            // form
905            var form = $(this);
906            // let's generate some string
907            var formId = Math.random().toString(36).substring(5);
908            // prepend form ID
909            form.prepend('<input type="hidden" name="stc_fid" value="'+formId+'">');
910        });
911    }
912}
913
914/**
915 * Multi-Form Callback function
916 *
917 * @param {object} data - The POST inputs of the form
918 * @return void
919 */
920function stcMultiCallback(data)
921{
922    // Multi-Form ID
923    var multiFormId = Object.keys(data)[0];
924    var multiIdInput = $('input[name=multi-id][value='+multiFormId+']');
925
926    // modal?
927    var modal = null;
928
929    // check input
930    if (multiIdInput.closest('div.stc-ls').length) {
931        var container = multiIdInput.closest('div.stc-ls');
932    } else {
933        var container = multiIdInput.closest('div.st-multi-form');
934    }
935
936    // check if the container is in a modal
937    if(container.closest('.modal').length) {
938        modal = container.closest('.modal');
939    }
940
941    // messages container
942    var errorsCon = container.find('.stc-api-form-errors');
943    var successCon = container.find('.stc-api-form-success');
944    if(errorsCon.length == 0){
945        container.prepend('<div class="alert alert-danger stc-api-form-errors hidden" role="alert"></div>');
946        errorsCon = container.find('.stc-api-form-errors');
947    }
948    if(successCon.length == 0){
949        container.prepend('<div class="alert alert-success stc-api-form-success hidden" role="alert"></div>');
950        successCon = container.find('.stc-api-form-success');
951    }
952
953    // last button data
954    var submitBtn = container.find('button[type=submit]').last();
955    // check if its modal
956    if(modal != null
957        && modal.find('.modal-footer').length
958    ){
959
960        // check if it has the submit modal btn
961        if (modal.find('.modal-footer').find('button.submit-modal').length) {
962            submitBtn = modal.find('.modal-footer').find('button.submit-modal');
963
964        // check if its the type
965        } else if (modal.find('.modal-footer').find('button[type=submit]').length) {
966            submitBtn = modal.find('.modal-footer').find('button[type=submit]');
967        }
968
969
970    }
971    var btnText = submitBtn.html();
972
973    // form top offset
974    var formOffset = parseInt(container.offset().top) - parseInt($('nav').height());
975
976    // GA settings
977    var formSettings = container.find('.stc-api-form-settings').length ? container.find('.stc-api-form-settings').html() : null;
978
979    // put recaptcha field
980    data['g-recaptcha-response'] = container.find('#g-recaptcha-response').val();
981
982    // put form ID
983    data['stc_fid'] = container.find('input[name=stc_fid]').val();
984
985    // set the URLs for submission
986    var landingUrl = 'https://hellidonlakeshotel.co.uk/contact-us';
987    var sessionReferer = '';
988    var contactPage = window.location.href;
989    var campaignId = '';
990    var adgroupId = '';
991    var gclid = '';
992    var keyword = '';
993    var gbraid = '';
994	var wbraid = '';
995
996	// check if the landing url contains process/post
997	if(landingUrl.includes('process/post')){
998
999		// set it to the current page
1000		landingUrl = window.location.href;
1001	}
1002
1003    // Get the form inputs
1004    if(container.find('form input').length) {
1005
1006        // Get the hidden input elements for the URLs
1007        var hiddenElements = container.find('form textarea[name$="-url"]');
1008        hiddenElements = hiddenElements.add(container.find('form textarea[name$="-id"]'));
1009        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_gclid"]'));
1010        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_keyword"]'));
1011        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_gbraid"]'));
1012        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_wbraid"]'));
1013
1014        var ids = [];
1015
1016        if(hiddenElements.length > 0) {
1017
1018            // Add each hidden input's id to the ids array
1019            hiddenElements.each(function() {
1020                ids.push($(this).attr('id'));
1021            });
1022
1023            if(ids.length > 0) {
1024
1025                // Set the formId for the activity form with the hidden inputs
1026                var formId = 'form-' + ids[0].split('-')[0];
1027
1028                // Loop through the ids array
1029                for(let i = 0; i < ids.length; i++) {
1030
1031                    // Check if the submitted data has a value for the current id
1032                    if(data[multiFormId][formId][ids[i]].length != "") {
1033                        // Reset the value if it exists
1034                        data[multiFormId][formId][ids[i]] = "";
1035                    }
1036
1037                    // Check for each URL field in the ids array and set the data to the corresponding URL
1038                    if(ids[i].includes('contact-form-url')) {
1039                        data[multiFormId][formId][ids[i]] = contactPage.trim();
1040                    } else if(ids[i].includes('landing-url')) {
1041                        data[multiFormId][formId][ids[i]] = landingUrl.trim();
1042                    } else if(ids[i].includes('contact-referer-url')) {
1043                        data[multiFormId][formId][ids[i]] = pageReferer.trim();
1044                    } else if(ids[i].includes('session-referer-url')) {
1045                        data[multiFormId][formId][ids[i]] = sessionReferer.trim();
1046                    } else if(ids[i].includes('campaign-id')) {
1047                        data[multiFormId][formId][ids[i]] = campaignId.trim();
1048                    } else if(ids[i].includes('adgroup-id')) {
1049                        data[multiFormId][formId][ids[i]] = adgroupId.trim();
1050                    } else if(ids[i].includes('_gclid')) {
1051                        data[multiFormId][formId][ids[i]] = gclid.trim();
1052                    } else if(ids[i].includes('_keyword')) {
1053                        data[multiFormId][formId][ids[i]] = keyword.trim();
1054                    } else if(ids[i].includes('_gbraid')) {
1055                        data[multiFormId][formId][ids[i]] = gbraid.trim();
1056                    } else if(ids[i].includes('_wbraid')) {
1057						data[multiFormId][formId][ids[i]] = wbraid.trim();
1058					}
1059                }
1060
1061                data['multiFormId'] = multiFormId;
1062                data['formId'] = formId;
1063
1064                // Get the form data for current formid
1065                /*var currentForm = data[multiFormId][formId];
1066
1067                var updatedForm = {};
1068
1069                // Loop through each key in the object
1070                for (var key in currentForm) {
1071                    if (currentForm.hasOwnProperty(key)) {
1072                        // Split the key at the first underscore
1073                        var newKey = key.split('_')[0];
1074
1075                        // Add the value to a new object
1076                        updatedForm[newKey] = currentForm[key];
1077                    }
1078                }
1079
1080                // Set the original data to use the updated object with the correct field names
1081                data[multiFormId][formId] = updatedForm;*/
1082            }
1083        }
1084
1085		// check for an email address field
1086		var emailAddress = container.find('input[placeholder*="Enter Email"]');
1087		if(emailAddress.length
1088			&& emailAddress.val() != ''
1089		) {
1090
1091			// Set the email address to the data
1092			data['email'] = emailAddress.val();
1093		}
1094    }
1095
1096    // send data
1097	$.ajax({
1098        type: 'POST',
1099        url: site_url+'process/post/',
1100        data: data,
1101        dataType: 'JSON',
1102        beforeSend: function(){
1103            // check if we have CRM Google Events
1104            if(typeof stGoogleEventsFormSubmit === 'function'){
1105                stGoogleEventsFormSubmit(container, 'Attempt');
1106            }else {
1107                if(formSettings != null && typeof gaEventProcess === 'function'){
1108                    gaEventProcess(formSettings, 'attempt');
1109                }
1110            }
1111
1112            // disable and show processing
1113            submitBtn.attr('disabled', true).html('<i class="fa fa-refresh fa-spin" aria-hidden="true"></i> Processing...');
1114            // reset alert messages
1115            container.find('div.alert').empty().addClass('hidden');
1116        },
1117        success: function(rs){
1118			var showSuccess = false;
1119			var showError = false;
1120
1121            if(rs.success){
1122                // check if we have CRM Google Events
1123                if(typeof stGoogleEventsFormSubmit === 'function'){
1124                    stGoogleEventsFormSubmit(container, 'Success');
1125                }else{
1126                    if(formSettings != null && typeof gaEventProcess === 'function'){
1127                        gaEventProcess(formSettings, 'success');
1128                    }
1129                }
1130
1131                if(rs.hasOwnProperty('result')){
1132                    if(rs.result.hasOwnProperty('html') && rs.result.html.length){
1133                        $('body').append('<div class="hidden">'+rs.result.html+'</div>');
1134                    }else{
1135						showSuccess = true;
1136					}
1137                }else{
1138					showSuccess = true;
1139				}
1140            }else{
1141                showError = true;
1142            }
1143
1144			if(showSuccess && rs.hasOwnProperty('message')){
1145                resetFields(container);
1146                successCon.html(rs.message).removeClass('hidden');
1147				scrollAnimate(formOffset, modal);
1148			}
1149
1150			if(showError){
1151                errorsCon.html(rs.error).removeClass('hidden');
1152				scrollAnimate(formOffset, modal);
1153			}
1154
1155            submitBtn.attr('disabled', false).html(btnText);
1156            if(typeof stopSubmitting === 'function'){
1157            	stopSubmitting();
1158            }
1159        },
1160        error: function(data){
1161            submitBtn.attr('disabled', false).html(btnText);
1162			scrollAnimate(formOffset, modal);
1163            if(typeof stopSubmitting === 'function'){
1164            	stopSubmitting();
1165            }
1166        }
1167    });
1168}
1169
1170/**
1171 * For scrolling into the top of the form
1172 */
1173function scrollAnimate(offset, modal)
1174{
1175    // set element to scroll to
1176    var element = $('html, body');
1177
1178    // check if modal
1179    if(modal != null){
1180        var modalId = modal.attr('id');
1181        element = $('#'+modalId);
1182        offset = 0;
1183    }
1184
1185    // scroll
1186    element.animate({
1187        scrollTop: offset
1188    }, 500);
1189}
1190
1191/**
1192 * Resets all fields
1193 *
1194 * @param {el} el - The multi-form element container
1195 */
1196function resetFields(el){
1197    // check for all elements
1198    if(el.find(':input').length){
1199        // loop through
1200        el.find(':input').each(function(){
1201
1202			// check that the element is visible
1203			if(!$(this).is(':visible')){
1204				return true;
1205			}
1206
1207            switch(this.type){
1208                case 'checkbox':
1209                case 'radio':
1210                    $(this).prop('checked', false);
1211                    break;
1212                case 'hidden':
1213                    // reset hidden flag
1214                    var resetHiddenFlag = true;
1215
1216                    // check fields that we don't want to reset
1217                    if(['multi-id', 'stc_fid'].indexOf($(this).attr('name')) >= 0 || $(this).attr('name').indexOf('-e') >= 0){
1218                        resetHiddenFlag = false;
1219                    }
1220
1221                    // check if reset hidden
1222                    if(resetHiddenFlag){
1223                        $(this).val('');
1224                    }
1225                    break;
1226                default:
1227                    $(this).val('');
1228                    break;
1229            }
1230        });
1231    }
1232}
1233
1234/**
1235 * Process the GA Event
1236 *
1237 * @param {json} gaSettings - The GA event details
1238 * @param {string} type - The Type of event
1239 * @return void
1240 */
1241function gaEventProcess(gaSettings, type){
1242    // check if we have CRM Google Events
1243    if(typeof stGoogleEventsFormSubmit === 'function'){
1244        return false;
1245    }
1246
1247    // let's try
1248    try {
1249        // prepare JSON settings
1250        var jsonGA = JSON.parse(gaSettings);
1251
1252        // let's check the proper details
1253        if(jsonGA.hasOwnProperty('event_'+type+'_name') && jsonGA.hasOwnProperty('event_'+type+'_category') && jsonGA.hasOwnProperty('event_'+type+'_label') && jsonGA.hasOwnProperty('event_'+type+'_value') && typeof gaEvent === 'function'){
1254            // set initial values
1255            var name = null;
1256            var category = null;
1257            var label = null;
1258            var value = null;
1259            // log type
1260            console.log(type);
1261
1262            // if attempt
1263            if(type == 'attempt'){
1264                name = jsonGA.event_attempt_name.length ? jsonGA.event_attempt_name : null;
1265                category = jsonGA.event_attempt_category.length ? jsonGA.event_attempt_category : null;
1266                label = jsonGA.event_attempt_label.length ? jsonGA.event_attempt_label : null;
1267                value = jsonGA.event_attempt_value.length ? jsonGA.event_attempt_value : null;
1268            }
1269
1270            // if success
1271            if(type == 'success'){
1272                name = jsonGA.event_success_name.length ? jsonGA.event_success_name : null;
1273                category = jsonGA.event_success_category.length ? jsonGA.event_success_category : null;
1274                label = jsonGA.event_success_label.length ? jsonGA.event_success_label : null;
1275                value = jsonGA.event_success_value.length ? jsonGA.event_success_value : null;
1276            }
1277
1278            // check values
1279            if(typeof gaEvent === 'function' && name !== null && category != null && label != null){
1280                // execute
1281                gaEvent(name, category, label, value);
1282            }
1283        }
1284    } catch(err) {
1285        console.log(err);
1286    }
1287}
1288var stSubmitting = false;
1289window.addEventListener('load', function(){
1290	$(document).ready(function(){
1291		$(document).on('submit','.st-multi-form form',function(e){
1292			e.preventDefault();
1293			if(!stSubmitting){
1294				submitMultiForm($(this).closest('.st-multi-form'));
1295			}
1296		});
1297		$(document).on('keypress','.st-multi-form input',function(e){
1298			if(e.keyCode == 13 && !stSubmitting){
1299				e.preventDefault();
1300				submitMultiForm($(this).closest('.st-multi-form'));
1301			}
1302		});
1303		$(document).on('keypress','.st-multi-form :input',function(e){
1304			if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) {
1305				e.preventDefault();
1306				submitMultiForm($(this).closest('.st-multi-form'));
1307			}
1308		});
1309	});
1310});
1311
1312function submitMultiForm(wrapper){
1313	stSubmitting = true;
1314	var name = wrapper.find('input[name=multi-id]').val();
1315	var d = {};
1316	d[name] = {};
1317	d['type'] = 'form-submit';
1318	if (wrapper.find('div.st-multi-wrapper').first().length) {
1319		if (wrapper.find('div.st-multi-wrapper').first().data('wbid') !== undefined) {
1320			if (wrapper.find('div.st-multi-wrapper').first().data('wbid').length) {
1321				d[name]['wbid'] = wrapper.find('div.st-multi-wrapper').data('wbid');
1322			}
1323		}
1324	}
1325	wrapper.find('form').each(function(){
1326		var data = getSTFormData($(this));
1327		d[name][data['formId']] = data;
1328	});
1329	stcMultiCallback(d);
1330}
1331function getSTFormData(t){
1332	var d = {};
1333	var id = t.attr('id');
1334
1335	d['formId'] = id;
1336	t.find(':input').each(function(){
1337		if (!$(this).hasClass('btn')) {
1338			var fid = $(this).attr('id');
1339			if($(this).closest('.st-context-screen').length == 0){
1340				var elementType = $(this).prop('nodeName');
1341				if($(this).attr('type') != "submit" && $(this).attr('id') != undefined){
1342					if(elementType == "TEXTAREA"){
1343						if(fid != undefined){
1344							if(typeof CKEDITOR != "undefined"){
1345								if(typeof CKEDITOR.instances != "undefined"){
1346									for(var i in CKEDITOR.instances) {
1347										if(CKEDITOR.instances[i].name == fid){
1348											CKEDITOR.instances[i].updateElement();
1349										}
1350									}
1351								}
1352							}
1353						}
1354						if ($(this).attr('name') == 'g-recaptcha-response') {
1355							fid = $(this).attr('name');
1356						}
1357						var val = $(this).val();
1358					} else {
1359						if($(this).is(':checkbox')){
1360							if($(this).prop('checked')){
1361								var val = 1;
1362							} else {
1363								var val = 0;
1364							}
1365						} else {
1366							var val = $(this).val();
1367						}
1368					}
1369				}
1370				d[fid] = val;
1371			}
1372			i++;
1373		}
1374	});
1375	t.find('.st-radio-wrapper').each(function(){
1376		fid = $(this).find('input[type=radio]:first').attr('name');
1377		if(fid != undefined){
1378			val = $(this).find('input[name=' + fid + ']:checked').val();
1379			d[fid] = ((val == undefined) ? '' : val);
1380		}
1381	});
1382	t.find('.small-wysiwyg').each(function(){
1383		if($(this).closest('.st-context-screen').length == 0){
1384			d[fid] = $(this).html();
1385		}
1386	});
1387	t.find('.st-signature').each(function(){
1388		if($(this).closest('.st-context-screen').length == 0){
1389			if(fid != undefined){
1390				fid = fid.split("-")[1];
1391				var img = getSignature($(this));
1392				d[fid] = img;
1393			}
1394		}
1395	});
1396	return d;
1397}
1398function stopSubmitting(){
1399	stSubmitting = false;
1400}
1401if($('.stc-leadmagnet').find('.st-multi-wrapper').length){
1402	var leadMagnets = $('.stc-leadmagnet');
1403	leadMagnets.each(function(){
1404		var last_wrapper = $(this).find('.st-multi-wrapper').last();
1405		if(last_wrapper.find('.stc-recaptcha').length) {
1406			last_wrapper.find('.strow').not(':last').addClass('hidden');
1407		} else {
1408			last_wrapper.find('.strow').addClass('hidden');
1409		}
1410	});
1411}
1412
1413if ($('.stc-leadmagnet').find('.st-multi-wrapper').length > 1) {
1414	$('.stc-leadmagnet').find('.st-multi-wrapper').last().find('.stformfooter').addClass('show');
1415    $('.stc-leadmagnet').find('.st-multi-wrapper').find('.stformfooter').not('.show').remove();
1416}
1417
1418// check for modals
1419if ($('.stc-leadmagnet-modal').length) {
1420    $('.stc-leadmagnet-modal').each(function(){
1421        if ($(this).find('.modal-header button.close').length == 0) {
1422            $(this).find('.modal-header').prepend('<button type="button" class="close btn-close" data-dismiss="modal" data-bs-dismiss="modal" aria-hidden="true"></button>');
1423        }
1424
1425        if ($(this).find('.modal-header h2').length) {
1426            if ($(this).find('.modal-header h2').html().trim().length == 0) {
1427                $(this).find('.modal-header h2').remove();
1428            }
1429        }
1430
1431        if ($(this).find('.modal-footer').length) {
1432            if ($(this).find('.modal-footer').html().trim().length == 0) {
1433                $(this).find('.modal-footer').remove();
1434            }
1435        }
1436    });
1437}
1438
1439/**
1440 * stSubmitData: Submits the Lead Magnet form
1441 *
1442 * @param {array} data
1443 * @returns void
1444 */
1445function stSubmitDataHPHEYAGB(data) {
1446
1447    var multiFormId = Object.keys(data)[0];
1448    var multiIdInput = $('input[name=multi-id][value='+multiFormId+']');
1449    var form = multiIdInput.closest('div.st-multi-form');
1450
1451	if (form.find('.alert').length) {
1452		form.find('.alert').remove();
1453	}
1454
1455    var submitBtn = form.find('button');
1456    var btnText = submitBtn.html();
1457
1458    data['csrf'] = $('meta[name=csrf-token]').attr('content');
1459
1460    $.ajax({
1461        url: link + 'generic/post.php'
1462        , type: "POST"
1463        , data: data
1464        , dataType: 'json'
1465        , beforeSend: function(){
1466            submitBtn.prop('disabled', true);
1467            submitBtn.text('Processing...');
1468        }
1469        , success: function(res) {
1470            submitBtn.prop('disabled', false);
1471            submitBtn.html(btnText);
1472
1473            if(res.success){
1474                var redirect = (res.redirect != undefined && res.redirect != "") ? res.redirect : "";
1475                if(redirect != ""){
1476                    window.location.href = redirect;
1477                } else {
1478                    var clear = (res.clear != undefined) ? res.clear : '';
1479                    if (clear == '') {
1480                        var data_clear = form.data('no-clear');
1481                        clear = (data_clear == 'true' || data_clear == true) ? false : true;
1482                    }
1483                    if (clear) {
1484                        if (typeof clearForm === 'function') {
1485                            clearForm(form);
1486                        } else {
1487                            clearFormHPHEYAGB(form);
1488                        }
1489                    }
1490
1491					var messageText = "Thanks for getting in touch. We'll get back to you soon.";
1492					if(form.closest('.stc-leadmagnet').length) {
1493						messageText = "Your submission has been successful. You should receive an email with the Download Link.";
1494					}
1495                    var message = '<div class="alert alert-success">' + messageText + '</div>';
1496                    if (res.message != undefined) {
1497
1498                        // return message
1499                        message = (res.message.substring(0,1) == "<") ? res.message : '<div class="alert alert-success"><ul><li>'+res.message+'</li></ul></div>';
1500                        form.prepend(message);
1501                    }
1502                    form.prepend(message);
1503					if(typeof t !== 'undefined') {
1504						$('html, body').animate({ scrollTop: (t.offset().top - 120) },750);
1505					}
1506					if (typeof stopSubmitting === 'function') {
1507						stopSubmitting();
1508					}
1509                }
1510            } else {
1511                if (typeof setErrors == 'function') {
1512                    setErrors(res.errors, form, true);
1513                } else {
1514                    setErrorsHPHEYAGB(res.errors, form, true);
1515                }
1516				if (typeof stopSubmitting === 'function') {
1517					stopSubmitting();
1518				}
1519            }
1520        }
1521    });
1522}
1523
1524/**
1525 * clearForm: Clears the form
1526 *
1527 * @param {form} element
1528 * @returns void
1529 */
1530function clearFormHPHEYAGB(form){
1531    form.find('input,select,textarea').each(function(){
1532        if ($(this).attr('id') !== undefined) {
1533            if($(this).attr('id').indexOf('-entity') == -1){
1534                $(this).val('');
1535            }
1536        } else {
1537            $(this).val('');
1538        }
1539    });
1540}
1541
1542/**
1543 * setErrors: Sets the errors on the front-end
1544 *
1545 * @param {array} errors
1546 * @param {DOMElement} element
1547 * @param {boolean} scroll
1548 * @returns void
1549 */
1550function setErrorsHPHEYAGB(errors, element, scroll){
1551
1552    // check scroll
1553    if (scroll !== false
1554        || scroll === undefined
1555    ) {
1556        scroll = true;
1557    }
1558
1559    // build error messages
1560    var errorMessage = '<ul class="error">';
1561    $.each(errors,function(index,val){
1562        if(val != ""){
1563            errorMessage += '<li>' + val + '</li>';
1564        }
1565    });
1566    errorMessage += '</ul>';
1567
1568    // check message element
1569    if (element.find('.alert-danger , .alert-warning').length == 0) {
1570        element.prepend('<div class="error-wrapper alert alert-danger" role="alert"><h4>Oops!</h4>' + errorMessage + '</div>');
1571    } else {
1572        element.find('.alert').html(errorMessage);
1573    }
1574    element.find('.error-wrapper').slideDown();
1575
1576    // check scroll
1577    if (scroll) {
1578
1579        // check for body padding
1580        var body_padding = parseInt($('body').css('padding-top'));
1581        $('html, body').animate({ scrollTop: (element.offset().top - body_padding) }, 1000);
1582    }
1583}
1584// remove all other buttons besides the last one
1585if($('.st-multi-form').length) {
1586    $('.st-multi-form').each(function() {
1587        if($(this).closest('div.modal').length == 0) {
1588            $(this).find('.stformfooter').last().addClass('show');
1589        }
1590    });
1591}
1592
1593// multi form element
1594var multiForms = $('.stc-api-multi-form');
1595// check for multi-form
1596if(multiForms.length){
1597    // check if there's reCaptcha within
1598    if(multiForms.find('.stc-recaptcha').length){
1599        // loop through
1600        multiForms.each(function(){
1601            // form
1602            var form = $(this);
1603            // let's generate some string
1604            var formId = Math.random().toString(36).substring(5);
1605            // prepend form ID
1606            form.prepend('<input type="hidden" name="stc_fid" value="'+formId+'">');
1607        });
1608    }
1609}
1610
1611/**
1612 * Multi-Form Callback function
1613 *
1614 * @param {object} data - The POST inputs of the form
1615 * @return void
1616 */
1617function stcMultiCallback(data)
1618{
1619    // Multi-Form ID
1620    var multiFormId = Object.keys(data)[0];
1621    var multiIdInput = $('input[name=multi-id][value='+multiFormId+']');
1622
1623    // modal?
1624    var modal = null;
1625
1626    // check input
1627    if (multiIdInput.closest('div.stc-ls').length) {
1628        var container = multiIdInput.closest('div.stc-ls');
1629    } else {
1630        var container = multiIdInput.closest('div.st-multi-form');
1631    }
1632
1633    // check if the container is in a modal
1634    if(container.closest('.modal').length) {
1635        modal = container.closest('.modal');
1636    }
1637
1638    // messages container
1639    var errorsCon = container.find('.stc-api-form-errors');
1640    var successCon = container.find('.stc-api-form-success');
1641    if(errorsCon.length == 0){
1642        container.prepend('<div class="alert alert-danger stc-api-form-errors hidden" role="alert"></div>');
1643        errorsCon = container.find('.stc-api-form-errors');
1644    }
1645    if(successCon.length == 0){
1646        container.prepend('<div class="alert alert-success stc-api-form-success hidden" role="alert"></div>');
1647        successCon = container.find('.stc-api-form-success');
1648    }
1649
1650    // last button data
1651    var submitBtn = container.find('button[type=submit]').last();
1652    // check if its modal
1653    if(modal != null
1654        && modal.find('.modal-footer').length
1655    ){
1656
1657        // check if it has the submit modal btn
1658        if (modal.find('.modal-footer').find('button.submit-modal').length) {
1659            submitBtn = modal.find('.modal-footer').find('button.submit-modal');
1660
1661        // check if its the type
1662        } else if (modal.find('.modal-footer').find('button[type=submit]').length) {
1663            submitBtn = modal.find('.modal-footer').find('button[type=submit]');
1664        }
1665
1666
1667    }
1668    var btnText = submitBtn.html();
1669
1670    // form top offset
1671    var formOffset = parseInt(container.offset().top) - parseInt($('nav').height());
1672
1673    // GA settings
1674    var formSettings = container.find('.stc-api-form-settings').length ? container.find('.stc-api-form-settings').html() : null;
1675
1676    // put recaptcha field
1677    data['g-recaptcha-response'] = container.find('#g-recaptcha-response').val();
1678
1679    // put form ID
1680    data['stc_fid'] = container.find('input[name=stc_fid]').val();
1681
1682    // set the URLs for submission
1683    var landingUrl = 'https://hellidonlakeshotel.co.uk/contact-us';
1684    var sessionReferer = '';
1685    var contactPage = window.location.href;
1686    var campaignId = '';
1687    var adgroupId = '';
1688    var gclid = '';
1689    var keyword = '';
1690    var gbraid = '';
1691	var wbraid = '';
1692
1693	// check if the landing url contains process/post
1694	if(landingUrl.includes('process/post')){
1695
1696		// set it to the current page
1697		landingUrl = window.location.href;
1698	}
1699
1700    // Get the form inputs
1701    if(container.find('form input').length) {
1702
1703        // Get the hidden input elements for the URLs
1704        var hiddenElements = container.find('form textarea[name$="-url"]');
1705        hiddenElements = hiddenElements.add(container.find('form textarea[name$="-id"]'));
1706        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_gclid"]'));
1707        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_keyword"]'));
1708        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_gbraid"]'));
1709        hiddenElements = hiddenElements.add(container.find('form textarea[name$="_wbraid"]'));
1710
1711        var ids = [];
1712
1713        if(hiddenElements.length > 0) {
1714
1715            // Add each hidden input's id to the ids array
1716            hiddenElements.each(function() {
1717                ids.push($(this).attr('id'));
1718            });
1719
1720            if(ids.length > 0) {
1721
1722                // Set the formId for the activity form with the hidden inputs
1723                var formId = 'form-' + ids[0].split('-')[0];
1724
1725                // Loop through the ids array
1726                for(let i = 0; i < ids.length; i++) {
1727
1728                    // Check if the submitted data has a value for the current id
1729                    if(data[multiFormId][formId][ids[i]].length != "") {
1730                        // Reset the value if it exists
1731                        data[multiFormId][formId][ids[i]] = "";
1732                    }
1733
1734                    // Check for each URL field in the ids array and set the data to the corresponding URL
1735                    if(ids[i].includes('contact-form-url')) {
1736                        data[multiFormId][formId][ids[i]] = contactPage.trim();
1737                    } else if(ids[i].includes('landing-url')) {
1738                        data[multiFormId][formId][ids[i]] = landingUrl.trim();
1739                    } else if(ids[i].includes('contact-referer-url')) {
1740                        data[multiFormId][formId][ids[i]] = pageReferer.trim();
1741                    } else if(ids[i].includes('session-referer-url')) {
1742                        data[multiFormId][formId][ids[i]] = sessionReferer.trim();
1743                    } else if(ids[i].includes('campaign-id')) {
1744                        data[multiFormId][formId][ids[i]] = campaignId.trim();
1745                    } else if(ids[i].includes('adgroup-id')) {
1746                        data[multiFormId][formId][ids[i]] = adgroupId.trim();
1747                    } else if(ids[i].includes('_gclid')) {
1748                        data[multiFormId][formId][ids[i]] = gclid.trim();
1749                    } else if(ids[i].includes('_keyword')) {
1750                        data[multiFormId][formId][ids[i]] = keyword.trim();
1751                    } else if(ids[i].includes('_gbraid')) {
1752                        data[multiFormId][formId][ids[i]] = gbraid.trim();
1753                    } else if(ids[i].includes('_wbraid')) {
1754						data[multiFormId][formId][ids[i]] = wbraid.trim();
1755					}
1756                }
1757
1758                data['multiFormId'] = multiFormId;
1759                data['formId'] = formId;
1760
1761                // Get the form data for current formid
1762                /*var currentForm = data[multiFormId][formId];
1763
1764                var updatedForm = {};
1765
1766                // Loop through each key in the object
1767                for (var key in currentForm) {
1768                    if (currentForm.hasOwnProperty(key)) {
1769                        // Split the key at the first underscore
1770                        var newKey = key.split('_')[0];
1771
1772                        // Add the value to a new object
1773                        updatedForm[newKey] = currentForm[key];
1774                    }
1775                }
1776
1777                // Set the original data to use the updated object with the correct field names
1778                data[multiFormId][formId] = updatedForm;*/
1779            }
1780        }
1781
1782		// check for an email address field
1783		var emailAddress = container.find('input[placeholder*="Enter Email"]');
1784		if(emailAddress.length
1785			&& emailAddress.val() != ''
1786		) {
1787
1788			// Set the email address to the data
1789			data['email'] = emailAddress.val();
1790		}
1791    }
1792
1793    // send data
1794	$.ajax({
1795        type: 'POST',
1796        url: site_url+'process/post/',
1797        data: data,
1798        dataType: 'JSON',
1799        beforeSend: function(){
1800            // check if we have CRM Google Events
1801            if(typeof stGoogleEventsFormSubmit === 'function'){
1802                stGoogleEventsFormSubmit(container, 'Attempt');
1803            }else {
1804                if(formSettings != null && typeof gaEventProcess === 'function'){
1805                    gaEventProcess(formSettings, 'attempt');
1806                }
1807            }
1808
1809            // disable and show processing
1810            submitBtn.attr('disabled', true).html('<i class="fa fa-refresh fa-spin" aria-hidden="true"></i> Processing...');
1811            // reset alert messages
1812            container.find('div.alert').empty().addClass('hidden');
1813        },
1814        success: function(rs){
1815			var showSuccess = false;
1816			var showError = false;
1817
1818            if(rs.success){
1819                // check if we have CRM Google Events
1820                if(typeof stGoogleEventsFormSubmit === 'function'){
1821                    stGoogleEventsFormSubmit(container, 'Success');
1822                }else{
1823                    if(formSettings != null && typeof gaEventProcess === 'function'){
1824                        gaEventProcess(formSettings, 'success');
1825                    }
1826                }
1827
1828                if(rs.hasOwnProperty('result')){
1829                    if(rs.result.hasOwnProperty('html') && rs.result.html.length){
1830                        $('body').append('<div class="hidden">'+rs.result.html+'</div>');
1831                    }else{
1832						showSuccess = true;
1833					}
1834                }else{
1835					showSuccess = true;
1836				}
1837            }else{
1838                showError = true;
1839            }
1840
1841			if(showSuccess && rs.hasOwnProperty('message')){
1842                resetFields(container);
1843                successCon.html(rs.message).removeClass('hidden');
1844				scrollAnimate(formOffset, modal);
1845			}
1846
1847			if(showError){
1848                errorsCon.html(rs.error).removeClass('hidden');
1849				scrollAnimate(formOffset, modal);
1850			}
1851
1852            submitBtn.attr('disabled', false).html(btnText);
1853            if(typeof stopSubmitting === 'function'){
1854            	stopSubmitting();
1855            }
1856        },
1857        error: function(data){
1858            submitBtn.attr('disabled', false).html(btnText);
1859			scrollAnimate(formOffset, modal);
1860            if(typeof stopSubmitting === 'function'){
1861            	stopSubmitting();
1862            }
1863        }
1864    });
1865}
1866
1867/**
1868 * For scrolling into the top of the form
1869 */
1870function scrollAnimate(offset, modal)
1871{
1872    // set element to scroll to
1873    var element = $('html, body');
1874
1875    // check if modal
1876    if(modal != null){
1877        var modalId = modal.attr('id');
1878        element = $('#'+modalId);
1879        offset = 0;
1880    }
1881
1882    // scroll
1883    element.animate({
1884        scrollTop: offset
1885    }, 500);
1886}
1887
1888/**
1889 * Resets all fields
1890 *
1891 * @param {el} el - The multi-form element container
1892 */
1893function resetFields(el){
1894    // check for all elements
1895    if(el.find(':input').length){
1896        // loop through
1897        el.find(':input').each(function(){
1898
1899			// check that the element is visible
1900			if(!$(this).is(':visible')){
1901				return true;
1902			}
1903
1904            switch(this.type){
1905                case 'checkbox':
1906                case 'radio':
1907                    $(this).prop('checked', false);
1908                    break;
1909                case 'hidden':
1910                    // reset hidden flag
1911                    var resetHiddenFlag = true;
1912
1913                    // check fields that we don't want to reset
1914                    if(['multi-id', 'stc_fid'].indexOf($(this).attr('name')) >= 0 || $(this).attr('name').indexOf('-e') >= 0){
1915                        resetHiddenFlag = false;
1916                    }
1917
1918                    // check if reset hidden
1919                    if(resetHiddenFlag){
1920                        $(this).val('');
1921                    }
1922                    break;
1923                default:
1924                    $(this).val('');
1925                    break;
1926            }
1927        });
1928    }
1929}
1930
1931/**
1932 * Process the GA Event
1933 *
1934 * @param {json} gaSettings - The GA event details
1935 * @param {string} type - The Type of event
1936 * @return void
1937 */
1938function gaEventProcess(gaSettings, type){
1939    // check if we have CRM Google Events
1940    if(typeof stGoogleEventsFormSubmit === 'function'){
1941        return false;
1942    }
1943
1944    // let's try
1945    try {
1946        // prepare JSON settings
1947        var jsonGA = JSON.parse(gaSettings);
1948
1949        // let's check the proper details
1950        if(jsonGA.hasOwnProperty('event_'+type+'_name') && jsonGA.hasOwnProperty('event_'+type+'_category') && jsonGA.hasOwnProperty('event_'+type+'_label') && jsonGA.hasOwnProperty('event_'+type+'_value') && typeof gaEvent === 'function'){
1951            // set initial values
1952            var name = null;
1953            var category = null;
1954            var label = null;
1955            var value = null;
1956            // log type
1957            console.log(type);
1958
1959            // if attempt
1960            if(type == 'attempt'){
1961                name = jsonGA.event_attempt_name.length ? jsonGA.event_attempt_name : null;
1962                category = jsonGA.event_attempt_category.length ? jsonGA.event_attempt_category : null;
1963                label = jsonGA.event_attempt_label.length ? jsonGA.event_attempt_label : null;
1964                value = jsonGA.event_attempt_value.length ? jsonGA.event_attempt_value : null;
1965            }
1966
1967            // if success
1968            if(type == 'success'){
1969                name = jsonGA.event_success_name.length ? jsonGA.event_success_name : null;
1970                category = jsonGA.event_success_category.length ? jsonGA.event_success_category : null;
1971                label = jsonGA.event_success_label.length ? jsonGA.event_success_label : null;
1972                value = jsonGA.event_success_value.length ? jsonGA.event_success_value : null;
1973            }
1974
1975            // check values
1976            if(typeof gaEvent === 'function' && name !== null && category != null && label != null){
1977                // execute
1978                gaEvent(name, category, label, value);
1979            }
1980        }
1981    } catch(err) {
1982        console.log(err);
1983    }
1984}
1985var stSubmitting = false;
1986window.addEventListener('load', function(){
1987	$(document).ready(function(){
1988		$(document).on('submit','.st-multi-form form',function(e){
1989			e.preventDefault();
1990			if(!stSubmitting){
1991				submitMultiForm($(this).closest('.st-multi-form'));
1992			}
1993		});
1994		$(document).on('keypress','.st-multi-form input',function(e){
1995			if(e.keyCode == 13 && !stSubmitting){
1996				e.preventDefault();
1997				submitMultiForm($(this).closest('.st-multi-form'));
1998			}
1999		});
2000		$(document).on('keypress','.st-multi-form :input',function(e){
2001			if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) {
2002				e.preventDefault();
2003				submitMultiForm($(this).closest('.st-multi-form'));
2004			}
2005		});
2006	});
2007});
2008
2009function submitMultiForm(wrapper){
2010	stSubmitting = true;
2011	var name = wrapper.find('input[name=multi-id]').val();
2012	var d = {};
2013	d[name] = {};
2014	d['type'] = 'form-submit';
2015	if (wrapper.find('div.st-multi-wrapper').first().length) {
2016		if (wrapper.find('div.st-multi-wrapper').first().data('wbid') !== undefined) {
2017			if (wrapper.find('div.st-multi-wrapper').first().data('wbid').length) {
2018				d[name]['wbid'] = wrapper.find('div.st-multi-wrapper').data('wbid');
2019			}
2020		}
2021	}
2022	wrapper.find('form').each(function(){
2023		var data = getSTFormData($(this));
2024		d[name][data['formId']] = data;
2025	});
2026	stcMultiCallback(d);
2027}
2028function getSTFormData(t){
2029	var d = {};
2030	var id = t.attr('id');
2031
2032	d['formId'] = id;
2033	t.find(':input').each(function(){
2034		if (!$(this).hasClass('btn')) {
2035			var fid = $(this).attr('id');
2036			if($(this).closest('.st-context-screen').length == 0){
2037				var elementType = $(this).prop('nodeName');
2038				if($(this).attr('type') != "submit" && $(this).attr('id') != undefined){
2039					if(elementType == "TEXTAREA"){
2040						if(fid != undefined){
2041							if(typeof CKEDITOR != "undefined"){
2042								if(typeof CKEDITOR.instances != "undefined"){
2043									for(var i in CKEDITOR.instances) {
2044										if(CKEDITOR.instances[i].name == fid){
2045											CKEDITOR.instances[i].updateElement();
2046										}
2047									}
2048								}
2049							}
2050						}
2051						if ($(this).attr('name') == 'g-recaptcha-response') {
2052							fid = $(this).attr('name');
2053						}
2054						var val = $(this).val();
2055					} else {
2056						if($(this).is(':checkbox')){
2057							if($(this).prop('checked')){
2058								var val = 1;
2059							} else {
2060								var val = 0;
2061							}
2062						} else {
2063							var val = $(this).val();
2064						}
2065					}
2066				}
2067				d[fid] = val;
2068			}
2069			i++;
2070		}
2071	});
2072	t.find('.st-radio-wrapper').each(function(){
2073		fid = $(this).find('input[type=radio]:first').attr('name');
2074		if(fid != undefined){
2075			val = $(this).find('input[name=' + fid + ']:checked').val();
2076			d[fid] = ((val == undefined) ? '' : val);
2077		}
2078	});
2079	t.find('.small-wysiwyg').each(function(){
2080		if($(this).closest('.st-context-screen').length == 0){
2081			d[fid] = $(this).html();
2082		}
2083	});
2084	t.find('.st-signature').each(function(){
2085		if($(this).closest('.st-context-screen').length == 0){
2086			if(fid != undefined){
2087				fid = fid.split("-")[1];
2088				var img = getSignature($(this));
2089				d[fid] = img;
2090			}
2091		}
2092	});
2093	return d;
2094}
2095function stopSubmitting(){
2096	stSubmitting = false;
2097}
2098if($('.stc-leadmagnet').find('.st-multi-wrapper').length){
2099	var leadMagnets = $('.stc-leadmagnet');
2100	leadMagnets.each(function(){
2101		var last_wrapper = $(this).find('.st-multi-wrapper').last();
2102		if(last_wrapper.find('.stc-recaptcha').length) {
2103			last_wrapper.find('.strow').not(':last').addClass('hidden');
2104		} else {
2105			last_wrapper.find('.strow').addClass('hidden');
2106		}
2107	});
2108}
2109
2110if ($('.stc-leadmagnet').find('.st-multi-wrapper').length > 1) {
2111	$('.stc-leadmagnet').find('.st-multi-wrapper').last().find('.stformfooter').addClass('show');
2112    $('.stc-leadmagnet').find('.st-multi-wrapper').find('.stformfooter').not('.show').remove();
2113}
2114
2115// check for modals
2116if ($('.stc-leadmagnet-modal').length) {
2117    $('.stc-leadmagnet-modal').each(function(){
2118        if ($(this).find('.modal-header button.close').length == 0) {
2119            $(this).find('.modal-header').prepend('<button type="button" class="close btn-close" data-dismiss="modal" data-bs-dismiss="modal" aria-hidden="true"></button>');
2120        }
2121
2122        if ($(this).find('.modal-header h2').length) {
2123            if ($(this).find('.modal-header h2').html().trim().length == 0) {
2124                $(this).find('.modal-header h2').remove();
2125            }
2126        }
2127
2128        if ($(this).find('.modal-footer').length) {
2129            if ($(this).find('.modal-footer').html().trim().length == 0) {
2130                $(this).find('.modal-footer').remove();
2131            }
2132        }
2133    });
2134}
2135
2136/**
2137 * stSubmitData: Submits the Lead Magnet form
2138 *
2139 * @param {array} data
2140 * @returns void
2141 */
2142function stSubmitDataHEUWTA2C(data) {
2143
2144    var multiFormId = Object.keys(data)[0];
2145    var multiIdInput = $('input[name=multi-id][value='+multiFormId+']');
2146    var form = multiIdInput.closest('div.st-multi-form');
2147
2148	if (form.find('.alert').length) {
2149		form.find('.alert').remove();
2150	}
2151
2152    var submitBtn = form.find('button');
2153    var btnText = submitBtn.html();
2154
2155    data['csrf'] = $('meta[name=csrf-token]').attr('content');
2156
2157    $.ajax({
2158        url: link + 'generic/post.php'
2159        , type: "POST"
2160        , data: data
2161        , dataType: 'json'
2162        , beforeSend: function(){
2163            submitBtn.prop('disabled', true);
2164            submitBtn.text('Processing...');
2165        }
2166        , success: function(res) {
2167            submitBtn.prop('disabled', false);
2168            submitBtn.html(btnText);
2169
2170            if(res.success){
2171                var redirect = (res.redirect != undefined && res.redirect != "") ? res.redirect : "";
2172                if(redirect != ""){
2173                    window.location.href = redirect;
2174                } else {
2175                    var clear = (res.clear != undefined) ? res.clear : '';
2176                    if (clear == '') {
2177                        var data_clear = form.data('no-clear');
2178                        clear = (data_clear == 'true' || data_clear == true) ? false : true;
2179                    }
2180                    if (clear) {
2181                        if (typeof clearForm === 'function') {
2182                            clearForm(form);
2183                        } else {
2184                            clearFormHEUWTA2C(form);
2185                        }
2186                    }
2187
2188					var messageText = "Thanks for getting in touch. We'll get back to you soon.";
2189					if(form.closest('.stc-leadmagnet').length) {
2190						messageText = "Your submission has been successful. You should receive an email with the Download Link.";
2191					}
2192                    var message = '<div class="alert alert-success">' + messageText + '</div>';
2193                    if (res.message != undefined) {
2194
2195                        // return message
2196                        message = (res.message.substring(0,1) == "<") ? res.message : '<div class="alert alert-success"><ul><li>'+res.message+'</li></ul></div>';
2197                        form.prepend(message);
2198                    }
2199                    form.prepend(message);
2200					if(typeof t !== 'undefined') {
2201						$('html, body').animate({ scrollTop: (t.offset().top - 120) },750);
2202					}
2203					if (typeof stopSubmitting === 'function') {
2204						stopSubmitting();
2205					}
2206                }
2207            } else {
2208                if (typeof setErrors == 'function') {
2209                    setErrors(res.errors, form, true);
2210                } else {
2211                    setErrorsHEUWTA2C(res.errors, form, true);
2212                }
2213				if (typeof stopSubmitting === 'function') {
2214					stopSubmitting();
2215				}
2216            }
2217        }
2218    });
2219}
2220
2221/**
2222 * clearForm: Clears the form
2223 *
2224 * @param {form} element
2225 * @returns void
2226 */
2227function clearFormHEUWTA2C(form){
2228    form.find('input,select,textarea').each(function(){
2229        if ($(this).attr('id') !== undefined) {
2230            if($(this).attr('id').indexOf('-entity') == -1){
2231                $(this).val('');
2232            }
2233        } else {
2234            $(this).val('');
2235        }
2236    });
2237}
2238
2239/**
2240 * setErrors: Sets the errors on the front-end
2241 *
2242 * @param {array} errors
2243 * @param {DOMElement} element
2244 * @param {boolean} scroll
2245 * @returns void
2246 */
2247function setErrorsHEUWTA2C(errors, element, scroll){
2248
2249    // check scroll
2250    if (scroll !== false
2251        || scroll === undefined
2252    ) {
2253        scroll = true;
2254    }
2255
2256    // build error messages
2257    var errorMessage = '<ul class="error">';
2258    $.each(errors,function(index,val){
2259        if(val != ""){
2260            errorMessage += '<li>' + val + '</li>';
2261        }
2262    });
2263    errorMessage += '</ul>';
2264
2265    // check message element
2266    if (element.find('.alert-danger , .alert-warning').length == 0) {
2267        element.prepend('<div class="error-wrapper alert alert-danger" role="alert"><h4>Oops!</h4>' + errorMessage + '</div>');
2268    } else {
2269        element.find('.alert').html(errorMessage);
2270    }
2271    element.find('.error-wrapper').slideDown();
2272
2273    // check scroll
2274    if (scroll) {
2275
2276        // check for body padding
2277        var body_padding = parseInt($('body').css('padding-top'));
2278        $('html, body').animate({ scrollTop: (element.offset().top - body_padding) }, 1000);
2279    }
2280}
2281var stSubmitting = false;
2282window.addEventListener('load', function(){
2283	$(document).ready(function(){
2284		$(document).on('submit','.st-multi-form form',function(e){
2285			e.preventDefault();
2286			if(!stSubmitting){
2287				submitMultiForm($(this).closest('.st-multi-form'));
2288			}
2289		});
2290		$(document).on('keypress','.st-multi-form input',function(e){
2291			if(e.keyCode == 13 && !stSubmitting){
2292				e.preventDefault();
2293				submitMultiForm($(this).closest('.st-multi-form'));
2294			}
2295		});
2296		$(document).on('keypress','.st-multi-form :input',function(e){
2297			if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) {
2298				e.preventDefault();
2299				submitMultiForm($(this).closest('.st-multi-form'));
2300			}
2301		});
2302	});
2303});
2304
2305function submitMultiForm(wrapper){
2306	stSubmitting = true;
2307	var name = wrapper.find('input[name=multi-id]').val();
2308	var d = {};
2309	d[name] = {};
2310	d['type'] = 'form-submit';
2311	if (wrapper.find('div.st-multi-wrapper').first().length) {
2312		if (wrapper.find('div.st-multi-wrapper').first().data('wbid') !== undefined) {
2313			if (wrapper.find('div.st-multi-wrapper').first().data('wbid').length) {
2314				d[name]['wbid'] = wrapper.find('div.st-multi-wrapper').data('wbid');
2315			}
2316		}
2317	}
2318	wrapper.find('form').each(function(){
2319		var data = getSTFormData($(this));
2320		d[name][data['formId']] = data;
2321	});
2322	stcMultiCallback(d);
2323}
2324function getSTFormData(t){
2325	var d = {};
2326	var id = t.attr('id');
2327
2328	d['formId'] = id;
2329	t.find(':input').each(function(){
2330		if (!$(this).hasClass('btn')) {
2331			var fid = $(this).attr('id');
2332			if($(this).closest('.st-context-screen').length == 0){
2333				var elementType = $(this).prop('nodeName');
2334				if($(this).attr('type') != "submit" && $(this).attr('id') != undefined){
2335					if(elementType == "TEXTAREA"){
2336						if(fid != undefined){
2337							if(typeof CKEDITOR != "undefined"){
2338								if(typeof CKEDITOR.instances != "undefined"){
2339									for(var i in CKEDITOR.instances) {
2340										if(CKEDITOR.instances[i].name == fid){
2341											CKEDITOR.instances[i].updateElement();
2342										}
2343									}
2344								}
2345							}
2346						}
2347						if ($(this).attr('name') == 'g-recaptcha-response') {
2348							fid = $(this).attr('name');
2349						}
2350						var val = $(this).val();
2351					} else {
2352						if($(this).is(':checkbox')){
2353							if($(this).prop('checked')){
2354								var val = 1;
2355							} else {
2356								var val = 0;
2357							}
2358						} else {
2359							var val = $(this).val();
2360						}
2361					}
2362				}
2363				d[fid] = val;
2364			}
2365			i++;
2366		}
2367	});
2368	t.find('.st-radio-wrapper').each(function(){
2369		fid = $(this).find('input[type=radio]:first').attr('name');
2370		if(fid != undefined){
2371			val = $(this).find('input[name=' + fid + ']:checked').val();
2372			d[fid] = ((val == undefined) ? '' : val);
2373		}
2374	});
2375	t.find('.small-wysiwyg').each(function(){
2376		if($(this).closest('.st-context-screen').length == 0){
2377			d[fid] = $(this).html();
2378		}
2379	});
2380	t.find('.st-signature').each(function(){
2381		if($(this).closest('.st-context-screen').length == 0){
2382			if(fid != undefined){
2383				fid = fid.split("-")[1];
2384				var img = getSignature($(this));
2385				d[fid] = img;
2386			}
2387		}
2388	});
2389	return d;
2390}
2391function stopSubmitting(){
2392	stSubmitting = false;
2393}
2394if($('.stc-leadmagnet').find('.st-multi-wrapper').length){
2395	var leadMagnets = $('.stc-leadmagnet');
2396	leadMagnets.each(function(){
2397		var last_wrapper = $(this).find('.st-multi-wrapper').last();
2398		if(last_wrapper.find('.stc-recaptcha').length) {
2399			last_wrapper.find('.strow').not(':last').addClass('hidden');
2400		} else {
2401			last_wrapper.find('.strow').addClass('hidden');
2402		}
2403	});
2404}
2405
2406if ($('.stc-leadmagnet').find('.st-multi-wrapper').length > 1) {
2407	$('.stc-leadmagnet').find('.st-multi-wrapper').last().find('.stformfooter').addClass('show');
2408    $('.stc-leadmagnet').find('.st-multi-wrapper').find('.stformfooter').not('.show').remove();
2409}
2410
2411// check for modals
2412if ($('.stc-leadmagnet-modal').length) {
2413    $('.stc-leadmagnet-modal').each(function(){
2414        if ($(this).find('.modal-header button.close').length == 0) {
2415            $(this).find('.modal-header').prepend('<button type="button" class="close btn-close" data-dismiss="modal" data-bs-dismiss="modal" aria-hidden="true"></button>');
2416        }
2417
2418        if ($(this).find('.modal-header h2').length) {
2419            if ($(this).find('.modal-header h2').html().trim().length == 0) {
2420                $(this).find('.modal-header h2').remove();
2421            }
2422        }
2423
2424        if ($(this).find('.modal-footer').length) {
2425            if ($(this).find('.modal-footer').html().trim().length == 0) {
2426                $(this).find('.modal-footer').remove();
2427            }
2428        }
2429    });
2430}
2431
2432/**
2433 * stSubmitData: Submits the Lead Magnet form
2434 *
2435 * @param {array} data
2436 * @returns void
2437 */
2438function stSubmitDataTAV2GDYB(data) {
2439
2440    var multiFormId = Object.keys(data)[0];
2441    var multiIdInput = $('input[name=multi-id][value='+multiFormId+']');
2442    var form = multiIdInput.closest('div.st-multi-form');
2443
2444	if (form.find('.alert').length) {
2445		form.find('.alert').remove();
2446	}
2447
2448    var submitBtn = form.find('button');
2449    var btnText = submitBtn.html();
2450
2451    data['csrf'] = $('meta[name=csrf-token]').attr('content');
2452
2453    $.ajax({
2454        url: link + 'generic/post.php'
2455        , type: "POST"
2456        , data: data
2457        , dataType: 'json'
2458        , beforeSend: function(){
2459            submitBtn.prop('disabled', true);
2460            submitBtn.text('Processing...');
2461        }
2462        , success: function(res) {
2463            submitBtn.prop('disabled', false);
2464            submitBtn.html(btnText);
2465
2466            if(res.success){
2467                var redirect = (res.redirect != undefined && res.redirect != "") ? res.redirect : "";
2468                if(redirect != ""){
2469                    window.location.href = redirect;
2470                } else {
2471                    var clear = (res.clear != undefined) ? res.clear : '';
2472                    if (clear == '') {
2473                        var data_clear = form.data('no-clear');
2474                        clear = (data_clear == 'true' || data_clear == true) ? false : true;
2475                    }
2476                    if (clear) {
2477                        if (typeof clearForm === 'function') {
2478                            clearForm(form);
2479                        } else {
2480                            clearFormTAV2GDYB(form);
2481                        }
2482                    }
2483
2484					var messageText = "Thanks for getting in touch. We'll get back to you soon.";
2485					if(form.closest('.stc-leadmagnet').length) {
2486						messageText = "Your submission has been successful. You should receive an email with the Download Link.";
2487					}
2488                    var message = '<div class="alert alert-success">' + messageText + '</div>';
2489                    if (res.message != undefined) {
2490
2491                        // return message
2492                        message = (res.message.substring(0,1) == "<") ? res.message : '<div class="alert alert-success"><ul><li>'+res.message+'</li></ul></div>';
2493                        form.prepend(message);
2494                    }
2495                    form.prepend(message);
2496					if(typeof t !== 'undefined') {
2497						$('html, body').animate({ scrollTop: (t.offset().top - 120) },750);
2498					}
2499					if (typeof stopSubmitting === 'function') {
2500						stopSubmitting();
2501					}
2502                }
2503            } else {
2504                if (typeof setErrors == 'function') {
2505                    setErrors(res.errors, form, true);
2506                } else {
2507                    setErrorsTAV2GDYB(res.errors, form, true);
2508                }
2509				if (typeof stopSubmitting === 'function') {
2510					stopSubmitting();
2511				}
2512            }
2513        }
2514    });
2515}
2516
2517/**
2518 * clearForm: Clears the form
2519 *
2520 * @param {form} element
2521 * @returns void
2522 */
2523function clearFormTAV2GDYB(form){
2524    form.find('input,select,textarea').each(function(){
2525        if ($(this).attr('id') !== undefined) {
2526            if($(this).attr('id').indexOf('-entity') == -1){
2527                $(this).val('');
2528            }
2529        } else {
2530            $(this).val('');
2531        }
2532    });
2533}
2534
2535/**
2536 * setErrors: Sets the errors on the front-end
2537 *
2538 * @param {array} errors
2539 * @param {DOMElement} element
2540 * @param {boolean} scroll
2541 * @returns void
2542 */
2543function setErrorsTAV2GDYB(errors, element, scroll){
2544
2545    // check scroll
2546    if (scroll !== false
2547        || scroll === undefined
2548    ) {
2549        scroll = true;
2550    }
2551
2552    // build error messages
2553    var errorMessage = '<ul class="error">';
2554    $.each(errors,function(index,val){
2555        if(val != ""){
2556            errorMessage += '<li>' + val + '</li>';
2557        }
2558    });
2559    errorMessage += '</ul>';
2560
2561    // check message element
2562    if (element.find('.alert-danger , .alert-warning').length == 0) {
2563        element.prepend('<div class="error-wrapper alert alert-danger" role="alert"><h4>Oops!</h4>' + errorMessage + '</div>');
2564    } else {
2565        element.find('.alert').html(errorMessage);
2566    }
2567    element.find('.error-wrapper').slideDown();
2568
2569    // check scroll
2570    if (scroll) {
2571
2572        // check for body padding
2573        var body_padding = parseInt($('body').css('padding-top'));
2574        $('html, body').animate({ scrollTop: (element.offset().top - body_padding) }, 1000);
2575    }
2576}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.