// //External Script // //CID if (typeof getQueryStringParamValueIF('cid') != 'undefined' && getQueryStringParamValueIF('cid') != '') { jQuery('[name="cid"]').val(getQueryStringParamValueIF('cid')).change(); var cid = getQueryStringParamValueIF('cid'); } //Webinar Registration if (typeof webinar_registration != 'undefined' && webinar_registration != '') { webinar_registration = false; } window.jQuery = window.jQuery || (() => ({ // these are all methods required by HubSpot change: () => {}, trigger: () => {}, })); (function ($) { //ThankYouButton if (thankyoubutton == true) { var dlbutton = '
'+thankyouButtonText +'
'; } else {var dlbutton = '';} if (thankyouInline == true) { var tyinlinemsg = '

Thank You for Your Submission

'+thankyouInlineMessage+'

'+dlbutton+'
'; } else { var tyinlinemsg = '
' } hbspt.forms.create({ portalId: hsPortalId, formId: hsformId, sfdcCampaignId: cid, css: "", inlineMessage: tyinlinemsg, onFormReady: function($form) { $('[name="lead_source_most_recent"]').val(lead_source).change(); $('[name="lead_source_detail_most_recent"]').val(lead_source_detail).change(); $('[name="lead_source_other_most_recent"]').val(lead_source_other).change(); $('[name="nurture_track"]').val(nurture_track).change(); $('[name="role"]').val(role).change(); $('[name="dm_products"]').val(dm_products).change(); $('[name="cid"]').val(cid).change(); $('[name="eid"]').val(emailID).change(); //Add GDPR To Display Fields Array $(".legal-consent-container").appendTo('.hs_submit'); $(".legal-consent-container .hs-richtext p").unwrap(); //DM Role Hide $form.find("[name='role'] option[value='Marketing']").hide(); $form.find("[name='role'] option[value='Internal Communications']").hide(); //Display Fields Hide $form.find('.hs-input').closest(".field").hide(); $.each( display_fields, function( i, val ) { $form.find('.hs-input[name='+val+']').closest(".field").addClass('display_field'); }); console.log(display_fields); console.log(required_fields); // Remove Hubspot Default form Submit Action to use jQuery validation $form.find("input[type=submit]").on("click", function(e) { e.preventDefault(); $form.submit(); $form.find('.error').appendTo("hs-form-required"); //OnSubmit Functions if ( !$('input').hasClass('error')) { //Webinar Registration if (webinar_registration = true){ $.ajax({ type: 'post', url: "https://onlinexperiences.com/LASParameterReorder.asp", data: { 'FirstName': $("[name='firstname']").val(), 'LastName': $("[name='lastname']").val(), 'CompanyName': $("[name='company']").val(), 'JobTitle': $("[name='jobtitle']").val(), 'EMailAddress': $("[name='email']").val(), 'LASCmd': 'AI:4;F:APIUTILS!50500', 'OpCodeList': 'Cr', 'TriggerRegistrationEvents': '1', 'UBMLCPWD': '1', 'GDPRAccept': '1', 'APIUserCredentials': apiusercredentials, 'APIUserAuthCode': apiuserauthcode, 'ShowKey': showkey, 'ShowPackageKey': showpackagekey, 'CompanyKey': companykey, }, success: function (data) { console.log('Submission was successful.'); console.log(data); }, });    } } }); //Free Emails Disallow Function $.validator.addMethod('nofreeemail', function (value) { return /^([\w-.]+@(?!icloud\.com)(?!protonmail\.ch)(?!protonmail\.com)(?!aol\.com)(?!outlook\.com)(?!gmail\.com)(?!gmail\.de)(?!yahoo\.com)(?!live\.com)(?!hotmail\.com)(?!mail\.ru)(?!yandex\.ru)(?!mail\.com)([\w-]+.)+[\w-]{2,4})?$/.test(value); }, 'Free email addresses not allowed.'); $.validator.messages.required = 'Required'; // Form Validation of Required Fields $form.validate({ rules: { email: { nofreeemail :exclude_free_emails ==true } }, messages: { email: { nofreeemail: "Please use a corporate email address." } } }); $.fn.required = function() { $.each( required_fields, function( i, val ) { $form.find('.hs-input[name='+val+']').rules("add", { required: true }); }); } $.fn.required(); //Placeholder Text if (placeholder_text === undefined || placeholder_text ==false ) { $.fn.placeholder = function() { var placeholder_text = false; //Required Caret $.each( required_fields, function( i, val ) { $form.find('.hs-input[name='+val+']').closest(".field").find("label").append('*'); }); } } else if (placeholder_text == true) { $.fn.placeholder = function() { $form.find(":input").not('input[type=checkbox], input[type=radio]').each(function(index, elem) { var eId = $form.find(elem).attr("id"); var label = null; if (eId && (label = $(elem).parents($form).find("label[for=" + eId + "] span")).length == 1) { $form.find('.hs-form-required').remove(); $form.find(elem).attr("placeholder", $form.find(label).html()); $form.find(label).not(".checkbox-aligned").remove(); } }); //Required Caret $.each( required_fields, function( i, val ) { $form.find('.hs-input[name='+val+']').closest(".field").prepend('*'); }); } } $.fn.placeholder(); //Layout Sort Functions if (layout == 1) { $form.find('input[type=submit]').css('width','100%'); } //Layout 2 Sort $.fn.layout2Sort = function() { n = 0; $form.find(".display_field").addClass("line").removeClass("fullwidthrow row-odd row-even").removeAttr('row'); $form.find(":input").each(function() { if ($(this).is("textarea") || $(this).is(":submit") || $(this).is(":checkbox") || $(this).is(":radio")) { $(this).closest('.display_field').addClass('fullwidthrow').css("width", "100%").removeClass('line'); } }); $form.find(".line").each(function() { if ($(this).prev('div').hasClass('fullwidthrow')) { n = 0 } $(this).closest('.display_field').attr('row', n); n++; if (n == 2) { n = 0 } }); //Placeholder Cleanup $form.find(".line").each(function() { if (($(this).attr('row') == 0 && $(this).next().hasClass('hs_submit')) || ($(this).attr('row') == 0 && $(this).next('.hs-form-field').hasClass('fullwidthrow')) || ($(this).attr('row') == 0 && $(this).next('noscript').length)) { $(this).closest('.display_field').addClass('fullwidthrow').removeClass('line').removeAttr('row'); } }); $form.find('.line[ row=' + 0 + ']').addClass('row-odd'); $form.find('.line[ row=' + 1 + ']').addClass('row-even'); } //Conditional Fields $form.find('.hs-dependent-field .hs-input').change(function() { if (layout == 2) { setTimeout(() => { $form.find('.hs-dependent-field .field').addClass('display_field'); if ($("[name='state']").length) { $.fn.statefilter(); } $.fn.layout2Sort(); $.fn.placeholder(); if (placeholder_text == 'true') { $('.hs-dependent-field div label').hide(); } },); } if (layout == 1) { setTimeout(() => { $('.hs-form input[type=submit]').css('width','100%'); if ($("[name='state']").length) { $.fn.statefilter(); } $.fn.placeholder(); if (placeholder_text == 'true') { $('.hs-dependent-field div label').hide(); } },); } }); //Submit Button Function $.fn.submitbutton = function() { setInterval(function(){ $(".hs-form input[type=submit]").val(submit_text ); },); } $.fn.submitbutton(); //Progressive Sort $.fn.progressiveSort = function() { $form.find(".hs-subscribe").nextAll('.smart-field').addClass('progressive'); $form.find(".progressive").insertBefore('.hs-subscribe'); } $form.find(".hs-subscribe").nextAll('.smart-field').addClass('progressive'); $form.find(".progressive").insertBefore('.hs-subscribe'); //Display Fields Fade In $form.fadeIn(400); $.each( display_fields, function( i, val ) { $form.find('.hs-input[name='+val+']').closest(".field").fadeIn(400); }); $form.find('.field').each(function(){ if ( $(this).css('display') == 'none') { $(this).removeClass('field hs-form-field').appendTo('form'); } }); //Sort Functions //STATE SORT FUNCTIONS // //Page Load If Country Present if ($form.find(".display_field [name='country']").length) { //Page Load State Field Country Logic if ($form.find(".display_field [name='state']").length) { var provinceArray = ["Alberta","Manitoba","British Columbia","New Brunswick","Newfoundland and Labrador","Nova Scotia","Northwest Territories","Nunavut","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon Territory"]; var optionValue = $("[name='state']").val(); //State Filter Function $.fn.statefilter = function() { $form.find("[name='state']").children('option').show(); $form.find('[name="state"] option').filter(function() { if ("US" == $form.find("[name='country'] option:selected").val()) { return $.inArray($.trim($(this).val()), provinceArray) !== -1; } else if ("CA" == $form.find("[name='country'] option:selected").val()) { return $.inArray($.trim($(this).val()), provinceArray) == -1; } }).hide(); } $.fn.stateShow = function() { $form.find("[name='state']").closest('.state_placeholder').addClass("display_field").removeClass('state_placeholder').removeAttr('row'); $form.find("[name='state'] option[value=None]").hide(); } $.fn.stateHide = function() { $form.find("[name='state']").closest('.display_field').removeClass("display_field row-odd row-even line").addClass('state_placeholder').removeAttr('row'); } // $form.find("[name='state']").change(function() { if ($.inArray($("[name='state']").val(), provinceArray) !== -1) { $form.find("[name='country']").val("CA"); } else { $form.find("[name='country']").val("US"); } }); 'use strict'; // //START OF COUNTRY/STATE FUNCTIONS // //Page Load If US/CA Field Merge if ("US" == $form.find("[name='country'] option:selected").val() || "CA" == $form.find("[name='country'] option:selected").val()) { $.fn.statefilter(); $form.find("[name='state']").prop("selectedIndex", 0); $form.find("[name='state']").val(""); $form.find("[name='state']").parents(":eq(1)").show(); if (layout == 1) { $form.find("[name='state']").closest(".state_placeholder").removeClass("state_placeholder"); } else if (layout == 2) { $.fn.stateShow(); $.fn.layout2Sort(); } } //Page Load No Country Field Merge Value else { $form.find("[name='state']").val("None"); $form.find("[name='state']").parents(":eq(1)").hide(); if (layout == 1) { $form.find("[name='stateProv']").closest(".display_field").addClass("state_placeholder"); } else if (layout == 2) { $.fn.stateHide(); $.fn.layout2Sort(); } } } //Page Load No State else { if (layout == 2) { $.fn.layout2Sort(); } } //Page Load IP Lookup $.get("https://extreme-ip-lookup.com/json/", function(e) { console.log(e.status) if (e.status == 'success') { $form.find("[name='country']").val(e.countryCode); if ($form.find(".display_field [name='state']").length || $form.find(".state_placeholder").length) { $.fn.statefilter(); if ("US" == $form.find("[name='country'] option:selected").val() || "CA" == $form.find("[name='country'] option:selected").val()) { $form.find("[name='state']").prop("selectedIndex", 0); $form.find("[name='state']").val(""); $form.find("[name='state']").parents(":eq(1)").show(); if (layout == 1) { $form.find("[name='state']").closest(".state_placeholder").removeClass("state_placeholder"); } else if (layout == 2) { $.fn.stateShow(); $.fn.layout2Sort(); } } else { $form.find("[name='state']").val("None"); $form.find("[name='state']").parents(":eq(1)").hide(); if (layout == 1) { $form.find("[name='state']").closest(".display_field").addClass("state_placeholder"); } else if (layout == 2) { $.fn.stateHide(); $.fn.layout2Sort(); } } } } }); } //Page Load No Country Field else { if (layout == 2) { $.fn.layout2Sort(); } } //Change Function Country if ($form.find(".display_field [name='state']").length || $form.find(".state_placeholder").length) { $form.find("[name='country']").change(function() { $.fn.statefilter(); if ("US" == $form.find("[name='country'] option:selected").val() || "CA" == $form.find("[name='country'] option:selected").val()) { $form.find("[name='state']").prop("selectedIndex", 0); $form.find("[name='state']").val(""); $form.find("[name='state']").parents(":eq(1)").show(); if (layout == 1) { $form.find("[name='state']").closest(".state_placeholder").removeClass("state_placeholder"); } else if (layout == 2) { $.fn.stateShow(); $.fn.layout2Sort(); } } else { $form.find("[name='state']").val("None"); $form.find("[name='state']").parents(":eq(1)").hide(); if (layout == 1) { $form.find("[name='state']").closest(".display_field").addClass("state_placeholder"); } else if (layout == 2) { $.fn.stateHide(); $.fn.layout2Sort(); } } }); } //Add Google Event on Form Submit var GAeventLabel = title + ' Form Submission'; var id_lookupTable = { 'b41a1795-396a-424a-8b16-a68f287bb265': 'NF Main', '8a2db07f-850b-4c7d-b82d-1e6338e41460': 'NF Resource', '382dae8d-48ce-4904-9dbe-331a323b35b0': 'NF Webinar Registration', }; window.addEventListener("message", function(event) { if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') { console.log('submitted'); dataLayer.push({ 'event': 'form-submission', 'formName': id_lookupTable[event.data.id], 'eventLabel': GAeventLabel }); } }); //Title Case and URL function titleCase(t) { for (var e = t.toLowerCase().split(" "), r = 0; r < e.length; r++) e[r] = e[r].charAt(0).toUpperCase() + e[r].substring(1); return e.join(" ") } if (typeof url != 'undefined' && url != '') { var parts = url.split("/"), last_part = parts[parts.length - 2], last_part = last_part.replace(/[^\w\s]/gi, ' '), last_part = titleCase(last_part); } else { url = window.location.host+window.location.pathname; } //Intrado.com UTM $form.find('[name="utm_content"]').val(decodeURI(getQueryStringParamValueIF('utm_content'))); $form.find('[name="utm_source"]').val(decodeURI(getQueryStringParamValueIF('utm_source'))); $form.find('[name="utm_medium"]').val(decodeURI(getQueryStringParamValueIF('utm_medium'))); $form.find('[name="utm_campaign"]').val(decodeURI(getQueryStringParamValueIF('utm_campaign'))); $form.find('[name="utm_term"]').val(decodeURI(getQueryStringParamValueIF('utm_term'))); $form.find('[name="url"]').val(url); $form.find('[name="referral"]').val(getQueryStringParamValueIF('referral')); if (typeof getQueryStringParamValueIF('source_main') != 'undefined' && getQueryStringParamValueIF('source_main') != '') { $form.find('[name="lead_source_most_recent__c"]').val(decodeURI(getQueryStringParamValueIF('source_main'))).change(); } if (typeof getQueryStringParamValueIF('source_detail') != 'undefined' && getQueryStringParamValueIF('source_detail') != '') { $form.find('[name="lead_source_detail_most_recent"]').val(decodeURI(getQueryStringParamValueIF('source_detail'))).change(); } if (typeof getQueryStringParamValueIF('source_other') != 'undefined' && getQueryStringParamValueIF('source_other') != '') { $form.find('[name="lead_source_other_most_recent"]').val(decodeURI(getQueryStringParamValueIF('source_other'))).change(); } if (typeof getQueryStringParamValueIF('gclid') != 'undefined' && getQueryStringParamValueIF('gclid') != '') { $form.find('[name="gclid"]').val(getQueryStringParamValueIF('gclid')).change(); $form.find('[name="lead_source_most_recent__c"]').val('PPC').change(); } //End Form Functions }, onFormSubmitted: function() { if (thankyouInline == false) { window.location = redirectLink; } } }); })(jQuery);