PageSourceSearch

https://www.optiwise.ai/wp-content/plugins/popup-builder/public/js/PopupBuilder.js?ver=4.3.5

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

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.