PageSourceSearch

https://www.smedk.ru/wp-content/plugins/popup-builder/public/js/PopupBuilder.js?ver=3.61.1

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

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.