PageSourceSearch

https://mediakit.triblive.com/wp-content/plugins/popup-builder/public/js/PopupBuilder.js?ver=4.4.3

js triblive.com collected 2026-09-24 08:28:07 UTC 79,614 bytes, 2,896 lines download raw bytes

1function sgAddEvent(element, eventName, fn)
2{
3	if (element.addEventListener)
4		element.addEventListener(eventName, fn, false);
5	else if (element.attachEvent)
6		element.attachEvent('on' + eventName, fn);
7}
8/*Popup order count*/
9window.SGPB_ORDER = 0;
10
11function SGPBPopup()
12{
13	this.id = null;
14	this.eventName = '';
15	this.popupData = null;
16	this.additionalPopupData = {};
17	this.popupConfig = {};
18	this.popupObj = null;
19	this.onceListener();
20	this.initialsListeners();
21	this.countPopupOpen = true;
22	this.closeButtonDefaultPositions = {};
23	this.closeButtonDefaultPositions[1] = {
24		'left': 9,
25		'right': 9,
26		'bottom': 9
27	};
28	this.closeButtonDefaultPositions[2] = {
29		'left': 0,
30		'right': 0,
31		'top': parseInt('-20'),
32		'bottom': parseInt('-20')
33	};
34	this.closeButtonDefaultPositions[3] = {
35		'right': 4,
36		'bottom': 4,
37		'left': 4,
38		'top': 4
39	};
40	this.closeButtonDefaultPositions[4] = {
41		'left': 12,
42		'right': 12,
43		'bottom': 9
44	};
45	this.closeButtonDefaultPositions[5] = {
46		'left': 8,
47		'right': 8,
48		'bottom': 8
49	};
50	this.closeButtonDefaultPositions[6] = {
51		'left': parseInt('-18.5'),
52		'right': parseInt('-18.5'),
53		'bottom': parseInt('-18.5'),
54		'top': parseInt('-18.5')
55	};
56}
57
58SGPBPopup.htmlCustomButton = function()
59{
60	var buttons = jQuery('.sgpb-html-custom-button');
61	var buttonActionBehaviors = function(button, settings)
62	{
63		button.bind('click', function() {
64			var behavior = settings['sgpb-custom-button'];
65
66			if (behavior === 'redirectToURL') {
67				if (settings['sgpb-custom-button-redirect-new-tab']) {
68					window.open(settings['sgpb-custom-button-redirect-URL']);
69				}
70				else {
71					window.location.href = settings['sgpb-custom-button-redirect-URL'];
72				}
73			}
74			if (behavior === 'hidePopup') {
75				SGPBPopup.closePopup();
76			}
77			if (behavior === 'copyToClipBoard') {
78				var tempInputId = 1;
79				var value = settings['sgpb-custom-button-copy-to-clipboard-text'];
80				var tempInput = document.createElement("input");
81				tempInput.id = tempInputId;
82				tempInput.value = value;
83				tempInput.style = 'position: absolute; right: -10000px';
84				if (!document.getElementById(tempInputId)) {
85					document.body.appendChild(tempInput);
86				}
87				tempInput.select();
88				document.execCommand("copy");
89
90				if (settings['sgpb-copy-to-clipboard-close-popup']) {
91					SGPBPopup.closePopup();
92				}
93
94				if (settings['sgpb-custom-button-copy-to-clipboard-alert']) {
95					alert(settings['sgpb-custom-button-copy-to-clipboard-message']);
96				}
97			}
98		});
99	};
100
101	buttons.each(function() {
102		var settings = jQuery.parseJSON(decodeURIComponent(jQuery(this).attr('data-options')));
103		buttonActionBehaviors(jQuery(this), settings);
104	});
105};
106
107SGPBPopup.listeners = function () {
108	var that = this;
109
110	sgAddEvent(window, 'sgpbPopupBuilderAdditionalDimensionSettings', function(e) {
111		SGPBPopup.mobileSafariAdditionalSettings(e);
112	});
113
114	sgAddEvent(window, 'sgpbDidOpen', function(e) {
115		/*for mobile landscape issue*/
116		if (typeof (Event) === 'function') {
117			var event = new CustomEvent('resize', {
118				bubbles: true,
119				cancelable: true
120			});
121		}
122		else {
123			if (SGPBPopup.isIE()) {
124				var event = document.createEvent('Event');
125				event.initEvent('resize', true, true);
126			}
127			else {
128				var event = new CustomEvent('resize', {
129					bubbles: true,
130					cancelable: true
131				});
132			}
133		}
134		window.dispatchEvent(event);
135
136		SGPBPopup.mobileSafariAdditionalSettings(e);
137		var args = e.detail;
138		var popupOptions = args.popupData;
139
140		var obj = e.detail.currentObj.sgpbPopupObj;
141
142		/* if no analytics extension */
143		if (typeof SGPB_ANALYTICS_PARAMS === 'undefined') {
144			if (obj.getCountPopupOpen()) {
145				obj.addToCounter(popupOptions);
146			}
147		}
148
149		if (popupOptions['sgpb-show-popup-same-user']) {
150			obj.setPopupLimitationCookie(popupOptions);
151		}
152		SGPBPopup.htmlCustomButton();
153	});
154
155	setInterval(function() {
156		var openedPopups = window.sgpbOpenedPopup || {};
157		if (!Object.keys(openedPopups).length) {
158			return false;
159		}
160		var params = {};
161		params.popupsIdCollection = window.sgpbOpenedPopup;
162
163		var data = {
164			action: 'sgpb_send_to_open_counter',
165			nonce: SGPB_JS_PARAMS.nonce,
166			params: params
167		};
168
169
170		window.sgpbOpenedPopup = {};
171		jQuery.post(SGPB_JS_PARAMS.ajaxUrl, data, function(res) {
172
173		});
174	}, 600);
175};
176
177SGPBPopup.mobileSafariAdditionalSettings = function(e)
178{
179	if (typeof e === 'undefined') {
180		var args = SGPBPopup.prototype.getAdditionalPopupData();
181		if (typeof args === 'undefined') {
182			return false;
183		}
184		var popupOptions = args.popupData;
185		var popupId = parseInt(args.popupId);
186	}
187	else {
188		var args = e.detail;
189		var alreadySavedArgs = SGPBPopup.prototype.getAdditionalPopupData();
190		if (jQuery.isEmptyObject(alreadySavedArgs)) {
191			SGPBPopup.prototype.setAdditionalPopupData(args);
192		}
193		var popupOptions = args.popupData;
194		var popupId = parseInt(args.popupId);
195	}
196	var userAgent = window.navigator.userAgent;
197	if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
198		if (typeof popupOptions['sgpb-popup-dimension-mode'] !== 'undefined' && popupOptions['sgpb-popup-dimension-mode'] === 'responsiveMode') {
199			var openedPopupWidth = parseInt(window.innerHeight-100);
200			if (e.detail.popupData['sgpb-type'] === 'iframe' || e.detail.popupData['sgpb-type'] === 'video') {
201				if (jQuery('.sgpb-popup-builder-content-'+popupId +' iframe').length) {
202					jQuery('.sgpb-popup-builder-content-'+popupId).attr('style', 'height:'+openedPopupWidth+'px !important;');
203				}
204			}
205		}
206	}
207};
208
209SGPBPopup.prototype.setAdditionalPopupData = function(additionalPopupData)
210{
211	this.additionalPopupData = additionalPopupData;
212};
213
214SGPBPopup.prototype.getAdditionalPopupData = function()
215{
216	return this.additionalPopupData;
217};
218
219SGPBPopup.prototype.setCountPopupOpen = function(countPopupOpen)
220{
221	this.countPopupOpen = countPopupOpen;
222};
223
224SGPBPopup.prototype.getCountPopupOpen = function()
225{
226	return this.countPopupOpen;
227};
228
229SGPBPopup.playMusic = function(e) {
230	var args = e.detail;
231	var popupId = parseInt(args.popupId);
232	var options = SGPBPopup.getPopupOptionsById(popupId);
233	var soundUrl = options['sgpb-sound-url'];
234	var soundStatus = options['sgpb-open-sound'];	
235	if (soundStatus && soundUrl ) {
236		var audio = new Audio(soundUrl);		
237		audio.play();		
238		window.SGPB_SOUND[popupId] = audio;
239	}
240};
241
242SGPBPopup.floatingButton = function (e) {
243	SGPBPopup.showFloatingButton(e);
244
245	jQuery(window).on('sgpbFormSuccess', function (e){
246		SGPBPopup.hideFloatingButton();
247	});
248};
249
250SGPBPopup.showFloatingButton = function (e) {
251	var popupObj = e || {};
252	var popupId = 0;
253	var shouldShowFloatingButton = true;
254
255	/* if argument e is event reference the popup object is wrapped inside e.detail.currentObj.sgpbPopupObj  */
256	if (e.hasOwnProperty('sgpbPopupObj')) {
257		popupObj = e.detail.currentObj.sgpbPopupObj;
258	}
259
260	if (popupObj instanceof SGPBPopup) {
261		popupId = parseInt(popupObj.id);
262		shouldShowFloatingButton = popupObj.forceCheckCurrentPopupType(popupObj);
263	}
264
265	/* If there is no cookie which will prevent popup opening we will show floating button */
266	if (shouldShowFloatingButton) {
267		/* if we have popup id we detect exact button */
268		if (popupId) {
269			jQuery('.sgpb-floating-button.sg-popup-id-' + popupId).show();
270		} else {
271			jQuery('.sgpb-floating-button').show();
272		}
273	}
274};
275
276SGPBPopup.hideFloatingButton = function (popupId) {
277	/* if we have popup id we detect exact button */
278	if (popupId) {
279		jQuery('.sgpb-floating-button.sg-popup-id-' + popupId).fadeOut();
280	} else {
281		jQuery('.sgpb-floating-button').fadeOut();
282	}
283};
284
285SGPBPopup.prototype.initialsListeners = function()
286{
287	/* one time calling events (sgpbDidOpen, sgpbDidClose ...) */
288	var that = this;
289	sgAddEvent(window, 'sgpbDidOpen', function(e) {
290		jQuery('.sg-popup-close').unbind('click').bind('click',function(){
291			var currentPopupId = jQuery(this).parents('.sg-popup-builder-content').attr('data-id');
292			SGPBPopup.closePopupById(currentPopupId);
293		});
294	});
295
296	sgAddEvent(window, 'sgpbDidClose', function(e) {
297		var args = e.detail;
298		var popupId = parseInt(args.popupId);
299		that.htmlIframeFilterForOpen(popupId, 'close');
300	});
301};
302
303SGPBPopup.prototype.onceListener = function()
304{
305	var that = this;
306
307	sgAddEvent(window, 'sgpbDidOpen', function(e) {
308		document.onkeydown = function(e) {
309			e = e || window.event;
310
311			if (e.keyCode === 27) { /*esc pressed*/
312				var currentPopup = that.getPopupIdForNextEsc();
313				if (!currentPopup) {
314					return false;
315				}
316				var lastPopupId = parseInt(currentPopup['popupId']);
317				SGPBPopup.closePopupById(lastPopupId);
318			}
319		};
320	});
321
322	sgAddEvent(window, 'sgpbDidClose', function(e) {
323		if (window.sgPopupBuilder.length !== 0) {
324			var popups = [].concat(window.sgPopupBuilder).reverse();
325			for (var i in popups) {
326				var nextIndex = ++i;
327				var nextObj = popups[nextIndex];
328
329				if (typeof nextObj === 'undefined') {
330					jQuery('html').removeClass('sgpb-overflow-hidden');
331					jQuery('body').removeClass('sgpb-overflow-hidden-body');
332					break;
333				}
334
335				if (nextObj.isOpen === false) {
336					continue;
337				}
338				var options = SGPBPopup.getPopupOptionsById(nextObj.popupId);
339				if (typeof options['sgpb-disable-page-scrolling'] === 'undefined') {
340					jQuery('html').removeClass('sgpb-overflow-hidden');
341					jQuery('body').removeClass('sgpb-overflow-hidden-body');
342				}
343				else {
344					jQuery('html').addClass('sgpb-overflow-hidden');
345					jQuery('body').addClass('sgpb-overflow-hidden-body');
346				}
347				break;
348			}
349		}
350		else {
351			jQuery('html').addClass('sgpb-overflow-hidden');
352			jQuery('body').addClass('sgpb-overflow-hidden-body');
353		}
354	});
355};
356
357SGPBPopup.prototype.getPopupIdForNextEsc = function()
358{
359	var popups = window.sgPopupBuilder;
360	var popup = false;
361
362	if (!popups.length) {
363		return popup;
364	}
365
366	var searchPopups = [].concat(popups).reverse();
367
368	for (var i in searchPopups) {
369		var popupData = searchPopups[i];
370
371		if (popupData.isOpen) {
372			var popupId = parseInt(popupData['popupId']);
373			var popupOptions = SGPBPopup.getPopupOptionsById(popupId);
374
375			if (!popupOptions['sgpb-disable-popup-closing'] && popupOptions['sgpb-esc-key']) {
376				popup = popupData;
377				break;
378			}
379		}
380	}
381
382	return popup;
383};
384
385SGPBPopup.prototype.setPopupId = function(popupId)
386{
387	this.id = parseInt(popupId);
388};
389
390SGPBPopup.prototype.getPopupId = function()
391{
392	return this.id;
393};
394
395SGPBPopup.prototype.setPopupObj = function(popupObj)
396{
397	this.popupObj = popupObj;
398};
399
400SGPBPopup.prototype.getPopupObj = function()
401{
402	return this.popupObj;
403};
404
405SGPBPopup.prototype.setPopupData = function(popupData)
406{
407	if (typeof popupData == 'string') {
408		var popupData = SGPBPopup.JSONParse(popupData);
409	}
410
411	this.popupData = popupData;
412};
413
414SGPBPopup.prototype.getPopupData = function()
415{
416	return this.popupData;
417};
418
419SGPBPopup.prototype.setPopupConfig = function(config)
420{
421	this.popupConfig = config;
422};
423
424SGPBPopup.prototype.getPopupConfig = function()
425{
426	return this.popupConfig;
427};
428
429SGPBPopup.prototype.setUpPopupConfig = function()
430{
431	var popupConfig = new PopupConfig();
432	this.setPopupConfig(popupConfig);
433};
434
435SGPBPopup.createPopupObjById = function(popupId)
436{
437	var options = SGPBPopup.getPopupOptionsById(popupId);
438
439	if (!options) {
440		return false;
441	}
442	var popupObj = new SGPBPopup();
443	popupObj.setPopupId(popupId);
444	popupObj.setPopupData(options);
445
446	return popupObj;
447};
448
449
450SGPBPopup.getPopupOptionsById = function(popupId)
451{
452	var popupDataDiv = jQuery('#sg-popup-content-wrapper-'+popupId);
453
454	if (!popupDataDiv.length) {
455		return false;
456	}
457	var options = popupDataDiv.attr('data-options');
458
459	return SGPBPopup.JSONParse(options);
460};
461
462SGPBPopup.prototype.getCompatibleZiIndex = function(popupZIndex)
463{
464	/*2147483647 it's maximal z index value*/
465	if (popupZIndex > 2147483647) {
466		return 2147483627;
467	}
468
469	return popupZIndex;
470};
471
472SGPBPopup.prototype.prepareOpen = function()
473{
474	var popupId = this.getPopupId();
475	var popupData = this.getPopupData();
476	var popupZIndex = this.getCompatibleZiIndex(popupData['sgpb-popup-z-index']);
477	var popupType = this.popupData['sgpb-type'];
478	this.setUpPopupConfig();
479	var that = this;
480	var popupConfig = this.getPopupConfig();
481
482	function decodeEntities(encodedString)
483	{
484		if (typeof encodedString == 'undefined') {
485			return '';
486		}
487		var suspiciousStrings = ['document.createElement', 'createElement', 'String.fromCharCode', 'fromCharCode'];
488		for (var i in suspiciousStrings) {
489			if (encodedString.indexOf(suspiciousStrings[i]) > 0) {
490				return '';
491			}
492		}
493		var textArea = document.createElement('textarea');
494		textArea.innerHTML = encodedString;
495
496		return textArea.value;
497	}
498
499	popupConfig.customShouldOpen = function()
500	{
501		var instructions = popupData['sgpb-ShouldOpen'];
502		instructions = decodeEntities(instructions);
503		var F = new Function (instructions);
504
505		return(F());
506	};
507
508	popupConfig.customShouldClose = function()
509	{
510		var instructions = popupData['sgpb-ShouldClose'];
511		instructions = decodeEntities(instructions);
512		var F = new Function (instructions);
513
514		return(F());
515	};
516
517	this.setPopupDimensions();
518
519	if (popupData['sgpb-disable-popup-closing'] == 'on') {
520		popupData['sgpb-enable-close-button'] = '';
521		popupData['sgpb-esc-key'] = '';
522		popupData['sgpb-overlay-click'] = '';
523	}
524	/*used in the analytics*/
525	popupData['eventName'] = this.eventName;
526
527	if (SGPBPopup.varToBool(popupData['sgpb-enable-close-button'])) {
528		popupConfig.magicCall('setCloseButtonDelay', parseInt(popupData['sgpb-close-button-delay']));
529	}
530
531	popupConfig.magicCall('setShowButton', SGPBPopup.varToBool(popupData['sgpb-enable-close-button']));
532	/* Convert seconds to micro seconds */
533	var openAnimationSpeed = parseFloat(popupData['sgpb-open-animation-speed'])*1000;
534	var closeAnimationSpeed = parseFloat(popupData['sgpb-close-animation-speed'])*1000;
535	popupConfig.magicCall('setOpenAnimationEffect', popupData['sgpb-open-animation-effect']);
536	popupConfig.magicCall('setCloseAnimationEffect', popupData['sgpb-close-animation-effect']);
537	popupConfig.magicCall('setOpenAnimationSpeed', openAnimationSpeed);
538	popupConfig.magicCall('setCloseAnimationSpeed', closeAnimationSpeed);
539	popupConfig.magicCall('setOpenAnimationStatus', popupData['sgpb-open-animation']);
540	popupConfig.magicCall('setCloseAnimationStatus', popupData['sgpb-close-animation']);
541	popupConfig.magicCall('setContentPadding', popupData['sgpb-content-padding']);
542	if (typeof SgpbRecentSalesPopupType != 'undefined') {
543		if (popupType == SgpbRecentSalesPopupType) {
544			/* set max z index for recent sales popup */
545			popupZIndex = 2147483647;
546			popupConfig.magicCall('setCloseAnimationEffect', 'fade');
547			popupConfig.magicCall('setCloseAnimationSpeed', 1000);
548			popupConfig.magicCall('setCloseAnimationStatus', 'on');
549		}
550	}
551
552	popupConfig.magicCall('setZIndex', popupZIndex);
553	popupConfig.magicCall('setCloseButtonWidth', popupData['sgpb-button-image-width']);
554	popupConfig.magicCall('setCloseButtonHeight', popupData['sgpb-button-image-height']);
555	popupConfig.magicCall('setPopupId', popupId);
556	popupConfig.magicCall('setPopupData', popupData);
557	popupConfig.magicCall('setAllowed', !SGPBPopup.varToBool(popupData['sgpb-disable-popup-closing']));
558	if (popupData['sgpb-type'] == SGPB_POPUP_PARAMS.popupTypeAgeRestriction) {
559		popupConfig.magicCall('setAllowed', false);
560	}
561	popupConfig.magicCall('setEscShouldClose', SGPBPopup.varToBool(popupData['sgpb-esc-key']));
562	popupConfig.magicCall('setOverlayShouldClose', SGPBPopup.varToBool(popupData['sgpb-overlay-click']));
563
564	popupConfig.magicCall('setScrollingEnabled', SGPBPopup.varToBool(popupData['sgpb-enable-content-scrolling']));
565
566	if (SGPBPopup.varToBool(popupData['sgpb-content-click'])) {
567		this.contentCloseBehavior();
568	}
569	sgAddEvent(window, 'sgpbWillOpen', function(e) {
570		if (popupId != e.detail.popupId || e.detail.popupData['sgpb-content-click'] == 'undefined') {
571			return false;
572		}
573		/* triggering any popup content click (analytics) */
574		that.popupContentClick(e);
575	});
576	if (SGPBPopup.varToBool(popupData['sgpb-popup-fixed'])) {
577		this.addFixedPosition();
578	}
579	/*ThemeCreator*/
580	this.themeCreator();
581	this.themeCustomizations();
582
583	popupConfig.magicCall('setContents', document.getElementById('sg-popup-content-wrapper-'+popupId));
584	popupConfig.magicCall('setPopupType', popupType);
585	this.setPopupConfig(popupConfig);
586	this.popupTriggeringListeners();
587
588	/* check popup type, then check if popup can be opened by popup type */
589	var allowToOpen = this.checkCurrentPopupType();
590	if (allowToOpen) {
591		this.open();
592	}
593};
594
595SGPBPopup.prototype.popupContentClick = function(e)
596{
597	var args = e.detail;
598	var popupId = parseInt(args['popupId']);
599	jQuery('.sgpb-content-' + popupId).on('click', function(event) {
600		var settings = {
601			popupId: popupId,
602			eventName: 'sgpbPopupContentclick'
603		};
604		jQuery(window).trigger('sgpbPopupContentclick', settings);
605	});
606};
607
608SGPBPopup.prototype.forceCheckCurrentPopupType = function(popupObj)
609{
610	var allowToOpen = true;
611	var popupConfig = new PopupConfig();
612	var className = popupObj.popupData['sgpb-type'];
613	if (typeof className == 'undefined' || className == 'undefined') {
614		return false;
615	}
616
617	if (typeof SGPB_POPUP_PARAMS.conditionalJsClasses != 'undefined' && SGPB_POPUP_PARAMS.conditionalJsClasses.length) {
618		var isAllowConditions = this.forceIsAllowJsConditions(popupObj);
619
620		if (!isAllowConditions) {
621			return false;
622		}
623	}
624
625	var popupConfig = new PopupConfig();
626	var className = this.popupData['sgpb-type'];
627	/* make the first letter of a string uppercase, then concat prefix (uppercase all prefix string) */
628	className = popupConfig.prefix.toUpperCase() + PopupConfig.firstToUpperCase(className);
629	/* hasOwnProperty returns boolean value */
630	if (window.hasOwnProperty(className)) {
631		className = eval(className);
632		/* create current popup type object */
633		var obj = new className;
634		/* call allowToOpen function if exists */
635		if (typeof obj.allowToOpen === 'function') {
636			allowToOpen = obj.allowToOpen(this.id);
637			if (!allowToOpen) {
638				isAllow = allowToOpen;
639			}
640		}
641	}
642
643	var allowToOpen = this.checkCurrentPopupType();
644	if (!allowToOpen) {
645		return false;
646	}
647
648	return allowToOpen;
649};
650
651SGPBPopup.prototype.checkCurrentPopupType = function()
652{
653	var allowToOpen = true;
654	var popupConfig = new PopupConfig();
655
656	var isPreview = parseInt(this.popupData['sgpb-is-preview']);
657	if (!isNaN(isPreview) && isPreview == 1) {
658		return allowToOpen;
659	}
660
661	var popupHasLimit = this.isSatistfyForShowingLimitation(this.popupData);
662	if (!popupHasLimit) {
663		return false;
664	}
665
666	var dontShowPopupCookieName = 'sgDontShowPopup' + this.popupData['sgpb-post-id'];
667	var dontShowPopup = SGPopup.getCookie(dontShowPopupCookieName);
668	if (dontShowPopup != '') {
669		return false;
670	}
671
672	var className = this.popupData['sgpb-type'];
673	if (typeof className == 'undefined' || className == 'undefined') {
674		return false;
675	}
676
677	if (typeof SGPB_POPUP_PARAMS.conditionalJsClasses != 'undefined' && SGPB_POPUP_PARAMS.conditionalJsClasses.length) {
678		var isAllowConditions = this.isAllowJsConditions();
679
680		if (!isAllowConditions) {
681			return false;
682		}
683	}
684
685	/* make the first letter of a string uppercase, then concat prefix (uppercase all prefix string) */
686	className = popupConfig.prefix.toUpperCase() + PopupConfig.firstToUpperCase(className);
687	/* hasOwnProperty returns boolean value */
688	if (window.hasOwnProperty(className)) {
689		className = eval(className);
690		/* create current popup type object */
691		var obj = new className;
692		/* call allowToOpen function if exists */
693		if (typeof obj.allowToOpen === 'function') {
694			allowToOpen = obj.allowToOpen(this.id);
695		}
696	}
697
698	return allowToOpen;
699};
700
701SGPBPopup.prototype.forceIsAllowJsConditions = function(popupObj) {
702	var conditions = SGPB_POPUP_PARAMS.conditionalJsClasses;
703
704	var isAllow = true;
705
706	for (var i in conditions) {
707		if (!conditions.hasOwnProperty(i)) {
708			break;
709		}
710
711		try {
712			var className = eval(conditions[i]);
713		}
714		catch (e) {
715			continue;
716		}
717		var obj = new className;
718		/* call allowToOpen function if exists */
719		if (typeof obj.forceAllowToOpen === 'function') {
720			var popupData = this.getPopupData();
721			var allowToOpen = obj.forceAllowToOpen(popupObj.id, popupObj);
722
723			if (!allowToOpen) {
724				isAllow = allowToOpen;
725				break;
726			}
727		}
728	}
729
730	return isAllow;
731};
732
733SGPBPopup.prototype.isAllowJsConditions = function() {
734	var conditions = SGPB_POPUP_PARAMS.conditionalJsClasses;
735	var isAllow = true;
736
737	for (var i in conditions) {
738		if (!conditions.hasOwnProperty(i)) {
739			break;
740		}
741
742		try {
743			var className = eval(conditions[i]);
744		}
745		catch (e) {
746			continue;
747		}
748		var obj = new className;
749		/* call allowToOpen function if exists */
750		if (typeof obj.allowToOpen === 'function') {
751			var allowToOpen = obj.allowToOpen(this.id, this);
752			if (!allowToOpen) {
753				isAllow = allowToOpen;
754				break;
755			}
756		}
757	}
758
759	return isAllow;
760};
761
762SGPBPopup.prototype.setPopupLimitationCookie = function(popupData)
763{
764	var cookieData = this.getPopupShowLimitationCookie(popupData);
765	var cookie = cookieData.cookie || {};
766	var openingCount = cookie.openingCount || 0;
767	var currentUrl = window.location.href;
768
769	if (!popupData['sgpb-show-popup-same-user-page-level']) {
770		currentUrl = '';
771	}
772	cookie.openingCount = openingCount + 1;
773	cookie.openingPage = currentUrl;
774	var popupShowingLimitExpiry = parseInt(popupData['sgpb-show-popup-same-user-expiry']);
775
776	SGPBPopup.setCookie(cookieData.cookieName, JSON.stringify(cookie), popupShowingLimitExpiry, currentUrl);
777};
778
779SGPBPopup.prototype.isSatistfyForShowingLimitation = function(popupData)
780{
781	/*enable||disable*/
782	var popupLimitation = popupData['sgpb-show-popup-same-user'];
783
784	/*if this option unchecked popup must be show*/
785	if (!popupLimitation) {
786		return true;
787	}
788	var cookieData = this.getPopupShowLimitationCookie(popupData);
789
790	/*when there is not*/
791	if (!cookieData.cookie) {
792		return true;
793	}
794
795	return popupData['sgpb-show-popup-same-user-count'] > cookieData.cookie.openingCount;
796};
797
798SGPBPopup.prototype.getPopupShowLimitationCookie = function(popupData)
799{
800	var savedCookie = this.getPopupShowLimitationCookieDetails(popupData);
801	var savedCookie = this.filterPopupLimitationCookie(savedCookie);
802
803	return savedCookie;
804};
805
806SGPBPopup.prototype.filterPopupLimitationCookie = function(cookie)
807{
808	var result = {};
809	result.cookie = '';
810	if (cookie.isPageLevel) {
811
812		result.cookieName = cookie.pageLevelCookieName;
813		if (cookie.pageLevelCookie) {
814			result.cookie = jQuery.parseJSON(cookie.pageLevelCookie);
815		}
816
817		SGPBPopup.deleteCookie(cookie.domainLevelCookieName);
818
819		return result;
820	}
821	result.cookieName = cookie.domainLevelCookieName;
822	if (cookie.domainLevelCookie) {
823		result.cookie = jQuery.parseJSON(cookie.domainLevelCookie);
824	}
825	var currentUrl = window.location.href;
826
827	SGPBPopup.deleteCookie(cookie.pageLevelCookieName, currentUrl);
828
829	return result;
830};
831
832SGPBPopup.prototype.getPopupShowLimitationCookieDetails = function(popupData)
833{
834	var result = false;
835	var currentUrl = window.location.href;
836	var currentPopupId = popupData['sgpb-post-id'];
837
838	/*Cookie names*/
839	var popupLimitationCookieHomePageLevelName = 'SGPBShowingLimitationHomePage' + currentPopupId;
840	var popupLimitationCookiePageLevelName = 'SGPBShowingLimitationPage' + currentPopupId;
841	var popupLimitationCookieDomainName = 'SGPBShowingLimitationDomain' + currentPopupId;
842
843	var pageLevelCookie = popupData['sgpb-show-popup-same-user-page-level'] || false;
844
845	/*check if current url is home page*/
846	if (currentUrl == SGPB_POPUP_PARAMS.homePageUrl) {
847		popupLimitationCookiePageLevelName = popupLimitationCookieHomePageLevelName;
848	}
849	var popupLimitationPageLevelCookie = SGPopup.getCookie(popupLimitationCookiePageLevelName);
850	var popupLimitationDomainCookie = SGPopup.getCookie(popupLimitationCookieDomainName);
851
852	result = {
853		'pageLevelCookieName': popupLimitationCookiePageLevelName,
854		'domainLevelCookieName': popupLimitationCookieDomainName,
855		'pageLevelCookie': popupLimitationPageLevelCookie,
856		'domainLevelCookie': popupLimitationDomainCookie,
857		'isPageLevel': pageLevelCookie
858	};
859
860	return result;
861};
862
863SGPBPopup.prototype.themeCreator = function()
864{
865	var noPositionSelected = false;
866	var popupData = this.getPopupData();
867	var popupId = this.getPopupId();
868	var popupConfig = this.getPopupConfig();
869	var forceRtlClass = '';
870	var forceRtl = SGPBPopup.varToBool(popupData['sgpb-force-rtl']);
871	var popupTheme = popupData['sgpb-popup-themes'];
872	var popupType = popupData['sgpb-type'];
873	var closeButtonWidth = popupData['sgpb-button-image-width'];
874	var closeButtonHeight = popupData['sgpb-button-image-height'];
875	var contentPadding = parseInt(popupData['sgpb-content-padding']);
876	/* close button position */
877	var top = parseInt(popupData['sgpb-button-position-top']);
878	var right = parseInt(popupData['sgpb-button-position-right']);
879	var bottom = parseInt(popupData['sgpb-button-position-bottom']);
880	var left = parseInt(popupData['sgpb-button-position-left']);
881
882	var contentClass = popupData['sgpb-content-custom-class'];
883	/* for the 2-nd and 3-rd themes only */
884	var popupBorder = SGPBPopup.varToBool(popupData['sgpb-disable-border']);
885	var closeButtonImage = popupConfig.closeButtonImage;
886	var themeNumber = 1;
887	var backgroundColor = 'black';
888	var borderColor = 'inherit';
889	var recentSalesPopup = false;
890	if (typeof SgpbRecentSalesPopupType != 'undefined') {
891		if (popupType == SgpbRecentSalesPopupType) {
892			recentSalesPopup = true;
893			popupTheme = 'sgpb-theme-2';
894			closeButtonPosition = 'topRight';
895			backgroundColor = 'white';
896			borderColor = '#ececec';
897			top = '-10';
898			right = '-10';
899			popupConfig.magicCall('setShadowSpread', 1);
900			popupConfig.magicCall('setContentShadowBlur', 5);
901			popupConfig.magicCall('setOverlayVisible', false);
902			popupConfig.magicCall('setContentShadowColor', '#000000b3');
903			popupConfig.magicCall('setContentBorderRadius', '5px');
904		}
905	}
906	var themeIndexNum = popupTheme[popupTheme.length -1];
907
908	if (isNaN(top)) {
909		top = this.closeButtonDefaultPositions[themeIndexNum].top;
910	}
911	if (isNaN(right)) {
912		right = this.closeButtonDefaultPositions[themeIndexNum].right;
913	}
914	if (isNaN(bottom)) {
915		bottom = this.closeButtonDefaultPositions[themeIndexNum].bottom;
916	}
917	if (isNaN(left)) {
918		left = this.closeButtonDefaultPositions[themeIndexNum].left;
919	}
920	if (forceRtl) {
921		forceRtlClass = ' sgpb-popup-content-direction-right';
922	}
923	if (popupData['sgpb-type'] == 'countdown') {
924		popupConfig.magicCall('setMinWidth', 300);
925	}
926	popupConfig.magicCall('setContentPadding', contentPadding);
927	popupConfig.magicCall('setOverlayAddClass', popupTheme+'-overlay sgpb-popup-overlay-' + popupId);
928	popupConfig.magicCall('setContentAddClass', 'sgpb-content sgpb-content-'+popupId+' ' + popupTheme+'-content ' + contentClass + forceRtlClass);
929
930	if (typeof popupData['sgpb-close-button-position'] == 'undefined' || popupData['sgpb-close-button-position'] == '') {
931		/*
932		 * in the old version we don't have close button position option
933		 * and if noPositionSelected is true, the popup was not edited
934		 */
935		var noPositionSelected = true;
936	}
937	else {
938		var closeButtonPosition = popupData['sgpb-close-button-position'];
939		popupConfig.magicCall('setButtonPosition', closeButtonPosition);
940	}
941
942	if (popupTheme == 'sgpb-theme-1') {
943		themeNumber = 1;
944		popupConfig.magicCall('setShadowSpread', 14);
945		/* 9px theme default close button position for all cases */
946		if (noPositionSelected || closeButtonPosition == 'bottomRight') {
947			popupConfig.magicCall('setCloseButtonPositionRight', right+'px');
948			popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px');
949		}
950		else {
951			popupConfig.magicCall('setCloseButtonPositionLeft', left+'px');
952			popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px');
953		}
954	}
955	else if (popupTheme == 'sgpb-theme-2') {
956		themeNumber = 2;
957		popupConfig.magicCall('setButtonInside', false);
958		popupConfig.magicCall('setContentBorderWidth', 1);
959		popupConfig.magicCall('setContentBackgroundColor', backgroundColor);
960		popupConfig.magicCall('setContentBorderColor', borderColor);
961		popupConfig.magicCall('setOverlayColor', 'white');
962		var rightPosition = '0';
963		var topPosition = '-' + closeButtonHeight + 'px';
964		if (recentSalesPopup) {
965			rightPosition = '-' + (closeButtonWidth / 2) + 'px';
966			topPosition = '-' + (closeButtonHeight / 2) + 'px';
967			themeNumber = 6;
968		}
969		if (noPositionSelected || closeButtonPosition == 'topRight') {
970			/* this theme has 1px border */
971			popupConfig.magicCall('setCloseButtonPositionRight', right+'px');
972			popupConfig.magicCall('setCloseButtonPositionTop', top+'px');
973		}
974		else {
975			if (closeButtonPosition == 'topLeft') {
976				popupConfig.magicCall('setCloseButtonPositionLeft', left+'px');
977				popupConfig.magicCall('setCloseButtonPositionTop', top+'px');
978			}
979			else if (closeButtonPosition == 'bottomRight') {
980				popupConfig.magicCall('setCloseButtonPositionRight', right+'px');
981				popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px');
982			}
983			else if (closeButtonPosition == 'bottomLeft') {
984				popupConfig.magicCall('setCloseButtonPositionLeft', left+'px');
985				popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px');
986			}
987		}
988
989		if (popupBorder) {
990			popupConfig.magicCall('setContentBorderWidth', 0);
991		}
992	}
993	else if (popupTheme == 'sgpb-theme-3') {
994		themeNumber = 3;
995		popupConfig.magicCall('setContentBorderWidth', 5);
996		popupConfig.magicCall('setContentBorderRadius', popupData['sgpb-border-radius']);
997		popupConfig.magicCall('setContentBorderRadiusType', popupData['sgpb-border-radius-type']);
998		popupConfig.magicCall('setContentBorderColor', popupData['sgpb-border-color']);
999		var closeButtonPositionPx = '4px';
1000		if (popupBorder) {
1001			popupConfig.magicCall('setContentBorderWidth', 0);
1002			closeButtonPositionPx = '0px';
1003		}
1004		if (noPositionSelected) {
1005			popupConfig.magicCall('setCloseButtonWidth', 38);
1006			popupConfig.magicCall('setCloseButtonHeight', 19);
1007			popupConfig.magicCall('setCloseButtonPositionRight', right+'px');
1008			popupConfig.magicCall('setCloseButtonPositionTop', top+'px');
1009		}
1010		else {
1011			if (closeButtonPosition == 'topRight') {
1012				popupConfig.magicCall('setCloseButtonPositionRight', right+'px');
1013				popupConfig.magicCall('setCloseButtonPositionTop', top+'px');
1014			}
1015			else if (closeButtonPosition == 'topLeft') {
1016				popupConfig.magicCall('setCloseButtonPositionLeft', left+'px');
1017				popupConfig.magicCall('setCloseButtonPositionTop', top+'px');
1018			}
1019			else if (closeButtonPosition == 'bottomRight') {
1020				popupConfig.magicCall('setCloseButtonPositionLeft', right+'px');
1021				popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px');
1022			}
1023			else if (closeButtonPosition == 'bottomLeft') {
1024				popupConfig.magicCall('setCloseButtonPositionLeft', left+'px');
1025				popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px');
1026			}
1027		}
1028	}
1029	else if (popupTheme == 'sgpb-theme-4') {
1030		/* in theme-4 close button type is button,not image,
1031		 * then set type to button, default is image and
1032		 * set text
1033		 */
1034		themeNumber = 4;
1035		popupConfig.magicCall('setButtonImage', popupData['sgpb-button-text']);
1036		popupConfig.magicCall('setCloseButtonType', 'button');
1037		popupConfig.magicCall('setCloseButtonText', popupData['sgpb-button-text']);
1038		popupConfig.magicCall('setContentBorderWidth', 0);
1039		popupConfig.magicCall('setContentBackgroundColor', 'white');
1040		popupConfig.magicCall('setContentBorderColor', 'white');
1041		popupConfig.magicCall('setOverlayColor', 'white');
1042		popupConfig.magicCall('setShadowSpread', 4);
1043		popupConfig.magicCall('setContentShadowBlur', 8);
1044		/* 8px/12px theme default close button position for all cases */
1045		if (noPositionSelected || closeButtonPosition == 'bottomRight') {
1046			popupConfig.magicCall('setCloseButtonPositionRight', right+'px');
1047			popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px');
1048		}
1049		else {
1050			popupConfig.magicCall('setCloseButtonPositionLeft', left+'px');
1051			popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px');
1052		}
1053	}
1054	else if (popupTheme == 'sgpb-theme-5') {
1055		themeNumber = 5;
1056		popupConfig.magicCall('setBoxBorderWidth', 10);
1057		popupConfig.magicCall('setContentBorderColor', '#4B4B4B');
1058		if (noPositionSelected || closeButtonPosition == 'bottomRight') {
1059			popupConfig.magicCall('setCloseButtonPositionRight', right+'px');
1060			popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px');
1061		}
1062		else {
1063			popupConfig.magicCall('setCloseButtonPositionLeft', left+'px');
1064			popupConfig.magicCall('setCloseButtonPositionBottom', bottom+'px');
1065		}
1066	}
1067	else if (popupTheme == 'sgpb-theme-6') {
1068		themeNumber = 6;
1069		popupConfig.magicCall('setButtonInside', false);
1070		popupConfig.magicCall('setContentBorderRadius', 7);
1071		popupConfig.magicCall('setContentBorderRadiusType', 'px');
1072		if (noPositionSelected) {
1073			popupConfig.magicCall('setCloseButtonWidth', 37);
1074			popupConfig.magicCall('setCloseButtonHeight', 37);
1075			popupConfig.magicCall('setCloseButtonPositionRight', right+'px');
1076			popupConfig.magicCall('setCloseButtonPositionTop', top+'px');
1077		}
1078		else {
1079			if (typeof popupData['sgpb-button-position-right'] == 'undefined') {
1080				right = '-' + (closeButtonWidth / 2);
1081				top = '-' + (closeButtonHeight / 2);
1082				left = '-' + (closeButtonWidth / 2);
1083				bottom = '-' + (closeButtonHeight / 2);
1084			}
1085			if (closeButtonPosition == 'topRight') {
1086				popupConfig.magicCall('setCloseButtonPositionRight', right + 'px');
1087				popupConfig.magicCall('setCloseButtonPositionTop', top + 'px');
1088			}
1089			else if (closeButtonPosition == 'topLeft') {
1090				popupConfig.magicCall('setCloseButtonPositionLeft', left + 'px');
1091				popupConfig.magicCall('setCloseButtonPositionTop', top + 'px');
1092			}
1093			else if (closeButtonPosition == 'bottomRight') {
1094				popupConfig.magicCall('setCloseButtonPositionRight', right + 'px');
1095				popupConfig.magicCall('setCloseButtonPositionBottom', bottom + 'px');
1096			}
1097			else if (closeButtonPosition == 'bottomLeft') {
1098				popupConfig.magicCall('setCloseButtonPositionLeft', left + 'px');
1099				popupConfig.magicCall('setCloseButtonPositionBottom', bottom + 'px');
1100			}
1101		}
1102	}
1103
1104	popupConfig.magicCall('setPopupTheme', themeNumber);
1105	if (!popupData['sgpb-button-image']) {
1106		closeButtonImage = SGPB_POPUP_PARAMS.defaultThemeImages[themeNumber];
1107		if (typeof closeButtonImage  != 'undefined') {
1108			popupConfig.magicCall('setButtonImage', closeButtonImage);
1109		}
1110	}
1111	else {
1112		popupConfig.magicCall('setButtonImage', 'data:image/png;base64,'+popupData['sgpb-button-image-data']);
1113		if (popupData['sgpb-button-image-data'] == '' || popupData['sgpb-button-image-data'].indexOf('http') != -1) {
1114			popupConfig.magicCall('setButtonImage', popupData['sgpb-button-image']);
1115		}
1116	}
1117
1118};
1119
1120SGPBPopup.prototype.themeCustomizations = function()
1121{
1122	var popupId = this.getPopupId();
1123	var popupData = this.getPopupData();
1124	var popupConfig = this.getPopupConfig();
1125
1126	var contentOpacity = popupData['sgpb-content-opacity'];
1127	var contentBgColor = popupData['sgpb-background-color'];
1128	if (popupData['sgpb-background-image-data']) {
1129		var contentBgImage = 'data:image/png;base64,'+popupData['sgpb-background-image-data'];
1130	}
1131	else {
1132		var contentBgImage = popupData['sgpb-background-image'];
1133	}
1134	var showContentBackground = popupData['sgpb-show-background'];
1135	var contentBgImageMode = popupData['sgpb-background-image-mode'];
1136	var overlayColor = popupData['sgpb-overlay-color'];
1137	var popupTheme = popupData['sgpb-popup-themes'];
1138	var popupType = popupData['sgpb-type'];
1139	if (typeof popupData['sgpb-overlay-custom-class'] == 'undefined') {
1140		popupData['sgpb-overlay-custom-class'] = 'sgpb-popup-overlay';
1141	}
1142	if (typeof popupData['sgpb-popup-themes'] == 'undefined') {
1143		popupTheme = 'sgpb-theme-2';
1144	}
1145
1146	if (typeof showContentBackground == 'undefined') {
1147		contentBgColor = '';
1148		contentBgImage = '';
1149		contentBgImageMode = '';
1150	}
1151	if (typeof SgpbRecentSalesPopupType != 'undefined') {
1152		if (popupType == SgpbRecentSalesPopupType) {
1153			showContentBackground = 'on';
1154			contentBgColor = popupData['sgpb-background-color'];
1155			contentOpacity = popupData['sgpb-content-opacity'];
1156		}
1157	}
1158
1159	if (contentOpacity) {
1160		popupConfig.magicCall('setContentBackgroundOpacity', contentOpacity);
1161	}
1162	if (contentBgImageMode) {
1163		popupConfig.magicCall('setContentBackgroundMode', contentBgImageMode);
1164	}
1165	if (contentBgImage) {
1166		popupConfig.magicCall('setContentBackgroundImage', contentBgImage);
1167	}
1168	if (contentBgColor) {
1169		contentBgColor = SGPBPopup.hexToRgba(contentBgColor, contentOpacity);
1170		popupConfig.magicCall('setContentBackgroundColor', contentBgColor);
1171	}
1172	if (overlayColor) {
1173		popupConfig.magicCall('setOverlayColor', overlayColor);
1174	}
1175
1176	var overlayClasses = popupTheme+'-overlay sgpb-popup-overlay-'+popupId;
1177	if (SGPB_JS_PACKAGES.extensions['advanced-closing']) {
1178		if (typeof popupData['sgpb-enable-popup-overlay'] != 'undefined' && popupData['sgpb-enable-popup-overlay'] == 'on') {
1179			popupData['sgpb-enable-popup-overlay'] = true;
1180		}
1181		else if (typeof popupData['sgpb-enable-popup-overlay'] == 'undefined') {
1182			popupData['sgpb-enable-popup-overlay'] = false;
1183		}
1184	}
1185	else {
1186		popupData['sgpb-enable-popup-overlay'] = true;
1187	}
1188
1189	popupConfig.magicCall('setOverlayVisible', SGPBPopup.varToBool(popupData['sgpb-enable-popup-overlay']));
1190	if (typeof SgpbRecentSalesPopupType != 'undefined') {
1191		popupConfig.magicCall('setOverlayVisible', false);
1192	}
1193	if (SGPBPopup.varToBool(popupData['sgpb-enable-popup-overlay'])) {
1194		popupConfig.magicCall('setOverlayAddClass', overlayClasses + ' ' + popupData['sgpb-overlay-custom-class']);
1195		var overlayOpacity = popupData['sgpb-overlay-opacity'] || 0.8;
1196		popupConfig.magicCall('setOverlayOpacity', overlayOpacity * 100);
1197	}
1198};
1199
1200SGPBPopup.prototype.formSubmissionDetection = function(args)
1201{
1202	if (args.length) {
1203		return false;
1204	}
1205	var popupId = args.popupId;
1206	var options = SGPBPopup.getPopupOptionsById(popupId);
1207
1208	if (!options['sgpb-reopen-after-form-submission']) {
1209		return false;
1210	}
1211
1212	jQuery('.sgpb-popup-builder-content-' + popupId + ' form').submit(function() {
1213		SGPBPopup.setCookie('SGPBSubmissionReloadPopup', popupId);
1214	});
1215};
1216
1217SGPBPopup.prototype.htmlIframeFilterForOpen = function(popupId, popupEventName)
1218{
1219	var popupContent = jQuery('.sgpb-content-' + popupId);
1220
1221	if (!popupContent.length) {
1222		return false;
1223	}
1224
1225	popupContent.find('iframe').each(function() {
1226
1227		if (popupEventName != 'open') {
1228			/* for do not affect facebook type buttons iframe only */
1229			if (jQuery(this).closest('.fb_iframe_widget').length) {
1230				return true;
1231			}
1232
1233			/*close*/
1234			if (typeof jQuery(this).attr('data-attr-src') == 'undefined') {
1235				var src = jQuery(this).attr('src');
1236				if (src != '') {
1237					jQuery(this).attr('data-attr-src', src);
1238					jQuery(this).attr('src', '');
1239				}
1240				return true;
1241			}
1242			else {
1243				var src = jQuery(this).attr('src');
1244				if (src != '') {
1245					jQuery(this).attr('data-attr-src', src);
1246					jQuery(this).attr('src', '');
1247				}
1248				return true;
1249			}
1250		}
1251		else {
1252			/*open*/
1253			if (typeof jQuery(this).attr('data-attr-src') == 'undefined') {
1254				var src = jQuery(this).attr('src');
1255				if (src != '') {
1256					jQuery(this).attr('data-attr-src', src);
1257				}
1258
1259				return true;
1260			}
1261			else {
1262				var src = jQuery(this).attr('data-attr-src');
1263				if (src != '') {
1264					jQuery(this).attr('src', src);
1265					jQuery(this).attr('data-attr-src', src);
1266				}
1267				return true;
1268			}
1269		}
1270	});
1271};
1272
1273SGPBPopup.prototype.iframeSizesInHtml = function(args)
1274{
1275	var popupId = args['popupId'];
1276	var popupOptions = args.popupData;
1277	var popupContent = jQuery('.sgpb-content-' + popupId);
1278
1279	if (!popupContent.length) {
1280		return false;
1281	}
1282	popupContent.find('iframe').each(function() {
1283		if (typeof jQuery(this) == 'undefined') {
1284			return false;
1285		}
1286		if (popupOptions['sgpb-popup-dimension-mode'] == 'customMode') {
1287			if (typeof jQuery(this).attr('width') == 'undefined' && typeof popupContent.attr('height') == 'undefined') {
1288				jQuery(this).css({'width': popupOptions['sgpb-width'], 'height': popupOptions['sgpb-height']});
1289			}
1290		}
1291	});
1292};
1293
1294SGPBPopup.prototype.getSearchDataFromContent = function(content)
1295{
1296	var pattern = /\[(\[?)(pbvariable)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]\*+(?:\[(?!\/\2\])[^\[]\*+)\*+)\[\/\2\])?)(\]?)/gi;
1297	var match;
1298	var collectedData = [];
1299
1300	while (match = pattern.exec(content)) {
1301		var currentSearchData = [];
1302		var attributes;
1303		var attributesKeyValue = [];
1304		var parseAttributes = /\s(\w+?)="(.+?)"/g;
1305		currentSearchData['replaceString'] = this.htmlDecode(match[0]);
1306
1307		while (attributes = parseAttributes.exec(match[3])) {
1308			attributesKeyValue[attributes[1]] = this.htmlDecode(attributes[2]);
1309		}
1310
1311		currentSearchData['searchData'] = attributesKeyValue;
1312		collectedData.push(currentSearchData);
1313	}
1314
1315	return collectedData;
1316};
1317
1318SGPBPopup.prototype.replaceWithCustomShortcode = function(popupId)
1319{
1320	var currentHtmlContent = jQuery('.sgpb-content-'+popupId).html();
1321	var searchData = this.getSearchDataFromContent(currentHtmlContent);
1322	var that = this;
1323
1324	if (!searchData.length) {
1325		return false;
1326	}
1327
1328	for (var index in searchData) {
1329		var currentSearchData = searchData[index];
1330		var searchAttributes = currentSearchData['searchData'];
1331
1332		if (typeof searchAttributes['selector'] == 'undefined' || typeof searchAttributes['attribute'] == 'undefined') {
1333			that.replaceShortCode(currentSearchData['replaceString'], '', popupId);
1334			continue;
1335		}
1336
1337		try {
1338			if (!jQuery(searchAttributes['selector']).length) {
1339				that.replaceShortCode(currentSearchData['replaceString'], '', popupId);
1340				continue;
1341			}
1342		}
1343		catch (e) {
1344			that.replaceShortCode(currentSearchData['replaceString'], '', popupId);
1345			continue;
1346		}
1347
1348		if (searchAttributes['attribute'] == 'text') {
1349			var replaceName = jQuery(searchAttributes['selector']).text();
1350		}
1351		else {
1352			var replaceName = jQuery(searchAttributes['selector']).attr(searchAttributes['attribute']);
1353		}
1354
1355		if (typeof replaceName == 'undefined') {
1356			that.replaceShortCode(currentSearchData['replaceString'], '', popupId);
1357			continue;
1358		}
1359
1360		that.replaceShortCode(currentSearchData['replaceString'], replaceName, popupId);
1361	}
1362};
1363
1364SGPBPopup.prototype.replaceShortCode = function(shortCode, replaceText, popupId)
1365{
1366	var popupId = parseInt(popupId);
1367
1368	if (!popupId) {
1369		return false;
1370	}
1371
1372	var popupContentWrapper = jQuery('.sgpb-content-' + popupId);
1373
1374	if (!popupContentWrapper.length) {
1375		return false;
1376	}
1377
1378	popupContentWrapper.find('div').each(function() {
1379		var currentHtmlContent = jQuery(this).contents();
1380
1381		if (!currentHtmlContent.length) {
1382			return false;
1383		}
1384
1385		currentHtmlContent.html(function(i, v) {
1386			if (typeof v != 'undefined') {
1387				return v.replace(shortCode, replaceText);
1388			}
1389		});
1390	});
1391
1392	return true;
1393};
1394
1395SGPBPopup.prototype.popupTriggeringListeners = function()
1396{
1397	var that = this;
1398	var popupData = this.getPopupData();
1399	var popupConfig = this.getPopupConfig();
1400
1401	sgAddEvent(window, 'sgpbDidOpen', function(e) {
1402		var args = e.detail;
1403		that.iframeSizesInHtml(args);
1404		that.formSubmissionDetection(args);
1405		var popupOptions = args.popupData;
1406
1407		var closeButtonDelay = parseInt(popupOptions['sgpb-close-button-delay']);
1408		if (closeButtonDelay) {
1409			that.closeButtonDisplay(popupOptions['sgpb-post-id'], 'show', closeButtonDelay);
1410		}
1411		var disablePageScrolling = popupOptions['sgpb-disable-page-scrolling'];
1412		if (popupOptions['sgpb-overlay-color']) {
1413			jQuery('.sgpb-theme-1-overlay').css({'background-image': 'none'});
1414		}
1415		if (SGPBPopup.varToBool(disablePageScrolling)) {
1416			jQuery('html').addClass('sgpb-overflow-hidden');
1417			jQuery('body').addClass('sgpb-overflow-hidden-body');
1418		}
1419	});
1420
1421	sgAddEvent(window, 'sgpbWillOpen', function(e) {
1422		var args = e.detail;
1423		var popupId = parseInt(args['popupId']);
1424		that.htmlIframeFilterForOpen(args.popupId, 'open');
1425		that.replaceWithCustomShortcode(popupId);
1426		that.sgpbDontShowPopup(popupId);
1427
1428		var closeButtonDelay = parseInt(popupData['sgpb-close-button-delay']);
1429		if (closeButtonDelay) {
1430			that.closeButtonDisplay(popupData['sgpb-post-id'], 'hide');
1431		}
1432		/* extra checker for analytics */
1433		var settings = {
1434			popupId: popupData['sgpb-post-id'],
1435			disabledAnalytics: popupData['sgpb-popup-counting-disabled'],
1436			disabledInGeneral: SGPB_POPUP_PARAMS.disableAnalyticsGeneral
1437		};
1438		jQuery(window).trigger('sgpbDisableAnalytics', settings);
1439	});
1440
1441	sgAddEvent(window, 'sgpbShouldClose', function(e) {
1442
1443	});
1444
1445	sgAddEvent(window, 'sgpbWillClose', function(e) {
1446		var args = e.detail;
1447		SGPBPopup.offPopup(e.detail.currentObj);
1448	});
1449};
1450
1451SGPBPopup.prototype.sgpbDontShowPopup = function(popupId)
1452{
1453	var dontShowPopup = jQuery('.sgpb-content-' + popupId).parent().find('[class*="sg-popup-dont-show"]');
1454	if (!dontShowPopup.length) {
1455		return false;
1456	}
1457
1458	dontShowPopup.each(function() {
1459		jQuery(this).bind('click', function(e) {
1460			e.preventDefault();
1461			var expireTime = SGPB_POPUP_PARAMS.dontShowPopupExpireTime;
1462			var cookieName = 'sgDontShowPopup' + popupId;
1463			var classNameSearch = jQuery(this).attr('class').match(/sg-popup-dont-show/);
1464			var className = classNameSearch['input'];
1465			var customExpireTime = className.match(/sg-popup-dont-show-(\d+$)/);
1466
1467			if (customExpireTime) {
1468				expireTime = parseInt(customExpireTime[1]);
1469			}
1470
1471			SGPBPopup.setCookie(cookieName, expireTime, expireTime);
1472			SGPBPopup.closePopupById(popupId);
1473		});
1474	});
1475};
1476
1477SGPBPopup.prototype.addToCounter = function(popupOptions)
1478{
1479	if (SGPB_POPUP_PARAMS.isPreview || (typeof popupOptions['sgpb-popup-counting-disabled'] != 'undefined')) {
1480		return false;
1481	}
1482	var that = this;
1483	var openedPopups = window.sgpbOpenedPopup || {};
1484
1485
1486	var popupId = parseInt(popupOptions['sgpb-post-id']);
1487
1488	if (typeof openedPopups[popupId] == 'undefined') {
1489		openedPopups[popupId] = 1;
1490	}
1491	else {
1492		openedPopups[popupId] += 1;
1493	}
1494	window.sgpbOpenedPopup = openedPopups;
1495};
1496
1497/*
1498 * closeButtonDisplay()
1499 * close or hide close button
1500 * @param popupId
1501 * @param display
1502 * @param delay
1503 */
1504
1505SGPBPopup.prototype.closeButtonDisplay = function(popupId, display, delay)
1506{
1507	if (display == 'show') {
1508		setTimeout(function() {
1509				jQuery('.sgpb-content-' + popupId).prev().show();
1510			},
1511			delay * 1000 /* received values covert to milliseconds */
1512		);
1513	}
1514	else if (display == 'hide') {
1515		jQuery('.sgpb-content-' + popupId).prev().hide();
1516	}
1517};
1518
1519SGPBPopup.prototype.open = function(args)
1520{
1521	var customEvent = this.customEvent;
1522	var config = this.getPopupConfig();
1523	var popupId = this.getPopupId();
1524	var eventName = this.eventName;
1525
1526	if (typeof window.sgPopupBuilder == 'undefined') {
1527		window.sgPopupBuilder = [];
1528	}
1529	var popupData = SGPBPopup.getPopupWindowDataById(popupId);
1530
1531	if (!popupData) {
1532		window.SGPB_ORDER += 1;
1533		var currentObj = {
1534			'eventName': eventName,
1535			'popupId': popupId,
1536			'order': window.SGPB_ORDER,
1537			'isOpen': true,
1538			'sgpbPopupObj': this
1539		};
1540		config.currentObj = currentObj;
1541		var popupConfig = config.combineConfigObj();
1542		var popup = new SGPopup(popupConfig);
1543		currentObj.popup = popup;
1544		window.sgPopupBuilder.push(currentObj);
1545	}
1546	else {
1547		popup = popupData['popup'];
1548		popupData['isOpen'] = true;
1549	}
1550
1551	if (typeof args != 'undefined' && !args['countPopupOpen']) {
1552		/* don't allow to count popup opening */
1553		this.setCountPopupOpen(false);
1554	}
1555	popup.customEvent = customEvent;
1556	popup.open();
1557	this.setPopupObj(popup);
1558
1559	/* contact form 7 form submission
1560	 * TODO: this must be moved to a better place in the future
1561	 * I'm leaving it here for now, since sgpbDidOpen() gets called way too much!
1562	 */
1563	var options = SGPBPopup.getPopupOptionsById(popupId);
1564	SgpbEventListener.CF7EventListener(popupId, options);
1565	if (typeof options['sgpb-behavior-after-special-events'] != 'undefined') {
1566		if (options['sgpb-behavior-after-special-events'].length) {
1567			options = options['sgpb-behavior-after-special-events'][0][0];
1568			if (options['param'] == 'contact-form-7') {
1569				SgpbEventListener.processCF7MailSent(popupId, options);
1570			}
1571		}
1572	}
1573};
1574
1575SGPBPopup.varToBool = function(optionName)
1576{
1577	var returnValue = optionName ? true : false;
1578
1579	return returnValue;
1580};
1581
1582SGPBPopup.hexToRgba = function(hex, opacity)
1583{
1584	var c;
1585	if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
1586		c = hex.substring(1).split('');
1587
1588		if (c.length == 3){
1589			c= [c[0], c[0], c[1], c[1], c[2], c[2]];
1590		}
1591		c = '0x'+c.join('');
1592		return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+','+opacity+')';
1593	}
1594	throw new Error('Bad Hex');
1595};
1596
1597SGPBPopup.prototype.contentCopyToClick = function()
1598{
1599	var popupData = this.getPopupData();
1600	var popupId = this.getPopupId();
1601
1602	var tempInputId = 'content-copy-to-click-'+popupId;
1603	var value = this.htmlDecode(popupData['sgpb-copy-to-clipboard-text']);
1604	var tempInput = document.createElement("input");
1605	tempInput.id = tempInputId;
1606	tempInput.value = value;
1607	tempInput.style = 'position: absolute; right: -10000px';
1608	if (!document.getElementById(tempInputId)) {
1609		document.body.appendChild(tempInput);
1610	}
1611	tempInput.select();
1612	document.execCommand("copy");
1613	document.body.removeChild(tempInput);
1614};
1615
1616SGPBPopup.prototype.htmlDecode = function(value)
1617{
1618	return jQuery('<textarea/>').html(value).text();
1619};
1620
1621SGPBPopup.prototype.findTargetInsideExceptionsList = function(targetName, exceptionList)
1622{
1623	var status = false;
1624	var popupContentMainDiv = document.getElementById('sgpb-popup-dialog-main-div');
1625
1626	while (targetName.parentNode) {
1627		targetName = targetName.parentNode;
1628		if (typeof targetName.tagName == 'undefined') {
1629			continue;
1630		}
1631		var tagName = targetName.tagName.toLowerCase();
1632		if (targetName === popupContentMainDiv) {
1633			break;
1634		}
1635		if (exceptionList.indexOf(tagName) != -1) {
1636			status =  true;
1637			break;
1638		}
1639	}
1640
1641	return status;
1642};
1643
1644SGPBPopup.prototype.contentCloseBehavior = function()
1645{
1646	var that = this;
1647	var popupData = this.getPopupData();
1648	var popupId = this.getPopupId();
1649	var redirectUrl = popupData['sgpb-click-redirect-to-url'];
1650	var contentClickBehavior = popupData['sgpb-content-click-behavior'];
1651	var redirectToNewTab = SGPBPopup.varToBool(popupData['sgpb-redirect-to-new-tab']);
1652	var closePopupAfterCopy = SGPBPopup.varToBool(popupData['sgpb-copy-to-clipboard-close-popup']);
1653	var clipboardAlert = SGPBPopup.varToBool(popupData['sgpb-copy-to-clipboard-alert']);
1654
1655	var separators = ['&amp;', '/&/g'];
1656	for (var i in separators) {
1657		redirectUrl = redirectUrl.split(separators[i]).join('&');
1658	}
1659
1660	sgAddEvent(window, 'sgpbDidOpen', function(e) {
1661
1662	});
1663	sgAddEvent(window, 'sgpbWillOpen', function(e) {
1664		if (popupId != e.detail.popupId || e.detail.popupData['sgpb-content-click'] == 'undefined') {
1665			return false;
1666		}
1667		if (contentClickBehavior == 'redirect') {
1668			jQuery('.sgpb-content-'+popupId).addClass('sgpb-cursor-pointer');
1669		}
1670		jQuery('.sgpb-content-'+e.detail.popupId).on('click', function(event) {
1671			/* we need this settings in analytics */
1672			var settings = {
1673				popupId: popupId,
1674				eventName: 'sgpbPopupContentClick'
1675			};
1676			jQuery(window).trigger('sgpbPopupContentClick', settings);
1677
1678			if (contentClickBehavior == 'redirect') {
1679				if (redirectToNewTab) {
1680					window.open(redirectUrl);
1681					SGPBPopup.closePopupById(that.getPopupId());
1682					return;
1683				}
1684				window.location = redirectUrl;
1685				SGPBPopup.closePopupById(that.getPopupId());
1686			}
1687			else if (contentClickBehavior == 'copy') {
1688				var exceptionList = ['input', 'textarea', 'select', 'button', 'a'];
1689				var targetName = event.target.tagName.toLowerCase();
1690				var parentTagName = event.target.parentNode.tagName.toLowerCase();
1691				var parentsIsInExceptionsList = that.findTargetInsideExceptionsList(event.target, exceptionList);
1692
1693				/*for do not copy when user click to any input element*/
1694				if (exceptionList.indexOf(targetName) == -1 && !parentsIsInExceptionsList) {
1695					that.contentCopyToClick();
1696
1697					if (closePopupAfterCopy) {
1698						SGPBPopup.closePopupById(that.getPopupId());
1699					}
1700					if (clipboardAlert) {
1701						alert(popupData['sgpb-copy-to-clipboard-message'])
1702					}
1703				}
1704			}
1705			else if (popupData['sgpb-disable-popup-closing'] != 'on') {
1706				SGPBPopup.closePopupById(that.getPopupId());
1707			}
1708		});
1709	});
1710
1711	sgAddEvent(window, 'sgpbDidClose', function(e) {
1712
1713	});
1714};
1715
1716SGPBPopup.prototype.addFixedPosition = function()
1717{
1718	var popupData = this.getPopupData();
1719	var popupId = this.getPopupId();
1720	var popupConfig = this.getPopupConfig();
1721
1722	var fixedPosition = popupData['sgpb-popup-fixed-position'];
1723	var positionRight = '';
1724	var positionTop = '';
1725	var positionBottom = '';
1726	var positionLeft = '';
1727
1728	if (fixedPosition == 1) {
1729		positionTop = 40;
1730		positionLeft = 20;
1731	}
1732	else if (fixedPosition == 2) {
1733		positionLeft = 'center';
1734		positionTop = 40;
1735	}
1736	else if (fixedPosition == 3) {
1737		positionTop = 40;
1738		positionRight = 20;
1739	}
1740	else if (fixedPosition == 4) {
1741		positionTop = 'center';
1742		positionLeft = 20;
1743	}
1744	else if (fixedPosition == 6) {
1745		positionTop = 'center';
1746		positionRight = 20;
1747	}
1748	else if (fixedPosition == 7) {
1749		positionLeft = 20;
1750		positionBottom = 2;
1751	}
1752	else if (fixedPosition == 8) {
1753		positionLeft = 'center';
1754		positionBottom = 2;
1755	}
1756	else if (fixedPosition == 9) {
1757		positionRight = 20;
1758		positionBottom = 2;
1759	}
1760
1761	if (typeof SgpbRecentSalesPopupType != 'undefined') {
1762		if (popupData['sgpb-type'] == SgpbRecentSalesPopupType) {
1763			if (positionTop != '') {
1764				positionTop = parseInt(positionTop+10);
1765			}
1766			else if (positionBottom != '') {
1767				positionBottom = parseInt(positionBottom+10);
1768			}
1769		}
1770	}
1771	popupConfig.magicCall('setPositionTop', positionTop);
1772	popupConfig.magicCall('setPositionRight', positionRight);
1773	popupConfig.magicCall('setPositionBottom', positionBottom);
1774	popupConfig.magicCall('setPositionLeft', positionLeft);
1775};
1776
1777SGPBPopup.prototype.setPopupDimensions = function()
1778{
1779	var popupData = this.getPopupData();
1780	var popupConfig = this.getPopupConfig();
1781	var popupId = this.getPopupId();
1782	var dimensionData = popupData['sgpb-popup-dimension-mode'];
1783	var maxWidth = popupData['sgpb-max-width'];
1784	var maxHeight = popupData['sgpb-max-height'];
1785	var minWidth = popupData['sgpb-min-width'];
1786	var minHeight = popupData['sgpb-min-height'];
1787	var contentPadding = popupData['sgpb-content-padding'];
1788	var popupType = popupData['sgpb-type'];
1789
1790	popupConfig.magicCall('setMaxWidth', maxWidth);
1791	popupConfig.magicCall('setMaxHeight', maxHeight);
1792	popupConfig.magicCall('setMinWidth', minWidth);
1793	popupConfig.magicCall('setMinHeight', minHeight);
1794
1795	if (popupType == 'image') {
1796		popupConfig.magicCall('setContentBackgroundImage', popupData['sgpb-image-url']);
1797		popupConfig.magicCall('setContentBackgroundMode', 'contain');
1798		if (dimensionData == 'customMode') {
1799			popupConfig.magicCall('setContentBackgroundPosition', 'center center');
1800		}
1801	}
1802	if (dimensionData == 'responsiveMode') {
1803		var dimensionMeasure = popupData['sgpb-responsive-dimension-measure'];
1804		/* for image popup type and responsive mode, set background image to fit */
1805		if (popupType == 'image' && dimensionMeasure != 'fullScreen') {
1806			popupConfig.magicCall('setContentBackgroundMode', 'fit');
1807			this.setMaxWidthForResponsiveImage();
1808		}
1809
1810		var popupConfig = this.getPopupConfig();
1811		if (dimensionMeasure != 'auto') {
1812			popupConfig.magicCall('setWidth', dimensionMeasure+'%');
1813
1814			popupConfig.magicCall('setContentBackgroundPosition', 'center');
1815		}
1816		else {
1817			var widthToSet = jQuery('.sgpb-popup-builder-content-'+popupId).width() + (contentPadding*2);
1818
1819			if (isNaN(widthToSet)) {
1820				widthToSet = 'auto';
1821			}
1822			else {
1823				popupConfig.magicCall('setContentBackgroundPosition', 'center center');
1824				widthToSet += 'px';
1825			}
1826
1827			popupConfig.magicCall('setWidth', widthToSet);
1828			if (dimensionMeasure == 'fullScreen') {
1829				popupConfig.magicCall('setHeight', widthToSet);
1830			}
1831		}
1832
1833		return popupConfig;
1834	}
1835
1836	var popupWidth = popupData['sgpb-width'];
1837	var popupHeight = popupData['sgpb-height'];
1838
1839	popupConfig.magicCall('setWidth', popupWidth);
1840	popupConfig.magicCall('setHeight', popupHeight);
1841
1842	return popupConfig;
1843};
1844
1845SGPBPopup.prototype.setMaxWidthForResponsiveImage = function()
1846{
1847	var popupData = this.getPopupData();
1848	var popupConfig = this.getPopupConfig();
1849	var dimensionMeasure = popupData['sgpb-responsive-dimension-measure'];
1850
1851	if (dimensionMeasure != 'auto') {
1852		var maxWidth = popupData['sgpb-max-width'];
1853		if (maxWidth == '') {
1854			popupConfig.magicCall('setMaxWidth', dimensionMeasure+'%');
1855			return true;
1856		}
1857		popupConfig.magicCall('setMaxWidth', dimensionMeasure+'%');
1858		if (maxWidth.indexOf('%') != '-1') {
1859			if (parseInt(maxWidth) < dimensionMeasure) {
1860				popupConfig.magicCall('setMaxWidth', maxWidth);
1861			}
1862		}
1863		else {
1864			var responsiveMeasureInPx = (dimensionMeasure*window.innerWidth)/100;
1865			if (maxWidth < responsiveMeasureInPx) {
1866				popupConfig.magicCall('setMaxWidth', maxWidth);
1867			}
1868		}
1869	}
1870};
1871SGPBPopup.JSONParse = function(data){
1872	return JSON.parse(atob(data, true));
1873};
1874
1875// unused function!
1876SGPBPopup.b64DecodeUnicode = function(str)
1877{
1878	var Base64 = {
1879
1880		/* private property */
1881		_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
1882
1883		/* public method for decoding */
1884		decode : function (input) {
1885			var output = "";
1886			var chr1, chr2, chr3;
1887			var enc1, enc2, enc3, enc4;
1888			var i = 0;
1889
1890			input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
1891
1892			while (i < input.length) {
1893				enc1 = this._keyStr.indexOf(input.charAt(i++));
1894				enc2 = this._keyStr.indexOf(input.charAt(i++));
1895				enc3 = this._keyStr.indexOf(input.charAt(i++));
1896				enc4 = this._keyStr.indexOf(input.charAt(i++));
1897
1898				chr1 = (enc1 << 2) | (enc2 >> 4);
1899				chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
1900				chr3 = ((enc3 & 3) << 6) | enc4;
1901
1902				output += String.fromCharCode(chr1);
1903
1904				if (enc3 != 64) {
1905					output += String.fromCharCode(chr2);
1906				}
1907				if (enc4 != 64) {
1908					output += String.fromCharCode(chr3);
1909				}
1910
1911			}
1912
1913			output = Base64._utf8_decode(output);
1914
1915			return output;
1916
1917		},
1918
1919		/* private method for UTF-8 decoding */
1920		_utf8_decode : function (utftext) {
1921			var string = "";
1922			var i = 0;
1923			var c = c1 = c2 = 0;
1924
1925			while (i < utftext.length) {
1926
1927				c = utftext.charCodeAt(i);
1928
1929				if (c < 128) {
1930					string += String.fromCharCode(c);
1931					i++;
1932				}
1933				else if ((c > 191) && (c < 224)) {
1934					c2 = utftext.charCodeAt(i+1);
1935					string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
1936					i += 2;
1937				}
1938				else {
1939					c2 = utftext.charCodeAt(i+1);
1940					c3 = utftext.charCodeAt(i+2);
1941					string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
1942					i += 3;
1943				}
1944			}
1945
1946			return string;
1947		}
1948	};
1949
1950	return Base64.decode(str);
1951};
1952
1953// unused function!
1954SGPBPopup.unserialize_old = function(data)
1955{
1956	data = SGPBPopup.b64DecodeUnicode(data);
1957
1958	var $global = (typeof window !== 'undefined' ? window : global);
1959
1960	var utf8Overhead = function(str) {
1961		var s = str.length;
1962		for (var i = str.length - 1; i >= 0; i--) {
1963			var code = str.charCodeAt(i);
1964			if (code > 0x7f && code <= 0x7ff) {
1965				s++;
1966			}
1967			else if (code > 0x7ff && code <= 0xffff) {
1968				s += 2;
1969			}
1970			/* trail surrogate */
1971			if (code >= 0xDC00 && code <= 0xDFFF) {
1972				i--;
1973			}
1974		}
1975		return s - 1;
1976	};
1977
1978	var error = function(type, msg, filename, line) {
1979		throw new $global[type](msg, filename, line);
1980	};
1981	var readUntil = function(data, offset, stopchr) {
1982		var i = 2;
1983		var buf = [];
1984		var chr = data.slice(offset, offset + 1);
1985
1986		while (chr !== stopchr) {
1987			if ((i + offset) > data.length) {
1988				error('Error', 'Invalid');
1989			}
1990			buf.push(chr);
1991			chr = data.slice(offset + (i - 1), offset + i);
1992			i += 1;
1993		}
1994		return [buf.length, buf.join('')];
1995	};
1996	var readChrs = function(data, offset, length) {
1997		var i, chr, buf;
1998
1999		buf = [];
2000		for (i = 0; i < length; i++) {
2001			chr = data.slice(offset + (i - 1), offset + i);
2002			buf.push(chr);
2003			length -= utf8Overhead(chr);
2004		}
2005		return [buf.length, buf.join('')];
2006	};
2007	function _unserialize(data, offset) {
2008		var dtype;
2009		var dataoffset;
2010		var keyandchrs;
2011		var keys;
2012		var contig;
2013		var length;
2014		var array;
2015		var readdata;
2016		var readData;
2017		var ccount;
2018		var stringlength;
2019		var i;
2020		var key;
2021		var kprops;
2022		var kchrs;
2023		var vprops;
2024		var vchrs;
2025		var value;
2026		var chrs = 0;
2027		var typeconvert = function(x) {
2028			return x
2029		};
2030
2031		if (!offset) {
2032			offset = 0
2033		}
2034		dtype = (data.slice(offset, offset + 1)).toLowerCase();
2035
2036		dataoffset = offset + 2;
2037
2038		switch (dtype) {
2039			case 'i':
2040				typeconvert = function(x) {
2041					return parseInt(x, 10);
2042				};
2043				readData = readUntil(data, dataoffset, ';');
2044				chrs = readData[0];
2045				readdata = readData[1];
2046				dataoffset += chrs + 1;
2047				break;
2048			case 'b':
2049				typeconvert = function(x) {
2050					return parseInt(x, 10) !== 0;
2051				};
2052				readData = readUntil(data, dataoffset, ';');
2053				chrs = readData[0];
2054				readdata = readData[1];
2055				dataoffset += chrs + 1;
2056				break;
2057			case 'd':
2058				typeconvert = function(x) {
2059					return parseFloat(x);
2060				};
2061				readData = readUntil(data, dataoffset, ';');
2062				chrs = readData[0];
2063				readdata = readData[1];
2064				dataoffset += chrs + 1;
2065				break;
2066			case 'n':
2067				readdata = null;
2068				break;
2069			case 's':
2070				ccount = readUntil(data, dataoffset, ':');
2071				chrs = ccount[0];
2072				stringlength = ccount[1];
2073				dataoffset += chrs + 2;
2074
2075				readData = readChrs(data, dataoffset + 1, parseInt(stringlength, 10));
2076				chrs = readData[0];
2077				readdata = readData[1];
2078				dataoffset += chrs + 2;
2079				if (chrs !== parseInt(stringlength, 10) && chrs !== readdata.length) {
2080					error('SyntaxError', 'String length mismatch')
2081				}
2082				break;
2083			case 'a':
2084				readdata = {};
2085
2086				keyandchrs = readUntil(data, dataoffset, ':');
2087				chrs = keyandchrs[0];
2088				keys = keyandchrs[1];
2089				dataoffset += chrs + 2;
2090
2091				length = parseInt(keys, 10);
2092				contig = true;
2093
2094				for (i = 0; i < length; i++) {
2095					kprops = _unserialize(data, dataoffset);
2096					kchrs = kprops[1];
2097					key = kprops[2];
2098					dataoffset += kchrs;
2099
2100					vprops = _unserialize(data, dataoffset);
2101					vchrs = vprops[1];
2102					value = vprops[2];
2103					dataoffset += vchrs;
2104
2105					if (key !== i) {
2106						contig = false;
2107					}
2108
2109					readdata[key] = value;
2110				}
2111
2112				if (contig) {
2113					array = new Array(length);
2114					for (i = 0; i < length; i++) {
2115						array[i] = readdata[i];
2116					}
2117					readdata = array;
2118				}
2119
2120				dataoffset += 1;
2121				break;
2122			default:
2123				error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype);
2124				break;
2125		}
2126
2127		return [dtype, dataoffset - offset, typeconvert(readdata)]
2128	}
2129
2130	return _unserialize((data + ''), 0)[2];
2131};
2132
2133SGPBPopup.closePopup = function()
2134{
2135	var popupObjs = window.sgPopupBuilder;
2136	var lastPopupObj = this.getLastPopup();
2137
2138	if (typeof lastPopupObj == 'undefined') {
2139		return false;
2140	}
2141
2142	var popupId = lastPopupObj.popupId;
2143
2144	SGPBPopup.closePopupById(popupId);
2145};
2146
2147SGPBPopup.closePopupById = function(popupId)
2148{
2149	var popupObjs = window.sgPopupBuilder;
2150	if (!popupObjs.length) {
2151		return;
2152	}
2153
2154	for (var i in popupObjs) {
2155
2156		var currentObj = popupObjs[i];
2157
2158		if (currentObj.popupId == popupId) {
2159			var popupObj = popupObjs[i]['popup'];
2160			if (popupObj) {
2161				/*Send true argument to don’t count disable popup option*/
2162				popupObj.close(true);
2163			}
2164		}
2165	}
2166};
2167
2168SGPBPopup.getPopupWindowDataById = function(popupId)
2169{
2170	var popups = window.sgPopupBuilder;
2171	var popup = false;
2172
2173	if (typeof popups == 'undefined' || !popups.length) {
2174		return popup;
2175	}
2176
2177	for (var i in popups) {
2178		var popupData = popups[i];
2179
2180		if (popupData.popupId == popupId) {
2181			popup = popupData;
2182			break;
2183		}
2184	}
2185
2186	return popup;
2187};
2188
2189SGPBPopup.findPopupObjById = function(popupId)
2190{
2191	var popup = false;
2192	var popupData = SGPBPopup.getPopupWindowDataById(popupId);
2193
2194	if (popupData) {
2195		popup = popupData['popup'];
2196	}
2197
2198	return popup;
2199};
2200
2201SGPBPopup.getLastPopup = function()
2202{
2203	var popups = window.sgPopupBuilder;
2204	var popup = false;
2205
2206	if (!popups.length) {
2207		return popup;
2208	}
2209
2210	var searchPopups = [].concat(popups);
2211
2212	for (var i in searchPopups) {
2213		var popupData = searchPopups[i];
2214
2215		if (popupData.isOpen) {
2216			popup = popupData;
2217			break;
2218		}
2219	}
2220
2221	return popup;
2222};
2223
2224SGPBPopup.offPopup = function(currentPopup)
2225{
2226	var popups = window.sgPopupBuilder;
2227
2228	if (!popups.length) {
2229		return false;
2230	}
2231
2232	for (var i in popups) {
2233		var popupData = popups[i];
2234
2235		if (popupData.order == currentPopup.order && popupData.eventName == currentPopup.eventName) {
2236			popups[i]['isOpen'] = false;
2237			break;
2238		}
2239	}
2240
2241	return true;
2242};
2243
2244SGPBPopup.capitalizeFirstLetter = function(string)
2245{
2246	return string.charAt(0).toUpperCase() + string.slice(1);
2247};
2248
2249SGPBPopup.getParamFromUrl = function(param)
2250{
2251	var url = window.location.href;
2252	param = param.replace(/[\[\]]/g, "\\$&");
2253	var regex = new RegExp("[?&]" + param + "(=([^&#]*)|&|#|$)"),
2254		results = regex.exec(url);
2255	if (!results) {
2256		return null;
2257	}
2258	if (!results[2]) {
2259		return '';
2260	}
2261	return decodeURIComponent(results[2].replace(/\+/g, " "));
2262};
2263
2264/*
2265 *
2266 * SGPBPopup Cookies' settings
2267 *
2268 */
2269SGPBPopup.setCookie = function(cName, cValue, exDays, cPageLevel)
2270{
2271	var sameSite = 'Lax';
2272	var isPreview = SGPBPopup.getParamFromUrl('preview');
2273	if (isPreview) {
2274		return false;
2275	}
2276	var expirationDate = new Date();
2277	var cookiePageLevel = '';
2278	var cookieExpirationData = 1;
2279	if (!exDays || isNaN(exDays)) {
2280		if (!exDays && exDays === 0) {
2281			exDays = 'session';
2282		}
2283		else {
2284			exDays = 365*50;
2285		}
2286	}
2287
2288	if (!Boolean(cPageLevel)) {
2289		cookiePageLevel = 'path=/;';
2290	}
2291
2292	if (exDays == 'session') {
2293		cookieExpirationData = 0;
2294	}
2295	else {
2296		expirationDate.setDate(parseInt(expirationDate.getDate() + parseInt(exDays)));
2297		cookieExpirationData = expirationDate.toUTCString();
2298	}
2299	var expires = 'expires='+cookieExpirationData;
2300	if (exDays == -1) {
2301		expires = '';
2302	}
2303
2304	if (!cookieExpirationData) {
2305		expires = '';
2306	}
2307
2308	/* in IE there is no need to specify the path */
2309	if (SGPBPopup.isIE()) {
2310		cookiePageLevel = '';
2311	}
2312
2313	var value = cValue+((exDays == null) ? ';' : '; '+expires+';'+cookiePageLevel+'; SameSite=' + sameSite);
2314	document.cookie = cName + '=' + value;
2315};
2316
2317SGPBPopup.isIE = function()
2318{
2319	ua = navigator.userAgent;
2320	/* MSIE used to detect old browsers and Trident used to newer ones*/
2321	var isIe = ua.indexOf('MSIE ') > -1 || ua.indexOf('Trident/') > -1;
2322
2323	return isIe;
2324};
2325
2326SGPBPopup.getCookie = function(cName)
2327{
2328	var name = cName + '=';
2329	var ca = document.cookie.split(';');
2330	for (var i = 0; i < ca.length; i++) {
2331		var c = ca[i];
2332		while (c.charAt(0) == ' ') {
2333			c = c.substring(1);
2334		}
2335		if (c.indexOf(name) == 0) {
2336			return c.substring(name.length, c.length);
2337		}
2338	}
2339
2340	return '';
2341};
2342
2343/*
2344 *
2345 * Delete the cookie by expiring it
2346 *
2347 */
2348
2349SGPBPopup.deleteCookie = function(cName, cPath)
2350{
2351	if (!cPath) {
2352		cPath = 'path=/;';
2353	}
2354
2355	document.cookie = cName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;' + cPath;
2356};
2357
2358/**
2359 *
2360 * @SgpbEventListener listen Events and call corresponding events
2361 *
2362 */
2363
2364function SgpbEventListener()
2365{
2366	this.evenets = null;
2367	this.popupObj = {};
2368}
2369
2370SgpbEventListener.inactivityIdicator = 0;
2371
2372SgpbEventListener.prototype.setEvents = function(events)
2373{
2374	this.evenets = events;
2375};
2376
2377SgpbEventListener.prototype.getEvents = function()
2378{
2379	return this.evenets;
2380};
2381
2382SgpbEventListener.prototype.setPopupObj = function(popupObj)
2383{
2384	this.popupObj = popupObj;
2385};
2386
2387SgpbEventListener.prototype.getPopupObj = function()
2388{
2389	return this.popupObj;
2390};
2391
2392SgpbEventListener.eventsListenerAfterDocumentReady = function()
2393{
2394	window.SGPB_SOUND = [];
2395
2396	sgAddEvent(window, 'sgpbDidOpen', function(e) {
2397
2398		//Modern browsers block autoplay with sound unless the user has interacted with the page
2399		//SGPBPopup.playMusic(e);
2400
2401		const pbsgsoundnotification = document.querySelector("#pbsgsoundnotification");
2402		if (pbsgsoundnotification) {
2403	       pbsgsoundnotification.addEventListener("click", () => {
2404	            SGPBPopup.playMusic(e);
2405	            pbsgsoundnotification.classList.add("fade");
2406	        });
2407	    }
2408	});
2409
2410	
2411
2412	sgAddEvent(window, 'sgpbDidClose', function(e) {
2413		var args = e.detail;
2414		var popupId = parseInt(args.popupId);
2415		if (typeof window.SGPB_SOUND[popupId] && window.SGPB_SOUND[popupId]) {
2416			window.SGPB_SOUND[popupId].pause();
2417			delete window.SGPB_SOUND[popupId];
2418		}
2419	});
2420};
2421
2422SgpbEventListener.init = function()
2423{
2424	SgpbEventListener.eventsListenerAfterDocumentReady();
2425	var popupsData = jQuery('.sg-popup-builder-content');
2426
2427	if (!popupsData) {
2428		return '';
2429	}
2430
2431	var that = this;
2432
2433	popupsData.each(function() {
2434		var popupObj = that.popupObjCreator(jQuery(this));
2435		SGPBPopup.floatingButton(popupObj);
2436	});
2437};
2438
2439SgpbEventListener.popupObjCreator = function(currentData)
2440{
2441	var popupId = currentData.data('id');
2442	var popupData = currentData.data('options');
2443
2444	var events = currentData.attr('data-events');
2445	events = jQuery.parseJSON(events);
2446
2447	SgpbEventListener.reopenAfterFormSubmission(popupData);
2448
2449	var popupObj = new SGPBPopup();
2450	popupObj.setPopupId(popupId);
2451	popupObj.setPopupData(popupData);
2452
2453	for (var i in events) {
2454		var obj = new this;
2455		obj.setPopupObj(popupObj);
2456		obj.eventListener(events[i]);
2457	}
2458
2459	return popupObj;
2460};
2461
2462SgpbEventListener.prototype.eventListener = function(eventData)
2463{
2464	if (eventData == null) {
2465		return '';
2466	}
2467	var event = '';
2468	if (typeof eventData == 'string') {
2469		event = eventData;
2470	}
2471	else if (typeof eventData.param != 'undefined') {
2472		event = eventData.param;
2473	}
2474
2475	if (!event) {
2476		return false;
2477	}
2478
2479	var popupObj = this.getPopupObj();
2480	var popupData = popupObj.getPopupData();
2481
2482	if (eventData.value == '') {
2483		eventData.value = popupData['sgpb-popup-delay'];
2484	}
2485
2486	var eventName = SGPBPopup.capitalizeFirstLetter(event);
2487
2488	eventName = 'sgpb'+eventName;
2489	popupObj.eventName = eventName;
2490
2491	var allowToOpen = popupObj.forceCheckCurrentPopupType(popupObj);
2492
2493	if (!allowToOpen) {
2494		return false;
2495	}
2496	try {
2497		eval('this.'+eventName)(this, eventData);
2498	}
2499	catch (err) {
2500		console.log(err)
2501	}
2502
2503};
2504
2505SgpbEventListener.reopenAfterFormSubmission = function(eventData)
2506{
2507	var popupId = SGPBPopup.getCookie('SGPBSubmissionReloadPopup');
2508	popupId = parseInt(popupId);
2509
2510	if (!popupId) {
2511		return false;
2512	}
2513	var popupObj = SGPBPopup.createPopupObjById(popupId);
2514	if (!popupObj) {
2515		return false;
2516	}
2517	var options = popupObj.getPopupData();
2518
2519	if (!options['sgpb-reopen-after-form-submission']) {
2520		return false;
2521	}
2522
2523	popupObj.prepareOpen();
2524	SGPBPopup.deleteCookie('SGPBSubmissionReloadPopup');
2525};
2526
2527SgpbEventListener.prototype.sgpbLoad = function(listenerObj, eventData)
2528{
2529	var timeout = parseInt(eventData.value);
2530	var popupObj = listenerObj.getPopupObj();
2531	var popupOptions = popupObj.getPopupData();
2532	timeout *= 1000;
2533	var timerId,
2534		repetitiveTimeout = null;
2535
2536
2537	/* same as checkCurrentPopupType(), but it fires ignoring any delay (etc. onload delay) */
2538	popupObj.forceCheckCurrentPopupType(popupObj);
2539
2540
2541	var openOnLoadPopup = function() {
2542		setTimeout(function() {
2543			jQuery(window).trigger('sgpbLoadEvent', popupOptions);
2544			popupObj.prepareOpen();
2545		}, timeout);
2546	};
2547	sgAddEvent(window, 'load', openOnLoadPopup(timeout, popupObj));
2548	sgAddEvent(window, 'sgpbDidOpen', function(e) {
2549		var args = e.detail;
2550		clearInterval(repetitiveTimeout);
2551	});
2552
2553	sgAddEvent(window, 'sgpbDidClose', function(e) {
2554		var args = e.detail;
2555		var options = popupObj.getPopupData();
2556		if (SGPBPopup.varToBool(eventData['repetitive'])) {
2557			var intervalTime = parseInt(eventData['value'])*1000;
2558			repetitiveTimeout = setInterval(function() {
2559				popupObj.prepareOpen();
2560			}, intervalTime);
2561		}
2562	});
2563};
2564
2565SgpbEventListener.prototype.timerIncrement = function(listenerObj , idleInterval)
2566{
2567	var lastActivity = SgpbEventListener.inactivityIdicator;
2568
2569	if (lastActivity == 0) {
2570		clearInterval(idleInterval);
2571		listenerObj.getPopupObj().prepareOpen();
2572	}
2573	SgpbEventListener.inactivityIdicator = 0;
2574};
2575
2576SgpbEventListener.prototype.sgpbInsideclick = function(listenerObj, eventData)
2577{
2578	sgAddEvent(window, 'sgpbDidOpen', function(e) {
2579		var args = e.detail;
2580		var that = listenerObj;
2581		var popupObj = that.getPopupObj();
2582		var popupId = parseInt(popupObj.id);
2583		var targetClick = jQuery('.sgpb-content .sgpb-popup-id-'+popupId);
2584
2585		if (!targetClick.length) {
2586			return false;
2587		}
2588
2589		targetClick.each(function() {
2590			jQuery(this).unbind('click').bind('click', function() {
2591				var dontCloseCurrentPopup = jQuery(this).attr('dontCloseCurrentPopup');
2592				if (typeof dontCloseCurrentPopup == 'undefined' || dontCloseCurrentPopup != 'on') {
2593					SGPBPopup.closePopup();
2594				}
2595				popupObj.prepareOpen();
2596			});
2597		});
2598	});
2599};
2600
2601SgpbEventListener.prototype.sgpbClick = function(listenerObj, eventData)
2602{
2603	var that = listenerObj;
2604	var popupIds = [];
2605	var popupObj = that.getPopupObj();
2606	var popupOptions = popupObj.getPopupData();
2607	var popupId = parseInt(popupObj.id);
2608	popupIds.push(popupId);
2609	var mapId = listenerObj.filterPopupId(popupId);
2610	popupIds.push(mapId);
2611	if (jQuery.inArray(mapId, popupIds) === -1) {
2612		popupIds.push(mapId);
2613	}
2614
2615	for(var key in popupIds) {
2616		var popupId = popupIds[key];
2617		if (!popupIds.hasOwnProperty(key)) {
2618			return false;
2619		}
2620		var targetClick = jQuery('a[href*="#sg-popup-id-' + popupId + '"], .sg-popup-id-' + popupId + ', .sgpb-popup-id-' + popupId);
2621
2622		if (typeof eventData.operator != 'undefined' && eventData.operator == 'clickActionCustomClass') {
2623			targetClick = jQuery('a[href*="#sg-popup-id-' + popupId + '"], .sg-popup-id-' + popupId + ', .sgpb-popup-id-' + popupId+', .'+eventData.value);
2624		}
2625		if (!targetClick.length) {
2626			continue;
2627		}
2628		var delay = parseInt(popupOptions['sgpb-popup-delay']) * 1000;
2629		var clickCount = 1;
2630		targetClick.each(function() {
2631
2632			if (!jQuery(this).attr('data-popup-id')) {
2633				jQuery(this).attr('data-popup-id', popupId);
2634			}
2635			var currentTarget = jQuery(this);
2636			currentTarget.bind('swipe', function(e) {
2637				return false;
2638			});
2639			currentTarget.bind('click', function(e) {
2640				if (clickCount > 1) {
2641					return true;
2642				}
2643
2644				var allowToOpen = popupObj.forceCheckCurrentPopupType(popupObj);
2645				if (!allowToOpen) {
2646					return true;
2647				}
2648				++clickCount;
2649				jQuery(window).trigger('sgpbClickEvent', popupOptions);
2650				var popupId = jQuery(this).data('popup-id');
2651				setTimeout(function() {
2652
2653					var popupObj = SGPBPopup.createPopupObjById(popupId);
2654					if (!popupObj) {
2655						var mapId = listenerObj.filterPopupId(popupId);
2656						popupObj = SGPBPopup.createPopupObjById(mapId);
2657					}
2658					popupObj.customEvent = 'Click';
2659					popupObj.prepareOpen();
2660					clickCount = 1;
2661				}, delay);
2662
2663				return false;
2664			});
2665		});
2666	}
2667};
2668
2669SgpbEventListener.prototype.sgpbHover = function(listenerObj, eventData)
2670{
2671	var that = listenerObj;
2672	var popupObj = that.getPopupObj();
2673
2674	if (!popupObj) {
2675		return false;
2676	}
2677	var popupIds = [];
2678	var popupOptions = popupObj.getPopupData();
2679	var popupId = parseInt(popupObj.id);
2680	popupIds.push(popupId);
2681	var mapId = listenerObj.filterPopupId(popupId);
2682	if (jQuery.inArray(mapId, popupIds) === -1) {
2683		popupIds.push(mapId);
2684	}
2685
2686	for(var key in popupIds) {
2687		var popupId = popupIds[key];
2688		if (!popupIds.hasOwnProperty(key)) {
2689			return false;
2690		}
2691
2692		var hoverSelector = jQuery('.sg-popup-hover-' + popupId + ', .sgpb-popup-id-' + popupId + '[data-popup-event="hover"]');
2693
2694		if (typeof eventData.operator != 'undefined' && eventData.operator == 'hoverActionCustomClass') {
2695			hoverSelector = jQuery('.sg-popup-hover-' + popupId + ', .sgpb-popup-id-' + popupId + '[data-popup-event="hover"]'+', .'+eventData.value);
2696		}
2697
2698		if (!hoverSelector) {
2699			return false;
2700		}
2701		var hoverCount = 1;
2702		var delay = parseInt(popupOptions['sgpb-popup-delay']) * 1000;
2703
2704		hoverSelector.each(function () {
2705			if (!jQuery(this).attr('data-popup-id')) {
2706				jQuery(this).attr('data-popup-id', popupId);
2707			}
2708			jQuery(this).bind('mouseenter', function() {
2709				if (hoverCount > 1) {
2710					return false;
2711				}
2712				++hoverCount;
2713				var popupId = jQuery(this).data('popup-id');
2714				jQuery(window).trigger('sgpbHoverEvent', popupOptions);
2715				setTimeout(function() {
2716					var popupObj = SGPBPopup.createPopupObjById(popupId);
2717					if (!popupObj) {
2718						var mapId = listenerObj.filterPopupId(popupId);
2719						popupObj = SGPBPopup.createPopupObjById(mapId);
2720					}
2721					popupObj.customEvent = 'Hover';
2722					popupObj.prepareOpen();
2723					hoverCount = 1;
2724				}, delay);
2725			});
2726		});
2727	}
2728};
2729
2730SgpbEventListener.prototype.sgpbConfirm = function(listenerObj, eventData)
2731{
2732	var that = listenerObj;
2733	var popupObj = that.getPopupObj();
2734
2735	if (!popupObj) {
2736		return false;
2737	}
2738	var popupIds = [];
2739	var popupOptions = popupObj.getPopupData();
2740	var popupId = parseInt(popupObj.id);
2741	popupIds.push(popupId);
2742	var mapId = listenerObj.filterPopupId(popupId);
2743	popupIds.push(mapId);
2744
2745	for(var key in popupIds) {
2746		var popupId = popupIds[key];
2747		if (!popupIds.hasOwnProperty(key)) {
2748			return false;
2749		}
2750
2751		var confirmSelector = jQuery('.sg-confirm-popup-' + popupId);
2752
2753		if (!confirmSelector) {
2754			return false;
2755		}
2756		var confirmCount = 1;
2757
2758		confirmSelector.bind('click', function(e) {
2759			if (confirmCount > 1) {
2760				return false;
2761			}
2762			++confirmCount;
2763			var allowToOpen = popupObj.forceCheckCurrentPopupType(popupObj);
2764
2765			if (!allowToOpen) {
2766				return true;
2767			}
2768			jQuery(window).trigger('sgpbConfirmEvent', popupOptions);
2769			var target = jQuery(this).attr('target');
2770
2771			if (typeof target == 'undefined') {
2772				target = 'self';
2773			}
2774			var href = jQuery(this).attr('href');
2775			var delay = parseInt(popupOptions['sgpb-popup-delay']) * 1000;
2776			setTimeout(function() {
2777				if (typeof href != 'undefined') {
2778					popupOptions['sgpb-confirm-' + popupId] = {'target' : target, 'href' : href};
2779					popupObj.setPopupData(popupOptions);
2780				}
2781				popupObj.prepareOpen();
2782				confirmCount = 1;
2783			}, delay);
2784
2785			return false;
2786		});
2787
2788		sgAddEvent(window, 'sgpbDidClose', function(e) {
2789			var args = e.detail;
2790			var popupId = parseInt(args.popupId);
2791			var popupOptions = args.popupData;
2792
2793			if (typeof popupOptions['sgpb-confirm-' + popupId] != 'undefined') {
2794				var confirmAgrs = popupOptions['sgpb-confirm-' + popupId];
2795
2796				if (confirmAgrs['target'] == '_blank') {
2797					window.open(confirmAgrs['href']);
2798				}
2799				else {
2800					window.location.href = confirmAgrs['href'];
2801				}
2802
2803				delete popupOptions['sgpb-confirm-' + popupId];
2804				popupObj.setPopupData(popupOptions);
2805			}
2806		});
2807	}
2808};
2809
2810SgpbEventListener.prototype.sgpbAttronload = function(listenerObj, eventData)
2811{
2812	var that = listenerObj;
2813	var popupObj = that.getPopupObj();
2814	var popupId = parseInt(popupObj.id);
2815	popupId = listenerObj.filterPopupId(popupId);
2816	var popupOptions = popupObj.getPopupData();
2817	var delay = parseInt(popupOptions['sgpb-popup-delay']) * 1000;
2818	jQuery(window).trigger('sgpbAttronloadEvent', popupOptions);
2819
2820	setTimeout(function() {
2821		popupObj.prepareOpen();
2822	}, delay);
2823};
2824
2825/*for the old popups*/
2826SgpbEventListener.prototype.filterPopupId = function(popupId)
2827{
2828	var convertedIds = SGPB_POPUP_PARAMS.convertedIdsReverse;
2829	var popupNewId = popupId;
2830	if (convertedIds[popupId]) {
2831		return convertedIds[popupId];
2832	}
2833	else {
2834		for(var i in convertedIds) {
2835			if (popupId == convertedIds[i]) {
2836				popupNewId = parseInt(i);
2837				break;
2838			}
2839		}
2840	}
2841
2842	return popupNewId;
2843};
2844
2845SgpbEventListener.findCF7InPopup = function(popupId)
2846{
2847	return document.querySelector('#sg-popup-content-wrapper-'+popupId+' .wpcf7');
2848};
2849
2850SgpbEventListener.CF7EventListener = function(popupId, options)
2851{
2852	var wpcf7Elm = SgpbEventListener.findCF7InPopup(popupId);
2853
2854	if (wpcf7Elm) {
2855		wpcf7Elm.addEventListener('wpcf7mailsent', function(event) {
2856			var settings = {
2857				popupId: popupId,
2858				eventName: 'sgpbCF7Success'
2859			};
2860			jQuery(window).trigger('sgpbCF7Success', settings);
2861		});
2862	}
2863};
2864
2865SgpbEventListener.processCF7MailSent = function(popupId, options)
2866{
2867	var wpcf7Elm = SgpbEventListener.findCF7InPopup(popupId);
2868
2869	if (wpcf7Elm) {
2870		wpcf7Elm.addEventListener('wpcf7mailsent', function(event) {
2871			if (typeof options['operator'] == 'undefined') {
2872				return;
2873			}
2874			if (options['operator'] == 'close-popup') {
2875				setTimeout(function() {
2876					SGPBPopup.closePopupById(popupId);
2877				}, parseInt(options['value'])*1000);
2878			}
2879			else if (options['operator'] == 'redirect-url') {
2880				window.location.href = options['value'];
2881			}
2882			else if (options['operator'] == 'open-popup') {
2883				SGPBPopup.closePopupById(popupId);
2884				var popupObj = SGPBPopup.createPopupObjById(Object.keys(options['value'])[0]);
2885				popupObj.prepareOpen();
2886			}
2887		}, false);
2888	}
2889};
2890
2891jQuery(document).ready(function(e) {
2892	setTimeout(function(){
2893		SgpbEventListener.init();
2894		SGPBPopup.listeners();
2895	}, 1);
2896});

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.