function isValidEmailAddress(emailAddress) { var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); return pattern.test(emailAddress); }; // Render submission container if we're returning from a successful user login. // This will invoke doShowSubmission $(document).ready(function () { if(window.location.href.indexOf("bvauthenticateuser=false") > -1) { $BV.configure("global", {userToken: ''}); $BV.ui("submission_container", {}); } if (window.location.href.indexOf("undefined2") !== -1) { $('.bv_ask_tab').click(); } if (window.location.href.indexOf("QUESTION_SUBMISSION") !== -1) { $('.bv_ask_tab').click(); $('html,body').animate({scrollTop: $("div[id='BVQASubmissionContainer']").offset().top-250},'slow'); } }); $BV.configure("global", { allowSamePageSubmission: true, userToken: "", doLogin: function(successCallback, successUrl) { // Note: doLogin only executes when anonymous submission is disabled in BV config. // When enabled, this is skipped and doShowSubmission is invoked directly. if (successUrl.indexOf('?destinationurl=') > -1) { // Bypass domain check and go directly to destinationurl. This is a workaround // due to server-side issue. returnUrl = decodeURIComponent(successUrl).split('?destinationurl=')[1]; } else { returnUrl = successUrl.split('#')[0]; } // hide regular content and show bv login flow $('.bvflow_hide').addClass('bv_hide'); $('.bvflow_show').removeClass('hidden'); $('.spp-page.wrapper > div, .responsive-tabs--bazaarvoice, .node-spp-related-content-item, .wrapper.cross-sells').not('.bvflow_show').addClass('hidden'); // set form action $('.bvflow_show form').attr('action', 'https://' + window.location.host + '/account/signin.tmpl'); // set return url $('.bvflow_show input[name="RETURN_URL"]').val(returnUrl); // set forgot pwd link $('.bvflow_show .forgot-pw a').attr('href', $('#login-form .forgot-pw a').attr('href')); $('.email_check .btn-bv').click(function(evt){ evt.preventDefault(); var email = $('.bv_email').val(); if(isValidEmailAddress(email)) { generic.jsonrpc.fetch({ method: 'user.registered', params: [{'email_address': email}], onSuccess: function(r) { var val = r.getValue(); var isUser = (val !== null) && (val === 1); if(isUser) { // show full login $('.bvflow_show .email_check').addClass('hidden'); $('.bvflow_show .full_sign_in').removeClass('hidden'); $('.full_sign_in input[name="EMAIL_ADDRESS"]').val(email); } else { // anonymous write-a-review $('.bvflow_show').addClass('hidden'); $('.bvflow_hide').removeClass('bv_hide'); $('.spp-page.wrapper > div, .responsive-tabs--bazaarvoice, .node-spp-related-content-item, .wrapper.cross-sells').not('.bvflow_show').removeClass('hidden'); if (window.location.href.indexOf("undefined2") == -1) { $('html,body').animate({scrollTop: $("div[id='BVSubmissionContainer']").offset().top-250},'slow'); } else { $('html,body').animate({scrollTop: $("div[id='BVQASubmissionContainer']").offset().top-250},'slow'); } } }, onFailure: function (r) {} }); } else { // show "please enter valid email address" msg $('span[for="EMAIL_ADDRESS"]').css('display', 'block'); } }); }, doShowSubmission: function() { // Note: When anonymous submission is disabled and doLogin is invoked, we don't // need to do anything more in the doShowSubmission callback. // Manually construct successUrl (workaround for anonymous login since doLogin won't fire) var bvreturn = document.URL.split('#')[0]; var bvdisplaycode = '3814-en_us'; var bvappcode = (window.location.href.indexOf("undefined2") == -1) ? 'rr' : 'qa'; var bvcontenttype = (window.location.href.indexOf("undefined2") == -1) ? 'REVIEW_SUBMISSION' : 'QUESTION_SUBMISSION'; var bvscriptpage = (window.location.href.indexOf("undefined2") == -1) ? 'submitreview.htm' : 'askquestion.djs'; var bvcampaignid = (window.location.href.indexOf("undefined2") == -1) ? 'BV_RATING_SUMMARY' : 'BV_QA_BROWSE'; var bvformat = (window.location.href.indexOf("undefined2") == -1) ? 'embedded' : 'embeddedhtml'; var bvproductid = '26237'; var bvhost = (typeof(bv_host) !== 'undefined') ? bv_host : 'origins.reviews.bazaarvoice.com' ; var bvpage = 'http://' + bvhost + '/' + bvdisplaycode + '/' + bvproductid + '/' + bvscriptpage + '?format=embedded&campaignid=' + bvcampaignid + '&sessionparams=__BVSESSIONPARAMS__&return=' + encodeURIComponent(bvreturn) + '&innerreturn=http%3A%2F%2Forigins.reviews.bazaarvoice.com%2F' + bvdisplaycode + '%2F' + bvproductid + '%2Freviews.djs%3Fformat%3Dembeddedhtml&user=__USERID__&authsourcetype=__AUTHTYPE__'; var returnUrl = bvreturn + '?bvdisplaycode=' + bvdisplaycode + '&bvappcode=' + bvappcode + '&bvproductid=' + bvproductid + '&bvpage=' + encodeURIComponent(bvpage) + '&bvcontenttype=' + bvcontenttype + '&bvauthenticateuser=false'; // Hide content and show BV login flow unless we're returning from login page. //if(window.location.href.indexOf("bvauthenticateuser") == -1) { if (!false) { // hide regular content and show bv login flow $('.bvflow_hide').addClass('bv_hide'); $('.bvflow_show').removeClass('hidden'); $('.spp-page.wrapper > div, .responsive-tabs--bazaarvoice, .node-spp-related-content-item, .wrapper.cross-sells').not('.bvflow_show').addClass('hidden'); $('.bvflow_show span[for="EMAIL_ADDRESS"]').addClass('hidden'); // toggle review vs. ask-n-answer content if (window.location.href.indexOf("undefined2") == -1) { $('.js-review').removeClass('hidden'); $('.js-ask').addClass('hidden'); } else { $('.js-review').addClass('hidden'); $('.js-ask').removeClass('hidden'); } } // set form action $('.bvflow_show form').attr('action', 'https://' + window.location.host + '/account/signin.tmpl'); $('.bvflow_show input[name="RETURN_URL"]').val(returnUrl); // set forgot pwd link $('.bvflow_show .forgot-pw a').attr('href', $('#login-form .forgot-pw a').attr('href')); $('.email_check .btn-bv').click(function(evt){ evt.preventDefault(); var email = $('.bv_email').val(); if(isValidEmailAddress(email)) { generic.jsonrpc.fetch({ method: 'user.registered', params: [{'email_address': email}], onSuccess: function(r) { var val = r.getValue(); var isUser = (val !== null) && (val === 1); if(isUser) { // show full login $('.bvflow_show .email_check').addClass('hidden'); $('.bvflow_show .full_sign_in').removeClass('hidden'); $('.full_sign_in input[name="EMAIL_ADDRESS"]').val(email); } else { // anonymous write-a-review $('.bvflow_show').addClass('hidden'); $('.bvflow_hide').removeClass('bv_hide'); $('.spp-page.wrapper > div, .responsive-tabs--bazaarvoice, .node-spp-related-content-item, .wrapper.cross-sells').not('.bvflow_show').removeClass('hidden'); if (window.location.href.indexOf("undefined2") == -1) { $('html,body').animate({scrollTop: $("div[id='BVSubmissionContainer']").offset().top-250},'slow'); } else { $('html,body').animate({scrollTop: $("div[id='BVQASubmissionContainer']").offset().top-250},'slow'); } } }, onFailure: function (r) {} }); } else { // show "please enter valid email address" msg $('.bvflow_show span[for="EMAIL_ADDRESS"]').removeClass('hidden').css('display', 'block'); } }); }, onSubmissionReturn: function() { }, doScrollSubmission: function() { if (window.location.href.indexOf("undefined2") == -1) { $('html,body').animate({scrollTop: $("div[id='BVSubmissionContainer']").offset().top-250},'slow'); } else { $('html,body').animate({scrollTop: $("div[id='BVQASubmissionContainer']").offset().top-250},'slow'); } } }); $BV.ui("rr", "show_reviews", { productId: "26237", submissionContainerDiv: "BVSubmissionContainer", onEvent: moveSummary }); if(1 === 1){ $BV.ui("qa", "show_questions", { productId: "26237", subjectType: "product", submissionContainerDiv: "BVQASubmissionContainer", onEvent: moveSummary }); } function moveSummary(bvEvent) { // this needed to properly set the tabs since we have login flows for both R&R and A&A // console.log(bvEvent); if(bvEvent.eventSource === 'Action') { if(bvEvent.bvProduct === 'AskAndAnswer') { $('.responsive-tabs--bazaarvoice li[aria-controls="tab_item-1"]').click(); } else { $('.responsive-tabs--bazaarvoice li[aria-controls="tab_item-0"]').click(); } if(bvEvent.eType === 'Read') { $('html,body').animate({scrollTop: $("a[name='bv_review']").offset().top-150},'slow'); } } };