PageSourceSearch

https://www.legends953.com/wp-content/plugins/wpb-contest/js/div_based_front.js?contest_ver=1.2.3&ver=7.1

js legends953.com collected 2026-09-26 18:39:27 UTC 44,601 bytes, 1,383 lines download raw bytes

1//WD-1113 + WD-1114
2function enterSurvey(contestId, email, subscriberId, contestType) {
3  var href = location.href;
4  var hasQuery = href.indexOf("?") + 1;
5  var hasHash = href.indexOf("#") + 1;
6  var appendix = (hasQuery ? "&" : "?") + "sg_sy=true";
7  location.href = hasHash ? href.replace("#", appendix + "#") : href + appendix;
8}
9//WPB-2539
10//WPB-3505 - added isFromUpdate
11function makeFileList_ImageGalleryUGC(isFromUpdate = false) {
12      if(isFromUpdate){//WPB-3505
13        var inputClass = document.getElementsByClassName('filesToUploadFromUpdate');
14        if(inputClass != null && inputClass.length > 0 ){
15          var input = inputClass[0];
16        } else {
17          var input = document.getElementById("filesToUpload");
18        }
19      } else {
20        var input = document.getElementById("filesToUpload");
21      }
22
23      var validImage = true;
24      var validExtensions = ['jpg','png','jpeg','tif','bmp','gif']; //array of valid extensions
25
26      for (var i = 0; i < input.files.length; i++) {
27         var fileName = input.files[i].name;
28         var fileNameExt = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase();
29         if (jQuery.inArray(fileNameExt, validExtensions) == -1) {
30            input.type = ''
31            input.type = 'file'
32            alert("Only these file types are accepted : "+validExtensions.join(', '));
33            validImage = false;
34         }
35      }
36
37      if(isFromUpdate){//WPB-3505
38        var ulClass = document.getElementsByClassName('fileListForUpdate');
39        if(ulClass != null && ulClass.length > 0 ){
40          var ul = ulClass[0];
41        } else {
42          var ul = document.getElementById("fileList");
43        }
44      } else {
45        var ul = document.getElementById("fileList");
46      }
47
48      while (ul.hasChildNodes()) {
49        ul.removeChild(ul.firstChild);
50      }
51
52      if (validImage) {
53        //valid then allowed.
54      }
55      else {
56        return false;
57      }
58
59      if (input.files.length > 0) {
60        var li = document.createElement("li");
61        li.style.listStyle = "none";
62        if (typeof (FileReader) != "undefined") {
63          li.innerHTML =  '<table cellpadding="0" cellspacing="0" border="0" width="600"><tr><td width="110">Image File</td><td width="90">Image</td><td width="150">Image Title</td><td width="150">Image Caption</td></tr></table>';
64        }
65        else {
66          //This browser does not support FileReader.
67          li.innerHTML =  '<table cellpadding="0" cellspacing="0" border="0" width="500"><tr><td width="110">Image File</td><td width="150">Image Title</td><td width="150">Image Caption</td></tr></table>'; 
68        }
69        ul.appendChild(li);
70      }
71
72      for (var i = 0; i < input.files.length; i++) {
73        if (typeof (FileReader) != "undefined") {
74            var reader = new FileReader();
75            input.files[i].index=i;
76            // Closure to capture the file information.
77            reader.onload = (function (theFile) {
78              var imageUni = 0;
79              return function (e) {
80                 var li = document.createElement("li");
81                 li.style.listStyle = "none";
82                  var picFile = e.target.result;
83                  li.innerHTML =  '<table cellpadding="0" cellspacing="0" border="0" width="600"><tr><td width="110">'+theFile.name+'</td><td width="90"><img id="image_'+theFile.index+'" src="' + picFile + '" width="50" height="50" /></td><td width="150">&nbsp;<input type="text" class="imageTitle" name="imageTitle['+theFile.index+']" size="15" /></td><td width="150">&nbsp;<input type="text" name="imageCaption['+theFile.index+']" size="15" /><input type="hidden" name="imageTitleHid[]"></td></tr></table>';
84                  ul.appendChild(li);
85                  imageUni++;
86
87              };
88          })(input.files[i]);
89
90          // Read in the image file as a data URL.
91        reader.readAsDataURL(input.files[i]);
92
93        }
94        else {
95          //This browser does not support FileReader.
96          li.innerHTML =  '<table cellpadding="0" cellspacing="0" border="0" width="500"><tr><td width="110">' + input.files[i].name + '</td><td width="150">&nbsp;<input type="text" class="imageTitle" name="imageTitle[]" size="15" /></td><td width="150">&nbsp;<input type="text" name="imageCaption[]" size="15" /><input type="hidden" name="imageTitleHid[]"></td></tr></table>';
97        }
98      }//End of for (var i = 0; i < input.files.length; i++)
99
100      if(!ul.hasChildNodes()) {
101        var li = document.createElement("li");
102        li.innerHTML = 'No Files Selected';
103        ul.appendChild(li);
104      }
105}
106
107function checkCookieForEnter(
108  contest_formId,
109  contestId,
110  isEntrant,
111  hasCustomQuestions,
112  email,
113  subscriberId,
114  isUgc,
115  contestType,
116  isNeedUpdate,
117  subReq
118) {
119  jQuery("#btnEmailSubmit_divMsg").html( '<font color="green">Checking, Please wait.....</font>' );
120  jQuery.ajax({
121    url: ajaxurl,
122    type: "POST",
123    data: {
124      action: "check_user_has_cookie_vipclub",
125      contest_formId: contest_formId,
126      postId: contestId
127    },
128    success: function(response) {
129      var objResult = jQuery.parseJSON(response);
130      if (objResult.isLogined) {
131        subscriberId = objResult.subscriberId;
132        email = objResult.email;
133        isEntrant = objResult.isEntrant;
134        isNeedUpdate = objResult.isNeedUpdate;
135      }
136      enterMeGigya(
137        contestId,
138        isEntrant,
139        hasCustomQuestions,
140        email,
141        subscriberId,
142        isUgc,
143        contestType,
144        isNeedUpdate,
145        subReq
146      );
147    }
148  });
149  jQuery("#btnEmailSubmit_divMsg").html("");
150}
151
152function enterMeGigya(
153  contestId,
154  isEntrant,
155  hasCustomQuestions,
156  email,
157  subscriberId,
158  isUgc,
159  contestType,
160  isNeedUpdate,
161  subReq
162) {
163  if (contestType == "song_survey_2") {
164    if (!subReq) {
165      showSongSurvey2(contestId);
166      return;
167    }
168  }
169  if (isEntrant) {
170    alert("You are already entered into this contest!");
171    return;
172  }
173
174  jQuery("#clicked_enter_me_contest").val("1");
175
176  //WPB-285
177  if (!email) {
178    loginGigyaFromContest();
179    return;
180  } else if (confirm("Please confirm that your email address is " + email)) {
181    fillContestFormFromContest(email);
182    return;
183  } else {
184    return;
185  }
186
187  jQuery("#email_second").val(email);
188  jQuery("#contest_signup_dialog_user_form").hide();
189  //hide registered
190  if (isUgc) {
191    loginGigyaFromContest();
192  } else if (contestType == "ugc_video_youtube") {
193    loginGigyaFromContest();
194  } else if (contestType == "image_gallery_ugc") {
195    loginGigyaFromContest();
196  } else if (hasCustomQuestions) {
197    loginGigyaFromContest();
198  } else if (contestType == "secret_word") {
199    loginGigyaFromContest();
200  } else {
201    jQuery("#contest_signup_dialog_form").submit();
202  }
203}
204
205function fillContestFormFromContest(email) {
206  jQuery(document).ready(function($) {
207    $.ajax({
208      url: ajaxurl,
209      type: "POST",
210      data: {
211        action: "fill_contest_from_user_loggedIn",
212        email: email
213      },
214      success: function(response) {
215        var objResult = jQuery.parseJSON(response);
216        if (!objResult.isLogined) {
217          loginGigyaFromContest();
218        } else {
219          // Call for contest
220          if ($("#contest_div #enter").length) { $("#contest_div").hide(); }
221          if ($("#contest_email_dialog #contest_email").length) { $("#contest_email_dialog #contest_email").val(objResult.subscriber.email); }
222          if ($("#email_second").length) { $("#email_second").val(objResult.subscriber.email); }
223          checkEmail();
224          if ($('input[name="firstname"]').length) { $('input[name="firstname"]').val(objResult.subscriber.firstname); }
225          if ($('input[name="lastname"]').length) { $('input[name="lastname"]').val(objResult.subscriber.lastname); }
226          if ($('input[name="birthday"]').length) { $('input[name="birthday"]').val(objResult.subscriber.birthday); }
227          if ($('input[name="zip"]').length) { $('input[name="zip"]').val(objResult.subscriber.zip); }
228          if ($('input[name="gender"]').length) { $('input[name="gender"]').val(objResult.subscriber.gender); }
229        }
230      }
231    });
232  });
233}
234
235function loginGigyaFromContest() {
236  jQuery(document).ready(function($) {
237    if (hostSiteurl === undefined) {
238      var hostSiteurl = "https://cumulustransactions.com/auth";
239    }
240    $("#clicked_enter_me_contest").val("1");
241    unique_idg = "contest_list";
242    $("#wpbGigyaLoginDiv").attr(
243      "src",
244      hostSiteurl +
245        "?siteID=" +
246        wpbgvlobj.blogID +
247        "&origin=" +
248        wpbgvlobj.siteUrl
249    );
250    $("#wpbGigyaLoginDiv").show();
251    wpbgvl.dialog = $("#showWpbGigyaModel").dialog({
252      autoOpen: true,
253      width: 550
254    });
255    $("[aria-describedby='showWpbGigyaModel']").addClass("wpbglm_model");
256  });
257}
258
259function enterMe(
260  contestId,
261  isEntrant,
262  hasCustomQuestions,
263  email,
264  subscriberId,
265  isUgc,
266  contestType,
267  isNeedUpdate,
268  subReq
269) {
270  if (contestType == "song_survey_2") {
271    if (!subReq) {
272      showSongSurvey2(contestId);
273      return;
274    }
275  }
276  if (isEntrant) {
277    alert("You are already entered into this contest!");
278    return;
279  }
280  //enter contest directly
281  if (
282    !email ||
283    (email && !confirm("Please confirm that your email address is " + email)) ||
284    isNeedUpdate
285  ) {
286    showEmailModal();
287    return;
288  }
289  jQuery("#email_second").val(email);
290  jQuery("#contest_signup_dialog_user_form").hide();
291  //hide registered
292  if (isUgc) {
293    showSignupModal();
294  } else if (contestType == "ugc_video_youtube") {
295    showSignupModal();
296  } else if (contestType == "image_gallery_ugc") { //WPB-2539
297    showSignupModal();
298  } else if (hasCustomQuestions) {
299    showSignupModal();
300  } else if (contestType == "secret_word") {
301    showSignupModal();
302  } else {
303    jQuery("#contest_signup_dialog_form").submit();
304  }
305}
306
307function showEmailModal() {
308  jQuery("#enter").css("display", "none");
309  //WPB-132 -- if want to hide contest shortcode image on click of enter now.
310  jQuery("#contest_email_dialog").show("slide", { direction: "left" }, 200);
311  jQuery("#btnSubmit").css("display", "block");
312}
313function showSignupModal() {
314  jQuery("#contest_email_dialog").hide("slide", { direction: "left" }, 200);
315  jQuery("#contest_signup_dialog").show("slide", { direction: "left" }, 200);
316}
317
318//WPB-3216
319function submitContestWithAjax(formName, uniqueDivId) {
320  console.log("100% contest AJAX >> submitContestWithAjax()");
321var siteId = jQuery('#externalContestSiteId').val();
322var contestFormSubmit = '/wp-content/plugins/wpb-contest/contest_submit_ajax.php';
323  if(jQuery('#externalContestSiteId').length>0)
324    contestFormSubmit = contestFormSubmit +'?siteId='+siteId;
325
326  var formData = new FormData(jQuery("#"+formName)[0]);
327
328  jQuery.ajax({
329    url: contestFormSubmit,
330    type: "POST",
331    data: formData,
332    success: function(response) {
333      response = response.replace("Sorry we could not find your email template.", "");
334      try {
335        var data = jQuery.parseJSON(response);
336        var sitePjax = 0;
337        if (typeof is_PjaxSite_JS === "function") { 
338          sitePjax = is_PjaxSite_JS();
339        }
340
341        try { //WPB-4323
342        var confirm_url_val = data.confirm_url; var thank_msg_val = data.thank_msg;
343          if (confirm_url_val) {
344             //diff url then same contest page.
345          }
346          else {
347             /**
348              * https://itmprojects.atlassian.net/browse/WPB-4564
349              * We need to force redirection for secret word contest as they have different template
350              * for wrong message and success message
351              */
352             if (thank_msg_val && data.redirectTo != null && data.redirectTo.indexOf('check_word_status') == -1) {
353                jQuery("#contest_signup_dialog").hide(); jQuery("#contest_update_dialog").hide();
354                console.log("HERE Only thanks message, NO redirect.........");
355                //same contest page , just display thank you message.
356                jQuery("#"+uniqueDivId+'_msg').html(thank_msg_val);
357                return;
358             }
359          }
360        }
361        catch(e) { }
362
363        var redirectDone = false;
364        try {
365        console.log("HERE Barba pjax.........");
366        Barba.Pjax.goTo(data.redirectTo); //hello-theme-child-master
367        redirectDone = true;
368        }
369        catch(ee) { }
370
371        try {
372          console.log("HERE Other pjax.........");
373          if (sitePjax) { //for other theme if this true then only check this.
374          var $ajaxLoader = $(".global-ajax-loader");
375              $ajaxLoader.fadeIn();
376          $.pjax({url: data.redirectTo , container:'#pjax-wrapper'});
377          redirectDone = true;
378          }//End of if (sitePjax)
379        }catch(ee1){ }
380
381        if (redirectDone) {
382          //if already done redirect above way.
383        }
384        else {
385        console.log("HERE location redirect.........");
386        document.location.href = data.redirectTo;
387        }
388
389        console.log("HERE at end : ajax submit : div_based_front.js .........");
390      } catch (error) {
391        jQuery("#btnSignSubmit_divMsg").html("<font color='#f8d7da'>Something went wrong!</font>");
392       console.log("Something went wrong "+error);
393      }
394      console.log(response);
395    },
396    cache: false,
397    contentType: false,
398    processData: false
399  });
400}//End of function submitContestWithAjax
401
402function submitSignUpform_add() {
403  var sitePjax = 0;
404  if (typeof is_PjaxSite_JS === "function") { 
405    sitePjax = is_PjaxSite_JS();
406  }
407
408  if (!checkSignupForm()) {
409    //also into views.js file for custom questions.
410    //WPB-134
411    try {
412      jQuery("#btnSignSubmit_divMsg").html("");
413    } catch (e) {}
414    return false;
415  } else {
416
417    var contestType = jQuery(
418      "#contest_signup_dialog_form [name=contest_type]"
419    ).val();
420
421    //if no custom fields.
422    if(contestType == "image_gallery_ugc"){
423      if(jQuery('input[name="imageTitleHid[]"]').length==0){
424        alert('Please select at least one image!')
425        return false;
426      }
427    }
428
429    jQuery("#btnSignSubmit_divMsg").html( '<font color="green">Saving, Please wait.....</font>' );
430
431    try { //WPB-4323 -- for ajax based submit need for custom questions.
432
433    for(var i = 0; i < window.cq.objs.length; i ++){
434      var temp = window.cq.objs[i];
435      if(!temp.validate()) {
436        //WPB-134
437        try {
438          jQuery('#btnSignSubmit_divMsg').html('');
439        }
440        catch(e){}
441        return false;
442      }
443    }
444
445    }catch(e123){  } //catch then no custom questions.
446      //stop form submit() method and now pjax or non-pjax both will use ajax only for contest form.
447      submitContestWithAjax('contest_signup_dialog_form','contest_signup_dialog'); //WPB-4323
448    }
449}
450
451function submitSignUpform_update() {
452  var sitePjax = 0;
453  if (typeof is_PjaxSite_JS === "function") { 
454    sitePjax = is_PjaxSite_JS();
455  }
456
457  if (!checkUpdateForm()) {
458    //WPB-134
459    try {
460      jQuery("#btnSignSubmit_divMsg").html("");
461    } catch (e) {}
462    return false;
463  } else {
464
465    var contestType = jQuery(
466      "#contest_update_dialog_form [name=contest_type]"
467    ).val();
468
469    //if no custom fields.
470    if(contestType == "image_gallery_ugc"){
471      if(jQuery('input[name="imageTitleHid[]"]').length==0){
472        alert('Please select at least one image!')
473        return false;
474      }
475    }
476
477    jQuery("#btnSignSubmit_divMsg").html(
478      '<font color="green">Saving, Please wait.....</font>'
479    );
480
481   try { //WPB-4323 -- for ajax based submit need for custom questions.
482
483   for(var i = 0; i < window.cq.objs2.length; i ++){
484      var temp = window.cq.objs2[i];
485      if(!temp.validate()) {
486        //WPB-134
487        try {
488          jQuery('#btnSignSubmit_divMsg').html('');
489        }
490        catch(e){}
491        return false;
492      }
493    }
494
495    }catch(e123){  } //catch then no custom questions.
496
497    //updtae form submit using pjax for both non-pjax, pjax.
498      submitContestWithAjax('contest_update_dialog_form','contest_update_dialog'); //WPB-4323
499  }
500}
501
502function checkSignupForm() {
503  //form validation rules
504  if (
505    jQuery("#contest_signup_dialog_user_form").length > 0 &&
506    jQuery("#contest_signup_dialog_user_form").css("display") != "none"
507  ) {
508    //wpb-315
509    try {
510      //contest_signup_dialog_user_form -- this is div.
511      var $form = jQuery("#contest_signup_dialog_form");
512      var return_gdpr = checkGDPRChkBox(
513        "contest_signup_dialog_form",
514        $form,
515        ""
516      );
517      if (!return_gdpr) {
518        return false;
519      }
520    } catch (e) {}
521
522    //-----------------------------------
523    //First make all message into hide status.
524    var checkArr = [
525      "firstname",
526      "lastname",
527      "birthday",
528      "zip",
529      "cell",
530      "address1",
531      "address2",
532      "city",
533      "state",
534      "country",
535      "facebook",
536      "twitter",
537      "instagram",
538      "pinterest"
539      //"canwetextyou" //WPB-572 -- radio button. so, commented textbox things.
540    ];
541    for (var i = 0; i < checkArr.length; i++) {
542      try {
543        if (
544          jQuery("#contest_signup_dialog_user_form [name=" + checkArr[i] + "]")
545            .length > 0 &&
546          jQuery.trim(
547            jQuery(
548              "#contest_signup_dialog_user_form [name=" + checkArr[i] + "]"
549            ).val()
550          ) != "" &&
551          jQuery(
552            "#contest_signup_dialog_user_form [name=" + checkArr[i] + "]"
553          ).attr("is_required") == 1
554        ) {
555          if (jQuery("#span" + checkArr[i]).length > 0) {
556            jQuery("#span" + checkArr[i]).remove();
557          }
558        }
559      } catch (e) {}
560    } //End of for loop.
561    //-----------------------------------
562
563    if (
564      jQuery.trim(
565        jQuery("#contest_signup_dialog_form [name=firstname]").val()
566      ) == ""
567    ) {
568      if (jQuery("#spanfirstname").length == 0) {
569        jQuery(
570          '<span id="spanfirstname"><font color="red">Please enter first name</font></span>'
571        ).insertAfter("#contest_signup_dialog_form [name=firstname]");
572      } else {
573        jQuery("#spanfirstname").show();
574      }
575      return false;
576    } else {
577      jQuery("#spanfirstname").remove();
578    }
579
580    if (
581      jQuery.trim(
582        jQuery("#contest_signup_dialog_form [name=lastname]").val()
583      ) == ""
584    ) {
585      if (jQuery("#spanlastname").length == 0) {
586        jQuery(
587          '<span id="spanlastname"><font color="red">Please enter last name</font></span>'
588        ).insertAfter("#contest_signup_dialog_form [name=lastname]");
589      } else {
590        jQuery("#spanlastname").show();
591      }
592      return false;
593    } else {
594      jQuery("#spanlastname").remove();
595    }
596
597    // WPB-5798
598    jQuery("#birthday_valid_errormsg").remove();
599    jQuery("#spanbirthday").remove();
600
601   if(typeof (jQuery("#contest_signup_dialog_form [name=birthday]").val())!='undefined'){
602    if (jQuery.trim(jQuery("#contest_signup_dialog_form [name=birthday]").val()) == "") {
603      if (jQuery("#spanbirthday").length == 0) {
604        jQuery(
605          '<span id="spanbirthday"><font color="red">Please enter birthday</font></span>'
606        ).insertAfter("#contest_signup_dialog_form [name=birthday]");
607      } else {
608        jQuery("#spanbirthday").show();
609      }
610      return false;
611    } else {
612      jQuery("#spanbirthday").remove();
613    }
614  }
615   
616    var txtVal = jQuery("#contest_signup_dialog_form [name=birthday]").val();
617    if (txtVal) {
618      if (isDateForContest(txtVal)) {
619        jQuery("#birthday_valid_errormsg").remove();
620      } else {
621        if (jQuery("#birthday_valid_errormsg").length == 0) {
622          jQuery("#birthday_valid_errormsg").remove();
623          jQuery(
624            '<font color="red" id="birthday_valid_errormsg">Please enter valid mm/dd/yyyy date.</font>'
625          ).insertAfter("#contest_signup_dialog_form [name=birthday]");
626          return false;
627        } else {
628          jQuery("#birthday_valid_errormsg").show();
629          return false;
630        }
631      }
632    } else {
633      jQuery("#birthday_valid_errormsg").remove();
634    }
635
636    //----------------------------------------------------
637    // WPB-5798 -- add contest time.
638    var currentDate_new = new Date();
639    let day_chk = String(currentDate_new.getDate()).padStart(2, '0');
640    let month_chk = String(currentDate_new.getMonth()+1).padStart(2,'0');
641    let year_chk = currentDate_new.getFullYear();
642
643    let currentDate_chk = `${month_chk}/${day_chk}/${year_chk}`; //mm/dd/yyyy
644    // WPB-5798 -- vipclub / classes / class-sendpress-data , wpb-contest / classes / class-sendpress-contest-front
645    var birthdayDate = new Date(txtVal);
646    var currentDateTime = new Date(currentDate_chk);
647
648    var ageInYears = currentDateTime.getFullYear() - birthdayDate.getFullYear();
649    var monthDiff = currentDateTime.getMonth() - birthdayDate.getMonth();
650    if (monthDiff < 0 || (monthDiff === 0 && currentDateTime.getDate() < birthdayDate.getDate())) {
651        ageInYears--;
652    }
653    //console.log(ageInYears);
654    if (ageInYears <= 12) {
655        jQuery("#birthday_valid_errormsg").remove();
656        jQuery(
657            '<font color="red" id="birthday_valid_errormsg">Oops! Looks like you\'re not quite old enough to sign up. We only allow users aged 13 and above to provide their information on this website. Hang in there, and we hope to see you back when you\'re a bit older!</font>'
658          ).insertAfter("#contest_signup_dialog_form [name=birthday]");
659        return false;
660    }
661    //----------------------------------------------------
662    var checkArr = [
663      "birthday",
664      "zip",
665      "cell",
666      "address1",
667      "address2",
668      "city",
669      "state",
670      "country",
671      "facebook",
672      "twitter",
673      "instagram",
674      "pinterest"
675      //"canwetextyou" //WPB-572
676    ];
677    for (var i = 0; i < checkArr.length; i++) {
678      try {
679        if (
680          jQuery("#contest_signup_dialog_form [name=" + checkArr[i] + "]")
681            .length > 0 &&
682          jQuery.trim(
683            jQuery(
684              "#contest_signup_dialog_form [name=" + checkArr[i] + "]"
685            ).val()
686          ) == "" &&
687          jQuery("#contest_signup_dialog_form [name=" + checkArr[i] + "]").attr(
688            "is_required"
689          ) == 1
690        ) {
691          if (checkArr[i] == "canwetextyou") {
692            //WPB-572
693            var messageField = checkArr[i];
694            //if you want to custom message, instead of field name.
695            if (messageField == "canwetextyou") {
696              messageField = "can we text you ?";
697            }
698
699            if (jQuery("#span" + checkArr[i]).length == 0) {
700              jQuery(
701                '<span id="span' +
702                  checkArr[i] +
703                  '"><font color="red">Please enter ' +
704                  messageField +
705                  "</font></span>"
706              ).insertAfter(
707                "#contest_signup_dialog_form [name=" + checkArr[i] + "]"
708              );
709            } else {
710              jQuery("#span" + checkArr[i]).show();
711            }
712          } else {
713            if (jQuery("#span" + checkArr[i]).length == 0) {
714              jQuery(
715                '<span id="span' +
716                  checkArr[i] +
717                  '"><font color="red">Please enter ' +
718                  checkArr[i] +
719                  "</font></span>"
720              ).insertAfter(
721                "#contest_signup_dialog_form [name=" + checkArr[i] + "]"
722              );
723            } else {
724              jQuery("#span" + checkArr[i]).show();
725            }
726          }
727          return false;
728        } else {
729          jQuery("#span" + checkArr[i]).remove();
730        }
731      } catch (e) {}
732    } //End of for loop.
733
734    //---------------------------------------------------------------------------------------------
735
736    //check , must add youtube url.
737    if (jQuery("#contest_signup_dialog_form [name=contest_type]")) {
738      contestType = jQuery(
739        "#contest_signup_dialog_form [name=contest_type]"
740      ).val();
741     
742      //new subscriber then check.
743      if(contestType == "image_gallery_ugc"){
744        if(jQuery('input[name="imageTitleHid[]"]').length==0){
745          alert('Please select at least one image!')
746          return false;
747        }
748      }
749      if (contestType == "ugc_video_youtube") {
750        if (
751          jQuery("#contest_signup_dialog_form [name=youtube_id]").length > 0 &&
752          jQuery.trim(
753            jQuery("#contest_signup_dialog_form [name=youtube_id]").val()
754          ) == ""
755        ) {
756          if (jQuery("#spanYoutubeId").length == 0) {
757            jQuery(
758              '<span id="spanYoutubeId"><font color="red">Please enter YouTube video id</font></span>'
759            ).insertAfter("#contest_signup_dialog_form [name=youtube_id]");
760          } else {
761            jQuery("#spanYoutubeId").show();
762          }
763          return false;
764        } else {
765          jQuery("#spanYoutubeId").remove();
766
767          //send ajax request to check valid youtube id. so, users cannot add dummy records.
768          var validYouTubeIdFound = false;
769          var urlVal =
770            SENDPRESS_CONTEST_URL +
771            "contest-validation-ajax.php?validate=youtubeId&youtube_id=" +
772            jQuery.trim(
773              jQuery("#contest_signup_dialog_form [name=youtube_id]").val()
774            );
775          jQuery.ajax({
776            url: urlVal,
777            success: function(data) {
778              eval(data);
779              try {
780                if (retVal["error"] != "0") {
781                  //if error then display message.
782                  alert(retVal["message"]);
783                  return false;
784                } else {
785                  validYouTubeIdFound = true;
786
787                  jQuery("#contest_signup_dialog_form").submit();
788                  return true;
789                }
790              } catch (e) {}
791            } //End of success function.
792          });
793          if (validYouTubeIdFound) {
794            return true;
795          } else {
796            return false;
797          }
798        }
799      } //End of if (contestType == 'ugc_video_youtube')
800    } //End of if($('#contest_signup_dialog_form [name=contest_type]'))
801    //---------------------------------------------------------------------------------------------
802  } else {
803    //if custom fields to contest and for existing subscriber.
804    try {
805      var $form = jQuery("#contest_signup_dialog_form");
806      var return_gdpr = checkGDPRChkBox(
807        "contest_signup_dialog_form",
808        $form,
809        ""
810      );
811      if (!return_gdpr) {
812        return false;
813      }
814    } catch (e) {}
815  }
816
817  if (
818    jQuery("#contest_signup_dialog_form [name=secret_word]").length > 0 &&
819    jQuery.trim(
820      jQuery("#contest_signup_dialog_form [name=secret_word]").val()
821    ) == "" &&
822    jQuery("#contest_signup_dialog_form [name=secret_word]").attr(
823      "is_required"
824    ) == 1
825  ) {
826    if (jQuery("#spanSecretWord").length == 0) {
827      jQuery(
828        '<span id="spanSecretWord"><font color="red">Please enter secret_word</font></span>'
829      ).insertAfter("#contest_signup_dialog_form [name=secret_word]");
830    } else {
831      jQuery("#spanSecretWord").show();
832    }
833    return false;
834  } else {
835    jQuery("#spanSecretWord").remove();
836  }
837
838  return true;
839}
840
841function showUpdateModal() {
842  jQuery("#contest_update_dialog").show("slide", { direction: "left" }, 200);
843  if (!checkUpdateForm()) {
844    return;
845  }
846}
847
848function isDateForContest(txtDate) {
849  var currVal = txtDate;
850  if (currVal == "") return false;
851
852  //Declare Regex
853  var rxDatePattern = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
854  var dtArray = currVal.match(rxDatePattern); // is format OK?
855
856  if (dtArray == null) return false;
857
858  //Checks for mm/dd/yyyy format.
859  dtMonth = dtArray[1];
860  dtDay = dtArray[3];
861  dtYear = dtArray[5];
862
863  //for dd/mm/yyyy
864
865  if (dtMonth < 1 || dtMonth > 12) return false;
866  else if (dtDay < 1 || dtDay > 31) return false;
867  else if (
868    (dtMonth == 4 || dtMonth == 6 || dtMonth == 9 || dtMonth == 11) &&
869    dtDay == 31
870  )
871    return false;
872  else if (dtMonth == 2) {
873    var isleap = dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0);
874    if (dtDay > 29 || (dtDay == 29 && !isleap)) return false;
875  }
876  return true;
877}
878
879function checkUpdateForm() {
880  if (
881    jQuery("#contest_update_dialog_user_form").length > 0 &&
882    jQuery("#contest_update_dialog_user_form").css("display") != "none"
883  ) {
884    //-----------------------------------
885    //First make all message into hide status.
886    var checkArr = [
887      "firstname",
888      "lastname",
889      "birthday",
890      "zip",
891      "cell",
892      "address1",
893      "address2",
894      "city",
895      "state",
896      "country",
897      "facebook",
898      "twitter",
899      "instagram",
900      "pinterest"
901      //"canwetextyou" //WPB-572 -- radio button. so, commented textbox things.
902    ];
903    for (var i = 0; i < checkArr.length; i++) {
904      try {
905        if (
906          jQuery("#contest_update_dialog_user_form [name=" + checkArr[i] + "]")
907            .length > 0 &&
908          jQuery.trim(
909            jQuery(
910              "#contest_update_dialog_user_form [name=" + checkArr[i] + "]"
911            ).val()
912          ) != "" &&
913          jQuery(
914            "#contest_update_dialog_user_form [name=" + checkArr[i] + "]"
915          ).attr("is_required") == 1
916        ) {
917          jQuery("#span" + checkArr[i]).remove();
918        }
919      } catch (e) {}
920    } //End of for loop.
921    //-----------------------------------
922
923    var txtVal = jQuery(
924      "#contest_update_dialog_user_form [name=birthday]"
925    ).val();
926    if (txtVal) {
927      if (isDateForContest(txtVal)) {
928        jQuery("#birthday_valid_errormsg").remove();
929      } else {
930        if (jQuery("#birthday_valid_errormsg").length == 0) {
931          jQuery("#birthday_valid_errormsg").remove();
932          jQuery(
933            '<font color="red" id="birthday_valid_errormsg">Please enter valid mm/dd/yyyy date.</font>'
934          ).insertAfter("#contest_update_dialog_user_form [name=birthday]");
935          return false;
936        } else {
937          jQuery("#birthday_valid_errormsg").show();
938          return false;
939        }
940      }
941    } else {
942      jQuery("#birthday_valid_errormsg").remove();
943    }
944
945    //----------------------------------------------------
946    // WPB-5798 -- for update time.
947    var currentDate_new = new Date();
948    let day_chk = String(currentDate_new.getDate()).padStart(2, '0');
949    let month_chk = String(currentDate_new.getMonth()+1).padStart(2,'0');
950    let year_chk = currentDate_new.getFullYear();
951
952    let currentDate_chk = `${month_chk}/${day_chk}/${year_chk}`; //mm/dd/yyyy
953    // WPB-5798 -- vipclub / classes / class-sendpress-data , wpb-contest / classes / class-sendpress-contest-front
954    var birthdayDate = new Date(txtVal);
955    var currentDateTime = new Date(currentDate_chk);
956
957    var ageInYears = currentDateTime.getFullYear() - birthdayDate.getFullYear();
958    var monthDiff = currentDateTime.getMonth() - birthdayDate.getMonth();
959    if (monthDiff < 0 || (monthDiff === 0 && currentDateTime.getDate() < birthdayDate.getDate())) {
960        ageInYears--;
961    }
962    //console.log(ageInYears);
963    if (ageInYears <= 12) {
964        jQuery("#birthday_valid_errormsg").remove();
965        jQuery(
966            '<font color="red" id="birthday_valid_errormsg">Oops! Looks like you\'re not quite old enough to sign up. We only allow users aged 13 and above to provide their information on this website. Hang in there, and we hope to see you back when you\'re a bit older!</font>'
967          ).insertAfter("#contest_update_dialog_user_form [name=birthday]");
968        // update dialog.......
969        return false;
970    }
971    //----------------------------------------------------
972
973    var checkArr = [
974      "birthday",
975      "zip",
976      "cell",
977      "address1",
978      "address2",
979      "city",
980      "state",
981      "country",
982      "facebook",
983      "twitter",
984      "instagram",
985      "pinterest"
986      //"canwetextyou" //WPB-572
987    ];
988    for (var i = 0; i < checkArr.length; i++) {
989      try {
990        if (
991          jQuery("#contest_update_dialog_user_form [name=" + checkArr[i] + "]")
992            .length > 0 &&
993          jQuery.trim(
994            jQuery(
995              "#contest_update_dialog_user_form [name=" + checkArr[i] + "]"
996            ).val()
997          ) == "" &&
998          jQuery(
999            "#contest_update_dialog_user_form [name=" + checkArr[i] + "]"
1000          ).attr("is_required") == 1
1001        ) {
1002          if (checkArr[i] == "canwetextyou") {
1003            //WPB-572
1004            var messageField = checkArr[i];
1005            //if you want to custom message, instead of field name.
1006            if (messageField == "canwetextyou") {
1007              messageField = "can we text you ?";
1008            }
1009
1010            if (jQuery("#span" + checkArr[i]).length == 0) {
1011              jQuery(
1012                '<span id="span' +
1013                  checkArr[i] +
1014                  '"><font color="red">Please enter ' +
1015                  messageField +
1016                  "</font></span>"
1017              ).insertAfter(
1018                "#contest_update_dialog_user_form [name=" + checkArr[i] + "]"
1019              );
1020            } else {
1021              jQuery("#span" + checkArr[i]).show();
1022            }
1023          } else {
1024            if (jQuery("#span" + checkArr[i]).length == 0) {
1025              jQuery(
1026                '<span id="span' +
1027                  checkArr[i] +
1028                  '"><font color="red">Please enter ' +
1029                  checkArr[i] +
1030                  "</font></span>"
1031              ).insertAfter(
1032                "#contest_update_dialog_user_form [name=" + checkArr[i] + "]"
1033              );
1034            } else {
1035              jQuery("#span" + checkArr[i]).show();
1036            }
1037          }
1038          return false;
1039        } else {
1040          jQuery("#span" + checkArr[i]).remove();
1041        }
1042      } catch (e) {}
1043    } //End of for loop.
1044
1045    if (
1046      jQuery("#contest_update_dialog_form [name=secret_word]").length > 0 &&
1047      jQuery.trim(
1048        jQuery("#contest_update_dialog_form [name=secret_word]").val()
1049      ) == "" &&
1050      jQuery("#contest_update_dialog_form [name=secret_word]").attr(
1051        "is_required"
1052      ) == 1
1053    ) {
1054      if (jQuery("#spanSecretWord").length == 0) {
1055        jQuery(
1056          '<span id="spanSecretWord"><font color="red">Please enter secret_word</font></span>'
1057        ).insertAfter("#contest_update_dialog_form [name=secret_word]");
1058      } else {
1059        jQuery("#spanSecretWord").show();
1060      }
1061      return false;
1062    } else {
1063      jQuery("#spanSecretWord").remove();
1064    }
1065    //---------------------------------------------------------------------------------------------
1066    //check , must add youtube url.
1067    if (jQuery("#contest_update_dialog_form [name=contest_type]")) {
1068      contestType = jQuery(
1069        "#contest_update_dialog_form [name=contest_type]"
1070      ).val();
1071
1072      //Existing subscriber then also check.
1073      if(contestType == "image_gallery_ugc"){
1074        if(jQuery('input[name="imageTitleHid[]"]').length==0){
1075          alert('Please select at least one image!')
1076          return false;
1077        }
1078      }
1079
1080      if (contestType == "ugc_video_youtube") {
1081        if (
1082          jQuery("#contest_update_dialog_form [name=youtube_id]").length > 0 &&
1083          jQuery.trim(
1084            jQuery("#contest_update_dialog_form [name=youtube_id]").val()
1085          ) == ""
1086        ) {
1087          if (jQuery("#spanYoutubeId").length == 0) {
1088            jQuery(
1089              '<span id="spanYoutubeId"><font color="red">Please enter YouTube video id</font></span>'
1090            ).insertAfter("#contest_update_dialog_form [name=youtube_id]");
1091          } else {
1092            jQuery("#spanYoutubeId").show();
1093          }
1094          return false;
1095        } else {
1096          jQuery("#spanYoutubeId").remove();
1097
1098          //send ajax request to check valid youtube id. so, users cannot add dummy records.
1099          var validYouTubeIdFound = false;
1100          var urlVal =
1101            SENDPRESS_CONTEST_URL +
1102            "contest-validation-ajax.php?validate=youtubeId&youtube_id=" +
1103            jQuery.trim(
1104              jQuery("#contest_update_dialog_form [name=youtube_id]").val()
1105            );
1106
1107          jQuery.ajax({
1108            url: urlVal,
1109            success: function(data) {
1110              eval(data);
1111              try {
1112                if (retVal["error"] != "0") {
1113                  //if error then display message.
1114                  alert(retVal["message"]);
1115                  return false;
1116                } else {
1117                  validYouTubeIdFound = true;
1118                  jQuery("#contest_update_dialog_form").submit();
1119                  return true;
1120                }
1121              } catch (e) {}
1122            } //End of success function.
1123          });
1124
1125          if (validYouTubeIdFound) {
1126            return true;
1127          } else {
1128            return false;
1129          }
1130        }
1131      } //End of if (contestType == 'ugc_video_youtube')
1132    } //End of if($('#contest_update_dialog_user_form [name=contest_type]'))
1133    //---------------------------------------------------------------------------------------------
1134  }
1135
1136  return true;
1137}
1138
1139function isValidEmailForContest(email) {
1140  var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
1141  if (!re.test(email)) {
1142    return false;
1143  }
1144  return true;
1145}
1146
1147function checkEmail() {
1148  var email = jQuery("#contest_email_dialog #contest_email").val();
1149  if (jQuery("#validEmailSpan")) {
1150    jQuery("#validEmailSpan").remove();
1151  }
1152  if (!isValidEmailForContest(email)) {
1153    jQuery(
1154      '<span id="validEmailSpan"><font color="red">Please enter a valid email address!</font></span>'
1155    ).insertAfter("#contest_email_dialog #contest_email");
1156    return false;
1157  } else {
1158    jQuery("#validEmailSpan").remove();
1159  }
1160
1161  if (jQuery("#contest_email_dialog  #siteId").val() != "") {
1162    var siteId = jQuery("#contest_email_dialog  #siteId").val();
1163  } else {
1164    var siteId = 0;
1165  }
1166
1167  jQuery("#btnEmailSubmit_divMsg").html(
1168    '<font color="green">Checking, Please wait.....</font>'
1169  );
1170
1171  var request_ajax_url = "";
1172  try {
1173    if (wpcontest_vars) {
1174      request_ajax_url = wpcontest_vars.ajaxurl;
1175    } else {
1176      request_ajax_url = ajaxurl;
1177    }
1178  } catch (e) {
1179    request_ajax_url = ajaxurl;
1180  }
1181
1182  jQuery.post(
1183    request_ajax_url,
1184    {
1185      email: email,
1186      action: "sendpress-contest-check-email",
1187      contestId: jQuery("#contest_email_dialog  #contest_id").val(),
1188      contest_type: jQuery("#contest_type").val(),
1189      contest_formId: jQuery("#contest_email_dialog  #contest_formId").val(),
1190      siteId: siteId
1191    },
1192    function(response) {
1193      //Start WPB-2556
1194      var response = response.replace(
1195        "Sorry we could not find your email template.",
1196        ""
1197      );
1198      // End WPB-2556
1199      response = JSON.parse(response);
1200      //WD-1114
1201      try {
1202        var surveydata = response.surveydata;
1203      } catch (e) {
1204        var surveydata = "";
1205      }
1206      var loc = document.location.href;
1207      var locArr = loc.split("?");
1208      loc = locArr[0];
1209      if (response.status == 1) {
1210        //You have entered this contest
1211        if (
1212          jQuery("#contest_type").val() == "song_survey" ||
1213          jQuery("#contest_type").val() == "song_survey_2"
1214        ) {
1215          //WD-1114
1216          document.location.href =
1217            loc + "?surveydata=" + surveydata + "&surveyPage=true&tmpChk=1"; // if already exist then also redirect to new page
1218        } else {
1219          //WPB-134 + WPB-443
1220          try {
1221            jQuery("#btnEmailSubmit_divMsg").html(""); //on email box clear message.
1222          } catch (e) {}
1223          alert(response.code);
1224        }
1225      } else if (response.status == 2) {
1226        //Normal entring
1227        jQuery("#email_second").val(
1228          jQuery("#contest_email_dialog #contest_email").val()
1229        );
1230        jQuery("#contest_signup_dialog_user_form").show();
1231        showSignupModal();
1232      } else if (response.status == 3) {
1233        //Let him fill all of ugc fields
1234        jQuery("#email_second").val(
1235          jQuery("#contest_email_dialog #contest_email").val()
1236        );
1237        jQuery("#contest_signup_dialog_user_form").hide();
1238        showSignupModal();
1239      } else if (response.status == 4) {
1240        //Let him in directly, if not ugc
1241        if (jQuery("#contest_type").val() == "song_survey") {
1242          //WD-1114
1243          document.location.href =
1244            loc + "?surveydata=" + surveydata + "&surveyPage=true&tmpChk=4";
1245        } else {
1246          document.location.href = response.code;
1247        }
1248      } else if (response.status == 5) {
1249        //existing subscriber.
1250        jQuery("#email_third").val(
1251          jQuery("#contest_email_dialog #contest_email").val()
1252        );
1253        jQuery("#contest_email_dialog").hide(
1254          "slide",
1255          { direction: "left" },
1256          200
1257        );
1258        var append_content = ""; var required_mark = "";
1259        //WD-1756
1260        var field_label_js_array = new Array();
1261
1262        jQuery.each(response.code, function(idx, item) {
1263          if (idx == "field_label_array") {
1264            field_label_js_array = item;
1265          }
1266        });
1267
1268        jQuery.each(response.code, function(idx, item) {
1269          if (idx == "field_label_array") {
1270            //donot check lable field array set for vipclub forms.
1271          } else {
1272            //---------------------------------------------
1273            if (!isNaN(idx)) {
1274              required_mark = '<span style="color:red;">*</span>';
1275
1276              var item_label = "";
1277              if (field_label_js_array) {
1278                item_label = field_label_js_array[item];
1279              }
1280
1281              if (item == "address_1") {
1282                item = "address1";
1283              } else if (item == "address_2") {
1284                item = "address2";
1285              }
1286              if (item_label)
1287                append_content +=
1288                  "<p>" +
1289                  required_mark +
1290                  item_label +
1291                  '</p><input type="text" name="' +
1292                  item +
1293                  '" class="sp_' +
1294                  item +
1295                  '" is_required="1" />';
1296              else
1297                append_content +=
1298                  "<p>" +
1299                  required_mark +
1300                  wpbc.ucFirstForContestLabel(item) +
1301                  '</p><input type="text" name="' +
1302                  item +
1303                  '" class="sp_' +
1304                  item +
1305                  '" is_required="1" />';
1306            } else {
1307              append_content +=
1308                '<input type="hidden" name="subscriber_id" value="' +
1309                item +
1310                '" />';
1311            }
1312            //---------------------------------------------
1313          }
1314        });
1315        jQuery("#contest_update_dialog_user_form").html(append_content);
1316        showUpdateModal();
1317      }
1318
1319      //WPB-134
1320      try {
1321        jQuery("#btnSignSubmit_divMsg").html("");
1322      } catch (e) {}
1323    }
1324  );
1325}
1326
1327function ucFirstForContestLabel(labelField) {
1328  if (labelField == "address1") {
1329    labelField = "Address Line 1";
1330  } else if (labelField == "address2") {
1331    labelField = "Address Line 2";
1332  }
1333  return labelField.charAt(0).toUpperCase() + labelField.slice(1);
1334}
1335
1336function showSongSurvey2(contestId) {
1337  jQuery.post(
1338    ajaxurl,
1339    {
1340      action: "get_song_survey_2_data",
1341      contestId: contestId
1342    },
1343    function(response) {
1344      response = JSON.parse(response);
1345      try {
1346        var surveydata = response.surveydata;
1347      } catch (e) {
1348        var surveydata = "";
1349      }
1350      if (response.status == 1) {
1351        var loc = document.location.href;
1352        var locArr = loc.split("?");
1353        loc = locArr[0];
1354        document.location.href =
1355          loc + "?surveydata=" + surveydata + "&surveyPage=true&tmpChk=1";
1356      }
1357    }
1358  );
1359}
1360
1361function recaptchaCallback() {
1362  jQuery("#btnSignSubmit").prop("disabled", false);
1363}
1364
1365function recaptchaCallbackUpdate() {
1366  jQuery("#btnSignSubmitUpdate").prop("disabled", false);
1367}
1368
1369function submitDisable(){
1370  jQuery("#btnSignSubmit").prop("disabled", true);
1371  jQuery("#btnSignSubmitUpdate").prop("disabled", true);
1372}
1373
1374if (typeof readyFn_recaptcha === "undefined") {
1375  function readyFn_recaptcha(){
1376    jQuery.getScript("https://www.google.com/recaptcha/api.js");  
1377    jQuery(".g-recaptcha").each(function () {
1378        grecaptcha.render(this, {
1379            'sitekey': jQuery( this ).attr( 'data-sitekey' ),
1380        });
1381    });
1382  } 
1383}

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.