//
//External Script
//
//CID
if (typeof getQueryStringParamValueIF('cid') != 'undefined' && getQueryStringParamValueIF('cid') != '') {
jQuery('[name="cid"]').val(getQueryStringParamValueIF('cid')).change();
var cid = getQueryStringParamValueIF('cid');
}
window.jQuery = window.jQuery || (() => ({
// these are all methods required by HubSpot
change: () => {},
trigger: () => {},
}));
(function ($) {
//ThankYouButton
if (thankyoubutton == true) {
var dlbutton = '
';
} 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) {
var placeholder_text = true;
$('[name="lead_source_most_recent__c"]').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="cid"]').val(cid).change();
$('[name="eid"]').val(emailID).change();
//Add GDPR To Display Fields Array
//var legal_consent_string = $('form .hs-input[name^="LEGAL_CONSENT"]' ).attr('name');
//var legal_consent = legal_consent_string.replace(".", "\\.")
display_fields.push('subscribe');
//Check Subscription Status and change language if subscribed
if ($("[name='subscribe']").is(':checked')) {
$(".hs_subscribe span").wrapInner('');
$(".hs_subscribe .new").replaceWith("You have previously consented to received emails from BCM One. Click here to change your email preferences.");
$(".hs_subscribe input").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");
});
//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%');
}
//Progressive Sort
$.fn.progressiveSort = function() {
$form.find(".hs-subscribe").nextAll('.smart-field').addClass('progressive');
$form.find(".progressive").insertBefore('.hs-subscribe');
}
//Submit Button Function
$.fn.submitbutton = function() {
setInterval(function(){
$(".hs-form input[type=submit]").val(submit_text );
},);
}
$.fn.submitbutton();
//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('div').hasClass('fullwidthrow')) {
$(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() {
$('label .hs-form-required').remove();
$.fn.required();
$.each( display_fields, function( i, val ) {
$form.find('.hs-input[name='+val+']').closest(".hs-dependent-field .field").addClass('display_field');
});
$.fn.placeholder();
if (layout == 2) {
$.fn.layout2Sort();
}
});
//Progressive Sort
$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) {
$form.find("[name='state'] option[value=None]").hide();
var provinceArray = ["AB", "MB", "BC", "NB", "NL", "NS", "NT", "NU", "ON", "PE", "QC", "SK", "YT"];
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');
}
$.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 = {
'7d8dc6b8-0e0f-499b-8371-015118bdb959': 'CC-TEL Flowroute Main',
'75b61f7a-4518-4183-ab43-20c9b8e86c5e': 'CC-TEL Flowroute Resources',
'46d07e40-3c6b-4a58-9834-963c9f0f9b96': 'CC-TEL Flowroute Events',
'74575006-5962-4483-9df2-061e14d07e60': 'CC-TEL Flowroute Webinar',
'2492bfef-8f13-4379-9d0e-77e4ec87a6bd': 'CC-TEL Flowroute Subscription Form',
};
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;
}
//Flowroute.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);