(function($) { $.debounce = function(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }; $(document).ready(function() { var rewriteDomain = $('body').data('rewrite'); if (rewriteDomain !== '') { $(".header_right_login").on("click", function() { cssSrc = rewriteDomain+"/singlepage/assets/css/bootstrap-pincode-input.css"; if ($('link[href=\"'+cssSrc+'\"]').length === 0) { var ss = document.createElement("link"); ss.type = "text/css"; ss.rel = "stylesheet"; ss.href = cssSrc; document.getElementsByTagName("head")[0].appendChild(ss); } jsSrc = rewriteDomain+"/singlepage/assets/js/custom-pincode-input.js"; if ($('script[src=\"'+jsSrc+'\"]').length === 0) { var sc = document.createElement("script"); sc.type = "text/javascript"; sc.src = jsSrc; sc.defer = true document.getElementsByTagName("head")[0].appendChild(sc); } }); } $(".main_menu_menuopener, .header_menu_opener").on("click", function() { $(".mobile_menu").fadeToggle(); }); $(".mobile_menu2_close").on("click", function() { $(".mobile_menu").fadeOut(); }); $(".forgot-pwd-btn").on("click", function() { $('#popup_login').modal('hide'); $("#modal-forgot").show(); $("#modal-mobile").hide(); setTimeout(function () { $('#popup_forgotpassword').modal('show') }, 400); }); $(".return-login-form").on("click", function() { $('#popup_forgotpassword').modal('hide'); setTimeout(function () { $('#popup_login').modal('show') }, 400); }); $("#preferredEmail").keypress(function(e){ var charCode = !e.charCode ? e.which : e.charCode; if(charCode == 32) e.preventDefault(); }); $(".prevent_default").on("click", function() { event.preventDefault(); }); var config = {}; var landingAssociation = $('[data-landing-association]').attr('data-landing-association'); var landingFinder = $('[data-landing-finder]').attr('data-landing-finder'); if (landingAssociation) { config.association = landingAssociation; } if (landingFinder) { config.finder = landingFinder; } window.$('body').data('current-sitecontext') var branchSiteData = '../staticassets/js/sitevariables.data'; if (!$('body').hasClass('page_usn') && !$('body').hasClass('page_usmc') && !$('body').hasClass('page_usaf') && !$('body').hasClass('page_uscg') && !$('body').hasClass('page_army')) { branchSiteData = '/usn/staticassets/js/sitevariables.data'; } $.getJSON(branchSiteData) .done(onHasData) .fail(function(){ // $.getJSON('usn/staticassets/js/sitevariables.data') // .done(onHasData) }); function onHasData(data){ var serviceBranch = ""; var currentSiteName = $('body').data('current-sitename'); $.each(data.sites, function(i, data) { config[data.SiteValue] = { url: data.url, finder: data.finder }; // service branch var template = '' if (!landingAssociation || config[data.SiteValue].finder[landingAssociation]) serviceBranch += template .replace("$(SiteValue)", data.SiteValue) .replace("$(SiteContext)", data.SiteContext) }); $('#service-select-login, #service-select-signup, #service-select-invite') .append(serviceBranch) .change(function() { var service = $('option:selected', this).val(); var context = $('option:selected', this).attr("context"); $('input[name="serviceBranch"]').attr("value", service); changeBranchOptions(service, context, config); if (config.finder){ $('[name="_F_InvitedBy"]', this.form).val(serviceObj.finder[config.finder]); } }); $('#service-select-login, #service-select-signup').trigger('change'); // if ($('[name="serviceBranch"]').val() != "") { // $('#service-select-signup').val($('[name="serviceBranch"]').val()); // $('#service-select-signup').change(); // $('#service-select-signup').prop("disabled", true); // } } function breakdownService(sName) { if (sName === "Navy") { return "U.S. Navy /USNR"; } else if (sName === "Marines") { return "U.S. Marine Corps /USMCR"; } else if (sName === "Army") { return "U.S. Army /USAR /ARNG"; } else if (sName === "Air Force") { return "U.S. Air Force /USAAF /USAFR /ANG"; } else if (sName === "Coast Guard") { return "U.S. Coast Guard /USCGR /USCGA"; } else { return sName; } } function changeBranchOptions(service, context, config){ var serviceObj = config[service]; var wwwlink = serviceObj && serviceObj.url ? serviceObj.url : ""; if (!wwwlink) return; $('.main_menu_tws > li').removeClass('active'); $(`.main_menu_tws > li.${context}`).addClass('active'); // RM12062: Support a Site parameter $("#signUpForm, #loginForm, #fb-form, #form-forgot").attr("action", wwwlink); $("#resetPassword").attr("href", wwwlink + "?cmd=Login&showResetPassword=true"); // $("#inviteForm").attr("action", wwwlink + "?cmd=PublicInvite&type=PublicInvitation"); } }); $('a[data-target="#popup_login"]').on("click", function() { $('#loginForm .username-passsword>input').val(""); }); $('.forgot-pwd-btn').on("click", function() { $('#form-forgot input[name="_F_Username"]').val(""); }); var validateLogin = $('#loginForm').validate({ errorClass: "pleasecheck", ignore: null, rules:{ "cw.login.CmdLogin.Password": "required", "cw.login.CmdLogin.UserName": "required", "service_select_login": "required" }, onkeyup: false, errorPlacement: function(error, element) { if (element[0].tagName === "INPUT") { errInput = $(".popup_login_error_password"); if (element.val() === "") { $(".ftitle").hide(); errInput.fadeIn(200); } else { if (element.hasClass("pleasecheck")) { errInput.hide(); $(".ftitle").show(); } } } if (element.hasClass('popup_login_select') && element.val() === "") { errSelect = $(".popup_login_error_branch"); $(".ftitle").hide(); errSelect.fadeIn(200); } }, success: "valid" }) var runValSignup = false; var validateSignup = $('#signUpForm').validate({ errorClass: "pleasecheck", ignore: null, rules: { _F_FirstName: { required: true, minlength: 2 }, _F_LastName: { required: true, minlength: 2 }, _F_Email: { required: true, email: true }, "service-select-signup": "required" }, onkeyup: false, errorPlacement: function(error, element) { runValSignup = true; if (element[0].tagName === "INPUT") { errInput = $(".popup_login_error_"+element[0].id); if (element.hasClass("pleasecheck")) { $(".ftitle").hide(); errInput.fadeIn(200); } } if (element.hasClass('popup_login_select')) { if (element.val() === "") { errSelect = $(".popup_login_error_branch"); $(".ftitle").hide(); errSelect.fadeIn(200); } else { element.removeClass("pleasecheck"); } } if ($("#signUpForm .pleasecheck").length < 1) { $(".ftitle").show(); } }, success: "valid" }) var timer; var validateReset = $('#form-forgot').validate({ errorClass: "pleasecheck", ignore: null, rules:{ "_F_Username": "required" }, errorPlacement: function(error, element) { errInput = $(".popup_reset_error_email"); errEmail = $('label[for="_F_Username"].pleasecheck'); if (element[0].tagName === "INPUT") { clearTimeout(timer); if (element.val() === "" && element.hasClass("pleasecheck") && $("#_F_Mobile").val() === "") { if (errEmail.length === 0) { $(".incorrect").empty(); error.appendTo(".incorrect"); } errInput.fadeIn(200); } else if (element.val() !== "" && element.hasClass("pleasecheck")) { timer = setTimeout(function() { if (errEmail.length === 0) { $(".incorrect").empty(); error.appendTo(".incorrect"); } errInput.fadeIn(200); }, 500); } else { errInput.hide(); } } }, messages:{ "_F_Username": "Invalid email" }, success: "valid" }) $(".popup_login_select").select2({ minimumResultsForSearch: Infinity, theme: "popup_login_select", templateSelection: function (data) { if (data.id === "" && $(data.element).parent().hasClass("popup")) { // adjust for custom placeholder values return "Service Branch Affiliation*"; } else if(data.id === "" && $(data.element).parent().hasClass("ownmil")) { return "Your Service Branch Affiliation"; } else if(data.id === "" && $(data.element).parent().hasClass("orgnet")) { return "Your Veteran's Service Branch Affiliation"; } return data.text; } }); $('input.form-control').on('blur', function () { errInput = $(".popup_login_error_"+this.id); if ($(this).val() !== "" && $(this).valid()) { errInput.hide(); } }); $('.popup_login_select').on('select2:select', function () { var selectedID = $(this).val(); if (selectedID !== "" && $(this).valid()) { $(".popup_login_error_top.popup_login_error_branch").hide(); // $(".ftitle").show(); } }); $(".popup_login_error_close").on("click", function() { $(this).parent(".popup_login_error_top").hide(); if (!$(this).parents(".popup_inner").find(".popup_login_error_top").is(':visible')) { $(".ftitle").show(); } }); $(".modal").on("show.bs.modal", function () { $(".popup_login_error_close").trigger("click"); }); $(".modal").on("hide.bs.modal", function () { $(".popup_login_error_top").hide(); $(".popup_login_error_bottom").hide(); validateLogin.resetForm(); if (runValSignup) { validateSignup.resetForm(); } validateReset.resetForm(); $(".ftitle").show(); }); $("#fb-auth").on("click", function() { //check serviceBranch var validator = jQuery( "#loginForm" ).validate(); var isServiceSelected = validator.element('input[name="serviceBranch"]'); if(!isServiceSelected){ return; } FB.login(processLogin, {scope:'email'}); }); function processLogin(response) { if (response.status=="connected" && response.authResponse) { document.getElementById("sesKey").value = response.authResponse.accessToken; document.getElementById("fb-form").submit() ; } } })(jQuery); // Fully reference jQuery after this point. function checkEmail() { var el = document.getElementById('preferredEmail'); var email = el.value.trim(); el.value = email; }