PageSourceSearch

https://northstar360.org/wp-content/plugins/profilegrid-user-profi…/js/profile-magic-public.js?ver=6.0.0.3

js northstar360.org collected 2026-10-02 19:04:19 UTC 74,411 bytes, 2,199 lines download raw bytes

1function pm_change_search_field(a)
2{
3    var group = a;
4    var data ={'action':'pm_advance_search_get_search_fields_by_gid', 'gid' : group, 'match_fields': ' '};
5    jQuery.post(pm_ajax_object.ajax_url, data, function (response){
6       if(response){
7           jQuery('#advance_seach_ul').empty();
8         jQuery('#advance_seach_ul').append(response);
9         pm_advance_user_search('');
10         if ( typeof pg_refresh_search_field == 'function' ) { 
11            pg_refresh_search_field();
12        }
13
14     }else{
15           //console.log("err");
16       }
17
18    });
19}
20function pm_remove_attachment(obj,key,value)
21{
22    jQuery('#pm-edit-group-popup, .pm-popup-mask, .pg-blog-dialog-mask').toggle();
23    ( function($) {
24        $( "#pg-remove-attachment-dialog" ).dialog({
25          resizable: false,
26          height: "auto",
27          width: 400,
28          modal: true,
29          buttons: {
30            "Yes": function() {
31                
32                var data = {
33                        'action': 'pm_remove_attachment',
34                        'key': key,
35                        'value':value,
36                        'nonce':pm_ajax_object.nonce
37                };
38                $.post(pm_ajax_object.ajax_url, data, function(response) {
39                    if(response)
40                    {
41                        $(obj).parent('a').parent('span.pm_frontend_attachment').remove();
42                    }
43                });
44
45                $( this ).dialog( "close" );
46            },
47            "No": function() {
48              $( this ).dialog( "close" );
49            }
50          }
51        });
52    } )(jQuery);
53}
54
55function pm_expand_all_conent()
56{
57	jQuery("#pm-accordion .pm-accordian-content").show();	
58}
59
60function pm_collapse_all_conent()
61{
62	jQuery("#pm-accordion .pm-accordian-content").hide();	
63}
64 
65function pm_show_hide(obj,primary,secondary,trinary)
66{	
67	a = jQuery(obj).is(':checked');
68	if (a == true)
69	 {
70		jQuery('#'+primary).show(500);
71		if(secondary!='')
72		{
73			jQuery('#'+secondary).hide(500);
74		}
75		if(trinary!='')
76		{
77			jQuery('#'+trinary).hide(500);
78		}		
79	}
80	else 
81	{
82		jQuery('#'+primary).hide(500);
83		if(secondary!='')
84		{
85			jQuery('#'+secondary).show(500);
86		}
87		if(trinary!='')
88		{
89			jQuery('#'+trinary).show(500);
90		}
91	}
92	
93}
94
95function pm_add_repeat(obj)
96{
97	a= jQuery(obj).parent('a').parent('div.pm_repeat').clone();
98	jQuery(a).children('input').val('');
99	jQuery(obj).parent('a').parent('div.pm_repeat').parent('div.pm-field-input').append(a);
100}
101
102function pm_remove_repeat(obj)
103{
104	jQuery(obj).parent('a').parent('div.pm_repeat').remove();
105}
106
107function validate_phone_number2(number)
108{
109    var isnumber = jQuery.isNumeric(number);
110    var regex = /^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$/;
111    var phone_num = number.replace(/[^\d]/g, '');
112    if ( number != "")
113    {
114//        if(isnumber == false )
115//        return false;
116    
117    if(phone_num.length <10 || phone_num.length > 13)
118        return false;
119    
120//    if(!regex.test(number))
121//        return false;
122    
123    return true;
124    }else
125    {
126        return true;
127    }
128   
129
130}
131
132function validate_phone_number(number) {
133    if(number!=""){
134    var phone_num = number.replace(/[^\d]/g, '');
135    var a = number;
136       var phone_num = number.replace(/[^\d]/g, '');
137    var filter = /^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/;
138    if (filter.test(a)&&(phone_num.length >=10 && phone_num.length <= 13)) {
139        //console.log(phone_num);
140        return true;
141    }
142    else {
143        return false;
144    }
145    }else{
146        return true;
147    }
148}
149
150function validateMobileNumber(number) {
151    if(number!=""){
152        var phone_num = number.replace(/[^\d]/g, '');
153        var a = number;
154        var phone_num = number.replace(/[^\d]/g, '');
155        var filter = /^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/;
156        if (filter.test(a)&&(phone_num.length >=10 && phone_num.length <= 13)) {
157            //console.log(phone_num);
158            return true;
159        }
160        else {
161            return false;
162        }
163    }else{
164        return true;
165    }
166    /*if (number != "") {
167        const regex = /^\+?(\d{1,4})?[-.\s]?((\d{10,15})|(\d{6,9}))$/;
168        return regex.test(number);
169    }
170    else
171    {
172        return true;
173    }*/
174}
175
176function validate_facebook_url(val)
177{
178    if (val != "") {
179        if (/(?:https?:\/\/)?(?:www\.)?facebook\.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[\w\-]*\/)*?(\/)?([\w\-\.]*)/i.test(val))
180        {
181            return true;
182        } else
183        {
184            return false;
185        }
186    } else {
187        return true;
188    }
189
190}
191
192function validate_twitter_url(val) {
193    if (val !== '') {
194        const regex = /^(https?:\/\/)(www\.)?(twitter\.com|x\.com)\/([A-Za-z0-9_]{1,15})\/?$/i;
195        return regex.test(val);
196    } else {
197        return true;
198    }
199}
200
201
202function validate_google_url(val)
203{
204    if (val != '') {
205        if (/((http:\/\/(plus\.google\.com\/.*|www\.google\.com\/profiles\/.*|google\.com\/profiles\/.*))|(https:\/\/(plus\.google\.com\/.*)))/i.test(val)) {
206            return true;
207        } else {
208            return false;
209        }
210
211    } else {
212        return true;
213    }
214}
215
216function validate_linked_in_url(val)
217{   if (val != '') {
218        if (/(ftp|http|https):\/\/?((www|\w\w)\.)?linkedin.com(\w+:{0,1}\w*@)?(\S+)(:([0-9])+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i.test(val)) {
219            return true;
220        } else {
221            return false;
222        }
223    } else {
224        return true;
225    }
226}
227
228function validate_youtube_url(val)
229{
230    if (val != '') {
231        if (/(ftp|http|https):\/\/?((www|\w\w)\.)?(youtube\.com|youtu\.be)(\w+:{0,1}\w*@)?(\S+)(:([0-9])+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i.test(val)) {
232            return true;
233        } else {
234            return false;
235        }
236
237    } else {
238        return true;
239    }
240}
241
242function validate_soundcloud_url(val)
243{
244    if (val != '') {
245        if (/(ftp|http|https):\/\/?((www|\w\w)\.)?soundcloud.com(\w+:{0,1}\w*@)?(\S+)(:([0-9])+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i.test(val)) {
246            return true;
247        } else {
248            return false;
249        }
250
251    } else {
252        return true;
253    }
254}
255
256function validate_mixcloud_url(val)
257{
258    if (val != '') {
259        if (/(ftp|http|https):\/\/?((www|\w\w)\.)?mixcloud.com(\w+:{0,1}\w*@)?(\S+)(:([0-9])+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i.test(val)) {
260            return true;
261        } else {
262            return false;
263        }
264
265    } else {
266        return true;
267    }
268}
269
270function validate_instagram_url(val)
271{
272    if (val != '') {
273        var regex = /(?:(?:http|https):\/\/)?(?:www.)?(?:instagram.com|instagr.am)\/([A-Za-z0-9-_]+)/;
274        if (val.match(regex)) {
275            return true;
276        } else {
277            return false;
278        }
279    } else {
280        return true;
281    }
282}
283
284function profile_magic_frontend_validation(form)
285{
286	
287	var email_val = "";
288	var formid = form.id;
289	var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
290	jQuery('.errortext').html('');
291	jQuery('.errortext').hide();
292	jQuery('.all_errors').html('');
293	jQuery('.warning').removeClass('warning');
294        jQuery('.pg-form-validation-error').removeClass('pg-form-validation-error');
295
296        jQuery('#'+formid+' .pm_email').each(function (index, element) {
297		var email = jQuery(this).children('input').val();
298		var isemail = regex.test(email);
299		if (isemail == false && email != "") {
300			jQuery(this).children('input').addClass('warning');
301			jQuery(this).children('.errortext').html(pm_error_object.valid_email);
302			jQuery(this).children('.errortext').show();
303		}
304	});
305	
306	jQuery('#'+formid+' .pm_number').each(function (index, element) {
307		var number = jQuery(this).children('input').val();
308		var isnumber = jQuery.isNumeric(number);
309		if (isnumber == false && number != "") {
310			jQuery(this).children('input').addClass('warning');
311			jQuery(this).children('.errortext').html(pm_error_object.valid_number);
312			jQuery(this).children('.errortext').show();
313		}
314	});
315	
316        	
317	jQuery('#'+formid+' .pm_phone_number').each(function (index, element) {
318		var number = jQuery(this).children('input').val();
319                if (!validate_phone_number(number)) {
320			jQuery(this).children('input').addClass('warning');
321			jQuery(this).children('.errortext').html(pm_error_object.valid_phone_number);
322			jQuery(this).children('.errortext').show();
323		}
324	});
325        
326        jQuery('#'+formid+' .pm_mobile_number').each(function (index, element) {
327		var number = jQuery(this).children('input').val();
328                if (!validateMobileNumber(number)) {
329			jQuery(this).children('input').addClass('warning');
330			jQuery(this).children('.errortext').html(pm_error_object.valid_mobile_number);
331			jQuery(this).children('.errortext').show();
332		}
333	});
334        
335        jQuery('#'+formid+' .pm_facebook_url').each(function (index, element) {
336		var number = jQuery(this).children('input').val();
337                if (!validate_facebook_url(number)) {
338			jQuery(this).children('input').addClass('warning');
339			jQuery(this).children('.errortext').html(pm_error_object.valid_facebook_url);
340			jQuery(this).children('.errortext').show();
341		}
342	});
343        
344        jQuery('#'+formid+' .pm_twitter_url').each(function (index, element) {
345		var number = jQuery(this).children('input').val();
346                if (!validate_twitter_url(number)) {
347			jQuery(this).children('input').addClass('warning');
348			jQuery(this).children('.errortext').html(pm_error_object.valid_twitter_url);
349			jQuery(this).children('.errortext').show();
350		}
351	});
352
353            
354        jQuery('#'+formid+' .pm_google_url').each(function (index, element) {
355		var number = jQuery(this).children('input').val();
356                if (!validate_google_url(number)) {
357			jQuery(this).children('input').addClass('warning');
358			jQuery(this).children('.errortext').html(pm_error_object.valid_google_url);
359			jQuery(this).children('.errortext').show();
360		}
361	});
362        
363                
364        jQuery('#'+formid+' .pm_linked_in_url').each(function (index, element) {
365		var number = jQuery(this).children('input').val();
366                if (!validate_linked_in_url(number)) {
367			jQuery(this).children('input').addClass('warning');
368			jQuery(this).children('.errortext').html(pm_error_object.valid_linked_in_url);
369			jQuery(this).children('.errortext').show();
370		}
371	});
372        
373                
374        jQuery('#'+formid+' .pm_youtube_url').each(function (index, element) {
375		var number = jQuery(this).children('input').val();
376                if (!validate_youtube_url(number)) {
377			jQuery(this).children('input').addClass('warning');
378			jQuery(this).children('.errortext').html(pm_error_object.valid_youtube_url);
379			jQuery(this).children('.errortext').show();
380		}
381	});
382        
383        jQuery('#'+formid+' .pm_mixcloud_url').each(function (index, element) {
384		var number = jQuery(this).children('input').val();
385                if (!validate_mixcloud_url(number)) {
386			jQuery(this).children('input').addClass('warning');
387			jQuery(this).children('.errortext').html(pm_error_object.valid_mixcloud_url);
388			jQuery(this).children('.errortext').show();
389		}
390	});
391        
392        jQuery('#'+formid+' .pm_soundcloud_url').each(function (index, element) {
393		var number = jQuery(this).children('input').val();
394                if (!validate_soundcloud_url(number)) {
395			jQuery(this).children('input').addClass('warning');
396			jQuery(this).children('.errortext').html(pm_error_object.valid_soundcloud_url);
397			jQuery(this).children('.errortext').show();
398		}
399	});
400        
401                
402        jQuery('#'+formid+' .pm_instagram_url').each(function (index, element) {
403		var number = jQuery(this).children('input').val();
404                if (!validate_instagram_url(number)) {
405			jQuery(this).children('input').addClass('warning');
406			jQuery(this).children('.errortext').html(pm_error_object.valid_instagram_url);
407			jQuery(this).children('.errortext').show();
408		}
409	});
410        
411	jQuery('#'+formid+' .pm_datepicker').each(function (index, element) {
412		var date = jQuery(this).children('input').val();
413		var pattern = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/;
414                if(pm_fields_object.dateformat == 'dd-mm-yy'){
415                    pattern = /^([0-9]{2})-([0-9]{2})-([0-9]{4})$/;
416                }
417                else if(pm_fields_object.dateformat =='yy-mm-dd'){
418                    pattern = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/;
419                }
420                else if(pm_fields_object.dateformat =='mm-dd-yy'){
421                    pattern = /^([0-9]{2})-([0-9]{2})-([0-9]{4})$/;
422                }
423                else if(pm_fields_object.dateformat == 'dd.mm.yy'){
424                    pattern = /^([0-9]{2}).([0-9]{2}).([0-9]{4})$/;
425                }
426                else if(pm_fields_object.dateformat =='yy.mm.dd'){
427                    pattern = /^([0-9]{4}).([0-9]{2}).([0-9]{2})$/;
428                }
429                else if(pm_fields_object.dateformat =='mm.dd.yy'){
430                    pattern = /^([0-9]{2}).([0-9]{2}).([0-9]{4})$/;
431                }
432                else if(pm_fields_object.dateformat =='yy/mm/dd'){
433                    pattern = /^([0-9]{4})\/([0-9]{2})\/([0-9]{2})$/;
434                }
435                else if(pm_fields_object.dateformat =='mm/dd/yy'){
436                    pattern = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
437                }else if(pm_fields_object.dateformat =='dd/mm/yy'){
438                    pattern = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
439                }
440                if (date != "" && !pattern.test(date)) {
441			jQuery(this).children('input').addClass('warning');
442			jQuery(this).children('.errortext').html(pm_error_object.valid_date);
443			jQuery(this).children('.errortext').show();
444		}
445            
446	});
447	
448	jQuery('#'+formid+' .pm_required').each(function (index, element) {
449		var value = jQuery(this).children('input').val();
450		var value = jQuery.trim(value);
451		if (value == "") {
452			jQuery(this).children('input').addClass('warning');
453			jQuery(this).children('.errortext').html(pm_error_object.required_field);
454			jQuery(this).children('.errortext').show();
455		}
456	});
457	
458	jQuery('#'+formid+' .pm_select_required').each(function (index, element) {
459		var value = jQuery(this).children('select').val();
460		var value = jQuery.trim(value);
461		if (value == "") {
462			jQuery(this).children('select').addClass('warning');
463			jQuery(this).children('.errortext').html(pm_error_object.required_field);
464			jQuery(this).children('.errortext').show();
465		}
466	});
467        
468	jQuery('#'+formid+' .pm_rich_editor_required').each(function (index, element) {
469           
470	});
471        
472	jQuery('#'+formid+' .pm_textarearequired').each(function (index, element) {
473		var value = jQuery(this).children('textarea').val();
474		var value = jQuery.trim(value);
475		if (value == "") {
476			jQuery(this).children('textarea').addClass('warning');
477			jQuery(this).children('.errortext').html(pm_error_object.required_field);
478			jQuery(this).children('.errortext').show();
479		}
480	});
481	
482	jQuery('#'+formid+' .pm_checkboxrequired').each(function (index, element) {
483		var checkboxlenght = jQuery(this).children('.pmradio').children('.pm-radio-option').children('input[type="checkbox"]:checked');
484		var atLeastOneIsChecked = checkboxlenght.length > 0;
485		if (atLeastOneIsChecked == true) {
486		}else{
487			//jQuery(this).children('textarea').addClass('warning');
488			jQuery(this).children('.errortext').html(pm_error_object.required_field);
489			jQuery(this).children('.errortext').show();
490		}
491	});
492	
493	jQuery('#'+formid+' .pm_radiorequired').each(function (index, element) {
494		var checkboxlenght = jQuery(this).children('.pmradio').children('.pm-radio-option').children('input[type="radio"]:checked');
495		var atLeastOneIsChecked = checkboxlenght.length > 0;
496		if (atLeastOneIsChecked == true) {
497		}else{
498			//jQuery(this).children('textarea').addClass('warning');
499			jQuery(this).children('.errortext').html(pm_error_object.required_field);
500			jQuery(this).children('.errortext').show();
501		}
502	});
503	
504	jQuery('#'+formid+' .pm_fileinput .pm_repeat').each(function (index, element) {
505		var val = jQuery(this).children('input').val().toLowerCase();
506		var allowextensions = jQuery(this).children('input').attr('data-filter-placeholder');
507		if(allowextensions=='')
508		{
509			allowextensions = pm_error_object.allow_file_ext;
510		}
511		
512		allowextensions = allowextensions.toLowerCase();
513		var regex = new RegExp("(.*?)\.(" + allowextensions + ")$");
514		if(!(regex.test(val)) && val!="") {
515		
516			jQuery(this).children('input').addClass('warning');
517			jQuery(this).children('.errortext').html(pm_error_object.file_type);
518			jQuery(this).children('.errortext').show();
519		}
520	});
521	
522	jQuery('#'+formid+' .pm_repeat_required .pm_repeat').each(function (index, element) {
523		var value = jQuery(this).children('input').val();
524		var value = jQuery.trim(value);
525		if (value == "") {
526			jQuery(this).children('input').addClass('warning');
527			jQuery(this).children('.errortext').html(pm_error_object.required_field);
528			jQuery(this).children('.errortext').show();
529		}
530	});
531	
532	jQuery('#'+formid+' .pm_user_pass').each(function (index, element) {
533		var password = jQuery(this).children('input').val();
534		var passwordlength = password.length;
535		if(password !="")
536		{
537			if(passwordlength < 7)
538			{
539				jQuery(this).children('input').addClass('warning');
540				jQuery(this).children('.errortext').html(pm_error_object.short_password);
541				jQuery(this).children('.errortext').show();
542			}
543		}
544	});
545	
546	jQuery('#'+formid+' .pm_confirm_pass').each(function (index, element) {
547		var confirm_pass = jQuery(this).children('input').val();
548		var password = password = jQuery('#'+formid+' .pm_user_pass').children('input').val();
549		if(password != confirm_pass)
550		{
551			jQuery(this).children('input').addClass('warning');
552			jQuery(this).children('.errortext').html(pm_error_object.pass_not_match);
553			jQuery(this).children('.errortext').show();
554		}
555	});
556	
557	jQuery('#'+formid+' .pm_recaptcha').each(function (index, element) {
558		if (typeof grecaptcha !== 'undefined' && typeof grecaptcha.getResponse === 'function') {
559			var response = grecaptcha.getResponse();
560			// recaptcha failed validation
561			if (response.length == 0) {
562				jQuery(this).children('.errortext').html(pm_error_object.required_field);
563				jQuery(this).children('.errortext').show();
564			}
565		}
566	});
567	
568	var b = '';
569	 jQuery('#'+formid+' .errortext').each(function () {
570		var a = jQuery(this).html();
571                if(a!=='')
572                {
573                    jQuery(this).addClass('pg-form-validation-error');
574                }
575		b = a + b;
576	});
577	
578	if (jQuery('#'+formid+' .usernameerror').length > 0) 
579		{
580			c = jQuery('#'+formid+' .usernameerror').html();
581                        if(c!=='')
582                        {
583                            jQuery('#'+formid+' .usernameerror').addClass('pg-form-validation-error');
584                        }
585			b = c + b;
586		}
587                else
588                {
589                    c = '';
590                }
591		
592		if (jQuery('#'+formid+' .useremailerror').length > 0) 
593		{
594			d = jQuery('.useremailerror').html();
595                         if(d!=='')
596                        {
597                            jQuery('#'+formid+' .useremailerror').addClass('pg-form-validation-error');
598                        }
599			b = c + b;
600			b = d + b;
601		}
602	jQuery('#'+formid+' .all_errors').html(b);
603	var error = jQuery('#'+formid+' .all_errors').html();
604	if (error == '') {
605		return true;
606	} else {
607            jQuery('html, body').animate({
608                scrollTop: jQuery('#'+formid+' .pg-form-validation-error').first().offset().top-40
609            }, 500);
610            jQuery('.pg-edit-group-popup-loader').remove();
611            jQuery('input[type=submit][name=reg_form_submit]').removeClass('pg-stripe-submit-disabled');
612		return false;
613	}
614}
615
616function profile_magic_frontend_validation_edit_profile(form)
617{
618	
619	var email_val = "";
620	var formid = form.id;
621	var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
622	jQuery('.errortext').html('');
623	jQuery('.errortext').hide();
624	jQuery('.all_errors').html('');
625	jQuery('.warning').removeClass('warning');
626
627        jQuery('#'+formid+' .pm_email').each(function (index, element) {
628		var email = jQuery(this).children('input').val();
629		var isemail = regex.test(email);
630		if (isemail == false && email != "") {
631			jQuery(this).children('input').addClass('warning');
632			jQuery(this).children('.errortext').html(pm_error_object.valid_email);
633			jQuery(this).children('.errortext').show();
634		}
635	});
636	
637	jQuery('#'+formid+' .pm_number').each(function (index, element) {
638		var number = jQuery(this).children('input').val();
639		var isnumber = jQuery.isNumeric(number);
640		if (isnumber == false && number != "") {
641			jQuery(this).children('input').addClass('warning');
642			jQuery(this).children('.errortext').html(pm_error_object.valid_number);
643			jQuery(this).children('.errortext').show();
644		}
645	});
646	
647        	
648	jQuery('#'+formid+' .pm_phone_number').each(function (index, element) {
649		var number = jQuery(this).children('input').val();
650                if (!validate_phone_number(number)) {
651			jQuery(this).children('input').addClass('warning');
652			jQuery(this).children('.errortext').html(pm_error_object.valid_phone_number);
653			jQuery(this).children('.errortext').show();
654		}
655	});
656        
657        jQuery('#'+formid+' .pm_mobile_number').each(function (index, element) {
658		var number = jQuery(this).children('input').val();
659                if (!validateMobileNumber(number)) {
660			jQuery(this).children('input').addClass('warning');
661			jQuery(this).children('.errortext').html(pm_error_object.valid_mobile_number);
662			jQuery(this).children('.errortext').show();
663		}
664	});
665        
666        jQuery('#'+formid+' .pm_facebook_url').each(function (index, element) {
667		var number = jQuery(this).children('input').val();
668                if (!validate_facebook_url(number)) {
669			jQuery(this).children('input').addClass('warning');
670			jQuery(this).children('.errortext').html(pm_error_object.valid_facebook_url);
671			jQuery(this).children('.errortext').show();
672		}
673	});
674        
675        jQuery('#'+formid+' .pm_twitter_url').each(function (index, element) {
676		var number = jQuery(this).children('input').val();
677                if (!validate_twitter_url(number)) {
678			jQuery(this).children('input').addClass('warning');
679			jQuery(this).children('.errortext').html(pm_error_object.valid_twitter_url);
680			jQuery(this).children('.errortext').show();
681		}
682	});
683
684            
685        jQuery('#'+formid+' .pm_google_url').each(function (index, element) {
686		var number = jQuery(this).children('input').val();
687                if (!validate_google_url(number)) {
688			jQuery(this).children('input').addClass('warning');
689			jQuery(this).children('.errortext').html(pm_error_object.valid_google_url);
690			jQuery(this).children('.errortext').show();
691		}
692	});
693        
694                
695        jQuery('#'+formid+' .pm_linked_in_url').each(function (index, element) {
696		var number = jQuery(this).children('input').val();
697                if (!validate_linked_in_url(number)) {
698			jQuery(this).children('input').addClass('warning');
699			jQuery(this).children('.errortext').html(pm_error_object.valid_linked_in_url);
700			jQuery(this).children('.errortext').show();
701		}
702	});
703        
704                
705        jQuery('#'+formid+' .pm_youtube_url').each(function (index, element) {
706		var number = jQuery(this).children('input').val();
707                if (!validate_youtube_url(number)) {
708			jQuery(this).children('input').addClass('warning');
709			jQuery(this).children('.errortext').html(pm_error_object.valid_youtube_url);
710			jQuery(this).children('.errortext').show();
711		}
712	});
713        
714        jQuery('#'+formid+' .pm_mixcloud_url').each(function (index, element) {
715		var number = jQuery(this).children('input').val();
716                if (!validate_mixcloud_url(number)) {
717			jQuery(this).children('input').addClass('warning');
718			jQuery(this).children('.errortext').html(pm_error_object.valid_mixcloud_url);
719			jQuery(this).children('.errortext').show();
720		}
721	});
722        
723        jQuery('#'+formid+' .pm_soundcloud_url').each(function (index, element) {
724		var number = jQuery(this).children('input').val();
725                if (!validate_soundcloud_url(number)) {
726			jQuery(this).children('input').addClass('warning');
727			jQuery(this).children('.errortext').html(pm_error_object.valid_soundcloud_url);
728			jQuery(this).children('.errortext').show();
729		}
730	});
731        
732                
733        jQuery('#'+formid+' .pm_instagram_url').each(function (index, element) {
734		var number = jQuery(this).children('input').val();
735                if (!validate_instagram_url(number)) {
736			jQuery(this).children('input').addClass('warning');
737			jQuery(this).children('.errortext').html(pm_error_object.valid_instagram_url);
738			jQuery(this).children('.errortext').show();
739		}
740	});
741        
742	jQuery('#'+formid+' .pm_datepicker').each(function (index, element) {
743		var date = jQuery(this).children('input').val();
744		var pattern = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/;
745                if(pm_fields_object.dateformat == 'dd-mm-yy'){
746                    pattern = /^([0-9]{2})-([0-9]{2})-([0-9]{4})$/;
747                }
748                else if(pm_fields_object.dateformat =='yy-mm-dd'){
749                    pattern = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/;
750                }
751                else if(pm_fields_object.dateformat =='mm-dd-yy'){
752                    pattern = /^([0-9]{2})-([0-9]{2})-([0-9]{4})$/;
753                }
754                else if(pm_fields_object.dateformat == 'dd.mm.yy'){
755                    pattern = /^([0-9]{2}).([0-9]{2}).([0-9]{4})$/;
756                }
757                else if(pm_fields_object.dateformat =='yy.mm.dd'){
758                    pattern = /^([0-9]{4}).([0-9]{2}).([0-9]{2})$/;
759                }
760                else if(pm_fields_object.dateformat =='mm.dd.yy'){
761                    pattern = /^([0-9]{2]).([0-9]{2}).([0-9]{4})$/;
762                }
763                else if(pm_fields_object.dateformat =='yy/mm/dd'){
764                    pattern = /^([0-9]{4})\/([0-9]{2})\/([0-9]{2})$/;
765                }
766                else if(pm_fields_object.dateformat =='mm/dd/yy'){
767                    pattern = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
768                }else if(pm_fields_object.dateformat =='dd/mm/yy'){
769                    pattern = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
770                }
771                if (date != "" && !pattern.test(date)) {
772			jQuery(this).children('input').addClass('warning');
773			jQuery(this).children('.errortext').html(pm_error_object.valid_date);
774			jQuery(this).children('.errortext').show();
775		}
776            
777	});
778	
779	jQuery('#'+formid+' .pm_required').each(function (index, element) {
780		var value = jQuery(this).children('input').val();
781		var value = jQuery.trim(value);
782		if (value == "") {
783			jQuery(this).children('input').addClass('warning');
784			jQuery(this).children('.errortext').html(pm_error_object.required_field);
785			jQuery(this).children('.errortext').show();
786		}
787	});
788	
789	jQuery('#'+formid+' .pm_select_required').each(function (index, element) {
790		var value = jQuery(this).children('select').val();
791		var value = jQuery.trim(value);
792		if (value == "") {
793			jQuery(this).children('select').addClass('warning');
794			jQuery(this).children('.errortext').html(pm_error_object.required_field);
795			jQuery(this).children('.errortext').show();
796		}
797	});
798        
799	jQuery('#'+formid+' .pm_rich_editor_required').each(function (index, element) {
800           
801	});
802        
803	jQuery('#'+formid+' .pm_textarearequired').each(function (index, element) {
804		var value = jQuery(this).children('textarea').val();
805		var value = jQuery.trim(value);
806		if (value == "") {
807			jQuery(this).children('textarea').addClass('warning');
808			jQuery(this).children('.errortext').html(pm_error_object.required_field);
809			jQuery(this).children('.errortext').show();
810		}
811	});
812	
813	jQuery('#'+formid+' .pm_checkboxrequired').each(function (index, element) {
814		var checkboxlenght = jQuery(this).children('.pmradio').children('.pm-radio-option').children('input[type="checkbox"]:checked');
815		var atLeastOneIsChecked = checkboxlenght.length > 0;
816		if (atLeastOneIsChecked == true) {
817		}else{
818			//jQuery(this).children('textarea').addClass('warning');
819			jQuery(this).children('.errortext').html(pm_error_object.required_field);
820			jQuery(this).children('.errortext').show();
821		}
822	});
823	
824	jQuery('#'+formid+' .pm_radiorequired').each(function (index, element) {
825		var checkboxlenght = jQuery(this).children('.pmradio').children('.pm-radio-option').children('input[type="radio"]:checked');
826		var atLeastOneIsChecked = checkboxlenght.length > 0;
827		if (atLeastOneIsChecked == true) {
828		}else{
829			//jQuery(this).children('textarea').addClass('warning');
830			jQuery(this).children('.errortext').html(pm_error_object.required_field);
831			jQuery(this).children('.errortext').show();
832		}
833	});
834	
835	jQuery('#'+formid+' .pm_fileinput .pm_repeat').each(function (index, element) {
836		var val = jQuery(this).children('input').val().toLowerCase();
837		var allowextensions = jQuery(this).children('input').attr('data-filter-placeholder');
838		if(allowextensions=='')
839		{
840			allowextensions = pm_error_object.allow_file_ext;
841		}
842		
843		allowextensions = allowextensions.toLowerCase();
844		var regex = new RegExp("(.*?)\.(" + allowextensions + ")$");
845		if(!(regex.test(val)) && val!="") {
846		
847			jQuery(this).children('input').addClass('warning');
848			jQuery(this).children('.errortext').html(pm_error_object.file_type);
849			jQuery(this).children('.errortext').show();
850		}
851	});
852	
853	jQuery('#'+formid+' .pm_repeat_required .pm_repeat').each(function (index, element) {
854		var value = jQuery(this).children('input').val();
855		var value = jQuery.trim(value);
856		if (value == "") {
857			jQuery(this).children('input').addClass('warning');
858			jQuery(this).children('.errortext').html(pm_error_object.required_field);
859			jQuery(this).children('.errortext').show();
860		}
861	});
862	
863	jQuery('#'+formid+' .pm_user_pass').each(function (index, element) {
864		var password = jQuery(this).children('input').val();
865		var passwordlength = password.length;
866		if(password !="")
867		{
868			if(passwordlength < 7)
869			{
870				jQuery(this).children('input').addClass('warning');
871				jQuery(this).children('.errortext').html(pm_error_object.short_password);
872				jQuery(this).children('.errortext').show();
873			}
874		}
875	});
876	
877	jQuery('#'+formid+' .pm_confirm_pass').each(function (index, element) {
878		var confirm_pass = jQuery(this).children('input').val();
879		var password = password = jQuery('#'+formid+' .pm_user_pass').children('input').val();
880		if(password != confirm_pass)
881		{
882			jQuery(this).children('input').addClass('warning');
883			jQuery(this).children('.errortext').html(pm_error_object.pass_not_match);
884			jQuery(this).children('.errortext').show();
885		}
886	});
887	
888	jQuery('#'+formid+' .pm_recaptcha').each(function (index, element) {
889		var response = grecaptcha.getResponse();
890				//recaptcha failed validation
891		if (response.length == 0) {
892			jQuery(this).children('.errortext').html(pm_error_object.required_field);
893			jQuery(this).children('.errortext').show();
894		}
895	});
896	
897	var b = '';
898	 jQuery('#'+formid+' .errortext').each(function () {
899		var a = jQuery(this).html();
900		b = a + b;
901	});
902	
903	if (jQuery('#'+formid+' .usernameerror').length > 0) 
904		{
905			c = jQuery('.usernameerror').html();
906			b = c + b;
907		}
908		
909		if (jQuery('#'+formid+' .useremailerror').length > 0) 
910		{
911			d = jQuery('.useremailerror').html();
912			b = d + b;
913		}
914	jQuery('#'+formid+' .all_errors').html(b);
915	var error = jQuery('#'+formid+' .all_errors').html();
916	if (error == '') {
917		return true;
918	} else {
919            pm_expand_all_conent();
920            jQuery(window).scrollTop( jQuery(".warning:first").offset().top);
921            console.log(jQuery(".warning:first").offset().top);
922		return false;
923	}
924}
925
926function pm_frontend_check_username(formid)
927{
928	jQuery('.pm_user_name').each(function (index, element) {
929			var field = this;
930			var username = jQuery(this).children('input').val();
931			var data = {
932							'action': 'pm_check_user_exist',
933                                                        'nonce': pm_ajax_object.nonce,
934							'type': 'validateUserName',
935							'userdata' : username
936						};
937		// We can also pass the url value separately from ajaxurl for front end AJAX implementations
938			jQuery.post(pm_ajax_object.ajax_url, data, function(response) {
939				if(response=="true")
940				{
941					jQuery(field).children('input').addClass('warning');
942					jQuery(field).children('.usernameerror').html(pm_error_object.user_exist);
943					jQuery(field).children('.usernameerror').show();
944				}
945				else
946				{
947					jQuery(field).children('input').removeClass('warning');
948					jQuery(field).children('.usernameerror').html('');
949					jQuery(field).children('.usernameerror').hide();
950				}
951				
952			});		
953		});	
954}
955
956function pm_frontend_check_useremail(previous)
957{
958	jQuery('.pm_user_email').each(function (index, element) {
959		var field = this;
960		var username = jQuery(this).children('input').val();
961		var data = {
962						'action': 'pm_check_user_exist',
963                                                'nonce': pm_ajax_object.nonce, 
964						'type': 'validateUserEmail',
965						'userdata' : username,
966                                                'previous_data':previous
967					};
968	// We can also pass the url value separately from ajaxurl for front end AJAX implementations
969		jQuery.post(pm_ajax_object.ajax_url, data, function(response) {
970			if(response=="true")
971			{
972				jQuery(field).children('input').addClass('warning');
973				jQuery(field).children('.useremailerror').html(pm_error_object.email_exist);
974				jQuery(field).children('.useremailerror').show();
975			}
976			else
977			{
978				jQuery(field).children('input').removeClass('warning');
979				jQuery(field).children('.useremailerror').html('');
980				jQuery(field).children('.useremailerror').hide();	
981			}
982		});		
983	});
984}
985
986function pm_frontend_change_password(form)
987{
988	var pass1 = jQuery(form).children('.pmrow').children('.pm-col').children('.pm-field-input').children('#pass1').val();	
989        var pass2 = jQuery(form).children('.pmrow').children('.pm-col').children('.pm-field-input').children('#pass2').val();	
990	var userid = jQuery(form).find('input[name="user_id"]').val();
991        jQuery('#pm_reset_passerror').removeClass('pm_password_error');
992        jQuery('#pm_reset_passerror').removeClass('pm_password_success');
993	var data = {'action': 'pm_change_frontend_user_pass','pass1': pass1,'pass2' : pass2, 'nonce': pm_ajax_object.nonce};
994	// We can also pass the url value separately from ajaxurl for front end AJAX implementations
995		jQuery.post(pm_ajax_object.ajax_url, data, function(response) {
996			if(response==true)
997			{
998                            jQuery('#pm_reset_passerror').addClass('pm_password_success');
999				jQuery('#pm_reset_passerror').html(pm_error_object.password_change_successfully);
1000				jQuery('#pm_reset_passerror').show();
1001                                window.location = pm_error_object.login_url;
1002                        }
1003                        else
1004                        {
1005                            
1006                            jQuery('#pm_reset_passerror').addClass('pm_password_error');
1007                            jQuery('#pm_reset_passerror').html(response);
1008			    jQuery('#pm_reset_passerror').show();
1009                        }
1010		});		
1011	return false;
1012}
1013
1014var searchRequest = null; 
1015function pm_advance_user_search(pagenum)
1016{
1017    var form = jQuery("#pm-advance-search-form");
1018    var ajaxUrl = (window.pm_ajax_object && pm_ajax_object.ajax_url) ? pm_ajax_object.ajax_url : (typeof window.ajaxurl === 'string' ? window.ajaxurl : '');
1019    var ajaxNonce = (window.pm_ajax_object && pm_ajax_object.nonce) ? pm_ajax_object.nonce : '';
1020
1021    if (ajaxUrl === '') {
1022        return;
1023    }
1024
1025    jQuery("#pm_result_pane").html('<div class="pm-loader"></div>');
1026    var pmDomColor = jQuery(".pmagic").find("a").css('color');
1027    jQuery(".pm-loader").css('border-top-color', pmDomColor);
1028  
1029
1030    if (jQuery('#advance_seach_ul li').length === 0){
1031       jQuery('#pm-advance-search-form #advance_search_pane #advance_seach_ul').addClass("pg-advance-search-hide"); 
1032    }else{
1033        jQuery('#pm-advance-search-form #advance_search_pane #advance_seach_ul').removeClass("pg-advance-search-hide"); 
1034    }
1035
1036       
1037       
1038    if(pagenum!== '')
1039    {
1040            if(pagenum=='Reset')
1041            {
1042                form.trigger('reset');
1043                jQuery('#advance_search_pane').hide(200);
1044                jQuery('#pagenum').attr("value",1);
1045                jQuery('input[type=checkbox]').attr("checked",false);
1046                pm_change_search_field('');
1047            }
1048            else
1049            {
1050                jQuery('#pagenum').attr("value",pagenum);
1051            }
1052        
1053    }
1054    else
1055    {
1056         jQuery('#pagenum').attr("value",1);
1057    }
1058    var form_values = form.serializeArray();
1059
1060    var data = {};
1061
1062    if (ajaxNonce !== '') {
1063        data.nonce = ajaxNonce;
1064    }
1065
1066    //creating data in object format and array for multiple checkbox
1067    jQuery.each(form_values, function () {
1068        if (data[this.name] !== undefined) {
1069            if (!data[this.name].push) {
1070                data[this.name] = [data[this.name]];
1071            }
1072            data[this.name].push(this.value);
1073        } else {
1074            data[this.name] = this.value;
1075        }
1076    });
1077    //console.log(data);
1078   
1079    if(searchRequest != null)
1080        searchRequest.abort();
1081        //ajax call start
1082    searchRequest =    jQuery.post(ajaxUrl, data, function (resp) 
1083        {
1084        
1085                if (resp)
1086                {   
1087                    jQuery("#pm_result_pane").html(resp);
1088                    
1089        var pmDomColor = jQuery(".pmagic").find("a").css('color');
1090        jQuery(".pm-color").css('color', pmDomColor);
1091        jQuery( ".page-numbers.current" ).css('background', pmDomColor); 
1092                } 
1093                else
1094                {
1095                    //console.log("err");
1096                }
1097            
1098         });
1099         //ajax call ends here
1100         
1101         
1102
1103
1104}
1105
1106function profile_magic_send_email(userid)
1107{
1108    var data = {'action': 'pm_send_change_pass_email','userid': userid,'nonce': pm_ajax_object.nonce};
1109	// We can also pass the url value separately from ajaxurl for front end AJAX implementations
1110		jQuery.post(pm_ajax_object.ajax_url, data, function(response) {
1111                    
1112		});		
1113	return false;
1114}
1115
1116function profile_magic_multistep_form_validation(form)
1117{
1118	
1119	var email_val = "";
1120	var formid = form.attr('id');
1121	var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
1122	if (typeof pm_fields_object === 'undefined' || pm_fields_object === null) {
1123		window.pm_fields_object = { dateformat: 'yy-mm-dd' };
1124	}
1125	jQuery('.errortext').html('');
1126	jQuery('.errortext').hide();
1127	jQuery('.all_errors').html('');
1128	jQuery('.warning').removeClass('warning');
1129jQuery('#'+formid+' .pm_email').each(function (index, element) {
1130		var email = jQuery(this).children('input').val();
1131		var isemail = regex.test(email);
1132		if (isemail == false && email != "") {
1133			jQuery(this).children('input').addClass('warning');
1134			jQuery(this).children('.errortext').html(pm_error_object.valid_email);
1135			jQuery(this).children('.errortext').show();
1136		}
1137	});
1138	
1139	jQuery('#'+formid+' .pm_number').each(function (index, element) {
1140		var number = jQuery(this).children('input').val();
1141		var isnumber = jQuery.isNumeric(number);
1142		if (isnumber == false && number != "") {
1143			jQuery(this).children('input').addClass('warning');
1144			jQuery(this).children('.errortext').html(pm_error_object.valid_number);
1145			jQuery(this).children('.errortext').show();
1146		}
1147	});
1148	
1149        jQuery('#'+formid+' .pm_phone_number').each(function (index, element) {
1150		var number = jQuery(this).children('input').val();
1151                if (!validate_phone_number(number)) {
1152			jQuery(this).children('input').addClass('warning');
1153			jQuery(this).children('.errortext').html(pm_error_object.valid_phone_number);
1154			jQuery(this).children('.errortext').show();
1155		}
1156	});
1157        
1158        jQuery('#'+formid+' .pm_mobile_number').each(function (index, element) {
1159		var number = jQuery(this).children('input').val();
1160                if (!validateMobileNumber(number)) {
1161			jQuery(this).children('input').addClass('warning');
1162			jQuery(this).children('.errortext').html(pm_error_object.valid_mobile_number);
1163			jQuery(this).children('.errortext').show();
1164		}
1165	});
1166        
1167        jQuery('#'+formid+' .pm_facebook_url').each(function (index, element) {
1168		var number = jQuery(this).children('input').val();
1169                if (!validate_facebook_url(number)) {
1170			jQuery(this).children('input').addClass('warning');
1171			jQuery(this).children('.errortext').html(pm_error_object.valid_facebook_url);
1172			jQuery(this).children('.errortext').show();
1173		}
1174	});
1175        
1176        jQuery('#'+formid+' .pm_twitter_url').each(function (index, element) {
1177		var number = jQuery(this).children('input').val();
1178                if (!validate_twitter_url(number)) {
1179			jQuery(this).children('input').addClass('warning');
1180			jQuery(this).children('.errortext').html(pm_error_object.valid_twitter_url);
1181			jQuery(this).children('.errortext').show();
1182		}
1183	});
1184
1185            
1186        jQuery('#'+formid+' .pm_google_url').each(function (index, element) {
1187		var number = jQuery(this).children('input').val();
1188                if (!validate_google_url(number)) {
1189			jQuery(this).children('input').addClass('warning');
1190			jQuery(this).children('.errortext').html(pm_error_object.valid_google_url);
1191			jQuery(this).children('.errortext').show();
1192		}
1193	});
1194        
1195                
1196        jQuery('#'+formid+' .pm_linked_in_url').each(function (index, element) {
1197		var number = jQuery(this).children('input').val();
1198                if (!validate_linked_in_url(number)) {
1199			jQuery(this).children('input').addClass('warning');
1200			jQuery(this).children('.errortext').html(pm_error_object.valid_linked_in_url);
1201			jQuery(this).children('.errortext').show();
1202		}
1203	});
1204        
1205                
1206        jQuery('#'+formid+' .pm_youtube_url').each(function (index, element) {
1207		var number = jQuery(this).children('input').val();
1208                if (!validate_youtube_url(number)) {
1209			jQuery(this).children('input').addClass('warning');
1210			jQuery(this).children('.errortext').html(pm_error_object.valid_youtube_url);
1211			jQuery(this).children('.errortext').show();
1212		}
1213	});
1214        
1215        jQuery('#'+formid+' .pm_mixcloud_url').each(function (index, element) {
1216		var number = jQuery(this).children('input').val();
1217                if (!validate_mixcloud_url(number)) {
1218			jQuery(this).children('input').addClass('warning');
1219			jQuery(this).children('.errortext').html(pm_error_object.valid_mixcloud_url);
1220			jQuery(this).children('.errortext').show();
1221		}
1222	});
1223        
1224        jQuery('#'+formid+' .pm_soundcloud_url').each(function (index, element) {
1225		var number = jQuery(this).children('input').val();
1226                if (!validate_soundcloud_url(number)) {
1227			jQuery(this).children('input').addClass('warning');
1228			jQuery(this).children('.errortext').html(pm_error_object.valid_soundcloud_url);
1229			jQuery(this).children('.errortext').show();
1230		}
1231	});
1232                
1233        jQuery('#'+formid+' .pm_instagram_url').each(function (index, element) {
1234		var number = jQuery(this).children('input').val();
1235                if (!validate_instagram_url(number)) {
1236			jQuery(this).children('input').addClass('warning');
1237			jQuery(this).children('.errortext').html(pm_error_object.valid_instagram_url);
1238			jQuery(this).children('.errortext').show();
1239		}
1240	});
1241        
1242	jQuery('#'+formid+' .pm_datepicker').each(function (index, element) {
1243		var date = jQuery(this).children('input').val();
1244		var pattern = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/;
1245                if(pm_fields_object.dateformat == 'dd-mm-yy'){
1246                    pattern = /^([0-9]{2})-([0-9]{2})-([0-9]{4})$/;
1247                }
1248                else if(pm_fields_object.dateformat =='yy-mm-dd'){
1249                    pattern = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/;
1250                }
1251                else if(pm_fields_object.dateformat =='mm-dd-yy'){
1252                    pattern = /^([0-9]{2})-([0-9]{2})-([0-9]{4})$/;
1253                }
1254                else if(pm_fields_object.dateformat == 'dd.mm.yy'){
1255                    pattern = /^([0-9]{2}).([0-9]{2}).([0-9]{4})$/;
1256                }
1257                else if(pm_fields_object.dateformat =='yy.mm.dd'){
1258                    pattern = /^([0-9]{4}).([0-9]{2}).([0-9]{2})$/;
1259                }
1260                else if(pm_fields_object.dateformat =='mm.dd.yy'){
1261                    pattern = /^([0-9]{2}).([0-9]{2}).([0-9]{4})$/;
1262                }
1263                else if(pm_fields_object.dateformat =='yy/mm/dd'){
1264                    pattern = /^([0-9]{4})\/([0-9]{2})\/([0-9]{2})$/;
1265                }
1266                else if(pm_fields_object.dateformat =='mm/dd/yy'){
1267                    pattern = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
1268                }else if(pm_fields_object.dateformat =='dd/mm/yy'){
1269                    pattern = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
1270                }
1271    	if (date != "" && !pattern.test(date)) {
1272			jQuery(this).children('input').addClass('warning');
1273			jQuery(this).children('.errortext').html(pm_error_object.valid_date);
1274			jQuery(this).children('.errortext').show();
1275		}
1276	});
1277	
1278	jQuery('#'+formid+' .pm_required').each(function (index, element) {
1279		var value = jQuery(this).children('input').val();
1280		var value = jQuery.trim(value);
1281		if (value == "") {
1282			jQuery(this).children('input').addClass('warning');
1283			jQuery(this).children('.errortext').html(pm_error_object.required_field);
1284			jQuery(this).children('.errortext').show();
1285		}
1286	});
1287	
1288	jQuery('#'+formid+' .pm_select_required').each(function (index, element) {
1289		var value = jQuery(this).children('select').val();
1290		var value = jQuery.trim(value);
1291		if (value == "") {
1292			jQuery(this).children('select').addClass('warning');
1293			jQuery(this).children('.errortext').html(pm_error_object.required_field);
1294			jQuery(this).children('.errortext').show();
1295		}
1296	});
1297	
1298	jQuery('#'+formid+' .pm_textarearequired').each(function (index, element) {
1299		var value = jQuery(this).children('textarea').val();
1300		var value = jQuery.trim(value);
1301		if (value == "") {
1302			jQuery(this).children('textarea').addClass('warning');
1303			jQuery(this).children('.errortext').html(pm_error_object.required_field);
1304			jQuery(this).children('.errortext').show();
1305		}
1306	});
1307	
1308	jQuery('#'+formid+' .pm_checkboxrequired').each(function (index, element) {
1309		var checkboxlenght = jQuery(this).children('.pmradio').children('.pm-radio-option').children('input[type="checkbox"]:checked');
1310		var atLeastOneIsChecked = checkboxlenght.length > 0;
1311		if (atLeastOneIsChecked == true) {
1312		}else{
1313			//jQuery(this).children('textarea').addClass('warning');
1314			jQuery(this).children('.errortext').html(pm_error_object.required_field);
1315			jQuery(this).children('.errortext').show();
1316		}
1317	});
1318	
1319	jQuery('#'+formid+' .pm_radiorequired').each(function (index, element) {
1320		var checkboxlenght = jQuery(this).children('.pmradio').children('.pm-radio-option').children('input[type="radio"]:checked');
1321		var atLeastOneIsChecked = checkboxlenght.length > 0;
1322		if (atLeastOneIsChecked == true) {
1323		}else{
1324			//jQuery(this).children('textarea').addClass('warning');
1325			jQuery(this).children('.errortext').html(pm_error_object.required_field);
1326			jQuery(this).children('.errortext').show();
1327		}
1328	});
1329	
1330	jQuery('#'+formid+' .pm_fileinput .pm_repeat').each(function (index, element) {
1331		var val = jQuery(this).children('input').val().toLowerCase();
1332		var allowextensions = jQuery(this).children('input').attr('data-filter-placeholder');
1333		if(allowextensions=='')
1334		{
1335			allowextensions = pm_error_object.allow_file_ext;
1336		}
1337		
1338		allowextensions = allowextensions.toLowerCase();
1339		var regex = new RegExp("(.*?)\.(" + allowextensions + ")$");
1340		if(!(regex.test(val)) && val!="") {
1341		
1342			jQuery(this).children('input').addClass('warning');
1343			jQuery(this).children('.errortext').html(pm_error_object.file_type);
1344			jQuery(this).children('.errortext').show();
1345		}
1346	});
1347	
1348	jQuery('#'+formid+' .pm_repeat_required .pm_repeat').each(function (index, element) {
1349		var value = jQuery(this).children('input').val();
1350		var value = jQuery.trim(value);
1351		if (value == "") {
1352			jQuery(this).children('input').addClass('warning');
1353			jQuery(this).children('.errortext').html(pm_error_object.required_field);
1354			jQuery(this).children('.errortext').show();
1355		}
1356	});
1357	
1358	jQuery('#'+formid+' .pm_user_pass').each(function (index, element) {
1359		var password = jQuery(this).children('input').val();
1360		var passwordlength = password.length;
1361		if(password !="")
1362		{
1363			if(passwordlength < 7)
1364			{
1365				jQuery(this).children('input').addClass('warning');
1366				jQuery(this).children('.errortext').html(pm_error_object.short_password);
1367				jQuery(this).children('.errortext').show();
1368			}
1369		}
1370	});
1371	
1372	jQuery('#'+formid+' .pm_confirm_pass').each(function (index, element) {
1373		var confirm_pass = jQuery(this).children('input').val();
1374		var password = password = jQuery('#'+formid+' .pm_user_pass').children('input').val();
1375		if(password != confirm_pass)
1376		{
1377			jQuery(this).children('input').addClass('warning');
1378			jQuery(this).children('.errortext').html(pm_error_object.pass_not_match);
1379			jQuery(this).children('.errortext').show();
1380		}
1381	});
1382	
1383	jQuery('#'+formid+' .pm_recaptcha').each(function (index, element) {
1384		var response = grecaptcha.getResponse();
1385				//recaptcha failed validation
1386		if (response.length == 0) {
1387			jQuery(this).children('.errortext').html(pm_error_object.required_field);
1388			jQuery(this).children('.errortext').show();
1389		}
1390	});
1391	
1392	var all_errors = '';
1393	jQuery('#'+formid+' .errortext').each(function () {
1394		var a = jQuery(this).html();
1395		all_errors = a + all_errors;
1396	});
1397		if (jQuery('#'+formid+' .usernameerror').length > 0) 
1398		{
1399			c = jQuery('.usernameerror').html();
1400			if(jQuery.trim(c)!='')
1401			jQuery('.pm_user_name').children('input').addClass('warning');
1402			all_errors = c + all_errors;
1403		}
1404		
1405		if (jQuery('#'+formid+' .useremailerror').length > 0) 
1406		{
1407			d = jQuery('.useremailerror').html();
1408			if(jQuery.trim(d)!='')
1409			jQuery('.pm_user_email').children('input').addClass('warning');
1410			all_errors = d + all_errors;
1411		}
1412	jQuery('#'+formid+' .all_errors').html(all_errors);
1413	var error = jQuery('#'+formid+' .all_errors').html();
1414	if (error == '') {
1415		return true;
1416	} else {
1417		return false;
1418	}
1419}
1420
1421function openParentTab() 
1422{
1423	locationHash = location.hash.substring( 1 );
1424	//console.log(locationHash);
1425	// Check if we have an location Hash
1426	if (locationHash) {
1427		// Check if the location hash exsist.
1428		var hash = jQuery('#'+locationHash);
1429		if (hash.length) {
1430			 var t = hash;
1431                        jQuery('li.pm-profile-tab a').removeClass('active');         
1432                        jQuery(this).addClass('active');
1433                        jQuery('.pg-profile-tab-content').hide();
1434                        jQuery(t).find('.pm-section-content:first').show();
1435                        jQuery('li.hideshow ul').hide();
1436                        jQuery(t).fadeIn('slow');
1437                        return false;
1438		}
1439	}
1440}
1441
1442function generateTabs(tabs) { 
1443
1444	html = '';
1445	for (var i in tabs) { 
1446		tab = tabs[i];
1447		html = html + '<li class="multipage_tab"><a href="#" onclick="return jQuery(\'#multipage\').gotopage(' + tab.number + ');">' + tab.title + '</a></li>';				
1448	}
1449	jQuery('<ul class="multipage_tabs" id="multipage_tabs">'+html+'<div class="clearer"></div></ul>').insertBefore('#multipage');
1450}
1451function setActiveTab(selector,page) { 
1452	jQuery('#multipage_tabs li').each(function(index){ 
1453		if ((index+1)==page) { 
1454			jQuery(this).addClass('active');
1455		} else {
1456			jQuery(this).removeClass('active');
1457		}
1458	});			
1459}
1460		
1461function transition(from,to) {
1462	jQuery(from).fadeOut('fast',function(){jQuery(to).fadeIn('fast');});
1463
1464}
1465function textpages(obj,page,pages) { 
1466	jQuery(obj).html(page + ' of ' + pages);
1467}
1468
1469function pm_user_image_validation(a)
1470{
1471	var val = jQuery(a).children('.pm-user-image').val().toLowerCase();
1472	if(val=='')
1473	{
1474		jQuery(a).children('pm-user-image').addClass('warning');
1475		jQuery(a).children('.pm-popup-error').html(pm_error_object.required_field);
1476		jQuery(a).children('.pm-popup-error').show();
1477		return false;
1478	}
1479	
1480	var allowextensions = 'jpg|jpeg|png|gif|webp|avif';
1481	if(allowextensions=='')
1482	{
1483		allowextensions = pm_error_object.allow_file_ext;
1484	}
1485	allowextensions = allowextensions.toLowerCase();
1486	var regex = new RegExp("(.*?)\.(" + allowextensions + ")$");
1487	if(!(regex.test(val)) && val!="") {
1488		jQuery(a).children('pm-user-image').addClass('warning');
1489		jQuery(a).children('.pm-popup-error').html(pm_error_object.file_type);
1490		jQuery(a).children('.pm-popup-error').show();
1491		return false;
1492	}
1493	else
1494	{
1495		jQuery(a).children('.pm-popup-error').html('');
1496		jQuery(a).children('.pm-popup-error').hide();
1497		return true;
1498	}
1499}
1500
1501
1502
1503
1504
1505//GUI Functions
1506function callPmPopup(dialog) {
1507    var pmId = dialog + "-dialog";
1508    jQuery(pmId).siblings('.pm-popup-mask').show();
1509    jQuery(pmId).show();
1510    jQuery('.pm-popup-container').css("animation", "pm-popup-in 0.3s ease-out 1");
1511}
1512
1513
1514
1515
1516function profile_magic_blogpost_validation()
1517{
1518	jQuery('.errortext').html('');
1519	jQuery('.errortext').hide();
1520	jQuery('.all_errors').html('');
1521	jQuery('.warning').removeClass('warning');
1522        jQuery('#pm_add_blog_post .pm_required').each(function (index, element) {
1523		var value = jQuery(this).children('input').val();
1524		var value = jQuery.trim(value);
1525		if (value == "") {
1526			jQuery(this).children('input').addClass('warning');
1527			jQuery(this).children('.errortext').html(pm_error_object.required_field);
1528			jQuery(this).children('.errortext').show();
1529		}
1530	});
1531        
1532        jQuery('#pm_add_blog_post .pm_fileinput .pm_repeat').each(function (index, element) {
1533		var val = jQuery(this).children('input').val().toLowerCase();
1534		var allowextensions = 'jpg|jpeg|png|gif|webp|avif';
1535		if(allowextensions=='')
1536		{
1537			allowextensions = pm_error_object.allow_file_ext;
1538		}
1539		
1540		allowextensions = allowextensions.toLowerCase();
1541		var regex = new RegExp("(.*?)\.(" + allowextensions + ")$");
1542		if(!(regex.test(val)) && val!="") {
1543		
1544			jQuery(this).children('input').addClass('warning');
1545			jQuery(this).children('.errortext').html(pm_error_object.file_type);
1546			jQuery(this).children('.errortext').show();
1547		}
1548	});
1549        var all_errors = '';
1550	jQuery('#pm_add_blog_post .errortext').each(function () {
1551		var a = jQuery(this).html();
1552		all_errors = a + all_errors;
1553	});
1554        jQuery('#pm_add_blog_post .all_errors').html(all_errors);
1555	var error = jQuery('#pm_add_blog_post .all_errors').html();
1556	if (error == '') {
1557            
1558            jQuery('input[name="pg_blog_submit"]').attr('disabled','disabled');
1559		return true;
1560	} else {
1561		return false;
1562	}
1563}
1564
1565function load_more_pg_blogs(uid)
1566{
1567    jQuery('.pm-load-more-blogs').hide();
1568    jQuery('.pg-load-more-container .pm-loader').show();
1569    var page = parseInt(jQuery('#pg_next_blog_page').val());
1570    var nextpage = page +1;
1571    var data = {action: 'pm_load_pg_blogs', 'uid': uid,'page':page,'nonce': pm_ajax_object.nonce};
1572    jQuery.post(pm_ajax_object.ajax_url, data, function (response) {
1573        if(response)
1574        {
1575            jQuery('.pg-load-more-container .pm-loader').hide();
1576            jQuery('#pg_next_blog_page').val(nextpage);
1577            jQuery('#pg-blog-container').append(response);
1578        }
1579    });
1580
1581}
1582
1583function load_more_user_blogs_shortcode_posts(authors,posttypes)
1584{
1585    jQuery('.pm-load-more-blogs').hide();
1586    jQuery('.pg-load-more-container .pm-loader').show();
1587    var page = parseInt(jQuery('#pg_next_blog_page').val());
1588    var nextpage = page +1;
1589    var data = {action: 'pm_load_user_blogs_shortcode_posts',authors: authors, posttypes:posttypes, page:page, 'nonce': pm_ajax_object.nonce};
1590    jQuery.post(pm_ajax_object.ajax_url, data, function (response) {
1591        if(response)
1592        {
1593            jQuery('.pg-load-more-container .pm-loader').hide();
1594            jQuery('#pg_next_blog_page').val(nextpage);
1595            jQuery('#pg-user-blog-container').append(response);
1596        }
1597    });
1598
1599}
1600
1601
1602
1603function pm_delete_account_setting(form)
1604{
1605        var formid = form.id;
1606        jQuery('#'+formid+' .errortext').html('');
1607	jQuery('#'+formid+' .errortext').hide();
1608	jQuery('#'+formid+' .all_errors').html('');
1609	jQuery('#'+formid+' .warning').removeClass('warning');
1610        jQuery('#'+formid+' .pm_required').each(function (index, element) {
1611		var value = jQuery(this).children('input').val();
1612		var value = jQuery.trim(value);
1613		if (value == "") {
1614			jQuery(this).children('input').addClass('warning');
1615			jQuery(this).children('.errortext').html(pm_error_object.required_field);
1616			jQuery(this).children('.errortext').show();
1617		}
1618	});
1619        var all_errors = '';
1620	jQuery('#'+formid+' .errortext').each(function () {
1621		var a = jQuery(this).html();
1622		all_errors = a + all_errors;
1623	});
1624        
1625        jQuery('#'+formid+' .all_errors').html(all_errors);
1626	var error = jQuery('#'+formid+' .all_errors').html();
1627	if (error == '') 
1628        {
1629		return true;
1630	} 
1631        else 
1632        {
1633		return false;
1634	}
1635        
1636}
1637function pm_save_account_setting(form)
1638{
1639    var email_val = "";
1640    var formid = form.id;
1641    var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
1642    jQuery('#'+formid+' .errortext').html('');
1643	jQuery('#'+formid+' .errortext').hide();
1644	jQuery('#'+formid+' .all_errors').html('');
1645	jQuery('#'+formid+' .warning').removeClass('warning');
1646        jQuery('#'+formid+' .pm_required').each(function (index, element) {
1647		var value = jQuery(this).children('input').val();
1648		var value = jQuery.trim(value);
1649		if (value == "") {
1650			jQuery(this).children('input').addClass('warning');
1651			jQuery(this).children('.errortext').html(pm_error_object.required_field);
1652			jQuery(this).children('.errortext').show();
1653		}
1654	});
1655        
1656        jQuery('#'+formid+' .pm_email').each(function (index, element) {
1657		var email = jQuery(this).children('input').val();
1658		var isemail = regex.test(email);
1659		if (isemail == false && email != "") {
1660			jQuery(this).children('input').addClass('warning');
1661			jQuery(this).children('.errortext').html(pm_error_object.valid_email);
1662			jQuery(this).children('.errortext').show();
1663		}
1664	});
1665	
1666        var all_errors = '';
1667	jQuery('#'+formid+' .errortext').each(function () {
1668		var a = jQuery(this).html();
1669		all_errors = a + all_errors;
1670	});
1671        
1672        jQuery('#'+formid+' .all_errors').html(all_errors);
1673	var error = jQuery('#'+formid+' .all_errors').html();
1674	if (error == '') 
1675        {
1676		return true;
1677	} 
1678        else 
1679        {
1680		return false;
1681	}
1682        
1683}
1684
1685(function PG_mobile_resposve ($) {
1686    var $window = $(window),
1687        $html = $('html'),
1688        $is_resize = 0;
1689        
1690
1691    $window.on( 'resize', function resize() {
1692        if ($window.width() < 479) {
1693            if($is_resize==0)
1694            {
1695                show_pg_section_left_panel();
1696                $is_resize = 1;
1697            }
1698            
1699            return $html.addClass('pg-mobile-479');
1700        }
1701        else
1702        {
1703            $('.pm-section-left-panel').show();
1704            $('.pm-section-right-panel').show();
1705        }
1706
1707        $html.removeClass('pg-mobile-479');
1708        
1709        if ($window.width() < 760) {
1710            return $html.addClass('pg-mobile-760');
1711            
1712        }
1713        
1714        $html.removeClass('pg-mobile-760');
1715        
1716        
1717         if ($window.width() < 979) {
1718            return $html.addClass('pg-mobile-979');
1719            
1720        }
1721
1722        $html.removeClass('pg-mobile-979');
1723        
1724    }).trigger('resize');
1725})(jQuery);
1726
1727function show_pg_section_right_panel()
1728{
1729    jQuery(".pg-mobile-479 .pm-section-right-panel").show();
1730    jQuery(".pg-mobile-479 .pm-section-left-panel").hide();
1731    jQuery(".pg-mobile-479 .pg-left-panel-icon").show();
1732}
1733
1734function show_pg_section_left_panel()
1735{
1736    jQuery(".pg-mobile-479 .pm-section-right-panel").hide();
1737    jQuery(".pg-mobile-479 .pm-section-left-panel").show();
1738    jQuery(".pg-mobile-479 .pg-left-panel-icon").hide();
1739}
1740
1741function pg_remove_user_group(uid,gid)
1742{
1743    var boxid = '#pg-user-group-box-'+gid;
1744    var data = {action:'pm_remove_user_group',uid:uid,gid:gid,'nonce': pm_ajax_object.nonce};
1745    jQuery('#pg_edit_group_html_container').html('<div class="pg-edit-group-popup-loader"><div class="pm-loader"></div></div>');
1746     var pmDomColor = jQuery(".pmagic").find("a").css('color');
1747        jQuery(".pm-loader").css('border-top-color', pmDomColor);
1748    jQuery.post(pm_ajax_object.ajax_url, data, function (resp) 
1749    {
1750        //window.location.reload(true);
1751       if(resp=='success')
1752       {
1753            
1754            //jQuery(boxid).remove();
1755            //jQuery('.pm-popup-mask, #pm-edit-group-popup, .pg-blog-dialog-mask').hide();
1756            window.location.reload(true);
1757
1758       }
1759    });
1760
1761}
1762
1763function pg_open_group_tab()
1764{
1765  var child =  jQuery('.pm-profile-tab ul li.pg-group-tab');
1766var parent = jQuery('ul.pm-profile-tab-wrap');
1767
1768     var i = 0;
1769      var tabindex=0;
1770       jQuery('ul.pm-profile-tab-wrap').children('li').each(function () {
1771           jQuery(this).find('a').removeClass("active");
1772        var obj = jQuery(this).find('a[href="#pg-groups"]'); // "this" is the current element in the loop
1773     if(obj.length)
1774        {
1775          jQuery('.pg-profile-tab-content').css("display","none");
1776          obj.addClass("active");
1777          tabindex = i;
1778       }
1779      
1780    i++;
1781  
1782});
1783 
1784 jQuery('#pg-groups').css("display","block");
1785}
1786
1787function pg_init_unread_message_toast() {
1788    var toast = document.getElementById('pg-unread-toast');
1789    if (!toast || toast.getAttribute('data-pg-initialized') === '1') {
1790        return;
1791    }
1792
1793    toast.setAttribute('data-pg-initialized', '1');
1794
1795    var target = toast.getAttribute('data-target');
1796    var baseTarget = toast.getAttribute('data-base-target') || '';
1797    var latest = parseInt(toast.getAttribute('data-latest'), 10) || 0;
1798    var latestRid = parseInt(toast.getAttribute('data-latest-rid'), 10) || 0;
1799    var latestTid = parseInt(toast.getAttribute('data-latest-tid'), 10) || 0;
1800    var dismissed = parseInt(toast.getAttribute('data-dismissed'), 10) || 0;
1801    var count = parseInt(toast.getAttribute('data-count'), 10) || 0;
1802    var show = parseInt(toast.getAttribute('data-show'), 10) || 0;
1803    var text = toast.querySelector('.pg-unread-toast__text');
1804    var openBtn = toast.querySelector('.pg-unread-toast__action');
1805    var closeBtn = toast.querySelector('.pg-unread-toast__close');
1806    var singleLabel = toast.getAttribute('data-single-label') || '';
1807    var multiLabel = toast.getAttribute('data-multi-label') || '';
1808    var summaryTimer = null;
1809    var summaryInFlight = false;
1810    var summaryNoChangeStreak = 0;
1811    var summaryErrorStreak = 0;
1812    var summaryLastActivityAt = Date.now();
1813    var dismissStorageKey = 'pgUnreadToastDismissedAt';
1814    var lastAutoOpenKey = '';
1815
1816    var buildMessageTarget = function (ridValue) {
1817        if (!baseTarget) {
1818            return target;
1819        }
1820
1821        var url = baseTarget;
1822        if (ridValue > 0) {
1823            url += (url.indexOf('?') === -1 ? '?' : '&') + 'rid=' + encodeURIComponent(ridValue);
1824        }
1825
1826        return url + '#pg-messages';
1827    };
1828
1829    var isMessagesTabActive = function () {
1830        var messagesTab = document.getElementById('pg-messages');
1831        if (!messagesTab) {
1832            return false;
1833        }
1834
1835        if (messagesTab.offsetParent !== null) {
1836            return true;
1837        }
1838
1839        return (window.location.hash || '').toLowerCase() === '#pg-messages';
1840    };
1841
1842    var getStoredDismissed = function () {
1843        var storedValue;
1844
1845        try {
1846            storedValue = window.localStorage ? parseInt(window.localStorage.getItem(dismissStorageKey), 10) || 0 : 0;
1847        } catch (e) {
1848            storedValue = 0;
1849        }
1850
1851        return storedValue;
1852    };
1853
1854    var storeDismissed = function (latestValue) {
1855        try {
1856            if (window.localStorage) {
1857                window.localStorage.setItem(dismissStorageKey, String(latestValue || 0
1857));
1858            }
1859        } catch (e) {
1860        }
1861    };
1862
1863    var clearStoredDismissed = function () {
1864        try {
1865            if (window.localStorage) {
1866                window.localStorage.removeItem(dismissStorageKey);
1867            }
1868        } catch (e) {
1869        }
1870    };
1871
1872    dismissed = Math.max(dismissed, getStoredDismissed());
1873
1874    var hideToast = function () {
1875        toast.classList.remove('pg-unread-toast--show');
1876    };
1877
1878    var playUnreadSound = function () {
1879        var tone = document.getElementById('msg_tone');
1880        var now = Date.now();
1881
1882        if (!tone) {
1883            return;
1884        }
1885
1886        if (window.pgUnreadSoundLastPlayedAt && (now - window.pgUnreadSoundLastPlayedAt) < 1200) {
1887            return;
1888        }
1889
1890        window.pgUnreadSoundLastPlayedAt = now;
1891
1892        try {
1893            if (typeof tone.currentTime === 'number') {
1894                tone.currentTime = 0;
1895            }
1896            if (typeof tone.play === 'function') {
1897                var promise = tone.play();
1898                if (promise && typeof promise.catch === 'function') {
1899                    promise.catch(function () {});
1900                }
1901            }
1902        } catch (e) {
1903        }
1904    };
1905
1906    var acknowledgeLatestUnread = function () {
1907        if (!latest) {
1908            return;
1909        }
1910
1911        dismissed = Math.max(dismissed, latest);
1912        storeDismissed(latest);
1913        persistToastDismissal(latest);
1914        hideToast();
1915    };
1916    var buildLabel = function (countValue) {
1917        if (countValue === 1) {
1918            return singleLabel;
1919        }
1920
1921        return multiLabel.replace('{{count}}', countValue);
1922    };
1923
1924    var renderToast = function (countValue, latestValue, dismissedValue) {
1925        if (!countValue || isMessagesTabActive() || (latestValue > 0 && dismissedValue >= latestValue)) {
1926            if (!countValue) {
1927                clearStoredDismissed();
1928            }
1929            hideToast();
1930            return;
1931        }
1932
1933        if (text) {
1934            text.textContent = buildLabel(countValue);
1935        }
1936
1937        toast.classList.add('pg-unread-toast--show');
1938    };
1939
1940    var markSummaryActive = function () {
1941        summaryLastActivityAt = Date.now();
1942        summaryNoChangeStreak = 0;
1943    };
1944
1945    var parseSummaryPayload = function (response) {
1946        if (!response) {
1947            return null;
1948        }
1949
1950        if (typeof response.success !== 'undefined') {
1951            if (!response.success || !response.data) {
1952                return null;
1953            }
1954
1955            return response.data;
1956        }
1957
1958        return response;
1959    };
1960
1961    var computeSummaryInterval = function (changed) {
1962        var isVisible = document.visibilityState === 'visible';
1963        var idleMs = Date.now() - summaryLastActivityAt;
1964        var interval = 9000;
1965
1966        if (!isVisible) {
1967            interval = 25000;
1968        } else if (isMessagesTabActive()) {
1969            interval = 2500;
1970        } else if (idleMs > 30000) {
1971            interval = 12000;
1972        }
1973
1974        if (!changed) {
1975            interval += Math.min(summaryNoChangeStreak * 2000, 12000);
1976        }
1977
1978        if (summaryErrorStreak > 0) {
1979            interval += Math.min(summaryErrorStreak * 4000, 12000);
1980        }
1981
1982        interval = Math.max(2000, Math.min(interval, 30000));
1983
1984        var jitter = Math.floor(interval * ((Math.random() * 0.2) - 0.1));
1985        return Math.max(1800, interval + jitter);
1986    };
1987
1988    var scheduleSummary = function (delay) {
1989        if (summaryTimer) {
1990            clearTimeout(summaryTimer);
1991        }
1992
1993        summaryTimer = setTimeout(runSummaryPoll, delay);
1994    };
1995
1996    var fetchSummaryAjax = function () {
1997        if (!window.pm_ajax_object || !pm_ajax_object.ajax_url || !pm_ajax_object.nonce) {
1998            return Promise.reject(new Error('ajax_not_available'));
1999        }
2000
2001        var data = new FormData();
2002        data.append('action', 'pm_unread_message_summary');
2003        data.append('nonce', pm_ajax_object.nonce);
2004
2005        return fetch(pm_ajax_object.ajax_url, {
2006            method: 'POST',
2007            credentials: 'same-origin',
2008            body: data
2009        }).then(function (response) {
2010            return response.json();
2011        });
2012    };
2013
2014    var persistToastDismissal = function (latestValue) {
2015        if (!latestValue || !window.pm_ajax_object || !pm_ajax_object.ajax_url || !pm_ajax_object.nonce) {
2016            return;
2017        }
2018
2019        var formData = new FormData();
2020        formData.append('action', 'pm_dismiss_unread_message_toast');
2021        formData.append('nonce', pm_ajax_object.nonce);
2022        formData.append('latest_ts', latestValue);
2023
2024        if (navigator.sendBeacon && typeof URLSearchParams !== 'undefined') {
2025            var beaconData = new URLSearchParams();
2026            beaconData.append('action', 'pm_dismiss_unread_message_toast');
2027            beaconData.append('nonce', pm_ajax_object.nonce);
2028            beaconData.append('latest_ts', latestValue);
2029            navigator.sendBeacon(pm_ajax_object.ajax_url, beaconData);
2030            return;
2031        }
2032
2033        fetch(pm_ajax_object.ajax_url, {
2034            method: 'POST',
2035            credentials: 'same-origin',
2036            body: formData,
2037            keepalive: true
2038        });
2039    };
2040
2041    var runSummaryPoll = function () {
2042        if (summaryInFlight) {
2043            return;
2044        }
2045
2046        summaryInFlight = true;
2047
2048        var request = fetchSummaryAjax();
2049
2050        request.then(function (response) {
2051            var payload = parseSummaryPayload(response);
2052
2053            if (!payload) {
2054                summaryErrorStreak++;
2055                return;
2056            }
2057
2058            var latestValue = parseInt(payload.latest_ts, 10) || 0;
2059            var latestRidValue = parseInt(payload.latest_rid, 10) || 0;
2060            var latestTidValue = parseInt(payload.latest_tid, 10) || 0;
2061            var dismissedValue = parseInt(payload.dismissed, 10) || 0;
2062            var countValue = parseInt(payload.count, 10) || 0;
2063            var previousCountValue = count;
2064            var changed = (latestValue !== latest || latestRidValue !== latestRid || latestTidValue !== latestTid || dism
2064issedValue !== dismissed || countValue !== count);
2065
2066            latest = latestValue;
2067            latestRid = latestRidValue;
2068            latestTid = latestTidValue;
2069            dismissed = dismissedValue;
2070            count = countValue;
2071            target = buildMessageTarget(latestRid);
2072            toast.setAttribute('data-target', target);
2073            toast.setAttribute('data-latest-rid', String(latestRid));
2074            toast.setAttribute('data-latest-tid', String(latestTid));
2075
2076            if (!isMessagesTabActive() && countValue > previousCountValue) {
2077                playUnreadSound();
2078            }
2079
2080            renderToast(countValue, latestValue, dismissedValue);
2081
2082            if (changed) {
2083                markSummaryActive();
2084            } else {
2085                summaryNoChangeStreak++;
2086            }
2087
2088            summaryErrorStreak = 0;
2089        }).catch(function () {
2090            summaryErrorStreak++;
2091        }).then(function () {
2092            summaryInFlight = false;
2093            scheduleSummary(computeSummaryInterval(false));
2094        });
2095    };
2096
2097    if (show) {
2098        renderToast(count, latest, dismissed);
2099    }
2100
2101    if (openBtn && target) {
2102        openBtn.addEventListener('click', function (e) {
2103            e.preventDefault();
2104            acknowledgeLatestUnread();
2105            window.location.href = target;
2106        });
2107    }
2108
2109    if (closeBtn) {
2110        closeBtn.textContent = String.fromCharCode(215);
2111        closeBtn.addEventListener('click', function (e) {
2112            e.preventDefault();
2113            acknowledgeLatestUnread();
2114        });
2115    }
2116
2117    var activateLatestUnreadThread = function () {
2118        if (!latestRid || typeof window.pg_activate_new_thread !== 'function') {
2119            return;
2120        }
2121
2122        var autoOpenKey = String(latest) + ':' + String(latestRid) + ':' + String(latestTid);
2123        if (lastAutoOpenKey === autoOpenKey) {
2124            return;
2125        }
2126
2127        lastAutoOpenKey = autoOpenKey;
2128        setTimeout(function () {
2129            window.pg_activate_new_thread(latestRid);
2130            scheduleSummary(1200);
2131        }, 250);
2132    };
2133
2134    var syncUnreadStateOnMessagesVisit = function () {
2135        if (!count || !latest) {
2136            return;
2137        }
2138
2139        acknowledgeLatestUnread();
2140        activateLatestUnreadThread();
2141    };
2142
2143    document.querySelectorAll('a[href="#pg-messages"]').forEach(function (link) {
2144        link.addEventListener('click', function () {
2145            markSummaryActive();
2146            syncUnreadStateOnMessagesVisit();
2147        });
2148    });
2149    document.addEventListener('visibilitychange', function () {
2150        if (document.visibilityState === 'visible') {
2151            markSummaryActive();
2152            scheduleSummary(1500);
2153        }
2154    });
2155
2156    window.addEventListener('focus', function () {
2157        markSummaryActive();
2158        scheduleSummary(1500);
2159    });
2160
2161    if ((window.location.hash || '').toLowerCase() === '#pg-messages') {
2162        syncUnreadStateOnMessagesVisit();
2163    }
2164
2165    window.pgUnreadToastSync = {
2166        acknowledgeCurrent: acknowledgeLatestUnread,
2167        refreshNow: function () {
2168            markSummaryActive();
2169            scheduleSummary(200);
2170        },
2171        hideWhileMessagesVisible: function () {
2172            if (isMessagesTabActive()) {
2173                hideToast();
2174            }
2175        }
2176    };
2177    scheduleSummary(6000);
2178}
2179
2180jQuery(function() {
2181    jQuery('.pm_linked_in_url, .pm_twitter_url, .pm_youtube_url, .pm_soundcloud_url, .pm_mixcloud_url, .pm_instagram_url, .pm_google_url').each(function(index, element) {
2182        var $wrapper = jQuery(element);
2183        var $input = $wrapper.find('input');
2184
2185        $input.on('blur', function() {
2186            var val = jQuery(this).val().trim();
2187            // Simple URL check: contains at least one dot and no spaces
2188            var urlPattern = /^[^\s]+\.[^\s]+$/; // rough check for URL
2189            if (val && urlPattern.test(val)) {
2190                // Prepend https:// if missing
2191                if (!/^https?:\/\//i.test(val)) {
2192                    jQuery(this).val('https://' + val);
2193                }
2194            }
2195        });
2196    });
2197
2198    pg_init_unread_message_toast();
2199});

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.